// MEET2 — Application form page.
// 5-step intake form, persisted to localStorage so refresh doesn't lose progress.
// Reuses tokens, Nav, Footer, T (bilingual helper) from shared.jsx.

const STORAGE_KEY = 'meet2.apply.v1';

const STEPS = [
  { key: 'basics',   zh: '基本資料',     en: 'Basics' },
  { key: 'about',    zh: '關於你',       en: 'About you' },
  { key: 'seeking',  zh: '你尋覓的對象', en: 'Seeking' },
  { key: 'values',   zh: '價值與生活',   en: 'Values & life' },
  { key: 'finish',   zh: '驗證與送出',   en: 'Verify & submit' },
];

function ApplyForm() {
  const [step, setStep] = React.useState(0);
  const [data, setData] = React.useState(() => {
    try { return JSON.parse(localStorage.getItem(STORAGE_KEY)) || {}; }
    catch (e) { return {}; }
  });
  const [submitted, setSubmitted] = React.useState(false);

  // Persist + scroll to top on step change.
  React.useEffect(() => {
    localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
  }, [data]);
  React.useEffect(() => {
    if (window.scrollY > 0) window.scrollTo({ top: 0, behavior: 'smooth' });
  }, [step]);

  const set = (key) => (val) => setData((d) => ({ ...d, [key]: val }));
  const next = () => setStep((s) => Math.min(s + 1, STEPS.length - 1));
  const back = () => setStep((s) => Math.max(s - 1, 0));

  const submit = () => {
    setSubmitted(true);
    window.scrollTo({ top: 0, behavior: 'smooth' });
  };
  const reset = () => {
    setData({}); setSubmitted(false); setStep(0);
    localStorage.removeItem(STORAGE_KEY);
  };

  return (
    <div className="apply">
      <Nav variant="light" sticky={true} />

      {submitted ? (
        <SubmitDone onReset={reset} data={data} />
      ) : (
        <>
          <ApplyHeader step={step} />
          <main className="apply-main">
            <aside className="apply-stepper">
              <StepperRail step={step} onJump={(i) => i <= step && setStep(i)} />
            </aside>

            <section className="apply-card">
              {step === 0 && <StepBasics  data={data} set={set} />}
              {step === 1 && <StepAbout   data={data} set={set} />}
              {step === 2 && <StepSeeking data={data} set={set} />}
              {step === 3 && <StepValues  data={data} set={set} />}
              {step === 4 && <StepFinish  data={data} set={set} />}

              <div className="apply-nav">
                <button
                  type="button"
                  className="m-btn m-btn-ghost"
                  onClick={back}
                  disabled={step === 0}
                  style={{ opacity: step === 0 ? 0.35 : 1 }}
                >
                  <T zh="上一步" en="Back" />
                </button>

                {step < STEPS.length - 1 ? (
                  <button type="button" className="m-btn m-btn-primary" onClick={next}>
                    <T zh="下一步" en="Continue" /> <ArrowA />
                  </button>
                ) : (
                  <button type="button" className="m-btn m-btn-primary" onClick={submit}>
                    <T zh="送出申請" en="Submit application" /> <ArrowA />
                  </button>
                )}
              </div>

              <div className="apply-savenote">
                <Lock />
                <T
                  zh="所有資料皆加密儲存，僅顧問團隊在配對時審閱。中途離開可從上次進度繼續。"
                  en="Encrypted at rest. Only your matchmaker sees the details. Pick up where you left off any time."
                />
              </div>
            </section>
          </main>
        </>
      )}

      <Footer variant="light" />
    </div>
  );
}

function ArrowA() {
  return <svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M2 7h10m-4-4l4 4-4 4" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg>;
}
function Lock() {
  return <svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true"><rect x="2.5" y="5.5" width="7" height="5" rx="1" stroke="currentColor" strokeWidth="1.1"/><path d="M4 5.5V4a2 2 0 014 0v1.5" stroke="currentColor" strokeWidth="1.1" strokeLinecap="round"/></svg>;
}

