<!doctype html>
<html lang="es">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Dashboard Profesional</title>
    <script>
        (function () {
            const root = document.documentElement;
            root.classList.add('sidebar-nav-pending');

            const releasePending = function () {
                root.classList.remove('sidebar-nav-pending');
            };

            const timeoutId = window.setTimeout(releasePending, 1200);

            if (document.querySelector('.admin-sidebar')) {
                window.clearTimeout(timeoutId);
                releasePending();
                return;
            }

            const observer = new MutationObserver(function () {
                if (!document.querySelector('.admin-sidebar')) {
                    return;
                }

                observer.disconnect();
                window.clearTimeout(timeoutId);
                releasePending();
            });

            observer.observe(document.documentElement, {
                childList: true,
                subtree: true,
            });
        })();
    </script>
    <style>
        @media (min-width: 992px) {
            html.sidebar-nav-pending main {
                visibility: hidden;
            }
        }
    </style>
    @vite(['resources/css/app.css', 'resources/js/app.js'])
    <style>
        #agenda-profesional {
            min-height: 620px;
            background: #fff;
            border: 1px solid rgba(0, 0, 0, 0.1);
            border-radius: 12px;
            padding: 0.5rem;
        }

        .agenda-resumen {
            background: #fff;
            border: 1px solid rgba(0, 0, 0, 0.1);
            border-radius: 12px;
        }

        .fc .fc-toolbar-title {
            font-size: 1.1rem;
        }

        .fc .fc-bg-event.evento-disponibilidad {
            opacity: 1 !important;
            background-color: rgba(25, 135, 84, 0.24) !important;
            border-color: rgba(25, 135, 84, 0.42) !important;
        }

        .fc .fc-bg-event.evento-feriado {
            opacity: 1 !important;
            background-color: rgba(220, 53, 69, 0.30) !important;
            border-color: rgba(220, 53, 69, 0.55) !important;
            color: #5b1f23 !important;
            font-weight: 600;
        }

        .fc .fc-bg-event.evento-receso,
        .fc .fc-bg-event.evento-vacaciones {
            opacity: 1 !important;
            background-color: rgba(220, 53, 69, 0.30) !important;
            border-color: rgba(220, 53, 69, 0.55) !important;
            color: #5b1f23 !important;
            font-weight: 600;
        }

        .fc .fc-bg-event.evento-feriado .fc-event-title,
        .fc .fc-bg-event.evento-feriado .fc-bg-event-title,
        .fc .fc-bg-event.evento-receso .fc-event-title,
        .fc .fc-bg-event.evento-receso .fc-bg-event-title,
        .fc .fc-bg-event.evento-vacaciones .fc-event-title,
        .fc .fc-bg-event.evento-vacaciones .fc-bg-event-title {
            color: #5b1f23 !important;
            opacity: 1;
        }

        .agenda-badge {
            display: inline-flex;
            align-items: center;
            gap: 0.35rem;
            padding: 0.45rem 0.7rem;
            border-radius: 999px;
            font-size: 0.85rem;
            font-weight: 600;
            border: 1px solid transparent;
        }

        .agenda-badge-hoy {
            background: #0d6efd;
            color: #fff;
            border-color: #0a58ca;
        }

        .agenda-badge-futuro {
            background: #e7f1ff;
            color: #0a58ca;
            border-color: #b6d4fe;
        }

        @media (max-width: 991.98px) {
            #agenda-profesional {
                min-height: 420px;
                padding: 0.25rem;
                overflow-x: auto;
            }

            .fc .fc-toolbar {
                flex-direction: column;
                align-items: stretch;
                gap: 0.5rem;
            }

            .fc .fc-toolbar-title {
                font-size: 1rem;
                text-align: center;
            }

            .fc .fc-button-group,
            .fc .fc-toolbar-chunk {
                display: flex;
                justify-content: center;
                flex-wrap: wrap;
                gap: 0.35rem;
            }

            .fc .fc-button {
                padding: 0.25rem 0.5rem;
                font-size: 0.8rem;
            }

            .fc .fc-col-header-cell-cushion,
            .fc .fc-timegrid-axis-cushion,
            .fc .fc-timegrid-slot-label-cushion {
                font-size: 0.75rem;
            }

            .agenda-resumen {
                margin-top: 0.5rem;
            }
        }

        @media (max-width: 575.98px) {
            .agenda-acciones {
                width: 100%;
                flex-direction: column;
                align-items: stretch !important;
            }

            .agenda-acciones .btn,
            .agenda-acciones .agenda-badge {
                width: 100%;
                justify-content: center;
            }

            .fc .fc-toolbar-title {
                font-size: 0.95rem;
            }
        }
    </style>
