@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 */
  .services-container {
    font-family: var(--fuente-principal);
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--sombra-media);
    max-width: 1400px;
    margin: 0 auto;
    overflow: hidden;
    animation: fadeIn 0.5s ease-out;
  }

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

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

  .services-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%);
  }

  .services-header h3 {
    margin: 0;
    font-weight: 600;
    display: flex;
    align-items: center;
  }

  .services-header h3 i {
    margin-right: 10px;
    font-size: 1.2em;
  }

  .services-body {
    padding: 2rem;
  }

  /* Botones */
  .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 servicios */
  .services-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--sombra-suave);
  }

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

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

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

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

  .services-table tbody tr:hover {
    background-color: var(--gris-claro);
    transform: scale(1.005);
  }

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

  .badge-success {
    background-color: rgba(76, 175, 80, 0.2);
    color: var(--verde-exito);
    border: 1px solid rgba(76, 175, 80, 0.3);
  }

  .badge-danger {
    background-color: rgba(244, 67, 54, 0.2);
    color: var(--rojo-error);
    border: 1px solid rgba(244, 67, 54, 0.3);
  }

  /* Botones de acción */
  .action-btn {
    width: 38px;
    height: 38px;
    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);
  }

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

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

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

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

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

  .action-btn-delete: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;
  }

  /* Responsive */
  @media (max-width: 767px) {
    .services-container {
      border-radius: 0;
      box-shadow: none;
    }
    
    .services-header, .services-body {
      padding: 1.2rem;
    }
    
    .services-table {
      display: block;
      overflow-x: auto;
      white-space: nowrap;
    }
    
    .services-table td, .services-table th {
      padding: 10px;
    }
    
    .action-btn {
      width: 34px;
      height: 34px;
    }
  }
</style>

<div class="container-fluid">
  <div class="services-container">
    <div class="services-header">
      <div class="d-flex justify-content-between align-items-center">
        <h3><i class="fas fa-heartbeat"></i> Servicios Médicos</h3>
        @if (Auth::user()->isAbleTo('create-medicalServices'))
        <a href="{{ route('/admin/create-medical-services') }}" class="btn-add">
          <i class="fas fa-plus-circle"></i> Nuevo Servicio
        </a>
        @endif
      </div>
    </div>
    
    <div class="services-body">
      @if(session('success'))
        <div class="alert alert-success">
          <i class="fas fa-check-circle me-2"></i> {{ session('success') }}
        </div>
      @endif

      <div class="table-responsive">
        <table class="services-table">
          <thead>
            <tr>
              <th style="width: 15%">ID</th>
              <th style="width: 15%">Nombre</th>
              <th style="width: 25%">Descripción</th>
              <th style="width: 12%">Costo</th>
              <th style="width: 10%">Moneda</th>
              <th style="width: 10%">Estado</th>
              <th style="width: 13%">Acciones</th>
            </tr>
          </thead>
          <tbody>
            @foreach($services as $service)
              <tr>
                <td>
                  <span class="text-muted" title="{{ $service->id }}">
                    {{ substr($service->id, 0, 8) }}...
                  </span>
                </td>
                <td><strong>{{ $service->name }}</strong></td>
                <td>
                  {{ $service->description ? substr($service->description, 0, 60) . (strlen($service->description) > 60 ? '...' : '') : 'Sin descripción' }}
                </td>
                <td><strong>{{ number_format($service->cost, 2) }}</strong></td>
                <td>{{ strtoupper($service->currency->title) }}</td>
                <td>
                  <span class="badge {{ $service->is_active ? 'badge-success' : 'badge-danger' }}">
                    {{ $service->is_active ? 'Activo' : 'Inactivo' }}
                  </span>
                </td>
                <td>
                  @if (Auth::user()->isAbleTo('create-medicalServices'))
                  <div class="d-flex">
                    <a href="{{ route('/admin/edit-medical-services', $service) }}" class="action-btn action-btn-edit" title="Editar">
                      <i class="fas fa-pen"></i>
                    </a>
                  @endif
                  @if (Auth::user()->isAbleTo('create-medicalServices'))
                    <form action="{{ route('/admin/delete-medical-services') }}" method="POST" class="d-inline">
                      @csrf
                      <input type="hidden" name="id" value="{{ $service->id }}">
                      <button type="submit" class="action-btn action-btn-delete" title="Eliminar" 
                              onclick="return confirm('¿Está seguro de eliminar este servicio?')">
                        <i class="fas fa-trash"></i>
                      </button>
                    </form>
                  @endif
                    </div>
                </td>
              </tr>
            @endforeach
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
@endsection 