// ── Header ─────────────────────────────────────────────
function ApplyHeader({ step }) {
  return (
    <header className="apply-hero">
      <div className="apply-hero-bg" aria-hidden="true">
        <div className="va-hero-blob va-hero-blob--pink" />
        <div className="va-hero-blob va-hero-blob--gold" />
      </div>
      <div className="apply-hero-inner">
        <span className="m-eyebrow"><T zh="入會申請" en="Membership application" /></span>
        <h1>
          <T zh={<>請花 8 分鐘，<br/>讓我們認識你。</>}
             en={<>Eight minutes to begin<br/>your search.</>} />
        </h1>
        <p>
          <T
            zh="覓 MEET2 採顧問配對制，申請送出後 3 個工作日內會由顧問親自聯繫，安排 60 分鐘免費面談。"
            en="MEET2 is a matchmaker-led service. A consultant will reach out within 3 business days of your application to schedule a free 60-minute interview."
          />
        </p>
      </div>
    </header>
  );
}

// ── Stepper rail (left column) ─────────────────────────
function StepperRail({ step, onJump }) {
  return (
    <ol className="apply-rail">
      {STEPS.map((s, i) => {
        const state = i < step ? 'done' : i === step ? 'active' : 'pending';
        return (
          <li key={s.key} className={`apply-rail-step is-${state}`} onClick={() => onJump(i)}>
            <span className="apply-rail-no">{state === 'done' ? <Check2 /> : `0${i + 1}`}</span>
            <span className="apply-rail-label">
              <span className="apply-rail-title"><T zh={s.zh} en={s.en} /></span>
              <span className="apply-rail-en">{s.en}</span>
            </span>
          </li>
        );
      })}
    </ol>
  );
}
function Check2() {
  return <svg width="12" height="12" viewBox="0 0 12 12" fill="none"><path d="M2.5 6.5l2.5 2.5L9.5 3" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/></svg>;
}

// ── Field primitives ───────────────────────────────────
function Field({ label, hint, required, children, span = 1 }) {
  return (
    <label className="apply-field" style={{ gridColumn: `span ${span}` }}>
      <span className="apply-field-label">
        {label}{required && <em>*</em>}
      </span>
      {children}
      {hint && <span className="apply-field-hint">{hint}</span>}
    </label>
  );
}
function TextInput({ value = '', onChange, placeholder, type = 'text' }) {
  return <input className="apply-input" type={type} value={value}
                onChange={(e) => onChange(e.target.value)} placeholder={placeholder} />;
}
function Select({ value = '', onChange, options }) {
  return (
    <div className="apply-select">
      <select value={value} onChange={(e) => onChange(e.target.value)}>
        <option value="" disabled></option>
        {options.map((o) => (
          <option key={typeof o === 'string' ? o : o.value} value={typeof o === 'string' ? o : o.value}>
            {typeof o === 'string' ? o : o.label}
          </option>
        ))}
      </select>
      <svg width="10" height="6" viewBox="0 0 10 6" fill="none" aria-hidden="true">
        <path d="M1 1l4 4 4-4" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round"/>
      </svg>
    </div>
  );
}
function Chips({ value = [], onChange, options, single = false }) {
  const arr = single ? (value ? [value] : []) : value;
  const toggle = (v) => {
    if (single) return onChange(v);
    if (arr.includes(v)) onChange(arr.filter((x) => x !== v));
    else onChange([...arr, v]);
  };
  return (
    <div className="apply-chips">
      {options.map((o) => {
        const v = typeof o === 'string' ? o : o.value;
        const label = typeof o === 'string' ? o : o.label;
        const on = arr.includes(v);
        return (
          <button type="button" key={v} className={`apply-chip ${on ? 'is-on' : ''}`}
                  onClick={() => toggle(v)}>
            {label}
          </button>
        );
      })}
    </div>
  );
}
function TextArea({ value = '', onChange, placeholder, rows = 4, maxLength = 400 }) {
  return (
    <div className="apply-ta">
      <textarea value={value} onChange={(e) => onChange(e.target.value)}
                placeholder={placeholder} rows={rows} maxLength={maxLength} />
      <span className="apply-ta-count">{value.length}/{maxLength}</span>
    </div>
  );
}

