<?php
$page_title = 'Additional Branding';
$page_description = 'Co-branded marketing collateral for Buy Local Lowveld members.';

require_once __DIR__ . '/includes/auth.php';
require_once __DIR__ . '/includes/csrf.php';

// Prefer DB (Phase 2a); fall back to Phase 1 array if DB isn't ready yet.
if (db_is_ready()) {
    $items = db_all('SELECT * FROM branding_items WHERE active = 1 ORDER BY id');
} else {
    $packages = require __DIR__ . '/data/packages.php';
    $items = array_map(fn($b) => [
        'slug'          => $b['slug'],
        'name'          => $b['name'],
        'price_display' => $b['price'],
        'description'   => $b['description'],
    ], $packages['branding']);
}

$logged_in = auth_check();

require 'includes/header.php';
?>

<section class="page-banner">
    <div class="container">
        <h1>Additional Branding</h1>
        <p>Go beyond a directory listing &mdash; co-branded assets that keep you top-of-mind.</p>
    </div>
</section>

<section class="section">
    <div class="container">
        <div class="grid grid-2">
            <div>
                <h2>Why you should brand your company</h2>
                <p>
                    Membership in Buy Local Lowveld gives you a badge &mdash; but a badge
                    only works if your customers see it. Branded collateral turns every
                    customer interaction, vehicle trip, and event into a visible reminder
                    that you're part of the community that's investing in this region.
                </p>
                <ul>
                    <li><strong>Instant recognition</strong> &mdash; customers who follow the Buy Local mark will spot you immediately.</li>
                    <li><strong>Social proof</strong> &mdash; being visibly part of a curated network builds trust faster than any ad.</li>
                    <li><strong>Network effect</strong> &mdash; every member who displays Buy Local branding grows the recognition of the whole group.</li>
                </ul>
            </div>
            <div>
                <div class="card">
                    <h3>Ordering process</h3>
                    <ol>
                        <li>Browse items below and add them to your cart.</li>
                        <li>Check out from your member dashboard.</li>
                        <li>We produce and ship within 10 business days.</li>
                    </ol>
                    <?php if (!$logged_in): ?>
                        <p class="muted" style="font-size:.85rem;">
                            Ordering requires a logged-in member account.
                            <a href="login.php">Log in</a> or
                            <a href="become-member.php">join first</a>.
                        </p>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</section>

<section class="section section-alt">
    <div class="container">
        <h2 class="text-center">Branding options</h2>
        <p class="text-center muted mb-3">All items are co-branded with your logo and the Buy Local mark.</p>

        <div class="grid grid-3">
            <?php foreach ($items as $b): ?>
                <div class="card">
                    <h3><?= htmlspecialchars($b['name']) ?></h3>
                    <p style="font-size:1.2rem;font-weight:800;color:var(--brand-primary);">
                        <?= htmlspecialchars($b['price_display']) ?>
                    </p>
                    <p><?= htmlspecialchars($b['description']) ?></p>

                    <?php if ($logged_in): ?>
                        <form method="post" action="member/add-to-cart.php" style="margin-top:1rem;">
                            <?= csrf_field() ?>
                            <input type="hidden" name="item_slug" value="<?= htmlspecialchars($b['slug']) ?>">
                            <input type="hidden" name="quantity" value="1">
                            <button type="submit" class="btn btn-block">Add to cart</button>
                        </form>
                    <?php else: ?>
                        <a href="login.php?next=additional-branding.php" class="btn btn-block mt-2">
                            Log in to add to cart
                        </a>
                    <?php endif; ?>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<?php require 'includes/footer.php'; ?>
