{"version":3,"file":"Figma_Data_Fetch.0bQFOCLR.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/nDVu3G5S8HcSoHIu5Xtf/m50jKut2kUnwkDwWihST/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/sp0g2XcJnRCzIs1AN6tu/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\":{\"supabase\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"CopyFigmaComponentButton\":{\"type\":\"reactComponent\",\"name\":\"CopyFigmaComponentButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"4eAmBuR,SAAgB,EAAyB,CAAC,YAAU,QAAM,mBAAiB,wBAAsB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