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

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

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

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

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