<?php $assetBase =
    basename(rtrim(FCPATH, "\\/")) === "public"
        ? "assets/"
        : "public/assets/"; ?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Email Templates · BrandSquare Admin</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="<?= base_url($assetBase . "css/admin.css") ?>">
</head>
<body class="admin-page">
    <aside class="admin-sidebar">
        <a href="<?= base_url(
            "admin/leads",
        ) ?>" class="admin-logo">Brand<span>Square.</span></a>
        <nav><a href="<?= base_url(
            "admin/leads",
        ) ?>"><i>◉</i> Leads</a><a href="<?= base_url(
    "admin/clients",
) ?>"><i>◉</i> Clients</a><a href="<?= base_url(
    "admin/quotations",
) ?>"><i>₹</i> Quotations</a><a href="<?= base_url(
    "admin/invoices",
) ?>"><i>▤</i> Invoices</a><a href="<?= base_url(
    "admin/industries",
) ?>"><i>◆</i> Industries</a><a class="active" href="<?= base_url(
    "admin/email-templates",
) ?>"><i>✦</i> Email templates</a><a href="<?= base_url(
    "admin/articles",
) ?>"><i>▤</i> Articles</a><a href="<?= base_url(
    "admin/settings",
) ?>"><i>⚙</i> Settings</a><a href="<?= base_url() ?>" target="_blank"><i>↗</i> View website</a></nav>
        <div class="admin-user"><span><?= esc(
            strtoupper(substr((string) session("admin_name"), 0, 2)),
        ) ?></span><div><b><?= esc(session("admin_name")) ?></b><small><?= esc(
    session("admin_email"),
) ?></small></div></div>
        <form action="<?= base_url(
            "admin/logout",
        ) ?>" method="post"><?= csrf_field() ?><button class="logout" type="submit">Sign out →</button></form>
    </aside>
    <main class="admin-main template-main">
        <header class="admin-heading"><div><span>Communication studio</span><h1>Email templates</h1><p>Control the messages customers and your team receive from BrandSquare.</p></div><div class="heading-date"><?= count(
            $templates,
        ) ?> templates</div></header>

        <?php if (session("error")): ?><div class="alert error"><?= esc(
    session("error"),
) ?></div><?php endif; ?>
        <?php if (session("success")): ?><div class="alert success"><?= esc(
    session("success"),
) ?></div><?php endif; ?>

        <section class="template-overview">
            <div><span>DESIGN SYSTEM</span><h2>One polished voice,<br>across every client moment.</h2></div>
            <p>Every template uses the same responsive BrandSquare email design. Edit the message and placeholders without touching email code.</p>
        </section>

        <div class="template-grid">
            <?php foreach ($templates as $index => $template): ?>
                <article class="template-card" style="--template-accent:<?= esc(
                    $template["accent_color"],
                ) ?>">
                    <div class="template-card-top"><span><?= str_pad(
                        (string) ($index + 1),
                        2,
                        "0",
                        STR_PAD_LEFT,
                    ) ?></span><b class="<?= $template["enabled"]
    ? "is-enabled"
    : "is-disabled" ?>"><?= $template["enabled"]
    ? "Active"
    : "Paused" ?></b></div>
                    <small><?= esc($template["category"]) ?></small>
                    <h2><?= esc($template["name"]) ?></h2>
                    <p><?= esc($template["description"]) ?></p>
                    <div class="template-subject"><span>Subject line</span><b><?= esc(
                        $template["subject"],
                    ) ?></b></div>
                    <div class="template-card-actions"><a href="<?= base_url(
                        "admin/email-templates/" . $template["template_key"],
                    ) ?>">Edit template <span>→</span></a><a class="preview-link" href="<?= base_url(
    "admin/email-templates/" . $template["template_key"] . "/preview",
) ?>" target="_blank">Preview ↗</a></div>
                </article>
            <?php endforeach; ?>
        </div>
    </main>
</body>
</html>
