<!DOCTYPE html>
<html lang="es">

<head>
  <meta charset="UTF-8">
  <title>Inicio</title>
  <meta name="csrf-token" content="{{ csrf_token() }}">
  <script src="https://cdn.tailwindcss.com"></script>
  <style>
    .dropdown {
      position: relative;
    }

    .dropdown-panel {
      position: absolute;
      left: 0;
      right: 0;
      top: 100%;
      z-index: 50;
    }

    /* Decorativos: cuadros redondeados azules y naranja */
    .bg-decor {
      position: absolute;
      inset: 0;
      pointer-events: none;
      overflow: hidden;
      z-index: 0;
    }

    .bg-decor .sq {
      position: absolute;
      border-radius: 22px;
      filter: saturate(1.1);
      opacity: .12;
    }

    .bg-decor .sq-blue {
      background: #2155CD;
    }

    .bg-decor .sq-orange {
      background: #FF7F0E;
    }

    /* Logo en el header */
    .brand {
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .brand .logo {
      width: 36px;
      height: 36px;
      border-radius: 10px;
      overflow: hidden;
      background: #fff;
      display: grid;
      place-items: center;
    }

    .brand .logo img {
      width: 100%;
      height: 100%;
      object-fit: contain;
      display: block;
    }
  </style>
</head>

<body class="bg-gray-100">



  <div class="area">
    <header class="app-header">
      <div class="inner">
        <div class="brand">
          <div class="logo">
            <img src="{{ asset('img/logo.png') }}" alt="Logo">
          </div>
          <h1 style="font-size:25px; font-weight:700;">Seguimiento contractual capitas</h1>
        </div>
        <div style="margin-left:auto; display:flex; gap:10px">
        </div>
      </div>
    </header>
    <ul class="circles">
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
    </ul>


      @if (session('status'))
        <div class="mb-4 rounded-lg border border-green-200 bg-green-50 text-green-800 p-3 flex items-start gap-3 shadow-sm">
          <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 mt-0.5 text-green-600" viewBox="0 0 20 20" fill="currentColor">
            <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.707a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 10-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
          </svg>
          <div>
            <div class="font-semibold">Acción completada</div>
            <div>{{ session('status') }}</div>
          </div>
        </div>
      @endif

      @if ($errors->any())
        <div class="p-3 rounded bg-red-50 text-red-700">
          <ul class="list-disc pl-4">
            @foreach ($errors->all() as $e)
              <li>{{ $e }}</li>
            @endforeach
          </ul>
        </div>
      @endif
      <div class="wrap">
        <h1 style="font-size:20px; font-weight:700; margin:0 0 16px;">Aplicativo Auditoria Capita > Home </h1>

        <div class="grid">

        
          <div class="col-left">

          {{-- === Seccion: Formularios (NIT â†’ sedes â†’ tipo) === --}}
          <section class="card">
            <h2 class="text-2xl font-bold mb-2 flex items-center gap-2">
              <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-indigo-700" viewBox="0 0 20 20"
                fill="currentColor">
                <path
                  d="M4 3a2 2 0 00-2 2v10a2 2 0 002 2h7.586A2 2 0 0013 16.586L16.586 13A2 2 0 0017 11.586V5a2 2 0 00-2-2H4z" />
              </svg>
              Formularios
            </h2>
            <p class="text-gray-600 mb-6">Selecciona NIT, sede y tipo.</p>

            <form id="formBuscar" class="space-y-5" method="POST" action="{{ route('buscar.sede') }}">
              @csrf

              {{-- hidden que viajan al back --}}
              <input type="hidden" id="hd_nit" name="nit" value="">
              <input type="hidden" id="hd_municipio" name="municipio_id" value="">
              <input type="hidden" id="hd_tipo" name="tipo_formulario" value="0">

              <div id="searchScope" data-url-nits="{{ route('api.nits') }}"
                data-url-sedes="{{ route('api.sedes.porNit') }}">

                {{-- NIT --}}
                <div class="dropdown">
                  <label for="nitInput" class="block text-sm font-medium mb-1">Buscar NIT</label>
                  <input id="nitInput" type="text" class="w-full border rounded px-3 py-2"
                    placeholder="Escribe NIT o nombre..." autocomplete="off" />
                  <div id="nitResults" class="dropdown-panel mt-1 bg-white border rounded shadow hidden"></div>
                  <div id="nitHint" class="text-sm mt-2 text-gray-600"></div>
                </div>

                {{-- Sede --}}
                <div>
                  <label for="municipio" class="block text-sm font-medium mb-1">Sede (Municipio)</label>
                  <select id="municipio" class="w-full border rounded px-3 py-2" disabled>
                    <option value="">Seleccione...</option>
                  </select>
                </div>

                <button id="btnContinuar" class="btn btn-accent">
                  Continuar
                </button>

              </div>
            </form>
          </section>
          {{-- === Seccion: Estadisticas y Repositorio documentos === --}}
          <section class="card">

            <h2 class="text-2xl font-bold mb-2">Estadi­sticas</h2>
            <p class="text-gray-600 mb-6">Accede a visualizaciones estadisticas.</p>
            <a href="{{ route('estadisticas.index') }}" class="btn btn-primary">
              Ir a Estadi­sticas
            </a>

            <h2 class="text-2xl font-bold mb-2">Repositorio documentos</h2>
            <p class="text-gray-600 mb-6">Accede a actas de seguimiento contractual</p>
            <a href="" class="btn btn-primary">
              Ir a actas
            </a>
            <a href="{{ route('formularios.htmls') }}" class="btn btn-ghost">HTMLs</a>
          </section>

          
          </div>

          {{-- === Seccion: Socializacion === --}}
          <section class="card">
            <h2 class="text-2xl font-bold mb-2">Socializacion</h2>
            <p class="text-gray-600 mb-4">Prestadores con formulario registrado.</p>

            @if ($formularios->isEmpty())
              <p class="text-sm text-gray-500">Aun no hay formularios disponibles.</p>
            @else
              <div class="border rounded-lg overflow-hidden">
                <div>
                  <table class="min-w-full text-sm">
                    <thead class="bg-gray-100 text-gray-700 uppercase text-xs">
                      <tr>
                        <th class="px-4 py-2 text-left">Prestador</th>
                        <th class="px-4 py-2 text-left">NIT</th>
                        <th class="px-4 py-2 text-left">Municipio</th>
                        <th class="px-4 py-2 text-left">Periodo</th>
                        <th class="px-4 py-2 text-left">Estado</th>
                        <th class="px-4 py-2 text-left">Guardado</th>
                        <th class="px-4 py-2"></th>
                      </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                      @foreach ($formularios as $formulario)
                        <tr class="hover:bg-gray-50">
                          <td class="px-4 py-2">{{ data_get($formulario->basicos, 'prestador') ?? 'Sin nombre' }}</td>
                          <td class="px-4 py-2">{{ $formulario->nit ?? data_get($formulario->basicos, 'nit') }}</td>
                          <td class="px-4 py-2">{{ $formulario->municipio ?? data_get($formulario->basicos, 'municipio') }}</td>
                          <td class="px-4 py-2">{{ data_get($formulario->basicos, 'periodo_evaluado') ?? data_get($formulario->ejecucion, 'periodo') ?? '-' }}</td>
                          <td class="px-4 py-2">{{ ucfirst($formulario->estado ?? '-') }}</td>
                          <td class="px-4 py-2">{{ optional($formulario->created_at)->format('d/m/Y H:i') }}</td>
                          <td class="px-4 py-2 text-right">
                            <a href="{{ route('formularios.revision', $formulario) }}" class="btn btn-ghost text-indigo-600">Revisar</a>
                          </td>
                        </tr>
                      @endforeach
                    </tbody>
                  </table>
                </div>
              </div>
            @endif
          </section>
        </div>
      </div>
  </div>





  @vite(['resources/css/home.css', 'resources/js/home-hub.js'])
  <script>
    document.addEventListener('DOMContentLoaded', function () {
      function addIcon(el, svg) { if (!el) return; el.classList.add('flex', 'items-center', 'gap-2'); el.insertAdjacentHTML('afterbegin', svg); }
      // Icono para botón Estadísticas
      try {
        const btnEst = document.querySelector("a[href*='estadisticas']");
        addIcon(btnEst, '<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" viewBox="0 0 20 20" fill="currentColor"><path d="M3 3a1 1 0 011-1h1v16H4a1 1 0 01-1-1V3zm4 6a1 1 0 011-1h1v10H8a1 1 0 01-1-1V9zm4-4a1 1 0 011-1h1v14h-1a1 1 0 01-1-1V5zm4 8a1 1 0 011-1h1v6h-1a1 1 0 01-1-1v-4z"/></svg>');
      } catch (e) { }
      // Icono para botón Actas (por texto)
      try {
        const links = Array.from(document.querySelectorAll('a.btn.btn-primary'));
        const btnActas = links.find(a => /actas/i.test(a.textContent || ''));
        addIcon(btnActas, '<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M5 2a2 2 0 00-2 2v12a2 2 0 002 2h8a2 2 0 002-2V7.414A2 2 0 0014.586 6L11 2.414A2 2 0 009.586 2H5zm5 2.414L14.586 9H11a1 1 0 01-1-1V4.414z" clip-rule="evenodd"/></svg>');
      } catch (e) { }
      // Icono para botón Continuar (Formularios)
      try {
        const btnCont = document.getElementById('btnContinuar');
        addIcon(btnCont, '<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" viewBox="0 0 20 20" fill="currentColor"><path d="M10.293 15.707a1 1 0 010-1.414L12.586 12H5a1 1 0 110-2h7.586l-2.293-2.293a1 1 0 111.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"/></svg>');
      } catch (e) { }
    });
  </script>
</body>

</html>
