
{{-- Styles --}}
  {{-- Custom --}}
    <link href="{{ asset('css/components/tables/reservation-components.css') }}" rel="stylesheet">
    <link href="{{ asset('css/components/forms/reservation-form-modal.css') }}" rel="stylesheet">

{{-- Page Configuration --}}
@extends('layouts.app')
@section('title', __('modules')['home']['reservations'])

{{-- Content --}}
@section('content')
  {{-- Imports --}}
    @php
      //* Imports
        use \App\Helpers\Environment\SystemFeaturesHelper;
        use \App\Helpers\Environment\SystemParametersHelper;

      //* Features
        $has_pax_pricing = SystemFeaturesHelper::getFeatureStatus('pax_pricing');
        $has_control_hours = SystemFeaturesHelper::getFeatureStatus('control_hours');
        $has_express_reservations = SystemFeaturesHelper::getFeatureStatus('express_reservations');

        $has_additional_pax_charge = SystemFeaturesHelper::getFeatureStatus('additional_pax_charge');

      //* Parameters
        $express_tolerance_minutes = (int) SystemParametersHelper::getValueOf('hotel.express_tolerance_minutes');
    @endphp

  {{-- Body --}}
    <div class="pr-0 col-12">

        {{-- Header --}}
        <div class="px-3 py-2 mb-3 cardtitle d-flex align-items-center justify-content-between">

            {{-- Title --}}
            <h3 class="pl-3 mb-0">
                {{ __('modules')['dashboard']['hotel']['reservations'] }}
            </h3>

            <div class="gap-2 d-flex align-items-center justify-content-end">

                {{-- Get Overbooked --}}
                <button type="button" onclick="showAlerts()" class="mx-3 btn btn-outline-secondary"
                    title="{{ __('entity_forms')['reservation']['page']['check_overbooking'] }}">
                    <i class="fas fa-exclamation-circle"></i> {{ __('entity_forms')['reservation']['page']['view_overbooking'] }}
                </button>

                {{-- Nueva Reserva --}}
                <button type="button" name="create_record" id="create_record" class="mx-3 btn boton">
                    ✚ {{ __('common_actions')['add'] }} {{ __('entities')['hotel']['reservation'] }}
                </button>

                {{-- Filter --}}
                <ul class="mx-2 cursor-pointer navbar-nav">
                    <li class="py-0 text-center nav-item dropdown btn btn-outline-light">

                        {{-- Activate --}}
                        <a id="filterDropdown" role="button" href="#"
                            title="Filtrar Reservas" class="px-3 pale-item btn btn-filter d-flex justify-content-between align-items-center"
                            data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" v-pre
                        >
                            <img src="{{ asset('icons/reservation_filter.svg') }}" style="width: 1.2rem;" alt="Filter">
                            <span class="ml-2">{{ __('entity_forms')['reservation']['page']['filter_button'] }}</span>
                        </a>

                        {{-- Structure --}}
                        <div aria-labelledby="filterDropdown" class="dropdown-menu dropdown-menu-right drop-filter" style="width: 30rem;">
                            <form method="post" id="filter_form" autocomplete="off"
                                enctype="multipart/form-data" class="container mb-3"
                            >@csrf

                                {{-- Header --}}
                                <div class="px-2 py-2 mb-3 d-flex align-items-center justify-content-between border-bottom">
                                    {{-- Title --}}
                                    <div class="d-flex align-items-center justify-content-start">
                                        {{-- Icon --}}
                                            <img src="{{ asset('icons/reservation_filter.svg') }}" alt="Filter"
                                                style="width: auto; height: 1.4rem;" class="ml-2">

                                        {{-- Title --}}
                                            <span class="mx-3 text-start text-uppercase harsi-color font-weight-bolder" style="font-size: 1.1rem">
                                                {{ __('entity_forms')['reservation']['page']['filter_title'] }}
                                            </span>
                                    </div>

                                    {{-- Buttons --}}
                                    <div class="d-flex align-items-center justify-content-end">
                                        {{-- Reset --}}
                                        <button type="button" class="py-1 mx-1 btn btn-secondary" id="resetFilter">
                                            Reset
                                        </button>

                                        {{-- Filter Button --}}
                                        <button type="submit" class="py-1 mx-2 btn btn-success" style="font-size: 1rem">
                                            {{ __('common_actions')['filter'] }}
                                        </button>
                                    </div>
                                </div>

                                {{-- Fecha --}}
                                <div class="row justify-content-center align-items-center">
                                    {{-- Title --}}
                                    <div class="px-1 col-2">
                                        <p class="py-1 pl-2 indicadores font-weight-bold">
                                            {{ __('entity_fields')['common']['date'] }} <span style="color:#dc3545">*</span>
                                        </p>
                                    </div>

                                    {{-- From --}}
                                    <div class="px-1 col-4">
                                        <input id="filter_from" type="date" name="filter_from"
                                            class="form-control" value="{{ date('Y-01-01') }}"
                                            max="2100-12-31" step="1" required>
                                    </div>

                                    {{-- Separator --}}
                                    <div class="col-1">
                                        <p class="py-1 text-center indicadores ">
                                            -
                                        </p>
                                    </div>

                                    {{-- To --}}
                                    <div class="px-1 col-4">
                                        <input id="filter_to" type="date" name="filter_to"
                                            class="form-control" value="{{ date('Y-12-31') }}"
                                            max="2100-12-31" step="1" required>
                                    </div>
                                </div>

                                <hr> {{-- Huesped --}}
                                <div class="row justify-content-center align-items-center">
                                    <div class="col-2">
                                        <p class="py-1 indicadores font-weight-bold">{{ __('common_actions')['search'] }}</p>
                                    </div>

                                    <div class="px-1 col-9">
                                        <input type="text" id="filter_guest_or_folio" name="filter_guest_or_folio" value=""
                                            class="form-control" placeholder="{{ __('entity_forms')['reservation']['page']['guest_filter'] }}"
                                            oninput="this.value = this.value.replace(/[^A-ZÁÉÍÓÚÑa-záéíóúñ0-9 ]/g, '')">
                                    </div>
                                </div>

                                <hr class="mb-2"> {{-- Tipo - Contrato - Estado de Pago --}}
                                <div class="d-flex g-1 justify-content-around">
                                    {{-- Tipo --}}
                                    <div>
                                        {{-- Title --}}
                                        <p class="pt-0 pb-1 pl-2 text-start indicadores">
                                            <b>{{ __('entity_fields')['common']['type'] }}</b>
                                        </p>

                                        {{-- Checkboxes --}}
                                        <div>
                                            <div class="pl-3">
                                                <input type="checkbox" name="filter_type[]" value="0"
                                                    class="mr-1" aria-label="Noches">
                                                <label class="unstyle switch_label font-weight-normal" for="filter_type[]">{{ __('neutral_words')['nights'] }}</label>
                                            </div>
                                            <div class="pl-3">
                                                <input type="checkbox" name="filter_type[]" value="1"
                                                    class="mr-1" aria-label="Express">
                                                <label class="unstyle switch_label font-weight-normal" for="filter_type[]">{{ __('neutral_words')['express'] }}</label>
                                            </div>
                                        </div>
                                    </div>

                                    {{-- Contrato --}}
                                    <div>
                                        {{-- Title --}}
                                        <p class="pt-0 pb-1 pl-2 text-start indicadores">
                                            <b>{{ __('entity_fields')['reservation']['contract'] }}</b>
                                        </p>

                                        {{-- Checkboxes --}}
                                        <div>
                                            <div class="pl-3">
                                                <input type="checkbox" name="filter_contract[]" value="Pago en Destino"
                                                    class="mr-1" aria-label="Pago en Destino">
                                                <label class="unstyle switch_label font-weight-normal" for="filter_contract[]">{{ __('neutral_words')['on_destiny'] }}</label>
                                            </div>
                                            <div class="pl-3">
                                                <input type="checkbox" name="filter_contract[]" value="Cortesia"
                                                    class="mr-1" aria-label="Cortesia">
                                                <label class="unstyle switch_label font-weight-normal" for="filter_contract[]">{{ __('neutral_words')['courtesy'] }}</label>
                                            </div>
                                            <div class="pl-3">
                                                <input type="checkbox" name="filter_contract[]" value="Credito"
                                                    class="mr-1" aria-label="Credito">
                                                <label class="unstyle switch_label font-weight-normal" for="filter_contract[]">{{ __('neutral_words')['credit'] }}</label>
                                            </div>
                                        </div>
                                    </div>

                                    {{-- Estado de Pago --}}
                                    <div>
                                        {{-- Title --}}
                                        <p class="pt-0 pb-1 pl-2 text-start indicadores">
                                            <b>{{ __('entity_fields')['common']['payment_status'] }}</b>
                                        </p>

                                        {{-- Checkboxes --}}
                                        <div>
                                            <div class="pl-3">
                                                <input type="checkbox" name="filter_status_payment[]" value="#fd2319"
                                                    class="mr-1" aria-label="Faltante">
                                                <label class="unstyle" for="filter_status_payment[]">{{ __('neutral_words')['missing'] }}</label>
                                            </div>
                                            <div class="pl-3">
                                                <input type="checkbox" name="filter_status_payment[]" value="#ffcf00"
                                                    class="mr-1" aria-label="En Proceso">
                                                <label class="unstyle" for="filter_status_payment[]">{{ __('neutral_words')['in_process'] }}</label>
                                            </div>
                                            <div class="pl-3">
                                                <input type="checkbox" name="filter_status_payment[]" value="#37f00f"
                                                    class="mr-1" aria-label="Finalizado">
                                                <label class="unstyle" for="filter_status_payment[]">{{ __('neutral_words')['completed'] }}</label>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <hr class="mb-2"> {{-- Agencia --}}
                                <div class="px-3 d-flex justify-content-between">
                                    {{-- Agencia --}}
                                    <div>
                                        {{-- Title --}}
                                        <p class="pt-0 pb-1 pl-2 text-start indicadores">
                                            <b>{{ __('entities')['hotel']['agency'] }}</b>
                                        </p>

                                        {{-- Checkbox --}}
                                        <div class="flex-wrap pl-3 mt-1 d-flex justify-content-between">
                                            <div class="w-33">
                                                <input type="checkbox" name="filter_agency[]"
                                                    value="" class="mr-1">
                                                <label for="filter_agency[]" class="unstyle switch_label font-weight-normal">{{ __('neutral_words')['none'] }}</label>
                                            </div>
                                            @foreach($agencies as $agency)
                                                <div class="w-33">
                                                    <input type="checkbox" name="filter_agency[]"
                                                        value="{{$agency->id}}" class="mr-1">
                                                    <label for="filter_agency[]" class="unstyle switch_label font-weight-normal">{{$agency->agency_name}}</label>
                                                </div>
                                            @endforeach
                                        </div>
                                    </div>
                                </div>

                            </form>
                        </div>
                    </li>
                </ul>

            </div>
        </div>

        {{-- Table Structure --}}
        <div class="mb-5 table-responsive">
            <table class="table text-center cardtable" id="user_table">
                <thead>
                    <tr class="cardtabletr">
                        <th width="10%" class="text-center th_minus">Folio</th>
                        <th width="8.5%" class="text-center th_minus">{{ __('entity_fields')['reservation']['contract'] }}</th>
                        <th width="10%" class="text-center th_minus">{{ __('entity_fields')['common']['type'] }}</th>
                        <th class="text-center th_minus">{{ __('entity_fields')['reservation']['client'] }}</th>
                        <th width="10%" class="text-center th_minus">{{ __('entity_fields')['reservation']['arrival'] }}</th>
                        <th width="10%" class="text-center th_minus">{{ __('entity_fields')['reservation']['date_departure'] }}</th>
                        <th width="10%" class="text-center th_minus">{{ __('entity_fields')['reservation']['room'] }}</th>
                        <th width="10%" class="text-center th_minus">{{ __('entity_fields')['reservation']['length_of_stay'] }}</th>
                        <th width="8.5%" class="text-center th_minus">{{ __('entity_fields')['common']['status'] }}</th>
                        <th width="13%" class="text-center th_minus">{{ __('entity_fields')['common']['actions'] }}</th>
                    </tr>
                </thead>
            </table>
        </div>

    </div>

    {{-- Formularios de Reservas --}}
        {{-- Básico --}}
        @include('shared.utils.reservation-form.basic.base', ['is_external' => false])

        {{-- Avanzado (OTAs) --}}
        {{-- <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#advanced_form_modal">
            Launch
        </button> --}}
        @include('shared.utils.reservation-form.complex.base', ['is_external' => false])

  {{-- Variables Globales --}}
    <script>
        window.config = {
            routes: {
                // For Reservation Interactions
                reservationStore: "{{ route('reservations.store') }}",
                reservationUpdate: "{{ route('reservations.update') }}",
                reservationFilter: "{{ route('reservations.filter') }}",

                // For Lodgings (Store)
                lodgingPayment: "{{ route('reservationPayments.lodging.store') }}",
                // For Consumptions (Store)
                consumptionPayment: "{{ route('reservationPayments.consumption.store') }}",
                consumptionCharge: "{{ route('reservationCharges.consumption.store') }}",
                // For Extras (Store)
                extraPayment: "{{ route('reservationPayments.extra.store') }}",
                extraCharge: "{{ route('reservationCharges.extra.store') }}",

                // For Lodgings (Update)
                updateLodgingPayment: "{{ route('reservationPayments.lodging.update') }}",
                // For Consumptions (Update)
                updateConsumptionPayment: "{{ route('reservationPayments.consumption.update') }}",
                updateConsumptionCharge: "{{ route('reservationCharges.consumption.update') }}",
                // For Extras (Update)
                updateExtraPayment: "{{ route('reservationPayments.extra.update') }}",
                updateExtraCharge: "{{ route('reservationCharges.extra.update') }}",

            },
            data: {
                language: "{{ session('locale') }}",

                fisrtday: '{{ date("Y-m-d",mktime(0, 0, 0, 1, 1, date("Y"))) }}',
                lastday: '{{ date("Y-m-d", mktime(0, 0, 0, 12, 31, date("Y"))) }}',
                currentday: '{{ date("Y-m-d") }}',

                statusCreate:`
                        @foreach($statuses as $status)
                            @if ($status->status_type === "Creation")
                                <option value="{{ $status->id }}">
                                    {{ __('seeders')['statuses'][$status->status_name] }}
                                </option>
                            @endif
                        @endforeach
                    `,
                statusEdit:`
                        @foreach($statuses as $status)
                            @if ($status->status_type === "Creation")
                                <option value="{{ $status->id }}">
                                    {{ __('seeders')['statuses'][$status->status_name] }}
                                </option>
                            @endif
                        @endforeach
                    `,

                guestStatusCreate:`
                        @foreach($statuses as $status)
                                    {{-- Check-out --}}               {{-- No se presenta --}}
                            @if ($status->id != 6 && $status->id != 5 && $status->status_type === "Guest")
                                <option value="{{ $status->id }}">
                                    {{ __('seeders')['statuses'][$status->status_name] }}
                                </option>
                            @endif
                        @endforeach
                    `,
                guestStatusEdit:`
                        @foreach($statuses as $status)
                            @if ($status->status_type === "Guest")
                                <option value="{{ $status->id }}">
                                    {{ __('seeders')['statuses'][$status->status_name] }}
                                </option>
                            @endif
                        @endforeach
                    `,

                waitingCheckinStatuses: `
                        @foreach($statuses as $status)
                            @if ($status->status_type === "Shared")
                                <option value="{{ $status->id }}">
                                    {{ __('seeders')['statuses'][$status->status_name] }}
                                </option>
                            @endif
                        @endforeach
                    `,

                normalRoomTypes: `
                        @foreach ($roomTypes as $tyroom)
                            @if (
                                (
                                    (Auth::check() && in_array(Auth::user()->role, ['administrador','gerente']))
                                    || $tyroom->id != 1
                                ) && !$tyroom->is_express_type
                            )
                                <option value="{{ $tyroom->id }}" data-limit="{{ $tyroom->pax_room_limit }}"
                                    @if ($has_express_reservations)
                                        data-minimum-stay="{{ $tyroom->minimum_express_stay }}"
                                    @endif
                                >
                                    {{ $tyroom->tr_name }}
                                </option>
                            @endif
                        @endforeach
                    `,

                expressRoomTypes: `
                        @foreach ($roomTypes as $tyroom)
                            @if (
                                (
                                    (Auth::check() && in_array(Auth::user()->role, ['administrador','gerente']))
                                    || $tyroom->id != 1
                                ) && $tyroom->is_express_type
                            )
                                <option value="{{ $tyroom->id }}" data-limit="{{ $tyroom->pax_room_limit }}"
                                    @if ($has_express_reservations)
                                        data-minimum-stay="{{ $tyroom->minimum_express_stay }}"
                                    @endif
                                >
                                    {{ $tyroom->tr_name }}
                                </option>
                            @endif
                        @endforeach
                    `,

                receptionist: '{{ Auth::user()->name }}',
                features: {
                    has_express_reservations : @json($has_express_reservations),
                    has_control_hours : @json($has_control_hours),
                    has_pax_pricing : @json($has_pax_pricing),

                    has_additional_pax_charge : @json($has_additional_pax_charge),
                },
                parameters: {
                    express_tolerance_minutes : @json($express_tolerance_minutes)
                },
            },
            assets: {
                toastInfoIcon: "{{ asset('images/toast-info-icon.png') }}",
            }
        };
    </script>

    {{-- Secondary Imports --}}
    <script type="text/javascript" src="{{ asset('js/hotel/reservationManage.js') }}"></script>
@endsection

@section('footer')
    @include('shared.components.footer.basic-footer')
@endsection
