{"version":3,"file":"ShopifyCollectionFetch.0XqsmJDC.mjs","names":[],"sources":["https:/framerusercontent.com/modules/TEO59dUEJL6A3lihCy8h/HBrqWcAmKmmSCJhEfMNI/ShopifyCollectionFetch.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";// ==========================================\n// 1. HARDCODE YOUR KEYS HERE (Bypass Framer UI)\n// ==========================================\nconst SHOP_SUBDOMAIN=\"bowling-stars\";const STOREFRONT_TOKEN=\"605c822ded51e6c3b91e2dd2d422f662\";export default function ShopifyCollectionFetcher(props){const{collectionId,namespacesAndKeys}=props;const isCanvas=RenderTarget.current()===RenderTarget.canvas;if(!isCanvas){console.log(\"🧩 [SHOPIFY DEBUG] Collection Fetcher mounted. Collection ID received:\",collectionId);}React.useEffect(()=>{// If Collection ID is missing, abort.\nif(isCanvas||!collectionId){if(!isCanvas)console.log(\"⚠️ [SHOPIFY DEBUG] Aborting fetch: Collection ID is missing. Check your CMS binding!\");return;}// 2. Detect Locale (URL is King)\nlet detectedLang=\"fr\";const pathLocale=window.location.pathname.split(\"/\")[1];if(pathLocale&&pathLocale.length===2){detectedLang=pathLocale;}else{const htmlLang=document.documentElement.lang;if(htmlLang&&htmlLang!==\"x-default\"){detectedLang=htmlLang;}}const localeCode=detectedLang.split(\"-\")[0].toUpperCase();// 3. Fetch Data\nlet formattedId=collectionId.trim();// Ensure it uses the Collection GID\nif(!formattedId.startsWith(\"gid://shopify/Collection/\")){formattedId=`gid://shopify/Collection/${formattedId.replace(/\\D/g,\"\")}`;}const aliases=(namespacesAndKeys||[]).map((nk,index)=>{const[ns,key]=nk.split(\".\");if(!ns||!key)return\"\";return`field_${index}: metafield(namespace: \"${ns.trim()}\", key: \"${key.trim()}\") { value }`;}).join(\"\\n\");// 4. GraphQL Query for Collections\nconst query=`\n            query getCollectionData($id: ID!, $language: LanguageCode!) @inContext(language: $language) {\n                collection(id: $id) {\n                    title\n                    description\n                    descriptionHtml\n                    ${aliases}\n                }\n            }\n        `;const fetchAllData=async()=>{try{const response=await fetch(`https://${SHOP_SUBDOMAIN}.myshopify.com/api/2024-01/graphql.json`,{method:\"POST\",headers:{\"Content-Type\":\"application/json\",\"X-Shopify-Storefront-Access-Token\":STOREFRONT_TOKEN},body:JSON.stringify({query,variables:{id:formattedId,language:localeCode}})});const json=await response.json();const collectionData=json.data?.collection;if(collectionData){const fetchedData={};fetchedData[\"title\"]=collectionData.title||\"\";fetchedData[\"description\"]=collectionData.description||\"\";fetchedData[\"descriptionHtml\"]=collectionData.descriptionHtml||\"\";(namespacesAndKeys||[]).forEach((nk,index)=>{fetchedData[nk]=collectionData[`field_${index}`]?.value||null;});// Store in a distinct window object so it doesn't overwrite product data\n// @ts-ignore\nwindow.__SHOPIFY_COLLECTION_DATA=fetchedData;// Dispatch a distinct event for collections\nwindow.dispatchEvent(new CustomEvent(\"shopify_collection_ready\"));}}catch(err){console.error(\"❌ [SHOPIFY DEBUG] Collection API Fetch Failed:\",err);}};fetchAllData();},[collectionId,namespacesAndKeys,isCanvas]);if(isCanvas){return /*#__PURE__*/_jsx(\"div\",{style:{padding:\"8px 12px\",backgroundColor:\"#059669\",color:\"#FFFFFF\",fontSize:12,fontWeight:600,borderRadius:6,display:\"inline-flex\",pointerEvents:\"none\"},children:\"📁 Shopify Collection Fetcher\"});}return /*#__PURE__*/_jsx(\"div\",{style:{display:\"none\"}});}addPropertyControls(ShopifyCollectionFetcher,{collectionId:{type:ControlType.String,title:\"Collection ID\"},namespacesAndKeys:{type:ControlType.Array,control:{type:ControlType.String},title:\"Metafields to Fetch\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ShopifyCollectionFetcher\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ShopifyCollectionFetch.map"],"mappings":"+LAG+F,SAAwB,EAA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