// components.jsx — small reusable bits shared across sections

const Stamp = ({ children, color="#7c1d1d", rotate=-6 }) => (
  <span className="cck-stamp" style={{ color, borderColor: color, transform:`rotate(${rotate}deg)` }}>
    {children}
  </span>
);

const Ticket = ({ children, color="#3f6b3a", bg="#d8e3cf" }) => (
  <span className="cck-ticket" style={{ color, background: bg }}>{children}</span>
);

const Squiggle = ({ color="#b94a16", width=120 }) => (
  <svg viewBox="0 0 120 12" width={width} height={12} style={{display:"block"}} aria-hidden="true">
    <path d="M2 6 Q 12 0, 22 6 T 42 6 T 62 6 T 82 6 T 102 6 T 118 6"
      fill="none" stroke={color} strokeWidth="2.4" strokeLinecap="round" />
  </svg>
);

const PaperCorner = ({ color="#fbe7c4" }) => (
  <svg viewBox="0 0 40 40" width="40" height="40" style={{position:"absolute", top:0, right:0}} aria-hidden="true">
    <path d="M0 0 H40 L0 40 Z" fill={color} />
    <path d="M40 0 L0 40" stroke="rgba(0,0,0,.08)" strokeWidth="0.5"/>
  </svg>
);

// Stylized marmita box illustration (top-down view) — used as placeholder + hero
const MarmitaBox = ({ dish, color="#7a2a1d", size=200, label="" }) => {
  const id = "mb-" + Math.random().toString(36).slice(2,7);
  return (
    <div className="cck-marmita" style={{ width:size, height:size*0.72 }}>
      <svg viewBox="0 0 200 144" width={size} height={size*0.72}>
        <defs>
          <linearGradient id={id+"lid"} x1="0" y1="0" x2="0" y2="1">
            <stop offset="0" stopColor="rgba(255,255,255,.7)"/>
            <stop offset="1" stopColor="rgba(255,255,255,.25)"/>
          </linearGradient>
          <radialGradient id={id+"food"} cx="0.5" cy="0.45" r="0.6">
            <stop offset="0" stopColor={color} stopOpacity="1"/>
            <stop offset="1" stopColor={color} stopOpacity="0.75"/>
          </radialGradient>
        </defs>
        {/* tray */}
        <rect x="10" y="14" width="180" height="120" rx="10" fill="#e9e3d6"/>
        <rect x="14" y="18" width="172" height="112" rx="8" fill="#fff9ef"/>
        {/* divider */}
        <line x1="100" y1="22" x2="100" y2="126" stroke="#d8cfba" strokeWidth="1.5"/>
        {/* rice side */}
        <rect x="18" y="22" width="78" height="104" rx="6" fill="#fbf3df"/>
        {/* rice grains */}
        {Array.from({length:14}).map((_,i)=>{
          const x = 24 + (i%4)*18 + (i*7)%6;
          const y = 30 + Math.floor(i/4)*24 + (i*5)%4;
          return <ellipse key={i} cx={x} cy={y} rx="3" ry="1.5" fill="#fff" stroke="#e8dcb8" strokeWidth=".5"/>;
        })}
        {/* feijão dot */}
        <circle cx="80" cy="116" r="6" fill="#2d1810"/>
        <circle cx="86" cy="110" r="5" fill="#3a1d12"/>
        <circle cx="74" cy="108" r="4.5" fill="#2d1810"/>
        {/* main dish side */}
        <rect x="104" y="22" width="82" height="104" rx="6" fill={`url(#${id+"food"})`}/>
        {/* dish texture */}
        <circle cx="120" cy="40" r="8" fill="rgba(0,0,0,.18)"/>
        <circle cx="155" cy="58" r="11" fill="rgba(255,255,255,.18)"/>
        <circle cx="135" cy="78" r="9" fill="rgba(0,0,0,.22)"/>
        <circle cx="165" cy="100" r="7" fill="rgba(255,255,255,.15)"/>
        <circle cx="118" cy="106" r="6" fill="rgba(0,0,0,.2)"/>
        {/* parsley specks */}
        <circle cx="128" cy="50" r="1.5" fill="#5a7a32"/>
        <circle cx="148" cy="92" r="1.5" fill="#5a7a32"/>
        <circle cx="172" cy="48" r="1.5" fill="#5a7a32"/>
        {/* tray glossy lid hint */}
        <rect x="14" y="18" width="172" height="36" rx="8" fill={`url(#${id+"lid"})`}/>
        {/* label sticker */}
        {label && (
          <g>
            <rect x="20" y="6" width={Math.min(160, label.length*6+16)} height="14" rx="2" fill="#fff8e6" stroke="#cdb27d" strokeWidth=".7"/>
            <text x={28} y={16} fontFamily="ui-monospace, Menlo, monospace" fontSize="9" fill="#5a3f1a" letterSpacing=".05em">
              {label.toUpperCase()}
            </text>
          </g>
        )}
      </svg>
    </div>
  );
};

