@extends('layouts.yellow')

@section('content')
<style>
  :root {
    --azul-primario: #2A4E6D;
    --azul-secundario: #3B6EA5;
    --azul-destacado: #4A90E2;
    --azul-suave: #E3F2FD;
    --degradado-azul: linear-gradient(135deg, #4A90E2 0%, #2A4E6D 100%);
    --amarillo-primario: #FFD54F;
    --amarillo-secundario: #FFECB3;
    --naranja-destacado: #FF9800;
    --verde-exito: #4CAF50;
    --rojo-error: #F44336;
    --gris-claro: #F5F7FA;
    --gris-medio: #E1E5E9;
    --gris-oscuro: #6C757D;
    --borde-principal: #D0D7DE;
    --sombra-suave: 0 4px 12px rgba(0, 0, 0, 0.05);
    --sombra-media: 0 6px 16px rgba(0, 0, 0, 0.08);
    --sombra-hover: 0 8px 24px rgba(0, 0, 0, 0.12);
    --transicion: all 0.3s ease;
    --fuente-principal: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  }

  /* Contenedor principal */
  .budgets-container {
    font-family: var(--fuente-principal);
    color: #333;
    line-height: 1.6;
    animation: fadeIn 0.5s ease-out;
  }

  @keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* Tarjeta principal */
  .budgets-card {
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--sombra-media);
    margin-bottom: 2rem;
  }

  /* Cabecera */
  .budgets-header {
    background: var(--degradado-azul);
    color: white;
    padding: 1.5rem 2rem;
    position: relative;
    overflow: hidden;
  }

  .budgets-header::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 150px;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    clip-path: polygon(100% 0, 0 0, 100% 100%);
  }

  .budgets-header h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
  }

  .budgets-header h3 i {
    margin-right: 10px;
  }

  .budgets-body {
    padding: 2rem;
  }

  /* Botón de nuevo presupuesto */
  .btn-add {
    background: white;
    color: var(--azul-primario);
    border: none;
    padding: 10px 20px;
    border-radius: 50px;
    font-weight: 600;
    transition: var(--transicion);
    display: inline-flex;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  }

  .btn-add:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    background: white;
    color: var(--azul-destacado);
  }

  .btn-add i {
    margin-right: 8px;
    font-size: 1.1em;
  }

  /* Tabla de presupuestos */
  .budgets-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--sombra-suave);
  }

  .budgets-table thead {
    background: var(--azul-suave);
  }

  .budgets-table th {
    color: var(--azul-primario);
    font-weight: 600;
    padding: 16px;
    text-align: left;
    border: none;
    font-size: 0.95rem;
  }

  .budgets-table td {
    padding: 16px;
    border-top: 1px solid var(--gris-medio);
    vertical-align: middle;
  }

  .budgets-table tr {
    background-color: #fff;
    transition: var(--transicion);
  }

  .budgets-table tbody tr:hover {
    background-color: var(--gris-claro);
    transform: translateY(-2px);
    box-shadow: var(--sombra-suave);
  }

  /* Estados (badges) */
  .badge {
    padding: 6px 12px;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
    text-align: center;
  }

  .bg-secondary {
    background-color: var(--gris-oscuro) !important;
    color: white;
  }

  .bg-info {
    background-color: var(--azul-destacado) !important;
    color: white;
  }

  .bg-success {
    background-color: var(--verde-exito) !important;
    color: white;
  }

  .bg-danger {
    background-color: var(--rojo-error) !important;
    color: white;
  }

  /* Botones de acción */
  .action-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transicion);
    border: none;
    margin-right: 5px;
    box-shadow: var(--sombra-suave);
    cursor: pointer;
  }

  .action-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--sombra-hover);
  }

  .action-btn i {
    font-size: 0.9rem;
  }

  .btn-info {
    background: var(--azul-destacado);
    color: white;
  }

  .btn-info:hover {
    background: var(--azul-secundario);
  }

  .btn-warning {
    background: var(--amarillo-primario);
    color: #333;
  }

  .btn-warning:hover {
    background: var(--amarillo-secundario);
  }

  .btn-primary {
    background: var(--azul-destacado);
    color: white;
  }

  .btn-primary:hover {
    background: var(--azul-secundario);
  }

  .btn-danger {
    background: var(--rojo-error);
    color: white;
  }

  .btn-danger:hover {
    background: #d32f2f;
  }

  /* Mensaje de éxito */
  .alert-success {
    background-color: rgba(76, 175, 80, 0.1);
    border-left: 4px solid var(--verde-exito);
    color: #2e7d32;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 0;
  }

  /* Sin resultados */
  .no-results {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--gris-oscuro);
  }

  .no-results i {
    font-size: 3rem;
    color: var(--gris-medio);
    margin-bottom: 1rem;
    display: block;
  }

  .no-results h4 {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--azul-primario);
  }

  /* Responsive */
  @media (max-width: 767px) {
    .budgets-header {
      padding: 1.2rem;
    }
    
    .budgets-body {
      padding: 1.2rem;
    }
    
    .budgets-table {
      display: block;
      overflow-x: auto;
      white-space: nowrap;
    }
    
    .budgets-table td, 
    .budgets-table th {
      padding: 12px;
    }
    
    .action-btn {
      width: 32px;
      height: 32px;
    }
  }
