@extends('admin.masterAdmin')

@section('content')
    <div class="card">
        <div class="card-header">
            <h5>{{ isset($leadership) ? 'Edit Leadership' : 'Add Leadership' }}</h5>
        </div>
        <div class="card-body">
            <form action="{{ isset($leadership) ? route('leadership.update', $leadership->id) : route('leadership.store') }}"
                method="POST" enctype="multipart/form-data">
                @csrf
                @if (isset($leadership))
                    @method('PUT')
                @endif

                <div class="mb-3">
                    <label>Name</label>
                    <input type="text" name="name" class="form-control"
                        value="{{ old('name', $leadership->name ?? '') }}" required>
                </div>

                <div class="mb-3">
                    <label>Email</label>
                    <input type="email" name="email" class="form-control"
                        value="{{ old('email', $leadership->email ?? '') }}" required>
                </div>

                <div class="mb-3">
                    <label>Degree</label>
                    <input type="text" name="degree" class="form-control"
                        value="{{ old('degree', $leadership->degree ?? '') }}">
                </div>

                <div class="mb-3">
                    <label>Position</label>
                    <input type="text" name="position" class="form-control"
                        value="{{ old('position', $leadership->position ?? '') }}" required>
                </div>

                <div class="mb-3">
                    <label>Short Description</label>
                    <textarea name="short_description" class="form-control" rows="2">{{ old('short_description', $leadership->short_description ?? '') }}</textarea>
                </div>

                <div class="mb-3">
                    <label>Description</label>
                    <textarea name="description" class="form-control" rows="4">{{ old('description', $leadership->description ?? '') }}</textarea>
                </div>

                <div class="mb-3">
                    <label>Image</label>
                    <input type="file" name="image" accept="image/*" class="form-control">
                    @if (isset($leadership) && $leadership->image)
                        <div class="mt-2">
                            <img src="{{ asset('public/' . $leadership->image) }}" alt="Leadership Image" width="120">
                        </div>
                    @endif
                </div>

                <div class="mb-3 form-check">
                    <input type="checkbox" name="is_ceo" id="is_ceo" class="form-check-input"
                        {{ old('is_ceo', $leadership->is_ceo ?? false) ? 'checked' : '' }}>
                    <label for="is_ceo" class="form-check-label ms-2">Is CEO?</label>
                    <small class="form-text text-muted">Check this if the person is the CEO.</small>
                </div>

                <button class="btn btn-success mt-3">{{ isset($leadership) ? 'Update' : 'Save' }}</button>
                <a href="{{ route('leadership.index') }}" class="btn btn-secondary mt-3">Cancel</a>
            </form>
        </div>
    </div>
@endsection