const KanjiTitle = ({ children, sub }) => (
  <div className="cck-kanji-title">
    <span className="cck-kanji">コミダ・カゼイラ</span>
    {sub && <span className="cck-kanji-sub">{sub}</span>}
  </div>
);

const SectionLabel = ({ num, label, color="#7c1d1d" }) => (
  <div className="cck-seclabel" style={{color}}>
    <span className="cck-seclabel-num">§ {num}</span>
    <span className="cck-seclabel-line" style={{background:color}}></span>
    <span className="cck-seclabel-text">{label}</span>
  </div>
);

const WhatsAppFloat = () => {
  // Esconde o FAB quando a seção Final CTA está visível (ela já tem CTA WA grande).
  const [hidden, setHidden] = React.useState(false);
  React.useEffect(() => {
    const target = document.querySelector(".cck-finalcta");
    if (!target || !("IntersectionObserver" in window)) return;
    const io = new IntersectionObserver(
      ([entry]) => setHidden(entry.isIntersecting),
      { threshold: 0.15 }
    );
    io.observe(target);
    return () => io.disconnect();
  }, []);
  return (
    <a className={`cck-wa-float ${hidden ? "is-hidden":""}`} href="https://wa.me/819017254898" target="_blank" rel="noopener">
      <svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true">
        <path fill="currentColor" d="M19.05 4.91A9.82 9.82 0 0 0 12.04 2c-5.46 0-9.91 4.45-9.91 9.91 0 1.75.46 3.45 1.32 4.95L2.05 22l5.25-1.38a9.9 9.9 0 0 0 4.74 1.21h.01c5.46 0 9.91-4.45 9.91-9.91 0-2.65-1.03-5.14-2.91-7.01zM12.04 20.15h-.01a8.23 8.23 0 0 1-4.2-1.15l-.3-.18-3.12.82.83-3.04-.2-.31a8.22 8.22 0 0 1-1.26-4.38c0-4.54 3.7-8.24 8.25-8.24 2.2 0 4.27.86 5.83 2.42a8.18 8.18 0 0 1 2.41 5.83c0 4.54-3.7 8.23-8.24 8.23zm4.52-6.16c-.25-.12-1.47-.72-1.69-.81-.23-.08-.39-.12-.56.12-.16.25-.64.81-.78.97-.14.16-.29.18-.54.06-.25-.12-1.05-.39-2-1.23-.74-.66-1.24-1.47-1.38-1.72-.14-.25-.02-.38.11-.5.11-.11.25-.29.37-.43.12-.14.16-.25.25-.41.08-.16.04-.31-.02-.43-.06-.12-.56-1.34-.76-1.84-.2-.48-.41-.42-.56-.43-.14-.01-.31-.01-.48-.01-.16 0-.43.06-.66.31-.23.25-.86.84-.86 2.06 0 1.21.88 2.38 1.01 2.55.12.16 1.74 2.66 4.21 3.73.59.25 1.05.4 1.41.52.59.19 1.13.16 1.55.1.47-.07 1.47-.6 1.67-1.18.21-.58.21-1.07.14-1.18-.06-.1-.22-.16-.47-.28z"/>
      </svg>
      WhatsApp
    </a>
  );
};

Object.assign(window, { Stamp, Ticket, Squiggle, PaperCorner, MarmitaBox, KanjiTitle, SectionLabel, WhatsAppFloat });
