<?= $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>';
};
$typeLabel = match ($company['customer_type'] ?? null) {
    'product' => 'Product based',
    'service' => 'Service based',
    'project' => 'Project based',
    default   => '—',
};
?>

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'    => 'Sales & CRM',
    'workspaceCrumbCurrent' => 'Company #' . $company['id'],
    'workspaceTitle'        => esc($company['name']),
    'workspaceDesc'         => 'Read-only company profile. Manage this customer in Contracts.',
]) ?>

<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">Company 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($company['name']) ?></dd>
                <dt class="col-sm-4 text-muted">Code</dt>
                <dd class="col-sm-8"><?= $company['code'] ? '<code>' . esc($company['code']) . '</code>' : '—' ?></dd>
                <dt class="col-sm-4 text-muted">Type</dt>
                <dd class="col-sm-8"><?= esc($typeLabel) ?></dd>
                <dt class="col-sm-4 text-muted">One-time</dt>
                <dd class="col-sm-8"><?= ! empty($company['is_one_time']) ? 'Yes' : 'No' ?></dd>
                <dt class="col-sm-4 text-muted">Group</dt>
                <dd class="col-sm-8"><?= esc($group['name'] ?? '—') ?></dd>
                <dt class="col-sm-4 text-muted">Industry</dt>
                <dd class="col-sm-8"><?= esc($company['industry'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Email</dt>
                <dd class="col-sm-8"><?= esc($company['email'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Phone</dt>
                <dd class="col-sm-8"><?= esc($company['phone'] ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Website</dt>
                <dd class="col-sm-8">
                    <?php if ($company['website']): ?>
                        <a href="<?= esc($company['website']) ?>" target="_blank" rel="noopener"><?= esc($company['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([$company['address'], $company['city'], $company['country']]))) ?: '—') ?></dd>
                <dt class="col-sm-4 text-muted">Status</dt>
                <dd class="col-sm-8"><?= $statusPill($company['status']) ?></dd>
                <dt class="col-sm-4 text-muted">Notes</dt>
                <dd class="col-sm-8"><?= esc($company['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('contracts/customers/' . $company['id']) ?>" class="btn btn-outline-primary btn-sm">
                    <i class="fa-solid fa-file-contract me-1"></i> Manage in Contracts
                </a>
                <a href="<?= base_url('sale/contacts/create?company_id=' . $company['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('sale/customer-history/create?company_id=' . $company['id']) ?>" class="btn btn-outline-secondary btn-sm">
                    <i class="fa-solid fa-clock-rotate-left me-1"></i> Log Event
                </a>
                <a href="<?= base_url('sale/customer-documents/create?company_id=' . $company['id']) ?>" class="btn btn-outline-secondary btn-sm">
                    <i class="fa-solid fa-file-arrow-up me-1"></i> Upload Document
                </a>
                <a href="<?= base_url('sale/companies') ?>" class="btn btn-outline-secondary btn-sm">Back to List</a>
            </div>
        </article>
    </div>
</div>

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