@extends('layouts.app')

@section('title', 'Corporate CRM Directory')

@section('content')
<div class="space-y-6">
    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
        <div>
            <h1 class="text-xl font-bold text-slate-900 dark:text-white">Corporate CRM Directory</h1>
            <p class="text-xs text-slate-500">Corporate clients, companies, free zones, mainland entities, and establishment cards.</p>
        </div>
        <a href="{{ route('app.corporate.companies.create') }}" class="px-4 py-2 bg-sky-600 hover:bg-sky-700 text-white font-bold text-xs rounded-xl shadow-sm">+ Add Corporate Company</a>
    </div>

    <!-- Corporate Directory Table (Requirements 40-45) -->
    <div class="bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700/60 shadow-sm overflow-hidden text-xs">
        <div class="overflow-x-auto">
            <table class="w-full text-left rtl:text-right">
                <thead class="bg-slate-50 dark:bg-slate-900/60 border-b border-slate-200 dark:border-slate-700 text-slate-500 uppercase tracking-wider font-bold">
                    <tr>
                        <th class="px-6 py-4">Company Code</th>
                        <th class="px-6 py-4">Company Name</th>
                        <th class="px-6 py-4">Trade License #</th>
                        <th class="px-6 py-4">Employees</th>
                        <th class="px-6 py-4">Credit Terms</th>
                        <th class="px-6 py-4">Status</th>
                        <th class="px-6 py-4 text-right rtl:text-left">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-200 dark:divide-slate-700/60 font-medium">
                    @foreach($companies as $company)
                        <tr class="hover:bg-slate-50 dark:hover:bg-slate-700/30">
                            <td class="px-6 py-4 font-mono font-bold text-sky-600 dark:text-sky-400">{{ $company->company_code }}</td>
                            <td class="px-6 py-4">
                                <div class="font-bold text-slate-900 dark:text-white">{{ $company->name_en }}</div>
                                <div class="text-[11px] text-slate-400 font-normal">{{ $company->legal_name }}</div>
                            </td>
                            <td class="px-6 py-4 font-mono text-slate-600 dark:text-slate-300 font-semibold">{{ $company->trade_license_number ?? 'N/A' }}</td>
                            <td class="px-6 py-4 font-bold text-sky-600">{{ $company->corporateEmployees->count() }} Employees</td>
                            <td class="px-6 py-4 font-mono">AED {{ number_format($company->credit_limit, 2) }} ({{ $company->credit_days }} Days)</td>
                            <td class="px-6 py-4">
                                <span class="px-2.5 py-0.5 rounded-full bg-emerald-100 text-emerald-700 font-bold text-[10px]">Active</span>
                            </td>
                            <td class="px-6 py-4 text-right rtl:text-left">
                                <a href="{{ route('app.corporate.companies.show', $company->id) }}" class="text-sky-600 font-bold hover:underline">Corporate 360</a>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div class="p-4 border-t border-slate-200 dark:border-slate-700">
            {{ $companies->links() }}
        </div>
    </div>
</div>
@endsection
