<?= $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' => 'Account',
    'workspaceTitle'        => $account['code'] . ' — ' . $account['name'],
    'workspaceDesc'         => 'Chart of accounts detail.',
    'workspaceAction'       => [
        'href'  => base_url('accounting/chart-of-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-sitemap"></i>
        <h2 class="enterprise-settings-card__title">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">Type</dt>
            <dd class="col-sm-8"><?= esc(ucfirst($account['type'])) ?></dd>
            <dt class="col-sm-4 text-muted">Parent</dt>
            <dd class="col-sm-8"><?= $parent ? esc($parent['code'] . ' — ' . $parent['name']) : '—' ?></dd>
            <dt class="col-sm-4 text-muted">Postable</dt>
            <dd class="col-sm-8"><?= ! empty($account['is_postable']) ? 'Yes' : 'No' ?></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">Description</dt>
            <dd class="col-sm-8"><?= esc($account['description'] ?: '—') ?></dd>
        </dl>
    </div>
    <div class="enterprise-settings-card__footer">
        <a href="<?= base_url('accounting/chart-of-accounts') ?>" class="btn btn-outline-secondary">Back</a>
        <a href="<?= base_url('accounting/reports/general-ledger?account_id=' . $account['id']) ?>" class="btn btn-primary">View Ledger</a>
    </div>
</article>

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