// 37 FORGE — App shell, route, tweaks
const {
  useState: useS,
  useEffect: useEf
} = React;
const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "accent": "#b08828",
  "accentBright": "#e6c25c",
  "gridIntensity": "subtle",
  "density": "spacious",
  "scanlines": true
} /*EDITMODE-END*/;
const ACCENT_PRESETS = {
  "#8a6c1d": {
    bright: "#d4a73a",
    deep: "#5e4a13"
  },
  // Forge Gold (default)
  "#b08828": {
    bright: "#e6c25c",
    deep: "#7a5e1a"
  },
  // Brighter gold
  "#a85d2a": {
    bright: "#d97a3f",
    deep: "#6e3d1a"
  },
  // Copper
  "#3d8b6e": {
    bright: "#5fb38f",
    deep: "#235640"
  } // Forge teal
};
const VALID_ROUTES = [
  "services",
  "our-services",
  "co-managed",
  "automation",
  "knowledge-base",
  "about",
  "contact",
  "industries/medical-offices",
  "industries/financial-services",
  "industries/property-management",
  "industries/other",
  "resources/m365-audit"
];
const routeFromPath = () => {
  // Strip leading/trailing slashes, lowercase, return the full path key.
  // "" → services (home). Unknown paths → services fallback.
  const path = window.location.pathname.replace(/^\/+|\/+$/g, "").toLowerCase();
  if (!path) return "services";
  return VALID_ROUTES.includes(path) ? path : "services";
};

function App() {
  const [route, setRoute] = useS(routeFromPath);
  const [tweaks, setTweak] = (window.useTweaks || (d => useS(d).concat([() => {}])))(TWEAK_DEFAULTS);

  // Sync route ↔ URL path (back/forward + direct links work)
  useEf(() => {
    const onPop = () => setRoute(routeFromPath());
    window.addEventListener("popstate", onPop);
    return () => window.removeEventListener("popstate", onPop);
  }, []);

  // Apply tweaks → CSS vars
  useEf(() => {
    const accent = tweaks.accent || "#8a6c1d";
    const preset = ACCENT_PRESETS[accent] || {
      bright: tweaks.accentBright || "#d4a73a",
      deep: "#5e4a13"
    };
    const root = document.documentElement;
    root.style.setProperty("--accent", accent);
    root.style.setProperty("--accent-bright", preset.bright);
    root.style.setProperty("--accent-deep", preset.deep);
    const gridMap = {
      subtle: 0.06,
      regular: 0.12,
      intense: 0.22
    };
    root.style.setProperty("--grid-opacity", gridMap[tweaks.gridIntensity] || 0.12);
    const densityMap = {
      compact: "64px",
      regular: "96px",
      spacious: "128px"
    };
    root.style.setProperty("--section-padding", densityMap[tweaks.density] || "96px");
    root.style.setProperty("--scanline-opacity", tweaks.scanlines ? 0.35 : 0);
  }, [tweaks]);
  const go = (r, anchor) => {
    setRoute(r);
    // services is the home page → "/" ; others → "/about", "/contact"
    const newPath = r === "services" ? "/" : "/" + r;
    if (window.location.pathname !== newPath) {
      history.pushState(null, "", newPath);
    }
    if (anchor) {
      // Wait for React to mount the new route, then scroll the anchor into view.
      requestAnimationFrame(() => requestAnimationFrame(() => {
        const el = document.getElementById(anchor);
        if (el) {
          const top = el.getBoundingClientRect().top + window.scrollY - 80; // offset for sticky nav
          window.scrollTo({
            top,
            behavior: "smooth"
          });
        } else {
          window.scrollTo({
            top: 0,
            behavior: "instant"
          });
        }
      }));
    } else {
      window.scrollTo({
        top: 0,
        behavior: "instant"
      });
    }
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(UtilBar, null), /*#__PURE__*/React.createElement(Nav, {
    route: route,
    go: go
  }), route === "services" && /*#__PURE__*/React.createElement(ServicesPage, {
    go: go
  }), route === "about" && /*#__PURE__*/React.createElement(AboutPage, {
    go: go
  }), route === "our-services" && /*#__PURE__*/React.createElement(window.OurServicesPage, {
    go: go
  }), route === "co-managed" && /*#__PURE__*/React.createElement(window.CoManagedPage, {
    go: go
  }), route === "automation" && /*#__PURE__*/React.createElement(window.AutomationPage, {
    go: go
  }), route === "knowledge-base" && /*#__PURE__*/React.createElement(window.KnowledgeBasePage, {
    go: go
  }), route === "contact" && /*#__PURE__*/React.createElement(ContactPage, {
    go: go
  }), route.startsWith("industries/") && /*#__PURE__*/React.createElement(window.IndustryPage, {
    go: go,
    slug: route
  }), route === "resources/m365-audit" && /*#__PURE__*/React.createElement(window.ResourceM365AuditPage, {
    go: go
  }), route !== "contact" && /*#__PURE__*/React.createElement(Footer, {
    go: go
  }), window.TweaksPanel && /*#__PURE__*/React.createElement(window.TweaksPanel, {
    title: "Tweaks \xB7 37 Forge"
  }, /*#__PURE__*/React.createElement(window.TweakSection, {
    label: "Accent"
  }), /*#__PURE__*/React.createElement(window.TweakColor, {
    label: "Accent color",
    value: tweaks.accent,
    options: ["#8a6c1d", "#b08828", "#a85d2a", "#3d8b6e"],
    onChange: v => setTweak("accent", v)
  }), /*#__PURE__*/React.createElement(window.TweakSection, {
    label: "Atmosphere"
  }), /*#__PURE__*/React.createElement(window.TweakRadio, {
    label: "Grid",
    value: tweaks.gridIntensity,
    options: ["subtle", "regular", "intense"],
    onChange: v => setTweak("gridIntensity", v)
  }), /*#__PURE__*/React.createElement(window.TweakRadio, {
    label: "Density",
    value: tweaks.density,
    options: ["compact", "regular", "spacious"],
    onChange: v => setTweak("density", v)
  }), /*#__PURE__*/React.createElement(window.TweakToggle, {
    label: "Scanlines",
    value: tweaks.scanlines,
    onChange: v => setTweak("scanlines", v)
  }), /*#__PURE__*/React.createElement(window.TweakSection, {
    label: "Pages"
  }), /*#__PURE__*/React.createElement("div", {
    style: {
      display: "grid",
      gridTemplateColumns: "1fr 1fr 1fr",
      gap: "6px"
    }
  }, ["services", "our-services", "co-managed", "automation", "about", "contact"].map(r => /*#__PURE__*/React.createElement("button", {
    key: r,
    onClick: () => go(r),
    style: {
      padding: "8px 6px",
      background: route === r ? "rgba(138,108,29,0.2)" : "transparent",
      border: route === r ? "1px solid #8a6c1d" : "1px solid rgba(0,0,0,0.1)",
      color: route === r ? "#5e4a13" : "rgba(41,38,27,.72)",
      font: '500 10px/1 "JetBrains Mono", monospace',
      textTransform: "uppercase",
      letterSpacing: "0.12em",
      cursor: "pointer",
      borderRadius: "4px"
    }
  }, r === "services" ? "HOME" : r === "our-services" ? "SERVICES" : r === "co-managed" ? "CO-MGD" : r)))));
}
ReactDOM.createRoot(document.getElementById("root")).render(/*#__PURE__*/React.createElement(App, null));