/* wrapped in an IIFE: keeps these declarations out of the global lexical scope,
   so each page's inline script can re-declare them from window. */
(function () {
/* global React */
const { Icon, PATHS } = window;
/* ============================================================
   HospitAlert — app screen mockups used across the marketing site.
   CAST is the single source of truth for names, numbers and places:
   every screen, page and video must agree with it.
   Exposes: CAST, PhoneShell, PhoneShowcase, StatusBar, HistoryRow,
   AlertQR, LockScreenDetection, AlertReceivedScreen, ContactsScreen.
   ============================================================ */

const CAST = {
  patient: { name: 'Emily Carter', sex: 'Female', dob: '04/12/1963', age: '62 F', initial: 'E', phone: '(206) 555-0104' },
  second: { name: 'Michael Brooks' },
  contacts: [
    { name: 'Sarah Mitchell', phone: '(206) 555-0142', rel: 'Daughter' },
    { name: 'David Carter', phone: '(206) 555-0119', rel: 'Spouse' },
    { name: 'Dr. Alan Reyes', phone: '(425) 555-0187', rel: 'Physician' },
  ],
  hospital: { name: 'Lakeside Regional Medical Center', short: 'Lakeside Regional', city: 'Seattle, WA 98122' },
  hospital2: { name: 'Harborview Community Hospital', city: 'Tacoma, WA 98405' },
};

/* ---------- Phone shell + showcase frame ---------- */
const PhoneShell = ({ children, bg = '#0B0B0C' }) => (
  <div style={{ width: 360, height: 760, borderRadius: 46, background: '#0A0A0B', padding: 8, boxShadow: '0 40px 90px -30px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.08)', flexShrink: 0 }}>
    <div style={{ width: '100%', height: '100%', borderRadius: 38, background: bg, overflow: 'hidden', position: 'relative', fontFamily: 'Poppins, sans-serif' }}>{children}</div>
  </div>
);

const PhoneShowcase = ({ children, scale = 0.82, tint = 'rgba(74,222,128,0.16)', label }) => (
  <div className="phone-stage">
    <div aria-hidden="true" style={{ position: 'absolute', inset: 0, background: `radial-gradient(60% 60% at 50% 0%, ${tint}, transparent 70%)` }}></div>
    <div className="phone-scale" style={{ '--phone-scale': scale }}>{children}</div>
    {label ? <div style={{ position: 'absolute', left: 18, top: 16, fontFamily: 'JetBrains Mono, monospace', fontSize: 10, letterSpacing: '0.18em', textTransform: 'uppercase', color: 'rgba(255,255,255,0.42)' }}>{label}</div> : null}
  </div>
);

const StatusBar = ({ dark = false, time = '9:41' }) => {
  const c = dark ? 'rgba(255,255,255,0.95)' : '#111827';
  return (
    <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '14px 26px 0', color: c, fontFamily: 'Poppins, sans-serif', fontSize: 14, fontWeight: 600 }}>
      <span>{time}</span>
      <span style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
        <svg width="17" height="12" viewBox="0 0 17 12" aria-hidden="true">{[0, 1, 2, 3].map(i => <rect key={i} x={i * 4.3} y={8 - i * 2.4} width="3" height={4 + i * 2.4} rx="1" fill={c} />)}</svg>
        <svg width="15" height="12" viewBox="0 0 15 12" fill="none" stroke={c} strokeWidth="1.6" strokeLinecap="round" aria-hidden="true"><path d="M1.5 4.2A8.5 8.5 0 0 1 13.5 4.2M4 6.8a5 5 0 0 1 7 0" /><circle cx="7.5" cy="9.6" r="1.1" fill={c} stroke="none" /></svg>
        <svg width="24" height="12" viewBox="0 0 24 12" aria-hidden="true"><rect x="0.6" y="0.6" width="19" height="10.8" rx="3.2" fill="none" stroke={c} strokeOpacity="0.5" /><rect x="2.2" y="2.2" width="15.8" height="7.6" rx="2" fill={c} /><rect x="21" y="4" width="2" height="4" rx="1" fill={c} fillOpacity="0.5" /></svg>
      </span>
    </div>
  );
};

