<?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>Articles · 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/articles",
) ?>"><i>¶</i> Articles</a><a href="<?= base_url(
    "admin/email-templates",
) ?>"><i>✦</i> Email templates</a><a href="<?= base_url(
    "admin/settings",
) ?>"><i>⚙</i> Settings</a><a href="<?= base_url(
    "brand-guide",
) ?>" target="_blank"><i>↗</i> View Brand Guide</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 clients-main">
    <header class="admin-heading"><div><span>Organic search publishing</span><h1>Brand Guide articles</h1><p>Create useful, search-friendly guidance for founders planning a new logo or redesigning an existing identity.</p></div><a class="primary-admin-action" href="<?= base_url(
        "admin/articles/new",
    ) ?>">Create article <span>＋</span></a></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="quotation-metrics article-metrics">
        <article><span>All articles</span><b><?= esc(
            $metrics["total"],
        ) ?></b><small>Publishing records</small></article>
        <article><span>Published</span><b><?= esc(
            $metrics["published"],
        ) ?></b><small>Visible in Brand Guide</small></article>
        <article><span>Drafts</span><b><?= esc(
            $metrics["drafts"],
        ) ?></b><small>Still being prepared</small></article>
        <article><span>Featured</span><b><?= esc(
            $metrics["featured"],
        ) ?></b><small>Priority guide content</small></article>
    </section>
    <section class="admin-panel client-panel">
        <div class="panel-toolbar"><div><h2>Article library</h2><span>SEO metadata, publishing status, and featured placement</span></div><form method="get" class="client-search"><input name="search" value="<?= esc(
            $search,
        ) ?>" placeholder="Search title, category, or keyword..."><button type="submit">Search</button><?php if (
    $search
): ?><a href="<?= base_url(
    "admin/articles",
) ?>">Clear</a><?php endif; ?></form></div>
        <div class="table-wrap"><table class="client-table article-admin-table"><thead><tr><th>Article</th><th>Category</th><th>SEO focus</th><th>Status</th><th>Actions</th></tr></thead><tbody>
        <?php if (
            !$articles
        ): ?><tr><td colspan="5" class="empty-state"><b>No articles found.</b><span>Create the first Brand Guide article.</span></td></tr><?php endif; ?>
        <?php foreach ($articles as $article): ?><tr>
            <td><a class="client-identity" href="<?= base_url(
                "admin/articles/" . $article["id"],
            ) ?>"><span class="article-theme-<?= esc(
    $article["theme"],
) ?>"><?= esc(
    strtoupper(substr($article["title"], 0, 2)),
) ?></span><div><b><?= esc($article["title"]) ?></b><small><?= esc(
    $article["reading_minutes"],
) ?> min read<?= $article["is_featured"]
     ? " · Featured"
     : "" ?></small></div></a></td>
            <td><span class="article-category"><?= esc(
                $article["category"],
            ) ?></span></td>
            <td><b><?= esc(
                $article["focus_keyword"] ?: "Not set",
            ) ?></b><small class="article-slug">/brand-guide/<?= esc(
    $article["slug"],
) ?></small></td>
            <td><span class="quote-status status-<?= $article["is_published"]
                ? "accepted"
                : "draft" ?>"><?= $article["is_published"]
    ? "Published"
    : "Draft" ?></span></td>
            <td><div class="client-row-actions"><a href="<?= base_url(
                "admin/articles/" . $article["id"],
            ) ?>">View</a><a href="<?= base_url(
    "admin/articles/" . $article["id"] . "/edit",
) ?>">Edit</a></div></td>
        </tr><?php endforeach; ?>
        </tbody></table></div>
    </section>
</main>
</body>
</html>
