'use client'

import * as React from 'react'
import { ArrowRight, Pill as PillIcon, Syringe, Snowflake, Box, Boxes, Cpu, Thermometer, Wind } from 'lucide-react'
import { useRouter } from '@/lib/router'
import { PageShell, PageHero, Section, SectionHeading, Reveal, Eyebrow, Card, DefRow, LabeledDivider, LinkButton, Pill, NumberedStep } from '@/components/site/ui'

const CAPABILITIES = [
  { icon: PillIcon, t: 'Tablet production', d: 'Direct compression, dry granulation (roller compaction) and wet granulation (high-shear, fluid-bed). Coating: film, enteric, modified-release. Tablet presses capable of high-speed production with in-process weight, hardness and thickness monitoring.' },
  { icon: Box, t: 'Capsule production', d: 'Hard-gelatin and HPMC capsule filling for powders, pellets, liquids and minitablets. Automatic weight control, dosator and tamping-pin systems. Combination fill capabilities for modified-release profiles.' },
  { icon: Syringe, t: 'Injectables', d: 'Solution, suspension and lyophilized injectables in vials, ampoules, pre-filled syringes and cartridges. Aseptic processing in ISO 5 environments with isolator and RABS technology.' },
  { icon: Snowflake, t: 'Sterile manufacturing', d: 'Aseptic processing per EU GMP Annex 1 and FDA Aseptic Processing Guidance. Blow-fill-seal, form-fill-seal and vial filling lines. Media fill validation, environmental monitoring and contamination control strategy (CCS).' },
  { icon: Thermometer, t: 'Lyophilization', d: 'Freeze-drying of thermolabile APIs and biologics. Cycle development and optimization, controlled nucleation, automated loading/unloading. Product characterization including residual moisture, reconstitution time and cake appearance.' },
  { icon: Boxes, t: 'Packaging', d: 'Primary, secondary and tertiary packaging — blister, bottle, pouch, carton, leaflet. Serialization and aggregation per EU FMD, US DSCSA and other regional track-and-trace requirements. Tamper-evidence and child-resistant options.' },
  { icon: Wind, t: 'Clean rooms', d: 'ISO-classified cleanrooms (ISO 5–8) with HEPA filtration, pressure cascades and continuous environmental monitoring. Gowning, training and behavior programs per EU GMP Annex 1.' },
  { icon: Snowflake, t: 'Cold chain', d: 'Refrigerated and frozen storage and distribution — 2–8°C, −20°C, −80°C — with validated lanes, temperature loggers, excursion response and 24/7 monitoring.' },
  { icon: Cpu, t: 'Digital & automation', d: 'SCADA, MES and DCS platforms for batch execution, electronic batch records, real-time release (RTRT) and process analytical technology (PAT). Statistical process control and continuous improvement.' },
]

