{"version":3,"file":"FacilityGate.BCGbmKDI.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/GQykvG0T3sY5I3POVvEi/tW1Ikobvc5i8N0EmFuGB/FacilityGate.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * STA-391 — Facility visibility gate.\n *\n * The admin portal decides which facilities are live (facilities.is_active).\n * On the PUBLISHED PRODUCTION site (circle-fit.com) clubs whose facility is\n * deactivated must never render. On every other host — Framer canvas,\n * staging *.framer.app, every branch preview — everything in the CMS renders,\n * so test facilities are always visible on test sites.\n *\n * Rules:\n *  - gate is ACTIVE only on production hostnames (host-based → works for\n *    every future branch preview automatically)\n *  - club with Facility ID set + facility active   → visible\n *  - club with Facility ID set + not in active set → hidden\n *  - club without Facility ID (legacy/coming-soon) → visible\n *  - API unreachable → fail-open (show everything; the location list must\n *    never go blank because of an API outage)\n */const PROD_HOSTS=new Set([\"circle-fit.com\",\"www.circle-fit.com\"]);const FACILITIES_API=\"https://ssabdkgtgmxjdkfjpznw.supabase.co/functions/v1/api/facilities\";export function isProdHost(){if(typeof window===\"undefined\")return false;return PROD_HOSTS.has(window.location.hostname);}let activeIdsPromise=null;/** Fetch the ACTIVE facility ids once per page load. null = failed (fail-open). */export function fetchActiveFacilityIds(){if(!activeIdsPromise){activeIdsPromise=fetch(FACILITIES_API,{headers:{accept:\"application/json\"}}).then(res=>res.ok?res.json():null).then(data=>{if(!data||!Array.isArray(data.facilities))return null;return new Set(data.facilities.map(f=>String(f?.id??\"\")).filter(Boolean));}).catch(()=>null);}return activeIdsPromise;}/**\n * Active facility ids for gating. Returns:\n *  - null  → gate inert (non-prod host, still loading, or API failed)\n *  - Set   → gate active; hide items whose facility id is set but absent\n */export function useActiveFacilityIds(){const[ids,setIds]=useState(null);useEffect(()=>{if(!isProdHost())return;let cancelled=false;fetchActiveFacilityIds().then(result=>{if(!cancelled&&result)setIds(result);});return()=>{cancelled=true;};},[]);return ids;}export function isFacilityVisible(facilityId,activeIds){if(!activeIds)return true// gate inert / loading / fail-open\n;const id=(facilityId||\"\").trim();if(!id)return true// unmapped club (legacy / coming soon)\n;return activeIds.has(id);}/** Filter a parsed item list (used by the store finder provider). */export function useFacilityGate(items,getFacilityId){const activeIds=useActiveFacilityIds();if(!activeIds)return items;return items.filter(item=>isFacilityVisible(getFacilityId(item),activeIds));}/**\n * Invisible guard placed INSIDE a collection-list item template. Bind\n * `facilityId` to the club's \"Facility ID\" CMS field. On production it hides\n * the whole list item when the facility is deactivated.\n */export function FacilityCardGuard(props){const activeIds=useActiveFacilityIds();const visible=isFacilityVisible(props.facilityId,activeIds);const ref=useRef(null);useEffect(()=>{if(visible||!ref.current)return;const item=ref.current.closest(\"li\")||ref.current.closest('[role=\"listitem\"]')||ref.current.parentElement?.parentElement;if(item instanceof HTMLElement){item.style.setProperty(\"display\",\"none\",\"important\");}},[visible]);return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{width:1,height:1,opacity:0,pointerEvents:\"none\"}});}addPropertyControls(FacilityCardGuard,{facilityId:{type:ControlType.String,title:\"Facility ID\"}});/**\n * Page guard for CMS detail pages (/location/:club, /schedule-trial-lesson/…).\n * Bind `facilityId` to the page item's \"Facility ID\" field. On production a\n * deactivated facility's page redirects to `redirectTo`.\n */export default function FacilityPageGuard(props){const activeIds=useActiveFacilityIds();const visible=isFacilityVisible(props.facilityId,activeIds);useEffect(()=>{if(visible)return;window.location.replace(props.redirectTo||\"/location\");},[visible,props.redirectTo]);return /*#__PURE__*/_jsx(\"div\",{style:{width:1,height:1,opacity:0,pointerEvents:\"none\"}});}addPropertyControls(FacilityPageGuard,{facilityId:{type:ControlType.String,title:\"Facility ID\"},redirectTo:{type:ControlType.String,title:\"Redirect to\",defaultValue:\"/location\"}});const registry=new Map;const registryListeners=new Set;function notifyRegistry(){for(const fn of registryListeners)fn();}/** Invisible marker repeated per club inside the layout template. */export function FacilityRegistryItem(props){const key=`${props.slug||\"\"}`;useEffect(()=>{if(!key)return;const slug=(props.slug||\"\").trim();registry.set(key,{facilityId:(props.facilityId||\"\").trim(),slug,proeflesSlug:(props.proeflesSlug||\"\").trim()||(slug?`probeer-circle-fit-gratis-uit-${slug}`:\"\")});notifyRegistry();},[key,props.facilityId,props.proeflesSlug]);return /*#__PURE__*/_jsx(\"div\",{style:{width:1,height:1,opacity:0,pointerEvents:\"none\"}});}addPropertyControls(FacilityRegistryItem,{facilityId:{type:ControlType.String,title:\"Facility ID\"},slug:{type:ControlType.String,title:\"Slug\"},proeflesSlug:{type:ControlType.String,title:\"Proefles Slug\"}});/** Mounted once in the layout template: hides links to hidden clubs on prod. */export function FacilityLinkGate(){const activeIds=useActiveFacilityIds();const[,forceRender]=useState(0);useEffect(()=>{const bump=()=>forceRender(n=>n+1);registryListeners.add(bump);return()=>{registryListeners.delete(bump);};},[]);useEffect(()=>{const styleId=\"facility-link-gate-style\";const existing=document.getElementById(styleId);if(!activeIds){if(existing)existing.remove();return;}const selectors=[];for(const entry of registry.values()){if(isFacilityVisible(entry.facilityId,activeIds))continue;if(entry.slug){selectors.push(`a[href$=\"/location/${entry.slug}\"]`);selectors.push(`a[href$=\"/location/${entry.slug}/\"]`);}if(entry.proeflesSlug){selectors.push(`a[href$=\"/schedule-trial-lesson/${entry.proeflesSlug}\"]`);selectors.push(`a[href$=\"/schedule-trial-lesson/${entry.proeflesSlug}/\"]`);}}const css=selectors.length?`${selectors.join(\",\\n\")} { display: none !important; }`:\"\";const style=existing||document.createElement(\"style\");style.id=styleId;style.textContent=css;if(!existing)document.head.appendChild(style);});return /*#__PURE__*/_jsx(\"div\",{style:{width:1,height:1,opacity:0,pointerEvents:\"none\"}});}addPropertyControls(FacilityLinkGate,{});\nexport const __FramerMetadata__ = {\"exports\":{\"FacilityRegistryItem\":{\"type\":\"reactComponent\",\"name\":\"FacilityRegistryItem\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"default\":{\"type\":\"reactComponent\",\"name\":\"FacilityPageGuard\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"isFacilityVisible\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"useFacilityGate\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"FacilityLinkGate\":{\"type\":\"reactComponent\",\"name\":\"FacilityLinkGate\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"isProdHost\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"useActiveFacilityIds\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"FacilityCardGuard\":{\"type\":\"reactComponent\",\"name\":\"FacilityCardGuard\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"fetchActiveFacilityIds\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./FacilityGate.map"],"mappings":"uMAiBiK,SAAgB,GAAY,CAA6C,OAAlC,IAAS,QAAgC,EAAW,IAAI,EAAO,SAAS,QAAQ,CAAE,CAA8G,SAAgB,GAAwB,CAAsS,MAArS,CAAsB,IAAiB,MAAM,EAAe,CAAC,QAAQ,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,KAAK,GAAK,EAAI,GAAG,EAAI,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,GAAU,CAAC,GAAM,CAAC,MAAM,QAAQ,EAAK,UAAU,EAAS,KAAY,IAAI,IAAI,EAAK,WAAW,IAAI,GAAG,OAAO,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,CAAG,CAAC,CAAC,UAAU,IAAI,EAAU,CAAiB,CAI3uB,SAAgB,GAAsB,CAAC,GAAK,CAAC,EAAI,GAAQA,EAAS,IAAI,EAA8K,OAA5K,MAAc,CAAC,GAAG,CAAC,EAAW,EAAE,OA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