<?php

$settings =
$settings
?? [];

if (empty($settings) && !empty($section['settings_json'])) {

    $decoded =
        json_decode(
            (string)$section['settings_json'],
            true
        );

    if (is_array($decoded)) {
        $settings = $decoded;
    }
}

$brochureFile =
    (string)(
        $settings['brochure_file']
        ?? ''
    );

?>

<div class="card border-0 shadow-sm mb-4">

    <div class="card-header bg-primary text-white fw-bold">
        <i class="fa fa-file-pdf me-2"></i>
        Conference Brochure PDF
    </div>

    <div class="card-body">

        <div class="row g-3">

            <div class="col-md-6">
                <label class="form-label fw-bold">
                    English Title
                </label>

                <input
                    type="text"
                    class="form-control"
                    name="brochure_title_en"
                    value="<?= htmlspecialchars($settings['title_en'] ?? 'Conference Brochure') ?>"
                >
            </div>

            <div class="col-md-6">
                <label class="form-label fw-bold">
                    العنوان العربي
                </label>

                <input
                    type="text"
                    class="form-control text-end"
                    name="brochure_title_ar"
                    value="<?= htmlspecialchars($settings['title_ar'] ?? 'كتيب المؤتمر') ?>"
                    dir="rtl"
                >
            </div>

            <div class="col-md-6">
                <label class="form-label fw-bold">
                    English Subtitle
                </label>

                <input
                    type="text"
                    class="form-control"
                    name="brochure_subtitle_en"
                    value="<?= htmlspecialchars($settings['subtitle_en'] ?? 'Download and view the official conference brochure') ?>"
                >
            </div>

            <div class="col-md-6">
                <label class="form-label fw-bold">
                    الوصف العربي
                </label>

                <input
                    type="text"
                    class="form-control text-end"
                    name="brochure_subtitle_ar"
                    value="<?= htmlspecialchars($settings['subtitle_ar'] ?? 'تحميل واستعراض كتيب المؤتمر الرسمي') ?>"
                    dir="rtl"
                >
            </div>

            <div class="col-12">
                <label class="form-label fw-bold">
                    Upload PDF
                </label>

                <input
                    type="file"
                    name="brochure_pdf"
                    class="form-control"
                    accept="application/pdf,.pdf"
                >

                <div class="form-text">
                    Only PDF files are allowed.
                </div>

                <?php if ($brochureFile !== ''): ?>

                    <input
                        type="hidden"
                        name="existing_brochure_file"
                        value="<?= htmlspecialchars($brochureFile) ?>"
                    >

                    <div class="mt-3">
                        <a
                            class="btn btn-sm btn-success"
                            target="_blank"
                            href="/easychair/uploads/conference_brochures/<?= htmlspecialchars($brochureFile) ?>"
                        >
                            <i class="fa fa-eye me-1"></i>
                            View Current Brochure
                        </a>
                    </div>

                <?php endif; ?>

            </div>

        </div>

    </div>

</div>
