<?php
$this->assign('title', 'Admin Dashboard');

$chevron = $this->element('ui_icon', ['name' => 'chevron_right', 'class' => 'h-4 w-4 shrink-0 transition-transform group-hover:translate-x-0.5']);
?>

<main class="min-h-screen pt-16 md:pt-20 pb-20 bg-neutral-50">
    <div class="max-w-7xl mx-auto px-6 lg:px-8">

        <div class="mb-12 text-center md:text-left">
            <h1 class="text-4xl md:text-5xl font-serif font-semibold text-neutral-900 tracking-tight">
                Welcome back, Admin
            </h1>
            <p class="mt-3 text-lg md:text-xl text-neutral-600">
                Here is what is happening with your academy today.
            </p>
        </div>

        <div class="bg-white/90 backdrop-blur-xl rounded-3xl shadow-lg shadow-neutral-900/5 border border-neutral-200/70 p-8 md:p-10 mb-12 hover:shadow-xl transition-shadow duration-300">
            <div class="flex flex-col md:flex-row gap-8 items-start">
                <div class="flex-1">
                    <div class="flex items-center gap-4 mb-6">
                        <div class="w-12 h-12 bg-primary-100 rounded-2xl flex items-center justify-center text-primary-600 ring-1 ring-primary-200/50">
                            <?= $this->element('ui_icon', ['name' => 'building_library', 'class' => 'h-7 w-7']) ?>
                        </div>
                        <div>
                            <h2 class="text-2xl md:text-3xl font-serif font-semibold text-neutral-900"><?= h($company->name ?? 'CandleCraft Academy') ?></h2>
                            <p class="text-neutral-500 text-sm">Core academy information</p>
                        </div>
                    </div>

                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-6 text-sm">
                        <div>
                            <span class="block text-neutral-500 mb-1">Contact Email</span>
                            <a href="mailto:<?= h($company->email ?? '') ?>" class="font-medium text-primary-600 hover:underline">
                                <?= h($company->email ?? 'Not set') ?>
                            </a>
                        </div>
                        <div>
                            <span class="block text-neutral-500 mb-1">Phone Number</span>
                            <p class="font-medium text-neutral-800"><?= h($company->phone ?? 'Not set') ?></p>
                        </div>
                        <div class="sm:col-span-2">
                            <span class="block text-neutral-500 mb-1">Address</span>
                            <p class="font-medium text-neutral-700"><?= h($company->address ?? 'Not set') ?></p>
                        </div>
                    </div>

                    <?php if (!empty($company->description)): ?>
                    <div class="mt-8 pt-8 border-t border-neutral-100">
                        <span class="block text-neutral-500 mb-2 text-sm">About the Academy</span>
                        <p class="text-neutral-600 leading-relaxed line-clamp-3">
                            <?= h($company->description) ?>
                        </p>
                    </div>
                    <?php endif; ?>
                </div>

                <div class="w-full md:w-auto md:text-right">
                    <?= $this->Html->link(
                        '<span class="inline-flex items-center justify-center gap-2">Edit company' . $chevron . '</span>',
                        ['action' => 'company'],
                        ['class' => 'inline-flex w-full md:w-auto items-center justify-center px-8 py-4 bg-primary-600 hover:bg-primary-700 text-white font-semibold rounded-2xl transition-all shadow-md hover:shadow-lg', 'escape' => false]
                    ) ?>
                </div>
            </div>
        </div>

        <div class="mb-6">
            <h3 class="text-xl md:text-2xl font-serif font-semibold text-neutral-800">Quick management</h3>
        </div>

        <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">

            <!-- Users -->
            <a href="<?= $this->Url->build(['controller' => 'Admin', 'action' => 'users']) ?>" class="group bg-white/90 backdrop-blur-xl rounded-3xl p-8 border border-neutral-200/70 hover:border-primary-200 hover:shadow-xl hover:shadow-primary-900/5 transition-all duration-300 flex flex-col">
                <div class="flex justify-between items-start mb-6">
                    <div class="flex h-14 w-14 items-center justify-center rounded-2xl bg-primary-50 text-primary-600 ring-1 ring-primary-100">
                        <?= $this->element('ui_icon', ['name' => 'users', 'class' => 'h-8 w-8']) ?>
                    </div>
                    <div class="text-right">
                        <div class="text-3xl font-bold text-primary-600 tabular-nums"><?= number_format($totalUsers ?? 0) ?></div>
                        <div class="text-[10px] font-semibold uppercase tracking-widest text-neutral-500">Users</div>
                    </div>
                </div>
                <h4 class="font-semibold text-lg text-neutral-900 group-hover:text-primary-700">Manage Users</h4>
                <p class="text-neutral-500 text-sm mt-2 flex-1">View, edit roles and delete accounts</p>
            </a>

            <!-- Teachers -->
            <a href="<?= $this->Url->build(['controller' => 'Admin', 'action' => 'teachers']) ?>" class="group bg-white/90 backdrop-blur-xl rounded-3xl p-8 border border-neutral-200/70 hover:border-primary-200 hover:shadow-xl transition-all flex flex-col">
                <div class="flex justify-between items-start mb-6">
                    <div class="flex h-14 w-14 items-center justify-center rounded-2xl bg-primary-50 text-primary-600">
                        <?= $this->element('ui_icon', ['name' => 'academic_cap', 'class' => 'h-8 w-8']) ?>
                    </div>
                    <div class="text-right">
                        <div class="text-3xl font-bold text-primary-600"><?= number_format($totalTeachers ?? 0) ?></div>
                        <div class="text-xs text-neutral-500">Teachers</div>
                    </div>
                </div>
                <h4 class="font-semibold text-lg">Manage Teachers</h4>
                <p class="text-neutral-500 text-sm mt-2 flex-1">Add, edit instructors</p>
            </a>

            <!-- Lessons -->
            <a href="<?= $this->Url->build(['controller' => 'Admin', 'action' => 'lessons']) ?>" class="group bg-white/90 backdrop-blur-xl rounded-3xl p-8 border hover:shadow-xl transition-all flex flex-col">
                <div class="flex justify-between mb-6">
                    <div class="h-14 w-14 flex items-center justify-center rounded-2xl bg-primary-50 text-primary-600">
                        <?= $this->element('ui_icon', ['name' => 'book_open', 'class' => 'h-8 w-8']) ?>
                    </div>
                    <div class="text-right">
                        <div class="text-3xl font-bold text-primary-600"><?= number_format($totalLessons ?? 0) ?></div>
                        <div class="text-xs text-neutral-500">Lessons</div>
                    </div>
                </div>
                <h4 class="font-semibold text-lg">Manage Lessons</h4>
                <p class="text-neutral-500 text-sm mt-2 flex-1">Workshops and pricing</p>
            </a>

            <!-- Materials -->
            <a href="<?= $this->Url->build(['controller' => 'Admin', 'action' => 'materials']) ?>" class="group bg-white/90 backdrop-blur-xl rounded-3xl p-8 border hover:shadow-xl transition-all flex flex-col">
                <div class="mb-6">
                    <div class="h-14 w-14 flex items-center justify-center rounded-2xl bg-primary-50 text-primary-600">
                        <?= $this->element('ui_icon', ['name' => 'cube', 'class' => 'h-8 w-8']) ?>
                    </div>
                </div>
                <h4 class="font-semibold text-lg">Manage Materials</h4>
                <p class="text-neutral-500 text-sm mt-2 flex-1">Supplies and requirements</p>
            </a>

            <!-- Bookings -->
            <a href="<?= $this->Url->build(['controller' => 'Admin', 'action' => 'bookings']) ?>" class="group bg-white/90 backdrop-blur-xl rounded-3xl p-8 border hover:shadow-xl transition-all flex flex-col">
                <div class="flex justify-between mb-6">
                    <div class="h-14 w-14 flex items-center justify-center rounded-2xl bg-primary-50 text-primary-600">
                        <?= $this->element('ui_icon', ['name' => 'calendar_days', 'class' => 'h-8 w-8']) ?>
                    </div>
                    <div class="text-right">
                        <div class="text-3xl font-bold text-amber-600"><?= number_format($pendingBookings ?? 0) ?></div>
                        <div class="text-xs text-neutral-500">Pending</div>
                    </div>
                </div>
                <h4 class="font-semibold text-lg">Manage Bookings</h4>
                <p class="text-neutral-500 text-sm mt-2 flex-1">Approve or reject</p>
            </a>

            <!-- Enquiries -->
            <a href="<?= $this->Url->build(['controller' => 'Admin', 'action' => 'enquiries']) ?>" class="group bg-white/90 backdrop-blur-xl rounded-3xl p-8 border hover:shadow-xl transition-all flex flex-col">
                <div class="flex justify-between mb-6">
                    <div class="h-14 w-14 flex items-center justify-center rounded-2xl bg-primary-50 text-primary-600">
                        <?= $this->element('ui_icon', ['name' => 'envelope', 'class' => 'h-8 w-8']) ?>
                    </div>
                    <div class="text-right">
                        <div class="text-3xl font-bold text-amber-600"><?= number_format($pendingEnquiries ?? 0) ?></div>
                        <div class="text-xs text-neutral-500">Pending</div>
                    </div>
                </div>
                <h4 class="font-semibold text-lg">Customer Enquiries</h4>
                <p class="text-neutral-500 text-sm mt-2 flex-1">Respond to messages</p>
            </a>

            <!-- FAQs -->
            <a href="<?= $this->Url->build(['controller' => 'Admin', 'action' => 'faqs']) ?>" class="group bg-white/90 backdrop-blur-xl rounded-3xl p-8 border hover:shadow-xl transition-all flex flex-col">
                <div class="mb-6">
                    <div class="h-14 w-14 flex items-center justify-center rounded-2xl bg-primary-50 text-primary-600">
                        <?= $this->element('ui_icon', ['name' => 'question_mark_circle', 'class' => 'h-8 w-8']) ?>
                    </div>
                </div>
                <h4 class="font-semibold text-lg">Manage FAQs</h4>
                <p class="text-neutral-500 text-sm mt-2 flex-1">Common questions</p>
            </a>

            <!-- Company -->
            <a href="<?= $this->Url->build(['controller' => 'Admin', 'action' => 'company']) ?>" class="group bg-white/90 backdrop-blur-xl rounded-3xl p-8 border hover:shadow-xl transition-all flex flex-col">
                <div class="mb-6">
                    <div class="h-14 w-14 flex items-center justify-center rounded-2xl bg-primary-50 text-primary-600">
                        <?= $this->element('ui_icon', ['name' => 'building_office_2', 'class' => 'h-8 w-8']) ?>
                    </div>
                </div>
                <h4 class="font-semibold text-lg">Company Settings</h4>
                <p class="text-neutral-500 text-sm mt-2 flex-1">Update info</p>
            </a>

        </div>

        <div class="mt-16 grid grid-cols-1 md:grid-cols-3 gap-6">
            <div class="bg-white/80 backdrop-blur rounded-3xl p-8 border border-neutral-200/60 shadow-sm">
                <p class="text-neutral-500 text-sm font-medium">Total Enquiries</p>
                <p class="text-4xl font-bold text-neutral-800 mt-2 tabular-nums"><?= number_format($totalEnquiries ?? 0) ?></p>
            </div>
            <div class="bg-white/80 backdrop-blur rounded-3xl p-8 border border-neutral-200/60 shadow-sm">
                <p class="text-neutral-500 text-sm font-medium">Pending Tasks</p>
                <p class="text-4xl font-bold text-amber-600 mt-2 tabular-nums"><?= number_format($pending ?? 0) ?></p>
            </div>
            <div class="bg-white/80 backdrop-blur rounded-3xl p-8 border border-neutral-200/60 shadow-sm">
                <p class="text-neutral-500 text-sm font-medium">Last Updated</p>
                <p class="text-xl font-medium text-neutral-700 mt-2"><?= date('d M Y · H:i') ?></p>
            </div>
        </div>

    </div>
</main>
