@extends('public-booking.layouts.shell')

@section('title', $hotel->name . ' — ' . ($hotel->public_site_tagline ?: 'Welcome'))

@php
    $dNavHome = $hotel->getPublicSiteSetting('nav_label_1', 'Home');
    $dNavContact = $hotel->getPublicSiteSetting('nav_label_4', 'Contact');
    $dirLbl = $hotel->getPublicSiteSetting('diamond_direct_label', 'Book directly');
    $dirOpt = $hotel->getPublicSiteSetting('diamond_direct_option', 'Exclusive benefits');
    $dHero = $hotel->public_site_tagline ?: 'NATURE HAS A SECRET';
    $dSub = $hotel->getPublicSiteSetting('diamond_sub', $hotel->public_site_hero_kicker);
    if (! filled($dSub)) {
        $dSub = 'a dreamy hotel on a magnificent island.';
    }
    $roomsK = $hotel->getPublicSiteSetting('rooms_section_kicker', 'Stay');
    $roomsT = $hotel->getPublicSiteSetting('rooms_section_title', 'Rooms & suites');
    $g = isset($guests) ? (int) $guests : (int) (request('guests', 2) ?: 2);
    $g = $g < 1 ? 1 : ($g > 20 ? 20 : $g);
    $nights = max(1, (int) request('nights', 3));
    $nights = $nights > 30 ? 30 : $nights;
    $fb = $hotel->getPublicSiteSetting('social_facebook', '');
    $tw = $hotel->getPublicSiteSetting('social_twitter', '');
    $ig = $hotel->getPublicSiteSetting('social_instagram', '');
    $yt = $hotel->getPublicSiteSetting('social_youtube', '');
@endphp

