/* icons.jsx — icon set, logo, pictogram, reveal hook. Exports to window. */
const { useEffect, useRef, useState } = React;

/* Resolve an asset: use bundled blob URL (window.__resources) if present, else the real path */
function R(id, path) { return (window.__resources && window.__resources[id]) || path; }

/* Brand emblem (from brand book): rounded capsule with sunrise, pine, house & hills */
function Pictogram({ size = 26, color = "#F5EFE1", sw = 1.7 }) {
  return (
    <svg width={size * 0.74} height={size} viewBox="0 0 40 52" fill="none"
         stroke={color} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round">
      <rect x="2.5" y="2" width="35" height="48" rx="17.5" />
      {/* sunrise */}
      <circle cx="20" cy="20.5" r="4.6" />
      <path d="M20 12.4V9M14.2 14.7l-2.1-2.1M25.8 14.7l2.1-2.1M11.6 20.5H8.6M31.4 20.5h-3" />
      {/* pine, left */}
      <path d="M14.6 27.2 11 32h7.2zM14.6 31.4 10 37h9.2zM14.6 42v-3" />
      {/* house with mono-pitch roof, right */}
      <path d="M23 42V32.6l8-4.4V42" />
      {/* hills */}
      <path d="M8.5 43.5c3.2-2.6 6-2.6 9 0 .2.2 .4 .3 .6 .4 2.7 1.6 5.4 1.4 8.4-.4" />
    </svg>
  );
}

function Logo({ dark = false }) {
  return (
    <a href="#top" className={"logo" + (dark ? " logo--dark" : "")} aria-label="Теплий">
      <span className="logo__mark"><img className="logo__emblem" src={R("logoEmblem","assets/logo-emblem.png")} alt="" /></span>
      <span className="logo__word">теплий</span>
    </a>
  );
}

