'use client';

import { useState, useEffect } from 'react';
import Link from 'next/link';
import FilmStripSlider from '@/components/FilmStripSlider';
import { HeroBanner, HeroBannerSettings } from '@/types';
import { heroBannersApi } from '@/lib/api';
import { useTranslation } from '@/lib/i18n';

export default function Home() {
  const { t, language } = useTranslation();
  const [banners, setBanners] = useState<HeroBanner[]>([]);
  const [bannerSettings, setBannerSettings] = useState<HeroBannerSettings | undefined>();

  useEffect(() => {
    loadBanners();
  }, []);

  const loadBanners = async () => {
    try {
      const [bannersData, settingsData] = await Promise.all([
        heroBannersApi.getList(language),
        heroBannersApi.getSettings(),
      ]);
      setBanners(bannersData);
      setBannerSettings(settingsData);
    } catch (error) {
      console.error('Failed to load banners:', error);
      // 에러 시 샘플 배너 사용 (FilmStripSlider 내부에서 처리)
    }
  };

  return (
    <div>
      {/* Hero Section with Film Strip Slider */}
      <section className="bg-gradient-to-r from-primary-700 to-primary-900 text-white">
        <div className="container mx-auto px-4 pt-12 pb-4 text-center">
          <h1 className="text-4xl md:text-5xl font-bold mb-4">
            {t.premiumKoreanUsedCars}
          </h1>
          <p className="text-xl md:text-2xl text-primary-100 mb-6">
            {t.qualityVehiclesExported}
          </p>
        </div>

        {/* Film Strip Slider */}
        <FilmStripSlider banners={banners} settings={bannerSettings} />

        <div className="container mx-auto px-4 py-8 text-center">
          <Link
            href="/vehicle-request"
            className="inline-block bg-yellow-500 text-white font-semibold px-8 py-3 rounded-lg hover:bg-yellow-600 transition shadow-lg"
          >
            {t.requestVehicle}
          </Link>
        </div>
      </section>

      {/* Features */}
      <section className="py-16 bg-gray-50">
        <div className="container mx-auto px-4">
          <h2 className="text-3xl font-bold text-center mb-12">{t.whyChooseUs}</h2>
          <div className="grid grid-cols-1 md:grid-cols-3 gap-8">
            <div className="text-center p-6">
              <div className="w-16 h-16 bg-primary-100 text-primary-600 rounded-full flex items-center justify-center mx-auto mb-4">
                <svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
                </svg>
              </div>
              <h3 className="text-xl font-semibold mb-2">{t.qualityAssured}</h3>
              <p className="text-gray-600">{t.qualityAssuredDesc}</p>
            </div>
            <div className="text-center p-6">
              <div className="w-16 h-16 bg-primary-100 text-primary-600 rounded-full flex items-center justify-center mx-auto mb-4">
                <svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                </svg>
              </div>
              <h3 className="text-xl font-semibold mb-2">{t.bestPrices}</h3>
              <p className="text-gray-600">{t.bestPricesDesc}</p>
            </div>
            <div className="text-center p-6">
              <div className="w-16 h-16 bg-primary-100 text-primary-600 rounded-full flex items-center justify-center mx-auto mb-4">
                <svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
                </svg>
              </div>
              <h3 className="text-xl font-semibold mb-2">{t.fullSupport}</h3>
              <p className="text-gray-600">{t.fullSupportDesc}</p>
            </div>
          </div>
        </div>
      </section>

      {/* CTA */}
      <section className="bg-primary-700 text-white py-16">
        <div className="container mx-auto px-4 text-center">
          <h2 className="text-3xl font-bold mb-4">{t.readyToFindYourCar}</h2>
          <p className="text-primary-100 mb-8 max-w-2xl mx-auto">
            {t.browseOurCollection}
          </p>
          <div className="flex justify-center space-x-4">
            <Link
              href="/cars"
              className="bg-white text-primary-700 font-semibold px-6 py-3 rounded-lg hover:bg-primary-100 transition"
            >
              {t.browseCars}
            </Link>
            <Link
              href="/contact"
              className="border-2 border-white text-white font-semibold px-6 py-3 rounded-lg hover:bg-white hover:text-primary-700 transition"
            >
              {t.contactUs}
            </Link>
          </div>
        </div>
      </section>
    </div>
  );
}
