import { Building2, Construction, Home, type LucideIcon } from "lucide-react";

import type { Dictionary } from "@/lib/i18n";
import type { Locale } from "@/lib/locales";
import { localizedPath, type ProductSlug } from "@/lib/routes";
import {
  operationalProductFaqs,
  supplementalProductFaqs,
} from "@/data/product-faqs.data";

export type ProductTone = "violet" | "blue" | "green";

export type ProductImage = {
  src:
    | "/images/dashboard.png"
    | "/images/dashboard-UI.png"
    | "/images/Login.png"
    | "/images/pureestate-login.png"
    | "/images/buildpro-login.png"
    | "/images/societypro-login.png";
  alt: string;
  width: number;
  height: number;
};

export type ProductFaq = readonly [question: string, answer: string];

export type Product = {
  slug: ProductSlug;
  name: string;
  short: string;
  overview: string;
  who: string[];
  features: string[];
  featureDescriptions: string[];
  benefits: string[];
  sales: string[];
  steps: string[];
  faqs: ProductFaq[];
  tone: ProductTone;
  artwork: "estate" | "build" | "society";
  icon: LucideIcon;
  seoTitle: string;
  seoDescription: string;
  images: {
    hero: ProductImage;
    gallery: ProductImage[];
  };
};

export type ProductPageCopy = {
  navbar: {
    overview: string;
    features: string;
    benefits: string;
    pricing: string;
    faq: string;
    contact: string;
    login: string;
    trial: string;
    register: string;
    productHome: string;
    openMenu: string;
    closeMenu: string;
  };
  heroBadge: string;
  trustPills: string[];
  overviewEyebrow: string;
  overviewTitle: string;
  overviewDescription: string;
  featuresEyebrow: string;
  featuresTitle: string;
  featuresDescription: string;
  benefitsEyebrow: string;
  benefitsTitle: string;
  audienceEyebrow: string;
  audienceTitle: string;
  galleryEyebrow: string;
  galleryTitle: string;
  galleryDescription: string;
  howEyebrow: string;
  howTitle: string;
  pricingEyebrow: string;
  pricingTitle: string;
  pricingDescription: string;
  requestQuote: string;
  faqEyebrow: string;
  faqTitle: string;
  ctaTitle: string;
  ctaDescription: string;
  access: {
    loginTitle: string;
    loginDescription: string;
    registerTitle: string;
    registerDescription: string;
    requestAccess: string;
    backToProduct: string;
  };
};

const dashboardImage: ProductImage = {
  src: "/images/dashboard.png",
  alt: "PureEstate CRM dashboard with lead, booking, revenue, and task insights",
  width: 1536,
  height: 1024,
};

const laptopDashboardImage: ProductImage = {
  src: "/images/dashboard-UI.png",
  alt: "PureSaaS dashboard displayed on a laptop",
  width: 1536,
  height: 1024,
};

const loginImage: ProductImage = {
  src: "/images/Login.png",
  alt: "Secure product login illustration",
  width: 1197,
  height: 1314,
};

const visuals: Record<
  ProductSlug,
  Pick<
    Product,
    | "slug"
    | "tone"
    | "artwork"
    | "icon"
    | "seoTitle"
    | "seoDescription"
    | "images"
  >
> = {
  pureestate: {
    slug: "pureestate",
    tone: "blue",
    artwork: "estate",
    icon: Building2,
    seoTitle: "PureEstate CRM | Real Estate, Broker & Lead Management Software",
    seoDescription:
      "PureEstate CRM helps real estate brokers, agencies, and property teams manage leads, follow-ups, property inventory, sales pipelines, finance summaries, and reports.",
    images: {
      hero: dashboardImage,
      gallery: [laptopDashboardImage, loginImage],
    },
  },
  buildpro: {
    slug: "buildpro",
    tone: "green",
    artwork: "build",
    icon: Construction,
    seoTitle: "BuildPro Builder CRM | Construction Project & Sales Management",
    seoDescription:
      "BuildPro builder CRM connects project tracking, unit inventory, booking management, construction progress, sales tracking, team tasks, reports, and analytics.",
    images: {
      hero: laptopDashboardImage,
      gallery: [dashboardImage, loginImage],
    },
  },
  societypro: {
    slug: "societypro",
    tone: "green",
    artwork: "society",
    icon: Home,
    seoTitle: "SocietyPro | Housing Society Management, Billing & Complaints",
    seoDescription:
      "SocietyPro helps housing societies manage residents, complaints, visitors, parking, vehicle records, facility booking, notices, maintenance billing, and collections.",
    images: {
      hero: laptopDashboardImage,
      gallery: [dashboardImage, loginImage],
    },
  },
};

