// star-kit.jsx — shared building blocks for the STAR 무대의상 home 시안 set.
// Exports to window so the other babel scripts can use them.
const W = 384, H = 832; // phone artboard size

// ---- helpers ----
const won = (n) => n.toLocaleString('ko-KR') + '원';

// 5-point star path inside a 100x100 box
const STAR_D = 'M50 4 L61.8 35.5 L95.1 37.5 L69 58.5 L77.9 90.5 L50 71 L22.1 90.5 L31 58.5 L4.9 37.5 L38.2 35.5 Z';

function Star({ size = 22, fill = '#FFC700', stroke, glow }) {
  return (
    <svg width={size} height={size} viewBox="0 0 100 100" style={{ display: 'block', filter: glow ? `drop-shadow(0 0 ${size * 0.35}px ${glow})` : 'none' }}>
      <path d={STAR_D} fill={fill} stroke={stroke || 'none'} strokeWidth={stroke ? 5 : 0} strokeLinejoin="round" />
    </svg>
  );
}

// Wordmark: ★ STAR
function StarLogo({ color = '#1A1A18', size = 26, sub }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', lineHeight: 1 }}>
      <span style={{ fontFamily: "'Cormorant Garamond', serif", fontWeight: 400, fontSize: size * 1.18, letterSpacing: size * 0.22, textIndent: size * 0.22, color }}>STAR</span>
      {sub && <span style={{ fontFamily: "'Noto Serif KR', serif", fontSize: size * 0.36, fontWeight: 300, letterSpacing: '.35em', color, opacity: 0.6, marginTop: 6 }}>{sub}</span>}
    </div>
  );
}

// iOS/Android-ish status bar
function StatusBar({ dark, tint }) {
  const c = dark ? '#fff' : (tint || '#1A1714');
  return (
    <div style={{ height: 30, flex: '0 0 30px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '0 20px', fontFamily: 'Noto Serif KR, sans-serif' }}>
      <span style={{ fontSize: 13, fontWeight: 700, color: c }}>9:41</span>
      <div style={{ display: 'flex', alignItems: 'center', gap: 5, color: c }}>
        <svg width="17" height="11" viewBox="0 0 17 11" fill={c}><rect x="0" y="6" width="3" height="5" rx="1"/><rect x="4.5" y="4" width="3" height="7" rx="1"/><rect x="9" y="2" width="3" height="9" rx="1"/><rect x="13.5" y="0" width="3" height="11" rx="1"/></svg>
        <svg width="16" height="11" viewBox="0 0 16 11" fill={c}><path d="M8 2.2c2 0 3.8.8 5.1 2l1.2-1.3A9.3 9.3 0 0 0 8 .2 9.3 9.3 0 0 0 1.7 2.9L2.9 4.2A7.3 7.3 0 0 1 8 2.2Z"/><path d="M8 5.4c1.1 0 2.2.4 3 1.2l1.2-1.3A6 6 0 0 0 8 3.6a6 6 0 0 0-4.2 1.7L5 6.6c.8-.8 1.9-1.2 3-1.2Z"/><circle cx="8" cy="9" r="1.6"/></svg>
        <div style={{ display: 'flex', alignItems: 'center', gap: 2 }}>
          <div style={{ width: 22, height: 11, borderRadius: 3, border: `1.5px solid ${c}`, padding: 1.5, opacity: 0.9 }}><div style={{ width: '72%', height: '100%', background: c, borderRadius: 1 }} /></div>
        </div>
      </div>
    </div>
  );
}

// Placeholder "stage photo" block — uses a real image when given, else a tasteful gradient
function Ph({ h = 160, grad, img, imgPos = 'center 28%', label, round = 0, children, dark, style }) {
  return (
    <div style={{ position: 'relative', width: '100%', height: h, borderRadius: round, background: grad || 'linear-gradient(135deg,#2a2440,#4a3a6a)', overflow: 'hidden', display: 'flex', alignItems: 'flex-end', ...style }}>
      {img
        ? <img src={img} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: imgPos }} />
        : <div style={{ position: 'absolute', top: '-30%', left: '50%', transform: 'translateX(-50%)', width: '80%', height: '120%', background: 'radial-gradient(ellipse at top, rgba(255,255,255,.22), transparent 60%)' }} />}
      {label && <span style={{ position: 'absolute', top: 8, left: 10, fontFamily: 'Noto Serif KR, sans-serif', fontSize: 9.5, fontWeight: 600, letterSpacing: 0.3, color: '#fff', background: 'rgba(0,0,0,.3)', padding: '2px 6px', borderRadius: 20 }}>{label}</span>}
      {children}
    </div>
  );
}