/* ---------- 01 · DETECTION — lock screen notification ---------- */
const LockScreenDetection = () => (
  <PhoneShell>
    <div style={{ position: 'absolute', inset: 0, background: '#7C1D2E' }}>
      <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(110% 55% at 78% 6%, #F0243C 0%, rgba(240,36,60,0) 58%), radial-gradient(95% 45% at 72% 34%, #F0A02A 0%, rgba(240,160,42,0) 62%), radial-gradient(120% 45% at 24% 62%, #C838B4 0%, rgba(200,56,180,0) 60%), radial-gradient(130% 50% at 60% 100%, #2FA8B8 0%, rgba(47,168,184,0) 62%), linear-gradient(180deg,#3B0A1C 0%,#8E1830 26%,#B8368C 62%,#2E8FA8 100%)' }}></div>
    </div>
    <div style={{ position: 'relative', height: '100%', display: 'flex', flexDirection: 'column', color: 'white' }}>
      <StatusBar dark />
      <div style={{ position: 'absolute', top: 12, left: '50%', transform: 'translateX(-50%)', width: 106, height: 30, borderRadius: 999, background: '#000' }}></div>
      <div style={{ textAlign: 'center', marginTop: 26 }}>
        <div style={{ fontSize: 14.5, fontWeight: 500, color: 'rgba(255,255,255,0.82)' }}>100% Charged</div>
        <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 500, fontSize: 82, lineHeight: 1, letterSpacing: '-0.02em', color: 'rgba(255,255,255,0.5)', marginTop: 4 }}>09:41</div>
      </div>
      <div style={{ marginTop: 'auto', padding: '0 14px 16px' }}>
        <div style={{ background: 'rgba(10,26,22,0.62)', backdropFilter: 'blur(18px)', WebkitBackdropFilter: 'blur(18px)', border: '1px solid rgba(74,222,128,0.22)', borderRadius: 22, padding: '13px 15px 15px' }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 9 }}>
            <span style={{ width: 20, height: 20, borderRadius: 5, background: '#4ADE80', display: 'grid', placeItems: 'center', flexShrink: 0 }}>
              <svg width="14" height="14" viewBox="0 0 100 100" aria-hidden="true"><path d="M 15 52 L 32 52 L 39 40 L 48 66 L 57 30 L 64 60 L 69 52 L 85 52" stroke="#0C2B1A" strokeWidth="9" strokeLinecap="round" strokeLinejoin="round" fill="none" /></svg>
            </span>
            <span style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 700, fontSize: 14.5, color: 'rgba(255,255,255,0.72)', flex: 1 }}>HospitAlert</span>
            <span style={{ fontSize: 12.5, fontWeight: 600, color: '#F5B24A' }}>Arrived · holding</span>
          </div>
          <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 700, fontSize: 17.5, letterSpacing: '-0.01em', marginTop: 9, lineHeight: 1.25 }}>We noticed you are at {CAST.hospital.short}.</div>
          <div style={{ fontSize: 13.5, color: 'rgba(255,255,255,0.62)', marginTop: 5 }}>We will check back in <span style={{ color: 'white', fontWeight: 600 }}>0:06</span></div>
          <div style={{ height: 4, borderRadius: 99, background: 'rgba(255,255,255,0.16)', marginTop: 11, overflow: 'hidden' }}><div className="wk-count" style={{ height: '100%', width: '62%', borderRadius: 99, background: '#F5A524' }}></div></div>
        </div>
        <div style={{ display: 'flex', justifyContent: 'space-between', padding: '18px 26px 6px' }}>
          {[0, 1].map(i => (
            <span key={i} style={{ width: 46, height: 46, borderRadius: 999, background: 'rgba(255,255,255,0.20)', backdropFilter: 'blur(8px)', display: 'grid', placeItems: 'center', color: 'white' }}>
              {i === 0
                ? <svg width="20" height="20" viewBox="0 0 24 24" fill="white" aria-hidden="true"><path d="M9.5 2h5v3.5h-5zM10 7h4l-.6 13h-2.8z" /></svg>
                : <svg width="21" height="21" viewBox="0 0 24 24" fill="white" aria-hidden="true"><path d="M4 8h3l1.4-2h7.2L17 8h3a1 1 0 011 1v9a1 1 0 01-1 1H4a1 1 0 01-1-1V9a1 1 0 011-1zm8 2.6a3.9 3.9 0 100 7.8 3.9 3.9 0 000-7.8z" /></svg>}
            </span>
          ))}
        </div>
        <div style={{ width: 118, height: 5, borderRadius: 99, background: 'rgba(255,255,255,0.85)', margin: '4px auto 0' }}></div>
      </div>
    </div>
  </PhoneShell>
);

