<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}">

    <title>Ticket | Reservation {{ $reservation->id }}</title>

    {{-- Boostrap --}}
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">

    {{-- Jquery --}}
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous"></script>

    {{-- AJAX --}}
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

    {{-- Import Hotel Settings Control --}}
    <script type="text/javascript" src="{{ asset('js/environment/hotelSettings.js') }}"></script>

    {{-- My Styles --}}
    <style>
        .ticket {
            max-width: 300px;
            margin: 0 auto;
            padding: 10px;
            border: 1px solid #000;
            text-align: center;
            font-size: 12px;
        }

        .ticket table {
            width: 100%;
            text-align: left;
            border-collapse: collapse;
        }

        .ticket th,
        .ticket td {
            border-bottom: 1px solid #000;
            padding: 4px;
        }

        .ticket th {
            text-align: left;
        }
        .ticket td {
            text-align: center;
        }

        /* Estilos específicos para la impresión */
        @media print {
            @page {
                size: 80mm auto; /* o 58mm según tu impresora */
                margin: 0;       /* para aprovechar el ancho completo */
            }

            * {
                -webkit-print-color-adjust: exact;
                print-color-adjust: exact;
            }

            body {
                margin: 0;
                padding: 0;
            }

            .ticket {
                box-shadow: none;
                border: none;
                margin: 0 auto;
            }

            .oculto-impresion {
                display: none;
            }

        }
    </style>
</head>

<body class="py-4 text-center">

    <div class="rounded ticket">

        {{-- Logo --}}
        @if (Auth::user()->profile_photo === null)
            <img class="mb-3 img-fluid" style="object-fit: contain; height: auto; max-width: 65%;" src="{{ asset('images/harsi_logo.png') }}" alt="">
        @else
            <img class="mb-3 img-fluid" style="object-fit: contain; max-height: 7rem; width: auto;" src="{{ Auth::user()->profile_photo }}" alt="">
        @endif

        {{-- Titulo --}}
        <p class="pt-2 text-center">
            @if($hotel->business_name != '')
                <b class="pb-0 mb-0 text-uppercase" style="font-size: 1.1rem !important">{{$hotel->business_name}}</b>
                <br>
            @endif

            <span style="font-size: 0.65rem !important">- {{ __('tickets')['hotel']['consumption_tickets']['title'] }} -</span>
        <p>

        {{-- Detalles Generales --}}
        <p class="px-2 text-left">

            {{ __('tickets')['hotel']['consumption_tickets']['reservation'] }} &nbsp; {{ $reservation->id }}

            <br>{{ __('tickets')['hotel']['consumption_tickets']['date'] }} {{ $reservation->date_entry }}

            @if($hotel->business_address != '')
                <br>
                {{ __('tickets')['hotel']['consumption_tickets']['address'] }}  &nbsp;<span class="text-uppercase">{{$hotel->business_address}}</span>
            @endif

        </p>

        {{-- Resumen del Pedido --}}
        <table class="mt-2 mb-3">
            <thead class="text-center">
                <tr>
                    <th class="cantidad">{{ __('tickets')['hotel']['consumption_tickets']['consumption_date'] }}</th>
                    <th class="producto">{{ __('tickets')['hotel']['consumption_tickets']['consumption_concat'] }}</th>
                    <th class="subtotal">{{ __('tickets')['hotel']['consumption_tickets']['consumption_amount'] }}</th>
                </tr>
            </thead>

            <tbody>

                {{-- Illusionary Divisor --}}
                <tr style="height: 0.5rem">
                    <td colspan="4" style="border: 0px !important;"></td>
                </tr>

                {{-- Productos Solicitados --}}
                @forelse($reservation->consumptionCharges->where('status', 'Activo') as $charges)
                    <tr class="text-center">
                        <td style="border-bottom: 1px solid #fefefe" class="cantidad">{{ $charges->consumption_date->format('Y-m-d H:i') }}</td>
                        <td style="border-bottom: 1px solid #fefefe" class="text-left producto">{{ $charges->consumption_concept}}</td>
                        <td style="border-bottom: 1px solid #fefefe" class="subtotal">
                            {{ \App\Helpers\Formats\FormatCurrencyHelper::formatCurrency( number_format($charges->consumption_price, 2) ) }}
                        </td>
                    </tr>
                @empty
                    <tr class="">
                        <td style="border-bottom: 1px solid #fefefe" class="cantidad">---</td>
                        <td style="border-bottom: 1px solid #fefefe" class="text-left producto">---</td>
                        <td style="border-bottom: 1px solid #fefefe" class="subtotal">---</td>
                    </tr>
                @endforelse

                {{-- Illusionary Divisor --}}
                <tr>
                    <td style="border-bottom: 1px solid #777777" colspan="4"></td>
                </tr>

            </tbody>
        </table>

        {{-- Importes --}}
        @php
            $chargesCount = $reservation->consumptionCharges->where('status', 'Activo');
            $totalCharges = $chargesCount->sum('consumption_price');
        @endphp
        <p class="mb-2 text-center">
            {{ __('tickets')['hotel']['consumption_tickets']['global_quantities'] }}
            &nbsp;{{ count($chargesCount) }}

            <br><br>
            {{ __('tickets')['hotel']['consumption_tickets']['amount'] }}
            &nbsp;{{ \App\Helpers\Formats\FormatCurrencyHelper::formatCurrency( number_format($totalCharges, 2) ) }}

            <br>
            {{ __('tickets')['hotel']['consumption_tickets']['iva'] }}
            &nbsp;{{ \App\Helpers\Formats\FormatCurrencyHelper::formatCurrency( number_format(($totalCharges * 0.16) , 2) ) }}

            <br><u><b>
                {{ __('tickets')['hotel']['consumption_tickets']['total'] }}
                &nbsp;{{ \App\Helpers\Formats\FormatCurrencyHelper::formatCurrency( number_format(($totalCharges * 1.16) , 2), false) }}
            </u></b>

        </p>

        {{-- Redes Sociales --}}
        <p class="text-center">
            {{ __('tickets')['hotel']['consumption_tickets']['acknowledgments'] }}

            @if($hotel->business_phone != '')
                <br>
                {{ __('tickets')['hotel']['consumption_tickets']['phone'] }}
                {{$hotel->business_phone}}
            @endif
        </p>
    </div>

    <button class="mt-4 btn btn-success oculto-impresion" onclick="imprimir()">
        {{ __('tickets')['hotel']['consumption_tickets']['print'] }}
    </button>

    {{-- Print Control --}}
    <script>
        function imprimir() {
            window.print();
        }
    </script>

</body>

</html>