</style>

<div class="container budgets-container">
  <div class="budgets-card">
    <div class="budgets-header">
      <div class="d-flex justify-content-between align-items-center">
        <h3><i class="fas fa-file-invoice-dollar"></i> {{ __('Presupuestos') }}</h3>
        @if(Auth::user()->isAbleTo('create-budget'))
        <a href="{{ route('budgets.create') }}" class="btn-add">
          <i class="fas fa-plus-circle"></i> Nuevo Presupuesto
        </a>
        @endif
      </div>
    </div>

    <div class="budgets-body">
      @if (session('success'))
        <div class="alert alert-success" role="alert">
          <i class="fas fa-check-circle me-2"></i> {{ session('success') }}
        </div>
      @endif

      <div class="table-responsive">
        <table class="budgets-table">
          <thead>
            <tr>
              <th width="10%">Código</th>
              <th width="20%">Paciente</th>
              <th width="15%">Total</th>
              <th width="10%">Estado</th>
              <th width="15%">Creado por</th>
              <th width="15%">Fecha</th>
              <th width="15%">Acciones</th>
            </tr>
          </thead>
          <tbody>
            @if(count($budgets) > 0)
              @foreach($budgets as $budget)
              <tr>
                <td><strong>{{ $budget->code }}</strong></td>
                <td>{{ $budget->patient->firstname }} {{ $budget->patient->lastname }}</td>
                <td><strong>${{ number_format($budget->total, 2) }}</strong></td>
                <td>
                  @switch($budget->status)
                    @case('draft')
                      <span class="badge bg-secondary">Borrador</span>
                      @break
                    @case('sent')
                      <span class="badge bg-info">Enviado</span>
                      @break
                    @case('approved')
                      <span class="badge bg-success">Aprobado</span>
                      @break
                    @case('rejected')
                      <span class="badge bg-danger">Rechazado</span>
                      @break
                  @endswitch
                </td>
                <td>{{ $budget->creator->name }}</td>
                <td>{{ $budget->created_at->format('d/m/Y H:i') }}</td>
                <td>
                  <div class="d-flex">
                    <a href="{{ route('budgets.show', $budget) }}" 
                       class="action-btn btn-info" 
                       title="Ver detalles">
                      <i class="fas fa-eye"></i>
                    </a>
                    
                    @if($budget->status === 'draft')
                      @if(Auth::user()->isAbleTo('edit-budget'))
                      <a href="{{ route('budgets.edit', $budget) }}" 
                         class="action-btn btn-warning" 
                         title="Editar">
                        <i class="fas fa-edit"></i>
                      </a>
                      @endif
                      
                      @if(Auth::user()->isAbleTo('send-budget'))
                      <form action="{{ route('budgets.send', $budget) }}" 
                            method="POST" 
                            class="d-inline">
                        @csrf
                        <button type="submit" 
                                class="action-btn btn-primary" 
                                title="Enviar por correo"
                                onclick="return confirm('¿Está seguro de enviar este presupuesto?')">
                          <i class="fas fa-envelope"></i>
                        </button>
                      </form>
                      @endif
                    @endif
                    
                    @if(Auth::user()->isAbleTo('delete-budget'))
                    <form action="{{ route('budgets.destroy', $budget) }}" 
                          method="POST" 
                          class="d-inline">
                      @csrf
                      @method('DELETE')
                      <button type="submit" 
                              class="action-btn btn-danger" 
                              title="Eliminar"
                              onclick="return confirm('¿Está seguro de eliminar este presupuesto?')">
                        <i class="fas fa-trash"></i>
                      </button>
                    </form>
                    @endif
                  </div>
                </td>
              </tr>
              @endforeach
            @else
              <tr>
                <td colspan="7">
                  <div class="no-results">
                    <i class="fas fa-folder-open"></i>
                    <h4>No hay presupuestos disponibles</h4>
                    <p>Crea un nuevo presupuesto haciendo clic en "Nuevo Presupuesto"</p>
                  </div>
                </td>
              </tr>
            @endif
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
@endsection 