{"version":3,"file":"DownloadButton.CdMfrdoS.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/AMuZv1Y8l99rn7Tpiluk/ddRyaMkBLAzU3qDIbox4/DownloadButton.js"],"sourcesContent":["// File Component - Ermöglicht das Herunterladen von Dateien mit angepasstem Dateinamen\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useState,startTransition}from\"react\";/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function BontermsFileDownload(props){// Added support for files linked from the CMS: uploadedFile string can be an external (CMS) file url.\nconst{uploadedFile=\"https://framerusercontent.com/assets/8w3IUatLX9a5JVJ6XPCVuHi94.mp3\",saveAs=\"download\",fileType,align=\"center\",stretch=false,buttonSlot,style}=props;const[isDownloading,setIsDownloading]=useState(false);const handleDownload=async()=>{if(!uploadedFile||isDownloading)return;startTransition(()=>setIsDownloading(true));try{const response=await fetch(uploadedFile);const blob=await response.blob();let fileExtension=\"file\";if(fileType&&fileType.trim()){fileExtension=fileType.toLowerCase().trim();}else{const extractedExt=uploadedFile.split(\".\").pop()?.split(\"?\")[0]||\"\";if(extractedExt&&extractedExt.length>=2&&extractedExt.length<=5&&/^[a-zA-Z0-9]+$/.test(extractedExt)){fileExtension=extractedExt.toLowerCase();}}// Check if saveAs already has a valid file extension at the end\nconst saveAsExt=saveAs.split(\".\").pop()||\"\";const hasValidExtension=saveAsExt.length>=2&&saveAsExt.length<=5&&/^[a-zA-Z0-9]+$/.test(saveAsExt);const filename=hasValidExtension?saveAs:`${saveAs}.${fileExtension}`;const url=window.URL.createObjectURL(blob);const link=document.createElement(\"a\");link.href=url;link.download=filename;document.body.appendChild(link);link.click();document.body.removeChild(link);window.URL.revokeObjectURL(url);// Track download event in Google Analytics 4\nif(typeof window!==\"undefined\"&&window.gtag){window.gtag(\"event\",\"file_download\",{file_name:filename,file_extension:fileExtension,file_url:uploadedFile,link_text:\"download_button\"});}}catch(error){console.error(\"Download failed:\",error);}finally{startTransition(()=>setIsDownloading(false));}};const alignmentStyles={left:{justifyContent:\"flex-start\"},center:{justifyContent:\"center\"},right:{justifyContent:\"flex-end\"}};return /*#__PURE__*/_jsx(\"div\",{style:{...style,display:\"flex\",width:\"100%\",minHeight:5,...alignmentStyles[align]},children:/*#__PURE__*/_jsx(\"div\",{onClick:handleDownload,style:{cursor:isDownloading?\"wait\":\"pointer\",width:stretch?\"100%\":\"auto\",opacity:isDownloading?.6:1,transition:\"opacity 0.2s ease\"},children:buttonSlot||/*#__PURE__*/_jsx(\"div\",{style:{padding:\"12px 24px\",backgroundColor:\"#0099FF\",color:\"#FFFFFF\",borderRadius:8,fontSize:16,fontWeight:600,textAlign:\"center\",userSelect:\"none\"},children:isDownloading?\"Processing...\":\"Get File\"})})});}addPropertyControls(BontermsFileDownload,{uploadedFile:{type:ControlType.Link,title:\"File (CMS)\"},saveAs:{type:ControlType.String,title:\"Save As\",defaultValue:\"download\",placeholder:\"filename.pdf\",description:\"Name your file\"},fileType:{type:ControlType.String,title:\"File Type\",placeholder:\"pdf\",description:\"File extension (used if Save As has no extension)\"},align:{type:ControlType.Enum,title:\"Align\",options:[\"left\",\"center\",\"right\"],optionTitles:[\"Left\",\"Center\",\"Right\"],defaultValue:\"center\",displaySegmentedControl:true},stretch:{type:ControlType.Boolean,title:\"Stretch\",defaultValue:false,enabledTitle:\"Auto\",disabledTitle:\"Fill width\"},buttonSlot:{type:ControlType.ComponentInstance,title:\"Button\",description:\"Connect an existing button component here\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"BontermsFileDownload\",\"slots\":[\"buttonSlot\"],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./DownloadButton.map"],"mappings":"0LAIG,SA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