{"version":3,"file":"SaveDownloadButton.RYkfJDmJ.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/NPc3GjGric32GpDIZX72/h2Vh2wxZHg5mA1kBccyw/SaveDownloadButton.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useEffect}from\"react\";import{supabase}from\"https://framerusercontent.com/modules/SJArjqHRgRc2gy0BwLnw/Oyiw3PRIl6sgvXz2lom1/supabaseClient.js\";export default function SaveDownloadButton({title,fileUrl,buttonText,backgroundColor,textColor,font,fontSize,borderRadius}){const[isSaved,setIsSaved]=useState(false);useEffect(()=>{const checkSaved=async()=>{const{data:userData}=await supabase.auth.getUser();if(!userData.user)return;const{data}=await supabase.from(\"user_materials\").select(\"id\").eq(\"user_id\",userData.user.id).eq(\"file_url\",fileUrl).maybeSingle();if(data){setIsSaved(true);}};checkSaved();},[]);const[message,setMessage]=useState(\"\");const handleClick=async()=>{// 👉 se già salvato → vai ai materiali (e NON aprire PDF)\nif(isSaved){window.location.href=\"/user-material\";return;}// 👉 primo click → apri PDF\nwindow.open(fileUrl,\"_blank\");const{data:userData}=await supabase.auth.getUser();if(!userData.user)return;const{data:existing}=await supabase.from(\"user_materials\").select(\"id\").eq(\"user_id\",userData.user.id).eq(\"file_url\",fileUrl).maybeSingle();if(existing){setIsSaved(true);return;}const{error}=await supabase.from(\"user_materials\").insert({user_id:userData.user.id,title:title,file_url:fileUrl});if(error){setMessage(\"Errore nel salvataggio\");}else{setIsSaved(true);setMessage(\"Salvato ✅\");}};return /*#__PURE__*/_jsx(\"button\",{onClick:handleClick,style:{background:isSaved?\"transparent\":backgroundColor,color:isSaved?\"#05E347\":textColor,padding:\"0px\",border:\"none\",borderRadius:borderRadius,cursor:\"pointer\",...font||{},fontSize:fontSize},children:buttonText});{message&&/*#__PURE__*/_jsx(\"p\",{style:{fontSize:12,marginTop:5},children:message});}}import{addPropertyControls,ControlType}from\"framer\";addPropertyControls(SaveDownloadButton,{title:{type:ControlType.String,title:\"Titolo\",defaultValue:\"Materiale\"},fileUrl:{type:ControlType.String,title:\"File URL\"},buttonText:{type:ControlType.String,title:\"Testo\",defaultValue:\"Scarica\"},backgroundColor:{type:ControlType.Color,title:\"Fill\",defaultValue:\"#0099ff\"},textColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#ffffff\"},fontSize:{type:ControlType.Number,title:\"Font Size\",defaultValue:14,min:10,max:40},borderRadius:{type:ControlType.Number,title:\"Radius\",defaultValue:6,min:0,max:20},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SaveDownloadButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SaveDownloadButton.map"],"mappings":"2OAAyM,SAAwB,EAAmB,CAAC,QAAM,UAAQ,aAAW,kBAAgB,YAAU,OAAK,WAAS,gBAAc,CAAC,GAAK,CAAC,EAAQ,GAAYA,EAAS,EAAK,EAAE,MAAc,EAAwQ,SAA7O,CAAC,GAAK,CAAC,KAAK,GAAU,MAAM,EAAS,KAAK,QAAQ,EAAE,GAAG,CAAC,EAAS,KAAK,OAAO,GAAK,CAAC,QAAM,MAAM,EAAS,KAAK,gBAAgB,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,UAAU,EAAS,KAAK,EAAE,CAAC,CAAC,GAAG,WAAW,CAAO,CAAC,CAAC,YAAY,EAAK,GAAM,EAAW,EAAI,CAAG,EAAE,CAAW,CAAE,EAAE,CAAC,CAAC,EAAE,GAAK,CAAC,EAAQ,GAAYA,EAAS,EAAE,EAE7M,OAAoB,EAAK,SAAS,CAAC,QAAQ,SAF+L,CAC1tB,GAAG,EAAQ,CAAC,EAAO,SAAS,KAAK,iBAAiB,MAAO,CACzD,EAAO,KAAK,EAAQ,QAAQ,EAAE,GAAK,CAAC,KAAK,GAAU,MAAM,EAAS,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