@push('head')
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,500;0,600;0,700;1,500&family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    @include('public-booking.partials.theme-variables', ['hotel' => $hotel])
    <style>
        * { box-sizing: border-box; }
        .d6 { margin: 0; min-height: 100vh; display: flex; font-family: 'Inter', system-ui, sans-serif; color: #111; background: #fff; }
        .d6-side {
            width: 72px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; padding: 1rem 0;
            border-right: 1px solid #eee; background: #fff; z-index: 30;
        }
        .d6-burger { width: 40px; height: 40px; background: #0a0a0a; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1rem; cursor: default; }
        .d6-side-mid { flex: 1; display: flex; align-items: center; justify-content: center; padding: 0.5rem; }
        .d6-vert { writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; font-size: 0.65rem; letter-spacing: 0.12em; color: #333; line-height: 1.6; }
        .d6-vert a { color: inherit; text-decoration: none; }
        .d6-side-soc { display: flex; flex-direction: column; gap: 0.75rem; padding-bottom: 0.5rem; }
        .d6-side-soc a { color: #111; font-size: 0.9rem; opacity: 0.85; }
        .d6-side-soc a:hover { opacity: 1; }
        .d6-main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
        .d6-top {
            position: fixed; z-index: 20; top: 0; left: 72px; right: 0; height: 4rem;
            display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 0.75rem 1rem;
            padding: 0 1.5rem; background: rgba(255,255,255,0.95); border-bottom: 1px solid rgba(0,0,0,0.06);
        }
        .d6-top > div:first-of-type { justify-self: start; min-width: 0; }
        .d6-top__nav {
            grid-column: 2;
            justify-self: center;
            display: flex; flex-wrap: wrap; justify-content: center; gap: 0.25rem 1.25rem;
        }
        .d6-top__nav a { color: #333; text-decoration: none; font-size: 0.78rem; font-weight: 500; }
        .d6-top__nav a:hover { color: #0a0a0a; }
        .d6-book-cta {
            grid-column: 3; justify-self: end;
            background: #0a0a0a; color: #fff; border: 0; padding: 0.5rem 1.1rem; font-size: 0.6rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; cursor: pointer; text-decoration: none; white-space: nowrap;
        }
        .d6-hero { position: relative; flex: 1; min-height: min(100vh, 900px); margin-top: 4rem; display: flex; flex-direction: column; }
        .d6-hero__bg { position: absolute; inset: 0; z-index: 0; }
        .d6-hero__bg .ph-hero { position: absolute; inset: 0; min-height: 100%; }
        .d6-hero__bg .ph-dim { background: linear-gradient(180deg, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.35) 100%); }
        .d6-dia {
            position: absolute; z-index: 1; right: 6%; top: 50%; transform: translateY(-50%) rotate(45deg);
            width: min(45vw, 320px); height: min(45vw, 320px);
            border: 1px solid rgba(255,255,255,0.5); border-radius: 2px; pointer-events: none; opacity: 0.9;
        }
        @media (max-width: 800px) { .d6-dia { opacity: 0.35; } }
        .d6-hero__txt {
            position: relative; z-index: 2; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
            padding: 2rem 1.5rem 11rem; max-width: 40rem; margin: 0 auto;
        }
        .d6-hero__txt h1 {
            font-family: 'Playfair Display', Georgia, serif; color: #fff; font-size: clamp(1.5rem, 4vw, 2.5rem);
            font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; margin: 0 0 0.75rem; line-height: 1.2;
        }
        .d6-hero__txt p.sub {
            font-family: 'Playfair Display', Georgia, serif; font-size: 1.05rem; font-style: italic; font-weight: 400; color: rgba(255,255,255,0.95); margin: 0; line-height: 1.5;
        }
        .d6-scroll { margin-top: 2rem; display: flex; flex-direction: column; align-items: center; gap: 0.35rem; color: rgba(255,255,255,0.85); }
        .d6-scroll__line { width: 1px; height: 2.5rem; background: rgba(255,255,255,0.7); }
        .d6-scroll i { font-size: 0.9rem; opacity: 0.9; }
        .d6-book { position: absolute; z-index: 4; left: 50%; transform: translateX(-50%); bottom: 2rem; width: min(94%, 920px);
            display: flex; flex-wrap: wrap; align-items: stretch; background: #fff; border-radius: 2px; box-shadow: 0 16px 48px rgba(0,0,0,0.2); }
        .d6-book .d6-bcell { flex: 1 1 140px; padding: 0.85rem 1rem; border-left: 1px solid #e5e5e5; display: flex; flex-direction: column; justify-content: center; gap: 0.25rem; }
        .d6-book .d6-bcell:first-child { border-left: 0; }
        .d6-book .d6-blab { font-size: 0.55rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: #9ca3af; }
        .d6-book .d6-bval { font-size: 0.9rem; font-weight: 600; color: #111; }
        .d6-book .d6-pseudo-select { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.88rem; font-weight: 500; }
        .d6-book input[type="date"] { border: 0; font: inherit; font-weight: 600; width: 100%; padding: 0; }
        .d6-nights { display: flex; align-items: center; justify-content: space-between; gap: 0.35rem; }
        .d6-nights button {
            width: 28px; height: 28px; border: 1px solid #ddd; background: #fafafa; border-radius: 2px; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0;
        }
        .d6-nights input { width: 2rem; text-align: center; border: 0; font: inherit; font-weight: 700; }
        .d6-book .d6-bbtn { background: #0a0a0a; color: #fff; border: 0; font-size: 0.58rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; cursor: pointer; min-width: 7.5rem; }
        @media (max-width: 700px) { .d6-top { left: 0; padding-left: 1rem; } .d6-hero { margin-top: 3.5rem; } }
        @media (max-width: 600px) {
            .d6 { flex-direction: column; }
            .d6-side { width: 100%; flex-direction: row; height: auto; border-right: 0; border-bottom: 1px solid #eee; padding: 0.5rem 1rem; }
            .d6-side-mid { display: none; }
            .d6-side-soc { flex-direction: row; gap: 0.6rem; }
            .d6-top { left: 0; position: fixed; }
        }
        .d6-rooms { padding: 3rem 1rem 4rem; background: #f8fafc; }
        .d6-rooms h2 { font-family: 'Playfair Display', serif; font-size: 1.5rem; margin: 0.25rem 0 1rem; }
        .d6-rooms .k { font-size: 0.6rem; letter-spacing: 0.2em; text-transform: uppercase; color: #94a3b8; }
        .m-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; max-width: 1000px; margin: 0 auto; }
        .pb-rm-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 1.1rem; }
        .pb-rm-title { font-size: 1.05rem; margin: 0; font-weight: 700; }
        .pb-rm-meta, .pb-rm-desc { color: #64748b; font-size: 0.82rem; margin: 0.35rem 0; }
    </style>
@endpush

@section('content')
<div class="d6">
    <aside class="d6-side" aria-label="Contact & social">
        <div class="d6-burger" title="Menu"><i class="fas fa-bars"></i></div>
        <div class="d6-side-mid">
            <div class="d6-vert">
                <a href="mailto:{{ e($hotel->email) }}">{{ e($hotel->email) }}</a>
                <span> · </span>
                <a href="tel:{{ preg_replace('/\s+/', '', $hotel->phone) }}">{{ e($hotel->phone) }}</a>
            </div>
        </div>
        <div class="d6-side-soc">
            @if(filled($fb))<a href="{{ e($fb) }}" target="_blank" rel="noopener" aria-label="Facebook"><i class="fab fa-facebook-f"></i></a>@endif
            @if(filled($tw))<a href="{{ e($tw) }}" target="_blank" rel="noopener" aria-label="Twitter"><i class="fab fa-x-twitter"></i></a>@endif
            @if(filled($ig))<a href="{{ e($ig) }}" target="_blank" rel="noopener" aria-label="Instagram"><i class="fab fa-instagram"></i></a>@endif
            @if(filled($yt))<a href="{{ e($yt) }}" target="_blank" rel="noopener" aria-label="YouTube"><i class="fab fa-youtube"></i></a>@endif
        </div>
    </aside>
    <div class="d6-main">
        <header class="d6-top">
            <div>@include('public-booking.partials.site-logo', ['logoVariant' => 'on-light', 'logoSize' => 'md'])</div>
            <nav class="d6-top__nav" aria-label="Main">
                <a href="{{ url()->current() }}">{{ e($dNavHome) }}</a>
                <a href="mailto:{{ e($hotel->email) }}">{{ e($dNavContact) }}</a>
            </nav>
            <a class="d6-book-cta" href="#d6-book-bar">{{ $hotel->getPublicSiteSetting('diamond_header_book', 'Book now') }}</a>
        </header>

        <section class="d6-hero">
            <div class="d6-hero__bg" aria-hidden="true">
                @include('public-booking.partials.hero-backdrop', ['variant' => '1'])
            </div>
            <div class="d6-dia" aria-hidden="true"></div>
            <div class="d6-hero__txt">
                <h1>{{ $dHero }}</h1>
                <p class="sub">{{ $dSub }}</p>
                <div class="d6-scroll" aria-hidden="true">
                    <div class="d6-scroll__line"></div>
                    <i class="fas fa-computer-mouse" style="font-size:1.1rem;"></i>
                </div>
            </div>

            <form class="d6-book" id="d6-book-bar" method="get" action="{{ url('/book/' . $hotel->slug) }}">
                <div class="d6-bcell">
                    <span class="d6-blab">{{ $dirLbl }}</span>
                    <div class="d6-pseudo-select d6-bval">
                        <span>{{ $dirOpt }}</span>
                        <i class="fas fa-chevron-down" style="font-size:0.7rem;opacity:0.5;"></i>
                    </div>
                </div>
                <div class="d6-bcell">
                    <span class="d6-blab">Check in</span>
                    <input type="date" name="check_in" value="{{ e($checkIn ?? '') }}" required>
                </div>
                <div class="d6-bcell">
                    <span class="d6-blab">Check out</span>
                    <input type="date" name="check_out" value="{{ e($checkOut ?? '') }}" required>
                </div>
                <div class="d6-bcell">
                    <span class="d6-blab">Nights</span>
                    <div class="d6-nights" data-d6-nights>
                        <button type="button" data-act="dec" aria-label="Fewer nights">−</button>
                        <input type="number" name="nights" id="d6nights" value="{{ $nights }}" min="1" max="30">
                        <button type="button" data-act="inc" aria-label="More nights">+</button>
                    </div>
                </div>
                <div class="d6-bcell" style="flex:0 0 auto;">
                    <span class="d6-blab" style="visibility:hidden;">—</span>
                    <input type="hidden" name="guests" value="{{ $g }}">
                    <button type="submit" class="d6-bbtn" style="height:100%; min-height:3.5rem; width:100%;">{{ $hotel->getPublicSiteSetting('diamond_form_book', 'Book now') }}</button>
                </div>
            </form>
        </section>

        <section class="d6-rooms" id="d6-rooms">
            <p class="k">{{ $hotel->guestPageText($roomsK) }}</p>
            <h2>{{ $hotel->guestPageText($roomsT) }}</h2>
            <div class="m-grid">
                @if(($bookableRooms ?? collect())->count() > 0 || $roomTypes->count()) @include('public-booking.partials.room-list') @else
                    <p style="color:#64748b; grid-column:1/-1; text-align:center;">Contact the hotel to book.</p>
                @endif
            </div>
        </section>
        <footer style="text-align:center; padding:1.5rem;">
            @include('public-booking.partials.guest-site-footer-block')
        </footer>
    </div>
</div>
<script>
(function () {
    var w = document.querySelector('[data-d6-nights]');
    if (!w) return;
    var inp = w.querySelector('#d6nights');
    function clamp(n) { n = parseInt(n, 10) || 1; return n < 1 ? 1 : (n > 30 ? 30 : n); }
    w.addEventListener('click', function (e) {
        var t = e.target;
        if (t.getAttribute('data-act') === 'inc') { inp.value = clamp(parseInt(inp.value, 10) + 1); }
        if (t.getAttribute('data-act') === 'dec') { inp.value = clamp(parseInt(inp.value, 10) - 1); }
    });
})();
</script>
@endsection
