const { Icon: FAIcon, Hazard: DSHazard } = window.UnderpinDesignSystem_726ee6;
const FA_EASE = 'cubic-bezier(.2,.7,.2,1)';

// Engineer's ruler running down an edge
function Ruler({ side = 'left', light = true, style }) {
  const c = light ? 'rgba(255,255,255,.28)' : 'rgba(47,51,59,.28)';
  return <div className="fa-desk" aria-hidden="true" style={{ position: 'absolute', top: 0, bottom: 0, [side]: '22px', width: '18px', backgroundImage: `repeating-linear-gradient(to bottom, ${c} 0 1px, transparent 1px 10px), repeating-linear-gradient(to bottom, ${c} 0 1px, transparent 1px 50px)`, backgroundSize: '8px 10px, 18px 50px', backgroundRepeat: 'repeat-y', backgroundPosition: side === 'left' ? '0 0, 0 0' : '10px 0, 0 0', ...style }} />;
}

// Survey crosshair — corner registration mark
function Crosshair({ style, color = 'rgba(255,255,255,.35)' }) {
  return (
    <svg className="fa-desk" aria-hidden="true" width="28" height="28" viewBox="0 0 28 28" style={{ position: 'absolute', ...style }}>
      <circle cx="14" cy="14" r="9" fill="none" stroke={color} strokeWidth="1" />
      <path d="M14 0v8M14 20v8M0 14h8M20 14h8" stroke={color} strokeWidth="1" />
    </svg>
  );
}

// Hairline crack — static version (ScrollCrack in Motion.jsx draws with scroll)
function Crack({ style, color = 'rgba(255,255,255,.16)', accent = 'var(--orange-600)' }) {
  return (
    <svg className="fa-desk" aria-hidden="true" viewBox="0 0 120 600" preserveAspectRatio="none" style={{ position: 'absolute', width: '120px', height: '100%', ...style }}>
      <path d="M62 0 L58 70 L71 118 L64 176 L79 238 L69 296 L84 340 L76 402 L90 470 L83 530 L95 600" fill="none" stroke={color} strokeWidth="1.4" strokeLinejoin="round" />
      <path d="M71 118 L48 140 L41 166 M84 340 L104 356 L110 384" fill="none" stroke={color} strokeWidth="1" />
      <path d="M64 176 l0 0" stroke={accent} strokeWidth="6" strokeLinecap="round" />
      <path d="M50 176 h30" stroke={accent} strokeWidth="1" strokeDasharray="2 3" />
    </svg>
  );
}

// Sticky offer bar after the hero scrolls away
function StickyBar({ price, title, cta, sub, href = '#offer' }) {
  const [show, setShow] = React.useState(false);
  React.useEffect(() => {
    const f = () => setShow(window.scrollY > 760 && window.innerHeight + window.scrollY < document.body.scrollHeight - 420);
    f(); window.addEventListener('scroll', f, { passive: true }); return () => window.removeEventListener('scroll', f);
  }, []);
  return (
    <div style={{ position: 'fixed', left: 0, right: 0, bottom: 0, zIndex: 50, transform: show ? 'none' : 'translateY(110%)', transition: `transform .5s ${FA_EASE}`, background: 'var(--ink-700)', boxShadow: '0 -12px 40px rgba(0,0,0,.35)' }}>
      <DSHazard height={4} />
      <div className="fa-bar" style={{ maxWidth: 'var(--container-max)', margin: '0 auto', padding: '12px 20px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '16px' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: '14px', minWidth: 0 }}>
          <img src={window.__res('mark', 'mark.svg')} alt="" style={{ width: '26px', height: '26px', flexShrink: 0 }} />
          <div style={{ minWidth: 0 }}>
            <div style={{ fontFamily: 'var(--font-bold)', fontWeight: 'var(--weight-bold)', fontSize: '15px', color: '#fff', whiteSpace: 'nowrap' }}>{title} <span style={{ color: 'var(--orange-500)' }}>{price}</span></div>
            <div className="fa-bar-sub" style={{ fontFamily: 'var(--font-mono)', fontSize: '11px', letterSpacing: '.12em', textTransform: 'uppercase', color: 'rgba(255,255,255,.55)' }}>{sub}</div>
          </div>
        </div>
        <a href={href} className="fa-cta" style={{ background: 'var(--orange-600)', color: '#fff', textDecoration: 'none', fontFamily: 'var(--font-bold)', fontWeight: 'var(--weight-bold)', fontSize: '15px', padding: '12px 20px', borderRadius: '2px', whiteSpace: 'nowrap', transition: 'transform .3s cubic-bezier(.34,1.56,.64,1), background .25s' }}>{cta}</a>
      </div>
    </div>
  );
}

Object.assign(window, { Ruler, Crosshair, Crack, StickyBar });
