/* Michael Style — Prototype · App shell (PhoneFrame, StatusBar, TabBar, icons, shared bits).
   Adapted from the DS app UI kit. Loaded via browser Babel; uses global React + DS namespace. */

const MSAPP = window.MichaelStyleDesignSystem_7fd21b;

/* —— inline stroked line icons (matches the concept's set) —— */
function Icon({ name, size = 18 }) {
  const paths = {
    home: <><path d="M3 11l9-8 9 8" /><path d="M5 10v10h14V10" /></>,
    book: <><rect x="4" y="5" width="16" height="16" rx="2" /><path d="M8 3v4M16 3v4" /></>,
    program: <><circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" /></>,
    work: <><rect x="3" y="4" width="18" height="14" rx="2" /><path d="M3 14l5-4 4 3 5-5 4 4" /></>,
    me: <><circle cx="12" cy="8" r="4" /><path d="M4 21c0-4 4-6 8-6s8 2 8 6" /></>,
    lock: <><rect x="5" y="11" width="14" height="9" rx="2" /><path d="M8 11V8a4 4 0 0 1 8 0v3" /></>,
    globe: <><circle cx="12" cy="12" r="9" /><path d="M3 12h18" /><path d="M12 3c2.5 2.7 2.5 15.3 0 18M12 3c-2.5 2.7-2.5 15.3 0 18" /></>,
    bell: <><path d="M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9" /><path d="M13.7 21a2 2 0 0 1-3.4 0" /></>,
    chevron: <><path d="M9 6l6 6-6 6" /></>,
    users: <><circle cx="9" cy="8" r="3.2" /><path d="M3.5 20c0-3 2.5-4.6 5.5-4.6s5.5 1.6 5.5 4.6" /><path d="M16 5.2a3.2 3.2 0 0 1 0 6.1M17.5 20c0-2.6-1.4-4.2-3.4-4.9" /></>,
    chart: <><path d="M4 20V4" /><path d="M4 20h16" /><rect x="7" y="12" width="3" height="5" /><rect x="12" y="8" width="3" height="9" /><rect x="17" y="14" width="3" height="3" /></>,
    plus: <><path d="M12 5v14M5 12h14" /></>,
    check: <><path d="M5 12l5 5L20 6" /></>,
    x: <><path d="M6 6l12 12M18 6L6 18" /></>,
    scissors: <><circle cx="6" cy="6" r="2.6" /><circle cx="6" cy="18" r="2.6" /><path d="M8 8l12 9M8 16l12-9" /></>,
    star: <><path d="M12 3l2.6 5.6 6 .7-4.5 4.1 1.2 6L12 16.8 6.7 19.5l1.2-6L3.4 9.3l6-.7z" /></>,
    clock: <><circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" /></>,
    camera: <><path d="M4 8h3l1.5-2h7L17 8h3a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z" /><circle cx="12" cy="13" r="3.4" /></>,
    megaphone: <><path d="M3 11v2a1 1 0 0 0 1 1h2l9 4V6L6 10H4a1 1 0 0 0-1 1z" /><path d="M15 8a4 4 0 0 1 0 8" /><path d="M6 14v4a1 1 0 0 0 1 1h1" /></>,
    share: <><circle cx="6" cy="12" r="2.4" /><circle cx="17" cy="6" r="2.4" /><circle cx="17" cy="18" r="2.4" /><path d="M8.1 11l6.8-3.6M8.1 13l6.8 3.6" /></>,
    menu: <><path d="M4 7h16M4 12h16M4 17h16" /></>,
    card: <><rect x="2.5" y="5" width="19" height="14" rx="2.5" /><path d="M2.5 9.5h19" /><path d="M6 15h3" /></>,
    cash: <><rect x="2.5" y="6" width="19" height="12" rx="2" /><circle cx="12" cy="12" r="2.6" /><path d="M5.5 9v6M18.5 9v6" /></>,
    dollar: <><path d="M12 3v18" /><path d="M16.5 7.2c0-1.7-2-3-4.5-3s-4.5 1.3-4.5 3 2 2.6 4.5 3 4.5 1.4 4.5 3-2 3-4.5 3-4.5-1.3-4.5-3" /></>,
    send: <><path d="M21 3L3 10.5l7 2.5L13 21l8-18z" /><path d="M10 13l4-4" /></>,
    phone: <><rect x="6.5" y="3" width="11" height="18" rx="2.5" /><path d="M10.5 18h3" /></>,
    wallet: <><path d="M3 8a2 2 0 0 1 2-2h12v0" /><path d="M3 8v9a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7a2 2 0 0 0-2-2H5" /><circle cx="16.5" cy="13.5" r="1.2" /></>,
    sound: <><path d="M4 9v6h3.5L13 19V5L7.5 9H4z" /><path d="M16.5 8.5a4.5 4.5 0 0 1 0 7" /><path d="M19 6a8 8 0 0 1 0 12" /></>,
    mute: <><path d="M4 9v6h3.5L13 19V5L7.5 9H4z" /><path d="M16.5 9.5l5 5M21.5 9.5l-5 5" /></>,
    upload: <><path d="M12 14V4" /><path d="M8 8l4-4 4 4" /><path d="M5 14v4a1.5 1.5 0 0 0 1.5 1.5h11a1.5 1.5 0 0 0 1.5-1.5v-4" /></>,
    pin: <><path d="M12 21s-6-5.2-6-10a6 6 0 0 1 12 0c0 4.8-6 10-6 10z" /><circle cx="12" cy="11" r="2.4" /></>,
    pencil: <><path d="M4 20h4L19 9a2 2 0 0 0-3-3L5 17v3z" /><path d="M14.5 7.5l3 3" /></>,
  };
  return (
    <svg viewBox="0 0 24 24" width={size} height={size} fill="none"
      stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      {paths[name]}
    </svg>
  );
}

