<?= $this->extend('layouts/enterprise') ?>

<?= $this->section('content') ?>

<?php
$statusPill = static function (string $status): string {
    $class = $status === 'active' ? 'active' : 'inactive';
    return '<span class="enterprise-status-pill enterprise-status-pill--' . esc($class) . '">' . esc(ucfirst($status)) . '</span>';
};
?>

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'    => 'Accounting',
    'workspaceCrumbCurrent' => 'Cash Account',
    'workspaceTitle'        => $account['code'] . ' — ' . $account['name'],
    'workspaceDesc'         => 'Cash account detail.',
    'workspaceAction'       => [
        'href'  => base_url('accounting/cash-accounts/' . $account['id'] . '/edit'),
        'label' => 'Edit',
        'icon'  => 'fa-solid fa-pen',
    ],
]) ?>

<article class="enterprise-settings-card" style="max-width:720px;">
    <div class="enterprise-settings-card__head">
        <i class="fa-solid fa-money-bill-wave"></i>
        <h2 class="enterprise-settings-card__title">Cash Account Details</h2>
    </div>
    <div class="enterprise-settings-card__body p-4">
        <dl class="row mb-0">
            <dt class="col-sm-4 text-muted">Code</dt>
            <dd class="col-sm-8"><code><?= esc($account['code']) ?></code></dd>
            <dt class="col-sm-4 text-muted">Name</dt>
            <dd class="col-sm-8"><?= esc($account['name']) ?></dd>
            <dt class="col-sm-4 text-muted">Currency</dt>
            <dd class="col-sm-8"><?= esc($account['currency']) ?></dd>
            <dt class="col-sm-4 text-muted">GL Account</dt>
            <dd class="col-sm-8">
                <?php if (! empty($account['account_code'])): ?>
                    <code><?= esc($account['account_code']) ?></code> <?= esc($account['account_name'] ?? '') ?>
                <?php else: ?>
                    —
                <?php endif; ?>
            </dd>
            <dt class="col-sm-4 text-muted">Opening Balance</dt>
            <dd class="col-sm-8"><?= number_format((float) $account['opening_balance'], 2) ?></dd>
            <dt class="col-sm-4 text-muted">Balance</dt>
            <dd class="col-sm-8"><?= number_format((float) $balance, 2) ?></dd>
            <dt class="col-sm-4 text-muted">Status</dt>
            <dd class="col-sm-8"><?= $statusPill($account['status']) ?></dd>
            <dt class="col-sm-4 text-muted">Notes</dt>
            <dd class="col-sm-8"><?= esc($account['notes'] ?: '—') ?></dd>
        </dl>
    </div>
    <div class="enterprise-settings-card__footer">
        <a href="<?= base_url('accounting/cash-accounts') ?>" class="btn btn-outline-secondary">Back</a>
        <a href="<?= base_url('accounting/cash-accounts/' . $account['id'] . '/edit') ?>" class="btn btn-primary">Edit</a>
    </div>
</article>

<?= $this->endSection() ?>
