{"version":3,"file":"SaveDownloadButton.DjlUOOlT.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,GAAM,CAAC,MAAc,EAAkB,SAAS,CAAC,GAAK,CAAC,KAAK,GAAU,MAAM,EAAS,KAAK,SAAS,CAAC,GAAG,CAAC,EAAS,KAAK,OAAO,GAAK,CAAC,QAAM,MAAM,EAAS,KAAK,iBAAiB,CAAC,OAAO,KAAK,CAAC,GAAG,UAAU,EAAS,KAAK,GAAG,CAAC,GAAG,WAAW,EAAQ,CAAC,aAAa,CAAI,GAAM,EAAW,GAAK,IAAgB,EAAG,EAAE,CAAC,CAAC,GAAK,CAAC,EAAQ,GAAYA,EAAS,GAAG,CAE9M,OAAoB,EAAK,SAAS,CAAC,QAF8L,SAAS,CAC1tB,GAAG,EAAQ,CAAC,EAAO,SAAS,KAAK,iBAAiB,OAClD,EAAO,KAAK,EAAQ,SAAS,CAAC,GAAK,CAAC,KAAK,GAAU,MAAM,EAAS,KAAK,SAAS,CAAC,GAAG,CAAC,EAAS,KAAK,OAAO,GAAK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