function PhoneFrame({ children }) {
  return (
    <div style={{
      background: '#000', borderRadius: 'var(--radius-phone)', padding: '9px',
      border: '1px solid #2a2a30', boxShadow: 'var(--shadow-phone)', width: '316px', flex: 'none',
    }} data-screen-label="App device">
      <div style={{
        background: 'var(--ink)', borderRadius: 'var(--radius-screen)', overflow: 'hidden',
        height: '648px', position: 'relative', display: 'flex', flexDirection: 'column',
      }}>
        <div style={{
          position: 'absolute', top: '9px', left: '50%', transform: 'translateX(-50%)',
          width: '100px', height: '26px', background: '#000', borderRadius: '16px', zIndex: 8,
        }} />
        <div style={{
          display: 'flex', justifyContent: 'space-between', padding: '14px 26px 4px',
          fontFamily: 'var(--font-mono)', fontSize: '0.6rem', color: 'var(--bone)', flex: 'none',
        }}>
          <span>9:41</span><span>5G ▰▰▰</span>
        </div>
        {children}
      </div>
    </div>
  );
}

function ScreenBody({ children, label }) {
  return (
    <div style={{ padding: '8px 18px 16px', overflowY: 'auto', flex: 1 }}
      className="ms-noscroll" data-screen-label={label}>{children}</div>
  );
}

function TabBar({ active, onChange }) {
  const tabs = [
    { id: 'home', label: 'Home' }, { id: 'book', label: 'Book' },
    { id: 'program', label: 'Program' }, { id: 'work', label: 'Work' }, { id: 'me', label: 'Me' },
  ];
  return (
    <div style={{
      display: 'flex', justifyContent: 'space-around', padding: '11px 0 16px', flex: 'none',
      borderTop: '1px solid var(--bd-d)', background: 'var(--scrim-dark)', backdropFilter: 'var(--blur-glass)',
    }}>
      {tabs.map((t) => {
        const on = t.id === active;
        return (
          <button key={t.id} onClick={() => onChange && onChange(t.id)} aria-current={on ? 'page' : undefined} style={{
            display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '4px',
            fontFamily: 'var(--font-mono)', fontSize: '0.49rem', letterSpacing: '0.05em',
            textTransform: 'uppercase', color: on ? 'var(--accent)' : 'var(--muted-2)',
            background: 'none', border: 'none', cursor: 'pointer',
          }}>
            <Icon name={t.id} /> {t.label}
          </button>
        );
      })}
    </div>
  );
}

/* —— shared small bits —— */
function Eyebrow({ children }) {
  return <div style={{
    fontFamily: 'var(--font-mono)', fontSize: '0.56rem', letterSpacing: '0.16em',
    textTransform: 'uppercase', color: 'var(--accent)',
  }}>{children}</div>;
}
function AppH({ children, style = {} }) {
  return <div style={{
    fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '1.55rem',
    textTransform: 'uppercase', letterSpacing: '-0.03em', margin: '6px 0 2px', color: 'var(--bone)', ...style,
  }}>{children}</div>;
}
function ASub({ children }) {
  return <div style={{ fontSize: '0.72rem', color: 'var(--muted)', marginBottom: '14px' }}>{children}</div>;
}

/* —— EN/ES language toggle (shared by the website header + owner Yo) —— */
function LangToggle({ value, onChange }) {
  return (
    <div style={{ display: 'inline-flex', border: '1px solid var(--bd-d)', borderRadius: 'var(--radius-pill)', overflow: 'hidden' }}>
      {['EN', 'ES'].map((l) => {
        const on = l === value;
        return (
          <button key={l} onClick={() => onChange(l)} aria-pressed={on} style={{
            fontFamily: 'var(--font-mono)', fontSize: '0.52rem', letterSpacing: '0.1em', padding: '5px 11px',
            background: on ? 'color-mix(in srgb, var(--bone) 12%, transparent)' : 'transparent',
            color: on ? 'var(--bone)' : 'var(--muted-2)',
            border: 'none', cursor: 'pointer',
          }}>{l}</button>
        );
      })}
    </div>
  );
}

Object.assign(window, { Icon, PhoneFrame, ScreenBody, TabBar, Eyebrow, AppH, ASub, LangToggle });
