<div>
    <x-layouts.app title="{{ __('Suppliers') }}">
        <!-- Page Header -->
        <div class="page-header d-flex justify-content-between align-items-center">
            <div>
                <h1 class="page-title">{{ __('Suppliers') }}</h1>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">{{ __('Dashboard') }}</a></li>
                        <li class="breadcrumb-item active">{{ __('Suppliers') }}</li>
                    </ol>
                </nav>
            </div>
            <div>
                <a href="{{ route('suppliers.create') }}" class="btn btn-primary">
                    <i class="fas fa-plus me-1"></i>{{ __('Add Supplier') }}
                </a>
            </div>
        </div>

        <!-- Filters -->
        <div class="card mb-4">
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-md-6">
                        <div class="input-group">
                            <span class="input-group-text"><i class="fas fa-search"></i></span>
                            <input type="text" class="form-control" 
                                   wire:model.live.debounce.300ms="search" 
                                   placeholder="{{ __('Search suppliers...') }}">
                        </div>
                    </div>
                    <div class="col-md-3">
                        <select class="form-select" wire:model.live="statusFilter">
                            <option value="">{{ __('All Status') }}</option>
                            <option value="active">{{ __('Active') }}</option>
                            <option value="inactive">{{ __('Inactive') }}</option>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <select class="form-select" wire:model.live="perPage">
                            <option value="15">15 {{ __('per page') }}</option>
                            <option value="25">25 {{ __('per page') }}</option>
                            <option value="50">50 {{ __('per page') }}</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        <!-- Suppliers Table -->
        <div class="card">
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-hover mb-0">
                        <thead>
                            <tr>
                                <th wire:click="sortBy('company_name')" style="cursor: pointer;">
                                    {{ __('Company') }}
                                    @if($sortField === 'company_name')
                                        <i class="fas fa-sort-{{ $sortDirection === 'asc' ? 'up' : 'down' }} ms-1"></i>
                                    @endif
                                </th>
                                <th>{{ __('Contact') }}</th>
                                <th>{{ __('Phone') }}</th>
                                <th>{{ __('Email') }}</th>
                                <th class="text-center">{{ __('Orders') }}</th>
                                <th class="text-center">{{ __('Status') }}</th>
                                <th style="width: 120px;" class="text-center">{{ __('Actions') }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($suppliers as $supplier)
                                <tr>
                                    <td>
                                        <div class="d-flex align-items-center">
                                            <div class="avatar-sm bg-info text-white rounded d-flex align-items-center justify-content-center me-2">
                                                <i class="fas fa-building"></i>
                                            </div>
                                            <div>
                                                <span class="fw-medium">{{ $supplier->company_name }}</span>
                                                @if($supplier->tax_number)
                                                    <br><small class="text-muted">{{ __('Tax') }}: {{ $supplier->tax_number }}</small>
                                                @endif
                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        {{ $supplier->contact_name ?? '-' }}
                                    </td>
                                    <td>
                                        <a href="tel:{{ $supplier->phone }}" class="text-decoration-none">
                                            {{ $supplier->phone }}
                                        </a>
                                    </td>
                                    <td>
                                        @if($supplier->email)
                                            <a href="mailto:{{ $supplier->email }}" class="text-decoration-none">
                                                {{ $supplier->email }}
                                            </a>
                                        @else
                                            <span class="text-muted">-</span>
                                        @endif
                                    </td>
                                    <td class="text-center">
                                        <span class="badge bg-secondary">{{ $supplier->purchase_orders_count }}</span>
                                    </td>
                                    <td class="text-center">
                                        @if($supplier->is_active)
                                            <span class="badge bg-success">{{ __('Active') }}</span>
                                        @else
                                            <span class="badge bg-secondary">{{ __('Inactive') }}</span>
                                        @endif
                                    </td>
                                    <td class="text-center">
                                        <div class="btn-group btn-group-sm">
                                            <a href="{{ route('suppliers.edit', $supplier) }}" class="btn btn-outline-primary">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                            <button type="button" class="btn btn-outline-danger" 
                                                    wire:click="confirmDelete({{ $supplier->id }})">
                                                <i class="fas fa-trash"></i>
                                            </button>
                                        </div>
                                    </td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="7" class="text-center py-5">
                                        <i class="fas fa-truck fa-3x text-muted mb-3"></i>
                                        <p class="text-muted mb-0">{{ __('No suppliers found.') }}</p>
                                        <a href="{{ route('suppliers.create') }}" class="btn btn-primary btn-sm mt-3">
                                            <i class="fas fa-plus me-1"></i>{{ __('Add First Supplier') }}
                                        </a>
                                    </td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
            @if($suppliers->hasPages())
                <div class="card-footer">
                    {{ $suppliers->links() }}
                </div>
            @endif
        </div>

        <!-- Delete Modal -->
        @if($showDeleteModal)
            <div class="modal fade show d-block" tabindex="-1" style="background: rgba(0,0,0,0.5);">
                <div class="modal-dialog modal-dialog-centered">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">{{ __('Confirm Delete') }}</h5>
                            <button type="button" class="btn-close" wire:click="cancelDelete"></button>
                        </div>
                        <div class="modal-body">
                            <p class="mb-0">{{ __('Are you sure you want to delete this supplier?') }}</p>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" wire:click="cancelDelete">{{ __('Cancel') }}</button>
                            <button type="button" class="btn btn-danger" wire:click="delete">
                                <i class="fas fa-trash me-1"></i>{{ __('Delete') }}
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        @endif
    </x-layouts.app>
</div>
