import { useEffect, useState } from 'react';
import { Helmet } from 'react-helmet-async';
import { motion } from 'motion/react';
import { ArrowRight, CheckCircle2, ShieldCheck, MapPin } from 'lucide-react';
import { pricingReviews } from '../data/pageReviews';
import { getPublicSingaporeAreaServed } from '../data/locations';
import { IslandwideServiceCoverage } from './IslandwideServiceCoverage';
import { COMMERCIAL_PAGE_HUB_CONFIG } from '../lib/seoHubArchitecture';
import { useIsZh } from '../hooks/useIsZh';
import { ZhHeadMeta } from './zh/ZhHeadMeta';

export const PricingPage = () => {
  const isZh = useIsZh();
  const [pricingType, setPricingType] = useState<'residential' | 'commercial'>('residential');
  const hubMeta = COMMERCIAL_PAGE_HUB_CONFIG['pricing'];

  useEffect(() => {
    window.scrollTo(0, 0);
  }, []);

  return (
    <div className="animate-in fade-in duration-700 bg-white">
      {isZh ? (
        <ZhHeadMeta pageKey="pricing" />
      ) : (
        <Helmet>
          <title>{hubMeta.seoTitle}</title>
          <meta name="description" content={hubMeta.seoDescription} />
          <meta name="keywords" content="aircon servicing price singapore, aircon servicing cost singapore, aircon rates from $19.50, cheap aircon servicing singapore, aircon maintenance cost, aircon gas top up price, aircon chemical wash price" />
          <link rel="canonical" href="https://skyblueaircon.com/pricing" />
          
          <meta property="og:title" content={hubMeta.seoTitle} />
          <meta property="og:description" content={hubMeta.seoDescription} />
          <meta property="og:type" content="website" />
          <meta property="og:image" content="https://skyblueaircon.com/PureLogo.png" />
          <meta property="og:url" content="https://skyblueaircon.com/pricing" />
          <meta property="og:site_name" content="Sky Blue Aircon Engineering" />
          <meta property="og:locale" content="en_SG" />
          
          <meta name="twitter:card" content="summary_large_image" />
          <meta name="twitter:title" content={hubMeta.seoTitle} />
          <meta name="twitter:description" content={hubMeta.seoDescription} />
          <meta name="twitter:image" content="https://skyblueaircon.com/PureLogo.png" />

          <script type="application/ld+json">
            {JSON.stringify([
              {
                "@context": "https://schema.org",
                "@type": "WebPage",
                "@id": "https://skyblueaircon.com/pricing/#webpage",
                "url": "https://skyblueaircon.com/pricing",
                "name": "Standard Aircon Servicing Pricing Guides",
                "description": "Transparent flat-rate pricing guides for general aircon servicing, deep chemical cleaning, Freon gas top-ups, and troubleshooting islandwide in Singapore."
              },
              {
                "@context": "https://schema.org",
                "@type": "BreadcrumbList",
                "itemListElement": [
                  {
                    "@type": "ListItem",
                    "position": 1,
                    "name": "Home",
                    "item": "https://skyblueaircon.com/"
                  },
                  {
                    "@type": "ListItem",
                    "position": 2,
                    "name": "Pricing",
                    "item": "https://skyblueaircon.com/pricing"
                  }
                ]
              },
              {
                "@context": "https://schema.org",
                "@type": "Product",
                "name": "Sky Blue Aircon Service Packages",
                "image": "https://skyblueaircon.com/PureLogo.png",
                "description": "Comprehensive range of air conditioning maintenance and repair services in Singapore. BCA-certified technicians for professional general servicing, chemical wash, gas top-up, and installations with transparent flat rates.",
                "brand": {
                  "@type": "Brand",
                  "name": "Sky Blue Aircon"
                },
                "areaServed": getPublicSingaporeAreaServed(),
                "offers": {
                  "@type": "AggregateOffer",
                  "priceCurrency": "SGD",
                  "lowPrice": "19.50",
                  "highPrice": "872.00",
                  "priceValidUntil": "2027-12-31",
                  "availability": "https://schema.org/InStock",
                  "url": "https://skyblueaircon.com/pricing",
                  "offerCount": "12",
                  "hasMerchantReturnPolicy": {
                    "@type": "MerchantReturnPolicy",
                    "applicableCountry": "SG",
                    "returnPolicyCategory": "https://schema.org/MerchantReturnNotPermitted"
                  }
                },
                "aggregateRating": {
                  "@type": "AggregateRating",
                  "ratingValue": "4.9",
                  "reviewCount": "3259",
                  "bestRating": "5",
                  "worstRating": "1"
                },
                "review": pricingReviews
              }
            ])}
          </script>
        </Helmet>
      )}

      {/* Unified Page Hero Section */}
      <section className="relative pt-36 pb-16 sm:pt-40 sm:pb-20 lg:pt-44 lg:pb-24 overflow-hidden bg-gradient-to-b from-sky-50/65 via-slate-50/40 to-white border-b border-slate-100">
        <div className="pointer-events-none absolute top-0 left-1/2 -translate-x-1/2 w-full max-w-6xl h-[340px] bg-sky-400/10 blur-[110px] rounded-full z-0" />

        <div className="max-w-4xl mx-auto px-6 sm:px-8 relative z-10 text-center">
          <motion.div
            initial={{ opacity: 0, y: 16 }}
            animate={{ opacity: 1, y: 0 }}
            transition={{ duration: 0.55, ease: 'easeOut' }}
            className="space-y-5 sm:space-y-6"
          >
            <span className="inline-flex items-center text-sky-600 font-extrabold uppercase tracking-[0.16em] text-[10px] sm:text-[10.5px] px-3.5 py-1.5 bg-sky-50/90 rounded-lg border border-sky-100 shadow-2xs whitespace-nowrap">
              {isZh ? '公开透明价目指南' : 'Transparent Rate Guide'}
            </span>
            <h1 className="text-3xl sm:text-5xl lg:text-[3.5rem] font-extrabold text-slate-900 leading-[1.12] tracking-tight text-balance">
              {isZh ? (
                <>诚实公开的<span className="text-sky-600">冷气收费标准</span></>
              ) : (
                <>Honest &amp; Transparent <span className="text-sky-600">Pricing</span></>
              )}
            </h1>
            <p className="max-w-2xl mx-auto text-sm sm:text-lg text-slate-500 leading-relaxed font-medium text-pretty">
              {isZh
                ? '根据您的实际台数选择合适方案。我们为新加坡住宅与商业冷气提供清晰透明的标准价目，绝无隐藏费用。'
                : 'Choose the right plan for your needs. We offer clear, upfront pricing with no hidden fees for both residential and commercial aircon units.'}
            </p>
          </motion.div>
        </div>
      </section>

      {/* Pricing Section */}
      <section className="py-24 bg-white">
        <div className="max-w-4xl mx-auto px-6 sm:px-8">
          <div className="flex flex-col sm:flex-row justify-between items-center mb-12 gap-6">
            <div>
              <h2 className="text-3xl font-extrabold text-slate-900 tracking-tight">
                {isZh ? '常规冷气清洗价目表' : 'Normal Servicing Rates'}
              </h2>
              <p className="text-slate-500 font-medium mt-2 text-sm sm:text-base">
                {isZh ? '全面细致的常规保养清洗，附带 30 天工艺保修。' : 'Comprehensive cleaning with our 30-day workmanship warranty.'}
              </p>
            </div>

            <div className="inline-flex bg-slate-100 p-1.5 rounded-xl shrink-0">
              <button
                onClick={() => setPricingType('residential')}
                className={`px-6 py-2.5 rounded-lg text-sm font-bold transition-all ${pricingType === 'residential' ? 'bg-white text-slate-900 shadow-sm' : 'text-slate-500 hover:text-slate-700'}`}
              >
                {isZh ? '住宅（HDB / 公寓）' : 'Residential'}
              </button>
              <button
                onClick={() => setPricingType('commercial')}
                className={`px-6 py-2.5 rounded-lg text-sm font-bold transition-all ${pricingType === 'commercial' ? 'bg-white text-slate-900 shadow-sm' : 'text-slate-500 hover:text-slate-700'}`}
              >
                {isZh ? '商业 / 办公室' : 'Commercial'}
              </button>
            </div>
          </div>

          <div className="overflow-hidden bg-white border border-slate-200 rounded-3xl shadow-[0_8px_30px_rgb(0,0,0,0.04)] mb-12">
            <div className="overflow-x-auto">
              <table className="w-full text-left border-collapse min-w-[500px]">
                <thead>
                  <tr>
                    <th className="bg-sky-600 text-white font-bold py-5 px-6 text-center border-r border-sky-500 w-1/3">
                      {isZh ? '室内机台数 (FCU)' : 'Nos Units FCU'}
                    </th>
                    <th className="bg-sky-600 text-white font-bold py-4 sm:py-5 px-4 sm:px-6 text-center border-r border-sky-500 w-1/3">
                      <span className="sm:hidden block leading-tight">
                        <span className="block">{isZh ? '单次清洗' : 'AD HOC'}</span>
                        <span className="block text-xs font-semibold opacity-95 mt-0.5">{isZh ? '(1次)' : '(1 Time)'}</span>
                      </span>
                      <span className="hidden sm:inline">
                        {isZh ? '单次清洗 (1 次)' : 'AD HOC (1 Time)'}
                      </span>
                    </th>
                    <th className="bg-sky-600 text-white font-bold py-5 px-6 text-center w-1/3">
                      {isZh ? '年度季度配套 (4 次/年)' : '4 X Yearly Quarterly'}
                    </th>
                  </tr>
                </thead>
                <tbody className="text-slate-700 font-medium text-center">
                  {(pricingType === 'residential' ? [
                    { units: "1", adhoc: "$41.00", yearly: "-" },
                    { units: "2", adhoc: "$56.10", yearly: "$203.80" },
                    { units: "3", adhoc: "$71.40", yearly: "$256.80" },
                    { units: "4", adhoc: "$86.60", yearly: "$326.00" },
                    { units: "5", adhoc: "$101.90", yearly: "$407.50" },
                    { units: "6", adhoc: "$117.20", yearly: "$468.60" }
                  ] : [
                    { units: "1", adhoc: "$65.40", yearly: "-" },
                    { units: "2", adhoc: "$98.10", yearly: "$348.80" },
                    { units: "3", adhoc: "$130.80", yearly: "$479.60" },
                    { units: "4", adhoc: "$163.50", yearly: "$610.40" },
                    { units: "5", adhoc: "$196.20", yearly: "$741.20" },
                    { units: "6", adhoc: "$228.90", yearly: "$872.00" }
                  ]).map((row, i) => {
                    const unitCount = Number(row.units);
                    const adhocNum = parseFloat(row.adhoc.replace('$', ''));
                    const perUnitAdhoc = unitCount >= 2 && !isNaN(adhocNum)
                      ? (adhocNum / unitCount).toFixed(2)
                      : null;

                    return (
                      <tr key={i} className={`border-b border-slate-100 last:border-0 hover:bg-slate-50 transition-colors`}>
                        <td className="py-4 sm:py-5 px-6 border-r border-slate-100">
                          {isZh ? `${row.units} 台` : row.units}
                        </td>
                        <td className="py-4 sm:py-5 px-6 border-r border-slate-100">
                          <div className="flex flex-col items-center justify-center gap-0.5">
                            <span className="font-bold text-slate-900">{row.adhoc}</span>
                            {pricingType === 'residential' && perUnitAdhoc && (
                              <span className="text-[12px] font-semibold text-sky-600 bg-sky-50/80 px-2 py-0.5 rounded-md border border-sky-100/60">
                                {isZh ? `平均 $${perUnitAdhoc} / 台` : `$${perUnitAdhoc} per unit`}
                              </span>
                            )}
                          </div>
                        </td>
                        <td className="py-4 sm:py-5 px-6 font-bold text-sky-600">{row.yearly}</td>
                      </tr>
                    );
                  })}
                </tbody>
              </table>
            </div>
            
            <div className="bg-slate-50 border-t border-slate-100 px-6 py-4 flex flex-col sm:flex-row items-center justify-center gap-3 text-center sm:text-left text-xs text-slate-600 font-medium leading-relaxed">
              <span className="inline-flex items-center gap-1 px-2.5 py-1 bg-amber-50 text-amber-800 font-bold rounded-lg text-[10px] uppercase border border-amber-200/50 tracking-wider shrink-0 shadow-sm">
                <MapPin size={12} className="text-amber-600" /> {isZh ? 'CBD 市区附加费' : 'CBD Area'}
              </span>
              <p className="max-w-2xl text-[11px] sm:text-xs">
                {isZh ? (
                  <>
                    新加坡中央商业区（CBD）范围内的上门服务，每趟将另收 <strong className="text-slate-900">$20（消费税 GST 前）</strong>交通与泊车附加费。
                  </>
                ) : (
                  <>
                    A flat transport &amp; traveling surcharge of <strong className="text-slate-900">$20 (before GST)</strong> applies per trip for jobs located within Singapore's Central Business District (CBD).
                  </>
                )}
              </p>
            </div>

            <div className="bg-slate-50 border-t border-slate-100 px-8 py-4 text-xs text-slate-500 font-semibold space-y-1.5 border-t border-slate-100">
              <p className="flex items-start gap-2 justify-center sm:justify-start">
                <span className="text-amber-500 select-none shrink-0">**</span>
                <span>{isZh ? '以上标准价格仅适用于安装高度不超过 12 英尺（约 3.6 米）的室内机。' : 'Prices above is based on a height up to 12 feet only'}</span>
              </p>
              <p className="flex items-start gap-2 justify-center sm:justify-start">
                <span className="text-amber-500 select-none shrink-0">**</span>
                <span>{isZh ? '7 台及以上室内机保养或商业合约，将按需求另行出具专属报价单。' : 'For 7 nos. of fan coil units & above, a separate quotation shall issue upon request.'}</span>
              </p>
            </div>
          </div>

          <div className="grid md:grid-cols-2 gap-8 mb-16">
            <div className="p-8 bg-sky-50 rounded-3xl border border-sky-100">
              <h3 className="text-xl font-bold text-slate-900 mb-4 flex items-center gap-3">
                <CheckCircle2 size={24} className="text-sky-600" />
                {isZh ? '为什么选择年度季度保养配套？' : 'Why Yearly Maintenance?'}
              </h3>
              <p className="text-slate-600 leading-relaxed font-medium text-sm mb-6">
                {isZh
                  ? '每年 4 次季度保养配套性价比更高，帮助冷气常年保持理想状态，减少突发故障与高额维修风险。'
                  : 'Our 4x yearly quarterly plan offers the best value, keeping your units in top condition year-round and preventing costly breakdowns.'}
              </p>
              <ul className="space-y-3">
                 <li className="flex gap-3 text-sm text-slate-700 font-medium">
                   <CheckCircle2 size={18} className="text-sky-500 shrink-0" /> {isZh ? '旺季期间优先安排上门时段' : 'Priority booking during peak periods'}
                 </li>
                 <li className="flex gap-3 text-sm text-slate-700 font-medium">
                   <CheckCircle2 size={18} className="text-sky-500 shrink-0" /> {isZh ? '定期留意日常部件老化迹象' : 'Early visibility into routine component wear'}
                 </li>
                 <li className="flex gap-3 text-sm text-slate-700 font-medium">
                   <CheckCircle2 size={18} className="text-sky-500 shrink-0" /> {isZh ? '有助长期维持稳定制冷与省电表现' : 'Consistent energy efficiency savings'}
                 </li>
              </ul>
            </div>

            <div className="p-8 bg-slate-50 rounded-3xl border border-slate-200">
               <h3 className="text-xl font-bold text-slate-900 mb-4 flex items-center gap-3">
                 <ShieldCheck size={24} className="text-slate-700" />
                 {isZh ? '30 天工艺保修说明' : '30-Day Workmanship Warranty'}
               </h3>
               <p className="text-slate-600 leading-relaxed font-medium text-sm">
                 {isZh
                   ? '所有标准清洗服务均涵盖已完工项目之 30 天工艺保修。若现场实际检查发现需要额外维修、更换零件或进行药水深层处理，均会在施工前向您透明报价并另行计费。'
                   : 'All standard servicing includes our 30-day workmanship warranty on completed servicing scope. Additional repairs, replacement parts, or chemical treatments are subject to on-site physical inspection and quoted separately before any work proceeds.'}
               </p>
               <div className="mt-8">
                 <a href="https://api.whatsapp.com/send?phone=6592487291" target="_blank" rel="noopener noreferrer" className="inline-flex items-center gap-2 px-6 py-3.5 bg-[#003B73] hover:bg-[#0369A1] text-white rounded-xl font-bold transition-all w-full justify-center group shadow-md shadow-[#003B73]/15 hover:shadow-xl hover:shadow-[#0369A1]/20">
                   <span>{isZh ? '联系冷气专员咨询' : 'Talk to an Expert'}</span>
                   <ArrowRight size={18} className="text-sky-300 group-hover:text-sky-200 group-hover:translate-x-1 transition-all" />
                 </a>
               </div>
            </div>
          </div>
        </div>
      </section>

      <IslandwideServiceCoverage serviceName="Aircon Servicing & Maintenance Pricing" />
    </div>
  );
};