/* ---------- 02 · THE ALERT — received alert with medical card + history ---------- */
const AlertQR = ({ size = 76 }) => {
  const cells = [];
  let seed = 13;
  for (let r = 0; r < 15; r++) for (let c = 0; c < 15; c++) {
    seed = (seed * 37 + r * 15 + c) % 101;
    const inFinder = (r < 5 && c < 5) || (r < 5 && c > 9) || (r > 9 && c < 5);
    if (!inFinder && seed % 2 === 0) cells.push(<rect key={r + '-' + c} x={5 + c * 6} y={5 + r * 6} width={5} height={5} fill="#0B0B0B" />);
  }
  const finder = (x, y) => (
    <g key={x + ',' + y}>
      <rect x={x} y={y} width={26} height={26} fill="#0B0B0B" />
      <rect x={x + 5} y={y + 5} width={16} height={16} fill="#fff" />
      <rect x={x + 9} y={y + 9} width={8} height={8} fill="#0B0B0B" />
    </g>
  );
  return <svg width={size} height={size} viewBox="0 0 100 100" aria-hidden="true" style={{ display: 'block', background: 'white' }}>{cells}{finder(5, 5)}{finder(69, 5)}{finder(5, 69)}</svg>;
};

const HistoryRow = ({ time, name, place, level = 'red' }) => {
  const tone = level === 'red' ? { bg: '#FDE3E3', fg: '#DC2626' } : { bg: '#FEF3C7', fg: '#D97706' };
  return (
    <div style={{ background: 'white', border: '1px solid #EEF0F2', borderRadius: 14, padding: '11px 13px' }}>
      <div style={{ fontSize: 11.5, color: '#9AA3AF' }}>{time}</div>
      <div style={{ display: 'flex', alignItems: 'center', gap: 11, marginTop: 7 }}>
        <span style={{ width: 34, height: 34, borderRadius: 9, background: tone.bg, color: tone.fg, display: 'grid', placeItems: 'center', flexShrink: 0 }}><Icon d={PATHS.warn} size={17} stroke={2.2} /></span>
        <div style={{ minWidth: 0, flex: 1 }}>
          <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 700, fontSize: 14.5, color: '#111827' }}>{name}</div>
          <div style={{ fontSize: 11.5, color: '#9AA3AF', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>at {place}</div>
        </div>
        <span style={{ width: 30, height: 30, borderRadius: 999, background: '#DCFCE7', color: '#16A34A', display: 'grid', placeItems: 'center', flexShrink: 0 }}><Icon d={PATHS.phone} size={14} stroke={2} /></span>
      </div>
    </div>
  );
};