// shared product catalog
const PRODUCTS = [
  { id: 1, name: '큐빅 반짝이 트로트 드레스', cat: '트로트', price: 189000, sale: 149000, rating: 4.9, reviews: 312, grad: 'linear-gradient(150deg,#ff5a98,#ffd166)', tag: '베스트' },
  { id: 2, name: '난타 공연 단체 티셔츠 (5인)', cat: '난타', price: 33000, rating: 4.8, reviews: 540, grad: 'linear-gradient(150deg,#ff8a3d,#ffd24a)', tag: '단체인기' },
  { id: 3, name: '장구난타 개량한복 세트', cat: '장구난타', price: 128000, sale: 98000, rating: 4.9, reviews: 176, grad: 'linear-gradient(150deg,#c0392b,#f0a04b)', tag: '맞춤제작' },
  { id: 4, name: '합창단 새틴 가운 드레스', cat: '합창', price: 96000, rating: 5.0, reviews: 88, grad: 'linear-gradient(150deg,#5b58c9,#9fd3ff)', tag: 'NEW' },
  { id: 5, name: '실버 시퀸 무대 자켓', cat: '트로트', price: 142000, rating: 4.7, reviews: 203, grad: 'linear-gradient(150deg,#8e9eab,#eef2f3)', tag: null },
  { id: 6, name: '사물놀이 오방색 단체복', cat: '전통', price: 78000, rating: 4.9, reviews: 134, grad: 'linear-gradient(150deg,#2d6cdf,#23b07a)', tag: '단체인기' },
];

const CATS = [
  { name: '저고리', emoji: '👘', grad: 'linear-gradient(145deg,#ff9a9e,#f06595)' },
  { name: '치마', emoji: '👗', grad: 'linear-gradient(145deg,#b78cff,#7a3fa0)' },
  { name: '원피스', emoji: '💃', grad: 'linear-gradient(145deg,#ffc3a0,#ff5e62)' },
  { name: '쾌자', emoji: '🥋', grad: 'linear-gradient(145deg,#8ec5ff,#5b58c9)' },
  { name: '자켓', emoji: '🧥', grad: 'linear-gradient(145deg,#ffd24a,#f0a000)' },
  { name: '조끼', emoji: '🦺', grad: 'linear-gradient(145deg,#a0e8af,#2b9348)' },
  { name: '블라우스', emoji: '👚', grad: 'linear-gradient(145deg,#9bd1ff,#2d6cdf)' },
  { name: '셔츠', emoji: '👔', grad: 'linear-gradient(145deg,#d9a7ff,#8e44ad)' },
  { name: '바지', emoji: '👖', grad: 'linear-gradient(145deg,#39c,#2b7)' },
  { name: '민복', emoji: '🪭', grad: 'linear-gradient(145deg,#ffd6a5,#ff924c)' },
];

// star rating row
function Stars({ r = 5, size = 11, color = '#9A7B4F' }) {
  return (
    <div style={{ display: 'flex', gap: 1 }}>
      {[0,1,2,3,4].map(i => <Star key={i} size={size} fill={i < Math.round(r) ? color : 'rgba(26,26,24,.16)'} />)}
    </div>
  );
}

