{
  "version": 3,
  "sources": ["ssg:https://framerusercontent.com/modules/nDVu3G5S8HcSoHIu5Xtf/NXAsfETMrnemhaJel3AB/Figma_Data_Fetch.js"],
  "sourcesContent": ["import{jsx as _jsx}from\"react/jsx-runtime\";import{Frame,addPropertyControls,ControlType}from\"framer\";import{createClient}from\"@supabase/supabase-js\";import{useState,useRef}from\"react\";import{useSessionData,MAX_MONTHLY_COMPONENTS,onComponentUsed}from\"https://framerusercontent.com/modules/cdM9qsAvVyrbpqiGYiU4/pb5E54aPp9URedBrf30s/Supabase.js\";const supabaseUrl=\"https://utxvzlmocdvqvcwwmgqk.supabase.co\";const supabaseAnonKey=\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InV0eHZ6bG1vY2R2cXZjd3dtZ3FrIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzQ1OTE2MzgsImV4cCI6MjA1MDE2NzYzOH0.7KfXuJw-twDCRI9ig_tv_dYgRiLXrTbn63r1azNt3Vg\";export const supabase=createClient(supabaseUrl,supabaseAnonKey);// Utility for logging in development mode\nconst log={info:(...args)=>process.env.NODE_ENV!==\"production\"&&console.log(...args),error:(...args)=>process.env.NODE_ENV!==\"production\"&&console.error(...args)};// Function to copy the Figma data to the clipboard\nconst copyFigmaToClipboard=async figmaCode=>{try{let success=false;// First try the newer Clipboard API\nif(navigator.clipboard&&navigator.clipboard.write){const htmlData=`\n                <html>\n                    <head>\n                        <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n                    </head>\n                    <body>\n                        <!--StartFragment-->\n                        ${figmaCode}\n                        <!--EndFragment-->\n                    </body>\n                </html>\n            `;const blob=new Blob([htmlData],{type:\"text/html\"});const clipboardItem=new ClipboardItem({\"text/html\":blob,\"text/plain\":new Blob([figmaCode],{type:\"text/plain\"})});await navigator.clipboard.write([clipboardItem]);log.info(\"Figma component copied to clipboard!\");success=true;}else{// Fallback for older browsers\nconst tempElement=document.createElement(\"div\");tempElement.innerHTML=figmaCode;// Preserve white space and line breaks\ntempElement.style.whiteSpace=\"pre\";tempElement.style.position=\"absolute\";tempElement.style.left=\"-9999px\";document.body.appendChild(tempElement);// Select the content\nconst range=document.createRange();range.selectNode(tempElement);const selection=window.getSelection();selection.removeAllRanges();selection.addRange(range);// Execute copy command\nconst successful=document.execCommand(\"copy\");// Cleanup\nselection.removeAllRanges();document.body.removeChild(tempElement);if(successful){log.info(\"Figma component copied to clipboard (fallback)!\");success=true;}else{throw new Error(\"Fallback copy failed\");}}return success;}catch(err){log.error(\"Failed to copy:\",err);return false;}};export function CopyFigmaComponentButton({tableName,rowId,buttonBackground,buttonHoverBackground,buttonText,textColor,borderRadius,onLoading,onSuccess,onError}){const[sessionData,setSessionData]=useSessionData();const{monthlyComponentsUsed,proIsUnlimited}=sessionData;const[loading,setLoading]=useState(false);const cachedData=useRef({})// Scoped cache: an object with tableName-rowId as keys\n;// Fetch Figma code from Supabase\nconst fetchFigmaCode=async()=>{if(loading)return;setLoading(true);onLoading?.()// Trigger On Loading interaction\n;if(!proIsUnlimited&&monthlyComponentsUsed>=MAX_MONTHLY_COMPONENTS){window.location.href=\"/limit-reached\";return;}const cacheKey=`${tableName}-${rowId}`;try{// Check if data is cached for this specific button\nif(cachedData.current[cacheKey]){log.info(\"Using cached data:\",cachedData.current[cacheKey]);const success=await copyFigmaToClipboard(cachedData.current[cacheKey]);if(success){onSuccess?.()// Success only after confirmed clipboard write\n;onComponentUsed(setSessionData);}else{onError?.();}setLoading(false);return;}// Fetch new data from Supabase\nconst{data,error}=await supabase.from(tableName).select(\"figma_code\").eq(\"id\",rowId).maybeSingle();if(error||!data?.figma_code){throw new Error(error?.message||\"No figma_code found\");}// Cache the fetched data and copy to clipboard\ncachedData.current[cacheKey]=data.figma_code;const success=await copyFigmaToClipboard(data.figma_code);if(success){onSuccess?.()// Trigger success interaction once clipboard write completes\n;onComponentUsed(setSessionData);}else{onError?.();}}catch(err){log.error(\"Error fetching Figma code:\",err);onError?.()// Trigger error variant\n;}finally{setLoading(false);}};// Button styles\nconst buttonStyles={display:\"flex\",alignItems:\"center\",justifyContent:\"center\",width:\"100%\",height:\"100%\",background:buttonBackground,color:textColor,border:\"none\",borderRadius:`${borderRadius}px`,cursor:loading?\"not-allowed\":\"pointer\",transition:\"background 0.3s ease\",opacity:loading?.7:1};return /*#__PURE__*/_jsx(Frame,{width:\"100%\",height:\"100%\",background:\"none\",style:{padding:0},onClick:fetchFigmaCode,onMouseEnter:e=>e.target.style.background=buttonHoverBackground,onMouseLeave:e=>e.target.style.background=buttonBackground,children:loading?\"Loading...\":buttonText||\"Copy to Figma\"});}// Add property controls for the component\naddPropertyControls(CopyFigmaComponentButton,{tableName:{type:ControlType.String,title:\"Table Name\",defaultValue:\"figma_components\"},rowId:{type:ControlType.String,title:\"Row ID\",defaultValue:\"example_row_id\"},buttonBackground:{type:ControlType.Color,title:\"Background\",defaultValue:\"#09f\"},buttonHoverBackground:{type:ControlType.Color,title:\"Hover Background\",defaultValue:\"#0073e6\"},buttonText:{type:ControlType.String,title:\"Text\",defaultValue:\"Copy to Figma\"},textColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#fff\"},borderRadius:{type:ControlType.Number,title:\"Border Radius\",defaultValue:5,min:0,max:50},onLoading:{type:ControlType.EventHandler,title:\"On Loading\"},onSuccess:{type:ControlType.EventHandler,title:\"On Success\"},onError:{type:ControlType.EventHandler,title:\"On Error\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"CopyFigmaComponentButton\":{\"type\":\"reactComponent\",\"name\":\"CopyFigmaComponentButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"supabase\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Figma_Data_Fetch.map"],
  "mappings": "4NAAuV,IAAMA,EAAY,2CAAiDC,EAAgB,mNAAgOC,EAASC,EAAaH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MAAM,OAAO,OAAO,OAAO,WAAWxB,EAAiB,MAAMG,EAAU,OAAO,OAAO,aAAa,GAAGC,CAAY,KAAK,OAAOS,EAAQ,cAAc,UAAU,WAAW,uBAAuB,QAAQA,EAAQ,GAAG,CAAC,EAAE,OAAoBY,EAAKC,EAAM,CAAC,MAAM,OAAO,OAAO,OAAO,WAAW,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQR,EAAe,aAAaS,GAAGA,EAAE,OAAO,MAAM,WAAW1B,EAAsB,aAAa0B,GAAGA,EAAE,OAAO,MAAM,WAAW3B,EAAiB,SAASa,EAAQ,aAAaX,GAAY,eAAe,CAAC,CAAE,CACjlB0B,EAAoB/B,EAAyB,CAAC,UAAU,CAAC,KAAKgC,EAAY,OAAO,MAAM,aAAa,aAAa,kBAAkB,EAAE,MAAM,CAAC,KAAKA,EAAY,OAAO,MAAM,SAAS,aAAa,gBAAgB,EAAE,iBAAiB,CAAC,KAAKA,EAAY,MAAM,MAAM,aAAa,aAAa,MAAM,EAAE,sBAAsB,CAAC,KAAKA,EAAY,MAAM,MAAM,mBAAmB,aAAa,SAAS,EAAE,WAAW,CAAC,KAAKA,EAAY,OAAO,MAAM,OAAO,aAAa,eAAe,EAAE,UAAU,CAAC,KAAKA,EAAY,MAAM,MAAM,aAAa,aAAa,MAAM,EAAE,aAAa,CAAC,KAAKA,EAAY,OAAO,MAAM,gBAAgB,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,KAAKA,EAAY,aAAa,MAAM,YAAY,EAAE,UAAU,CAAC,KAAKA,EAAY,aAAa,MAAM,YAAY,EAAE,QAAQ,CAAC,KAAKA,EAAY,aAAa,MAAM,UAAU,CAAC,CAAC",
  "names": ["supabaseUrl", "supabaseAnonKey", "supabase", "createClient", "log", "args", "copyFigmaToClipboard", "figmaCode", "success", "navigator", "htmlData", "blob", "clipboardItem", "tempElement", "range", "selection", "window", "successful", "err", "CopyFigmaComponentButton", "tableName", "rowId", "buttonBackground", "buttonHoverBackground", "buttonText", "textColor", "borderRadius", "onLoading", "onSuccess", "onError", "sessionData", "setSessionData", "useSessionData", "monthlyComponentsUsed", "proIsUnlimited", "loading", "setLoading", "ye", "cachedData", "pe", "fetchFigmaCode", "MAX_MONTHLY_COMPONENTS", "cacheKey", "onComponentUsed", "data", "error", "buttonStyles", "p", "Frame", "e", "addPropertyControls", "ControlType"]
}