// ── Step 1 · Basics ────────────────────────────────────
function StepBasics({ data, set }) {
  return (
    <>
      <StepHead idx={0} />
      <div className="apply-grid">
        <Field required label={<T zh="姓名（法律名）" en="Legal name" />}
               hint={<T zh="僅顧問可見，不會公開" en="Visible only to your matchmaker" />}>
          <TextInput value={data.name} onChange={set('name')} placeholder="王小明 / Ming Wang" />
        </Field>
        <Field required label={<T zh="暱稱（顧問稱呼）" en="Nickname" />}>
          <TextInput value={data.nickname} onChange={set('nickname')} placeholder="Ming" />
        </Field>

        <Field required label={<T zh="性別" en="Gender" />}>
          <Chips single value={data.gender} onChange={set('gender')}
            options={[
              { value: 'f', label: <T zh="女" en="Female" /> },
              { value: 'm', label: <T zh="男" en="Male" /> },
              { value: 'nb', label: <T zh="非二元 / 其他" en="Non-binary / Other" /> },
            ]} />
        </Field>
        <Field required label={<T zh="出生日期" en="Date of birth" />}>
          <TextInput type="date" value={data.dob} onChange={set('dob')} />
        </Field>

        <Field required label={<T zh="所在城市" en="City" />}>
          <Select value={data.city} onChange={set('city')}
            options={['台北', '新北', '桃園', '新竹', '台中', '台南', '高雄', '其他 / 海外']} />
        </Field>
        <Field required label={<T zh="婚姻狀態" en="Marital status" />}>
          <Select value={data.marital} onChange={set('marital')}
            options={[
              { value: 'single',   label: '單身（未婚）' },
              { value: 'divorced', label: '離異' },
              { value: 'widowed',  label: '喪偶' },
              { value: 'separated',label: '分居' },
            ]} />
        </Field>

        <Field required label={<T zh="手機" en="Mobile" />} span={1}>
          <TextInput type="tel" value={data.phone} onChange={set('phone')} placeholder="09xx-xxx-xxx" />
        </Field>
        <Field required label={<T zh="電子郵件" en="Email" />} span={1}>
          <TextInput type="email" value={data.email} onChange={set('email')} placeholder="you@example.com" />
        </Field>

        <Field label={<T zh="如何認識覓 MEET2？" en="How did you hear about us?" />} span={2}>
          <Chips single value={data.source} onChange={set('source')}
            options={[
              { value: 'friend', label: <T zh="朋友推薦" en="A friend" /> },
              { value: 'media',  label: <T zh="媒體報導" en="Press" /> },
              { value: 'social', label: <T zh="社群平台" en="Social media" /> },
              { value: 'event',  label: <T zh="活動現場" en="An event" /> },
              { value: 'search', label: <T zh="網路搜尋" en="Online search" /> },
              { value: 'other',  label: <T zh="其他" en="Other" /> },
            ]} />
        </Field>
      </div>
    </>
  );
}

