<?php
$pageTitle = htmlspecialchars($client['company_name'] ?? 'Client Profile');
$breadcrumb = [
    ['label' => 'Clients', 'url' => APP_URL . '/clients'],
    ['label' => $pageTitle, 'url' => null]
];
ob_start();
?>
<div class="mb-6 flex flex-col md:flex-row md:items-center justify-between">
    <div class="flex items-center gap-4">
        <h1 class="text-2xl font-bold text-gray-900"><?= $pageTitle ?></h1>
        <span class="px-3 py-1 text-xs font-semibold rounded-full bg-gray-200 text-gray-700"><?= htmlspecialchars($client['client_code'] ?? '') ?></span>
    </div>
    <div class="mt-4 md:mt-0 flex gap-2">
        <a href="<?= APP_URL ?>/clients/<?= $client['id'] ?>/edit" class="bg-gray-100 hover:bg-gray-200 text-gray-800 border border-gray-300 font-bold py-2 px-4 rounded shadow">Edit</a>
    </div>
</div>

<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
    <div class="bg-white rounded-lg shadow p-6">
        <h3 class="text-lg font-medium text-gray-900 mb-4 border-b pb-2">Company Information</h3>
        <dl class="grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-4">
            <div>
                <dt class="text-sm font-medium text-gray-500">Industry</dt>
                <dd class="mt-1 text-sm text-gray-900"><?= htmlspecialchars($client['industry'] ?? '-') ?></dd>
            </div>
            <div>
                <dt class="text-sm font-medium text-gray-500">TIN</dt>
                <dd class="mt-1 text-sm text-gray-900"><?= htmlspecialchars($client['tin'] ?? '-') ?></dd>
            </div>
            <div>
                <dt class="text-sm font-medium text-gray-500">Phone</dt>
                <dd class="mt-1 text-sm text-gray-900"><?= htmlspecialchars($client['phone'] ?? '-') ?></dd>
            </div>
            <div>
                <dt class="text-sm font-medium text-gray-500">Email</dt>
                <dd class="mt-1 text-sm text-gray-900"><?= htmlspecialchars($client['email'] ?? '-') ?></dd>
            </div>
            <div class="sm:col-span-2">
                <dt class="text-sm font-medium text-gray-500">Address</dt>
                <dd class="mt-1 text-sm text-gray-900"><?= htmlspecialchars($client['address'] ?? '-') ?></dd>
            </div>
        </dl>
    </div>
    <div class="bg-gray-50 rounded-lg p-6 border border-gray-200">
        <h3 class="text-lg font-medium text-gray-900 mb-4 border-b pb-2">Contact Person</h3>
        <dl class="grid grid-cols-1 gap-y-4">
            <div>
                <dt class="text-sm font-medium text-gray-500">Name</dt>
                <dd class="mt-1 text-sm text-gray-900"><?= htmlspecialchars($client['contact_name'] ?? '-') ?></dd>
            </div>
            <div>
                <dt class="text-sm font-medium text-gray-500">Phone</dt>
                <dd class="mt-1 text-sm text-gray-900"><?= htmlspecialchars($client['contact_phone'] ?? '-') ?></dd>
            </div>
            <div>
                <dt class="text-sm font-medium text-gray-500">Email</dt>
                <dd class="mt-1 text-sm text-gray-900"><?= htmlspecialchars($client['contact_email'] ?? '-') ?></dd>
            </div>
        </dl>
    </div>
</div>

<div class="bg-white rounded-lg shadow mt-8">
    <div class="px-6 py-4 border-b border-gray-200">
        <h3 class="text-lg font-medium text-gray-900">Projects</h3>
    </div>
    <table class="min-w-full divide-y divide-gray-200">
        <thead class="bg-gray-50">
            <tr>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Project Name</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Value</th>
            </tr>
        </thead>
        <tbody class="bg-white divide-y divide-gray-200">
            <?php if (empty($client['projects'])): ?>
            <tr><td colspan="3" class="px-6 py-4 text-center text-gray-500">No projects yet.</td></tr>
            <?php else: ?>
                <?php foreach ($client['projects'] as $p): ?>
                <tr>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-[#0A3A6B]"><a href="<?= APP_URL ?>/projects/<?= $p['id'] ?>"><?= htmlspecialchars($p['name']) ?></a></td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?= htmlspecialchars(ucfirst($p['status'] ?? '')) ?></td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900"><?= formatCurrency((float)($p['project_value'] ?? 0), $p['currency'] ?? DEFAULT_CURRENCY) ?></td>
                </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
</div>
<?php
$content = ob_get_clean();
require ROOT_PATH . '/modules/shared/views/layouts/main.php';
?>