const AlertReceivedScreen = () => (
  <PhoneShell bg="#140406">
    <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(120% 60% at 50% 0%, #4A0A10 0%, #140406 62%)' }}></div>
    <div aria-hidden="true" style={{ position: 'absolute', top: 74, left: 0, right: 0, height: 90, opacity: 0.18 }}>
      <svg viewBox="0 0 360 90" width="100%" height="90" fill="none"><path d="M0 60h60l14-26 16 46 14-52 12 32h44l14-26 16 46 14-52 12 32h124" stroke="#F87171" strokeWidth="3" strokeLinecap="round" /></svg>
    </div>
    <div style={{ position: 'relative', height: '100%', display: 'flex', flexDirection: 'column', color: 'white' }}>
      <StatusBar dark />
      <div style={{ padding: '20px 20px 0' }}>
        <div style={{ display: 'inline-flex', alignItems: 'center', gap: 8, background: '#C21E2C', borderRadius: 999, padding: '7px 15px', fontSize: 12.5, fontWeight: 600 }}>
          <span style={{ width: 8, height: 8, borderRadius: 99, background: '#2B0407' }}></span> Alert Active
        </div>
        <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 800, fontSize: 27, letterSpacing: '-0.02em', marginTop: 13 }}>You received an alert.</div>
        <div style={{ fontSize: 13, color: '#F0A5A5', marginTop: 8, lineHeight: 1.5 }}>Received 9:25 AM<br />{CAST.hospital.name}, {CAST.hospital.city}</div>
        <div style={{ background: 'white', borderRadius: 12, overflow: 'hidden', marginTop: 16, boxShadow: '0 18px 36px -16px rgba(0,0,0,0.6)' }}>
          <div style={{ background: '#DC2626', color: 'white', padding: '9px 14px', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 9, fontFamily: 'Urbanist, sans-serif', fontWeight: 700, fontSize: 14 }}>
            <svg width="15" height="15" viewBox="0 0 24 24" fill="white" aria-hidden="true"><path d="M10 3h4v7h7v4h-7v7h-4v-7H3v-4h7z" /></svg> Medical Information
          </div>
          <div style={{ display: 'flex', gap: 12, padding: '13px 14px 15px', color: '#111827' }}>
            <div style={{ flex: 1, minWidth: 0 }}>
              <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 800, fontSize: 17 }}>{CAST.patient.name}</div>
              <div style={{ fontSize: 11, fontWeight: 600, marginTop: 3 }}>{CAST.patient.sex}, {CAST.patient.dob}</div>
              <div style={{ fontSize: 10.5, color: '#1F2937', marginTop: 9, lineHeight: 1.65 }}>
                Blood Type: A-<br />Conditions: Diabetes, Asthma<br />Allergies: Sulfa, Wheat<br />Medications: Metformin, Albuterol
              </div>
            </div>
            <div style={{ textAlign: 'center', flexShrink: 0 }}>
              <AlertQR size={72} />
              <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 800, fontSize: 8, letterSpacing: '0.02em', color: '#DC2626', marginTop: 5, lineHeight: 1.3 }}>SCAN TO ACCESS<br />HEALTH RECORD</div>
            </div>
          </div>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 11, background: '#DC2626', borderRadius: 12, padding: '11px 13px', marginTop: 14 }}>
          <span style={{ width: 30, height: 30, borderRadius: 8, background: 'rgba(255,255,255,0.22)', display: 'grid', placeItems: 'center' }}><Icon d={PATHS.warn} size={16} stroke={2.2} /></span>
          <span style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 700, fontSize: 14.5, flex: 1 }}>Call or get directions</span>
          <Icon d={PATHS.chevronRight} size={16} stroke={2.4} />
        </div>
      </div>
      <div style={{ marginTop: 20, flex: 1, background: 'white', borderRadius: '20px 20px 0 0', padding: '18px 18px 0' }}>
        <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between' }}>
          <div>
            <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 800, fontSize: 18, color: '#111827' }}>Alert History</div>
            <div style={{ fontSize: 12.5, color: '#9AA3AF', marginTop: 2 }}>Past 48 hours</div>
          </div>
          <span style={{ color: '#6B7280' }}><Icon d={PATHS.filter} size={18} /></span>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 10, marginTop: 14 }}>
          <HistoryRow time="Today 9:25 AM" name={CAST.patient.name} place={`${CAST.hospital.name}, Seattle`} level="red" />
          <HistoryRow time="Yesterday 3:15 PM" name={CAST.second.name} place={`${CAST.hospital2.name}, Tacoma`} level="amber" />
        </div>
      </div>
    </div>
  </PhoneShell>
);