// ── Step 2 · About you ─────────────────────────────────
function StepAbout({ data, set }) {
  return (
    <>
      <StepHead idx={1} />
      <div className="apply-grid">
        <Field required label={<T zh="職業 / 職稱" en="Occupation / Title" />}>
          <TextInput value={data.job} onChange={set('job')} placeholder="產品經理 / Product Manager" />
        </Field>
        <Field required label={<T zh="產業" en="Industry" />}>
          <Select value={data.industry} onChange={set('industry')}
            options={['科技 / 軟體', '金融 / 投資', '醫療', '法律', '教育 / 學術',
                      '創意 / 設計', '製造業', '政府 / 公務', '創業 / 自雇', '其他']} />
        </Field>

        <Field required label={<T zh="最高學歷" en="Education" />}>
          <Select value={data.edu} onChange={set('edu')}
            options={['高中以下', '專科 / 副學士', '大學', '碩士', '博士']} />
        </Field>
        <Field label={<T zh="年收入區間" en="Annual income" />}
               hint={<T zh="僅作為配對參考，不公開" en="For matching only, never shown to others" />}>
          <Select value={data.income} onChange={set('income')}
            options={['不便透露', '60 萬以下', '60–100 萬', '100–200 萬', '200–500 萬', '500 萬以上']} />
        </Field>

        <Field required label={<T zh="身高（cm）" en="Height (cm)" />}>
          <TextInput type="number" value={data.height} onChange={set('height')} placeholder="170" />
        </Field>
        <Field label={<T zh="體型" en="Body type" />}>
          <Select value={data.body} onChange={set('body')}
            options={['纖細', '勻稱', '健壯 / 運動型', '豐滿', '偏胖', '不便透露']} />
        </Field>

        <Field label={<T zh="是否抽菸" en="Smoking" />}>
          <Chips single value={data.smoke} onChange={set('smoke')}
            options={[
              { value: 'no', label: <T zh="不抽" en="No" /> },
              { value: 'soc', label: <T zh="社交場合" en="Socially" /> },
              { value: 'yes', label: <T zh="會抽" en="Yes" /> },
            ]} />
        </Field>
        <Field label={<T zh="飲酒" en="Drinking" />}>
          <Chips single value={data.drink} onChange={set('drink')}
            options={[
              { value: 'no', label: <T zh="不喝" en="Never" /> },
              { value: 'soc', label: <T zh="社交場合" en="Socially" /> },
              { value: 'yes', label: <T zh="常喝" en="Often" /> },
            ]} />
        </Field>

        <Field label={<T zh="是否有子女" en="Children" />} span={1}>
          <Chips single value={data.kids} onChange={set('kids')}
            options={[
              { value: 'no', label: <T zh="沒有" en="None" /> },
              { value: 'yes_with', label: <T zh="有，同住" en="Yes, with me" /> },
              { value: 'yes_not', label: <T zh="有，未同住" en="Yes, not with me" /> },
            ]} />
        </Field>
        <Field label={<T zh="宗教 / 信仰" en="Faith" />} span={1}>
          <Select value={data.faith} onChange={set('faith')}
            options={['無特定信仰', '佛教', '道教', '一貫道', '基督教', '天主教', '伊斯蘭教', '其他']} />
        </Field>
      </div>
    </>
  );
}

