<x-admin-layout :title="$item->exists ? 'Edit Content Block' : 'Create Content Block'">
    <x-admin.form-panel :back-route="route('admin.content-blocks.index')">
        <form method="POST" action="{{ $item->exists ? route('admin.content-blocks.update', $item) : route('admin.content-blocks.store') }}" class="space-y-4">
            @csrf
            @if ($item->exists) @method('PUT') @endif

            <div class="grid grid-cols-2 gap-4">
                <div>
                    <label class="block text-sm font-medium">Page</label>
                    <input name="page" value="{{ old('page', $item->page) }}" class="admin-input" required>
                </div>
                <div>
                    <label class="block text-sm font-medium">Section Key</label>
                    <input name="section_key" value="{{ old('section_key', $item->section_key) }}" class="admin-input" required>
                </div>
            </div>
            <div>
                <label class="block text-sm font-medium">Title</label>
                <textarea name="title" rows="2" class="admin-input">{{ old('title', $item->title) }}</textarea>
            </div>
            <div>
                <label class="block text-sm font-medium">Body</label>
                <textarea name="body" rows="4" class="admin-input">{{ old('body', $item->body) }}</textarea>
            </div>
            <div>
                <label class="block text-sm font-medium">Meta (JSON)</label>
                <textarea name="meta" rows="6" class="admin-input font-mono text-sm">{{ old('meta', $item->meta ? json_encode($item->meta, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) : '') }}</textarea>
            </div>
            <div>
                <label class="block text-sm font-medium">Sort Order</label>
                <input type="number" name="sort_order" value="{{ old('sort_order', $item->sort_order ?? 0) }}" class="admin-input" required>
            </div>
            <button type="submit" class="admin-btn-primary">Save</button>
        </form>
    </x-admin.form-panel>
</x-admin-layout>
