import { Helmet } from "react-helmet-async";
import { Link } from "react-router-dom";
import { ArrowRight, CheckCircle } from "lucide-react";
import type { LucideIcon } from "lucide-react";
import { Layout } from "@/components/layout/Layout";
import { Section, SectionHeader } from "@/components/ui/Section";
import { SEOHead } from "@/components/SEOHead";
import { useForceLanguage } from "@/hooks/useForceLanguage";

export const CALENDLY_URL = "https://calendly.com/sutekistudios/strategic-project-discussion";
const DOMAIN = "https://sutekistudios.com";

export type IndustryLang = "sv" | "en";

export interface IndustryContent {
  metaTitle: string;
  metaDescription: string;
  eyebrow: string;
  h1: string;
  heroBody: string;
  heroNote: string;
  needsTitle: string;
  needsIntro: string;
  needs: { title: string; body: string }[];
  solutionsTitle: string;
  solutionsIntro: string;
  solutions: { icon: LucideIcon; label: string; body: string; href: string }[];
  processTitle: string;
  processIntro: string;
  process: { step: string; title: string; body: string }[];
  proofTitle: string;
  proofBody: string;
  proofCta: string;
  finalTitle: string;
  finalBody: string;
  serviceName: string;
  serviceDescription: string;
  breadcrumbHome: string;
  breadcrumbLabel: string;
}

interface IndustryPageProps {
  lang: IndustryLang;
  svPath: string;
  enPath: string;
  content: Record<IndustryLang, IndustryContent>;
  ogImage?: string;
}