// ── Step 3 · Seeking ───────────────────────────────────
function StepSeeking({ data, set }) {
  return (
    <>
      <StepHead idx={2} />
      <div className="apply-grid">
        <Field required label={<T zh="希望對象性別" en="Looking for" />}>
          <Chips single value={data.seekGender} onChange={set('seekGender')}
            options={[
              { value: 'f',  label: <T zh="女性" en="Female" /> },
              { value: 'm',  label: <T zh="男性" en="Male" /> },
              { value: 'any', label: <T zh="不限" en="Any" /> },
            ]} />
        </Field>
        <Field required label={<T zh="年齡區間" en="Age range" />}>
          <div className="apply-row">
            <TextInput type="number" value={data.ageMin} onChange={set('ageMin')} placeholder="28" />
            <span className="apply-row-sep">—</span>
            <TextInput type="number" value={data.ageMax} onChange={set('ageMax')} placeholder="42" />
          </div>
        </Field>

        <Field label={<T zh="希望對象所在地" en="Preferred location" />} span={2}>
          <Chips value={data.seekCity || []} onChange={set('seekCity')}
            options={['台北', '新北', '桃園', '新竹', '台中', '台南', '高雄', '不限', '海外可']} />
        </Field>

        <Field required label={<T zh="婚姻計畫" en="Marriage timeline" />} span={2}>
          <Chips single value={data.timeline} onChange={set('timeline')}
            options={[
              { value: '1y',  label: <T zh="一年內結婚" en="Within 1 year" /> },
              { value: '2y',  label: <T zh="兩年內結婚" en="Within 2 years" /> },
              { value: '3y',  label: <T zh="三到五年內" en="3–5 years" /> },
              { value: 'open', label: <T zh="遇到對的人再說" en="When it feels right" /> },
            ]} />
        </Field>

        <Field label={<T zh="是否想要孩子" en="Want children" />} span={2}>
          <Chips single value={data.wantKids} onChange={set('wantKids')}
            options={[
              { value: 'yes', label: <T zh="想要" en="Yes" /> },
              { value: 'open', label: <T zh="可以討論" en="Open" /> },
              { value: 'no',  label: <T zh="不想要" en="No" /> },
              { value: 'has', label: <T zh="已有，順其自然" en="Already have" /> },
            ]} />
        </Field>

        <Field label={<T zh="對方的「不可」（地雷）" en="Dealbreakers" />}
               hint={<T zh="勾選 0–4 項，協助顧問避雷" en="Pick up to 4. Helps your matchmaker steer clear." />}
               span={2}>
          <Chips value={data.dealbreakers || []} onChange={set('dealbreakers')}
            options={[
              { value: 'smoke',  label: <T zh="抽菸" en="Smoking" /> },
              { value: 'drink',  label: <T zh="重度飲酒" en="Heavy drinking" /> },
              { value: 'kids',   label: <T zh="不想要孩子" en="No kids" /> },
              { value: 'religion', label: <T zh="不同信仰" en="Different faith" /> },
              { value: 'distance', label: <T zh="遠距離" en="Long distance" /> },
              { value: 'divorced', label: <T zh="有婚姻紀錄" en="Previously married" /> },
              { value: 'haskids', label: <T zh="已有子女" en="Has children" /> },
            ]} />
        </Field>
      </div>
    </>
  );
}

// ── Step 4 · Values & life ─────────────────────────────
function StepValues({ data, set }) {
  return (
    <>
      <StepHead idx={3} />

      <Field required label={<T zh="一段自我介紹" en="A short self-introduction" />}
             hint={<T zh="可寫工作日常、業餘喜好、最近在讀的書 — 任何讓你感到自在的事" en="Daily life, what you love doing, a book you're reading — anything that feels like you." />}>
        <TextArea value={data.intro} onChange={set('intro')}
                  placeholder="例：在新創公司做產品，週末喜歡騎車去山裡看雲。最近迷上手沖咖啡⋯⋯"
                  rows={5} maxLength={500} />
      </Field>

      <Field required label={<T zh="你對「好的關係」是什麼想像？" en="What does a good relationship look like to you?" />}>
        <TextArea value={data.love} onChange={set('love')}
                  placeholder="例：可以一起安靜看書、也能在彼此低潮時陪伴⋯⋯"
                  rows={4} maxLength={400} />
      </Field>

      <div className="apply-grid">
        <Field label={<T zh="生活步調" en="Life pace" />}>
          <Chips single value={data.pace} onChange={set('pace')}
            options={[
              { value: 'fast',  label: <T zh="充滿挑戰" en="High-paced" /> },
              { value: 'mid',   label: <T zh="忙碌但有節奏" en="Balanced" /> },
              { value: 'slow',  label: <T zh="慢一點，更深一點" en="Slow & deep" /> },
            ]} />
        </Field>
        <Field label={<T zh="個性傾向" en="Personality" />}>
          <Chips single value={data.persona} onChange={set('persona')}
            options={[
              { value: 'i',  label: <T zh="內向" en="Introvert" /> },
              { value: 'mid', label: <T zh="平衡" en="Ambivert" /> },
              { value: 'e',   label: <T zh="外向" en="Extrovert" /> },
            ]} />
        </Field>

        <Field label={<T zh="興趣（多選）" en="Interests (multi)" />} span={2}>
          <Chips value={data.interests || []} onChange={set('interests')}
            options={[
              '閱讀', '電影', '音樂 / 演唱會', '美食探索', '咖啡 / 茶',
              '健身 / 運動', '登山 / 戶外', '旅行', '攝影', '藝術 / 展覽',
              '寵物', '園藝', '料理', '桌遊 / 棋類', '科技 / Gadget',
            ]} />
        </Field>

        <Field label={<T zh="對家庭的想像" en="Family vision" />} span={2}>
          <Chips single value={data.family} onChange={set('family')}
            options={[
              { value: 'classic', label: <T zh="希望有屬於兩人的家，孩子是加分" en="A home of our own — kids a plus" /> },
              { value: 'kids',    label: <T zh="非常希望有孩子" en="Strongly want kids" /> },
              { value: 'dink',    label: <T zh="兩人世界即可" en="Just the two of us" /> },
              { value: 'open',    label: <T zh="開放，跟對方討論" en="Open to discuss" /> },
            ]} />
        </Field>
      </div>
    </>
  );
}

