<?php
function brd_h($v) {
    return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
}

$org = $org ?? [];
$conference = $conference ?? null;
?>

<div class="container-fluid py-3">

    <div class="card border-0 shadow-sm mb-4" style="border-radius:24px;background:linear-gradient(135deg,#0f172a,#1d4ed8);color:#fff;">
        <div class="card-body p-4">
            <h3 class="fw-bold mb-1"><i class="fa fa-image"></i> Branding / Logos</h3>
            <div class="opacity-75">Upload organization and conference logos used on the public conference homepage.</div>
        </div>
    </div>

    <?php if (!empty($_GET['saved'])): ?>
        <div class="alert alert-success">Branding updated successfully.</div>
    <?php endif; ?>

    <form method="post" action="/easychair/admin/branding/save" enctype="multipart/form-data">

        <div class="row g-4">
            <div class="col-lg-6">
                <div class="card border-0 shadow-sm h-100" style="border-radius:22px;">
                    <div class="card-body p-4">
                        <h5 class="fw-bold mb-3">Organization Logo</h5>

                        <?php if (!empty($org['logo_path'])): ?>
                            <div class="mb-3">
                                <img src="/easychair/storage/<?= brd_h($org['logo_path']) ?>" style="max-height:110px;max-width:100%;border-radius:18px;border:1px solid #e5e7eb;padding:8px;">
                            </div>
                        <?php endif; ?>

                        <label class="form-label fw-bold">Upload Organization Logo</label>
                        <input type="file" name="org_logo" class="form-control mb-3" accept=".jpg,.jpeg,.png,.webp,.gif">

                        <?php if (!empty($org['banner_path'])): ?>
                            <div class="mb-3">
                                <img src="/easychair/storage/<?= brd_h($org['banner_path']) ?>" style="max-height:120px;max-width:100%;border-radius:18px;border:1px solid #e5e7eb;padding:8px;">
                            </div>
                        <?php endif; ?>

                        <label class="form-label fw-bold">Upload Organization Banner</label>
                        <input type="file" name="org_banner" class="form-control" accept=".jpg,.jpeg,.png,.webp,.gif">
                    </div>
                </div>
            </div>

            <div class="col-lg-6">
                <div class="card border-0 shadow-sm h-100" style="border-radius:22px;">
                    <div class="card-body p-4">
                        <h5 class="fw-bold mb-3">Conference Logo</h5>

                        <?php if (!$conference): ?>
                            <div class="alert alert-warning">Select a conference first to upload conference-specific logo.</div>
                        <?php else: ?>
                            <div class="text-muted mb-3">
                                <?= brd_h(($conference['title_ar'] ?? '') ?: ($conference['title_en'] ?? $conference['short_name'] ?? 'Conference')) ?>
                            </div>

                            <?php if (!empty($conference['logo_path'])): ?>
                                <div class="mb-3">
                                    <img src="/easychair/storage/<?= brd_h($conference['logo_path']) ?>" style="max-height:110px;max-width:100%;border-radius:18px;border:1px solid #e5e7eb;padding:8px;">
                                </div>
                            <?php endif; ?>

                            <label class="form-label fw-bold">Upload Conference Logo</label>
                            <input type="file" name="conference_logo" class="form-control mb-3" accept=".jpg,.jpeg,.png,.webp,.gif">

                            <?php if (!empty($conference['banner_path'])): ?>
                                <div class="mb-3">
                                    <img src="/easychair/storage/<?= brd_h($conference['banner_path']) ?>" style="max-height:120px;max-width:100%;border-radius:18px;border:1px solid #e5e7eb;padding:8px;">
                                </div>
                            <?php endif; ?>

                            <label class="form-label fw-bold">Upload Conference Banner</label>
                            <input type="file" name="conference_banner" class="form-control" accept=".jpg,.jpeg,.png,.webp,.gif">
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <div class="card border-0 shadow-sm mt-4" style="border-radius:22px;">
            <div class="card-body p-4">
                <button class="btn btn-success btn-lg rounded-pill px-5">
                    Save Branding
                </button>
            </div>
        </div>

    </form>
</div>
