<x-admin-layout title="Companies">
    <div class="card">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h5 class="fw-bold mb-0">Companies</h5>
                <a href="{{ route('admin.companies.create') }}" class="btn btn-dark btn-sm">
                    <i class="bi bi-plus-lg me-1"></i>Add Company
                </a>
            </div>

            @if ($companies->isEmpty())
                <div class="text-center text-muted py-5">
                    <i class="bi bi-building fs-1 d-block mb-2"></i>
                    No companies yet.
                </div>
            @else
                <div class="table-responsive">
                    <table class="table align-middle datatable">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Code</th>
                                <th>Country</th>
                                <th>Currency</th>
                                <th>Status</th>
                                <th class="text-end">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($companies as $company)
                                <tr>
                                    <td>
                                        <div class="fw-semibold">{{ $company->name }}</div>
                                        <div class="text-muted small">{{ $company->contact_email }}</div>
                                    </td>
                                    <td><span class="badge bg-light text-dark border">{{ $company->code }}</span></td>
                                    <td>{{ $company->country->name ?? '—' }}</td>
                                    <td>{{ $company->currency?->code ?? '—' }}</td>
                                    <td>
                                        @if ($company->is_active)
                                            <span class="badge is-green">Active</span>
                                        @else
                                            <span class="badge is-rose">Inactive</span>
                                        @endif
                                    </td>
                                    <td class="text-end">
                                        <a href="{{ route('admin.companies.edit', $company) }}" class="btn btn-sm btn-outline-secondary">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        <form method="POST" action="{{ route('admin.companies.destroy', $company) }}" class="d-inline"
                                              data-confirm-title="Delete company?" data-confirm-text="Delete {{ $company->name }}? This cannot be undone."
                                              data-confirm-button="Delete">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
                                        </form>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            @endif
        </div>
    </div>
</x-admin-layout>
