/* global React, openLead, Spark */
const { useState: useStateF, useEffect: useEffectF } = React;

const WA_PRESET = "Здравствуйте! Хочу подобрать корпоративные новогодние подарки Mereke. Количество: ___ шт. Бюджет: ___ ₸. Нужен ли логотип: да/нет.";
const WA_FAB_LINK = "https://wa.me/77006116869?text=" + encodeURIComponent(WA_PRESET);

const WAGlyph = ({ style = {} }) => React.createElement("svg", { viewBox: "0 0 32 32", fill: "currentColor", style, "aria-hidden": "true" },
  React.createElement("path", { d: "M16 .4C7.4.4.4 7.4.4 16c0 2.8.7 5.4 2 7.7L.3 31.7l8.2-2.1c2.2 1.2 4.7 1.9 7.4 1.9 8.6 0 15.6-7 15.6-15.6S24.6.4 16 .4zm0 28.5c-2.4 0-4.7-.6-6.7-1.8l-.5-.3-4.9 1.3 1.3-4.8-.3-.5c-1.3-2-2-4.4-2-6.9C2.7 8.7 8.7 2.7 16 2.7S29.3 8.7 29.3 16 23.3 28.9 16 28.9z" }),
  React.createElement("path", { d: "M23.4 19.3c-.4-.2-2.4-1.2-2.8-1.3-.4-.1-.6-.2-.9.2-.3.4-1 1.3-1.2 1.5-.2.2-.4.3-.8.1-2.4-1.2-3.9-2.1-5.5-4.8-.4-.7.4-.6 1.2-2.1.1-.3.1-.5 0-.7-.1-.2-.9-2.1-1.2-2.9-.3-.8-.6-.7-.9-.7h-.7c-.3 0-.7.1-1 .5-.4.4-1.3 1.3-1.3 3.1s1.4 3.6 1.5 3.9c.2.3 2.6 4 6.3 5.6 2.3 1 3.2 1.1 4.4.9.7-.1 2.4-1 2.7-1.9.3-.9.3-1.7.2-1.9-.1-.2-.3-.3-.7-.4z" }));

const CalcGlyph = ({ style = {} }) => React.createElement("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", style, "aria-hidden": "true" },
  React.createElement("rect", { x: 5, y: 2, width: 14, height: 20, rx: 2 }),
  React.createElement("path", { d: "M8 6h8M8 10h0M12 10h0M16 10h0M8 14h0M12 14h0M16 14h0M8 18h4" }));

function FloatingActions() {
  const [showPill, setShowPill] = useStateF(false);
  useEffectF(() => {
    let last = window.scrollY;
    const onScroll = () => {
      const y = window.scrollY;
      if (y < 400) setShowPill(false);            // у верха страницы — скрыта
      else if (y < last - 4) setShowPill(true);   // скролл вверх — показываем
      else if (y > last + 4) setShowPill(false);  // скролл вниз — прячем (не мешает)
      last = y;
    };
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  return React.createElement("div", { className: "lp-fab", "aria-hidden": "false" },
    React.createElement("div", { className: `lp-fab-pill-wrap ${showPill ? "show" : ""}` },
      React.createElement("button", { type: "button", className: "lp-btn lp-btn-amber lp-btn-sm lp-fab-pillbtn", onClick: () => openLead() },
        React.createElement(CalcGlyph, { style: { width: 18, height: 18 } }), "Получить подборку и расчёт")),
    React.createElement("a", { className: "lp-fab-wa", href: WA_FAB_LINK, target: "_blank", rel: "noopener", "aria-label": "Написать в WhatsApp" },
      React.createElement(WAGlyph, { style: { width: 31, height: 31, position: "relative" } })));
}

Object.assign(window, { FloatingActions });
