"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,o)=>{for(var t in o)__defProp(e,t,{get:o[t],enumerable:!0})},__copyProps=(e,o,t,r)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let n of __getOwnPropNames(o))__hasOwnProp.call(e,n)||n===t||__defProp(e,n,{get:()=>o[n],enumerable:!(r=__getOwnPropDesc(o,n))||r.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),edit_downloads_modal_exports={};__export(edit_downloads_modal_exports,{EditDownloadsModal:()=>EditDownloadsModal}),module.exports=__toCommonJS(edit_downloads_modal_exports);var import_i18n=require("@wordpress/i18n"),import_element=require("@wordpress/element"),import_icons=require("@wordpress/icons"),import_data=require("@wordpress/data"),import_tracks=require("@woocommerce/tracks"),import_components=require("@woocommerce/components"),import_components2=require("@wordpress/components"),import_union_icon=require("./images/union-icon"),import_downloads_custom_image=require("./images/downloads-custom-image");const EditDownloadsModal=({downloadableItem:e,onCancel:o,onChange:t,onRemove:r,onSave:n})=>{const{createNotice:m}=(0,import_data.useDispatch)("core/notices"),[i,a]=(0,import_element.useState)(!1),{id:l=0,file:c="",name:_=""}=e;return(0,import_element.createElement)(import_components2.Modal,{title:(0,import_i18n.sprintf)((0,import_i18n.__)("Edit %s","woocommerce"),_),onRequestClose:e=>{!e||e.isPropagationStopped()||i||((0,import_tracks.recordEvent)("product_downloads_modal_cancel"),o())},className:"woocommerce-edit-downloads-modal"},(0,import_element.createElement)("div",{className:"woocommerce-edit-downloads-modal__preview"},(0,import_element.createElement)(import_components.ImageGallery,{allowDragging:!1,columns:1},((e="")=>{if(!e)return;const o=(e.split(".").pop()||"").toLowerCase();return["jpg","jpeg","png","gif","webp"].includes(o)})(c)?(0,import_element.createElement)(import_components.ImageGalleryItem,{key:l,alt:_,src:c,id:`${l}`,isCover:!1}):(0,import_element.createElement)(import_downloads_custom_image.DownloadsCustomImage,null)),(0,import_element.createElement)("div",{className:"components-form-file-upload"},(0,import_element.createElement)("p",null,_))),(0,import_element.createElement)(import_components2.BaseControl,{id:"file-name-help",className:"woocommerce-edit-downloads-modal__file-name",help:(0,import_i18n.__)("Your customers will see this on the thank-you page and in their order confirmation email.","woocommerce")},(0,import_element.createElement)(import_components2.__experimentalInputControl,{id:"file-name",label:(0,import_i18n.__)("FILE NAME","woocommerce"),name:"file-name",value:_||"",onChange:e=>{t(e??"")}})),(0,import_element.createElement)("div",{className:"woocommerce-edit-downloads-modal__file-url"},(0,import_element.createElement)(import_components2.__experimentalInputControl,{disabled:!0,id:"file-url",label:(0,import_i18n.__)("FILE URL","woocommerce"),name:"file-url",value:c||"",suffix:(0,import_element.createElement)(import_components2.Button,{icon:(0,import_element.createElement)(import_union_icon.UnionIcon,null),onClick:async function(){(0,import_tracks.recordEvent)("product_downloads_modal_copy_url_to_clipboard"),a(!0),await async function(e){if("clipboard"in navigator)await navigator.clipboard.writeText(e);else{const o=document.createElement("textarea");o.value=e,document.body.appendChild(o),o.select(),document.execCommand("copy"),document.body.removeChild(o)}await void m("success",(0,import_i18n.__)("URL copied successfully.","woocommerce"))}(c),a(!1)}})})),(0,import_element.createElement)("div",{className:"woocommerce-edit-downloads-modal__buttons"},(0,import_element.createElement)("div",{className:"woocommerce-edit-downloads-modal__buttons-left"},(0,import_element.createElement)(import_components2.Button,{icon:import_icons.trash,isDestructive:!0,variant:"tertiary",label:(0,import_i18n.__)("Delete","woocommerce"),onClick:()=>{(0,import_tracks.recordEvent)("product_downloads_modal_delete"),r()}},(0,import_i18n.__)("Delete file","woocommerce"))),(0,import_element.createElement)("div",{className:"woocommerce-edit-downloads-modal__buttons-right"},(0,import_element.createElement)(import_components2.Button,{label:(0,import_i18n.__)("Cancel","woocommerce"),onClick:()=>{(0,import_tracks.recordEvent)("product_downloads_modal_cancel"),o()},variant:"tertiary"},(0,import_i18n.__)("Cancel","woocommerce")),(0,import_element.createElement)(import_components2.Button,{label:(0,import_i18n.__)("Update","woocommerce"),onClick:()=>{(0,import_tracks.recordEvent)("product_downloads_modal_update"),n()},variant:"primary"},(0,import_i18n.__)("Update","woocommerce")))))};