@extends('layouts.yellow')

@section('title', 'Transacciones de ' . $inventory->name)

@section('content')
    <div class="container-fluid inventory-container">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1><i class="fas fa-exchange-alt"></i> Transacciones de: {{ $inventory->name }}</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.show', $inventory) }}">{{ $inventory->name }}</a></li>
                    <li class="breadcrumb-item active">Transacciones</li>
                </ol>
            </div>
        </div>

        <!-- Información del producto -->
        <div class="row mb-3">
            <div class="col-md-12">
                <div class="inventory-card inventory-info-card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-3">
                                <p><strong>Nombre:</strong> {{ $inventory->name }}</p>
                            </div>
                            <div class="col-md-3">
                                <p><strong>Categoría:</strong> {{ $inventory->category->name ?? 'N/A' }}</p>
                            </div>
                            <div class="col-md-3">
                                <p><strong>Stock actual:</strong> 
                                    @if ($inventory->isLowStock())
                                        <span class="badge-inventory badge-inventory-danger">{{ $inventory->quantity }} (Bajo)</span>
                                    @elseif ($inventory->isOutOfStock())
                                        <span class="badge-inventory badge-inventory-danger">Agotado</span>
                                    @else
                                        <span class="badge-inventory badge-inventory-success">{{ $inventory->quantity }}</span>
                                    @endif
                                </p>
                            </div>
                            <div class="col-md-3">
                                <p><strong>Stock mínimo:</strong> {{ $inventory->min_stock ?? 'No establecido' }}</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Acciones rápidas -->
        <div class="row mb-3">
            <div class="col-md-12">
                <a href="{{ route('inventory.transactions.create') }}?inventory_id={{ $inventory->id }}" class="btn-inventory btn-inventory-success">
                    <i class="fas fa-plus"></i> Nueva Transacción
                </a>
                <a href="{{ route('inventory.show', $inventory) }}" class="btn-inventory btn-inventory-primary">
                    <i class="fas fa-box"></i> Ver Detalles del Producto
                </a>
                <a href="{{ route('inventory.transactions.index') }}" class="btn-inventory btn-inventory-secondary">
                    <i class="fas fa-list"></i> Todas las Transacciones
                </a>
            </div>
        </div>

        <!-- Listado de transacciones -->
        <div class="inventory-card">
            <div class="card-header">
                <h3 class="card-title">Historial de Transacciones</h3>
            </div>
            <div class="card-body">
                @if(count($transactions) > 0)
                    <div class="table-responsive">
                        <table class="inventory-table">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Fecha</th>
                                    <th>Tipo</th>
                                    <th>Usuario</th>
                                    <th>Cantidad</th>
                                    <th>Cantidad Anterior</th>
                                    <th>Nueva Cantidad</th>
                                    <th>Referencia</th>
                                    <th>Acciones</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($transactions as $transaction)
                                    <tr>
                                        <td>{{ $transaction->id }}</td>
                                        <td>{{ $transaction->created_at->format('d/m/Y H:i') }}</td>
                                        <td>
                                            @if($transaction->transaction_type == 'entry')
                                                <span class="badge-inventory badge-inventory-success">Entrada</span>
                                            @elseif($transaction->transaction_type == 'exit')
                                                <span class="badge-inventory badge-inventory-danger">Salida</span>
                                            @elseif($transaction->transaction_type == 'adjustment')
                                                <span class="badge-inventory badge-inventory-warning">Ajuste</span>
                                            @elseif($transaction->transaction_type == 'transfer')
                                                <span class="badge-inventory badge-inventory-info">Transferencia</span>
                                            @endif
                                        </td>
                                        <td>{{ $transaction->user->name ?? 'N/A' }}</td>
                                        <td class="text-right">{{ number_format($transaction->quantity, 2) }}</td>
                                        <td class="text-right">{{ number_format($transaction->previous_quantity, 2) }}</td>
                                        <td class="text-right">{{ number_format($transaction->new_quantity, 2) }}</td>
                                        <td>{{ $transaction->reference ?? 'N/A' }}</td>
                                        <td>
                                            <a href="{{ route('inventory.transactions.show', $transaction) }}" class="btn-inventory btn-inventory-info btn-sm">
                                                <i class="fas fa-eye"></i> Ver
                                            </a>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div class="d-flex justify-content-center mt-3">
                        {{ $transactions->links() }}
                    </div>
                @else
                    <div class="low-stock-alert">
                        <h5><i class="icon fas fa-info"></i> ¡No hay transacciones!</h5>
                        <p>No se encontraron transacciones para este producto.</p>
                    </div>
                @endif
            </div>
        </div>
    </div>
@endsection 