<script setup lang="ts">
import {Flight, SharedProps, User} from "@/Types/types";
import AirlineLogo from "@/Components/FlightsGoneBy/AirlineLogo.vue";
import AircraftToolTip from "@/Components/FlightsGoneBy/AircraftToolTip.vue";
import UserFlightContextMenu from "@/Components/FlightsGoneBy/UserFlightContextMenu.vue";
import {usePage} from "@inertiajs/vue3";
import Mono from "@/Components/FlightsGoneBy/Mono.vue";
import BoardingPassEndpoint from "@/Components/FlightsGoneBy/BoardingPasses/BoardingPassEndpoint.vue";
import BoardingPassStat from "@/Components/FlightsGoneBy/BoardingPasses/BoardingPassStat.vue";

defineProps<{
    flight: Flight
    showTooltips?: boolean
    canEdit?: boolean
    user?: User
}>()

const page = usePage<SharedProps>().props

</script>

<template>
    <div class="boarding-pass">
        <div class="pass-header" :class="`class-${flight.flight_class?.internal_name}-global`">
            <Mono v-if="flight.flight_class?.name !== 'Unspecified'" class="pass-header-class" uppercase smallest largeSpacing>
                {{ flight.flight_class?.name }}
            </Mono>
            <span v-else></span>
            <UserFlightContextMenu v-if="user" :profile-user="user" :flight="flight" :can-edit="canEdit ?? false" referrer="boarding-passes"/>
        </div>

        <div class="pass-body">
            <div class="pass-route">
                <BoardingPassEndpoint :airport="flight.departure_airport" :date="flight.departure_date_display" :time="flight.departure_time_display" />

                <div class="pass-centre">
                    <AirlineLogo :airline="flight.airline" size="44" class="pass-logo" />
                    <Mono class="pass-flight-number">{{ flight.flight_number }}</Mono>
                    <div class="pass-airline-name">{{ flight.airline?.name }}</div>
                    <AircraftToolTip v-if="flight.aircraft?.designator" :aircraft="flight.aircraft">
                        <div v-if="flight.aircraft?.designator" class="pass-aircraft">{{ flight.aircraft.manufacturer_code}} {{flight.aircraft.model_full_name}}</div>
                    </AircraftToolTip>
                </div>

                <BoardingPassEndpoint :dayDifference="flight.arrival_day_difference" right :airport="flight.arrival_airport" :date="flight.arrival_date_display" :time="flight.arrival_time_display" />
            </div>

            <div v-if="flight.duration_display || flight.distance || flight.seat_number" class="pass-tear">
                <div class="pass-tear-notch pass-tear-notch--left" />
                <div class="pass-tear-notch pass-tear-notch--right" />
                <div v-if="flight.duration_display || flight.distance " class="pass-stats-row">
                    <BoardingPassStat v-if="flight.seat_number" label="Seat" :value="flight.seat_number" />
                    <span class="pass-stat-divider" v-if="flight.duration_display && flight.distance">·</span>
                    <BoardingPassStat label="Duration" :value="flight.duration_display" />
                    <span class="pass-stat-divider" v-if="flight.duration_display && flight.distance">·</span>
                    <BoardingPassStat label="Distance" :value="flight.distance" isDistance />
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped>


.pass-stats-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    background-image: repeating-linear-gradient(
        to right,
        rgba(255,255,255,0.08) 0px,
        rgba(255,255,255,0.08) 6px,
        transparent 6px,
        transparent 12px
    );
    background-size: 100% 1px;
    background-repeat: no-repeat;
    background-position: top center;
}

.pass-tear {
    position: relative;
    margin-top: 1rem;
}

.pass-tear-notch {
    position: absolute;
    top: 0;
    width: 15px;
    height: 15px;
    background: #0e1018; /* match your page background */
    border-radius: 50%;
    transform: translateY(-50%);
    z-index: 1;
}

.pass-tear-notch--left  { left: -1.6rem; }  /* bleeds into the padding */
.pass-tear-notch--right { right: -1.6rem; }

.pass-stat-divider {
    color: #334;
    font-size: 1rem;
    line-height: 1;
    margin-top: 0.5rem;
}

.boarding-pass {
    background: #181b24;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.06);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.pass-header {
    display: flex;
    align-items: center;
    justify-content: space-between; /* was flex-end */
    padding: 0.5rem 0.85rem;
    min-height: 2rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}



.pass-body {
    padding: 1.25rem 1.25rem 1rem;
}

.pass-route {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.5rem;
}


.pass-centre {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0 0.5rem;
}

.pass-logo { opacity: 0.9; }

.pass-flight-number {
    font-weight: 700;
}

.pass-airline-name {
    font-family: 'Barlow', sans-serif;
    font-size: 0.72rem;
    color: #778899;
    text-align: center;
}

.pass-aircraft {
    font-size: 0.65rem;
    color: #445566;
    letter-spacing: 0.06em;
    white-space: nowrap
}
</style>