const PATHS = {
  arrow: <path d="M5 12h14M13 6l6 6-6 6" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/>,
  calendar: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="5" width="18" height="16" rx="3"/><path d="M3 9h18M8 3v4M16 3v4"/></g>,
  clock: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 7.5V12l3 2"/></g>,
  pin: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M20 10c0 5.5-8 11-8 11s-8-5.5-8-11a8 8 0 1 1 16 0Z"/><circle cx="12" cy="10" r="2.6"/></g>,
  cup: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M4 9h13v5a5 5 0 0 1-5 5H9a5 5 0 0 1-5-5V9Z"/><path d="M17 10h2.2a2.8 2.8 0 0 1 0 5.6H17"/><path d="M8 3c-.6 1 .6 1.8 0 2.8M12 3c-.6 1 .6 1.8 0 2.8"/></g>,
  fire: <path d="M12 3c.5 3-2 4-2 7a4 4 0 0 0 8 0c0-1-.3-2-1-3 .2 2-1 3-1 3 .4-3-1.5-5-4-7Zm-1.5 9.5c0 1.5 1 2.5 2.5 2.5"  stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" fill="none"/>,
  crystal: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 2 7 9l5 13 5-13-5-7Z"/><path d="M7 9h10M12 2v20"/></g>,
  music: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M9 18V6l11-2v12"/><circle cx="6" cy="18" r="3"/><circle cx="17" cy="16" r="3"/></g>,
  key: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="8" cy="8" r="4.5"/><path d="M11.2 11.2 20 20M17 17l2-2M14 14l2-2"/></g>,
  droplet: <path d="M12 3s6 6.3 6 10.5A6 6 0 0 1 6 13.5C6 9.3 12 3 12 3Z" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" fill="none"/>,
  gift: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M4 11h16v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8Z"/><path d="M3 7h18v4H3zM12 7v14"/><path d="M12 7S11 3 8.5 3 6 6 9 7M12 7s1-4 3.5-4S18 6 15 7"/></g>,
  check: <path d="M5 13l4.5 4.5L19 7" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"/>,
  shield: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 3l7 3v6c0 4.5-3 7.5-7 9-4-1.5-7-4.5-7-9V6l7-3Z"/><path d="M9 12l2 2 4-4"/></g>,
  coins: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><ellipse cx="9" cy="7" rx="6" ry="3"/><path d="M3 7v5c0 1.66 2.7 3 6 3s6-1.34 6-3"/><path d="M15 11.5c2.5.3 6 1.4 6 3.5 0 1.66-2.7 3-6 3-1.2 0-2.3-.18-3.2-.48"/><path d="M9 15v3c0 1.66 2.7 3 6 3"/></g>,
  phone: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="6.5" y="2.5" width="11" height="19" rx="3"/><path d="M10.5 18.5h3"/></g>,
  mountain: <path d="M3 19h18L14.5 7l-3.2 5.2L9 9l-6 10Z" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" fill="none"/>,
  tree: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 2 6 11h3l-3 5h12l-3-5h3L12 2Z"/><path d="M12 16v6"/></g>,
  road: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M9 3 5 21M15 3l4 18M12 5v2M12 11v2M12 17v2"/></g>,
  present: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="4" width="18" height="12" rx="2"/><path d="M12 16v4M8.5 21h7M7.5 11.5 11 8l2.2 2.2L17 6"/></g>,
  route: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="6" cy="6.5" r="2.6"/><circle cx="18" cy="17.5" r="2.6"/><path d="M8.6 6.5H14a3.2 3.2 0 0 1 0 6.4h-4a3.2 3.2 0 0 0 0 6.4h5.4"/></g>,
  leaf: <path d="M4 20c0-9 7-15 16-16 1 9-5 16-12 16-2 0-4-2-4-2Zm2 0C9 14 13 10 18 8" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" fill="none"/>,
  plus: <path d="M12 5v14M5 12h14" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round"/>,
  close: <path d="M6 6l12 12M18 6 6 18" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round"/>,
  chevL: <path d="M15 5l-7 7 7 7" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/>,
  chevR: <path d="M9 5l7 7-7 7" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/>,
  mail: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="5" width="18" height="14" rx="3"/><path d="m4 7 8 6 8-6"/></g>,
  instagram: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="1.1" fill="currentColor" stroke="none"/></g>,
  telegram: <path d="M21 4 3 11l5 2 2 6 3-4 5 4 3-15Z" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" fill="none"/>,
  ruler: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="2.5" y="8" width="19" height="8" rx="2"/><path d="M7 8v3M11 8v4M15 8v3M19 8v3"/></g>,
  bed: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M3 18V8M3 12h18a0 0 0 0 1 0 0v6M3 18h18M7 12V9.5A1.5 1.5 0 0 1 8.5 8h9A1.5 1.5 0 0 1 19 9.5V12"/></g>,
  sofa: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M4 11V8a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v3"/><path d="M2 12a2 2 0 0 1 2 2v3h16v-3a2 2 0 0 1 2-2 2 2 0 0 0-2 2H4a2 2 0 0 0-2-2Z"/><path d="M6 17v2M18 17v2"/></g>,
  deck: <g stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M3 8h18l-2 3H5L3 8Z"/><path d="M5 11v9M19 11v9M5 16h14"/></g>,
};

function Icon({ name, size = 24, className }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" className={className} aria-hidden="true">
      {PATHS[name] || null}
    </svg>
  );
}

/* IntersectionObserver reveal */
function useReveal() {
  useEffect(() => {
    const els = document.querySelectorAll(".reveal:not(.in)");
    if (!("IntersectionObserver" in window)) { els.forEach(e => e.classList.add("in")); return; }
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) { e.target.classList.add("in"); io.unobserve(e.target); } });
    }, { threshold: 0.12, rootMargin: "0px 0px -8% 0px" });
    els.forEach(e => io.observe(e));
    return () => io.disconnect();
  });
}

Object.assign(window, { Pictogram, Logo, Icon, useReveal, R });
