<script setup lang="ts">
import GradientText from "@/components/dredgy/GradientText.vue";
import TourQuickFacts from "@/components/TourNavigator/TourQuickFacts.vue";
import TourOverviewActions from "@/components/TourNavigator/TourOverviewActions.vue";
import type {Tour, TourDay} from "@/types";
import {ref} from "vue";

interface Props {
    tour: Tour;
    tourDay?: TourDay;
}
const currentStep = ref(1)
const props = defineProps<Props>();
</script>

<template>
    <section v-show-on-intersect class="no-gap tour-overview chamfer-tl">
        <div
            :style="{ backgroundImage: `url('/img/tours/${tour.internal_name}.jpg')` }"
            style="background-attachment: scroll; background-size: cover; background-position: center"
            class="tour-overview-header"
        >
            <h1 class="glass chamfer">
                <GradientText>{{ tour.name }}</GradientText>
            </h1>
        </div>
        <div class="tour-overview-body">
            <section class="tour-content">
                <article class="tour-description">
                    <div v-if="tour.tour_days?.length" class="custom-stepper">
                        <!-- Horizontal Stepper Header -->
                        <div class="stepper-header">
                            <button
                                v-for="(day, index) in tour.tour_days"
                                :key="day.id"
                                class="stepper-step"
                                :class="{
                  active: currentStep === index + 1,
                  complete: currentStep > index + 1
                }"
                                @click="currentStep = index + 1"
                            >
                                <span class="step-number">Day {{ index + 1 }}</span>
                            </button>
                        </div>

                        <!-- Stepper Content -->
                        <div class="stepper-content">
                            <div
                                v-for="(day, index) in tour.tour_days"
                                :key="day.id"
                                v-show="currentStep === index + 1"
                                class="step-item"
                            >
                                <h2 class="text-h3 font-weight-bold mb-2">
                                    Day {{ index + 1 }}
                                </h2>
                                <p class="text-h6 text-grey mb-6">
                                    {{ day.description }}
                                </p>

                                <div v-if="day.image" class="mb-6">
                                    <v-img
                                        :src="day.image"
                                        :alt="`Day ${index + 1}`"
                                        class="rounded"
                                        height="300"
                                        cover
                                    />
                                </div>

                                <div class="text-body1 line-height-relaxed mb-6">
                                    {{ day.content }}
                                </div>

                                <div class="d-flex gap-3">
                                    <v-btn
                                        v-if="index > 0"
                                        variant="outlined"
                                        @click="currentStep = index"
                                    >
                                        Previous
                                    </v-btn>
                                    <v-btn
                                        v-if="index < tour.tour_days.length - 1"
                                        color="primary"
                                        @click="currentStep = index + 2"
                                    >
                                        Next
                                    </v-btn>
                                    <v-btn
                                        v-else
                                        color="success"
                                        disabled
                                    >
                                        Tour Complete
                                    </v-btn>
                                </div>
                            </div>
                        </div>
                    </div>
                </article>
            </section>
            <aside class="chamfer chamfer-tl">
                <TourQuickFacts :tour="tour" />
            </aside>
        </div>
    </section>
</template>

<style scoped>
.tour-overview {
    margin: 5%;
    background: var(--sidebar-background);
    align-self: center;
    justify-self: center;
    min-height: 70vh;
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
}

.tour-overview-header {
    width: 100%;
    height: auto;
    flex-shrink: 0;
    position: relative;
    min-height: 300px;
}

.tour-overview-header h1 {
    position: absolute;
    bottom: 0;
    transform: translateY(50%) translateX(-50%);
    left: 37.5%;
    padding: 0.2em 0.75em;
    text-align: center;
    font-size: 2.5em;
    margin: 0;
    z-index: 999;
}

.tour-overview-body {
    flex: 1;
    width: 100%;
    display: flex;
    gap: 2rem;
}

.tour-overview-body .tour-content {
    flex: 1;
    padding: 2em;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
}

.tour-description {
    width: 100%;
    display: flex;
    flex-direction: column;
}

.tour-overview-body aside {
    display: flex;
    flex-direction: column;
    flex-basis: 25%;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .tour-overview {
        height: auto;
    }

    .tour-overview-header h1 {
        font-size: 1.5em;
        left: 50%;
    }

    .tour-overview-body {
        flex-direction: column;
        gap: 1rem;
    }

    .tour-overview-body aside {
        order: 1;
        height: auto;
        min-height: 0;
    }

    .tour-overview-body .tour-content {
        padding-top: 0.5em;
        order: 2;
    }
}

.chamfer {
    --cut: 20px;
    clip-path: polygon(
        0 0,
        calc(100% - var(--cut)) 0,
        100% var(--cut),
        100% 100%,
        var(--cut) 100%,
        0 calc(100% - var(--cut))
    );
}

.chamfer-tl {
    --cut: 20px;
    clip-path: polygon(
        var(--cut) 0,
        100% 0,
        100% 100%,
        0 100%,
        0 0
    );
}

.line-height-relaxed {
    line-height: 1.6;
}

.custom-stepper {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.stepper-header {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding: 1rem 0;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.stepper-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.stepper-step:hover {
    border-color: rgba(255, 255, 255, 0.6);
    color: rgba(255, 255, 255, 0.9);
}

.stepper-step.active {
    border-color: #1976d2;
    background-color: rgba(25, 118, 210, 0.1);
    color: #1976d2;
}

.stepper-step.complete {
    border-color: #4caf50;
    color: #4caf50;
}

.step-number {
    font-weight: bold;
    font-size: 1.2em;
}

.step-label {
    font-size: 0.875em;
}

.stepper-content {
    flex: 1;
    overflow-y: auto;
}

.step-item {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
</style>
