<?php $__env->startSection('content'); ?>
<div class="container mx-auto max-w-3xl px-4">
    <?php echo $__env->make('admin.panel._nav', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <div class="mb-6 flex items-center justify-between">
        <h1 class="text-xl font-semibold text-gray-900">Edit Section: <?php echo e($section->name); ?></h1>
        <a href="<?php echo e(route('admin.sections.index')); ?>" class="text-sm text-gray-500 hover:underline">&larr; Kembali</a>
    </div>

    <?php if($section->key === 'seo'): ?>
        <div class="mb-4 rounded border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-800">
            Pengaturan ini dipakai untuk SEO &amp; tampilan saat link situs dibagikan (WhatsApp, Facebook, dll).
            <strong>Judul</strong> = meta title / og:title, <strong>Subjudul</strong> = meta description / og:description,
            <strong>Gambar</strong> = gambar preview saat dibagikan (og:image). Judul ini jadi default — halaman
            tertentu (mis. Contact) tetap bisa punya judulnya sendiri.
        </div>
    <?php endif; ?>

    <form method="POST" action="<?php echo e(route('admin.sections.update', $section)); ?>" enctype="multipart/form-data" class="space-y-4">
        <?php echo csrf_field(); ?>
        <?php echo method_field('PUT'); ?>

        <div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
            <div>
                <label class="block text-sm font-medium text-gray-700">Judul (ID)</label>
                <input type="text" name="title[id]" value="<?php echo e(old('title.id', $section->getTranslation('title', 'id', false))); ?>"
                       class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700">Title (EN)</label>
                <input type="text" name="title[en]" value="<?php echo e(old('title.en', $section->getTranslation('title', 'en', false))); ?>"
                       class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
            </div>
        </div>

        <div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
            <div>
                <label class="block text-sm font-medium text-gray-700">Subjudul (ID)</label>
                <textarea name="subtitle[id]" rows="2"
                          class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm"><?php echo e(old('subtitle.id', $section->getTranslation('subtitle', 'id', false))); ?></textarea>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700">Subtitle (EN)</label>
                <textarea name="subtitle[en]" rows="2"
                          class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm"><?php echo e(old('subtitle.en', $section->getTranslation('subtitle', 'en', false))); ?></textarea>
            </div>
        </div>
        <?php if($section->key === 'footer'): ?>
            <p class="text-xs text-gray-400">Subjudul di sini tampil sebagai keterangan singkat di bawah logo pada kolom pertama footer.</p>
        <?php endif; ?>

        <?php
            $contentLabel = match ($section->key) {
                'team' => 'URL Embed Google Maps',
                'footer' => 'Teks Copyright',
                'contact' => 'Alamat',
                'services' => 'Deskripsi About Us',
                'visimisi' => 'Pernyataan Visi',
                'privacy_policy', 'terms_conditions' => 'Isi Halaman',
                default => 'Konten',
            };
            $proseContent = in_array($section->key, ['services', 'visimisi', 'privacy_policy', 'terms_conditions'], true);
        ?>
        <div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
            <div>
                <label class="block text-sm font-medium text-gray-700"><?php echo e($contentLabel); ?> (ID)</label>
                <div class="mt-1">
                    <?php if($proseContent): ?>
                        <?php echo $__env->make('admin.panel._rich-editor', ['name' => 'content[id]', 'value' => old('content.id', $section->getTranslation('content', 'id', false))], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    <?php else: ?>
                        <textarea name="content[id]" rows="3"
                                  class="w-full rounded border border-gray-300 px-3 py-2 text-sm"><?php echo e(old('content.id', $section->getTranslation('content', 'id', false))); ?></textarea>
                    <?php endif; ?>
                </div>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700"><?php echo e($contentLabel); ?> (EN)</label>
                <div class="mt-1">
                    <?php if($proseContent): ?>
                        <?php echo $__env->make('admin.panel._rich-editor', ['name' => 'content[en]', 'value' => old('content.en', $section->getTranslation('content', 'en', false))], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    <?php else: ?>
                        <textarea name="content[en]" rows="3"
                                  class="w-full rounded border border-gray-300 px-3 py-2 text-sm"><?php echo e(old('content.en', $section->getTranslation('content', 'en', false))); ?></textarea>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        <?php if($proseContent): ?>
            <p class="text-xs text-gray-400">Enter untuk baris baru. Gunakan tombol <strong>B</strong> untuk tebal dan tombol angka/bullet untuk daftar bernomor.</p>
        <?php else: ?>
            <p class="text-xs text-gray-400">Untuk section "team" &amp; "contact", nilai ID dan EN biasanya sama (URL peta / alamat tidak perlu diterjemahkan) &mdash; cukup isi keduanya sama.</p>
        <?php endif; ?>

        <?php if($section->key === 'contact'): ?>
            <div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
                <div>
                    <label class="block text-sm font-medium text-gray-700">Telepon</label>
                    <input type="text" name="meta[phone]" value="<?php echo e(old('meta.phone', $section->meta['phone'] ?? '')); ?>"
                           class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700">Email</label>
                    <input type="email" name="meta[email]" value="<?php echo e(old('meta.email', $section->meta['email'] ?? '')); ?>"
                           class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
                </div>
            </div>
        <?php endif; ?>

        <?php if(in_array($section->key, ['hero'], true)): ?>
            <div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
                <div>
                    <label class="block text-sm font-medium text-gray-700">Teks Tombol (ID)</label>
                    <input type="text" name="button_text[id]" value="<?php echo e(old('button_text.id', $section->getTranslation('button_text', 'id', false))); ?>"
                           class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700">Button Text (EN)</label>
                    <input type="text" name="button_text[en]" value="<?php echo e(old('button_text.en', $section->getTranslation('button_text', 'en', false))); ?>"
                           class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
                </div>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700">Link Tombol</label>
                <input type="text" name="button_link" value="<?php echo e(old('button_link', $section->button_link)); ?>"
                       class="mt-1 w-full rounded border border-gray-300 px-3 py-2 text-sm">
            </div>
        <?php endif; ?>

        <div>
            <label class="block text-sm font-medium text-gray-700">Gambar</label>
            <?php if($section->imageUrl()): ?>
                <img src="<?php echo e($section->imageUrl()); ?>"
                     alt="<?php echo e($section->name); ?>" class="mt-2 h-20 rounded border border-gray-200 object-cover">
            <?php endif; ?>
            <input type="file" name="image" accept="image/*" class="mt-1 w-full text-sm">
        </div>

        <div class="flex items-center gap-2">
            <input type="checkbox" name="is_active" id="is_active" value="1" <?php if(old('is_active', $section->is_active)): echo 'checked'; endif; ?>>
            <label for="is_active" class="text-sm text-gray-700">Aktif</label>
        </div>

        <div class="flex gap-3">
            <button type="submit" class="rounded bg-gray-900 px-4 py-2 text-sm text-white hover:bg-gray-700">Simpan</button>
            <a href="<?php echo e(route('admin.sections.index')); ?>" class="rounded border border-gray-300 px-4 py-2 text-sm text-gray-700">Batal</a>
        </div>
    </form>

    <div class="mt-10">
        <div class="mb-4 flex items-center justify-between">
            <h2 class="text-lg font-semibold text-gray-900">Item <?php echo e($section->name); ?></h2>
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('create sections')): ?>
                <a href="<?php echo e(route('admin.sections.items.create', $section)); ?>"
                   class="rounded bg-gray-900 px-3 py-2 text-sm text-white hover:bg-gray-700">
                    Tambah Item
                </a>
            <?php endif; ?>
        </div>
        <?php if($section->key === 'services'): ?>
            <p class="mb-3 text-xs text-gray-400">Item di sini adalah kartu statistik: isi "Judul" dengan angka (mis. "10+") dan "Deskripsi" dengan labelnya (mis. "Tahun Pengalaman").</p>
        <?php elseif($section->key === 'visimisi'): ?>
            <p class="mb-3 text-xs text-gray-400">Item di sini adalah poin-poin Misi: isi "Judul" dengan satu poin misi (deskripsi tidak dipakai).</p>
        <?php elseif($section->key === 'whatwedo'): ?>
            <p class="mb-3 text-xs text-gray-400">Item di sini tampil sebagai kartu/kotak: isi "Ikon", "Judul", dan "Deskripsi" untuk tiap kartu.</p>
        <?php elseif($section->key === 'features'): ?>
            <p class="mb-3 text-xs text-gray-400">Isi "Link" (opsional) kalau kartu layanan ini perlu diarahkan ke website lain saat diklik — kosongkan kalau tidak perlu.</p>
        <?php elseif($section->key === 'footer'): ?>
            <p class="mb-3 text-xs text-gray-400">Item di sini tampil sebagai link kanan-bawah footer (mis. Kebijakan Privasi, Syarat &amp; Ketentuan): isi "Judul" dan "Link" tujuannya.</p>
        <?php endif; ?>

        <div class="overflow-x-auto rounded border border-gray-200">
            <table class="min-w-full text-sm">
                <thead class="bg-gray-50 text-left text-gray-600">
                    <tr>
                        <th class="px-4 py-2">Urutan</th>
                        <th class="px-4 py-2">Gambar</th>
                        <th class="px-4 py-2">Judul</th>
                        <th class="px-4 py-2">Status</th>
                        <th class="px-4 py-2">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $section->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr class="border-t border-gray-100">
                            <td class="px-4 py-2"><?php echo e($item->order); ?></td>
                            <td class="px-4 py-2">
                                <?php if($item->imageUrl()): ?>
                                    <img src="<?php echo e($item->imageUrl()); ?>"
                                         alt="<?php echo e($item->title); ?>" class="h-8 w-auto rounded">
                                <?php else: ?>
                                    -
                                <?php endif; ?>
                            </td>
                            <td class="px-4 py-2"><?php echo e($item->title ?: '-'); ?></td>
                            <td class="px-4 py-2">
                                <?php if($item->is_active): ?>
                                    <span class="rounded bg-green-100 px-2 py-1 text-xs text-green-800">Aktif</span>
                                <?php else: ?>
                                    <span class="rounded bg-gray-200 px-2 py-1 text-xs text-gray-700">Nonaktif</span>
                                <?php endif; ?>
                            </td>
                            <td class="px-4 py-2">
                                <div class="flex flex-wrap gap-2">
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('edit sections')): ?>
                                        <a href="<?php echo e(route('admin.items.edit', $item)); ?>" class="text-blue-600 hover:underline">Edit</a>
                                        <form method="POST" action="<?php echo e(route('admin.sections.items.toggle-status', $item)); ?>">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('PATCH'); ?>
                                            <button type="submit" class="text-amber-600 hover:underline">
                                                <?php echo e($item->is_active ? 'Nonaktifkan' : 'Aktifkan'); ?>

                                            </button>
                                        </form>
                                    <?php endif; ?>
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('delete sections')): ?>
                                        <form method="POST" action="<?php echo e(route('admin.items.destroy', $item)); ?>"
                                              onsubmit="return confirm('Hapus item ini?')">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button type="submit" class="text-red-600 hover:underline">Hapus</button>
                                        </form>
                                    <?php endif; ?>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="5" class="px-4 py-6 text-center text-gray-500">Belum ada item.</td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon2\www\dsi112com\resources\views/admin/panel/sections/edit.blade.php ENDPATH**/ ?>