// Generic bottom tab bar; theme = {bg, active, inactive, border}
function BottomNav({ active = 0, theme = {} }) {
  const t = { bg: '#fff', active: '#F0A000', inactive: '#A9A29A', border: '#EFEAE0', ...theme };
  const items = [
    { label: '홈', icon: 'M3 11.5 12 4l9 7.5M5 10v9h5v-5h4v5h5v-9' },
    { label: '카테고리', icon: 'M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z' },
    { label: '단체주문', icon: 'STAR' },
    { label: '마이', icon: 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8ZM4 21c0-4 4-6 8-6s8 2 8 6' },
    { label: '장바구니', icon: 'M5 7h14l-1.2 11.2a2 2 0 0 1-2 1.8H8.2a2 2 0 0 1-2-1.8L5 7ZM8.5 7a3.5 3.5 0 0 1 7 0' },
  ];
  return (
    <div style={{ height: 62, flex: '0 0 62px', background: t.bg, borderTop: `1px solid ${t.border}`, display: 'flex', alignItems: 'stretch', fontFamily: 'Noto Serif KR, sans-serif' }}>
      {items.map((it, i) => {
        const on = i === active;
        const col = on ? t.active : t.inactive;
        return (
          <div key={i} style={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 3, position: 'relative' }}>
            {it.icon === 'STAR'
              ? <div style={{ marginTop: -16, width: 42, height: 42, borderRadius: 21, background: on ? t.active : '#1A1714', display: 'flex', alignItems: 'center', justifyContent: 'center', boxShadow: '0 4px 12px rgba(240,160,0,.4)' }}><Star size={22} fill="#fff" /></div>
              : <svg width="23" height="23" viewBox="0 0 24 24" fill="none" stroke={col} strokeWidth={on ? 2.2 : 1.8} strokeLinecap="round" strokeLinejoin="round"><path d={it.icon} /></svg>}
            <span style={{ fontSize: 10, fontWeight: on ? 800 : 600, whiteSpace: 'nowrap', color: it.icon === 'STAR' ? (on ? t.active : '#1A1714') : col }}>{it.label}</span>
          </div>
        );
      })}
    </div>
  );
}

// rounded search bar
function SearchBar({ placeholder = 'STAR에서 무대의상 검색', bg = '#FBFAF6', color = '#1A1A18', radius = 2, border = '1px solid rgba(26,26,24,.14)' }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 9, background: bg, borderRadius: radius, padding: '12px 16px', border: border }}>
      <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.6" strokeLinecap="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>
      <span style={{ fontFamily: "'Noto Serif KR', serif", fontSize: 13.5, fontWeight: 300, color, opacity: 0.6, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{placeholder}</span>
    </div>
  );
}

// KakaoPay chip / button
function KakaoBtn({ small, label = '카카오페이 간편결제', full }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 7, background: '#FEE500', borderRadius: small ? 10 : 14, padding: small ? '8px 12px' : '15px 18px', width: full ? '100%' : 'auto', fontFamily: 'Noto Serif KR, sans-serif' }}>
      <svg width={small ? 18 : 22} height={small ? 18 : 22} viewBox="0 0 24 24"><path d="M12 3C6.5 3 2 6.6 2 11c0 2.8 1.9 5.3 4.7 6.7l-1 3.6c-.1.4.3.7.6.5l4.3-2.8c.4 0 .9.1 1.4.1 5.5 0 10-3.6 10-8s-4.5-8-10-8Z" fill="#3C1E1E"/></svg>
      <span style={{ fontSize: small ? 12.5 : 15, fontWeight: 800, color: '#3C1E1E' }}>{label}</span>
    </div>
  );
}

Object.assign(window, { W, H, won, Star, StarLogo, StatusBar, Ph, PRODUCTS, CATS, Stars, BottomNav, SearchBar, KakaoBtn });
