// sections2.jsx — Keitta 랜딩 섹션들 (데이터, 후기, FAQ, 베타폼, 푸터)

const C2 = window.KEITTA_COLORS;
const { Section, SectionLabel, SectionTitle, DarkLabel, ConnectorDot } = window.LandingSections1;

// ─────────────────────────────────────────────────────────────────────────────
// DonutChart — 참고 인포그래픽 스타일
function Donut({ value, label, color = C2.body, size = 160, total = '1,000명' }) {
  const r = 60;
  const C_LEN = 2 * Math.PI * r;
  const dash = (value / 100) * C_LEN;
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', position: 'relative' }}>
      <svg width={size} height={size} viewBox="0 0 160 160">
        <circle cx="80" cy="80" r={r} fill="none" stroke="#E5E0F2" strokeWidth="20"/>
        <circle cx="80" cy="80" r={r} fill="none" stroke={color} strokeWidth="20"
                strokeDasharray={`${dash} ${C_LEN - dash}`}
                strokeDashoffset={C_LEN / 4}
                strokeLinecap="round"
                transform="rotate(-90 80 80)"/>
        <text x="80" y="76" textAnchor="middle" fontSize="11" fill="#7A6FA0" fontWeight="500">그렇다</text>
        <text x="80" y="98" textAnchor="middle" fontSize="22" fill={color} fontWeight="800">{value}%</text>
      </svg>
      <div style={{ fontSize: 11, color: '#9A92B5', marginTop: -4 }}>(전체 : {total})</div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// 5. INSIGHTS — 정성 인터뷰 인용 (가짜 통계 대신)
function Data() {
  const insights = [
    {
      n: '01',
      quote: '“샀을 땐 분명히 이유가 있었는데,\n며칠 지나면 그냥 흐려져요.”',
      tag: '판단의 근거가 시간이 지나면 휘발됨',
    },
    {
      n: '02',
      quote: '“커뮤니티 분위기였는지,\n진짜 분석이었는지 헷갈려요.”',
      tag: '감정 신호와 분석의 분리가 어려움',
    },
    {
      n: '03',
      quote: '“수익률은 보이는데,\n그때 내 판단은 안 보이거든요.”',
      tag: '결과 데이터는 있지만 판단 자체가 기록되지 않음',
    },
    {
      n: '04',
      quote: '“나중에 다시 보면 좋겠는데,\n어디 적어두진 않게 돼요.”',
      tag: '회고의 필요는 있지만 기록 도구가 없음',
    },
  ];
  return (
    <Section style={{ background: '#F4F0FF', padding: '140px 24px' }}>
      <div style={{ marginBottom: 56, position: 'relative' }}>
        <SectionLabel>WHAT WE HEARD</SectionLabel>
        <SectionTitle>
          개인 투자자들의 이야기를<br/>들어봤습니다.
        </SectionTitle>
        <p style={{ marginTop: 18, fontSize: 14, color: '#7A6FA0', textWrap: 'pretty' }}>
          베타를 준비하며 만난 분들에게서 반복해서 나온 말들입니다.<br/>
          이 말들이 Keitta가 시작된 자리입니다.
        </p>
        <div style={{ position: 'absolute', top: -30, right: 20, transform: 'rotate(8deg)' }}>
          <Keitta pose="point" size={110}/>
        </div>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(360px, 1fr))', gap: 32 }}>
        {insights.map((c, i) => (
          <div key={i}>
            <div style={{
              background: 'white', borderRadius: 20, padding: '36px 32px 32px',
              minHeight: 220,
              border: '1px solid rgba(26,21,48,0.04)',
              position: 'relative',
              display: 'flex', flexDirection: 'column',
            }}>
              <div style={{
                fontSize: 11, fontWeight: 800, color: C2.body,
                letterSpacing: '0.14em', marginBottom: 16,
              }}>VOICE {c.n}</div>

              {/* 큰 따옴표 장식 */}
              <div style={{
                position: 'absolute', top: 20, right: 28,
                fontSize: 56, lineHeight: 1, color: 'rgba(124,92,252,0.14)',
                fontFamily: 'Georgia, serif', fontWeight: 700,
              }}>“</div>

              <div style={{
                fontSize: 17, fontWeight: 600, color: '#1A1530', lineHeight: 1.6,
                letterSpacing: '-0.01em', whiteSpace: 'pre-line',
                textWrap: 'pretty', flex: 1,
              }}>{c.quote}</div>
            </div>
            <ConnectorDot style={{ marginTop: 16, marginBottom: 12 }}/>
            <DarkLabel>{c.tag}</DarkLabel>
          </div>
        ))}
      </div>

      {/* 푸터 노트 — 출처 솔직하게 */}
      <div style={{
        marginTop: 40, padding: '18px 22px',
        background: 'rgba(255,255,255,0.5)', borderRadius: 12,
        border: '1px solid rgba(124,92,252,0.12)',
        fontSize: 12.5, color: '#7A6FA0', lineHeight: 1.6, textWrap: 'pretty',
      }}>
        <span style={{ fontWeight: 700, color: '#3D2799' }}>NOTE.</span>{' '}
        위 인용은 베타 준비 과정에서 만난 분들의 말을 정리한 것입니다.
        통계가 아니라, 반복해서 들렸던 결의 이야기입니다.
      </div>
    </Section>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// 6. PRINCIPLES — 베타가 약속하는 것 (가짜 후기 대신)
function Testimonials() {
  const principles = [
    {
      n: '01', label: '판단을 점수로 매기지 않습니다.',
      desc: '“얼마나 좋은 판단인가”가 아니라 “어디에서 흔들렸나”를 봅니다.\n맞고 틀림은 시장이 정합니다.',
    },
    {
      n: '02', label: '광고처럼 말하지 않습니다.',
      desc: '결과를 부풀리거나 손실을 위협으로 쓰지 않습니다.\n담담한 거울이 되는 것이 목표입니다.',
    },
    {
      n: '03', label: '기록은 사용자의 것입니다.',
      desc: '입력한 판단은 암호화되어 저장되며,\n학습 목적의 외부 공유는 없습니다. 언제든 전체 삭제 가능합니다.',
    },
  ];
  return (
    <Section style={{ background: 'white' }}>
      <div style={{ marginBottom: 56, position: 'relative' }}>
        <SectionLabel>OUR PRINCIPLES</SectionLabel>
        <SectionTitle>
          베타에서, 그리고 그 이후에도<br/>
          지키려는 것들.
        </SectionTitle>
        <div style={{ position: 'absolute', top: -10, right: 0, transform: 'rotate(-6deg)' }}>
          <Keitta pose="sit" size={100}/>
        </div>
      </div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
        {principles.map((p, i) => (
          <div key={i} style={{
            display: 'grid', gridTemplateColumns: '60px 1fr', gap: 24,
            padding: '28px 32px',
            background: '#FAF8FF', borderRadius: 20,
            border: '1px solid rgba(124,92,252,0.1)',
            alignItems: 'flex-start',
          }}>
            <div style={{
              fontSize: 14, fontWeight: 800, color: C2.body,
              letterSpacing: '0.12em', paddingTop: 4,
            }}>{p.n}</div>
            <div>
              <div style={{
                fontSize: 19, fontWeight: 700, color: '#1A1530',
                letterSpacing: '-0.015em', lineHeight: 1.4, textWrap: 'pretty',
              }}>{p.label}</div>
              <div style={{
                fontSize: 14, color: '#5A5470', marginTop: 10,
                lineHeight: 1.7, whiteSpace: 'pre-line', textWrap: 'pretty',
              }}>{p.desc}</div>
            </div>
          </div>
        ))}
      </div>
    </Section>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// 7. FAQ
function FAQ() {
  const items = [
    { q: '베타는 무료인가요?', a: '네, 클로즈드 베타 기간 동안은 무료입니다. 정식 출시 이후 요금 정책은 별도로 안내드립니다.' },
    { q: '매매 데이터를 직접 가져가나요?', a: '아니요. 사용자가 직접 입력한 매매 종목과 한 줄 이유만 다룹니다. 증권사 연동은 베타에서 다루지 않습니다.' },
    { q: '제 기록은 안전한가요?', a: '입력한 판단 기록은 암호화 저장되며, 학습 목적의 외부 공유는 없습니다. 언제든 전체 삭제 가능합니다.' },
    { q: 'AI는 어떤 기준으로 판단을 분석하나요?', a: '근거의 구체성·감정 신호·시점 의존도 같은 축으로 한 줄을 분리해 보여줍니다. 옳다/틀리다가 아니라 흔들린 지점을 짚는 방식입니다.' },
    { q: '안드로이드/iOS 둘 다 되나요?', a: '베타는 모바일 웹으로 시작합니다. 정식 앱은 베타 피드백을 반영해 준비 중입니다.' },
  ];
  const [open, setOpen] = React.useState(0);
  return (
    <Section style={{ background: '#FAF8FF' }}>
      <div style={{ display: 'grid', gridTemplateColumns: 'minmax(0, 320px) 1fr', gap: 56, alignItems: 'flex-start' }}>
        <div style={{ position: 'sticky', top: 40 }}>
          <SectionLabel>FAQ</SectionLabel>
          <SectionTitle style={{ fontSize: 32 }}>자주 묻는 것들.</SectionTitle>
          <div style={{ marginTop: 32, transform: 'rotate(-4deg)' }}>
            <Keitta pose="sit" size={130}/>
          </div>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
          {items.map((it, i) => (
            <div key={i} style={{
              background: 'white', borderRadius: 16,
              border: '1px solid rgba(26,21,48,0.06)',
              overflow: 'hidden',
            }}>
              <button onClick={() => setOpen(open === i ? -1 : i)} style={{
                width: '100%', padding: '20px 24px',
                display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16,
                background: 'transparent', border: 0, cursor: 'pointer',
                fontSize: 15, fontWeight: 700, color: '#1A1530', textAlign: 'left',
              }}>
                <span style={{ flex: 1, minWidth: 0 }}>{it.q}</span>
                <span style={{
                  width: 24, height: 24, borderRadius: '50%',
                  flexShrink: 0,
                  background: open === i ? C2.body : 'rgba(124,92,252,0.12)',
                  color: open === i ? 'white' : C2.body,
                  display: 'flex', alignItems: 'center', justifyContent: 'center',
                  fontSize: 14, transition: 'all .2s',
                }}>{open === i ? '−' : '+'}</span>
              </button>
              {open === i && (
                <div style={{
                  padding: '0 24px 22px', fontSize: 14, lineHeight: 1.7,
                  color: '#5A5470', textWrap: 'pretty',
                }}>{it.a}</div>
              )}
            </div>
          ))}
        </div>
      </div>
    </Section>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// 8. BETA FORM
// [β-Phase L-B] hardcoded 자체 동작 (setSubmitted) → props 인터페이스 변환.
// 비주얼 JSX 0 변경 (form 디자인 / 색상 / 레이아웃 100% 보존).
// captchaSlot 자리 추가 — agree 체크박스 위에 {captchaSlot} (Wrapper에서 Turnstile mount div 전달).
//   mockup 자체엔 Turnstile 자리 부재 → form 내부 적절한 위치 결정 (트래킹 문서 명시).
// onSubmit 성공 시 자체 setSubmitted(true), 실패 시 errorMsg 표시.
function BetaForm({ onSubmit, captchaSlot, errorMsg, loading }) {
  const [email, setEmail] = React.useState('');
  const [name, setName] = React.useState('');
  const [reason, setReason] = React.useState('');
  const [agree, setAgree] = React.useState(false);
  const [submitted, setSubmitted] = React.useState(false);

  const handleSubmit = async (e) => {
    e.preventDefault();
    if (!agree || !email) return;
    if (!onSubmit) { setSubmitted(true); return; }
    const ok = await onSubmit({ email, name, reason });
    if (ok) setSubmitted(true);
  };

  return (
    <Section id="beta" style={{
      background: 'linear-gradient(180deg, #2A2440 0%, #1A1530 100%)',
      padding: '120px 24px',
    }}>
      <div style={{ maxWidth: 560, margin: '0 auto', textAlign: 'center', position: 'relative' }}>
        <div style={{
          display: 'inline-flex', padding: '6px 14px', borderRadius: 999,
          background: 'rgba(124,92,252,0.18)', color: '#A892FF',
          fontSize: 11, fontWeight: 800, letterSpacing: '0.14em',
          marginBottom: 24,
        }}>BETA</div>
        <h2 style={{
          fontSize: 36, fontWeight: 800, color: 'white',
          margin: 0, letterSpacing: '-0.02em', lineHeight: 1.3,
        }}>지금은 클로즈드 베타입니다.</h2>
        <p style={{ marginTop: 16, fontSize: 15, lineHeight: 1.7, color: '#B5AED0' }}>
          먼저 써볼 분을 모집하고 있습니다.<br/>
          신청해주시면 검토 후 안내드립니다. 무료입니다.
        </p>

        <div style={{ position: 'absolute', top: -30, right: -20, transform: 'rotate(12deg)' }}>
          <Keitta pose="jump" size={90}/>
        </div>

        {submitted ? (
          <div style={{
            marginTop: 40, padding: '40px 32px',
            background: 'rgba(124,92,252,0.12)', borderRadius: 20,
            border: '1px solid rgba(124,92,252,0.3)',
          }}>
            <div style={{ display: 'flex', justifyContent: 'center', marginBottom: 12 }}>
              <Keitta pose="wave" size={80}/>
            </div>
            <div style={{ color: 'white', fontSize: 18, fontWeight: 700 }}>신청이 접수되었습니다.</div>
            <div style={{ color: '#B5AED0', fontSize: 14, marginTop: 8 }}>
              검토 후 입력해주신 이메일로 안내드릴게요.
            </div>
          </div>
        ) : (
          <form onSubmit={handleSubmit}
                style={{
                  marginTop: 40, padding: '32px 28px',
                  background: 'rgba(255,255,255,0.04)', borderRadius: 20,
                  border: '1px solid rgba(124,92,252,0.25)',
                  textAlign: 'left',
                }}>
            {[
              { label: '이메일', required: true, val: email, set: setEmail, ph: 'you@example.com', type: 'email' },
              { label: '이름 / 닉네임', val: name, set: setName, ph: '예: 비투자', type: 'text' },
            ].map((f, i) => (
              <div key={i} style={{ marginBottom: 18 }}>
                <label style={{ display: 'block', fontSize: 12, color: '#B5AED0', fontWeight: 600, marginBottom: 8 }}>
                  {f.label} {f.required && <span style={{ color: '#A892FF' }}>*</span>}
                </label>
                <input type={f.type} required={f.required} value={f.val} onChange={e => f.set(e.target.value)}
                       placeholder={f.ph}
                       style={{
                         width: '100%', padding: '14px 16px',
                         background: 'rgba(255,255,255,0.06)',
                         border: '1px solid rgba(255,255,255,0.1)',
                         borderRadius: 10, color: 'white', fontSize: 14, outline: 'none',
                         boxSizing: 'border-box',
                       }}/>
              </div>
            ))}
            <div style={{ marginBottom: 18 }}>
              <label style={{ display: 'block', fontSize: 12, color: '#B5AED0', fontWeight: 600, marginBottom: 8 }}>
                신청 이유 / 투자 경험 (선택)
              </label>
              <textarea value={reason} onChange={e => setReason(e.target.value.slice(0, 200))}
                        placeholder="어떤 점이 궁금하신가요? 200자 이내."
                        rows={4}
                        style={{
                          width: '100%', padding: '14px 16px',
                          background: 'rgba(255,255,255,0.06)',
                          border: '1px solid rgba(255,255,255,0.1)',
                          borderRadius: 10, color: 'white', fontSize: 14, outline: 'none',
                          boxSizing: 'border-box', resize: 'vertical', fontFamily: 'inherit',
                        }}/>
              <div style={{ textAlign: 'right', fontSize: 11, color: '#7A6FA0', marginTop: 4 }}>{reason.length}/200</div>
            </div>
            {captchaSlot && (
              <div style={{ marginBottom: 18, display: 'flex', justifyContent: 'center' }}>
                {captchaSlot}
              </div>
            )}
            <label style={{ display: 'flex', alignItems: 'flex-start', gap: 10, fontSize: 12.5, color: '#B5AED0', cursor: 'pointer', lineHeight: 1.5 }}>
              <input type="checkbox" checked={agree} onChange={e => setAgree(e.target.checked)}
                     style={{ marginTop: 3, accentColor: C2.body }}/>
              <span>개인정보 수집·이용에 동의합니다 (이메일·이름·신청 이유, 베타 운영 목적).</span>
            </label>
            {errorMsg && (
              <div style={{ marginTop: 12, padding: '10px 14px', background: 'rgba(248,113,113,0.12)', border: '1px solid rgba(248,113,113,0.3)', borderRadius: 10, color: '#F87171', fontSize: 13 }}>
                ⚠ {errorMsg}
              </div>
            )}
            <button type="submit" disabled={!agree || !email || loading}
                    style={{
                      width: '100%', marginTop: 20, padding: '16px',
                      background: agree && email && !loading ? C2.body : 'rgba(124,92,252,0.3)',
                      border: 0, borderRadius: 12, color: 'white',
                      fontSize: 15, fontWeight: 700, cursor: agree && email && !loading ? 'pointer' : 'not-allowed',
                      boxShadow: agree && email && !loading ? '0 8px 22px rgba(124,92,252,0.4)' : 'none',
                      transition: 'all .15s',
                    }}>
              {loading ? '전송 중…' : '신청하기 →'}
            </button>
          </form>
        )}
      </div>
    </Section>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// 9. FOOTER
function Footer() {
  return (
    <footer style={{
      background: '#1A1530', color: '#7A6FA0',
      padding: '40px 24px', borderTop: '1px solid rgba(124,92,252,0.15)',
    }}>
      <div style={{
        maxWidth: 1080, margin: '0 auto',
        display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: 16,
      }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
          <Keitta pose="default" size={32}/>
          <span style={{ fontSize: 14, fontWeight: 700, color: '#B5AED0' }}>Keitta</span>
          <span style={{ fontSize: 12, marginLeft: 12 }}>© 2026 Keitta</span>
        </div>
        <div style={{ display: 'flex', gap: 20, fontSize: 12, flexWrap: 'wrap' }}>
          {['개인정보처리방침', '이용약관', '베타 약관', '문의'].map((x, i) => (
            <a key={i} href="#" style={{ color: '#7A6FA0', textDecoration: 'none', whiteSpace: 'nowrap' }}>{x}</a>
          ))}
        </div>
      </div>
    </footer>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// NAV
function Nav() {
  return (
    <nav style={{
      position: 'fixed', top: 0, left: 0, right: 0, zIndex: 100,
      padding: '16px 24px',
      background: 'rgba(255,255,255,0.85)',
      backdropFilter: 'blur(20px)',
      borderBottom: '1px solid rgba(26,21,48,0.06)',
    }}>
      <div style={{
        maxWidth: 1080, margin: '0 auto',
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
      }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
          <Keitta pose="default" size={32}/>
          <span style={{ fontSize: 17, fontWeight: 800, color: '#1A1530', letterSpacing: '-0.02em' }}>Keitta</span>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 24 }}>
          <a href="#how" style={{ fontSize: 13, fontWeight: 600, color: '#5A5470', textDecoration: 'none' }}>사용법</a>
          <a href="#beta" style={{
            padding: '8px 16px', borderRadius: 8,
            background: '#1A1530', color: 'white', fontSize: 13, fontWeight: 700,
            whiteSpace: 'nowrap',
            textDecoration: 'none',
          }}>베타 신청</a>
        </div>
      </div>
    </nav>
  );
}

window.LandingSections2 = { Data, Testimonials, FAQ, BetaForm, Footer, Nav };