// ── Step 5 · Verify & submit ───────────────────────────
function StepFinish({ data, set }) {
  return (
    <>
      <StepHead idx={4} />

      <div className="apply-verify">
        <div className="apply-verify-row">
          <h4><T zh="身分證明上傳" en="Identity verification" /></h4>
          <p><T
            zh="請上傳：身分證／護照其中一項，並可選擇婚姻狀態證明（單身證明、離婚證明）。"
            en="Upload one of: National ID or passport. Optionally include a marital-status certificate."
          /></p>
          <div className="apply-uploads">
            <UploadSlot id="u-id"       label={<T zh="身分證 / 護照" en="ID / Passport" />} value={data.docId}   onChange={set('docId')} />
            <UploadSlot id="u-marital"  label={<T zh="婚姻狀態證明" en="Marital cert." />}     value={data.docMarital} onChange={set('docMarital')} />
            <UploadSlot id="u-photo"    label={<T zh="近期照片 ×3" en="Recent photos ×3" />}    value={data.docPhotos}   onChange={set('docPhotos')} multi />
          </div>
        </div>

        <div className="apply-summary">
          <h4><T zh="申請摘要" en="Application summary" /></h4>
          <ul>
            <SummaryRow k={<T zh="姓名" en="Name" />} v={data.name} />
            <SummaryRow k={<T zh="性別 / 年齡" en="Gender / Age" />} v={`${labelOf(data.gender, {f:'女',m:'男',nb:'非二元'})} · ${ageFrom(data.dob)}`} />
            <SummaryRow k={<T zh="城市" en="City" />} v={data.city} />
            <SummaryRow k={<T zh="職業" en="Occupation" />} v={data.job} />
            <SummaryRow k={<T zh="婚姻計畫" en="Timeline" />} v={labelOf(data.timeline, {'1y':'一年內','2y':'兩年內','3y':'三到五年','open':'順其自然'})} />
          </ul>
        </div>

        <label className="apply-consent">
          <input type="checkbox" checked={!!data.consent} onChange={(e) => set('consent')(e.target.checked)} />
          <span>
            <T
              zh={<>我已閱讀並同意 <a href="#">隱私權政策</a> 與 <a href="#">會員約款</a>，並理解所有資料皆受加密保護。</>}
              en={<>I have read and agree to the <a href="#">Privacy Policy</a> and <a href="#">Member Terms</a>, and understand all data is encrypted.</>} />
          </span>
        </label>
      </div>
    </>
  );
}

function ageFrom(dob) {
  if (!dob) return '—';
  const d = new Date(dob);
  if (isNaN(+d)) return '—';
  const diff = Date.now() - d.getTime();
  const yrs = Math.floor(diff / (365.25 * 24 * 3600 * 1000));
  return yrs > 0 ? `${yrs}` : '—';
}
function labelOf(v, m) { return v && m[v] ? m[v] : '—'; }

