@extends('layouts.admin', ['title' => ($category->exists ? 'تعديل فئة' : 'فئة جديدة').' | RaseedNow'])

@section('content')
    <section class="lc-page-shell">
        <div class="surface p-6">
            <div class="section-heading">
                <div>
                    <span>Catalog</span>
                    <h1>{{ $category->exists ? 'تعديل فئة' : 'فئة جديدة' }}</h1>
                </div>
                <a class="secondary-button" href="{{ route('admin.categories.index') }}">الفئات</a>
            </div>

            @if($errors->any())
                <div class="mt-4 rounded border border-red-200 bg-red-50 p-3 text-sm text-red-700">{{ $errors->first() }}</div>
            @endif

            <form method="POST" action="{{ $category->exists ? route('admin.categories.update', $category) : route('admin.categories.store') }}" class="mt-6 grid gap-4 md:grid-cols-2">
                @csrf
                @if($category->exists)
                    @method('PATCH')
                @endif
                <label class="form-field"><span>الاسم العربي</span><input name="name_ar" value="{{ old('name_ar', $category->name_ar) }}" required></label>
                <label class="form-field"><span>الاسم الإنجليزي</span><input name="name_en" value="{{ old('name_en', $category->name_en) }}" required></label>
                <label class="form-field"><span>Slug</span><input name="slug" value="{{ old('slug', $category->slug) }}" placeholder="يولد تلقائيًا عند تركه فارغًا"></label>
                <label class="form-field"><span>Icon Key</span><input name="icon" value="{{ old('icon', $category->icon) }}"></label>
                <label class="form-field"><span>اللون</span><input name="color" value="{{ old('color', $category->color) }}" required></label>
                <label class="form-field"><span>الترتيب</span><input name="sort_order" value="{{ old('sort_order', $category->sort_order) }}" type="number" min="0" required></label>
                <label class="form-field md:col-span-2"><span>الوصف العربي</span><input name="description_ar" value="{{ old('description_ar', $category->description_ar) }}"></label>
                <label class="form-field md:col-span-2"><span>English Description</span><input name="description_en" value="{{ old('description_en', $category->description_en) }}"></label>
                <label class="flex items-center gap-2 font-bold text-[#17264d]"><input name="is_featured" type="checkbox" value="1" @checked(old('is_featured', $category->is_featured))> مميزة</label>
                <label class="flex items-center gap-2 font-bold text-[#17264d]"><input name="is_active" type="checkbox" value="1" @checked(old('is_active', $category->is_active))> نشطة</label>
                <button class="primary-button md:col-span-2" type="submit">حفظ</button>
            </form>
        </div>
    </section>
@endsection
