<?= $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'    => 'Procurement',
    'workspaceCrumbCurrent' => 'Supplier #' . $supplier['id'],
    'workspaceTitle'        => esc($supplier['name']),
    'workspaceDesc'         => 'Supplier profile and purchasing actions.',
]) ?>

<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-building"></i>
                <h2 class="enterprise-settings-card__title">Supplier 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($supplier['name']) ?></dd>
                <dt class="col-sm-4 text-muted">Code</dt>
                <dd class="col-sm-8"><?= $supplier['code'] ? '<code>' . esc($supplier['code']) . '</code>' : '—' ?></dd>
                <dt class="col-sm-4 text-muted">Email</dt>
                <dd class="col-sm-8"><?= esc($supplier['email'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Phone</dt>
                <dd class="col-sm-8"><?= esc($supplier['phone'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Website</dt>
                <dd class="col-sm-8">
                    <?php if ($supplier['website']): ?>
                        <a href="<?= esc($supplier['website']) ?>" target="_blank" rel="noopener"><?= esc($supplier['website']) ?></a>
                    <?php else: ?>
                        —
                    <?php endif; ?>
                </dd>
                <dt class="col-sm-4 text-muted">Address</dt>
                <dd class="col-sm-8"><?= esc(trim(implode(', ', array_filter([$supplier['address'], $supplier['city'], $supplier['country']]))) ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Status</dt>
                <dd class="col-sm-8"><?= $statusPill($supplier['status']) ?></dd>
                <dt class="col-sm-4 text-muted">Notes</dt>
                <dd class="col-sm-8"><?= esc($supplier['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('procurement/suppliers/' . $supplier['id'] . '/edit') ?>" class="btn btn-outline-primary btn-sm">
                    <i class="fa-solid fa-pen me-1"></i> Edit Supplier
                </a>
                <a href="<?= base_url('procurement/supplier-contacts/create?supplier_id=' . $supplier['id']) ?>" class="btn btn-outline-secondary btn-sm">
                    <i class="fa-solid fa-user-plus me-1"></i> Add Contact
                </a>
                <a href="<?= base_url('procurement/suppliers') ?>" class="btn btn-outline-secondary btn-sm">Back to List</a>
            </div>
        </article>
    </div>
</div>

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