// screens-public.jsx — 공개 출입신청 폼 + QR 이메일/카톡 미리보기

// ═══════════════════════════════════════════════════════════════
// 출입신청 (방문객 작성)
// ═══════════════════════════════════════════════════════════════
function PublicForm() {
  return (
    <div style={{ width: '100%', height: '100%', background: 'var(--paper-1)', color: 'var(--ink-0)', fontFamily: 'var(--font-sans)', display: 'flex', flexDirection: 'column' }}>
      {/* Top brand bar */}
      <header style={{ padding: '18px 56px', borderBottom: '0.5px solid var(--paper-stroke)', display: 'flex', alignItems: 'center', justifyContent: 'space-between', background: 'var(--paper-0)' }}>
        <Brandmark size={22} />
        <div style={{ display: 'flex', gap: 24, fontSize: 13, color: 'var(--ink-2)' }}>
          <a href={ROUTES.mQR} style={{ color: 'inherit', textDecoration: 'none' }}>내 방문증</a>
          <a href={ROUTES.kiosk} style={{ color: 'inherit', textDecoration: 'none' }}>단말기</a>
          <a href={ROUTES.admin} style={{ color: 'inherit', textDecoration: 'none' }}>관리자 로그인</a>
        </div>
      </header>

      <div style={{ flex: 1, display: 'grid', gridTemplateColumns: '1fr 380px', gap: 0, overflow: 'hidden' }}>
        {/* Left: form column */}
        <div style={{ padding: '48px 80px', overflow: 'auto', display: 'flex', flexDirection: 'column', gap: 36, background: 'var(--paper-0)' }}>
          <div>
            <div style={{ fontSize: 11, color: 'var(--ink-3)', letterSpacing: '0.2em', textTransform: 'uppercase', marginBottom: 14 }}>출입신청 · STEP 2 / 3</div>
            <div className="serif" style={{ fontSize: 36, fontWeight: 500, letterSpacing: '-0.02em', lineHeight: 1.15, marginBottom: 12 }}>
              어떤 일로<br/>방문하시나요?
            </div>
            <div style={{ fontSize: 13.5, color: 'var(--ink-2)', maxWidth: 480, lineHeight: 1.6 }}>
              호스트 승인 후 입력하신 연락처로 일회용 QR을 발송해드립니다.<br/>
              QR은 약속 시간 30분 전부터 사용할 수 있어요.
            </div>
          </div>

          {/* Steps progress */}
          <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
            {[
              { n:1, label:'본인 정보', done:true },
              { n:2, label:'방문 목적', current:true },
              { n:3, label:'확인 · 제출' },
            ].map((s, i, arr) => (
              <React.Fragment key={s.n}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                  <div style={{
                    width: 22, height: 22, borderRadius: 100,
                    background: s.done ? 'var(--ink-0)' : s.current ? 'var(--ink-0)' : 'var(--paper-2)',
                    color: s.done || s.current ? 'var(--paper-0)' : 'var(--ink-3)',
                    display: 'flex', alignItems: 'center', justifyContent: 'center',
                    fontSize: 11, fontWeight: 500,
                  }}>{s.done ? <Icon name="check" size={11} color="var(--paper-0)" /> : s.n}</div>
                  <span style={{ fontSize: 12, color: s.current ? 'var(--ink-0)' : 'var(--ink-3)', fontWeight: s.current ? 500 : 400 }}>{s.label}</span>
                </div>
                {i < arr.length - 1 && <div style={{ flex: '0 0 32px', height: '0.5px', background: 'var(--paper-stroke)' }} />}
              </React.Fragment>
            ))}
          </div>

          <div style={{ display: 'flex', flexDirection: 'column', gap: 22, maxWidth: 560 }}>
            <Field label="방문 목적" required>
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 8 }}>
                {[
                  { k:'meeting', label:'미팅', icon:'users', on:true },
                  { k:'delivery', label:'납품·수거', icon:'door' },
                  { k:'interview', label:'면접', icon:'user' },
                  { k:'event', label:'행사·세미나', icon:'calendar' },
                  { k:'maintenance', label:'점검·시공', icon:'settings' },
                  { k:'etc', label:'기타', icon:'plus' },
                ].map(o => (
                  <button key={o.k} style={{
                    display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 8,
                    padding: '14px 14px', border: o.on ? '1px solid var(--ink-0)' : '0.5px solid var(--paper-stroke)',
                    borderRadius: 9, background: o.on ? 'var(--paper-1)' : 'var(--paper-0)', cursor: 'pointer', fontFamily: 'inherit',
                    color: 'var(--ink-0)', fontSize: 12.5, fontWeight: 500, textAlign: 'left',
                  }}>
                    <Icon name={o.icon} size={15} color="var(--ink-1)" />
                    {o.label}
                  </button>
                ))}
              </div>
            </Field>

            <Field label="호스트" required hint="검색하면 자동완성됩니다">
              <div style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '14px 16px', border: '0.5px solid var(--paper-stroke)', borderRadius: 8, background: 'var(--paper-0)' }}>
                <Avatar name="박" size={28} />
                <div style={{ flex: 1 }}>
                  <div style={{ fontSize: 13, fontWeight: 500 }}>박정민 책임</div>
                  <div style={{ fontSize: 11, color: 'var(--ink-3)' }}>디자인팀 · jm.park@company.kr</div>
                </div>
                <Icon name="check" size={14} color="var(--celadon-deep)" />
              </div>
            </Field>

            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16 }}>
              <Field label="방문일" required>
                <div style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '12px 14px', border: '0.5px solid var(--paper-stroke)', borderRadius: 8, background: 'var(--paper-0)' }}>
                  <Icon name="calendar" size={14} color="var(--ink-2)" />
                  <span style={{ fontSize: 13, color: 'var(--ink-0)' }}>2026년 5월 8일 (금)</span>
                </div>
              </Field>
              <Field label="시간" required>
                <div style={{ display: 'flex', gap: 8 }}>
                  <div style={{ flex: 1, display: 'flex', alignItems: 'center', gap: 10, padding: '12px 14px', border: '0.5px solid var(--paper-stroke)', borderRadius: 8, background: 'var(--paper-0)' }}>
                    <Icon name="clock" size={14} color="var(--ink-2)" />
                    <span className="tabular" style={{ fontSize: 13 }}>15:00</span>
                  </div>
                  <span style={{ alignSelf: 'center', color: 'var(--ink-3)' }}>—</span>
                  <div style={{ flex: 1, display: 'flex', alignItems: 'center', gap: 10, padding: '12px 14px', border: '0.5px solid var(--paper-stroke)', borderRadius: 8, background: 'var(--paper-0)' }}>
                    <span className="tabular" style={{ fontSize: 13 }}>17:00</span>
                  </div>
                </div>
              </Field>
            </div>

            <Field label="상세 내용">
              <div style={{ padding: '14px 16px', border: '0.5px solid var(--paper-stroke)', borderRadius: 8, background: 'var(--paper-0)', minHeight: 86, fontSize: 13, color: 'var(--ink-1)', lineHeight: 1.6 }}>
                프로젝트 시안 리뷰 미팅입니다. 디자인 시안 출력본과 노트북 1대를 지참할 예정입니다.
                <span style={{ display: 'inline-block', width: 1.5, height: 14, background: 'var(--ink-0)', verticalAlign: 'middle', marginLeft: 2, animation: 'blink 1s infinite' }} />
              </div>
            </Field>

            <Field label="추가 옵션">
              <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
                <Check on>구내식당 식권 1매 요청 (호스트 승인 시)</Check>
                <Check on>주차 등록 · 차량번호 25가 4719</Check>
                <Check>동반자 추가</Check>
              </div>
            </Field>

            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', paddingTop: 12 }}>
              <button style={{ background: 'transparent', border: '0.5px solid var(--paper-stroke)', padding: '11px 20px', borderRadius: 8, fontSize: 13, color: 'var(--ink-2)', cursor: 'pointer', fontFamily: 'inherit' }}>이전</button>
              <button style={{ background: 'var(--ink-0)', color: 'var(--paper-0)', border: 'none', padding: '12px 28px', borderRadius: 8, fontSize: 13, fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit', display: 'flex', alignItems: 'center', gap: 8 }}>
                다음 단계 <Icon name="arrow" size={13} color="var(--paper-0)" />
              </button>
            </div>
          </div>
        </div>

        {/* Right: live preview */}
        <aside style={{ background: 'var(--paper-1)', borderLeft: '0.5px solid var(--paper-stroke)', padding: '48px 32px', overflow: 'auto' }}>
          <div style={{ fontSize: 11, color: 'var(--ink-3)', letterSpacing: '0.2em', textTransform: 'uppercase', marginBottom: 14 }}>실시간 요약</div>
          <div style={{ background: 'var(--paper-0)', border: '0.5px solid var(--paper-stroke)', borderRadius: 'var(--r-md)', overflow: 'hidden' }}>
            <div style={{ padding: '18px 20px', borderBottom: '0.5px solid var(--paper-stroke)', display: 'flex', alignItems: 'center', gap: 12 }}>
              <Avatar name="김" size={36} />
              <div>
                <div style={{ fontSize: 13.5, fontWeight: 500 }}>김도현</div>
                <div style={{ fontSize: 11, color: 'var(--ink-3)' }}>(주) 한솔디자인</div>
              </div>
            </div>
            <div style={{ padding: '14px 20px', display: 'flex', flexDirection: 'column', gap: 10 }}>
              <SumRow label="목적">미팅</SumRow>
              <SumRow label="호스트">박정민 · 디자인팀</SumRow>
              <SumRow label="일시">5/8 (금) 15:00—17:00</SumRow>
              <SumRow label="추가">식권 · 주차</SumRow>
            </div>
            <div style={{ padding: '14px 20px', borderTop: '0.5px solid var(--paper-stroke)', background: 'var(--celadon-soft)', display: 'flex', alignItems: 'center', gap: 10 }}>
              <Icon name="shield" size={14} color="var(--celadon-deep)" />
              <span style={{ fontSize: 11, color: 'var(--celadon-deep)', fontWeight: 500 }}>호스트 승인 후 QR 자동 발송</span>
            </div>
          </div>

          <div style={{ marginTop: 24, padding: 18, border: '0.5px dashed var(--paper-stroke)', borderRadius: 'var(--r-md)' }}>
            <div style={{ fontSize: 11, color: 'var(--ink-3)', letterSpacing: '0.04em', marginBottom: 8 }}>전송 채널 (선택)</div>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 6, fontSize: 12 }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, color: 'var(--ink-1)' }}>
                <Icon name="mail" size={12} color="var(--celadon-deep)" /> 이메일 · dh.kim@hansol.design
              </div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, color: 'var(--ink-1)' }}>
                <Icon name="msg" size={12} color="var(--celadon-deep)" /> SMS · 010-4827-3091
              </div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, color: 'var(--ink-1)' }}>
                <Icon name="msg" size={12} color="var(--celadon-deep)" /> 카카오 알림톡 · 동일번호
              </div>
            </div>
          </div>
        </aside>
      </div>
    </div>
  );
}