export function ManufacturingPage() {
  const { navigate } = useRouter()
  return (
    <PageShell>
      <PageHero
        index="01"
        eyebrow="Manufacturing"
        title="Quality is not a checkpoint."
        highlight="It is the system."
        lead="Espandiar operates eight manufacturing sites producing oral solids, sterile injectables, biologics and lyophilized products to current Good Manufacturing Practice (cGMP). This page describes our capabilities — without disclosing site-specific proprietary information."
        image="/images/cleanroom.png"
      />

      {/* Overview */}
      <Section tone="light">
        <SectionHeading
          index="02"
          eyebrow="Manufacturing overview"
          title="Pharmaceutical manufacturing,"
          highlight="at global scale."
          lead="Pharmaceutical manufacturing is one of the most regulated industrial activities in the world. Our sites operate under cGMP as defined by FDA (21 CFR 210/211, 21 CFR 600 series for biologics), EU GMP (EudraLex Volume 4), WHO TRS and ICH Q7 guidelines."
        />
        <div className="mt-12 grid gap-8 lg:grid-cols-[1.1fr_0.9fr]">
          <Reveal>
            <div className="space-y-5 text-[15px] leading-7 text-muted-foreground">
              <p>
                Modern pharmaceutical manufacturing combines chemical
                engineering, microbiology, analytical chemistry, automation
                and quality management. Each manufacturing line is designed
                around a control strategy that identifies critical quality
                attributes (CQAs) and the critical process parameters (CPPs)
                that influence them — an approach defined by ICH Q8
                (pharmaceutical development), Q9 (quality risk management)
                and Q10 (pharmaceutical quality system).
              </p>
              <p>
                Sterile manufacturing is held to a particularly high
                standard. The revised EU GMP Annex 1 (effective 2023) and
                the FDA Aseptic Processing Guidance require a comprehensive
                contamination control strategy (CCS), barrier technology
                (isolators or RABS), rigorous environmental monitoring and
                aseptic-process simulation (media fills) at a frequency
                matched to risk.
              </p>
              <p>
                Digital manufacturing has become central to quality and
                efficiency. Our sites use SCADA for process control, MES for
                batch execution and electronic batch records (EBR), and
                process analytical technology (PAT) for real-time
                measurement of critical attributes. These systems support
                continuous process verification (ICH Q8) and enable
                real-time release testing (RTRT) where scientifically
                justified.
              </p>
              <p>
                The descriptions below cover our major manufacturing
                capabilities. They reflect established pharmaceutical
                engineering and regulatory practice, not site-specific
                proprietary data. Specific facility information is provided
                through customer audits and regulatory filings.
              </p>
            </div>
          </Reveal>
          <Reveal delay={0.1}>
            <Card className="bg-[#eef1ec] dark:bg-[#17231f]">
              <Eyebrow>Regulatory framework</Eyebrow>
              <dl className="mt-6">
                <DefRow term="cGMP">FDA 21 CFR 210/211 (drug products), 21 CFR 600 series (biologics).</DefRow>
                <DefRow term="EU GMP">EudraLex Volume 4 — Parts I, II, III; Annex 1 (sterile), Annex 11 (computerized systems).</DefRow>
                <DefRow term="WHO GMP">WHO Technical Report Series — used in many LMIC markets.</DefRow>
                <DefRow term="ICH">Q7 (API GMP), Q8 (development), Q9 (risk), Q10 (PQS), Q12 (lifecycle).</DefRow>
                <DefRow term="Serialization">EU FMD, US DSCSA, Russia MDLP, Brazil SNCM — global track-and-trace compliance.</DefRow>
              </dl>
            </Card>
          </Reveal>
        </div>
      </Section>

      {/* Capabilities grid */}
      <Section tone="dark">
        <SectionHeading
          tone="dark"
          index="03"
          eyebrow="Capabilities"
          title="From oral solids"
          highlight="to biologics."
          lead="Our manufacturing network covers the major pharmaceutical dosage forms. Each capability is described in terms of the technology platforms, the quality controls applied, and the regulatory frameworks that govern it."
        />
        <div className="mt-12 grid gap-4 md:grid-cols-2 lg:grid-cols-3">
          {CAPABILITIES.map((c, i) => {
            const Icon = c.icon
            return (
              <Reveal key={c.t} delay={(i % 3) * 0.08}>
                <Card tone="dark" className="h-full">
                  <div className="grid h-12 w-12 place-items-center rounded-2xl bg-white/10 text-white">
                    <Icon className="h-5 w-5" />
                  </div>
                  <h3 className="mt-5 text-lg font-semibold tracking-[-0.02em]">{c.t}</h3>
                  <p className="mt-3 text-sm leading-6 text-white/60">{c.d}</p>
                </Card>
              </Reveal>
            )
          })}
        </div>
      </Section>

      {/* Sterile manufacturing deep dive */}
      <Section tone="pearl">
        <SectionHeading
          index="04"
          eyebrow="Sterile manufacturing deep-dive"
          title="Sterility is not tested in."
          highlight="It is designed in."
          lead="Sterile manufacturing is the most demanding activity in pharmaceutical production. The revised EU GMP Annex 1 (effective 2023) places unprecedented emphasis on contamination control strategy, barrier technology and quality risk management."
        />
        <div className="mt-12 grid gap-8 lg:grid-cols-[1fr_1fr]">
          <Reveal>
            <div className="space-y-5 text-[15px] leading-7 text-muted-foreground">
              <p>
                Sterile products — injectables, ophthalmics, inhalation
                products and certain biologics — must be free of viable
                microorganisms. Because terminal sterilization is not always
                possible (e.g., for proteins and heat-sensitive products),
                many sterile products are manufactured aseptically: the
                product is sterilized by filtration, and downstream
                processing is performed in a controlled aseptic environment.
              </p>
              <p>
                Barrier technology — isolators or restricted access barrier
                systems (RABS) — physically separates the product from
                operators, the principal source of microbial contamination
                in an aseptic environment. Isolators provide the highest
                level of separation and are increasingly the technology of
                choice for new facilities.
              </p>
              <p>
                Environmental monitoring (EM) is the continuous surveillance
                of the manufacturing environment. Viable and non-viable
                particulate monitoring, surface contact plates, glove
                fingerprints and active air sampling provide a real-time
                picture of contamination risk. EM data are trended and
                investigated using ICH Q9 risk-management principles.
              </p>
              <p>
                Aseptic process simulation (media fills) — replacing product
                with sterile growth medium and running a full simulated
                batch — validates that the aseptic process can produce
                sterile product. Annex 1 specifies frequency, volume and
                acceptance criteria for media fills.
              </p>
            </div>
          </Reveal>
          <Reveal delay={0.1}>
            <div className="space-y-4">
              {[
                { t: 'Contamination control strategy (CCS)', d: 'A documented, holistic strategy identifying, evaluating and controlling contamination risks across the complete lifecycle.' },
                { t: 'Barrier technology', d: 'Isolators and RABS providing ISO 5 environment with physical separation from operators.' },
                { t: 'Rapid microbial methods', d: 'Rapid detection systems reducing time-to-result for environmental monitoring.' },
                { t: 'Single-use technology', d: 'Disposable tubing, bags and filters reducing cross-contamination risk and cleaning burden.' },
                { t: 'Continuous monitoring', d: 'Real-time viable and non-viable particle monitoring with alarm and escalation.' },
              ].map((s, i) => (
                <div key={s.t} className="rounded-2xl border border-border bg-card p-5">
                  <b className="text-sm font-semibold">{`0${i + 1}`} — {s.t}</b>
                  <p className="mt-1.5 text-sm text-muted-foreground">{s.d}</p>
                </div>
              ))}
            </div>
          </Reveal>
        </div>
      </Section>

      {/* Digital manufacturing */}
      <Section tone="light">
        <SectionHeading
          index="05"
          eyebrow="Digital & automation"
          title="Manufacturing that"
          highlight="thinks for itself."
          lead="Industry 4.0 has reached pharmaceutical manufacturing. Digital systems — SCADA, MES, PAT, digital twins and AI — are transforming how we operate, monitor and improve."
        />
        <div className="mt-12 space-y-7">
          {[
            { n: '01', t: 'SCADA & DCS', d: 'Supervisory control and data acquisition (SCADA) and distributed control systems (DCS) provide real-time control of process equipment — temperature, pressure, flow, agitation. Validated systems ensure reproducibility and 21 CFR Part 11 / Annex 11 compliance for electronic records and signatures.' },
            { n: '02', t: 'MES & EBR', d: 'Manufacturing execution systems (MES) orchestrate batch execution, enforce recipe steps, manage electronic batch records (EBR) and integrate with quality and inventory systems. EBR eliminates paper, reduces errors and accelerates batch release.' },
            { n: '03', t: 'PAT & RTRT', d: 'Process analytical technology (PAT) uses in-line and on-line sensors (NIR, Raman, acoustic, imaging) to measure critical quality attributes in real time. Where PAT is fully integrated, real-time release testing (RTRT) can replace end-product testing for certain attributes, reducing cycle time.' },
            { n: '04', t: 'Digital twins & AI', d: 'Digital twins — process simulations calibrated to actual plant data — support optimization, troubleshooting and predictive maintenance. Machine learning models detect drifting processes before they fail specification.' },
          ].map((s) => (
            <Reveal key={s.n}>
              <NumberedStep n={s.n} title={s.t}>
                {s.d}
              </NumberedStep>
            </Reveal>
          ))}
        </div>
      </Section>

      {/* Warehouse & supply */}
      <Section tone="dark">
        <SectionHeading
          tone="dark"
          index="06"
          eyebrow="Warehouse & supply chain"
          title="Materials in motion,"
          highlight="under control."
          lead="Pharmaceutical warehousing and supply chain operate under Good Distribution Practice (GDP). Temperature, traceability and serialization are central to product integrity."
        />
        <div className="mt-12 grid gap-4 md:grid-cols-2 lg:grid-cols-4">
          {[
            { t: 'Warehouse management', d: 'WMS with FEFO (first-expiry-first-out), lot-level traceability and quarantine controls.' },
            { t: 'Temperature mapping', d: 'Pre-use temperature mapping of all storage areas; continuous monitoring with calibrated probes.' },
            { t: 'Serialization', d: 'Aggregated packaging hierarchy per regional requirements (EU FMD, US DSCSA, etc.).' },
            { t: 'Cold chain logistics', d: 'Validated shipping containers, temperature loggers and excursion response for refrigerated and frozen shipments.' },
          ].map((w, i) => (
            <Reveal key={w.t} delay={(i % 4) * 0.08}>
              <Card tone="dark" className="h-full">
                <Pill tone="dark">0{i + 1}</Pill>
                <h3 className="mt-5 text-base font-semibold tracking-[-0.02em]">{w.t}</h3>
                <p className="mt-3 text-sm leading-6 text-white/60">{w.d}</p>
              </Card>
            </Reveal>
          ))}
        </div>
      </Section>

      {/* CTA */}
      <Section tone="light">
        <div className="grid gap-8 lg:grid-cols-[1.2fr_0.8fr] lg:items-center">
          <Reveal>
            <Eyebrow>Manufacturing partnerships</Eyebrow>
            <h2 className="mt-5 text-3xl font-semibold tracking-[-0.04em] sm:text-5xl">
              Manufacturing capacity for your program.
            </h2>
            <p className="mt-5 max-w-xl text-sm leading-6 text-muted-foreground">
              Our CDMO team supports clinical-trial supply and commercial
              manufacturing across oral solids, sterile injectables,
              biologics and lyophilized products. From technology transfer
              through commercial supply, we provide end-to-end
              manufacturing under one quality system.
            </p>
          </Reveal>
          <Reveal delay={0.1} className="flex flex-wrap gap-3 lg:justify-end">
            <LinkButton variant="primary" onClick={() => navigate('cdmo')}>
              Explore CDMO
              <ArrowRight className="h-4 w-4" />
            </LinkButton>
            <LinkButton variant="ghost" className="border border-border" onClick={() => navigate('quality')}>
              Quality systems
              <ArrowRight className="h-4 w-4" />
            </LinkButton>
          </Reveal>
        </div>
        <Reveal className="mt-10">
          <LabeledDivider label="Note" />
          <p className="mt-4 text-sm leading-6 text-muted-foreground">
            The descriptions on this page reflect established pharmaceutical
            engineering and regulatory practice. They do not constitute a
            representation about the specifications, capacities or regulatory
            status of any specific Espandiar manufacturing site. Site-specific
            information is shared under confidentiality through customer
            audits and regulatory filings.
          </p>
        </Reveal>
      </Section>
    </PageShell>
  )
}