</head>
<body id="top" class="d-flex flex-column min-vh-100 bg-light">
    <header class="app-navbar">
        <nav class="navbar navbar-expand-lg">
            <div class="container">
                @php
                    $nombreSesion = trim((string) session('personal_nombre', 'Profesional'));
                    $nombreSaludo = $nombreSesion !== '' ? explode(' ', $nombreSesion)[0] : 'Profesional';
                @endphp
                <a class="navbar-brand d-flex align-items-center gap-2" href="/profesional/dashboard">
                    <div class="d-flex align-items-center justify-content-center" style="width: 130px; height: 52px;">
                        <img src="{{ asset('images/logo.png') }}" alt="Logo" class="img-fluid" style="max-height: 70px; width: auto; object-fit: contain;">
                    </div>
                    <span class="fw-semibold">¡Hola, {{ $nombreSaludo }}!</span>
                </a>

                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#menuPrincipal" aria-controls="menuPrincipal" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="menuPrincipal">
                    <ul class="navbar-nav mx-auto mb-2 mb-lg-0">
                        <li class="nav-item"><a class="btn app-navbar-link" href="/profesional/dashboard">Mi Agenda</a></li>
                        <li class="nav-item"><a class="btn app-navbar-link" href="/profesional/clientes">Mis Clientes</a></li>
                        <li class="nav-item"><a class="btn app-navbar-link" href="/profesional/mis-datos">Mis Datos</a></li>
                        <li class="nav-item">
                            <a class="btn app-navbar-link position-relative" href="/profesional/formularios">
                                Revisar Formularios
                                @if(($formulariosPendientesCount ?? 0) > 0)
                                    <span class="position-absolute top-0 start-100 translate-middle p-1 bg-danger rounded-circle">
                                        <span class="visually-hidden">Hay formularios pendientes</span>
                                    </span>
                                @endif
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="btn app-navbar-link position-relative" href="/profesional/notificaciones" data-notificaciones-claves='@json($notificacionesClaves ?? [])'>
                                Notificaciones
                                @if(($notificacionesCount ?? 0) > 0)
                                    <span class="position-absolute top-0 start-100 translate-middle p-1 bg-danger rounded-circle js-notificaciones-badge d-none">
                                        <span class="visually-hidden">Hay notificaciones</span>
                                    </span>
                                @endif
                            </a>
                        </li>
                    </ul>

                    <a class="btn app-navbar-link" href="/logout">Cerrar Sesion</a>
                </div>
            </div>
        </nav>
    </header>

    <main class="container py-4 flex-grow-1">
        @if(session('turno_directo_success'))
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                {{ session('turno_directo_success') }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Cerrar"></button>
            </div>
        @endif

        @if(session('turno_directo_error'))
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                {{ session('turno_directo_error') }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Cerrar"></button>
            </div>
        @endif

        @if(session('profesional_action_success'))
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                {{ session('profesional_action_success') }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Cerrar"></button>
            </div>
        @endif

        @if(session('profesional_action_error'))
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                {{ session('profesional_action_error') }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Cerrar"></button>
            </div>
        @endif

        @if($errors->any())
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <strong>Errores en el formulario:</strong>
                <ul class="mb-0 mt-1">
                    @foreach($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Cerrar"></button>
            </div>
        @endif

        <div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">
            <h1 class="h4 mb-0">Mi Agenda</h1>
            <div class="d-flex align-items-center gap-2 flex-wrap agenda-acciones">
                <a href="/profesional/configurar-agenda" class="btn btn-outline-secondary btn-sm">Configurar mi agenda</a>
                <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#modalAsignarTurno">Agendar un turno</button>
                <span class="agenda-badge agenda-badge-hoy">📅 Hoy: {{ $cantidadTurnosHoy ?? 0 }}</span>
                <span class="agenda-badge agenda-badge-futuro">🗓️ Futuros: {{ $cantidadTurnosFuturos ?? 0 }}</span>
            </div>
        </div>

        <div class="row g-3">
            <div class="col-12 col-xl-9">
                <div id="agenda-profesional"></div>
            </div>

            <div class="col-12 col-xl-3">
                <div class="agenda-resumen p-3 h-100">
                    <h2 class="h6 mb-3">Detalle del turno</h2>
                    <div id="agenda-detalle" class="small text-muted">
                        Seleccioná un turno del calendario para ver la información.
                    </div>
                </div>
            </div>
        </div>
    </main>

    <form id="formCancelarTurno" method="POST" action="" class="d-none">
        @csrf
    </form>

    <button id="abrirModalReprogramarTurno" type="button" class="d-none" data-bs-toggle="modal" data-bs-target="#modalReprogramarTurno"></button>
    <button id="abrirModalAdvertenciaTurnoDirecto" type="button" class="d-none" data-bs-toggle="modal" data-bs-target="#modalAdvertenciaTurnoDirecto"></button>
    <button id="abrirModalAdvertenciaReprogramarTurno" type="button" class="d-none" data-bs-toggle="modal" data-bs-target="#modalAdvertenciaReprogramarTurno"></button>

    <div class="modal fade" id="modalReprogramarTurno" tabindex="-1" aria-labelledby="modalReprogramarTurnoLabel" aria-hidden="true">
        <div class="modal-dialog">
            <form id="formReprogramarTurno" method="POST" action="">
                @csrf
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="modalReprogramarTurnoLabel">Reprogramar turno</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
                    </div>
                    <div class="modal-body">
                        <div class="mb-3">
                            <label for="rt_fecha" class="form-label">Nueva fecha</label>
                            <input type="date" class="form-control" id="rt_fecha" name="fecha_turno" min="{{ now()->toDateString() }}" required>
                        </div>
                        <div class="mb-0">
                            <label for="rt_hora" class="form-label">Nuevo horario</label>
                            <input type="time" class="form-control" id="rt_hora" name="hora_turno" required>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancelar</button>
                        <button type="submit" class="btn btn-primary">Guardar reprogramación</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const agendaEl = document.getElementById('agenda-profesional');
            const detalleEl = document.getElementById('agenda-detalle');
            const eventos = @json($eventosAgenda ?? []);
            const modalReprogramarEl = document.getElementById('modalReprogramarTurno');
            const formReprogramar = document.getElementById('formReprogramarTurno');
            const inputFechaReprogramar = document.getElementById('rt_fecha');
            const inputHoraReprogramar = document.getElementById('rt_hora');
            const botonAbrirModalReprogramar = document.getElementById('abrirModalReprogramarTurno');

            if (!agendaEl) {
                return;
            }

            const escaparHtml = (valor) => {
                return String(valor ?? '-')
                    .replace(/&/g, '&amp;')
                    .replace(/</g, '&lt;')
                    .replace(/>/g, '&gt;')
                    .replace(/"/g, '&quot;')
                    .replace(/'/g, '&#039;');
            };

            const renderDetalle = (event) => {
                if (!detalleEl || !event) {
                    return;
                }

                const props = event.extendedProps || {};
                if (props.tipoEvento === 'disponibilidad') {
                    const inicioDisponibilidad = event.start
                        ? event.start.toLocaleString('es-AR', {
                            dateStyle: 'short',
                            timeStyle: 'short'
                        })
                        : '-';

                    detalleEl.innerHTML = `
                        <p class="mb-1"><strong>Tipo:</strong> Disponibilidad</p>
                        <p class="mb-1"><strong>Estado:</strong> ${escaparHtml(props.estado || 'Disponible')}</p>
                        <p class="mb-1"><strong>Inicio:</strong> ${escaparHtml(inicioDisponibilidad)}</p>
                        <p class="mb-0"><strong>Descripción:</strong> ${escaparHtml(props.descripcion || '-')}</p>
                    `;
                    return;
                }

                const inicio = event.start
                    ? event.start.toLocaleString('es-AR', {
                        dateStyle: 'short',
                        timeStyle: 'short'
                    })
                    : '-';

                const turnoIdSeguro = Number.isInteger(Number(props.turnoId)) ? String(props.turnoId) : '';
                const fechaSeguro = typeof event.startStr === 'string' ? escaparHtml(event.startStr.slice(0, 10)) : '';
                const horaSeguro = typeof event.startStr === 'string' ? escaparHtml(event.startStr.slice(11, 16)) : '';

                detalleEl.innerHTML = `
                    <p class="mb-1"><strong>Servicio:</strong> ${escaparHtml(props.servicio || '-')}</p>
                    <p class="mb-1"><strong>Cliente:</strong> ${escaparHtml(props.cliente || '-')}</p>
                    <p class="mb-1"><strong>Celular:</strong> ${escaparHtml(props.celular || '-')}</p>
                    <p class="mb-1"><strong>Correo:</strong> ${escaparHtml(props.correo || '-')}</p>
                    <p class="mb-1"><strong>Modalidad:</strong> ${escaparHtml(props.modalidad || '-')}</p>
                    <p class="mb-1"><strong>Estado:</strong> ${escaparHtml(props.estado || '-')}</p>
                    <p class="mb-1"><strong>Inicio:</strong> ${escaparHtml(inicio)}</p>
                    <p class="mb-3"><strong>Descripción:</strong> ${escaparHtml(props.descripcion || '-')}</p>
                    ${props.puedeReprogramarse && turnoIdSeguro ? `
                        <button type="button" class="btn btn-outline-primary btn-sm w-100 mb-2" data-reprogramar-turno-id="${turnoIdSeguro}" data-reprogramar-turno-fecha="${fechaSeguro}" data-reprogramar-turno-hora="${horaSeguro}">
                            Reprogramar turno
                        </button>
                    ` : ''}
                    ${props.puedeCancelarse && turnoIdSeguro ? `
                        <button type="button" class="btn btn-outline-danger btn-sm w-100" data-cancelar-turno-id="${turnoIdSeguro}">
                            Cancelar turno
                        </button>
                    ` : ''}
                `;
            };

            detalleEl?.addEventListener('click', function (event) {
                const botonReprogramar = event.target.closest('[data-reprogramar-turno-id]');
                if (botonReprogramar) {
                    const turnoId = botonReprogramar.getAttribute('data-reprogramar-turno-id');
                    if (!turnoId || !formReprogramar || !inputFechaReprogramar || !inputHoraReprogramar || !modalReprogramarEl || !botonAbrirModalReprogramar) {
                        return;
                    }

                    inputFechaReprogramar.value = botonReprogramar.getAttribute('data-reprogramar-turno-fecha') || '';
                    inputHoraReprogramar.value = botonReprogramar.getAttribute('data-reprogramar-turno-hora') || '';
                    formReprogramar.action = '/profesional/turnos/' + turnoId + '/reprogramar';
                    botonAbrirModalReprogramar.click();
                    return;
                }

                const boton = event.target.closest('[data-cancelar-turno-id]');
                if (!boton) {
                    return;
                }

                const turnoId = boton.getAttribute('data-cancelar-turno-id');
                if (!turnoId) {
                    return;
                }

                if (!window.confirm('¿Querés cancelar este turno?')) {
                    return;
                }

                const form = document.getElementById('formCancelarTurno');
                if (!form) {
                    return;
                }

                form.action = '/profesional/turnos/' + turnoId + '/cancelar';
                form.submit();
            });

            const esPantallaChica = window.innerWidth < 768;

            const calendar = new FullCalendar.Calendar(agendaEl, {
                locale: window.FullCalendarLocales?.es || 'es',
                plugins: [
                    window.FullCalendarPlugins?.dayGridPlugin,
                    window.FullCalendarPlugins?.timeGridPlugin,
                    window.FullCalendarPlugins?.interactionPlugin,
                ].filter(Boolean),
                initialView: esPantallaChica ? 'timeGridDay' : 'timeGridWeek',
                headerToolbar: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'dayGridMonth,timeGridWeek,timeGridDay'
                },
                buttonText: {
                    today: 'Hoy',
                    month: 'Mes',
                    week: 'Semana',
                    day: 'Día'
                },
                height: esPantallaChica ? 650 : 'auto',
                contentHeight: esPantallaChica ? 650 : 'auto',
                navLinks: true,
                events: eventos,
                eventDisplay: 'block',
                eventOverlap: true,
                eventOrder: 'start,-duration,allDay,title',
                eventDidMount: function (info) {
                    const props = info.event.extendedProps || {};
                    if (props.tipoEvento) {
                        return;
                    }

                    const harness = info.el.closest('.fc-timegrid-event-harness');
                    if (harness) {
                        harness.style.left = '0px';
                        harness.style.right = '0px';
                    }
                },
                eventClick: function (info) {
                    renderDetalle(info.event);
                }
            });

            calendar.render();

            if (eventos.length > 0) {
                const primerEvento = calendar.getEventById(String(eventos[0].id));
                if (primerEvento) {
                    renderDetalle(primerEvento);
                }
            }
        });
    </script>

    {{-- Boton oculto para reabrir modal si hay errores de validacion --}}
    @if($errors->any())
        <button id="reabrirModalTurnoDirecto" class="d-none" data-bs-toggle="modal" data-bs-target="#modalAsignarTurno"></button>
    @endif

    {{-- Modal: Asignar un turno --}}
    <div class="modal fade" id="modalAsignarTurno" tabindex="-1" aria-labelledby="modalAsignarTurnoLabel" aria-hidden="true">
        <div class="modal-dialog">
            <form method="POST" action="/profesional/asignar-turno-directo">
                @csrf
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="modalAsignarTurnoLabel">Asignar un turno</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
                    </div>
                    <div class="modal-body">
                        <div class="mb-3">
                            <label for="at_nombrecompleto" class="form-label">Nombre completo cliente</label>
                            <input type="text" class="form-control @error('nombrecompleto') is-invalid @enderror" id="at_nombrecompleto" name="nombrecompleto" value="{{ old('nombrecompleto') }}" required maxlength="200">
                            @error('nombrecompleto')<div class="invalid-feedback">{{ $message }}</div>@enderror
                        </div>
                        <div class="mb-3">
                            <label for="at_correo" class="form-label">Correo electronico</label>
                            <input type="email" class="form-control @error('correo') is-invalid @enderror" id="at_correo" name="correo" value="{{ old('correo') }}" required maxlength="255">
                            @error('correo')<div class="invalid-feedback">{{ $message }}</div>@enderror
                        </div>
                        <div class="mb-3">
                            <label for="at_celular" class="form-label">Celular del cliente</label>
                            <input type="text" class="form-control @error('celular') is-invalid @enderror" id="at_celular" name="celular" value="{{ old('celular') }}" required maxlength="15" inputmode="numeric" pattern="[0-9]{8,15}" title="Ingresá entre 8 y 15 números.">
                            @error('celular')<div class="invalid-feedback">{{ $message }}</div>@enderror
                        </div>
                        <div class="mb-3">
                            <label for="at_descripcion" class="form-label">Descripción</label>
                            <textarea class="form-control @error('descripcion') is-invalid @enderror" id="at_descripcion" name="descripcion" rows="3" maxlength="1000" placeholder="Ingrese una descripción del turno">{{ old('descripcion') }}</textarea>
                            @error('descripcion')<div class="invalid-feedback">{{ $message }}</div>@enderror
                        </div>
                        <div class="mb-3">
                            <label for="at_servicio" class="form-label">Servicio</label>
                            <select class="form-select @error('servicio_id') is-invalid @enderror" id="at_servicio" name="servicio_id" required>
                                <option value="">Seleccionar servicio</option>
                                @forelse($servicios ?? [] as $servicio)
                                    <option value="{{ $servicio->id }}" {{ old('servicio_id') == $servicio->id ? 'selected' : '' }}>{{ $servicio->titulo }}</option>
                                @empty
                                    <option value="" disabled>No hay servicios activos para tu profesión</option>
                                @endforelse
                            </select>
                            <div class="form-text">Solo se muestran servicios correspondientes a tu profesión.</div>
                            @error('servicio_id')<div class="invalid-feedback">{{ $message }}</div>@enderror
                        </div>
                        <div class="mb-3">
                            <label for="at_modalidad" class="form-label">Modalidad</label>
                            <select class="form-select @error('modalidad_id') is-invalid @enderror" id="at_modalidad" name="modalidad_id" required>
                                <option value="">Seleccionar modalidad</option>
                                @foreach($modalidades ?? [] as $modalidad)
                                    <option value="{{ $modalidad->id }}" {{ old('modalidad_id') == $modalidad->id ? 'selected' : '' }}>{{ $modalidad->descripcion }}</option>
                                @endforeach
                            </select>
                            @error('modalidad_id')<div class="invalid-feedback">{{ $message }}</div>@enderror
                        </div>
                        <div class="row">
                            <div class="col-6">
                                <label for="at_fecha" class="form-label">Fecha del turno</label>
                                <input type="date" class="form-control @error('fecha_turno') is-invalid @enderror" id="at_fecha" name="fecha_turno" value="{{ old('fecha_turno') }}" min="{{ now()->toDateString() }}" required>
                                @error('fecha_turno')<div class="invalid-feedback">{{ $message }}</div>@enderror
                            </div>
                            <div class="col-6">
                                <label for="at_hora" class="form-label">Horario</label>
                                <input type="time" class="form-control @error('hora_turno') is-invalid @enderror" id="at_hora" name="hora_turno" value="{{ old('hora_turno') }}" required>
                                @error('hora_turno')<div class="invalid-feedback">{{ $message }}</div>@enderror
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancelar</button>
                        <button type="submit" class="btn btn-primary">Guardar turno</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    @php
        $turnoDirectoWarning = session('turno_directo_warning');
        $reprogramarTurnoWarning = session('reprogramar_turno_warning');
    @endphp

    <div class="modal fade" id="modalAdvertenciaTurnoDirecto" tabindex="-1" aria-labelledby="modalAdvertenciaTurnoDirectoLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modalAdvertenciaTurnoDirectoLabel">Advertencia al asignar turno</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
                </div>
                <div class="modal-body">
                    <p class="mb-2">El día u horario elegido coincide con restricciones de agenda.</p>
                    <ul class="mb-0 ps-3">
                        @foreach(($turnoDirectoWarning['advertencias'] ?? []) as $advertencia)
                            <li>{{ $advertencia }}</li>
                        @endforeach
                    </ul>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">No aceptar</button>
                    <form method="POST" action="/profesional/asignar-turno-directo" class="m-0">
                        @csrf
                        <input type="hidden" name="omitir_restricciones" value="1">
                        <input type="hidden" name="nombrecompleto" value="{{ $turnoDirectoWarning['inputs']['nombrecompleto'] ?? '' }}">
                        <input type="hidden" name="correo" value="{{ $turnoDirectoWarning['inputs']['correo'] ?? '' }}">
                        <input type="hidden" name="celular" value="{{ $turnoDirectoWarning['inputs']['celular'] ?? '' }}">
                        <input type="hidden" name="servicio_id" value="{{ $turnoDirectoWarning['inputs']['servicio_id'] ?? '' }}">
                        <input type="hidden" name="modalidad_id" value="{{ $turnoDirectoWarning['inputs']['modalidad_id'] ?? '' }}">
                        <input type="hidden" name="descripcion" value="{{ $turnoDirectoWarning['inputs']['descripcion'] ?? '' }}">
                        <input type="hidden" name="fecha_turno" value="{{ $turnoDirectoWarning['inputs']['fecha_turno'] ?? '' }}">
                        <input type="hidden" name="hora_turno" value="{{ $turnoDirectoWarning['inputs']['hora_turno'] ?? '' }}">
                        <button type="submit" class="btn btn-primary">Aceptar igualmente</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="modalAdvertenciaReprogramarTurno" tabindex="-1" aria-labelledby="modalAdvertenciaReprogramarTurnoLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modalAdvertenciaReprogramarTurnoLabel">Advertencia al reprogramar turno</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Cerrar"></button>
                </div>
                <div class="modal-body">
                    <p class="mb-2">El día u horario elegido coincide con restricciones de agenda.</p>
                    <ul class="mb-0 ps-3">
                        @foreach(($reprogramarTurnoWarning['advertencias'] ?? []) as $advertencia)
                            <li>{{ $advertencia }}</li>
                        @endforeach
                    </ul>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">No aceptar</button>
                    <form method="POST" action="/profesional/turnos/{{ $reprogramarTurnoWarning['turno_id'] ?? 0 }}/reprogramar" class="m-0">
                        @csrf
                        <input type="hidden" name="omitir_restricciones" value="1">
                        <input type="hidden" name="fecha_turno" value="{{ $reprogramarTurnoWarning['inputs']['fecha_turno'] ?? '' }}">
                        <input type="hidden" name="hora_turno" value="{{ $reprogramarTurnoWarning['inputs']['hora_turno'] ?? '' }}">
                        <button type="submit" class="btn btn-primary">Aceptar igualmente</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            document.getElementById('reabrirModalTurnoDirecto')?.click();

            @if($turnoDirectoWarning)
                document.getElementById('abrirModalAdvertenciaTurnoDirecto')?.click();
            @endif

            @if($reprogramarTurnoWarning)
                document.getElementById('abrirModalAdvertenciaReprogramarTurno')?.click();
            @endif
        });
    </script>

    @include('partials.reportar-falla-boton')
</body>
</html>



