const SERVICE_DATA = [
  { id: 'p1', num: '01', tab: 'Custom Software', title: 'Custom Software & Product Development', lead: 'Production applications and APIs designed around your data model, permissions, and the people who use them every day.', items: [['app-window', 'Custom Web & SaaS Applications', 'Multi-tenant apps with auth, billing hooks and admin panels.'], ['smartphone', 'Mobile Apps & Internal Tools', 'Field apps and back-office tools your staff actually adopt.'], ['layout-dashboard', 'Dashboards & API Development', 'Typed REST/GraphQL APIs and live operational dashboards.'], ['refresh-cw', 'Application Modernization', 'Move legacy desktop and spreadsheet systems to the web, module by module.']], V: 'SoftwareVisual' },
  { id: 'p2', num: '02', tab: 'AI Agents', title: 'AI Agents & Customer Communication Automation', lead: 'Voice and chat agents that answer, qualify and follow up across channels, then hand the conversation to a person with full context.', items: [['phone-call', 'Inbound & Outbound Voice Agents', 'Answer, qualify, book and confirm over the phone.'], ['message-square-text', 'Web Chat & Internal Assistants', 'Site chat and staff assistants grounded in your docs.'], ['send', 'Omnichannel Follow-Ups', 'WhatsApp, Email and SMS sequences triggered by conversation outcomes.'], ['user-round-check', 'Lead Routing & Warm Human Handoffs', 'Route by intent and pass a written summary to the right rep.']], V: 'AgentsVisual' },
  { id: 'p3', num: '03', tab: 'Ops Automation', title: 'Business Process & Operations Automation', lead: 'Connect the systems your team re-types between, with approval steps where judgement matters and reporting at the end.', items: [['arrow-left-right', 'CRM & Pipeline Synchronization', 'Two-way sync between CRM, ERP and billing.'], ['folder-sync', 'Data Movement & Back-Office Tasks', 'Document parsing, record creation and reconciliation.'], ['shield-check', 'Human-in-the-Loop Approvals', 'Approval cards in Slack, email or a web console.'], ['chart-no-axes-combined', 'Operational Reporting Pipelines', 'Scheduled and event-driven reports from clean data.']], V: 'OpsVisual' },
  { id: 'p4', num: '04', tab: 'Digital Marketing', title: 'Digital Marketing Automation & AI-Assisted Content Operations', lead: 'Lead capture and campaign plumbing, plus drafting support for content teams. Nothing publishes without a human reviewer.', items: [['funnel', 'Lead Capture, Segmentation & Nurturing', 'Forms, enrichment, segments and nurture sequences.'], ['megaphone', 'Campaign Operations & Reporting', 'Launch checklists, UTM hygiene, weekly performance reports.'], ['file-text', 'Research-Supported Blog & Social Drafts', 'Drafts with sources attached for fact-checking.'], ['clapperboard', 'Social Concepts, Captions & Reel Scripts', 'Short-form video/Reel scripts with human review before publication.']], V: 'MarketingVisual' },
];

function DeliverableCard({ ic, t, d }) {
  const { Icon } = DS;
  const [h, setH] = React.useState(false);
  return (
    <div onMouseEnter={() => setH(true)} onMouseLeave={() => setH(false)} style={{ display: 'flex', gap: 12, padding: 14, borderRadius: 12, background: 'var(--glass-bg)', backdropFilter: 'var(--glass-blur)', WebkitBackdropFilter: 'var(--glass-blur)', boxShadow: 'var(--glass-shadow)', border: `1px solid ${h ? 'var(--border-accent)' : 'var(--glass-border)'}`, transform: h ? 'translateY(-2px)' : 'none', transition: 'all .22s cubic-bezier(.22,1,.36,1)' }}>
      <span style={{ width: 34, height: 34, flex: 'none', borderRadius: 9, display: 'grid', placeItems: 'center', background: '#fff', color: 'var(--yk-violet)' }}><Icon name={ic} size={17} /></span>
      <div><div style={{ font: '600 14px/1.35 var(--font-display)', color: 'var(--yk-indigo)' }}>{t}</div><div style={{ font: '400 13px/1.5 var(--font-body)', color: 'var(--text-muted)', marginTop: 3 }}>{d}</div></div>
    </div>
  );
}

function Services({ pillar, setPillar }) {
  const { SectionHeader, Tabs } = DS;
  const wide = useMedia('(min-width: 1040px)');
  const cur = SERVICE_DATA.find((s) => s.id === pillar) || SERVICE_DATA[0];
  const Visual = window[cur.V];
  return (
    <section id="services" style={{ padding: `${wide ? 112 : 72}px 0` }}>
      <Container>
        <Reveal><SectionHeader eyebrow="Services" title="Four practices. One engineering team." lead="Each engagement draws on whichever practices the workflow needs. Pick a pillar to see what we deliver and how it behaves in production." /></Reveal>
        <Reveal delay={0.07} style={{ marginTop: 40, borderBottom: '1px solid var(--border-default)' }}>
          <Tabs variant="underline" value={pillar} onChange={setPillar} tabs={SERVICE_DATA.map((s) => ({ value: s.id, label: `${s.num}  ${s.tab}` }))} style={{ borderBottom: 0, width: '100%' }} />
        </Reveal>
        <div key={cur.id} style={{ display: 'grid', gridTemplateColumns: wide ? 'minmax(0,.9fr) minmax(0,1.1fr)' : 'minmax(0,1fr)', gap: wide ? 48 : 32, marginTop: 40, alignItems: 'start', animation: 'yk-fade-up .45s cubic-bezier(.22,1,.36,1) both' }}>
          <div style={{ display: 'grid', gap: 18, position: wide ? 'sticky' : 'static', top: 96 }}>
            <MonoLabel color="var(--yk-violet)">PILLAR {cur.num}</MonoLabel>
            <h3 style={{ font: '600 26px/1.25 var(--font-display)', letterSpacing: '-.02em', color: 'var(--yk-indigo)' }}>{cur.title}</h3>
            <p style={{ font: '400 16px/1.6 var(--font-body)', color: 'var(--yk-charcoal)' }}>{cur.lead}</p>
            <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))', gap: 10, marginTop: 4 }}>
              {cur.items.map(([ic, t, d]) => <DeliverableCard key={t} ic={ic} t={t} d={d} />)}
            </div>
          </div>
          <ScrollRise style={{ minWidth: 0 }}><DepthStack radius={22}><div style={{ ...glassPanel, borderRadius: 22, padding: wide ? 12 : 8 }}><Visual /></div></DepthStack></ScrollRise>
        </div>
      </Container>
    </section>
  );
}

Object.assign(window, { Services, SERVICE_DATA });
