@extends('layouts.yellow')

@section('title', 'Detalles del Proveedor')

@section('content')
    <div class="container-fluid inventory-container">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1><i class="fas fa-truck"></i> Detalles del Proveedor</h1>
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                    <li class="breadcrumb-item"><a href="{{ route('inventory.index') }}">Inventario</a></li>
                    <li class="breadcrumb-item"><a href="{{ route('inventory.suppliers.index') }}">Proveedores</a></li>
                    <li class="breadcrumb-item active">{{ $supplier->name }}</li>
                </ol>
            </div>
        </div>

        <!-- Acciones rápidas -->
        <div class="row mb-3">
            <div class="col-md-12">
                <a href="{{ route('inventory.suppliers.edit', $supplier) }}" class="btn-inventory btn-inventory-warning">
                    <i class="fas fa-edit"></i> Editar Proveedor
                </a>
                <a href="{{ route('inventory.suppliers.index') }}" class="btn-inventory btn-inventory-primary">
                    <i class="fas fa-arrow-left"></i> Volver al Listado
                </a>
                <button type="button" class="btn-inventory btn-inventory-danger" data-toggle="modal" data-target="#deleteModal">
                    <i class="fas fa-trash"></i> Eliminar Proveedor
                </button>
            </div>
        </div>

        <!-- Información del proveedor -->
        <div class="row">
            <div class="col-md-6">
                <div class="inventory-card">
                    <div class="card-header">
                        <h3 class="card-title">Información General</h3>
                    </div>
                    <div class="card-body">
                        <table class="inventory-table">
                            <tr>
                                <th style="width: 30%">ID</th>
                                <td>{{ $supplier->id }}</td>
                            </tr>
                            <tr>
                                <th>Nombre</th>
                                <td>{{ $supplier->name }}</td>
                            </tr>
                            <tr>
                                <th>Empresa</th>
                                <td>{{ $supplier->company_name ?? 'No disponible' }}</td>
                            </tr>
                            <tr>
                                <th>NIT/RUC</th>
                                <td>{{ $supplier->tax_id ?? 'No disponible' }}</td>
                            </tr>
                            <tr>
                                <th>Email</th>
                                <td>
                                    @if($supplier->email)
                                        <a href="mailto:{{ $supplier->email }}">{{ $supplier->email }}</a>
                                    @else
                                        <span class="text-muted">No disponible</span>
                                    @endif
                                </td>
                            </tr>
                            <tr>
                                <th>Teléfono</th>
                                <td>{{ $supplier->phone ?? 'No disponible' }}</td>
                            </tr>
                            <tr>
                                <th>Estado</th>
                                <td>
                                    @if($supplier->is_active)
                                        <span class="badge-inventory badge-inventory-success">Activo</span>
                                    @else
                                        <span class="badge-inventory badge-inventory-danger">Inactivo</span>
                                    @endif
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>

            <div class="col-md-6">
                <div class="inventory-card">
                    <div class="card-header">
                        <h3 class="card-title">Dirección e Información de Contacto</h3>
                    </div>
                    <div class="card-body">
                        <table class="inventory-table">
                            <tr>
                                <th style="width: 30%">Dirección</th>
                                <td>{{ $supplier->address ?? 'No disponible' }}</td>
                            </tr>
                            <tr>
                                <th>Ciudad</th>
                                <td>{{ $supplier->city ?? 'No disponible' }}</td>
                            </tr>
                            <tr>
                                <th>Departamento/Estado</th>
                                <td>{{ $supplier->state ?? 'No disponible' }}</td>
                            </tr>
                            <tr>
                                <th>Código Postal</th>
                                <td>{{ $supplier->postal_code ?? 'No disponible' }}</td>
                            </tr>
                            <tr>
                                <th>País</th>
                                <td>{{ $supplier->country ?? 'No disponible' }}</td>
                            </tr>
                            <tr>
                                <th>Sitio Web</th>
                                <td>
                                    @if($supplier->website)
                                        <a href="{{ $supplier->website }}" target="_blank">{{ $supplier->website }}</a>
                                    @else
                                        <span class="text-muted">No disponible</span>
                                    @endif
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <!-- Información de contacto adicional -->
        <div class="inventory-card mt-4">
            <div class="card-header">
                <h3 class="card-title">Información de Contacto Adicional</h3>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label>Persona de Contacto:</label>
                            <p>{{ $supplier->contact_person ?? 'No especificado' }}</p>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label>Teléfono de Contacto:</label>
                            <p>{{ $supplier->contact_phone ?? 'No especificado' }}</p>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label>Email de Contacto:</label>
                            <p>
                                @if($supplier->contact_email)
                                    <a href="mailto:{{ $supplier->contact_email }}">{{ $supplier->contact_email }}</a>
                                @else
                                    No especificado
                                @endif
                            </p>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label>Notas:</label>
                            <p>{{ $supplier->notes ?? 'Sin notas adicionales' }}</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Productos de este proveedor -->
        <div class="inventory-card mt-4">
            <div class="card-header">
                <h3 class="card-title">Productos de este Proveedor</h3>
                <div class="card-tools">
                    <a href="{{ route('inventory.suppliers.items', $supplier) }}" class="btn-inventory btn-inventory-info btn-sm">
                        Ver Todos los Productos
                    </a>
                </div>
            </div>
            <div class="card-body">
                @if(isset($inventoryItems) && count($inventoryItems) > 0)
                    <div class="table-responsive">
                        <table class="inventory-table">
                            <thead>
                                <tr>
                                    <th>Nombre</th>
                                    <th>Categoría</th>
                                    <th>Stock</th>
                                    <th>Precio</th>
                                    <th>Estado</th>
                                    <th>Acciones</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($inventoryItems as $item)
                                    <tr>
                                        <td>{{ $item->name }}</td>
                                        <td>{{ $item->category->name ?? 'Sin categoría' }}</td>
                                        <td>
                                            @if($item->quantity <= $item->min_stock && $item->min_stock > 0)
                                                <span class="badge-inventory badge-inventory-danger">{{ $item->quantity }}</span>
                                            @else
                                                <span class="badge-inventory badge-inventory-success">{{ $item->quantity }}</span>
                                            @endif
                                        </td>
                                        <td>{{ $item->unit_price ? '$' . number_format($item->unit_price, 2) : 'No disponible' }}</td>
                                        <td>
                                            @if($item->status == 'active')
                                                <span class="badge-inventory badge-inventory-success">Activo</span>
                                            @elseif($item->status == 'inactive')
                                                <span class="badge-inventory badge-inventory-danger">Inactivo</span>
                                            @else
                                                <span class="badge-inventory badge-inventory-warning">Mantenimiento</span>
                                            @endif
                                        </td>
                                        <td>
                                            <a href="{{ route('inventory.show', $item) }}" class="btn-inventory btn-inventory-info btn-sm">
                                                <i class="fas fa-eye"></i>
                                            </a>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="low-stock-alert mb-0">
                        <i class="fas fa-info-circle"></i> No hay productos asociados a este proveedor.
                    </div>
                @endif
            </div>
        </div>

        <!-- Modal de confirmación de eliminación -->
        <div class="modal fade inventory-modal" id="deleteModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Confirmar eliminación</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        ¿Estás seguro de que deseas eliminar al proveedor <strong>{{ $supplier->name }}</strong>?
                        
                        @if(isset($inventoryItems) && count($inventoryItems) > 0)
                            <div class="low-stock-alert mt-3">
                                <i class="fas fa-exclamation-triangle"></i>
                                Este proveedor tiene {{ count($inventoryItems) }} productos asociados.
                                No se puede eliminar un proveedor con productos asociados.
                            </div>
                        @endif
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn-inventory btn-inventory-secondary" data-dismiss="modal">Cancelar</button>
                        <form action="{{ route('inventory.suppliers.destroy', $supplier) }}" method="POST">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn-inventory btn-inventory-danger" {{ (isset($inventoryItems) && count($inventoryItems) > 0) ? 'disabled' : '' }}>
                                Eliminar
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection 