@extends('admin.ad_master')

@section('title', $title)
@section('ad_page_title', 'Edit Privacy Policy')
@section('ad_page_subtitle', 'Legal copy (EN/AR) + SEO')

@section('ad_content')
    @php
        $contentEn = $contentEn ?? [];
        $contentAr = $contentAr ?? [];
    @endphp

    <div class="container-fluid py-4">
        <div class="d-flex flex-column flex-md-row justify-content-between align-items-start gap-3 mb-4">
            <div>
                <h1 class="h3 mb-1">Privacy Policy</h1>
                <p class="text-muted mb-0">Hero, sections, cross-link band, and meta tags.</p>
            </div>
            <div class="d-flex flex-wrap gap-2">
                <a href="{{ route('privacy.policy') }}" target="_blank" rel="noopener" class="btn btn-outline-primary btn-sm">
                    <i class="fa-solid fa-arrow-up-right-from-square me-1"></i> View live (EN)
                </a>
                <a href="{{ route('ar.privacy.policy') }}" target="_blank" rel="noopener" class="btn btn-outline-secondary btn-sm">
                    <i class="fa-solid fa-arrow-up-right-from-square me-1"></i> View live (AR)
                </a>
            </div>
        </div>

        @if (session('success'))
            <div class="alert alert-success" role="alert">{{ session('success') }}</div>
        @endif

        @if ($errors->any())
            <div class="alert alert-danger" role="alert">
                <ul class="mb-0">
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <form action="{{ route('admin.pages.privacy-policy.update') }}" method="POST">
            @csrf
            @method('PUT')

            <div class="card shadow-sm border-0">
                <div class="card-body p-4">
                    <ul class="nav nav-tabs mb-4" role="tablist">
                        <li class="nav-item" role="presentation">
                            <button class="nav-link active" type="button" data-bs-toggle="tab" data-bs-target="#tab-privacy-en" role="tab">English</button>
                        </li>
                        <li class="nav-item" role="presentation">
                            <button class="nav-link" type="button" data-bs-toggle="tab" data-bs-target="#tab-privacy-ar" role="tab" dir="rtl">Arabic</button>
                        </li>
                    </ul>

                    <div class="tab-content">
                        <div class="tab-pane fade show active" id="tab-privacy-en" role="tabpanel">
                            @include('admin.pages._legal-page-lang-fields', ['prefix' => 'en', 'c' => $contentEn])
                        </div>
                        <div class="tab-pane fade" id="tab-privacy-ar" role="tabpanel">
                            @include('admin.pages._legal-page-lang-fields', ['prefix' => 'ar', 'c' => $contentAr])
                        </div>
                    </div>

                    <hr class="my-4">
                    @include('admin.pages._seo-fields', ['seo' => $seo])

                    <div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mt-4">
                        <a href="{{ route('admin.pages.page-contents.edit', ['pageKey' => 'privacy_policy']) }}" class="btn btn-link btn-sm text-muted px-0">
                            Advanced: edit raw JSON
                        </a>
                        <div class="d-flex gap-2">
                            <a href="{{ route('admin.dashboard') }}" class="btn btn-light border">Cancel</a>
                            <button type="submit" class="btn btn-primary px-4">Save changes</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
@endsection
