var u=(t,e,o)=>new Promise((i,r)=>{var s=a=>{try{c(o.next(a))}catch(l){r(l)}},n=a=>{try{c(o.throw(a))}catch(l){r(l)}},c=a=>a.done?i(a.value):Promise.resolve(a.value).then(s,n);c((o=o.apply(t,e)).next())});import{c0 as g,b6 as m,bf as h}from"./bootstrap-Bqxdt4iG.js";import d from"./index-BsjhuR3T.js";const S=!1,p="wms",$=`/storage/v1/object/public/${p}/`;function L(t){return t?t.startsWith("http://")||t.startsWith("https://")?t:`https://e.tdexpress.co${$}${t}`:""}function b(t){if(!t)return"";if(!t.startsWith("http://")&&!t.startsWith("https://"))return t;const e=`/object/public/${p}/`,o=t.indexOf(e);return o===-1?t:decodeURIComponent(t.slice(o+e.length))}function E(t){const e=t.lastIndexOf("."),o=e===-1?t:t.slice(0,e),i=e===-1?"":t.slice(e).toLowerCase();let r=o.replaceAll(/[^\w.-]+/g,"-").replaceAll(/-+/g,"-");r=r.replaceAll(/^-+|-+$/g,""),r||(r="file");const s=i.replaceAll(/[^\w.]/g,"");return r+s}function w(t){const e=new Date;return`${[String(e.getFullYear()).slice(-2),String(e.getMonth()+1).padStart(2,"0"),String(e.getDate()).padStart(2,"0"),"-",String(e.getHours()).padStart(2,"0"),String(e.getMinutes()).padStart(2,"0"),String(e.getSeconds()).padStart(2,"0")].join("")}-${E(t)}`}function T(t,e){return u(this,null,function*(){const{file:o,onError:i,onProgress:r,onSuccess:s}=e;try{if(r==null||r({percent:0}),!S){const n=h.storage;if(!n)throw new Error("Supabase storage is not configured");const c=w(o.name),a=`${t}/${c}`,{data:l,error:f}=yield n.from(p).upload(a,o);if(f)throw f;r==null||r({percent:100}),s==null||s({url:l.path},o)}}catch(n){i==null||i(n instanceof Error?n:new Error(String(n)))}})}function A(t,e){return u(this,null,function*(){const{file:o,onError:i,onProgress:r,onSuccess:s}=e;try{if(r==null||r({percent:0}),!S){const n=h.storage;if(!n)throw new Error("Supabase storage is not configured");const c=w(o.name),a=`${t}/${c}`,{data:l,error:f}=yield n.from(p).upload(a,o);if(f)throw f;r==null||r({percent:100}),s==null||s({url:l.path},o)}}catch(n){i==null||i(n instanceof Error?n:new Error(String(n)))}})}function R(t){return u(this,null,function*(){if(t.length===0)return;const e=h.storage;if(!e)return;const o=t.map(r=>b(r)).filter(Boolean);if(o.length===0)return;const{error:i}=yield e.from(p).remove(o);i&&console.error("Failed to delete storage files:",i)})}function W(t,e){const o=new Set(e);return t.filter(i=>!o.has(i))}function _(t){return t.map((e,o)=>({uid:`existing-${o}`,name:e.split("/").pop()||`photo-${o}`,status:"done",url:L(e),response:{url:e}}))}function C(t,e=5,o="image"){if(o==="image"){if(!t.type.startsWith("image/"))return g.error(m("page.common.photoTypeLimit")||"Only images are allowed!"),d.LIST_IGNORE}else if(o==="video"&&!t.type.startsWith("video/"))return g.error(m("page.common.videoTypeLimit")||"Only videos are allowed!"),d.LIST_IGNORE;if(e>0&&!(t.size/1024/1024<e)){let r="page.common.fileSizeLimit";return o==="image"&&(r="page.common.photoSizeLimit"),o==="video"&&(r="page.common.videoSizeLimit"),g.error(m(r,[e])||`File must be smaller than ${e}MB!`),d.LIST_IGNORE}return!1}export{L as a,T as b,A as c,R as d,W as g,C as h,_ as u};
