@extends('admin.masterAdmin')

@section('content')
    <div class="row">
        <div class="col-lg-12">
            <div class="card card-fullheight">
                <div class="card-header">
                    <h5 class="box-title">{{ isset($Commitment) ? 'Edit Commitment' : 'Add Commitment' }}</h5>
                </div>

                <div class="card-body">
                    @include('components.alert')

                    <form
                        action="{{ isset($Commitment) ? route('commitment.update', $Commitment->id) : route('commitment.store') }}"
                        method="POST" enctype="multipart/form-data">

                        @csrf
                        @if (isset($Commitment))
                            @method('PUT')
                        @endif

                        <input name="type" value="1" hidden>

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

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



                        {{-- Image Upload --}}
                        <div class="mb-3">
                            <label for="image" class="form-label">Image</label>
                            <input type="file" name="image" id="image" class="form-control" accept="image/*">
                            @if (isset($Commitment) && $Commitment->image)
                                <div class="mt-2">
                                    <img src="{{ asset($Commitment->image) }}" alt="Current Image" width="120">
                                </div>
                            @endif
                        </div>

                        {{-- Buttons --}}
                        <div class="mt-4">
                            <button type="submit" class="btn btn-success">
                                {{ isset($Commitment) ? 'Update' : 'Save' }}
                            </button>
                            <a href="{{ route('commitment.index') }}" class="btn btn-secondary">Cancel</a>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection
