@extends('layouts.app')

@section('title', __('Companies'))

@section('content')
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="mb-0">{{ __('Companies') }}</h4>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb mb-0">
                    <li class="breadcrumb-item"><a href="{{ url('/') }}">{{ __('Dashboard') }}</a></li>
                    <li class="breadcrumb-item active">{{ __('Companies') }}</li>
                </ol>
            </nav>
        </div>
        <a href="{{ route('companies.create') }}" class="btn btn-primary px-4">
            <i class="bi bi-plus-lg me-2"></i> {{ __('Add Company') }}
        </a>
    </div>

    <!-- Quick Stats -->
    <div class="row g-4 mb-4">
        <div class="col-md-4">
            <div class="card border-0 shadow-sm p-4">
                <div class="d-flex align-items-center gap-3">
                    <div class="stat-icon bg-primary-subtle text-primary rounded-3 d-flex align-items-center justify-content-center" style="width: 48px; height: 48px;">
                        <i class="bi bi-buildings fs-4"></i>
                    </div>
                    <div>
                        <h6 class="text-muted mb-0 small">{{ __('Total Companies') }}</h6>
                        <h4 class="mb-0 fw-bold">{{ $companies->total() }}</h4>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card border-0 shadow-sm p-4">
                <div class="d-flex align-items-center gap-3">
                    <div class="stat-icon bg-success-subtle text-success rounded-3 d-flex align-items-center justify-content-center" style="width: 48px; height: 48px;">
                        <i class="bi bi-building-check fs-4"></i>
                    </div>
                    <div>
                        <h6 class="text-muted mb-0 small">{{ __('Active Entities') }}</h6>
                        <h4 class="mb-0 fw-bold">{{ $companies->where('status', 'active')->count() }}</h4>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card border-0 shadow-sm p-4">
                <div class="d-flex align-items-center gap-3">
                    <div class="stat-icon bg-info-subtle text-info rounded-3 d-flex align-items-center justify-content-center" style="width: 48px; height: 48px;">
                        <i class="bi bi-geo-alt fs-4"></i>
                    </div>
                    <div>
                        <h6 class="text-muted mb-0 small">{{ __('Involved Nodes') }}</h6>
                        <h4 class="mb-0 fw-bold">384+</h4>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card border-0 shadow-sm">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="ps-4">{{ __('Company Name') }}</th>
                            <th>{{ __('Address') }}</th>
                            <th>{{ __('VAT Number') }}</th>
                            <th>{{ __('Status') }}</th>
                            <th class="text-end pe-4">{{ __('Actions') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($companies as $company)
                            <tr>
                                <td class="ps-4">
                                    <div class="d-flex align-items-center gap-3">
                                        <div class="avatar bg-primary-subtle text-primary rounded d-flex align-items-center justify-content-center"
                                            style="width: 40px; height: 40px;">
                                            {{ substr($company->name, 0, 1) }}
                                        </div>
                                        <span class="fw-semibold">{{ $company->name }}</span>
                                    </div>
                                </td>
                                <td>{{ $company->address ?? '-' }}</td>
                                <td>{{ $company->vat_number ?? '-' }}</td>
                                <td>
                                    @if($company->status == 'active')
                                        <span
                                            class="badge bg-success-subtle text-success border border-success-subtle">{{ __('Active') }}</span>
                                    @else
                                        <span
                                            class="badge bg-secondary-subtle text-secondary border border-secondary-subtle">{{ __('Inactive') }}</span>
                                    @endif
                                </td>
                                <td class="text-end pe-4">
                                    <div class="dropdown">
                                        <button class="btn btn-light btn-sm rounded-circle" data-bs-toggle="dropdown">
                                            <i class="bi bi-three-dots-vertical"></i>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-end shadow-sm border-0">
                                            <li><a class="dropdown-item" href="{{ route('companies.edit', $company->id) }}"><i
                                                        class="bi bi-pencil me-2"></i> {{ __('Edit') }}</a></li>
                                            <li><a class="dropdown-item" href="{{ route('companies.show', $company->id) }}"><i
                                                        class="bi bi-eye me-2"></i> {{ __('View') }}</a></li>
                                            <li>
                                                <hr class="dropdown-divider">
                                            </li>
                                            <li>
                                                <form action="{{ route('companies.destroy', $company->id) }}" method="POST"
                                                    onsubmit="return confirm('{{ __('Are you sure?') }}')">
                                                    @csrf
                                                    @method('DELETE')
                                                    <button type="submit" class="dropdown-item text-danger"><i
                                                            class="bi bi-trash me-2"></i> {{ __('Delete') }}</button>
                                                </form>
                                            </li>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="5" class="text-center py-5 text-muted">{{ __('No companies found.') }}</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
        @if($companies->hasPages())
            <div class="card-footer bg-transparent border-top-0">
                {{ $companies->links() }}
            </div>
        @endif
    </div>
@endsection