<?= $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'    => 'Inventory',
    'workspaceCrumbCurrent' => 'Product #' . $product['id'],
    'workspaceTitle'        => esc($product['name']),
    'workspaceDesc'         => 'Product profile and catalog details.',
]) ?>

<div class="row g-4">
    <div class="col-lg-8">
        <article class="enterprise-settings-card">
            <div class="enterprise-settings-card__head">
                <i class="fa-solid fa-box"></i>
                <h2 class="enterprise-settings-card__title">Product Information</h2>
            </div>
            <dl class="row mb-0 small">
                <dt class="col-sm-4 text-muted">Name</dt>
                <dd class="col-sm-8 fw-semibold"><?= esc($product['name']) ?></dd>
                <dt class="col-sm-4 text-muted">SKU</dt>
                <dd class="col-sm-8"><code><?= esc($product['sku']) ?></code></dd>
                <dt class="col-sm-4 text-muted">Barcode</dt>
                <dd class="col-sm-8"><?= esc($product['barcode'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Category</dt>
                <dd class="col-sm-8"><?= esc($product['category_name'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Brand</dt>
                <dd class="col-sm-8"><?= esc($product['brand_name'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Unit</dt>
                <dd class="col-sm-8"><?= esc($product['unit_name'] ? $product['unit_name'] . ' (' . $product['unit_code'] . ')' : '—') ?></dd>
                <dt class="col-sm-4 text-muted">Cost Price</dt>
                <dd class="col-sm-8"><?= number_format((float) $product['cost_price'], 2) ?></dd>
                <dt class="col-sm-4 text-muted">Sale Price</dt>
                <dd class="col-sm-8"><?= number_format((float) $product['sale_price'], 2) ?></dd>
                <dt class="col-sm-4 text-muted">Reorder Level</dt>
                <dd class="col-sm-8"><?= number_format((float) $product['reorder_level'], 3) ?></dd>
                <dt class="col-sm-4 text-muted">Status</dt>
                <dd class="col-sm-8"><?= $statusPill($product['status']) ?></dd>
                <dt class="col-sm-4 text-muted">Description</dt>
                <dd class="col-sm-8"><?= esc($product['description'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Notes</dt>
                <dd class="col-sm-8"><?= esc($product['notes'] ?: '—') ?></dd>
            </dl>
        </article>
    </div>

    <div class="col-lg-4">
        <article class="enterprise-settings-card">
            <div class="enterprise-settings-card__head">
                <i class="fa-solid fa-bolt"></i>
                <h2 class="enterprise-settings-card__title">Actions</h2>
            </div>
            <div class="d-grid gap-2">
                <a href="<?= base_url('inventory/products/' . $product['id'] . '/edit') ?>" class="btn btn-outline-primary btn-sm">
                    <i class="fa-solid fa-pen me-1"></i> Edit Product
                </a>
                <a href="<?= base_url('inventory/stock?q=' . urlencode($product['sku'])) ?>" class="btn btn-outline-secondary btn-sm">
                    <i class="fa-solid fa-cubes me-1"></i> View Stock
                </a>
                <a href="<?= base_url('inventory/products') ?>" class="btn btn-outline-secondary btn-sm">Back to List</a>
            </div>
        </article>
    </div>
</div>

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