/* ---------- 03 · YOUR CIRCLE — contacts screen ---------- */
const ContactsScreen = () => (
  <PhoneShell bg="#F7F8FA">
    <div style={{ position: 'relative', height: '100%', display: 'flex', flexDirection: 'column', color: '#111827' }}>
      <StatusBar time="7:09" />
      <div style={{ padding: '22px 22px 0' }}>
        <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 800, fontSize: 32, letterSpacing: '-0.03em' }}>Contacts</div>
        <div style={{ display: 'flex', background: '#EEF0F2', borderRadius: 999, padding: 4, marginTop: 20 }}>
          <div style={{ flex: 1, textAlign: 'center', background: '#4ADE80', color: '#0C2B1A', borderRadius: 999, padding: '10px 0', fontFamily: 'Urbanist, sans-serif', fontWeight: 700, fontSize: 15 }}>Monitored</div>
          <div style={{ flex: 1, textAlign: 'center', color: '#374151', padding: '10px 0', fontFamily: 'Urbanist, sans-serif', fontWeight: 600, fontSize: 15 }}>Emergency</div>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginTop: 24 }}>
          <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 800, fontSize: 19 }}>Monitored</div>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: 7, background: '#4ADE80', color: '#0C2B1A', borderRadius: 999, padding: '7px 14px', fontFamily: 'Urbanist, sans-serif', fontWeight: 700, fontSize: 13 }}><Icon d={PATHS.person} size={14} stroke={2.2} /> Manage</div>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginTop: 18 }}>
          <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 600, fontSize: 15, color: '#4B5563' }}>Family</div>
          <div style={{ fontSize: 13, color: '#9AA3AF' }}>2 members</div>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 10, marginTop: 12 }}>
          <div style={{ background: 'white', border: '1px solid #EEF0F2', borderRadius: 16, padding: '14px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
            <div>
              <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 700, fontSize: 16 }}>{CAST.patient.name}</div>
              <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 12.5, color: '#9AA3AF', marginTop: 3 }}>{CAST.patient.phone}</div>
            </div>
            <div style={{ textAlign: 'right' }}>
              <div style={{ fontSize: 12, color: '#16A34A', fontWeight: 600 }}>Monitoring</div>
              <div style={{ fontSize: 12, color: '#9AA3AF', marginTop: 3 }}>Mom</div>
            </div>
          </div>
          <div style={{ background: 'white', border: '1px solid #EEF0F2', borderRadius: 16, padding: '14px 16px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
            <div>
              <div style={{ fontFamily: 'Urbanist, sans-serif', fontWeight: 700, fontSize: 16 }}>{CAST.second.name}</div>
              <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 12.5, color: '#9AA3AF', marginTop: 3 }}>(206) 555-0168</div>
            </div>
            <div style={{ textAlign: 'right' }}>
              <div style={{ fontSize: 12, color: '#9AA3AF' }}>Not Available</div>
              <div style={{ fontSize: 12.5, color: '#2563EB', textDecoration: 'underline', marginTop: 3 }}>Send Invite</div>
            </div>
          </div>
        </div>
      </div>
      <div style={{ marginTop: 'auto', borderTop: '1px solid #EDEFF1', background: 'white', borderRadius: '20px 20px 0 0', padding: '14px 26px 20px', display: 'flex', justifyContent: 'space-between' }}>
        {[{ i: PATHS.bell, t: 'Alert' }, { i: PATHS.users, t: 'Contact', on: true }, { i: PATHS.person, t: 'Account' }].map(tab => (
          <div key={tab.t} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 5, color: tab.on ? '#16A34A' : '#9AA3AF' }}>
            <Icon d={tab.i} size={21} stroke={2} />
            <span style={{ fontSize: 12, fontWeight: tab.on ? 600 : 500 }}>{tab.t}</span>
          </div>
        ))}
      </div>
    </div>
  </PhoneShell>
);

Object.assign(window, { CAST, PhoneShell, PhoneShowcase, StatusBar, HistoryRow, AlertQR, LockScreenDetection, AlertReceivedScreen, ContactsScreen });
})();
