@extends('admin.layouts.app')

@section('title', 'Үйлчилгээ засах')
@section('page_title', 'Үйлчилгээ засах: ' . $service->title)

@section('content')

<form action="{{ route('admin.services.update', $service) }}" method="POST" enctype="multipart/form-data" class="max-w-3xl bg-white rounded-2xl border border-gray-100 p-6 lg:p-8 space-y-5">
    @csrf @method('PUT')

    <div>
        <label class="block text-sm font-semibold mb-1">Үйлчилгээний нэр <span class="text-nsma-red">*</span></label>
        <input type="text" name="title" value="{{ old('title', $service->title) }}" required class="w-full px-4 py-3 border border-gray-200 rounded-lg outline-none">
    </div>

    <div>
        <label class="block text-sm font-semibold mb-1">Богино тайлбар</label>
        <textarea name="short_description" rows="2" class="w-full px-4 py-3 border border-gray-200 rounded-lg outline-none">{{ old('short_description', $service->short_description) }}</textarea>
    </div>

    <div>
        <label class="block text-sm font-semibold mb-1">Дэлгэрэнгүй тайлбар</label>
        <textarea name="description" rows="4" class="w-full px-4 py-3 border border-gray-200 rounded-lg outline-none">{{ old('description', $service->description) }}</textarea>
    </div>

    <div>
        <label class="block text-sm font-semibold mb-1">Бүтэн контент (HTML)</label>
        <textarea name="full_content" rows="8" class="w-full px-4 py-3 border border-gray-200 rounded-lg outline-none font-mono text-sm">{{ old('full_content', $service->full_content) }}</textarea>
    </div>

    <div>
        <label class="block text-sm font-semibold mb-1">Онцлог</label>
        <textarea name="features" rows="4" class="w-full px-4 py-3 border border-gray-200 rounded-lg outline-none">{{ old('features', is_array($service->features) ? implode("\n", $service->features) : '') }}</textarea>
    </div>

    <div class="grid md:grid-cols-2 gap-4">
        <div>
            <label class="block text-sm font-semibold mb-1">Дүрс зураг</label>
            @if($service->iconImageUrl()) <img src="{{ $service->iconImageUrl() }}" class="w-16 h-16 mb-2 rounded-lg"> @endif
            <input type="file" name="icon_image" accept="image/*" class="w-full">
        </div>
        <div>
            <label class="block text-sm font-semibold mb-1">Cover зураг</label>
            @if($service->coverImageUrl()) <img src="{{ $service->coverImageUrl() }}" class="w-32 h-20 mb-2 rounded-lg object-cover"> @endif
            <input type="file" name="cover_image" accept="image/*" class="w-full">
        </div>
    </div>

    <div class="grid md:grid-cols-3 gap-4">
        <div>
            <label class="block text-sm font-semibold mb-1">Эрэмбэ</label>
            <input type="number" name="sort_order" value="{{ $service->sort_order }}" class="w-full px-4 py-3 border border-gray-200 rounded-lg outline-none">
        </div>
        <label class="flex items-center gap-2 pt-7"><input type="hidden" name="is_active" value="0"><input type="checkbox" name="is_active" value="1" {{ $service->is_active ? 'checked' : '' }} class="rounded"> Идэвхтэй</label>
        <label class="flex items-center gap-2 pt-7"><input type="hidden" name="show_on_home" value="0"><input type="checkbox" name="show_on_home" value="1" {{ $service->show_on_home ? 'checked' : '' }} class="rounded"> Нүүр хуудсанд</label>
    </div>

    <div class="flex items-center gap-3 pt-4 border-t">
        <button type="submit" class="bg-nsma-red text-white font-semibold px-6 py-3 rounded-lg hover:bg-red-600">Хадгалах</button>
        <a href="{{ route('admin.services.index') }}" class="text-gray-600">Цуцлах</a>
    </div>
</form>

@endsection
