<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     
    @hotelSettings
    <title>Transaction History - {{ hotelName() }}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary-green: #1a936f;
            --dark-green: #114b5f;
        }
        
        body {
            background-color: #f8f9fa;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        .main-content {
            margin-left: 250px;
            margin-right: 250px;
            padding: 20px;
            margin-top: 70px;
        }
        
        .dashboard-card {
            border-radius: 12px;
            border: none;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        }
        
        .card-header {
            background: linear-gradient(90deg, var(--dark-green) 0%, var(--primary-green) 100%);
            color: white;
            border-radius: 12px 12px 0 0 !important;
            padding: 15px 25px;
        }
        
        .btn-primary {
            background-color: var(--primary-green);
            border-color: var(--primary-green);
        }
        
        .transaction-in { 
            background-color: #d4edda; 
            color: #155724; 
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 0.8rem;
            font-weight: 500;
        }
        
        .transaction-out { 
            background-color: #f8d7da; 
            color: #721c24; 
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 0.8rem;
            font-weight: 500;
        }
        
        .transaction-adjustment { 
            background-color: #fff3cd; 
            color: #856404; 
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 0.8rem;
            font-weight: 500;
        }
        
        @media (max-width: 768px) {
            .main-content {
                margin-left: 0;
                margin-top: 60px;
                padding: 15px;
            }
        }
    </style>
</head>
<body>
    <!-- Main Content -->
    <div class="main-content">
        <!-- Header -->
        <div class="row mb-4">
            <div class="col">
                <h2><i class="fas fa-history me-2"></i>Transaction History</h2>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="{{ route('inventory.index') }}">Inventory</a></li>
                        <li class="breadcrumb-item active" aria-current="page">Transactions</li>
                    </ol>
                </nav>
            </div>
        </div>

        <!-- Filters -->
        <div class="card dashboard-card mb-4">
            <div class="card-body">
                <form method="GET" action="{{ route('inventory.transactions') }}">
                    <div class="row g-3">
                        <div class="col-md-3">
                            <label class="form-label">Date From</label>
                            <input type="date" class="form-control" name="date_from" value="{{ request('date_from') }}">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Date To</label>
                            <input type="date" class="form-control" name="date_to" value="{{ request('date_to') }}">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">Type</label>
                            <select class="form-select" name="type">
                                <option value="">All Types</option>
                                <option value="in" {{ request('type') == 'in' ? 'selected' : '' }}>Stock In</option>
                                <option value="out" {{ request('type') == 'out' ? 'selected' : '' }}>Stock Out</option>
                                <option value="adjustment" {{ request('type') == 'adjustment' ? 'selected' : '' }}>Adjustment</option>
                                <option value="return" {{ request('type') == 'return' ? 'selected' : '' }}>Return / Exception</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label class="form-label">&nbsp;</label>
                            <div class="d-grid gap-2">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fas fa-filter me-2"></i>Filter
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <!-- Transactions Table -->
        <div class="card dashboard-card">
            <div class="card-header">
                <h5 class="m-0">
                    <i class="fas fa-exchange-alt me-2"></i>All Transactions
                </h5>
            </div>
            <div class="card-body">
                @if($transactions->isEmpty())
                    <div class="text-center py-5">
                        <i class="fas fa-history fa-4x text-muted mb-4"></i>
                        <h4>No Transactions Found</h4>
                        <p class="text-muted">Transaction history will appear here as inventory activities occur.</p>
                        <a href="{{ route('inventory.index') }}" class="btn btn-primary mt-3">
                            <i class="fas fa-arrow-left me-2"></i>Back to Inventory
                        </a>
                    </div>
                @else
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>Date</th>
                                    <th>Item</th>
                                    <th>Type</th>
                                    <th>Quantity Change</th>
                                    <th>Reference</th>
                                    <th>Performed By</th>
                                    <th>Notes</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($transactions as $transaction)
                                    <tr>
                                        <td>{{ optional($transaction->created_at)->format('M d, Y H:i') }}</td>
                                        <td>{{ $transaction->item->name ?? 'N/A' }}</td>
                                        <td>
                                            @if($transaction->movement_type == 'in')
                                                <span class="transaction-in">Stock In</span>
                                            @elseif($transaction->movement_type == 'out')
                                                <span class="transaction-out">Stock Out</span>
                                            @elseif($transaction->movement_type == 'return')
                                                <span class="badge bg-secondary">Return / Exception</span>
                                            @else
                                                <span class="transaction-adjustment">Adjustment</span>
                                            @endif
                                        </td>
                                        <td>
                                            @if($transaction->quantity_change > 0)
                                                <span class="text-success">+{{ $transaction->quantity_change }}</span>
                                            @else
                                                <span class="text-danger">{{ $transaction->quantity_change }}</span>
                                            @endif
                                        </td>
                                        <td>{{ $transaction->reference_number ?? 'N/A' }}</td>
                                        <td>{{ $transaction->performer->full_name ?? trim(($transaction->performer->first_name ?? '') . ' ' . ($transaction->performer->last_name ?? '')) ?: 'System' }}</td>
                                        <td>{{ $transaction->notes ?? '-' }}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    
                    <!-- Pagination -->
                    @if($transactions->hasPages())
                    <div class="d-flex justify-content-between align-items-center mt-4">
                        <div class="text-muted">
                            Showing {{ $transactions->firstItem() }} to {{ $transactions->lastItem() }} of {{ $transactions->total() }} transactions
                        </div>
                        <nav>
                            {{ $transactions->links() }}
                        </nav>
                    </div>
                    @endif
                @endif
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

<script src="{{ asset('js/theme-applier.js') }}"></script>
</body>
</html>

