<script setup>
import { ArrowUpRight, Mail, MapPin, Phone } from 'lucide-vue-next'
import { usePublicSiteLocations } from '~/composables/usePublicSiteLocations'
import { useSiteContent } from '~/content/site'
import { normalizePublicInternalPath } from '~/utils/public-routes'

const year = new Date().getFullYear()
const { locale } = usePublicLocale()
const ui = usePublicUi()
const siteContent = useSiteContent()
const { locations } = usePublicSiteLocations()

const siteSocialLinks = computed(() => siteContent.footerSocialLinks.value || [])
const business = computed(() => siteContent.business.value || {})
const contactPhone = computed(() => business.value.telephone || siteContent.siteSettings.value?.supportPhone || '')
const contactEmail = computed(() => business.value.email || siteContent.siteSettings.value?.supportEmail || '')
const serviceCityLine = computed(() => {
  const locationCities = [...new Set(
    (locations.value || [])
      .map((location) => String(location?.city || '').trim())
      .filter(Boolean),
  )]

  const primaryCity = String(business.value.address?.addressLocality || '').trim()
  const extraCities = locationCities.filter((city) => city !== primaryCity)

  return extraCities.length ? extraCities.join(', ') : ''
})

const contactAddressLines = computed(() => {
  const address = business.value.address || {}
  const lines = [
    [address.addressLocality, address.addressCountry].filter(Boolean).join(', '),
    address.streetAddress,
  ].filter(Boolean)

  if (serviceCityLine.value) {
    lines.push(serviceCityLine.value)
  }

  return lines.length ? lines : ['Tbilisi, Georgia']
})

function footerRoute(path) {
  return normalizePublicInternalPath(path, locale.value)
}
</script>

<template>
  <footer class="bg-[#0a0a0a] text-slate-300 border-t border-white/5">
    <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
      <div class="py-16 md:py-20 border-b border-white/10 flex flex-col lg:flex-row lg:items-center justify-between gap-8">
        <div class="max-w-3xl">
          <p class="text-xs font-bold uppercase tracking-[0.35em] text-slate-500 mb-4">
            {{ ui.footer.explore }}
          </p>
          <h2 class="text-3xl md:text-5xl font-black text-white leading-tight">
            {{ ui.footer.journeyPrefix }} <span class="text-brand-orange">{{ ui.footer.journeyAccent }}</span>
          </h2>
          <p class="mt-4 max-w-2xl text-sm md:text-base text-slate-400 leading-relaxed">
            {{ ui.footer.brandDescription }}
          </p>
        </div>

        <NuxtLink
          :to="footerRoute('/rent')"
          class="inline-flex items-center justify-center gap-2 w-full sm:w-auto rounded-full bg-brand-orange px-6 py-3.5 text-sm font-black uppercase tracking-wider text-slate-900 hover:scale-[1.02] transition-transform duration-300 shrink-0"
        >
          {{ ui.footer.book }}
          <ArrowUpRight class="w-5 h-5" />
        </NuxtLink>
      </div>

      <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-12 lg:gap-16 py-16 border-b border-white/10">
        <div class="flex flex-col justify-between">
          <div>
            <h3 class="text-white font-black text-2xl tracking-tighter mb-6">BENT.GE</h3>
            <p class="text-sm opacity-70 leading-relaxed max-w-xs">
              {{ ui.footer.brandDescription }}
            </p>
          </div>
        </div>

        <div>
          <h4 class="text-white font-bold uppercase tracking-widest text-xs mb-6 opacity-50">{{ ui.footer.explore }}</h4>
          <ul class="space-y-4 text-sm font-medium">
            <li><NuxtLink :to="footerRoute('/about')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.aboutUs }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/corporate')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.b2bLongTerm }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/services')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.additionalServices }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/partners')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.affiliatesPartners }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/reviews')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.clientReviews }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/vehicles')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.ourFleet }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/locations')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.locations }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/blog')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.routesBlog }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/news')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.newsUpdates }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/offers')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.specialOffers }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/driving-guide')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.drivingGuide }}</NuxtLink></li>
          </ul>
        </div>

        <div>
          <h4 class="text-white font-bold uppercase tracking-widest text-xs mb-6 opacity-50">{{ ui.footer.support }}</h4>
          <ul class="space-y-4 text-sm font-medium">
            <li><NuxtLink :to="footerRoute('/help')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.helpCenter }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/faq')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.faq }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/contact')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.contact }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/rental-info')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.rentalTerms }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/privacy')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.privacyPolicy }}</NuxtLink></li>
            <li><NuxtLink :to="footerRoute('/terms')" class="inline-block hover:text-brand-orange hover:translate-x-1 transition-all duration-300">{{ ui.footer.termsConditions }}</NuxtLink></li>
          </ul>
        </div>

        <div>
          <h4 class="text-white font-bold uppercase tracking-widest text-xs mb-6 opacity-50">{{ ui.footer.contact }}</h4>
          <ul class="space-y-4 text-sm font-medium">
            <li v-if="contactPhone">
              <a :href="`tel:${contactPhone}`" class="group flex items-center gap-3 hover:text-brand-orange transition-colors">
                <span class="w-8 h-8 rounded-full bg-white/5 flex items-center justify-center group-hover:bg-brand-orange/20 transition-colors">
                  <Phone class="w-4 h-4" />
                </span>
                {{ contactPhone }}
              </a>
            </li>
            <li v-if="contactEmail">
              <a :href="`mailto:${contactEmail}`" class="group flex items-center gap-3 hover:text-brand-orange transition-colors">
                <span class="w-8 h-8 rounded-full bg-white/5 flex items-center justify-center group-hover:bg-brand-orange/20 transition-colors">
                  <Mail class="w-4 h-4" />
                </span>
                {{ contactEmail }}
              </a>
            </li>
            <li class="flex items-start gap-3 text-slate-500">
              <span class="w-8 h-8 rounded-full bg-white/5 flex items-center justify-center shrink-0">
                <MapPin class="w-4 h-4" />
              </span>
              <span class="mt-1">
                <template v-for="(line, index) in contactAddressLines" :key="`${line}-${index}`">
                  {{ line }}<br v-if="index < contactAddressLines.length - 1">
                </template>
              </span>
            </li>
          </ul>
        </div>
      </div>

      <div class="py-8 flex flex-col md:flex-row justify-between items-center gap-4 text-xs font-bold uppercase tracking-widest text-slate-600">
        <p>&copy; {{ year }} {{ ui.footer.rightsReserved }}</p>
        <div class="flex gap-6">
          <template v-for="item in siteSocialLinks" :key="item.id">
            <a
              v-if="item.href"
              :href="item.href"
              class="hover:text-white transition-colors"
              target="_blank"
              rel="noreferrer"
            >
              {{ item.label }}
            </a>
            <span v-else class="opacity-50 cursor-default">
              {{ item.label }}
            </span>
          </template>
        </div>
      </div>
    </div>
  </footer>
</template>
