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

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

<?php
$statusPill = static function (string $status): string {
    $label = ucwords(str_replace('_', ' ', $status));
    if ($status === 'active') {
        $class = 'active';
    } elseif ($status === 'disposed') {
        $class = 'inactive';
    } elseif ($status === 'fully_depreciated') {
        $class = 'draft';
    } else {
        $class = 'default';
    }
    return '<span class="enterprise-status-pill enterprise-status-pill--' . esc($class) . '">' . esc($label) . '</span>';
};
$st = $asset['status'];
?>

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'    => 'Accounting',
    'workspaceCrumbCurrent' => 'Fixed Asset',
    'workspaceTitle'        => $asset['number'],
    'workspaceDesc'         => $asset['name'] . (! empty($asset['category_name']) ? ' · ' . $asset['category_name'] : ''),
]) ?>

<article class="enterprise-settings-card mb-4">
    <div class="enterprise-settings-card__head">
        <i class="fa-solid fa-building"></i>
        <h2 class="enterprise-settings-card__title">Asset Summary</h2>
    </div>
    <div class="p-4">
        <dl class="row mb-0">
            <dt class="col-sm-3 text-muted">Number</dt>
            <dd class="col-sm-3"><code><?= esc($asset['number']) ?></code></dd>
            <dt class="col-sm-3 text-muted">Status</dt>
            <dd class="col-sm-3"><?= $statusPill($st) ?></dd>
            <dt class="col-sm-3 text-muted">Name</dt>
            <dd class="col-sm-3"><?= esc($asset['name']) ?></dd>
            <dt class="col-sm-3 text-muted">Category</dt>
            <dd class="col-sm-3"><?= esc($asset['category_name'] ?? '—') ?></dd>
            <dt class="col-sm-3 text-muted">Purchase Date</dt>
            <dd class="col-sm-3"><?= esc($asset['purchase_date']) ?></dd>
            <dt class="col-sm-3 text-muted">In-Service Date</dt>
            <dd class="col-sm-3"><?= esc($asset['in_service_date'] ?: '—') ?></dd>
            <dt class="col-sm-3 text-muted">Cost</dt>
            <dd class="col-sm-3"><?= number_format((float) $asset['cost'], 2) ?></dd>
            <dt class="col-sm-3 text-muted">Salvage Value</dt>
            <dd class="col-sm-3"><?= number_format((float) $asset['salvage_value'], 2) ?></dd>
            <dt class="col-sm-3 text-muted">Accum. Depreciation</dt>
            <dd class="col-sm-3"><?= number_format((float) $asset['accum_depreciation'], 2) ?></dd>
            <dt class="col-sm-3 text-muted">Book Value</dt>
            <dd class="col-sm-3"><?= number_format((float) $asset['book_value'], 2) ?></dd>
            <dt class="col-sm-3 text-muted">Useful Life</dt>
            <dd class="col-sm-3"><?= $asset['useful_life_months'] ? (int) $asset['useful_life_months'] . ' months' : '—' ?></dd>
            <dt class="col-sm-3 text-muted">Location</dt>
            <dd class="col-sm-3"><?= esc($asset['location'] ?: '—') ?></dd>
            <dt class="col-sm-3 text-muted">Notes</dt>
            <dd class="col-sm-9"><?= esc($asset['notes'] ?: '—') ?></dd>
        </dl>
    </div>
    <div class="enterprise-settings-card__footer gap-2">
        <a href="<?= base_url('accounting/fixed-assets') ?>" class="btn btn-outline-secondary">Back</a>
        <?php if ($st === 'active'): ?>
            <a href="<?= base_url('accounting/fixed-assets/' . $asset['id'] . '/edit') ?>" class="btn btn-primary">Edit</a>
        <?php endif; ?>
    </div>
</article>

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