const pageCopy: Record<Locale, ProductPageCopy> = {
  en: {
    navbar: {
      overview: "Overview",
      features: "Features",
      benefits: "Benefits",
      pricing: "Pricing",
      faq: "FAQ",
      contact: "Contact",
      login: "Login",
      register: "Register",
      trial: "Start 7-Day Free Trial",
      productHome: "Product home",
      openMenu: "Open product navigation",
      closeMenu: "Close product navigation",
    },
    heroBadge: "Purpose-built business software",
    trustPills: ["Fast onboarding", "Secure workflows", "Clear reporting"],
    overviewEyebrow: "One connected workspace",
    overviewTitle: "Replace scattered work with a clear operating system.",
    overviewDescription:
      "Keep your people, records, follow-ups, and reports connected. Your team sees the next action clearly while managers get reliable visibility.",
    featuresEyebrow: "Product capabilities",
    featuresTitle: "Everything your team needs to stay organized.",
    featuresDescription:
      "Focused workflows keep daily work simple without losing the information your business needs to grow.",
    benefitsEyebrow: "Business outcomes",
    benefitsTitle: "Make every working day easier to manage.",
    audienceEyebrow: "Built for your team",
    audienceTitle: "Give every stakeholder a clearer way to work.",
    galleryEyebrow: "Product experience",
    galleryTitle: "A clean interface designed for daily use.",
    galleryDescription:
      "Explore the dashboards and access experience your team can use across desktop and mobile workflows.",
    howEyebrow: "Simple rollout",
    howTitle: "Get your team live without unnecessary complexity.",
    pricingEyebrow: "Flexible plans",
    pricingTitle: "Start with the workflows you need today.",
    pricingDescription:
      "Choose a practical starting plan. We will confirm the right scope after a short discovery call.",
    requestQuote: "Request a quote",
    faqEyebrow: "Frequently asked questions",
    faqTitle: "Straight answers before you get started.",
    ctaTitle: "Ready to see the right workflow for your team?",
    ctaDescription:
      "Book a focused demo and explore how this product can simplify your day-to-day operations.",
    access: {
      loginTitle: "Access your product workspace",
      loginDescription:
        "Product access is provisioned for onboarded teams. Contact us if you need your workspace link or account support.",
      registerTitle: "Start your product onboarding",
      registerDescription:
        "Tell us about your workflow and we will prepare the right product setup, migration plan, and team onboarding path.",
      requestAccess: "Request access support",
      backToProduct: "Back to product",
    },
  },
  hi: {
    navbar: {
      overview: "ओवरव्यू",
      features: "फीचर्स",
      benefits: "फायदे",
      pricing: "कीमत",
      faq: "सवाल",
      contact: "संपर्क",
      trial: "7 दिन का फ्री ट्रायल शुरू करें",
      login: "लॉगिन",
      register: "रजिस्टर",
      productHome: "प्रोडक्ट होम",
      openMenu: "प्रोडक्ट मेनू खोलें",
      closeMenu: "प्रोडक्ट मेनू बंद करें",
    },
    heroBadge: "आपके बिजनेस के लिए बना सॉफ्टवेयर",
    trustPills: ["आसान शुरुआत", "सुरक्षित वर्कफ्लो", "साफ रिपोर्टिंग"],
    overviewEyebrow: "एक जुड़ा हुआ वर्कस्पेस",
    overviewTitle: "बिखरे हुए काम को एक साफ सिस्टम में बदलें।",
    overviewDescription:
      "टीम, रिकॉर्ड, फॉलो-अप और रिपोर्ट एक जगह रखें। आपकी टीम अगला काम साफ देखती है और मैनेजर को सही जानकारी मिलती है।",
    featuresEyebrow: "प्रोडक्ट क्षमताएं",
    featuresTitle: "टीम को व्यवस्थित रखने के लिए जरूरी सभी सुविधाएं।",
    featuresDescription:
      "सरल वर्कफ्लो रोज के काम को आसान रखते हैं और बिजनेस बढ़ाने के लिए जरूरी जानकारी संभालते हैं।",
    benefitsEyebrow: "बिजनेस फायदे",
    benefitsTitle: "हर कार्यदिवस को संभालना आसान बनाएं।",
    audienceEyebrow: "आपकी टीम के लिए",
    audienceTitle: "हर उपयोगकर्ता को काम करने का साफ तरीका दें।",
    galleryEyebrow: "प्रोडक्ट अनुभव",
    galleryTitle: "रोज के उपयोग के लिए बना साफ इंटरफेस।",
    galleryDescription:
      "डैशबोर्ड और सुरक्षित एक्सेस अनुभव देखें जिन्हें आपकी टीम डेस्कटॉप और मोबाइल पर उपयोग कर सकती है।",
    howEyebrow: "सरल शुरुआत",
    howTitle: "बिना अनावश्यक जटिलता के अपनी टीम को लाइव करें।",
    pricingEyebrow: "लचीले प्लान",
    pricingTitle: "आज जरूरी वर्कफ्लो के साथ शुरुआत करें।",
    pricingDescription:
      "एक उपयोगी शुरुआती प्लान चुनें। छोटी बातचीत के बाद हम सही स्कोप स्पष्ट करेंगे।",
    requestQuote: "कोटेशन मांगें",
    faqEyebrow: "अक्सर पूछे जाने वाले सवाल",
    faqTitle: "शुरू करने से पहले साफ जवाब।",
    ctaTitle: "अपनी टीम के लिए सही वर्कफ्लो देखना चाहते हैं?",
    ctaDescription:
      "एक केंद्रित डेमो बुक करें और देखें कि यह प्रोडक्ट रोज के काम को कैसे आसान बना सकता है।",
    access: {
      loginTitle: "अपने प्रोडक्ट वर्कस्पेस को खोलें",
      loginDescription:
        "ऑनबोर्ड की गई टीम को प्रोडक्ट एक्सेस दिया जाता है। वर्कस्पेस लिंक या अकाउंट सहायता के लिए हमसे संपर्क करें।",
      registerTitle: "अपनी प्रोडक्ट ऑनबोर्डिंग शुरू करें",
      registerDescription:
        "अपना वर्कफ्लो बताएं और हम सही सेटअप, माइग्रेशन प्लान और टीम ऑनबोर्डिंग तैयार करेंगे।",
      requestAccess: "एक्सेस सहायता मांगें",
      backToProduct: "प्रोडक्ट पर वापस जाएं",
    },
  },
  gu: {
    navbar: {
      overview: "ઓવરવ્યૂ",
      features: "ફીચર્સ",
      benefits: "ફાયદા",
      pricing: "કિંમત",
      faq: "પ્રશ્નો",
      contact: "સંપર્ક",
      login: "લૉગિન",
      trial: "7 દિવસનું ફ્રી ટ્રાયલ શરૂ કરો",
      register: "રજિસ્ટર",
      productHome: "પ્રોડક્ટ હોમ",
      openMenu: "પ્રોડક્ટ મેનૂ ખોલો",
      closeMenu: "પ્રોડક્ટ મેનૂ બંધ કરો",
    },
    heroBadge: "તમારા બિઝનેસ માટે બનાવેલ સોફ્ટવેર",
    trustPills: ["સરળ શરૂઆત", "સુરક્ષિત વર્કફ્લો", "સ્પષ્ટ રિપોર્ટિંગ"],
    overviewEyebrow: "એક જોડાયેલું વર્કસ્પેસ",
    overviewTitle: "વેરવિખેર કામને સ્પષ્ટ સિસ્ટમમાં ફેરવો.",
    overviewDescription:
      "ટીમ, રેકોર્ડ, ફોલો-અપ અને રિપોર્ટ એક જગ્યાએ રાખો. ટીમ આગળનું કામ સ્પષ્ટ રીતે જુએ અને મેનેજરને વિશ્વસનીય માહિતી મળે.",
    featuresEyebrow: "પ્રોડક્ટ ક્ષમતાઓ",
    featuresTitle: "ટીમને વ્યવસ્થિત રાખવા માટે જરૂરી તમામ સુવિધાઓ.",
    featuresDescription:
      "સરળ વર્કફ્લો રોજિંદા કામને સરળ રાખે છે અને બિઝનેસ વૃદ્ધિ માટે જરૂરી માહિતી સાચવે છે.",
    benefitsEyebrow: "બિઝનેસ ફાયદા",
    benefitsTitle: "દરેક કાર્યદિવસને સંભાળવો સરળ બનાવો.",
    audienceEyebrow: "તમારી ટીમ માટે",
    audienceTitle: "દરેક વપરાશકર્તાને કામ કરવાની સ્પષ્ટ રીત આપો.",
    galleryEyebrow: "પ્રોડક્ટ અનુભવ",
    galleryTitle: "રોજિંદા ઉપયોગ માટે બનાવેલ સ્વચ્છ ઇન્ટરફેસ.",
    galleryDescription:
      "ડૅશબોર્ડ અને સુરક્ષિત ઍક્સેસ અનુભવ જુઓ જે ટીમ ડેસ્કટોપ અને મોબાઇલ વર્કફ્લોમાં વાપરી શકે છે.",
    howEyebrow: "સરળ શરૂઆત",
    howTitle: "બિનજરૂરી જટિલતા વિના તમારી ટીમને લાઇવ કરો.",
    pricingEyebrow: "લવચીક પ્લાન",
    pricingTitle: "આજે જરૂરી વર્કફ્લોથી શરૂઆત કરો.",
    pricingDescription:
      "વ્યવહારુ શરૂઆતનો પ્લાન પસંદ કરો. ટૂંકી ચર્ચા પછી અમે યોગ્ય સ્કોપ સ્પષ્ટ કરીશું.",
    requestQuote: "ક્વોટ માંગો",
    faqEyebrow: "વારંવાર પૂછાતા પ્રશ્નો",
    faqTitle: "શરૂ કરતા પહેલા સ્પષ્ટ જવાબો.",
    ctaTitle: "તમારી ટીમ માટે યોગ્ય વર્કફ્લો જોવા તૈયાર છો?",
    ctaDescription:
      "કેન્દ્રિત ડેમો બુક કરો અને જુઓ કે આ પ્રોડક્ટ રોજિંદી કામગીરીને કેવી રીતે સરળ બનાવી શકે છે.",
    access: {
      loginTitle: "તમારું પ્રોડક્ટ વર્કસ્પેસ ખોલો",
      loginDescription:
        "ઓનબોર્ડ થયેલી ટીમને પ્રોડક્ટ ઍક્સેસ આપવામાં આવે છે. વર્કસ્પેસ લિંક અથવા અકાઉન્ટ સહાય માટે અમારો સંપર્ક કરો.",
      registerTitle: "તમારી પ્રોડક્ટ ઓનબોર્ડિંગ શરૂ કરો",
      registerDescription:
        "તમારો વર્કફ્લો જણાવો અને અમે યોગ્ય સેટઅપ, માઇગ્રેશન પ્લાન અને ટીમ ઓનબોર્ડિંગ તૈયાર કરીશું.",
      requestAccess: "ઍક્સેસ સહાય માંગો",
      backToProduct: "પ્રોડક્ટ પર પાછા જાઓ",
    },
  },
};

export function getProducts(dictionary: Dictionary, locale: Locale): Product[] {
  return (Object.keys(visuals) as ProductSlug[]).map((slug) => {
    const content = dictionary.products[slug];
    return {
      ...visuals[slug],
      ...content,
      faqs: [
        ...content.faqs.map(
          ([question, answer]) => [question ?? "", answer ?? ""] as ProductFaq,
        ),
        ...supplementalProductFaqs[locale][slug],
        ...operationalProductFaqs[locale][slug],
      ],
    };
  });
}

export function getProduct(
  dictionary: Dictionary,
  slug: ProductSlug,
  locale: Locale,
) {
  return getProducts(dictionary, locale).find(
    (product) => product.slug === slug,
  );
}

export function getProductPageCopy(locale: Locale) {
  return pageCopy[locale];
}

export function getProductLinks(
  locale: Locale,
  product: Pick<Product, "slug">,
) {
  const productHome = localizedPath(locale, `/products/${product.slug}`);
  return {
    productHome,
    login: `${productHome}/login`,
    register: `${productHome}/register`,
    demo: `${localizedPath(locale, "/demo")}?product=${product.slug}`,
    contact: `${localizedPath(locale, "/contact")}?product=${product.slug}`,
  };
}
