<template>
  <PageMeta
      :title="$t('page_title')"
      :description="$t('page_description')"
  />

  <div class="rental-container">
    <!-- Main Image Section -->
    <div class="main-image-container">
      <v-img
        src="/images/photos/IMG_2216.min.JPG"
        :alt="$t('main_image_alt')"
        cover
        eager
        :height="$vuetify.display.xs ? 300 : 500"
        class="main-image rounded-lg"
        :loading="loading"
        @click="selectImage('/images/photos/IMG_2216.min.JPG')"
        style="cursor: pointer; max-width: 100%;"
      ></v-img>
    </div>

    <!-- Thumbnails Section -->
    <div class="thumbnails-container mt-4">
      <v-row>
        <v-col v-for="(image, index) in thumbnailImages" :key="index" cols="12" sm="6" md="4">
          <v-img
            :src="image.src"
            :alt="image.alt"
            height="150"
            max-height="150"
            cover
            eager
            class="thumbnail rounded-lg"
            @click="selectImage(image.src)"
          ></v-img>
        </v-col>
      </v-row>
    </div>

    <!-- Description Section -->
    <div class="description-container mt-10">
      <h2>{{ $t('welcome_heading') }}</h2>
      <v-card class="pa-5 rounded-lg elevation-2" style="max-width: 100%; overflow-wrap: break-word;">
        <p class="text-body-1">
          {{ $t('welcome_description') }}
          
          <template v-if="$t('welcome_residencies_intro')">
            
            {{ ' ' + $t('welcome_residencies_intro') }}
            
            <a href="https://semillas-asso.fr/" target="_blank" rel="noopener noreferrer">semillas-asso.fr</a>).
          </template>
        </p>
      </v-card>
    </div>

    <!-- Features Summary Section -->
    <div class="features-container mt-10">
      <h2>{{ $t('features_heading') }}</h2>
      <v-row>
        <v-col cols="12" md="6">
          <v-card class="pa-5 h-100 rounded-lg elevation-2" style="max-width: 100%; overflow-wrap: break-word;">
            <h3 class="text-h6 mb-4">{{ $t('general_info_heading') }}</h3>
            <ul class="feature-list">
              <li>{{ $t('general_info_contact_note') }}</li>
              <li>{{ $t('general_info_item_1') }}</li>
              <!-- Removed price and minimum duration -->
              <!-- <li>{{ $t('general_info_item_2') }}</li> -->
              <!-- <li>{{ $t('general_info_item_3') }}</li> -->
              <!-- <li>{{ $t('general_info_item_4') }}</li> -->
              <li>{{ $t('general_info_item_5') }}</li>
              <!-- Removed deposit mention -->
              <!-- <li>{{ $t('general_info_item_8') }}</li> -->
            </ul>
          </v-card>
        </v-col>
        <v-col cols="12" md="6">
          <v-card class="pa-5 h-100 rounded-lg elevation-2" style="max-width: 100%; overflow-wrap: break-word;">
            <h3 class="text-h6 mb-4">{{ $t('equipment_heading') }}</h3>
            <ul class="feature-list">
              <li>{{ $t('equipment_item_1') }}</li>
              <li>{{ $t('equipment_item_2') }}</li>
              <li>{{ $t('equipment_item_3') }}</li>
              <li>{{ $t('equipment_item_4') }}</li>
              <li>{{ $t('equipment_item_5') }}</li>
              <li>{{ $t('equipment_item_6') }}</li>
            </ul>
          </v-card>
        </v-col>
      </v-row>
    </div>

    <!-- Location Section -->
    <div class="location-container mt-10">
      <h2>{{ $t('location_heading') }}</h2>
      <v-card class="pa-5 rounded-lg elevation-2" style="max-width: 100%; overflow-wrap: break-word;">
        <ul class="feature-list">
          <li>{{ $t('location_item_1') }}</li>
          <li>{{ $t('location_item_2') }}</li>
          <li>{{ $t('location_item_3') }}</li>
          <li>{{ $t('location_item_4') }}</li>
        </ul>
      </v-card>
    </div>

    <!-- Conditions Section -->
    <div class="conditions-container mt-10">
      <h2>{{ $t('conditions_heading') }}</h2>
      <v-card class="pa-5 rounded-lg elevation-2" style="max-width: 100%; overflow-wrap: break-word;">
        <ul class="feature-list">
          <li>{{ $t('conditions_item_1') }}</li>
          <li>{{ $t('conditions_item_2') }}</li>
          <li>{{ $t('conditions_item_3') }}</li>
          <li>{{ $t('conditions_item_4') }}</li>
        </ul>
      </v-card>
    </div>

    <!-- Tourism Section -->
    <div class="tourism-container mt-10">
      <h2>{{ $t('tourism_heading') }}</h2>
      <v-card class="pa-5 rounded-lg elevation-2" style="max-width: 100%; overflow-wrap: break-word;">
        <v-row>
          <v-col cols="12" md="6">
            <v-card class="px-4 h-100 rounded-lg elevation-1" style="max-width: 100%; overflow-wrap: break-word;">
              <h3 class="text-h6 mb-3 mt-2">{{ $t('tourism_attractions_heading') }}</h3>
              <ul class="feature-list">
                <li><a href="https://www.tourisme-granville-terre-mer.com/" target="_blank" rel="noopener noreferrer">{{ $t('tourism_link_office') }}</a></li>
                <li><a href="https://www.tourisme-granville-terre-mer.com/decouvrir/grands-espaces/havre-vanlee/" target="_blank" rel="noopener noreferrer">{{ $t('tourism_link_havre') }}</a></li>
                <li><a href="https://www.ouest-france.fr/normandie/brehal-50290/saint-martin-de-brehal-la-plage-familiale-ideale-37ea86ac-4cf8-11f0-a713-daeef56bef5e" target="_blank" rel="noopener noreferrer">{{ $t('tourism_link_beach') }}</a></li>
              </ul>
            </v-card>
          </v-col>
          <v-col cols="12" md="6">
            <v-card class="px-4 h-100 rounded-lg elevation-1" style="max-width: 100%; overflow-wrap: break-word;">
              <h3 class="text-h6 mb-3 mt-2">{{ $t('tourism_activities_heading') }}</h3>
              <ul class="feature-list">
                <li><a href="https://www.attitude-manche.fr/" target="_blank" rel="noopener noreferrer">{{ $t('tourism_link_manche') }}</a></li>
                <li><a href="https://ileschausey.com/" target="_blank" rel="noopener noreferrer">{{ $t('tourism_link_chausey') }}</a></li>
                <li><a href="https://www.ot-montsaintmichel.com/" target="_blank" rel="noopener noreferrer">{{ $t('tourism_link_mont_st_michel') }}</a></li>
              </ul>
            </v-card>
          </v-col>
        </v-row>
      </v-card>
    </div>

    <!-- Contact Section -->
    <div id="contact" class="contact-container mt-10">
      <h2>{{ $t('contact_heading') }}</h2>
      <v-card class="pa-5 rounded-lg elevation-2" style="max-width: 100%; overflow-wrap: break-word;">
        <Contact />
      </v-card>
    </div>

    <!-- Image Modal -->
    <v-dialog v-model="showImageModal" max-width="90vw" content-class="image-modal-dialog">
      <v-card class="image-modal-card">
        <v-btn icon class="close-btn" @click="showImageModal = false">
          <v-icon>fas fa-times</v-icon>
        </v-btn>
        <v-card-text class="text-center pa-0">
          <v-img
            :src="selectedImageSrc"
            class="enlarged-image"
            :loading="loading"
            max-width="100%"
            contain
          >
            <template v-slot:placeholder>
              <div class="d-flex align-center justify-center" style="height: 300px;">
                <v-progress-circular indeterminate color="primary"></v-progress-circular>
              </div>
            </template>
          </v-img>
        </v-card-text>
      </v-card>
    </v-dialog>
  </div>
