@extends('admin.layouts.app')

@section('content')
    <h1 class="text-3xl font-bold mb-8">Tambah Berita</h1>

    <div class="bg-white rounded-2xl shadow p-6">
        <form action="{{ route('admin.posts.store') }}" method="POST" enctype="multipart/form-data" class="space-y-6">
            @csrf

            <div>
                <label class="block mb-2 font-medium">Judul</label>
                <input type="text" name="title" value="{{ old('title') }}"
                    class="w-full border border-slate-300 rounded-xl px-4 py-3">
                @error('title') <p class="text-red-600 text-sm mt-2">{{ $message }}</p> @enderror
            </div>

            <div>
                <label class="block mb-2 font-medium">Ringkasan</label>
                <textarea name="excerpt" rows="3"
                    class="w-full border border-slate-300 rounded-xl px-4 py-3">{{ old('excerpt') }}</textarea>
            </div>

            <div>
                <label class="block mb-2 font-medium">Konten</label>
                <textarea id="content" name="content" rows="10"
                    class="w-full border border-slate-300 rounded-xl px-4 py-3">{{ old('content') }}</textarea>
                @error('content') <p class="text-red-600 text-sm mt-2">{{ $message }}</p> @enderror
            </div>

            <div>
                <label class="block mb-2 font-medium">Gambar</label>
                <input type="file" name="image" class="w-full border border-slate-300 rounded-xl px-4 py-3">
                @error('image') <p class="text-red-600 text-sm mt-2">{{ $message }}</p> @enderror
            </div>

            <div class="flex items-center gap-2">
                <input type="checkbox" name="is_published" value="1" checked>
                <label>Publish sekarang</label>
            </div>

            <div class="flex gap-3">
                <button type="submit" class="bg-blue-900 hover:bg-blue-800 text-white px-6 py-3 rounded-xl font-semibold">
                    Simpan
                </button>
                <a href="{{ route('admin.posts.index') }}"
                    class="bg-slate-300 hover:bg-slate-400 text-slate-800 px-6 py-3 rounded-xl font-semibold">
                    Kembali
                </a>
            </div>
        </form>
    </div>
    <script src="{{ asset('vendor/tinymce/tinymce/tinymce.min.js') }}"></script>
    <script>
        tinymce.init({
            selector: '#content',
            height: 500,
            menubar: true,
            license_key: 'gpl',
            base_url: "{{ asset('vendor/tinymce/tinymce') }}",
            suffix: '.min',
            plugins: 'lists link image table code preview fullscreen wordcount',
            toolbar: 'undo redo | blocks | bold italic underline | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image table | preview code fullscreen',
            branding: false
        });
    </script>
@endsection