<?php
$assetBase =
    basename(rtrim(FCPATH, "\\/")) === "public" ? "assets/" : "public/assets/";
$fullName = $client["first_name"] . " " . $client["last_name"];
$initials =
    substr($client["first_name"], 0, 1) . substr($client["last_name"], 0, 1);
$phoneHref = preg_replace("/[^0-9+]/", "", $client["mobile"]);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?= esc($fullName) ?> · 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 class="active" 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 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 client-profile-main">
        <header class="admin-heading"><div><a class="back-to-templates" href="<?= base_url(
            "admin/clients",
        ) ?>">← Client directory</a><h1>Client profile</h1><p>Contact details and account information in one place.</p></div><a class="primary-admin-action" href="<?= base_url(
    "admin/clients/" . $client["id"] . "/edit",
) ?>">Edit client <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="client-profile-card">
            <div class="client-profile-hero">
                <span><?= esc(strtoupper($initials)) ?></span>
                <div><small>CLIENT #<?= esc(
                    $client["id"],
                ) ?></small><h2><?= esc(
    $fullName,
) ?></h2><p>Client since <?= date(
    "d F Y",
    strtotime($client["created_at"]),
) ?></p></div>
            </div>
            <div class="client-contact-grid">
                <article><span>Email address</span><a href="mailto:<?= esc(
                    $client["email"],
                ) ?>"><?= esc(
    $client["email"],
) ?></a><small>Send an email ↗</small></article>
                <article><span>Mobile number</span><a href="tel:<?= esc(
                    $phoneHref,
                ) ?>"><?= esc(
    $client["mobile"],
) ?></a><small>Call this client ↗</small></article>
                <article class="profile-address"><span>Address</span><p><?= nl2br(
                    esc($client["address"]),
                ) ?></p></article>
            </div>
            <div class="client-profile-footer">
                <span>Last updated <?= date(
                    "d M Y, h:i A",
                    strtotime($client["updated_at"]),
                ) ?></span>
                <form method="post" action="<?= base_url(
                    "admin/clients/" . $client["id"] . "/delete",
                ) ?>" onsubmit="return confirm('Permanently delete <?= esc(
    addslashes($fullName),
) ?>? This cannot be undone.')">
                    <?= csrf_field() ?>
                    <button type="submit">Delete client</button>
                </form>
            </div>
        </section>
    </main>
</body>
</html>