</template>

<script setup lang="ts">
import { useDisplay, useTheme } from 'vuetify'
import type { Ref } from '@vue/reactivity'
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'

const i18n = useI18n()
const theme = useTheme()

const loading = ref(true)
const imageErrors = ref<string[]>([])
const imagesLoaded = ref<string[]>([])

// Variables for image modal
const showImageModal = ref(false)
const selectedImageSrc = ref('')

// List of thumbnail images
const thumbnailImages = ref([
  { src: '/images/photos/IMG_2219.min.JPG', alt: i18n.t('thumbnail_alt_interior') },
  { src: '/images/photos/IMG_2220.min.JPG', alt: i18n.t('thumbnail_alt_interior') },
  { src: '/images/photos/IMG_2222.min.JPG', alt: i18n.t('thumbnail_alt_interior') },
  { src: '/images/photos/IMG_2223.min.JPG', alt: i18n.t('thumbnail_alt_interior') },
  { src: '/images/photos/IMG_2224.min.JPG', alt: i18n.t('thumbnail_alt_interior') },
  { src: '/images/photos/IMG_2225.min.JPG', alt: i18n.t('thumbnail_alt_interior') },
])

// Function to select an image and show it in the modal
const selectImage = (src: string) => {
  console.log('Selected image:', src)
  selectedImageSrc.value = src
  showImageModal.value = true
}
</script>

