// Shared UI primitives for BeckHost

const BHLogo = ({ size = 28 }) => (
  <img src="assets/logo-mark-transparent.png" alt="BeckHost"
       width={size} height={size}
       style={{display:"block", objectFit:"contain"}}/>
);

const Wordmark = ({ size = 22 }) => (
  <div style={{display:"flex", alignItems:"center", gap: 10}}>
    <BHLogo size={size + 10} />
    <div style={{fontFamily:"var(--f-display)", fontWeight:700, fontSize: size, letterSpacing:"-0.025em", lineHeight:1}}>
      <span>beck</span><span style={{color:"var(--bh-green-deep)"}}>host</span>
      <span style={{color:"var(--mute)", fontWeight:500}}>.net</span>
    </div>
  </div>
);

const Arrow = ({ size = 14 }) => (
  <svg className="arr" width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden="true">
    <path d="M5 12 H19 M13 6 L19 12 L13 18" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
  </svg>
);

const Check = ({ size = 16 }) => (
  <svg width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden="true">
    <circle cx="12" cy="12" r="10" fill="var(--bh-green-soft)" />
    <path d="M7.5 12.5 L10.5 15.5 L16.5 9" stroke="var(--bh-green-deep)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
  </svg>
);

const Btn = ({ kind = "primary", children, onClick, href, ...rest }) => {
  const cls = `btn btn-${kind}`;
  if (href) return <a className={cls} href={href} onClick={onClick} {...rest}>{children}</a>;
  return <button className={cls} onClick={onClick} {...rest}>{children}</button>;
};

// Faux browser frame for portfolio
const BrowserFrame = ({ url, children, accent }) => (
  <div style={{
    border: "1px solid var(--line)",
    borderRadius: 14,
    overflow: "hidden",
    background: "var(--bg-2)",
    boxShadow: "var(--shadow-md)",
  }}>
    <div style={{
      display:"flex", alignItems:"center", gap: 10,
      padding: "10px 14px",
      borderBottom: "1px solid var(--line)",
      background: "var(--bg-3)",
    }}>
      <div style={{display:"flex", gap:6}}>
        <span style={{width:9,height:9,borderRadius:"50%",background:"#e8a3a3"}}/>
        <span style={{width:9,height:9,borderRadius:"50%",background:"#e8d49a"}}/>
        <span style={{width:9,height:9,borderRadius:"50%",background:"#a3d9b3"}}/>
      </div>
      <div style={{
        flex:1, height:22, borderRadius:6, background:"var(--bg-2)",
        border:"1px solid var(--line)",
        display:"flex", alignItems:"center", gap:8, padding: "0 10px",
        fontFamily:"var(--f-mono)", fontSize:11, color:"var(--mute)"
      }}>
        <span style={{
          width:8, height:8, borderRadius:"50%",
          background:accent||"var(--bh-green)", display:"inline-block"
        }}/>
        {url}
      </div>
    </div>
    <div>{children}</div>
  </div>
);

// Tag with dot
const Dot = ({ color = "var(--bh-green)" }) => (
  <span style={{width:8,height:8,borderRadius:"50%",background:color,display:"inline-block"}}/>
);

// Map of NH to subtly reinforce locality (stylized, not literal)
const NHGlyph = ({ size = 80 }) => (
  <svg width={size} height={size} viewBox="0 0 100 100" aria-hidden="true">
    <path d="M10 78 L34 42 L52 64 L70 38 L92 78 Z" fill="var(--bh-green-soft)" />
    <path d="M10 78 L34 42 L52 64 L70 38 L92 78" stroke="var(--bh-green-deep)" strokeWidth="1.5" fill="none"/>
    <circle cx="50" cy="22" r="3" fill="var(--bh-green)"/>
    <line x1="50" y1="22" x2="50" y2="38" stroke="var(--bh-green)" strokeWidth="1.2" strokeDasharray="2 3"/>
  </svg>
);

const useIsMobile = (breakpoint = 768) => {
  const [isMobile, setIsMobile] = React.useState(window.innerWidth <= breakpoint);
  React.useEffect(() => {
    const handler = () => setIsMobile(window.innerWidth <= breakpoint);
    window.addEventListener("resize", handler);
    return () => window.removeEventListener("resize", handler);
  }, [breakpoint]);
  return isMobile;
};

Object.assign(window, { BHLogo, Wordmark, Arrow, Check, Btn, BrowserFrame, Dot, NHGlyph, useIsMobile });
