@extends('layouts.app')
@section('title', 'Expenses')
@section('page-title', 'Expenses')

@section('content')

<div class="d-flex align-items-center justify-content-between mb-4">
    <div>
        <h5 class="fw-700 mb-0" style="color:#1e293b;">Expenses</h5>
        <small class="text-muted">Track your business spending</small>
    </div>
    <div class="d-flex gap-2">
        <a href="{{ route('expenses.summary') }}" class="btn btn-sm btn-outline-secondary fw-500">
            <i class="bi bi-pie-chart me-1"></i>Summary
        </a>
        <a href="{{ route('expenses.create') }}" class="btn fw-600" style="background:#00a651;color:white;">
            <i class="bi bi-plus-lg me-2"></i>Add Expense
        </a>
    </div>
</div>

<div class="card table-card">
    @if($expenses->isEmpty())
        <div class="empty-state">
            <div class="empty-icon"><i class="bi bi-wallet2"></i></div>
            <h5>No expenses yet</h5>
            <p>Start tracking your business expenses to see profit/loss reports.</p>
            <a href="{{ route('expenses.create') }}" class="btn" style="background:#00a651;color:white;">
                <i class="bi bi-plus-lg me-2"></i>Add Expense
            </a>
        </div>
    @else
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Category</th>
                        <th>Description</th>
                        <th class="text-end">Amount</th>
                        <th style="width:100px;"></th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($expenses as $expense)
                    <tr>
                        <td class="text-muted small">{{ $expense->date->format('d/m/Y') }}</td>
                        <td>
                            <span class="badge rounded-pill"
                                  style="background:#f1f5f9;color:#374151;font-size:0.75rem;font-weight:500;">
                                {{ $expense->category_label }}
                            </span>
                        </td>
                        <td class="text-muted small">{{ $expense->description ?? '—' }}</td>
                        <td class="text-end fw-600" style="color:#1e293b;">
                            ₦{{ number_format($expense->amount, 2) }}
                        </td>
                        <td>
                            <div class="d-flex gap-1 justify-content-end">
                                <a href="{{ route('expenses.edit', $expense) }}"
                                   class="btn btn-sm btn-light" title="Edit">
                                    <i class="bi bi-pencil"></i>
                                </a>
                                <form method="POST" action="{{ route('expenses.destroy', $expense) }}">
                                    @csrf @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-light text-danger"
                                            onclick="return confirm('Delete this expense?')">
                                        <i class="bi bi-trash3"></i>
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
                <tfoot>
                    <tr style="background:#f8fafc;">
                        <td colspan="3" class="fw-700 text-end" style="color:#1e293b;">Total</td>
                        <td class="text-end fw-700" style="color:#dc2626;">
                            ₦{{ number_format($expenses->sum('amount'), 2) }}
                        </td>
                        <td></td>
                    </tr>
                </tfoot>
            </table>
        </div>
        @if($expenses->hasPages())
            <div class="p-3 border-top">{{ $expenses->links() }}</div>
        @endif
    @endif
</div>
@endsection