function Field({ label, required, hint, children }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
      <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between' }}>
        <label style={{ fontSize: 12, color: 'var(--ink-1)', fontWeight: 500, letterSpacing: '0.01em' }}>
          {label} {required && <span style={{ color: 'var(--clay)', fontWeight: 400 }}>*</span>}
        </label>
        {hint && <span style={{ fontSize: 10.5, color: 'var(--ink-3)' }}>{hint}</span>}
      </div>
      {children}
    </div>
  );
}

function Check({ children, on }) {
  return (
    <label style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '8px 0', cursor: 'pointer' }}>
      <div style={{
        width: 16, height: 16, borderRadius: 4,
        border: on ? 'none' : '1px solid var(--paper-stroke)',
        background: on ? 'var(--ink-0)' : 'var(--paper-0)',
        display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0,
      }}>
        {on && <Icon name="check" size={11} color="var(--paper-0)" />}
      </div>
      <span style={{ fontSize: 12.5, color: 'var(--ink-1)' }}>{children}</span>
    </label>
  );
}

function SumRow({ label, children }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', fontSize: 12 }}>
      <span style={{ color: 'var(--ink-3)' }}>{label}</span>
      <span style={{ color: 'var(--ink-0)', fontWeight: 500 }}>{children}</span>
    </div>
  );
}

Object.assign(window, { PublicForm, Field, Check, SumRow });