<style scoped lang="scss">
.rental-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  width: 100%;
  box-sizing: border-box;
  
  @media (max-width: 600px) {
    padding: 0 8px;
  }
}

.text-body-1 {
  line-height: 1.7;
  margin-bottom: 1rem;
  font-size: 1.05rem;
}

.main-image {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;

  &:hover {
    transform: scale(1.01);
  }
}

.thumbnail {
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease;
  max-width: 100%;
  max-height: 150px;
  object-fit: cover;

  &:hover {
    transform: scale(1.05);
  }
}

.feature-list {
  list-style-type: none;
  padding-left: 0;
  margin: 0.5rem 0;

  li {
    padding: 10px 0;
    position: relative;
    padding-left: 28px;
    margin-bottom: 4px;
    line-height: 1.5;

    &:before {
      content: "•";
      color: rgb(var(--v-theme-primary));
      position: absolute;
      left: 8px;
      font-size: 18px;
      top: 8px;
    }

    &:last-child {
      margin-bottom: 0;
    }
    
    a {
      color: rgb(var(--v-theme-primary));
      text-decoration: none;
      position: relative;
      transition: all 0.3s ease;
      font-weight: 500;
      
      &:hover {
        color: rgba(var(--v-theme-primary), 0.8);
        
        &:after {
          width: 100%;
        }
      }
      
      &:after {
        content: '';
        position: absolute;
        bottom: -2px;
        left: 0;
        width: 0;
        height: 2px;
        background-color: rgba(var(--v-theme-primary), 0.5);
        transition: width 0.3s ease;
      }
    }
  }
}

h2 {
  color: rgb(var(--v-theme-primary));
  font-weight: 700;
  font-size: 1.8rem;
  margin: 2rem 0 1.5rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid rgba(var(--v-theme-primary), 0.3);
  letter-spacing: 0.02em;
}

h3 {
  color: rgb(var(--v-theme-primary));
  font-weight: 600;
  font-size: 1.4rem;
  margin: 1.5rem 0 1rem 0;
  letter-spacing: 0.01em;
}

.enlarged-image {
  border-radius: 0;
  margin: 0 auto;
  max-height: 90vh;
  width: auto;
  max-width: 100%;
  
  @media (max-width: 600px) {
    max-height: 80vh;
  }
}

:deep(.image-modal-dialog) {
  background-color: rgba(0, 0, 0, 0.9);
  padding: 6px;
}

.image-modal-card {
  background: transparent;
  box-shadow: none;
  position: relative;
  overflow: visible;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  background-color: rgba(0, 0, 0, 0.3);
  color: white;
  transition: background-color 0.2s;

  &:hover {
    background-color: rgba(0, 0, 0, 0.5);
  }
}
</style>