export function IndustryPage({ lang, svPath, enPath, content, ogImage }: IndustryPageProps) {
  useForceLanguage(lang);
  const isSv = lang === "sv";
  const t = content[lang];

  const path = isSv ? svPath : enPath;
  const contactPath = isSv ? "/kontakt" : "/contact";
  const casesPath = isSv ? "/cases" : "/en/cases";
  const primaryCta = isSv ? "Få ett konkret förslag" : "Get a tailored proposal";
  const secondaryCta = isSv ? "Se kundcase" : "See client cases";
  const calendlyCta = isSv ? "Boka ett samtal" : "Book a call";
  const exploreLabel = isSv ? "Läs mer" : "Learn more";

  const jsonLd = [
    {
      "@context": "https://schema.org",
      "@type": "Service",
      name: t.serviceName,
      description: t.serviceDescription,
      serviceType: t.serviceName,
      inLanguage: isSv ? "sv-SE" : "en",
      url: `${DOMAIN}${path}`,
      provider: {
        "@type": "Organization",
        name: "Suteki Studios Inc.",
        url: DOMAIN,
      },
    },
    {
      "@context": "https://schema.org",
      "@type": "BreadcrumbList",
      itemListElement: [
        { "@type": "ListItem", position: 1, name: t.breadcrumbHome, item: `${DOMAIN}${isSv ? "/" : "/en"}` },
        { "@type": "ListItem", position: 2, name: t.breadcrumbLabel, item: `${DOMAIN}${path}` },
      ],
    },
  ];

  return (
    <Layout>
      <SEOHead
        title={t.metaTitle}
        description={t.metaDescription}
        ogImage={ogImage}
        ogType="website"
        forceLang={lang}
        hreflangOverrides={{ sv: svPath, en: enPath, xDefault: svPath }}
      />
      <Helmet>
        <script type="application/ld+json">{JSON.stringify(jsonLd)}</script>
      </Helmet>

      {/* ═══ HERO ═══ */}
      <section className="relative overflow-hidden min-h-[62vh] flex items-end" data-hero="true">
        <div className="absolute inset-0" style={{ background: "linear-gradient(to bottom, #0B1220 0%, #101c33 55%, #0B1220 100%)" }} />
        <div className="container mx-auto px-6 lg:px-8 relative z-10 pt-40 pb-20">
          <div className="max-w-3xl">
            <p className="hero-eyebrow mb-5 animate-fade-up">{t.eyebrow}</p>
            <h1 className="display mb-8 animate-fade-up" style={{ color: "#FFFFFF" }}>{t.h1}</h1>
            <p className="text-lg md:text-xl mb-10 leading-relaxed animate-fade-up-delay-1" style={{ color: "#CBD5E1" }}>
              {t.heroBody}
            </p>
            <div className="flex flex-col sm:flex-row gap-4 animate-fade-up-delay-2">
              <Link to={contactPath} className="btn-white inline-flex items-center gap-2">
                {primaryCta} <ArrowRight className="h-4 w-4" style={{ color: "#0B1220" }} aria-hidden="true" />
              </Link>
              <Link to={casesPath} className="btn-outline inline-flex items-center gap-2" style={{ color: "#fff", borderColor: "rgba(255,255,255,0.25)" }}>
                {secondaryCta}
              </Link>
            </div>
            <p className="mt-5 text-sm" style={{ color: "#94A3B8" }}>{t.heroNote}</p>
          </div>
        </div>
      </section>

      {/* ═══ NEEDS / OUTCOMES ═══ */}
      <Section className="section-white">
        <SectionHeader title={t.needsTitle} subtitle={t.needsIntro} align="center" />
        <div className="grid sm:grid-cols-2 gap-5 max-w-4xl mx-auto">
          {t.needs.map((need, i) => (
            <div key={need.title} className="enterprise-card p-6 animate-fade-up" style={{ animationDelay: `${0.1 * i}s` }}>
              <div className="flex items-start gap-4">
                <CheckCircle className="h-5 w-5 flex-shrink-0 mt-1" style={{ color: "#2563EB" }} aria-hidden="true" />
                <div>
                  <h3 className="text-lg font-semibold mb-2 text-foreground">{need.title}</h3>
                  <p className="text-muted-foreground leading-relaxed">{need.body}</p>
                </div>
              </div>
            </div>
          ))}
        </div>
      </Section>

      {/* ═══ SOLUTION PATHS ═══ */}
      <section className="relative overflow-hidden" data-theme="dark" style={{ background: "#0d1629" }}>
        <div className="container mx-auto px-6 lg:px-8 py-[var(--space-section)]">
          <div className="max-w-3xl mx-auto text-center mb-12">
            <h2 className="mb-4" style={{ color: "#FFFFFF" }}>{t.solutionsTitle}</h2>
            <p style={{ color: "rgba(226,232,240,0.75)" }}>{t.solutionsIntro}</p>
          </div>
          <div className="grid md:grid-cols-3 gap-6 max-w-5xl mx-auto">
            {t.solutions.map((s, i) => {
              const Icon = s.icon;
              return (
                <Link
                  key={s.label}
                  to={s.href}
                  className="group p-8 rounded-2xl border border-white/[0.08] bg-white/[0.02] hover:bg-white/[0.05] transition-all animate-fade-up"
                  style={{ animationDelay: `${0.1 * i}s` }}
                >
                  <Icon className="h-8 w-8 mb-4" style={{ color: "#2563EB" }} aria-hidden="true" />
                  <h3 className="text-xl font-semibold mb-3" style={{ color: "#FFFFFF" }}>{s.label}</h3>
                  <p className="mb-4 leading-relaxed" style={{ color: "rgba(226,232,240,0.7)" }}>{s.body}</p>
                  <span className="text-sm font-medium inline-flex items-center gap-1" style={{ color: "#60A5FA" }}>
                    {exploreLabel} <ArrowRight className="h-3 w-3" aria-hidden="true" />
                  </span>
                </Link>
              );
            })}
          </div>
        </div>
      </section>

      {/* ═══ PROCESS ═══ */}
      <Section className="section-beige">
        <SectionHeader title={t.processTitle} subtitle={t.processIntro} align="center" />
        <div className="grid sm:grid-cols-2 lg:grid-cols-4 gap-5 max-w-5xl mx-auto">
          {t.process.map((step, i) => (
            <div key={step.title} className="enterprise-card p-6 animate-fade-up" style={{ animationDelay: `${0.08 * i}s` }}>
              <span className="inline-flex items-center justify-center h-8 px-3 rounded-full text-sm font-semibold mb-4" style={{ background: "#2563EB", color: "#FFFFFF" }}>
                {step.step}
              </span>
              <h3 className="text-lg font-semibold mb-2 text-foreground">{step.title}</h3>
              <p className="text-muted-foreground leading-relaxed text-sm">{step.body}</p>
            </div>
          ))}
        </div>
      </Section>

      {/* ═══ PROOF ═══ */}
      <Section className="section-white">
        <div className="max-w-2xl mx-auto text-center">
          <h2 className="mb-5 text-foreground">{t.proofTitle}</h2>
          <p className="text-muted-foreground mb-8 leading-relaxed">{t.proofBody}</p>
          <Link to={casesPath} className="btn-outline inline-flex items-center gap-2">
            {t.proofCta} <ArrowRight className="h-4 w-4" aria-hidden="true" />
          </Link>
        </div>
      </Section>

      {/* ═══ FINAL CTA ═══ */}
      <Section className="section-beige">
        <div className="max-w-2xl mx-auto text-center">
          <h2 className="mb-5 text-foreground">{t.finalTitle}</h2>
          <p className="text-muted-foreground mb-10 leading-relaxed">{t.finalBody}</p>
          <div className="flex flex-col sm:flex-row gap-4 justify-center">
            <Link to={contactPath} className="btn-primary inline-flex items-center gap-2">
              {primaryCta} <ArrowRight className="h-4 w-4" aria-hidden="true" />
            </Link>
            <a href={CALENDLY_URL} target="_blank" rel="noopener noreferrer" className="btn-outline inline-flex items-center gap-2">
              {calendlyCta}
            </a>
          </div>
        </div>
      </Section>
    </Layout>
  );
}
