@extends('layouts.admin', ['title' => ($banner->exists ? 'تعديل بانر' : 'بانر جديد').' | RaseedNow'])

@section('content')
    <section class="lc-page-shell">
        <div class="surface p-6">
            <div class="section-heading">
                <div><span>Hero</span><h1>{{ $banner->exists ? 'تعديل بانر' : 'بانر جديد' }}</h1></div>
                <a class="secondary-button" href="{{ route('admin.banners.index') }}">البانرات</a>
            </div>
            @if($errors->any())
                <div class="mt-4 rounded-xl border border-red-200 bg-red-50 p-3 text-sm font-bold text-red-700">{{ $errors->first() }}</div>
            @endif
            <form method="POST" action="{{ $banner->exists ? route('admin.banners.update', $banner) : route('admin.banners.store') }}" enctype="multipart/form-data" class="mt-6 grid gap-4 md:grid-cols-2">
                @csrf
                @if($banner->exists)
                    @method('PATCH')
                @endif
                <label class="form-field"><span>العنوان العربي</span><input name="title_ar" value="{{ old('title_ar', $banner->title_ar) }}" required></label>
                <label class="form-field"><span>English title</span><input name="title_en" value="{{ old('title_en', $banner->title_en) }}" required></label>
                <label class="form-field"><span>الوصف العربي</span><input name="subtitle_ar" value="{{ old('subtitle_ar', $banner->subtitle_ar) }}"></label>
                <label class="form-field"><span>English subtitle</span><input name="subtitle_en" value="{{ old('subtitle_en', $banner->subtitle_en) }}"></label>
                <label class="form-field"><span>الرابط</span><input name="url" value="{{ old('url', $banner->url ?? '#') }}" required></label>
                <label class="form-field"><span>الترتيب</span><input name="sort_order" type="number" min="0" value="{{ old('sort_order', $banner->sort_order ?? 0) }}" required></label>
                <label class="form-field"><span>CTA عربي</span><input name="cta_label_ar" value="{{ old('cta_label_ar', $banner->cta_label_ar) }}"></label>
                <label class="form-field"><span>CTA English</span><input name="cta_label_en" value="{{ old('cta_label_en', $banner->cta_label_en) }}"></label>
                <label class="form-field"><span>Tone</span><input name="tone" value="{{ old('tone', $banner->tone ?? 'blue') }}" required></label>
                <label class="form-field"><span>مسار صورة جاهزة</span><input name="image_path" value="{{ old('image_path', $banner->image_path) }}" placeholder="images/kroti/hero-00.webp"></label>
                <label class="form-field md:col-span-2"><span>رفع صورة الهيرو</span><input name="image" type="file" accept="image/*"></label>
                @if($banner->image_path)
                    <div class="md:col-span-2 rounded-xl border border-[#dfe7e5] bg-white p-3">
                        <span class="mb-2 block text-sm font-bold text-[#475569]">الصورة الحالية</span>
                        <img src="{{ asset($banner->image_path) }}" alt="{{ $banner->title_ar }}" class="h-36 rounded-xl object-contain">
                    </div>
                @endif
                <label class="flex items-center gap-2 font-bold text-[#17264d]"><input name="is_active" type="checkbox" value="1" @checked(old('is_active', $banner->is_active))> نشط</label>
                <button class="primary-button md:col-span-2" type="submit">حفظ</button>
            </form>
        </div>
    </section>
@endsection