function SummaryRow({ k, v }) {
  return <li><span>{k}</span><b>{v || '—'}</b></li>;
}

function UploadSlot({ id, label, value, onChange, multi = false }) {
  const fileRef = React.useRef(null);
  const has = multi ? (Array.isArray(value) && value.length) : !!value;
  const handle = (e) => {
    const files = [...e.target.files];
    if (!files.length) return;
    if (multi) onChange((value || []).concat(files.map((f) => f.name)));
    else onChange(files[0].name);
  };
  return (
    <button type="button" className={`apply-upload ${has ? 'is-has' : ''}`} onClick={() => fileRef.current?.click()}>
      <input ref={fileRef} type="file" hidden multiple={multi}
             accept="image/*,application/pdf" onChange={handle} />
      <div className="apply-upload-icon">
        {has ? <Check2 /> : <UploadIcon />}
      </div>
      <div className="apply-upload-label">{label}</div>
      <div className="apply-upload-state">
        {has
          ? (multi ? `${value.length} ${'file(s)'}` : value)
          : <T zh="點擊上傳" en="Click to upload" />}
      </div>
    </button>
  );
}
function UploadIcon() {
  return <svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M8 11V3M8 3l-3 3M8 3l3 3M3 12v1.5A1.5 1.5 0 004.5 15h7A1.5 1.5 0 0013 13.5V12" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round"/></svg>;
}

// ── Step head ──────────────────────────────────────────
function StepHead({ idx }) {
  const s = STEPS[idx];
  const sub = [
    { zh: '基本聯絡資訊與所在地，我們才能安排顧問與你聯繫。',     en: 'Basic contact information so a matchmaker can reach you.' },
    { zh: '你的背景與生活狀態 — 這是配對的起點。',                en: 'Your background — the starting point for matching.' },
    { zh: '請告訴顧問你心中那個人的輪廓。',                       en: 'Tell us about the person you’re looking for.' },
    { zh: '比起條件，我們更想了解你怎麼看待愛與生活。',           en: 'Beyond the bullet points: how you see love and life.' },
    { zh: '最後一步 — 上傳證明、確認資訊、送出。',                en: 'Final step — verify your identity and submit.' },
  ][idx];
  return (
    <header className="apply-step-head">
      <span className="apply-step-no">Step 0{idx + 1} / 0{STEPS.length}</span>
      <h2><T zh={s.zh} en={s.en} /></h2>
      <p><T zh={sub.zh} en={sub.en} /></p>
    </header>
  );
}

// ── Submitted state ────────────────────────────────────
function SubmitDone({ onReset, data }) {
  return (
    <section className="apply-done">
      <div className="apply-done-inner">
        <div className="apply-done-mark"><Check2 /></div>
        <span className="m-eyebrow"><T zh="申請已送出" en="Application received" /></span>
        <h1>
          <T zh={<>謝謝你，{data.nickname || ''}。<br/>顧問會在 3 個工作日內聯繫你。</>}
             en={<>Thank you, {data.nickname || 'friend'}.<br/>A matchmaker will be in touch within 3 business days.</>} />
        </h1>
        <p>
          <T zh="我們也會寄一封確認信到你的信箱，內含面談時段預約連結與隱私說明。"
             en="A confirmation email is on its way, with a link to book your interview and a note on privacy." />
        </p>
        <div className="apply-done-cta">
          <a href="index.html" className="m-btn m-btn-primary">
            <T zh="回到首頁" en="Back to home" /> <ArrowA />
          </a>
          <button type="button" className="m-btn m-btn-ghost" onClick={onReset}>
            <T zh="重新填寫" en="Start over" />
          </button>
        </div>
      </div>
    </section>
  );
}

window.ApplyForm = ApplyForm;
