@codingfactory/mediables-vue 2.19.1 → 2.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var Eh=Object.defineProperty;var Sh=(o,a,t)=>a in o?Eh(o,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[a]=t;var ie=(o,a,t)=>Sh(o,typeof a!="symbol"?a+"":a,t);const ml=require("pinia"),e=require("vue"),Ch=require("./imageEditorState-PrcqbsfM.cjs"),jt=require("pixi.js"),de=require("./editor-P9MyuiTc.cjs"),la=require("./index-QOKC8XA_.cjs"),G=require("@ionic/vue"),xh=require("pixi-filters");function Nh(o){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(a,t,n.get?n:{enumerable:!0,get:()=>o[t]})}}return a.default=o,Object.freeze(a)}const na=Nh(jt);let Ia={apiBaseUrl:"/api/v1",isAdmin:!1};function vc(o){return typeof o=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(o)}function ai(o){Ia={...Ia,...o}}function im(){return{...Ia}}function rm(o){Ia={...o}}function lm(o){const a=im();return ai(o),()=>{rm(a)}}function Vh(o){const a=o.trim().replace(/\/+$/,"");return a===""?"/api/v1":a.startsWith("/")?a:`/${a}`}function Th(o,a){const t=Vh(a),n=(i,r="")=>{const l=`/api${t}`;return!t.startsWith("/api/")&&i.startsWith(`${l}/`)?`${i.slice(4)}${r}`:!t.startsWith("/api/")&&i===l?`${t}${r}`:`${i}${r}`};if(/^https?:\/\//i.test(o))try{const i=typeof window<"u"?window.location.origin:"http://localhost",r=new URL(o,i);if(r.origin===i)return n(r.pathname,`${r.search}${r.hash}`)}catch{return o}return n(o)}const Bh=async(o,a={})=>{var s;const t=(s=document.querySelector('meta[name="csrf-token"]'))==null?void 0:s.getAttribute("content"),n={Accept:"application/json",...a.headers};t&&(n["X-CSRF-TOKEN"]=t),a.body instanceof FormData||(n["Content-Type"]="application/json");const r={method:a.method||"GET",headers:n,credentials:"include"};a.body instanceof FormData?r.body=a.body:a.body!==void 0&&(r.body=JSON.stringify(a.body));const l=await fetch(o,r);if(!l.ok){const d=await l.json().catch(()=>({message:"Request failed"}));throw new Error(d.message||`HTTP ${l.status}`)}if(l.status!==204)return await l.json()},ja=ml.defineStore("media",()=>{const o=e.ref([]),a=e.ref([]),t=e.ref(!1),n=e.ref(null),i=e.ref(1),r=e.ref(1),l=e.ref(24),s=e.ref({type:null,uuid:null}),d=e.ref([]),c=e.ref(!1),u=e.ref(null),m=e.ref(new Map),p=e.ref(new Map),f=e.ref(new Set),h=e.ref(new Map),v=e.ref({}),y=5*60*1e3,w=e.computed(()=>{if(Ia.apiScope)return Ia.apiScope;if(Ia.isAdmin)return"admin"}),_=e.computed(()=>w.value==="admin");function b(){return Ia.httpClient||Bh}function g(be){const _e=Ia.apiBaseUrl||"/api/v1",ye=w.value?`/${w.value}`:"";return`${_e}${ye}${be}`}function I(be){return`${Ia.apiBaseUrl||"/api/v1"}${be}`}function T(be,_e){return`${w.value??"default"}-${be}-${JSON.stringify(_e)}`}function $(be){return Date.now()-be<y}function N(){h.value.clear(),v.value={}}function B(be){if(!be||!be.data)return;const _e={};be.data.forEach(ye=>{const Ne=`${ye.file_name}-${ye.collection_name||"default"}`,Se=_e[Ne];(!Se||Object.keys(ye.generated_conversions||{}).length>Object.keys(Se.generated_conversions||{}).length)&&(_e[Ne]=ye)}),o.value=Object.values(_e),be.meta&&(i.value=be.meta.current_page,r.value=Math.ceil(be.meta.total/be.meta.per_page))}async function P(be=1,_e={}){const ye=T(be,_e),Ne=h.value.get(ye);if(Ne&&$(Ne.timestamp)){const Se=Ne.data;return B(Se),Se}t.value=!0,n.value=null;try{const Se=new URLSearchParams;Se.append("page",be.toString()),Se.append("per_page",l.value.toString()),_.value&&Se.append("linked","1");for(const it in _e)if(Object.prototype.hasOwnProperty.call(_e,it)){const rt=_e[it];rt!=null&&rt!==""&&Se.append(it,String(rt))}const Oe=await b()(g(`/media?${Se}`));return h.value.set(ye,{data:Oe,timestamp:Date.now()}),B(Oe),Oe}catch(Se){throw n.value=Se instanceof Error?Se.message:"Failed to fetch media",o.value=[],new Error(n.value)}finally{t.value=!1}}async function x(be,_e){t.value=!0,n.value=null;const ye=`${be.name}-${Date.now()}`,Ne={file:be,progress:0,status:"uploading"};m.value.set(ye,Ne);try{const Se=new FormData;Se.append("file",be),Se.append("collection",_e.collection),_e.ownerUuid&&(Se.append("owner_uuid",_e.ownerUuid),Se.append("owner_type",_e.ownerType||"")),_e.usageUuid&&(Se.append("usage_uuid",_e.usageUuid),Se.append("usage_type",_e.usageType||""),Se.append("usage_purpose",_e.usagePurpose||"")),_e.customProperties&&Se.append("custom_properties",JSON.stringify(_e.customProperties));const Oe=await b()(g("/media"),{method:"POST",body:Se});return Ne.status="completed",Ne.progress=100,Ne.media=Oe==null?void 0:Oe.data,i.value===1&&(Oe!=null&&Oe.data)&&(o.value=[Oe.data,...o.value]),N(),(Oe==null?void 0:Oe.data)||null}catch(Se){throw Ne.status="error",Ne.error=Se instanceof Error?Se.message:"Upload failed",n.value=Ne.error,new Error(n.value)}finally{t.value=!1,setTimeout(()=>{m.value.delete(ye)},5e3)}}async function M(be){t.value=!0,n.value=null;const _e=o.value.findIndex(Ne=>Ne.uuid===be);let ye;_e!==-1&&(ye=o.value.splice(_e,1)[0]);try{return await b()(g(`/media/${be}`),{method:"DELETE"}),f.value.delete(be),N(),!0}catch(Ne){throw ye&&_e!==-1&&o.value.splice(_e,0,ye),n.value=Ne instanceof Error?Ne.message:"Failed to delete media",new Error(n.value)}finally{t.value=!1}}async function E(be,_e){t.value=!0,n.value=null;try{const Ne=await b()(g(`/media/${be}`),{method:"PATCH",body:_e,data:_e});if(Ne!=null&&Ne.data){const Se=o.value.findIndex(Re=>Re.uuid===be);return Se!==-1&&(o.value[Se]={...o.value[Se],...Ne.data}),N(),Ne.data}return null}catch(ye){throw n.value=ye instanceof Error?ye.message:"Failed to update media",new Error(n.value)}finally{t.value=!1}}async function D(){t.value=!0,n.value=null;try{const _e=await b()(g("/media/collections"));return a.value=(_e==null?void 0:_e.data)||[],a.value}catch(be){throw n.value=be instanceof Error?be.message:"Failed to fetch collections",a.value=[],new Error(n.value)}finally{t.value=!1}}async function j(be,_e,ye="images",Ne){c.value=!0,u.value=null;try{const Se=new URLSearchParams;Se.append("collection",ye),Ne&&Se.append("search",Ne);const Oe=await b()(g(`/media/model/${be}/${_e}?${Se}`));return Oe!=null&&Oe.data?(d.value=Oe.data,Oe.data):[]}catch(Se){throw u.value=Se instanceof Error?Se.message:"Failed to fetch model media",d.value=[],new Error(u.value)}finally{c.value=!1}}async function L(be,_e,ye,Ne="images"){c.value=!0,u.value=null;const Se=[...d.value];try{const Oe=await b()(g(`/media/model/${be}/${_e}/attach`),{method:"POST",body:{media_uuids:ye,collection:Ne}});return await j(be,_e,Ne),(Oe==null?void 0:Oe.data)||[]}catch(Re){throw d.value=Se,u.value=Re instanceof Error?Re.message:"Failed to attach media",new Error(u.value)}finally{c.value=!1}}async function z(be,_e,ye,Ne="images"){c.value=!0,u.value=null;const Se=[...d.value];d.value=d.value.filter(Re=>Re.uuid!==ye);try{return await b()(g(`/media/model/${be}/${_e}/detach`),{method:"POST",body:{media_uuid:ye,collection:Ne}}),!0}catch(Re){throw d.value=Se,u.value=Re instanceof Error?Re.message:"Failed to detach media",new Error(u.value)}finally{c.value=!1}}async function C(be,_e,ye,Ne="images"){c.value=!0,u.value=null;const Se=[...d.value],Re=new Map(d.value.map(Oe=>[Oe.uuid,Oe]));d.value=ye.map(Oe=>Re.get(Oe)).filter(Oe=>Oe!==void 0);try{return await b()(g(`/media/model/${be}/${_e}/reorder`),{method:"POST",body:{media_uuids:ye,collection:Ne}}),!0}catch(Oe){throw d.value=Se,u.value=Oe instanceof Error?Oe.message:"Failed to reorder media",new Error(u.value)}finally{c.value=!1}}async function A(be,_e,ye={}){var pt,Nt;const Ne=b(),Se=Ia.apiBaseUrl||"/api/v1";let Re=vc(_e.documentId)?_e.documentId:vc((pt=_e.document)==null?void 0:pt.id)?_e.document.id:null,Oe=_e.documentRevisionId??null,it=typeof _e.documentRevisionNumber=="number"?_e.documentRevisionNumber:typeof((Nt=_e.document)==null?void 0:Nt.revision)=="number"?_e.document.revision:null;if(_e.document){const Ce=await Ne(`${Se}/media/${be}/editor-documents/materialize`,{method:"POST",body:{document_id:Re,base_document_revision:it,document:_e.document}});Re=Ce.document_id,Oe=Ce.document_revision_id,it=Ce.document_revision_number}if(_e.document&&Re&&Oe&&typeof it=="number"){const Ce=new FormData,Le=(_e.mimeType||_e.blob.type||"image/png")==="image/jpeg"?"jpg":"png";Ce.append("flattened_file",_e.blob,`edited.${Le}`),Ce.append("document_id",Re),Ce.append("document_revision_id",Oe),Ce.append("expected_document_revision",String(it)),Ce.append("output_mode",ye.asVariant?"save-as-variant":"save-as-new");const nt=await Ne(`${Se}/media/${be}/editor-documents/save`,{method:"POST",body:Ce});if(nt.media)return nt.media;throw new Error("Unexpected response from layered editor save endpoint")}const rt=new FormData,bt=(_e.mimeType||_e.blob.type||"image/png")==="image/jpeg"?"jpg":"png";rt.append("image_file",_e.blob,`edited.${bt}`);const Ct=Ch.serializeEditorState(_e.state);Ct&&rt.append("editor_state",Ct),rt.append("save_as_new","true"),ye.asVariant&&rt.append("as_variant","true"),ye.name!==void 0&&rt.append("name",ye.name);const mt=await Ne(`${Se}/editor/${be}/save`,{method:"POST",body:rt});if("media"in mt&&mt.media)return mt.media;if("status_url"in mt&&mt.status_url)return O(Ne,Th(mt.status_url,Se),ye.pollTimeout??6e4);throw new Error("Unexpected response from editor save endpoint")}async function O(be,_e,ye){const Ne=Date.now(),Se=2e3;for(;Date.now()-Ne<ye;){await new Promise(Oe=>setTimeout(Oe,Se));const Re=await be(_e);if(Re.status==="completed"&&Re.media)return Re.media;if(Re.status==="failed")throw new Error(Re.error??"Image processing failed")}throw new Error("Image processing timed out")}function K(be,_e,ye){s.value=ye!==void 0?{type:be,uuid:_e,collection:ye}:{type:be,uuid:_e},v.value[`${be}-${_e}`]={timestamp:Date.now()}}function se(){s.value={type:null,uuid:null},d.value=[],u.value=null}async function xe(){if(!s.value.type||!s.value.uuid)return;const be=await j(s.value.type,s.value.uuid,s.value.collection||"images");d.value=be||[]}function ue(){o.value.forEach(be=>f.value.add(be.uuid))}function le(){f.value.clear()}function Z(be){f.value.has(be)?f.value.delete(be):f.value.add(be)}function k(be){return f.value.has(be)}function F(){return Array.from(m.value.values()).some(be=>be.status==="uploading")}function W(be){return m.value.get(be)||p.value.get(be)}function J(){return[...Array.from(m.value.values()),...Array.from(p.value.values())]}async function ce(){const be=Array.from(f.value);let _e=0;for(const ye of be)try{await M(ye),_e++}catch{}return le(),_e}function Ue(be,_e){var ye;return _e&&((ye=be.conversion_urls)!=null&&ye[_e])?be.conversion_urls[_e]||"":be.original_url||be.url||""}return{items:o,collections:a,loading:t,error:n,currentPage:i,totalPages:r,itemsPerPage:l,isAdmin:_,modelContext:s,modelMedia:d,isLoadingModelMedia:c,modelMediaError:u,selectedItems:f,uploadProgress:m,uploadQueue:p,cachedResponses:v,fetchMedia:P,uploadFile:x,deleteMedia:M,updateMedia:E,clearCache:N,fetchCollections:D,fetchModelMedia:j,attachMedia:L,detachMedia:z,reorderMedia:C,saveEditedImage:A,setModelContext:K,clearModelContext:se,refreshModelMedia:xe,selectAllItems:ue,clearSelection:le,toggleSelection:Z,isSelected:k,deleteSelectedItems:ce,getHttpClient:b,getApiUrl:g,getEditorApiUrl:I,hasActiveUploads:F,getUploadProgress:W,getAllUploadProgress:J,getMediaUrl:Ue}}),sm=()=>((Ia.apiScope!=="admin"||Ia.isAdmin!==!0)&&ai({...Ia,apiScope:"admin",isAdmin:!0}),ja());class dm{constructor(a,t){this.state=a,this.editor=t,this.element=null,this._tabs=new Map,this._unsubscribers=[],this._onSelect=null}render({onSelect:a}={}){return this._onSelect=a,this.element=de.el("div",{className:"panel-tabs",role:"tablist","aria-label":"Filter categories","data-testid":"v2-category-tabs"}),de.EDITOR_CATEGORIES.forEach(t=>{const n=de.el("button",{type:"button",className:`panel-tab ${this._isSelected(t.id)?"active":""}`,role:"tab","aria-selected":this._isSelected(t.id)?"true":"false","data-category":t.id,"data-testid":`v2-category-${t.id}`,onClick:()=>this._selectCategory(t.id)});if(t.icon){const i=de.el("span",{className:"panel-tab-icon","aria-hidden":"true"});i.innerHTML=t.icon,n.appendChild(i)}n.appendChild(de.el("span",{className:"panel-tab-label"},t.name)),this._tabs.set(t.id,n),this.element.appendChild(n)}),this._unsubscribers.push(this.state.on("change:selectedCategory",()=>this._refreshActive())),this.element}_isSelected(a){const t=this.state.get("selectedCategory");return a==="crop"?this.state.get("mode")==="crop":t===a&&this.state.get("mode")!=="crop"}_selectCategory(a){var n;this.state.set("selectedCategory",a);const t=this.state.get("mode");a==="crop"?t!=="crop"&&this.editor.setMode("crop"):t!=="filters"&&this.editor.setMode("filters"),this._refreshActive(),(n=this._onSelect)==null||n.call(this,a)}_refreshActive(){this._tabs.forEach((a,t)=>{const n=this._isSelected(t);a.classList.toggle("active",n),a.setAttribute("aria-selected",n?"true":"false")})}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._tabs.clear(),(a=this.element)==null||a.remove(),this.element=null}}class cm{constructor(a,t){this.state=a,this.filterManager=t,this.element=null,this._unsubscribers=[],this._onToggle=null,this._onSelect=null}render({onToggle:a,onSelect:t}={}){return this._onToggle=a,this._onSelect=t,this.element=de.el("div",{className:"filter-list",role:"listbox","aria-label":"Filters","data-testid":"v2-filter-list"}),this._renderRows(),this._unsubscribers.push(this.state.on("change:selectedCategory",()=>this._renderRows()),this.state.on("change:activeFilters",()=>this._renderRows()),this.state.on("change:selectedFilter",()=>this._renderRows()),this.state.on("change:filterValues",()=>this._refreshSummaries())),this.element}_renderRows(){this.element.innerHTML="";const a=this.state.get("selectedCategory");if(!a||a==="crop")return;const t=this.filterManager.getFiltersByCategory(a),n=this.state.get("activeFilters"),i=this.state.get("selectedFilter"),r=typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId");t.forEach(l=>{var c;const s=((c=n==null?void 0:n.has)==null?void 0:c.call(n,l.id))??!1,d=i===l.id;this.element.appendChild(this._renderRow(l,s,d,r))})}_renderRow(a,t,n,i=null){const r=de.el("button",{type:"button",className:`filter-row ${n?"selected":""}`,role:"option","aria-selected":n?"true":"false","data-filter":a.id,"data-testid":`v2-filter-${a.id}`,onClick:()=>{var u;return(u=this._onSelect)==null?void 0:u.call(this,a.id,i)}}),l=de.el("button",{type:"button",className:`filter-row-toggle ${t?"active":""}`,"aria-label":`${t?"Disable":"Enable"} ${a.name}`,"aria-pressed":t?"true":"false","data-testid":`v2-filter-toggle-${a.id}`,onClick:u=>{var p,f,h,v;u.stopPropagation();const m=!((f=(p=this.state.get("activeFilters"))==null?void 0:p.has)!=null&&f.call(p,a.id));(h=this._onToggle)==null||h.call(this,a.id,m,i),m&&((v=this._onSelect)==null||v.call(this,a.id,i))}});t&&(l.innerHTML=de.checkmark),r.appendChild(l);const s=de.el("div",{className:"filter-row-body"});s.appendChild(de.el("span",{className:"filter-row-name"},a.name));const d=this._buildSummary(a,t);d&&s.appendChild(de.el("span",{className:"filter-row-summary"},d)),r.appendChild(s);const c=de.el("span",{className:"filter-row-chevron","aria-hidden":"true"});return c.innerHTML=de.chevronRight,r.appendChild(c),r}_buildSummary(a,t){if(!t)return a.description||"";const n=this.state.getFilterValues(a.id);if(!n||Object.keys(n).length===0)return a.description||"Active";const i=[];for(const r of(a.controls||[]).slice(0,4)){const l=n[r.id];if(!(l===void 0||l===r.default)&&(i.push(this._formatControlValue(r,l)),i.length>=2))break}return i.length===0?"Active":i.join(" · ")}_formatControlValue(a,t){return a.type==="toggle"?a.label:typeof t=="number"?(a.max??1)<=1&&(a.min??0)>=0?`${a.label} ${Math.round(t*100)}%`:Number.isInteger(t)?`${a.label} ${t}`:`${a.label} ${t.toFixed(2)}`:typeof t=="string"?`${a.label}`:a.label}_refreshSummaries(){var i;const a=this.state.get("selectedCategory");if(!a||a==="crop")return;const t=this.filterManager.getFiltersByCategory(a),n=this.state.get("activeFilters");for(const r of t){const l=this.element.querySelector(`[data-filter="${r.id}"]`);if(!l)continue;const s=((i=n==null?void 0:n.has)==null?void 0:i.call(n,r.id))??!1,d=this._buildSummary(r,s),c=l.querySelector(".filter-row-summary");if(d&&c)c.textContent=d;else if(d&&!c){const u=l.querySelector(".filter-row-body");u==null||u.appendChild(de.el("span",{className:"filter-row-summary"},d))}else!d&&c&&c.remove()}}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}class um{constructor(a,t){this.state=a,this.filterManager=t,this.element=null,this._unsubscribers=[],this._onChange=null,this._onReset=null,this._onAction=null}render({onChange:a,onReset:t,onAction:n}={}){return this._onChange=a,this._onReset=t,this._onAction=n,this.element=de.el("div",{className:"controls-section","data-testid":"v2-controls-section"}),this._renderControls(),this._unsubscribers.push(this.state.on("change:selectedFilter",()=>this._renderControls()),this.state.on("change:activeFilters",()=>this._renderControls())),this.element}_renderControls(){this.element.innerHTML="";const a=this.state.get("selectedFilter");if(!a){this.element.appendChild(de.el("div",{className:"no-filter-selected"},"Select a filter to adjust"));return}const t=typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId"),n=this.filterManager.getFilterDef(a);if(!n){this.element.appendChild(de.el("div",{className:"no-filter-selected"},"Filter not found"));return}const i=de.el("div",{className:"controls-header"});i.appendChild(de.el("span",{className:"controls-title"},n.name)),i.appendChild(de.createButton({label:"Reset",className:"btn-text",onClick:()=>this._handleReset(a,t)})),this.element.appendChild(i);const r=de.el("div",{className:"controls-grid"}),l=this.state.getFilterValues(a);(n.controls||[]).forEach(d=>{if(d.hidden)return;const c=this._createControl(a,d,l[d.id]??d.default,t);c&&r.appendChild(c)});const s=this.filterManager.getInstance(a);if(s&&typeof s.getDynamicControls=="function"){let d=[];try{d=s.getDynamicControls()||[]}catch{}d.forEach(c=>{const u=c.property||c.id,m=l[u]??c.default,p=this._createControl(a,c,m,t);p&&r.appendChild(p)})}this.element.appendChild(r)}_createControl(a,t,n,i=null){if(t.hidden)return null;const r=t.label||t.id,l=this._normalizeControlType(t.type),s=t.property||t.id;switch(l){case"slider":return de.createSlider({id:`v2-${a}-${t.id}`,label:r,min:t.min??0,max:t.max??1,step:t.step??.01,value:typeof n=="number"?n:t.default??0,onChange:d=>{var c;return(c=this._onChange)==null?void 0:c.call(this,a,s,d,i)}});case"toggle":return de.createToggle({id:`v2-${a}-${t.id}`,label:r,checked:!!n,onChange:d=>{var c;return(c=this._onChange)==null?void 0:c.call(this,a,s,d,i)}});case"color":return de.createColorPicker({id:`v2-${a}-${t.id}`,label:r,value:typeof n=="string"&&n.startsWith("#")?n:t.default||"#000000",onChange:d=>{var c;return(c=this._onChange)==null?void 0:c.call(this,a,s,d,i)}});case"select":{const d=(t.options||[]).map(c=>typeof c=="object"&&c.value!==void 0?{value:c.value,label:c.label||String(c.value)}:{value:c,label:String(c)});return de.createSelect({id:`v2-${a}-${t.id}`,label:r,options:d,value:n??t.default,onChange:c=>{var u;return(u=this._onChange)==null?void 0:u.call(this,a,s,c,i)}})}case"text":return de.createTextInput({id:`v2-${a}-${t.id}`,label:r,value:typeof n=="string"?n:t.default??"",placeholder:t.placeholder||"",onCommit:d=>{var c;return(c=this._onChange)==null?void 0:c.call(this,a,s,d,i)}});case"button":{const d=de.el("div",{className:"button-control"});return d.appendChild(de.createButton({label:r,className:"btn-secondary",onClick:()=>{var c;(c=this._onAction)==null||c.call(this,a,t.action||t.id,i),this._renderControls()}})),d}default:return null}}_normalizeControlType(a){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button",text:"text"}[a]||a}_handleReset(a,t=null){var n;(n=this._onReset)==null||n.call(this,a,t),this._renderControls()}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}class Mh{constructor(a,t){this.state=a,this.filterManager=t,this.element=null,this._unsubscribers=[],this._onRemove=null,this._onSelect=null,this._onClearAll=null}render({onRemove:a,onSelect:t,onClearAll:n}={}){return this._onRemove=a,this._onSelect=t,this._onClearAll=n,this.element=de.el("div",{className:"panel-section","data-testid":"v2-active-stack"}),this._renderContents(),this._unsubscribers.push(this.state.on("change:activeFilters",()=>this._renderContents()),this.state.on("change:selectedFilter",()=>this._refreshSelection())),this.element}_renderContents(){this.element.innerHTML="";const a=this.state.get("activeFilters"),t=(a==null?void 0:a.size)??0,n=this._activeFilterLayerId(),i=de.el("div",{className:"panel-section-title"});if(i.appendChild(de.el("span",{},`Active (${t})`)),t>0&&this._onClearAll&&i.appendChild(de.el("button",{type:"button",className:"btn btn-text",style:{padding:"2px 8px",fontSize:"11px"},"data-testid":"v2-clear-all",onClick:()=>{var s;return(s=this._onClearAll)==null?void 0:s.call(this,n)}},"Clear all")),this.element.appendChild(i),t===0){this.element.appendChild(de.el("div",{className:"active-empty"},"No filters applied"));return}const r=de.el("div",{className:"active-stack"}),l=this.state.get("selectedFilter");for(const s of a){const d=this.filterManager.getFilterDef(s);d&&r.appendChild(this._renderChip(d,s===l,n))}this.element.appendChild(r)}_renderChip(a,t,n=null){const i=de.el("div",{className:`active-chip ${t?"selected":""}`,"data-filter":a.id,"data-testid":`v2-active-${a.id}`});i.appendChild(de.el("button",{type:"button",className:"active-chip-name","aria-label":`Select ${a.name}`,onClick:()=>{var l;return(l=this._onSelect)==null?void 0:l.call(this,a.id,n)}},a.name));const r=de.el("button",{type:"button",className:"active-chip-remove","aria-label":`Remove ${a.name}`,"data-testid":`v2-active-remove-${a.id}`,onClick:()=>{var l;return(l=this._onRemove)==null?void 0:l.call(this,a.id,n)}});return r.innerHTML=de.close,i.appendChild(r),i}_activeFilterLayerId(){return typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId")}_refreshSelection(){var n;const a=this.state.get("selectedFilter"),t=(n=this.element)==null?void 0:n.querySelectorAll(".active-chip");t&&t.forEach(i=>{const r=i.getAttribute("data-filter");i.classList.toggle("selected",r===a)})}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}const Zo=["collapsed","half","full"];class Ih{constructor(a={}){this._onSnapChange=a.onSnapChange||null,this._ariaLabel=a.ariaLabel||"Filter controls drawer",this.element=null,this._handle=null,this._body=null,this._headerSlot=null,this._snap="half",this._dragging=!1,this._dragStartY=0,this._dragStartHeight=0,this._dragPointerId=null,this._containerHeight=0}build({header:a,body:t}={}){this.element=de.el("div",{className:"editor-v2-drawer",role:"dialog","aria-label":this._ariaLabel,"data-testid":"v2-bottom-drawer","data-snap":this._snap}),this._handle=de.el("button",{type:"button",className:"drawer-handle","aria-label":"Drag to resize filters drawer","aria-expanded":this._snap==="full"?"true":"false","data-testid":"v2-drawer-handle"});const n=de.el("span",{className:"drawer-handle-grip","aria-hidden":"true"});return this._handle.appendChild(n),this._handle.addEventListener("click",i=>{if(this._wasDragging){this._wasDragging=!1,i.preventDefault();return}this._cycleSnap()}),this._handle.addEventListener("pointerdown",i=>this._onPointerDown(i)),this._handle.addEventListener("pointermove",i=>this._onPointerMove(i)),this._handle.addEventListener("pointerup",i=>this._onPointerEnd(i)),this._handle.addEventListener("pointercancel",i=>this._onPointerEnd(i)),this.element.appendChild(this._handle),this._headerSlot=de.el("div",{className:"drawer-header"}),a&&this._headerSlot.appendChild(a),this.element.appendChild(this._headerSlot),this._body=de.el("div",{className:"drawer-body"}),t&&this._body.appendChild(t),this.element.appendChild(this._body),this.element}updateContainerHeight(a){this._containerHeight=Math.max(0,Number(a)||0),this._applySnap(this._snap,{animate:!1})}snapTo(a,t={}){Zo.includes(a)&&this._applySnap(a,{animate:t.animate!==!1})}get snap(){return this._snap}setBodyContent(a){this._body&&(this._body.innerHTML="",a&&this._body.appendChild(a))}setHeaderContent(a){this._headerSlot&&(this._headerSlot.innerHTML="",a&&this._headerSlot.appendChild(a))}_onPointerDown(a){var t,n,i;if(!(a.button!==void 0&&a.button!==0)){this._dragging=!0,this._wasDragging=!1,this._dragPointerId=a.pointerId,this._dragStartY=a.clientY,this._dragStartHeight=((t=this.element)==null?void 0:t.offsetHeight)||0;try{(i=(n=this._handle)==null?void 0:n.setPointerCapture)==null||i.call(n,a.pointerId)}catch{}this.element&&(this.element.style.transition="none")}}_onPointerMove(a){if(!this._dragging||a.pointerId!==this._dragPointerId)return;const t=a.clientY-this._dragStartY,n=this._dragStartHeight-t;this._containerHeight||window.innerHeight;const i=this._heightForSnap("collapsed"),r=this._heightForSnap("full"),l=Math.max(i,Math.min(r,n));this.element&&(this.element.style.height=`${l}px`),Math.abs(t)>4&&(this._wasDragging=!0),a.preventDefault()}_onPointerEnd(a){var i,r,l;if(!this._dragging)return;this._dragging=!1;try{(r=(i=this._handle)==null?void 0:i.releasePointerCapture)==null||r.call(i,a.pointerId)}catch{}this._dragPointerId=null;const t=((l=this.element)==null?void 0:l.offsetHeight)||0,n=this._nearestSnap(t);this._applySnap(n,{animate:!0})}_cycleSnap(){const a=Zo.indexOf(this._snap),t=Zo[(a+1)%Zo.length];this._applySnap(t,{animate:!0})}_heightForSnap(a){const t=this._containerHeight||window.innerHeight||600;switch(a){case"collapsed":return 80;case"half":return Math.round(t*.45);case"full":return Math.round(t*.85);default:return Math.round(t*.45)}}_nearestSnap(a){let t=Zo[0],n=1/0;for(const i of Zo){const r=this._heightForSnap(i),l=Math.abs(r-a);l<n&&(n=l,t=i)}return t}_applySnap(a,{animate:t}){var r,l;if(!this.element)return;const n=this._snap;this._snap=a;const i=typeof window<"u"&&((r=window.matchMedia)==null?void 0:r.call(window,"(prefers-reduced-motion: reduce)").matches);t&&!i?this.element.style.transition="height 0.25s cubic-bezier(0.33, 1, 0.68, 1)":this.element.style.transition="none",this.element.style.height=`${this._heightForSnap(a)}px`,this.element.dataset.snap=a,this._handle&&this._handle.setAttribute("aria-expanded",a==="full"?"true":"false"),a!==n&&((l=this._onSnapChange)==null||l.call(this,a,n))}destroy(){var a;(a=this.element)==null||a.remove(),this.element=null,this._handle=null,this._body=null,this._headerSlot=null}}const $h=[{id:"warm",label:"Warm",ariaLabel:"Apply warm gradient background",style:"linear-gradient(135deg, #101820 0%, #f2aa4c 100%)",fill:{gradientType:"linear",angle:135,stops:[{offset:0,color:"#101820"},{offset:1,color:"#f2aa4c"}]}},{id:"cool",label:"Cool",ariaLabel:"Apply cool gradient background",style:"linear-gradient(135deg, #0f766e 0%, #38bdf8 100%)",fill:{gradientType:"linear",angle:135,stops:[{offset:0,color:"#0f766e"},{offset:1,color:"#38bdf8"}]}},{id:"neutral",label:"Neutral",ariaLabel:"Apply neutral gradient background",style:"linear-gradient(135deg, #27272a 0%, #d4d4d8 100%)",fill:{gradientType:"linear",angle:135,stops:[{offset:0,color:"#27272a"},{offset:1,color:"#d4d4d8"}]}}];class mm{constructor(a,t){this.state=a,this.editor=t,this.element=null,this._errorMessage=null,this._unsubscribers=[]}render(){return this.element=de.el("div",{className:"background-panel","data-testid":"v2-background-panel"}),this._render(),this._unsubscribers.push(this.state.on("change:layers",()=>this._render())),this.element}_render(){var f,h,v;if(!this.element)return;this.element.innerHTML="";const a=this._backgroundLayer(),t=a!=null&&a.fill&&typeof a.fill=="object"?a.fill:{kind:"transparent"},n=typeof t.fit=="string"?t.fit:"cover",i=this._backgroundBlur(a),r=(a==null?void 0:a.locked)===!0,l=t.kind==="color"&&typeof t.value=="string"?t.value:"#ffffff";this.element.appendChild(de.el("div",{className:"panel-section-title"},de.el("span",{},"Background"))),this._errorMessage&&this.element.appendChild(de.el("p",{className:"background-panel-error",role:"alert","data-testid":"v2-background-error"},this._errorMessage));const s=de.el("input",{type:"color",className:"color-input",value:l,disabled:r?"disabled":void 0,"aria-label":"Background color","data-testid":"v2-background-color",onInput:y=>{this._runAction(this.editor.setBackgroundColor(y.target.value))}});this.element.appendChild(this._field("Color",s));const d=de.el("div",{className:"background-gradient-grid"});for(const y of $h){const w=de.el("button",{type:"button",className:"background-gradient-swatch",style:{background:y.style},"aria-label":y.ariaLabel,disabled:r?"disabled":void 0,"data-testid":`v2-background-gradient-${y.id}`,onClick:()=>{this._runAction(this.editor.setBackgroundGradient(y.fill))}},de.el("span",{className:"background-gradient-label"},y.label));d.appendChild(w)}this.element.appendChild(this._field("Gradient",d));const c=de.el("input",{type:"file",accept:"image/*",className:"background-upload-input",disabled:r?"disabled":void 0,"aria-label":"Upload background image","data-testid":"v2-background-upload",onChange:y=>{var _;const w=(_=y.target.files)==null?void 0:_[0];w&&this._runAction(this.editor.setBackgroundImageFromFile(w,{fit:n})),y.target.value=""}});this.element.appendChild(this._field("Upload",c));const u=(v=(h=(f=this.editor)==null?void 0:f._options)==null?void 0:h.backgroundReplacement)==null?void 0:v.mediaChoices;if(Array.isArray(u)&&u.length>0){const y=de.el("div",{className:"background-media-grid"});for(const w of u)w!=null&&w.source&&y.appendChild(de.el("button",{type:"button",className:"background-media-choice","aria-label":`Use ${w.label||"media"} as background`,disabled:r?"disabled":void 0,"data-testid":`v2-background-media-${w.id||w.source.mediaUuid||"choice"}`,onClick:()=>{this._runAction(this.editor.setBackgroundMediaSource(w.source,{fit:w.fit||n}))}},w.label||"Media"));this.element.appendChild(this._field("Media",y))}const m=de.el("select",{className:"select-input",disabled:r?"disabled":void 0,"aria-label":"Background image fit","data-testid":"v2-background-fit",onChange:y=>{this._runAction(this.editor.setBackgroundFit(y.target.value))}},this._option("cover","Cover",n),this._option("contain","Contain",n),this._option("stretch","Stretch",n),this._option("tile","Tile",n));this.element.appendChild(this._field("Fit",m));const p=de.el("input",{type:"range",min:"0",max:"40",step:"1",value:String(i),className:"range-input",disabled:r?"disabled":void 0,"aria-label":"Background blur","data-testid":"v2-background-blur",onInput:y=>{this._runAction(this.editor.setBackgroundBlur(Number(y.target.value)))}});this.element.appendChild(this._field("Blur",p)),this.element.appendChild(de.el("button",{type:"button",className:"btn btn-secondary background-remove-btn","aria-label":"Remove background layer",disabled:r?"disabled":void 0,"data-testid":"v2-background-remove",onClick:()=>{this._runAction(this.editor.removeBackgroundLayer())}},"Remove"))}_runAction(a){this._errorMessage=null,Promise.resolve(a).catch(t=>{var i,r;const n=t instanceof Error?t:new Error(String(t));this._errorMessage=n.message||"Background update failed",(r=(i=this.editor)==null?void 0:i.emit)==null||r.call(i,"error",n),this._render()})}_field(a,t){return de.el("label",{className:"background-field"},de.el("span",{className:"background-field-label"},a),t)}_option(a,t,n){return de.el("option",{value:a,selected:n===a?"selected":void 0},t)}_backgroundLayer(){const a=this.state.get("layers");return Array.isArray(a)?a.find(t=>(t==null?void 0:t.type)==="background"||(t==null?void 0:t.role)==="background")??null:null}_backgroundBlur(a){var r;const n=(Array.isArray(a==null?void 0:a.effects)?a.effects:[]).find(l=>(l==null?void 0:l.id)==="background-blur"),i=Number((r=n==null?void 0:n.params)==null?void 0:r.amount);return Number.isFinite(i)?i:0}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}class pm{constructor(a,t){this.state=a,this.editor=t,this.element=null,this._listEl=null,this._unsubscribers=[]}render(){return this.element=de.el("section",{className:"layer-stack-panel",role:"region","aria-label":"Layers","data-order":"bottom-to-top","data-testid":"v2-layer-stack-panel"}),this.element.appendChild(de.el("div",{className:"layer-stack-header"},de.el("span",{className:"layer-stack-title"},"Layers"),de.el("span",{className:"layer-stack-order"},"Bottom to top"))),this._listEl=de.el("div",{className:"layer-stack-list",role:"listbox","aria-label":"Layer order, bottom to top"}),this.element.appendChild(this._listEl),this._renderRows(),this._unsubscribers.push(this.state.on("change:layers",()=>this._renderRows()),this.state.on("change:activeLayerId",()=>this._renderRows())),this.element}_layers(){const a=this.state.get("layers");return Array.isArray(a)?a:[]}_renderRows(){if(!this._listEl)return;this._listEl.innerHTML="";const a=this._layers();if(!a.length){this._listEl.appendChild(de.el("div",{className:"layer-stack-empty",role:"status"},"No layers"));return}a.forEach((t,n)=>{this._listEl.appendChild(this._row(t,n,a.length))})}_row(a,t,n){const i=String((a==null?void 0:a.id)??""),r=this._layerName(a),l=(a==null?void 0:a.visible)!==!1,s=(a==null?void 0:a.locked)===!0,d=this.state.get("activeLayerId")===i,c=[d?"active":null,l?"visible":"hidden",s?"locked":"unlocked"].filter(Boolean).join(", "),u=de.el("div",{className:`layer-row${d?" active":""}${l?"":" hidden"}${s?" locked":""}`,role:"option","aria-selected":d?"true":"false","aria-label":`${r}, ${this._layerTypeLabel(a)}, ${c}`,"data-layer-id":i,"data-testid":`v2-layer-row-${i}`});u.appendChild(this._button({testId:`v2-layer-select-${i}`,label:`Select ${r}`,className:"layer-row-select",onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).selectLayer)==null?void 0:f.call(p,i)})},this._thumbnail(a))),u.appendChild(de.el("div",{className:"layer-row-main"},de.el("span",{className:"layer-row-name"},r),de.el("span",{className:"layer-row-meta"},this._layerTypeLabel(a))));const m=de.el("div",{className:"layer-row-actions"});return m.appendChild(this._iconButton({testId:`v2-layer-${l?"hide":"show"}-${i}`,label:`${l?"Hide":"Show"} ${r}`,icon:l?de.eye:de.eyeOff,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).setLayerVisibility)==null?void 0:f.call(p,i,!l)})})),m.appendChild(this._iconButton({testId:`v2-layer-${s?"unlock":"lock"}-${i}`,label:`${s?"Unlock":"Lock"} ${r}`,icon:s?de.lockClosed:de.lockOpen,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).setLayerLocked)==null?void 0:f.call(p,i,!s)})})),m.appendChild(this._iconButton({testId:`v2-layer-move-up-${i}`,label:`Move ${r} up`,icon:de.chevronRight,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).moveLayer)==null?void 0:f.call(p,i,"up")})})),m.appendChild(this._iconButton({testId:`v2-layer-move-down-${i}`,label:`Move ${r} down`,icon:de.chevronLeft,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).moveLayer)==null?void 0:f.call(p,i,"down")})})),m.appendChild(this._iconButton({testId:`v2-layer-bring-front-${i}`,label:`Bring ${r} to front`,icon:de.chevronRight,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).moveLayer)==null?void 0:f.call(p,i,"front")})})),m.appendChild(this._iconButton({testId:`v2-layer-send-back-${i}`,label:`Send ${r} to back`,icon:de.chevronLeft,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).moveLayer)==null?void 0:f.call(p,i,"back")})})),m.appendChild(this._iconButton({testId:`v2-layer-rename-${i}`,label:`Rename ${r}`,icon:de.pencil,disabled:s,onClick:()=>this._renameLayer(i,r)})),m.appendChild(this._iconButton({testId:`v2-layer-duplicate-${i}`,label:`Duplicate ${r}`,icon:de.duplicate,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).duplicateLayer)==null?void 0:f.call(p,i)})})),m.appendChild(this._iconButton({testId:`v2-layer-delete-${i}`,label:`Delete ${r}`,icon:de.trash,disabled:s||n<=1,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).deleteLayer)==null?void 0:f.call(p,i)})})),u.appendChild(m),u}_thumbnail(a){const t=de.el("span",{className:"layer-thumb","aria-hidden":"true"}),n=a==null?void 0:a.fill;if((n==null?void 0:n.kind)==="color")t.style.background=n.value||n.color||"#ffffff";else if((n==null?void 0:n.kind)==="gradient"&&Array.isArray(n.stops)){const i=n.stops.map(r=>`${r.color} ${Math.round(Number(r.offset||0)*100)}%`).join(", ");t.style.background=`linear-gradient(${Number(n.angle||135)}deg, ${i})`}else t.innerHTML=(a==null?void 0:a.type)==="background"?de.layers:de.move;return t}_button({testId:a,label:t,...n},i){const r=de.el("button",{type:"button","aria-label":t,"data-testid":a,...n});return i&&r.appendChild(i),r}_iconButton({testId:a,label:t,icon:n,disabled:i=!1,onClick:r}){const l=de.el("button",{type:"button",className:"layer-action-btn","aria-label":t,title:t,disabled:i?"disabled":void 0,"data-testid":a,onClick:r});return l.innerHTML=n,l}_renameLayer(a,t){var i;const n=(i=window.prompt)==null?void 0:i.call(window,"Layer name",t);typeof n=="string"&&this._runAction(()=>{var r,l;return(l=(r=this.editor).renameLayer)==null?void 0:l.call(r,a,n)})}_runAction(a){var t,n;try{Promise.resolve(a()).catch(i=>{var r,l;return(l=(r=this.editor).emit)==null?void 0:l.call(r,"error",{error:i,context:"layer-stack"})})}catch(i){(n=(t=this.editor).emit)==null||n.call(t,"error",{error:i,context:"layer-stack"})}}_layerName(a){return(typeof(a==null?void 0:a.name)=="string"?a.name.trim():"")||"Layer"}_layerTypeLabel(a){return(a==null?void 0:a.type)==="background"||(a==null?void 0:a.role)==="background"?"Background":(a==null?void 0:a.role)==="subject"?"Subject":(a==null?void 0:a.type)==="text"?"Text":"Image"}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null,this._listEl=null}}const Fh=[{value:"400",label:"Regular"},{value:"500",label:"Medium"},{value:"600",label:"Semibold"},{value:"700",label:"Bold"},{value:"800",label:"Heavy"}],Dh=[{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}],Ah=[{value:"normal",label:"Normal"},{value:"multiply",label:"Multiply"},{value:"screen",label:"Screen"},{value:"overlay",label:"Overlay"}],vr={stroke:{enabled:!1,color:"#000000",width:0},shadow:{enabled:!1,color:"#000000",alpha:.5,blur:0,distance:0,angle:45},glow:{enabled:!1,color:"#ffffff",alpha:.5,blur:0},backdrop:{enabled:!1,color:"#000000",opacity:.5,padding:0,radius:0,blur:0}};class fm{constructor(a,t){this.state=a,this.editor=t,this.element=null,this._errorMessage=null,this._unsubscribers=[]}render(){return this.element=de.el("div",{className:"text-panel","data-testid":"v2-text-panel"}),this._render(),this._unsubscribers.push(this.state.on("change:layers",()=>this._render()),this.state.on("change:activeLayerId",()=>this._render())),this.element}_render(){if(!this.element)return;this.element.innerHTML="";const a=this._activeTextLayer(),t=(a==null?void 0:a.locked)===!0;if(this.element.appendChild(de.el("div",{className:"text-panel-header"},de.el("div",{className:"panel-section-title"},de.el("span",{},"Text")),de.el("button",{type:"button",className:"btn btn-secondary","data-testid":"v2-text-add",onClick:()=>{var d,c;return this._runAction((c=(d=this.editor).addTextLayer)==null?void 0:c.call(d))}},"Add text"))),this._errorMessage&&this.element.appendChild(de.el("p",{className:"text-panel-error",role:"alert","data-testid":"v2-text-error"},this._errorMessage)),!a){this.element.appendChild(de.el("p",{className:"text-panel-empty"},"Select or add a text layer."));return}const n=a.text&&typeof a.text=="object"?a.text:{},i=n.style&&typeof n.style=="object"?n.style:{},r=n.box&&typeof n.box=="object"?n.box:{},l=a.transform&&typeof a.transform=="object"?a.transform:{},s=this._textEffects(n.effects);this.element.appendChild(this._contentControl(a.id,n.content??"",t)),this.element.appendChild(this._controlGrid([this._numberField({label:"Opacity",testId:"v2-text-opacity",value:a.opacity??1,min:0,max:1,step:.05,disabled:t,onInput:d=>{var c,u;return this._runAction((u=(c=this.editor).updateTextLayer)==null?void 0:u.call(c,a.id,{opacity:d}))}}),this._selectField({label:"Blend",testId:"v2-text-blend-mode",value:a.blendMode||"normal",options:Ah,disabled:t,onChange:d=>{var c,u;return this._runAction((u=(c=this.editor).updateTextLayer)==null?void 0:u.call(c,a.id,{blendMode:d}))}})])),this.element.appendChild(this._selectField({label:"Font",testId:"v2-text-font-family",value:i.fontFamily||"Inter",options:la.TEXT_LAYER_FONT_FAMILIES.map(d=>({value:d,label:d})),disabled:t,onChange:d=>this._updateStyle(a.id,{fontFamily:d})})),this.element.appendChild(this._controlGrid([this._numberField({label:"Size",testId:"v2-text-font-size",value:i.fontSize??64,min:8,max:400,step:1,disabled:t,onInput:d=>this._updateStyle(a.id,{fontSize:d})}),this._selectField({label:"Weight",testId:"v2-text-font-weight",value:String(i.fontWeight??700),options:Fh,disabled:t,onChange:d=>this._updateStyle(a.id,{fontWeight:Number(d)})}),this._selectField({label:"Style",testId:"v2-text-font-style",value:i.fontStyle||"normal",options:[{value:"normal",label:"Normal"},{value:"italic",label:"Italic"}],disabled:t,onChange:d=>this._updateStyle(a.id,{fontStyle:d})}),this._selectField({label:"Align",testId:"v2-text-align",value:i.align||"center",options:Dh,disabled:t,onChange:d=>this._updateStyle(a.id,{align:d})})])),this.element.appendChild(this._controlGrid([this._colorField({label:"Fill",testId:"v2-text-fill",value:i.fill||"#ffffff",disabled:t,onInput:d=>this._updateStyle(a.id,{fill:d})}),this._numberField({label:"Line",testId:"v2-text-line-height",value:i.lineHeight??1.2,min:.8,max:3,step:.05,disabled:t,onInput:d=>this._updateStyle(a.id,{lineHeight:d})}),this._numberField({label:"Track",testId:"v2-text-letter-spacing",value:i.letterSpacing??0,min:-100,max:100,step:.5,disabled:t,onInput:d=>this._updateStyle(a.id,{letterSpacing:d})})])),this.element.appendChild(this._controlGrid([this._numberField({label:"X",testId:"v2-text-box-x",value:r.x??.2,min:0,max:1,step:.01,disabled:t,onInput:d=>this._updateBox(a.id,{x:d})}),this._numberField({label:"Y",testId:"v2-text-box-y",value:r.y??.2,min:0,max:1,step:.01,disabled:t,onInput:d=>this._updateBox(a.id,{y:d})}),this._numberField({label:"W",testId:"v2-text-box-width",value:r.width??.6,min:.05,max:1,step:.01,disabled:t,onInput:d=>this._updateBox(a.id,{width:d})}),this._numberField({label:"H",testId:"v2-text-box-height",value:r.height??.18,min:.05,max:1,step:.01,disabled:t,onInput:d=>this._updateBox(a.id,{height:d})}),this._numberField({label:"Rotate",testId:"v2-text-rotation",value:l.rotation??0,min:0,max:360,step:1,disabled:t,onInput:d=>{var c,u;return this._runAction((u=(c=this.editor).updateTextLayer)==null?void 0:u.call(c,a.id,{transform:{rotation:d}}))}})])),this.element.appendChild(this._effectSection("Stroke",[this._checkboxField({label:"Stroke",testId:"v2-text-stroke-enabled",checked:s.stroke.enabled,disabled:t,onChange:d=>this._updateEffects(a.id,{stroke:{enabled:d}})}),this._colorField({label:"Stroke Color",testId:"v2-text-stroke-color",value:s.stroke.color,disabled:t,onInput:d=>this._updateEffects(a.id,{stroke:{color:d}})}),this._numberField({label:"Stroke Width",testId:"v2-text-stroke-width",value:s.stroke.width,min:0,max:80,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{stroke:{width:d}})})])),this.element.appendChild(this._effectSection("Shadow",[this._checkboxField({label:"Shadow",testId:"v2-text-shadow-enabled",checked:s.shadow.enabled,disabled:t,onChange:d=>this._updateEffects(a.id,{shadow:{enabled:d}})}),this._colorField({label:"Shadow Color",testId:"v2-text-shadow-color",value:s.shadow.color,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{color:d}})}),this._numberField({label:"Shadow Alpha",testId:"v2-text-shadow-alpha",value:s.shadow.alpha,min:0,max:1,step:.05,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{alpha:d}})}),this._numberField({label:"Shadow Blur",testId:"v2-text-shadow-blur",value:s.shadow.blur,min:0,max:120,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{blur:d}})}),this._numberField({label:"Shadow Distance",testId:"v2-text-shadow-distance",value:s.shadow.distance,min:0,max:200,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{distance:d}})}),this._numberField({label:"Shadow Angle",testId:"v2-text-shadow-angle",value:s.shadow.angle,min:0,max:360,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{angle:d}})})])),this.element.appendChild(this._effectSection("Glow",[this._checkboxField({label:"Glow",testId:"v2-text-glow-enabled",checked:s.glow.enabled,disabled:t,onChange:d=>this._updateEffects(a.id,{glow:{enabled:d}})}),this._colorField({label:"Glow Color",testId:"v2-text-glow-color",value:s.glow.color,disabled:t,onInput:d=>this._updateEffects(a.id,{glow:{color:d}})}),this._numberField({label:"Glow Alpha",testId:"v2-text-glow-alpha",value:s.glow.alpha,min:0,max:1,step:.05,disabled:t,onInput:d=>this._updateEffects(a.id,{glow:{alpha:d}})}),this._numberField({label:"Glow Blur",testId:"v2-text-glow-blur",value:s.glow.blur,min:0,max:120,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{glow:{blur:d}})})])),this.element.appendChild(this._effectSection("Backdrop",[this._checkboxField({label:"Backdrop",testId:"v2-text-backdrop-enabled",checked:s.backdrop.enabled,disabled:t,onChange:d=>this._updateEffects(a.id,{backdrop:{enabled:d}})}),this._colorField({label:"Backdrop Color",testId:"v2-text-backdrop-color",value:s.backdrop.color,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{color:d}})}),this._numberField({label:"Backdrop Opacity",testId:"v2-text-backdrop-opacity",value:s.backdrop.opacity,min:0,max:1,step:.05,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{opacity:d}})}),this._numberField({label:"Backdrop Padding",testId:"v2-text-backdrop-padding",value:s.backdrop.padding,min:0,max:200,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{padding:d}})}),this._numberField({label:"Backdrop Radius",testId:"v2-text-backdrop-radius",value:s.backdrop.radius,min:0,max:200,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{radius:d}})}),this._numberField({label:"Backdrop Blur",testId:"v2-text-backdrop-blur",value:s.backdrop.blur,min:0,max:80,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{blur:d}})})]))}_contentControl(a,t,n){const i=de.el("div",{className:"text-field text-content-field"});i.appendChild(de.el("label",{className:"text-field-label",for:"v2-text-content"},"Content"));let r=t==null?"":String(t);const l=de.el("textarea",{id:"v2-text-content",className:"text-area-input",rows:"4",disabled:n?"disabled":void 0,"data-testid":"v2-text-content",onInput:d=>{r=d.target.value},onBlur:()=>{var d,c;r!==t&&this._runAction((c=(d=this.editor).updateTextLayer)==null?void 0:c.call(d,a,{content:r}))},onKeyDown:d=>{var c,u;if(d.key==="Escape"){d.preventDefault(),r=t==null?"":String(t),l.value=r,l.blur();return}d.key==="Enter"&&(d.metaKey||d.ctrlKey)&&(d.preventDefault(),this._runAction((u=(c=this.editor).updateTextLayer)==null?void 0:u.call(c,a,{content:r})),l.blur())}});l.value=r,i.appendChild(l);const s=de.el("div",{className:"text-content-actions"});return s.appendChild(de.el("button",{type:"button",className:"btn btn-text",disabled:n?"disabled":void 0,"data-testid":"v2-text-cancel",onClick:()=>{r=t==null?"":String(t),l.value=r}},"Cancel")),s.appendChild(de.el("button",{type:"button",className:"btn btn-secondary",disabled:n?"disabled":void 0,"data-testid":"v2-text-commit",onClick:()=>{var d,c;return this._runAction((c=(d=this.editor).updateTextLayer)==null?void 0:c.call(d,a,{content:r}))}},"Commit")),i.appendChild(s),i}_controlGrid(a){const t=de.el("div",{className:"text-control-grid"});for(const n of a)t.appendChild(n);return t}_effectSection(a,t){return de.el("div",{className:"text-effect-section"},de.el("div",{className:"text-effect-title"},a),this._controlGrid(t))}_selectField({label:a,testId:t,value:n,options:i,disabled:r,onChange:l}){const s=de.el("select",{className:"select-input",disabled:r?"disabled":void 0,"data-testid":t,onChange:d=>l(d.target.value)});for(const d of i)s.appendChild(de.el("option",{value:d.value,selected:String(n)===String(d.value)?"selected":void 0},d.label));return this._field(a,s)}_numberField({label:a,testId:t,value:n,min:i,max:r,step:l,disabled:s,onInput:d}){const c=de.el("input",{type:"number",className:"text-number-input",min:String(i),max:String(r),step:String(l),value:String(n),disabled:s?"disabled":void 0,"data-testid":t,onInput:u=>d(Number(u.target.value))});return this._field(a,c)}_colorField({label:a,testId:t,value:n,disabled:i,onInput:r}){const l=de.el("input",{type:"color",className:"color-input",value:n,disabled:i?"disabled":void 0,"data-testid":t,onInput:s=>r(s.target.value)});return this._field(a,l)}_checkboxField({label:a,testId:t,checked:n,disabled:i,onChange:r}){const l=de.el("input",{type:"checkbox",className:"text-checkbox-input",checked:n?"checked":void 0,disabled:i?"disabled":void 0,"data-testid":t,onChange:s=>r(s.target.checked===!0)});return de.el("label",{className:"text-field text-checkbox-field"},de.el("span",{className:"text-field-label"},a),l)}_field(a,t){return de.el("label",{className:"text-field"},de.el("span",{className:"text-field-label"},a),t)}_updateStyle(a,t){var n,i;this._runAction((i=(n=this.editor).updateTextLayer)==null?void 0:i.call(n,a,{style:t}))}_updateBox(a,t){var n,i;this._runAction((i=(n=this.editor).updateTextLayer)==null?void 0:i.call(n,a,{box:t}))}_updateEffects(a,t){var n,i;this._runAction((i=(n=this.editor).updateTextLayer)==null?void 0:i.call(n,a,{effects:t}))}_textEffects(a){const t=a&&typeof a=="object"?a:{};return{stroke:{...vr.stroke,...t.stroke&&typeof t.stroke=="object"?t.stroke:{}},shadow:{...vr.shadow,...t.shadow&&typeof t.shadow=="object"?t.shadow:{}},glow:{...vr.glow,...t.glow&&typeof t.glow=="object"?t.glow:{}},backdrop:{...vr.backdrop,...t.backdrop&&typeof t.backdrop=="object"?t.backdrop:{}}}}_runAction(a){this._errorMessage=null,Promise.resolve(a).catch(t=>{var i,r;const n=t instanceof Error?t:new Error(String(t));this._errorMessage=n.message||"Text update failed",(r=(i=this.editor)==null?void 0:i.emit)==null||r.call(i,"error",n),this._render()})}_activeTextLayer(){const a=this.state.get("activeLayerId"),t=this.state.get("layers");return!a||!Array.isArray(t)?null:t.find(n=>(n==null?void 0:n.id)===a&&(n.type==="text"||n.role==="text"))??null}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}class Rh{constructor(a,t,n){this.state=a,this.filterManager=t,this.editor=n,this.element=null,this._headerEl=null,this._bodyEl=null,this._view="categories",this._onNavigate=null,this._callbacks=null,this._unsubscribers=[],this._categoryTabs=null,this._filterListView=null,this._filterControlsView=null,this._backgroundPanel=null,this._layerStackPanel=null,this._textPanel=null}build(a){return this._callbacks=a,this._onNavigate=a.onViewChange||null,this.element=de.el("div",{className:"drawer-nav","data-testid":"v2-mobile-nav"}),this._headerEl=de.el("div",{className:"drawer-nav-header"}),this.element.appendChild(this._headerEl),this._bodyEl=de.el("div",{className:"drawer-nav-body"}),this.element.appendChild(this._bodyEl),this._buildViews(),this._unsubscribers.push(this.state.on("change:selectedFilter",({value:t})=>{t&&this._view!=="controls"&&this.navigateTo("controls")}),this.state.on("change:selectedCategory",()=>{}),this.state.on("change:mode",({value:t})=>{t==="filters"&&this._view!=="categories"&&!this.state.get("selectedFilter")&&this.navigateTo("categories")})),this.navigateTo("categories"),this.element}_buildViews(){this._categoryTabs=new dm(this.state,this.editor),this._categoryTabsEl=this._categoryTabs.render({onSelect:a=>{if(a==="background"||a==="layers"||a==="text"){this.navigateTo(a);return}this.navigateTo("filters")}}),this._filterListView=new cm(this.state,this.filterManager),this._filterListEl=this._filterListView.render({onToggle:(a,t,n)=>this._callbacks.onFilterToggle(a,t,n),onSelect:(a,t)=>{this._callbacks.onFilterSelect(a,t),this.navigateTo("controls")}}),this._filterControlsView=new um(this.state,this.filterManager),this._filterControlsEl=this._filterControlsView.render({onChange:(a,t,n,i)=>this._callbacks.onFilterChange(a,t,n,i),onReset:(a,t)=>this._callbacks.onFilterReset(a,t),onAction:(a,t,n)=>this._callbacks.onFilterAction(a,t,n)}),this._backgroundPanel=new mm(this.state,this.editor),this._backgroundPanelEl=this._backgroundPanel.render(),this._layerStackPanel=new pm(this.state,this.editor),this._layerStackPanelEl=this._layerStackPanel.render(),this._textPanel=new fm(this.state,this.editor),this._textPanelEl=this._textPanel.render()}navigateTo(a){var n;if(!this.element)return;this._view=a,this._renderHeader(),this._bodyEl.innerHTML="";let t=null;switch(a){case"categories":t=this._categoryTabsEl;break;case"filters":t=this._filterListEl;break;case"controls":t=this._filterControlsEl;break;case"background":t=this._backgroundPanelEl;break;case"layers":t=this._layerStackPanelEl;break;case"text":t=this._textPanelEl;break;default:t=this._categoryTabsEl}t&&this._bodyEl.appendChild(t),(n=this._onNavigate)==null||n.call(this,a)}_renderHeader(){if(!this._headerEl)return;if(this._headerEl.innerHTML="",this._view!=="categories"){const n=de.el("button",{type:"button",className:"drawer-back-btn","aria-label":"Go back","data-testid":"v2-drawer-back",onClick:()=>this._goBack()});n.innerHTML=de.chevronLeft,this._headerEl.appendChild(n)}const t=this._titleForView(this._view);if(this._headerEl.appendChild(de.el("h2",{className:"drawer-nav-title"},t)),this._view==="controls"){const n=this.state.get("selectedFilter");if(n){const i=this._activeFilterLayerId();this._headerEl.appendChild(de.createButton({label:"Reset",className:"btn-text",onClick:()=>this._callbacks.onFilterReset(n,i)}))}}}_activeFilterLayerId(){return typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId")}_titleForView(a){switch(a){case"categories":return"Filters";case"filters":{const t=this.state.get("selectedCategory");return this._categoryLabel(t)||"Filters"}case"background":return"Background";case"layers":return"Layers";case"text":return"Text";case"controls":{const t=this.state.get("selectedFilter"),n=t?this.filterManager.getFilterDef(t):null;return(n==null?void 0:n.name)||"Filter"}default:return""}}_categoryLabel(a){var t;return a&&((t=de.EDITOR_CATEGORIES.find(n=>n.id===a))==null?void 0:t.name)||null}_goBack(){this._view==="controls"?(this.state.set("selectedFilter",null),this.navigateTo("filters")):(this._view==="filters"||this._view==="background"||this._view==="layers"||this._view==="text")&&this.navigateTo("categories")}get currentView(){return this._view}destroy(){var a,t,n,i,r,l,s;this._unsubscribers.forEach(d=>d()),this._unsubscribers=[],(a=this._categoryTabs)==null||a.destroy(),(t=this._filterListView)==null||t.destroy(),(n=this._filterControlsView)==null||n.destroy(),(i=this._backgroundPanel)==null||i.destroy(),(r=this._layerStackPanel)==null||r.destroy(),(l=this._textPanel)==null||l.destroy(),(s=this.element)==null||s.remove(),this.element=null}}class Lh{constructor(a,t){this.state=a,this.filterManager=t,this.element=null,this._onSelect=null,this._onRemove=null,this._unsubscribers=[]}render({onSelect:a,onRemove:t}={}){return this._onSelect=a,this._onRemove=t,this.element=de.el("div",{className:"mobile-active-chips",role:"region","aria-label":"Active filters","data-testid":"v2-mobile-active-chips"}),this._renderChips(),this._unsubscribers.push(this.state.on("change:activeFilters",()=>this._renderChips()),this.state.on("change:selectedFilter",()=>this._refreshSelection())),this.element}_renderChips(){this.element.innerHTML="";const a=this.state.get("activeFilters");if(((a==null?void 0:a.size)??0)===0){this.element.style.display="none";return}this.element.style.display="";const n=de.el("div",{className:"mobile-active-track"}),i=this.state.get("selectedFilter"),r=this._activeFilterLayerId();for(const l of a){const s=this.filterManager.getFilterDef(l);s&&n.appendChild(this._renderChip(s,l===i,r))}this.element.appendChild(n)}_renderChip(a,t,n=null){const i=de.el("div",{className:`mobile-active-chip ${t?"selected":""}`,"data-filter":a.id,"data-testid":`v2-mobile-chip-${a.id}`});i.appendChild(de.el("button",{type:"button",className:"mobile-active-chip-name","aria-label":`Edit ${a.name}`,onClick:()=>{var l;return(l=this._onSelect)==null?void 0:l.call(this,a.id,n)}},a.name));const r=de.el("button",{type:"button",className:"mobile-active-chip-remove","aria-label":`Remove ${a.name}`,"data-testid":`v2-mobile-chip-remove-${a.id}`,onClick:l=>{var s;l.stopPropagation(),(s=this._onRemove)==null||s.call(this,a.id,n)}});return r.innerHTML=de.close,i.appendChild(r),i}_activeFilterLayerId(){return typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId")}_refreshSelection(){var n;const a=this.state.get("selectedFilter"),t=(n=this.element)==null?void 0:n.querySelectorAll(".mobile-active-chip");t==null||t.forEach(i=>{const r=i.getAttribute("data-filter");i.classList.toggle("selected",r===a)})}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}const gc="(max-width: 900px)";let Ph=class{constructor(a,t,n){this.state=a,this.filterManager=t,this.editor=n,this.root=null,this.canvasSection=null,this.canvasContainer=null,this.cropOverlay=null,this._callbacks=null,this._isMobile=!1,this._panel=null,this._categoryTabs=null,this._filterListView=null,this._filterControlsView=null,this._activeStack=null,this._backgroundPanel=null,this._layerStackPanel=null,this._textPanel=null,this._desktopBackgroundSection=null,this._desktopLayerSection=null,this._desktopTextSection=null,this._desktopFilterListSection=null,this._desktopCropWrapper=null,this._mobileChips=null,this._mobileDrawer=null,this._mobileNav=null,this._mobileCropWrapper=null,this._cropControlsEl=null,this._unsubscribers=[],this._mql=null,this._mqlHandler=null,this._resizeObserver=null}build(a){var t;return this._callbacks=a,this.root=de.el("div",{className:"editor-v2-body"}),this.canvasSection=de.el("div",{className:"editor-v2-canvas"}),this.canvasContainer=de.el("div",{className:"canvas-container"}),this.cropOverlay=de.el("canvas",{className:"crop-overlay","aria-hidden":"true"}),this.canvasSection.appendChild(this.canvasContainer),this.canvasSection.appendChild(this.cropOverlay),this._zoomOverlay=this._buildCanvasZoomOverlay(),this.canvasSection.appendChild(this._zoomOverlay),this.root.appendChild(this.canvasSection),this._isMobile=typeof window<"u"&&((t=window.matchMedia)==null?void 0:t.call(window,gc).matches)===!0,this._isMobile?this._buildMobileShell():this._buildDesktopShell(),typeof window<"u"&&window.matchMedia&&(this._mql=window.matchMedia(gc),this._mqlHandler=n=>this._handleBreakpointChange(n.matches),this._mql.addEventListener?this._mql.addEventListener("change",this._mqlHandler):this._mql.addListener&&this._mql.addListener(this._mqlHandler)),this._unsubscribers.push(this.state.on("change:mode",({value:n})=>this._applyMode(n)),this.state.on("change:selectedCategory",()=>this._applyMode(this.state.get("mode")))),{root:this.root,canvasContainer:this.canvasContainer,cropOverlay:this.cropOverlay}}mountCropControls(a){this._cropControlsEl=a,this._mountCropControlsInActiveShell()}_buildDesktopShell(){this._panel=de.el("div",{className:"editor-v2-panel","data-testid":"v2-inspector-panel"}),this._categoryTabs=new dm(this.state,this.editor),this._panel.appendChild(this._categoryTabs.render({onSelect:()=>this._handleDesktopCategoryChange()}));const a=de.el("div",{className:"panel-body"});this._desktopFilterListSection=de.el("div",{className:"panel-section"}),this._desktopFilterListSection.appendChild(de.el("div",{className:"panel-section-title"},de.el("span",{},"Filters"))),this._filterListView=new cm(this.state,this.filterManager),this._desktopFilterListSection.appendChild(this._filterListView.render({onToggle:(t,n,i)=>this._callbacks.onFilterToggle(t,n,i),onSelect:(t,n)=>this._callbacks.onFilterSelect(t,n)})),a.appendChild(this._desktopFilterListSection),this._filterControlsView=new um(this.state,this.filterManager),a.appendChild(this._filterControlsView.render({onChange:(t,n,i,r)=>this._callbacks.onFilterChange(t,n,i,r),onReset:(t,n)=>this._callbacks.onFilterReset(t,n),onAction:(t,n,i)=>this._callbacks.onFilterAction(t,n,i)})),this._desktopCropWrapper=de.el("div",{className:"crop-controls-wrapper",style:{display:"none"}}),a.appendChild(this._desktopCropWrapper),this._activeStack=new Mh(this.state,this.filterManager),a.appendChild(this._activeStack.render({onRemove:(t,n)=>this._callbacks.onFilterToggle(t,!1,n),onSelect:(t,n)=>this._callbacks.onFilterSelect(t,n),onClearAll:t=>{var n,i;return(i=(n=this._callbacks).onClearAll)==null?void 0:i.call(n,t)}})),this._desktopBackgroundSection=de.el("div",{className:"panel-section",style:{display:"none"}}),this._backgroundPanel=new mm(this.state,this.editor),this._desktopBackgroundSection.appendChild(this._backgroundPanel.render()),a.appendChild(this._desktopBackgroundSection),this._desktopLayerSection=de.el("div",{className:"panel-section",style:{display:"none"}}),this._layerStackPanel=new pm(this.state,this.editor),this._desktopLayerSection.appendChild(this._layerStackPanel.render()),a.appendChild(this._desktopLayerSection),this._desktopTextSection=de.el("div",{className:"panel-section",style:{display:"none"}}),this._textPanel=new fm(this.state,this.editor),this._desktopTextSection.appendChild(this._textPanel.render()),a.appendChild(this._desktopTextSection),this._panel.appendChild(a),this.root.appendChild(this._panel),this._mountCropControlsInActiveShell(),this._applyMode(this.state.get("mode"))}_buildMobileShell(){this._mobileChips=new Lh(this.state,this.filterManager);const a=this._mobileChips.render({onSelect:(r,l)=>{var s,d;this._callbacks.onFilterSelect(r,l),(s=this._mobileDrawer)==null||s.snapTo("full"),(d=this._mobileNav)==null||d.navigateTo("controls")},onRemove:(r,l)=>this._callbacks.onFilterToggle(r,!1,l)});this.root.appendChild(a),this._mobileDrawer=new Ih({onSnapChange:r=>{this.canvasContainer&&window.dispatchEvent(new Event("resize"))}}),this._mobileNav=new Rh(this.state,this.filterManager,this.editor);const t=this._mobileNav.build({onFilterToggle:this._callbacks.onFilterToggle,onFilterSelect:this._callbacks.onFilterSelect,onFilterChange:this._callbacks.onFilterChange,onFilterReset:this._callbacks.onFilterReset,onFilterAction:this._callbacks.onFilterAction,onViewChange:r=>{var l;r==="controls"&&((l=this._mobileDrawer)==null?void 0:l.snap)==="collapsed"&&this._mobileDrawer.snapTo("half")}});this._mobileCropWrapper=de.el("div",{className:"crop-controls-wrapper",style:{display:"none"}});const n=de.el("div",{className:"drawer-content"});n.appendChild(t),n.appendChild(this._mobileCropWrapper);const i=this._mobileDrawer.build({body:n});this.root.appendChild(i),this._wireDrawerSizing(),this._mountCropControlsInActiveShell(),this._applyMode(this.state.get("mode"))}_wireDrawerSizing(){if(!this.root||!this._mobileDrawer)return;const a=()=>{const t=this.root.getBoundingClientRect().height;this._mobileDrawer.updateContainerHeight(t)};a(),this._resizeObserver=new ResizeObserver(()=>a()),this._resizeObserver.observe(this.root)}_destroyDesktopShell(){var a,t,n,i,r,l,s,d,c,u;(a=this._categoryTabs)==null||a.destroy(),this._categoryTabs=null,(t=this._filterListView)==null||t.destroy(),this._filterListView=null,(n=this._filterControlsView)==null||n.destroy(),this._filterControlsView=null,(i=this._activeStack)==null||i.destroy(),this._activeStack=null,(r=this._backgroundPanel)==null||r.destroy(),this._backgroundPanel=null,(l=this._layerStackPanel)==null||l.destroy(),this._layerStackPanel=null,(s=this._textPanel)==null||s.destroy(),this._textPanel=null,this._desktopBackgroundSection=null,this._desktopLayerSection=null,this._desktopTextSection=null,this._desktopFilterListSection=null,(d=this._desktopCropWrapper)!=null&&d.parentElement&&((c=this._cropControlsEl)==null?void 0:c.parentElement)===this._desktopCropWrapper&&this._desktopCropWrapper.removeChild(this._cropControlsEl),this._desktopCropWrapper=null,(u=this._panel)==null||u.remove(),this._panel=null}_destroyMobileShell(){var a,t,n,i,r;(a=this._resizeObserver)==null||a.disconnect(),this._resizeObserver=null,(t=this._mobileNav)==null||t.destroy(),this._mobileNav=null,(n=this._mobileChips)==null||n.destroy(),this._mobileChips=null,this._mobileCropWrapper&&((i=this._cropControlsEl)==null?void 0:i.parentElement)===this._mobileCropWrapper&&this._mobileCropWrapper.removeChild(this._cropControlsEl),this._mobileCropWrapper=null,(r=this._mobileDrawer)==null||r.destroy(),this._mobileDrawer=null}_handleBreakpointChange(a){a!==this._isMobile&&(this._isMobile=a,a?(this._destroyDesktopShell(),this._buildMobileShell()):(this._destroyMobileShell(),this._buildDesktopShell()))}_mountCropControlsInActiveShell(){if(!this._cropControlsEl)return;this._cropControlsEl.remove();const a=this._isMobile?this._mobileCropWrapper:this._desktopCropWrapper;a==null||a.appendChild(this._cropControlsEl)}_handleDesktopCategoryChange(){if(this.state.get("mode")==="crop"||["background","layers","text"].includes(this.state.get("selectedCategory")))return;const t=this.state.get("selectedFilter");if(!t)return;this.filterManager.getFiltersByCategory(this.state.get("selectedCategory")).some(i=>i.id===t)||this.state.set("selectedFilter",null)}_applyMode(a){var s,d,c;const t=a==="crop",n=!t&&this.state.get("selectedCategory")==="background",i=!t&&this.state.get("selectedCategory")==="layers",r=!t&&this.state.get("selectedCategory")==="text",l=n||i||r;this._desktopFilterListSection&&(this._desktopFilterListSection.style.display=t||l?"none":""),(s=this._filterControlsView)!=null&&s.element&&(this._filterControlsView.element.style.display=t||l?"none":""),(d=this._activeStack)!=null&&d.element&&(this._activeStack.element.style.display=t||l?"none":""),this._desktopBackgroundSection&&(this._desktopBackgroundSection.style.display=n?"":"none"),this._desktopLayerSection&&(this._desktopLayerSection.style.display=i?"":"none"),this._desktopTextSection&&(this._desktopTextSection.style.display=r?"":"none"),this._desktopCropWrapper&&(this._desktopCropWrapper.style.display=t?"":"none"),(c=this._mobileNav)!=null&&c.element&&(this._mobileNav.element.style.display=t?"none":""),this._mobileCropWrapper&&(this._mobileCropWrapper.style.display=t?"":"none"),t&&this._mobileDrawer&&this._mobileDrawer.snapTo("half")}_buildCanvasZoomOverlay(){const a=de.el("div",{className:"canvas-zoom-overlay",role:"group","aria-label":"Zoom controls"}),t=de.createIconButton({icon:de.zoomOut,title:"Zoom Out",className:"canvas-zoom-btn",testId:"btn-zoom-out",ariaLabel:"Zoom out",onClick:()=>{const l=this.state.get("zoom");this.editor.setZoom(l-.25)}}),n=de.el("span",{className:"canvas-zoom-label","aria-live":"polite","aria-atomic":"true",role:"status"},`${Math.round((this.state.get("zoom")??1)*100)}%`),i=de.createIconButton({icon:de.zoomIn,title:"Zoom In",className:"canvas-zoom-btn",testId:"btn-zoom-in",ariaLabel:"Zoom in",onClick:()=>{const l=this.state.get("zoom");this.editor.setZoom(l+.25)}}),r=de.createIconButton({icon:de.expand,title:"Fit to Screen",className:"canvas-zoom-btn",testId:"btn-fit-screen",ariaLabel:"Fit to screen",onClick:()=>this.editor.fitToScreen()});return a.appendChild(t),a.appendChild(n),a.appendChild(i),a.appendChild(r),this._unsubscribers.push(this.state.on("change:zoom",({value:l})=>{n.textContent=`${Math.round(l*100)}%`})),a}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._mql&&this._mqlHandler&&(this._mql.removeEventListener?this._mql.removeEventListener("change",this._mqlHandler):this._mql.removeListener&&this._mql.removeListener(this._mqlHandler),this._mql=null,this._mqlHandler=null),this._destroyDesktopShell(),this._destroyMobileShell(),(a=this.root)==null||a.remove(),this.root=null,this.canvasSection=null,this.canvasContainer=null,this.cropOverlay=null}};function qo(o){if(!Number.isFinite(Number(o)))return 0;const a=Number(o)%360;return a<0?a+360:a}function Uh(o,a){const t=qo(o);return(qo(a)-t+540)%360-180}function Oh(){return new Date().toISOString()}function gr(o){return typeof o=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(o)}class zh extends la.EventEmitter{constructor(a,t={}){var r,l,s,d,c;if(super(),!a)throw new Error("VanillaImageEditorV2: container element is required");this._container=a,this._destroyed=!1,this._loadVersion=0,this._objectUrls=new Set,this._activeObjectUrl=null;const n=t.preset?de.getPreset(t.preset):null,i=n?{initialMode:n.initialMode==="crop"?"crop":"adjust",cropShape:n.cropShape,initialAspectRatio:n.aspectRatio}:{};this._options={theme:"auto",initialImage:null,initialMode:"adjust",cropShape:"free",initialAspectRatio:"free",layout:"split-panel",backgroundRemoval:{enabled:!0,endpoint:"/api/v1/media/background-removal/preview",optionsEndpoint:"/api/v1/media/background-removal/options",savedEndpoint:"/api/v1/media/{media}/background-removal",fallbackEndpoint:null},backgroundReplacement:{assetEndpoint:null,materializeEndpoint:null,targetMediaUuid:null,mediaChoices:[]},...i,...t},this._preset=n,this._state=la.createState(),this._state.set("theme",this._options.theme),this._state.set("crop.shape",this._options.cropShape),this._state.set("crop.aspect",this._options.initialAspectRatio),this._preset&&(this._state.set("lockCropShape",!!this._preset.lockCropShape),this._state.set("lockAspectRatio",!!this._preset.lockAspectRatio),this._state.set("showFilters",this._preset.showFilters!==!1),this._state.set("showCropControls",this._preset.showCropControls!==!1),this._state.set("autoZoomOnCropOverflow",!!this._preset.autoZoomOnCropOverflow)),this._renderer=new de.PixiRenderer,this._filterManager=new de.FilterManager(this._state,this._renderer),this._cropManager=new de.CropManager(this._state,this._renderer),this._removeBgManager=null,this._backgroundRemovalAvailable=!1,((r=this._options.backgroundRemoval)==null?void 0:r.enabled)!==!1&&(this._removeBgManager=new de.RemoveBgManager({endpoint:(l=this._options.backgroundRemoval)==null?void 0:l.endpoint,optionsEndpoint:(s=this._options.backgroundRemoval)==null?void 0:s.optionsEndpoint,savedEndpoint:(d=this._options.backgroundRemoval)==null?void 0:d.savedEndpoint,fallbackEndpoint:(c=this._options.backgroundRemoval)==null?void 0:c.fallbackEndpoint})),this._loadingOverlay=null,this._toolbar=null,this._layout=null,this._cropControls=null,this._editorEl=null,this._toolbarContainer=null,this._canvasContainer=null,this._cropOverlay=null,this._fileInput=null,this._mobileSaveBar=null,this._mobileSaveBtn=null,this._mobileSaveUnsub=null,this._resizeObserver=null,this._initPromise=Promise.resolve(this._init()).catch(u=>{this._destroyed||this.emit("error",u instanceof Error?u:new Error(String(u)))})}async _init(){this._state.detectTheme(),this._buildDOM(),!(!await this._renderer.mount(this._canvasContainer,0,{backgroundAlpha:0})||this._destroyed)&&(this._cropManager.setOverlayCanvas(this._cropOverlay),this._initUI(),this._setupResizeObserver(),this._setupWindowResize(),this._subscribeToState(),this._refreshBackgroundRemovalAvailability(),this._options.initialImage&&await this.loadImage(this._options.initialImage),this.emit("ready"))}_buildDOM(){this._container.innerHTML="",this._editorEl=de.el("div",{className:`vanilla-image-editor-v2 ${this._state.get("isDarkMode")?"dark":"light"}`}),this._toolbarContainer=de.el("div",{className:"editor-v2-toolbar"}),this._editorEl.appendChild(this._toolbarContainer),this._layout=new Ph(this._state,this._filterManager,this);const{root:a,canvasContainer:t,cropOverlay:n}=this._layout.build({onFilterToggle:(i,r,l)=>this._handleFilterToggle(i,r,l),onFilterSelect:(i,r)=>this._handleFilterSelect(i,r),onFilterChange:(i,r,l,s)=>this._handleFilterChange(i,r,l,s),onFilterReset:(i,r)=>this._handleFilterReset(i,r),onFilterAction:(i,r,l)=>this._handleFilterAction(i,r,l),onClearAll:i=>this.resetAll(i)});this._canvasContainer=t,this._cropOverlay=n,this._editorEl.appendChild(a),this._buildMobileSaveBar(),this._mobileSaveBar&&this._editorEl.appendChild(this._mobileSaveBar),this._fileInput=de.el("input",{type:"file",accept:"image/*",className:"hidden-file-input",style:{display:"none"},"aria-label":"Choose image file to edit",onChange:i=>this._handleFileSelect(i)}),this._editorEl.appendChild(this._fileInput),this._container.appendChild(this._editorEl)}_initUI(){this._toolbar=new de.Toolbar(this._state,this),this._toolbarContainer.appendChild(this._toolbar.render()),this._cropControls=new de.CropControls(this._state,this._cropManager,this);const a=this._cropControls.render();this._layout.mountCropControls(a)}_setupResizeObserver(){if(!this._canvasContainer)return;let a=null;this._resizeObserver=new ResizeObserver(()=>{clearTimeout(a),a=setTimeout(()=>{var t,n;this._destroyed||!this._canvasContainer||(this._renderer.resizeTo(this._canvasContainer),this._state.get("mode")==="crop"&&((n=(t=this._cropManager).drawOverlay)==null||n.call(t)))},50)}),this._resizeObserver.observe(this._canvasContainer)}_setupWindowResize(){this._handleWindowResize=()=>{},window.addEventListener("resize",this._handleWindowResize)}_subscribeToState(){this._state.on("change:isDarkMode",({value:a})=>{var t,n;(t=this._editorEl)==null||t.classList.toggle("dark",a),(n=this._editorEl)==null||n.classList.toggle("light",!a)})}async _handleFileSelect(a){var n;const t=(n=a.target.files)==null?void 0:n[0];t&&await this.loadImage(t),this._fileInput.value=""}_matchesExpectedFilterLayer(a){if(a===void 0)return!0;if(a===null)return typeof this._state.getActiveFilterLayerId=="function"?this._state.getActiveFilterLayerId()===null:this._state.get("activeLayerId")===null;const t=typeof a=="string"?a.trim():"";return t===""?!1:typeof this._state.getActiveFilterLayerId=="function"?this._state.getActiveFilterLayerId()===t:this._state.get("activeLayerId")===t}_handleFilterToggle(a,t,n=void 0){this._filterManager.toggle(a,t,n)!==!1&&(t?this._state.set("selectedFilter",a):this._state.get("selectedFilter")===a&&this._state.set("selectedFilter",null))}_handleFilterSelect(a,t=void 0){var r;if(!this._matchesExpectedFilterLayer(t))return;const n=this._state.get("activeFilters");if(!((r=n==null?void 0:n.has)!=null&&r.call(n,a))&&this._filterManager.toggle(a,!0,t)===!1)return;this._state.set("selectedFilter",a);const i=this._filterManager.getFilterDef(a);if(typeof(i==null?void 0:i.category)=="string"){const l=de.REGISTRY_TO_UI[i.category]||i.category;this._state.get("selectedCategory")!==l&&this._state.set("selectedCategory",l)}}_handleFilterChange(a,t,n,i=void 0){this._filterManager.updateValue(a,t,n,i)||this._filterManager.applyFilters(),this._renderer.render()}_handleFilterReset(a,t=void 0){var n,i;this._filterManager.resetValues(a,t),(i=(n=this._filterManager)==null?void 0:n.applyFilters)==null||i.call(n)}_handleFilterAction(a,t,n=void 0){this._filterManager.performFilterAction(a,t,n)}_revokeObjectUrl(a){!a||!this._objectUrls.has(a)||(URL.revokeObjectURL(a),this._objectUrls.delete(a),this._activeObjectUrl===a&&(this._activeObjectUrl=null))}_replaceActiveObjectUrl(a){const t=this._activeObjectUrl;this._activeObjectUrl=a,this._objectUrls.add(a),t&&t!==a&&this._revokeObjectUrl(t)}_clearActiveObjectUrl(){this._activeObjectUrl&&this._revokeObjectUrl(this._activeObjectUrl)}async _renderCurrentDocument(){var a,t;return(t=(a=this._renderer).renderLayerDocument)==null?void 0:t.call(a,this._state.getSerializableDocument(),{fallbackImageUrl:this._state.get("imageUrl")??null})}async setBackgroundFill(a){var n;const t=this._state.setBackgroundFill(a);return await this._renderCurrentDocument(),this.emit("background-changed",{layerId:t,fill:((n=this._state.getLayer(t))==null?void 0:n.fill)??null}),t}async setBackgroundColor(a){return this.setBackgroundFill({kind:"color",value:typeof a=="string"&&a.trim()!==""?a:"#ffffff"})}async setBackgroundGradient(a={}){return this.setBackgroundFill({kind:"gradient",gradientType:a.gradientType||"linear",angle:Number.isFinite(Number(a.angle))?Number(a.angle):135,stops:Array.isArray(a.stops)?a.stops:[{offset:0,color:"#111827"},{offset:1,color:"#f59e0b"}],fit:a.fit||"cover"})}async setBackgroundMediaSource(a,t={}){if(!a||typeof a!="object")throw new Error("Background source is required");return this.setBackgroundFill({kind:"media",source:a,fit:t.fit||"cover"})}async setBackgroundImageFromFile(a,t={}){var i,r;if(!(a instanceof Blob))throw new Error("Background image file is required");const n=URL.createObjectURL(a);this._objectUrls.add(n);try{if(((r=(i=this._state).isBackgroundLayerLocked)==null?void 0:r.call(i))===!0)throw new Error("Background layer is locked");const l=this._captureEditorDocumentContext(),s=await this._probeImageDimensions(n);if(!this._isCurrentEditorDocumentContext(l))return URL.revokeObjectURL(n),this._objectUrls.delete(n),null;const d=this._state.ensureBackgroundLayer();if(!d)throw new Error("Background layer is locked");let c=null,u=this._captureEditorDocumentContext(d);if(this._canUploadBackgroundAsset()){if(!await this._materializeBackgroundLayerForUpload(d))return URL.revokeObjectURL(n),this._objectUrls.delete(n),null;if(u=this._captureEditorDocumentContext(d),c=await this._uploadBackgroundAsset(a,d,n),!this._isCurrentEditorDocumentContext(u))return URL.revokeObjectURL(n),this._objectUrls.delete(n),null}return c||(c={kind:"runtime",runtimeRef:`background-${Date.now()}`,originalWidth:s.width,originalHeight:s.height,sourceHash:null,previewUrl:n}),this._isCurrentEditorDocumentContext(u)?this.setBackgroundMediaSource(c,{fit:t.fit||"cover"}):(URL.revokeObjectURL(n),this._objectUrls.delete(n),null)}catch(l){throw URL.revokeObjectURL(n),this._objectUrls.delete(n),l}}async setBackgroundFit(a){if(!this._state.setBackgroundFit(a))return!1;const n=this._backgroundLayerId();await this._renderCurrentDocument();const i=n?this._state.getLayer(n):null;return i&&this.emit("background-changed",{layerId:n,fill:i.fill??null}),!0}async setBackgroundBlur(a){if(!this._state.setBackgroundBlur(a))return!1;const n=this._backgroundLayerId();await this._renderCurrentDocument();const i=n?this._state.getLayer(n):null;return i&&this.emit("background-changed",{layerId:n,effects:i.effects??[]}),!0}_backgroundLayerId(){const a=this._state.getSerializableDocument(),t=Array.isArray(a==null?void 0:a.layers)?a.layers.find(n=>(n==null?void 0:n.type)==="background"||(n==null?void 0:n.role)==="background"):null;return typeof(t==null?void 0:t.id)=="string"?t.id:null}async removeBackgroundLayer(){return this._state.removeBackgroundLayer()?(await this._renderCurrentDocument(),this.emit("background-changed",{layerId:null,fill:null}),!0):!1}async selectLayer(a){var n,i;return this._state.setActiveLayer(a)?((i=(n=this._filterManager)==null?void 0:n.applyFilters)==null||i.call(n),this.emit("layer-changed",{action:"select",layerId:a}),!0):!1}async renameLayer(a,t){var i;return this._state.renameLayer(a,t)?(this.emit("layer-changed",{action:"rename",layerId:a,name:((i=this._state.getLayer(a))==null?void 0:i.name)??null}),!0):!1}async duplicateLayer(a){const t=this._state.duplicateLayer(a);return t?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"duplicate",layerId:a,duplicateLayerId:t}),t):null}async deleteLayer(a){return this._state.deleteLayer(a)?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"delete",layerId:a,activeLayerId:this._state.get("activeLayerId")}),!0):!1}async moveLayer(a,t){return this._state.moveLayer(a,t)?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"move",layerId:a,direction:t}),!0):!1}async setLayerVisibility(a,t){return this._state.setLayerVisibility(a,t)?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"visibility",layerId:a,visible:!!t}),!0):!1}async setLayerLocked(a,t){return this._state.setLayerLocked(a,t)?(this.emit("layer-changed",{action:"lock",layerId:a,locked:!!t}),!0):!1}async addTextLayer(a={}){const t=this._state.addTextLayer(a);return t?(this._state.set("selectedCategory","text"),await this._renderCurrentDocument(),this.emit("layer-changed",{action:"text-add",layerId:t}),t):null}async updateTextLayer(a,t={}){return this._state.updateTextLayer(a,t)?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"text-update",layerId:a,patch:t}),!0):!1}_canUploadBackgroundAsset(){var r,l;const a=(l=(r=this._options)==null?void 0:r.backgroundReplacement)==null?void 0:l.assetEndpoint,t=this._state.getEditorDocumentBinding(),n=this._state.getSerializableDocument(),i=this._backgroundTargetMediaUuid(n);return typeof a=="string"&&a.trim()!==""&&!!(t!=null&&t.documentId)&&!!n&&typeof i=="string"&&i.trim()!==""}async _materializeBackgroundLayerForUpload(a){return this._materializeCurrentDocument("Background layer materialization failed",a)}_documentMaterializationSignature(a){try{return JSON.stringify(a??null)}catch{return null}}_captureDocumentMaterializationContext(a,t,n=null){return{loadVersion:this._loadVersion,documentId:(t==null?void 0:t.documentId)??null,documentRevisionId:(t==null?void 0:t.documentRevisionId)??null,documentRevisionNumber:(t==null?void 0:t.documentRevisionNumber)??null,documentSignature:this._documentMaterializationSignature(a),requiredLayerId:n}}_captureEditorDocumentContext(a=null){return{loadVersion:this._loadVersion,documentSignature:this._documentMaterializationSignature(this._state.getSerializableDocument()),requiredLayerId:a}}_isCurrentEditorDocumentContext(a){return!(!a||this._destroyed||this._loadVersion!==a.loadVersion||this._documentMaterializationSignature(this._state.getSerializableDocument())!==a.documentSignature||a.requiredLayerId&&!this._state.getLayer(a.requiredLayerId))}_isCurrentDocumentMaterializationContext(a){if(!a||this._destroyed||this._loadVersion!==a.loadVersion)return!1;const t=this._state.getEditorDocumentBinding();if(!t||(t.documentId??null)!==a.documentId||(t.documentRevisionId??null)!==a.documentRevisionId||(t.documentRevisionNumber??null)!==a.documentRevisionNumber)return!1;const n=this._state.getSerializableDocument();return!(this._documentMaterializationSignature(n)!==a.documentSignature||a.requiredLayerId&&!this._state.getLayer(a.requiredLayerId))}async _materializeCurrentDocument(a="Editor document materialization failed",t=null){const n=this._backgroundMaterializeEndpoint(),i=this._state.getEditorDocumentBinding(),r=this._state.getSerializableDocument();if(!n||!(i!=null&&i.documentId)||!r||t!==null&&!t)return!1;const l=this._resolveBackgroundEndpoint(n,r);if(!l)return!1;const s=this._captureDocumentMaterializationContext(r,i,t),d=gr(i.documentId)?i.documentId:null,c=await fetch(l,{method:"POST",credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({document_id:d,base_document_revision:d===null?null:i.documentRevisionNumber,document:r})});let u=null;try{u=await c.json()}catch{u=null}if(!c.ok){const m=(u==null?void 0:u.message)||a;throw new Error(m)}return this._isCurrentDocumentMaterializationContext(s)?(u!=null&&u.document&&this._state.setEditorDocument(u.document,{documentId:u.document_id??i.documentId,documentRevisionId:u.document_revision_id??i.documentRevisionId,documentRevisionNumber:typeof u.document_revision_number=="number"?u.document_revision_number:i.documentRevisionNumber}),!0):!1}async _uploadBackgroundAsset(a,t,n){var f,h,v;const i=(h=(f=this._options)==null?void 0:f.backgroundReplacement)==null?void 0:h.assetEndpoint,r=this._state.getEditorDocumentBinding(),l=this._state.getSerializableDocument();if(!i||!(r!=null&&r.documentId)||!l)return null;const s=this._resolveBackgroundEndpoint(i,l);if(!s)return null;const d=await this._sha256File(a),c=new FormData;c.append("asset_file",a,a instanceof File&&a.name?a.name:"background.png"),c.append("asset_kind","background-upload"),c.append("document_id",r.documentId),c.append("layer_id",t),c.append("client_hash",d);const u=await fetch(s,{method:"POST",credentials:"include",headers:{Accept:"application/json"},body:c});if(!u.ok)throw new Error("Background upload failed");const m=await u.json(),p=(v=m==null?void 0:m.asset)==null?void 0:v.source;if(!p||typeof p!="object")throw new Error("Background upload did not return a usable layer source");return{...p,previewUrl:n}}_backgroundMaterializeEndpoint(){var i,r,l,s,d,c;const a=(r=(i=this._options)==null?void 0:i.backgroundReplacement)==null?void 0:r.materializeEndpoint;if(typeof a=="string"&&a.trim()!=="")return a;const t=(s=(l=this._options)==null?void 0:l.backgroundReplacement)==null?void 0:s.assetEndpoint;if(typeof t=="string"&&t.trim()!=="")return t.replace(/\/editor-assets\/?$/,"/editor-documents/materialize");const n=(c=(d=this._options)==null?void 0:d.backgroundRemoval)==null?void 0:c.savedEndpoint;return typeof n=="string"&&n.trim()!==""?n.replace(/\/background-removal\/?$/,"/editor-documents/materialize"):null}_resolveBackgroundEndpoint(a,t){if(typeof a!="string"||a.trim()==="")return null;const n=this._backgroundTargetMediaUuid(t);return a.includes("{media}")?typeof n!="string"||n.trim()===""?null:a.replace("{media}",encodeURIComponent(n)):a}_backgroundTargetMediaUuid(a){var n,i;const t=(i=(n=this._options)==null?void 0:n.backgroundReplacement)==null?void 0:i.targetMediaUuid;return typeof t=="string"&&t.trim()!==""?t:typeof(a==null?void 0:a.sourceMediaUuid)=="string"&&a.sourceMediaUuid.trim()!==""?a.sourceMediaUuid:null}async _sha256File(a){var i,r,l;const t=await a.arrayBuffer(),n=await((l=(r=(i=globalThis.crypto)==null?void 0:i.subtle)==null?void 0:r.digest)==null?void 0:l.call(r,"SHA-256",t));if(!n)throw new Error("Background upload hashing is unavailable");return Array.from(new Uint8Array(n)).map(s=>s.toString(16).padStart(2,"0")).join("")}_probeImageDimensions(a){return new Promise(t=>{const n=new Image;n.onload=()=>t({width:Math.max(1,Math.round(n.naturalWidth||n.width||1)),height:Math.max(1,Math.round(n.naturalHeight||n.height||1))}),n.onerror=()=>t({width:1,height:1}),n.src=a})}setFilterRegistry(a){this._filterManager.setRegistry(a)}async loadImage(a,t={}){var s,d,c,u;if(this._destroyed)return;(d=(s=this._removeBgManager)==null?void 0:s.cancelActiveRequests)==null||d.call(s,"image-load");const n=++this._loadVersion;let i=a,r=null;this._resetEditorState(),this._state.set("hasImage",!1),this._state.set("imageUrl",null),a instanceof Blob&&(i=URL.createObjectURL(a),r=i,this._objectUrls.add(i));const l=await this._renderer.loadTexture(i,{isCurrent:()=>!this._destroyed&&this._loadVersion===n});if(this._destroyed||this._loadVersion!==n){this._revokeObjectUrl(r);return}if(!l){this._revokeObjectUrl(r),this.emit("error",new Error("Failed to load image"));return}r?this._replaceActiveObjectUrl(r):this._clearActiveObjectUrl(),this._state.set("hasImage",!0),this._state.set("imageUrl",i),t.document?await this._hydrateDocument(t.document,{documentId:t.documentId??(gr((c=t.document)==null?void 0:c.id)?t.document.id:null),documentRevisionId:t.documentRevisionId??null,documentRevisionNumber:t.documentRevisionNumber??((u=t.document)==null?void 0:u.revision)??null,fallbackImageUrl:i}):this._initializeDefaultDocument(i),t.state&&this._hydrateState(t.state),this._options.initialMode==="crop"&&this.setMode("crop"),this.emit("imageLoaded",{url:i})}_resetEditorState(){this._filterManager.resetAll(),this._state.set("crop.rect",null),this._state.set("crop.appliedRect",null),this._state.set("crop.appliedShape",null),this._state.set("crop.appliedAspect",null),this._state.set("crop.dirty",!1),this._state.set("crop.shape",this._options.cropShape||"free"),this._state.set("crop.aspect",this._options.initialAspectRatio||"free"),this._state.set("transform.rotation",0),this._state.clearEditorDocument(),this._state.get("mode")==="crop"&&(this._cropManager.disable(),this._state.set("mode","filters"))}_initializeDefaultDocument(a){var c,u,m,p;const t=this._renderer.originalTexture,n=Math.max(1,Math.round((t==null?void 0:t.width)||1)),i=Math.max(1,Math.round((t==null?void 0:t.height)||1)),r=Oh(),l=typeof((u=(c=this._options)==null?void 0:c.backgroundReplacement)==null?void 0:u.targetMediaUuid)=="string"&&this._options.backgroundReplacement.targetMediaUuid.trim()!==""?this._options.backgroundReplacement.targetMediaUuid.trim():null,s=l?{kind:"media",mediaUuid:l,originalWidth:n,originalHeight:i,sourceHash:null}:{kind:"runtime",runtimeRef:"source-image",originalWidth:n,originalHeight:i,sourceHash:null,previewUrl:typeof a=="string"?a:null},d={version:2,id:`client-doc-${Date.now()}`,sourceMediaUuid:l,canvas:{width:n,height:i,backgroundPreviewColor:null},revision:0,layers:[{id:"subject-layer",type:"image",role:"subject",name:"Subject",visible:!0,locked:!1,opacity:1,blendMode:"normal",transform:{x:0,y:0,scaleX:1,scaleY:1,rotation:0},effects:[],metadata:{},source:s,crop:null,filters:[]}],activeLayerId:"subject-layer",export:{mimeType:"image/png",quality:null,preserveTransparency:!0,matteColor:null,trimTransparentBounds:!1},createdAt:r,updatedAt:r};this._state.setEditorDocument(d,{documentId:null,documentRevisionId:null,documentRevisionNumber:0}),(p=(m=this._renderer).renderLayerDocument)==null||p.call(m,d,{fallbackImageUrl:typeof a=="string"?a:null})}async _hydrateDocument(a,t={}){var n,i;!a||a.version!==2||(this._state.setEditorDocument(a,{documentId:t.documentId??(gr(a.id)?a.id:null),documentRevisionId:t.documentRevisionId??null,documentRevisionNumber:t.documentRevisionNumber??a.revision??null}),await((i=(n=this._renderer).renderLayerDocument)==null?void 0:i.call(n,this._state.getSerializableDocument(),{fallbackImageUrl:t.fallbackImageUrl??this._state.get("imageUrl")??null})))}_hydrateState(a){var n;if(!a||a.version!==1)return;const t=qo(((n=a.transform)==null?void 0:n.rotation)??0);if(t!==0&&this._renderer.rotateBy(t)&&this._state.set("transform.rotation",t),a.crop){const i=a.crop.shape||"free",r=a.crop.aspectRatio||"free";a.crop.rect&&(this._cropManager.applyFromPixelRect(a.crop.rect,i),this._state.set("crop.appliedRect",{...a.crop.rect}),this._state.set("crop.appliedShape",i),this._state.set("crop.appliedAspect",r)),this._state.set("crop.shape",i),this._state.set("crop.aspect",r)}if(Array.isArray(a.filters)){let i=null;for(const r of a.filters)if(r.enabled&&(i===null&&(i=r.id),this._state.toggleFilter(r.id,!0),this._filterManager.initializeValues(r.id),r.values))for(const[l,s]of Object.entries(r.values))this._state.setFilterValue(r.id,l,s);if(i!==null){this._state.set("selectedFilter",i);const r=this._filterManager.getFilterDef(i);if(typeof(r==null?void 0:r.category)=="string"){const l=de.REGISTRY_TO_UI[r.category]??r.category;this._state.set("selectedCategory",l)}}this._filterManager.applyFilters()}}openFilePicker(){var a;(a=this._fileInput)==null||a.click()}exportImage(a="png",t=.92,n={}){return!this._state.get("hasImage")||!this._applyPendingCropBeforeExport("VanillaImageEditorV2.exportImage")?null:this._renderer.exportImage(a,t,n.maxEdge??0,n.dontUpscale!==!1,n.maxPixels??0)}async exportBlob(a="png",t=.92,n={}){return!this._state.get("hasImage")||!this._applyPendingCropBeforeExport("VanillaImageEditorV2.exportBlob")?null:this._renderer.exportBlob(a,t,n)}_applyPendingCropBeforeExport(a){return!(this._state.get("crop.rect")&&!this._cropManager.apply())}async save(){if(!this._state.get("hasImage"))return;this._state.set("isSaving",!0);let a=null;try{const t=await this.exportBlob("png",.92);if(!t)throw new Error("Failed to export image");const n=i.createElement("a");a=URL.createObjectURL(t.blob),n.href=a,n.download=`edited-image-${Date.now()}.png`,i.body.appendChild(n),n.click(),i.body.removeChild(n);const i=this.getSerializableDocument(),r=this.getEditorDocumentBinding();this.emit("save",{blob:t.blob,mimeType:t.blob.type||"image/png",dimensions:{width:t.width,height:t.height},state:this.getSerializableState(),document:i,documentId:(r==null?void 0:r.documentId)??(gr(i==null?void 0:i.id)?i.id:null),documentRevisionId:(r==null?void 0:r.documentRevisionId)??null,documentRevisionNumber:(r==null?void 0:r.documentRevisionNumber)??(i==null?void 0:i.revision)??null})}catch(t){this.emit("error",{error:t})}finally{a&&URL.revokeObjectURL(a),this._state.set("isSaving",!1)}}getSerializableState(){const a=this._state.get("activeFilters"),t=[];if(a)for(const l of a){const s=this._state.getFilterValues(l);t.push({id:l,enabled:!0,values:{...s}})}const n=this._state.get("crop.appliedRect"),i=this._state.get("crop.rect"),r=n||i;return{version:1,crop:{rect:r?{...r}:null,aspectRatio:this._state.get("crop.appliedAspect")||this._state.get("crop.aspect")||"free",shape:this._state.get("crop.appliedShape")||this._state.get("crop.shape")||"free"},transform:{rotation:qo(this._state.get("transform.rotation")??0)},filters:t}}getSerializableDocument(){return this._state.getSerializableDocument()}getEditorDocumentBinding(){return this._state.getEditorDocumentBinding()}close(){this.emit("cancel")}setZoom(a){this._renderer.setZoom(a)}fitToScreen(){this._renderer.fitToScreen()}resetAll(a=void 0){this._filterManager.resetAll(a)}rotateBy(a){const t=this._state.get("transform.rotation")??0;return this.setRotationAngle(Number(t)+Number(a))}setRotationAngle(a){if(!this._state.get("hasImage"))return!1;const t=qo(this._state.get("transform.rotation")??0),n=qo(a),i=Uh(t,n),r=this._state.get("mode")==="crop";if(Math.abs(i)>.001){if(r&&this._cropManager.disable(),!this._renderer.rotateBy(i))return r&&this._cropManager.enable(),!1;this._filterManager.applyFilters(),this._state.set("crop.rect",null),this._state.set("crop.dirty",!1),r&&this._cropManager.enable()}return this._state.set("transform.rotation",n),this.emit("transformChanged",{rotation:n}),!0}resetRotation(){return this.setRotationAngle(0)}toggleTheme(){const a=this._state.get("isDarkMode");this._state.set("isDarkMode",!a)}setTheme(a){this._state.set("theme",a),this._state.detectTheme()}setMode(a){a==="crop"?this._cropManager.enable():this._cropManager.disable(),this._state.set("mode",a)}getState(){return this._state.getAll()}async removeBackground(a={}){var t,n,i,r,l,s,d,c,u,m;if(!this._removeBgManager)throw new Error("Background removal is not enabled");if(!this._state.get("hasImage"))throw new Error("No image loaded");if(!this.canRemoveBackground())throw new Error("Background removal is not available for the current editor state");this._state.set("isProcessing",!0),this._showLoadingOverlay("Removing background...");try{const p=this._activeBackgroundRemovalLayer();if(this._hasSavedEditorDocumentBinding()&&p!==null&&this._backgroundMaterializeEndpoint()&&!await this._materializeCurrentDocument("Background removal materialization failed"))return this.emit("background-removal-stale",{operationId:a.operationId??null,targetLayerId:p.id}),{stale:!0};const f=this._buildSavedBackgroundRemovalContext(a);if(f){const g=await this._removeBgManager.removeSavedMediaBackground(f.request);if(!this._isCurrentBackgroundRemovalContext(f,g))return this.emit("background-removal-stale",{operationId:f.request.operationId,targetLayerId:f.request.targetLayerId}),{stale:!0};const I=(t=g==null?void 0:g.result)==null?void 0:t.source;if(!I||I.kind!=="edit-asset")throw new Error("Background removal did not return a persisted layer source");const T=(n=g==null?void 0:g.result)==null?void 0:n.previewDataUrl;return typeof T=="string"&&T.startsWith("data:image/")&&(!await this._renderer.loadTexture(T,{isCurrent:()=>!this._destroyed&&this._isCurrentBackgroundRemovalContext(f,g)})||!this._isCurrentBackgroundRemovalContext(f,g))?(this.emit("background-removal-stale",{operationId:f.request.operationId,targetLayerId:f.request.targetLayerId}),{stale:!0}):this._isCurrentBackgroundRemovalContext(f,g)?(this._state.replaceLayerSource(f.request.targetLayerId,I),await((r=(i=this._renderer).renderLayerDocument)==null?void 0:r.call(i,this._state.getSerializableDocument(),{fallbackImageUrl:this._state.get("imageUrl")??null})),this.emit("background-removed",{model:(l=g==null?void 0:g.result)==null?void 0:l.model,processMs:(s=g==null?void 0:g.result)==null?void 0:s.process_ms,source:I,operationId:f.request.operationId,targetLayerId:f.request.targetLayerId}),{model:(d=g==null?void 0:g.result)==null?void 0:d.model,processMs:(c=g==null?void 0:g.result)==null?void 0:c.process_ms,source:I}):(this.emit("background-removal-stale",{operationId:f.request.operationId,targetLayerId:f.request.targetLayerId}),{stale:!0})}const h=this._buildPreviewBackgroundRemovalInput(a);if(!h)throw new Error("Failed to export image for background removal");const v=this._buildPreviewBackgroundRemovalContext(h.options),y=await this._removeBgManager.preparePreviewRequest(h.imageData,h.options),w=this._resolvePreviewBackgroundRemovalContext(v,y);if(!await this._isCurrentPreviewBackgroundRemovalContext(w))return this.emit("background-removal-stale",{operationId:w.operationId,sourceHash:w.sourceHash,targetLayerId:w.activeLayerId??null}),{stale:!0};const _=await this._removeBgManager.removeBackground(y.blob,y);if(!await this._isCurrentPreviewBackgroundRemovalContext(w,_))return this.emit("background-removal-stale",{operationId:w.operationId,sourceHash:w.sourceHash}),{stale:!0};const b=await this._applyPreviewBackgroundRemovalResult(w,_);return b?(this.emit("background-removed",{model:_.model,processMs:_.processMs,operationId:w.operationId,targetLayerId:w.activeLayerId??null,source:b.source}),{model:_.model,processMs:_.processMs,...b.source?{source:b.source}:{}}):(this.emit("background-removal-stale",{operationId:w.operationId,sourceHash:w.sourceHash,targetLayerId:w.activeLayerId??null}),{stale:!0})}catch(p){throw this.emit("error",{error:p,context:"background-removal"}),p}finally{(m=(u=this._state)==null?void 0:u.set)==null||m.call(u,"isProcessing",!1),this._hideLoadingOverlay()}}async isBackgroundRemovalAvailable(){return this._removeBgManager?this._refreshBackgroundRemovalAvailability():!1}canRemoveBackground(){if(!this._removeBgManager||this._state.get("hasImage")!==!0||this._backgroundRemovalAvailable!==!0)return!1;const a=this._state.getSerializableDocument();return(a==null?void 0:a.version)===2&&Array.isArray(a.layers)?this._activeBackgroundRemovalLayer({requireSourceHash:this._hasSavedEditorDocumentBinding()})!==null:!0}async _refreshBackgroundRemovalAvailability(){if(!this._removeBgManager)return this._backgroundRemovalAvailable=!1,this._state.set("backgroundRemovalAvailable",!1),!1;const a=await this._removeBgManager.isAvailable();return this._destroyed?!1:(this._backgroundRemovalAvailable=a,this._state.set("backgroundRemovalAvailable",a),a)}_hasSavedEditorDocumentBinding(){const a=this._state.getEditorDocumentBinding();return!!(a!=null&&a.documentId)&&!!(a!=null&&a.documentRevisionId)}_activeBackgroundRemovalLayer(a={}){var l;const t=a.requireSourceHash!==!1,n=this._state.get("activeLayerId");if(!n)return null;const i=this._state.getLayer(n);if(!i||i.type!=="image"||i.locked===!0||i.visible===!1)return null;const r=(l=i==null?void 0:i.source)==null?void 0:l.sourceHash;return t&&(typeof r!="string"||!/^[a-f0-9]{64}$/i.test(r))?null:i}_buildSavedBackgroundRemovalContext(a={}){var u,m,p,f,h;const t=this._state.getSerializableDocument(),n=this._state.getEditorDocumentBinding();if(!t||!(n!=null&&n.documentId)||!(n!=null&&n.documentRevisionId))return null;const i=typeof t.sourceMediaUuid=="string"&&t.sourceMediaUuid!==""?t.sourceMediaUuid:null;if(!i)return null;const r=this._activeBackgroundRemovalLayer({requireSourceHash:!0}),l=r==null?void 0:r.id,s=(u=r==null?void 0:r.source)==null?void 0:u.sourceHash;if(!l||typeof s!="string"||!/^[a-f0-9]{64}$/i.test(s))return null;const d=a.operationId||((p=(m=globalThis.crypto)==null?void 0:m.randomUUID)==null?void 0:p.call(m))||`op-${Date.now()}-${Math.random().toString(16).slice(2)}`,c={loadVersion:this._loadVersion,activeLayerId:l,documentRevisionId:n.documentRevisionId,documentSignature:this._documentMaterializationSignature(t),sourceHash:s,request:{targetMediaUuid:i,operationId:d,documentId:n.documentId,documentRevisionId:n.documentRevisionId,targetLayerId:l,expectedSourceHash:s,tier:a.tier||((h=(f=this._options)==null?void 0:f.backgroundRemoval)==null?void 0:h.defaultTier)||"balanced"}};return a.model&&(c.request.model=a.model),a.alpha_matting!==void 0&&(c.request.alpha_matting=a.alpha_matting),a.max_megapixels!==void 0&&(c.request.max_megapixels=a.max_megapixels),c}_buildPreviewBackgroundRemovalContext(a){const t=this._state.getSerializableDocument(),n=(t==null?void 0:t.version)===2&&Array.isArray(t.layers),i=n?this._activeBackgroundRemovalLayer({requireSourceHash:!1}):null;return{loadVersion:this._loadVersion,activeLayerId:n?(i==null?void 0:i.id)??null:null,documentSignature:n?this._documentMaterializationSignature(t):null,imageUrl:this._state.get("imageUrl")??null,operationId:a.operationId,sessionKey:a.sessionKey,sourceHash:a.sourceHash,targetRef:a.targetRef??null}}_resolvePreviewBackgroundRemovalContext(a,t){return{...a,operationId:t.operationId,sessionKey:t.sessionKey,sourceHash:t.sourceHash,targetRef:t.targetRef??a.targetRef??null}}_buildPreviewBackgroundRemovalInput(a={}){const t=this._state.getSerializableDocument();if((t==null?void 0:t.version)===2&&Array.isArray(t.layers)){const i=this._activeBackgroundRemovalLayer({requireSourceHash:!1}),r=this._sourceUrlForLayerSource(i==null?void 0:i.source);return!i||!r?null:{imageData:r,options:{...a,targetRef:i.id}}}const n=this.exportImage("png");return n?{imageData:n,options:a}:null}_sourceUrlForLayerSource(a){if(!a||typeof a!="object")return null;for(const t of["previewUrl","sourceUrl","url"]){const n=a[t];if(typeof n=="string"&&n.trim()!=="")return n}return null}async _applyPreviewBackgroundRemovalResult(a,t){var r,l;if(a.documentSignature===null||!a.activeLayerId)return await this.loadImage(t.dataUrl),{source:null};const n=await this._probeImageDimensions(t.dataUrl);if(!await this._isCurrentPreviewBackgroundRemovalContext(a,t))return null;const i={kind:"runtime",runtimeRef:`background-removal-${a.operationId||Date.now()}`,originalWidth:n.width,originalHeight:n.height,sourceHash:null,previewUrl:t.dataUrl};return this._state.replaceLayerSource(a.activeLayerId,i)?(await((l=(r=this._renderer).renderLayerDocument)==null?void 0:l.call(r,this._state.getSerializableDocument(),{fallbackImageUrl:this._state.get("imageUrl")??null})),{source:i}):null}async _isCurrentPreviewBackgroundRemovalContext(a,t=null){if(this._destroyed||this._loadVersion!==a.loadVersion||this._state.get("hasImage")!==!0||(this._state.get("imageUrl")??null)!==a.imageUrl)return!1;if(t){if(t.operationId&&t.operationId!==a.operationId||t.sessionKey&&t.sessionKey!==a.sessionKey||t.sourceHash&&t.sourceHash!==a.sourceHash)return!1;if(a.documentSignature!==null){if(!a.targetRef||a.targetRef!==a.activeLayerId||t.targetRef!==a.targetRef)return!1}else if(t.targetRef&&a.targetRef&&t.targetRef!==a.targetRef)return!1}if(a.documentSignature!==null){const i=this._state.getSerializableDocument();if(this._documentMaterializationSignature(i)!==a.documentSignature)return!1;const r=this._activeBackgroundRemovalLayer({requireSourceHash:!1});return!(!r||r.id!==a.activeLayerId)}const n=this.exportImage("png");return n?await this._removeBgManager.computeImageDataHash(n)===a.sourceHash:!1}_isCurrentBackgroundRemovalContext(a,t=null){var l;if(this._destroyed||this._loadVersion!==a.loadVersion)return!1;const n=this._state.getEditorDocumentBinding();if(!n||n.documentRevisionId!==a.documentRevisionId)return!1;const i=this._state.getSerializableDocument();if(this._documentMaterializationSignature(i)!==a.documentSignature||this._state.get("activeLayerId")!==a.activeLayerId)return!1;const r=this._state.getLayer(a.request.targetLayerId);return!(!r||((l=r==null?void 0:r.source)==null?void 0:l.sourceHash)!==a.sourceHash||r.locked===!0||r.visible===!1||t&&(t.operation_id&&t.operation_id!==a.request.operationId||t.target_layer_id&&t.target_layer_id!==a.request.targetLayerId||t.document_revision_id&&t.document_revision_id!==a.request.documentRevisionId||t.source_hash&&t.source_hash!==a.request.expectedSourceHash))}_showLoadingOverlay(a){var n;if(!this._loadingOverlay)this._loadingOverlay=de.el("div",{className:"editor-loading-overlay"},de.el("div",{className:"editor-loading-spinner"}),de.el("div",{className:"editor-loading-text"},a));else{const i=this._loadingOverlay.querySelector(".editor-loading-text");i&&(i.textContent=a)}const t=(n=this._canvasContainer)==null?void 0:n.parentElement;t&&!this._loadingOverlay.parentElement&&t.appendChild(this._loadingOverlay)}_hideLoadingOverlay(){var a;(a=this._loadingOverlay)==null||a.remove()}_buildMobileSaveBar(){var l,s;this._mobileSaveBar=de.el("div",{className:"editor-v2-mobile-save-bar",role:"region","aria-label":"Save bar"}),this._mobileSaveBtn=de.el("button",{type:"button",className:"mobile-save-btn",title:"Save Image","aria-label":"Save image",dataset:{testid:"btn-save-edit-mobile"},onClick:()=>this.save()});const a=de.el("span",{className:"mobile-save-icon"});a.innerHTML=de.save;const t=a.querySelector("svg");t&&t.setAttribute("aria-hidden","true"),this._mobileSaveBtn.appendChild(a),this._mobileSaveBtn.appendChild(de.el("span",{className:"mobile-save-label"},"Save")),this._mobileSaveBar.appendChild(this._mobileSaveBtn);const n=()=>{var m,p;if(!this._mobileSaveBtn)return;const d=((m=this._state)==null?void 0:m.get("hasImage"))===!0,c=((p=this._state)==null?void 0:p.get("isProcessing"))===!0,u=!d||c;this._mobileSaveBtn.disabled=u,this._mobileSaveBtn.setAttribute("aria-disabled",u?"true":"false")};n();const i=(l=this._state)==null?void 0:l.on("change:hasImage",n),r=(s=this._state)==null?void 0:s.on("change:isProcessing",n);this._mobileSaveUnsub=()=>{try{i==null||i()}catch{}try{r==null||r()}catch{}}}destroy(){var a,t,n,i,r,l,s,d;this._destroyed=!0,(t=(a=this._removeBgManager)==null?void 0:a.cancelActiveRequests)==null||t.call(a,"editor-destroy");for(const c of this._objectUrls)try{URL.revokeObjectURL(c)}catch{}this._objectUrls.clear(),this._activeObjectUrl=null,(n=this._resizeObserver)==null||n.disconnect(),this._renderer.destroy(),this._cropManager.disable(),this._handleWindowResize&&window.removeEventListener("resize",this._handleWindowResize),(i=this._toolbar)==null||i.destroy(),(r=this._cropControls)==null||r.destroy(),(l=this._layout)==null||l.destroy(),(s=this._mobileSaveUnsub)==null||s.call(this),this._mobileSaveUnsub=null,this._mobileSaveBtn=null,this._mobileSaveBar=null,(d=this._editorEl)==null||d.remove(),this._container=null,this._state=null,this.emit("destroyed"),this.removeAllListeners()}}function jh(o,a){try{let t=la.getFilter(o);if(t||(la.registerCorePixiFilters(),t=la.getFilter(o)),!t){try{const r=la.getAllFilters()}catch{}return null}const n={...t.defaultParams,...a};return t.createFilter(n)}catch{return null}}const Wh=78e5,Hh=e.defineComponent({__name:"ImageEditor",props:{initialImage:{},initialState:{default:null},initialDocument:{default:null},initialDocumentId:{default:null},initialDocumentRevisionId:{default:null},initialDocumentRevisionNumber:{default:null},sessionKey:{default:0},theme:{default:"auto"},cropShape:{default:"square"},preset:{},editorVersion:{default:"v2"},backgroundRemoval:{default:null},backgroundReplacement:{default:null},primaryColor:{default:"#3880ff"},secondaryColor:{default:"#5260ff"},saveButtonColor:{default:"#3880ff"},downloadButtonColor:{default:"#2dd36f"}},emits:["save","cancel","error"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(null);let r=null,l=null;function s(v){return typeof v=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v)}function d(){const v={state:t.initialState??null,sessionKey:t.sessionKey};return t.initialDocument&&(v.document=t.initialDocument,v.documentId=t.initialDocumentId,v.documentRevisionId=t.initialDocumentRevisionId,v.documentRevisionNumber=t.initialDocumentRevisionNumber),v}async function c(){var v,y,w;try{if(!r){n("error",new Error("Editor not initialized"));return}const _=await((v=r.exportBlob)==null?void 0:v.call(r,"png",.92,{maxPixels:Wh}));if(!_){n("error",new Error("Failed to export image — the image could not be processed"));return}const b=r.getSerializableState(),g={blob:_.blob,mimeType:_.blob.type||"image/png",dimensions:{width:_.width,height:_.height},state:b},I=((y=r.getSerializableDocument)==null?void 0:y.call(r))??null;if(I){const T=((w=r.getEditorDocumentBinding)==null?void 0:w.call(r))??null;g.document=I,g.documentId=(T==null?void 0:T.documentId)??(s(I.id)?I.id:null),g.documentRevisionId=(T==null?void 0:T.documentRevisionId)??null,g.documentRevisionNumber=(T==null?void 0:T.documentRevisionNumber)??I.revision??null}n("save",g)}catch(_){n("error",_ instanceof Error?_:new Error("Failed to export image"))}}function u(){n("cancel")}function m(v){if(v instanceof Error)return v;if(v!==null&&typeof v=="object"&&"error"in v){const y=v.error;if(y instanceof Error)return y;if(typeof y=="string"&&y.trim()!=="")return new Error(y)}return typeof v=="string"&&v.trim()!==""?new Error(v):new Error("Failed to load image")}function p(v){n("error",m(v))}function f(){if(!i.value||r)return;window.PIXI=na,la.initializeFilterRegistry();const v={theme:t.theme};t.backgroundRemoval&&(v.backgroundRemoval=t.backgroundRemoval),t.backgroundReplacement&&(v.backgroundReplacement=t.backgroundReplacement),t.preset&&(v.preset=t.preset),t.preset?t.cropShape==="circle"&&(v.cropShape="circle",v.initialAspectRatio="1:1",v.initialMode="crop"):(v.cropShape=t.cropShape==="circle"?"circle":"free",v.initialAspectRatio=t.cropShape==="circle"?"1:1":"free",v.initialMode=t.cropShape==="circle"?"crop":"adjust");const y=t.editorVersion==="v2"?zh:de.VanillaImageEditor,w=new y(i.value,v);r=w,w.setFilterRegistry({getAllFilters:la.getAllFilters,getFilter:la.getFilter,getFiltersByCategory:la.getFiltersByCategory}),w.save=function(){c()},w.on("cancel",u),w.on("error",p),t.initialImage&&w.loadImage(t.initialImage,d())}e.onMounted(()=>{i.value&&(i.value.clientWidth>0?f():(l=new ResizeObserver(v=>{const y=v[0];y&&y.contentRect.width>0&&!r&&(f(),l==null||l.disconnect(),l=null)}),l.observe(i.value)))});const h=()=>{!r||!t.initialImage||r.loadImage(t.initialImage,d())};return e.watch(()=>t.initialImage,(v,y)=>{!r||!v||v===y||h()}),e.watch(()=>t.sessionKey,(v,y)=>{v!==y&&h()}),e.watch(()=>t.initialState,(v,y)=>{v!==y&&h()}),e.watch(()=>[t.initialDocument,t.initialDocumentId,t.initialDocumentRevisionId,t.initialDocumentRevisionNumber],(v,y)=>{v!==y&&h()}),e.onUnmounted(()=>{l==null||l.disconnect(),l=null,r&&(r.destroy(),r=null)}),(v,y)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"containerRef",ref:i,class:"vanilla-editor-wrapper","data-testid":"vanilla-image-editor"},null,512))}}),Ae=(o,a)=>{const t=o.__vccOpts||o;for(const[n,i]of a)t[n]=i;return t},hm=Ae(Hh,[["__scopeId","data-v-8ab74f83"]]),Zh={class:"editor-modal-panel"},Gh={class:"editor-fill"},Xh=e.defineComponent({__name:"ImageEditorModal",props:{modelValue:{type:Boolean,default:!1},initialImage:{},initialState:{default:null},initialDocument:{default:null},initialDocumentId:{default:null},initialDocumentRevisionId:{default:null},initialDocumentRevisionNumber:{default:null},sessionKey:{default:0},acceptedFormats:{default:"image/jpeg,image/png,image/webp,image/gif"},maxFileSize:{default:10},theme:{default:"auto"},cropShape:{default:"square"},preset:{},editorVersion:{default:"v2"},backgroundRemoval:{default:null},backgroundReplacement:{default:null},primaryColor:{default:"#3880ff"},secondaryColor:{default:"#5260ff"},saveButtonColor:{default:"#3880ff"},downloadButtonColor:{default:"#2dd36f"},saveHandler:{}},emits:["update:modelValue","save","cancel","error"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(null),r=e.ref(t.modelValue),l=e.ref(!1),s=e.ref(null),d=v=>{n("error",v)},c=()=>{e.nextTick(()=>{if(i.value){const v=i.value.querySelector("button:not([disabled]), [href], input:not([disabled])");v&&v.focus()}})};e.watch(()=>t.modelValue,v=>{r.value=v,v&&(s.value=document.activeElement,c())},{immediate:!0});const u=async v=>{try{if(l.value=!0,t.saveHandler){await t.saveHandler(v);return}n("save",v)}catch(y){d(y instanceof Error?y:new Error("Failed to save image"))}finally{l.value=!1}},m=()=>{n("cancel"),f()},p=()=>{l.value||f()},f=()=>{r.value=!1,n("update:modelValue",!1),s.value&&s.value instanceof HTMLElement&&(s.value.focus(),s.value=null)},h=v=>{if(v.key==="Escape"&&r.value&&!l.value){f();return}if(v.key==="Tab"&&r.value&&i.value){const y=i.value.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])');if(y.length===0)return;const w=y[0],_=y[y.length-1];v.shiftKey&&document.activeElement===w?(v.preventDefault(),_.focus()):!v.shiftKey&&document.activeElement===_&&(v.preventDefault(),w.focus())}};return e.onMounted(()=>{document.addEventListener("keydown",h)}),e.onBeforeUnmount(()=>{document.removeEventListener("keydown",h)}),(v,y)=>(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[r.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"overlayRef",ref:i,role:"dialog","aria-modal":"true","aria-label":"Image editor",class:"editor-modal-overlay","data-testid":"image-editor-modal",onKeydown:e.withKeys(p,["escape"])},[e.createElementVNode("div",{class:"editor-modal-backdrop",onClick:p}),e.createElementVNode("div",Zh,[e.createElementVNode("div",Gh,[e.createVNode(hm,{"initial-image":v.initialImage,"initial-state":v.initialState,"initial-document":v.initialDocument,"initial-document-id":v.initialDocumentId,"initial-document-revision-id":v.initialDocumentRevisionId,"initial-document-revision-number":v.initialDocumentRevisionNumber,"session-key":v.sessionKey,theme:v.theme,"crop-shape":v.cropShape,preset:v.preset,"editor-version":v.editorVersion,"background-removal":v.backgroundRemoval,"background-replacement":v.backgroundReplacement,"primary-color":v.primaryColor,"secondary-color":v.secondaryColor,"save-button-color":v.saveButtonColor,"download-button-color":v.downloadButtonColor,onSave:u,onCancel:m,onError:d},null,8,["initial-image","initial-state","initial-document","initial-document-id","initial-document-revision-id","initial-document-revision-number","session-key","theme","crop-shape","preset","editor-version","background-removal","background-replacement","primary-color","secondary-color","save-button-color","download-button-color"])])])],544)):e.createCommentVNode("",!0)]))}}),vm=Ae(Xh,[["__scopeId","data-v-bd4e671f"]]),Kh={class:"media-workspace"},qh={class:"media-workspace-toolbar"},Jh={class:"media-workspace-label"},Yh=["value"],Qh={class:"media-workspace-grid"},ev=["onClick"],tv=e.defineComponent({__name:"MediaWorkspace",props:{apiScope:{},subScopes:{},initialScopeId:{}},emits:["scope-change","update:media","upload","preview"],setup(o,{emit:a}){var m;const t=o,n=a,i=ja(),r=e.ref(t.initialScopeId??((m=t.subScopes[0])==null?void 0:m.id)??""),l=e.computed(()=>t.subScopes),s=e.computed(()=>l.value.find(p=>p.id===r.value));let d=null;function c(){d&&(d(),d=null),t.apiScope&&(d=lm({apiScope:t.apiScope,isAdmin:t.apiScope==="admin"}))}async function u(){var f;const p={};(f=s.value)!=null&&f.collection&&(p.collection=s.value.collection),await i.fetchMedia(1,p),n("update:media",[...i.items])}return e.watch(()=>t.initialScopeId,p=>{p&&p!==r.value&&(r.value=p)}),e.watch(()=>t.subScopes,p=>{if(p.length===0){r.value="";return}p.some(f=>f.id===r.value)||(r.value=p[0].id)},{deep:!0}),e.watch(()=>t.apiScope,()=>{c(),u()}),e.watch(r,p=>{p&&(n("scope-change",p),u())}),e.onMounted(()=>{c(),u()}),e.onUnmounted(()=>{d&&(d(),d=null)}),(p,f)=>(e.openBlock(),e.createElementBlock("div",Kh,[e.createElementVNode("div",qh,[e.createElementVNode("label",Jh,[f[2]||(f[2]=e.createElementVNode("span",{class:"media-workspace-label-text"},"Scope",-1)),e.withDirectives(e.createElementVNode("select",{"onUpdate:modelValue":f[0]||(f[0]=h=>r.value=h),"data-testid":"scope-select",class:"media-workspace-select"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.value,h=>(e.openBlock(),e.createElementBlock("option",{key:h.id,value:h.id},e.toDisplayString(h.label),9,Yh))),128))],512),[[e.vModelSelect,r.value]])]),e.createElementVNode("button",{type:"button",class:"media-workspace-upload","data-testid":"upload-button",onClick:f[1]||(f[1]=h=>n("upload"))}," Upload ")]),e.createElementVNode("div",Qh,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i).items,h=>(e.openBlock(),e.createElementBlock("button",{key:h.uuid,type:"button",class:"media-workspace-item","data-testid":"media-item",onClick:v=>n("preview",h)},e.toDisplayString(h.file_name),9,ev))),128))])]))}}),av=Ae(tv,[["__scopeId","data-v-895f26fe"]]),nv={class:"managed-media-gallery"},ov={class:"gallery-grid"},iv=e.defineComponent({__name:"ManagedMediaGallery",props:{media:{},selectable:{type:Boolean},multiple:{type:Boolean}},emits:["select","remove"],setup(o){return(a,t)=>(e.openBlock(),e.createElementBlock("div",nv,[e.createElementVNode("div",ov,[e.renderSlot(a.$slots,"default",{},void 0,!0)])]))}}),rv=Ae(iv,[["__scopeId","data-v-10a9b8c5"]]),Fr="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M256 176v160M336 256H176' class='ionicon-fill-none ionicon-stroke-width'/></svg>",md="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M256 112v288M400 256H112' class='ionicon-fill-none ionicon-stroke-width'/></svg>",lv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208 208-93.31 208-208S370.69 48 256 48zm0 319.91a20 20 0 1120-20 20 20 0 01-20 20zm21.72-201.15l-5.74 122a16 16 0 01-32 0l-5.74-121.94v-.05a21.74 21.74 0 1143.44 0z'/></svg>",pd="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M250.26 166.05L256 288l5.73-121.95a5.74 5.74 0 00-5.79-6h0a5.74 5.74 0 00-5.68 6z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M256 367.91a20 20 0 1120-20 20 20 0 01-20 20z'/></svg>",sv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M244 400L100 256l144-144M120 256h292' class='ionicon-fill-none'/></svg>",dv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M268 112l144 144-144 144M392 256H100' class='ionicon-fill-none'/></svg>",bc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256L272 88v96C103.57 184 64 304.77 64 424c48.61-62.24 91.6-96 208-96v96z' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",yc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M240 424v-96c116.4 0 159.39 33.76 208 96 0-119.23-39.57-240-208-240V88L64 256z' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Bi="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M452.37 59.63h0a40.49 40.49 0 00-57.26 0L184 294.74c23.08 4.7 46.12 27.29 49.26 49.26l219.11-227.11a40.49 40.49 0 000-57.26zM138 336c-29.88 0-54 24.5-54 54.86 0 23.95-20.88 36.57-36 36.57C64.56 449.74 92.82 464 120 464c39.78 0 72-32.73 72-73.14 0-30.36-24.12-54.86-54-54.86z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",cv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M350.54 148.68l-26.62-42.06C318.31 100.08 310.62 96 302 96h-92c-8.62 0-16.31 4.08-21.92 10.62l-26.62 42.06C155.85 155.23 148.62 160 140 160H80a32 32 0 00-32 32v192a32 32 0 0032 32h352a32 32 0 0032-32V192a32 32 0 00-32-32h-59c-8.65 0-16.85-4.77-22.46-11.32z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='256' cy='272' r='80' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M124 158v-22h-24v22' class='ionicon-fill-none ionicon-stroke-width'/></svg>",gm="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208 208-93.31 208-208S370.69 48 256 48zm108.25 138.29l-134.4 160a16 16 0 01-12 5.71h-.27a16 16 0 01-11.89-5.3l-57.6-64a16 16 0 1123.78-21.4l45.29 50.32 122.59-145.91a16 16 0 0124.5 20.58z'/></svg>",bm="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M416 128L192 384l-96-96' class='ionicon-fill-none ionicon-stroke-width'/></svg>",wc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M328 112L184 256l144 144' class='ionicon-fill-none'/></svg>",uv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M112 184l144 144 144-144' class='ionicon-fill-none'/></svg>",mv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M184 112l144 144-144 144' class='ionicon-fill-none'/></svg>",kc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M184 112l144 144-144 144' class='ionicon-fill-none'/></svg>",$o="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M368 368L144 144M368 144L144 368' class='ionicon-fill-none ionicon-stroke-width'/></svg>",_c="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M320 367.79h76c55 0 100-29.21 100-83.6s-53-81.47-96-83.6c-8.89-85.06-71-136.8-144-136.8-69 0-113.44 45.79-128 91.2-60 5.7-112 43.88-112 106.4s54 106.4 120 106.4h56' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M320 255.79l-64-64-64 64M256 448.21V207.79' class='ionicon-fill-none ionicon-stroke-width'/></svg>",pv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='256' cy='184' r='120' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='344' cy='328' r='120' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='168' cy='328' r='120' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",to="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M430.11 347.9c-6.6-6.1-16.3-7.6-24.6-9-11.5-1.9-15.9-4-22.6-10-14.3-12.7-14.3-31.1 0-43.8l30.3-26.9c46.4-41 46.4-108.2 0-149.2-34.2-30.1-80.1-45-127.8-45-55.7 0-113.9 20.3-158.8 60.1-83.5 73.8-83.5 194.7 0 268.5 41.5 36.7 97.5 55 152.9 55.4h1.7c55.4 0 110-17.9 148.8-52.4 14.4-12.7 11.99-36.6.1-47.7z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='144' cy='208' r='32'/><circle cx='152' cy='311' r='32'/><circle cx='224' cy='144' r='32'/><circle cx='256' cy='367' r='48'/><circle cx='328' cy='144' r='32'/></svg>",fv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M304 416V304h112M314.2 314.23L432 432M208 96v112H96M197.8 197.77L80 80M416 208H304V96M314.23 197.8L432 80M96 304h112v112M197.77 314.2L80 432' class='ionicon-fill-none ionicon-stroke-width'/></svg>",ki="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='256' cy='256' r='208' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M256 464c-114.88 0-208-93.12-208-208S141.12 48 256 48z'/></svg>",Ss="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><rect x='128' y='128' width='336' height='336' rx='57' ry='57' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M383.5 128l.5-24a56.16 56.16 0 00-56-56H112a64.19 64.19 0 00-64 64v216a56.16 56.16 0 0056 56h24' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",hv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M384 224v184a40 40 0 01-40 40H104a40 40 0 01-40-40V168a40 40 0 0140-40h167.48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M459.94 53.25a16.06 16.06 0 00-23.22-.56L424.35 65a8 8 0 000 11.31l11.34 11.32a8 8 0 0011.34 0l12.06-12c6.1-6.09 6.67-16.01.85-22.38zM399.34 90L218.82 270.2a9 9 0 00-2.31 3.93L208.16 299a3.91 3.91 0 004.86 4.86l24.85-8.35a9 9 0 003.93-2.31L422 112.66a9 9 0 000-12.66l-9.95-10a9 9 0 00-12.71 0z'/></svg>",Ec="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M144 48v272a48 48 0 0048 48h272' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M368 304V192a48 48 0 00-48-48H208M368 368v96M144 144H48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Gr="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='104' cy='152' r='56' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='104' cy='360' r='56' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M157 175l-11 15 37 15s3.46-6.42 7-10z' stroke-linecap='square' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M154.17 334.43L460 162c-2.5-6.7-28-12-64-4-29.12 6.47-121.16 29.05-159.16 56.05C205.85 236.06 227 272 192 298c-25.61 19-44.43 22.82-44.43 22.82zM344.47 278.24L295 306.67c14.23 6.74 65.54 33.27 117 36.33 14.92.89 30 .39 39-6z' stroke-linecap='round' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='256' cy='240' r='32' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",ni="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M336 176h40a40 40 0 0140 40v208a40 40 0 01-40 40H136a40 40 0 01-40-40V216a40 40 0 0140-40h40' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M176 272l80 80 80-80M256 48v288' class='ionicon-fill-none ionicon-stroke-width'/></svg>",vv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='256' cy='256' r='32' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='416' cy='256' r='32' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='96' cy='256' r='32' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",gv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M432 320v112H320M421.8 421.77L304 304M80 192V80h112M90.2 90.23L208 208M320 80h112v112M421.77 90.2L304 208M192 432H80V320M90.23 421.8L208 304' class='ionicon-fill-none ionicon-stroke-width'/></svg>",bv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M432 320v112H320M421.8 421.77L304 304M80 192V80h112M90.2 90.23L208 208M320 80h112v112M421.77 90.2L304 208M192 432H80V320M90.23 421.8L208 304' class='ionicon-fill-none ionicon-stroke-width'/></svg>",yv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M432 448a15.92 15.92 0 01-11.31-4.69l-352-352a16 16 0 0122.62-22.62l352 352A16 16 0 01432 448zM255.66 384c-41.49 0-81.5-12.28-118.92-36.5-34.07-22-64.74-53.51-88.7-91v-.08c19.94-28.57 41.78-52.73 65.24-72.21a2 2 0 00.14-2.94L93.5 161.38a2 2 0 00-2.71-.12c-24.92 21-48.05 46.76-69.08 76.92a31.92 31.92 0 00-.64 35.54c26.41 41.33 60.4 76.14 98.28 100.65C162 402 207.9 416 255.66 416a239.13 239.13 0 0075.8-12.58 2 2 0 00.77-3.31l-21.58-21.58a4 4 0 00-3.83-1 204.8 204.8 0 01-51.16 6.47zM490.84 238.6c-26.46-40.92-60.79-75.68-99.27-100.53C349 110.55 302 96 255.66 96a227.34 227.34 0 00-74.89 12.83 2 2 0 00-.75 3.31l21.55 21.55a4 4 0 003.88 1 192.82 192.82 0 0150.21-6.69c40.69 0 80.58 12.43 118.55 37 34.71 22.4 65.74 53.88 89.76 91a.13.13 0 010 .16 310.72 310.72 0 01-64.12 72.73 2 2 0 00-.15 2.95l19.9 19.89a2 2 0 002.7.13 343.49 343.49 0 0068.64-78.48 32.2 32.2 0 00-.1-34.78z'/><path d='M256 160a95.88 95.88 0 00-21.37 2.4 2 2 0 00-1 3.38l112.59 112.56a2 2 0 003.38-1A96 96 0 00256 160zM165.78 233.66a2 2 0 00-3.38 1 96 96 0 00115 115 2 2 0 001-3.38z'/></svg>",Mi="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M255.66 112c-77.94 0-157.89 45.11-220.83 135.33a16 16 0 00-.27 17.77C82.92 340.8 161.8 400 255.66 400c92.84 0 173.34-59.38 221.79-135.25a16.14 16.14 0 000-17.47C428.89 172.28 347.8 112 255.66 112z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='256' cy='256' r='80' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Sc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M80 464V68.14a8 8 0 014-6.9C91.81 56.66 112.92 48 160 48c64 0 145 48 192 48a199.53 199.53 0 0077.23-15.77 2 2 0 012.77 1.85v219.36a4 4 0 01-2.39 3.65C421.37 308.7 392.33 320 352 320c-48 0-128-32-192-32s-80 16-80 16' stroke-linecap='round' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",es="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M315.27 33L96 304h128l-31.51 173.23a2.36 2.36 0 002.33 2.77h0a2.36 2.36 0 001.89-.95L416 208H288l31.66-173.25a2.45 2.45 0 00-2.44-2.75h0a2.42 2.42 0 00-1.95 1z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",wv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M496 152a56 56 0 00-56-56H220.11a23.89 23.89 0 01-13.31-4L179 73.41A55.77 55.77 0 00147.89 64H72a56 56 0 00-56 56v48a8 8 0 008 8h464a8 8 0 008-8zM16 392a56 56 0 0056 56h368a56 56 0 0056-56V216a8 8 0 00-8-8H24a8 8 0 00-8 8z'/></svg>",kv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='129' cy='96' r='48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='129' cy='416' r='48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M129 144v224' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='385' cy='288' r='48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M129 144c0 96 112 144 208 144' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",ts="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M432 112V96a48.14 48.14 0 00-48-48H64a48.14 48.14 0 00-48 48v256a48.14 48.14 0 0048 48h16' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><rect x='96' y='128' width='400' height='336' rx='45.99' ry='45.99' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><ellipse cx='372.92' cy='219.64' rx='30.77' ry='30.55' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M342.15 372.17L255 285.78a30.93 30.93 0 00-42.18-1.21L96 387.64M265.23 464l118.59-117.73a31 31 0 0141.46-1.87L496 402.91' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",_v="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M248 64C146.39 64 64 146.39 64 248s82.39 184 184 184 184-82.39 184-184S349.61 64 248 64z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M220 220h32v116' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M208 340h88' class='ionicon-fill-none ionicon-stroke-width'/><path d='M248 130a26 26 0 1026 26 26 26 0 00-26-26z'/></svg>",Ev="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M368 128h80M64 128h240M368 384h80M64 384h240M208 256h240M64 256h80' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='336' cy='128' r='32' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='176' cy='256' r='32' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='336' cy='384' r='32' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Sv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M208 432h-48a16 16 0 01-16-16V96a16 16 0 0116-16h48a16 16 0 0116 16v320a16 16 0 01-16 16zM352 432h-48a16 16 0 01-16-16V96a16 16 0 0116-16h48a16 16 0 0116 16v320a16 16 0 01-16 16z'/></svg>",Cv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208 208-93.31 208-208S370.69 48 256 48zm-32 272a16 16 0 01-32 0V192a16 16 0 0132 0zm96 0a16 16 0 01-32 0V192a16 16 0 0132 0z'/></svg>",ym="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M208 192v128M304 192v128' class='ionicon-fill-none ionicon-stroke-width'/></svg>",fd="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M176 96h16v320h-16zM320 96h16v320h-16z' class='ionicon-fill-none ionicon-stroke-width'/></svg>",xv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M133 440a35.37 35.37 0 01-17.5-4.67c-12-6.8-19.46-20-19.46-34.33V111c0-14.37 7.46-27.53 19.46-34.33a35.13 35.13 0 0135.77.45l247.85 148.36a36 36 0 010 61l-247.89 148.4A35.5 35.5 0 01133 440z'/></svg>",Nv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M30.71 229.47l188.87-113a30.54 30.54 0 0131.09-.39 33.74 33.74 0 0116.76 29.47v79.05l180.72-108.16a30.54 30.54 0 0131.09-.39A33.74 33.74 0 01496 145.52v221A33.73 33.73 0 01479.24 396a30.54 30.54 0 01-31.09-.39L267.43 287.4v79.08A33.73 33.73 0 01250.67 396a30.54 30.54 0 01-31.09-.39l-188.87-113a31.27 31.27 0 010-53z'/></svg>",Vv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M480 145.52v221c0 13.28-13 21.72-23.63 15.35L267.5 268.8c-9.24-5.53-9.24-20.07 0-25.6l188.87-113C467 123.8 480 132.24 480 145.52zM251.43 145.52v221c0 13.28-13 21.72-23.63 15.35L38.93 268.8c-9.24-5.53-9.24-20.07 0-25.6l188.87-113c10.64-6.4 23.63 2.04 23.63 15.32z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Tv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208 208-93.31 208-208S370.69 48 256 48zm74.77 217.3l-114.45 69.14a10.78 10.78 0 01-16.32-9.31V186.87a10.78 10.78 0 0116.32-9.31l114.45 69.14a10.89 10.89 0 010 18.6z'/></svg>",wm="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M216.32 334.44l114.45-69.14a10.89 10.89 0 000-18.6l-114.45-69.14a10.78 10.78 0 00-16.32 9.31v138.26a10.78 10.78 0 0016.32 9.31z'/></svg>",Bv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M481.29 229.47l-188.87-113a30.54 30.54 0 00-31.09-.39 33.74 33.74 0 00-16.76 29.47v79.05L63.85 116.44a30.54 30.54 0 00-31.09-.39A33.74 33.74 0 0016 145.52v221A33.74 33.74 0 0032.76 396a30.54 30.54 0 0031.09-.39L244.57 287.4v79.08A33.74 33.74 0 00261.33 396a30.54 30.54 0 0031.09-.39l188.87-113a31.27 31.27 0 000-53z'/></svg>",Mv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M32 145.52v221c0 13.28 13 21.72 23.63 15.35l188.87-113c9.24-5.53 9.24-20.07 0-25.6l-188.87-113C45 123.8 32 132.24 32 145.52zM260.57 145.52v221c0 13.28 13 21.72 23.63 15.35l188.87-113c9.24-5.53 9.24-20.07 0-25.6l-188.87-113c-10.64-6.47-23.63 1.97-23.63 15.25z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",hd="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M112 111v290c0 17.44 17 28.52 31 20.16l247.9-148.37c12.12-7.25 12.12-26.33 0-33.58L143 90.84c-14-8.36-31 2.72-31 20.16z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Iv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M400 111v290c0 17.44-17 28.52-31 20.16L121.09 272.79c-12.12-7.25-12.12-26.33 0-33.58L369 90.84c14-8.36 31 2.72 31 20.16z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M112 80v352' class='ionicon-fill-none ionicon-stroke-width'/></svg>",$v="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M112 111v290c0 17.44 17 28.52 31 20.16l247.9-148.37c12.12-7.25 12.12-26.33 0-33.58L143 90.84c-14-8.36-31 2.72-31 20.16z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M400 80v352' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Uo="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M320 146s24.36-12-64-12a160 160 0 10160 160' stroke-linecap='round' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M256 58l80 80-80 80' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Fv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M336 256H176' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Dv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M400 256H112' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Cc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M304 96h112v112M405.77 106.2L111.98 400.02M208 416H96V304' class='ionicon-fill-none ionicon-stroke-width'/></svg>",pl="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M380.93 57.37A32 32 0 00358.3 48H94.22A46.21 46.21 0 0048 94.22v323.56A46.21 46.21 0 0094.22 464h323.56A46.36 46.36 0 00464 417.78V153.7a32 32 0 00-9.37-22.63zM256 416a64 64 0 1164-64 63.92 63.92 0 01-64 64zm48-224H112a16 16 0 01-16-16v-64a16 16 0 0116-16h192a16 16 0 0116 16v64a16 16 0 01-16 16z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Av="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='256' cy='256' r='48'/><path d='M470.39 300l-.47-.38-31.56-24.75a16.11 16.11 0 01-6.1-13.33v-11.56a16 16 0 016.11-13.22L469.92 212l.47-.38a26.68 26.68 0 005.9-34.06l-42.71-73.9a1.59 1.59 0 01-.13-.22A26.86 26.86 0 00401 92.14l-.35.13-37.1 14.93a15.94 15.94 0 01-14.47-1.29q-4.92-3.1-10-5.86a15.94 15.94 0 01-8.19-11.82l-5.59-39.59-.12-.72A27.22 27.22 0 00298.76 26h-85.52a26.92 26.92 0 00-26.45 22.39l-.09.56-5.57 39.67a16 16 0 01-8.13 11.82 175.21 175.21 0 00-10 5.82 15.92 15.92 0 01-14.43 1.27l-37.13-15-.35-.14a26.87 26.87 0 00-32.48 11.34l-.13.22-42.77 73.95a26.71 26.71 0 005.9 34.1l.47.38 31.56 24.75a16.11 16.11 0 016.1 13.33v11.56a16 16 0 01-6.11 13.22L42.08 300l-.47.38a26.68 26.68 0 00-5.9 34.06l42.71 73.9a1.59 1.59 0 01.13.22 26.86 26.86 0 0032.45 11.3l.35-.13 37.07-14.93a15.94 15.94 0 0114.47 1.29q4.92 3.11 10 5.86a15.94 15.94 0 018.19 11.82l5.56 39.59.12.72A27.22 27.22 0 00213.24 486h85.52a26.92 26.92 0 0026.45-22.39l.09-.56 5.57-39.67a16 16 0 018.18-11.82c3.42-1.84 6.76-3.79 10-5.82a15.92 15.92 0 0114.43-1.27l37.13 14.95.35.14a26.85 26.85 0 0032.48-11.34 2.53 2.53 0 01.13-.22l42.71-73.89a26.7 26.7 0 00-5.89-34.11zm-134.48-40.24a80 80 0 11-83.66-83.67 80.21 80.21 0 0183.66 83.67z'/></svg>",as="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M400 304l48 48-48 48M400 112l48 48-48 48M64 352h85.19a80 80 0 0066.56-35.62L256 256' class='ionicon-fill-none ionicon-stroke-width'/><path d='M64 160h85.19a80 80 0 0166.56 35.62l80.5 120.76A80 80 0 00362.81 352H416M416 160h-53.19a80 80 0 00-66.56 35.62L288 208' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",eo="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' class='ionicon'><path d='M259.92 262.91L216.4 149.77a9 9 0 00-16.8 0l-43.52 113.14a9 9 0 01-5.17 5.17L37.77 311.6a9 9 0 000 16.8l113.14 43.52a9 9 0 015.17 5.17l43.52 113.14a9 9 0 0016.8 0l43.52-113.14a9 9 0 015.17-5.17l113.14-43.52a9 9 0 000-16.8l-113.14-43.52a9 9 0 01-5.17-5.17zM108 68L88 16 68 68 16 88l52 20 20 52 20-52 52-20-52-20zM426.67 117.33L400 48l-26.67 69.33L304 144l69.33 26.67L400 240l26.67-69.33L496 144l-69.33-26.67z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",_i="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-miterlimit='10' d='M256 48v48M256 416v48M403.08 108.92l-33.94 33.94M142.86 369.14l-33.94 33.94M464 256h-48M96 256H48M403.08 403.08l-33.94-33.94M142.86 142.86l-33.94-33.94' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='256' cy='256' r='80' stroke-linecap='round' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",xc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M304 48l112 112-112 112M398.87 160H96M208 464L96 352l112-112M114 352h302' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Rv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M512 128v256a64.07 64.07 0 01-64 64H64a64.07 64.07 0 01-64-64V128a64.07 64.07 0 0164-64h384a64.07 64.07 0 0164 64zM32 384a32 32 0 0032 32h384a32 32 0 0032-32V128a32 32 0 00-32-32H64a32 32 0 00-32 32z'/><path d='M0 128a64.07 64.07 0 0164-64h384a64.07 64.07 0 0164 64v256a64.07 64.07 0 01-64 64H64a64.07 64.07 0 01-64-64V128m480 256V128a32 32 0 00-32-32H64a32 32 0 00-32 32v256a32 32 0 0032 32h384a32 32 0 0032-32m-16 0a16 16 0 01-16 16H64a16 16 0 01-16-16V128a16 16 0 0116-16h384a16 16 0 0116 16v256z'/></svg>",km="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M32 415.5l120-320 120 320M230 303.5H74M326 239.5c12.19-28.69 41-48 74-48h0c46 0 80 32 80 80v144' class='ionicon-fill-none ionicon-stroke-width'/><path d='M320 358.5c0 36 26.86 58 60 58 54 0 100-27 100-106v-15c-20 0-58 1-92 5-32.77 3.86-68 19-68 58z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Xr="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M112 112l20 320c.95 18.49 14.4 32 32 32h184c17.67 0 30.87-13.51 32-32l20-320' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M80 112h352' class='ionicon-stroke-width'/><path d='M192 112V72h0a23.93 23.93 0 0124-24h80a23.93 23.93 0 0124 24h0v40M256 176v224M184 176l8 224M328 176l-8 224' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",_m="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M374.79 308.78L457.5 367a16 16 0 0022.5-14.62V159.62A16 16 0 00457.5 145l-82.71 58.22A16 16 0 00368 216.3v79.4a16 16 0 006.79 13.08z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M268 384H84a52.15 52.15 0 01-52-52V180a52.15 52.15 0 0152-52h184.48A51.68 51.68 0 01320 179.52V332a52.15 52.15 0 01-52 52z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Lv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M232 416a23.88 23.88 0 01-14.2-4.68 8.27 8.27 0 01-.66-.51L125.76 336H56a24 24 0 01-24-24V200a24 24 0 0124-24h69.75l91.37-74.81a8.27 8.27 0 01.66-.51A24 24 0 01256 120v272a24 24 0 01-24 24zm-106.18-80zm-.27-159.86zM320 336a16 16 0 01-14.29-23.19c9.49-18.87 14.3-38 14.3-56.81 0-19.38-4.66-37.94-14.25-56.73a16 16 0 0128.5-14.54C346.19 208.12 352 231.44 352 256c0 23.86-6 47.81-17.7 71.19A16 16 0 01320 336z'/><path d='M368 384a16 16 0 01-13.86-24C373.05 327.09 384 299.51 384 256c0-44.17-10.93-71.56-29.82-103.94a16 16 0 0127.64-16.12C402.92 172.11 416 204.81 416 256c0 50.43-13.06 83.29-34.13 120a16 16 0 01-13.87 8z'/><path d='M416 432a16 16 0 01-13.39-24.74C429.85 365.47 448 323.76 448 256c0-66.5-18.18-108.62-45.49-151.39a16 16 0 1127-17.22C459.81 134.89 480 181.74 480 256c0 64.75-14.66 113.63-50.6 168.74A16 16 0 01416 432z'/></svg>",Pv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M296 416.19a23.92 23.92 0 01-14.21-4.69l-.66-.51-91.46-75H120a24 24 0 01-24-24V200a24 24 0 0124-24h69.65l91.46-75 .66-.51A24 24 0 01320 119.83v272.34a24 24 0 01-24 24zM384 336a16 16 0 01-14.29-23.18c9.49-18.9 14.3-38 14.3-56.82 0-19.36-4.66-37.92-14.25-56.73a16 16 0 0128.5-14.54C410.2 208.16 416 231.47 416 256c0 23.83-6 47.78-17.7 71.18A16 16 0 01384 336z'/></svg>",Uv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M264 416.19a23.92 23.92 0 01-14.21-4.69l-.66-.51-91.46-75H88a24 24 0 01-24-24V200a24 24 0 0124-24h69.65l91.46-75 .66-.51A24 24 0 01288 119.83v272.34a24 24 0 01-24 24zM352 336a16 16 0 01-14.29-23.18c9.49-18.9 14.3-38 14.3-56.82 0-19.36-4.66-37.92-14.25-56.73a16 16 0 0128.5-14.54C378.2 208.16 384 231.47 384 256c0 23.83-6 47.78-17.7 71.18A16 16 0 01352 336z'/><path d='M400 384a16 16 0 01-13.87-24C405 327.05 416 299.45 416 256c0-44.12-10.94-71.52-29.83-103.95A16 16 0 01413.83 136C434.92 172.16 448 204.88 448 256c0 50.36-13.06 83.24-34.12 120a16 16 0 01-13.88 8z'/></svg>",Ov="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M157.65 192H88a8 8 0 00-8 8v112a8 8 0 008 8h69.65a16 16 0 0110.14 3.63l91.47 75a8 8 0 0012.74-6.46V119.83a8 8 0 00-12.74-6.44l-91.47 75a16 16 0 01-10.14 3.61zM352 320c9.74-19.41 16-40.81 16-64 0-23.51-6-44.4-16-64M400 368c19.48-34 32-64 32-112s-12-77.7-32-112' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",zv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-miterlimit='10' d='M416 432L64 80' class='ionicon-fill-none ionicon-stroke-width'/><path d='M243.33 98.86a23.89 23.89 0 00-25.55 1.82l-.66.51-28.52 23.35a8 8 0 00-.59 11.85l54.33 54.33a8 8 0 0013.66-5.66v-64.49a24.51 24.51 0 00-12.67-21.71zM251.33 335.29L96.69 180.69A16 16 0 0085.38 176H56a24 24 0 00-24 24v112a24 24 0 0024 24h69.76l92 75.31a23.9 23.9 0 0025.87 1.69A24.51 24.51 0 00256 391.45v-44.86a16 16 0 00-4.67-11.3zM352 256c0-24.56-5.81-47.87-17.75-71.27a16 16 0 10-28.5 14.55C315.34 218.06 320 236.62 320 256q0 4-.31 8.13a8 8 0 002.32 6.25l14.36 14.36a8 8 0 0013.55-4.31A146 146 0 00352 256zM416 256c0-51.18-13.08-83.89-34.18-120.06a16 16 0 00-27.64 16.12C373.07 184.44 384 211.83 384 256c0 23.83-3.29 42.88-9.37 60.65a8 8 0 001.9 8.26L389 337.4a8 8 0 0013.13-2.79C411 311.76 416 287.26 416 256z'/><path d='M480 256c0-74.25-20.19-121.11-50.51-168.61a16 16 0 10-27 17.22C429.82 147.38 448 189.5 448 256c0 46.19-8.43 80.27-22.43 110.53a8 8 0 001.59 9l11.92 11.92a8 8 0 0012.92-2.16C471.6 344.9 480 305 480 256z'/></svg>",jv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-miterlimit='10' d='M416 432L64 80' class='ionicon-fill-none ionicon-stroke-width'/><path d='M224 136.92v33.8a4 4 0 001.17 2.82l24 24a4 4 0 006.83-2.82v-74.15a24.53 24.53 0 00-12.67-21.72 23.91 23.91 0 00-25.55 1.83 8.27 8.27 0 00-.66.51l-31.94 26.15a4 4 0 00-.29 5.92l17.05 17.06a4 4 0 005.37.26zM224 375.08l-78.07-63.92a32 32 0 00-20.28-7.16H64v-96h50.72a4 4 0 002.82-6.83l-24-24a4 4 0 00-2.82-1.17H56a24 24 0 00-24 24v112a24 24 0 0024 24h69.76l91.36 74.8a8.27 8.27 0 00.66.51 23.93 23.93 0 0025.85 1.69A24.49 24.49 0 00256 391.45v-50.17a4 4 0 00-1.17-2.82l-24-24a4 4 0 00-6.83 2.82zM125.82 336zM352 256c0-24.56-5.81-47.88-17.75-71.27a16 16 0 00-28.5 14.54C315.34 218.06 320 236.62 320 256q0 4-.31 8.13a8 8 0 002.32 6.25l19.66 19.67a4 4 0 006.75-2A146.89 146.89 0 00352 256zM416 256c0-51.19-13.08-83.89-34.18-120.06a16 16 0 00-27.64 16.12C373.07 184.44 384 211.83 384 256c0 23.83-3.29 42.88-9.37 60.65a8 8 0 001.9 8.26l16.77 16.76a4 4 0 006.52-1.27C410.09 315.88 416 289.91 416 256z'/><path d='M480 256c0-74.26-20.19-121.11-50.51-168.61a16 16 0 10-27 17.22C429.82 147.38 448 189.5 448 256c0 47.45-8.9 82.12-23.59 113a4 4 0 00.77 4.55L443 391.39a4 4 0 006.4-1C470.88 348.22 480 307 480 256z'/></svg>",Wv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M85.57 446.25h340.86a32 32 0 0028.17-47.17L284.18 82.58c-12.09-22.44-44.27-22.44-56.36 0L57.4 399.08a32 32 0 0028.17 47.17z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M250.26 195.39l5.74 122 5.73-121.95a5.74 5.74 0 00-5.79-6h0a5.74 5.74 0 00-5.68 5.95z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M256 397.25a20 20 0 1120-20 20 20 0 01-20 20z'/></svg>",br="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M400 320c0 88.37-55.63 144-144 144s-144-55.63-144-144c0-94.83 103.23-222.85 134.89-259.88a12 12 0 0118.23 0C296.77 97.15 400 225.17 400 320z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M344 328a72 72 0 01-72 72' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Nc=()=>{};function Hv(o,a){function t(...n){return new Promise((i,r)=>{Promise.resolve(o(()=>a.apply(this,n),{fn:a,thisArg:this,args:n})).then(i).catch(r)})}return t}function Zv(o,a={}){let t,n,i=Nc;const r=d=>{clearTimeout(d),i(),i=Nc};let l;return d=>{const c=e.toValue(o),u=e.toValue(a.maxWait);return t&&r(t),c<=0||u!==void 0&&u<=0?(n&&(r(n),n=null),Promise.resolve(d())):new Promise((m,p)=>{i=a.rejectOnCancel?p:m,l=d,u&&!n&&(n=setTimeout(()=>{t&&r(t),n=null,m(l())},u)),t=setTimeout(()=>{n&&r(n),n=null,m(d())},c)})}}function Gv(o,a=200,t={}){return Hv(Zv(a,t),o)}const Ei=new Map;function Xv(o){const a=e.getCurrentScope();function t(s){var d;const c=Ei.get(o)||new Set;c.add(s),Ei.set(o,c);const u=()=>i(s);return(d=a==null?void 0:a.cleanups)==null||d.push(u),u}function n(s){function d(...c){i(d),s(...c)}return t(d)}function i(s){const d=Ei.get(o);d&&(d.delete(s),d.size||r())}function r(){Ei.delete(o)}function l(s,d){var c;(c=Ei.get(o))==null||c.forEach(u=>u(s,d))}return{on:t,once:n,off:i,emit:l,reset:r}}function Em(){var r,l;const o=typeof window<"u"&&"Capacitor"in window&&((l=(r=window.Capacitor)==null?void 0:r.isNativePlatform)==null?void 0:l.call(r));return{selection:()=>{var s,d;if(o)try{const c=(d=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:d.Haptics;c&&c.impact({style:"LIGHT"})}catch{}else"vibrate"in navigator&&navigator.vibrate(10)},success:()=>{var s,d;if(o)try{const c=(d=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:d.Haptics;c&&c.impact({style:"MEDIUM"})}catch{}else"vibrate"in navigator&&navigator.vibrate(30)},error:()=>{var s,d;if(o)try{const c=(d=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:d.Haptics;c&&c.impact({style:"HEAVY"})}catch{}else"vibrate"in navigator&&navigator.vibrate([50,50,50])},notification:()=>{var s,d;if(o)try{const c=(d=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:d.Haptics;c&&c.notification({type:"SUCCESS"})}catch{}else"vibrate"in navigator&&navigator.vibrate([20,100,20])}}}function fl(o,a={}){const t=e.ref(new Set),n=e.ref(new Map),i=e.ref(null),r=e.ref(-1),l=e.ref(a.scopeKey!==void 0?e.toValue(a.scopeKey):"default"),s=e.ref(!1),d=e.ref(null),c=Xv("media-selection"),u=Em(),m=()=>{if(a.currentPage===void 0)return null;const O=e.toValue(a.currentPage);return typeof O=="number"&&Number.isFinite(O)?O:null};function p(O){t.value=O,n.value=new Map(Array.from(n.value.entries()).filter(([K])=>O.has(K)))}function f(O){if(n.value.has(O))return;const K=new Map(n.value);K.set(O,{uuid:O,selectedAt:Date.now(),page:m()}),n.value=K}const h=e.computed(()=>o.value.filter(O=>t.value.has(O.uuid))),v=e.computed(()=>t.value.size),y=e.computed(()=>Array.from(n.value.values()).sort((O,K)=>O.selectedAt-K.selectedAt).map(O=>O.uuid)),w=e.computed(()=>Math.max(0,v.value-h.value.length)),_=e.computed(()=>{const O=new Map;for(const K of n.value.values())K.page!==null&&O.set(K.page,(O.get(K.page)??0)+1);return O});e.watch(t,O=>{c.emit({type:"selection:changed",count:O.size,selectedIds:Array.from(O)})}),a.scopeKey!==void 0&&e.watch(()=>e.toValue(a.scopeKey),(O,K)=>{O!==void 0&&O!==K&&z(O)});const b=e.computed(()=>o.value.length>0&&o.value.every(O=>t.value.has(O.uuid))),g=e.computed(()=>o.value.some(O=>t.value.has(O.uuid)));function I(O){return t.value.has(O)}function T(O){const K=new Set(t.value),se=K.size===0;K.add(O),f(O),t.value=K,i.value=O,r.value=o.value.findIndex(xe=>xe.uuid===O),se&&u.selection()}function $(O){const K=new Set(t.value);K.delete(O);const se=new Map(n.value);se.delete(O),n.value=se,t.value=K,i.value===O&&(i.value=null,r.value=-1)}function N(O){if(t.value.has(O)){$(O);return}T(O)}function B(){const O=new Set(t.value);for(const K of o.value)O.add(K.uuid),f(K.uuid);t.value=O}function P(){t.value=new Set,n.value=new Map,i.value=null,r.value=-1,s.value=!1,d.value=null}function x(){if(b.value){P();return}B()}function M(O,K){const se=o.value.findIndex(xe=>xe.uuid===O);if(se!==-1){if(K!=null&&K.shiftKey&&r.value!==-1){const xe=Math.min(r.value,se),ue=Math.max(r.value,se),le=new Set(t.value);for(let Z=xe;Z<=ue;Z++){const k=o.value[Z];k!==void 0&&(le.add(k.uuid),f(k.uuid))}t.value=le;return}N(O)}}function E(){if(o.value.length===0)return;let O=r.value+1;O>=o.value.length&&(O=0),P();const K=o.value[O];K!==void 0&&T(K.uuid)}function D(){if(o.value.length===0)return;let O=r.value-1;O<0&&(O=o.value.length-1),P();const K=o.value[O];K!==void 0&&T(K.uuid)}function j(O){switch(O.key){case"ArrowDown":O.preventDefault(),E();break;case"ArrowUp":O.preventDefault(),D();break;case"a":(O.ctrlKey||O.metaKey)&&(O.preventDefault(),B());break;case"Escape":O.preventDefault(),P();break;case" ":i.value&&(O.preventDefault(),N(i.value));break}}async function L(O){var se;if(v.value===0||l.value===O)return!0;const K=(se=a.confirmScopeChange)==null?void 0:se.call(a,{from:l.value,to:O,selectedCount:v.value});return K===void 0?!0:await K}async function z(O){return l.value===O?!0:await L(O)?(l.value=O,P(),!0):!1}async function C(){if(!a.fetchMatchingUuids){const K={uuids:o.value.map(se=>se.uuid),overCap:!1,totalMatching:o.value.length};return A(K),K}const O=await a.fetchMatchingUuids();return A(O),O}function A(O){const K=new Set(O.uuids),se=new Map,xe=Date.now();O.uuids.forEach((ue,le)=>{se.set(ue,{uuid:ue,selectedAt:xe+le,page:m()})}),p(K),n.value=se,s.value=O.overCap,d.value=O.totalMatching}return{selectedIds:e.computed(()=>t.value),selectedRecords:e.computed(()=>n.value),selectedItems:h,selectedCount:v,orderedIds:y,crossPageCount:w,selectedPages:_,overCap:e.computed(()=>s.value),totalMatching:e.computed(()=>d.value),activeScopeKey:e.computed(()=>l.value),isAllSelected:b,isSomeSelected:g,lastSelectedId:e.computed(()=>i.value),isSelected:I,toggle:N,select:T,deselect:$,selectAll:B,clear:P,toggleAll:x,rangeSelect:M,selectAcrossAllPages:C,setScopeKey:z,canChangeScope:L,selectNext:E,selectPrevious:D,handleKeydown:j,selectionBus:c}}const Kv={class:"flex items-center justify-between w-full px-4"},qv={class:"p-4"},Jv={key:0,class:"mb-4 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg"},Yv={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"},Qv=["value"],eg={class:"flex gap-2 mt-4"},tg={class:"flex justify-end mb-4"},ag={key:1,class:"flex justify-center items-center h-64"},ng={key:2,class:"flex flex-col items-center justify-center h-64 text-center"},og={class:"text-sm text-theme-secondary"},ig={key:0},rg={class:"mb-4"},lg={class:"mb-4"},sg={class:"flex gap-2"},dg={class:"flex items-center justify-between px-4 py-2"},cg={class:"text-sm text-theme-secondary"},ug={key:0},mg={key:0},pg={key:1},fg={class:"flex gap-2"},hg=e.defineComponent({__name:"AdminMediaBrowser",props:{isOpen:{type:Boolean},selectionMode:{default:"single"},selectedItems:{default:()=>[]},modelType:{},modelId:{},collection:{default:"images"},maxSelection:{}},emits:["close","confirm"],setup(o,{emit:a}){const t=o,n=a,i=e.ref("recent"),r=e.ref("grid"),l=e.ref(""),s=e.ref(!1),d=e.ref([]),{selectedItems:c}=e.toRefs(t),u=e.ref(new Set(c.value)),m=e.ref(!1),p=e.ref({}),f=e.ref(["images","documents","videos"]),h=e.ref(1),v=e.ref(!0),y=e.ref(!1),w=sm(),_=fl(d);function b(Z){var be;const k=Z.conversion_urls||{},F=Z.proxy_url||Z.original_url||Z.url||"",W=k.thumb||k.preview||Z.preview_url||Z.thumbnail_url||F,J=Z.custom_properties||{},ce=J.width,Ue=J.height;return{...Z,uuid:Z.uuid,name:Z.name||Z.file_name,file_name:Z.file_name,filename:Z.file_name,mime_type:Z.mime_type,size:Z.size,collection_name:Z.collection_name||"images",disk:Z.disk,original_url:F,url:F,thumbnail_url:W,conversions:Z.conversions||{},conversion_urls:k,generated_conversions:Z.generated_conversions||{},custom_properties:J,caption:Z.caption||null,alt_text:Z.alt_text||null,created_at:Z.created_at,updated_at:Z.updated_at,is_image:((be=Z.mime_type)==null?void 0:be.startsWith("image/"))||!1,...typeof ce=="number"?{width:ce}:{},...typeof Ue=="number"?{height:Ue}:{},...Z.formatted_size!==void 0?{formatted_size:Z.formatted_size}:{}}}e.watch(()=>t.selectedItems,Z=>{u.value=new Set(Z),_.clear(),Z.forEach(k=>_.select(k))});const g=e.computed(()=>{var k;let Z=d.value;return(k=p.value.types)!=null&&k.length&&(Z=Z.filter(F=>{var J,ce;const W=(J=F.mime_type)==null?void 0:J.split("/")[0];return(ce=p.value.types)==null?void 0:ce.includes(W)})),(p.value.sizeMin!==void 0||p.value.sizeMax!==void 0)&&(Z=Z.filter(F=>{const W=F.size/1048576;return!(p.value.sizeMin!==void 0&&W<p.value.sizeMin||p.value.sizeMax!==void 0&&W>p.value.sizeMax)})),Z}),I=e.computed(()=>{var k;let Z=0;return p.value.search&&Z++,p.value.collection&&Z++,(p.value.dateFrom||p.value.dateTo)&&Z++,(k=p.value.types)!=null&&k.length&&(Z+=p.value.types.length),(p.value.sizeMin!==void 0||p.value.sizeMax!==void 0)&&Z++,Z}),T=e.computed(()=>{const Z=_.selectedCount.value;return Z===0?"Select Media":`Select ${t.selectionMode==="multiple"?`${Z} ${Z===1?"Item":"Items"}`:"Item"}`}),$=e.computed(()=>{const Z=_.selectedCount.value;return!!(Z===0||t.selectionMode==="single"&&Z>1||t.maxSelection&&Z>t.maxSelection)}),N=e.computed(()=>{switch(i.value){case"recent":return"Recent Uploads";case"model":return"Model Media";case"library":return"Media Library";default:return"Media Browser"}});async function B(Z=!0){Z?(s.value=!0,d.value=[],h.value=1,v.value=!0):y.value=!0;try{const k={collection:p.value.collection||t.collection,per_page:24};switch((l.value||p.value.search)&&(k.search=l.value||p.value.search||""),p.value.dateFrom&&(k.from_date=p.value.dateFrom),p.value.dateTo&&(k.to_date=p.value.dateTo),i.value){case"recent":await w.fetchMedia(h.value,k),Z?d.value=w.items.map(F=>b(F)):d.value=[...d.value,...w.items.map(F=>b(F))],v.value=w.currentPage<w.totalPages;break;case"model":if(t.modelType&&t.modelId){const F=await w.fetchModelMedia(t.modelType,t.modelId,k.collection,k.search);d.value=F?F.map(W=>b(W)):[],v.value=!1}break;case"library":await w.fetchMedia(h.value,k),Z?d.value=w.items.map(F=>b(F)):d.value=[...d.value,...w.items.map(F=>b(F))],v.value=w.currentPage<w.totalPages;break}}catch{}finally{s.value=!1,y.value=!1}}async function P(Z){if(!v.value||y.value){Z!=null&&Z.target&&Z.target.complete();return}h.value++,await B(!1),Z!=null&&Z.target&&(Z.target.complete(),v.value||(Z.target.disabled=!0))}function x(Z){return Z==="recent"||Z==="model"||Z==="library"}function M(Z){i.value=Z,B()}function E(Z){typeof Z=="string"&&x(Z)&&M(Z)}async function D(Z){t.selectionMode==="single"?(_.clear(),_.select(Z.uuid)):(_.toggle(Z.uuid),t.maxSelection&&_.selectedCount.value>t.maxSelection&&(_.deselect(Z.uuid),await(await G.toastController.create({message:`Maximum ${t.maxSelection} items can be selected`,duration:2e3,color:"warning"})).present()))}function j(){n("confirm",_.selectedItems.value)}function L(){n("close")}function z(Z){}const C=e.ref(null),A=e.ref(!1);function O(Z){C.value=Z,A.value=!0}function K(Z){const k=d.value.findIndex(W=>W.uuid===Z.uuid);k!==-1&&(d.value[k]=Z);const F={};Z.alt_text!==void 0&&(F.alt_text=Z.alt_text),Z.caption!==void 0&&(F.caption=Z.caption),Z.custom_properties!==void 0&&(F.custom_properties=Z.custom_properties),w.updateMedia(Z.uuid,F)}function se(){B()}function xe(){p.value={},l.value="",B()}const ue=Gv(()=>{B(!0)},300);e.watch(l,()=>{t.isOpen&&ue()});async function le(Z){try{await(await G.alertController.create({header:"Delete Media",message:"Are you sure you want to delete this media item?",buttons:[{text:"Cancel",role:"cancel"},{text:"Delete",role:"destructive",handler:async()=>{await w.deleteMedia(Z),await B()}}]})).present()}catch{}}return e.watch(()=>t.isOpen,Z=>{Z&&B()}),e.onMounted(()=>{t.selectedItems.length>0&&t.selectedItems.forEach(Z=>_.select(Z))}),(Z,k)=>{const F=e.resolveComponent("AdminMediaGrid"),W=e.resolveComponent("AdminMediaListItem");return e.openBlock(),e.createBlock(e.unref(G.IonModal),{"is-open":Z.isOpen,onDidDismiss:L,"backdrop-dismiss":!1,class:"media-browser-modal"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonHeader),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonToolbar),null,{end:e.withCtx(()=>[e.createVNode(e.unref(G.IonButtons),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonButton),{onClick:L},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"close-outline"})]),_:1})]),_:1})]),default:e.withCtx(()=>[e.createVNode(e.unref(G.IonTitle),null,{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(N.value),1)]),_:1})]),_:1}),e.createVNode(e.unref(G.IonToolbar),null,{default:e.withCtx(()=>[e.createElementVNode("div",Kv,[e.createVNode(e.unref(G.IonSegment),{value:i.value,onIonChange:k[0]||(k[0]=J=>E(J.detail.value)),class:"max-w-xs"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonSegmentButton),{value:"recent"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[15]||(k[15]=[e.createTextVNode("Recent",-1)])]),_:1})]),_:1}),t.modelType&&t.modelId?(e.openBlock(),e.createBlock(e.unref(G.IonSegmentButton),{key:0,value:"model"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[16]||(k[16]=[e.createTextVNode("Model",-1)])]),_:1})]),_:1})):e.createCommentVNode("",!0),e.createVNode(e.unref(G.IonSegmentButton),{value:"library"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[17]||(k[17]=[e.createTextVNode("Library",-1)])]),_:1})]),_:1})]),_:1},8,["value"]),e.createVNode(e.unref(G.IonButton),{fill:"clear",size:"small",onClick:k[1]||(k[1]=J=>m.value=!m.value),class:"relative"},{"icon-only":e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"filter-outline"})]),default:e.withCtx(()=>[I.value>0?(e.openBlock(),e.createBlock(e.unref(G.IonBadge),{key:0,color:"primary",class:"absolute -top-1 -right-1 min-w-[20px] h-5 rounded-full flex items-center justify-center text-xs"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(I.value),1)]),_:1})):e.createCommentVNode("",!0)]),_:1})])]),_:1})]),_:1}),e.createVNode(e.unref(G.IonContent),null,{default:e.withCtx(()=>[e.createElementVNode("div",qv,[m.value?(e.openBlock(),e.createElementBlock("div",Jv,[e.createElementVNode("div",Yv,[e.createElementVNode("div",null,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[18]||(k[18]=[e.createTextVNode("Collection",-1)])]),_:1}),e.withDirectives(e.createElementVNode("select",{"onUpdate:modelValue":k[2]||(k[2]=J=>p.value.collection=J),class:"w-full p-2 border rounded"},[k[19]||(k[19]=e.createElementVNode("option",{value:""},"All Collections",-1)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value,J=>(e.openBlock(),e.createElementBlock("option",{key:J,value:J},e.toDisplayString(J),9,Qv))),128))],512),[[e.vModelSelect,p.value.collection]])]),e.createElementVNode("div",null,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[20]||(k[20]=[e.createTextVNode("From Date",-1)])]),_:1}),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":k[3]||(k[3]=J=>p.value.dateFrom=J),type:"date",class:"w-full p-2 border rounded"},null,512),[[e.vModelText,p.value.dateFrom]])]),e.createElementVNode("div",null,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[21]||(k[21]=[e.createTextVNode("To Date",-1)])]),_:1}),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":k[4]||(k[4]=J=>p.value.dateTo=J),type:"date",class:"w-full p-2 border rounded"},null,512),[[e.vModelText,p.value.dateTo]])])]),e.createElementVNode("div",eg,[e.createVNode(e.unref(G.IonButton),{size:"small",onClick:se},{default:e.withCtx(()=>[...k[22]||(k[22]=[e.createTextVNode("Apply",-1)])]),_:1}),e.createVNode(e.unref(G.IonButton),{size:"small",fill:"clear",onClick:xe},{default:e.withCtx(()=>[...k[23]||(k[23]=[e.createTextVNode("Clear",-1)])]),_:1})])])):e.createCommentVNode("",!0),e.createVNode(e.unref(G.IonSearchbar),{modelValue:l.value,"onUpdate:modelValue":k[5]||(k[5]=J=>l.value=J),placeholder:"Search media...",debounce:300,class:"mb-4"},null,8,["modelValue"]),e.createElementVNode("div",tg,[e.createVNode(e.unref(G.IonButtons),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonButton),{fill:r.value==="grid"?"solid":"clear",size:"small",onClick:k[6]||(k[6]=J=>r.value="grid")},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"grid-outline"})]),_:1},8,["fill"]),e.createVNode(e.unref(G.IonButton),{fill:r.value==="list"?"solid":"clear",size:"small",onClick:k[7]||(k[7]=J=>r.value="list")},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"list-outline"})]),_:1},8,["fill"])]),_:1})]),s.value?(e.openBlock(),e.createElementBlock("div",ag,[e.createVNode(e.unref(G.IonSpinner),{name:"crescent"})])):g.value.length===0?(e.openBlock(),e.createElementBlock("div",ng,[e.createVNode(e.unref(G.IonIcon),{name:"images-outline",class:"text-6xl text-theme-secondary mb-4"}),k[24]||(k[24]=e.createElementVNode("h3",{class:"text-lg font-medium text-theme mb-2"}," No Media Found ",-1)),e.createElementVNode("p",og,e.toDisplayString(l.value?"Try adjusting your search":"No media items available"),1)])):r.value==="grid"?(e.openBlock(),e.createBlock(F,{key:3,"media-items":g.value,"selected-items":e.unref(_).selectedItems.value,"is-loading":!1,"selection-mode":!0,columns:{mobile:2,sm:3,md:4,lg:5,xl:6},onToggleSelect:D,onPreview:z,onEdit:O,onDelete:le},null,8,["media-items","selected-items"])):(e.openBlock(),e.createBlock(e.unref(G.IonList),{key:4,lines:"none",class:"rounded-lg overflow-hidden"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(g.value,(J,ce)=>(e.openBlock(),e.createBlock(W,{key:J.uuid,media:J,selected:e.unref(_).isSelected(J.uuid),"selection-mode":!0,index:ce,onToggleSelect:D,onPreview:z,onEdit:O,onDelete:le},null,8,["media","selected","index"]))),128))]),_:1})),!s.value&&g.value.length>0&&i.value!=="model"?(e.openBlock(),e.createBlock(e.unref(G.IonInfiniteScroll),{key:5,threshold:"100px",onIonInfinite:k[8]||(k[8]=J=>P(J))},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonInfiniteScrollContent),{"loading-spinner":"crescent","loading-text":"Loading more media..."})]),_:1})):e.createCommentVNode("",!0)])]),_:1}),e.createVNode(e.unref(G.IonModal),{"is-open":A.value,onDidDismiss:k[14]||(k[14]=J=>A.value=!1)},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonHeader),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonToolbar),null,{end:e.withCtx(()=>[e.createVNode(e.unref(G.IonButtons),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonButton),{onClick:k[9]||(k[9]=J=>A.value=!1)},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"close-outline"})]),_:1})]),_:1})]),default:e.withCtx(()=>[e.createVNode(e.unref(G.IonTitle),null,{default:e.withCtx(()=>[...k[25]||(k[25]=[e.createTextVNode("Edit Media Info",-1)])]),_:1})]),_:1})]),_:1}),e.createVNode(e.unref(G.IonContent),{class:"p-4"},{default:e.withCtx(()=>[C.value?(e.openBlock(),e.createElementBlock("div",ig,[e.createElementVNode("div",rg,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[26]||(k[26]=[e.createTextVNode("Caption",-1)])]),_:1}),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":k[10]||(k[10]=J=>C.value.caption=J),type:"text",class:"w-full p-2 border rounded mt-1",placeholder:"Enter caption..."},null,512),[[e.vModelText,C.value.caption]])]),e.createElementVNode("div",lg,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[27]||(k[27]=[e.createTextVNode("Alt Text",-1)])]),_:1}),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":k[11]||(k[11]=J=>C.value.alt_text=J),type:"text",class:"w-full p-2 border rounded mt-1",placeholder:"Enter alt text..."},null,512),[[e.vModelText,C.value.alt_text]])]),e.createElementVNode("div",sg,[e.createVNode(e.unref(G.IonButton),{onClick:k[12]||(k[12]=J=>K(C.value))},{default:e.withCtx(()=>[...k[28]||(k[28]=[e.createTextVNode("Save",-1)])]),_:1}),e.createVNode(e.unref(G.IonButton),{fill:"clear",onClick:k[13]||(k[13]=J=>A.value=!1)},{default:e.withCtx(()=>[...k[29]||(k[29]=[e.createTextVNode("Cancel",-1)])]),_:1})])])):e.createCommentVNode("",!0)]),_:1})]),_:1},8,["is-open"]),e.createVNode(e.unref(G.IonFooter),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonToolbar),null,{default:e.withCtx(()=>[e.createElementVNode("div",dg,[e.createElementVNode("div",cg,[e.unref(_).selectedCount.value>0?(e.openBlock(),e.createElementBlock("span",ug,[e.createTextVNode(e.toDisplayString(e.unref(_).selectedCount.value)+" selected ",1),t.maxSelection?(e.openBlock(),e.createElementBlock("span",mg," / "+e.toDisplayString(t.maxSelection)+" max ",1)):e.createCommentVNode("",!0)])):(e.openBlock(),e.createElementBlock("span",pg," Select "+e.toDisplayString(t.selectionMode==="multiple"?"items":"an item"),1))]),e.createElementVNode("div",fg,[e.createVNode(e.unref(G.IonButton),{fill:"clear",onClick:L},{default:e.withCtx(()=>[...k[30]||(k[30]=[e.createTextVNode(" Cancel ",-1)])]),_:1}),e.createVNode(e.unref(G.IonButton),{disabled:$.value,onClick:j},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(T.value),1)]),_:1},8,["disabled"])])])]),_:1})]),_:1})]),_:1},8,["is-open"])}}}),vg=Ae(hg,[["__scopeId","data-v-9a8c0954"]]),gg={key:1,class:"flex flex-col items-center justify-center py-16"},bg=["draggable","onDragstart","onDragover","onDrop"],yg={key:0,class:"absolute top-2 left-2 z-20"},wg=["checked","onChange"],kg={key:2,class:"absolute top-2 right-2 z-20 opacity-0 group-hover:opacity-100 transition-opacity cursor-move"},_g=["data-media-id"],Eg={key:0,class:"w-full h-full flex items-center justify-center"},Sg=["src","alt","onError","onLoad"],Cg={key:2,class:"w-full h-full flex items-center justify-center bg-gray-100 dark:bg-gray-700"},xg={class:"text-center"},Ng={class:"text-4xl text-gray-400 mb-2"},Vg={class:"text-sm font-medium text-gray-500"},Tg={class:"absolute inset-0 bg-black/70 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2"},Bg=["onClick"],Mg=["onClick"],Ig=["onClick"],$g={class:"p-3"},Fg={class:"text-sm font-medium truncate mb-1"},Dg={class:"text-xs text-gray-600 dark:text-gray-400"},Ag={key:0},Rg={key:0,class:"text-xs text-gray-500 dark:text-gray-500 mt-1 truncate"},Lg=e.defineComponent({__name:"MediaGrid",props:{mediaItems:{default:()=>[]},selectedItems:{default:()=>[]},isLoading:{type:Boolean,default:!1},selectionMode:{type:Boolean,default:!1},reorderable:{type:Boolean,default:!1},showEditButton:{type:Boolean,default:!1},columns:{default:()=>({mobile:2,sm:3,md:4,lg:5,xl:6})}},emits:["toggleSelect","preview","edit","delete","reorder","upload"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(null),r=e.ref(null),l=e.ref(new Set),s=e.ref(null),d=$=>t.selectedItems.some(N=>N.uuid===$.uuid),c=e.computed(()=>{const $=t.columns,N=["grid","gap-4"];switch($.mobile){case 1:N.push("grid-cols-1");break;case 2:N.push("grid-cols-2");break;case 3:N.push("grid-cols-3");break;case 4:N.push("grid-cols-4");break;default:N.push("grid-cols-2");break}switch($.sm){case 1:N.push("sm:grid-cols-1");break;case 2:N.push("sm:grid-cols-2");break;case 3:N.push("sm:grid-cols-3");break;case 4:N.push("sm:grid-cols-4");break;case 5:N.push("sm:grid-cols-5");break;default:N.push("sm:grid-cols-3");break}switch($.md){case 2:N.push("md:grid-cols-2");break;case 3:N.push("md:grid-cols-3");break;case 4:N.push("md:grid-cols-4");break;case 5:N.push("md:grid-cols-5");break;case 6:N.push("md:grid-cols-6");break;default:N.push("md:grid-cols-4");break}switch($.lg){case 3:N.push("lg:grid-cols-3");break;case 4:N.push("lg:grid-cols-4");break;case 5:N.push("lg:grid-cols-5");break;case 6:N.push("lg:grid-cols-6");break;case 7:N.push("lg:grid-cols-7");break;default:N.push("lg:grid-cols-5");break}switch($.xl){case 4:N.push("xl:grid-cols-4");break;case 5:N.push("xl:grid-cols-5");break;case 6:N.push("xl:grid-cols-6");break;case 7:N.push("xl:grid-cols-7");break;case 8:N.push("xl:grid-cols-8");break;default:N.push("xl:grid-cols-6");break}return N.join(" ")});function u($,N,B){t.reorderable&&(i.value=N,$.dataTransfer&&($.dataTransfer.effectAllowed="move",$.dataTransfer.setData("text/html","")))}function m($,N){t.reorderable&&($.preventDefault(),r.value=N)}function p(){r.value=null}function f($,N){if(!t.reorderable||!i.value)return;$.preventDefault();const B=[...t.mediaItems],P=B.findIndex(x=>{var M;return x.uuid===((M=i.value)==null?void 0:M.uuid)});if(P!==-1&&P!==N&&i.value){const[x]=B.splice(P,1);B.splice(N,0,x),n("reorder",B)}i.value=null,r.value=null}function h($){return $<1024?$+" B":$<1024*1024?($/1024).toFixed(1)+" KB":($/(1024*1024)).toFixed(1)+" MB"}function v($){var B;return $.thumbnail_url||((B=$.conversion_urls)==null?void 0:B.thumb)||$.original_url||$.url||""}function y($){var P,x,M;const N=((P=$.mime_type)==null?void 0:P.startsWith("image/"))||!1,B=!!($.thumbnail_url||(x=$.conversion_urls)!=null&&x.thumb||(M=$.conversion_urls)!=null&&M.preview||$.original_url||$.url);return N&&B}function w($){var N;return((N=$.split(".").pop())==null?void 0:N.toUpperCase())||""}function _($){var B;const N=((B=$.mime_type)==null?void 0:B.toLowerCase())||"";return N.startsWith("image/")?"image":N.startsWith("video/")?"videocam":N.startsWith("audio/")?"musical-notes":N.includes("pdf")?"document-text":N.includes("zip")||N.includes("rar")?"archive":N.includes("sheet")||N.includes("excel")?"grid":N.includes("document")||N.includes("word")?"document-text":"document"}e.onMounted(()=>{typeof window<"u"&&"IntersectionObserver"in window&&(s.value=new IntersectionObserver($=>{$.forEach(N=>{var B;if(N.isIntersecting){const P=N.target.getAttribute("data-media-id");P&&(l.value.add(P),(B=s.value)==null||B.unobserve(N.target))}})},{rootMargin:"50px"}))}),e.onUnmounted(()=>{s.value&&s.value.disconnect()});function b($){return!0}function g(){s.value&&e.nextTick(()=>{document.querySelectorAll("[data-media-id]").forEach(N=>{var P;const B=N.getAttribute("data-media-id");B&&!l.value.has(B)&&((P=s.value)==null||P.observe(N))})})}e.watch(()=>t.mediaItems,()=>{l.value.clear(),g()},{immediate:!0,deep:!0});function I($,N){const B=$.target;delete B.dataset.fallbackIndex}function T($,N){const B=$.target,P=B.closest("[data-media-id]"),x=[N.original_url,N.url,N.thumbnail_url,"preview_url"in N?N.preview_url:void 0].filter(M=>M&&M.trim()!==""&&M!==B.src);if(x.length>0&&B.dataset.fallbackIndex){const M=parseInt(B.dataset.fallbackIndex);if(M<x.length){B.dataset.fallbackIndex=(M+1).toString(),B.src=x[M]||"";return}}else if(x.length>0){B.dataset.fallbackIndex="1",B.src=x[0]||"";return}if(B.style.display="none",P&&!P.querySelector(".media-fallback-icon")){const E=document.createElement("div");E.className="media-fallback-icon w-full h-full flex items-center justify-center bg-gray-100 dark:bg-gray-800",E.innerHTML=`
1
+ "use strict";var Eh=Object.defineProperty;var Sh=(o,a,t)=>a in o?Eh(o,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[a]=t;var ie=(o,a,t)=>Sh(o,typeof a!="symbol"?a+"":a,t);const ml=require("pinia"),e=require("vue"),Ch=require("./imageEditorState-PrcqbsfM.cjs"),jt=require("pixi.js"),de=require("./editor-BDmZ747c.cjs"),la=require("./index-QOKC8XA_.cjs"),G=require("@ionic/vue"),xh=require("pixi-filters");function Nh(o){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(a,t,n.get?n:{enumerable:!0,get:()=>o[t]})}}return a.default=o,Object.freeze(a)}const na=Nh(jt);let Ia={apiBaseUrl:"/api/v1",isAdmin:!1};function vc(o){return typeof o=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(o)}function ai(o){Ia={...Ia,...o}}function im(){return{...Ia}}function rm(o){Ia={...o}}function lm(o){const a=im();return ai(o),()=>{rm(a)}}function Vh(o){const a=o.trim().replace(/\/+$/,"");return a===""?"/api/v1":a.startsWith("/")?a:`/${a}`}function Th(o,a){const t=Vh(a),n=(i,r="")=>{const l=`/api${t}`;return!t.startsWith("/api/")&&i.startsWith(`${l}/`)?`${i.slice(4)}${r}`:!t.startsWith("/api/")&&i===l?`${t}${r}`:`${i}${r}`};if(/^https?:\/\//i.test(o))try{const i=typeof window<"u"?window.location.origin:"http://localhost",r=new URL(o,i);if(r.origin===i)return n(r.pathname,`${r.search}${r.hash}`)}catch{return o}return n(o)}const Bh=async(o,a={})=>{var s;const t=(s=document.querySelector('meta[name="csrf-token"]'))==null?void 0:s.getAttribute("content"),n={Accept:"application/json",...a.headers};t&&(n["X-CSRF-TOKEN"]=t),a.body instanceof FormData||(n["Content-Type"]="application/json");const r={method:a.method||"GET",headers:n,credentials:"include"};a.body instanceof FormData?r.body=a.body:a.body!==void 0&&(r.body=JSON.stringify(a.body));const l=await fetch(o,r);if(!l.ok){const d=await l.json().catch(()=>({message:"Request failed"}));throw new Error(d.message||`HTTP ${l.status}`)}if(l.status!==204)return await l.json()},ja=ml.defineStore("media",()=>{const o=e.ref([]),a=e.ref([]),t=e.ref(!1),n=e.ref(null),i=e.ref(1),r=e.ref(1),l=e.ref(24),s=e.ref({type:null,uuid:null}),d=e.ref([]),c=e.ref(!1),u=e.ref(null),m=e.ref(new Map),p=e.ref(new Map),f=e.ref(new Set),h=e.ref(new Map),v=e.ref({}),y=5*60*1e3,w=e.computed(()=>{if(Ia.apiScope)return Ia.apiScope;if(Ia.isAdmin)return"admin"}),_=e.computed(()=>w.value==="admin");function b(){return Ia.httpClient||Bh}function g(be){const _e=Ia.apiBaseUrl||"/api/v1",ye=w.value?`/${w.value}`:"";return`${_e}${ye}${be}`}function I(be){return`${Ia.apiBaseUrl||"/api/v1"}${be}`}function T(be,_e){return`${w.value??"default"}-${be}-${JSON.stringify(_e)}`}function $(be){return Date.now()-be<y}function N(){h.value.clear(),v.value={}}function B(be){if(!be||!be.data)return;const _e={};be.data.forEach(ye=>{const Ne=`${ye.file_name}-${ye.collection_name||"default"}`,Se=_e[Ne];(!Se||Object.keys(ye.generated_conversions||{}).length>Object.keys(Se.generated_conversions||{}).length)&&(_e[Ne]=ye)}),o.value=Object.values(_e),be.meta&&(i.value=be.meta.current_page,r.value=Math.ceil(be.meta.total/be.meta.per_page))}async function P(be=1,_e={}){const ye=T(be,_e),Ne=h.value.get(ye);if(Ne&&$(Ne.timestamp)){const Se=Ne.data;return B(Se),Se}t.value=!0,n.value=null;try{const Se=new URLSearchParams;Se.append("page",be.toString()),Se.append("per_page",l.value.toString()),_.value&&Se.append("linked","1");for(const it in _e)if(Object.prototype.hasOwnProperty.call(_e,it)){const rt=_e[it];rt!=null&&rt!==""&&Se.append(it,String(rt))}const Oe=await b()(g(`/media?${Se}`));return h.value.set(ye,{data:Oe,timestamp:Date.now()}),B(Oe),Oe}catch(Se){throw n.value=Se instanceof Error?Se.message:"Failed to fetch media",o.value=[],new Error(n.value)}finally{t.value=!1}}async function x(be,_e){t.value=!0,n.value=null;const ye=`${be.name}-${Date.now()}`,Ne={file:be,progress:0,status:"uploading"};m.value.set(ye,Ne);try{const Se=new FormData;Se.append("file",be),Se.append("collection",_e.collection),_e.ownerUuid&&(Se.append("owner_uuid",_e.ownerUuid),Se.append("owner_type",_e.ownerType||"")),_e.usageUuid&&(Se.append("usage_uuid",_e.usageUuid),Se.append("usage_type",_e.usageType||""),Se.append("usage_purpose",_e.usagePurpose||"")),_e.customProperties&&Se.append("custom_properties",JSON.stringify(_e.customProperties));const Oe=await b()(g("/media"),{method:"POST",body:Se});return Ne.status="completed",Ne.progress=100,Ne.media=Oe==null?void 0:Oe.data,i.value===1&&(Oe!=null&&Oe.data)&&(o.value=[Oe.data,...o.value]),N(),(Oe==null?void 0:Oe.data)||null}catch(Se){throw Ne.status="error",Ne.error=Se instanceof Error?Se.message:"Upload failed",n.value=Ne.error,new Error(n.value)}finally{t.value=!1,setTimeout(()=>{m.value.delete(ye)},5e3)}}async function M(be){t.value=!0,n.value=null;const _e=o.value.findIndex(Ne=>Ne.uuid===be);let ye;_e!==-1&&(ye=o.value.splice(_e,1)[0]);try{return await b()(g(`/media/${be}`),{method:"DELETE"}),f.value.delete(be),N(),!0}catch(Ne){throw ye&&_e!==-1&&o.value.splice(_e,0,ye),n.value=Ne instanceof Error?Ne.message:"Failed to delete media",new Error(n.value)}finally{t.value=!1}}async function E(be,_e){t.value=!0,n.value=null;try{const Ne=await b()(g(`/media/${be}`),{method:"PATCH",body:_e,data:_e});if(Ne!=null&&Ne.data){const Se=o.value.findIndex(Re=>Re.uuid===be);return Se!==-1&&(o.value[Se]={...o.value[Se],...Ne.data}),N(),Ne.data}return null}catch(ye){throw n.value=ye instanceof Error?ye.message:"Failed to update media",new Error(n.value)}finally{t.value=!1}}async function D(){t.value=!0,n.value=null;try{const _e=await b()(g("/media/collections"));return a.value=(_e==null?void 0:_e.data)||[],a.value}catch(be){throw n.value=be instanceof Error?be.message:"Failed to fetch collections",a.value=[],new Error(n.value)}finally{t.value=!1}}async function j(be,_e,ye="images",Ne){c.value=!0,u.value=null;try{const Se=new URLSearchParams;Se.append("collection",ye),Ne&&Se.append("search",Ne);const Oe=await b()(g(`/media/model/${be}/${_e}?${Se}`));return Oe!=null&&Oe.data?(d.value=Oe.data,Oe.data):[]}catch(Se){throw u.value=Se instanceof Error?Se.message:"Failed to fetch model media",d.value=[],new Error(u.value)}finally{c.value=!1}}async function L(be,_e,ye,Ne="images"){c.value=!0,u.value=null;const Se=[...d.value];try{const Oe=await b()(g(`/media/model/${be}/${_e}/attach`),{method:"POST",body:{media_uuids:ye,collection:Ne}});return await j(be,_e,Ne),(Oe==null?void 0:Oe.data)||[]}catch(Re){throw d.value=Se,u.value=Re instanceof Error?Re.message:"Failed to attach media",new Error(u.value)}finally{c.value=!1}}async function z(be,_e,ye,Ne="images"){c.value=!0,u.value=null;const Se=[...d.value];d.value=d.value.filter(Re=>Re.uuid!==ye);try{return await b()(g(`/media/model/${be}/${_e}/detach`),{method:"POST",body:{media_uuid:ye,collection:Ne}}),!0}catch(Re){throw d.value=Se,u.value=Re instanceof Error?Re.message:"Failed to detach media",new Error(u.value)}finally{c.value=!1}}async function C(be,_e,ye,Ne="images"){c.value=!0,u.value=null;const Se=[...d.value],Re=new Map(d.value.map(Oe=>[Oe.uuid,Oe]));d.value=ye.map(Oe=>Re.get(Oe)).filter(Oe=>Oe!==void 0);try{return await b()(g(`/media/model/${be}/${_e}/reorder`),{method:"POST",body:{media_uuids:ye,collection:Ne}}),!0}catch(Oe){throw d.value=Se,u.value=Oe instanceof Error?Oe.message:"Failed to reorder media",new Error(u.value)}finally{c.value=!1}}async function A(be,_e,ye={}){var pt,Nt;const Ne=b(),Se=Ia.apiBaseUrl||"/api/v1";let Re=vc(_e.documentId)?_e.documentId:vc((pt=_e.document)==null?void 0:pt.id)?_e.document.id:null,Oe=_e.documentRevisionId??null,it=typeof _e.documentRevisionNumber=="number"?_e.documentRevisionNumber:typeof((Nt=_e.document)==null?void 0:Nt.revision)=="number"?_e.document.revision:null;if(_e.document){const Ce=await Ne(`${Se}/media/${be}/editor-documents/materialize`,{method:"POST",body:{document_id:Re,base_document_revision:it,document:_e.document}});Re=Ce.document_id,Oe=Ce.document_revision_id,it=Ce.document_revision_number}if(_e.document&&Re&&Oe&&typeof it=="number"){const Ce=new FormData,Le=(_e.mimeType||_e.blob.type||"image/png")==="image/jpeg"?"jpg":"png";Ce.append("flattened_file",_e.blob,`edited.${Le}`),Ce.append("document_id",Re),Ce.append("document_revision_id",Oe),Ce.append("expected_document_revision",String(it)),Ce.append("output_mode",ye.asVariant?"save-as-variant":"save-as-new");const nt=await Ne(`${Se}/media/${be}/editor-documents/save`,{method:"POST",body:Ce});if(nt.media)return nt.media;throw new Error("Unexpected response from layered editor save endpoint")}const rt=new FormData,bt=(_e.mimeType||_e.blob.type||"image/png")==="image/jpeg"?"jpg":"png";rt.append("image_file",_e.blob,`edited.${bt}`);const Ct=Ch.serializeEditorState(_e.state);Ct&&rt.append("editor_state",Ct),rt.append("save_as_new","true"),ye.asVariant&&rt.append("as_variant","true"),ye.name!==void 0&&rt.append("name",ye.name);const mt=await Ne(`${Se}/editor/${be}/save`,{method:"POST",body:rt});if("media"in mt&&mt.media)return mt.media;if("status_url"in mt&&mt.status_url)return O(Ne,Th(mt.status_url,Se),ye.pollTimeout??6e4);throw new Error("Unexpected response from editor save endpoint")}async function O(be,_e,ye){const Ne=Date.now(),Se=2e3;for(;Date.now()-Ne<ye;){await new Promise(Oe=>setTimeout(Oe,Se));const Re=await be(_e);if(Re.status==="completed"&&Re.media)return Re.media;if(Re.status==="failed")throw new Error(Re.error??"Image processing failed")}throw new Error("Image processing timed out")}function K(be,_e,ye){s.value=ye!==void 0?{type:be,uuid:_e,collection:ye}:{type:be,uuid:_e},v.value[`${be}-${_e}`]={timestamp:Date.now()}}function se(){s.value={type:null,uuid:null},d.value=[],u.value=null}async function xe(){if(!s.value.type||!s.value.uuid)return;const be=await j(s.value.type,s.value.uuid,s.value.collection||"images");d.value=be||[]}function ue(){o.value.forEach(be=>f.value.add(be.uuid))}function le(){f.value.clear()}function Z(be){f.value.has(be)?f.value.delete(be):f.value.add(be)}function k(be){return f.value.has(be)}function F(){return Array.from(m.value.values()).some(be=>be.status==="uploading")}function W(be){return m.value.get(be)||p.value.get(be)}function J(){return[...Array.from(m.value.values()),...Array.from(p.value.values())]}async function ce(){const be=Array.from(f.value);let _e=0;for(const ye of be)try{await M(ye),_e++}catch{}return le(),_e}function Ue(be,_e){var ye;return _e&&((ye=be.conversion_urls)!=null&&ye[_e])?be.conversion_urls[_e]||"":be.original_url||be.url||""}return{items:o,collections:a,loading:t,error:n,currentPage:i,totalPages:r,itemsPerPage:l,isAdmin:_,modelContext:s,modelMedia:d,isLoadingModelMedia:c,modelMediaError:u,selectedItems:f,uploadProgress:m,uploadQueue:p,cachedResponses:v,fetchMedia:P,uploadFile:x,deleteMedia:M,updateMedia:E,clearCache:N,fetchCollections:D,fetchModelMedia:j,attachMedia:L,detachMedia:z,reorderMedia:C,saveEditedImage:A,setModelContext:K,clearModelContext:se,refreshModelMedia:xe,selectAllItems:ue,clearSelection:le,toggleSelection:Z,isSelected:k,deleteSelectedItems:ce,getHttpClient:b,getApiUrl:g,getEditorApiUrl:I,hasActiveUploads:F,getUploadProgress:W,getAllUploadProgress:J,getMediaUrl:Ue}}),sm=()=>((Ia.apiScope!=="admin"||Ia.isAdmin!==!0)&&ai({...Ia,apiScope:"admin",isAdmin:!0}),ja());class dm{constructor(a,t){this.state=a,this.editor=t,this.element=null,this._tabs=new Map,this._unsubscribers=[],this._onSelect=null}render({onSelect:a}={}){return this._onSelect=a,this.element=de.el("div",{className:"panel-tabs",role:"tablist","aria-label":"Filter categories","data-testid":"v2-category-tabs"}),de.EDITOR_CATEGORIES.forEach(t=>{const n=de.el("button",{type:"button",className:`panel-tab ${this._isSelected(t.id)?"active":""}`,role:"tab","aria-selected":this._isSelected(t.id)?"true":"false","data-category":t.id,"data-testid":`v2-category-${t.id}`,onClick:()=>this._selectCategory(t.id)});if(t.icon){const i=de.el("span",{className:"panel-tab-icon","aria-hidden":"true"});i.innerHTML=t.icon,n.appendChild(i)}n.appendChild(de.el("span",{className:"panel-tab-label"},t.name)),this._tabs.set(t.id,n),this.element.appendChild(n)}),this._unsubscribers.push(this.state.on("change:selectedCategory",()=>this._refreshActive())),this.element}_isSelected(a){const t=this.state.get("selectedCategory");return a==="crop"?this.state.get("mode")==="crop":t===a&&this.state.get("mode")!=="crop"}_selectCategory(a){var n;this.state.set("selectedCategory",a);const t=this.state.get("mode");a==="crop"?t!=="crop"&&this.editor.setMode("crop"):t!=="filters"&&this.editor.setMode("filters"),this._refreshActive(),(n=this._onSelect)==null||n.call(this,a)}_refreshActive(){this._tabs.forEach((a,t)=>{const n=this._isSelected(t);a.classList.toggle("active",n),a.setAttribute("aria-selected",n?"true":"false")})}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._tabs.clear(),(a=this.element)==null||a.remove(),this.element=null}}class cm{constructor(a,t){this.state=a,this.filterManager=t,this.element=null,this._unsubscribers=[],this._onToggle=null,this._onSelect=null}render({onToggle:a,onSelect:t}={}){return this._onToggle=a,this._onSelect=t,this.element=de.el("div",{className:"filter-list",role:"listbox","aria-label":"Filters","data-testid":"v2-filter-list"}),this._renderRows(),this._unsubscribers.push(this.state.on("change:selectedCategory",()=>this._renderRows()),this.state.on("change:activeFilters",()=>this._renderRows()),this.state.on("change:selectedFilter",()=>this._renderRows()),this.state.on("change:filterValues",()=>this._refreshSummaries())),this.element}_renderRows(){this.element.innerHTML="";const a=this.state.get("selectedCategory");if(!a||a==="crop")return;const t=this.filterManager.getFiltersByCategory(a),n=this.state.get("activeFilters"),i=this.state.get("selectedFilter"),r=typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId");t.forEach(l=>{var c;const s=((c=n==null?void 0:n.has)==null?void 0:c.call(n,l.id))??!1,d=i===l.id;this.element.appendChild(this._renderRow(l,s,d,r))})}_renderRow(a,t,n,i=null){const r=de.el("button",{type:"button",className:`filter-row ${n?"selected":""}`,role:"option","aria-selected":n?"true":"false","data-filter":a.id,"data-testid":`v2-filter-${a.id}`,onClick:()=>{var u;return(u=this._onSelect)==null?void 0:u.call(this,a.id,i)}}),l=de.el("button",{type:"button",className:`filter-row-toggle ${t?"active":""}`,"aria-label":`${t?"Disable":"Enable"} ${a.name}`,"aria-pressed":t?"true":"false","data-testid":`v2-filter-toggle-${a.id}`,onClick:u=>{var p,f,h,v;u.stopPropagation();const m=!((f=(p=this.state.get("activeFilters"))==null?void 0:p.has)!=null&&f.call(p,a.id));(h=this._onToggle)==null||h.call(this,a.id,m,i),m&&((v=this._onSelect)==null||v.call(this,a.id,i))}});t&&(l.innerHTML=de.checkmark),r.appendChild(l);const s=de.el("div",{className:"filter-row-body"});s.appendChild(de.el("span",{className:"filter-row-name"},a.name));const d=this._buildSummary(a,t);d&&s.appendChild(de.el("span",{className:"filter-row-summary"},d)),r.appendChild(s);const c=de.el("span",{className:"filter-row-chevron","aria-hidden":"true"});return c.innerHTML=de.chevronRight,r.appendChild(c),r}_buildSummary(a,t){if(!t)return a.description||"";const n=this.state.getFilterValues(a.id);if(!n||Object.keys(n).length===0)return a.description||"Active";const i=[];for(const r of(a.controls||[]).slice(0,4)){const l=n[r.id];if(!(l===void 0||l===r.default)&&(i.push(this._formatControlValue(r,l)),i.length>=2))break}return i.length===0?"Active":i.join(" · ")}_formatControlValue(a,t){return a.type==="toggle"?a.label:typeof t=="number"?(a.max??1)<=1&&(a.min??0)>=0?`${a.label} ${Math.round(t*100)}%`:Number.isInteger(t)?`${a.label} ${t}`:`${a.label} ${t.toFixed(2)}`:typeof t=="string"?`${a.label}`:a.label}_refreshSummaries(){var i;const a=this.state.get("selectedCategory");if(!a||a==="crop")return;const t=this.filterManager.getFiltersByCategory(a),n=this.state.get("activeFilters");for(const r of t){const l=this.element.querySelector(`[data-filter="${r.id}"]`);if(!l)continue;const s=((i=n==null?void 0:n.has)==null?void 0:i.call(n,r.id))??!1,d=this._buildSummary(r,s),c=l.querySelector(".filter-row-summary");if(d&&c)c.textContent=d;else if(d&&!c){const u=l.querySelector(".filter-row-body");u==null||u.appendChild(de.el("span",{className:"filter-row-summary"},d))}else!d&&c&&c.remove()}}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}class um{constructor(a,t){this.state=a,this.filterManager=t,this.element=null,this._unsubscribers=[],this._onChange=null,this._onReset=null,this._onAction=null}render({onChange:a,onReset:t,onAction:n}={}){return this._onChange=a,this._onReset=t,this._onAction=n,this.element=de.el("div",{className:"controls-section","data-testid":"v2-controls-section"}),this._renderControls(),this._unsubscribers.push(this.state.on("change:selectedFilter",()=>this._renderControls()),this.state.on("change:activeFilters",()=>this._renderControls())),this.element}_renderControls(){this.element.innerHTML="";const a=this.state.get("selectedFilter");if(!a){this.element.appendChild(de.el("div",{className:"no-filter-selected"},"Select a filter to adjust"));return}const t=typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId"),n=this.filterManager.getFilterDef(a);if(!n){this.element.appendChild(de.el("div",{className:"no-filter-selected"},"Filter not found"));return}const i=de.el("div",{className:"controls-header"});i.appendChild(de.el("span",{className:"controls-title"},n.name)),i.appendChild(de.createButton({label:"Reset",className:"btn-text",onClick:()=>this._handleReset(a,t)})),this.element.appendChild(i);const r=de.el("div",{className:"controls-grid"}),l=this.state.getFilterValues(a);(n.controls||[]).forEach(d=>{if(d.hidden)return;const c=this._createControl(a,d,l[d.id]??d.default,t);c&&r.appendChild(c)});const s=this.filterManager.getInstance(a);if(s&&typeof s.getDynamicControls=="function"){let d=[];try{d=s.getDynamicControls()||[]}catch{}d.forEach(c=>{const u=c.property||c.id,m=l[u]??c.default,p=this._createControl(a,c,m,t);p&&r.appendChild(p)})}this.element.appendChild(r)}_createControl(a,t,n,i=null){if(t.hidden)return null;const r=t.label||t.id,l=this._normalizeControlType(t.type),s=t.property||t.id;switch(l){case"slider":return de.createSlider({id:`v2-${a}-${t.id}`,label:r,min:t.min??0,max:t.max??1,step:t.step??.01,value:typeof n=="number"?n:t.default??0,onChange:d=>{var c;return(c=this._onChange)==null?void 0:c.call(this,a,s,d,i)}});case"toggle":return de.createToggle({id:`v2-${a}-${t.id}`,label:r,checked:!!n,onChange:d=>{var c;return(c=this._onChange)==null?void 0:c.call(this,a,s,d,i)}});case"color":return de.createColorPicker({id:`v2-${a}-${t.id}`,label:r,value:typeof n=="string"&&n.startsWith("#")?n:t.default||"#000000",onChange:d=>{var c;return(c=this._onChange)==null?void 0:c.call(this,a,s,d,i)}});case"select":{const d=(t.options||[]).map(c=>typeof c=="object"&&c.value!==void 0?{value:c.value,label:c.label||String(c.value)}:{value:c,label:String(c)});return de.createSelect({id:`v2-${a}-${t.id}`,label:r,options:d,value:n??t.default,onChange:c=>{var u;return(u=this._onChange)==null?void 0:u.call(this,a,s,c,i)}})}case"text":return de.createTextInput({id:`v2-${a}-${t.id}`,label:r,value:typeof n=="string"?n:t.default??"",placeholder:t.placeholder||"",onCommit:d=>{var c;return(c=this._onChange)==null?void 0:c.call(this,a,s,d,i)}});case"button":{const d=de.el("div",{className:"button-control"});return d.appendChild(de.createButton({label:r,className:"btn-secondary",onClick:()=>{var c;(c=this._onAction)==null||c.call(this,a,t.action||t.id,i),this._renderControls()}})),d}default:return null}}_normalizeControlType(a){return{slider:"slider",range:"slider",toggle:"toggle",checkbox:"toggle",color:"color",select:"select",dropdown:"select",button:"button",text:"text"}[a]||a}_handleReset(a,t=null){var n;(n=this._onReset)==null||n.call(this,a,t),this._renderControls()}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}class Mh{constructor(a,t){this.state=a,this.filterManager=t,this.element=null,this._unsubscribers=[],this._onRemove=null,this._onSelect=null,this._onClearAll=null}render({onRemove:a,onSelect:t,onClearAll:n}={}){return this._onRemove=a,this._onSelect=t,this._onClearAll=n,this.element=de.el("div",{className:"panel-section","data-testid":"v2-active-stack"}),this._renderContents(),this._unsubscribers.push(this.state.on("change:activeFilters",()=>this._renderContents()),this.state.on("change:selectedFilter",()=>this._refreshSelection())),this.element}_renderContents(){this.element.innerHTML="";const a=this.state.get("activeFilters"),t=(a==null?void 0:a.size)??0,n=this._activeFilterLayerId(),i=de.el("div",{className:"panel-section-title"});if(i.appendChild(de.el("span",{},`Active (${t})`)),t>0&&this._onClearAll&&i.appendChild(de.el("button",{type:"button",className:"btn btn-text",style:{padding:"2px 8px",fontSize:"11px"},"data-testid":"v2-clear-all",onClick:()=>{var s;return(s=this._onClearAll)==null?void 0:s.call(this,n)}},"Clear all")),this.element.appendChild(i),t===0){this.element.appendChild(de.el("div",{className:"active-empty"},"No filters applied"));return}const r=de.el("div",{className:"active-stack"}),l=this.state.get("selectedFilter");for(const s of a){const d=this.filterManager.getFilterDef(s);d&&r.appendChild(this._renderChip(d,s===l,n))}this.element.appendChild(r)}_renderChip(a,t,n=null){const i=de.el("div",{className:`active-chip ${t?"selected":""}`,"data-filter":a.id,"data-testid":`v2-active-${a.id}`});i.appendChild(de.el("button",{type:"button",className:"active-chip-name","aria-label":`Select ${a.name}`,onClick:()=>{var l;return(l=this._onSelect)==null?void 0:l.call(this,a.id,n)}},a.name));const r=de.el("button",{type:"button",className:"active-chip-remove","aria-label":`Remove ${a.name}`,"data-testid":`v2-active-remove-${a.id}`,onClick:()=>{var l;return(l=this._onRemove)==null?void 0:l.call(this,a.id,n)}});return r.innerHTML=de.close,i.appendChild(r),i}_activeFilterLayerId(){return typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId")}_refreshSelection(){var n;const a=this.state.get("selectedFilter"),t=(n=this.element)==null?void 0:n.querySelectorAll(".active-chip");t&&t.forEach(i=>{const r=i.getAttribute("data-filter");i.classList.toggle("selected",r===a)})}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}const Zo=["collapsed","half","full"];class Ih{constructor(a={}){this._onSnapChange=a.onSnapChange||null,this._ariaLabel=a.ariaLabel||"Filter controls drawer",this.element=null,this._handle=null,this._body=null,this._headerSlot=null,this._snap="half",this._dragging=!1,this._dragStartY=0,this._dragStartHeight=0,this._dragPointerId=null,this._containerHeight=0}build({header:a,body:t}={}){this.element=de.el("div",{className:"editor-v2-drawer",role:"dialog","aria-label":this._ariaLabel,"data-testid":"v2-bottom-drawer","data-snap":this._snap}),this._handle=de.el("button",{type:"button",className:"drawer-handle","aria-label":"Drag to resize filters drawer","aria-expanded":this._snap==="full"?"true":"false","data-testid":"v2-drawer-handle"});const n=de.el("span",{className:"drawer-handle-grip","aria-hidden":"true"});return this._handle.appendChild(n),this._handle.addEventListener("click",i=>{if(this._wasDragging){this._wasDragging=!1,i.preventDefault();return}this._cycleSnap()}),this._handle.addEventListener("pointerdown",i=>this._onPointerDown(i)),this._handle.addEventListener("pointermove",i=>this._onPointerMove(i)),this._handle.addEventListener("pointerup",i=>this._onPointerEnd(i)),this._handle.addEventListener("pointercancel",i=>this._onPointerEnd(i)),this.element.appendChild(this._handle),this._headerSlot=de.el("div",{className:"drawer-header"}),a&&this._headerSlot.appendChild(a),this.element.appendChild(this._headerSlot),this._body=de.el("div",{className:"drawer-body"}),t&&this._body.appendChild(t),this.element.appendChild(this._body),this.element}updateContainerHeight(a){this._containerHeight=Math.max(0,Number(a)||0),this._applySnap(this._snap,{animate:!1})}snapTo(a,t={}){Zo.includes(a)&&this._applySnap(a,{animate:t.animate!==!1})}get snap(){return this._snap}setBodyContent(a){this._body&&(this._body.innerHTML="",a&&this._body.appendChild(a))}setHeaderContent(a){this._headerSlot&&(this._headerSlot.innerHTML="",a&&this._headerSlot.appendChild(a))}_onPointerDown(a){var t,n,i;if(!(a.button!==void 0&&a.button!==0)){this._dragging=!0,this._wasDragging=!1,this._dragPointerId=a.pointerId,this._dragStartY=a.clientY,this._dragStartHeight=((t=this.element)==null?void 0:t.offsetHeight)||0;try{(i=(n=this._handle)==null?void 0:n.setPointerCapture)==null||i.call(n,a.pointerId)}catch{}this.element&&(this.element.style.transition="none")}}_onPointerMove(a){if(!this._dragging||a.pointerId!==this._dragPointerId)return;const t=a.clientY-this._dragStartY,n=this._dragStartHeight-t;this._containerHeight||window.innerHeight;const i=this._heightForSnap("collapsed"),r=this._heightForSnap("full"),l=Math.max(i,Math.min(r,n));this.element&&(this.element.style.height=`${l}px`),Math.abs(t)>4&&(this._wasDragging=!0),a.preventDefault()}_onPointerEnd(a){var i,r,l;if(!this._dragging)return;this._dragging=!1;try{(r=(i=this._handle)==null?void 0:i.releasePointerCapture)==null||r.call(i,a.pointerId)}catch{}this._dragPointerId=null;const t=((l=this.element)==null?void 0:l.offsetHeight)||0,n=this._nearestSnap(t);this._applySnap(n,{animate:!0})}_cycleSnap(){const a=Zo.indexOf(this._snap),t=Zo[(a+1)%Zo.length];this._applySnap(t,{animate:!0})}_heightForSnap(a){const t=this._containerHeight||window.innerHeight||600;switch(a){case"collapsed":return 80;case"half":return Math.round(t*.45);case"full":return Math.round(t*.85);default:return Math.round(t*.45)}}_nearestSnap(a){let t=Zo[0],n=1/0;for(const i of Zo){const r=this._heightForSnap(i),l=Math.abs(r-a);l<n&&(n=l,t=i)}return t}_applySnap(a,{animate:t}){var r,l;if(!this.element)return;const n=this._snap;this._snap=a;const i=typeof window<"u"&&((r=window.matchMedia)==null?void 0:r.call(window,"(prefers-reduced-motion: reduce)").matches);t&&!i?this.element.style.transition="height 0.25s cubic-bezier(0.33, 1, 0.68, 1)":this.element.style.transition="none",this.element.style.height=`${this._heightForSnap(a)}px`,this.element.dataset.snap=a,this._handle&&this._handle.setAttribute("aria-expanded",a==="full"?"true":"false"),a!==n&&((l=this._onSnapChange)==null||l.call(this,a,n))}destroy(){var a;(a=this.element)==null||a.remove(),this.element=null,this._handle=null,this._body=null,this._headerSlot=null}}const $h=[{id:"warm",label:"Warm",ariaLabel:"Apply warm gradient background",style:"linear-gradient(135deg, #101820 0%, #f2aa4c 100%)",fill:{gradientType:"linear",angle:135,stops:[{offset:0,color:"#101820"},{offset:1,color:"#f2aa4c"}]}},{id:"cool",label:"Cool",ariaLabel:"Apply cool gradient background",style:"linear-gradient(135deg, #0f766e 0%, #38bdf8 100%)",fill:{gradientType:"linear",angle:135,stops:[{offset:0,color:"#0f766e"},{offset:1,color:"#38bdf8"}]}},{id:"neutral",label:"Neutral",ariaLabel:"Apply neutral gradient background",style:"linear-gradient(135deg, #27272a 0%, #d4d4d8 100%)",fill:{gradientType:"linear",angle:135,stops:[{offset:0,color:"#27272a"},{offset:1,color:"#d4d4d8"}]}}];class mm{constructor(a,t){this.state=a,this.editor=t,this.element=null,this._errorMessage=null,this._unsubscribers=[]}render(){return this.element=de.el("div",{className:"background-panel","data-testid":"v2-background-panel"}),this._render(),this._unsubscribers.push(this.state.on("change:layers",()=>this._render())),this.element}_render(){var f,h,v;if(!this.element)return;this.element.innerHTML="";const a=this._backgroundLayer(),t=a!=null&&a.fill&&typeof a.fill=="object"?a.fill:{kind:"transparent"},n=typeof t.fit=="string"?t.fit:"cover",i=this._backgroundBlur(a),r=(a==null?void 0:a.locked)===!0,l=t.kind==="color"&&typeof t.value=="string"?t.value:"#ffffff";this.element.appendChild(de.el("div",{className:"panel-section-title"},de.el("span",{},"Background"))),this._errorMessage&&this.element.appendChild(de.el("p",{className:"background-panel-error",role:"alert","data-testid":"v2-background-error"},this._errorMessage));const s=de.el("input",{type:"color",className:"color-input",value:l,disabled:r?"disabled":void 0,"aria-label":"Background color","data-testid":"v2-background-color",onInput:y=>{this._runAction(this.editor.setBackgroundColor(y.target.value))}});this.element.appendChild(this._field("Color",s));const d=de.el("div",{className:"background-gradient-grid"});for(const y of $h){const w=de.el("button",{type:"button",className:"background-gradient-swatch",style:{background:y.style},"aria-label":y.ariaLabel,disabled:r?"disabled":void 0,"data-testid":`v2-background-gradient-${y.id}`,onClick:()=>{this._runAction(this.editor.setBackgroundGradient(y.fill))}},de.el("span",{className:"background-gradient-label"},y.label));d.appendChild(w)}this.element.appendChild(this._field("Gradient",d));const c=de.el("input",{type:"file",accept:"image/*",className:"background-upload-input",disabled:r?"disabled":void 0,"aria-label":"Upload background image","data-testid":"v2-background-upload",onChange:y=>{var _;const w=(_=y.target.files)==null?void 0:_[0];w&&this._runAction(this.editor.setBackgroundImageFromFile(w,{fit:n})),y.target.value=""}});this.element.appendChild(this._field("Upload",c));const u=(v=(h=(f=this.editor)==null?void 0:f._options)==null?void 0:h.backgroundReplacement)==null?void 0:v.mediaChoices;if(Array.isArray(u)&&u.length>0){const y=de.el("div",{className:"background-media-grid"});for(const w of u)w!=null&&w.source&&y.appendChild(de.el("button",{type:"button",className:"background-media-choice","aria-label":`Use ${w.label||"media"} as background`,disabled:r?"disabled":void 0,"data-testid":`v2-background-media-${w.id||w.source.mediaUuid||"choice"}`,onClick:()=>{this._runAction(this.editor.setBackgroundMediaSource(w.source,{fit:w.fit||n}))}},w.label||"Media"));this.element.appendChild(this._field("Media",y))}const m=de.el("select",{className:"select-input",disabled:r?"disabled":void 0,"aria-label":"Background image fit","data-testid":"v2-background-fit",onChange:y=>{this._runAction(this.editor.setBackgroundFit(y.target.value))}},this._option("cover","Cover",n),this._option("contain","Contain",n),this._option("stretch","Stretch",n),this._option("tile","Tile",n));this.element.appendChild(this._field("Fit",m));const p=de.el("input",{type:"range",min:"0",max:"40",step:"1",value:String(i),className:"range-input",disabled:r?"disabled":void 0,"aria-label":"Background blur","data-testid":"v2-background-blur",onInput:y=>{this._runAction(this.editor.setBackgroundBlur(Number(y.target.value)))}});this.element.appendChild(this._field("Blur",p)),this.element.appendChild(de.el("button",{type:"button",className:"btn btn-secondary background-remove-btn","aria-label":"Remove background layer",disabled:r?"disabled":void 0,"data-testid":"v2-background-remove",onClick:()=>{this._runAction(this.editor.removeBackgroundLayer())}},"Remove"))}_runAction(a){this._errorMessage=null,Promise.resolve(a).catch(t=>{var i,r;const n=t instanceof Error?t:new Error(String(t));this._errorMessage=n.message||"Background update failed",(r=(i=this.editor)==null?void 0:i.emit)==null||r.call(i,"error",n),this._render()})}_field(a,t){return de.el("label",{className:"background-field"},de.el("span",{className:"background-field-label"},a),t)}_option(a,t,n){return de.el("option",{value:a,selected:n===a?"selected":void 0},t)}_backgroundLayer(){const a=this.state.get("layers");return Array.isArray(a)?a.find(t=>(t==null?void 0:t.type)==="background"||(t==null?void 0:t.role)==="background")??null:null}_backgroundBlur(a){var r;const n=(Array.isArray(a==null?void 0:a.effects)?a.effects:[]).find(l=>(l==null?void 0:l.id)==="background-blur"),i=Number((r=n==null?void 0:n.params)==null?void 0:r.amount);return Number.isFinite(i)?i:0}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}class pm{constructor(a,t){this.state=a,this.editor=t,this.element=null,this._listEl=null,this._unsubscribers=[]}render(){return this.element=de.el("section",{className:"layer-stack-panel",role:"region","aria-label":"Layers","data-order":"bottom-to-top","data-testid":"v2-layer-stack-panel"}),this.element.appendChild(de.el("div",{className:"layer-stack-header"},de.el("span",{className:"layer-stack-title"},"Layers"),de.el("span",{className:"layer-stack-order"},"Bottom to top"))),this._listEl=de.el("div",{className:"layer-stack-list",role:"listbox","aria-label":"Layer order, bottom to top"}),this.element.appendChild(this._listEl),this._renderRows(),this._unsubscribers.push(this.state.on("change:layers",()=>this._renderRows()),this.state.on("change:activeLayerId",()=>this._renderRows())),this.element}_layers(){const a=this.state.get("layers");return Array.isArray(a)?a:[]}_renderRows(){if(!this._listEl)return;this._listEl.innerHTML="";const a=this._layers();if(!a.length){this._listEl.appendChild(de.el("div",{className:"layer-stack-empty",role:"status"},"No layers"));return}a.forEach((t,n)=>{this._listEl.appendChild(this._row(t,n,a.length))})}_row(a,t,n){const i=String((a==null?void 0:a.id)??""),r=this._layerName(a),l=(a==null?void 0:a.visible)!==!1,s=(a==null?void 0:a.locked)===!0,d=this.state.get("activeLayerId")===i,c=[d?"active":null,l?"visible":"hidden",s?"locked":"unlocked"].filter(Boolean).join(", "),u=de.el("div",{className:`layer-row${d?" active":""}${l?"":" hidden"}${s?" locked":""}`,role:"option","aria-selected":d?"true":"false","aria-label":`${r}, ${this._layerTypeLabel(a)}, ${c}`,"data-layer-id":i,"data-testid":`v2-layer-row-${i}`});u.appendChild(this._button({testId:`v2-layer-select-${i}`,label:`Select ${r}`,className:"layer-row-select",onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).selectLayer)==null?void 0:f.call(p,i)})},this._thumbnail(a))),u.appendChild(de.el("div",{className:"layer-row-main"},de.el("span",{className:"layer-row-name"},r),de.el("span",{className:"layer-row-meta"},this._layerTypeLabel(a))));const m=de.el("div",{className:"layer-row-actions"});return m.appendChild(this._iconButton({testId:`v2-layer-${l?"hide":"show"}-${i}`,label:`${l?"Hide":"Show"} ${r}`,icon:l?de.eye:de.eyeOff,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).setLayerVisibility)==null?void 0:f.call(p,i,!l)})})),m.appendChild(this._iconButton({testId:`v2-layer-${s?"unlock":"lock"}-${i}`,label:`${s?"Unlock":"Lock"} ${r}`,icon:s?de.lockClosed:de.lockOpen,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).setLayerLocked)==null?void 0:f.call(p,i,!s)})})),m.appendChild(this._iconButton({testId:`v2-layer-move-up-${i}`,label:`Move ${r} up`,icon:de.chevronRight,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).moveLayer)==null?void 0:f.call(p,i,"up")})})),m.appendChild(this._iconButton({testId:`v2-layer-move-down-${i}`,label:`Move ${r} down`,icon:de.chevronLeft,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).moveLayer)==null?void 0:f.call(p,i,"down")})})),m.appendChild(this._iconButton({testId:`v2-layer-bring-front-${i}`,label:`Bring ${r} to front`,icon:de.chevronRight,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).moveLayer)==null?void 0:f.call(p,i,"front")})})),m.appendChild(this._iconButton({testId:`v2-layer-send-back-${i}`,label:`Send ${r} to back`,icon:de.chevronLeft,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).moveLayer)==null?void 0:f.call(p,i,"back")})})),m.appendChild(this._iconButton({testId:`v2-layer-rename-${i}`,label:`Rename ${r}`,icon:de.pencil,disabled:s,onClick:()=>this._renameLayer(i,r)})),m.appendChild(this._iconButton({testId:`v2-layer-duplicate-${i}`,label:`Duplicate ${r}`,icon:de.duplicate,disabled:s,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).duplicateLayer)==null?void 0:f.call(p,i)})})),m.appendChild(this._iconButton({testId:`v2-layer-delete-${i}`,label:`Delete ${r}`,icon:de.trash,disabled:s||n<=1,onClick:()=>this._runAction(()=>{var p,f;return(f=(p=this.editor).deleteLayer)==null?void 0:f.call(p,i)})})),u.appendChild(m),u}_thumbnail(a){const t=de.el("span",{className:"layer-thumb","aria-hidden":"true"}),n=a==null?void 0:a.fill;if((n==null?void 0:n.kind)==="color")t.style.background=n.value||n.color||"#ffffff";else if((n==null?void 0:n.kind)==="gradient"&&Array.isArray(n.stops)){const i=n.stops.map(r=>`${r.color} ${Math.round(Number(r.offset||0)*100)}%`).join(", ");t.style.background=`linear-gradient(${Number(n.angle||135)}deg, ${i})`}else t.innerHTML=(a==null?void 0:a.type)==="background"?de.layers:de.move;return t}_button({testId:a,label:t,...n},i){const r=de.el("button",{type:"button","aria-label":t,"data-testid":a,...n});return i&&r.appendChild(i),r}_iconButton({testId:a,label:t,icon:n,disabled:i=!1,onClick:r}){const l=de.el("button",{type:"button",className:"layer-action-btn","aria-label":t,title:t,disabled:i?"disabled":void 0,"data-testid":a,onClick:r});return l.innerHTML=n,l}_renameLayer(a,t){var i;const n=(i=window.prompt)==null?void 0:i.call(window,"Layer name",t);typeof n=="string"&&this._runAction(()=>{var r,l;return(l=(r=this.editor).renameLayer)==null?void 0:l.call(r,a,n)})}_runAction(a){var t,n;try{Promise.resolve(a()).catch(i=>{var r,l;return(l=(r=this.editor).emit)==null?void 0:l.call(r,"error",{error:i,context:"layer-stack"})})}catch(i){(n=(t=this.editor).emit)==null||n.call(t,"error",{error:i,context:"layer-stack"})}}_layerName(a){return(typeof(a==null?void 0:a.name)=="string"?a.name.trim():"")||"Layer"}_layerTypeLabel(a){return(a==null?void 0:a.type)==="background"||(a==null?void 0:a.role)==="background"?"Background":(a==null?void 0:a.role)==="subject"?"Subject":(a==null?void 0:a.type)==="text"?"Text":"Image"}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null,this._listEl=null}}const Fh=[{value:"400",label:"Regular"},{value:"500",label:"Medium"},{value:"600",label:"Semibold"},{value:"700",label:"Bold"},{value:"800",label:"Heavy"}],Dh=[{value:"left",label:"Left"},{value:"center",label:"Center"},{value:"right",label:"Right"}],Ah=[{value:"normal",label:"Normal"},{value:"multiply",label:"Multiply"},{value:"screen",label:"Screen"},{value:"overlay",label:"Overlay"}],vr={stroke:{enabled:!1,color:"#000000",width:0},shadow:{enabled:!1,color:"#000000",alpha:.5,blur:0,distance:0,angle:45},glow:{enabled:!1,color:"#ffffff",alpha:.5,blur:0},backdrop:{enabled:!1,color:"#000000",opacity:.5,padding:0,radius:0,blur:0}};class fm{constructor(a,t){this.state=a,this.editor=t,this.element=null,this._errorMessage=null,this._unsubscribers=[]}render(){return this.element=de.el("div",{className:"text-panel","data-testid":"v2-text-panel"}),this._render(),this._unsubscribers.push(this.state.on("change:layers",()=>this._render()),this.state.on("change:activeLayerId",()=>this._render())),this.element}_render(){if(!this.element)return;this.element.innerHTML="";const a=this._activeTextLayer(),t=(a==null?void 0:a.locked)===!0;if(this.element.appendChild(de.el("div",{className:"text-panel-header"},de.el("div",{className:"panel-section-title"},de.el("span",{},"Text")),de.el("button",{type:"button",className:"btn btn-secondary","data-testid":"v2-text-add",onClick:()=>{var d,c;return this._runAction((c=(d=this.editor).addTextLayer)==null?void 0:c.call(d))}},"Add text"))),this._errorMessage&&this.element.appendChild(de.el("p",{className:"text-panel-error",role:"alert","data-testid":"v2-text-error"},this._errorMessage)),!a){this.element.appendChild(de.el("p",{className:"text-panel-empty"},"Select or add a text layer."));return}const n=a.text&&typeof a.text=="object"?a.text:{},i=n.style&&typeof n.style=="object"?n.style:{},r=n.box&&typeof n.box=="object"?n.box:{},l=a.transform&&typeof a.transform=="object"?a.transform:{},s=this._textEffects(n.effects);this.element.appendChild(this._contentControl(a.id,n.content??"",t)),this.element.appendChild(this._controlGrid([this._numberField({label:"Opacity",testId:"v2-text-opacity",value:a.opacity??1,min:0,max:1,step:.05,disabled:t,onInput:d=>{var c,u;return this._runAction((u=(c=this.editor).updateTextLayer)==null?void 0:u.call(c,a.id,{opacity:d}))}}),this._selectField({label:"Blend",testId:"v2-text-blend-mode",value:a.blendMode||"normal",options:Ah,disabled:t,onChange:d=>{var c,u;return this._runAction((u=(c=this.editor).updateTextLayer)==null?void 0:u.call(c,a.id,{blendMode:d}))}})])),this.element.appendChild(this._selectField({label:"Font",testId:"v2-text-font-family",value:i.fontFamily||"Inter",options:la.TEXT_LAYER_FONT_FAMILIES.map(d=>({value:d,label:d})),disabled:t,onChange:d=>this._updateStyle(a.id,{fontFamily:d})})),this.element.appendChild(this._controlGrid([this._numberField({label:"Size",testId:"v2-text-font-size",value:i.fontSize??64,min:8,max:400,step:1,disabled:t,onInput:d=>this._updateStyle(a.id,{fontSize:d})}),this._selectField({label:"Weight",testId:"v2-text-font-weight",value:String(i.fontWeight??700),options:Fh,disabled:t,onChange:d=>this._updateStyle(a.id,{fontWeight:Number(d)})}),this._selectField({label:"Style",testId:"v2-text-font-style",value:i.fontStyle||"normal",options:[{value:"normal",label:"Normal"},{value:"italic",label:"Italic"}],disabled:t,onChange:d=>this._updateStyle(a.id,{fontStyle:d})}),this._selectField({label:"Align",testId:"v2-text-align",value:i.align||"center",options:Dh,disabled:t,onChange:d=>this._updateStyle(a.id,{align:d})})])),this.element.appendChild(this._controlGrid([this._colorField({label:"Fill",testId:"v2-text-fill",value:i.fill||"#ffffff",disabled:t,onInput:d=>this._updateStyle(a.id,{fill:d})}),this._numberField({label:"Line",testId:"v2-text-line-height",value:i.lineHeight??1.2,min:.8,max:3,step:.05,disabled:t,onInput:d=>this._updateStyle(a.id,{lineHeight:d})}),this._numberField({label:"Track",testId:"v2-text-letter-spacing",value:i.letterSpacing??0,min:-100,max:100,step:.5,disabled:t,onInput:d=>this._updateStyle(a.id,{letterSpacing:d})})])),this.element.appendChild(this._controlGrid([this._numberField({label:"X",testId:"v2-text-box-x",value:r.x??.2,min:0,max:1,step:.01,disabled:t,onInput:d=>this._updateBox(a.id,{x:d})}),this._numberField({label:"Y",testId:"v2-text-box-y",value:r.y??.2,min:0,max:1,step:.01,disabled:t,onInput:d=>this._updateBox(a.id,{y:d})}),this._numberField({label:"W",testId:"v2-text-box-width",value:r.width??.6,min:.05,max:1,step:.01,disabled:t,onInput:d=>this._updateBox(a.id,{width:d})}),this._numberField({label:"H",testId:"v2-text-box-height",value:r.height??.18,min:.05,max:1,step:.01,disabled:t,onInput:d=>this._updateBox(a.id,{height:d})}),this._numberField({label:"Rotate",testId:"v2-text-rotation",value:l.rotation??0,min:0,max:360,step:1,disabled:t,onInput:d=>{var c,u;return this._runAction((u=(c=this.editor).updateTextLayer)==null?void 0:u.call(c,a.id,{transform:{rotation:d}}))}})])),this.element.appendChild(this._effectSection("Stroke",[this._checkboxField({label:"Stroke",testId:"v2-text-stroke-enabled",checked:s.stroke.enabled,disabled:t,onChange:d=>this._updateEffects(a.id,{stroke:{enabled:d}})}),this._colorField({label:"Stroke Color",testId:"v2-text-stroke-color",value:s.stroke.color,disabled:t,onInput:d=>this._updateEffects(a.id,{stroke:{color:d}})}),this._numberField({label:"Stroke Width",testId:"v2-text-stroke-width",value:s.stroke.width,min:0,max:80,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{stroke:{width:d}})})])),this.element.appendChild(this._effectSection("Shadow",[this._checkboxField({label:"Shadow",testId:"v2-text-shadow-enabled",checked:s.shadow.enabled,disabled:t,onChange:d=>this._updateEffects(a.id,{shadow:{enabled:d}})}),this._colorField({label:"Shadow Color",testId:"v2-text-shadow-color",value:s.shadow.color,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{color:d}})}),this._numberField({label:"Shadow Alpha",testId:"v2-text-shadow-alpha",value:s.shadow.alpha,min:0,max:1,step:.05,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{alpha:d}})}),this._numberField({label:"Shadow Blur",testId:"v2-text-shadow-blur",value:s.shadow.blur,min:0,max:120,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{blur:d}})}),this._numberField({label:"Shadow Distance",testId:"v2-text-shadow-distance",value:s.shadow.distance,min:0,max:200,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{distance:d}})}),this._numberField({label:"Shadow Angle",testId:"v2-text-shadow-angle",value:s.shadow.angle,min:0,max:360,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{shadow:{angle:d}})})])),this.element.appendChild(this._effectSection("Glow",[this._checkboxField({label:"Glow",testId:"v2-text-glow-enabled",checked:s.glow.enabled,disabled:t,onChange:d=>this._updateEffects(a.id,{glow:{enabled:d}})}),this._colorField({label:"Glow Color",testId:"v2-text-glow-color",value:s.glow.color,disabled:t,onInput:d=>this._updateEffects(a.id,{glow:{color:d}})}),this._numberField({label:"Glow Alpha",testId:"v2-text-glow-alpha",value:s.glow.alpha,min:0,max:1,step:.05,disabled:t,onInput:d=>this._updateEffects(a.id,{glow:{alpha:d}})}),this._numberField({label:"Glow Blur",testId:"v2-text-glow-blur",value:s.glow.blur,min:0,max:120,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{glow:{blur:d}})})])),this.element.appendChild(this._effectSection("Backdrop",[this._checkboxField({label:"Backdrop",testId:"v2-text-backdrop-enabled",checked:s.backdrop.enabled,disabled:t,onChange:d=>this._updateEffects(a.id,{backdrop:{enabled:d}})}),this._colorField({label:"Backdrop Color",testId:"v2-text-backdrop-color",value:s.backdrop.color,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{color:d}})}),this._numberField({label:"Backdrop Opacity",testId:"v2-text-backdrop-opacity",value:s.backdrop.opacity,min:0,max:1,step:.05,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{opacity:d}})}),this._numberField({label:"Backdrop Padding",testId:"v2-text-backdrop-padding",value:s.backdrop.padding,min:0,max:200,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{padding:d}})}),this._numberField({label:"Backdrop Radius",testId:"v2-text-backdrop-radius",value:s.backdrop.radius,min:0,max:200,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{radius:d}})}),this._numberField({label:"Backdrop Blur",testId:"v2-text-backdrop-blur",value:s.backdrop.blur,min:0,max:80,step:1,disabled:t,onInput:d=>this._updateEffects(a.id,{backdrop:{blur:d}})})]))}_contentControl(a,t,n){const i=de.el("div",{className:"text-field text-content-field"});i.appendChild(de.el("label",{className:"text-field-label",for:"v2-text-content"},"Content"));let r=t==null?"":String(t);const l=de.el("textarea",{id:"v2-text-content",className:"text-area-input",rows:"4",disabled:n?"disabled":void 0,"data-testid":"v2-text-content",onInput:d=>{r=d.target.value},onBlur:()=>{var d,c;r!==t&&this._runAction((c=(d=this.editor).updateTextLayer)==null?void 0:c.call(d,a,{content:r}))},onKeyDown:d=>{var c,u;if(d.key==="Escape"){d.preventDefault(),r=t==null?"":String(t),l.value=r,l.blur();return}d.key==="Enter"&&(d.metaKey||d.ctrlKey)&&(d.preventDefault(),this._runAction((u=(c=this.editor).updateTextLayer)==null?void 0:u.call(c,a,{content:r})),l.blur())}});l.value=r,i.appendChild(l);const s=de.el("div",{className:"text-content-actions"});return s.appendChild(de.el("button",{type:"button",className:"btn btn-text",disabled:n?"disabled":void 0,"data-testid":"v2-text-cancel",onClick:()=>{r=t==null?"":String(t),l.value=r}},"Cancel")),s.appendChild(de.el("button",{type:"button",className:"btn btn-secondary",disabled:n?"disabled":void 0,"data-testid":"v2-text-commit",onClick:()=>{var d,c;return this._runAction((c=(d=this.editor).updateTextLayer)==null?void 0:c.call(d,a,{content:r}))}},"Commit")),i.appendChild(s),i}_controlGrid(a){const t=de.el("div",{className:"text-control-grid"});for(const n of a)t.appendChild(n);return t}_effectSection(a,t){return de.el("div",{className:"text-effect-section"},de.el("div",{className:"text-effect-title"},a),this._controlGrid(t))}_selectField({label:a,testId:t,value:n,options:i,disabled:r,onChange:l}){const s=de.el("select",{className:"select-input",disabled:r?"disabled":void 0,"data-testid":t,onChange:d=>l(d.target.value)});for(const d of i)s.appendChild(de.el("option",{value:d.value,selected:String(n)===String(d.value)?"selected":void 0},d.label));return this._field(a,s)}_numberField({label:a,testId:t,value:n,min:i,max:r,step:l,disabled:s,onInput:d}){const c=de.el("input",{type:"number",className:"text-number-input",min:String(i),max:String(r),step:String(l),value:String(n),disabled:s?"disabled":void 0,"data-testid":t,onInput:u=>d(Number(u.target.value))});return this._field(a,c)}_colorField({label:a,testId:t,value:n,disabled:i,onInput:r}){const l=de.el("input",{type:"color",className:"color-input",value:n,disabled:i?"disabled":void 0,"data-testid":t,onInput:s=>r(s.target.value)});return this._field(a,l)}_checkboxField({label:a,testId:t,checked:n,disabled:i,onChange:r}){const l=de.el("input",{type:"checkbox",className:"text-checkbox-input",checked:n?"checked":void 0,disabled:i?"disabled":void 0,"data-testid":t,onChange:s=>r(s.target.checked===!0)});return de.el("label",{className:"text-field text-checkbox-field"},de.el("span",{className:"text-field-label"},a),l)}_field(a,t){return de.el("label",{className:"text-field"},de.el("span",{className:"text-field-label"},a),t)}_updateStyle(a,t){var n,i;this._runAction((i=(n=this.editor).updateTextLayer)==null?void 0:i.call(n,a,{style:t}))}_updateBox(a,t){var n,i;this._runAction((i=(n=this.editor).updateTextLayer)==null?void 0:i.call(n,a,{box:t}))}_updateEffects(a,t){var n,i;this._runAction((i=(n=this.editor).updateTextLayer)==null?void 0:i.call(n,a,{effects:t}))}_textEffects(a){const t=a&&typeof a=="object"?a:{};return{stroke:{...vr.stroke,...t.stroke&&typeof t.stroke=="object"?t.stroke:{}},shadow:{...vr.shadow,...t.shadow&&typeof t.shadow=="object"?t.shadow:{}},glow:{...vr.glow,...t.glow&&typeof t.glow=="object"?t.glow:{}},backdrop:{...vr.backdrop,...t.backdrop&&typeof t.backdrop=="object"?t.backdrop:{}}}}_runAction(a){this._errorMessage=null,Promise.resolve(a).catch(t=>{var i,r;const n=t instanceof Error?t:new Error(String(t));this._errorMessage=n.message||"Text update failed",(r=(i=this.editor)==null?void 0:i.emit)==null||r.call(i,"error",n),this._render()})}_activeTextLayer(){const a=this.state.get("activeLayerId"),t=this.state.get("layers");return!a||!Array.isArray(t)?null:t.find(n=>(n==null?void 0:n.id)===a&&(n.type==="text"||n.role==="text"))??null}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}class Rh{constructor(a,t,n){this.state=a,this.filterManager=t,this.editor=n,this.element=null,this._headerEl=null,this._bodyEl=null,this._view="categories",this._onNavigate=null,this._callbacks=null,this._unsubscribers=[],this._categoryTabs=null,this._filterListView=null,this._filterControlsView=null,this._backgroundPanel=null,this._layerStackPanel=null,this._textPanel=null}build(a){return this._callbacks=a,this._onNavigate=a.onViewChange||null,this.element=de.el("div",{className:"drawer-nav","data-testid":"v2-mobile-nav"}),this._headerEl=de.el("div",{className:"drawer-nav-header"}),this.element.appendChild(this._headerEl),this._bodyEl=de.el("div",{className:"drawer-nav-body"}),this.element.appendChild(this._bodyEl),this._buildViews(),this._unsubscribers.push(this.state.on("change:selectedFilter",({value:t})=>{t&&this._view!=="controls"&&this.navigateTo("controls")}),this.state.on("change:selectedCategory",()=>{}),this.state.on("change:mode",({value:t})=>{t==="filters"&&this._view!=="categories"&&!this.state.get("selectedFilter")&&this.navigateTo("categories")})),this.navigateTo("categories"),this.element}_buildViews(){this._categoryTabs=new dm(this.state,this.editor),this._categoryTabsEl=this._categoryTabs.render({onSelect:a=>{if(a==="background"||a==="layers"||a==="text"){this.navigateTo(a);return}this.navigateTo("filters")}}),this._filterListView=new cm(this.state,this.filterManager),this._filterListEl=this._filterListView.render({onToggle:(a,t,n)=>this._callbacks.onFilterToggle(a,t,n),onSelect:(a,t)=>{this._callbacks.onFilterSelect(a,t),this.navigateTo("controls")}}),this._filterControlsView=new um(this.state,this.filterManager),this._filterControlsEl=this._filterControlsView.render({onChange:(a,t,n,i)=>this._callbacks.onFilterChange(a,t,n,i),onReset:(a,t)=>this._callbacks.onFilterReset(a,t),onAction:(a,t,n)=>this._callbacks.onFilterAction(a,t,n)}),this._backgroundPanel=new mm(this.state,this.editor),this._backgroundPanelEl=this._backgroundPanel.render(),this._layerStackPanel=new pm(this.state,this.editor),this._layerStackPanelEl=this._layerStackPanel.render(),this._textPanel=new fm(this.state,this.editor),this._textPanelEl=this._textPanel.render()}navigateTo(a){var n;if(!this.element)return;this._view=a,this._renderHeader(),this._bodyEl.innerHTML="";let t=null;switch(a){case"categories":t=this._categoryTabsEl;break;case"filters":t=this._filterListEl;break;case"controls":t=this._filterControlsEl;break;case"background":t=this._backgroundPanelEl;break;case"layers":t=this._layerStackPanelEl;break;case"text":t=this._textPanelEl;break;default:t=this._categoryTabsEl}t&&this._bodyEl.appendChild(t),(n=this._onNavigate)==null||n.call(this,a)}_renderHeader(){if(!this._headerEl)return;if(this._headerEl.innerHTML="",this._view!=="categories"){const n=de.el("button",{type:"button",className:"drawer-back-btn","aria-label":"Go back","data-testid":"v2-drawer-back",onClick:()=>this._goBack()});n.innerHTML=de.chevronLeft,this._headerEl.appendChild(n)}const t=this._titleForView(this._view);if(this._headerEl.appendChild(de.el("h2",{className:"drawer-nav-title"},t)),this._view==="controls"){const n=this.state.get("selectedFilter");if(n){const i=this._activeFilterLayerId();this._headerEl.appendChild(de.createButton({label:"Reset",className:"btn-text",onClick:()=>this._callbacks.onFilterReset(n,i)}))}}}_activeFilterLayerId(){return typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId")}_titleForView(a){switch(a){case"categories":return"Filters";case"filters":{const t=this.state.get("selectedCategory");return this._categoryLabel(t)||"Filters"}case"background":return"Background";case"layers":return"Layers";case"text":return"Text";case"controls":{const t=this.state.get("selectedFilter"),n=t?this.filterManager.getFilterDef(t):null;return(n==null?void 0:n.name)||"Filter"}default:return""}}_categoryLabel(a){var t;return a&&((t=de.EDITOR_CATEGORIES.find(n=>n.id===a))==null?void 0:t.name)||null}_goBack(){this._view==="controls"?(this.state.set("selectedFilter",null),this.navigateTo("filters")):(this._view==="filters"||this._view==="background"||this._view==="layers"||this._view==="text")&&this.navigateTo("categories")}get currentView(){return this._view}destroy(){var a,t,n,i,r,l,s;this._unsubscribers.forEach(d=>d()),this._unsubscribers=[],(a=this._categoryTabs)==null||a.destroy(),(t=this._filterListView)==null||t.destroy(),(n=this._filterControlsView)==null||n.destroy(),(i=this._backgroundPanel)==null||i.destroy(),(r=this._layerStackPanel)==null||r.destroy(),(l=this._textPanel)==null||l.destroy(),(s=this.element)==null||s.remove(),this.element=null}}class Lh{constructor(a,t){this.state=a,this.filterManager=t,this.element=null,this._onSelect=null,this._onRemove=null,this._unsubscribers=[]}render({onSelect:a,onRemove:t}={}){return this._onSelect=a,this._onRemove=t,this.element=de.el("div",{className:"mobile-active-chips",role:"region","aria-label":"Active filters","data-testid":"v2-mobile-active-chips"}),this._renderChips(),this._unsubscribers.push(this.state.on("change:activeFilters",()=>this._renderChips()),this.state.on("change:selectedFilter",()=>this._refreshSelection())),this.element}_renderChips(){this.element.innerHTML="";const a=this.state.get("activeFilters");if(((a==null?void 0:a.size)??0)===0){this.element.style.display="none";return}this.element.style.display="";const n=de.el("div",{className:"mobile-active-track"}),i=this.state.get("selectedFilter"),r=this._activeFilterLayerId();for(const l of a){const s=this.filterManager.getFilterDef(l);s&&n.appendChild(this._renderChip(s,l===i,r))}this.element.appendChild(n)}_renderChip(a,t,n=null){const i=de.el("div",{className:`mobile-active-chip ${t?"selected":""}`,"data-filter":a.id,"data-testid":`v2-mobile-chip-${a.id}`});i.appendChild(de.el("button",{type:"button",className:"mobile-active-chip-name","aria-label":`Edit ${a.name}`,onClick:()=>{var l;return(l=this._onSelect)==null?void 0:l.call(this,a.id,n)}},a.name));const r=de.el("button",{type:"button",className:"mobile-active-chip-remove","aria-label":`Remove ${a.name}`,"data-testid":`v2-mobile-chip-remove-${a.id}`,onClick:l=>{var s;l.stopPropagation(),(s=this._onRemove)==null||s.call(this,a.id,n)}});return r.innerHTML=de.close,i.appendChild(r),i}_activeFilterLayerId(){return typeof this.state.getActiveFilterLayerId=="function"?this.state.getActiveFilterLayerId():this.state.get("activeLayerId")}_refreshSelection(){var n;const a=this.state.get("selectedFilter"),t=(n=this.element)==null?void 0:n.querySelectorAll(".mobile-active-chip");t==null||t.forEach(i=>{const r=i.getAttribute("data-filter");i.classList.toggle("selected",r===a)})}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],(a=this.element)==null||a.remove(),this.element=null}}const gc="(max-width: 900px)";let Ph=class{constructor(a,t,n){this.state=a,this.filterManager=t,this.editor=n,this.root=null,this.canvasSection=null,this.canvasContainer=null,this.cropOverlay=null,this._callbacks=null,this._isMobile=!1,this._panel=null,this._categoryTabs=null,this._filterListView=null,this._filterControlsView=null,this._activeStack=null,this._backgroundPanel=null,this._layerStackPanel=null,this._textPanel=null,this._desktopBackgroundSection=null,this._desktopLayerSection=null,this._desktopTextSection=null,this._desktopFilterListSection=null,this._desktopCropWrapper=null,this._mobileChips=null,this._mobileDrawer=null,this._mobileNav=null,this._mobileCropWrapper=null,this._cropControlsEl=null,this._unsubscribers=[],this._mql=null,this._mqlHandler=null,this._resizeObserver=null}build(a){var t;return this._callbacks=a,this.root=de.el("div",{className:"editor-v2-body"}),this.canvasSection=de.el("div",{className:"editor-v2-canvas"}),this.canvasContainer=de.el("div",{className:"canvas-container"}),this.cropOverlay=de.el("canvas",{className:"crop-overlay","aria-hidden":"true"}),this.canvasSection.appendChild(this.canvasContainer),this.canvasSection.appendChild(this.cropOverlay),this._zoomOverlay=this._buildCanvasZoomOverlay(),this.canvasSection.appendChild(this._zoomOverlay),this.root.appendChild(this.canvasSection),this._isMobile=typeof window<"u"&&((t=window.matchMedia)==null?void 0:t.call(window,gc).matches)===!0,this._isMobile?this._buildMobileShell():this._buildDesktopShell(),typeof window<"u"&&window.matchMedia&&(this._mql=window.matchMedia(gc),this._mqlHandler=n=>this._handleBreakpointChange(n.matches),this._mql.addEventListener?this._mql.addEventListener("change",this._mqlHandler):this._mql.addListener&&this._mql.addListener(this._mqlHandler)),this._unsubscribers.push(this.state.on("change:mode",({value:n})=>this._applyMode(n)),this.state.on("change:selectedCategory",()=>this._applyMode(this.state.get("mode")))),{root:this.root,canvasContainer:this.canvasContainer,cropOverlay:this.cropOverlay}}mountCropControls(a){this._cropControlsEl=a,this._mountCropControlsInActiveShell()}_buildDesktopShell(){this._panel=de.el("div",{className:"editor-v2-panel","data-testid":"v2-inspector-panel"}),this._categoryTabs=new dm(this.state,this.editor),this._panel.appendChild(this._categoryTabs.render({onSelect:()=>this._handleDesktopCategoryChange()}));const a=de.el("div",{className:"panel-body"});this._desktopFilterListSection=de.el("div",{className:"panel-section"}),this._desktopFilterListSection.appendChild(de.el("div",{className:"panel-section-title"},de.el("span",{},"Filters"))),this._filterListView=new cm(this.state,this.filterManager),this._desktopFilterListSection.appendChild(this._filterListView.render({onToggle:(t,n,i)=>this._callbacks.onFilterToggle(t,n,i),onSelect:(t,n)=>this._callbacks.onFilterSelect(t,n)})),a.appendChild(this._desktopFilterListSection),this._filterControlsView=new um(this.state,this.filterManager),a.appendChild(this._filterControlsView.render({onChange:(t,n,i,r)=>this._callbacks.onFilterChange(t,n,i,r),onReset:(t,n)=>this._callbacks.onFilterReset(t,n),onAction:(t,n,i)=>this._callbacks.onFilterAction(t,n,i)})),this._desktopCropWrapper=de.el("div",{className:"crop-controls-wrapper",style:{display:"none"}}),a.appendChild(this._desktopCropWrapper),this._activeStack=new Mh(this.state,this.filterManager),a.appendChild(this._activeStack.render({onRemove:(t,n)=>this._callbacks.onFilterToggle(t,!1,n),onSelect:(t,n)=>this._callbacks.onFilterSelect(t,n),onClearAll:t=>{var n,i;return(i=(n=this._callbacks).onClearAll)==null?void 0:i.call(n,t)}})),this._desktopBackgroundSection=de.el("div",{className:"panel-section",style:{display:"none"}}),this._backgroundPanel=new mm(this.state,this.editor),this._desktopBackgroundSection.appendChild(this._backgroundPanel.render()),a.appendChild(this._desktopBackgroundSection),this._desktopLayerSection=de.el("div",{className:"panel-section",style:{display:"none"}}),this._layerStackPanel=new pm(this.state,this.editor),this._desktopLayerSection.appendChild(this._layerStackPanel.render()),a.appendChild(this._desktopLayerSection),this._desktopTextSection=de.el("div",{className:"panel-section",style:{display:"none"}}),this._textPanel=new fm(this.state,this.editor),this._desktopTextSection.appendChild(this._textPanel.render()),a.appendChild(this._desktopTextSection),this._panel.appendChild(a),this.root.appendChild(this._panel),this._mountCropControlsInActiveShell(),this._applyMode(this.state.get("mode"))}_buildMobileShell(){this._mobileChips=new Lh(this.state,this.filterManager);const a=this._mobileChips.render({onSelect:(r,l)=>{var s,d;this._callbacks.onFilterSelect(r,l),(s=this._mobileDrawer)==null||s.snapTo("full"),(d=this._mobileNav)==null||d.navigateTo("controls")},onRemove:(r,l)=>this._callbacks.onFilterToggle(r,!1,l)});this.root.appendChild(a),this._mobileDrawer=new Ih({onSnapChange:r=>{this.canvasContainer&&window.dispatchEvent(new Event("resize"))}}),this._mobileNav=new Rh(this.state,this.filterManager,this.editor);const t=this._mobileNav.build({onFilterToggle:this._callbacks.onFilterToggle,onFilterSelect:this._callbacks.onFilterSelect,onFilterChange:this._callbacks.onFilterChange,onFilterReset:this._callbacks.onFilterReset,onFilterAction:this._callbacks.onFilterAction,onViewChange:r=>{var l;r==="controls"&&((l=this._mobileDrawer)==null?void 0:l.snap)==="collapsed"&&this._mobileDrawer.snapTo("half")}});this._mobileCropWrapper=de.el("div",{className:"crop-controls-wrapper",style:{display:"none"}});const n=de.el("div",{className:"drawer-content"});n.appendChild(t),n.appendChild(this._mobileCropWrapper);const i=this._mobileDrawer.build({body:n});this.root.appendChild(i),this._wireDrawerSizing(),this._mountCropControlsInActiveShell(),this._applyMode(this.state.get("mode"))}_wireDrawerSizing(){if(!this.root||!this._mobileDrawer)return;const a=()=>{const t=this.root.getBoundingClientRect().height;this._mobileDrawer.updateContainerHeight(t)};a(),this._resizeObserver=new ResizeObserver(()=>a()),this._resizeObserver.observe(this.root)}_destroyDesktopShell(){var a,t,n,i,r,l,s,d,c,u;(a=this._categoryTabs)==null||a.destroy(),this._categoryTabs=null,(t=this._filterListView)==null||t.destroy(),this._filterListView=null,(n=this._filterControlsView)==null||n.destroy(),this._filterControlsView=null,(i=this._activeStack)==null||i.destroy(),this._activeStack=null,(r=this._backgroundPanel)==null||r.destroy(),this._backgroundPanel=null,(l=this._layerStackPanel)==null||l.destroy(),this._layerStackPanel=null,(s=this._textPanel)==null||s.destroy(),this._textPanel=null,this._desktopBackgroundSection=null,this._desktopLayerSection=null,this._desktopTextSection=null,this._desktopFilterListSection=null,(d=this._desktopCropWrapper)!=null&&d.parentElement&&((c=this._cropControlsEl)==null?void 0:c.parentElement)===this._desktopCropWrapper&&this._desktopCropWrapper.removeChild(this._cropControlsEl),this._desktopCropWrapper=null,(u=this._panel)==null||u.remove(),this._panel=null}_destroyMobileShell(){var a,t,n,i,r;(a=this._resizeObserver)==null||a.disconnect(),this._resizeObserver=null,(t=this._mobileNav)==null||t.destroy(),this._mobileNav=null,(n=this._mobileChips)==null||n.destroy(),this._mobileChips=null,this._mobileCropWrapper&&((i=this._cropControlsEl)==null?void 0:i.parentElement)===this._mobileCropWrapper&&this._mobileCropWrapper.removeChild(this._cropControlsEl),this._mobileCropWrapper=null,(r=this._mobileDrawer)==null||r.destroy(),this._mobileDrawer=null}_handleBreakpointChange(a){a!==this._isMobile&&(this._isMobile=a,a?(this._destroyDesktopShell(),this._buildMobileShell()):(this._destroyMobileShell(),this._buildDesktopShell()))}_mountCropControlsInActiveShell(){if(!this._cropControlsEl)return;this._cropControlsEl.remove();const a=this._isMobile?this._mobileCropWrapper:this._desktopCropWrapper;a==null||a.appendChild(this._cropControlsEl)}_handleDesktopCategoryChange(){if(this.state.get("mode")==="crop"||["background","layers","text"].includes(this.state.get("selectedCategory")))return;const t=this.state.get("selectedFilter");if(!t)return;this.filterManager.getFiltersByCategory(this.state.get("selectedCategory")).some(i=>i.id===t)||this.state.set("selectedFilter",null)}_applyMode(a){var s,d,c;const t=a==="crop",n=!t&&this.state.get("selectedCategory")==="background",i=!t&&this.state.get("selectedCategory")==="layers",r=!t&&this.state.get("selectedCategory")==="text",l=n||i||r;this._desktopFilterListSection&&(this._desktopFilterListSection.style.display=t||l?"none":""),(s=this._filterControlsView)!=null&&s.element&&(this._filterControlsView.element.style.display=t||l?"none":""),(d=this._activeStack)!=null&&d.element&&(this._activeStack.element.style.display=t||l?"none":""),this._desktopBackgroundSection&&(this._desktopBackgroundSection.style.display=n?"":"none"),this._desktopLayerSection&&(this._desktopLayerSection.style.display=i?"":"none"),this._desktopTextSection&&(this._desktopTextSection.style.display=r?"":"none"),this._desktopCropWrapper&&(this._desktopCropWrapper.style.display=t?"":"none"),(c=this._mobileNav)!=null&&c.element&&(this._mobileNav.element.style.display=t?"none":""),this._mobileCropWrapper&&(this._mobileCropWrapper.style.display=t?"":"none"),t&&this._mobileDrawer&&this._mobileDrawer.snapTo("half")}_buildCanvasZoomOverlay(){const a=de.el("div",{className:"canvas-zoom-overlay",role:"group","aria-label":"Zoom controls"}),t=de.createIconButton({icon:de.zoomOut,title:"Zoom Out",className:"canvas-zoom-btn",testId:"btn-zoom-out",ariaLabel:"Zoom out",onClick:()=>{const l=this.state.get("zoom");this.editor.setZoom(l-.25)}}),n=de.el("span",{className:"canvas-zoom-label","aria-live":"polite","aria-atomic":"true",role:"status"},`${Math.round((this.state.get("zoom")??1)*100)}%`),i=de.createIconButton({icon:de.zoomIn,title:"Zoom In",className:"canvas-zoom-btn",testId:"btn-zoom-in",ariaLabel:"Zoom in",onClick:()=>{const l=this.state.get("zoom");this.editor.setZoom(l+.25)}}),r=de.createIconButton({icon:de.expand,title:"Fit to Screen",className:"canvas-zoom-btn",testId:"btn-fit-screen",ariaLabel:"Fit to screen",onClick:()=>this.editor.fitToScreen()});return a.appendChild(t),a.appendChild(n),a.appendChild(i),a.appendChild(r),this._unsubscribers.push(this.state.on("change:zoom",({value:l})=>{n.textContent=`${Math.round(l*100)}%`})),a}destroy(){var a;this._unsubscribers.forEach(t=>t()),this._unsubscribers=[],this._mql&&this._mqlHandler&&(this._mql.removeEventListener?this._mql.removeEventListener("change",this._mqlHandler):this._mql.removeListener&&this._mql.removeListener(this._mqlHandler),this._mql=null,this._mqlHandler=null),this._destroyDesktopShell(),this._destroyMobileShell(),(a=this.root)==null||a.remove(),this.root=null,this.canvasSection=null,this.canvasContainer=null,this.cropOverlay=null}};function qo(o){if(!Number.isFinite(Number(o)))return 0;const a=Number(o)%360;return a<0?a+360:a}function Uh(o,a){const t=qo(o);return(qo(a)-t+540)%360-180}function Oh(){return new Date().toISOString()}function gr(o){return typeof o=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(o)}class zh extends la.EventEmitter{constructor(a,t={}){var r,l,s,d,c;if(super(),!a)throw new Error("VanillaImageEditorV2: container element is required");this._container=a,this._destroyed=!1,this._loadVersion=0,this._objectUrls=new Set,this._activeObjectUrl=null;const n=t.preset?de.getPreset(t.preset):null,i=n?{initialMode:n.initialMode==="crop"?"crop":"adjust",cropShape:n.cropShape,initialAspectRatio:n.aspectRatio}:{};this._options={theme:"auto",initialImage:null,initialMode:"adjust",cropShape:"free",initialAspectRatio:"free",layout:"split-panel",backgroundRemoval:{enabled:!0,endpoint:"/api/v1/media/background-removal/preview",optionsEndpoint:"/api/v1/media/background-removal/options",savedEndpoint:"/api/v1/media/{media}/background-removal",fallbackEndpoint:null},backgroundReplacement:{assetEndpoint:null,materializeEndpoint:null,targetMediaUuid:null,mediaChoices:[]},...i,...t},this._preset=n,this._state=la.createState(),this._state.set("theme",this._options.theme),this._state.set("crop.shape",this._options.cropShape),this._state.set("crop.aspect",this._options.initialAspectRatio),this._preset&&(this._state.set("lockCropShape",!!this._preset.lockCropShape),this._state.set("lockAspectRatio",!!this._preset.lockAspectRatio),this._state.set("showFilters",this._preset.showFilters!==!1),this._state.set("showCropControls",this._preset.showCropControls!==!1),this._state.set("autoZoomOnCropOverflow",!!this._preset.autoZoomOnCropOverflow)),this._renderer=new de.PixiRenderer,this._filterManager=new de.FilterManager(this._state,this._renderer),this._cropManager=new de.CropManager(this._state,this._renderer),this._removeBgManager=null,this._backgroundRemovalAvailable=!1,((r=this._options.backgroundRemoval)==null?void 0:r.enabled)!==!1&&(this._removeBgManager=new de.RemoveBgManager({endpoint:(l=this._options.backgroundRemoval)==null?void 0:l.endpoint,optionsEndpoint:(s=this._options.backgroundRemoval)==null?void 0:s.optionsEndpoint,savedEndpoint:(d=this._options.backgroundRemoval)==null?void 0:d.savedEndpoint,fallbackEndpoint:(c=this._options.backgroundRemoval)==null?void 0:c.fallbackEndpoint})),this._loadingOverlay=null,this._toolbar=null,this._layout=null,this._cropControls=null,this._editorEl=null,this._toolbarContainer=null,this._canvasContainer=null,this._cropOverlay=null,this._fileInput=null,this._mobileSaveBar=null,this._mobileSaveBtn=null,this._mobileSaveUnsub=null,this._resizeObserver=null,this._initPromise=Promise.resolve(this._init()).catch(u=>{this._destroyed||this.emit("error",u instanceof Error?u:new Error(String(u)))})}async _init(){this._state.detectTheme(),this._buildDOM(),!(!await this._renderer.mount(this._canvasContainer,0,{backgroundAlpha:0})||this._destroyed)&&(this._cropManager.setOverlayCanvas(this._cropOverlay),this._initUI(),this._setupResizeObserver(),this._setupWindowResize(),this._subscribeToState(),this._refreshBackgroundRemovalAvailability(),this._options.initialImage&&await this.loadImage(this._options.initialImage),this.emit("ready"))}_buildDOM(){this._container.innerHTML="",this._editorEl=de.el("div",{className:`vanilla-image-editor-v2 ${this._state.get("isDarkMode")?"dark":"light"}`}),this._toolbarContainer=de.el("div",{className:"editor-v2-toolbar"}),this._editorEl.appendChild(this._toolbarContainer),this._layout=new Ph(this._state,this._filterManager,this);const{root:a,canvasContainer:t,cropOverlay:n}=this._layout.build({onFilterToggle:(i,r,l)=>this._handleFilterToggle(i,r,l),onFilterSelect:(i,r)=>this._handleFilterSelect(i,r),onFilterChange:(i,r,l,s)=>this._handleFilterChange(i,r,l,s),onFilterReset:(i,r)=>this._handleFilterReset(i,r),onFilterAction:(i,r,l)=>this._handleFilterAction(i,r,l),onClearAll:i=>this.resetAll(i)});this._canvasContainer=t,this._cropOverlay=n,this._editorEl.appendChild(a),this._buildMobileSaveBar(),this._mobileSaveBar&&this._editorEl.appendChild(this._mobileSaveBar),this._fileInput=de.el("input",{type:"file",accept:"image/*",className:"hidden-file-input",style:{display:"none"},"aria-label":"Choose image file to edit",onChange:i=>this._handleFileSelect(i)}),this._editorEl.appendChild(this._fileInput),this._container.appendChild(this._editorEl)}_initUI(){this._toolbar=new de.Toolbar(this._state,this),this._toolbarContainer.appendChild(this._toolbar.render()),this._cropControls=new de.CropControls(this._state,this._cropManager,this);const a=this._cropControls.render();this._layout.mountCropControls(a)}_setupResizeObserver(){if(!this._canvasContainer)return;let a=null;this._resizeObserver=new ResizeObserver(()=>{clearTimeout(a),a=setTimeout(()=>{var t,n;this._destroyed||!this._canvasContainer||(this._renderer.resizeTo(this._canvasContainer),this._state.get("mode")==="crop"&&((n=(t=this._cropManager).drawOverlay)==null||n.call(t)))},50)}),this._resizeObserver.observe(this._canvasContainer)}_setupWindowResize(){this._handleWindowResize=()=>{},window.addEventListener("resize",this._handleWindowResize)}_subscribeToState(){this._state.on("change:isDarkMode",({value:a})=>{var t,n;(t=this._editorEl)==null||t.classList.toggle("dark",a),(n=this._editorEl)==null||n.classList.toggle("light",!a)})}async _handleFileSelect(a){var n;const t=(n=a.target.files)==null?void 0:n[0];t&&await this.loadImage(t),this._fileInput.value=""}_matchesExpectedFilterLayer(a){if(a===void 0)return!0;if(a===null)return typeof this._state.getActiveFilterLayerId=="function"?this._state.getActiveFilterLayerId()===null:this._state.get("activeLayerId")===null;const t=typeof a=="string"?a.trim():"";return t===""?!1:typeof this._state.getActiveFilterLayerId=="function"?this._state.getActiveFilterLayerId()===t:this._state.get("activeLayerId")===t}_handleFilterToggle(a,t,n=void 0){this._filterManager.toggle(a,t,n)!==!1&&(t?this._state.set("selectedFilter",a):this._state.get("selectedFilter")===a&&this._state.set("selectedFilter",null))}_handleFilterSelect(a,t=void 0){var r;if(!this._matchesExpectedFilterLayer(t))return;const n=this._state.get("activeFilters");if(!((r=n==null?void 0:n.has)!=null&&r.call(n,a))&&this._filterManager.toggle(a,!0,t)===!1)return;this._state.set("selectedFilter",a);const i=this._filterManager.getFilterDef(a);if(typeof(i==null?void 0:i.category)=="string"){const l=de.REGISTRY_TO_UI[i.category]||i.category;this._state.get("selectedCategory")!==l&&this._state.set("selectedCategory",l)}}_handleFilterChange(a,t,n,i=void 0){this._filterManager.updateValue(a,t,n,i)||this._filterManager.applyFilters(),this._renderer.render()}_handleFilterReset(a,t=void 0){var n,i;this._filterManager.resetValues(a,t),(i=(n=this._filterManager)==null?void 0:n.applyFilters)==null||i.call(n)}_handleFilterAction(a,t,n=void 0){this._filterManager.performFilterAction(a,t,n)}_revokeObjectUrl(a){!a||!this._objectUrls.has(a)||(URL.revokeObjectURL(a),this._objectUrls.delete(a),this._activeObjectUrl===a&&(this._activeObjectUrl=null))}_replaceActiveObjectUrl(a){const t=this._activeObjectUrl;this._activeObjectUrl=a,this._objectUrls.add(a),t&&t!==a&&this._revokeObjectUrl(t)}_clearActiveObjectUrl(){this._activeObjectUrl&&this._revokeObjectUrl(this._activeObjectUrl)}async _renderCurrentDocument(){var a,t;return(t=(a=this._renderer).renderLayerDocument)==null?void 0:t.call(a,this._state.getSerializableDocument(),{fallbackImageUrl:this._state.get("imageUrl")??null})}async setBackgroundFill(a){var n;const t=this._state.setBackgroundFill(a);return await this._renderCurrentDocument(),this.emit("background-changed",{layerId:t,fill:((n=this._state.getLayer(t))==null?void 0:n.fill)??null}),t}async setBackgroundColor(a){return this.setBackgroundFill({kind:"color",value:typeof a=="string"&&a.trim()!==""?a:"#ffffff"})}async setBackgroundGradient(a={}){return this.setBackgroundFill({kind:"gradient",gradientType:a.gradientType||"linear",angle:Number.isFinite(Number(a.angle))?Number(a.angle):135,stops:Array.isArray(a.stops)?a.stops:[{offset:0,color:"#111827"},{offset:1,color:"#f59e0b"}],fit:a.fit||"cover"})}async setBackgroundMediaSource(a,t={}){if(!a||typeof a!="object")throw new Error("Background source is required");return this.setBackgroundFill({kind:"media",source:a,fit:t.fit||"cover"})}async setBackgroundImageFromFile(a,t={}){var i,r;if(!(a instanceof Blob))throw new Error("Background image file is required");const n=URL.createObjectURL(a);this._objectUrls.add(n);try{if(((r=(i=this._state).isBackgroundLayerLocked)==null?void 0:r.call(i))===!0)throw new Error("Background layer is locked");const l=this._captureEditorDocumentContext(),s=await this._probeImageDimensions(n);if(!this._isCurrentEditorDocumentContext(l))return URL.revokeObjectURL(n),this._objectUrls.delete(n),null;const d=this._state.ensureBackgroundLayer();if(!d)throw new Error("Background layer is locked");let c=null,u=this._captureEditorDocumentContext(d);if(this._canUploadBackgroundAsset()){if(!await this._materializeBackgroundLayerForUpload(d))return URL.revokeObjectURL(n),this._objectUrls.delete(n),null;if(u=this._captureEditorDocumentContext(d),c=await this._uploadBackgroundAsset(a,d,n),!this._isCurrentEditorDocumentContext(u))return URL.revokeObjectURL(n),this._objectUrls.delete(n),null}return c||(c={kind:"runtime",runtimeRef:`background-${Date.now()}`,originalWidth:s.width,originalHeight:s.height,sourceHash:null,previewUrl:n}),this._isCurrentEditorDocumentContext(u)?this.setBackgroundMediaSource(c,{fit:t.fit||"cover"}):(URL.revokeObjectURL(n),this._objectUrls.delete(n),null)}catch(l){throw URL.revokeObjectURL(n),this._objectUrls.delete(n),l}}async setBackgroundFit(a){if(!this._state.setBackgroundFit(a))return!1;const n=this._backgroundLayerId();await this._renderCurrentDocument();const i=n?this._state.getLayer(n):null;return i&&this.emit("background-changed",{layerId:n,fill:i.fill??null}),!0}async setBackgroundBlur(a){if(!this._state.setBackgroundBlur(a))return!1;const n=this._backgroundLayerId();await this._renderCurrentDocument();const i=n?this._state.getLayer(n):null;return i&&this.emit("background-changed",{layerId:n,effects:i.effects??[]}),!0}_backgroundLayerId(){const a=this._state.getSerializableDocument(),t=Array.isArray(a==null?void 0:a.layers)?a.layers.find(n=>(n==null?void 0:n.type)==="background"||(n==null?void 0:n.role)==="background"):null;return typeof(t==null?void 0:t.id)=="string"?t.id:null}async removeBackgroundLayer(){return this._state.removeBackgroundLayer()?(await this._renderCurrentDocument(),this.emit("background-changed",{layerId:null,fill:null}),!0):!1}async selectLayer(a){var n,i;return this._state.setActiveLayer(a)?((i=(n=this._filterManager)==null?void 0:n.applyFilters)==null||i.call(n),this.emit("layer-changed",{action:"select",layerId:a}),!0):!1}async renameLayer(a,t){var i;return this._state.renameLayer(a,t)?(this.emit("layer-changed",{action:"rename",layerId:a,name:((i=this._state.getLayer(a))==null?void 0:i.name)??null}),!0):!1}async duplicateLayer(a){const t=this._state.duplicateLayer(a);return t?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"duplicate",layerId:a,duplicateLayerId:t}),t):null}async deleteLayer(a){return this._state.deleteLayer(a)?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"delete",layerId:a,activeLayerId:this._state.get("activeLayerId")}),!0):!1}async moveLayer(a,t){return this._state.moveLayer(a,t)?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"move",layerId:a,direction:t}),!0):!1}async setLayerVisibility(a,t){return this._state.setLayerVisibility(a,t)?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"visibility",layerId:a,visible:!!t}),!0):!1}async setLayerLocked(a,t){return this._state.setLayerLocked(a,t)?(this.emit("layer-changed",{action:"lock",layerId:a,locked:!!t}),!0):!1}async addTextLayer(a={}){const t=this._state.addTextLayer(a);return t?(this._state.set("selectedCategory","text"),await this._renderCurrentDocument(),this.emit("layer-changed",{action:"text-add",layerId:t}),t):null}async updateTextLayer(a,t={}){return this._state.updateTextLayer(a,t)?(await this._renderCurrentDocument(),this.emit("layer-changed",{action:"text-update",layerId:a,patch:t}),!0):!1}_canUploadBackgroundAsset(){var r,l;const a=(l=(r=this._options)==null?void 0:r.backgroundReplacement)==null?void 0:l.assetEndpoint,t=this._state.getEditorDocumentBinding(),n=this._state.getSerializableDocument(),i=this._backgroundTargetMediaUuid(n);return typeof a=="string"&&a.trim()!==""&&!!(t!=null&&t.documentId)&&!!n&&typeof i=="string"&&i.trim()!==""}async _materializeBackgroundLayerForUpload(a){return this._materializeCurrentDocument("Background layer materialization failed",a)}_documentMaterializationSignature(a){try{return JSON.stringify(a??null)}catch{return null}}_captureDocumentMaterializationContext(a,t,n=null){return{loadVersion:this._loadVersion,documentId:(t==null?void 0:t.documentId)??null,documentRevisionId:(t==null?void 0:t.documentRevisionId)??null,documentRevisionNumber:(t==null?void 0:t.documentRevisionNumber)??null,documentSignature:this._documentMaterializationSignature(a),requiredLayerId:n}}_captureEditorDocumentContext(a=null){return{loadVersion:this._loadVersion,documentSignature:this._documentMaterializationSignature(this._state.getSerializableDocument()),requiredLayerId:a}}_isCurrentEditorDocumentContext(a){return!(!a||this._destroyed||this._loadVersion!==a.loadVersion||this._documentMaterializationSignature(this._state.getSerializableDocument())!==a.documentSignature||a.requiredLayerId&&!this._state.getLayer(a.requiredLayerId))}_isCurrentDocumentMaterializationContext(a){if(!a||this._destroyed||this._loadVersion!==a.loadVersion)return!1;const t=this._state.getEditorDocumentBinding();if(!t||(t.documentId??null)!==a.documentId||(t.documentRevisionId??null)!==a.documentRevisionId||(t.documentRevisionNumber??null)!==a.documentRevisionNumber)return!1;const n=this._state.getSerializableDocument();return!(this._documentMaterializationSignature(n)!==a.documentSignature||a.requiredLayerId&&!this._state.getLayer(a.requiredLayerId))}async _materializeCurrentDocument(a="Editor document materialization failed",t=null){const n=this._backgroundMaterializeEndpoint(),i=this._state.getEditorDocumentBinding(),r=this._state.getSerializableDocument();if(!n||!(i!=null&&i.documentId)||!r||t!==null&&!t)return!1;const l=this._resolveBackgroundEndpoint(n,r);if(!l)return!1;const s=this._captureDocumentMaterializationContext(r,i,t),d=gr(i.documentId)?i.documentId:null,c=await fetch(l,{method:"POST",credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({document_id:d,base_document_revision:d===null?null:i.documentRevisionNumber,document:r})});let u=null;try{u=await c.json()}catch{u=null}if(!c.ok){const m=(u==null?void 0:u.message)||a;throw new Error(m)}return this._isCurrentDocumentMaterializationContext(s)?(u!=null&&u.document&&this._state.setEditorDocument(u.document,{documentId:u.document_id??i.documentId,documentRevisionId:u.document_revision_id??i.documentRevisionId,documentRevisionNumber:typeof u.document_revision_number=="number"?u.document_revision_number:i.documentRevisionNumber}),!0):!1}async _uploadBackgroundAsset(a,t,n){var f,h,v;const i=(h=(f=this._options)==null?void 0:f.backgroundReplacement)==null?void 0:h.assetEndpoint,r=this._state.getEditorDocumentBinding(),l=this._state.getSerializableDocument();if(!i||!(r!=null&&r.documentId)||!l)return null;const s=this._resolveBackgroundEndpoint(i,l);if(!s)return null;const d=await this._sha256File(a),c=new FormData;c.append("asset_file",a,a instanceof File&&a.name?a.name:"background.png"),c.append("asset_kind","background-upload"),c.append("document_id",r.documentId),c.append("layer_id",t),c.append("client_hash",d);const u=await fetch(s,{method:"POST",credentials:"include",headers:{Accept:"application/json"},body:c});if(!u.ok)throw new Error("Background upload failed");const m=await u.json(),p=(v=m==null?void 0:m.asset)==null?void 0:v.source;if(!p||typeof p!="object")throw new Error("Background upload did not return a usable layer source");return{...p,previewUrl:n}}_backgroundMaterializeEndpoint(){var i,r,l,s,d,c;const a=(r=(i=this._options)==null?void 0:i.backgroundReplacement)==null?void 0:r.materializeEndpoint;if(typeof a=="string"&&a.trim()!=="")return a;const t=(s=(l=this._options)==null?void 0:l.backgroundReplacement)==null?void 0:s.assetEndpoint;if(typeof t=="string"&&t.trim()!=="")return t.replace(/\/editor-assets\/?$/,"/editor-documents/materialize");const n=(c=(d=this._options)==null?void 0:d.backgroundRemoval)==null?void 0:c.savedEndpoint;return typeof n=="string"&&n.trim()!==""?n.replace(/\/background-removal\/?$/,"/editor-documents/materialize"):null}_resolveBackgroundEndpoint(a,t){if(typeof a!="string"||a.trim()==="")return null;const n=this._backgroundTargetMediaUuid(t);return a.includes("{media}")?typeof n!="string"||n.trim()===""?null:a.replace("{media}",encodeURIComponent(n)):a}_backgroundTargetMediaUuid(a){var n,i;const t=(i=(n=this._options)==null?void 0:n.backgroundReplacement)==null?void 0:i.targetMediaUuid;return typeof t=="string"&&t.trim()!==""?t:typeof(a==null?void 0:a.sourceMediaUuid)=="string"&&a.sourceMediaUuid.trim()!==""?a.sourceMediaUuid:null}async _sha256File(a){var i,r,l;const t=await a.arrayBuffer(),n=await((l=(r=(i=globalThis.crypto)==null?void 0:i.subtle)==null?void 0:r.digest)==null?void 0:l.call(r,"SHA-256",t));if(!n)throw new Error("Background upload hashing is unavailable");return Array.from(new Uint8Array(n)).map(s=>s.toString(16).padStart(2,"0")).join("")}_probeImageDimensions(a){return new Promise(t=>{const n=new Image;n.onload=()=>t({width:Math.max(1,Math.round(n.naturalWidth||n.width||1)),height:Math.max(1,Math.round(n.naturalHeight||n.height||1))}),n.onerror=()=>t({width:1,height:1}),n.src=a})}setFilterRegistry(a){this._filterManager.setRegistry(a)}async loadImage(a,t={}){var s,d,c,u;if(this._destroyed)return;(d=(s=this._removeBgManager)==null?void 0:s.cancelActiveRequests)==null||d.call(s,"image-load");const n=++this._loadVersion;let i=a,r=null;this._resetEditorState(),this._state.set("hasImage",!1),this._state.set("imageUrl",null),a instanceof Blob&&(i=URL.createObjectURL(a),r=i,this._objectUrls.add(i));const l=await this._renderer.loadTexture(i,{isCurrent:()=>!this._destroyed&&this._loadVersion===n});if(this._destroyed||this._loadVersion!==n){this._revokeObjectUrl(r);return}if(!l){this._revokeObjectUrl(r),this.emit("error",new Error("Failed to load image"));return}r?this._replaceActiveObjectUrl(r):this._clearActiveObjectUrl(),this._state.set("hasImage",!0),this._state.set("imageUrl",i),t.document?await this._hydrateDocument(t.document,{documentId:t.documentId??(gr((c=t.document)==null?void 0:c.id)?t.document.id:null),documentRevisionId:t.documentRevisionId??null,documentRevisionNumber:t.documentRevisionNumber??((u=t.document)==null?void 0:u.revision)??null,fallbackImageUrl:i}):this._initializeDefaultDocument(i),t.state&&this._hydrateState(t.state),this._options.initialMode==="crop"&&this.setMode("crop"),this.emit("imageLoaded",{url:i})}_resetEditorState(){this._filterManager.resetAll(),this._state.set("crop.rect",null),this._state.set("crop.appliedRect",null),this._state.set("crop.appliedShape",null),this._state.set("crop.appliedAspect",null),this._state.set("crop.dirty",!1),this._state.set("crop.shape",this._options.cropShape||"free"),this._state.set("crop.aspect",this._options.initialAspectRatio||"free"),this._state.set("transform.rotation",0),this._state.clearEditorDocument(),this._state.get("mode")==="crop"&&(this._cropManager.disable(),this._state.set("mode","filters"))}_initializeDefaultDocument(a){var c,u,m,p;const t=this._renderer.originalTexture,n=Math.max(1,Math.round((t==null?void 0:t.width)||1)),i=Math.max(1,Math.round((t==null?void 0:t.height)||1)),r=Oh(),l=typeof((u=(c=this._options)==null?void 0:c.backgroundReplacement)==null?void 0:u.targetMediaUuid)=="string"&&this._options.backgroundReplacement.targetMediaUuid.trim()!==""?this._options.backgroundReplacement.targetMediaUuid.trim():null,s=l?{kind:"media",mediaUuid:l,originalWidth:n,originalHeight:i,sourceHash:null}:{kind:"runtime",runtimeRef:"source-image",originalWidth:n,originalHeight:i,sourceHash:null,previewUrl:typeof a=="string"?a:null},d={version:2,id:`client-doc-${Date.now()}`,sourceMediaUuid:l,canvas:{width:n,height:i,backgroundPreviewColor:null},revision:0,layers:[{id:"subject-layer",type:"image",role:"subject",name:"Subject",visible:!0,locked:!1,opacity:1,blendMode:"normal",transform:{x:0,y:0,scaleX:1,scaleY:1,rotation:0},effects:[],metadata:{},source:s,crop:null,filters:[]}],activeLayerId:"subject-layer",export:{mimeType:"image/png",quality:null,preserveTransparency:!0,matteColor:null,trimTransparentBounds:!1},createdAt:r,updatedAt:r};this._state.setEditorDocument(d,{documentId:null,documentRevisionId:null,documentRevisionNumber:0}),(p=(m=this._renderer).renderLayerDocument)==null||p.call(m,d,{fallbackImageUrl:typeof a=="string"?a:null})}async _hydrateDocument(a,t={}){var n,i;!a||a.version!==2||(this._state.setEditorDocument(a,{documentId:t.documentId??(gr(a.id)?a.id:null),documentRevisionId:t.documentRevisionId??null,documentRevisionNumber:t.documentRevisionNumber??a.revision??null}),await((i=(n=this._renderer).renderLayerDocument)==null?void 0:i.call(n,this._state.getSerializableDocument(),{fallbackImageUrl:t.fallbackImageUrl??this._state.get("imageUrl")??null})))}_hydrateState(a){var n;if(!a||a.version!==1)return;const t=qo(((n=a.transform)==null?void 0:n.rotation)??0);if(t!==0&&this._renderer.rotateBy(t)&&this._state.set("transform.rotation",t),a.crop){const i=a.crop.shape||"free",r=a.crop.aspectRatio||"free";a.crop.rect&&(this._cropManager.applyFromPixelRect(a.crop.rect,i),this._state.set("crop.appliedRect",{...a.crop.rect}),this._state.set("crop.appliedShape",i),this._state.set("crop.appliedAspect",r)),this._state.set("crop.shape",i),this._state.set("crop.aspect",r)}if(Array.isArray(a.filters)){let i=null;for(const r of a.filters)if(r.enabled&&(i===null&&(i=r.id),this._state.toggleFilter(r.id,!0),this._filterManager.initializeValues(r.id),r.values))for(const[l,s]of Object.entries(r.values))this._state.setFilterValue(r.id,l,s);if(i!==null){this._state.set("selectedFilter",i);const r=this._filterManager.getFilterDef(i);if(typeof(r==null?void 0:r.category)=="string"){const l=de.REGISTRY_TO_UI[r.category]??r.category;this._state.set("selectedCategory",l)}}this._filterManager.applyFilters()}}openFilePicker(){var a;(a=this._fileInput)==null||a.click()}exportImage(a="png",t=.92,n={}){return!this._state.get("hasImage")||!this._applyPendingCropBeforeExport("VanillaImageEditorV2.exportImage")?null:this._renderer.exportImage(a,t,n.maxEdge??0,n.dontUpscale!==!1,n.maxPixels??0)}async exportBlob(a="png",t=.92,n={}){return!this._state.get("hasImage")||!this._applyPendingCropBeforeExport("VanillaImageEditorV2.exportBlob")?null:this._renderer.exportBlob(a,t,n)}_applyPendingCropBeforeExport(a){return!(this._state.get("crop.rect")&&!this._cropManager.apply())}async save(){if(!this._state.get("hasImage"))return;this._state.set("isSaving",!0);let a=null;try{const t=await this.exportBlob("png",.92);if(!t)throw new Error("Failed to export image");const n=i.createElement("a");a=URL.createObjectURL(t.blob),n.href=a,n.download=`edited-image-${Date.now()}.png`,i.body.appendChild(n),n.click(),i.body.removeChild(n);const i=this.getSerializableDocument(),r=this.getEditorDocumentBinding();this.emit("save",{blob:t.blob,mimeType:t.blob.type||"image/png",dimensions:{width:t.width,height:t.height},state:this.getSerializableState(),document:i,documentId:(r==null?void 0:r.documentId)??(gr(i==null?void 0:i.id)?i.id:null),documentRevisionId:(r==null?void 0:r.documentRevisionId)??null,documentRevisionNumber:(r==null?void 0:r.documentRevisionNumber)??(i==null?void 0:i.revision)??null})}catch(t){this.emit("error",{error:t})}finally{a&&URL.revokeObjectURL(a),this._state.set("isSaving",!1)}}getSerializableState(){const a=this._state.get("activeFilters"),t=[];if(a)for(const l of a){const s=this._state.getFilterValues(l);t.push({id:l,enabled:!0,values:{...s}})}const n=this._state.get("crop.appliedRect"),i=this._state.get("crop.rect"),r=n||i;return{version:1,crop:{rect:r?{...r}:null,aspectRatio:this._state.get("crop.appliedAspect")||this._state.get("crop.aspect")||"free",shape:this._state.get("crop.appliedShape")||this._state.get("crop.shape")||"free"},transform:{rotation:qo(this._state.get("transform.rotation")??0)},filters:t}}getSerializableDocument(){return this._state.getSerializableDocument()}getEditorDocumentBinding(){return this._state.getEditorDocumentBinding()}close(){this.emit("cancel")}setZoom(a){this._renderer.setZoom(a)}fitToScreen(){this._renderer.fitToScreen()}resetAll(a=void 0){this._filterManager.resetAll(a)}rotateBy(a){const t=this._state.get("transform.rotation")??0;return this.setRotationAngle(Number(t)+Number(a))}setRotationAngle(a){if(!this._state.get("hasImage"))return!1;const t=qo(this._state.get("transform.rotation")??0),n=qo(a),i=Uh(t,n),r=this._state.get("mode")==="crop";if(Math.abs(i)>.001){if(r&&this._cropManager.disable(),!this._renderer.rotateBy(i))return r&&this._cropManager.enable(),!1;this._filterManager.applyFilters(),this._state.set("crop.rect",null),this._state.set("crop.dirty",!1),r&&this._cropManager.enable()}return this._state.set("transform.rotation",n),this.emit("transformChanged",{rotation:n}),!0}resetRotation(){return this.setRotationAngle(0)}toggleTheme(){const a=this._state.get("isDarkMode");this._state.set("isDarkMode",!a)}setTheme(a){this._state.set("theme",a),this._state.detectTheme()}setMode(a){a==="crop"?this._cropManager.enable():this._cropManager.disable(),this._state.set("mode",a)}getState(){return this._state.getAll()}async removeBackground(a={}){var t,n,i,r,l,s,d,c,u,m;if(!this._removeBgManager)throw new Error("Background removal is not enabled");if(!this._state.get("hasImage"))throw new Error("No image loaded");if(!this.canRemoveBackground())throw new Error("Background removal is not available for the current editor state");this._state.set("isProcessing",!0),this._showLoadingOverlay("Removing background...");try{const p=this._activeBackgroundRemovalLayer();if(this._hasSavedEditorDocumentBinding()&&p!==null&&this._backgroundMaterializeEndpoint()&&!await this._materializeCurrentDocument("Background removal materialization failed"))return this.emit("background-removal-stale",{operationId:a.operationId??null,targetLayerId:p.id}),{stale:!0};const f=this._buildSavedBackgroundRemovalContext(a);if(f){const g=await this._removeBgManager.removeSavedMediaBackground(f.request);if(!this._isCurrentBackgroundRemovalContext(f,g))return this.emit("background-removal-stale",{operationId:f.request.operationId,targetLayerId:f.request.targetLayerId}),{stale:!0};const I=(t=g==null?void 0:g.result)==null?void 0:t.source;if(!I||I.kind!=="edit-asset")throw new Error("Background removal did not return a persisted layer source");const T=(n=g==null?void 0:g.result)==null?void 0:n.previewDataUrl;return typeof T=="string"&&T.startsWith("data:image/")&&(!await this._renderer.loadTexture(T,{isCurrent:()=>!this._destroyed&&this._isCurrentBackgroundRemovalContext(f,g)})||!this._isCurrentBackgroundRemovalContext(f,g))?(this.emit("background-removal-stale",{operationId:f.request.operationId,targetLayerId:f.request.targetLayerId}),{stale:!0}):this._isCurrentBackgroundRemovalContext(f,g)?(this._state.replaceLayerSource(f.request.targetLayerId,I),await((r=(i=this._renderer).renderLayerDocument)==null?void 0:r.call(i,this._state.getSerializableDocument(),{fallbackImageUrl:this._state.get("imageUrl")??null})),this.emit("background-removed",{model:(l=g==null?void 0:g.result)==null?void 0:l.model,processMs:(s=g==null?void 0:g.result)==null?void 0:s.process_ms,source:I,operationId:f.request.operationId,targetLayerId:f.request.targetLayerId}),{model:(d=g==null?void 0:g.result)==null?void 0:d.model,processMs:(c=g==null?void 0:g.result)==null?void 0:c.process_ms,source:I}):(this.emit("background-removal-stale",{operationId:f.request.operationId,targetLayerId:f.request.targetLayerId}),{stale:!0})}const h=this._buildPreviewBackgroundRemovalInput(a);if(!h)throw new Error("Failed to export image for background removal");const v=this._buildPreviewBackgroundRemovalContext(h.options),y=await this._removeBgManager.preparePreviewRequest(h.imageData,h.options),w=this._resolvePreviewBackgroundRemovalContext(v,y);if(!await this._isCurrentPreviewBackgroundRemovalContext(w))return this.emit("background-removal-stale",{operationId:w.operationId,sourceHash:w.sourceHash,targetLayerId:w.activeLayerId??null}),{stale:!0};const _=await this._removeBgManager.removeBackground(y.blob,y);if(!await this._isCurrentPreviewBackgroundRemovalContext(w,_))return this.emit("background-removal-stale",{operationId:w.operationId,sourceHash:w.sourceHash}),{stale:!0};const b=await this._applyPreviewBackgroundRemovalResult(w,_);return b?(this.emit("background-removed",{model:_.model,processMs:_.processMs,operationId:w.operationId,targetLayerId:w.activeLayerId??null,source:b.source}),{model:_.model,processMs:_.processMs,...b.source?{source:b.source}:{}}):(this.emit("background-removal-stale",{operationId:w.operationId,sourceHash:w.sourceHash,targetLayerId:w.activeLayerId??null}),{stale:!0})}catch(p){throw this.emit("error",{error:p,context:"background-removal"}),p}finally{(m=(u=this._state)==null?void 0:u.set)==null||m.call(u,"isProcessing",!1),this._hideLoadingOverlay()}}async isBackgroundRemovalAvailable(){return this._removeBgManager?this._refreshBackgroundRemovalAvailability():!1}canRemoveBackground(){if(!this._removeBgManager||this._state.get("hasImage")!==!0||this._backgroundRemovalAvailable!==!0)return!1;const a=this._state.getSerializableDocument();return(a==null?void 0:a.version)===2&&Array.isArray(a.layers)?this._activeBackgroundRemovalLayer({requireSourceHash:this._hasSavedEditorDocumentBinding()})!==null:!0}async _refreshBackgroundRemovalAvailability(){if(!this._removeBgManager)return this._backgroundRemovalAvailable=!1,this._state.set("backgroundRemovalAvailable",!1),!1;const a=await this._removeBgManager.isAvailable();return this._destroyed?!1:(this._backgroundRemovalAvailable=a,this._state.set("backgroundRemovalAvailable",a),a)}_hasSavedEditorDocumentBinding(){const a=this._state.getEditorDocumentBinding();return!!(a!=null&&a.documentId)&&!!(a!=null&&a.documentRevisionId)}_activeBackgroundRemovalLayer(a={}){var l;const t=a.requireSourceHash!==!1,n=this._state.get("activeLayerId");if(!n)return null;const i=this._state.getLayer(n);if(!i||i.type!=="image"||i.locked===!0||i.visible===!1)return null;const r=(l=i==null?void 0:i.source)==null?void 0:l.sourceHash;return t&&(typeof r!="string"||!/^[a-f0-9]{64}$/i.test(r))?null:i}_buildSavedBackgroundRemovalContext(a={}){var u,m,p,f,h;const t=this._state.getSerializableDocument(),n=this._state.getEditorDocumentBinding();if(!t||!(n!=null&&n.documentId)||!(n!=null&&n.documentRevisionId))return null;const i=typeof t.sourceMediaUuid=="string"&&t.sourceMediaUuid!==""?t.sourceMediaUuid:null;if(!i)return null;const r=this._activeBackgroundRemovalLayer({requireSourceHash:!0}),l=r==null?void 0:r.id,s=(u=r==null?void 0:r.source)==null?void 0:u.sourceHash;if(!l||typeof s!="string"||!/^[a-f0-9]{64}$/i.test(s))return null;const d=a.operationId||((p=(m=globalThis.crypto)==null?void 0:m.randomUUID)==null?void 0:p.call(m))||`op-${Date.now()}-${Math.random().toString(16).slice(2)}`,c={loadVersion:this._loadVersion,activeLayerId:l,documentRevisionId:n.documentRevisionId,documentSignature:this._documentMaterializationSignature(t),sourceHash:s,request:{targetMediaUuid:i,operationId:d,documentId:n.documentId,documentRevisionId:n.documentRevisionId,targetLayerId:l,expectedSourceHash:s,tier:a.tier||((h=(f=this._options)==null?void 0:f.backgroundRemoval)==null?void 0:h.defaultTier)||"balanced"}};return a.model&&(c.request.model=a.model),a.alpha_matting!==void 0&&(c.request.alpha_matting=a.alpha_matting),a.max_megapixels!==void 0&&(c.request.max_megapixels=a.max_megapixels),c}_buildPreviewBackgroundRemovalContext(a){const t=this._state.getSerializableDocument(),n=(t==null?void 0:t.version)===2&&Array.isArray(t.layers),i=n?this._activeBackgroundRemovalLayer({requireSourceHash:!1}):null;return{loadVersion:this._loadVersion,activeLayerId:n?(i==null?void 0:i.id)??null:null,documentSignature:n?this._documentMaterializationSignature(t):null,imageUrl:this._state.get("imageUrl")??null,operationId:a.operationId,sessionKey:a.sessionKey,sourceHash:a.sourceHash,targetRef:a.targetRef??null}}_resolvePreviewBackgroundRemovalContext(a,t){return{...a,operationId:t.operationId,sessionKey:t.sessionKey,sourceHash:t.sourceHash,targetRef:t.targetRef??a.targetRef??null}}_buildPreviewBackgroundRemovalInput(a={}){const t=this._state.getSerializableDocument();if((t==null?void 0:t.version)===2&&Array.isArray(t.layers)){const i=this._activeBackgroundRemovalLayer({requireSourceHash:!1}),r=this._sourceUrlForLayerSource(i==null?void 0:i.source);return!i||!r?null:{imageData:r,options:{...a,targetRef:i.id}}}const n=this.exportImage("png");return n?{imageData:n,options:a}:null}_sourceUrlForLayerSource(a){if(!a||typeof a!="object")return null;for(const t of["previewUrl","sourceUrl","url"]){const n=a[t];if(typeof n=="string"&&n.trim()!=="")return n}return null}async _applyPreviewBackgroundRemovalResult(a,t){var r,l;if(a.documentSignature===null||!a.activeLayerId)return await this.loadImage(t.dataUrl),{source:null};const n=await this._probeImageDimensions(t.dataUrl);if(!await this._isCurrentPreviewBackgroundRemovalContext(a,t))return null;const i={kind:"runtime",runtimeRef:`background-removal-${a.operationId||Date.now()}`,originalWidth:n.width,originalHeight:n.height,sourceHash:null,previewUrl:t.dataUrl};return this._state.replaceLayerSource(a.activeLayerId,i)?(await((l=(r=this._renderer).renderLayerDocument)==null?void 0:l.call(r,this._state.getSerializableDocument(),{fallbackImageUrl:this._state.get("imageUrl")??null})),{source:i}):null}async _isCurrentPreviewBackgroundRemovalContext(a,t=null){if(this._destroyed||this._loadVersion!==a.loadVersion||this._state.get("hasImage")!==!0||(this._state.get("imageUrl")??null)!==a.imageUrl)return!1;if(t){if(t.operationId&&t.operationId!==a.operationId||t.sessionKey&&t.sessionKey!==a.sessionKey||t.sourceHash&&t.sourceHash!==a.sourceHash)return!1;if(a.documentSignature!==null){if(!a.targetRef||a.targetRef!==a.activeLayerId||t.targetRef!==a.targetRef)return!1}else if(t.targetRef&&a.targetRef&&t.targetRef!==a.targetRef)return!1}if(a.documentSignature!==null){const i=this._state.getSerializableDocument();if(this._documentMaterializationSignature(i)!==a.documentSignature)return!1;const r=this._activeBackgroundRemovalLayer({requireSourceHash:!1});return!(!r||r.id!==a.activeLayerId)}const n=this.exportImage("png");return n?await this._removeBgManager.computeImageDataHash(n)===a.sourceHash:!1}_isCurrentBackgroundRemovalContext(a,t=null){var l;if(this._destroyed||this._loadVersion!==a.loadVersion)return!1;const n=this._state.getEditorDocumentBinding();if(!n||n.documentRevisionId!==a.documentRevisionId)return!1;const i=this._state.getSerializableDocument();if(this._documentMaterializationSignature(i)!==a.documentSignature||this._state.get("activeLayerId")!==a.activeLayerId)return!1;const r=this._state.getLayer(a.request.targetLayerId);return!(!r||((l=r==null?void 0:r.source)==null?void 0:l.sourceHash)!==a.sourceHash||r.locked===!0||r.visible===!1||t&&(t.operation_id&&t.operation_id!==a.request.operationId||t.target_layer_id&&t.target_layer_id!==a.request.targetLayerId||t.document_revision_id&&t.document_revision_id!==a.request.documentRevisionId||t.source_hash&&t.source_hash!==a.request.expectedSourceHash))}_showLoadingOverlay(a){var n;if(!this._loadingOverlay)this._loadingOverlay=de.el("div",{className:"editor-loading-overlay"},de.el("div",{className:"editor-loading-spinner"}),de.el("div",{className:"editor-loading-text"},a));else{const i=this._loadingOverlay.querySelector(".editor-loading-text");i&&(i.textContent=a)}const t=(n=this._canvasContainer)==null?void 0:n.parentElement;t&&!this._loadingOverlay.parentElement&&t.appendChild(this._loadingOverlay)}_hideLoadingOverlay(){var a;(a=this._loadingOverlay)==null||a.remove()}_buildMobileSaveBar(){var l,s;this._mobileSaveBar=de.el("div",{className:"editor-v2-mobile-save-bar",role:"region","aria-label":"Save bar"}),this._mobileSaveBtn=de.el("button",{type:"button",className:"mobile-save-btn",title:"Save Image","aria-label":"Save image",dataset:{testid:"btn-save-edit-mobile"},onClick:()=>this.save()});const a=de.el("span",{className:"mobile-save-icon"});a.innerHTML=de.save;const t=a.querySelector("svg");t&&t.setAttribute("aria-hidden","true"),this._mobileSaveBtn.appendChild(a),this._mobileSaveBtn.appendChild(de.el("span",{className:"mobile-save-label"},"Save")),this._mobileSaveBar.appendChild(this._mobileSaveBtn);const n=()=>{var m,p;if(!this._mobileSaveBtn)return;const d=((m=this._state)==null?void 0:m.get("hasImage"))===!0,c=((p=this._state)==null?void 0:p.get("isProcessing"))===!0,u=!d||c;this._mobileSaveBtn.disabled=u,this._mobileSaveBtn.setAttribute("aria-disabled",u?"true":"false")};n();const i=(l=this._state)==null?void 0:l.on("change:hasImage",n),r=(s=this._state)==null?void 0:s.on("change:isProcessing",n);this._mobileSaveUnsub=()=>{try{i==null||i()}catch{}try{r==null||r()}catch{}}}destroy(){var a,t,n,i,r,l,s,d;this._destroyed=!0,(t=(a=this._removeBgManager)==null?void 0:a.cancelActiveRequests)==null||t.call(a,"editor-destroy");for(const c of this._objectUrls)try{URL.revokeObjectURL(c)}catch{}this._objectUrls.clear(),this._activeObjectUrl=null,(n=this._resizeObserver)==null||n.disconnect(),this._renderer.destroy(),this._cropManager.disable(),this._handleWindowResize&&window.removeEventListener("resize",this._handleWindowResize),(i=this._toolbar)==null||i.destroy(),(r=this._cropControls)==null||r.destroy(),(l=this._layout)==null||l.destroy(),(s=this._mobileSaveUnsub)==null||s.call(this),this._mobileSaveUnsub=null,this._mobileSaveBtn=null,this._mobileSaveBar=null,(d=this._editorEl)==null||d.remove(),this._container=null,this._state=null,this.emit("destroyed"),this.removeAllListeners()}}function jh(o,a){try{let t=la.getFilter(o);if(t||(la.registerCorePixiFilters(),t=la.getFilter(o)),!t){try{const r=la.getAllFilters()}catch{}return null}const n={...t.defaultParams,...a};return t.createFilter(n)}catch{return null}}const Wh=78e5,Hh=e.defineComponent({__name:"ImageEditor",props:{initialImage:{},initialState:{default:null},initialDocument:{default:null},initialDocumentId:{default:null},initialDocumentRevisionId:{default:null},initialDocumentRevisionNumber:{default:null},sessionKey:{default:0},theme:{default:"auto"},cropShape:{default:"square"},preset:{},editorVersion:{default:"v2"},backgroundRemoval:{default:null},backgroundReplacement:{default:null},primaryColor:{default:"#3880ff"},secondaryColor:{default:"#5260ff"},saveButtonColor:{default:"#3880ff"},downloadButtonColor:{default:"#2dd36f"}},emits:["save","cancel","error"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(null);let r=null,l=null;function s(v){return typeof v=="string"&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v)}function d(){const v={state:t.initialState??null,sessionKey:t.sessionKey};return t.initialDocument&&(v.document=t.initialDocument,v.documentId=t.initialDocumentId,v.documentRevisionId=t.initialDocumentRevisionId,v.documentRevisionNumber=t.initialDocumentRevisionNumber),v}async function c(){var v,y,w;try{if(!r){n("error",new Error("Editor not initialized"));return}const _=await((v=r.exportBlob)==null?void 0:v.call(r,"png",.92,{maxPixels:Wh}));if(!_){n("error",new Error("Failed to export image — the image could not be processed"));return}const b=r.getSerializableState(),g={blob:_.blob,mimeType:_.blob.type||"image/png",dimensions:{width:_.width,height:_.height},state:b},I=((y=r.getSerializableDocument)==null?void 0:y.call(r))??null;if(I){const T=((w=r.getEditorDocumentBinding)==null?void 0:w.call(r))??null;g.document=I,g.documentId=(T==null?void 0:T.documentId)??(s(I.id)?I.id:null),g.documentRevisionId=(T==null?void 0:T.documentRevisionId)??null,g.documentRevisionNumber=(T==null?void 0:T.documentRevisionNumber)??I.revision??null}n("save",g)}catch(_){n("error",_ instanceof Error?_:new Error("Failed to export image"))}}function u(){n("cancel")}function m(v){if(v instanceof Error)return v;if(v!==null&&typeof v=="object"&&"error"in v){const y=v.error;if(y instanceof Error)return y;if(typeof y=="string"&&y.trim()!=="")return new Error(y)}return typeof v=="string"&&v.trim()!==""?new Error(v):new Error("Failed to load image")}function p(v){n("error",m(v))}function f(){if(!i.value||r)return;window.PIXI=na,la.initializeFilterRegistry();const v={theme:t.theme};t.backgroundRemoval&&(v.backgroundRemoval=t.backgroundRemoval),t.backgroundReplacement&&(v.backgroundReplacement=t.backgroundReplacement),t.preset&&(v.preset=t.preset),t.preset?t.cropShape==="circle"&&(v.cropShape="circle",v.initialAspectRatio="1:1",v.initialMode="crop"):(v.cropShape=t.cropShape==="circle"?"circle":"free",v.initialAspectRatio=t.cropShape==="circle"?"1:1":"free",v.initialMode=t.cropShape==="circle"?"crop":"adjust");const y=t.editorVersion==="v2"?zh:de.VanillaImageEditor,w=new y(i.value,v);r=w,w.setFilterRegistry({getAllFilters:la.getAllFilters,getFilter:la.getFilter,getFiltersByCategory:la.getFiltersByCategory}),w.save=function(){c()},w.on("cancel",u),w.on("error",p),t.initialImage&&w.loadImage(t.initialImage,d())}e.onMounted(()=>{i.value&&(i.value.clientWidth>0?f():(l=new ResizeObserver(v=>{const y=v[0];y&&y.contentRect.width>0&&!r&&(f(),l==null||l.disconnect(),l=null)}),l.observe(i.value)))});const h=()=>{!r||!t.initialImage||r.loadImage(t.initialImage,d())};return e.watch(()=>t.initialImage,(v,y)=>{!r||!v||v===y||h()}),e.watch(()=>t.sessionKey,(v,y)=>{v!==y&&h()}),e.watch(()=>t.initialState,(v,y)=>{v!==y&&h()}),e.watch(()=>[t.initialDocument,t.initialDocumentId,t.initialDocumentRevisionId,t.initialDocumentRevisionNumber],(v,y)=>{v!==y&&h()}),e.onUnmounted(()=>{l==null||l.disconnect(),l=null,r&&(r.destroy(),r=null)}),(v,y)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"containerRef",ref:i,class:"vanilla-editor-wrapper","data-testid":"vanilla-image-editor"},null,512))}}),Ae=(o,a)=>{const t=o.__vccOpts||o;for(const[n,i]of a)t[n]=i;return t},hm=Ae(Hh,[["__scopeId","data-v-8ab74f83"]]),Zh={class:"editor-modal-panel"},Gh={class:"editor-fill"},Xh=e.defineComponent({__name:"ImageEditorModal",props:{modelValue:{type:Boolean,default:!1},initialImage:{},initialState:{default:null},initialDocument:{default:null},initialDocumentId:{default:null},initialDocumentRevisionId:{default:null},initialDocumentRevisionNumber:{default:null},sessionKey:{default:0},acceptedFormats:{default:"image/jpeg,image/png,image/webp,image/gif"},maxFileSize:{default:10},theme:{default:"auto"},cropShape:{default:"square"},preset:{},editorVersion:{default:"v2"},backgroundRemoval:{default:null},backgroundReplacement:{default:null},primaryColor:{default:"#3880ff"},secondaryColor:{default:"#5260ff"},saveButtonColor:{default:"#3880ff"},downloadButtonColor:{default:"#2dd36f"},saveHandler:{}},emits:["update:modelValue","save","cancel","error"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(null),r=e.ref(t.modelValue),l=e.ref(!1),s=e.ref(null),d=v=>{n("error",v)},c=()=>{e.nextTick(()=>{if(i.value){const v=i.value.querySelector("button:not([disabled]), [href], input:not([disabled])");v&&v.focus()}})};e.watch(()=>t.modelValue,v=>{r.value=v,v&&(s.value=document.activeElement,c())},{immediate:!0});const u=async v=>{try{if(l.value=!0,t.saveHandler){await t.saveHandler(v);return}n("save",v)}catch(y){d(y instanceof Error?y:new Error("Failed to save image"))}finally{l.value=!1}},m=()=>{n("cancel"),f()},p=()=>{l.value||f()},f=()=>{r.value=!1,n("update:modelValue",!1),s.value&&s.value instanceof HTMLElement&&(s.value.focus(),s.value=null)},h=v=>{if(v.key==="Escape"&&r.value&&!l.value){f();return}if(v.key==="Tab"&&r.value&&i.value){const y=i.value.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])');if(y.length===0)return;const w=y[0],_=y[y.length-1];v.shiftKey&&document.activeElement===w?(v.preventDefault(),_.focus()):!v.shiftKey&&document.activeElement===_&&(v.preventDefault(),w.focus())}};return e.onMounted(()=>{document.addEventListener("keydown",h)}),e.onBeforeUnmount(()=>{document.removeEventListener("keydown",h)}),(v,y)=>(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[r.value?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"overlayRef",ref:i,role:"dialog","aria-modal":"true","aria-label":"Image editor",class:"editor-modal-overlay","data-testid":"image-editor-modal",onKeydown:e.withKeys(p,["escape"])},[e.createElementVNode("div",{class:"editor-modal-backdrop",onClick:p}),e.createElementVNode("div",Zh,[e.createElementVNode("div",Gh,[e.createVNode(hm,{"initial-image":v.initialImage,"initial-state":v.initialState,"initial-document":v.initialDocument,"initial-document-id":v.initialDocumentId,"initial-document-revision-id":v.initialDocumentRevisionId,"initial-document-revision-number":v.initialDocumentRevisionNumber,"session-key":v.sessionKey,theme:v.theme,"crop-shape":v.cropShape,preset:v.preset,"editor-version":v.editorVersion,"background-removal":v.backgroundRemoval,"background-replacement":v.backgroundReplacement,"primary-color":v.primaryColor,"secondary-color":v.secondaryColor,"save-button-color":v.saveButtonColor,"download-button-color":v.downloadButtonColor,onSave:u,onCancel:m,onError:d},null,8,["initial-image","initial-state","initial-document","initial-document-id","initial-document-revision-id","initial-document-revision-number","session-key","theme","crop-shape","preset","editor-version","background-removal","background-replacement","primary-color","secondary-color","save-button-color","download-button-color"])])])],544)):e.createCommentVNode("",!0)]))}}),vm=Ae(Xh,[["__scopeId","data-v-bd4e671f"]]),Kh={class:"media-workspace"},qh={class:"media-workspace-toolbar"},Jh={class:"media-workspace-label"},Yh=["value"],Qh={class:"media-workspace-grid"},ev=["onClick"],tv=e.defineComponent({__name:"MediaWorkspace",props:{apiScope:{},subScopes:{},initialScopeId:{}},emits:["scope-change","update:media","upload","preview"],setup(o,{emit:a}){var m;const t=o,n=a,i=ja(),r=e.ref(t.initialScopeId??((m=t.subScopes[0])==null?void 0:m.id)??""),l=e.computed(()=>t.subScopes),s=e.computed(()=>l.value.find(p=>p.id===r.value));let d=null;function c(){d&&(d(),d=null),t.apiScope&&(d=lm({apiScope:t.apiScope,isAdmin:t.apiScope==="admin"}))}async function u(){var f;const p={};(f=s.value)!=null&&f.collection&&(p.collection=s.value.collection),await i.fetchMedia(1,p),n("update:media",[...i.items])}return e.watch(()=>t.initialScopeId,p=>{p&&p!==r.value&&(r.value=p)}),e.watch(()=>t.subScopes,p=>{if(p.length===0){r.value="";return}p.some(f=>f.id===r.value)||(r.value=p[0].id)},{deep:!0}),e.watch(()=>t.apiScope,()=>{c(),u()}),e.watch(r,p=>{p&&(n("scope-change",p),u())}),e.onMounted(()=>{c(),u()}),e.onUnmounted(()=>{d&&(d(),d=null)}),(p,f)=>(e.openBlock(),e.createElementBlock("div",Kh,[e.createElementVNode("div",qh,[e.createElementVNode("label",Jh,[f[2]||(f[2]=e.createElementVNode("span",{class:"media-workspace-label-text"},"Scope",-1)),e.withDirectives(e.createElementVNode("select",{"onUpdate:modelValue":f[0]||(f[0]=h=>r.value=h),"data-testid":"scope-select",class:"media-workspace-select"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.value,h=>(e.openBlock(),e.createElementBlock("option",{key:h.id,value:h.id},e.toDisplayString(h.label),9,Yh))),128))],512),[[e.vModelSelect,r.value]])]),e.createElementVNode("button",{type:"button",class:"media-workspace-upload","data-testid":"upload-button",onClick:f[1]||(f[1]=h=>n("upload"))}," Upload ")]),e.createElementVNode("div",Qh,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(i).items,h=>(e.openBlock(),e.createElementBlock("button",{key:h.uuid,type:"button",class:"media-workspace-item","data-testid":"media-item",onClick:v=>n("preview",h)},e.toDisplayString(h.file_name),9,ev))),128))])]))}}),av=Ae(tv,[["__scopeId","data-v-895f26fe"]]),nv={class:"managed-media-gallery"},ov={class:"gallery-grid"},iv=e.defineComponent({__name:"ManagedMediaGallery",props:{media:{},selectable:{type:Boolean},multiple:{type:Boolean}},emits:["select","remove"],setup(o){return(a,t)=>(e.openBlock(),e.createElementBlock("div",nv,[e.createElementVNode("div",ov,[e.renderSlot(a.$slots,"default",{},void 0,!0)])]))}}),rv=Ae(iv,[["__scopeId","data-v-10a9b8c5"]]),Fr="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M256 176v160M336 256H176' class='ionicon-fill-none ionicon-stroke-width'/></svg>",md="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M256 112v288M400 256H112' class='ionicon-fill-none ionicon-stroke-width'/></svg>",lv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208 208-93.31 208-208S370.69 48 256 48zm0 319.91a20 20 0 1120-20 20 20 0 01-20 20zm21.72-201.15l-5.74 122a16 16 0 01-32 0l-5.74-121.94v-.05a21.74 21.74 0 1143.44 0z'/></svg>",pd="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M250.26 166.05L256 288l5.73-121.95a5.74 5.74 0 00-5.79-6h0a5.74 5.74 0 00-5.68 6z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M256 367.91a20 20 0 1120-20 20 20 0 01-20 20z'/></svg>",sv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M244 400L100 256l144-144M120 256h292' class='ionicon-fill-none'/></svg>",dv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M268 112l144 144-144 144M392 256H100' class='ionicon-fill-none'/></svg>",bc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256L272 88v96C103.57 184 64 304.77 64 424c48.61-62.24 91.6-96 208-96v96z' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",yc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M240 424v-96c116.4 0 159.39 33.76 208 96 0-119.23-39.57-240-208-240V88L64 256z' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Bi="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M452.37 59.63h0a40.49 40.49 0 00-57.26 0L184 294.74c23.08 4.7 46.12 27.29 49.26 49.26l219.11-227.11a40.49 40.49 0 000-57.26zM138 336c-29.88 0-54 24.5-54 54.86 0 23.95-20.88 36.57-36 36.57C64.56 449.74 92.82 464 120 464c39.78 0 72-32.73 72-73.14 0-30.36-24.12-54.86-54-54.86z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",cv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M350.54 148.68l-26.62-42.06C318.31 100.08 310.62 96 302 96h-92c-8.62 0-16.31 4.08-21.92 10.62l-26.62 42.06C155.85 155.23 148.62 160 140 160H80a32 32 0 00-32 32v192a32 32 0 0032 32h352a32 32 0 0032-32V192a32 32 0 00-32-32h-59c-8.65 0-16.85-4.77-22.46-11.32z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='256' cy='272' r='80' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M124 158v-22h-24v22' class='ionicon-fill-none ionicon-stroke-width'/></svg>",gm="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208 208-93.31 208-208S370.69 48 256 48zm108.25 138.29l-134.4 160a16 16 0 01-12 5.71h-.27a16 16 0 01-11.89-5.3l-57.6-64a16 16 0 1123.78-21.4l45.29 50.32 122.59-145.91a16 16 0 0124.5 20.58z'/></svg>",bm="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M416 128L192 384l-96-96' class='ionicon-fill-none ionicon-stroke-width'/></svg>",wc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M328 112L184 256l144 144' class='ionicon-fill-none'/></svg>",uv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M112 184l144 144 144-144' class='ionicon-fill-none'/></svg>",mv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M184 112l144 144-144 144' class='ionicon-fill-none'/></svg>",kc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' stroke-width='48' d='M184 112l144 144-144 144' class='ionicon-fill-none'/></svg>",$o="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M368 368L144 144M368 144L144 368' class='ionicon-fill-none ionicon-stroke-width'/></svg>",_c="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M320 367.79h76c55 0 100-29.21 100-83.6s-53-81.47-96-83.6c-8.89-85.06-71-136.8-144-136.8-69 0-113.44 45.79-128 91.2-60 5.7-112 43.88-112 106.4s54 106.4 120 106.4h56' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M320 255.79l-64-64-64 64M256 448.21V207.79' class='ionicon-fill-none ionicon-stroke-width'/></svg>",pv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='256' cy='184' r='120' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='344' cy='328' r='120' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='168' cy='328' r='120' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",to="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M430.11 347.9c-6.6-6.1-16.3-7.6-24.6-9-11.5-1.9-15.9-4-22.6-10-14.3-12.7-14.3-31.1 0-43.8l30.3-26.9c46.4-41 46.4-108.2 0-149.2-34.2-30.1-80.1-45-127.8-45-55.7 0-113.9 20.3-158.8 60.1-83.5 73.8-83.5 194.7 0 268.5 41.5 36.7 97.5 55 152.9 55.4h1.7c55.4 0 110-17.9 148.8-52.4 14.4-12.7 11.99-36.6.1-47.7z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='144' cy='208' r='32'/><circle cx='152' cy='311' r='32'/><circle cx='224' cy='144' r='32'/><circle cx='256' cy='367' r='48'/><circle cx='328' cy='144' r='32'/></svg>",fv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M304 416V304h112M314.2 314.23L432 432M208 96v112H96M197.8 197.77L80 80M416 208H304V96M314.23 197.8L432 80M96 304h112v112M197.77 314.2L80 432' class='ionicon-fill-none ionicon-stroke-width'/></svg>",ki="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='256' cy='256' r='208' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M256 464c-114.88 0-208-93.12-208-208S141.12 48 256 48z'/></svg>",Ss="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><rect x='128' y='128' width='336' height='336' rx='57' ry='57' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M383.5 128l.5-24a56.16 56.16 0 00-56-56H112a64.19 64.19 0 00-64 64v216a56.16 56.16 0 0056 56h24' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",hv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M384 224v184a40 40 0 01-40 40H104a40 40 0 01-40-40V168a40 40 0 0140-40h167.48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M459.94 53.25a16.06 16.06 0 00-23.22-.56L424.35 65a8 8 0 000 11.31l11.34 11.32a8 8 0 0011.34 0l12.06-12c6.1-6.09 6.67-16.01.85-22.38zM399.34 90L218.82 270.2a9 9 0 00-2.31 3.93L208.16 299a3.91 3.91 0 004.86 4.86l24.85-8.35a9 9 0 003.93-2.31L422 112.66a9 9 0 000-12.66l-9.95-10a9 9 0 00-12.71 0z'/></svg>",Ec="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M144 48v272a48 48 0 0048 48h272' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M368 304V192a48 48 0 00-48-48H208M368 368v96M144 144H48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Gr="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='104' cy='152' r='56' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='104' cy='360' r='56' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M157 175l-11 15 37 15s3.46-6.42 7-10z' stroke-linecap='square' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M154.17 334.43L460 162c-2.5-6.7-28-12-64-4-29.12 6.47-121.16 29.05-159.16 56.05C205.85 236.06 227 272 192 298c-25.61 19-44.43 22.82-44.43 22.82zM344.47 278.24L295 306.67c14.23 6.74 65.54 33.27 117 36.33 14.92.89 30 .39 39-6z' stroke-linecap='round' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='256' cy='240' r='32' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",ni="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M336 176h40a40 40 0 0140 40v208a40 40 0 01-40 40H136a40 40 0 01-40-40V216a40 40 0 0140-40h40' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M176 272l80 80 80-80M256 48v288' class='ionicon-fill-none ionicon-stroke-width'/></svg>",vv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='256' cy='256' r='32' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='416' cy='256' r='32' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='96' cy='256' r='32' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",gv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M432 320v112H320M421.8 421.77L304 304M80 192V80h112M90.2 90.23L208 208M320 80h112v112M421.77 90.2L304 208M192 432H80V320M90.23 421.8L208 304' class='ionicon-fill-none ionicon-stroke-width'/></svg>",bv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M432 320v112H320M421.8 421.77L304 304M80 192V80h112M90.2 90.23L208 208M320 80h112v112M421.77 90.2L304 208M192 432H80V320M90.23 421.8L208 304' class='ionicon-fill-none ionicon-stroke-width'/></svg>",yv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M432 448a15.92 15.92 0 01-11.31-4.69l-352-352a16 16 0 0122.62-22.62l352 352A16 16 0 01432 448zM255.66 384c-41.49 0-81.5-12.28-118.92-36.5-34.07-22-64.74-53.51-88.7-91v-.08c19.94-28.57 41.78-52.73 65.24-72.21a2 2 0 00.14-2.94L93.5 161.38a2 2 0 00-2.71-.12c-24.92 21-48.05 46.76-69.08 76.92a31.92 31.92 0 00-.64 35.54c26.41 41.33 60.4 76.14 98.28 100.65C162 402 207.9 416 255.66 416a239.13 239.13 0 0075.8-12.58 2 2 0 00.77-3.31l-21.58-21.58a4 4 0 00-3.83-1 204.8 204.8 0 01-51.16 6.47zM490.84 238.6c-26.46-40.92-60.79-75.68-99.27-100.53C349 110.55 302 96 255.66 96a227.34 227.34 0 00-74.89 12.83 2 2 0 00-.75 3.31l21.55 21.55a4 4 0 003.88 1 192.82 192.82 0 0150.21-6.69c40.69 0 80.58 12.43 118.55 37 34.71 22.4 65.74 53.88 89.76 91a.13.13 0 010 .16 310.72 310.72 0 01-64.12 72.73 2 2 0 00-.15 2.95l19.9 19.89a2 2 0 002.7.13 343.49 343.49 0 0068.64-78.48 32.2 32.2 0 00-.1-34.78z'/><path d='M256 160a95.88 95.88 0 00-21.37 2.4 2 2 0 00-1 3.38l112.59 112.56a2 2 0 003.38-1A96 96 0 00256 160zM165.78 233.66a2 2 0 00-3.38 1 96 96 0 00115 115 2 2 0 001-3.38z'/></svg>",Mi="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M255.66 112c-77.94 0-157.89 45.11-220.83 135.33a16 16 0 00-.27 17.77C82.92 340.8 161.8 400 255.66 400c92.84 0 173.34-59.38 221.79-135.25a16.14 16.14 0 000-17.47C428.89 172.28 347.8 112 255.66 112z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='256' cy='256' r='80' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Sc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M80 464V68.14a8 8 0 014-6.9C91.81 56.66 112.92 48 160 48c64 0 145 48 192 48a199.53 199.53 0 0077.23-15.77 2 2 0 012.77 1.85v219.36a4 4 0 01-2.39 3.65C421.37 308.7 392.33 320 352 320c-48 0-128-32-192-32s-80 16-80 16' stroke-linecap='round' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",es="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M315.27 33L96 304h128l-31.51 173.23a2.36 2.36 0 002.33 2.77h0a2.36 2.36 0 001.89-.95L416 208H288l31.66-173.25a2.45 2.45 0 00-2.44-2.75h0a2.42 2.42 0 00-1.95 1z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",wv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M496 152a56 56 0 00-56-56H220.11a23.89 23.89 0 01-13.31-4L179 73.41A55.77 55.77 0 00147.89 64H72a56 56 0 00-56 56v48a8 8 0 008 8h464a8 8 0 008-8zM16 392a56 56 0 0056 56h368a56 56 0 0056-56V216a8 8 0 00-8-8H24a8 8 0 00-8 8z'/></svg>",kv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='129' cy='96' r='48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='129' cy='416' r='48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M129 144v224' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='385' cy='288' r='48' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M129 144c0 96 112 144 208 144' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",ts="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M432 112V96a48.14 48.14 0 00-48-48H64a48.14 48.14 0 00-48 48v256a48.14 48.14 0 0048 48h16' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><rect x='96' y='128' width='400' height='336' rx='45.99' ry='45.99' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><ellipse cx='372.92' cy='219.64' rx='30.77' ry='30.55' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M342.15 372.17L255 285.78a30.93 30.93 0 00-42.18-1.21L96 387.64M265.23 464l118.59-117.73a31 31 0 0141.46-1.87L496 402.91' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",_v="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M248 64C146.39 64 64 146.39 64 248s82.39 184 184 184 184-82.39 184-184S349.61 64 248 64z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M220 220h32v116' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M208 340h88' class='ionicon-fill-none ionicon-stroke-width'/><path d='M248 130a26 26 0 1026 26 26 26 0 00-26-26z'/></svg>",Ev="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M368 128h80M64 128h240M368 384h80M64 384h240M208 256h240M64 256h80' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='336' cy='128' r='32' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='176' cy='256' r='32' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='336' cy='384' r='32' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Sv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M208 432h-48a16 16 0 01-16-16V96a16 16 0 0116-16h48a16 16 0 0116 16v320a16 16 0 01-16 16zM352 432h-48a16 16 0 01-16-16V96a16 16 0 0116-16h48a16 16 0 0116 16v320a16 16 0 01-16 16z'/></svg>",Cv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208 208-93.31 208-208S370.69 48 256 48zm-32 272a16 16 0 01-32 0V192a16 16 0 0132 0zm96 0a16 16 0 01-32 0V192a16 16 0 0132 0z'/></svg>",ym="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M208 192v128M304 192v128' class='ionicon-fill-none ionicon-stroke-width'/></svg>",fd="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M176 96h16v320h-16zM320 96h16v320h-16z' class='ionicon-fill-none ionicon-stroke-width'/></svg>",xv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M133 440a35.37 35.37 0 01-17.5-4.67c-12-6.8-19.46-20-19.46-34.33V111c0-14.37 7.46-27.53 19.46-34.33a35.13 35.13 0 0135.77.45l247.85 148.36a36 36 0 010 61l-247.89 148.4A35.5 35.5 0 01133 440z'/></svg>",Nv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M30.71 229.47l188.87-113a30.54 30.54 0 0131.09-.39 33.74 33.74 0 0116.76 29.47v79.05l180.72-108.16a30.54 30.54 0 0131.09-.39A33.74 33.74 0 01496 145.52v221A33.73 33.73 0 01479.24 396a30.54 30.54 0 01-31.09-.39L267.43 287.4v79.08A33.73 33.73 0 01250.67 396a30.54 30.54 0 01-31.09-.39l-188.87-113a31.27 31.27 0 010-53z'/></svg>",Vv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M480 145.52v221c0 13.28-13 21.72-23.63 15.35L267.5 268.8c-9.24-5.53-9.24-20.07 0-25.6l188.87-113C467 123.8 480 132.24 480 145.52zM251.43 145.52v221c0 13.28-13 21.72-23.63 15.35L38.93 268.8c-9.24-5.53-9.24-20.07 0-25.6l188.87-113c10.64-6.4 23.63 2.04 23.63 15.32z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Tv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208 208-93.31 208-208S370.69 48 256 48zm74.77 217.3l-114.45 69.14a10.78 10.78 0 01-16.32-9.31V186.87a10.78 10.78 0 0116.32-9.31l114.45 69.14a10.89 10.89 0 010 18.6z'/></svg>",wm="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M216.32 334.44l114.45-69.14a10.89 10.89 0 000-18.6l-114.45-69.14a10.78 10.78 0 00-16.32 9.31v138.26a10.78 10.78 0 0016.32 9.31z'/></svg>",Bv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M481.29 229.47l-188.87-113a30.54 30.54 0 00-31.09-.39 33.74 33.74 0 00-16.76 29.47v79.05L63.85 116.44a30.54 30.54 0 00-31.09-.39A33.74 33.74 0 0016 145.52v221A33.74 33.74 0 0032.76 396a30.54 30.54 0 0031.09-.39L244.57 287.4v79.08A33.74 33.74 0 00261.33 396a30.54 30.54 0 0031.09-.39l188.87-113a31.27 31.27 0 000-53z'/></svg>",Mv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M32 145.52v221c0 13.28 13 21.72 23.63 15.35l188.87-113c9.24-5.53 9.24-20.07 0-25.6l-188.87-113C45 123.8 32 132.24 32 145.52zM260.57 145.52v221c0 13.28 13 21.72 23.63 15.35l188.87-113c9.24-5.53 9.24-20.07 0-25.6l-188.87-113c-10.64-6.47-23.63 1.97-23.63 15.25z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",hd="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M112 111v290c0 17.44 17 28.52 31 20.16l247.9-148.37c12.12-7.25 12.12-26.33 0-33.58L143 90.84c-14-8.36-31 2.72-31 20.16z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Iv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M400 111v290c0 17.44-17 28.52-31 20.16L121.09 272.79c-12.12-7.25-12.12-26.33 0-33.58L369 90.84c14-8.36 31 2.72 31 20.16z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M112 80v352' class='ionicon-fill-none ionicon-stroke-width'/></svg>",$v="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M112 111v290c0 17.44 17 28.52 31 20.16l247.9-148.37c12.12-7.25 12.12-26.33 0-33.58L143 90.84c-14-8.36-31 2.72-31 20.16z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M400 80v352' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Uo="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M320 146s24.36-12-64-12a160 160 0 10160 160' stroke-linecap='round' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M256 58l80 80-80 80' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Fv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192 192-86 192-192z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-linejoin='round' d='M336 256H176' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Dv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M400 256H112' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Cc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M304 96h112v112M405.77 106.2L111.98 400.02M208 416H96V304' class='ionicon-fill-none ionicon-stroke-width'/></svg>",pl="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M380.93 57.37A32 32 0 00358.3 48H94.22A46.21 46.21 0 0048 94.22v323.56A46.21 46.21 0 0094.22 464h323.56A46.36 46.36 0 00464 417.78V153.7a32 32 0 00-9.37-22.63zM256 416a64 64 0 1164-64 63.92 63.92 0 01-64 64zm48-224H112a16 16 0 01-16-16v-64a16 16 0 0116-16h192a16 16 0 0116 16v64a16 16 0 01-16 16z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Av="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><circle cx='256' cy='256' r='48'/><path d='M470.39 300l-.47-.38-31.56-24.75a16.11 16.11 0 01-6.1-13.33v-11.56a16 16 0 016.11-13.22L469.92 212l.47-.38a26.68 26.68 0 005.9-34.06l-42.71-73.9a1.59 1.59 0 01-.13-.22A26.86 26.86 0 00401 92.14l-.35.13-37.1 14.93a15.94 15.94 0 01-14.47-1.29q-4.92-3.1-10-5.86a15.94 15.94 0 01-8.19-11.82l-5.59-39.59-.12-.72A27.22 27.22 0 00298.76 26h-85.52a26.92 26.92 0 00-26.45 22.39l-.09.56-5.57 39.67a16 16 0 01-8.13 11.82 175.21 175.21 0 00-10 5.82 15.92 15.92 0 01-14.43 1.27l-37.13-15-.35-.14a26.87 26.87 0 00-32.48 11.34l-.13.22-42.77 73.95a26.71 26.71 0 005.9 34.1l.47.38 31.56 24.75a16.11 16.11 0 016.1 13.33v11.56a16 16 0 01-6.11 13.22L42.08 300l-.47.38a26.68 26.68 0 00-5.9 34.06l42.71 73.9a1.59 1.59 0 01.13.22 26.86 26.86 0 0032.45 11.3l.35-.13 37.07-14.93a15.94 15.94 0 0114.47 1.29q4.92 3.11 10 5.86a15.94 15.94 0 018.19 11.82l5.56 39.59.12.72A27.22 27.22 0 00213.24 486h85.52a26.92 26.92 0 0026.45-22.39l.09-.56 5.57-39.67a16 16 0 018.18-11.82c3.42-1.84 6.76-3.79 10-5.82a15.92 15.92 0 0114.43-1.27l37.13 14.95.35.14a26.85 26.85 0 0032.48-11.34 2.53 2.53 0 01.13-.22l42.71-73.89a26.7 26.7 0 00-5.89-34.11zm-134.48-40.24a80 80 0 11-83.66-83.67 80.21 80.21 0 0183.66 83.67z'/></svg>",as="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M400 304l48 48-48 48M400 112l48 48-48 48M64 352h85.19a80 80 0 0066.56-35.62L256 256' class='ionicon-fill-none ionicon-stroke-width'/><path d='M64 160h85.19a80 80 0 0166.56 35.62l80.5 120.76A80 80 0 00362.81 352H416M416 160h-53.19a80 80 0 00-66.56 35.62L288 208' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",eo="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' class='ionicon'><path d='M259.92 262.91L216.4 149.77a9 9 0 00-16.8 0l-43.52 113.14a9 9 0 01-5.17 5.17L37.77 311.6a9 9 0 000 16.8l113.14 43.52a9 9 0 015.17 5.17l43.52 113.14a9 9 0 0016.8 0l43.52-113.14a9 9 0 015.17-5.17l113.14-43.52a9 9 0 000-16.8l-113.14-43.52a9 9 0 01-5.17-5.17zM108 68L88 16 68 68 16 88l52 20 20 52 20-52 52-20-52-20zM426.67 117.33L400 48l-26.67 69.33L304 144l69.33 26.67L400 240l26.67-69.33L496 144l-69.33-26.67z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",_i="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-miterlimit='10' d='M256 48v48M256 416v48M403.08 108.92l-33.94 33.94M142.86 369.14l-33.94 33.94M464 256h-48M96 256H48M403.08 403.08l-33.94-33.94M142.86 142.86l-33.94-33.94' class='ionicon-fill-none ionicon-stroke-width'/><circle cx='256' cy='256' r='80' stroke-linecap='round' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",xc="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M304 48l112 112-112 112M398.87 160H96M208 464L96 352l112-112M114 352h302' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Rv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M512 128v256a64.07 64.07 0 01-64 64H64a64.07 64.07 0 01-64-64V128a64.07 64.07 0 0164-64h384a64.07 64.07 0 0164 64zM32 384a32 32 0 0032 32h384a32 32 0 0032-32V128a32 32 0 00-32-32H64a32 32 0 00-32 32z'/><path d='M0 128a64.07 64.07 0 0164-64h384a64.07 64.07 0 0164 64v256a64.07 64.07 0 01-64 64H64a64.07 64.07 0 01-64-64V128m480 256V128a32 32 0 00-32-32H64a32 32 0 00-32 32v256a32 32 0 0032 32h384a32 32 0 0032-32m-16 0a16 16 0 01-16 16H64a16 16 0 01-16-16V128a16 16 0 0116-16h384a16 16 0 0116 16v256z'/></svg>",km="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-linejoin='round' d='M32 415.5l120-320 120 320M230 303.5H74M326 239.5c12.19-28.69 41-48 74-48h0c46 0 80 32 80 80v144' class='ionicon-fill-none ionicon-stroke-width'/><path d='M320 358.5c0 36 26.86 58 60 58 54 0 100-27 100-106v-15c-20 0-58 1-92 5-32.77 3.86-68 19-68 58z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Xr="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M112 112l20 320c.95 18.49 14.4 32 32 32h184c17.67 0 30.87-13.51 32-32l20-320' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path stroke-linecap='round' stroke-miterlimit='10' d='M80 112h352' class='ionicon-stroke-width'/><path d='M192 112V72h0a23.93 23.93 0 0124-24h80a23.93 23.93 0 0124 24h0v40M256 176v224M184 176l8 224M328 176l-8 224' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",_m="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M374.79 308.78L457.5 367a16 16 0 0022.5-14.62V159.62A16 16 0 00457.5 145l-82.71 58.22A16 16 0 00368 216.3v79.4a16 16 0 006.79 13.08z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M268 384H84a52.15 52.15 0 01-52-52V180a52.15 52.15 0 0152-52h184.48A51.68 51.68 0 01320 179.52V332a52.15 52.15 0 01-52 52z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/></svg>",Lv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M232 416a23.88 23.88 0 01-14.2-4.68 8.27 8.27 0 01-.66-.51L125.76 336H56a24 24 0 01-24-24V200a24 24 0 0124-24h69.75l91.37-74.81a8.27 8.27 0 01.66-.51A24 24 0 01256 120v272a24 24 0 01-24 24zm-106.18-80zm-.27-159.86zM320 336a16 16 0 01-14.29-23.19c9.49-18.87 14.3-38 14.3-56.81 0-19.38-4.66-37.94-14.25-56.73a16 16 0 0128.5-14.54C346.19 208.12 352 231.44 352 256c0 23.86-6 47.81-17.7 71.19A16 16 0 01320 336z'/><path d='M368 384a16 16 0 01-13.86-24C373.05 327.09 384 299.51 384 256c0-44.17-10.93-71.56-29.82-103.94a16 16 0 0127.64-16.12C402.92 172.11 416 204.81 416 256c0 50.43-13.06 83.29-34.13 120a16 16 0 01-13.87 8z'/><path d='M416 432a16 16 0 01-13.39-24.74C429.85 365.47 448 323.76 448 256c0-66.5-18.18-108.62-45.49-151.39a16 16 0 1127-17.22C459.81 134.89 480 181.74 480 256c0 64.75-14.66 113.63-50.6 168.74A16 16 0 01416 432z'/></svg>",Pv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M296 416.19a23.92 23.92 0 01-14.21-4.69l-.66-.51-91.46-75H120a24 24 0 01-24-24V200a24 24 0 0124-24h69.65l91.46-75 .66-.51A24 24 0 01320 119.83v272.34a24 24 0 01-24 24zM384 336a16 16 0 01-14.29-23.18c9.49-18.9 14.3-38 14.3-56.82 0-19.36-4.66-37.92-14.25-56.73a16 16 0 0128.5-14.54C410.2 208.16 416 231.47 416 256c0 23.83-6 47.78-17.7 71.18A16 16 0 01384 336z'/></svg>",Uv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M264 416.19a23.92 23.92 0 01-14.21-4.69l-.66-.51-91.46-75H88a24 24 0 01-24-24V200a24 24 0 0124-24h69.65l91.46-75 .66-.51A24 24 0 01288 119.83v272.34a24 24 0 01-24 24zM352 336a16 16 0 01-14.29-23.18c9.49-18.9 14.3-38 14.3-56.82 0-19.36-4.66-37.92-14.25-56.73a16 16 0 0128.5-14.54C378.2 208.16 384 231.47 384 256c0 23.83-6 47.78-17.7 71.18A16 16 0 01352 336z'/><path d='M400 384a16 16 0 01-13.87-24C405 327.05 416 299.45 416 256c0-44.12-10.94-71.52-29.83-103.95A16 16 0 01413.83 136C434.92 172.16 448 204.88 448 256c0 50.36-13.06 83.24-34.12 120a16 16 0 01-13.88 8z'/></svg>",Ov="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M157.65 192H88a8 8 0 00-8 8v112a8 8 0 008 8h69.65a16 16 0 0110.14 3.63l91.47 75a8 8 0 0012.74-6.46V119.83a8 8 0 00-12.74-6.44l-91.47 75a16 16 0 01-10.14 3.61zM352 320c9.74-19.41 16-40.81 16-64 0-23.51-6-44.4-16-64M400 368c19.48-34 32-64 32-112s-12-77.7-32-112' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>",zv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-miterlimit='10' d='M416 432L64 80' class='ionicon-fill-none ionicon-stroke-width'/><path d='M243.33 98.86a23.89 23.89 0 00-25.55 1.82l-.66.51-28.52 23.35a8 8 0 00-.59 11.85l54.33 54.33a8 8 0 0013.66-5.66v-64.49a24.51 24.51 0 00-12.67-21.71zM251.33 335.29L96.69 180.69A16 16 0 0085.38 176H56a24 24 0 00-24 24v112a24 24 0 0024 24h69.76l92 75.31a23.9 23.9 0 0025.87 1.69A24.51 24.51 0 00256 391.45v-44.86a16 16 0 00-4.67-11.3zM352 256c0-24.56-5.81-47.87-17.75-71.27a16 16 0 10-28.5 14.55C315.34 218.06 320 236.62 320 256q0 4-.31 8.13a8 8 0 002.32 6.25l14.36 14.36a8 8 0 0013.55-4.31A146 146 0 00352 256zM416 256c0-51.18-13.08-83.89-34.18-120.06a16 16 0 00-27.64 16.12C373.07 184.44 384 211.83 384 256c0 23.83-3.29 42.88-9.37 60.65a8 8 0 001.9 8.26L389 337.4a8 8 0 0013.13-2.79C411 311.76 416 287.26 416 256z'/><path d='M480 256c0-74.25-20.19-121.11-50.51-168.61a16 16 0 10-27 17.22C429.82 147.38 448 189.5 448 256c0 46.19-8.43 80.27-22.43 110.53a8 8 0 001.59 9l11.92 11.92a8 8 0 0012.92-2.16C471.6 344.9 480 305 480 256z'/></svg>",jv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path stroke-linecap='round' stroke-miterlimit='10' d='M416 432L64 80' class='ionicon-fill-none ionicon-stroke-width'/><path d='M224 136.92v33.8a4 4 0 001.17 2.82l24 24a4 4 0 006.83-2.82v-74.15a24.53 24.53 0 00-12.67-21.72 23.91 23.91 0 00-25.55 1.83 8.27 8.27 0 00-.66.51l-31.94 26.15a4 4 0 00-.29 5.92l17.05 17.06a4 4 0 005.37.26zM224 375.08l-78.07-63.92a32 32 0 00-20.28-7.16H64v-96h50.72a4 4 0 002.82-6.83l-24-24a4 4 0 00-2.82-1.17H56a24 24 0 00-24 24v112a24 24 0 0024 24h69.76l91.36 74.8a8.27 8.27 0 00.66.51 23.93 23.93 0 0025.85 1.69A24.49 24.49 0 00256 391.45v-50.17a4 4 0 00-1.17-2.82l-24-24a4 4 0 00-6.83 2.82zM125.82 336zM352 256c0-24.56-5.81-47.88-17.75-71.27a16 16 0 00-28.5 14.54C315.34 218.06 320 236.62 320 256q0 4-.31 8.13a8 8 0 002.32 6.25l19.66 19.67a4 4 0 006.75-2A146.89 146.89 0 00352 256zM416 256c0-51.19-13.08-83.89-34.18-120.06a16 16 0 00-27.64 16.12C373.07 184.44 384 211.83 384 256c0 23.83-3.29 42.88-9.37 60.65a8 8 0 001.9 8.26l16.77 16.76a4 4 0 006.52-1.27C410.09 315.88 416 289.91 416 256z'/><path d='M480 256c0-74.26-20.19-121.11-50.51-168.61a16 16 0 10-27 17.22C429.82 147.38 448 189.5 448 256c0 47.45-8.9 82.12-23.59 113a4 4 0 00.77 4.55L443 391.39a4 4 0 006.4-1C470.88 348.22 480 307 480 256z'/></svg>",Wv="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M85.57 446.25h340.86a32 32 0 0028.17-47.17L284.18 82.58c-12.09-22.44-44.27-22.44-56.36 0L57.4 399.08a32 32 0 0028.17 47.17z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M250.26 195.39l5.74 122 5.73-121.95a5.74 5.74 0 00-5.79-6h0a5.74 5.74 0 00-5.68 5.95z' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/><path d='M256 397.25a20 20 0 1120-20 20 20 0 01-20 20z'/></svg>",br="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><path d='M400 320c0 88.37-55.63 144-144 144s-144-55.63-144-144c0-94.83 103.23-222.85 134.89-259.88a12 12 0 0118.23 0C296.77 97.15 400 225.17 400 320z' stroke-miterlimit='10' class='ionicon-fill-none ionicon-stroke-width'/><path d='M344 328a72 72 0 01-72 72' stroke-linecap='round' stroke-linejoin='round' class='ionicon-fill-none ionicon-stroke-width'/></svg>";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Nc=()=>{};function Hv(o,a){function t(...n){return new Promise((i,r)=>{Promise.resolve(o(()=>a.apply(this,n),{fn:a,thisArg:this,args:n})).then(i).catch(r)})}return t}function Zv(o,a={}){let t,n,i=Nc;const r=d=>{clearTimeout(d),i(),i=Nc};let l;return d=>{const c=e.toValue(o),u=e.toValue(a.maxWait);return t&&r(t),c<=0||u!==void 0&&u<=0?(n&&(r(n),n=null),Promise.resolve(d())):new Promise((m,p)=>{i=a.rejectOnCancel?p:m,l=d,u&&!n&&(n=setTimeout(()=>{t&&r(t),n=null,m(l())},u)),t=setTimeout(()=>{n&&r(n),n=null,m(d())},c)})}}function Gv(o,a=200,t={}){return Hv(Zv(a,t),o)}const Ei=new Map;function Xv(o){const a=e.getCurrentScope();function t(s){var d;const c=Ei.get(o)||new Set;c.add(s),Ei.set(o,c);const u=()=>i(s);return(d=a==null?void 0:a.cleanups)==null||d.push(u),u}function n(s){function d(...c){i(d),s(...c)}return t(d)}function i(s){const d=Ei.get(o);d&&(d.delete(s),d.size||r())}function r(){Ei.delete(o)}function l(s,d){var c;(c=Ei.get(o))==null||c.forEach(u=>u(s,d))}return{on:t,once:n,off:i,emit:l,reset:r}}function Em(){var r,l;const o=typeof window<"u"&&"Capacitor"in window&&((l=(r=window.Capacitor)==null?void 0:r.isNativePlatform)==null?void 0:l.call(r));return{selection:()=>{var s,d;if(o)try{const c=(d=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:d.Haptics;c&&c.impact({style:"LIGHT"})}catch{}else"vibrate"in navigator&&navigator.vibrate(10)},success:()=>{var s,d;if(o)try{const c=(d=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:d.Haptics;c&&c.impact({style:"MEDIUM"})}catch{}else"vibrate"in navigator&&navigator.vibrate(30)},error:()=>{var s,d;if(o)try{const c=(d=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:d.Haptics;c&&c.impact({style:"HEAVY"})}catch{}else"vibrate"in navigator&&navigator.vibrate([50,50,50])},notification:()=>{var s,d;if(o)try{const c=(d=(s=window.Capacitor)==null?void 0:s.Plugins)==null?void 0:d.Haptics;c&&c.notification({type:"SUCCESS"})}catch{}else"vibrate"in navigator&&navigator.vibrate([20,100,20])}}}function fl(o,a={}){const t=e.ref(new Set),n=e.ref(new Map),i=e.ref(null),r=e.ref(-1),l=e.ref(a.scopeKey!==void 0?e.toValue(a.scopeKey):"default"),s=e.ref(!1),d=e.ref(null),c=Xv("media-selection"),u=Em(),m=()=>{if(a.currentPage===void 0)return null;const O=e.toValue(a.currentPage);return typeof O=="number"&&Number.isFinite(O)?O:null};function p(O){t.value=O,n.value=new Map(Array.from(n.value.entries()).filter(([K])=>O.has(K)))}function f(O){if(n.value.has(O))return;const K=new Map(n.value);K.set(O,{uuid:O,selectedAt:Date.now(),page:m()}),n.value=K}const h=e.computed(()=>o.value.filter(O=>t.value.has(O.uuid))),v=e.computed(()=>t.value.size),y=e.computed(()=>Array.from(n.value.values()).sort((O,K)=>O.selectedAt-K.selectedAt).map(O=>O.uuid)),w=e.computed(()=>Math.max(0,v.value-h.value.length)),_=e.computed(()=>{const O=new Map;for(const K of n.value.values())K.page!==null&&O.set(K.page,(O.get(K.page)??0)+1);return O});e.watch(t,O=>{c.emit({type:"selection:changed",count:O.size,selectedIds:Array.from(O)})}),a.scopeKey!==void 0&&e.watch(()=>e.toValue(a.scopeKey),(O,K)=>{O!==void 0&&O!==K&&z(O)});const b=e.computed(()=>o.value.length>0&&o.value.every(O=>t.value.has(O.uuid))),g=e.computed(()=>o.value.some(O=>t.value.has(O.uuid)));function I(O){return t.value.has(O)}function T(O){const K=new Set(t.value),se=K.size===0;K.add(O),f(O),t.value=K,i.value=O,r.value=o.value.findIndex(xe=>xe.uuid===O),se&&u.selection()}function $(O){const K=new Set(t.value);K.delete(O);const se=new Map(n.value);se.delete(O),n.value=se,t.value=K,i.value===O&&(i.value=null,r.value=-1)}function N(O){if(t.value.has(O)){$(O);return}T(O)}function B(){const O=new Set(t.value);for(const K of o.value)O.add(K.uuid),f(K.uuid);t.value=O}function P(){t.value=new Set,n.value=new Map,i.value=null,r.value=-1,s.value=!1,d.value=null}function x(){if(b.value){P();return}B()}function M(O,K){const se=o.value.findIndex(xe=>xe.uuid===O);if(se!==-1){if(K!=null&&K.shiftKey&&r.value!==-1){const xe=Math.min(r.value,se),ue=Math.max(r.value,se),le=new Set(t.value);for(let Z=xe;Z<=ue;Z++){const k=o.value[Z];k!==void 0&&(le.add(k.uuid),f(k.uuid))}t.value=le;return}N(O)}}function E(){if(o.value.length===0)return;let O=r.value+1;O>=o.value.length&&(O=0),P();const K=o.value[O];K!==void 0&&T(K.uuid)}function D(){if(o.value.length===0)return;let O=r.value-1;O<0&&(O=o.value.length-1),P();const K=o.value[O];K!==void 0&&T(K.uuid)}function j(O){switch(O.key){case"ArrowDown":O.preventDefault(),E();break;case"ArrowUp":O.preventDefault(),D();break;case"a":(O.ctrlKey||O.metaKey)&&(O.preventDefault(),B());break;case"Escape":O.preventDefault(),P();break;case" ":i.value&&(O.preventDefault(),N(i.value));break}}async function L(O){var se;if(v.value===0||l.value===O)return!0;const K=(se=a.confirmScopeChange)==null?void 0:se.call(a,{from:l.value,to:O,selectedCount:v.value});return K===void 0?!0:await K}async function z(O){return l.value===O?!0:await L(O)?(l.value=O,P(),!0):!1}async function C(){if(!a.fetchMatchingUuids){const K={uuids:o.value.map(se=>se.uuid),overCap:!1,totalMatching:o.value.length};return A(K),K}const O=await a.fetchMatchingUuids();return A(O),O}function A(O){const K=new Set(O.uuids),se=new Map,xe=Date.now();O.uuids.forEach((ue,le)=>{se.set(ue,{uuid:ue,selectedAt:xe+le,page:m()})}),p(K),n.value=se,s.value=O.overCap,d.value=O.totalMatching}return{selectedIds:e.computed(()=>t.value),selectedRecords:e.computed(()=>n.value),selectedItems:h,selectedCount:v,orderedIds:y,crossPageCount:w,selectedPages:_,overCap:e.computed(()=>s.value),totalMatching:e.computed(()=>d.value),activeScopeKey:e.computed(()=>l.value),isAllSelected:b,isSomeSelected:g,lastSelectedId:e.computed(()=>i.value),isSelected:I,toggle:N,select:T,deselect:$,selectAll:B,clear:P,toggleAll:x,rangeSelect:M,selectAcrossAllPages:C,setScopeKey:z,canChangeScope:L,selectNext:E,selectPrevious:D,handleKeydown:j,selectionBus:c}}const Kv={class:"flex items-center justify-between w-full px-4"},qv={class:"p-4"},Jv={key:0,class:"mb-4 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg"},Yv={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"},Qv=["value"],eg={class:"flex gap-2 mt-4"},tg={class:"flex justify-end mb-4"},ag={key:1,class:"flex justify-center items-center h-64"},ng={key:2,class:"flex flex-col items-center justify-center h-64 text-center"},og={class:"text-sm text-theme-secondary"},ig={key:0},rg={class:"mb-4"},lg={class:"mb-4"},sg={class:"flex gap-2"},dg={class:"flex items-center justify-between px-4 py-2"},cg={class:"text-sm text-theme-secondary"},ug={key:0},mg={key:0},pg={key:1},fg={class:"flex gap-2"},hg=e.defineComponent({__name:"AdminMediaBrowser",props:{isOpen:{type:Boolean},selectionMode:{default:"single"},selectedItems:{default:()=>[]},modelType:{},modelId:{},collection:{default:"images"},maxSelection:{}},emits:["close","confirm"],setup(o,{emit:a}){const t=o,n=a,i=e.ref("recent"),r=e.ref("grid"),l=e.ref(""),s=e.ref(!1),d=e.ref([]),{selectedItems:c}=e.toRefs(t),u=e.ref(new Set(c.value)),m=e.ref(!1),p=e.ref({}),f=e.ref(["images","documents","videos"]),h=e.ref(1),v=e.ref(!0),y=e.ref(!1),w=sm(),_=fl(d);function b(Z){var be;const k=Z.conversion_urls||{},F=Z.proxy_url||Z.original_url||Z.url||"",W=k.thumb||k.preview||Z.preview_url||Z.thumbnail_url||F,J=Z.custom_properties||{},ce=J.width,Ue=J.height;return{...Z,uuid:Z.uuid,name:Z.name||Z.file_name,file_name:Z.file_name,filename:Z.file_name,mime_type:Z.mime_type,size:Z.size,collection_name:Z.collection_name||"images",disk:Z.disk,original_url:F,url:F,thumbnail_url:W,conversions:Z.conversions||{},conversion_urls:k,generated_conversions:Z.generated_conversions||{},custom_properties:J,caption:Z.caption||null,alt_text:Z.alt_text||null,created_at:Z.created_at,updated_at:Z.updated_at,is_image:((be=Z.mime_type)==null?void 0:be.startsWith("image/"))||!1,...typeof ce=="number"?{width:ce}:{},...typeof Ue=="number"?{height:Ue}:{},...Z.formatted_size!==void 0?{formatted_size:Z.formatted_size}:{}}}e.watch(()=>t.selectedItems,Z=>{u.value=new Set(Z),_.clear(),Z.forEach(k=>_.select(k))});const g=e.computed(()=>{var k;let Z=d.value;return(k=p.value.types)!=null&&k.length&&(Z=Z.filter(F=>{var J,ce;const W=(J=F.mime_type)==null?void 0:J.split("/")[0];return(ce=p.value.types)==null?void 0:ce.includes(W)})),(p.value.sizeMin!==void 0||p.value.sizeMax!==void 0)&&(Z=Z.filter(F=>{const W=F.size/1048576;return!(p.value.sizeMin!==void 0&&W<p.value.sizeMin||p.value.sizeMax!==void 0&&W>p.value.sizeMax)})),Z}),I=e.computed(()=>{var k;let Z=0;return p.value.search&&Z++,p.value.collection&&Z++,(p.value.dateFrom||p.value.dateTo)&&Z++,(k=p.value.types)!=null&&k.length&&(Z+=p.value.types.length),(p.value.sizeMin!==void 0||p.value.sizeMax!==void 0)&&Z++,Z}),T=e.computed(()=>{const Z=_.selectedCount.value;return Z===0?"Select Media":`Select ${t.selectionMode==="multiple"?`${Z} ${Z===1?"Item":"Items"}`:"Item"}`}),$=e.computed(()=>{const Z=_.selectedCount.value;return!!(Z===0||t.selectionMode==="single"&&Z>1||t.maxSelection&&Z>t.maxSelection)}),N=e.computed(()=>{switch(i.value){case"recent":return"Recent Uploads";case"model":return"Model Media";case"library":return"Media Library";default:return"Media Browser"}});async function B(Z=!0){Z?(s.value=!0,d.value=[],h.value=1,v.value=!0):y.value=!0;try{const k={collection:p.value.collection||t.collection,per_page:24};switch((l.value||p.value.search)&&(k.search=l.value||p.value.search||""),p.value.dateFrom&&(k.from_date=p.value.dateFrom),p.value.dateTo&&(k.to_date=p.value.dateTo),i.value){case"recent":await w.fetchMedia(h.value,k),Z?d.value=w.items.map(F=>b(F)):d.value=[...d.value,...w.items.map(F=>b(F))],v.value=w.currentPage<w.totalPages;break;case"model":if(t.modelType&&t.modelId){const F=await w.fetchModelMedia(t.modelType,t.modelId,k.collection,k.search);d.value=F?F.map(W=>b(W)):[],v.value=!1}break;case"library":await w.fetchMedia(h.value,k),Z?d.value=w.items.map(F=>b(F)):d.value=[...d.value,...w.items.map(F=>b(F))],v.value=w.currentPage<w.totalPages;break}}catch{}finally{s.value=!1,y.value=!1}}async function P(Z){if(!v.value||y.value){Z!=null&&Z.target&&Z.target.complete();return}h.value++,await B(!1),Z!=null&&Z.target&&(Z.target.complete(),v.value||(Z.target.disabled=!0))}function x(Z){return Z==="recent"||Z==="model"||Z==="library"}function M(Z){i.value=Z,B()}function E(Z){typeof Z=="string"&&x(Z)&&M(Z)}async function D(Z){t.selectionMode==="single"?(_.clear(),_.select(Z.uuid)):(_.toggle(Z.uuid),t.maxSelection&&_.selectedCount.value>t.maxSelection&&(_.deselect(Z.uuid),await(await G.toastController.create({message:`Maximum ${t.maxSelection} items can be selected`,duration:2e3,color:"warning"})).present()))}function j(){n("confirm",_.selectedItems.value)}function L(){n("close")}function z(Z){}const C=e.ref(null),A=e.ref(!1);function O(Z){C.value=Z,A.value=!0}function K(Z){const k=d.value.findIndex(W=>W.uuid===Z.uuid);k!==-1&&(d.value[k]=Z);const F={};Z.alt_text!==void 0&&(F.alt_text=Z.alt_text),Z.caption!==void 0&&(F.caption=Z.caption),Z.custom_properties!==void 0&&(F.custom_properties=Z.custom_properties),w.updateMedia(Z.uuid,F)}function se(){B()}function xe(){p.value={},l.value="",B()}const ue=Gv(()=>{B(!0)},300);e.watch(l,()=>{t.isOpen&&ue()});async function le(Z){try{await(await G.alertController.create({header:"Delete Media",message:"Are you sure you want to delete this media item?",buttons:[{text:"Cancel",role:"cancel"},{text:"Delete",role:"destructive",handler:async()=>{await w.deleteMedia(Z),await B()}}]})).present()}catch{}}return e.watch(()=>t.isOpen,Z=>{Z&&B()}),e.onMounted(()=>{t.selectedItems.length>0&&t.selectedItems.forEach(Z=>_.select(Z))}),(Z,k)=>{const F=e.resolveComponent("AdminMediaGrid"),W=e.resolveComponent("AdminMediaListItem");return e.openBlock(),e.createBlock(e.unref(G.IonModal),{"is-open":Z.isOpen,onDidDismiss:L,"backdrop-dismiss":!1,class:"media-browser-modal"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonHeader),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonToolbar),null,{end:e.withCtx(()=>[e.createVNode(e.unref(G.IonButtons),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonButton),{onClick:L},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"close-outline"})]),_:1})]),_:1})]),default:e.withCtx(()=>[e.createVNode(e.unref(G.IonTitle),null,{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(N.value),1)]),_:1})]),_:1}),e.createVNode(e.unref(G.IonToolbar),null,{default:e.withCtx(()=>[e.createElementVNode("div",Kv,[e.createVNode(e.unref(G.IonSegment),{value:i.value,onIonChange:k[0]||(k[0]=J=>E(J.detail.value)),class:"max-w-xs"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonSegmentButton),{value:"recent"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[15]||(k[15]=[e.createTextVNode("Recent",-1)])]),_:1})]),_:1}),t.modelType&&t.modelId?(e.openBlock(),e.createBlock(e.unref(G.IonSegmentButton),{key:0,value:"model"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[16]||(k[16]=[e.createTextVNode("Model",-1)])]),_:1})]),_:1})):e.createCommentVNode("",!0),e.createVNode(e.unref(G.IonSegmentButton),{value:"library"},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[17]||(k[17]=[e.createTextVNode("Library",-1)])]),_:1})]),_:1})]),_:1},8,["value"]),e.createVNode(e.unref(G.IonButton),{fill:"clear",size:"small",onClick:k[1]||(k[1]=J=>m.value=!m.value),class:"relative"},{"icon-only":e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"filter-outline"})]),default:e.withCtx(()=>[I.value>0?(e.openBlock(),e.createBlock(e.unref(G.IonBadge),{key:0,color:"primary",class:"absolute -top-1 -right-1 min-w-[20px] h-5 rounded-full flex items-center justify-center text-xs"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(I.value),1)]),_:1})):e.createCommentVNode("",!0)]),_:1})])]),_:1})]),_:1}),e.createVNode(e.unref(G.IonContent),null,{default:e.withCtx(()=>[e.createElementVNode("div",qv,[m.value?(e.openBlock(),e.createElementBlock("div",Jv,[e.createElementVNode("div",Yv,[e.createElementVNode("div",null,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[18]||(k[18]=[e.createTextVNode("Collection",-1)])]),_:1}),e.withDirectives(e.createElementVNode("select",{"onUpdate:modelValue":k[2]||(k[2]=J=>p.value.collection=J),class:"w-full p-2 border rounded"},[k[19]||(k[19]=e.createElementVNode("option",{value:""},"All Collections",-1)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value,J=>(e.openBlock(),e.createElementBlock("option",{key:J,value:J},e.toDisplayString(J),9,Qv))),128))],512),[[e.vModelSelect,p.value.collection]])]),e.createElementVNode("div",null,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[20]||(k[20]=[e.createTextVNode("From Date",-1)])]),_:1}),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":k[3]||(k[3]=J=>p.value.dateFrom=J),type:"date",class:"w-full p-2 border rounded"},null,512),[[e.vModelText,p.value.dateFrom]])]),e.createElementVNode("div",null,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[21]||(k[21]=[e.createTextVNode("To Date",-1)])]),_:1}),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":k[4]||(k[4]=J=>p.value.dateTo=J),type:"date",class:"w-full p-2 border rounded"},null,512),[[e.vModelText,p.value.dateTo]])])]),e.createElementVNode("div",eg,[e.createVNode(e.unref(G.IonButton),{size:"small",onClick:se},{default:e.withCtx(()=>[...k[22]||(k[22]=[e.createTextVNode("Apply",-1)])]),_:1}),e.createVNode(e.unref(G.IonButton),{size:"small",fill:"clear",onClick:xe},{default:e.withCtx(()=>[...k[23]||(k[23]=[e.createTextVNode("Clear",-1)])]),_:1})])])):e.createCommentVNode("",!0),e.createVNode(e.unref(G.IonSearchbar),{modelValue:l.value,"onUpdate:modelValue":k[5]||(k[5]=J=>l.value=J),placeholder:"Search media...",debounce:300,class:"mb-4"},null,8,["modelValue"]),e.createElementVNode("div",tg,[e.createVNode(e.unref(G.IonButtons),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonButton),{fill:r.value==="grid"?"solid":"clear",size:"small",onClick:k[6]||(k[6]=J=>r.value="grid")},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"grid-outline"})]),_:1},8,["fill"]),e.createVNode(e.unref(G.IonButton),{fill:r.value==="list"?"solid":"clear",size:"small",onClick:k[7]||(k[7]=J=>r.value="list")},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"list-outline"})]),_:1},8,["fill"])]),_:1})]),s.value?(e.openBlock(),e.createElementBlock("div",ag,[e.createVNode(e.unref(G.IonSpinner),{name:"crescent"})])):g.value.length===0?(e.openBlock(),e.createElementBlock("div",ng,[e.createVNode(e.unref(G.IonIcon),{name:"images-outline",class:"text-6xl text-theme-secondary mb-4"}),k[24]||(k[24]=e.createElementVNode("h3",{class:"text-lg font-medium text-theme mb-2"}," No Media Found ",-1)),e.createElementVNode("p",og,e.toDisplayString(l.value?"Try adjusting your search":"No media items available"),1)])):r.value==="grid"?(e.openBlock(),e.createBlock(F,{key:3,"media-items":g.value,"selected-items":e.unref(_).selectedItems.value,"is-loading":!1,"selection-mode":!0,columns:{mobile:2,sm:3,md:4,lg:5,xl:6},onToggleSelect:D,onPreview:z,onEdit:O,onDelete:le},null,8,["media-items","selected-items"])):(e.openBlock(),e.createBlock(e.unref(G.IonList),{key:4,lines:"none",class:"rounded-lg overflow-hidden"},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(g.value,(J,ce)=>(e.openBlock(),e.createBlock(W,{key:J.uuid,media:J,selected:e.unref(_).isSelected(J.uuid),"selection-mode":!0,index:ce,onToggleSelect:D,onPreview:z,onEdit:O,onDelete:le},null,8,["media","selected","index"]))),128))]),_:1})),!s.value&&g.value.length>0&&i.value!=="model"?(e.openBlock(),e.createBlock(e.unref(G.IonInfiniteScroll),{key:5,threshold:"100px",onIonInfinite:k[8]||(k[8]=J=>P(J))},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonInfiniteScrollContent),{"loading-spinner":"crescent","loading-text":"Loading more media..."})]),_:1})):e.createCommentVNode("",!0)])]),_:1}),e.createVNode(e.unref(G.IonModal),{"is-open":A.value,onDidDismiss:k[14]||(k[14]=J=>A.value=!1)},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonHeader),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonToolbar),null,{end:e.withCtx(()=>[e.createVNode(e.unref(G.IonButtons),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonButton),{onClick:k[9]||(k[9]=J=>A.value=!1)},{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonIcon),{name:"close-outline"})]),_:1})]),_:1})]),default:e.withCtx(()=>[e.createVNode(e.unref(G.IonTitle),null,{default:e.withCtx(()=>[...k[25]||(k[25]=[e.createTextVNode("Edit Media Info",-1)])]),_:1})]),_:1})]),_:1}),e.createVNode(e.unref(G.IonContent),{class:"p-4"},{default:e.withCtx(()=>[C.value?(e.openBlock(),e.createElementBlock("div",ig,[e.createElementVNode("div",rg,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[26]||(k[26]=[e.createTextVNode("Caption",-1)])]),_:1}),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":k[10]||(k[10]=J=>C.value.caption=J),type:"text",class:"w-full p-2 border rounded mt-1",placeholder:"Enter caption..."},null,512),[[e.vModelText,C.value.caption]])]),e.createElementVNode("div",lg,[e.createVNode(e.unref(G.IonLabel),null,{default:e.withCtx(()=>[...k[27]||(k[27]=[e.createTextVNode("Alt Text",-1)])]),_:1}),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":k[11]||(k[11]=J=>C.value.alt_text=J),type:"text",class:"w-full p-2 border rounded mt-1",placeholder:"Enter alt text..."},null,512),[[e.vModelText,C.value.alt_text]])]),e.createElementVNode("div",sg,[e.createVNode(e.unref(G.IonButton),{onClick:k[12]||(k[12]=J=>K(C.value))},{default:e.withCtx(()=>[...k[28]||(k[28]=[e.createTextVNode("Save",-1)])]),_:1}),e.createVNode(e.unref(G.IonButton),{fill:"clear",onClick:k[13]||(k[13]=J=>A.value=!1)},{default:e.withCtx(()=>[...k[29]||(k[29]=[e.createTextVNode("Cancel",-1)])]),_:1})])])):e.createCommentVNode("",!0)]),_:1})]),_:1},8,["is-open"]),e.createVNode(e.unref(G.IonFooter),null,{default:e.withCtx(()=>[e.createVNode(e.unref(G.IonToolbar),null,{default:e.withCtx(()=>[e.createElementVNode("div",dg,[e.createElementVNode("div",cg,[e.unref(_).selectedCount.value>0?(e.openBlock(),e.createElementBlock("span",ug,[e.createTextVNode(e.toDisplayString(e.unref(_).selectedCount.value)+" selected ",1),t.maxSelection?(e.openBlock(),e.createElementBlock("span",mg," / "+e.toDisplayString(t.maxSelection)+" max ",1)):e.createCommentVNode("",!0)])):(e.openBlock(),e.createElementBlock("span",pg," Select "+e.toDisplayString(t.selectionMode==="multiple"?"items":"an item"),1))]),e.createElementVNode("div",fg,[e.createVNode(e.unref(G.IonButton),{fill:"clear",onClick:L},{default:e.withCtx(()=>[...k[30]||(k[30]=[e.createTextVNode(" Cancel ",-1)])]),_:1}),e.createVNode(e.unref(G.IonButton),{disabled:$.value,onClick:j},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(T.value),1)]),_:1},8,["disabled"])])])]),_:1})]),_:1})]),_:1},8,["is-open"])}}}),vg=Ae(hg,[["__scopeId","data-v-9a8c0954"]]),gg={key:1,class:"flex flex-col items-center justify-center py-16"},bg=["draggable","onDragstart","onDragover","onDrop"],yg={key:0,class:"absolute top-2 left-2 z-20"},wg=["checked","onChange"],kg={key:2,class:"absolute top-2 right-2 z-20 opacity-0 group-hover:opacity-100 transition-opacity cursor-move"},_g=["data-media-id"],Eg={key:0,class:"w-full h-full flex items-center justify-center"},Sg=["src","alt","onError","onLoad"],Cg={key:2,class:"w-full h-full flex items-center justify-center bg-gray-100 dark:bg-gray-700"},xg={class:"text-center"},Ng={class:"text-4xl text-gray-400 mb-2"},Vg={class:"text-sm font-medium text-gray-500"},Tg={class:"absolute inset-0 bg-black/70 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2"},Bg=["onClick"],Mg=["onClick"],Ig=["onClick"],$g={class:"p-3"},Fg={class:"text-sm font-medium truncate mb-1"},Dg={class:"text-xs text-gray-600 dark:text-gray-400"},Ag={key:0},Rg={key:0,class:"text-xs text-gray-500 dark:text-gray-500 mt-1 truncate"},Lg=e.defineComponent({__name:"MediaGrid",props:{mediaItems:{default:()=>[]},selectedItems:{default:()=>[]},isLoading:{type:Boolean,default:!1},selectionMode:{type:Boolean,default:!1},reorderable:{type:Boolean,default:!1},showEditButton:{type:Boolean,default:!1},columns:{default:()=>({mobile:2,sm:3,md:4,lg:5,xl:6})}},emits:["toggleSelect","preview","edit","delete","reorder","upload"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(null),r=e.ref(null),l=e.ref(new Set),s=e.ref(null),d=$=>t.selectedItems.some(N=>N.uuid===$.uuid),c=e.computed(()=>{const $=t.columns,N=["grid","gap-4"];switch($.mobile){case 1:N.push("grid-cols-1");break;case 2:N.push("grid-cols-2");break;case 3:N.push("grid-cols-3");break;case 4:N.push("grid-cols-4");break;default:N.push("grid-cols-2");break}switch($.sm){case 1:N.push("sm:grid-cols-1");break;case 2:N.push("sm:grid-cols-2");break;case 3:N.push("sm:grid-cols-3");break;case 4:N.push("sm:grid-cols-4");break;case 5:N.push("sm:grid-cols-5");break;default:N.push("sm:grid-cols-3");break}switch($.md){case 2:N.push("md:grid-cols-2");break;case 3:N.push("md:grid-cols-3");break;case 4:N.push("md:grid-cols-4");break;case 5:N.push("md:grid-cols-5");break;case 6:N.push("md:grid-cols-6");break;default:N.push("md:grid-cols-4");break}switch($.lg){case 3:N.push("lg:grid-cols-3");break;case 4:N.push("lg:grid-cols-4");break;case 5:N.push("lg:grid-cols-5");break;case 6:N.push("lg:grid-cols-6");break;case 7:N.push("lg:grid-cols-7");break;default:N.push("lg:grid-cols-5");break}switch($.xl){case 4:N.push("xl:grid-cols-4");break;case 5:N.push("xl:grid-cols-5");break;case 6:N.push("xl:grid-cols-6");break;case 7:N.push("xl:grid-cols-7");break;case 8:N.push("xl:grid-cols-8");break;default:N.push("xl:grid-cols-6");break}return N.join(" ")});function u($,N,B){t.reorderable&&(i.value=N,$.dataTransfer&&($.dataTransfer.effectAllowed="move",$.dataTransfer.setData("text/html","")))}function m($,N){t.reorderable&&($.preventDefault(),r.value=N)}function p(){r.value=null}function f($,N){if(!t.reorderable||!i.value)return;$.preventDefault();const B=[...t.mediaItems],P=B.findIndex(x=>{var M;return x.uuid===((M=i.value)==null?void 0:M.uuid)});if(P!==-1&&P!==N&&i.value){const[x]=B.splice(P,1);B.splice(N,0,x),n("reorder",B)}i.value=null,r.value=null}function h($){return $<1024?$+" B":$<1024*1024?($/1024).toFixed(1)+" KB":($/(1024*1024)).toFixed(1)+" MB"}function v($){var B;return $.thumbnail_url||((B=$.conversion_urls)==null?void 0:B.thumb)||$.original_url||$.url||""}function y($){var P,x,M;const N=((P=$.mime_type)==null?void 0:P.startsWith("image/"))||!1,B=!!($.thumbnail_url||(x=$.conversion_urls)!=null&&x.thumb||(M=$.conversion_urls)!=null&&M.preview||$.original_url||$.url);return N&&B}function w($){var N;return((N=$.split(".").pop())==null?void 0:N.toUpperCase())||""}function _($){var B;const N=((B=$.mime_type)==null?void 0:B.toLowerCase())||"";return N.startsWith("image/")?"image":N.startsWith("video/")?"videocam":N.startsWith("audio/")?"musical-notes":N.includes("pdf")?"document-text":N.includes("zip")||N.includes("rar")?"archive":N.includes("sheet")||N.includes("excel")?"grid":N.includes("document")||N.includes("word")?"document-text":"document"}e.onMounted(()=>{typeof window<"u"&&"IntersectionObserver"in window&&(s.value=new IntersectionObserver($=>{$.forEach(N=>{var B;if(N.isIntersecting){const P=N.target.getAttribute("data-media-id");P&&(l.value.add(P),(B=s.value)==null||B.unobserve(N.target))}})},{rootMargin:"50px"}))}),e.onUnmounted(()=>{s.value&&s.value.disconnect()});function b($){return!0}function g(){s.value&&e.nextTick(()=>{document.querySelectorAll("[data-media-id]").forEach(N=>{var P;const B=N.getAttribute("data-media-id");B&&!l.value.has(B)&&((P=s.value)==null||P.observe(N))})})}e.watch(()=>t.mediaItems,()=>{l.value.clear(),g()},{immediate:!0,deep:!0});function I($,N){const B=$.target;delete B.dataset.fallbackIndex}function T($,N){const B=$.target,P=B.closest("[data-media-id]"),x=[N.original_url,N.url,N.thumbnail_url,"preview_url"in N?N.preview_url:void 0].filter(M=>M&&M.trim()!==""&&M!==B.src);if(x.length>0&&B.dataset.fallbackIndex){const M=parseInt(B.dataset.fallbackIndex);if(M<x.length){B.dataset.fallbackIndex=(M+1).toString(),B.src=x[M]||"";return}}else if(x.length>0){B.dataset.fallbackIndex="1",B.src=x[0]||"";return}if(B.style.display="none",P&&!P.querySelector(".media-fallback-icon")){const E=document.createElement("div");E.className="media-fallback-icon w-full h-full flex items-center justify-center bg-gray-100 dark:bg-gray-800",E.innerHTML=`
2
2
  <div class="text-center">
3
3
  <div class="text-4xl text-gray-400 mb-2">${_(N)}</div>
4
4
  <p class="text-sm font-medium text-gray-500">${w(N.file_name)}</p>
@@ -333,7 +333,7 @@ ${i.text}
333
333
  font-size: 13px;
334
334
  padding: 12px 0;
335
335
  }
336
- `,a=document.createElement("style");a.textContent=o,document.head.appendChild(a)}class z2{constructor({filters:a=[],callbacks:t={}}){O2(),this._filters=a,this._cb=t,this._selectedCategory="all",this._selectedFilterId=null,this._activeFilters=new Map,this._drawerOpen=!1,this._drawerFilterId=null,this._root=null,this._catRow=null,this._filterRow=null,this._activeRow=null,this._drawer=null,this._drawerTitle=null,this._drawerBody=null}mount(a){return this._root=xt("div",{className:"mvfp"}),this._catRow=xt("div",{className:"mvfp-row"}),this._root.appendChild(this._catRow),this._filterRow=xt("div",{className:"mvfp-row"}),this._root.appendChild(this._filterRow),this._activeRow=xt("div",{className:"mvfp-active-row"}),this._root.appendChild(this._activeRow),this._buildDrawer(),this._root.appendChild(this._drawer),this._renderCategories(),this._renderFilters(),this._renderActiveChips(),a.appendChild(this._root),this._root}setFilters(a){this._filters=a,this._renderCategories(),this._renderFilters()}setActiveFilters(a){this._activeFilters.clear(),a&&a.forEach((t,n)=>{this._activeFilters.set(n,t)}),this._renderFilters(),this._renderActiveChips(),this._drawerOpen&&this._drawerFilterId&&!this._activeFilters.has(this._drawerFilterId)&&this.closeDrawer()}destroy(){var a;this.closeDrawer(),(a=this._root)==null||a.remove(),this._root=null}_getCategories(){const a=new Map;a.set("all","All");for(const t of this._filters){const n=t.category||"other";a.has(n)||a.set(n,n.charAt(0).toUpperCase()+n.slice(1))}return a}_renderCategories(){this._catRow.innerHTML="",this._getCategories().forEach((t,n)=>{const i=xt("div",{className:`mvfp-cat${this._selectedCategory===n?" active":""}`,onClick:()=>{this._selectedCategory=n,this._renderCategories(),this._renderFilters()}},t);this._catRow.appendChild(i)})}_currentFilters(){return this._selectedCategory==="all"?this._filters:this._filters.filter(a=>(a.category||"other")===this._selectedCategory)}_renderFilters(){this._filterRow.innerHTML="";for(const a of this._currentFilters()){const t=this._activeFilters.has(a.id),n=this._selectedFilterId===a.id,i=xt("div",{className:`mvfp-filter${t?" active":""}${n?" selected":""}`,onClick:()=>this._selectFilter(a)});if(t){const r=xt("div",{className:"mvfp-check",onClick:l=>{l.stopPropagation(),this._removeFilter(a.id)}});r.innerHTML="✓",i.appendChild(r)}i.appendChild(xt("span",{},a.name)),this._filterRow.appendChild(i)}}_selectFilter(a){var t,n,i,r;this._selectedFilterId=a.id,this._activeFilters.has(a.id)||(n=(t=this._cb).onApplyFilter)==null||n.call(t,a),(r=(i=this._cb).onPreviewFilter)==null||r.call(i,a),this._renderFilters(),a.params&&a.params.length>0&&this.openDrawer(a.id)}_removeFilter(a){var t,n;(n=(t=this._cb).onRemoveFilter)==null||n.call(t,a),this._selectedFilterId===a&&(this._selectedFilterId=null)}_renderActiveChips(){if(this._activeRow.innerHTML="",this._activeFilters.size===0){this._activeRow.appendChild(xt("div",{className:"mvfp-placeholder"},"No active filters"));return}this._activeFilters.forEach((a,t)=>{const n=this._filters.find(d=>d.id===t);if(!n)return;const i=this._drawerOpen&&this._drawerFilterId===t,r=xt("div",{className:`mvfp-achip${i?" selected":""}`}),l=xt("span",{style:{cursor:"pointer"},onClick:()=>{this._selectedFilterId=t,this._renderFilters(),n.params&&n.params.length>0&&this.openDrawer(t)}},n.name),s=xt("button",{className:"mvfp-achip-x","aria-label":`Remove ${n.name}`,onClick:d=>{d.stopPropagation(),this._removeFilter(t)}});s.innerHTML='<svg width="10" height="10" viewBox="0 0 12 12"><path d="M3 3l6 6M9 3l-6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',r.appendChild(l),r.appendChild(s),this._activeRow.appendChild(r)})}_buildDrawer(){this._drawer=xt("div",{className:"mvfp-drawer"});const a=xt("div",{className:"mvfp-drawer-hdr"});this._drawerTitle=xt("span",{className:"mvfp-drawer-title"},"Filter");const t=xt("div",{className:"mvfp-drawer-actions"});t.appendChild(xt("button",{className:"mvfp-drawer-btn",onClick:()=>this._resetDrawerFilter()},"Reset")),t.appendChild(xt("button",{className:"mvfp-drawer-btn danger",onClick:()=>{this._drawerFilterId&&(this._removeFilter(this._drawerFilterId),this.closeDrawer())}},"Remove"));const n=xt("button",{className:"mvfp-drawer-close","aria-label":"Close",onClick:()=>this.closeDrawer()});n.innerHTML='<svg width="14" height="14" viewBox="0 0 14 14"><path d="M3 3l8 8M11 3l-8 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',t.appendChild(n),a.appendChild(this._drawerTitle),a.appendChild(t),this._drawer.appendChild(a),this._drawerBody=xt("div",{className:"mvfp-drawer-body"}),this._drawer.appendChild(this._drawerBody)}openDrawer(a){const t=this._filters.find(n=>n.id===a);if(t&&(this._drawerFilterId=a,this._drawerTitle.textContent=t.name,this._renderDrawerControls(t),this._renderActiveChips(),!this._drawerOpen)){this._drawerOpen=!0;const n=this._root.offsetHeight;n>0&&(this._drawer.style.height=n+"px"),this._drawer.style.transition="none",this._drawer.style.transform="translateY(100%)",this._drawer.offsetHeight,this._drawer.style.transition="transform 0.25s cubic-bezier(0.33, 1, 0.68, 1)",this._drawer.style.transform="translateY(0)"}}closeDrawer(){this._drawerOpen&&(this._drawerOpen=!1,this._drawerFilterId=null,this._drawer.style.transition="transform 0.2s cubic-bezier(0.32, 0, 0.67, 0)",this._drawer.style.transform="translateY(100%)",this._renderActiveChips())}_renderDrawerControls(a){if(this._drawerBody.innerHTML="",!a.params||a.params.length===0){this._drawerBody.appendChild(xt("div",{className:"mvfp-no-params"},"No adjustable parameters"));return}const t=this._activeFilters.get(a.id),n=(t==null?void 0:t.params)||{};for(const i of a.params){const r=n[i.id]??i.default,l=xt("div",{className:"mvfp-ctl"}),s=xt("label",{className:"mvfp-ctl-label"},i.label||i.id);l.appendChild(s);const d=i.type||"slider";if(d==="slider"||d==="range"){const c=xt("div",{className:"mvfp-slider-row"}),u=xt("span",{className:"mvfp-range-val"},qc(r)),m=xt("input",{type:"range",className:"mvfp-range",min:String(i.min??0),max:String(i.max??1),step:String(i.step??.01),value:String(typeof r=="number"?r:i.default??0),onInput:p=>{var h,v;const f=parseFloat(p.target.value);u.textContent=qc(f),(v=(h=this._cb).onUpdateParam)==null||v.call(h,a.id,i.id,f)}});c.appendChild(m),c.appendChild(u),l.appendChild(c)}else if(d==="toggle"||d==="checkbox"){const c=xt("div",{className:"mvfp-toggle-row"}),u=xt("input",{type:"checkbox",checked:r?"checked":void 0,onChange:m=>{var p,f;return(f=(p=this._cb).onUpdateParam)==null?void 0:f.call(p,a.id,i.id,m.target.checked)}});c.appendChild(u),l.appendChild(c)}else if(d==="color"){const c=xt("div",{className:"mvfp-color-row"}),u=xt("input",{type:"color",className:"mvfp-color-input",value:typeof r=="string"?r:"#000000",onInput:m=>{var p,f;return(f=(p=this._cb).onUpdateParam)==null?void 0:f.call(p,a.id,i.id,m.target.value)}});c.appendChild(u),l.appendChild(c)}else if(d==="select"||d==="dropdown"){const c=xt("div",{className:"mvfp-select-row"}),u=xt("select",{className:"mvfp-select",onChange:m=>{var p,f;return(f=(p=this._cb).onUpdateParam)==null?void 0:f.call(p,a.id,i.id,m.target.value)}});for(const m of i.options||[]){const p=xt("option",{value:m.value},m.label||String(m.value));m.value===r&&(p.selected=!0),u.appendChild(p)}c.appendChild(u),l.appendChild(c)}this._drawerBody.appendChild(l)}}_resetDrawerFilter(){var t,n;if(!this._drawerFilterId)return;const a=this._filters.find(i=>i.id===this._drawerFilterId);if(a!=null&&a.params){for(const i of a.params)(n=(t=this._cb).onUpdateParam)==null||n.call(t,this._drawerFilterId,i.id,i.default);this._renderDrawerControls(a)}}}const j2=[200,500,1e3];function W2(o){return{"360p":[640,360],"480p":[854,480],"720p":[1280,720],"1080p":[1920,1080],"1440p":[2560,1440],"2160p":[3840,2160]}[o??""]??[1920,1080]}function Yc(o){if(!o)return null;const a=o.duration;if(typeof a=="number"&&Number.isFinite(a)&&a>0)return a;if(a&&typeof a=="object"&&"value"in a){const t=a.value;if(typeof t=="number"&&Number.isFinite(t)&&t>0)return t}return null}function H2(o){return new Promise(a=>{window.setTimeout(a,o)})}async function Qc(){return await Promise.resolve().then(()=>require("./PixiFrameExporter-DkXTPJWn.cjs"))}function eu(o,a=0){var r;const t=o.timeline[0],n=t?Math.max(0,t.sourceIn):0,i=(t==null?void 0:t.sourceOut)??((r=o.source)==null?void 0:r.duration)??a;return Math.max(0,i-n)}function lp(o){let a=null;return{canExportClientSide:async()=>{try{const{isWebCodecsSupported:i}=await Qc();return i()}catch{return!1}},renderRecipeWithPixi:async(i,r,l)=>{var f,h,v,y;const s=i.timeline[0],d=s?Math.max(0,s.sourceIn):0,c=s?s.sourceOut:void 0,[u,m]=W2((r==null?void 0:r.quality)??((f=i.output)==null?void 0:f.quality)),p=((h=i.output)==null?void 0:h.fps)||30;o.setPlaying(!1),o.forcePixiPreview.value=!0,await e.nextTick();try{let w=!1;for(const D of j2){await H2(D);const j=o.getPreviewRef();if(!(!j||typeof j.captureFrameAt!="function")){if(typeof j.ensureReadyForCapture=="function"){if(w=await j.ensureReadyForCapture(),w)break;continue}w=!0;break}}const _=o.getPreviewRef();if(!_||typeof _.captureFrameAt!="function")throw new Error("PIXI preview not available for export. Ensure the preview is mounted.");if(!w)throw new Error("PIXI preview not ready for frame capture after retries. The video may still be loading.");const{exportWithPixiFrames:b,isWebCodecsSupported:g}=await Qc();if(!g())throw new Error("WebCodecs is not supported in this browser. Export requires Chrome 94+ or equivalent.");a=new AbortController;const I={width:u,height:m,fps:p,trimStart:d,signal:a.signal};c!==void 0&&(I.trimEnd=c),l&&(I.onProgress=l);const T=o.getSourceUrl();T!==""&&(I.sourceUrl=T);const $=Yc(_)??((v=i.source)==null?void 0:v.duration)??c??0,N=await b({captureFrameAt:D=>{var j;return((j=_.captureFrameAt)==null?void 0:j.call(_,D))??Promise.resolve(null)},duration:{value:$}},I),B=new File([N],`edited-video-${Date.now()}.mp4`,{type:"video/mp4"}),P=Yc(_),x=((y=i.source)==null?void 0:y.duration)??0,E=Math.max(0,(c??P??x)-d);return{file:B,recipe:i,meta:{duration:E,width:u,height:m,format:"mp4",sizeBytes:B.size,size_bytes:B.size}}}finally{o.forcePixiPreview.value=!1,a=null}},cancelClientExport:()=>{a==null||a.abort(),a=null},resetClientExport:()=>{a=null}}}const li="default-video-track",no="default-media-source";function sp(o){var r,l;const a=G2(o),t=X2(o),n=K2(o.timeline,((r=t[0])==null?void 0:r.id)??li,((l=a[0])==null?void 0:l.id)??no),i={version:o.version,source:{...o.source},mediaSources:a,tracks:q2(t,n),clips:n,markers:o.markers?o.markers.map(s=>({...s})):[],transitions:o.transitions?o.transitions.map(up):[],filters:o.filters.map(s=>({...s,params:{...s.params}})),audio:{...o.audio},output:{...o.output}};return typeof o.duration=="number"&&(i.duration=o.duration),o.snapSettings&&(i.snapSettings={...o.snapSettings}),o.textOverlays&&(i.textOverlays=[...o.textOverlays]),o.captionTracks&&(i.captionTracks=o.captionTracks.map(mp)),o.visualLayers&&(i.visualLayers=o.visualLayers.map(pp)),o.audioTracks&&(i.audioTracks=[...o.audioTracks]),o.posterFrame&&(i.posterFrame=o.posterFrame),o.metadata&&(i.metadata={...o.metadata}),i}function Z2(o){const a={version:"1.0",source:{...o.source},timeline:o.clips.map(t=>({...t})),mediaSources:o.mediaSources.map(dp),tracks:o.tracks.map(cp),markers:o.markers.map(t=>({...t})),transitions:o.transitions.map(up),filters:o.filters.map(t=>({...t,params:{...t.params}})),audio:{...o.audio},output:{...o.output}};return typeof o.duration=="number"&&(a.duration=o.duration),o.snapSettings&&(a.snapSettings={...o.snapSettings}),o.textOverlays&&(a.textOverlays=[...o.textOverlays]),o.captionTracks&&(a.captionTracks=o.captionTracks.map(mp)),o.visualLayers&&(a.visualLayers=o.visualLayers.map(pp)),o.audioTracks&&(a.audioTracks=[...o.audioTracks]),o.posterFrame&&(a.posterFrame=o.posterFrame),o.metadata&&(a.metadata={...o.metadata}),a}function G2(o){var t,n;if(o.mediaSources&&o.mediaSources.length>0)return o.mediaSources.map(dp);const a={id:((t=o.timeline.find(i=>i.sourceRefId))==null?void 0:t.sourceRefId)??no,type:"media",mediaUuid:o.source.media_uuid,duration:o.source.duration,width:o.source.original_width,height:o.source.original_height};return(n=o.metadata)!=null&&n.source_url&&(a.url=o.metadata.source_url),[a]}function X2(o){var a;return o.tracks&&o.tracks.length>0?o.tracks.map(cp):[{id:((a=o.timeline.find(t=>t.trackId))==null?void 0:a.trackId)??li,type:"video",name:"Video",order:0}]}function K2(o,a,t){return o.map(n=>{const i={...n,trackId:n.trackId??a,sourceRefId:n.sourceRefId??t};return n.filters&&(i.filters=n.filters.map(r=>({...r,params:{...r.params}}))),n.transform&&(i.transform={...n.transform}),n.keyframes&&(i.keyframes=n.keyframes.map(r=>({...r}))),i})}function q2(o,a){return o.map(t=>{const n=a.filter(i=>i.trackId===t.id).map(i=>i.id);return{...t,clipIds:n}})}function dp(o){const a={...o};return o.metadata&&(a.metadata={...o.metadata}),a}function cp(o){const a={...o};return o.clipIds&&(a.clipIds=[...o.clipIds]),a}function up(o){const a={...o};return o.params&&(a.params={...o.params}),a}function mp(o){return{...o,segments:o.segments.map(t=>{const n={...t};return t.words&&(n.words=t.words.map(i=>({...i}))),n})}}function pp(o){return{...o,transform:{...o.transform,position:{...o.transform.position},anchor:{...o.transform.anchor},scale:{...o.transform.scale}},keyframes:o.keyframes?o.keyframes.map(a=>({...a})):void 0}}const fp="video-project-draft-snapshot:v1",qs="mediables:video-project-drafts",J2=(o,a={})=>{var p,f;const t=Pn(a.now)??Date.now(),n=Pn(a.createdAt)??t,i=Pn(a.updatedAt)??t,r=dE(o),l={id:Ja(a.id)??pE(i),payloadKind:r,createdAt:new Date(n).toISOString(),updatedAt:new Date(i).toISOString(),deviceKind:a.deviceKind??"unknown"},s=Ja(a.projectId),d=Ja(a.sourceMediaUuid)??Ja(o.source.media_uuid),c=Js(a.durationSeconds)??cE(o),u=Ja(a.editorVersion)??Ja((p=o.metadata)==null?void 0:p.editor_version),m=Ja(a.title)??Ja((f=o.metadata)==null?void 0:f.title);return s!==null&&(l.projectId=s),d!==null&&(l.sourceMediaUuid=d),c!==null&&(l.durationSeconds=c),u!==null&&(l.editorVersion=u),m!==null&&(l.title=m),a.saveReason!==void 0&&(l.saveReason=a.saveReason),{schemaVersion:fp,metadata:l,payload:o}},hp=(o,a=qs)=>{const t=Ja(a)??qs,n=iu(o.metadata.projectId??"unsaved-project"),i=iu(o.metadata.id);return`${t}:${n}:${i}`},Y2=o=>JSON.stringify(o),Q2=o=>{if(typeof o!="string"||o.trim().length===0)return null;try{const a=JSON.parse(o);return rE(a)?a:null}catch{return null}},eE=o=>{const a=[];for(const t of o){const n=Ja(t.key),i=Q2(t.value);n===null||i===null||a.push({key:n,snapshot:i})}return ji(a)},tE=(o,a)=>{const t=mE(a.maxCount),n=Pn(a.now)??Date.now(),i=wp(a.maxAgeMs),r=[],l=[];let s=0;for(const d of ji(o)){if(!bp(d,a.projectId)){r.push(d);continue}if(yp(d.snapshot,n,i)||s>=t){l.push(d);continue}r.push(d),s+=1}return{retained:ji(r),removed:ji(l)}},aE=(o,a={})=>{const t={key:hp(o),snapshot:o};if(!bp(t,a.projectId))return!1;const n=Pn(a.now)??Date.now(),i=wp(a.maxAgeMs);if(yp(o,n,i))return!1;const r=a.savedAt===null?null:Pn(a.savedAt);return r===null?!0:al(o)>r},nE=(o,a={})=>ji(o).filter(t=>aE(t.snapshot,a)),oE=(o,a,t={})=>{const n=nE(o,t);if(a==="mobile"){const i=n[0]??null;return i===null?[]:[i]}return n},iE=async(o,a,t=hp(a))=>(await o.setItem(t,Y2(a)),{key:t,snapshot:a}),tu=async(o,a=qs)=>{const t=await o.listKeys(a),n=[];for(const i of t)n.push({key:i,value:await o.getItem(i)});return eE(n)},au=async(o,a)=>{for(const t of a)await o.removeItem(t.key)},rE=o=>!Un(o)||o.schemaVersion!==fp||!lE(o.metadata)?!1:o.metadata.payloadKind==="project"?vp(o.payload):sE(o.payload),lE=o=>Un(o)?Fd(o.id)&&hE(o.payloadKind)&&ou(o.createdAt)&&ou(o.updatedAt)&&vE(o.deviceKind)&&Er(o.projectId)&&Er(o.sourceMediaUuid)&&fE(o.durationSeconds)&&Er(o.editorVersion)&&Er(o.title)&&gE(o.saveReason):!1,sE=o=>Un(o)?o.version==="1.0"&&gp(o.source)&&Array.isArray(o.timeline)&&Array.isArray(o.filters)&&Un(o.audio)&&Un(o.output):!1,vp=o=>Un(o)?o.version==="1.0"&&gp(o.source)&&Array.isArray(o.mediaSources)&&Array.isArray(o.tracks)&&Array.isArray(o.clips)&&Array.isArray(o.markers)&&Array.isArray(o.filters)&&Un(o.audio)&&Un(o.output):!1,gp=o=>Un(o)?Fd(o.media_uuid)&&Wi(o.duration)&&Wi(o.original_width)&&Wi(o.original_height):!1,dE=o=>vp(o)?"project":"recipe",cE=o=>Js(o.duration)??Js(o.source.duration),bp=(o,a)=>{const t=Ja(a);return t===null?!0:o.snapshot.metadata.projectId===t},yp=(o,a,t)=>t===null?!1:a-al(o)>t,ji=o=>[...o].sort(uE),uE=(o,a)=>{const t=al(a.snapshot)-al(o.snapshot);if(t!==0)return t;const n=nu(a.snapshot)-nu(o.snapshot);return n!==0?n:o.snapshot.metadata.id.localeCompare(a.snapshot.metadata.id)},al=o=>Pn(o.metadata.updatedAt)??0,nu=o=>Pn(o.metadata.createdAt)??0,mE=o=>!Number.isFinite(o)||o<0?0:Math.floor(o),wp=o=>o===void 0||!Number.isFinite(o)||o<0?null:Math.floor(o),Pn=o=>{if(o==null)return null;if(o instanceof Date)return Number.isFinite(o.getTime())?o.getTime():null;if(typeof o=="number")return Number.isFinite(o)?o:null;const a=o.trim();if(a.length===0)return null;const t=Date.parse(a);return Number.isFinite(t)?t:null},ou=o=>typeof o=="string"&&Pn(o)!==null,pE=o=>{var t;const a=typeof((t=globalThis.crypto)==null?void 0:t.randomUUID)=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,12);return`draft-${o}-${a}`},iu=o=>encodeURIComponent(o.trim()),Ja=o=>{if(typeof o!="string")return null;const a=o.trim();return a.length>0?a:null},Fd=o=>Ja(o)!==null,Er=o=>o===void 0||Fd(o),Js=o=>{if(!Wi(o))return null;const a=Number(o.toFixed(6));return Object.is(a,-0)?0:a},Wi=o=>typeof o=="number"&&Number.isFinite(o)&&o>=0,fE=o=>o===void 0||Wi(o),hE=o=>o==="recipe"||o==="project",vE=o=>o==="desktop"||o==="mobile"||o==="tablet"||o==="unknown",gE=o=>o===void 0||o==="autosave"||o==="manual"||o==="before-export"||o==="before-close",Un=o=>typeof o=="object"&&o!==null&&!Array.isArray(o),bE=1,yE="master",Ji=-60,Ys=12,Dd=0,oo=-90,nl=6,wE=4,kp=8;function _p(){return{mobile:{canAdjustTrackFaders:!0,canAdjustMasterFader:!0,canMuteTracks:!0,canSoloTracks:!0,canAdjustPan:!1,canViewMeters:!0,canEditEffectSlots:!1,canEditRouting:!1,canEditAutomation:!1,meterMode:"basic",maxEffectSlots:0},desktop:{canAdjustTrackFaders:!0,canAdjustMasterFader:!0,canMuteTracks:!0,canSoloTracks:!0,canAdjustPan:!0,canViewMeters:!0,canEditEffectSlots:!0,canEditRouting:!0,canEditAutomation:!0,meterMode:"full",maxEffectSlots:kp}}}function kE(o,a=_p()){return ed(a[o])}function Ep(o){return Number.isNaN(o)?Dd:o<=0||o===Number.NEGATIVE_INFINITY?Ji:Yi(20*Math.log10(o))}function Qs(o){const a=Yi(o);return a<=Ji?0:ro(Math.pow(10,a/20),6)}function Yi(o){return Number.isNaN(o)?Dd:o===Number.NEGATIVE_INFINITY?Ji:o===Number.POSITIVE_INFINITY?Ys:ro(cr(o,Ji,Ys),3)}function Sp(o){return Number.isFinite(o)?ro(cr(o,-1,1),3):0}function _E(o,a=!1){const t=o.some(n=>n.controls.solo);return o.map(n=>{const i=n.controls.muted,r=t&&!n.controls.solo,l=a||i||r,s=l?0:n.controls.fader.linearGain;return{trackId:n.id,soloed:n.controls.solo,mutedByTrack:i,mutedBySolo:r,mutedByMaster:a,effectivelyMuted:l,audible:!l,effectiveGainLinear:s}})}function EE(o,a={}){const t=FE(a.effectSlotCount),n=new Set;return{schemaVersion:bE,capabilities:a.capabilities?LE(a.capabilities):_p(),tracks:o.map((i,r)=>CE(i,r,t,n)),master:xE(a.master,t)}}function Cp(o){const a=Yi(o);return{valueDb:a,minDb:Ji,maxDb:Ys,unityDb:Dd,linearGain:Qs(a)}}function SE(o,a="constant-power"){return{value:Sp(o),mode:a}}function xp(o=oo,a=oo,t=o){const n=ds(o),i=ds(a),r=ds(t);return{peakDb:n,rmsDb:i,peakHoldDb:r,clipping:n>=0||r>=0}}function Np(o){const a=Bp(o);return{id:`empty-effect-slot-${a}`,index:a,kind:"empty",label:"Empty",enabled:!1,bypassed:!0,wetMix:0,parameters:{}}}function CE(o,a,t,n){const i=Tp(o.id),l={id:$E(i??`legacy-audio-track-${a+1}`,n),kind:"legacy-url",name:BE(o.name,a),order:a,source:NE(o.source),controls:{fader:Cp(o.faderDb??Ep(o.volume??1)),pan:SE(o.pan??0),muted:o.muted??!1,solo:o.solo??!1,meter:xp(o.peakDb,o.rmsDb,o.peakHoldDb)},timeline:VE(o),effectSlots:Vp(o.effectSlots,t)};return i!==void 0&&(l.legacyTrackId=i),l}function xE(o,a){return{id:yE,name:ME(o==null?void 0:o.name),fader:Cp((o==null?void 0:o.faderDb)??Ep((o==null?void 0:o.volume)??1)),muted:(o==null?void 0:o.muted)??!1,meter:xp(o==null?void 0:o.peakDb,o==null?void 0:o.rmsDb,o==null?void 0:o.peakHoldDb),effectSlots:Vp(o==null?void 0:o.effectSlots,a)}}function NE(o){const a=o.trim();return a===""?{type:"missing"}:{type:"url",url:a}}function VE(o){const a={startTime:AE(o.startTime??0),loop:o.loop??!1},t=DE(o.duration);t!==void 0&&(a.duration=t);const n=ru(o.fadeIn);n!==void 0&&(a.fadeIn=n);const i=ru(o.fadeOut);return i!==void 0&&(a.fadeOut=i),a}function Vp(o,a){const t=new Map;for(const n of o??[]){const i=TE(n,a);t.set(i.index,i)}return Array.from({length:a},(n,i)=>t.get(i)??Np(i))}function TE(o,a){const t=Bp(o.index),n=a>0?Math.min(t,a-1):0,i=o.kind;return i==="empty"?Np(n):{id:Tp(o.id)??`${i}-effect-slot-${n}`,index:n,kind:i,label:IE(o.label,i),enabled:o.enabled,bypassed:o.bypassed,wetMix:RE(o.wetMix),parameters:{...o.parameters}}}function BE(o,a){const t=o==null?void 0:o.trim();return t&&t!==""?t:`Audio ${a+1}`}function ME(o){const a=o==null?void 0:o.trim();return a&&a!==""?a:"Master"}function IE(o,a){const t=o.trim();return t!==""?t:a}function $E(o,a){if(!a.has(o))return a.add(o),o;let t=2,n=`${o}-${t}`;for(;a.has(n);)t+=1,n=`${o}-${t}`;return a.add(n),n}function Tp(o){const a=o==null?void 0:o.trim();if(!(!a||a===""))return a}function FE(o){return o===void 0||!Number.isFinite(o)?wE:Math.trunc(cr(o,0,kp))}function Bp(o){return!Number.isFinite(o)||o<0?0:Math.trunc(o)}function DE(o){if(!(o===void 0||!Number.isFinite(o)||o<=0))return ro(o,3)}function ru(o){if(!(o===void 0||!Number.isFinite(o)||o<0))return ro(o,3)}function AE(o){return!Number.isFinite(o)||o<0?0:ro(o,3)}function RE(o){return Number.isFinite(o)?ro(cr(o,0,1),3):1}function ds(o){return Number.isNaN(o)||o===Number.NEGATIVE_INFINITY?oo:o===Number.POSITIVE_INFINITY?nl:ro(cr(o,oo,nl),3)}function LE(o){return{mobile:ed(o.mobile),desktop:ed(o.desktop)}}function ed(o){return{...o}}function cr(o,a,t){return Math.min(t,Math.max(a,o))}function ro(o,a){const t=10**a;return Math.round(o*t)/t}const PE=/^(\d{2,}:[0-5]\d:[0-5]\d,\d{3})\s+-->\s+(\d{2,}:[0-5]\d:[0-5]\d,\d{3})$/,UE=/^(\d{2,}):([0-5]\d):([0-5]\d),(\d{3})$/,OE="srt-cue";class io extends Error{constructor(a,t,n={}){super(t),this.name="CaptionSrtError",this.code=a,this.context=n}}function zE(o,a={}){var l,s;const t=jE(a.idPrefix),n=o.replace(/^\uFEFF/,"").replace(/\r\n?/g,`
336
+ `,a=document.createElement("style");a.textContent=o,document.head.appendChild(a)}class z2{constructor({filters:a=[],callbacks:t={}}){O2(),this._filters=a,this._cb=t,this._selectedCategory="all",this._selectedFilterId=null,this._activeFilters=new Map,this._drawerOpen=!1,this._drawerFilterId=null,this._root=null,this._catRow=null,this._filterRow=null,this._activeRow=null,this._drawer=null,this._drawerTitle=null,this._drawerBody=null}mount(a){return this._root=xt("div",{className:"mvfp"}),this._catRow=xt("div",{className:"mvfp-row"}),this._root.appendChild(this._catRow),this._filterRow=xt("div",{className:"mvfp-row"}),this._root.appendChild(this._filterRow),this._activeRow=xt("div",{className:"mvfp-active-row"}),this._root.appendChild(this._activeRow),this._buildDrawer(),this._root.appendChild(this._drawer),this._renderCategories(),this._renderFilters(),this._renderActiveChips(),a.appendChild(this._root),this._root}setFilters(a){this._filters=a,this._renderCategories(),this._renderFilters()}setActiveFilters(a){this._activeFilters.clear(),a&&a.forEach((t,n)=>{this._activeFilters.set(n,t)}),this._renderFilters(),this._renderActiveChips(),this._drawerOpen&&this._drawerFilterId&&!this._activeFilters.has(this._drawerFilterId)&&this.closeDrawer()}destroy(){var a;this.closeDrawer(),(a=this._root)==null||a.remove(),this._root=null}_getCategories(){const a=new Map;a.set("all","All");for(const t of this._filters){const n=t.category||"other";a.has(n)||a.set(n,n.charAt(0).toUpperCase()+n.slice(1))}return a}_renderCategories(){this._catRow.innerHTML="",this._getCategories().forEach((t,n)=>{const i=xt("div",{className:`mvfp-cat${this._selectedCategory===n?" active":""}`,onClick:()=>{this._selectedCategory=n,this._renderCategories(),this._renderFilters()}},t);this._catRow.appendChild(i)})}_currentFilters(){return this._selectedCategory==="all"?this._filters:this._filters.filter(a=>(a.category||"other")===this._selectedCategory)}_renderFilters(){this._filterRow.innerHTML="";for(const a of this._currentFilters()){const t=this._activeFilters.has(a.id),n=this._selectedFilterId===a.id,i=xt("div",{className:`mvfp-filter${t?" active":""}${n?" selected":""}`,onClick:()=>this._selectFilter(a)});if(t){const r=xt("div",{className:"mvfp-check",onClick:l=>{l.stopPropagation(),this._removeFilter(a.id)}});r.innerHTML="✓",i.appendChild(r)}i.appendChild(xt("span",{},a.name)),this._filterRow.appendChild(i)}}_selectFilter(a){var t,n,i,r;this._selectedFilterId=a.id,this._activeFilters.has(a.id)||(n=(t=this._cb).onApplyFilter)==null||n.call(t,a),(r=(i=this._cb).onPreviewFilter)==null||r.call(i,a),this._renderFilters(),a.params&&a.params.length>0&&this.openDrawer(a.id)}_removeFilter(a){var t,n;(n=(t=this._cb).onRemoveFilter)==null||n.call(t,a),this._selectedFilterId===a&&(this._selectedFilterId=null)}_renderActiveChips(){if(this._activeRow.innerHTML="",this._activeFilters.size===0){this._activeRow.appendChild(xt("div",{className:"mvfp-placeholder"},"No active filters"));return}this._activeFilters.forEach((a,t)=>{const n=this._filters.find(d=>d.id===t);if(!n)return;const i=this._drawerOpen&&this._drawerFilterId===t,r=xt("div",{className:`mvfp-achip${i?" selected":""}`}),l=xt("span",{style:{cursor:"pointer"},onClick:()=>{this._selectedFilterId=t,this._renderFilters(),n.params&&n.params.length>0&&this.openDrawer(t)}},n.name),s=xt("button",{className:"mvfp-achip-x","aria-label":`Remove ${n.name}`,onClick:d=>{d.stopPropagation(),this._removeFilter(t)}});s.innerHTML='<svg width="10" height="10" viewBox="0 0 12 12"><path d="M3 3l6 6M9 3l-6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',r.appendChild(l),r.appendChild(s),this._activeRow.appendChild(r)})}_buildDrawer(){this._drawer=xt("div",{className:"mvfp-drawer"});const a=xt("div",{className:"mvfp-drawer-hdr"});this._drawerTitle=xt("span",{className:"mvfp-drawer-title"},"Filter");const t=xt("div",{className:"mvfp-drawer-actions"});t.appendChild(xt("button",{className:"mvfp-drawer-btn",onClick:()=>this._resetDrawerFilter()},"Reset")),t.appendChild(xt("button",{className:"mvfp-drawer-btn danger",onClick:()=>{this._drawerFilterId&&(this._removeFilter(this._drawerFilterId),this.closeDrawer())}},"Remove"));const n=xt("button",{className:"mvfp-drawer-close","aria-label":"Close",onClick:()=>this.closeDrawer()});n.innerHTML='<svg width="14" height="14" viewBox="0 0 14 14"><path d="M3 3l8 8M11 3l-8 8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',t.appendChild(n),a.appendChild(this._drawerTitle),a.appendChild(t),this._drawer.appendChild(a),this._drawerBody=xt("div",{className:"mvfp-drawer-body"}),this._drawer.appendChild(this._drawerBody)}openDrawer(a){const t=this._filters.find(n=>n.id===a);if(t&&(this._drawerFilterId=a,this._drawerTitle.textContent=t.name,this._renderDrawerControls(t),this._renderActiveChips(),!this._drawerOpen)){this._drawerOpen=!0;const n=this._root.offsetHeight;n>0&&(this._drawer.style.height=n+"px"),this._drawer.style.transition="none",this._drawer.style.transform="translateY(100%)",this._drawer.offsetHeight,this._drawer.style.transition="transform 0.25s cubic-bezier(0.33, 1, 0.68, 1)",this._drawer.style.transform="translateY(0)"}}closeDrawer(){this._drawerOpen&&(this._drawerOpen=!1,this._drawerFilterId=null,this._drawer.style.transition="transform 0.2s cubic-bezier(0.32, 0, 0.67, 0)",this._drawer.style.transform="translateY(100%)",this._renderActiveChips())}_renderDrawerControls(a){if(this._drawerBody.innerHTML="",!a.params||a.params.length===0){this._drawerBody.appendChild(xt("div",{className:"mvfp-no-params"},"No adjustable parameters"));return}const t=this._activeFilters.get(a.id),n=(t==null?void 0:t.params)||{};for(const i of a.params){const r=n[i.id]??i.default,l=xt("div",{className:"mvfp-ctl"}),s=xt("label",{className:"mvfp-ctl-label"},i.label||i.id);l.appendChild(s);const d=i.type||"slider";if(d==="slider"||d==="range"){const c=xt("div",{className:"mvfp-slider-row"}),u=xt("span",{className:"mvfp-range-val"},qc(r)),m=xt("input",{type:"range",className:"mvfp-range",min:String(i.min??0),max:String(i.max??1),step:String(i.step??.01),value:String(typeof r=="number"?r:i.default??0),onInput:p=>{var h,v;const f=parseFloat(p.target.value);u.textContent=qc(f),(v=(h=this._cb).onUpdateParam)==null||v.call(h,a.id,i.id,f)}});c.appendChild(m),c.appendChild(u),l.appendChild(c)}else if(d==="toggle"||d==="checkbox"){const c=xt("div",{className:"mvfp-toggle-row"}),u=xt("input",{type:"checkbox",checked:r?"checked":void 0,onChange:m=>{var p,f;return(f=(p=this._cb).onUpdateParam)==null?void 0:f.call(p,a.id,i.id,m.target.checked)}});c.appendChild(u),l.appendChild(c)}else if(d==="color"){const c=xt("div",{className:"mvfp-color-row"}),u=xt("input",{type:"color",className:"mvfp-color-input",value:typeof r=="string"?r:"#000000",onInput:m=>{var p,f;return(f=(p=this._cb).onUpdateParam)==null?void 0:f.call(p,a.id,i.id,m.target.value)}});c.appendChild(u),l.appendChild(c)}else if(d==="select"||d==="dropdown"){const c=xt("div",{className:"mvfp-select-row"}),u=xt("select",{className:"mvfp-select",onChange:m=>{var p,f;return(f=(p=this._cb).onUpdateParam)==null?void 0:f.call(p,a.id,i.id,m.target.value)}});for(const m of i.options||[]){const p=xt("option",{value:m.value},m.label||String(m.value));m.value===r&&(p.selected=!0),u.appendChild(p)}c.appendChild(u),l.appendChild(c)}this._drawerBody.appendChild(l)}}_resetDrawerFilter(){var t,n;if(!this._drawerFilterId)return;const a=this._filters.find(i=>i.id===this._drawerFilterId);if(a!=null&&a.params){for(const i of a.params)(n=(t=this._cb).onUpdateParam)==null||n.call(t,this._drawerFilterId,i.id,i.default);this._renderDrawerControls(a)}}}const j2=[200,500,1e3];function W2(o){return{"360p":[640,360],"480p":[854,480],"720p":[1280,720],"1080p":[1920,1080],"1440p":[2560,1440],"2160p":[3840,2160]}[o??""]??[1920,1080]}function Yc(o){if(!o)return null;const a=o.duration;if(typeof a=="number"&&Number.isFinite(a)&&a>0)return a;if(a&&typeof a=="object"&&"value"in a){const t=a.value;if(typeof t=="number"&&Number.isFinite(t)&&t>0)return t}return null}function H2(o){return new Promise(a=>{window.setTimeout(a,o)})}async function Qc(){return await Promise.resolve().then(()=>require("./PixiFrameExporter-CZkLc9b5.cjs"))}function eu(o,a=0){var r;const t=o.timeline[0],n=t?Math.max(0,t.sourceIn):0,i=(t==null?void 0:t.sourceOut)??((r=o.source)==null?void 0:r.duration)??a;return Math.max(0,i-n)}function lp(o){let a=null;return{canExportClientSide:async()=>{try{const{isWebCodecsSupported:i}=await Qc();return i()}catch{return!1}},renderRecipeWithPixi:async(i,r,l)=>{var f,h,v,y;const s=i.timeline[0],d=s?Math.max(0,s.sourceIn):0,c=s?s.sourceOut:void 0,[u,m]=W2((r==null?void 0:r.quality)??((f=i.output)==null?void 0:f.quality)),p=((h=i.output)==null?void 0:h.fps)||30;o.setPlaying(!1),o.forcePixiPreview.value=!0,await e.nextTick();try{let w=!1;for(const D of j2){await H2(D);const j=o.getPreviewRef();if(!(!j||typeof j.captureFrameAt!="function")){if(typeof j.ensureReadyForCapture=="function"){if(w=await j.ensureReadyForCapture(),w)break;continue}w=!0;break}}const _=o.getPreviewRef();if(!_||typeof _.captureFrameAt!="function")throw new Error("PIXI preview not available for export. Ensure the preview is mounted.");if(!w)throw new Error("PIXI preview not ready for frame capture after retries. The video may still be loading.");const{exportWithPixiFrames:b,isWebCodecsSupported:g}=await Qc();if(!g())throw new Error("WebCodecs is not supported in this browser. Export requires Chrome 94+ or equivalent.");a=new AbortController;const I={width:u,height:m,fps:p,trimStart:d,signal:a.signal};c!==void 0&&(I.trimEnd=c),l&&(I.onProgress=l);const T=o.getSourceUrl();T!==""&&(I.sourceUrl=T);const $=Yc(_)??((v=i.source)==null?void 0:v.duration)??c??0,N=await b({captureFrameAt:D=>{var j;return((j=_.captureFrameAt)==null?void 0:j.call(_,D))??Promise.resolve(null)},duration:{value:$}},I),B=new File([N],`edited-video-${Date.now()}.mp4`,{type:"video/mp4"}),P=Yc(_),x=((y=i.source)==null?void 0:y.duration)??0,E=Math.max(0,(c??P??x)-d);return{file:B,recipe:i,meta:{duration:E,width:u,height:m,format:"mp4",sizeBytes:B.size,size_bytes:B.size}}}finally{o.forcePixiPreview.value=!1,a=null}},cancelClientExport:()=>{a==null||a.abort(),a=null},resetClientExport:()=>{a=null}}}const li="default-video-track",no="default-media-source";function sp(o){var r,l;const a=G2(o),t=X2(o),n=K2(o.timeline,((r=t[0])==null?void 0:r.id)??li,((l=a[0])==null?void 0:l.id)??no),i={version:o.version,source:{...o.source},mediaSources:a,tracks:q2(t,n),clips:n,markers:o.markers?o.markers.map(s=>({...s})):[],transitions:o.transitions?o.transitions.map(up):[],filters:o.filters.map(s=>({...s,params:{...s.params}})),audio:{...o.audio},output:{...o.output}};return typeof o.duration=="number"&&(i.duration=o.duration),o.snapSettings&&(i.snapSettings={...o.snapSettings}),o.textOverlays&&(i.textOverlays=[...o.textOverlays]),o.captionTracks&&(i.captionTracks=o.captionTracks.map(mp)),o.visualLayers&&(i.visualLayers=o.visualLayers.map(pp)),o.audioTracks&&(i.audioTracks=[...o.audioTracks]),o.posterFrame&&(i.posterFrame=o.posterFrame),o.metadata&&(i.metadata={...o.metadata}),i}function Z2(o){const a={version:"1.0",source:{...o.source},timeline:o.clips.map(t=>({...t})),mediaSources:o.mediaSources.map(dp),tracks:o.tracks.map(cp),markers:o.markers.map(t=>({...t})),transitions:o.transitions.map(up),filters:o.filters.map(t=>({...t,params:{...t.params}})),audio:{...o.audio},output:{...o.output}};return typeof o.duration=="number"&&(a.duration=o.duration),o.snapSettings&&(a.snapSettings={...o.snapSettings}),o.textOverlays&&(a.textOverlays=[...o.textOverlays]),o.captionTracks&&(a.captionTracks=o.captionTracks.map(mp)),o.visualLayers&&(a.visualLayers=o.visualLayers.map(pp)),o.audioTracks&&(a.audioTracks=[...o.audioTracks]),o.posterFrame&&(a.posterFrame=o.posterFrame),o.metadata&&(a.metadata={...o.metadata}),a}function G2(o){var t,n;if(o.mediaSources&&o.mediaSources.length>0)return o.mediaSources.map(dp);const a={id:((t=o.timeline.find(i=>i.sourceRefId))==null?void 0:t.sourceRefId)??no,type:"media",mediaUuid:o.source.media_uuid,duration:o.source.duration,width:o.source.original_width,height:o.source.original_height};return(n=o.metadata)!=null&&n.source_url&&(a.url=o.metadata.source_url),[a]}function X2(o){var a;return o.tracks&&o.tracks.length>0?o.tracks.map(cp):[{id:((a=o.timeline.find(t=>t.trackId))==null?void 0:a.trackId)??li,type:"video",name:"Video",order:0}]}function K2(o,a,t){return o.map(n=>{const i={...n,trackId:n.trackId??a,sourceRefId:n.sourceRefId??t};return n.filters&&(i.filters=n.filters.map(r=>({...r,params:{...r.params}}))),n.transform&&(i.transform={...n.transform}),n.keyframes&&(i.keyframes=n.keyframes.map(r=>({...r}))),i})}function q2(o,a){return o.map(t=>{const n=a.filter(i=>i.trackId===t.id).map(i=>i.id);return{...t,clipIds:n}})}function dp(o){const a={...o};return o.metadata&&(a.metadata={...o.metadata}),a}function cp(o){const a={...o};return o.clipIds&&(a.clipIds=[...o.clipIds]),a}function up(o){const a={...o};return o.params&&(a.params={...o.params}),a}function mp(o){return{...o,segments:o.segments.map(t=>{const n={...t};return t.words&&(n.words=t.words.map(i=>({...i}))),n})}}function pp(o){return{...o,transform:{...o.transform,position:{...o.transform.position},anchor:{...o.transform.anchor},scale:{...o.transform.scale}},keyframes:o.keyframes?o.keyframes.map(a=>({...a})):void 0}}const fp="video-project-draft-snapshot:v1",qs="mediables:video-project-drafts",J2=(o,a={})=>{var p,f;const t=Pn(a.now)??Date.now(),n=Pn(a.createdAt)??t,i=Pn(a.updatedAt)??t,r=dE(o),l={id:Ja(a.id)??pE(i),payloadKind:r,createdAt:new Date(n).toISOString(),updatedAt:new Date(i).toISOString(),deviceKind:a.deviceKind??"unknown"},s=Ja(a.projectId),d=Ja(a.sourceMediaUuid)??Ja(o.source.media_uuid),c=Js(a.durationSeconds)??cE(o),u=Ja(a.editorVersion)??Ja((p=o.metadata)==null?void 0:p.editor_version),m=Ja(a.title)??Ja((f=o.metadata)==null?void 0:f.title);return s!==null&&(l.projectId=s),d!==null&&(l.sourceMediaUuid=d),c!==null&&(l.durationSeconds=c),u!==null&&(l.editorVersion=u),m!==null&&(l.title=m),a.saveReason!==void 0&&(l.saveReason=a.saveReason),{schemaVersion:fp,metadata:l,payload:o}},hp=(o,a=qs)=>{const t=Ja(a)??qs,n=iu(o.metadata.projectId??"unsaved-project"),i=iu(o.metadata.id);return`${t}:${n}:${i}`},Y2=o=>JSON.stringify(o),Q2=o=>{if(typeof o!="string"||o.trim().length===0)return null;try{const a=JSON.parse(o);return rE(a)?a:null}catch{return null}},eE=o=>{const a=[];for(const t of o){const n=Ja(t.key),i=Q2(t.value);n===null||i===null||a.push({key:n,snapshot:i})}return ji(a)},tE=(o,a)=>{const t=mE(a.maxCount),n=Pn(a.now)??Date.now(),i=wp(a.maxAgeMs),r=[],l=[];let s=0;for(const d of ji(o)){if(!bp(d,a.projectId)){r.push(d);continue}if(yp(d.snapshot,n,i)||s>=t){l.push(d);continue}r.push(d),s+=1}return{retained:ji(r),removed:ji(l)}},aE=(o,a={})=>{const t={key:hp(o),snapshot:o};if(!bp(t,a.projectId))return!1;const n=Pn(a.now)??Date.now(),i=wp(a.maxAgeMs);if(yp(o,n,i))return!1;const r=a.savedAt===null?null:Pn(a.savedAt);return r===null?!0:al(o)>r},nE=(o,a={})=>ji(o).filter(t=>aE(t.snapshot,a)),oE=(o,a,t={})=>{const n=nE(o,t);if(a==="mobile"){const i=n[0]??null;return i===null?[]:[i]}return n},iE=async(o,a,t=hp(a))=>(await o.setItem(t,Y2(a)),{key:t,snapshot:a}),tu=async(o,a=qs)=>{const t=await o.listKeys(a),n=[];for(const i of t)n.push({key:i,value:await o.getItem(i)});return eE(n)},au=async(o,a)=>{for(const t of a)await o.removeItem(t.key)},rE=o=>!Un(o)||o.schemaVersion!==fp||!lE(o.metadata)?!1:o.metadata.payloadKind==="project"?vp(o.payload):sE(o.payload),lE=o=>Un(o)?Fd(o.id)&&hE(o.payloadKind)&&ou(o.createdAt)&&ou(o.updatedAt)&&vE(o.deviceKind)&&Er(o.projectId)&&Er(o.sourceMediaUuid)&&fE(o.durationSeconds)&&Er(o.editorVersion)&&Er(o.title)&&gE(o.saveReason):!1,sE=o=>Un(o)?o.version==="1.0"&&gp(o.source)&&Array.isArray(o.timeline)&&Array.isArray(o.filters)&&Un(o.audio)&&Un(o.output):!1,vp=o=>Un(o)?o.version==="1.0"&&gp(o.source)&&Array.isArray(o.mediaSources)&&Array.isArray(o.tracks)&&Array.isArray(o.clips)&&Array.isArray(o.markers)&&Array.isArray(o.filters)&&Un(o.audio)&&Un(o.output):!1,gp=o=>Un(o)?Fd(o.media_uuid)&&Wi(o.duration)&&Wi(o.original_width)&&Wi(o.original_height):!1,dE=o=>vp(o)?"project":"recipe",cE=o=>Js(o.duration)??Js(o.source.duration),bp=(o,a)=>{const t=Ja(a);return t===null?!0:o.snapshot.metadata.projectId===t},yp=(o,a,t)=>t===null?!1:a-al(o)>t,ji=o=>[...o].sort(uE),uE=(o,a)=>{const t=al(a.snapshot)-al(o.snapshot);if(t!==0)return t;const n=nu(a.snapshot)-nu(o.snapshot);return n!==0?n:o.snapshot.metadata.id.localeCompare(a.snapshot.metadata.id)},al=o=>Pn(o.metadata.updatedAt)??0,nu=o=>Pn(o.metadata.createdAt)??0,mE=o=>!Number.isFinite(o)||o<0?0:Math.floor(o),wp=o=>o===void 0||!Number.isFinite(o)||o<0?null:Math.floor(o),Pn=o=>{if(o==null)return null;if(o instanceof Date)return Number.isFinite(o.getTime())?o.getTime():null;if(typeof o=="number")return Number.isFinite(o)?o:null;const a=o.trim();if(a.length===0)return null;const t=Date.parse(a);return Number.isFinite(t)?t:null},ou=o=>typeof o=="string"&&Pn(o)!==null,pE=o=>{var t;const a=typeof((t=globalThis.crypto)==null?void 0:t.randomUUID)=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,12);return`draft-${o}-${a}`},iu=o=>encodeURIComponent(o.trim()),Ja=o=>{if(typeof o!="string")return null;const a=o.trim();return a.length>0?a:null},Fd=o=>Ja(o)!==null,Er=o=>o===void 0||Fd(o),Js=o=>{if(!Wi(o))return null;const a=Number(o.toFixed(6));return Object.is(a,-0)?0:a},Wi=o=>typeof o=="number"&&Number.isFinite(o)&&o>=0,fE=o=>o===void 0||Wi(o),hE=o=>o==="recipe"||o==="project",vE=o=>o==="desktop"||o==="mobile"||o==="tablet"||o==="unknown",gE=o=>o===void 0||o==="autosave"||o==="manual"||o==="before-export"||o==="before-close",Un=o=>typeof o=="object"&&o!==null&&!Array.isArray(o),bE=1,yE="master",Ji=-60,Ys=12,Dd=0,oo=-90,nl=6,wE=4,kp=8;function _p(){return{mobile:{canAdjustTrackFaders:!0,canAdjustMasterFader:!0,canMuteTracks:!0,canSoloTracks:!0,canAdjustPan:!1,canViewMeters:!0,canEditEffectSlots:!1,canEditRouting:!1,canEditAutomation:!1,meterMode:"basic",maxEffectSlots:0},desktop:{canAdjustTrackFaders:!0,canAdjustMasterFader:!0,canMuteTracks:!0,canSoloTracks:!0,canAdjustPan:!0,canViewMeters:!0,canEditEffectSlots:!0,canEditRouting:!0,canEditAutomation:!0,meterMode:"full",maxEffectSlots:kp}}}function kE(o,a=_p()){return ed(a[o])}function Ep(o){return Number.isNaN(o)?Dd:o<=0||o===Number.NEGATIVE_INFINITY?Ji:Yi(20*Math.log10(o))}function Qs(o){const a=Yi(o);return a<=Ji?0:ro(Math.pow(10,a/20),6)}function Yi(o){return Number.isNaN(o)?Dd:o===Number.NEGATIVE_INFINITY?Ji:o===Number.POSITIVE_INFINITY?Ys:ro(cr(o,Ji,Ys),3)}function Sp(o){return Number.isFinite(o)?ro(cr(o,-1,1),3):0}function _E(o,a=!1){const t=o.some(n=>n.controls.solo);return o.map(n=>{const i=n.controls.muted,r=t&&!n.controls.solo,l=a||i||r,s=l?0:n.controls.fader.linearGain;return{trackId:n.id,soloed:n.controls.solo,mutedByTrack:i,mutedBySolo:r,mutedByMaster:a,effectivelyMuted:l,audible:!l,effectiveGainLinear:s}})}function EE(o,a={}){const t=FE(a.effectSlotCount),n=new Set;return{schemaVersion:bE,capabilities:a.capabilities?LE(a.capabilities):_p(),tracks:o.map((i,r)=>CE(i,r,t,n)),master:xE(a.master,t)}}function Cp(o){const a=Yi(o);return{valueDb:a,minDb:Ji,maxDb:Ys,unityDb:Dd,linearGain:Qs(a)}}function SE(o,a="constant-power"){return{value:Sp(o),mode:a}}function xp(o=oo,a=oo,t=o){const n=ds(o),i=ds(a),r=ds(t);return{peakDb:n,rmsDb:i,peakHoldDb:r,clipping:n>=0||r>=0}}function Np(o){const a=Bp(o);return{id:`empty-effect-slot-${a}`,index:a,kind:"empty",label:"Empty",enabled:!1,bypassed:!0,wetMix:0,parameters:{}}}function CE(o,a,t,n){const i=Tp(o.id),l={id:$E(i??`legacy-audio-track-${a+1}`,n),kind:"legacy-url",name:BE(o.name,a),order:a,source:NE(o.source),controls:{fader:Cp(o.faderDb??Ep(o.volume??1)),pan:SE(o.pan??0),muted:o.muted??!1,solo:o.solo??!1,meter:xp(o.peakDb,o.rmsDb,o.peakHoldDb)},timeline:VE(o),effectSlots:Vp(o.effectSlots,t)};return i!==void 0&&(l.legacyTrackId=i),l}function xE(o,a){return{id:yE,name:ME(o==null?void 0:o.name),fader:Cp((o==null?void 0:o.faderDb)??Ep((o==null?void 0:o.volume)??1)),muted:(o==null?void 0:o.muted)??!1,meter:xp(o==null?void 0:o.peakDb,o==null?void 0:o.rmsDb,o==null?void 0:o.peakHoldDb),effectSlots:Vp(o==null?void 0:o.effectSlots,a)}}function NE(o){const a=o.trim();return a===""?{type:"missing"}:{type:"url",url:a}}function VE(o){const a={startTime:AE(o.startTime??0),loop:o.loop??!1},t=DE(o.duration);t!==void 0&&(a.duration=t);const n=ru(o.fadeIn);n!==void 0&&(a.fadeIn=n);const i=ru(o.fadeOut);return i!==void 0&&(a.fadeOut=i),a}function Vp(o,a){const t=new Map;for(const n of o??[]){const i=TE(n,a);t.set(i.index,i)}return Array.from({length:a},(n,i)=>t.get(i)??Np(i))}function TE(o,a){const t=Bp(o.index),n=a>0?Math.min(t,a-1):0,i=o.kind;return i==="empty"?Np(n):{id:Tp(o.id)??`${i}-effect-slot-${n}`,index:n,kind:i,label:IE(o.label,i),enabled:o.enabled,bypassed:o.bypassed,wetMix:RE(o.wetMix),parameters:{...o.parameters}}}function BE(o,a){const t=o==null?void 0:o.trim();return t&&t!==""?t:`Audio ${a+1}`}function ME(o){const a=o==null?void 0:o.trim();return a&&a!==""?a:"Master"}function IE(o,a){const t=o.trim();return t!==""?t:a}function $E(o,a){if(!a.has(o))return a.add(o),o;let t=2,n=`${o}-${t}`;for(;a.has(n);)t+=1,n=`${o}-${t}`;return a.add(n),n}function Tp(o){const a=o==null?void 0:o.trim();if(!(!a||a===""))return a}function FE(o){return o===void 0||!Number.isFinite(o)?wE:Math.trunc(cr(o,0,kp))}function Bp(o){return!Number.isFinite(o)||o<0?0:Math.trunc(o)}function DE(o){if(!(o===void 0||!Number.isFinite(o)||o<=0))return ro(o,3)}function ru(o){if(!(o===void 0||!Number.isFinite(o)||o<0))return ro(o,3)}function AE(o){return!Number.isFinite(o)||o<0?0:ro(o,3)}function RE(o){return Number.isFinite(o)?ro(cr(o,0,1),3):1}function ds(o){return Number.isNaN(o)||o===Number.NEGATIVE_INFINITY?oo:o===Number.POSITIVE_INFINITY?nl:ro(cr(o,oo,nl),3)}function LE(o){return{mobile:ed(o.mobile),desktop:ed(o.desktop)}}function ed(o){return{...o}}function cr(o,a,t){return Math.min(t,Math.max(a,o))}function ro(o,a){const t=10**a;return Math.round(o*t)/t}const PE=/^(\d{2,}:[0-5]\d:[0-5]\d,\d{3})\s+-->\s+(\d{2,}:[0-5]\d:[0-5]\d,\d{3})$/,UE=/^(\d{2,}):([0-5]\d):([0-5]\d),(\d{3})$/,OE="srt-cue";class io extends Error{constructor(a,t,n={}){super(t),this.name="CaptionSrtError",this.code=a,this.context=n}}function zE(o,a={}){var l,s;const t=jE(a.idPrefix),n=o.replace(/^\uFEFF/,"").replace(/\r\n?/g,`
337
337
  `).split(`
338
338
  `),i=[];let r=0;for(;r<n.length;){for(;r<n.length&&uu(n[r]);)r+=1;if(r>=n.length)break;const d=r+1,c=WE(((l=n[r])==null?void 0:l.trim())??"",d);if(r+=1,r>=n.length)throw new io("missing-timing",`Cue ${c} is missing its timing line.`,{cueIndex:i.length,cueNumber:c,lineNumber:d});const u=r+1,m=HE(((s=n[r])==null?void 0:s.trim())??"",c,u);r+=1;const p=[];for(;r<n.length&&!uu(n[r]);)p.push(n[r]??""),r+=1;i.push({cueNumber:c,id:`${t}-${i.length+1}`,startTime:m.startTime,endTime:m.endTime,text:p.join(`
339
339
  `)})}return Mp(i),i}function lu(o){return Mp(o),o.length===0?"":`${o.map((a,t)=>GE(a,t+1)).join(`
@@ -354,4 +354,4 @@ ${i.text}
354
354
  * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
355
355
  */function dd(o,a){(a==null||a>o.length)&&(a=o.length);for(var t=0,n=Array(a);t<a;t++)n[t]=o[t];return n}function ZF(o){if(Array.isArray(o))return dd(o)}function GF(o,a,t){return(a=YF(a))in o?Object.defineProperty(o,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):o[a]=t,o}function XF(o){if(typeof Symbol<"u"&&o[Symbol.iterator]!=null||o["@@iterator"]!=null)return Array.from(o)}function KF(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
356
356
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ou(o,a){var t=Object.keys(o);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(o);a&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(o,i).enumerable})),t.push.apply(t,n)}return t}function zu(o){for(var a=1;a<arguments.length;a++){var t=arguments[a]!=null?arguments[a]:{};a%2?Ou(Object(t),!0).forEach(function(n){GF(o,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(t)):Ou(Object(t)).forEach(function(n){Object.defineProperty(o,n,Object.getOwnPropertyDescriptor(t,n))})}return o}function qF(o){return ZF(o)||XF(o)||QF(o)||KF()}function JF(o,a){if(typeof o!="object"||!o)return o;var t=o[Symbol.toPrimitive];if(t!==void 0){var n=t.call(o,a);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(o)}function YF(o){var a=JF(o,"string");return typeof a=="symbol"?a:a+""}function QF(o,a){if(o){if(typeof o=="string")return dd(o,a);var t={}.toString.call(o).slice(8,-1);return t==="Object"&&o.constructor&&(t=o.constructor.name),t==="Map"||t==="Set"?Array.from(o):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?dd(o,a):void 0}}var ju={activateTrap:function(a,t){if(a.length>0){var n=a[a.length-1];n!==t&&n._setPausedState(!0)}var i=a.indexOf(t);i===-1||a.splice(i,1),a.push(t)},deactivateTrap:function(a,t){var n=a.indexOf(t);n!==-1&&a.splice(n,1),a.length>0&&!a[a.length-1]._isManuallyPaused()&&a[a.length-1]._setPausedState(!1)}},e8=function(a){return a.tagName&&a.tagName.toLowerCase()==="input"&&typeof a.select=="function"},t8=function(a){return(a==null?void 0:a.key)==="Escape"||(a==null?void 0:a.key)==="Esc"||(a==null?void 0:a.keyCode)===27},Zi=function(a){return(a==null?void 0:a.key)==="Tab"||(a==null?void 0:a.keyCode)===9},a8=function(a){return Zi(a)&&!a.shiftKey},n8=function(a){return Zi(a)&&a.shiftKey},Wu=function(a){return setTimeout(a,0)},Vi=function(a){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];return typeof a=="function"?a.apply(void 0,n):a},Tr=function(a){return a.target.shadowRoot&&typeof a.composedPath=="function"?a.composedPath()[0]:a.target},o8=[],i8=function(a,t){var n=(t==null?void 0:t.document)||document,i=(t==null?void 0:t.trapStack)||o8,r=zu({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:a8,isKeyBackward:n8},t),l={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,manuallyPaused:!1,delayInitialFocusTimer:void 0,recentNavEvent:void 0},s,d=function(E,D,j){return E&&E[D]!==void 0?E[D]:r[j||D]},c=function(E,D){var j=typeof(D==null?void 0:D.composedPath)=="function"?D.composedPath():void 0;return l.containerGroups.findIndex(function(L){var z=L.container,C=L.tabbableNodes;return z.contains(E)||(j==null?void 0:j.includes(z))||C.find(function(A){return A===E})})},u=function(E){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},j=D.hasFallback,L=j===void 0?!1:j,z=D.params,C=z===void 0?[]:z,A=r[E];if(typeof A=="function"&&(A=A.apply(void 0,qF(C))),A===!0&&(A=void 0),!A){if(A===void 0||A===!1)return A;throw new Error("`".concat(E,"` was specified but was not a node, or did not return a node"))}var O=A;if(typeof A=="string"){try{O=n.querySelector(A)}catch(K){throw new Error("`".concat(E,'` appears to be an invalid selector; error="').concat(K.message,'"'))}if(!O&&!L)throw new Error("`".concat(E,"` as selector refers to no known node"))}return O},m=function(){var E=u("initialFocus",{hasFallback:!0});if(E===!1)return!1;if(E===void 0||E&&!bs(E,r.tabbableOptions))if(c(n.activeElement)>=0)E=n.activeElement;else{var D=l.tabbableGroups[0],j=D&&D.firstTabbableNode;E=j||u("fallbackFocus")}else E===null&&(E=u("fallbackFocus"));if(!E)throw new Error("Your focus-trap needs to have at least one focusable element");return E},p=function(){if(l.containerGroups=l.containers.map(function(E){var D=jF(E,r.tabbableOptions),j=WF(E,r.tabbableOptions),L=D.length>0?D[0]:void 0,z=D.length>0?D[D.length-1]:void 0,C=j.find(function(K){return Xo(K)}),A=j.slice().reverse().find(function(K){return Xo(K)}),O=!!D.find(function(K){return Vo(K)>0});return{container:E,tabbableNodes:D,focusableNodes:j,posTabIndexesFound:O,firstTabbableNode:L,lastTabbableNode:z,firstDomTabbableNode:C,lastDomTabbableNode:A,nextTabbableNode:function(se){var xe=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,ue=D.indexOf(se);return ue<0?xe?j.slice(j.indexOf(se)+1).find(function(le){return Xo(le)}):j.slice(0,j.indexOf(se)).reverse().find(function(le){return Xo(le)}):D[ue+(xe?1:-1)]}}}),l.tabbableGroups=l.containerGroups.filter(function(E){return E.tabbableNodes.length>0}),l.tabbableGroups.length<=0&&!u("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times");if(l.containerGroups.find(function(E){return E.posTabIndexesFound})&&l.containerGroups.length>1)throw new Error("At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.")},f=function(E){var D=E.activeElement;if(D)return D.shadowRoot&&D.shadowRoot.activeElement!==null?f(D.shadowRoot):D},h=function(E){if(E!==!1&&E!==f(document)){if(!E||!E.focus){h(m());return}E.focus({preventScroll:!!r.preventScroll}),l.mostRecentlyFocusedNode=E,e8(E)&&E.select()}},v=function(E){var D=u("setReturnFocus",{params:[E]});return D||(D===!1?!1:E)},y=function(E){var D=E.target,j=E.event,L=E.isBackward,z=L===void 0?!1:L;D=D||Tr(j),p();var C=null;if(l.tabbableGroups.length>0){var A=c(D,j),O=A>=0?l.containerGroups[A]:void 0;if(A<0)z?C=l.tabbableGroups[l.tabbableGroups.length-1].lastTabbableNode:C=l.tabbableGroups[0].firstTabbableNode;else if(z){var K=l.tabbableGroups.findIndex(function(k){var F=k.firstTabbableNode;return D===F});if(K<0&&(O.container===D||bs(D,r.tabbableOptions)&&!Xo(D,r.tabbableOptions)&&!O.nextTabbableNode(D,!1))&&(K=A),K>=0){var se=K===0?l.tabbableGroups.length-1:K-1,xe=l.tabbableGroups[se];C=Vo(D)>=0?xe.lastTabbableNode:xe.lastDomTabbableNode}else Zi(j)||(C=O.nextTabbableNode(D,!1))}else{var ue=l.tabbableGroups.findIndex(function(k){var F=k.lastTabbableNode;return D===F});if(ue<0&&(O.container===D||bs(D,r.tabbableOptions)&&!Xo(D,r.tabbableOptions)&&!O.nextTabbableNode(D))&&(ue=A),ue>=0){var le=ue===l.tabbableGroups.length-1?0:ue+1,Z=l.tabbableGroups[le];C=Vo(D)>=0?Z.firstTabbableNode:Z.firstDomTabbableNode}else Zi(j)||(C=O.nextTabbableNode(D))}}else C=u("fallbackFocus");return C},w=function(E){var D=Tr(E);if(!(c(D,E)>=0)){if(Vi(r.clickOutsideDeactivates,E)){s.deactivate({returnFocus:r.returnFocusOnDeactivate});return}Vi(r.allowOutsideClick,E)||E.preventDefault()}},_=function(E){var D=Tr(E),j=c(D,E)>=0;if(j||D instanceof Document)j&&(l.mostRecentlyFocusedNode=D);else{E.stopImmediatePropagation();var L,z=!0;if(l.mostRecentlyFocusedNode)if(Vo(l.mostRecentlyFocusedNode)>0){var C=c(l.mostRecentlyFocusedNode),A=l.containerGroups[C].tabbableNodes;if(A.length>0){var O=A.findIndex(function(K){return K===l.mostRecentlyFocusedNode});O>=0&&(r.isKeyForward(l.recentNavEvent)?O+1<A.length&&(L=A[O+1],z=!1):O-1>=0&&(L=A[O-1],z=!1))}}else l.containerGroups.some(function(K){return K.tabbableNodes.some(function(se){return Vo(se)>0})})||(z=!1);else z=!1;z&&(L=y({target:l.mostRecentlyFocusedNode,isBackward:r.isKeyBackward(l.recentNavEvent)})),h(L||l.mostRecentlyFocusedNode||m())}l.recentNavEvent=void 0},b=function(E){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;l.recentNavEvent=E;var j=y({event:E,isBackward:D});j&&(Zi(E)&&E.preventDefault(),h(j))},g=function(E){(r.isKeyForward(E)||r.isKeyBackward(E))&&b(E,r.isKeyBackward(E))},I=function(E){t8(E)&&Vi(r.escapeDeactivates,E)!==!1&&(E.preventDefault(),s.deactivate())},T=function(E){var D=Tr(E);c(D,E)>=0||Vi(r.clickOutsideDeactivates,E)||Vi(r.allowOutsideClick,E)||(E.preventDefault(),E.stopImmediatePropagation())},$=function(){if(l.active)return ju.activateTrap(i,s),l.delayInitialFocusTimer=r.delayInitialFocus?Wu(function(){h(m())}):h(m()),n.addEventListener("focusin",_,!0),n.addEventListener("mousedown",w,{capture:!0,passive:!1}),n.addEventListener("touchstart",w,{capture:!0,passive:!1}),n.addEventListener("click",T,{capture:!0,passive:!1}),n.addEventListener("keydown",g,{capture:!0,passive:!1}),n.addEventListener("keydown",I),s},N=function(){if(l.active)return n.removeEventListener("focusin",_,!0),n.removeEventListener("mousedown",w,!0),n.removeEventListener("touchstart",w,!0),n.removeEventListener("click",T,!0),n.removeEventListener("keydown",g,!0),n.removeEventListener("keydown",I),s},B=function(E){var D=E.some(function(j){var L=Array.from(j.removedNodes);return L.some(function(z){return z===l.mostRecentlyFocusedNode})});D&&h(m())},P=typeof window<"u"&&"MutationObserver"in window?new MutationObserver(B):void 0,x=function(){P&&(P.disconnect(),l.active&&!l.paused&&l.containers.map(function(E){P.observe(E,{subtree:!0,childList:!0})}))};return s={get active(){return l.active},get paused(){return l.paused},activate:function(E){if(l.active)return this;var D=d(E,"onActivate"),j=d(E,"onPostActivate"),L=d(E,"checkCanFocusTrap");L||p(),l.active=!0,l.paused=!1,l.nodeFocusedBeforeActivation=f(n),D==null||D();var z=function(){L&&p(),$(),x(),j==null||j()};return L?(L(l.containers.concat()).then(z,z),this):(z(),this)},deactivate:function(E){if(!l.active)return this;var D=zu({onDeactivate:r.onDeactivate,onPostDeactivate:r.onPostDeactivate,checkCanReturnFocus:r.checkCanReturnFocus},E);clearTimeout(l.delayInitialFocusTimer),l.delayInitialFocusTimer=void 0,N(),l.active=!1,l.paused=!1,x(),ju.deactivateTrap(i,s);var j=d(D,"onDeactivate"),L=d(D,"onPostDeactivate"),z=d(D,"checkCanReturnFocus"),C=d(D,"returnFocus","returnFocusOnDeactivate");j==null||j();var A=function(){Wu(function(){C&&h(v(l.nodeFocusedBeforeActivation)),L==null||L()})};return C&&z?(z(v(l.nodeFocusedBeforeActivation)).then(A,A),this):(A(),this)},pause:function(E){return l.active?(l.manuallyPaused=!0,this._setPausedState(!0,E)):this},unpause:function(E){return l.active?(l.manuallyPaused=!1,i[i.length-1]!==this?this:this._setPausedState(!1,E)):this},updateContainerElements:function(E){var D=[].concat(E).filter(Boolean);return l.containers=D.map(function(j){return typeof j=="string"?n.querySelector(j):j}),l.active&&p(),x(),this}},Object.defineProperties(s,{_isManuallyPaused:{value:function(){return l.manuallyPaused}},_setPausedState:{value:function(E,D){if(l.paused===E)return this;if(l.paused=E,E){var j=d(D,"onPause"),L=d(D,"onPostPause");j==null||j(),N(),x(),L==null||L()}else{var z=d(D,"onUnpause"),C=d(D,"onPostUnpause");z==null||z(),p(),$(),x(),C==null||C()}return this}}}),s.updateContainerElements(a),s};const r8=["aria-labelledby"],l8={class:"media-preview-sheet__header"},s8=["id"],d8=["aria-label"],c8=["src","alt"],u8=["src"],m8={class:"media-preview-sheet__actions"},p8=["disabled","aria-label"],f8=["aria-label","aria-pressed"],h8=["disabled","aria-label"],v8=e.defineComponent({__name:"MediaPreviewSheet",props:{open:{type:Boolean,default:!1},media:{default:null},canGoPrevious:{type:Boolean,default:!1},canGoNext:{type:Boolean,default:!1},selected:{type:Boolean,default:!1},closeLabel:{default:"Close"},previousLabel:{default:"Previous"},nextLabel:{default:"Next"},selectLabel:{default:"Select"},deselectLabel:{default:"Deselect"}},emits:["close","previous","next","toggleSelect"],setup(o,{emit:a}){const t=o,n=a,i=e.useId(),r=e.ref(null),l=e.ref(null);let s=null,d=null;const c=e.computed(()=>{var P;return((P=t.media)==null?void 0:P.mime_type.startsWith("image/"))===!0}),u=/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/ig,m=/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,p=e.computed(()=>t.media?t.media.preview_url??t.media.original_url:"");function f(P){const x=P.replace(/\.[^.]+$/,""),E=x.replace(u,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim();return E!==""?E:x||P}function h(P){var D,j;const x=(D=P.name)==null?void 0:D.trim(),M=P.file_name.replace(/\.[^.]+$/,"");if(x!==void 0&&x!==""&&x!==P.file_name&&x!==M&&!m.test(x))return x;const E=(j=P.alt_text)==null?void 0:j.trim();return E!==void 0&&E!==""?E:f(x||P.file_name)}const v=e.computed(()=>t.media?h(t.media):"media"),y=e.computed(()=>t.media?`Preview ${v.value}`:"Media preview"),w=e.computed(()=>t.media?`Close preview of ${v.value}`:"Close preview"),_=e.computed(()=>t.canGoPrevious?"Previous media":"No previous media"),b=e.computed(()=>t.canGoNext?"Next media":"No next media"),g=e.computed(()=>{const P=t.selected?t.deselectLabel:t.selectLabel;return t.media?t.selected?`${t.deselectLabel} ${v.value}`:`${t.selectLabel} ${v.value}`:P}),I=e.computed(()=>t.selected?t.deselectLabel:t.selectLabel),T=()=>{t.media&&n("toggleSelect",t.media)},$=P=>{if(P.key==="Escape"){P.preventDefault(),n("close");return}if(P.key==="ArrowLeft"&&t.canGoPrevious){P.preventDefault(),n("previous");return}P.key==="ArrowRight"&&t.canGoNext&&(P.preventDefault(),n("next"))},N=()=>{if(s){try{s.deactivate({returnFocus:!1})}catch{}s=null}},B=()=>{const P=d;d=null,P&&typeof P.focus=="function"&&e.nextTick(()=>{P.focus()})};return e.watch(()=>t.open&&t.media!==null,async P=>{var x;if(P){d=document.activeElement instanceof HTMLElement?document.activeElement:null,await e.nextTick();const M=r.value;if(M)try{s=i8(M,{initialFocus:()=>l.value??M,escapeDeactivates:!1,clickOutsideDeactivates:!1,returnFocusOnDeactivate:!1,allowOutsideClick:!0}),s.activate()}catch{(x=l.value)==null||x.focus()}}else N(),B()},{immediate:!0}),e.onBeforeUnmount(()=>{N()}),(P,x)=>(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[P.open&&P.media?(e.openBlock(),e.createElementBlock("section",{key:0,ref_key:"sheetRef",ref:r,class:"media-preview-sheet",role:"dialog","aria-modal":"true","aria-labelledby":e.unref(i),tabindex:"-1","data-testid":"media-preview-sheet",onKeydown:$},[e.createElementVNode("header",l8,[e.createElementVNode("strong",{id:e.unref(i),"data-testid":"media-preview-sheet-title"},e.toDisplayString(y.value),9,s8),e.createElementVNode("button",{ref_key:"closeButtonRef",ref:l,type:"button",class:"media-preview-sheet__close","aria-label":w.value,"data-testid":"btn-media-preview-close",onClick:x[0]||(x[0]=M=>n("close"))},e.toDisplayString(P.closeLabel),9,d8)]),c.value?(e.openBlock(),e.createElementBlock("img",{key:0,class:"media-preview-sheet__image",src:p.value,alt:P.media.alt_text||v.value},null,8,c8)):(e.openBlock(),e.createElementBlock("video",{key:1,class:"media-preview-sheet__video",src:p.value,controls:""},null,8,u8)),e.createElementVNode("div",m8,[e.createElementVNode("button",{type:"button",class:"media-preview-sheet__nav",disabled:!P.canGoPrevious,"aria-label":_.value,"data-testid":"btn-media-preview-previous",onClick:x[1]||(x[1]=M=>n("previous"))},e.toDisplayString(P.previousLabel),9,p8),e.createElementVNode("button",{type:"button",class:"media-preview-sheet__select","aria-label":g.value,"aria-pressed":P.selected,"data-testid":"btn-media-preview-select",onClick:T},e.toDisplayString(I.value),9,f8),e.createElementVNode("button",{type:"button",class:"media-preview-sheet__nav",disabled:!P.canGoNext,"aria-label":b.value,"data-testid":"btn-media-preview-next",onClick:x[2]||(x[2]=M=>n("next"))},e.toDisplayString(P.nextLabel),9,h8)])],40,r8)):e.createCommentVNode("",!0)]))}}),Wd=Ae(v8,[["__scopeId","data-v-fa05530d"]]),g8={key:0,class:"media-album-grid","data-testid":"media-source-sheet"},b8={class:"media-album-grid__items"},y8={class:"media-album-grid__card-name"},w8={class:"media-album-grid__card-name"},k8=["data-testid","onClick"],_8={class:"media-album-grid__card-name"},E8={key:0,class:"media-album-grid__card-meta"},S8={key:0,class:"media-album-grid__empty"},C8=e.defineComponent({__name:"MediaSourceSheet",props:{open:{type:Boolean,default:!1},currentView:{},albums:{},viewLibraryLabel:{default:"Library"},browseAlbumsLabel:{default:"Albums"},createAlbumLabel:{default:"Create album"},enableAlbumCreation:{type:Boolean,default:!1}},emits:["close","selectLibrary","selectAlbum","createAlbum"],setup(o,{emit:a}){const t=a;return(n,i)=>n.open?(e.openBlock(),e.createElementBlock("section",g8,[e.createElementVNode("div",b8,[n.enableAlbumCreation?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"media-album-grid__card media-album-grid__card--create","data-testid":"btn-media-source-create-album",onClick:i[0]||(i[0]=r=>t("createAlbum"))},[i[2]||(i[2]=e.createElementVNode("div",{class:"media-album-grid__card-icon"},[e.createElementVNode("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[e.createElementVNode("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.createElementVNode("line",{x1:"5",y1:"12",x2:"19",y2:"12"})])],-1)),e.createElementVNode("span",y8,e.toDisplayString(n.createAlbumLabel),1)])):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"button",class:e.normalizeClass(["media-album-grid__card",{"is-active":n.currentView.scope==="library"}]),"data-testid":"btn-media-source-library",onClick:i[1]||(i[1]=r=>t("selectLibrary"))},[i[3]||(i[3]=e.createStaticVNode('<div class="media-album-grid__card-icon" data-v-129f67b1><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" data-v-129f67b1><rect x="3" y="3" width="7" height="7" data-v-129f67b1></rect><rect x="14" y="3" width="7" height="7" data-v-129f67b1></rect><rect x="14" y="14" width="7" height="7" data-v-129f67b1></rect><rect x="3" y="14" width="7" height="7" data-v-129f67b1></rect></svg></div>',1)),e.createElementVNode("span",w8,e.toDisplayString(n.viewLibraryLabel),1),i[4]||(i[4]=e.createElementVNode("span",{class:"media-album-grid__card-meta"},"All media",-1))],2),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.albums,r=>(e.openBlock(),e.createElementBlock("button",{key:r.id,type:"button",class:e.normalizeClass(["media-album-grid__card",{"is-active":n.currentView.scope==="album"&&n.currentView.albumId===r.id}]),"data-testid":`btn-media-source-album-${r.id}`,onClick:l=>t("selectAlbum",r)},[i[5]||(i[5]=e.createElementVNode("div",{class:"media-album-grid__card-icon"},[e.createElementVNode("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[e.createElementVNode("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})])],-1)),e.createElementVNode("span",_8,e.toDisplayString(r.name),1),r.mediaCount!==void 0?(e.openBlock(),e.createElementBlock("span",E8,e.toDisplayString(r.mediaCount)+" item"+e.toDisplayString(r.mediaCount===1?"":"s"),1)):e.createCommentVNode("",!0)],10,k8))),128))]),n.albums.length===0?(e.openBlock(),e.createElementBlock("p",S8," No albums yet. ")):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)}}),Vf=Ae(C8,[["__scopeId","data-v-129f67b1"]]),x8={key:0,class:"media-upload-sheet","data-testid":"media-upload-sheet"},N8={class:"media-upload-sheet__dropzone-text"},V8={key:0,class:"media-upload-sheet__dropzone-helper","data-testid":"text-media-upload-sheet-helper"},T8={class:"media-upload-sheet__sr-only"},B8=["accept","aria-label"],M8=["aria-label"],I8={class:"media-upload-sheet__queue-row"},$8={key:0,class:"media-upload-sheet__preview"},F8=["src","alt","data-testid"],D8={class:"media-upload-sheet__queue-body"},A8={class:"media-upload-sheet__queue-info"},R8={class:"media-upload-sheet__queue-status"},L8=["aria-valuenow","aria-label","data-testid"],P8=["aria-label"],U8=e.defineComponent({__name:"MediaUploadSheet",props:{open:{type:Boolean,default:!1},queue:{},accept:{default:""},uploadLabel:{default:"Upload"},dropzoneLabel:{default:"Drop files here or browse"},dropzoneHelperText:{default:""},fileInputLabel:{default:"Choose media files"},closeButtonAriaLabel:{default:"Close upload panel"},closeButtonLabel:{default:"Done"},progressAriaLabel:{}},emits:["close","filesSelected"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(!1),r=p=>{var h;return t.progressAriaLabel!==void 0?t.progressAriaLabel(p):`Uploading ${((h=p.file)==null?void 0:h.name)??"file"}`},l=p=>{const f=Number.isFinite(p.progress)?p.progress:0;return f<0?0:f>100?100:Math.round(f)},s=e.computed(()=>t.queue.length===0?"":`${t.queue.length} upload${t.queue.length===1?"":"s"} in progress`),d=p=>{const f=p.target;!(f instanceof HTMLInputElement)||f.files===null||(n("filesSelected",Array.from(f.files)),f.value="")},c=p=>{p.preventDefault(),i.value=!0},u=()=>{i.value=!1},m=p=>{var f;p.preventDefault(),i.value=!1,(f=p.dataTransfer)!=null&&f.files&&p.dataTransfer.files.length>0&&n("filesSelected",Array.from(p.dataTransfer.files))};return(p,f)=>p.open?(e.openBlock(),e.createElementBlock("section",x8,[e.createElementVNode("label",{class:e.normalizeClass(["media-upload-sheet__dropzone",{"is-drag-over":i.value}]),onDragover:c,onDragleave:u,onDrop:m},[f[1]||(f[1]=e.createStaticVNode('<div class="media-upload-sheet__dropzone-icon" data-v-df614629><svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" data-v-df614629><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" data-v-df614629></path><polyline points="17 8 12 3 7 8" data-v-df614629></polyline><line x1="12" y1="3" x2="12" y2="15" data-v-df614629></line></svg></div>',1)),e.createElementVNode("span",N8,e.toDisplayString(p.dropzoneLabel),1),p.dropzoneHelperText?(e.openBlock(),e.createElementBlock("span",V8,e.toDisplayString(p.dropzoneHelperText),1)):e.createCommentVNode("",!0),e.createElementVNode("span",T8,e.toDisplayString(p.fileInputLabel),1),e.createElementVNode("input",{type:"file",accept:p.accept,multiple:"",class:"media-upload-sheet__file-input","data-testid":"input-media-upload-sheet","aria-label":p.fileInputLabel,onChange:d},null,40,B8)],34),p.queue.length>0?(e.openBlock(),e.createElementBlock("ul",{key:0,class:"media-upload-sheet__queue","aria-live":"polite","aria-label":s.value,"data-testid":"list-media-upload-sheet-queue"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p.queue,h=>(e.openBlock(),e.createElementBlock("li",{key:h.id,class:"media-upload-sheet__queue-item"},[e.createElementVNode("div",I8,[h.previewUrl?(e.openBlock(),e.createElementBlock("div",$8,[e.createElementVNode("img",{src:h.previewUrl,alt:`Preview of ${h.file.name}`,"data-testid":`img-media-upload-sheet-preview-${h.id}`},null,8,F8)])):e.createCommentVNode("",!0),e.createElementVNode("div",D8,[e.createElementVNode("div",A8,[e.createElementVNode("strong",null,e.toDisplayString(h.file.name),1),e.createElementVNode("span",R8,e.toDisplayString(h.status),1)]),e.createElementVNode("div",{class:"media-upload-sheet__progress-bar",role:"progressbar","aria-valuemin":"0","aria-valuemax":"100","aria-valuenow":l(h),"aria-label":r(h),"data-testid":`progress-media-upload-sheet-${h.id}`},[e.createElementVNode("div",{class:"media-upload-sheet__progress-fill",style:e.normalizeStyle({width:`${l(h)}%`})},null,4)],8,L8)])])]))),128))],8,M8)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"button",class:"media-upload-sheet__close-btn","aria-label":p.closeButtonAriaLabel,"data-testid":"btn-close-upload-sheet",onClick:f[0]||(f[0]=h=>n("close"))},e.toDisplayString(p.closeButtonLabel),9,P8)])):e.createCommentVNode("",!0)}}),Tf=Ae(U8,[["__scopeId","data-v-df614629"]]),O8=["aria-label","aria-pressed","data-testid"],z8=["src","alt"],j8={key:1,class:"media-thumbnail-cell__video"},W8={class:"media-thumbnail-cell__video-name"},H8={key:2,class:"media-thumbnail-cell__selected-badge"},Z8={key:3,class:"media-thumbnail-cell__status-badge"},G8=["aria-label"],X8=e.defineComponent({__name:"MediaThumbnailCell",props:{media:{},selected:{type:Boolean,default:!1},status:{},testId:{default:"media-library-thumbnail"}},emits:["toggle","preview"],setup(o,{emit:a}){const t=o,n=a,i=e.computed(()=>t.media.thumbnail_url??t.media.preview_url??t.media.original_url),r=e.computed(()=>t.media.mime_type.startsWith("image/")),l=e.computed(()=>{switch(t.status){case"missing":return"Unavailable";case"forbidden":return"Restricted";case"uploading":return"Uploading";case"failed":return"Failed";case"file_lost":return"Needs file";default:return null}}),s=e.computed(()=>{const u=t.media.file_name;return t.selected?`Deselect ${u}`:`Select ${u}`}),d=()=>{n("toggle",t.media)},c=()=>{n("preview",t.media)};return(u,m)=>(e.openBlock(),e.createElementBlock("article",{class:e.normalizeClass(["media-thumbnail-cell",{"is-selected":u.selected,"has-status":l.value!==null}])},[e.createElementVNode("button",{type:"button",class:"media-thumbnail-cell__button","aria-label":s.value,"aria-pressed":u.selected?"true":"false","data-testid":u.testId,onClick:d},[r.value?(e.openBlock(),e.createElementBlock("img",{key:0,class:"media-thumbnail-cell__image",src:i.value,alt:u.media.file_name},null,8,z8)):(e.openBlock(),e.createElementBlock("div",j8,[m[0]||(m[0]=e.createElementVNode("span",{class:"media-thumbnail-cell__video-label"},"Video",-1)),e.createElementVNode("span",W8,e.toDisplayString(u.media.file_name),1)])),u.selected?(e.openBlock(),e.createElementBlock("span",H8," Selected ")):e.createCommentVNode("",!0),l.value!==null?(e.openBlock(),e.createElementBlock("span",Z8,e.toDisplayString(l.value),1)):e.createCommentVNode("",!0)],8,O8),e.createElementVNode("button",{type:"button",class:"media-thumbnail-cell__preview-button","aria-label":`Preview ${u.media.file_name}`,onClick:c}," Preview ",8,G8)],2))}}),Bf=Ae(X8,[["__scopeId","data-v-edd4f0ad"]]),K8={class:"virtual-media-grid"},q8={key:0,class:"virtual-media-grid__state","data-testid":"media-grid-loading"},J8={key:1,class:"virtual-media-grid__state","data-testid":"media-grid-empty"},Y8={key:2,class:"virtual-media-grid__items"},Q8=["disabled"],eD=e.defineComponent({__name:"VirtualMediaGrid",props:{items:{},selectedItems:{},loading:{type:Boolean,default:!1},loadingMore:{type:Boolean,default:!1},hasMore:{type:Boolean,default:!1},emptyMessage:{default:"No media found."},testIdPrefix:{default:"media-grid-item"},loadingMessage:{default:"Loading media..."},loadMoreLabel:{default:"Load more"},loadingMoreLabel:{default:"Loading…"}},emits:["toggle","preview","loadMore"],setup(o,{emit:a}){const t=o,n=a;function i(r){return t.selectedItems.find(l=>l.id===r)}return(r,l)=>(e.openBlock(),e.createElementBlock("div",K8,[r.loading&&r.items.length===0?(e.openBlock(),e.createElementBlock("div",q8,e.toDisplayString(r.loadingMessage),1)):r.items.length===0?(e.openBlock(),e.createElementBlock("div",J8,e.toDisplayString(r.emptyMessage),1)):(e.openBlock(),e.createElementBlock("div",Y8,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.items,s=>{var d,c;return e.openBlock(),e.createBlock(Bf,{key:s.uuid,media:s,selected:((d=i(s.uuid))==null?void 0:d.status)==="ready",status:(c=i(s.uuid))==null?void 0:c.status,"test-id":`${r.testIdPrefix}-${s.uuid}`,onToggle:l[0]||(l[0]=u=>n("toggle",u)),onPreview:l[1]||(l[1]=u=>n("preview",u))},null,8,["media","selected","status","test-id"])}),128))])),r.hasMore?(e.openBlock(),e.createElementBlock("button",{key:3,type:"button",class:"virtual-media-grid__load-more",disabled:r.loadingMore,"data-testid":"btn-media-grid-load-more",onClick:l[2]||(l[2]=s=>n("loadMore"))},e.toDisplayString(r.loadingMore?r.loadingMoreLabel:r.loadMoreLabel),9,Q8)):e.createCommentVNode("",!0)]))}}),Mf=Ae(eD,[["__scopeId","data-v-34667f65"]]);function ul(o){if(o===0)return"0 Bytes";const a=1024,t=["Bytes","KB","MB","GB"],n=Math.floor(Math.log(o)/Math.log(a));return parseFloat((o/Math.pow(a,n)).toFixed(2))+" "+t[n]}function If(o){var t;const a=o.split(".");return a.length>1?`.${(t=a.pop())==null?void 0:t.toLowerCase()}`:""}function Hd(o){return o.type.startsWith("image/")}async function $f(o){return Hd(o)?new Promise(a=>{const t=new Image,n=URL.createObjectURL(o);t.onload=()=>{URL.revokeObjectURL(n),a({width:t.naturalWidth,height:t.naturalHeight})},t.onerror=()=>{URL.revokeObjectURL(n),a(null)},t.src=n}):null}async function Ff(o,a){const t=[];if(a.maxFileSize&&o.size>a.maxFileSize&&t.push({field:"size",message:`File exceeds maximum size of ${ul(a.maxFileSize)}`,code:"MAX_FILE_SIZE"}),a.minFileSize&&o.size<a.minFileSize&&t.push({field:"size",message:`File is smaller than minimum size of ${ul(a.minFileSize)}`,code:"MIN_FILE_SIZE"}),a.acceptedMimeTypes&&a.acceptedMimeTypes.length>0&&(a.acceptedMimeTypes.some(i=>i.endsWith("/*")?o.type.startsWith(i.slice(0,-1)):o.type===i)||t.push({field:"type",message:`File type "${o.type}" is not allowed`,code:"INVALID_MIME_TYPE"})),a.acceptedExtensions&&a.acceptedExtensions.length>0){const n=If(o.name);a.acceptedExtensions.some(r=>r.toLowerCase()===n.toLowerCase())||t.push({field:"extension",message:`File extension "${n}" is not allowed`,code:"INVALID_EXTENSION"})}if(Hd(o)&&(a.maxDimensions||a.minDimensions)){const n=await $f(o);n&&(a.maxDimensions&&(n.width>a.maxDimensions.width&&t.push({field:"dimensions",message:`Image width (${n.width}px) exceeds maximum (${a.maxDimensions.width}px)`,code:"MAX_WIDTH"}),n.height>a.maxDimensions.height&&t.push({field:"dimensions",message:`Image height (${n.height}px) exceeds maximum (${a.maxDimensions.height}px)`,code:"MAX_HEIGHT"})),a.minDimensions&&(n.width<a.minDimensions.width&&t.push({field:"dimensions",message:`Image width (${n.width}px) is smaller than minimum (${a.minDimensions.width}px)`,code:"MIN_WIDTH"}),n.height<a.minDimensions.height&&t.push({field:"dimensions",message:`Image height (${n.height}px) is smaller than minimum (${a.minDimensions.height}px)`,code:"MIN_HEIGHT"})))}if(a.customValidator){const n=await a.customValidator(o);t.push(...n)}return{valid:t.length===0,errors:t}}function Zd(o={}){const a=e.ref(o.rules||{});function t(d){a.value=d}async function n(d){return Ff(d,a.value)}async function i(d){const c=new Map;return await Promise.all(d.map(async u=>{const m=await n(u);c.set(u,m)})),c}function r(d,c){return a.value.maxItems?c+d<=a.value.maxItems:!0}const l=e.computed(()=>{const d=[];return a.value.acceptedMimeTypes&&d.push(...a.value.acceptedMimeTypes),a.value.acceptedExtensions&&d.push(...a.value.acceptedExtensions),d.join(",")});function s(d){return!a.value.acceptedMimeTypes||a.value.acceptedMimeTypes.length===0?!0:a.value.acceptedMimeTypes.some(c=>c.endsWith("/*")?d.startsWith(c.slice(0,-1)):d===c)}return{rules:a,setRules:t,validateFile:n,validateFiles:i,canAddFiles:r,acceptString:l,isMimeTypeAllowed:s}}function tD(){return`upload-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function aD(o){if(o.type.startsWith("image/"))return URL.createObjectURL(o)}function Gd(o){const{adapter:a,maxConcurrent:t=3,rules:n,collection:i,onUploadStart:r,onUploadProgress:l,onUploadComplete:s,onUploadError:d,onQueueComplete:c,postUpload:u}=o,m=e.ref(new Map),p=e.ref(new Set),f=n?{rules:n}:{},{validateFile:h}=Zd(f);async function v(){if(p.value.size>=t)return;const M=Array.from(m.value.entries()).find(([j,L])=>L.status==="pending"&&!p.value.has(j));if(!M){Array.from(m.value.values()).every(L=>L.status==="completed"||L.status==="error")&&m.value.size>0&&(c==null||c());return}const[E,D]=M;await y(E,D)}async function y(M,E){p.value.add(M),E.status="uploading",E.abortController=new AbortController,m.value.set(M,{...E}),r==null||r(E);try{const D={onProgress:L=>{E.progress=L,m.value.set(M,{...E}),l==null||l(E)},signal:E.abortController.signal};i&&(D.collection=i);const j=await a.upload(E.file,D);u&&(E.status="attaching",m.value.set(M,{...E}),l==null||l(E),await u(E,j.media,a)),E.status="completed",E.progress=100,E.media=j.media,m.value.set(M,{...E}),s==null||s(E,j.media)}catch(D){D.name==="AbortError"?m.value.delete(M):(E.status="error",E.error=D.message,m.value.set(M,{...E}),d==null||d(E,D))}finally{p.value.delete(M),delete E.abortController,v()}}async function w(M){var j;const E=Array.from(M),D=[];for(const L of E){const z=await h(L),C=tD(),A=aD(L),O={id:C,file:L,progress:0,status:z.valid?"pending":"error"};!z.valid&&((j=z.errors[0])!=null&&j.message)&&(O.error=z.errors[0].message),A&&(O.previewUrl=A),m.value.set(C,O);const K={media:null,clientId:C,name:L.name,order:0,upload:O,errors:z.errors};D.push(K)}for(let L=0;L<t;L++)v();return D}function _(M){const E=m.value.get(M);E&&(E.abortController&&E.abortController.abort(),E.previewUrl&&URL.revokeObjectURL(E.previewUrl),m.value.delete(M),p.value.delete(M),v())}async function b(M){const E=m.value.get(M);!E||E.status!=="error"||(E.status="pending",E.progress=0,delete E.error,m.value.set(M,{...E}),v())}function g(){for(const[M,E]of m.value.entries())(E.status==="completed"||E.status==="error")&&(E.previewUrl&&URL.revokeObjectURL(E.previewUrl),m.value.delete(M))}function I(){for(const M of m.value.values())M.abortController&&M.abortController.abort(),M.previewUrl&&URL.revokeObjectURL(M.previewUrl);m.value.clear(),p.value.clear()}function T(M){return m.value.get(M)}const $=e.computed(()=>p.value.size>0),N=e.computed(()=>p.value.size),B=e.computed(()=>Array.from(m.value.values()).filter(M=>M.status==="pending").length),P=e.computed(()=>m.value.size===0?!0:Array.from(m.value.values()).every(M=>M.status==="completed"||M.status==="error")),x=e.computed(()=>Array.from(m.value.values()));return{uploads:m,isUploading:$,activeCount:N,pendingCount:B,isComplete:P,addFiles:w,cancelUpload:_,retryUpload:b,clearCompleted:g,clearAll:I,getUpload:T,uploadsArray:x}}const nD=["missing_alt","has_alt","missing_caption","has_caption","has_tags","decorative"];function Po(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function oD(o){return typeof o=="string"&&nD.includes(o)}function tr(o){return typeof o=="string"?o:null}function Ti(o){return typeof o=="number"?o:null}function iD(o){return typeof o=="boolean"?o:null}function Df(o){return Po(o)&&typeof o.uuid=="string"&&typeof o.file_name=="string"&&typeof o.mime_type=="string"&&(typeof o.original_url=="string"||o.original_url===null)&&typeof o.size=="number"&&typeof o.disk=="string"&&typeof o.created_at=="string"&&typeof o.updated_at=="string"}function rD(o){return!Po(o)||typeof o.id!="string"||typeof o.status!="string"?null:o.status==="ready"?Df(o.media)?{id:o.id,status:"ready",media:o.media}:null:o.status==="missing"||o.status==="forbidden"?{id:o.id,status:o.status}:null}function lD(o){return Po(o)?{next_cursor:tr(o.next_cursor),previous_cursor:tr(o.previous_cursor),has_more:iD(o.has_more)??!1,per_page:Ti(o.per_page),count:Ti(o.count),total:Ti(o.total),current_page:Ti(o.current_page),last_page:Ti(o.last_page)}:null}function Hu(o){const a=Po(o)?o:{},t=Array.isArray(a.data)?a.data.filter(Df):[],n=Po(a.meta)?a.meta:{},i=lD(n.pagination),r=(i==null?void 0:i.next_cursor)??tr(n.next_cursor)??tr(n.cursor),l=(i==null?void 0:i.has_more)??n.has_more===!0,s=Array.isArray(a.hydrated)?a.hydrated.map(rD).filter(c=>c!==null):[],d={cursor:r,has_more:l};return i!==null&&(d.pagination=i),{data:t,meta:d,hydrated:s}}function Zu(o,a,t,n,i,r){const l={view:o.scope==="album"?{scope:"album",album_id:o.albumId}:{scope:o.scope},per_page:t,sort:a.sort??"newest"};return a.query&&a.query.trim()!==""&&(l.query=a.query.trim()),a.kinds&&a.kinds.length>0&&(l.kinds=a.kinds),a.created_after&&a.created_after.trim()!==""&&(l.created_after=a.created_after.trim()),a.created_before&&a.created_before.trim()!==""&&(l.created_before=a.created_before.trim()),(a.usage_status==="used"||a.usage_status==="not_used")&&(l.usage_status=a.usage_status),oD(a.metadata_status)&&(l.metadata_status=a.metadata_status),(a.unfiled_only===!0||o.scope==="unfiled")&&(l.unfiled_only=1),a.selected_uuids&&a.selected_uuids.length>0&&(l.selected_uuids=[...a.selected_uuids]),r!=null?(l.page=r,l.include_total=1):n!==null&&(l.cursor=n),i&&i.length>0&&(l.hydrate_ids=i),l}function Gu(o){const a=new Set,t=[];for(const n of o)a.has(n.uuid)||(a.add(n.uuid),t.push(n));return t}function sD(o){var t;if(!(o instanceof Error))return null;const a=(t=o.response)==null?void 0:t.status;return typeof a=="number"?a:null}function dD(o){var a;return o instanceof Error?((a=o.response)==null?void 0:a.data)??null:null}function cD(o){if(!Po(o))return[];const a=[];for(const t of Object.values(o)){if(typeof t=="string"&&t.trim()!==""){a.push(t.trim());continue}if(Array.isArray(t))for(const n of t){if(typeof n!="string")continue;const i=n.trim();i!==""&&a.push(i)}}return Array.from(new Set(a))}function uD(o){var r;const a=dD(o),t=Po(a)?a:null,n=((r=tr(t==null?void 0:t.message))==null?void 0:r.trim())??null,i=cD(t==null?void 0:t.errors);return n!==null&&i.length>0?n==="Validation failed"?i.join(" "):i.every(s=>n.includes(s))?n:`${n} ${i.join(" ")}`:n!==null?n:i.length>0?i.join(" "):o instanceof Error?o.message:"Failed to load media."}function Xu(o,a){const t=uD(a),n=sD(a);return{code:n===403?"permission_denied":o,message:t,retriable:n!==403,cause:a}}function Xd(o){const a=()=>{const T=o.perPage!==void 0?e.toValue(o.perPage):40;return T>0?T:40},t=()=>{const T=o.page!==void 0?e.toValue(o.page):null;return T==null?null:T>0?T:1},n=e.ref([]),i=e.ref([]),r=e.ref(null),l=e.ref(!1),s=e.ref(!1),d=e.ref(!1),c=e.ref(!1),u=e.ref(null),m=e.ref(null),p=e.ref(null),f=e.ref(null);let h=null,v=0;const y=async(T,$)=>{v+=1;const N=v;h==null||h.abort();const B=new AbortController;h=B,T?d.value=!0:s.value=!0,u.value=null,c.value=!1;const P=$??t(),x=P!==null;try{const M=await o.httpClient.get("/v1/media/library",{params:Zu(o.view.value,o.filters.value,a(),x?null:T?r.value:null,void 0,P),signal:B.signal});if(N!==v)return;const E=Hu(M);n.value=T&&!x?Gu([...n.value,...E.data]):E.data,i.value=E.hydrated,r.value=E.meta.cursor,l.value=E.meta.has_more;const D=E.meta.pagination;m.value=(D==null?void 0:D.total)??null,p.value=(D==null?void 0:D.current_page)??(x&&P!==null?P:null);const j=(D==null?void 0:D.per_page)??a();f.value=(D==null?void 0:D.last_page)??(m.value!==null&&j>0?Math.max(1,Math.ceil(m.value/j)):null)}catch(M){if(B.signal.aborted||N!==v)return;const E=Xu(T?"load_more_failed":"query_failed",M);u.value=E,c.value=E.code==="permission_denied",T||(n.value=[],r.value=null,l.value=!1)}finally{N===v&&(s.value=!1,d.value=!1)}},w=async T=>{if(T.length===0)return i.value=[],[];try{const $=await o.httpClient.get("/v1/media/library",{params:Zu(o.view.value,o.filters.value,1,null,T)}),N=Hu($);return i.value=N.hydrated,N.hydrated}catch($){return u.value=Xu("hydration_failed",$),[]}},_=T=>{n.value=Gu([T,...n.value])},b=async()=>{!l.value||d.value||t()===null&&await y(!0)};return{items:n,hydrated:i,cursor:r,hasMore:l,loading:s,loadingMore:d,permissionDenied:c,error:u,total:m,currentPage:p,totalPages:f,loadInitial:async()=>{r.value=null,await y(!1)},loadMore:b,loadAll:async T=>{const $=(T==null?void 0:T.maxItems)??5e3;if(!(s.value||d.value))for(;l.value&&n.value.length<$;){const N=n.value.length;if(await b(),u.value!==null||n.value.length===N)return}},goToPage:async T=>{!Number.isFinite(T)||T<1||s.value||d.value||await y(!1,T)},refresh:async()=>{r.value=null,await y(!1)},hydrateSelection:w,prepend:_}}const mD="mediables.media-library.";function pD(o){return!o||o.key.trim()===""?null:`${mD}${o.key}`}function ys(){return typeof window>"u"||typeof window.sessionStorage>"u"?null:window.sessionStorage}function fD(o,a){const t=Date.parse(o);return Number.isFinite(t)?Date.now()-t>a*60*1e3:!0}function Af(o){const a=pD(o),t=(o==null?void 0:o.ttlMinutes)??30,n=`${(o==null?void 0:o.key)??"media-library"}:${Date.now()}`;return{restore:()=>{if(a===null)return null;const s=ys();if(s===null)return null;const d=s.getItem(a);if(d===null)return null;let c;try{c=JSON.parse(d)}catch{return s.removeItem(a),null}if(typeof c!="object"||c===null||Array.isArray(c))return s.removeItem(a),null;const u=c;if(u.version!==1||typeof u.savedAt!="string"||fD(u.savedAt,t))return s.removeItem(a),null;const m={selectedIds:Array.isArray(u.selectedIds)?u.selectedIds.filter(p=>typeof p=="string"&&p.trim()!==""):[]};return((o==null?void 0:o.restoreView)??!0)&&u.view&&(m.view=u.view),u.filters&&(m.filters=u.filters),m},save:s=>{if(a===null)return;const d=ys();if(d===null)return;const c={version:1,savedAt:new Date().toISOString(),selectedIds:[...s.selectedIds]};((o==null?void 0:o.restoreView)??!0)&&s.view&&(c.view=s.view),s.filters&&(c.filters=s.filters),d.setItem(a,JSON.stringify(c))},clear:()=>{if(a===null)return;const s=ys();s==null||s.removeItem(a)},sessionId:n}}function Rf(o){const a=e.ref(o);return{state:a,transition:n=>{a.value=n}}}function Lf(o){return{emitMetric:(t,n)=>{const i={name:t,timestamp:new Date().toISOString()};n!==void 0&&(i.payload=n),o==null||o(i)}}}function ti(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function hD(o){const a=ti(o)?o:{};return(Array.isArray(a.data)?a.data:ti(a.data)&&Array.isArray(a.data.data)?a.data.data:Array.isArray(o)?o:[]).map(n=>{if(!ti(n)||typeof n.id!="string"||typeof n.name!="string")return null;const i={id:n.id,name:n.name};return typeof n.description=="string"&&n.description.trim()!==""&&(i.description=n.description),typeof n.media_count=="number"&&(i.mediaCount=n.media_count),i}).filter(n=>n!==null)}function vD(o){const a=ti(o)?o:{},t=ti(a.data)?a.data:ti(o)?o:null;if(t===null||typeof t.id!="string"||typeof t.name!="string")return null;const n={id:t.id,name:t.name};return typeof t.description=="string"&&t.description.trim()!==""&&(n.description=t.description),n}function gD(o){return o==="ready"||o==="uploading"||o==="failed"}function ko(o,a="ready"){return{id:o.uuid,media:o,status:a,countsTowardMax:gD(a)}}function bD(o,a){return o.scope==="library"?!0:o.scope!=="album"?!1:a.type==="album"&&a.albumId===o.albumId}function yD(o,a){return o.scope==="library"?a.type==="library"||a.type==="album":o.scope!=="album"?!1:a.type==="album"&&a.albumId===o.albumId}function ws(o){return{code:"configuration_error",message:o,retriable:!1}}const Pf="/v1/albums";function wD(o){var a;return((a=o.deps.albumEndpoints)==null?void 0:a.list)??Pf}function kD(o){var a,t;return((a=o.deps.albumEndpoints)==null?void 0:a.create)??((t=o.deps.albumEndpoints)==null?void 0:t.list)??Pf}function _D(o){return typeof o!="string"||o.length===0?"document":o.startsWith("image/")?"image":o.startsWith("video/")?"video":o.startsWith("audio/")?"audio":"document"}function ED(o,a){return a.length===0||o===null?!0:a.includes(_D(o.mime_type))}function Ku(o){return{...o??{},...(o==null?void 0:o.kinds)!==void 0?{kinds:[...o.kinds]}:{},...(o==null?void 0:o.selected_uuids)!==void 0?{selected_uuids:[...o.selected_uuids]}:{}}}function Uf(o){var Z,k;const a=o.selectionMode??"multiple",t=o.maxSelection,n=o.uploadBehavior??"adapter",i=e.ref(o.initialView??{scope:"library"}),r=((Z=o.initialFilters)==null?void 0:Z.kinds)??(o.allowedMediaKinds&&o.allowedMediaKinds.length>0?[...o.allowedMediaKinds]:void 0),l=e.ref({...Ku(o.initialFilters),sort:((k=o.initialFilters)==null?void 0:k.sort)??"newest",...r?{kinds:r}:{}}),s=o.allowedMediaKinds?[...o.allowedMediaKinds]:[],d=e.ref([]),c=e.ref([]),u=e.ref(null),m=e.ref(null),p=Af(o.sessionPolicy),{emitMetric:f}=Lf(o.telemetry),h=Rf("idle"),v=Xd({httpClient:o.deps.httpClient,view:i,filters:l}),y=e.computed(()=>c.value.map(F=>F.id)),w=e.computed(()=>{const F=u.value;return F===null?null:v.items.value[F]??null}),_=e.computed(()=>o.uploadTarget??{type:"library"}),b=Gd({adapter:o.deps.uploadAdapter??{name:"missing-upload-adapter",upload:async()=>{throw new Error("Upload adapter is not configured.")},attach:async()=>{},attachMany:async()=>{},detach:async()=>{},reorder:async()=>{},fetchModelMedia:async()=>[],getUrl:F=>F.original_url,getThumbnailUrl:F=>F.thumbnail_url??F.preview_url??F.original_url},postUpload:async(F,W,J)=>{const ce=_.value;ce.type!=="album"||!ce.albumId||await J.attach(W.uuid,{modelType:"album",modelId:ce.albumId})},onUploadComplete:(F,W)=>{const J=_.value;bD(i.value,J)&&v.prepend(W),o.autoSelectUploaded&&yD(i.value,J)&&P(W),f("upload-complete",{mediaId:W.uuid,targetType:J.type,targetAlbumId:J.albumId})},onUploadError:(F,W)=>{m.value={code:"upload_failed",message:W.message,retriable:!0,cause:W}}}),g=e.computed(()=>b.isUploading.value),I=()=>{p.save({selectedIds:[...y.value],view:i.value,filters:l.value})},T=async F=>{const W=await v.hydrateSelection(F);c.value=W.map(J=>J.status==="ready"&&J.media?ko(J.media):{id:J.id,media:null,status:J.status,countsTowardMax:!1})},$=e.computed(()=>c.value.filter(F=>F.countsTowardMax).length),N=()=>a==="single"||t===void 0?!0:$.value<t,B=F=>{if(c.value.findIndex(J=>J.id===F.uuid)>=0){a==="multiple"?c.value=c.value.filter(J=>J.id!==F.uuid):c.value=[ko(F)],I();return}if(!N()){m.value={code:"selection_invalid",message:t!==void 0?`You can only select up to ${t} items.`:"You cannot select more items.",retriable:!0};return}a==="single"?c.value=[ko(F)]:c.value=[...c.value,ko(F)],m.value=null,I()},P=F=>{const W=c.value.findIndex(J=>J.id===F.uuid);if(W>=0){c.value=c.value.map((J,ce)=>ce===W?ko(F):J),m.value=null,I();return}if(!N()){m.value={code:"selection_invalid",message:t!==void 0?`You can only select up to ${t} items.`:"You cannot select more items.",retriable:!0};return}a==="single"?c.value=[ko(F)]:c.value=[...c.value,ko(F)],m.value=null,I()},x=async()=>{var W;h.transition("restoring");const F=p.restore();if(F===null){h.transition("ready");return}F.view&&(i.value=F.view),F.filters&&(l.value={...Ku(F.filters),sort:F.filters.sort??"newest"}),await v.loadInitial(),(((W=o.sessionPolicy)==null?void 0:W.restoreSelection)??!0)&&await T(F.selectedIds),h.transition("ready")};e.watch(()=>v.error.value,F=>{F!==null&&(m.value=F,h.transition("error"))});const M=async()=>{m.value=null,h.transition("idle"),await x(),v.items.value.length===0&&!v.loading.value&&!v.permissionDenied.value&&await v.loadInitial();const F=o.defaultSelectedIds??[];c.value.length===0&&F.length>0&&await T(F),h.transition("ready")},E=async(F,W="user")=>{const J=i.value;i.value=F,W==="user"&&o.preserveSelectionOnViewChange===!1&&(c.value=[]),f("view-change",{from:J.scope,to:F.scope,reason:W}),await v.loadInitial(),I()},D=async()=>{const F=await o.deps.httpClient.get(wD(o));d.value=hD(F)},j=async(F,W)=>{try{const J={name:F,visibility:"private"};W&&W.trim()!==""&&(J.parent_id=W);const ce=await o.deps.httpClient.post(kD(o),J),Ue=vD(ce);return Ue===null?ws("Album creation response was invalid."):(d.value=[Ue,...d.value.filter(be=>be.id!==Ue.id)],await E({scope:"album",albumId:Ue.id,albumName:Ue.name},"inline-album-created"),Ue)}catch(J){const ce={code:"album_create_failed",message:J instanceof Error?J.message:"Album creation failed.",retriable:!0,cause:J};return m.value=ce,ce}},L=async F=>{if(!o.enableUpload){m.value=ws("Uploads are not enabled for this picker.");return}if(n!=="delegate"){if(!o.deps.uploadAdapter){m.value=ws("Uploads require a configured upload adapter.");return}await b.addFiles(F)}},z=()=>{var J;if(s.length>0&&c.value.find(Ue=>Ue.media!==null&&!ED(Ue.media,s))){const be={code:"selection_invalid",message:`Selected media is not allowed here. Choose one of: ${s.join(", ")}.`,retriable:!0};return m.value=be,be}const F=((J=o.validateSelection)==null?void 0:J.call(o,c.value))??null;if(F!==null){const ce={code:"selection_invalid",message:F,retriable:!0};return m.value=ce,ce}if(c.value.filter(ce=>ce.status==="ready"&&ce.media!==null).length===0){const ce={code:"selection_invalid",message:"Select at least one available media item.",retriable:!0};return m.value=ce,ce}return{orderedIds:y.value,items:[...c.value],view:i.value,filters:l.value,dirty:!0,sessionId:p.sessionId}},C=F=>{const W=v.items.value.findIndex(J=>J.uuid===F.uuid);u.value=W>=0?W:null},A=()=>{u.value=null},O=()=>{u.value===null||u.value<=0||(u.value-=1)},K=()=>{u.value===null||u.value>=v.items.value.length-1||(u.value+=1)},se=F=>{c.value=c.value.filter(W=>W.id!==F),I()},xe=async()=>{await v.refresh()},ue=async F=>{l.value={...l.value,...F&&F.trim()!==""?{query:F.trim()}:{}},(!F||F.trim()==="")&&delete l.value.query,await v.loadInitial(),I()},le=async()=>{await E({scope:"library"},"permission-unavailable")};return{view:i,filters:l,albums:d,selectedItems:c,orderedIds:y,queryItems:v.items,cursor:v.cursor,hasMore:v.hasMore,loading:v.loading,loadingMore:v.loadingMore,permissionDenied:v.permissionDenied,error:m,uploadQueue:b.uploadsArray,isUploading:g,previewIndex:u,previewItem:w,initialize:M,refresh:xe,loadMore:v.loadMore,setQuery:ue,setView:E,toggleSelection:B,removeSelected:se,confirmSelection:z,openPreview:C,closePreview:A,showPreviousPreview:O,showNextPreview:K,loadAlbums:D,createAlbum:j,addUploadFiles:L,goToLibrary:le,sessionId:p.sessionId}}const SD=["data-testid"],CD={class:"mlp-location-bar"},xD={class:"mlp-location-bar__left"},ND={class:"mlp-location-bar__label"},VD={class:"mlp-tabs","data-testid":"media-picker-tabs"},TD={key:0,class:"mlp-search-row"},BD=["placeholder"],MD={key:2,class:"mlp-overlay-panel"},ID={key:0,class:"mlp-error","data-testid":"media-picker-error"},$D={key:5,class:"mlp-bottom-bar"},FD={key:0,class:"mlp-bottom-bar__selection"},DD={class:"mlp-bottom-bar__count"},AD={class:"mlp-bottom-bar__thumbs"},RD=["src","alt"],LD={key:1,class:"mlp-bottom-bar__thumb-placeholder"},PD=["aria-label","onClick"],UD={class:"mlp-bottom-bar__actions"},OD=e.defineComponent({__name:"MediaLibraryPicker",props:{deps:{},mode:{default:"picker-multi"},capabilities:{default:()=>({})},itemFilter:{},modelValue:{default:()=>[]},defaultSelectedIds:{default:()=>[]},selectionMode:{default:"multiple"},maxSelection:{},preserveSelectionOnViewChange:{type:Boolean,default:!0},initialView:{default:()=>({scope:"library"})},initialFilters:{default:()=>({sort:"newest"})},enableUpload:{type:Boolean,default:!1},uploadBehavior:{default:"adapter"},enablePreview:{type:Boolean,default:!0},enableAlbumCreation:{type:Boolean,default:!1},allowedMediaKinds:{},accept:{},validateSelection:{},uploadTarget:{},autoSelectUploaded:{type:Boolean,default:!1},createAlbumDefaultVisibility:{default:"private"},sessionPolicy:{},labels:{default:()=>({})},showFooter:{type:Boolean,default:!0},testIdPrefix:{default:"media-picker"},telemetry:{}},emits:["update:modelValue","confirm","cancel","selection-change","select","view-change","error","metric","request-upload-files"],setup(o,{expose:a,emit:t}){const n=o,i=t,r=e.computed(()=>{var k,F,W,J,ce,Ue,be,_e,ye,Ne,Se,Re,Oe,it,rt,Pt,bt,Ct,mt,pt,Nt,Ce,Ve,Le,nt,Ge,Je,_t,ht,Wt,Pe,Ht,Zt,It,Ut,Gt,sa,ae,ge;return{title:((k=n.labels)==null?void 0:k.title)??"Media library",searchPlaceholder:((F=n.labels)==null?void 0:F.searchPlaceholder)??"Search your media",viewLibrary:((W=n.labels)==null?void 0:W.viewLibrary)??"Library",browseAlbums:((J=n.labels)==null?void 0:J.browseAlbums)??"Albums",createAlbum:((ce=n.labels)==null?void 0:ce.createAlbum)??"Create album",createAlbumNameLabel:((Ue=n.labels)==null?void 0:Ue.createAlbumNameLabel)??"Album name",emptyLibrary:((be=n.labels)==null?void 0:be.emptyLibrary)??"No media found in your library.",emptyAlbum:((_e=n.labels)==null?void 0:_e.emptyAlbum)??"No media found in this album.",networkError:((ye=n.labels)==null?void 0:ye.networkError)??"Unable to load media right now.",retry:((Ne=n.labels)==null?void 0:Ne.retry)??"Retry",selectedCount:((Se=n.labels)==null?void 0:Se.selectedCount)??(pe=>`${pe} selected`),confirmAction:((Re=n.labels)==null?void 0:Re.confirmAction)??"Attach selected",cancel:((Oe=n.labels)==null?void 0:Oe.cancel)??"Cancel",dismiss:((it=n.labels)==null?void 0:it.dismiss)??"Remove",uploadLabel:((rt=n.labels)==null?void 0:rt.uploadLabel)??"Upload",albumUnavailableTitle:((Pt=n.labels)==null?void 0:Pt.albumUnavailableTitle)??"Album unavailable",albumUnavailableBody:((bt=n.labels)==null?void 0:bt.albumUnavailableBody)??"You no longer have access to this album.",goToLibrary:((Ct=n.labels)==null?void 0:Ct.goToLibrary)??"Go to library",allMediaTab:((mt=n.labels)==null?void 0:mt.allMediaTab)??"All Media",loadingMedia:((pt=n.labels)==null?void 0:pt.loadingMedia)??"Loading media…",loadMore:((Nt=n.labels)==null?void 0:Nt.loadMore)??"Load more",loadingMore:((Ce=n.labels)==null?void 0:Ce.loadingMore)??"Loading…",uploadDropzone:((Ve=n.labels)==null?void 0:Ve.uploadDropzone)??"Drop files here or browse",uploadDropzoneHelper:((Le=n.labels)==null?void 0:Le.uploadDropzoneHelper)??"",uploadDone:((nt=n.labels)==null?void 0:nt.uploadDone)??"Done",uploadDoneAria:((Ge=n.labels)==null?void 0:Ge.uploadDoneAria)??"Close upload panel",uploadFileInputLabel:((Je=n.labels)==null?void 0:Je.uploadFileInputLabel)??"Choose media files",previewClose:((_t=n.labels)==null?void 0:_t.previewClose)??"Close preview",previewPrevious:((ht=n.labels)==null?void 0:ht.previewPrevious)??"Previous media",previewNext:((Wt=n.labels)==null?void 0:Wt.previewNext)??"Next media",previewSelect:((Pe=n.labels)==null?void 0:Pe.previewSelect)??"Select media",previewDeselect:((Ht=n.labels)==null?void 0:Ht.previewDeselect)??"Deselect media",selectAction:((Zt=n.labels)==null?void 0:Zt.selectAction)??"Select",allMedia:((It=n.labels)==null?void 0:It.allMedia)??((Ut=n.labels)==null?void 0:Ut.allMediaTab)??"All media",unfiled:((Gt=n.labels)==null?void 0:Gt.unfiled)??"Unfiled",pageTitle:((sa=n.labels)==null?void 0:sa.pageTitle)??((ae=n.labels)==null?void 0:ae.title)??"Media library",albumLabel:((ge=n.labels)==null?void 0:ge.albumLabel)??"Album"}}),l=e.computed(()=>n.mode),s=e.computed(()=>l.value==="picker-single"?"single":n.selectionMode),d=e.computed(()=>n.showFooter===!0&&l.value!=="picker-single"),c=e.computed(()=>n.enablePreview===!0&&l.value!=="picker-single"),u={deps:n.deps,selectionMode:s.value,initialView:n.initialView,initialFilters:n.initialFilters,...n.maxSelection!==void 0?{maxSelection:n.maxSelection}:{},...n.modelValue.length>0||n.defaultSelectedIds.length>0?{defaultSelectedIds:n.modelValue.length>0?n.modelValue:n.defaultSelectedIds}:{},...n.sessionPolicy?{sessionPolicy:n.sessionPolicy}:{},...n.enableUpload?{enableUpload:!0}:{},uploadBehavior:n.uploadBehavior,...n.uploadTarget?{uploadTarget:n.uploadTarget}:{},...n.autoSelectUploaded?{autoSelectUploaded:!0}:{},...n.validateSelection?{validateSelection:n.validateSelection}:{},...n.allowedMediaKinds&&n.allowedMediaKinds.length>0?{allowedMediaKinds:n.allowedMediaKinds}:{},preserveSelectionOnViewChange:n.preserveSelectionOnViewChange,telemetry:k=>{var F;(F=n.telemetry)==null||F.call(n,k),i("metric",k)}},m=Uf(u),p=e.ref(n.initialFilters.query??""),f=e.ref(n.enableUpload?"upload":"media"),h=e.ref(!1),v=JSON.stringify(n.modelValue.length>0?n.modelValue:n.defaultSelectedIds);let y=null;const w=e.computed(()=>JSON.stringify(m.orderedIds.value)!==v),_=e.computed(()=>m.view.value.scope==="album"?r.value.emptyAlbum:r.value.emptyLibrary),b=e.computed(()=>r.value.selectedCount(m.selectedItems.value.length));function g(k){return typeof k=="boolean"?{allowed:k}:typeof k=="string"?{allowed:!1,reason:k}:k}function I(k){return n.itemFilter?g(n.itemFilter(k)):{allowed:!0}}const T=e.computed(()=>n.itemFilter?m.queryItems.value.filter(k=>I(k).allowed):m.queryItems.value),$=e.computed(()=>m.view.value.scope==="album"?m.view.value.albumName??"Album":r.value.viewLibrary),N=e.computed(()=>m.view.value.scope==="album"),B=()=>{y!==null&&(window.clearTimeout(y),y=null)},P=()=>{i("update:modelValue",[...m.orderedIds.value]),i("selection-change",{orderedIds:[...m.orderedIds.value],items:[...m.selectedItems.value],dirty:w.value})},x=k=>{k!==null&&i("error",k)},M=k=>typeof k.code=="string",E=k=>typeof k=="object"&&k!==null&&"code"in k&&typeof k.code=="string",D=()=>{const k=m.confirmSelection();if(M(k)){x(k);return}i("confirm",{...k,dirty:w.value})},j=k=>{const F=I(k);if(!F.allowed){x({code:"selection_invalid",message:F.reason??"This media item is not available for this picker.",retriable:!0});return}m.toggleSelection(k),l.value==="picker-single"&&i("select",k)},L=(k="user")=>{i("cancel",{dirty:w.value,reason:k,sessionId:m.sessionId})},z=async()=>{f.value="albums",await m.loadAlbums()},C=async()=>{await m.goToLibrary(),f.value="albums",await m.loadAlbums()},A=k=>{m.setView({scope:"album",albumId:k.id,albumName:k.name}),f.value="media"},O=async(k,F)=>{const W=m.view.value,J=await m.createAlbum(k,F);if(E(J)){x(J);return}h.value=!1,f.value="media",i("view-change",{from:W,to:{scope:"album",albumId:J.id,albumName:J.name},reason:"inline-album-created",restoredFromSession:!1})},K=async k=>{if(n.uploadBehavior==="delegate"){i("request-upload-files",{files:[...k],view:m.view.value,filters:m.filters.value,sessionId:m.sessionId});return}await m.addUploadFiles(k)};function se(k){var F;return k?k.thumbnail_url??((F=k.conversion_urls)==null?void 0:F.thumb)??k.preview_url??k.original_url??k.url??null:null}function xe(k){return k!=null&&k.mime_type?k.mime_type.startsWith("image/"):!1}e.watch(()=>p.value,k=>{B(),y=window.setTimeout(()=>{m.setQuery(k)},250)}),e.watch(()=>m.selectedItems.value,()=>{P()},{deep:!0}),e.watch(()=>m.error.value,k=>{x(k)}),e.watch(()=>n.enableUpload,k=>{!k&&f.value==="upload"&&(f.value="media")}),e.onMounted(()=>{m.initialize()}),e.onBeforeUnmount(()=>{B()}),a({refresh:m.refresh});function ue(k){if(k==="albums"){z();return}if(k==="upload"&&!n.enableUpload){f.value="media";return}f.value=k}const le=e.computed(()=>({activeTab:f.value,setActiveTab:ue,enableUpload:n.enableUpload,labels:{uploadLabel:r.value.uploadLabel,allMediaTab:r.value.allMediaTab,browseAlbums:r.value.browseAlbums}})),Z=e.computed(()=>({query:p.value,setQuery:k=>{p.value=k},placeholder:r.value.searchPlaceholder}));return(k,F)=>(e.openBlock(),e.createElementBlock("section",{class:"media-library-picker","data-testid":k.testIdPrefix},[e.createElementVNode("header",CD,[e.createElementVNode("div",xD,[N.value?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"mlp-location-bar__back","aria-label":"Back to library","data-testid":"btn-media-picker-back",onClick:C},[...F[8]||(F[8]=[e.createElementVNode("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e.createElementVNode("polyline",{points:"15 18 9 12 15 6"})],-1)])])):e.createCommentVNode("",!0),e.createElementVNode("span",ND,e.toDisplayString($.value),1)])]),e.renderSlot(k.$slots,"tabs",e.normalizeProps(e.guardReactiveProps(le.value)),()=>[e.createElementVNode("nav",VD,[k.enableUpload?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:e.normalizeClass(["mlp-tabs__tab",{"is-active":f.value==="upload"}]),"data-testid":"tab-media-picker-upload",onClick:F[0]||(F[0]=W=>f.value="upload")},e.toDisplayString(r.value.uploadLabel),3)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"button",class:e.normalizeClass(["mlp-tabs__tab",{"is-active":f.value==="media"}]),"data-testid":"tab-media-picker-all",onClick:F[1]||(F[1]=W=>f.value="media")},e.toDisplayString(r.value.allMediaTab),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass(["mlp-tabs__tab",{"is-active":f.value==="albums"}]),"data-testid":"tab-media-picker-albums",onClick:z},e.toDisplayString(r.value.browseAlbums),3)])],!0),f.value==="media"||f.value==="albums"?(e.openBlock(),e.createElementBlock("div",TD,[e.renderSlot(k.$slots,"search",e.normalizeProps(e.guardReactiveProps(Z.value)),()=>[F[9]||(F[9]=e.createElementVNode("svg",{class:"mlp-search-row__icon",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e.createElementVNode("circle",{cx:"11",cy:"11",r:"8"}),e.createElementVNode("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})],-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":F[2]||(F[2]=W=>p.value=W),class:"mlp-search-row__input",type:"search",placeholder:r.value.searchPlaceholder,"data-testid":"input-media-picker-search"},null,8,BD),[[e.vModelText,p.value]])],!0)])):e.createCommentVNode("",!0),k.enableUpload&&f.value==="upload"?(e.openBlock(),e.createBlock(Tf,{key:1,open:!0,queue:e.unref(m).uploadQueue.value,accept:k.accept,"upload-label":r.value.uploadLabel,"dropzone-label":r.value.uploadDropzone,"dropzone-helper-text":r.value.uploadDropzoneHelper,"file-input-label":r.value.uploadFileInputLabel,"close-button-label":r.value.uploadDone,"close-button-aria-label":r.value.uploadDoneAria,onClose:F[3]||(F[3]=W=>f.value="media"),onFilesSelected:K},null,8,["queue","accept","upload-label","dropzone-label","dropzone-helper-text","file-input-label","close-button-label","close-button-aria-label"])):e.createCommentVNode("",!0),h.value?(e.openBlock(),e.createElementBlock("div",MD,[e.createVNode(jd,{open:h.value,"name-label":r.value.createAlbumNameLabel,albums:e.unref(m).albums.value,onCancel:F[4]||(F[4]=W=>h.value=!1),onCreate:O},null,8,["open","name-label","albums"])])):e.createCommentVNode("",!0),e.unref(m).permissionDenied.value&&e.unref(m).view.value.scope==="album"?(e.openBlock(),e.createBlock(kf,{key:3,title:r.value.albumUnavailableTitle,body:r.value.albumUnavailableBody,"action-label":r.value.goToLibrary,onGoToLibrary:e.unref(m).goToLibrary},null,8,["title","body","action-label","onGoToLibrary"])):e.createCommentVNode("",!0),!e.unref(m).permissionDenied.value||e.unref(m).view.value.scope!=="album"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:4},[e.unref(m).error.value?(e.openBlock(),e.createElementBlock("div",ID,[e.createElementVNode("p",null,e.toDisplayString(e.unref(m).error.value.message||r.value.networkError),1),e.createElementVNode("button",{type:"button",class:"mlp-error__retry",onClick:F[5]||(F[5]=(...W)=>e.unref(m).refresh&&e.unref(m).refresh(...W))},e.toDisplayString(r.value.retry),1)])):e.createCommentVNode("",!0),f.value==="media"?(e.openBlock(),e.createBlock(Mf,{key:1,items:T.value,"selected-items":e.unref(m).selectedItems.value,loading:e.unref(m).loading.value,"loading-more":e.unref(m).loadingMore.value,"has-more":e.unref(m).hasMore.value,"empty-message":_.value,"loading-message":r.value.loadingMedia,"load-more-label":r.value.loadMore,"loading-more-label":r.value.loadingMore,"test-id-prefix":`${k.testIdPrefix}-item`,onToggle:j,onPreview:e.unref(m).openPreview,onLoadMore:e.unref(m).loadMore},null,8,["items","selected-items","loading","loading-more","has-more","empty-message","loading-message","load-more-label","loading-more-label","test-id-prefix","onPreview","onLoadMore"])):f.value==="albums"?(e.openBlock(),e.createBlock(Vf,{key:2,open:!0,"current-view":e.unref(m).view.value,albums:e.unref(m).albums.value,"view-library-label":r.value.viewLibrary,"browse-albums-label":r.value.browseAlbums,"create-album-label":r.value.createAlbum,"enable-album-creation":k.enableAlbumCreation,onSelectLibrary:C,onSelectAlbum:A,onCreateAlbum:F[6]||(F[6]=W=>h.value=!0)},null,8,["current-view","albums","view-library-label","browse-albums-label","create-album-label","enable-album-creation"])):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0),d.value?(e.openBlock(),e.createElementBlock("footer",$D,[e.unref(m).selectedItems.value.length>0?(e.openBlock(),e.createElementBlock("div",FD,[e.createElementVNode("span",DD,e.toDisplayString(b.value),1),e.createElementVNode("div",AD,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(m).selectedItems.value,W=>{var J,ce,Ue;return e.openBlock(),e.createElementBlock("div",{key:W.id,class:"mlp-bottom-bar__thumb-item"},[xe(W.media)&&se(W.media)?(e.openBlock(),e.createElementBlock("img",{key:0,src:se(W.media),alt:((J=W.media)==null?void 0:J.alt_text)??((ce=W.media)==null?void 0:ce.file_name)??"Selected",class:"mlp-bottom-bar__thumb-img"},null,8,RD)):(e.openBlock(),e.createElementBlock("div",LD,[...F[10]||(F[10]=[e.createElementVNode("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[e.createElementVNode("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.createElementVNode("polyline",{points:"14 2 14 8 20 8"})],-1)])])),e.createElementVNode("button",{type:"button",class:"mlp-bottom-bar__thumb-remove","aria-label":`${r.value.dismiss} ${((Ue=W.media)==null?void 0:Ue.file_name)??W.id}`,"data-testid":"btn-media-picker-remove-selected",onClick:be=>e.unref(m).removeSelected(W.id)},[...F[11]||(F[11]=[e.createElementVNode("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"3","stroke-linecap":"round"},[e.createElementVNode("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.createElementVNode("line",{x1:"6",y1:"6",x2:"18",y2:"18"})],-1)])],8,PD)])}),128))])])):e.createCommentVNode("",!0),e.createElementVNode("div",UD,[e.createElementVNode("button",{type:"button",class:"mlp-bottom-bar__cancel","data-testid":"btn-media-picker-cancel",onClick:F[7]||(F[7]=W=>L())},e.toDisplayString(r.value.cancel),1),e.createElementVNode("button",{type:"button",class:"mlp-bottom-bar__confirm","data-testid":"btn-media-picker-confirm",onClick:D},e.toDisplayString(r.value.confirmAction),1)])])):e.createCommentVNode("",!0),c.value?(e.openBlock(),e.createBlock(Wd,{key:6,open:e.unref(m).previewItem.value!==null,media:e.unref(m).previewItem.value,"can-go-previous":e.unref(m).previewIndex.value!==null&&e.unref(m).previewIndex.value>0,"can-go-next":e.unref(m).previewIndex.value!==null&&e.unref(m).previewIndex.value<e.unref(m).queryItems.value.length-1,selected:e.unref(m).previewItem.value!==null&&e.unref(m).orderedIds.value.includes(e.unref(m).previewItem.value.uuid),"close-label":r.value.previewClose,"previous-label":r.value.previewPrevious,"next-label":r.value.previewNext,"select-label":r.value.previewSelect,"deselect-label":r.value.previewDeselect,onClose:e.unref(m).closePreview,onPrevious:e.unref(m).showPreviousPreview,onNext:e.unref(m).showNextPreview,onToggleSelect:e.unref(m).toggleSelection},null,8,["open","media","can-go-previous","can-go-next","selected","close-label","previous-label","next-label","select-label","deselect-label","onClose","onPrevious","onNext","onToggleSelect"])):e.createCommentVNode("",!0)],8,SD))}}),Of=Ae(OD,[["__scopeId","data-v-307fef12"]]),zD={key:0,class:"media-library-picker-modal","data-testid":"media-library-picker-modal"},jD={class:"media-library-picker-modal__panel"},WD=e.defineComponent({__name:"MediaLibraryPickerModal",props:{deps:{},mode:{},capabilities:{},itemFilter:{},modelValue:{},defaultSelectedIds:{},selectionMode:{},maxSelection:{},preserveSelectionOnViewChange:{type:Boolean},initialView:{},initialFilters:{},enableUpload:{type:Boolean},uploadBehavior:{},enablePreview:{type:Boolean},enableAlbumCreation:{type:Boolean},allowedMediaKinds:{},accept:{},validateSelection:{},uploadTarget:{},autoSelectUploaded:{type:Boolean},createAlbumDefaultVisibility:{},sessionPolicy:{},labels:{},showFooter:{type:Boolean},testIdPrefix:{},telemetry:{},isOpen:{type:Boolean,default:!1},closeOnBackdrop:{type:Boolean,default:!0}},emits:["update:modelValue","confirm","cancel","close"],setup(o,{emit:a}){const t=o,n=a,i=()=>{t.closeOnBackdrop&&n("close")};return(r,l)=>r.isOpen?(e.openBlock(),e.createElementBlock("div",zD,[e.createElementVNode("button",{type:"button",class:"media-library-picker-modal__backdrop","aria-label":"Close media picker",onClick:i}),e.createElementVNode("div",jD,[e.createVNode(Of,e.mergeProps(t,{"onUpdate:modelValue":l[0]||(l[0]=s=>n("update:modelValue",s)),onConfirm:l[1]||(l[1]=s=>n("confirm",s)),onCancel:l[2]||(l[2]=s=>n("cancel",s))}),null,16)])])):e.createCommentVNode("",!0)}}),HD=Ae(WD,[["__scopeId","data-v-a92e8703"]]),ZD=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(", ");function GD(o){return o.getAttribute("aria-hidden")==="true"||o.hasAttribute("disabled")?!1:o.tabIndex>=0}function jl(o){return Array.from(o.querySelectorAll(ZD)).filter(GD)}function fa(o){o instanceof HTMLElement&&typeof o.focus=="function"&&o.focus()}function Kd(o,a){if(o.key!=="Tab"||!(a instanceof HTMLElement))return;const t=jl(a);if(t.length===0){o.preventDefault(),fa(a);return}const n=t[0],i=t[t.length-1];if(o.shiftKey&&document.activeElement===n){o.preventDefault(),fa(i);return}!o.shiftKey&&document.activeElement===i&&(o.preventDefault(),fa(n))}function cd(o,a){if(!(a instanceof HTMLElement)||!["ArrowDown","ArrowUp","Home","End"].includes(o.key))return!1;const t=jl(a);if(t.length===0)return!1;o.preventDefault();const n=t.findIndex(d=>d===document.activeElement);if(o.key==="Home")return fa(t[0]),!0;if(o.key==="End")return fa(t[t.length-1]),!0;const i=o.key==="ArrowDown"?-1:0,r=n>=0?n:i,l=o.key==="ArrowDown"?1:-1,s=(r+l+t.length)%t.length;return fa(t[s]),!0}const XD=["aria-labelledby","aria-describedby"],KD={class:"media-album-picker-modal__header"},qD=["id"],JD=["id"],YD={key:0,class:"media-album-picker-modal__create-row"},QD={class:"media-album-picker-modal__create-field",for:"media-album-picker-create-name"},e6={class:"media-album-picker-modal__create-label"},t6=["maxlength","aria-invalid","disabled"],a6={class:"media-album-picker-modal__create-meta"},n6={key:0,id:"media-album-picker-create-error",class:"media-album-picker-modal__create-error","data-testid":"media-album-picker-create-error",role:"alert"},o6={key:1,class:"media-album-picker-modal__create-helper"},i6={class:"media-album-picker-modal__create-actions"},r6=["disabled"],l6=["disabled"],s6={key:0},d6={key:1},c6={key:2,class:"media-album-picker-modal__selection","data-testid":"media-album-picker-selection"},u6={class:"media-album-picker-modal__actions"},m6=["disabled"],p6=e.defineComponent({__name:"MediaAlbumPickerModal",props:{open:{type:Boolean},selectedCount:{},labels:{default:()=>({})},nameMaxLength:{default:120}},emits:["cancel","confirm","error"],setup(o,{emit:a}){const t=o,n=a,i=Ol(),r=e.ref(null),l=e.ref(!1),s=e.ref(""),d=e.ref(""),c=e.ref(!1),u=e.ref(null),m=e.ref(null),p=e.ref(null),f=e.ref(null),h=e.ref(null),v=e.ref(null),y=e.useId(),w=e.useId(),_=e.computed(()=>{var C,A,O,K,se,xe,ue,le,Z,k,F,W;return{title:((C=t.labels)==null?void 0:C.title)??"Add to album",body:((A=t.labels)==null?void 0:A.body)??`Choose an album for ${t.selectedCount} selected item${t.selectedCount===1?"":"s"}.`,confirm:((O=t.labels)==null?void 0:O.confirm)??"Add",cancel:((K=t.labels)==null?void 0:K.cancel)??"Cancel",selectedAlbum:((se=t.labels)==null?void 0:se.selectedAlbum)??(J=>`Selected: ${J}`),createNew:((xe=t.labels)==null?void 0:xe.createNew)??"+ Create new album",createNewPrompt:((ue=t.labels)==null?void 0:ue.createNewPrompt)??"Name this album",createNewSubmit:((le=t.labels)==null?void 0:le.createNewSubmit)??"Create",createNewCancel:((Z=t.labels)==null?void 0:Z.createNewCancel)??"Cancel",createNewEmptyError:((k=t.labels)==null?void 0:k.createNewEmptyError)??"Please enter a name.",createNewTooLongError:((F=t.labels)==null?void 0:F.createNewTooLongError)??`Name must be ${t.nameMaxLength} characters or fewer.`,createNewGenericError:((W=t.labels)==null?void 0:W.createNewGenericError)??"Could not create album. Try again."}}),b=e.computed(()=>s.value.trim()),g=e.computed(()=>b.value===""),I=e.computed(()=>b.value.length>t.nameMaxLength),T=e.computed(()=>!c.value&&!g.value&&!I.value),$=e.computed(()=>b.value.length),N=e.computed(()=>s.value.length>t.nameMaxLength*.6);function B(){s.value="",d.value="",c.value=!1}function P(){r.value=null,l.value=!1,B()}e.watch(()=>t.open,C=>{if(C)v.value=typeof document<"u"&&document.activeElement instanceof HTMLElement?document.activeElement:null,e.nextTick(()=>{fa(p.value??f.value??m.value)});else{P();const A=v.value;v.value=null,e.nextTick(()=>fa(A))}},{immediate:!0});function x(C){l.value||(r.value=C)}function M(){r.value!==null&&n("confirm",r.value.id)}async function E(){var C;l.value=!0,B(),await e.nextTick(),(C=h.value)==null||C.focus()}function D(){l.value=!1,B(),e.nextTick(()=>fa(p.value))}function j(){d.value!==""&&!g.value&&!I.value&&(d.value="")}async function L(){var C,A,O,K;if(!c.value){if(g.value){d.value=_.value.createNewEmptyError,(C=h.value)==null||C.focus();return}if(I.value){d.value=_.value.createNewTooLongError,(A=h.value)==null||A.focus();return}c.value=!0,d.value="";try{const se=await i.createAlbum({name:b.value});if(se==null){d.value=_.value.createNewGenericError,c.value=!1,(O=h.value)==null||O.focus();return}r.value=se,l.value=!1,B(),n("confirm",se.id)}catch(se){const xe=se instanceof Error?se:new Error(String(se));d.value=xe.message!==""?xe.message:_.value.createNewGenericError,c.value=!1,(K=h.value)==null||K.focus(),n("error",xe)}}}function z(C){if(C.key==="Escape"&&l.value){C.preventDefault(),C.stopPropagation(),D();return}if(C.key==="Escape"){C.preventDefault(),C.stopPropagation(),n("cancel");return}C.key==="Tab"&&Kd(C,u.value)}return(C,A)=>{var O;return e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[t.open?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"modalRef",ref:u,class:"media-album-picker-modal","data-testid":"media-album-picker-modal",role:"dialog","aria-modal":"true","aria-labelledby":e.unref(y),"aria-describedby":e.unref(w),tabindex:"-1",onKeydown:z},[e.createElementVNode("div",{ref_key:"panelRef",ref:m,class:"media-album-picker-modal__panel"},[e.createElementVNode("header",KD,[e.createElementVNode("h2",{id:e.unref(y)},e.toDisplayString(_.value.title),9,qD),e.createElementVNode("p",{id:e.unref(w)},e.toDisplayString(_.value.body),9,JD)]),l.value?(e.openBlock(),e.createElementBlock("form",{key:1,class:"media-album-picker-modal__create-form","data-testid":"media-album-picker-create-form",novalidate:"",onSubmit:A[2]||(A[2]=e.withModifiers(K=>void L(),["prevent"]))},[e.createElementVNode("label",QD,[e.createElementVNode("span",e6,e.toDisplayString(_.value.createNewPrompt),1),e.withDirectives(e.createElementVNode("input",{id:"media-album-picker-create-name",ref_key:"createInputRef",ref:h,"onUpdate:modelValue":A[1]||(A[1]=K=>s.value=K),type:"text",class:e.normalizeClass(["media-album-picker-modal__create-input",{"media-album-picker-modal__create-input--error":d.value!==""}]),maxlength:t.nameMaxLength+16,"aria-invalid":d.value!==""?"true":"false","aria-describedby":"media-album-picker-create-error media-album-picker-create-counter",autocomplete:"off","data-testid":"input-media-album-picker-create-name",disabled:c.value,onInput:j},null,42,t6),[[e.vModelText,s.value]]),e.createElementVNode("div",a6,[d.value!==""?(e.openBlock(),e.createElementBlock("span",n6,e.toDisplayString(d.value),1)):(e.openBlock(),e.createElementBlock("span",o6," Press Enter to create. ")),N.value?(e.openBlock(),e.createElementBlock("span",{key:2,id:"media-album-picker-create-counter",class:e.normalizeClass(["media-album-picker-modal__create-counter",{"media-album-picker-modal__create-counter--over":I.value}]),"data-testid":"media-album-picker-create-counter"},e.toDisplayString($.value)+" / "+e.toDisplayString(t.nameMaxLength),3)):e.createCommentVNode("",!0)])]),e.createElementVNode("div",i6,[e.createElementVNode("button",{type:"button",class:"media-album-picker-modal__btn media-album-picker-modal__btn--ghost","data-testid":"btn-media-album-picker-create-cancel",disabled:c.value,onClick:D},e.toDisplayString(_.value.createNewCancel),9,r6),e.createElementVNode("button",{type:"submit",class:"media-album-picker-modal__btn media-album-picker-modal__btn--primary","data-testid":"btn-media-album-picker-create-submit",disabled:!T.value},[c.value?(e.openBlock(),e.createElementBlock("span",s6,"…")):(e.openBlock(),e.createElementBlock("span",d6,e.toDisplayString(_.value.createNewSubmit),1))],8,l6)])],32)):(e.openBlock(),e.createElementBlock("div",YD,[e.createElementVNode("button",{ref_key:"createNewButtonRef",ref:p,type:"button",class:"media-album-picker-modal__create-new","data-testid":"btn-media-album-picker-create-new","aria-label":"Create new album",onClick:A[0]||(A[0]=K=>void E())},e.toDisplayString(_.value.createNew),513)])),e.createVNode(zl,{class:"media-album-picker-modal__tree","model-value":((O=r.value)==null?void 0:O.id)??null,draggable:!1,compact:!0,"data-testid":"media-album-picker-tree",onAlbumSelected:x},null,8,["model-value"]),r.value!==null&&!l.value?(e.openBlock(),e.createElementBlock("p",c6,e.toDisplayString(_.value.selectedAlbum(r.value.name)),1)):e.createCommentVNode("",!0),e.createElementVNode("footer",u6,[e.createElementVNode("button",{ref_key:"cancelButtonRef",ref:f,type:"button",class:"media-album-picker-modal__btn media-album-picker-modal__btn--ghost","data-testid":"btn-media-album-picker-cancel",onClick:A[3]||(A[3]=K=>n("cancel"))},e.toDisplayString(_.value.cancel),513),e.createElementVNode("button",{type:"button",class:"media-album-picker-modal__btn media-album-picker-modal__btn--primary","data-testid":"btn-media-album-picker-confirm",disabled:r.value===null||l.value,onClick:M},e.toDisplayString(_.value.confirm),9,m6)])],512)],40,XD)):e.createCommentVNode("",!0)])}}}),zf=Ae(p6,[["__scopeId","data-v-4bc0ef5f"]]),f6={key:0,class:"media-bulk-action-bar","data-testid":"media-bulk-action-bar","aria-live":"polite"},h6=["aria-label"],v6={class:"media-bulk-action-bar__actions"},g6=["disabled"],b6=e.defineComponent({__name:"MediaBulkActionBar",props:{selectedCount:{},crossPageCount:{default:0},overCap:{type:Boolean,default:!1},totalMatching:{default:null},scope:{},sourceAlbum:{default:null},capabilities:{default:()=>({})},labels:{default:()=>({})}},emits:["bulk-add-to-album","bulk-move-between-albums","bulk-remove-from-current-album","bulk-move-to-trash","bulk-create-post","bulk-create-gallery","bulk-restore","bulk-purge","bulk-download","clear","inspect"],setup(o,{emit:a}){const t=o,n=a,i=e.computed(()=>{var s,d,c,u,m,p,f,h,v,y,w,_,b,g;return{selectedCount:((s=t.labels)==null?void 0:s.selectedCount)??(I=>`${I} selected`),selectedAcrossPages:((d=t.labels)==null?void 0:d.selectedAcrossPages)??((I,T)=>`${I} selected, including ${T} not on this page`),cappedSelection:((c=t.labels)==null?void 0:c.cappedSelection)??((I,T)=>`Selected first ${I} of ${T??"many"} matching items`),addToAlbum:((u=t.labels)==null?void 0:u.addToAlbum)??"Add to album",moveBetweenAlbums:((m=t.labels)==null?void 0:m.moveBetweenAlbums)??(I=>`Move from ${I} to...`),removeFromCurrentAlbum:((p=t.labels)==null?void 0:p.removeFromCurrentAlbum)??"Remove from this album",moveToTrash:((f=t.labels)==null?void 0:f.moveToTrash)??"Move to trash",createPost:((h=t.labels)==null?void 0:h.createPost)??"Create post",createGallery:((v=t.labels)==null?void 0:v.createGallery)??"Create gallery",restore:((y=t.labels)==null?void 0:y.restore)??"Restore",purge:((w=t.labels)==null?void 0:w.purge)??"Delete forever",download:((_=t.labels)==null?void 0:_.download)??"Download",inspect:((b=t.labels)==null?void 0:b.inspect)??"Inspect",clear:((g=t.labels)==null?void 0:g.clear)??"Clear"}}),r=e.computed(()=>t.overCap?i.value.cappedSelection(t.selectedCount,t.totalMatching):t.crossPageCount>0?i.value.selectedAcrossPages(t.selectedCount,t.crossPageCount):i.value.selectedCount(t.selectedCount)),l=e.computed(()=>t.sourceAlbum?i.value.moveBetweenAlbums(t.sourceAlbum.name):i.value.addToAlbum);return(s,d)=>(e.openBlock(),e.createBlock(e.Transition,{name:"media-bulk-action-bar"},{default:e.withCtx(()=>[t.selectedCount>0?(e.openBlock(),e.createElementBlock("aside",f6,[e.createElementVNode("button",{type:"button",class:"media-bulk-action-bar__count","data-testid":"media-bulk-action-count","aria-label":`${i.value.inspect}: ${r.value}`,onClick:d[0]||(d[0]=c=>n("inspect"))},e.toDisplayString(r.value),9,h6),e.createElementVNode("div",v6,[t.scope!=="trash"&&t.capabilities.allowAddToAlbum===!0?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button","data-testid":"btn-media-bulk-add-album",onClick:d[1]||(d[1]=c=>t.scope==="album"?n("bulk-move-between-albums"):n("bulk-add-to-album"))},e.toDisplayString(t.scope==="album"?l.value:i.value.addToAlbum),1)):e.createCommentVNode("",!0),t.scope!=="trash"&&t.capabilities.allowCreatePost===!0?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button","data-testid":"btn-media-bulk-create-post",onClick:d[2]||(d[2]=c=>n("bulk-create-post"))},e.toDisplayString(i.value.createPost),1)):e.createCommentVNode("",!0),t.scope!=="trash"&&t.capabilities.allowCreateGallery===!0?(e.openBlock(),e.createElementBlock("button",{key:2,type:"button","data-testid":"btn-media-bulk-create-gallery",onClick:d[3]||(d[3]=c=>n("bulk-create-gallery"))},e.toDisplayString(i.value.createGallery),1)):e.createCommentVNode("",!0),t.scope==="album"?(e.openBlock(),e.createElementBlock("button",{key:3,type:"button","data-testid":"btn-media-bulk-remove-current-album",onClick:d[4]||(d[4]=c=>n("bulk-remove-from-current-album"))},e.toDisplayString(i.value.removeFromCurrentAlbum),1)):e.createCommentVNode("",!0),t.scope!=="trash"?(e.openBlock(),e.createElementBlock("button",{key:4,type:"button","data-testid":"btn-media-bulk-trash",onClick:d[5]||(d[5]=c=>n("bulk-move-to-trash"))},e.toDisplayString(i.value.moveToTrash),1)):e.createCommentVNode("",!0),t.scope==="trash"?(e.openBlock(),e.createElementBlock("button",{key:5,type:"button","data-testid":"btn-media-bulk-restore",onClick:d[6]||(d[6]=c=>n("bulk-restore"))},e.toDisplayString(i.value.restore),1)):e.createCommentVNode("",!0),t.scope==="trash"?(e.openBlock(),e.createElementBlock("button",{key:6,type:"button","data-testid":"btn-media-bulk-purge",onClick:d[7]||(d[7]=c=>n("bulk-purge"))},e.toDisplayString(i.value.purge),1)):e.createCommentVNode("",!0),e.createElementVNode("button",{type:"button","data-testid":"btn-media-bulk-download",disabled:t.capabilities.allowDownloadZip!==!0,onClick:d[8]||(d[8]=c=>n("bulk-download"))},e.toDisplayString(i.value.download),9,g6),e.createElementVNode("button",{type:"button","data-testid":"btn-media-bulk-clear",onClick:d[9]||(d[9]=c=>n("clear"))},e.toDisplayString(i.value.clear),1)])])):e.createCommentVNode("",!0)]),_:1}))}}),qd=Ae(b6,[["__scopeId","data-v-f934b5b2"]]),y6={class:"media-library-toolbar__group"},w6=["aria-controls","aria-expanded"],k6=["id"],_6={class:"media-library-toolbar__group"},E6=["aria-controls","aria-expanded"],S6=["id"],C6={key:0,class:"media-library-toolbar__menu-status"},x6={key:1,class:"media-library-toolbar__menu-status"},N6=["data-testid","onClick"],V6={"aria-hidden":"true"},T6={class:"media-library-toolbar__group"},B6=["aria-controls","aria-expanded"],M6=["id"],I6=e.defineComponent({__name:"MediaLibraryToolbar",props:{sort:{default:"newest"},density:{default:"comfortable"},hasDateFilter:{type:Boolean,default:!1},httpClient:{},timelineEndpoint:{default:"/v1/media/library/timeline"},labels:{default:()=>({})}},emits:["update:sort","update:density","jump-to","jump-to-all","upload-files"],setup(o,{emit:a}){const t=o,n=a,i=e.computed(()=>{var z,C,A,O,K,se,xe,ue,le,Z,k,F;return{sort:((z=t.labels)==null?void 0:z.sort)??"Sort",sortNewest:((C=t.labels)==null?void 0:C.sortNewest)??"Newest",sortOldest:((A=t.labels)==null?void 0:A.sortOldest)??"Oldest",sortName:((O=t.labels)==null?void 0:O.sortName)??"Name A–Z",sortLargest:((K=t.labels)==null?void 0:K.sortLargest)??"Largest first",jumpTo:((se=t.labels)==null?void 0:se.jumpTo)??"Jump to",jumpToAll:((xe=t.labels)==null?void 0:xe.jumpToAll)??"All time",jumpToEmpty:((ue=t.labels)==null?void 0:ue.jumpToEmpty)??"No history yet",density:((le=t.labels)==null?void 0:le.density)??"Density",densityComfortable:((Z=t.labels)==null?void 0:Z.densityComfortable)??"Comfortable",densityCompact:((k=t.labels)==null?void 0:k.densityCompact)??"Compact",upload:((F=t.labels)==null?void 0:F.upload)??"Upload"}}),r=e.ref(null);function l(){var z;(z=r.value)==null||z.click()}function s(z){const C=z.target;!(C instanceof HTMLInputElement)||C.files===null||C.files.length===0||(n("upload-files",Array.from(C.files)),C.value="")}const d=e.ref(null),c=e.ref(null),u=e.ref(null),m=e.ref(null),p=e.ref(null),f=e.useId(),h={sort:`${f}-sort`,jump:`${f}-jump`,density:`${f}-density`};function v(z){return z==="sort"?u.value:z==="jump"?m.value:p.value}function y(){e.nextTick(()=>{const z=c.value;if(z===null)return;const C=z.querySelector('[role="menu"]');C!==null&&fa(jl(C)[0]??null)})}function w(z){if(d.value===z){_(!0);return}d.value=z,y()}function _(z=!1){const C=d.value;d.value=null,z&&C!==null&&e.nextTick(()=>fa(v(C)))}function b(z){if(d.value===null)return;const C=c.value;C!==null&&(z.target instanceof Node&&C.contains(z.target)||_())}function g(z){d.value!==null&&z.key==="Escape"&&(z.preventDefault(),_(!0))}function I(z){if(z.key==="Escape"){z.preventDefault(),_(!0);return}cd(z,z.currentTarget instanceof HTMLElement?z.currentTarget:null)}const T=e.computed(()=>{switch(t.sort){case"oldest":return i.value.sortOldest;case"name":return i.value.sortName;case"largest":return i.value.sortLargest;default:return i.value.sortNewest}}),$=e.computed(()=>t.density==="compact"?i.value.densityCompact:i.value.densityComfortable);function N(z){_(!0),n("update:sort",z)}function B(z){_(!0),n("update:density",z)}const P=e.ref([]),x=e.ref(!1),M=e.ref(!1);async function E(){if(!(x.value||M.value||t.httpClient===void 0)){M.value=!0;try{const z=await t.httpClient.get(t.timelineEndpoint),C=z.data,A=(C==null?void 0:C.buckets)??z.buckets??[];P.value=Array.isArray(A)?A:[],x.value=!0}finally{M.value=!1}}}async function D(){w("jump"),d.value==="jump"&&await E()}function j(z){_(!0),n("jump-to",z)}function L(){_(!0),n("jump-to-all")}return e.onMounted(()=>{typeof window<"u"&&(document.addEventListener("pointerdown",b,!0),document.addEventListener("keydown",g))}),e.onBeforeUnmount(()=>{typeof window<"u"&&(document.removeEventListener("pointerdown",b,!0),document.removeEventListener("keydown",g))}),(z,C)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"toolbarRoot",ref:c,class:"media-library-toolbar","data-testid":"media-library-toolbar"},[e.createElementVNode("button",{type:"button",class:"media-library-toolbar__upload","data-testid":"btn-media-toolbar-upload",onClick:l}," ⤴ "+e.toDisplayString(i.value.upload),1),e.createElementVNode("input",{ref_key:"fileInputRef",ref:r,type:"file",multiple:"",accept:"image/*,video/*","data-testid":"input-media-toolbar-upload",class:"media-library-toolbar__file-input",onChange:s},null,544),e.createElementVNode("div",y6,[e.createElementVNode("button",{ref_key:"sortTriggerRef",ref:u,type:"button",class:"media-library-toolbar__trigger","data-testid":"btn-media-toolbar-sort","aria-haspopup":"menu","aria-controls":h.sort,"aria-expanded":d.value==="sort"?"true":"false",onClick:C[0]||(C[0]=A=>w("sort"))},e.toDisplayString(i.value.sort)+": "+e.toDisplayString(T.value),9,w6),d.value==="sort"?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.sort,class:"media-library-toolbar__menu",role:"menu","data-testid":"media-library-toolbar-sort-menu",onKeydown:I},[e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":"opt-sort-newest",onClick:C[1]||(C[1]=A=>N("newest"))},e.toDisplayString(i.value.sortNewest),1),e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":"opt-sort-oldest",onClick:C[2]||(C[2]=A=>N("oldest"))},e.toDisplayString(i.value.sortOldest),1),e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":"opt-sort-name",onClick:C[3]||(C[3]=A=>N("name"))},e.toDisplayString(i.value.sortName),1),e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":"opt-sort-largest",onClick:C[4]||(C[4]=A=>N("largest"))},e.toDisplayString(i.value.sortLargest),1)],40,k6)):e.createCommentVNode("",!0)]),e.createElementVNode("div",_6,[e.createElementVNode("button",{ref_key:"jumpTriggerRef",ref:m,type:"button",class:"media-library-toolbar__trigger","data-testid":"btn-media-toolbar-jump-to","aria-haspopup":"menu","aria-controls":h.jump,"aria-expanded":d.value==="jump"?"true":"false",onClick:C[5]||(C[5]=A=>void D())},e.toDisplayString(i.value.jumpTo),9,E6),d.value==="jump"?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.jump,class:"media-library-toolbar__menu",role:"menu","data-testid":"media-library-toolbar-jump-menu",onKeydown:I},[e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":"opt-jump-all",onClick:L},e.toDisplayString(i.value.jumpToAll),1),M.value?(e.openBlock(),e.createElementBlock("p",C6,"Loading…")):x.value&&P.value.length===0?(e.openBlock(),e.createElementBlock("p",x6,e.toDisplayString(i.value.jumpToEmpty),1)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(P.value,A=>(e.openBlock(),e.createElementBlock("button",{key:A.starts_at,type:"button",role:"menuitem","data-testid":`opt-jump-${A.starts_at}`,onClick:O=>j(A)},[e.createTextVNode(e.toDisplayString(A.label)+" ",1),e.createElementVNode("span",V6,"("+e.toDisplayString(A.count)+")",1)],8,N6))),128))],40,S6)):e.createCommentVNode("",!0)]),e.createElementVNode("div",T6,[e.createElementVNode("button",{ref_key:"densityTriggerRef",ref:p,type:"button",class:"media-library-toolbar__trigger","data-testid":"btn-media-toolbar-density","aria-haspopup":"menu","aria-controls":h.density,"aria-expanded":d.value==="density"?"true":"false",onClick:C[6]||(C[6]=A=>w("density"))},e.toDisplayString(i.value.density)+": "+e.toDisplayString($.value),9,B6),d.value==="density"?(e.openBlock(),e.createElementBlock("div",{key:0,id:h.density,class:"media-library-toolbar__menu",role:"menu","data-testid":"media-library-toolbar-density-menu",onKeydown:I},[e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":"opt-density-comfortable",onClick:C[7]||(C[7]=A=>B("comfortable"))},e.toDisplayString(i.value.densityComfortable),1),e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":"opt-density-compact",onClick:C[8]||(C[8]=A=>B("compact"))},e.toDisplayString(i.value.densityCompact),1)],40,M6)):e.createCommentVNode("",!0)])],512))}}),jf=Ae(I6,[["__scopeId","data-v-2bd00d6a"]]),$6={class:"media-shortcut-help__panel"},F6={class:"media-shortcut-help__header"},D6=e.defineComponent({__name:"MediaShortcutHelp",props:{open:{type:Boolean},shortcuts:{default:()=>[{key:"j / k",label:"Move focus",group:"Navigation"},{key:"x",label:"Toggle selection",group:"Selection"},{key:"?",label:"Open shortcuts",group:"Help"},{key:"Esc",label:"Close panel",group:"Navigation"}]},title:{default:"Shortcuts"},closeLabel:{default:"Close"}},emits:["close"],setup(o,{emit:a}){const t=o,n=a;function i(){const r=new Map;for(const l of t.shortcuts)r.set(l.group,[...r.get(l.group)??[],l]);return Array.from(r.entries()).map(([l,s])=>({group:l,shortcuts:s}))}return(r,l)=>t.open?(e.openBlock(),e.createElementBlock("div",{key:0,class:"media-shortcut-help",role:"dialog","aria-modal":"true","data-testid":"media-shortcut-help",onKeydown:l[1]||(l[1]=e.withKeys(s=>n("close"),["escape"]))},[e.createElementVNode("div",$6,[e.createElementVNode("header",F6,[e.createElementVNode("h3",null,e.toDisplayString(t.title),1),e.createElementVNode("button",{type:"button","data-testid":"btn-media-shortcut-close",onClick:l[0]||(l[0]=s=>n("close"))},e.toDisplayString(t.closeLabel),1)]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i(),s=>(e.openBlock(),e.createElementBlock("section",{key:s.group,class:"media-shortcut-help__group"},[e.createElementVNode("h4",null,e.toDisplayString(s.group),1),e.createElementVNode("dl",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.shortcuts,d=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:`${s.group}-${d.key}`},[e.createElementVNode("dt",null,[e.createElementVNode("kbd",null,e.toDisplayString(d.key),1)]),e.createElementVNode("dd",null,e.toDisplayString(d.label),1)],64))),128))])]))),128))])],32)):e.createCommentVNode("",!0)}}),Wf=Ae(D6,[["__scopeId","data-v-abcdccb6"]]),A6="/v1/media/upload";function Hf(o){const a=o.endpoint??A6,t=e.ref([]),n=e.computed(()=>t.value.some(u=>u.status==="uploading"||u.status==="queued"));function i(){return`upload-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function r(u){if(u.type.startsWith("image/")&&typeof URL<"u")try{return URL.createObjectURL(u)}catch{return}}function l(u){t.value=t.value.filter(m=>m.cid!==u)}async function s(u){const m=i(),p=r(u),f={cid:m,fileName:u.name,size:u.size,status:"uploading",progress:0,...p!==void 0?{previewUrl:p}:{}};t.value=[f,...t.value];const h=new FormData;h.append("file",u);try{const v=await o.httpClient.post(a,h),y=v.data??v;return t.value=t.value.map(w=>w.cid===m?{...w,status:"success",progress:100}:w),typeof o.onMediaUploaded=="function"&&y&&typeof y.uuid=="string"&&await o.onMediaUploaded(y),setTimeout(()=>l(m),350),t.value.find(w=>w.cid===m)??f}catch(v){const y=v instanceof Error?v.message:"Upload failed";return t.value=t.value.map(w=>w.cid===m?{...w,status:"error",errorMessage:y}:w),t.value.find(w=>w.cid===m)??f}finally{if(p!==void 0&&typeof URL<"u")try{URL.revokeObjectURL(p)}catch{}}}async function d(u){const m=Array.from(u);return Promise.all(m.map(p=>s(p)))}function c(){t.value=[]}return{uploads:t,hasActiveUploads:n,uploadFile:s,uploadFiles:d,dismiss:l,clear:c}}const R6={class:"media-usage-list","data-testid":"media-usage-list"},L6={class:"media-usage-list__title"},P6={key:0,class:"media-usage-list__empty","data-testid":"media-usage-loading"},U6={key:1,class:"media-usage-list__empty","data-testid":"media-usage-empty"},O6={key:2,class:"media-usage-list__items"},z6=["data-testid"],j6=["href"],W6={key:1},H6={key:2,class:"media-usage-list__count"},Z6=e.defineComponent({__name:"MediaUsageList",props:{media:{},httpClient:{},items:{default:()=>[]},title:{default:"Used in"},emptyLabel:{default:"No visible usages"}},setup(o){const a=o,t=e.ref(!1),n=e.ref([]),i=e.computed(()=>a.items.length>0?a.items:n.value);function r(s){var m;if(typeof s!="object"||s===null||!("data"in s))return[];const d=s.data;if(!Array.isArray(d))return[];const c=d[0];return(Array.isArray((m=c==null?void 0:c.report)==null?void 0:m.blocks)?c.report.blocks:[]).map((p,f)=>({id:`${p.type??"usage"}-${f}`,label:p.context??p.type??"Usage"}))}async function l(){if(!a.httpClient||a.media===null){n.value=[];return}t.value=!0;try{const s=await a.httpClient.post("/v1/media/deletion/check",{uuids:[a.media.uuid]});n.value=r(s)}finally{t.value=!1}}return e.watch(()=>{var s;return(s=a.media)==null?void 0:s.uuid},()=>{l()}),e.onMounted(()=>{l()}),(s,d)=>(e.openBlock(),e.createElementBlock("section",R6,[e.createElementVNode("h4",L6,e.toDisplayString(a.title),1),t.value?(e.openBlock(),e.createElementBlock("p",P6," Loading... ")):i.value.length===0?(e.openBlock(),e.createElementBlock("p",U6,e.toDisplayString(a.emptyLabel),1)):(e.openBlock(),e.createElementBlock("ul",O6,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.value,c=>(e.openBlock(),e.createElementBlock("li",{key:c.id,class:"media-usage-list__item","data-testid":`media-usage-${c.id}`},[c.href?(e.openBlock(),e.createElementBlock("a",{key:0,href:c.href},e.toDisplayString(c.label),9,j6)):(e.openBlock(),e.createElementBlock("span",W6,e.toDisplayString(c.label),1)),typeof c.count=="number"?(e.openBlock(),e.createElementBlock("span",H6,e.toDisplayString(c.count),1)):e.createCommentVNode("",!0)],8,z6))),128))]))]))}}),Zf=Ae(Z6,[["__scopeId","data-v-ef6f09cf"]]),G6={class:"media-variant-strip","data-testid":"media-variant-strip"},X6={class:"media-variant-strip__title"},K6={key:0,class:"media-variant-strip__empty"},q6={key:1,class:"media-variant-strip__empty"},J6={key:2,class:"media-variant-strip__list"},Y6=["data-testid"],Q6=["src","alt"],eA={key:1,class:"media-variant-strip__placeholder"},tA={class:"media-variant-strip__label"},aA=e.defineComponent({__name:"MediaVariantStrip",props:{media:{},httpClient:{},variants:{default:()=>[]},title:{default:"Variants"}},setup(o){const a=o,t=e.ref(!1),n=e.ref([]),i=e.computed(()=>{const c=a.variants.length>0?a.variants:n.value;return a.media?[a.media,...c.filter(u=>{var m;return u.uuid!==((m=a.media)==null?void 0:m.uuid)})]:c});function r(c){if(typeof c!="object"||c===null||!("data"in c))return[];const u=c.data;return Array.isArray(u)?u.filter(m=>typeof m=="object"&&m!==null&&typeof m.uuid=="string"&&typeof m.file_name=="string"):[]}async function l(){if(!a.httpClient||a.media===null){n.value=[];return}t.value=!0;try{const c=await a.httpClient.get(`/v1/media/${encodeURIComponent(a.media.uuid)}/variants`);n.value=r(c)}finally{t.value=!1}}function s(c){return c.thumbnail_url??c.preview_url??c.original_url??null}function d(c,u){if(c===0)return"Current";if(c===1)return"Original";const m=new Date(u.created_at);if(Number.isNaN(m.getTime()))return"Edited";const p=Math.max(0,Math.round((Date.now()-m.getTime())/864e5));return p===0?"Edited today":p===1?"Edited 1 day ago":`Edited ${p} days ago`}return e.watch(()=>{var c;return(c=a.media)==null?void 0:c.uuid},()=>{l()}),e.onMounted(()=>{l()}),(c,u)=>(e.openBlock(),e.createElementBlock("section",G6,[e.createElementVNode("h4",X6,e.toDisplayString(a.title),1),t.value?(e.openBlock(),e.createElementBlock("p",K6,"Loading...")):i.value.length<=1?(e.openBlock(),e.createElementBlock("p",q6," No edits ")):(e.openBlock(),e.createElementBlock("ol",J6,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.value,(m,p)=>(e.openBlock(),e.createElementBlock("li",{key:m.uuid,class:"media-variant-strip__item","data-testid":`media-variant-${m.uuid}`},[s(m)?(e.openBlock(),e.createElementBlock("img",{key:0,src:s(m)??"",alt:m.alt_text??m.file_name},null,8,Q6)):(e.openBlock(),e.createElementBlock("span",eA,e.toDisplayString(m.file_name),1)),e.createElementVNode("span",tA,e.toDisplayString(d(p,m)),1)],8,Y6))),128))]))]))}}),Gf=Ae(aA,[["__scopeId","data-v-adb529cb"]]),nA=/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/ig,qu=/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i;function Ju(o){const a=o.replace(/\.[^.]+$/,""),t=a.replace(nA,""),n=t.replace(/(?:[-_\s]+edited)+$/i,""),i=t.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/(?:[-_\s]+edited)+$/i,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim();return i!==""?i:n||a||o}function Yu(o,a){var n;const t=(n=o.custom_properties)==null?void 0:n[a];return typeof t=="string"&&t.trim()!==""?t.trim():null}function Xf(o){const a=Yu(o,"display_name");if(a!==null&&!qu.test(a))return a;const t=Yu(o,"original_filename");return t!==null&&!qu.test(t)?Ju(t):Ju(o.file_name)}const oA=o=>`/v1/media/${encodeURIComponent(o)}`,iA=new Set(["caption","alt_text","is_decorative","tags"]);function ks(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function Br(o,a){return Object.prototype.hasOwnProperty.call(o,a)}function Qu(o){if(o==null)return null;const a=o.trim();return a===""?null:a}function rA(o){const a=[];for(const t of o){const n=t.trim();n===""||a.includes(n)||a.push(n)}return a}function lA(o){const a=o,t={};for(const n of Object.keys(a))if(!iA.has(n))throw new Error(`Unsupported media metadata field: ${n}`);if(Br(o,"caption")&&(t.caption=Qu(o.caption)),Br(o,"alt_text")&&(t.alt_text=Qu(o.alt_text)),Br(o,"is_decorative")&&(t.is_decorative=o.is_decorative===!0),Br(o,"tags")&&(t.tags=Array.isArray(o.tags)?rA(o.tags):[]),Object.keys(t).length===0)throw new Error("At least one media metadata field must be provided");return t}function sA(o){const a=ks(o)&&ks(o.data)?o.data:o;if(ks(a)&&typeof a.uuid=="string")return a;throw new Error("Media metadata update response did not include a media record")}function Kf(o){const a=e.ref(!1),t=e.ref(null),n=o.endpoint??oA;async function i(r,l){const s=r.trim();if(s==="")throw new Error("media uuid must not be empty");if(typeof o.httpClient.patch!="function")throw new Error("httpClient.patch is required to update media metadata");const d=lA(l);a.value=!0,t.value=null;try{const c=await o.httpClient.patch(n(s),d,o.requestConfig);return sA(c)}catch(c){throw t.value=c instanceof Error?c.message:"Failed to update media metadata",c}finally{a.value=!1}}return{updateMetadata:i,isUpdating:a,error:t}}const dA=["role","aria-modal"],cA={key:0,class:"media-inspector-panel__overlay-bar"},uA=["aria-label"],mA={class:"media-inspector-panel__header"},pA={key:0,class:"media-inspector-panel__raw-name"},fA={class:"media-inspector-panel__preview"},hA=["src","alt"],vA={class:"media-inspector-panel__meta"},gA={class:"media-inspector-panel__metadata","data-testid":"media-inspector-metadata-editor","aria-labelledby":"media-inspector-metadata-heading"},bA={class:"media-inspector-panel__metadata-heading"},yA={id:"media-inspector-metadata-heading"},wA={key:0,class:"media-inspector-panel__metadata-warning","data-testid":"media-inspector-missing-alt"},kA={class:"media-inspector-panel__field"},_A={class:"media-inspector-panel__field"},EA=["disabled"],SA={class:"media-inspector-panel__checkbox"},CA={id:"media-inspector-decorative-help",class:"media-inspector-panel__metadata-help"},xA={class:"media-inspector-panel__field"},NA={key:0,class:"media-inspector-panel__metadata-error","data-testid":"media-inspector-metadata-error",role:"alert"},VA={class:"media-inspector-panel__metadata-actions"},TA=["disabled"],BA=["disabled"],MA={key:2,class:"media-inspector-panel__metadata-read"},IA={key:0,class:"media-inspector-panel__metadata-status","data-testid":"media-inspector-metadata-status",role:"status"},$A={class:"media-inspector-panel__actions"},FA=["aria-label"],DA=["aria-label"],AA=["aria-label"],RA=["aria-label"],LA=["aria-label"],PA=["aria-label"],UA=["aria-label"],OA=["aria-label"],zA={class:"media-inspector-panel__actions"},jA=["aria-label"],WA=["aria-label"],HA=["aria-label"],ZA=["aria-label"],GA={key:3,class:"media-inspector-panel__empty"},XA=e.defineComponent({__name:"MediaInspectorPanel",props:{target:{},httpClient:{},capabilities:{default:()=>({})},inAlbumScope:{type:Boolean,default:!1},labels:{default:()=>({})},mode:{default:"pinned"}},emits:["edit","replace","download","set-visibility","move-to-trash","remove-from-this-album","remove-from-albums","set-as-album-cover","bulk-add-to-album","bulk-create-album","bulk-move-to-trash","bulk-download","metadata-updated","close"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(null),r=e.ref(null),l=e.ref(null),s=e.ref(null),d=e.ref(!1),c=e.ref(""),u=e.ref(""),m=e.ref(!1),p=e.ref(""),f=e.ref(""),h=e.ref("");function v(){return Promise.reject(new Error("Media metadata editing requires a PATCH-capable httpClient."))}const w=Kf({httpClient:{get:async(k,F)=>{var W;return((W=t.httpClient)==null?void 0:W.get(k,F))??v()},post:async(k,F,W)=>{var J;return((J=t.httpClient)==null?void 0:J.post(k,F,W))??v()},patch:async(k,F,W)=>{var J,ce;return((ce=(J=t.httpClient)==null?void 0:J.patch)==null?void 0:ce.call(J,k,F,W))??v()}}});e.watch(()=>t.target,(k,F)=>{const W=F==null,J=k==null;if(W&&!J){typeof document<"u"&&document.activeElement instanceof HTMLElement&&(s.value=document.activeElement),e.nextTick(()=>{var ce,Ue;if(t.mode==="overlay"){(ce=l.value)==null||ce.focus();return}(Ue=r.value)==null||Ue.focus()});return}if(!W&&J){const ce=s.value;s.value=null,ce instanceof HTMLElement&&ce.focus()}});function _(k){if(t.mode==="overlay"&&k.key==="Escape"){k.preventDefault(),k.stopPropagation(),n("close");return}t.mode==="overlay"&&k.key==="Tab"&&Kd(k,i.value)}const b=e.computed(()=>t.mode==="overlay"?"dialog":"complementary"),g=e.computed(()=>{var k,F,W,J,ce,Ue,be,_e,ye,Ne,Se,Re,Oe,it,rt,Pt,bt,Ct,mt,pt,Nt,Ce,Ve,Le,nt,Ge;return{title:((k=t.labels)==null?void 0:k.title)??"Inspector",emptyTitle:((F=t.labels)==null?void 0:F.emptyTitle)??"Select media to inspect",multiTitle:((W=t.labels)==null?void 0:W.multiTitle)??(Je=>`${Je} selected`),edit:((J=t.labels)==null?void 0:J.edit)??"Edit",replace:((ce=t.labels)==null?void 0:ce.replace)??"Replace",download:((Ue=t.labels)==null?void 0:Ue.download)??"Download",setVisibility:((be=t.labels)==null?void 0:be.setVisibility)??"Set visibility",moveToTrash:((_e=t.labels)==null?void 0:_e.moveToTrash)??"Move to trash",removeFromThisAlbum:((ye=t.labels)==null?void 0:ye.removeFromThisAlbum)??"Remove from this album",removeFromAlbums:((Ne=t.labels)==null?void 0:Ne.removeFromAlbums)??(t.inAlbumScope?"Move to another album":"Add to album"),addToAlbum:((Se=t.labels)==null?void 0:Se.addToAlbum)??"Add to album",createAlbum:((Re=t.labels)==null?void 0:Re.createAlbum)??"Create album from selection",setAsAlbumCover:((Oe=t.labels)==null?void 0:Oe.setAsAlbumCover)??"Set as album cover",metadataTitle:((it=t.labels)==null?void 0:it.metadataTitle)??"Metadata",metadataEdit:((rt=t.labels)==null?void 0:rt.metadataEdit)??"Edit metadata",caption:((Pt=t.labels)==null?void 0:Pt.caption)??"Caption",altText:((bt=t.labels)==null?void 0:bt.altText)??"Alt text",decorative:((Ct=t.labels)==null?void 0:Ct.decorative)??"Decorative image",tags:((mt=t.labels)==null?void 0:mt.tags)??"Tags",saveMetadata:((pt=t.labels)==null?void 0:pt.saveMetadata)??"Save metadata",cancelMetadata:((Nt=t.labels)==null?void 0:Nt.cancelMetadata)??"Cancel",metadataSaved:((Ce=t.labels)==null?void 0:Ce.metadataSaved)??"Metadata saved",close:((Ve=t.labels)==null?void 0:Ve.close)??"Close inspector",missingAltTitle:((Le=t.labels)==null?void 0:Le.missingAltTitle)??"Missing alt text",missingAltDescription:((nt=t.labels)==null?void 0:nt.missingAltDescription)??"Add alt text or mark this image as decorative.",decorativeHelp:((Ge=t.labels)==null?void 0:Ge.decorativeHelp)??"Decorative media does not need alt text."}}),I=e.computed(()=>{var k;return((k=t.target)==null?void 0:k.kind)==="single"?t.target.media:null});function T(k){const F=k.mime_type.toLowerCase();return k.is_image===!0||F.startsWith("image/")?"image":F.startsWith("video/")?"video":null}const $=e.computed(()=>{const k=I.value;if(k===null)return!1;const F=T(k);return F==="image"?t.capabilities.allowImageEdit===!0:F==="video"?t.capabilities.allowVideoEdit===!0:!1}),N=e.computed(()=>t.capabilities.allowReplaceMedia===!0),B=e.computed(()=>t.capabilities.allowDownloadOriginal===!0),P=e.computed(()=>t.capabilities.allowBulkDelete===!0),x=e.computed(()=>t.inAlbumScope||t.capabilities.allowAddToAlbum===!0),M=e.computed(()=>t.capabilities.allowAddToAlbum===!0),E=e.computed(()=>t.capabilities.allowBulkDelete===!0),D=e.computed(()=>t.capabilities.allowDownloadZip===!0),j=e.computed(()=>{var k;return I.value!==null&&t.capabilities.allowMetadataEdit===!0&&typeof((k=t.httpClient)==null?void 0:k.patch)=="function"}),L=e.computed(()=>{const k=I.value;return k===null?null:T(k)}),z=e.computed(()=>{const k=I.value;return k!==null&&L.value==="image"&&k.is_decorative!==!0&&!O(k.alt_text)}),C=e.computed(()=>w.isUpdating.value),A=e.computed(()=>{var k;return K((k=I.value)==null?void 0:k.tags)});function O(k){return typeof k=="string"&&k.trim()!==""}function K(k){return Array.isArray(k)?k.filter(F=>F.trim()!=="").join(", "):""}function se(k){const F=[];for(const W of k.split(",")){const J=W.trim();J===""||F.includes(J)||F.push(J)}return F}function xe(k,F=!0){c.value=(k==null?void 0:k.caption)??"",u.value=(k==null?void 0:k.alt_text)??"",m.value=(k==null?void 0:k.is_decorative)===!0,p.value=K(k==null?void 0:k.tags),f.value="",F&&(h.value="")}function ue(){xe(I.value),d.value=!0}function le(){xe(I.value),d.value=!1}async function Z(){const k=I.value;if(!(k===null||!j.value||C.value)){f.value="",h.value="";try{const F=await w.updateMetadata(k.uuid,{caption:c.value,alt_text:m.value?null:u.value,is_decorative:m.value,tags:se(p.value)});xe(F,!1),d.value=!1,h.value=g.value.metadataSaved,n("metadata-updated",F)}catch(F){f.value=F instanceof Error?F.message:"Failed to save media metadata"}}}return e.watch(I,(k,F)=>{const W=(k==null?void 0:k.uuid)!==(F==null?void 0:F.uuid);xe(k,W),d.value=!1},{immediate:!0}),e.watch(m,k=>{k&&(u.value="")}),(k,F)=>{var W;return e.openBlock(),e.createElementBlock("aside",{ref_key:"panelRef",ref:i,class:"media-inspector-panel","data-testid":"media-inspector-panel",role:b.value,"aria-modal":t.mode==="overlay"?"true":void 0,"aria-labelledby":"media-inspector-heading",onKeydown:_},[t.mode==="overlay"?(e.openBlock(),e.createElementBlock("div",cA,[e.createElementVNode("button",{ref_key:"closeButtonRef",ref:l,type:"button",class:"media-inspector-panel__close","data-testid":"btn-media-inspector-close","aria-label":g.value.close,onClick:F[0]||(F[0]=J=>n("close"))}," × ",8,uA)])):e.createCommentVNode("",!0),I.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("header",mA,[e.createElementVNode("h3",{id:"media-inspector-heading",ref_key:"headingRef",ref:r,tabindex:"-1"},e.toDisplayString(e.unref(Xf)(I.value)),513),I.value.file_name?(e.openBlock(),e.createElementBlock("p",pA,e.toDisplayString(I.value.file_name),1)):e.createCommentVNode("",!0)]),e.createElementVNode("div",fA,[I.value.thumbnail_url??I.value.preview_url??I.value.original_url?(e.openBlock(),e.createElementBlock("img",{key:0,src:I.value.thumbnail_url??I.value.preview_url??I.value.original_url,alt:I.value.alt_text??I.value.file_name},null,8,hA)):e.createCommentVNode("",!0)]),e.createElementVNode("dl",vA,[e.createElementVNode("div",null,[F[17]||(F[17]=e.createElementVNode("dt",null,"Type",-1)),e.createElementVNode("dd",null,e.toDisplayString(I.value.mime_type),1)]),e.createElementVNode("div",null,[F[18]||(F[18]=e.createElementVNode("dt",null,"Size",-1)),e.createElementVNode("dd",null,e.toDisplayString(I.value.formatted_size??I.value.size),1)])]),e.createElementVNode("section",gA,[e.createElementVNode("div",bA,[e.createElementVNode("h4",yA,e.toDisplayString(g.value.metadataTitle),1),j.value&&!d.value?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button","data-testid":"btn-media-inspector-metadata-edit",onClick:ue},e.toDisplayString(g.value.metadataEdit),1)):e.createCommentVNode("",!0)]),z.value?(e.openBlock(),e.createElementBlock("p",wA,[e.createElementVNode("strong",null,e.toDisplayString(g.value.missingAltTitle),1),e.createElementVNode("span",null,e.toDisplayString(g.value.missingAltDescription),1)])):e.createCommentVNode("",!0),d.value?(e.openBlock(),e.createElementBlock("form",{key:1,class:"media-inspector-panel__metadata-form",onSubmit:e.withModifiers(Z,["prevent"])},[e.createElementVNode("label",kA,[e.createElementVNode("span",null,e.toDisplayString(g.value.caption),1),e.withDirectives(e.createElementVNode("textarea",{"onUpdate:modelValue":F[1]||(F[1]=J=>c.value=J),"data-testid":"textarea-media-inspector-caption",rows:"3"},null,512),[[e.vModelText,c.value]])]),e.createElementVNode("label",_A,[e.createElementVNode("span",null,e.toDisplayString(g.value.altText),1),e.withDirectives(e.createElementVNode("textarea",{"onUpdate:modelValue":F[2]||(F[2]=J=>u.value=J),"data-testid":"textarea-media-inspector-alt-text",rows:"3",disabled:m.value,"aria-describedby":"media-inspector-decorative-help"},null,8,EA),[[e.vModelText,u.value]])]),e.createElementVNode("label",SA,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":F[3]||(F[3]=J=>m.value=J),type:"checkbox","data-testid":"checkbox-media-inspector-decorative","aria-describedby":"media-inspector-decorative-help"},null,512),[[e.vModelCheckbox,m.value]]),e.createElementVNode("span",null,e.toDisplayString(g.value.decorative),1)]),e.createElementVNode("p",CA,e.toDisplayString(g.value.decorativeHelp),1),e.createElementVNode("label",xA,[e.createElementVNode("span",null,e.toDisplayString(g.value.tags),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":F[4]||(F[4]=J=>p.value=J),type:"text","data-testid":"input-media-inspector-tags"},null,512),[[e.vModelText,p.value]])]),f.value?(e.openBlock(),e.createElementBlock("p",NA,e.toDisplayString(f.value),1)):e.createCommentVNode("",!0),e.createElementVNode("div",VA,[e.createElementVNode("button",{type:"submit","data-testid":"btn-media-inspector-metadata-save",disabled:C.value,onClick:e.withModifiers(Z,["prevent"])},e.toDisplayString(g.value.saveMetadata),9,TA),e.createElementVNode("button",{type:"button","data-testid":"btn-media-inspector-metadata-cancel",disabled:C.value,onClick:le},e.toDisplayString(g.value.cancelMetadata),9,BA)])],32)):(e.openBlock(),e.createElementBlock("div",MA,[e.createElementVNode("dl",null,[e.createElementVNode("div",null,[e.createElementVNode("dt",null,e.toDisplayString(g.value.caption),1),e.createElementVNode("dd",null,e.toDisplayString(I.value.caption||"None"),1)]),e.createElementVNode("div",null,[e.createElementVNode("dt",null,e.toDisplayString(g.value.altText),1),e.createElementVNode("dd",null,e.toDisplayString(I.value.alt_text||"None"),1)]),e.createElementVNode("div",null,[e.createElementVNode("dt",null,e.toDisplayString(g.value.decorative),1),e.createElementVNode("dd",null,e.toDisplayString(I.value.is_decorative===!0?"Yes":"No"),1)]),e.createElementVNode("div",null,[e.createElementVNode("dt",null,e.toDisplayString(g.value.tags),1),e.createElementVNode("dd",null,e.toDisplayString(A.value||"None"),1)])]),h.value?(e.openBlock(),e.createElementBlock("p",IA,e.toDisplayString(h.value),1)):e.createCommentVNode("",!0)]))]),e.createVNode(Zf,{media:I.value,"http-client":t.httpClient},null,8,["media","http-client"]),e.createVNode(Gf,{media:I.value,"http-client":t.httpClient},null,8,["media","http-client"]),e.createElementVNode("div",$A,[$.value?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button","data-testid":"btn-media-inspector-edit","aria-label":g.value.edit,onClick:F[5]||(F[5]=J=>n("edit",I.value))},e.toDisplayString(g.value.edit),9,FA)):e.createCommentVNode("",!0),N.value?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button","data-testid":"btn-media-inspector-replace","aria-label":g.value.replace,onClick:F[6]||(F[6]=J=>n("replace",I.value))},e.toDisplayString(g.value.replace),9,DA)):e.createCommentVNode("",!0),B.value?(e.openBlock(),e.createElementBlock("button",{key:2,type:"button","data-testid":"btn-media-inspector-download","aria-label":g.value.download,onClick:F[7]||(F[7]=J=>n("download",I.value))},e.toDisplayString(g.value.download),9,AA)):e.createCommentVNode("",!0),t.capabilities.allowVisibilityChange?(e.openBlock(),e.createElementBlock("button",{key:3,type:"button","data-testid":"btn-media-inspector-visibility","aria-label":g.value.setVisibility,onClick:F[8]||(F[8]=J=>n("set-visibility",I.value))},e.toDisplayString(g.value.setVisibility),9,RA)):e.createCommentVNode("",!0),t.inAlbumScope?(e.openBlock(),e.createElementBlock("button",{key:4,type:"button","data-testid":"btn-set-as-album-cover","aria-label":g.value.setAsAlbumCover,onClick:F[9]||(F[9]=J=>n("set-as-album-cover",I.value))},e.toDisplayString(g.value.setAsAlbumCover),9,LA)):e.createCommentVNode("",!0),t.inAlbumScope?(e.openBlock(),e.createElementBlock("button",{key:5,type:"button","data-testid":"btn-media-inspector-remove-current-album","aria-label":g.value.removeFromThisAlbum,onClick:F[10]||(F[10]=J=>n("remove-from-this-album",I.value))},e.toDisplayString(g.value.removeFromThisAlbum),9,PA)):e.createCommentVNode("",!0),x.value?(e.openBlock(),e.createElementBlock("button",{key:6,type:"button","data-testid":"btn-media-inspector-album-membership","aria-label":g.value.removeFromAlbums,onClick:F[11]||(F[11]=J=>n("remove-from-albums",I.value))},e.toDisplayString(g.value.removeFromAlbums),9,UA)):e.createCommentVNode("",!0),P.value?(e.openBlock(),e.createElementBlock("button",{key:7,type:"button","data-testid":"btn-media-inspector-trash","aria-label":g.value.moveToTrash,onClick:F[12]||(F[12]=J=>n("move-to-trash",I.value))},e.toDisplayString(g.value.moveToTrash),9,OA)):e.createCommentVNode("",!0)])],64)):((W=t.target)==null?void 0:W.kind)==="multi"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createElementVNode("h3",{id:"media-inspector-heading",ref_key:"headingRef",ref:r,tabindex:"-1"},e.toDisplayString(g.value.multiTitle(t.target.count)),513),e.createElementVNode("div",zA,[M.value?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button","data-testid":"btn-media-inspector-bulk-add-album","aria-label":g.value.addToAlbum,onClick:F[13]||(F[13]=J=>n("bulk-add-to-album"))},e.toDisplayString(g.value.addToAlbum),9,jA)):e.createCommentVNode("",!0),M.value?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button","data-testid":"btn-media-inspector-bulk-create-album","aria-label":g.value.createAlbum,onClick:F[14]||(F[14]=J=>n("bulk-create-album"))},e.toDisplayString(g.value.createAlbum),9,WA)):e.createCommentVNode("",!0),E.value?(e.openBlock(),e.createElementBlock("button",{key:2,type:"button","data-testid":"btn-media-inspector-bulk-trash","aria-label":g.value.moveToTrash,onClick:F[15]||(F[15]=J=>n("bulk-move-to-trash"))},e.toDisplayString(g.value.moveToTrash),9,HA)):e.createCommentVNode("",!0),D.value?(e.openBlock(),e.createElementBlock("button",{key:3,type:"button","data-testid":"btn-media-inspector-bulk-download","aria-label":g.value.download,onClick:F[16]||(F[16]=J=>n("bulk-download"))},e.toDisplayString(g.value.download),9,ZA)):e.createCommentVNode("",!0)])],64)):(e.openBlock(),e.createElementBlock("p",GA,e.toDisplayString(g.value.emptyTitle),1))],40,dA)}}}),qf=Ae(XA,[["__scopeId","data-v-f6d70239"]]),KA={class:"media-filter-chips__scroll"},qA={key:0,class:"media-filter-chips__chip media-filter-chips__chip--scope","data-testid":"media-filter-scope-chip"},JA=["data-testid","aria-label","onClick"],YA={class:"media-filter-chips__add-wrap"},QA=["aria-controls","aria-expanded"],eR=["id","aria-label"],tR=["placeholder","aria-label"],aR={class:"media-filter-chips__search-actions"},nR={type:"submit",class:"media-filter-chips__search-button","data-testid":"btn-media-filter-query-apply"},oR=e.defineComponent({__name:"MediaFilterChips",props:{filters:{},scopeLabel:{default:""},labels:{default:()=>({})}},emits:["update:filters","change","clear"],setup(o,{emit:a}){var z;const t=o,n=a,i=e.ref(!1),r=e.ref(((z=t.filters.query)==null?void 0:z.trim())??""),l=e.ref(null),s=e.ref(null),d=e.ref(null),c=e.useId(),u=e.computed(()=>{var C,A,O,K,se,xe,ue,le,Z,k,F,W,J,ce,Ue,be,_e,ye,Ne,Se,Re;return{addFilter:((C=t.labels)==null?void 0:C.addFilter)??"Filter",clearAll:((A=t.labels)==null?void 0:A.clearAll)??"Clear all filters",typeLabel:((O=t.labels)==null?void 0:O.typeLabel)??"Type",usageLabel:((K=t.labels)==null?void 0:K.usageLabel)??"Usage",metadataLabel:((se=t.labels)==null?void 0:se.metadataLabel)??"Metadata",imageLabel:((xe=t.labels)==null?void 0:xe.imageLabel)??"Image",videoLabel:((ue=t.labels)==null?void 0:ue.videoLabel)??"Video",usedLabel:((le=t.labels)==null?void 0:le.usedLabel)??"Used",notUsedLabel:((Z=t.labels)==null?void 0:Z.notUsedLabel)??"Not used",missingAltLabel:((k=t.labels)==null?void 0:k.missingAltLabel)??"Missing alt text",hasAltLabel:((F=t.labels)==null?void 0:F.hasAltLabel)??"Has alt text",missingCaptionLabel:((W=t.labels)==null?void 0:W.missingCaptionLabel)??"Missing caption",hasCaptionLabel:((J=t.labels)==null?void 0:J.hasCaptionLabel)??"Has caption",hasTagsLabel:((ce=t.labels)==null?void 0:ce.hasTagsLabel)??"Has tags",decorativeLabel:((Ue=t.labels)==null?void 0:Ue.decorativeLabel)??"Decorative",dateAfterLabel:((be=t.labels)==null?void 0:be.dateAfterLabel)??"After",dateBeforeLabel:((_e=t.labels)==null?void 0:_e.dateBeforeLabel)??"Before",searchLabel:((ye=t.labels)==null?void 0:ye.searchLabel)??"Search",searchPlaceholder:((Ne=t.labels)==null?void 0:Ne.searchPlaceholder)??"Search media",applySearch:((Se=t.labels)==null?void 0:Se.applySearch)??"Apply",clearSearch:((Re=t.labels)==null?void 0:Re.clearSearch)??"Clear"}});e.watch(()=>t.filters.query,C=>{r.value=(C==null?void 0:C.trim())??""});function m(){return{...t.filters,...t.filters.kinds!==void 0?{kinds:[...t.filters.kinds]}:{},...t.filters.selected_uuids!==void 0?{selected_uuids:[...t.filters.selected_uuids]}:{}}}function p(C){n("update:filters",C),n("change",C)}function f(C){const A=m(),O=(A.kinds??[]).filter(K=>K!==C);O.length>0?A.kinds=O:delete A.kinds,p(A)}function h(C){const A=m(),O=new Set(A.kinds??[]);O.add(C),A.kinds=Array.from(O),p(A),g(!0)}function v(){const C=m();delete C.usage_status,p(C)}function y(C){const A=m();A.usage_status=C,p(A),g(!0)}function w(C){const A=u.value;return{missing_alt:A.missingAltLabel,has_alt:A.hasAltLabel,missing_caption:A.missingCaptionLabel,has_caption:A.hasCaptionLabel,has_tags:A.hasTagsLabel,decorative:A.decorativeLabel}[C]}function _(){const C=m();delete C.metadata_status,p(C)}function b(C){const A=m();A.metadata_status=C,p(A),g(!0)}function g(C=!1){i.value&&(i.value=!1,C&&e.nextTick(()=>fa(s.value)))}function I(){var C;i.value=!0,r.value=((C=t.filters.query)==null?void 0:C.trim())??"",e.nextTick(()=>fa(d.value))}function T(){if(i.value){g(!0);return}I()}function $(){const C=m(),A=r.value.trim();A===""?delete C.query:C.query=A,p(C),g(!0)}function N(){const C=m();delete C.query,r.value="",p(C),g(!0)}function B(C){const A=new Date;return A.setHours(0,0,0,0),A.setDate(A.getDate()-C),A.toISOString()}function P(){const C=new Date;return new Date(C.getFullYear(),0,1).toISOString()}function x(C,A=null){const O=m();C===null?delete O.created_after:O.created_after=C,A===null?delete O.created_before:O.created_before=A,p(O),g(!0)}function M(C){const A=m();delete A[C],p(A)}function E(){p({sort:t.filters.sort??"newest"}),n("clear")}function D(C){if(!i.value)return;const A=l.value;A!==null&&(C.target instanceof Node&&A.contains(C.target)||g(!1))}function j(C){!i.value||C.key!=="Escape"||(C.preventDefault(),g(!0))}e.onMounted(()=>{document.addEventListener("pointerdown",D,!0),document.addEventListener("keydown",j)}),e.onBeforeUnmount(()=>{document.removeEventListener("pointerdown",D,!0),document.removeEventListener("keydown",j)});const L=e.computed(()=>{const C=[];for(const A of t.filters.kinds??[]){const O=A==="image"?u.value.imageLabel:A==="video"?u.value.videoLabel:String(A);C.push({key:`kind-${A}`,label:`${u.value.typeLabel}: ${O}`,remove:()=>f(A)})}return(t.filters.usage_status==="used"||t.filters.usage_status==="not_used")&&C.push({key:"usage",label:`${u.value.usageLabel}: ${t.filters.usage_status==="used"?u.value.usedLabel:u.value.notUsedLabel}`,remove:v}),t.filters.metadata_status&&C.push({key:"metadata-status",label:`${u.value.metadataLabel}: ${w(t.filters.metadata_status)}`,remove:_}),t.filters.created_after&&C.push({key:"created-after",label:`${u.value.dateAfterLabel}: ${t.filters.created_after}`,remove:()=>M("created_after")}),t.filters.created_before&&C.push({key:"created-before",label:`${u.value.dateBeforeLabel}: ${t.filters.created_before}`,remove:()=>M("created_before")}),t.filters.query&&t.filters.query.trim()!==""&&C.push({key:"query",label:`${u.value.searchLabel}: "${t.filters.query.trim()}"`,remove:()=>M("query")}),C});return(C,A)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"rootRef",ref:l,class:"media-filter-chips","data-testid":"media-filter-chips"},[e.createElementVNode("div",KA,[t.scopeLabel!==""?(e.openBlock(),e.createElementBlock("span",qA,e.toDisplayString(t.scopeLabel),1)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(L.value,O=>(e.openBlock(),e.createElementBlock("button",{key:O.key,type:"button",class:"media-filter-chips__chip","data-testid":`media-filter-chip-${O.key}`,"aria-label":`Remove filter ${O.label}`,onClick:O.remove},[e.createElementVNode("span",null,e.toDisplayString(O.label),1),A[14]||(A[14]=e.createElementVNode("span",{"aria-hidden":"true"},"×",-1))],8,JA))),128)),L.value.length>=2?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"media-filter-chips__clear","data-testid":"btn-media-filter-clear-all",onClick:E},e.toDisplayString(u.value.clearAll),1)):e.createCommentVNode("",!0)]),e.createElementVNode("div",YA,[e.createElementVNode("button",{ref_key:"triggerRef",ref:s,type:"button",class:"media-filter-chips__add","data-testid":"btn-media-filter-add","aria-haspopup":"dialog","aria-controls":e.unref(c),"aria-expanded":i.value?"true":"false",onClick:T}," + "+e.toDisplayString(u.value.addFilter),9,QA),i.value?(e.openBlock(),e.createElementBlock("div",{key:0,id:e.unref(c),class:"media-filter-chips__menu","data-testid":"media-filter-menu",role:"dialog","aria-label":u.value.addFilter},[e.createElementVNode("form",{class:"media-filter-chips__search","data-testid":"media-filter-query-form",onSubmit:e.withModifiers($,["prevent"])},[e.withDirectives(e.createElementVNode("input",{ref_key:"queryInputRef",ref:d,"onUpdate:modelValue":A[0]||(A[0]=O=>r.value=O),type:"search",class:"media-filter-chips__search-input","data-testid":"input-media-filter-query",placeholder:u.value.searchPlaceholder,"aria-label":u.value.searchPlaceholder},null,8,tR),[[e.vModelText,r.value]]),e.createElementVNode("div",aR,[e.createElementVNode("button",nR,e.toDisplayString(u.value.applySearch),1),e.createElementVNode("button",{type:"button",class:"media-filter-chips__search-button media-filter-chips__search-button--muted","data-testid":"btn-media-filter-query-clear",onClick:N},e.toDisplayString(u.value.clearSearch),1)])],32),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-image",onClick:A[1]||(A[1]=O=>h("image"))},e.toDisplayString(u.value.typeLabel)+": "+e.toDisplayString(u.value.imageLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-video",onClick:A[2]||(A[2]=O=>h("video"))},e.toDisplayString(u.value.typeLabel)+": "+e.toDisplayString(u.value.videoLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-used",onClick:A[3]||(A[3]=O=>y("used"))},e.toDisplayString(u.value.usageLabel)+": "+e.toDisplayString(u.value.usedLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-not-used",onClick:A[4]||(A[4]=O=>y("not_used"))},e.toDisplayString(u.value.usageLabel)+": "+e.toDisplayString(u.value.notUsedLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-missing-alt",onClick:A[5]||(A[5]=O=>b("missing_alt"))},e.toDisplayString(u.value.metadataLabel)+": "+e.toDisplayString(u.value.missingAltLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-has-alt",onClick:A[6]||(A[6]=O=>b("has_alt"))},e.toDisplayString(u.value.metadataLabel)+": "+e.toDisplayString(u.value.hasAltLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-missing-caption",onClick:A[7]||(A[7]=O=>b("missing_caption"))},e.toDisplayString(u.value.metadataLabel)+": "+e.toDisplayString(u.value.missingCaptionLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-has-caption",onClick:A[8]||(A[8]=O=>b("has_caption"))},e.toDisplayString(u.value.metadataLabel)+": "+e.toDisplayString(u.value.hasCaptionLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-has-tags",onClick:A[9]||(A[9]=O=>b("has_tags"))},e.toDisplayString(u.value.metadataLabel)+": "+e.toDisplayString(u.value.hasTagsLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-decorative",onClick:A[10]||(A[10]=O=>b("decorative"))},e.toDisplayString(u.value.metadataLabel)+": "+e.toDisplayString(u.value.decorativeLabel),1),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-date-7d",onClick:A[11]||(A[11]=O=>x(B(7)))},"Date: Last 7 days"),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-date-30d",onClick:A[12]||(A[12]=O=>x(B(30)))},"Date: Last 30 days"),e.createElementVNode("button",{type:"button","data-testid":"opt-filter-date-year",onClick:A[13]||(A[13]=O=>x(P()))},"Date: This year")],8,eR)):e.createCommentVNode("",!0)])],512))}}),Jf=Ae(oR,[["__scopeId","data-v-42cb25b6"]]);class Wl extends Error{constructor(a,t="Media deletion requires explicit confirmation."){super(t),this.name="RequiresConfirmationError",this.softBlocks=a}}const iR="/v1/media/deletion/check",rR="/v1/media/deletion/delete",Mr=100;function em(o){const a=new Set,t=[];for(const n of o){const i=n.trim().toLowerCase();i===""||a.has(i)||(a.add(i),t.push(i))}return t.sort()}function Jd(o){const a=o.checkEndpoint??iR,t=o.deleteEndpoint??rR,n=e.ref(!1),i=e.ref(!1),r=e.ref(null),l=e.ref(null),s=e.ref(null);async function d(f){s.value=null;const h=em(f);if(h.length===0)return r.value=[],[];if(h.length>Mr){const v=new Error(`Cannot check more than ${Mr} media items at once.`);throw s.value=v,v}n.value=!0;try{const v=await o.httpClient.post(a,{uuids:h}),y=((v==null?void 0:v.data)??[]).map(w=>{var _,b,g,I;return{uuid:w.uuid,canDelete:((_=w.report)==null?void 0:_.canDelete)??!1,blocks:Array.isArray((b=w.report)==null?void 0:b.blocks)?w.report.blocks:[],cascade:Array.isArray((g=w.report)==null?void 0:g.cascade)?w.report.cascade:[],variantCount:typeof((I=w.report)==null?void 0:I.variantCount)=="number"?w.report.variantCount:0}});return r.value=y,y}catch(v){throw s.value=v instanceof Error?v:new Error(String(v)),s.value}finally{n.value=!1}}async function c(f,h={}){s.value=null;const v=em(f);if(v.length===0){const y={results:[],summary:{}};return l.value=y,y}if(v.length>Mr){const y=new Error(`Cannot delete more than ${Mr} media items at once.`);throw s.value=y,y}i.value=!0;try{const y=await o.httpClient.post(t,{uuids:v,force:h.force===!0,confirmed:h.confirmed===!0}),w={results:Array.isArray(y==null?void 0:y.results)?y.results:[],summary:(y==null?void 0:y.summary)??{}};return l.value=w,w}catch(y){const w=u(y);if(w&&w.requires_confirmation===!0){const _=m(w.soft_blocks),b=new Wl(_);throw s.value=b,b}throw s.value=y instanceof Error?y:new Error(String(y)),s.value}finally{i.value=!1}}function u(f){if(typeof f!="object"||f===null)return null;const h=f;if(h.response&&typeof h.response=="object"&&h.response.data&&typeof h.response.data=="object")return h.response.data;const v=f;return"requires_confirmation"in v||"soft_blocks"in v?v:null}function m(f){if(typeof f!="object"||f===null)return{};const h={};for(const[v,y]of Object.entries(f)){if(!Array.isArray(y))continue;const w=[];for(const _ of y){if(typeof _!="object"||_===null)continue;const b=_;typeof b.type=="string"&&typeof b.context=="string"&&w.push({type:b.type,context:b.context})}h[v]=w}return h}function p(){r.value=null,l.value=null,s.value=null}return{isChecking:n,isDeleting:i,lastReport:r,lastResponse:l,error:s,checkDependencies:d,deleteMany:c,reset:p}}const lR="/v1/user/media/trash";function sR(o){return`/v1/user/media/${encodeURIComponent(o)}/restore`}function dR(o){return`/v1/user/media/${encodeURIComponent(o)}/purge`}function Yd(o){const a=o.listEndpoint??lR,t=o.buildRestoreEndpoint??sR,n=o.buildPurgeEndpoint??dR,i=o.perPage??50,r=e.ref([]),l=e.ref(0),s=e.ref(1),d=e.ref(!1),c=e.ref(!1),u=e.ref(!1),m=e.ref(null);async function p(y=1){var w,_;m.value=null,d.value=!0;try{const b=await o.httpClient.get(a,{params:{page:y,per_page:i}});r.value=Array.isArray(b==null?void 0:b.data)?b.data:[],l.value=typeof((w=b==null?void 0:b.meta)==null?void 0:w.total)=="number"?b.meta.total:0,s.value=typeof((_=b==null?void 0:b.meta)==null?void 0:_.current_page)=="number"?b.meta.current_page:y}catch(b){throw m.value=b instanceof Error?b:new Error(String(b)),m.value}finally{d.value=!1}}async function f(y){m.value=null,c.value=!0;try{const w=await o.httpClient.post(t(y)),_={status:(w==null?void 0:w.status)??"failed",data:(w==null?void 0:w.data)??null,duplicate_uuid:(w==null?void 0:w.duplicate_uuid)??null};return typeof(w==null?void 0:w.message)=="string"&&(_.message=w.message),_.status==="restored"&&(r.value=r.value.filter(b=>b.uuid!==y),l.value=Math.max(0,l.value-1)),_}catch(w){const _=tm(w);if(_&&typeof _.status=="string"){const b={status:_.status,duplicate_uuid:typeof _.duplicate_uuid=="string"?_.duplicate_uuid:null};return typeof _.message=="string"&&(b.message=_.message),b}throw m.value=w instanceof Error?w:new Error(String(w)),m.value}finally{c.value=!1}}async function h(y){m.value=null,u.value=!0;try{if(typeof o.httpClient.delete!="function")throw new Error("Media trash purge requires an HTTP client with delete support.");const w=await o.httpClient.delete(n(y)),_={status:(w==null?void 0:w.status)??"failed"};return typeof(w==null?void 0:w.message)=="string"&&(_.message=w.message),_.status==="purging"&&(r.value=r.value.filter(b=>b.uuid!==y),l.value=Math.max(0,l.value-1)),_}catch(w){const _=tm(w);if(_&&typeof _.status=="string"){const b={status:_.status};return typeof _.message=="string"&&(b.message=_.message),b}throw m.value=w instanceof Error?w:new Error(String(w)),m.value}finally{u.value=!1}}function v(){r.value=[],l.value=0,s.value=1,m.value=null}return{items:r,total:l,currentPage:s,isLoading:d,isRestoring:c,isPurging:u,error:m,fetch:p,restore:f,purge:h,reset:v}}function tm(o){var t;if(typeof o!="object"||o===null)return null;const a=o;return(t=a.response)!=null&&t.data&&typeof a.response.data=="object"?a.response.data:null}const cR={class:"media-management-view","data-testid":"media-management-view"},uR={key:0,class:"media-management-view__header"},mR={class:"media-management-view__title"},pR={class:"media-management-view__actions"},fR={key:0,class:"media-management-view__badge"},hR={key:1,class:"media-management-view__panel","data-testid":"panel-library"},vR={key:0,class:"media-management-view__view-mode",role:"radiogroup","aria-label":"Media library layout","data-testid":"media-management-layout-mode"},gR=["aria-checked"],bR=["aria-checked"],yR={key:1,class:"media-management-view__status","data-testid":"library-loading"},wR={key:2,class:"media-management-view__status media-management-view__status--error","data-testid":"library-error"},kR={key:3,class:"media-management-view__empty","data-testid":"library-empty"},_R={class:"media-management-view__empty-state"},ER={class:"media-management-view__empty-title","data-testid":"library-empty-title"},SR={class:"media-management-view__empty-description","data-testid":"library-empty-description"},CR={key:4,class:"media-management-view__table","data-testid":"library-table"},xR={scope:"col","data-testid":"table-header-select"},NR={class:"media-management-view__checkbox-label"},VR=["checked",".indeterminate","aria-label"],TR={class:"media-management-view__sr-only"},BR={scope:"col","data-testid":"table-header-thumbnail"},MR={scope:"col","data-testid":"table-header-name"},IR={scope:"col","data-testid":"table-header-type"},$R={scope:"col","data-testid":"table-header-created"},FR={scope:"col","data-testid":"table-header-size"},DR={scope:"col","data-testid":"table-header-status"},AR={scope:"col","data-testid":"table-header-actions"},RR=["data-testid"],LR={class:"media-management-view__checkbox-label"},PR=["checked","aria-label","data-testid","onChange"],UR=["data-testid","onClick"],OR=["src","alt","onError"],zR=["data-testid"],jR=["title","data-testid"],WR=["data-testid"],HR=["data-testid"],ZR={class:"media-management-view__item-actions"},GR=["onKeydown"],XR=["data-testid","aria-label","aria-expanded","onClick"],KR=["data-testid"],qR=["data-testid","onClick"],JR={key:5,class:"media-management-view__grid","data-testid":"library-grid"},YR=["data-testid"],QR=["data-testid","aria-pressed","onClick"],eL=["src","alt","onError"],tL=["data-testid"],aL={class:"media-management-view__selection-corner"},nL={class:"media-management-view__sr-only"},oL=["checked","data-testid","onChange"],iL={class:"media-management-view__item-meta"},rL=["title","data-testid"],lL=["data-testid"],sL=["data-testid"],dL={key:2,class:"media-management-view__item-badge","data-testid":"badge-orphaned"},cL=["data-testid"],uL={class:"media-management-view__item-actions media-management-view__item-actions--grid"},mL=["onKeydown"],pL=["data-testid","aria-label","aria-expanded","onClick"],fL=["data-testid"],hL=["data-testid","onClick"],vL={class:"media-management-view__bulk-bar","data-testid":"bulk-bar"},gL={"data-testid":"bulk-count"},bL=["disabled"],yL={key:7,class:"media-management-view__pagination","data-testid":"media-management-pagination"},wL={class:"media-management-view__pagination-count","data-testid":"media-management-pagination-count","aria-live":"polite"},kL={key:0,class:"media-management-view__page-size",role:"group","aria-label":"Items per page","data-testid":"media-management-page-size"},_L=["value","disabled"],EL=["value","data-testid"],SL=["disabled"],CL={key:2,class:"media-management-view__page-bar","aria-label":"Media library pagination","data-testid":"media-management-page-bar"},xL=["disabled"],NL=["data-testid","disabled","aria-current","aria-label","onClick"],VL=["disabled"],TL={key:2,class:"media-management-view__panel","data-testid":"panel-trash"},BL={key:0,class:"media-management-view__status","data-testid":"trash-loading"},ML={key:1,class:"media-management-view__empty","data-testid":"trash-empty"},IL={class:"media-management-view__empty-state"},$L={class:"media-management-view__empty-title","data-testid":"trash-empty-title"},FL={class:"media-management-view__empty-description","data-testid":"trash-empty-description"},DL={key:2,class:"media-management-view__grid","data-testid":"trash-grid"},AL=["data-testid"],RL={class:"media-management-view__item-thumb"},LL=["src","alt","onError"],PL=["data-testid"],UL={class:"media-management-view__item-meta"},OL={class:"media-management-view__item-name"},zL={key:0,class:"media-management-view__item-meta-line"},jL=["data-testid","disabled","onClick"],WL=["data-testid"],HL=e.defineComponent({__name:"MediaManagementView",props:{httpClient:{},capabilities:{default:()=>({})},labels:{default:()=>({})},filters:{},initialView:{},perPage:{},pageSizeOptions:{default:()=>[]},showAllOption:{type:Boolean,default:!1},loadAllMaxItems:{},paginated:{type:Boolean,default:!1},groupVariants:{type:Boolean,default:!0},paginationWindow:{default:7},initialLayoutMode:{},layoutMode:{},confirmBulkDelete:{},confirmDestructiveAction:{},onRestoreCollision:{}},emits:["deleted","restored","restore-conflict","create-post","create-gallery","add-to-album","edit","update:layoutMode","error"],setup(o,{expose:a,emit:t}){const n=o,i=t,r=e.computed(()=>({showTrash:!0,showHeader:!0,showLayoutSwitcher:!0,allowBulkDelete:!0,allowPreview:!0,allowCreatePost:!1,allowCreateGallery:!1,allowAddToAlbum:!1,allowImageEdit:!1,allowVideoEdit:!1,showOwner:!1,showRawFileName:!1,...n.capabilities})),l=e.computed(()=>{var q,ke,oe,$e,At,zt,Ft,wt,yt,Yt,Et,Kt,Ca,X,Y,fe,he,Te,Ke,ct,tt,qe,vt,gt,ot,Qt,Rt,Za,ha,Cn,Ta,xa,Aa,va,Qa,On,Ga,zn,ga;return{title:((q=n.labels)==null?void 0:q.title)??"My Media",libraryTab:((ke=n.labels)==null?void 0:ke.libraryTab)??"Library",trashTab:((oe=n.labels)==null?void 0:oe.trashTab)??"Trash",loading:(($e=n.labels)==null?void 0:$e.loading)??"Loading…",emptyLibrary:((At=n.labels)==null?void 0:At.emptyLibrary)??"No media yet — upload your first creation.",emptyLibraryTitle:((zt=n.labels)==null?void 0:zt.emptyLibraryTitle)??"Your media library is ready",emptyLibraryDescription:((Ft=n.labels)==null?void 0:Ft.emptyLibraryDescription)??"Images and videos you upload for creations are saved here so you can reuse them later.",emptyTrash:((wt=n.labels)==null?void 0:wt.emptyTrash)??"Trash is empty.",emptyTrashTitle:((yt=n.labels)==null?void 0:yt.emptyTrashTitle)??"No media in trash",emptyTrashDescription:((Yt=n.labels)==null?void 0:Yt.emptyTrashDescription)??"Deleted files appear here for 30 days before permanent removal.",orphanedBadge:((Et=n.labels)==null?void 0:Et.orphanedBadge)??"Not in use",selectedCount:((Kt=n.labels)==null?void 0:Kt.selectedCount)??(Ra=>`${Ra} selected`),deleteButton:((Ca=n.labels)==null?void 0:Ca.deleteButton)??"Delete",createPostButton:((X=n.labels)==null?void 0:X.createPostButton)??"Create Post",createGalleryButton:((Y=n.labels)==null?void 0:Y.createGalleryButton)??"Create Gallery",addToAlbumButton:((fe=n.labels)==null?void 0:fe.addToAlbumButton)??"Add to Album",previewButton:((he=n.labels)==null?void 0:he.previewButton)??"Preview",previewCloseButton:((Te=n.labels)==null?void 0:Te.previewCloseButton)??"Close",previewPreviousButton:((Ke=n.labels)==null?void 0:Ke.previewPreviousButton)??"Previous",previewNextButton:((ct=n.labels)==null?void 0:ct.previewNextButton)??"Next",previewSelectButton:((tt=n.labels)==null?void 0:tt.previewSelectButton)??"Select",previewDeselectButton:((qe=n.labels)==null?void 0:qe.previewDeselectButton)??"Deselect",editButton:((vt=n.labels)==null?void 0:vt.editButton)??"Edit",loadMoreButton:((gt=n.labels)==null?void 0:gt.loadMoreButton)??"Load more",loadingMoreButton:((ot=n.labels)==null?void 0:ot.loadingMoreButton)??"Loading more...",restoreButton:((Qt=n.labels)==null?void 0:Qt.restoreButton)??"Restore",restoreUnavailable:((Rt=n.labels)==null?void 0:Rt.restoreUnavailable)??"Restore unavailable",gridView:((Za=n.labels)==null?void 0:Za.gridView)??"Grid",tableView:((ha=n.labels)==null?void 0:ha.tableView)??"Table",tableSelectHeader:((Cn=n.labels)==null?void 0:Cn.tableSelectHeader)??"Select",tableThumbnailHeader:((Ta=n.labels)==null?void 0:Ta.tableThumbnailHeader)??"Preview",tableNameHeader:((xa=n.labels)==null?void 0:xa.tableNameHeader)??"Name",tableTypeHeader:((Aa=n.labels)==null?void 0:Aa.tableTypeHeader)??"Type",tableCreatedHeader:((va=n.labels)==null?void 0:va.tableCreatedHeader)??"Uploaded",tableSizeHeader:((Qa=n.labels)==null?void 0:Qa.tableSizeHeader)??"Size",tableStatusHeader:((On=n.labels)==null?void 0:On.tableStatusHeader)??"Status",tableActionsHeader:((Ga=n.labels)==null?void 0:Ga.tableActionsHeader)??"Actions",purgeAfter:((zn=n.labels)==null?void 0:zn.purgeAfter)??(Ra=>`Purges ${Ra}`),ownerLabel:((ga=n.labels)==null?void 0:ga.ownerLabel)??(Ra=>`User ${Ra.user_id??""}`)}}),s=e.computed(()=>l.value.title),d=e.computed(()=>l.value.libraryTab),c=e.computed(()=>l.value.trashTab),u=e.computed(()=>l.value.loading),m=e.computed(()=>l.value.emptyLibraryTitle),p=e.computed(()=>l.value.emptyLibraryDescription),f=e.computed(()=>l.value.emptyTrashTitle),h=e.computed(()=>l.value.emptyTrashDescription),v=e.computed(()=>l.value.orphanedBadge),y=e.computed(()=>l.value.deleteButton),w=e.computed(()=>l.value.restoreButton),_=e.computed(()=>l.value.restoreUnavailable),b=e.computed(()=>l.value.gridView),g=e.computed(()=>l.value.tableView);function I(q){const ke=r.value.canRestore;return ke?ke(q):!0}const T=e.ref("library"),$=e.ref(n.layoutMode??n.initialLayoutMode??"grid"),N=e.ref(null),B=e.ref(null);function P(q){return{...q??{},...(q==null?void 0:q.kinds)!==void 0?{kinds:[...q.kinds]}:{}}}const x=e.ref(n.initialView??{scope:"library"}),M=e.ref(P(n.filters)),E=e.ref(n.perPage??50),D=e.ref(!1),j=e.ref(n.paginated?1:null),L=Xd({httpClient:n.httpClient,view:x,filters:M,perPage:E,page:j}),z=e.computed(()=>n.groupVariants!==!0?L.items.value:L.items.value.filter(q=>typeof q.parent_media_uuid!="string"||q.parent_media_uuid.trim()==="")),C=e.computed(()=>L.loading.value),A=e.computed(()=>{var q;return((q=L.error.value)==null?void 0:q.message)??null}),O=e.computed(()=>r.value.allowBulkDelete!==!1||r.value.allowCreatePost===!0||r.value.allowCreateGallery===!0||r.value.allowAddToAlbum===!0),K=e.computed(()=>{const q=N.value;return q===null?null:z.value[q]??null}),se=fl(z),xe=Jd({httpClient:n.httpClient}),ue=Yd({httpClient:n.httpClient});function le(q){return l.value.selectedCount(q)}function Z(q){return l.value.purgeAfter(q)}function k(q){return l.value.ownerLabel(q)}const F=e.computed(()=>{const q=z.value.length;return q===0?"":L.hasMore.value?q===1?"Showing 1 item":`Showing ${q} items`:q===1?"Showing all 1 item":`Showing all ${q} items`});function W(q){$.value!==q&&(Ut(),$.value=q,i("update:layoutMode",q))}function J(q){return q.mime_type.startsWith("image/")}function ce(q){return q.mime_type.startsWith("video/")}function Ue(q){return J(q)?"image":ce(q)?"video":null}function be(q){return J(q)?r.value.allowImageEdit===!0:ce(q)?r.value.allowVideoEdit===!0:!1}const _e=Xf;function ye(q){return typeof q.variant_count=="number"&&Number.isFinite(q.variant_count)?Math.max(0,q.variant_count):0}function Ne(q){return q===1?"1 edit":`${q} edits`}function Se(q){return J(q)?"Image":ce(q)?"Video":q.mime_type.startsWith("audio/")?"Audio":"File"}function Re(q){if(typeof q.formatted_size=="string"&&q.formatted_size.trim()!=="")return q.formatted_size;if(!Number.isFinite(q.size)||q.size<=0)return"";const ke=["B","KB","MB","GB"];let oe=q.size,$e=0;for(;oe>=1024&&$e<ke.length-1;)oe/=1024,$e+=1;return`${oe>=10||$e===0?Math.round(oe):oe.toFixed(1)} ${ke[$e]}`}function Oe(q){const ke=new Date(q.created_at);return Number.isNaN(ke.getTime())?q.created_at:new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(ke)}function it(q){return q.deletion_status==="active"||q.deletion_status===void 0||q.deletion_status===null?"Ready":q.deletion_status.replace(/_/g," ").replace(/\b\w/g,ke=>ke.toUpperCase())}function rt(q){if(typeof q.thumbnail_url=="string"&&q.thumbnail_url.length>0)return q.thumbnail_url;const ke=typeof q.mime_type=="string"&&q.mime_type.startsWith("image/"),oe=typeof q.mime_type=="string"&&q.mime_type.startsWith("video/");return ke?q.original_url||null:oe&&typeof q.preview_url=="string"&&q.preview_url.length>0?q.preview_url:null}function Pt(q){return typeof q.mime_type=="string"&&q.mime_type.startsWith("video/")?`Video — ${q.file_name}`:q.file_name}const bt=e.ref(new Set);function Ct(q){if(bt.value.has(q.uuid))return;const ke=new Set(bt.value);ke.add(q.uuid),bt.value=ke}function mt(q){if(r.value.allowPreview===!1)return;const ke=z.value.findIndex(oe=>oe.uuid===q.uuid);N.value=ke>=0?ke:null}function pt(){N.value=null}function Nt(){N.value===null||N.value<=0||(N.value-=1)}function Ce(){N.value===null||N.value>=z.value.length-1||(N.value+=1)}async function Ve(){try{await L.loadMore()}catch(q){i("error",q instanceof Error?q:new Error(String(q)))}}const Le=e.computed(()=>{const q=L.totalPages.value??0,ke=L.currentPage.value??1;if(q<=1)return[];const oe=Math.max(3,n.paginationWindow);if(q<=oe)return Array.from({length:q},(yt,Yt)=>({kind:"page",key:`p-${Yt+1}`,value:Yt+1}));const $e=oe-2,At=Math.floor($e/2);let zt=Math.max(2,ke-At),Ft=Math.min(q-1,zt+$e-1);Ft===q-1&&(zt=Math.max(2,Ft-$e+1));const wt=[{kind:"page",key:"p-1",value:1}];zt>2&&wt.push({kind:"ellipsis",key:"el-left"});for(let yt=zt;yt<=Ft;yt++)wt.push({kind:"page",key:`p-${yt}`,value:yt});return Ft<q-1&&wt.push({kind:"ellipsis",key:"el-right"}),wt.push({kind:"page",key:`p-${q}`,value:q}),wt});async function nt(q){if(!(q===L.currentPage.value||L.loading.value)){j.value=q;try{await L.goToPage(q)}catch(ke){i("error",ke instanceof Error?ke:new Error(String(ke)))}}}async function Ge(q){const ke=L.currentPage.value??1,oe=L.totalPages.value??1,$e=Math.min(Math.max(1,ke+q),oe);$e!==ke&&await nt($e)}const Je=e.computed(()=>{const q=n.pageSizeOptions.map(ke=>({value:String(ke),label:String(ke)}));return q.length===0&&!n.showAllOption?[]:(n.showAllOption&&q.push({value:"all",label:"All"}),q)}),_t=e.computed(()=>D.value?"all":String(E.value));async function ht(q){const ke=q.target;if(!(ke instanceof HTMLSelectElement))return;const oe=ke.value;try{if(oe==="all"){const $e=n.pageSizeOptions,At=$e.length>0?Math.max(...$e):E.value;j.value=null,E.value=At,D.value=!1,await L.refresh();const zt=n.loadAllMaxItems!==void 0?{maxItems:n.loadAllMaxItems}:void 0;await L.loadAll(zt),D.value=!L.hasMore.value}else{const $e=Number.parseInt(oe,10);Number.isFinite($e)&&$e>0&&(E.value=$e),D.value=!1,n.paginated&&(j.value=1),await L.refresh()}}catch($e){i("error",$e instanceof Error?$e:new Error(String($e)))}}function Wt(q,ke){i("create-post",{mediaIds:q.map(oe=>oe.uuid),items:q,source:ke})}function Pe(q,ke){i("create-gallery",{mediaIds:q.map(oe=>oe.uuid),items:q,source:ke})}function Ht(q,ke){i("add-to-album",{mediaIds:q.map(oe=>oe.uuid),items:q,source:ke})}function Zt(q){const ke=Ue(q);ke===null||!be(q)||i("edit",{media:q,kind:ke})}function It(q){B.value=B.value===q?null:q}function Ut(){B.value=null}function Gt(q){q.run(),Ut()}function sa(q){const ke=[];return r.value.allowPreview!==!1&&ke.push({id:"preview",label:l.value.previewButton,testId:`btn-preview-${q.uuid}`,run:()=>mt(q)}),be(q)&&ke.push({id:"edit",label:l.value.editButton,testId:`btn-edit-${q.uuid}`,run:()=>Zt(q)}),r.value.allowCreatePost===!0&&ke.push({id:"create-post",label:l.value.createPostButton,testId:`btn-create-post-${q.uuid}`,run:()=>Wt([q],"item")}),r.value.allowCreateGallery===!0&&ke.push({id:"create-gallery",label:l.value.createGalleryButton,testId:`btn-create-gallery-${q.uuid}`,run:()=>Pe([q],"item")}),r.value.allowAddToAlbum===!0&&ke.push({id:"add-to-album",label:l.value.addToAlbumButton,testId:`btn-add-to-album-${q.uuid}`,run:()=>Ht([q],"item")}),ke}async function ae(q){const ke=q.results.filter(oe=>oe.status==="trashed"||oe.status==="already_trashed").map(oe=>oe.uuid);if(ke.length!==0){for(const oe of ke)se.deselect(oe);i("deleted",ke),await L.refresh(),r.value.showTrash!==!1&&await ue.fetch(ue.currentPage.value).catch(()=>{})}}function ge(q){const ke=new Set;for(const At of q)for(const zt of At.blocks)zt.context&&ke.add(zt.context);const oe=Array.from(ke),$e=oe.length>0?`This media is still attached to: ${oe.map(At=>`"${At}"`).join(", ")}. Remove from those and delete?`:"This media is still attached to other items. Remove from those and delete?";return window.confirm($e)}function pe(q){return Object.entries(q).map(([ke,oe])=>({uuid:ke,blocks:oe}))}async function me(){const q=se.selectedItems.value;if(q.length===0)return;const ke=r.value.canDelete?q.filter($e=>r.value.canDelete($e)):q;if(ke.length===0||n.confirmBulkDelete&&!await n.confirmBulkDelete(ke))return;const oe=ke.map($e=>$e.uuid);try{const $e=await xe.deleteMany(oe);await ae($e)}catch($e){if($e instanceof Wl){const At=pe($e.softBlocks);if(!(n.confirmDestructiveAction?await n.confirmDestructiveAction({items:ke,softBlocks:At}):ge(At)))return;try{const Ft=await xe.deleteMany(oe,{confirmed:!0});await ae(Ft)}catch(Ft){i("error",Ft instanceof Error?Ft:new Error(String(Ft)))}return}i("error",$e instanceof Error?$e:new Error(String($e)))}}async function Be(q){var oe;const ke=ue.items.value.find($e=>$e.uuid===q);if(!(ke&&!I(ke)))try{const $e=await ue.restore(q);if($e.status==="restored"){i("restored",q),await L.refresh().catch(()=>{});return}if($e.status==="duplicate_conflict"){i("restore-conflict",{uuid:q,duplicateUuid:$e.duplicate_uuid??null}),(oe=n.onRestoreCollision)==null||oe.call(n,q,$e.duplicate_uuid??null);return}}catch($e){i("error",$e instanceof Error?$e:new Error(String($e)))}}async function He(){T.value="trash",ue.items.value.length===0&&!ue.isLoading.value&&await ue.fetch().catch(q=>{i("error",q instanceof Error?q:new Error(String(q)))})}function lt(q){if(q==="trash"){He();return}T.value=q}const Vt=e.computed(()=>({activeTab:T.value,setActiveTab:lt,trashCount:ue.total.value,showTrash:r.value.showTrash!==!1,labels:{libraryTab:l.value.libraryTab,trashTab:l.value.trashTab}})),Ot=e.computed(()=>({selectedCount:se.selectedCount.value,selectedItemIds:Array.from(se.selectedIds.value),selectedItems:se.selectedItems.value,crossPageCount:se.crossPageCount.value,isDeleting:xe.isDeleting.value,onBulkDelete:me,...r.value.allowCreatePost===!0?{onCreatePost:()=>Wt(se.selectedItems.value,"bulk")}:{},...r.value.allowCreateGallery===!0?{onCreateGallery:()=>Pe(se.selectedItems.value,"bulk")}:{},...r.value.allowAddToAlbum===!0?{onAddToAlbum:()=>Ht(se.selectedItems.value,"bulk")}:{},clearSelection:se.clear,labels:{deleteButton:l.value.deleteButton,...r.value.allowCreatePost===!0?{createPostButton:l.value.createPostButton}:{},...r.value.allowCreateGallery===!0?{createGalleryButton:l.value.createGalleryButton}:{},...r.value.allowAddToAlbum===!0?{addToAlbumButton:l.value.addToAlbumButton}:{},selectedCount:l.value.selectedCount}})),$t=e.computed(()=>({filters:M.value,view:x.value,total:L.total.value,shown:z.value.length,loading:L.loading.value}));function st(q){return{media:q,selected:se.isSelected(q.uuid),canEdit:be(q),onPreview:()=>mt(q),...be(q)?{onEdit:()=>Zt(q)}:{},...r.value.allowCreatePost===!0?{onCreatePost:()=>Wt([q],"item")}:{},...r.value.allowCreateGallery===!0?{onCreateGallery:()=>Pe([q],"item")}:{},...r.value.allowAddToAlbum===!0?{onAddToAlbum:()=>Ht([q],"item")}:{},labels:{previewButton:l.value.previewButton,editButton:l.value.editButton,createPostButton:l.value.createPostButton,createGalleryButton:l.value.createGalleryButton,addToAlbumButton:l.value.addToAlbumButton}}}function Jt(q){return{media:q,canRestore:I(q),isRestoring:ue.isRestoring.value,onRestore:()=>Be(q.uuid),labels:{restoreButton:l.value.restoreButton,restoreUnavailable:l.value.restoreUnavailable}}}return e.watch(T,async q=>{q==="library"&&z.value.length===0&&!C.value&&await L.refresh().catch(()=>{})}),e.watch(()=>n.layoutMode,q=>{q!==void 0&&($.value=q)}),e.watch(()=>n.filters,async q=>{M.value=P(q),se.clear(),pt(),await L.refresh().catch(ke=>{i("error",ke instanceof Error?ke:new Error(String(ke)))})},{deep:!0}),e.onMounted(async()=>{await L.refresh().catch(q=>{i("error",q instanceof Error?q:new Error(String(q)))}),r.value.showTrash!==!1&&ue.fetch().catch(()=>{})}),a({refresh:()=>L.refresh(),refreshTrash:()=>ue.fetch(),selection:se,deletion:xe,trash:ue}),(q,ke)=>(e.openBlock(),e.createElementBlock("div",cR,[r.value.showHeader!==!1?(e.openBlock(),e.createElementBlock("header",uR,[e.createElementVNode("h2",mR,e.toDisplayString(s.value),1),e.createElementVNode("div",pR,[e.renderSlot(q.$slots,"tabs",e.normalizeProps(e.guardReactiveProps(Vt.value)),()=>[r.value.showTrash!==!1?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createElementVNode("button",{type:"button",class:e.normalizeClass(["media-management-view__tab-button",{"is-active":T.value==="library"}]),"data-testid":"tab-library",onClick:ke[0]||(ke[0]=oe=>T.value="library")},e.toDisplayString(d.value),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass(["media-management-view__tab-button",{"is-active":T.value==="trash"}]),"data-testid":"tab-trash",onClick:He},[e.createTextVNode(e.toDisplayString(c.value)+" ",1),e.unref(ue).total.value>0?(e.openBlock(),e.createElementBlock("span",fR,e.toDisplayString(e.unref(ue).total.value),1)):e.createCommentVNode("",!0)],2)],64)):e.createCommentVNode("",!0)],!0)])])):e.createCommentVNode("",!0),T.value==="library"?(e.openBlock(),e.createElementBlock("section",hR,[r.value.showLayoutSwitcher!==!1?(e.openBlock(),e.createElementBlock("div",vR,[e.createElementVNode("button",{type:"button",role:"radio",class:e.normalizeClass(["media-management-view__view-mode-button",{"is-active":$.value==="grid"}]),"aria-checked":$.value==="grid"?"true":"false","data-testid":"view-mode-grid",onClick:ke[1]||(ke[1]=oe=>W("grid"))},e.toDisplayString(b.value),11,gR),e.createElementVNode("button",{type:"button",role:"radio",class:e.normalizeClass(["media-management-view__view-mode-button",{"is-active":$.value==="table"}]),"aria-checked":$.value==="table"?"true":"false","data-testid":"view-mode-table",onClick:ke[2]||(ke[2]=oe=>W("table"))},e.toDisplayString(g.value),11,bR)])):e.createCommentVNode("",!0),e.renderSlot(q.$slots,"filter-bar",e.normalizeProps(e.guardReactiveProps($t.value)),void 0,!0),C.value?(e.openBlock(),e.createElementBlock("div",yR,e.toDisplayString(u.value),1)):A.value?(e.openBlock(),e.createElementBlock("div",wR,e.toDisplayString(A.value),1)):z.value.length===0?(e.openBlock(),e.createElementBlock("div",kR,[e.renderSlot(q.$slots,"empty-library",{},()=>[e.createElementVNode("div",_R,[e.createElementVNode("p",ER,e.toDisplayString(m.value),1),e.createElementVNode("p",SR,e.toDisplayString(p.value),1)])],!0)])):$.value==="table"?(e.openBlock(),e.createElementBlock("table",CR,[e.createElementVNode("thead",null,[e.createElementVNode("tr",null,[e.createElementVNode("th",xR,[e.createElementVNode("label",NR,[e.createElementVNode("input",{class:"media-management-view__checkbox",type:"checkbox",checked:e.unref(se).isAllSelected.value,".indeterminate":e.unref(se).isSomeSelected.value&&!e.unref(se).isAllSelected.value,"aria-label":l.value.tableSelectHeader,"data-testid":"checkbox-select-all",onChange:ke[3]||(ke[3]=(...oe)=>e.unref(se).toggleAll&&e.unref(se).toggleAll(...oe))},null,40,VR),e.createElementVNode("span",TR,e.toDisplayString(l.value.tableSelectHeader),1)])]),e.createElementVNode("th",BR,e.toDisplayString(l.value.tableThumbnailHeader),1),e.createElementVNode("th",MR,e.toDisplayString(l.value.tableNameHeader),1),e.createElementVNode("th",IR,e.toDisplayString(l.value.tableTypeHeader),1),e.createElementVNode("th",$R,e.toDisplayString(l.value.tableCreatedHeader),1),e.createElementVNode("th",FR,e.toDisplayString(l.value.tableSizeHeader),1),e.createElementVNode("th",DR,e.toDisplayString(l.value.tableStatusHeader),1),e.createElementVNode("th",AR,e.toDisplayString(l.value.tableActionsHeader),1)])]),e.createElementVNode("tbody",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(z.value,oe=>(e.openBlock(),e.createElementBlock("tr",{key:oe.uuid,class:e.normalizeClass({"is-selected":e.unref(se).isSelected(oe.uuid),"has-open-actions":B.value===oe.uuid}),"data-testid":`media-row-${oe.uuid}`},[e.createElementVNode("td",null,[e.createElementVNode("label",LR,[e.createElementVNode("input",{class:"media-management-view__checkbox",type:"checkbox",checked:e.unref(se).isSelected(oe.uuid),"aria-label":`${l.value.tableSelectHeader} ${e.unref(_e)(oe)}`,"data-testid":`checkbox-select-${oe.uuid}`,onChange:$e=>e.unref(se).toggle(oe.uuid)},null,40,PR)])]),e.createElementVNode("td",null,[e.createElementVNode("button",{type:"button",class:"media-management-view__table-thumb","data-testid":`btn-preview-thumb-${oe.uuid}`,onClick:$e=>mt(oe)},[rt(oe)&&!bt.value.has(oe.uuid)?(e.openBlock(),e.createElementBlock("img",{key:0,src:rt(oe)??"",alt:oe.alt_text||oe.file_name,loading:"lazy",onError:$e=>Ct(oe)},null,40,OR)):(e.openBlock(),e.createElementBlock("span",{key:1,class:"media-management-view__item-placeholder","data-testid":`placeholder-${oe.uuid}`},e.toDisplayString(Pt(oe)),9,zR))],8,UR)]),e.createElementVNode("td",null,[e.createElementVNode("span",{class:"media-management-view__display-name",title:oe.file_name,"data-testid":`media-display-name-${oe.uuid}`},e.toDisplayString(e.unref(_e)(oe)),9,jR),ye(oe)>0?(e.openBlock(),e.createElementBlock("span",{key:0,class:"media-management-view__variant-badge","data-testid":`media-variant-badge-${oe.uuid}`},e.toDisplayString(Ne(ye(oe))),9,WR)):e.createCommentVNode("",!0),r.value.showRawFileName===!0?(e.openBlock(),e.createElementBlock("span",{key:1,class:"media-management-view__raw-filename","data-testid":`media-raw-filename-${oe.uuid}`},e.toDisplayString(oe.file_name),9,HR)):e.createCommentVNode("",!0)]),e.createElementVNode("td",null,e.toDisplayString(Se(oe)),1),e.createElementVNode("td",null,e.toDisplayString(Oe(oe)),1),e.createElementVNode("td",null,e.toDisplayString(Re(oe)),1),e.createElementVNode("td",null,e.toDisplayString(it(oe)),1),e.createElementVNode("td",null,[e.renderSlot(q.$slots,"item-actions",e.mergeProps({ref_for:!0},st(oe)),()=>[e.createElementVNode("div",ZR,[e.createElementVNode("div",{class:"media-management-view__action-menu",onKeydown:e.withKeys(e.withModifiers(Ut,["stop"]),["escape"])},[e.createElementVNode("button",{type:"button",class:"media-management-view__action-menu-trigger","data-testid":`btn-actions-menu-${oe.uuid}`,"aria-label":`Actions for ${e.unref(_e)(oe)}`,"aria-haspopup":"menu","aria-expanded":B.value===oe.uuid?"true":"false",onClick:$e=>It(oe.uuid)}," ... ",8,XR),B.value===oe.uuid?(e.openBlock(),e.createElementBlock("div",{key:0,class:"media-management-view__action-menu-panel",role:"menu","data-testid":`media-item-actions-menu-${oe.uuid}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(sa(oe),$e=>(e.openBlock(),e.createElementBlock("button",{key:$e.id,type:"button",class:"media-management-view__action-menu-item",role:"menuitem","data-testid":$e.testId,onClick:At=>Gt($e)},e.toDisplayString($e.label),9,qR))),128))],8,KR)):e.createCommentVNode("",!0)],40,GR)])],!0)])],10,RR))),128))])])):(e.openBlock(),e.createElementBlock("ul",JR,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(z.value,oe=>(e.openBlock(),e.createElementBlock("li",{key:oe.uuid,class:e.normalizeClass(["media-management-view__item",{"is-selected":e.unref(se).isSelected(oe.uuid),"has-open-actions":B.value===oe.uuid}]),"data-testid":`media-item-${oe.uuid}`},[e.createElementVNode("button",{type:"button",class:"media-management-view__item-thumb","data-testid":`btn-select-${oe.uuid}`,"aria-pressed":e.unref(se).isSelected(oe.uuid),onClick:$e=>e.unref(se).toggle(oe.uuid)},[rt(oe)&&!bt.value.has(oe.uuid)?(e.openBlock(),e.createElementBlock("img",{key:0,src:rt(oe)??"",alt:oe.alt_text||oe.file_name,loading:"lazy",onError:$e=>Ct(oe)},null,40,eL)):(e.openBlock(),e.createElementBlock("span",{key:1,class:"media-management-view__item-placeholder","data-testid":`placeholder-${oe.uuid}`},e.toDisplayString(Pt(oe)),9,tL))],8,QR),e.createElementVNode("label",aL,[e.createElementVNode("span",nL,e.toDisplayString(l.value.tableSelectHeader)+" "+e.toDisplayString(e.unref(_e)(oe)),1),e.createElementVNode("input",{class:"media-management-view__checkbox media-management-view__checkbox--overlay",type:"checkbox",checked:e.unref(se).isSelected(oe.uuid),"data-testid":`checkbox-select-${oe.uuid}`,onClick:ke[4]||(ke[4]=e.withModifiers(()=>{},["stop"])),onChange:$e=>e.unref(se).toggle(oe.uuid)},null,40,oL)]),e.createElementVNode("div",iL,[e.createElementVNode("span",{class:"media-management-view__item-name",title:oe.file_name,"data-testid":`media-display-name-${oe.uuid}`},e.toDisplayString(e.unref(_e)(oe)),9,rL),r.value.showRawFileName===!0?(e.openBlock(),e.createElementBlock("span",{key:0,class:"media-management-view__raw-filename","data-testid":`media-raw-filename-${oe.uuid}`},e.toDisplayString(oe.file_name),9,lL)):e.createCommentVNode("",!0),r.value.showOwner&&oe.user_id?(e.openBlock(),e.createElementBlock("span",{key:1,class:"media-management-view__item-owner","data-testid":`owner-${oe.uuid}`},e.toDisplayString(k(oe)),9,sL)):e.createCommentVNode("",!0),oe.is_orphaned?(e.openBlock(),e.createElementBlock("span",dL,e.toDisplayString(v.value),1)):e.createCommentVNode("",!0),ye(oe)>0?(e.openBlock(),e.createElementBlock("span",{key:3,class:"media-management-view__variant-badge","data-testid":`media-variant-badge-${oe.uuid}`},e.toDisplayString(Ne(ye(oe))),9,cL)):e.createCommentVNode("",!0)]),e.renderSlot(q.$slots,"item-actions",e.mergeProps({ref_for:!0},st(oe)),()=>[e.createElementVNode("div",uL,[e.createElementVNode("div",{class:"media-management-view__action-menu",onKeydown:e.withKeys(e.withModifiers(Ut,["stop"]),["escape"])},[e.createElementVNode("button",{type:"button",class:"media-management-view__action-menu-trigger","data-testid":`btn-actions-menu-${oe.uuid}`,"aria-label":`Actions for ${e.unref(_e)(oe)}`,"aria-haspopup":"menu","aria-expanded":B.value===oe.uuid?"true":"false",onClick:$e=>It(oe.uuid)}," ... ",8,pL),B.value===oe.uuid?(e.openBlock(),e.createElementBlock("div",{key:0,class:"media-management-view__action-menu-panel",role:"menu","data-testid":`media-item-actions-menu-${oe.uuid}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(sa(oe),$e=>(e.openBlock(),e.createElementBlock("button",{key:$e.id,type:"button",class:"media-management-view__action-menu-item",role:"menuitem","data-testid":$e.testId,onClick:At=>Gt($e)},e.toDisplayString($e.label),9,hL))),128))],8,fL)):e.createCommentVNode("",!0)],40,mL)])],!0)],10,YR))),128))])),e.unref(se).selectedCount.value>0&&O.value?e.renderSlot(q.$slots,"bulk-actions",e.normalizeProps(e.mergeProps({key:6},Ot.value)),()=>[e.createElementVNode("footer",vL,[e.createElementVNode("span",gL,e.toDisplayString(le(e.unref(se).selectedCount.value)),1),r.value.allowCreatePost===!0?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"media-management-view__btn-action","data-testid":"btn-bulk-create-post",onClick:ke[5]||(ke[5]=oe=>Wt(e.unref(se).selectedItems.value,"bulk"))},e.toDisplayString(l.value.createPostButton),1)):e.createCommentVNode("",!0),r.value.allowCreateGallery===!0?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"media-management-view__btn-action","data-testid":"btn-bulk-create-gallery",onClick:ke[6]||(ke[6]=oe=>Pe(e.unref(se).selectedItems.value,"bulk"))},e.toDisplayString(l.value.createGalleryButton),1)):e.createCommentVNode("",!0),r.value.allowAddToAlbum===!0?(e.openBlock(),e.createElementBlock("button",{key:2,type:"button",class:"media-management-view__btn-action","data-testid":"btn-bulk-add-to-album",onClick:ke[7]||(ke[7]=oe=>Ht(e.unref(se).selectedItems.value,"bulk"))},e.toDisplayString(l.value.addToAlbumButton),1)):e.createCommentVNode("",!0),r.value.allowBulkDelete!==!1?(e.openBlock(),e.createElementBlock("button",{key:3,type:"button",class:"media-management-view__btn-delete","data-testid":"btn-bulk-delete",disabled:e.unref(xe).isDeleting.value,onClick:me},e.toDisplayString(y.value),9,bL)):e.createCommentVNode("",!0)])],!0):e.createCommentVNode("",!0),z.value.length>0?(e.openBlock(),e.createElementBlock("footer",yL,[e.createElementVNode("span",wL,e.toDisplayString(F.value),1),Je.value.length>0?(e.openBlock(),e.createElementBlock("div",kL,[ke[11]||(ke[11]=e.createElementVNode("label",{class:"media-management-view__page-size-label",for:"media-management-page-size-select"},"Show:",-1)),e.createElementVNode("select",{id:"media-management-page-size-select",class:"media-management-view__page-size-select","data-testid":"select-media-management-page-size",value:_t.value,disabled:e.unref(L).loading.value||e.unref(L).loadingMore.value,onChange:ht},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Je.value,oe=>(e.openBlock(),e.createElementBlock("option",{key:oe.value,value:oe.value,"data-testid":`option-page-size-${oe.value}`},e.toDisplayString(oe.label),9,EL))),128))],40,_L)])):e.createCommentVNode("",!0),!q.paginated&&e.unref(L).hasMore.value?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"media-management-view__load-more","data-testid":"btn-media-management-load-more",disabled:e.unref(L).loadingMore.value,onClick:Ve},e.toDisplayString(e.unref(L).loadingMore.value?l.value.loadingMoreButton:l.value.loadMoreButton),9,SL)):e.createCommentVNode("",!0),q.paginated&&(e.unref(L).totalPages.value??0)>1?(e.openBlock(),e.createElementBlock("nav",CL,[e.createElementVNode("button",{type:"button",class:"media-management-view__page-bar-step","data-testid":"btn-media-management-page-prev",disabled:(e.unref(L).currentPage.value??1)<=1||e.unref(L).loading.value,"aria-label":"Previous page",onClick:ke[8]||(ke[8]=oe=>Ge(-1))}," ‹ ",8,xL),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Le.value,oe=>(e.openBlock(),e.createElementBlock("button",{key:oe.key,type:"button",class:e.normalizeClass(["media-management-view__page-bar-page",{"is-current":oe.kind==="page"&&oe.value===e.unref(L).currentPage.value}]),"data-testid":oe.kind==="page"?`btn-media-management-page-${oe.value}`:"media-management-page-ellipsis",disabled:oe.kind!=="page"||e.unref(L).loading.value,"aria-current":oe.kind==="page"&&oe.value===e.unref(L).currentPage.value?"page":void 0,"aria-label":oe.kind==="page"?`Page ${oe.value}`:void 0,onClick:$e=>oe.kind==="page"?nt(oe.value):void 0},e.toDisplayString(oe.kind==="page"?oe.value:"…"),11,NL))),128)),e.createElementVNode("button",{type:"button",class:"media-management-view__page-bar-step","data-testid":"btn-media-management-page-next",disabled:(e.unref(L).currentPage.value??1)>=(e.unref(L).totalPages.value??1)||e.unref(L).loading.value,"aria-label":"Next page",onClick:ke[9]||(ke[9]=oe=>Ge(1))}," › ",8,VL)])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])):T.value==="trash"?(e.openBlock(),e.createElementBlock("section",TL,[e.unref(ue).isLoading.value?(e.openBlock(),e.createElementBlock("div",BL,e.toDisplayString(u.value),1)):e.unref(ue).items.value.length===0?(e.openBlock(),e.createElementBlock("div",ML,[e.renderSlot(q.$slots,"empty-trash",{},()=>[e.createElementVNode("div",IL,[e.createElementVNode("p",$L,e.toDisplayString(f.value),1),e.createElementVNode("p",FL,e.toDisplayString(h.value),1)])],!0)])):(e.openBlock(),e.createElementBlock("ul",DL,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(ue).items.value,oe=>(e.openBlock(),e.createElementBlock("li",{key:oe.uuid,class:"media-management-view__item is-trashed","data-testid":`trash-item-${oe.uuid}`},[e.createElementVNode("div",RL,[rt(oe)&&!bt.value.has(oe.uuid)?(e.openBlock(),e.createElementBlock("img",{key:0,src:rt(oe)??"",alt:oe.alt_text||oe.file_name,loading:"lazy",onError:$e=>Ct(oe)},null,40,LL)):(e.openBlock(),e.createElementBlock("span",{key:1,class:"media-management-view__item-placeholder","data-testid":`placeholder-trash-${oe.uuid}`},e.toDisplayString(Pt(oe)),9,PL))]),e.createElementVNode("div",UL,[e.createElementVNode("span",OL,e.toDisplayString(oe.file_name),1),oe.purge_after?(e.openBlock(),e.createElementBlock("span",zL,e.toDisplayString(Z(oe.purge_after)),1)):e.createCommentVNode("",!0)]),e.renderSlot(q.$slots,"trash-action",e.mergeProps({ref_for:!0},Jt(oe)),()=>[I(oe)?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"media-management-view__btn-restore","data-testid":`btn-restore-${oe.uuid}`,disabled:e.unref(ue).isRestoring.value,onClick:$e=>Be(oe.uuid)},e.toDisplayString(w.value),9,jL)):(e.openBlock(),e.createElementBlock("span",{key:1,class:"media-management-view__btn-restore is-unavailable","data-testid":`btn-restore-${oe.uuid}-unavailable`,"aria-disabled":!0},e.toDisplayString(_.value),9,WL))],!0)],8,AL))),128))]))])):e.createCommentVNode("",!0),r.value.allowPreview!==!1?(e.openBlock(),e.createBlock(Wd,{key:3,open:K.value!==null,media:K.value,"can-go-previous":N.value!==null&&N.value>0,"can-go-next":N.value!==null&&N.value<z.value.length-1,selected:K.value!==null&&e.unref(se).isSelected(K.value.uuid),"close-label":l.value.previewCloseButton,"previous-label":l.value.previewPreviousButton,"next-label":l.value.previewNextButton,"select-label":l.value.previewSelectButton,"deselect-label":l.value.previewDeselectButton,onClose:pt,onPrevious:Nt,onNext:Ce,onToggleSelect:ke[10]||(ke[10]=oe=>e.unref(se).toggle(oe.uuid))},null,8,["open","media","can-go-previous","can-go-next","selected","close-label","previous-label","next-label","select-label","deselect-label"])):e.createCommentVNode("",!0)]))}}),Yf=Ae(HL,[["__scopeId","data-v-8c4b53f6"]]),ZL={class:"media-library-workspace","data-testid":"media-library-workspace"},GL=e.defineComponent({__name:"MediaLibraryWorkspace",props:{httpClient:{},filters:{default:()=>({sort:"newest"})},initialView:{default:()=>({scope:"library"})},capabilities:{default:()=>({})},labels:{default:()=>({})},groupVariants:{type:Boolean,default:!0}},emits:["filters-change","create-post","create-gallery","add-to-album","edit","deleted","restored","restore-conflict","error"],setup(o,{emit:a}){const t=o,n=a;function i(s){return{...s,...s.kinds!==void 0?{kinds:[...s.kinds]}:{},...s.selected_uuids!==void 0?{selected_uuids:[...s.selected_uuids]}:{}}}const r=e.ref(i(t.filters));e.watch(()=>t.filters,s=>{r.value=i(s)},{deep:!0});function l(s){r.value=i(s),n("filters-change",r.value)}return(s,d)=>(e.openBlock(),e.createElementBlock("section",ZL,[e.createVNode(Yf,{"http-client":t.httpClient,filters:r.value,"initial-view":t.initialView,"group-variants":t.groupVariants,capabilities:{showHeader:!1,showTrash:!1,allowAddToAlbum:t.capabilities.allowAddToAlbum,allowBulkDelete:t.capabilities.allowBulkDelete,allowCreateGallery:t.capabilities.allowCreateGallery,allowCreatePost:t.capabilities.allowCreatePost,showRawFileName:t.capabilities.showRawFileName,allowPreview:t.capabilities.allowPreview,allowImageEdit:t.capabilities.allowImageEdit,allowVideoEdit:t.capabilities.allowVideoEdit},labels:{title:t.labels.title??"Media"},onCreatePost:d[0]||(d[0]=c=>n("create-post",c)),onCreateGallery:d[1]||(d[1]=c=>n("create-gallery",c)),onAddToAlbum:d[2]||(d[2]=c=>n("add-to-album",c)),onEdit:d[3]||(d[3]=c=>n("edit",c)),onDeleted:d[4]||(d[4]=c=>n("deleted",c)),onRestored:d[5]||(d[5]=c=>n("restored",c)),onRestoreConflict:d[6]||(d[6]=c=>n("restore-conflict",c)),onError:d[7]||(d[7]=c=>n("error",c))},{"filter-bar":e.withCtx(()=>[e.createVNode(Jf,{filters:r.value,"scope-label":t.labels.scopeLabel??"","onUpdate:filters":l},null,8,["filters","scope-label"])]),"bulk-actions":e.withCtx(c=>[e.renderSlot(s.$slots,"bulk-actions",e.normalizeProps(e.guardReactiveProps(c)),void 0,!0)]),"item-actions":e.withCtx(c=>[e.renderSlot(s.$slots,"item-actions",e.normalizeProps(e.guardReactiveProps(c)),void 0,!0)]),"empty-library":e.withCtx(()=>[e.renderSlot(s.$slots,"empty-library",{},void 0,!0)]),_:3},8,["http-client","filters","initial-view","group-variants","capabilities","labels"])]))}}),Qf=Ae(GL,[["__scopeId","data-v-54a820dd"]]),XL=["data-testid"],KL={class:"media-empty-state__illustration","aria-hidden":"true"},qL={class:"media-empty-state__copy"},JL={class:"media-empty-state__title"},YL={key:0,class:"media-empty-state__description"},QL={class:"media-empty-state__actions"},eP=e.defineComponent({__name:"MediaEmptyState",props:{title:{},description:{default:""},actionLabel:{default:""},testId:{default:"media-empty-state"}},emits:["action"],setup(o,{emit:a}){const t=o,n=a;return(i,r)=>(e.openBlock(),e.createElementBlock("section",{class:"media-empty-state","data-testid":t.testId},[e.createElementVNode("div",KL,[e.renderSlot(i.$slots,"illustration",{},()=>[r[1]||(r[1]=e.createElementVNode("span",{class:"media-empty-state__icon"},"□",-1))],!0)]),e.createElementVNode("div",qL,[e.createElementVNode("h3",JL,e.toDisplayString(t.title),1),t.description!==""?(e.openBlock(),e.createElementBlock("p",YL,e.toDisplayString(t.description),1)):e.createCommentVNode("",!0)]),e.createElementVNode("div",QL,[e.renderSlot(i.$slots,"actions",{},()=>[t.actionLabel!==""?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"media-empty-state__action","data-testid":"btn-media-empty-state-action",onClick:r[0]||(r[0]=l=>n("action"))},e.toDisplayString(t.actionLabel),1)):e.createCommentVNode("",!0)],!0)])],8,XL))}}),eh=Ae(eP,[["__scopeId","data-v-7b8e2619"]]),tP=["aria-busy"],aP={class:"media-trash-workspace__header"},nP=["disabled"],oP={key:0,class:"media-trash-workspace__status media-trash-workspace__status--error","data-testid":"media-trash-error",role:"alert"},iP={key:1,class:"media-trash-workspace__status","data-testid":"media-trash-status","aria-live":"polite"},rP={key:2,class:"media-trash-workspace__status"},lP={key:4,class:"media-trash-workspace__grid"},sP=["data-testid"],dP={class:"media-trash-workspace__select"},cP=["checked","data-testid","onChange"],uP=["src","alt"],mP={key:1,class:"media-trash-workspace__purge"},pP=e.defineComponent({__name:"MediaTrashWorkspace",props:{httpClient:{},labels:{default:()=>({})}},emits:["restored","purged","error"],setup(o,{emit:a}){const t=o,n=a,i=e.computed(()=>{var y,w,_,b,g,I,T,$,N,B,P;return{title:((y=t.labels)==null?void 0:y.title)??"Trash",emptyTitle:((w=t.labels)==null?void 0:w.emptyTitle)??"Your trash is empty",emptyDescription:((_=t.labels)==null?void 0:_.emptyDescription)??"Deleted files appear here before permanent removal.",restore:((b=t.labels)==null?void 0:b.restore)??"Restore",purge:((g=t.labels)==null?void 0:g.purge)??"Delete forever",emptyTrash:((I=t.labels)==null?void 0:I.emptyTrash)??"Empty trash",confirmPurgeSelected:((T=t.labels)==null?void 0:T.confirmPurgeSelected)??(x=>`Delete ${x} ${x===1?"item":"items"} forever? This cannot be undone.`),confirmEmptyTrash:(($=t.labels)==null?void 0:$.confirmEmptyTrash)??(x=>`Empty trash and permanently delete ${x} ${x===1?"item":"items"}? This cannot be undone.`),purgeSuccess:((N=t.labels)==null?void 0:N.purgeSuccess)??(x=>`${x} ${x===1?"item":"items"} deleted forever.`),purgeError:((B=t.labels)==null?void 0:B.purgeError)??"Could not delete one or more items forever. Try again.",restoreError:((P=t.labels)==null?void 0:P.restoreError)??"Could not restore one or more items. Try again."}}),r=Yd({httpClient:t.httpClient}),l=fl(r.items),s=e.ref(""),d=e.ref(""),c=e.computed(()=>r.isPurging.value||r.isRestoring.value);function u(y){return y.thumbnail_url??y.preview_url??y.original_url??null}async function m(){const y=Array.from(l.selectedIds.value),w=[];s.value="",d.value="";try{for(const _ of y){const b=await r.restore(_);b.status==="restored"?w.push(_):s.value=b.message??i.value.restoreError}l.clear(),w.length>0&&n("restored",w)}catch(_){const b=_ instanceof Error?_:new Error(String(_));s.value=b.message!==""?b.message:i.value.restoreError,n("error",b)}}async function p(){const y=Array.from(l.selectedIds.value);h(i.value.confirmPurgeSelected(y.length),y.length)&&await v(y)}async function f(){const y=r.items.value.map(w=>w.uuid);h(i.value.confirmEmptyTrash(y.length),y.length)&&await v(y)}function h(y,w){return w===0||typeof window>"u"||typeof window.confirm!="function"?!1:window.confirm(y)}async function v(y){if(y.length===0)return;const w=[],_=[];s.value="",d.value="";try{for(const b of y){const g=await r.purge(b);g.status==="purging"?w.push(b):_.push(g.message??i.value.purgeError)}l.clear(),w.length>0&&(d.value=i.value.purgeSuccess(w.length),n("purged",w)),_.length>0&&(s.value=Array.from(new Set(_)).join(" "),n("error",new Error(s.value)))}catch(b){const g=b instanceof Error?b:new Error(String(b));s.value=g.message!==""?g.message:i.value.purgeError,n("error",g)}}return e.onMounted(()=>{r.fetch().catch(y=>{n("error",y instanceof Error?y:new Error(String(y)))})}),(y,w)=>(e.openBlock(),e.createElementBlock("section",{class:"media-trash-workspace","data-testid":"media-trash-workspace","aria-busy":c.value?"true":"false"},[e.createElementVNode("header",aP,[e.createElementVNode("h2",null,e.toDisplayString(i.value.title),1),e.unref(r).items.value.length>0?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button","data-testid":"btn-media-empty-trash",disabled:e.unref(r).isPurging.value,onClick:f},e.toDisplayString(i.value.emptyTrash),9,nP)):e.createCommentVNode("",!0)]),s.value?(e.openBlock(),e.createElementBlock("p",oP,e.toDisplayString(s.value),1)):d.value?(e.openBlock(),e.createElementBlock("p",iP,e.toDisplayString(d.value),1)):e.createCommentVNode("",!0),e.unref(r).isLoading.value?(e.openBlock(),e.createElementBlock("p",rP,"Loading...")):e.unref(r).items.value.length===0?(e.openBlock(),e.createBlock(eh,{key:3,title:i.value.emptyTitle,description:i.value.emptyDescription,"test-id":"media-empty-trash"},null,8,["title","description"])):(e.openBlock(),e.createElementBlock("ul",lP,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(r).items.value,_=>(e.openBlock(),e.createElementBlock("li",{key:_.uuid,class:e.normalizeClass(["media-trash-workspace__item",{"is-selected":e.unref(l).isSelected(_.uuid)}]),"data-testid":`media-trash-item-${_.uuid}`},[e.createElementVNode("label",dP,[e.createElementVNode("input",{type:"checkbox",checked:e.unref(l).isSelected(_.uuid),"data-testid":`checkbox-trash-${_.uuid}`,onChange:b=>e.unref(l).toggle(_.uuid)},null,40,cP),e.createElementVNode("span",null,e.toDisplayString(_.file_name),1)]),u(_)?(e.openBlock(),e.createElementBlock("img",{key:0,src:u(_)??"",alt:_.alt_text??_.file_name},null,8,uP)):e.createCommentVNode("",!0),_.purge_after?(e.openBlock(),e.createElementBlock("span",mP,e.toDisplayString(_.purge_after),1)):e.createCommentVNode("",!0)],10,sP))),128))])),e.createVNode(qd,{"selected-count":e.unref(l).selectedCount.value,"cross-page-count":e.unref(l).crossPageCount.value,scope:"trash",labels:{restore:i.value.restore,purge:i.value.purge},onBulkRestore:m,onBulkPurge:p,onClear:e.unref(l).clear},null,8,["selected-count","cross-page-count","labels","onClear"])],8,tP))}}),th=Ae(pP,[["__scopeId","data-v-1bce0570"]]),fP=["data-density"],hP={class:"media-library-shell__toolbar"},vP={class:"media-library-shell__tabs","aria-label":"Media library sections"},gP=["aria-label"],bP=["data-testid","onClick"],yP={key:2,class:"media-library-shell__uploads","data-testid":"media-library-uploads","aria-live":"polite"},wP=["data-testid"],kP={class:"media-library-shell__upload-thumb"},_P=["src","alt"],EP={key:1,"aria-hidden":"true"},SP={class:"media-library-shell__upload-meta"},CP={class:"media-library-shell__upload-name"},xP={class:"media-library-shell__upload-status"},NP=["data-testid","onClick"],VP={class:"media-library-shell__workspace"},TP={key:0,class:"media-library-shell__breadcrumb","data-testid":"media-album-breadcrumb"},BP={class:"media-library-shell__breadcrumb-current"},MP={class:"media-library-shell__breadcrumb-name"},IP={key:0,class:"media-library-shell__album-actions","data-media-album-menu-root":""},$P=["aria-label","aria-controls","aria-expanded"],FP=["id"],DP=["aria-label"],AP={class:"media-album-grid__toolbar"},RP=["placeholder","aria-label"],LP={class:"media-album-grid__tiles",role:"list"},PP={class:"media-album-grid__new-tile-label"},UP={class:"media-album-grid__new-tile-field",for:"media-album-grid-new-name"},OP={class:"media-album-grid__new-tile-field-label"},zP=["maxlength","aria-invalid","disabled"],jP={key:0,id:"media-album-grid-new-error",class:"media-album-grid__new-tile-error","data-testid":"media-album-new-tile-error",role:"alert"},WP={class:"media-album-grid__new-tile-actions"},HP=["disabled"],ZP=["disabled"],GP={key:0},XP={key:1},KP=["data-testid"],qP=["data-testid","onClick"],JP={class:"media-album-grid__cover","aria-hidden":"true"},YP=["src"],QP={key:1,class:"media-album-grid__cover-initial"},eU={class:"media-album-grid__tile-meta"},tU={class:"media-album-grid__tile-name"},aU={class:"media-album-grid__tile-count"},nU={class:"media-album-grid__tile-actions","data-media-album-menu-root":""},oU=["data-testid","aria-label","aria-controls","aria-expanded","onClick"],iU=["id","data-testid"],rU=["data-testid","onClick"],lU=["data-testid","onClick"],sU={key:0,class:"media-album-grid__empty","data-testid":"media-album-grid-empty-search"},dU={key:1,class:"media-album-grid__empty","data-testid":"media-album-grid-empty"},cU={class:"media-library-shell__item-actions"},uU={class:"media-library-shell__item-action-menu","data-media-item-menu-root":""},mU=["data-testid","aria-label","aria-controls","aria-expanded","onClick"],pU=["id","data-testid"],fU=["data-testid","onClick"],hU=["data-testid","onClick"],vU=["data-testid","onClick"],gU=["data-testid","onClick"],bU=["data-testid","onClick"],yU=["data-testid","onClick"],wU=["data-testid","onClick"],kU=["aria-label"],_U=["aria-describedby"],EU={class:"media-album-dialog__header"},SU={id:"media-album-dialog-title"},CU={class:"media-album-dialog__field"},xU=["maxlength","aria-invalid","disabled"],NU={class:"media-album-dialog__field"},VU=["disabled"],TU={key:0,id:"media-album-dialog-error",class:"media-album-dialog__error","data-testid":"media-album-edit-error",role:"alert"},BU={class:"media-album-dialog__actions"},MU=["disabled"],IU=["disabled"],$U={key:1,class:"media-album-dialog__form","data-testid":"media-album-delete-confirmation"},FU={class:"media-album-dialog__header"},DU={id:"media-album-dialog-title"},AU={id:"media-album-dialog-delete-description",class:"media-album-dialog__description"},RU={key:0,id:"media-album-dialog-error",class:"media-album-dialog__error","data-testid":"media-album-delete-error",role:"alert"},LU={class:"media-album-dialog__actions"},PU=["disabled"],UU=["disabled"],am="media-library:density",nm="media-library:recent-albums",om=5,Ir=120,OU=e.defineComponent({__name:"MediaLibraryShell",props:{httpClient:{},albumHttpClient:{},albumBaseUrl:{},initialTab:{default:"library"},initialAlbumId:{default:null},initialFilters:{default:()=>({sort:"newest"})},capabilities:{default:()=>({})},labels:{default:()=>({})},currentRoute:{},routerPush:{},routerReplace:{}},emits:["tab-change","album-change","filters-change","selection-change","create-post","create-gallery","add-to-album","edit","deleted","restored","restore-conflict","metadata-updated","error"],setup(o,{emit:a}){function t(){if(typeof window>"u")return"comfortable";try{return window.localStorage.getItem(am)==="compact"?"compact":"comfortable"}catch{return"comfortable"}}function n(H){if(!(typeof window>"u"))try{window.localStorage.setItem(am,H)}catch{}}function i(){if(typeof window>"u")return[];try{const H=window.localStorage.getItem(nm);if(typeof H!="string"||H==="")return[];const Q=JSON.parse(H);return Array.isArray(Q)?Q.filter(Fe=>typeof Fe=="string"):[]}catch{return[]}}function r(H){if(!(typeof window>"u"))try{window.localStorage.setItem(nm,JSON.stringify(H.slice(0,om)))}catch{}}const l=o,s=a,d=e.ref(l.initialTab),c=e.ref(l.initialAlbumId),u=e.ref({...l.initialFilters}),m=e.ref(null),p=e.ref(null),f=e.ref(null),h=e.ref(null),v=e.ref(!1),y=e.ref(null),w=e.ref(null),_=e.ref(t()),b=e.ref(i()),g=e.ref(!1),I=e.ref(""),T=e.ref(null),$=e.ref(null),N=e.ref(null),B=e.ref(null),P=e.ref(""),x=e.ref(""),M=e.ref(""),E=e.ref(!1),D=e.ref(!1),j=e.ref(null),L=e.ref(null),z=e.ref(null),C=e.ref(null),A=e.ref(!1);let O=null;function K(){if(typeof document>"u")return!1;const H=document.activeElement;if(!(H instanceof HTMLElement))return!1;if(H.isContentEditable)return!0;const Q=H.tagName.toLowerCase();return Q==="input"||Q==="textarea"||Q==="select"}function se(H){H.key==="?"&&(H.metaKey||H.ctrlKey||H.altKey||K()||(H.preventDefault(),g.value=!0))}function xe(H){H.target instanceof Element&&(T.value!==null&&H.target.closest("[data-media-album-menu-root]")===null&&it(!1),f.value!==null&&H.target.closest("[data-media-item-menu-root]")===null&&Ga(!1))}function ue(H){A.value=H.matches}function le(){typeof window>"u"||typeof window.matchMedia=="function"&&(O=window.matchMedia("(max-width: 1535px)"),A.value=O.matches,O.addEventListener("change",ue))}function Z(){O==null||O.removeEventListener("change",ue),O=null}const k=e.computed(()=>A.value?"overlay":"pinned");function F(){m.value=null}const W=e.computed(()=>d.value==="albums"&&c.value===null),J=e.computed(()=>d.value==="albums"&&c.value!==null&&c.value!=="unfiled"),ce=e.computed(()=>{var H;return c.value===null||c.value==="unfiled"?"":((H=Ge.albumsById.value.get(c.value))==null?void 0:H.name)??""}),Ue=e.computed(()=>c.value===null||c.value==="unfiled"?null:Ge.albumsById.value.get(c.value)??null),be=e.computed(()=>{const H=I.value.trim().toLowerCase(),Q=Ge.albums.value;return H===""?Q:Q.filter(Fe=>Fe.name.toLowerCase().includes(H)||(Fe.description??"").toLowerCase().includes(H))});function _e(H){const Q=H.name.trim();return Q.length===0?"·":Q.charAt(0).toUpperCase()}function ye(H){var ne,Qe,Tt;const Q=H.cover_media;if(Q==null)return null;const Fe=((ne=Q.urls)==null?void 0:ne.thumb)??((Qe=Q.urls)==null?void 0:Qe.preview)??((Tt=Q.urls)==null?void 0:Tt.original)??null;return typeof Fe=="string"&&Fe!==""?Fe:null}function Ne(H){return Pe.value.itemsCount(H.media_count)}function Se(H){return`media-album-action-menu-${H}`}function Re(H){e.nextTick(()=>{if(typeof document>"u")return;const Q=document.getElementById(H);Q!==null&&fa(jl(Q)[0]??null)})}function Oe(H,Q){if(T.value===H){it(!0);return}$.value=(Q==null?void 0:Q.currentTarget)instanceof HTMLElement?Q.currentTarget:null,T.value=H,Re(Se(H))}function it(H=!1){T.value=null,H&&e.nextTick(()=>fa($.value))}function rt(H){if(H.key==="Escape"){H.preventDefault(),H.stopPropagation(),it(!0);return}cd(H,H.currentTarget instanceof HTMLElement?H.currentTarget:null)}function Pt(){C.value=typeof document<"u"&&document.activeElement instanceof HTMLElement?document.activeElement:$.value}function bt(H){Pt(),it(!1),N.value="edit",B.value=H,P.value=H.name,x.value=H.description??"",M.value="",E.value=!1,D.value=!1,e.nextTick(()=>{var Q,Fe;(Q=j.value)==null||Q.focus(),(Fe=j.value)==null||Fe.select()})}function Ct(H){Pt(),it(!1),N.value="delete",B.value=H,M.value="",E.value=!1,D.value=!1,e.nextTick(()=>{var Q;(Q=L.value)==null||Q.focus()})}function mt(){if(E.value||D.value)return;const H=C.value;N.value=null,B.value=null,P.value="",x.value="",M.value="",C.value=null,e.nextTick(()=>fa(H))}function pt(H){if(H.key==="Escape"){H.preventDefault(),H.stopPropagation(),mt();return}H.key==="Tab"&&Kd(H,z.value)}async function Nt(){var Q,Fe,ne;const H=B.value;if(!(H===null||N.value!=="edit"||E.value)){if(lt.value){M.value=Pe.value.albumEditEmptyError,(Q=j.value)==null||Q.focus();return}if(He.value){M.value=Pe.value.albumEditTooLongError,(Fe=j.value)==null||Fe.focus();return}E.value=!0,M.value="";try{await Ge.updateAlbum(H.id,{name:Be.value,description:x.value.trim()}),E.value=!1,mt()}catch(Qe){E.value=!1;const Tt=Qe instanceof Error?Qe:new Error(String(Qe));M.value=Tt.message!==""?Tt.message:Pe.value.albumEditGenericError,(ne=j.value)==null||ne.focus(),s("error",Tt)}}}async function Ce(){const H=B.value;if(!(H===null||N.value!=="delete"||D.value)){D.value=!0,M.value="";try{await Ge.deleteAlbum(H.id),b.value=b.value.filter(Q=>Q!==H.id),r(b.value),D.value=!1,mt(),c.value===H.id&&At(),Ge.fetchAlbums({parent_id:null}).catch(Q=>{s("error",Q instanceof Error?Q:new Error(String(Q)))})}catch(Q){D.value=!1;const Fe=Q instanceof Error?Q:new Error(String(Q));M.value=Fe.message!==""?Fe.message:Pe.value.albumDeleteGenericError,s("error",Fe)}}}const Ve=e.computed(()=>b.value.map(H=>{const Q=Ge.albumsById.value.get(H);return Q?{id:H,name:Q.name}:null}).filter(H=>H!==null));function Le(H){const Q=[H,...b.value.filter(Fe=>Fe!==H)].slice(0,om);b.value=Q,r(Q)}const nt=e.computed(()=>u.value.sort??"newest"),Ge=Ol(),Je=Jd({httpClient:l.httpClient}),_t=Hf({httpClient:l.httpClient,onMediaUploaded:()=>{ht.value+=1}}),ht=e.ref(0);function Wt(H){H.length!==0&&_t.uploadFiles(H).catch(Q=>{s("error",Q instanceof Error?Q:new Error(String(Q)))})}const Pe=e.computed(()=>{var H,Q,Fe,ne,Qe,Tt,dn,La,Hn,Nn,Pa,ya,Zn,uo,cn,Vn,Ua,mo,Tn,Bn,an,Gn,un,Mn,mn,In,nn,po,Xn,gi,bi,$n,Kn,qn,fo,ho,vo,go,bo,S,R,te,we,ze,je,ut,Bt,qt,ca;return{library:((H=l.labels)==null?void 0:H.library)??((Q=l.labels)==null?void 0:Q.libraryTab)??"Library",libraryTab:((Fe=l.labels)==null?void 0:Fe.libraryTab)??((ne=l.labels)==null?void 0:ne.library)??"Library",albums:((Qe=l.labels)==null?void 0:Qe.albums)??((Tt=l.labels)==null?void 0:Tt.albumsTab)??"Albums",albumsTab:((dn=l.labels)==null?void 0:dn.albumsTab)??((La=l.labels)==null?void 0:La.albums)??"Albums",trash:((Hn=l.labels)==null?void 0:Hn.trash)??((Nn=l.labels)==null?void 0:Nn.trashTab)??"Trash",trashTab:((Pa=l.labels)==null?void 0:Pa.trashTab)??((ya=l.labels)==null?void 0:ya.trash)??"Trash",allMedia:((Zn=l.labels)==null?void 0:Zn.allMedia)??"All media",unfiled:((uo=l.labels)==null?void 0:uo.unfiled)??"Unfiled",newAlbum:((cn=l.labels)==null?void 0:cn.newAlbum)??"New album",selectionScope:((Vn=l.labels)==null?void 0:Vn.selectionScope)??"Showing selected items",exitSelectionScope:((Ua=l.labels)==null?void 0:Ua.exitSelectionScope)??"Exit selection view",findAlbum:((mo=l.labels)==null?void 0:mo.findAlbum)??"Find album…",noAlbumsYet:((Tn=l.labels)==null?void 0:Tn.noAlbumsYet)??"No albums yet — albums are private buckets where you group photos and videos. Create your first one above to start organising your work.",noAlbumMatchesFound:((Bn=l.labels)==null?void 0:Bn.noAlbumMatchesFound)??"No albums match your search.",itemsCount:((an=l.labels)==null?void 0:an.itemsCount)??(Na=>`${Na} ${Na===1?"item":"items"}`),newAlbumNamePrompt:((Gn=l.labels)==null?void 0:Gn.newAlbumNamePrompt)??"Name this album",newAlbumSubmit:((un=l.labels)==null?void 0:un.newAlbumSubmit)??"Create",newAlbumCancel:((Mn=l.labels)==null?void 0:Mn.newAlbumCancel)??"Cancel",newAlbumEmptyError:((mn=l.labels)==null?void 0:mn.newAlbumEmptyError)??"Please enter a name.",newAlbumTooLongError:((In=l.labels)==null?void 0:In.newAlbumTooLongError)??"Name must be 120 characters or fewer.",newAlbumGenericError:((nn=l.labels)==null?void 0:nn.newAlbumGenericError)??"Could not create album. Try again.",recentSection:((po=l.labels)==null?void 0:po.recentSection)??"Recent albums",albumActions:((Xn=l.labels)==null?void 0:Xn.albumActions)??(Na=>`Album actions for ${Na}`),editAlbum:((gi=l.labels)==null?void 0:gi.editAlbum)??"Edit album",deleteAlbum:((bi=l.labels)==null?void 0:bi.deleteAlbum)??"Delete album",editAlbumTitle:(($n=l.labels)==null?void 0:$n.editAlbumTitle)??"Edit album",albumNameLabel:((Kn=l.labels)==null?void 0:Kn.albumNameLabel)??"Album name",albumDescriptionLabel:((qn=l.labels)==null?void 0:qn.albumDescriptionLabel)??"Description",saveAlbum:((fo=l.labels)==null?void 0:fo.saveAlbum)??"Save changes",cancelAlbumEdit:((ho=l.labels)==null?void 0:ho.cancelAlbumEdit)??"Cancel",albumEditEmptyError:((vo=l.labels)==null?void 0:vo.albumEditEmptyError)??"Please enter a name.",albumEditTooLongError:((go=l.labels)==null?void 0:go.albumEditTooLongError)??"Name must be 120 characters or fewer.",albumEditGenericError:((bo=l.labels)==null?void 0:bo.albumEditGenericError)??"Could not update album. Try again.",deleteAlbumTitle:((S=l.labels)==null?void 0:S.deleteAlbumTitle)??(Na=>`Delete ${Na}?`),deleteAlbumDescription:((R=l.labels)==null?void 0:R.deleteAlbumDescription)??"This deletes the album only. The photos and videos inside it stay in your media library.",confirmDeleteAlbum:((te=l.labels)==null?void 0:te.confirmDeleteAlbum)??"Delete album",cancelDeleteAlbum:((we=l.labels)==null?void 0:we.cancelDeleteAlbum)??"Cancel",albumDeleteGenericError:((ze=l.labels)==null?void 0:ze.albumDeleteGenericError)??"Could not delete album. Try again.",closeAlbumDialog:((je=l.labels)==null?void 0:je.closeAlbumDialog)??"Close album dialog",itemActions:((ut=l.labels)==null?void 0:ut.itemActions)??(Na=>`Actions for ${Na}`),moveToAnotherAlbum:((Bt=l.labels)==null?void 0:Bt.moveToAnotherAlbum)??"Move to another album",removeFromThisAlbum:((qt=l.labels)==null?void 0:qt.removeFromThisAlbum)??"Remove from this album",addToAlbum:((ca=l.labels)==null?void 0:ca.addToAlbum)??"Add to album"}}),Ht=e.ref(!1),Zt=e.ref(""),It=e.ref(""),Ut=e.ref(!1),Gt=e.ref(null),sa=e.computed(()=>Zt.value.trim()),ae=e.computed(()=>sa.value.length>Ir),ge=e.computed(()=>sa.value===""),pe=e.computed(()=>!Ut.value&&!ge.value&&!ae.value),me=e.computed(()=>N.value!==null&&B.value!==null),Be=e.computed(()=>P.value.trim()),He=e.computed(()=>Be.value.length>Ir),lt=e.computed(()=>Be.value===""),Vt=e.computed(()=>!E.value&&!lt.value&&!He.value),Ot=e.computed(()=>y.value!==null?{scope:"library"}:c.value==="unfiled"?{scope:"unfiled"}:c.value!==null?{scope:"album",albumId:c.value}:{scope:"library"}),$t=e.computed(()=>y.value!==null?{...u.value,selected_uuids:[...y.value],unfiled_only:!1}:u.value),st=e.computed(()=>{if(c.value===null||c.value==="unfiled")return null;const H=Ge.albumsById.value.get(c.value);return{uuid:c.value,name:(H==null?void 0:H.name)??"this album"}}),Jt=e.computed(()=>d.value==="trash"?"trash":y.value!==null?"selection":st.value!==null?"album":"all"),q=e.computed(()=>({...l.capabilities,allowReplaceMedia:!1,allowVisibilityChange:!1,allowDownloadZip:!1})),ke=e.computed(()=>d.value==="trash"?Pe.value.trash:y.value!==null?Pe.value.selectionScope:c.value==="unfiled"?Pe.value.unfiled:st.value!==null?st.value.name:Pe.value.allMedia);function oe(H){var Q,Fe,ne;d.value!==H&&(d.value=H,s("tab-change",H),H==="trash"?(Q=l.routerPush)==null||Q.call(l,"/media/trash"):H==="albums"?(Fe=l.routerPush)==null||Fe.call(l,"/media/albums"):(ne=l.routerPush)==null||ne.call(l,"/media"))}function $e(H){var Q;Y(),c.value=H,d.value="albums",Le(H),u.value={...u.value,unfiled_only:!1},s("album-change",H),(Q=l.routerPush)==null||Q.call(l,`/media/album/${encodeURIComponent(H)}`)}function At(){var H;Y(),c.value=null,d.value="albums",u.value={...u.value,unfiled_only:!1},s("album-change",null),(H=l.routerPush)==null||H.call(l,"/media/albums")}async function zt(H){if(c.value===null||c.value==="unfiled")return;const Q=c.value;try{await Ge.updateAlbum(Q,{meta:{cover_media_uuid:H.uuid}}),Ge.fetchAlbums({parent_id:null})}catch(Fe){s("error",Fe instanceof Error?Fe:new Error(String(Fe)))}}function Ft(){Zt.value="",It.value="",Ut.value=!1}async function wt(){var H;Ht.value=!0,Ft(),await e.nextTick(),(H=Gt.value)==null||H.focus()}function yt(){Ht.value=!1,Ft()}function Yt(){It.value!==""&&!ge.value&&!ae.value&&(It.value="")}async function Et(){var H,Q,Fe,ne;if(!Ut.value){if(ge.value){It.value=Pe.value.newAlbumEmptyError,(H=Gt.value)==null||H.focus();return}if(ae.value){It.value=Pe.value.newAlbumTooLongError,(Q=Gt.value)==null||Q.focus();return}Ut.value=!0,It.value="";try{const Qe=await Ge.createAlbum({name:sa.value});if(Qe==null){It.value=Pe.value.newAlbumGenericError,Ut.value=!1,(Fe=Gt.value)==null||Fe.focus();return}Ht.value=!1,Ft(),$e(Qe.id)}catch(Qe){const Tt=Qe instanceof Error?Qe:new Error(String(Qe));It.value=Tt.message!==""?Tt.message:Pe.value.newAlbumGenericError,Ut.value=!1,(ne=Gt.value)==null||ne.focus(),s("error",Tt)}}}function Kt(H){H.key==="Escape"&&(H.stopPropagation(),yt())}function Ca(){return d.value==="trash"?"/media/trash":c.value==="unfiled"?"/media/unfiled":c.value!==null?`/media/album/${encodeURIComponent(c.value)}`:"/media"}function X(H){var Q;H.length!==0&&(y.value===null&&(w.value=Ca()),y.value=[...H],(Q=l.routerPush)==null||Q.call(l,{path:"/media",query:{view:"selection"}}))}function Y(){y.value=null,w.value=null}function fe(){var Q;const H=w.value;Y(),H!==null&&((Q=l.routerPush)==null||Q.call(l,H))}function he(H){var Q;u.value={...u.value,sort:H},s("filters-change",u.value),(Q=l.routerReplace)==null||Q.call(l,{query:u.value})}function Te(H){_.value=H,n(H)}function Ke(H){var Q;u.value={...u.value,created_after:H.starts_at,created_before:H.ends_at},s("filters-change",u.value),(Q=l.routerReplace)==null||Q.call(l,{query:u.value})}function ct(){var Q;const H={...u.value};delete H.created_after,delete H.created_before,u.value=H,s("filters-change",u.value),(Q=l.routerReplace)==null||Q.call(l,{query:u.value})}const tt=e.computed(()=>u.value.created_after!==void 0||u.value.created_before!==void 0);function qe(H){var Q;u.value={...H,...H.kinds!==void 0?{kinds:[...H.kinds]}:{},...H.selected_uuids!==void 0?{selected_uuids:[...H.selected_uuids]}:{}},s("filters-change",u.value),(Q=l.routerReplace)==null||Q.call(l,{query:u.value})}function vt(){gf({...l.albumHttpClient!==void 0?{httpClient:l.albumHttpClient}:{},...l.albumBaseUrl!==void 0?{albumBaseUrl:l.albumBaseUrl}:{}})}function gt(H){H.mediaIds.length!==0&&(p.value=H,v.value=!0)}function ot(){v.value=!1,p.value=null,ha.value=null}function Qt(H){const Q=new Set(H.mediaIds),Fe=m.value;if((Fe==null?void 0:Fe.kind)==="single"&&Q.has(Fe.media.uuid)){m.value=null;return}(Fe==null?void 0:Fe.kind)==="multi"&&(m.value=null)}function Rt(H){ht.value+=1,Qt(H)}async function Za(H){const Q=p.value;if(Q===null)return;const Fe=ha.value;try{await Ge.attachMedia(H,Q.mediaIds),Fe!==null&&await Promise.all(Q.mediaIds.map(ne=>Ge.detachMedia(Fe,ne))),v.value=!1,p.value=null,ha.value=null,Rt(Q),s("add-to-album",Q)}catch(ne){s("error",ne instanceof Error?ne:new Error(String(ne)))}}const ha=e.ref(null);function Cn(H){H.mediaIds.length===0||st.value===null||(p.value=H,ha.value=st.value.uuid,v.value=!0)}async function Ta(H){if(H.mediaIds.length===0||st.value===null)return;const Q=st.value.uuid;try{await Promise.all(H.mediaIds.map(Fe=>Ge.detachMedia(Q,Fe))),Rt(H)}catch(Fe){s("error",Fe instanceof Error?Fe:new Error(String(Fe)))}}function xa(H){return{mediaIds:[H.uuid],items:[H],source:"item"}}function Aa(){const H=m.value;if(H===null)return null;if(H.kind==="single")return xa(H.media);const Q=H.items??[];return Q.length===0?null:{mediaIds:Q.map(Fe=>Fe.uuid),items:Q,source:"bulk"}}function va(H){return H.name??H.file_name}function Qa(H){return`media-shell-item-actions-menu-${H}`}function On(H,Q){if(f.value===H){Ga(!0);return}h.value=(Q==null?void 0:Q.currentTarget)instanceof HTMLElement?Q.currentTarget:null,f.value=H,Re(Qa(H))}function Ga(H=!1){f.value=null,H&&e.nextTick(()=>fa(h.value))}function zn(H){if(H.key==="Escape"){H.preventDefault(),H.stopPropagation(),Ga(!0);return}cd(H,H.currentTarget instanceof HTMLElement?H.currentTarget:null)}function ga(H){H(),Ga(!1)}function Ra(H){Cn(xa(H))}async function Wo(H){await Ta(xa(H))}function lo(H){Wo(H)}function hi(H){const Q=H.mime_type.toLowerCase();return(H.is_image===!0||Q.startsWith("image/"))&&l.capabilities.allowImageEdit===!0?"image":Q.startsWith("video/")&&l.capabilities.allowVideoEdit===!0?"video":null}function vi(H){const Q=hi(H);Q!==null&&s("edit",{media:H,kind:Q})}function xn(H){const Q=m.value;(Q==null?void 0:Q.kind)==="single"&&Q.media.uuid===H.uuid&&(m.value={kind:"single",media:H}),ht.value+=1,s("metadata-updated",H)}function ba(H){const Q=H.original_url!==""?H.original_url:H.url;if(typeof document>"u"||typeof Q!="string"||Q==="")return;const Fe=document.createElement("a");Fe.href=Q,Fe.download=H.file_name,Fe.rel="noopener",Fe.target="_blank",document.body.appendChild(Fe),Fe.click(),Fe.remove()}function sn(H){return Object.entries(H).map(([Q,Fe])=>({uuid:Q,blocks:Fe}))}function so(H){if(typeof window>"u"||typeof window.confirm!="function")return!1;const Q=new Set;for(const Qe of H)for(const Tt of Qe.blocks)Tt.context&&Q.add(Tt.context);const Fe=Array.from(Q),ne=Fe.length>0?`This media is still attached to: ${Fe.map(Qe=>`"${Qe}"`).join(", ")}. Remove from those and move to trash?`:"This media is still attached to other items. Remove from those and move to trash?";return window.confirm(ne)}function jn(H,Q){const Fe=H.results.filter(ne=>ne.status==="trashed"||ne.status==="already_trashed").map(ne=>ne.uuid);if(Fe.length!==0){if(y.value!==null){const ne=new Set(Fe);y.value=y.value.filter(Qe=>!ne.has(Qe)),y.value.length===0&&Y()}Rt(Q),s("deleted",Fe)}}async function en(H){if(!(l.capabilities.allowBulkDelete!==!0||H.mediaIds.length===0))try{const Q=await Je.deleteMany(H.mediaIds);jn(Q,H)}catch(Q){if(Q instanceof Wl){const Fe=sn(Q.softBlocks);if(!so(Fe))return;try{const ne=await Je.deleteMany(H.mediaIds,{confirmed:!0});jn(ne,H)}catch(ne){s("error",ne instanceof Error?ne:new Error(String(ne)))}return}s("error",Q instanceof Error?Q:new Error(String(Q)))}}function Wn(H){en(xa(H))}function Xa(){const H=Aa();H!==null&&gt(H)}function da(){const H=Aa();H!==null&&en(H)}function Ba(H){if(st.value!==null){Ra(H);return}l.capabilities.allowAddToAlbum===!0&&gt(xa(H))}function tn(H,Q){if(Q>0){X(H.mediaIds);return}if(H.mediaIds.length===1&&H.items.length===1){m.value={kind:"single",media:H.items[0]};return}m.value={kind:"multi",count:H.mediaIds.length,items:H.items}}e.watch(()=>l.initialAlbumId,H=>{c.value=H});function co(H){H===null||H==="unfiled"||Ge.albumsById.value.has(H)||Ge.fetchAlbum(H).catch(Q=>{s("error",Q instanceof Error?Q:new Error(String(Q)))})}return e.watch(()=>c.value,H=>co(H)),vt(),e.onMounted(()=>{co(c.value),Ge.fetchAlbums({parent_id:null}).catch(H=>{s("error",H instanceof Error?H:new Error(String(H)))}),typeof window<"u"&&(window.addEventListener("keydown",se),document.addEventListener("pointerdown",xe,!0),le())}),e.onUnmounted(()=>{typeof window<"u"&&(window.removeEventListener("keydown",se),document.removeEventListener("pointerdown",xe,!0),Z())}),e.watch(()=>[l.albumHttpClient,l.albumBaseUrl],()=>vt()),(H,Q)=>{var Fe;return e.openBlock(),e.createElementBlock("section",{class:e.normalizeClass(["media-library-shell",{"is-density-compact":_.value==="compact"}]),"data-density":_.value,"data-testid":"media-library-shell"},[e.createElementVNode("header",hP,[e.createElementVNode("nav",vP,[e.createElementVNode("button",{type:"button",class:e.normalizeClass({"is-active":d.value==="library"}),"data-testid":"tab-media-library",onClick:Q[0]||(Q[0]=ne=>oe("library"))},e.toDisplayString(Pe.value.library),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({"is-active":d.value==="albums"}),"data-testid":"tab-media-albums",onClick:Q[1]||(Q[1]=ne=>oe("albums"))},e.toDisplayString(Pe.value.albums),3),e.createElementVNode("button",{type:"button",class:e.normalizeClass({"is-active":d.value==="trash"}),"data-testid":"tab-media-trash",onClick:Q[2]||(Q[2]=ne=>oe("trash"))},e.toDisplayString(Pe.value.trash),3)]),e.createElementVNode("button",{type:"button",class:"media-library-shell__shortcut-trigger","data-testid":"btn-media-shortcuts","aria-label":"Show keyboard shortcuts",onClick:Q[3]||(Q[3]=ne=>g.value=!0)}," ? "),y.value!==null?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"media-library-shell__exit-selection","data-testid":"btn-media-exit-selection-scope",onClick:fe},e.toDisplayString(Pe.value.exitSelectionScope),1)):e.createCommentVNode("",!0)]),d.value!=="trash"&&!W.value?(e.openBlock(),e.createBlock(jf,{key:0,class:"media-library-shell__toolbar-row",sort:nt.value,density:_.value,"has-date-filter":tt.value,"http-client":l.httpClient,"onUpdate:sort":he,"onUpdate:density":Te,onJumpTo:Ke,onJumpToAll:ct,onUploadFiles:Wt},null,8,["sort","density","has-date-filter","http-client"])):e.createCommentVNode("",!0),Ve.value.length>0&&d.value!=="trash"&&!W.value&&!J.value?(e.openBlock(),e.createElementBlock("nav",{key:1,class:"media-library-shell__recent-albums","data-testid":"media-library-recent-albums","aria-label":Pe.value.recentSection},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Ve.value,ne=>(e.openBlock(),e.createElementBlock("button",{key:ne.id,type:"button",class:"media-library-shell__recent-chip","data-testid":`btn-media-recent-album-${ne.id}`,onClick:Qe=>$e(ne.id)},e.toDisplayString(ne.name),9,bP))),128))],8,gP)):e.createCommentVNode("",!0),e.unref(_t).uploads.value.length>0&&d.value!=="trash"?(e.openBlock(),e.createElementBlock("div",yP,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(_t).uploads.value,ne=>(e.openBlock(),e.createElementBlock("article",{key:ne.cid,class:e.normalizeClass(["media-library-shell__upload-tile",`is-status-${ne.status}`]),"data-testid":`upload-tile-${ne.cid}`},[e.createElementVNode("div",kP,[ne.previewUrl?(e.openBlock(),e.createElementBlock("img",{key:0,src:ne.previewUrl,alt:ne.fileName},null,8,_P)):(e.openBlock(),e.createElementBlock("span",EP,"⤴"))]),e.createElementVNode("div",SP,[e.createElementVNode("span",CP,e.toDisplayString(ne.fileName),1),e.createElementVNode("span",xP,[ne.status==="uploading"||ne.status==="queued"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode("Uploading…")],64)):ne.status==="success"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode("Uploaded")],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createTextVNode(e.toDisplayString(ne.errorMessage??"Upload failed"),1)],64))])]),e.createElementVNode("button",{type:"button",class:"media-library-shell__upload-dismiss","data-testid":`btn-upload-dismiss-${ne.cid}`,onClick:Qe=>e.unref(_t).dismiss(ne.cid)}," × ",8,NP)],10,wP))),128))])):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(["media-library-shell__body",{"has-inspector-target":m.value!==null}])},[e.createElementVNode("main",VP,[J.value?(e.openBlock(),e.createElementBlock("header",TP,[e.createElementVNode("button",{type:"button",class:"media-library-shell__breadcrumb-back","data-testid":"btn-media-album-back",onClick:At}," ← "+e.toDisplayString(Pe.value.albums),1),Q[25]||(Q[25]=e.createElementVNode("span",{class:"media-library-shell__breadcrumb-sep","aria-hidden":"true"},"/",-1)),e.createElementVNode("div",BP,[e.createElementVNode("span",MP,e.toDisplayString(ce.value),1),Ue.value?(e.openBlock(),e.createElementBlock("div",IP,[e.createElementVNode("button",{type:"button",class:"media-library-shell__album-action-trigger","data-testid":"btn-media-active-album-actions","aria-label":Pe.value.albumActions(Ue.value.name),"aria-haspopup":"menu","aria-controls":Se(Ue.value.id),"aria-expanded":T.value===Ue.value.id?"true":"false",onClick:Q[4]||(Q[4]=e.withModifiers(ne=>Oe(Ue.value.id,ne),["stop"]))}," ⋯ ",8,$P),T.value===Ue.value.id?(e.openBlock(),e.createElementBlock("div",{key:0,id:Se(Ue.value.id),class:"media-library-shell__album-action-menu",role:"menu","data-testid":"media-active-album-action-menu",onKeydown:rt},[e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":"btn-media-active-album-edit",onClick:Q[5]||(Q[5]=e.withModifiers(ne=>bt(Ue.value),["stop"]))},e.toDisplayString(Pe.value.editAlbum),1),e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":"btn-media-active-album-delete",onClick:Q[6]||(Q[6]=e.withModifiers(ne=>Ct(Ue.value),["stop"]))},e.toDisplayString(Pe.value.deleteAlbum),1)],40,FP)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])])):e.createCommentVNode("",!0),d.value==="trash"?(e.openBlock(),e.createBlock(th,{key:1,"http-client":l.httpClient,onError:Q[7]||(Q[7]=ne=>s("error",ne))},null,8,["http-client"])):W.value?(e.openBlock(),e.createElementBlock("section",{key:2,class:"media-album-grid","data-testid":"media-album-grid","aria-label":Pe.value.albums},[e.createElementVNode("header",AP,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":Q[8]||(Q[8]=ne=>I.value=ne),type:"search",class:"media-album-grid__search",placeholder:Pe.value.findAlbum,"data-testid":"input-media-album-filter","aria-label":Pe.value.findAlbum},null,8,RP),[[e.vModelText,I.value]])]),e.createElementVNode("div",LP,[Ht.value?(e.openBlock(),e.createElementBlock("form",{key:1,class:"media-album-grid__new-tile media-album-grid__new-tile--form","data-testid":"media-album-new-tile-form",role:"listitem",novalidate:"",onSubmit:Q[11]||(Q[11]=e.withModifiers(ne=>void Et(),["prevent"])),onKeydown:Kt},[e.createElementVNode("label",UP,[e.createElementVNode("span",OP,e.toDisplayString(Pe.value.newAlbumNamePrompt),1),e.withDirectives(e.createElementVNode("input",{id:"media-album-grid-new-name",ref_key:"newAlbumInputRef",ref:Gt,"onUpdate:modelValue":Q[10]||(Q[10]=ne=>Zt.value=ne),type:"text",class:e.normalizeClass(["media-album-grid__new-tile-input",{"media-album-grid__new-tile-input--error":It.value!==""}]),maxlength:Ir+16,"aria-invalid":It.value!==""?"true":"false","aria-describedby":"media-album-grid-new-error",autocomplete:"off","data-testid":"input-media-album-new-tile-name",disabled:Ut.value,onInput:Yt},null,42,zP),[[e.vModelText,Zt.value]])]),It.value!==""?(e.openBlock(),e.createElementBlock("p",jP,e.toDisplayString(It.value),1)):e.createCommentVNode("",!0),e.createElementVNode("div",WP,[e.createElementVNode("button",{type:"button",class:"media-album-grid__new-tile-btn media-album-grid__new-tile-btn--ghost","data-testid":"btn-media-album-new-tile-cancel",disabled:Ut.value,onClick:yt},e.toDisplayString(Pe.value.newAlbumCancel),9,HP),e.createElementVNode("button",{type:"submit",class:"media-album-grid__new-tile-btn media-album-grid__new-tile-btn--primary","data-testid":"btn-media-album-new-tile-submit",disabled:!pe.value},[Ut.value?(e.openBlock(),e.createElementBlock("span",GP,"…")):(e.openBlock(),e.createElementBlock("span",XP,e.toDisplayString(Pe.value.newAlbumSubmit),1))],8,ZP)])],32)):(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"media-album-grid__new-tile","data-testid":"btn-media-album-new-tile",role:"listitem","aria-label":"Create new album",onClick:Q[9]||(Q[9]=ne=>void wt())},[Q[26]||(Q[26]=e.createElementVNode("span",{class:"media-album-grid__new-tile-glyph","aria-hidden":"true"},"+",-1)),e.createElementVNode("span",PP,e.toDisplayString(Pe.value.newAlbum),1)])),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(be.value,ne=>(e.openBlock(),e.createElementBlock("article",{key:ne.id,class:"media-album-grid__tile","data-testid":`media-album-tile-${ne.id}`,role:"listitem"},[e.createElementVNode("button",{type:"button",class:"media-album-grid__tile-button","data-testid":`btn-media-album-open-${ne.id}`,onClick:Qe=>$e(ne.id)},[e.createElementVNode("div",JP,[ye(ne)!==null?(e.openBlock(),e.createElementBlock("img",{key:0,class:"media-album-grid__cover-image",src:ye(ne),alt:"",loading:"lazy"},null,8,YP)):(e.openBlock(),e.createElementBlock("span",QP,e.toDisplayString(_e(ne)),1))]),e.createElementVNode("div",eU,[e.createElementVNode("span",tU,e.toDisplayString(ne.name),1),e.createElementVNode("span",aU,e.toDisplayString(Ne(ne)),1)])],8,qP),e.createElementVNode("div",nU,[e.createElementVNode("button",{type:"button",class:"media-album-grid__tile-action-trigger","data-testid":`btn-media-album-actions-${ne.id}`,"aria-label":Pe.value.albumActions(ne.name),"aria-haspopup":"menu","aria-controls":Se(ne.id),"aria-expanded":T.value===ne.id?"true":"false",onClick:e.withModifiers(Qe=>Oe(ne.id,Qe),["stop"])}," ⋯ ",8,oU),T.value===ne.id?(e.openBlock(),e.createElementBlock("div",{key:0,id:Se(ne.id),class:"media-album-grid__action-menu",role:"menu","data-testid":`media-album-action-menu-${ne.id}`,onKeydown:rt},[e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":`btn-media-album-edit-${ne.id}`,onClick:e.withModifiers(Qe=>bt(ne),["stop"])},e.toDisplayString(Pe.value.editAlbum),9,rU),e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":`btn-media-album-delete-${ne.id}`,onClick:e.withModifiers(Qe=>Ct(ne),["stop"])},e.toDisplayString(Pe.value.deleteAlbum),9,lU)],40,iU)):e.createCommentVNode("",!0)])],8,KP))),128))]),be.value.length===0&&I.value!==""?(e.openBlock(),e.createElementBlock("p",sU,e.toDisplayString(Pe.value.noAlbumMatchesFound),1)):be.value.length===0?(e.openBlock(),e.createElementBlock("p",dU,e.toDisplayString(Pe.value.noAlbumsYet),1)):e.createCommentVNode("",!0)],8,DP)):(e.openBlock(),e.createBlock(Qf,{key:`workspace-${ht.value}`,"http-client":l.httpClient,filters:$t.value,"initial-view":Ot.value,capabilities:l.capabilities,labels:{scopeLabel:ke.value},onFiltersChange:qe,onCreatePost:Q[12]||(Q[12]=ne=>s("create-post",ne)),onCreateGallery:Q[13]||(Q[13]=ne=>s("create-gallery",ne)),onAddToAlbum:gt,onEdit:Q[14]||(Q[14]=ne=>s("edit",ne)),onDeleted:Q[15]||(Q[15]=ne=>s("deleted",ne)),onRestored:Q[16]||(Q[16]=ne=>s("restored",ne)),onRestoreConflict:Q[17]||(Q[17]=ne=>s("restore-conflict",ne)),onError:Q[18]||(Q[18]=ne=>s("error",ne))},{"bulk-actions":e.withCtx(ne=>[e.createVNode(qd,{"selected-count":ne.selectedCount,"cross-page-count":ne.crossPageCount,scope:Jt.value,"source-album":st.value,capabilities:l.capabilities,onClear:ne.clearSelection,onBulkMoveToTrash:ne.onBulkDelete,onBulkAddToAlbum:Qe=>{var Tt;return(Tt=ne.onAddToAlbum)==null?void 0:Tt.call(ne)},onBulkMoveBetweenAlbums:Qe=>Cn({mediaIds:ne.selectedItemIds,items:ne.selectedItems,source:"bulk"}),onBulkRemoveFromCurrentAlbum:Qe=>void Ta({mediaIds:ne.selectedItemIds,items:ne.selectedItems,source:"bulk"}),onBulkCreatePost:Qe=>{var Tt;return(Tt=ne.onCreatePost)==null?void 0:Tt.call(ne)},onBulkCreateGallery:Qe=>{var Tt;return(Tt=ne.onCreateGallery)==null?void 0:Tt.call(ne)},onInspect:Qe=>tn({mediaIds:ne.selectedItemIds,items:ne.selectedItems},ne.crossPageCount)},null,8,["selected-count","cross-page-count","scope","source-album","capabilities","onClear","onBulkMoveToTrash","onBulkAddToAlbum","onBulkMoveBetweenAlbums","onBulkRemoveFromCurrentAlbum","onBulkCreatePost","onBulkCreateGallery","onInspect"])]),"item-actions":e.withCtx(ne=>[e.createElementVNode("div",cU,[e.createElementVNode("div",uU,[e.createElementVNode("button",{type:"button",class:"media-library-shell__item-action-trigger","data-testid":`btn-media-shell-item-actions-${ne.media.uuid}`,"aria-label":Pe.value.itemActions(va(ne.media)),"aria-haspopup":"menu","aria-controls":Qa(ne.media.uuid),"aria-expanded":f.value===ne.media.uuid?"true":"false",onClick:Qe=>On(ne.media.uuid,Qe)}," ... ",8,mU),f.value===ne.media.uuid?(e.openBlock(),e.createElementBlock("div",{key:0,id:Qa(ne.media.uuid),class:"media-library-shell__item-action-panel",role:"menu","data-testid":`media-shell-item-actions-menu-${ne.media.uuid}`,onKeydown:zn},[e.createElementVNode("button",{type:"button",role:"menuitem","data-testid":`btn-media-shell-preview-${ne.media.uuid}`,onClick:Qe=>ga(ne.onPreview)},e.toDisplayString(ne.labels.previewButton),9,fU),ne.onEdit?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",role:"menuitem","data-testid":`btn-media-shell-edit-${ne.media.uuid}`,onClick:Qe=>ga(ne.onEdit)},e.toDisplayString(ne.labels.editButton),9,hU)):e.createCommentVNode("",!0),ne.onCreatePost?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",role:"menuitem","data-testid":`btn-media-shell-create-post-${ne.media.uuid}`,onClick:Qe=>ga(ne.onCreatePost)},e.toDisplayString(ne.labels.createPostButton),9,vU)):e.createCommentVNode("",!0),ne.onCreateGallery?(e.openBlock(),e.createElementBlock("button",{key:2,type:"button",role:"menuitem","data-testid":`btn-media-shell-create-gallery-${ne.media.uuid}`,onClick:Qe=>ga(ne.onCreateGallery)},e.toDisplayString(ne.labels.createGalleryButton),9,gU)):e.createCommentVNode("",!0),st.value!==null&&l.capabilities.allowAddToAlbum===!0?(e.openBlock(),e.createElementBlock("button",{key:3,type:"button",role:"menuitem","data-testid":`btn-media-shell-move-album-${ne.media.uuid}`,onClick:Qe=>ga(()=>Ra(ne.media))},e.toDisplayString(Pe.value.moveToAnotherAlbum),9,bU)):ne.onAddToAlbum?(e.openBlock(),e.createElementBlock("button",{key:4,type:"button",role:"menuitem","data-testid":`btn-media-shell-add-album-${ne.media.uuid}`,onClick:Qe=>ga(ne.onAddToAlbum)},e.toDisplayString(ne.labels.addToAlbumButton),9,yU)):e.createCommentVNode("",!0),st.value!==null?(e.openBlock(),e.createElementBlock("button",{key:5,type:"button",role:"menuitem","data-testid":`btn-media-shell-remove-current-album-${ne.media.uuid}`,onClick:Qe=>ga(()=>Wo(ne.media))},e.toDisplayString(Pe.value.removeFromThisAlbum),9,wU)):e.createCommentVNode("",!0)],40,pU)):e.createCommentVNode("",!0)])])]),_:1},8,["http-client","filters","initial-view","capabilities","labels"]))]),e.createVNode(zf,{open:v.value,"selected-count":((Fe=p.value)==null?void 0:Fe.mediaIds.length)??0,onCancel:ot,onConfirm:Za,onError:Q[19]||(Q[19]=ne=>s("error",ne))},null,8,["open","selected-count"]),e.createVNode(qf,{class:"media-library-shell__inspector",target:m.value,"http-client":l.httpClient,capabilities:q.value,mode:k.value,"in-album-scope":c.value!==null&&c.value!=="unfiled",labels:{removeFromThisAlbum:Pe.value.removeFromThisAlbum,removeFromAlbums:st.value!==null?Pe.value.moveToAnotherAlbum:Pe.value.addToAlbum},onEdit:vi,onDownload:ba,onMoveToTrash:Wn,onSetAsAlbumCover:zt,onRemoveFromThisAlbum:lo,onRemoveFromAlbums:Ba,onBulkAddToAlbum:Xa,onBulkCreateAlbum:Xa,onBulkMoveToTrash:da,onMetadataUpdated:xn,onClose:F},null,8,["target","http-client","capabilities","mode","in-album-scope","labels"])],2),(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[me.value&&B.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"media-album-dialog","data-testid":"media-album-dialog",role:"presentation",onKeydown:pt},[e.createElementVNode("button",{type:"button",class:"media-album-dialog__backdrop","data-testid":"btn-media-album-dialog-backdrop","aria-label":Pe.value.closeAlbumDialog,tabindex:"-1",onClick:mt},null,8,kU),e.createElementVNode("section",{ref_key:"albumDialogPanelRef",ref:z,class:"media-album-dialog__panel",role:"dialog","aria-modal":"true","aria-labelledby":"media-album-dialog-title","aria-describedby":N.value==="delete"?"media-album-dialog-delete-description media-album-dialog-error":void 0},[N.value==="edit"?(e.openBlock(),e.createElementBlock("form",{key:0,class:"media-album-dialog__form","data-testid":"media-album-edit-form",onSubmit:Q[22]||(Q[22]=e.withModifiers(ne=>void Nt(),["prevent"]))},[e.createElementVNode("header",EU,[e.createElementVNode("h3",SU,e.toDisplayString(Pe.value.editAlbumTitle),1)]),e.createElementVNode("label",CU,[e.createElementVNode("span",null,e.toDisplayString(Pe.value.albumNameLabel),1),e.withDirectives(e.createElementVNode("input",{ref_key:"albumEditNameRef",ref:j,"onUpdate:modelValue":Q[20]||(Q[20]=ne=>P.value=ne),type:"text","data-testid":"input-media-album-edit-name",maxlength:Ir+16,"aria-invalid":M.value!==""?"true":"false",autocomplete:"off",disabled:E.value},null,8,xU),[[e.vModelText,P.value]])]),e.createElementVNode("label",NU,[e.createElementVNode("span",null,e.toDisplayString(Pe.value.albumDescriptionLabel),1),e.withDirectives(e.createElementVNode("textarea",{"onUpdate:modelValue":Q[21]||(Q[21]=ne=>x.value=ne),"data-testid":"textarea-media-album-edit-description",rows:"4",disabled:E.value},null,8,VU),[[e.vModelText,x.value]])]),M.value!==""?(e.openBlock(),e.createElementBlock("p",TU,e.toDisplayString(M.value),1)):e.createCommentVNode("",!0),e.createElementVNode("footer",BU,[e.createElementVNode("button",{type:"button",class:"media-album-dialog__button","data-testid":"btn-media-album-edit-cancel",disabled:E.value,onClick:mt},e.toDisplayString(Pe.value.cancelAlbumEdit),9,MU),e.createElementVNode("button",{type:"submit",class:"media-album-dialog__button media-album-dialog__button--primary","data-testid":"btn-media-album-edit-save",disabled:!Vt.value},e.toDisplayString(Pe.value.saveAlbum),9,IU)])],32)):(e.openBlock(),e.createElementBlock("div",$U,[e.createElementVNode("header",FU,[e.createElementVNode("h3",DU,e.toDisplayString(Pe.value.deleteAlbumTitle(B.value.name)),1)]),e.createElementVNode("p",AU,e.toDisplayString(Pe.value.deleteAlbumDescription),1),M.value!==""?(e.openBlock(),e.createElementBlock("p",RU,e.toDisplayString(M.value),1)):e.createCommentVNode("",!0),e.createElementVNode("footer",LU,[e.createElementVNode("button",{ref_key:"albumDeleteCancelRef",ref:L,type:"button",class:"media-album-dialog__button","data-testid":"btn-media-album-delete-cancel",disabled:D.value,onClick:mt},e.toDisplayString(Pe.value.cancelDeleteAlbum),9,PU),e.createElementVNode("button",{type:"button",class:"media-album-dialog__button media-album-dialog__button--danger","data-testid":"btn-media-album-delete-confirm",disabled:D.value,onClick:Q[23]||(Q[23]=ne=>void Ce())},e.toDisplayString(Pe.value.confirmDeleteAlbum),9,UU)])]))],8,_U)],32)):e.createCommentVNode("",!0)])),e.createVNode(Wf,{open:g.value,onClose:Q[24]||(Q[24]=ne=>g.value=!1)},null,8,["open"])],10,fP)}}}),zU=Ae(OU,[["__scopeId","data-v-ad1d5942"]]),jU={class:"album-nav-rail__search"},WU={class:"album-nav-rail__sr-only"},HU=["placeholder"],ZU={class:"album-nav-rail__primary","aria-label":"Media scopes"},GU={class:"album-nav-rail__count"},XU={class:"album-nav-rail__count"},KU={key:0,class:"album-nav-rail__recent","data-testid":"album-rail-recent","aria-label":"Recent albums"},qU={class:"album-nav-rail__section-label"},JU=["data-testid","onClick"],YU={class:"album-nav-rail__tree"},QU={class:"album-nav-rail__utility"},e9={class:"album-nav-rail__count"},t9=e.defineComponent({__name:"AlbumNavRail",props:{activeAlbumId:{},collapsed:{type:Boolean,default:!1},allowDragDropTarget:{type:Boolean,default:!1},mediaCounts:{default:()=>({})},labels:{default:()=>({})},recentAlbums:{default:()=>[]}},emits:["change-album","create-album","drop-media","open-trash"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(!1),r=e.ref(""),l=e.ref([]),s=e.ref(null),d=e.computed(()=>{var w,_,b,g,I,T;return{allMedia:((w=t.labels)==null?void 0:w.allMedia)??"All media",unfiled:((_=t.labels)==null?void 0:_.unfiled)??"Unfiled",newAlbum:((b=t.labels)==null?void 0:b.newAlbum)??"New album",findAlbum:((g=t.labels)==null?void 0:g.findAlbum)??"Find album...",trash:((I=t.labels)==null?void 0:I.trash)??"Trash",recentSection:((T=t.labels)==null?void 0:T.recentSection)??"Recent"}});function c(w){return typeof w=="number"&&Number.isFinite(w)?String(w):""}function u(w){n("change-album",w.id)}function m(w,_){i.value=!1,n("create-album",_?{name:w,parentId:_}:{name:w})}function p(w){var b;const _=((b=w.dataTransfer)==null?void 0:b.getData("application/x-mediables-media-ids"))??"";if(_.trim()==="")return l.value;try{const g=JSON.parse(_);return Array.isArray(g)?g.filter(I=>typeof I=="string"&&I.trim()!==""):[]}catch{return _.split(",").map(g=>g.trim()).filter(g=>g!=="")}}function f(w,_){t.allowDragDropTarget&&(w.preventDefault(),s.value=_)}function h(){s.value=null}function v(w,_){if(!t.allowDragDropTarget)return;w.preventDefault();const b=p(w);s.value=null,b.length!==0&&n("drop-media",{albumId:_==="all"||_==="unfiled"?null:_,mediaIds:b})}const y=e.computed(()=>({"is-collapsed":t.collapsed}));return(w,_)=>(e.openBlock(),e.createElementBlock("aside",{class:e.normalizeClass(["album-nav-rail",y.value]),"data-testid":"album-rail"},[e.createElementVNode("label",jU,[e.createElementVNode("span",WU,e.toDisplayString(d.value.findAlbum),1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":_[0]||(_[0]=b=>r.value=b),type:"search",placeholder:d.value.findAlbum,"data-testid":"input-album-rail-search"},null,8,HU),[[e.vModelText,r.value]])]),e.createElementVNode("nav",ZU,[e.createElementVNode("button",{type:"button",class:e.normalizeClass(["album-nav-rail__row",{"is-active":t.activeAlbumId===null,"is-drop-target":s.value==="all"}]),"data-testid":"album-rail-row-all",onClick:_[1]||(_[1]=b=>n("change-album",null)),onDragover:_[2]||(_[2]=b=>f(b,"all")),onDragleave:h,onDrop:_[3]||(_[3]=b=>v(b,"all"))},[e.createElementVNode("span",null,e.toDisplayString(d.value.allMedia),1),e.createElementVNode("span",GU,e.toDisplayString(c(t.mediaCounts.all)),1)],34),e.createElementVNode("button",{type:"button",class:e.normalizeClass(["album-nav-rail__row",{"is-active":t.activeAlbumId==="unfiled","is-drop-target":s.value==="unfiled"}]),"data-testid":"album-rail-row-unfiled",onClick:_[4]||(_[4]=b=>n("change-album","unfiled")),onDragover:_[5]||(_[5]=b=>f(b,"unfiled")),onDragleave:h,onDrop:_[6]||(_[6]=b=>v(b,"unfiled"))},[e.createElementVNode("span",null,e.toDisplayString(d.value.unfiled),1),e.createElementVNode("span",XU,e.toDisplayString(c(t.mediaCounts.unfiled)),1)],34)]),t.recentAlbums.length>0?(e.openBlock(),e.createElementBlock("section",KU,[e.createElementVNode("p",qU,e.toDisplayString(d.value.recentSection),1),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.recentAlbums,b=>(e.openBlock(),e.createElementBlock("button",{key:`recent-${b.id}`,type:"button",class:e.normalizeClass(["album-nav-rail__row album-nav-rail__row--recent",{"is-active":t.activeAlbumId===b.id}]),"data-testid":`album-rail-recent-${b.id}`,onClick:g=>n("change-album",b.id)},[e.createElementVNode("span",null,e.toDisplayString(b.name),1)],10,JU))),128))])):e.createCommentVNode("",!0),e.createElementVNode("div",YU,[e.createVNode(zl,{"model-value":t.activeAlbumId==="unfiled"?null:t.activeAlbumId,mode:"rail",compact:!0,draggable:!1,onAlbumSelected:u},null,8,["model-value"])]),e.createElementVNode("button",{type:"button",class:"album-nav-rail__new","data-testid":"btn-album-rail-new",onClick:_[7]||(_[7]=b=>i.value=!0)}," + "+e.toDisplayString(d.value.newAlbum),1),e.createVNode(jd,{open:i.value,onCancel:_[8]||(_[8]=b=>i.value=!1),onCreate:m},null,8,["open"]),e.createElementVNode("div",QU,[e.createElementVNode("button",{type:"button",class:e.normalizeClass(["album-nav-rail__row album-nav-rail__row--utility",{"is-drop-target":s.value==="trash"}]),"data-testid":"album-rail-row-trash",onClick:_[9]||(_[9]=b=>n("open-trash")),onDragover:_[10]||(_[10]=b=>f(b,"trash")),onDragleave:h,onDrop:_[11]||(_[11]=b=>v(b,"trash"))},[e.createElementVNode("span",null,e.toDisplayString(d.value.trash),1),e.createElementVNode("span",e9,e.toDisplayString(c(t.mediaCounts.trash)),1)],34)])],2))}}),a9=Ae(t9,[["__scopeId","data-v-0913c5b6"]]),n9=o=>`/v1/media/${o}/hide`,o9=o=>`/v1/media/${o}/unhide`,i9="/v1/media/bulk-hide",r9="/v1/media/bulk-unhide";function l9(o){const a=e.ref(!1),t=o.hideEndpoint??n9,n=o.unhideEndpoint??o9,i=o.bulkHideEndpoint??i9,r=o.bulkUnhideEndpoint??r9;async function l(d){a.value=!0;try{await o.httpClient.post(d,{})}finally{a.value=!1}}async function s(d,c){if(c.length===0)throw new Error("media_uuids must not be empty");a.value=!0;try{const u=await o.httpClient.post(d,{media_uuids:c});return{updated_count:Number((u==null?void 0:u.updated_count)??0),skipped_count:Number((u==null?void 0:u.skipped_count)??0)}}finally{a.value=!1}}return{hide:d=>l(t(d)),unhide:d=>l(n(d)),bulkHide:d=>s(i,d),bulkUnhide:d=>s(r,d),isMutating:a}}const s9={key:0,class:"media-selection-tray","data-testid":"media-selection-tray"},d9={class:"media-selection-tray__header"},c9={class:"media-selection-tray__title"},u9={class:"media-selection-tray__items"},m9={class:"media-selection-tray__item-preview"},p9=["src","alt"],f9={key:1,class:"media-selection-tray__file-icon"},h9={class:"media-selection-tray__item-copy"},v9=["aria-label","onClick"],g9=e.defineComponent({__name:"MediaSelectionTray",props:{items:{},selectedCountLabel:{default:"Selected items"},dismissLabel:{default:"Remove"}},emits:["remove"],setup(o,{emit:a}){const t=a;function n(r){var l;return r?r.thumbnail_url??((l=r.conversion_urls)==null?void 0:l.thumb)??r.preview_url??r.original_url??r.url??null:null}function i(r){return r!=null&&r.mime_type?r.mime_type.startsWith("image/"):!1}return(r,l)=>r.items.length>0?(e.openBlock(),e.createElementBlock("section",s9,[e.createElementVNode("header",d9,[e.createElementVNode("h3",c9,e.toDisplayString(r.selectedCountLabel),1)]),e.createElementVNode("div",u9,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.items,s=>{var d,c,u,m;return e.openBlock(),e.createElementBlock("article",{key:s.id,class:"media-selection-tray__item"},[e.createElementVNode("div",m9,[i(s.media)&&n(s.media)?(e.openBlock(),e.createElementBlock("img",{key:0,src:n(s.media),alt:((d=s.media)==null?void 0:d.alt_text)??((c=s.media)==null?void 0:c.file_name)??"Selected media",class:"media-selection-tray__thumb"},null,8,p9)):(e.openBlock(),e.createElementBlock("div",f9,[...l[0]||(l[0]=[e.createElementVNode("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[e.createElementVNode("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.createElementVNode("polyline",{points:"14 2 14 8 20 8"})],-1)])]))]),e.createElementVNode("div",h9,[e.createElementVNode("strong",null,e.toDisplayString(((u=s.media)==null?void 0:u.file_name)??s.id),1),e.createElementVNode("span",null,e.toDisplayString(s.status),1)]),e.createElementVNode("button",{type:"button",class:"media-selection-tray__remove","aria-label":`${r.dismissLabel} ${((m=s.media)==null?void 0:m.file_name)??s.id}`,onClick:p=>t("remove",s.id)},e.toDisplayString(r.dismissLabel),9,v9)])}),128))])])):e.createCommentVNode("",!0)}}),b9=Ae(g9,[["__scopeId","data-v-f2a3d69d"]]);function Qd(o={}){const a=e.ref(!1),t=e.ref(!1),n=e.ref(null),i=e.ref(null),r=e.ref(0),l=e.ref(0),s=e.ref(null),d=e.ref(null),c=e.computed(()=>d.value!==null),u=_=>{if(r.value++,d.value=null,i.value=null,t.value=!1,_!=null&&typeof _=="object"&&!(_ instanceof Blob)&&("image"in _||"state"in _||"sessionKey"in _)){const b=_;n.value=b.image??null,s.value=b.state??null,l.value=b.sessionKey??r.value}else n.value=_??null,s.value=null,l.value=r.value;a.value=!0},m=()=>{a.value=!1,n.value=null,i.value=null,d.value=null,t.value=!1,s.value=null},p=async _=>{try{return t.value=!0,i.value=_,o.onSave&&await o.onSave(_),m(),_}catch(b){const g=b;throw d.value=g,o.onError&&o.onError(g),g}finally{t.value=!1}},f=()=>{o.onCancel&&o.onCancel(),m()},h=_=>{d.value=_,o.onError&&o.onError(_)},v=()=>{d.value=null},y=()=>i.value,w=e.computed(()=>a.value&&i.value!==null&&!t.value);return{isOpen:a,isProcessing:t,uploadedImage:n,editedImage:i,sessionKey:l,initialState:s,error:d,hasError:c,hasUnsavedChanges:w,open:u,close:m,handleSave:p,handleCancel:f,handleError:h,clearError:v,getEditedImage:y}}let _s=null;function y9(o){return _s||(_s=Qd(o)),_s}function w9(o){return a=>new Promise((t,n)=>{Qd({...o,onSave:async r=>{o!=null&&o.onSave&&await o.onSave(r),t(r)},onError:r=>{o!=null&&o.onError&&o.onError(r),n(r)},onCancel:()=>{o!=null&&o.onCancel&&o.onCancel(),n(new Error("User cancelled"))}}).open(a)})}function ec(o){return o.filter(a=>a.media&&!a.markedForRemoval).map((a,t)=>{const n={uuid:a.media.uuid,name:a.name,order:t};return a.customProperties&&(n.custom_properties=a.customProperties),n})}function ud(o){return o.map((a,t)=>{const n={media:a,clientId:a.uuid,name:a.name||a.file_name,order:t};return a.custom_properties&&(n.customProperties=a.custom_properties),n})}function tc(o){if(o){const t={};o.apiBaseUrl!==void 0&&(t.apiBaseUrl=o.apiBaseUrl),o.isAdmin!==void 0&&(t.isAdmin=o.isAdmin),ai(t)}return{name:"mediables",async upload(t,n){const r=await ja().uploadFile(t,{collection:(n==null?void 0:n.collection)||"default",customProperties:n==null?void 0:n.customProperties});if(!r)throw new Error("Upload failed: No media returned");return{media:r,uuid:r.uuid}},async attach(t,n){await ja().attachMedia(n.modelType,String(n.modelId),[t],n.collection||"images")},async attachMany(t,n){await ja().attachMedia(n.modelType,String(n.modelId),t,n.collection||"images")},async detach(t,n){await ja().detachMedia(n.modelType,String(n.modelId),t,n.collection||"images")},async reorder(t,n){await ja().reorderMedia(t.modelType,String(t.modelId),n,t.collection||"images")},async fetchModelMedia(t){return await ja().fetchModelMedia(t.modelType,String(t.modelId),t.collection||"images")},getUrl(t,n){return ja().getMediaUrl(t,n)},getThumbnailUrl(t){var n,i;return(n=t.conversion_urls)!=null&&n.thumb?t.conversion_urls.thumb:(i=t.conversion_urls)!=null&&i.thumbnail?t.conversion_urls.thumbnail:t.thumbnail_url?t.thumbnail_url:t.original_url||t.url||""},async delete(t){await ja().deleteMedia(t)},async update(t,n){const r=await ja().updateMedia(t,n);if(!r)throw new Error("Update failed: No media returned");return r},configure(t){const n={};t.apiBaseUrl!==void 0&&(n.apiBaseUrl=t.apiBaseUrl),t.isAdmin!==void 0&&(n.isAdmin=t.isAdmin),ai(n)}}}let Hr=null;function k9(){return Hr||(Hr=tc()),Hr}function _9(){Hr=null}const E9={apiBaseUrl:"/media-library-pro"};function $r(){var o;return typeof document>"u"?null:((o=document.querySelector('meta[name="csrf-token"]'))==null?void 0:o.getAttribute("content"))||null}function Es(o){const a={uuid:o.uuid,file_name:o.fileName||o.name,mime_type:`application/${o.extension}`,size:o.size,disk:"public",original_url:o.original_url||"",created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return o.name&&(a.name=o.name),o.original_url&&(a.url=o.original_url),o.preview_url&&(a.thumbnail_url=o.preview_url,a.preview_url=o.preview_url),o.custom_properties&&(a.custom_properties=o.custom_properties),a}function ac(o){const a={...E9,...o};return{name:"spatie",async upload(n,i){const r=new FormData;r.append("file",n),i!=null&&i.collection&&r.append("collection",i.collection),i!=null&&i.customProperties&&r.append("custom_properties",JSON.stringify(i.customProperties));const l={Accept:"application/json",...a.headers},s=a.csrfToken||$r();s&&(l["X-CSRF-TOKEN"]=s);const d={method:"POST",headers:l,body:r,credentials:"include"};i!=null&&i.signal&&(d.signal=i.signal);const c=await fetch(`${a.apiBaseUrl}/uploads`,d);if(!c.ok){const p=await c.json().catch(()=>({message:"Upload failed"}));throw new Error(p.message||`HTTP ${c.status}`)}const u=await c.json(),m=Es(u);return i!=null&&i.onProgress&&i.onProgress(100),{media:m,uuid:u.uuid}},async attach(n,i){},async attachMany(n,i){},async detach(n,i){},async reorder(n,i){},async fetchModelMedia(n){const i={Accept:"application/json",...a.headers},r=a.csrfToken||$r();r&&(i["X-CSRF-TOKEN"]=r);const l=new URLSearchParams;l.append("model_type",n.modelType),l.append("model_id",String(n.modelId)),n.collection&&l.append("collection",n.collection);try{const s=await fetch(`${a.apiBaseUrl}/media?${l}`,{method:"GET",headers:i,credentials:"include"});if(!s.ok)throw new Error(`HTTP ${s.status}`);return(await s.json()).map(Es)}catch{return[]}},getUrl(n,i){var r;if(i){const l=(r=n.conversion_urls)==null?void 0:r[i];if(l)return l}return n.original_url||n.url||""},getThumbnailUrl(n){var i,r;return n.preview_url?n.preview_url:(i=n.conversion_urls)!=null&&i.preview?n.conversion_urls.preview:n.thumbnail_url?n.thumbnail_url:(r=n.conversion_urls)!=null&&r.thumb?n.conversion_urls.thumb:n.original_url||n.url||""},async delete(n){const i={Accept:"application/json",...a.headers},r=a.csrfToken||$r();r&&(i["X-CSRF-TOKEN"]=r);const l=await fetch(`${a.apiBaseUrl}/uploads/${n}`,{method:"DELETE",headers:i,credentials:"include"});if(!l.ok){const s=await l.json().catch(()=>({message:"Delete failed"}));throw new Error(s.message||`HTTP ${l.status}`)}},async update(n,i){const r={Accept:"application/json","Content-Type":"application/json",...a.headers},l=a.csrfToken||$r();l&&(r["X-CSRF-TOKEN"]=l);const s=await fetch(`${a.apiBaseUrl}/uploads/${n}`,{method:"PATCH",headers:r,body:JSON.stringify(i),credentials:"include"});if(!s.ok){const c=await s.json().catch(()=>({message:"Update failed"}));throw new Error(c.message||`HTTP ${s.status}`)}const d=await s.json();return Es(d)},configure(n){Object.assign(a,n)}}}let Zr=null;function S9(){return Zr||(Zr=ac()),Zr}function C9(){Zr=null}function ah(o,a){switch(o){case"mediables":return tc(a);case"spatie":return ac(a);default:throw new Error(`Unknown adapter: ${o}`)}}function nh(o={}){const{enabled:a=!0,onReorder:t,onDragStart:n,onDragEnd:i,draggingClass:r="is-dragging",dropTargetClass:l="is-drop-target"}=o,s=e.ref({isDragging:!1,dragIndex:null,dropIndex:null,draggedItem:null}),d=e.ref(!1);let c=null;function u(_,b,g){a&&("dataTransfer"in _&&_.dataTransfer&&(_.dataTransfer.effectAllowed="move",_.dataTransfer.setData("text/plain",String(g))),c=_.target,c&&c.classList.add(r),s.value={isDragging:!0,dragIndex:g,dropIndex:g,draggedItem:b},d.value=!0,n==null||n(b,g))}function m(_,b){var g;if(!(!a||!s.value.isDragging)&&(_.preventDefault(),s.value.dropIndex!==b)){const I=document.querySelector(`.${l}`);I==null||I.classList.remove(l);const T=(g=_.target)==null?void 0:g.closest("[data-index]");T==null||T.classList.add(l),s.value.dropIndex=b}}function p(){if(!s.value.isDragging)return;const{dragIndex:_,dropIndex:b,draggedItem:g}=s.value;c&&c.classList.remove(r);const I=document.querySelector(`.${l}`);I==null||I.classList.remove(l),_!==null&&b!==null&&_!==b&&g&&(t==null||t({fromIndex:_,toIndex:b,item:g})),h(),i==null||i()}function f(){c&&c.classList.remove(r);const _=document.querySelector(`.${l}`);_==null||_.classList.remove(l),h(),i==null||i()}function h(){s.value={isDragging:!1,dragIndex:null,dropIndex:null,draggedItem:null},d.value=!1,c=null}function v(_,b,g){const I=[..._],[T]=I.splice(b,1);return I.splice(g,0,T),I.map(($,N)=>({...$,order:N}))}function y(_,b){return{draggable:a,"data-index":b,onDragstart:g=>u(g,_,b),onDragover:g=>m(g,b),onDragend:()=>p(),onDrop:g=>{g.preventDefault(),p()}}}function w(_){_.key==="Escape"&&s.value.isDragging&&f()}return e.onMounted(()=>{document.addEventListener("keydown",w)}),e.onUnmounted(()=>{document.removeEventListener("keydown",w),f()}),{dragState:s,isDragging:d,startDrag:u,handleDragOver:m,endDrag:p,cancelDrag:f,reorderItems:v,getDragProps:y}}function Hl(o={}){const{initialItems:a=[],modelType:t,modelId:n,collection:i="images",maxItems:r,maxFileSize:l,acceptedMimeTypes:s,sortable:d=!0,disabled:c=!1,rules:u={},adapterType:m="mediables",adapter:p,maxConcurrentUploads:f=3,onChange:h,onUpload:v,onUploadComplete:y,onUploadError:w,onRemove:_,onReorder:b,onError:g,onReadyToSubmitChange:I}=o,T={maxItems:r,maxFileSize:l,acceptedMimeTypes:s,...u},$=p||ah(m),N=e.ref([]),B=e.ref(!1),P=e.ref([]);function x(ye){if(ye.length===0)return[];const Ne=ye[0];return"media"in Ne&&"clientId"in Ne?ye:ud(ye)}N.value=x(a);const{acceptString:M,canAddFiles:E}=Zd({rules:T}),D=Gd({adapter:$,maxConcurrent:f,rules:T,collection:i,onUploadStart:ye=>{v==null||v(ye)},onUploadComplete:(ye,Ne)=>{const Se=N.value.findIndex(Re=>Re.clientId===ye.id);Se!==-1&&(N.value[Se]={...N.value[Se],media:Ne,name:Ne.name||Ne.file_name,upload:{...ye,status:"completed"}}),y==null||y(Ne)},onUploadError:(ye,Ne)=>{const Se=N.value.findIndex(Re=>Re.clientId===ye.id);Se!==-1&&(N.value[Se]={...N.value[Se],upload:{...ye,status:"error",error:Ne.message},errors:[{field:"upload",message:Ne.message,code:"UPLOAD_ERROR"}]}),w==null||w({file:ye.file,message:Ne.message})},onQueueComplete:()=>{h==null||h(N.value)}}),{dragState:j,getDragProps:L,reorderItems:z}=nh({enabled:d&&!c,onReorder:ye=>{N.value=z(N.value,ye.fromIndex,ye.toIndex),b==null||b(N.value),h==null||h(N.value)}}),C=e.computed(()=>D.isUploading.value),A=e.computed(()=>!D.isUploading.value&&D.pendingCount.value===0),O=e.computed(()=>r?N.value.length>=r:!1),K=e.computed(()=>ec(N.value)),se=e.computed(()=>N.value.length),xe=e.computed(()=>r?Math.max(0,r-N.value.length):1/0);e.watch(A,ye=>{I==null||I(ye)});function ue(ye){N.value=x(ye),h==null||h(N.value)}async function le(ye){if(c)return;const Ne=Array.from(ye);if(!E(Ne.length,N.value.length)){const it={field:"count",message:`Maximum ${r} files allowed`,code:"MAX_ITEMS"};P.value=[it],g==null||g([it]);return}const Se=await D.addFiles(Ne),Re=N.value.length,Oe=Se.map((it,rt)=>({...it,order:Re+rt}));N.value=[...N.value,...Oe],h==null||h(N.value)}function Z(ye){c||(ye.upload&&(ye.upload.status==="uploading"||ye.upload.status==="pending")&&D.cancelUpload(ye.clientId),N.value=N.value.filter(Ne=>Ne.clientId!==ye.clientId),N.value=N.value.map((Ne,Se)=>({...Ne,order:Se})),_==null||_(ye),h==null||h(N.value))}function k(ye){const Ne=N.value.find(Se=>Se.clientId===ye);Ne&&Z(Ne)}function F(){c||(D.clearAll(),N.value=[],h==null||h(N.value))}function W(ye,Ne){c||!d||(N.value=z(N.value,ye,Ne),b==null||b(N.value),h==null||h(N.value))}function J(ye,Ne){if(c)return;const Se=N.value.findIndex(Re=>Re.clientId===ye);Se!==-1&&(N.value[Se]={...N.value[Se],...Ne},h==null||h(N.value))}function ce(ye){D.cancelUpload(ye),k(ye)}async function Ue(ye){await D.retryUpload(ye)}async function be(){if(!t||!n)throw new Error("modelType and modelId are required for save()");const ye={modelType:t,modelId:n,collection:i},Ne=N.value.filter(Se=>Se.media&&!Se.markedForRemoval).map(Se=>Se.media.uuid);B.value=!0;try{await $.attachMany(Ne,ye),await $.reorder(ye,Ne)}finally{B.value=!1}}async function _e(){if(!t||!n)throw new Error("modelType and modelId are required for load()");const ye={modelType:t,modelId:n,collection:i};B.value=!0;try{const Ne=await $.fetchModelMedia(ye);N.value=ud(Ne),h==null||h(N.value)}finally{B.value=!1}}return e.onMounted(()=>{t&&n&&a.length===0&&_e().catch(console.error)}),e.onUnmounted(()=>{D.clearAll()}),{items:N,setItems:ue,addFiles:le,removeItem:Z,removeItemById:k,clearAll:F,reorderItems:W,updateItem:J,cancelUpload:ce,retryUpload:Ue,save:be,load:_e,isLoading:B,isUploading:C,isReadyToSubmit:A,isAtMaxItems:O,errors:P,dragState:j,getDragProps:L,adapter:$,formValues:K,acceptString:M,count:se,remainingSlots:xe}}const x9=["aria-disabled"],N9=["accept","multiple","disabled"],V9={class:"media-dropzone__content"},T9={class:"media-dropzone__title"},B9={class:"media-dropzone__subtitle"},M9=["disabled"],I9={key:0,class:"media-dropzone__helper"},$9=e.defineComponent({__name:"MediaCollectionDropzone",props:{accept:{default:"*"},multiple:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},maxFileSize:{},maxItems:{},title:{default:"Drop files here"},subtitle:{default:"or click to browse"},buttonText:{default:"Select files"}},emits:["files"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(!1),r=e.ref(null),l=e.computed(()=>({"media-dropzone":!0,"media-dropzone--drag-over":i.value,"media-dropzone--disabled":t.disabled})),s=e.computed(()=>{const v=[];return t.maxFileSize&&v.push(`Max size: ${ul(t.maxFileSize)}`),t.maxItems&&t.maxItems>1&&v.push(`Max files: ${t.maxItems}`),v.join(" • ")});function d(v){v.preventDefault(),!t.disabled&&(i.value=!0)}function c(v){v.preventDefault(),i.value=!1}function u(v){v.preventDefault()}function m(v){var w;if(v.preventDefault(),i.value=!1,t.disabled)return;const y=(w=v.dataTransfer)==null?void 0:w.files;y&&y.length>0&&n("files",y)}function p(){var v;t.disabled||(v=r.value)==null||v.click()}function f(v){const y=v.target,w=y.files;w&&w.length>0&&n("files",w),y.value=""}function h(v){(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),p())}return(v,y)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(l.value),role:"button",tabindex:"0","aria-disabled":v.disabled,"aria-label":"Upload files",onClick:p,onKeydown:h,onDragenter:d,onDragleave:c,onDragover:u,onDrop:m},[e.createElementVNode("input",{ref_key:"fileInput",ref:r,type:"file",accept:v.accept,multiple:v.multiple,disabled:v.disabled,class:"media-dropzone__input",onChange:f},null,40,N9),e.createElementVNode("div",V9,[e.renderSlot(v.$slots,"icon",{},()=>[y[0]||(y[0]=e.createElementVNode("svg",{class:"media-dropzone__icon",xmlns:"http://www.w3.org/2000/svg",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.createElementVNode("polyline",{points:"17 8 12 3 7 8"}),e.createElementVNode("line",{x1:"12",y1:"3",x2:"12",y2:"15"})],-1))],!0),e.createElementVNode("p",T9,[e.renderSlot(v.$slots,"title",{},()=>[e.createTextVNode(e.toDisplayString(v.title),1)],!0)]),e.createElementVNode("p",B9,[e.renderSlot(v.$slots,"subtitle",{},()=>[e.createTextVNode(e.toDisplayString(v.subtitle),1)],!0)]),e.createElementVNode("button",{type:"button",class:"media-dropzone__button",disabled:v.disabled,onClick:e.withModifiers(p,["stop"])},[e.renderSlot(v.$slots,"button",{},()=>[e.createTextVNode(e.toDisplayString(v.buttonText),1)],!0)],8,M9),s.value?(e.openBlock(),e.createElementBlock("p",I9,e.toDisplayString(s.value),1)):e.createCommentVNode("",!0)])],42,x9))}}),nc=Ae($9,[["__scopeId","data-v-b1366c1e"]]),F9=["data-index"],D9={key:0,class:"media-item__drag-handle","aria-label":"Drag to reorder",role:"button",tabindex:"0"},A9={class:"media-item__thumbnail"},R9=["src","alt"],L9={key:1,class:"media-item__file-icon"},P9={key:2,class:"media-item__progress-overlay"},U9={class:"media-item__progress-text"},O9={key:3,class:"media-item__processing-overlay"},z9={key:4,class:"media-item__error-overlay"},j9={class:"media-item__info"},W9=["title"],H9={key:0,class:"media-item__size"},Z9={key:1,class:"media-item__error-message"},G9={class:"media-item__actions"},X9=["disabled"],K9=["disabled"],q9=["disabled"],J9=["disabled"],Y9=e.defineComponent({__name:"MediaCollectionItem",props:{item:{},adapter:{},disabled:{type:Boolean,default:!1},sortable:{type:Boolean,default:!1},showRemove:{type:Boolean,default:!0},showEdit:{type:Boolean,default:!1},index:{default:0}},emits:["remove","edit","retry","cancel"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(!1),r=e.computed(()=>{var b;return(b=t.item.upload)!=null&&b.previewUrl?t.item.upload.previewUrl:t.item.media?t.adapter.getThumbnailUrl(t.item.media):null}),l=e.computed(()=>{var b,g,I;return((b=t.item.upload)==null?void 0:b.status)==="uploading"||((g=t.item.upload)==null?void 0:g.status)==="pending"||((I=t.item.upload)==null?void 0:I.status)==="queued"}),s=e.computed(()=>{var b;return((b=t.item.upload)==null?void 0:b.status)==="processing"}),d=e.computed(()=>{var b;return((b=t.item.upload)==null?void 0:b.status)==="error"||t.item.errors&&t.item.errors.length>0}),c=e.computed(()=>{var b;return(b=t.item.upload)!=null&&b.error?t.item.upload.error:t.item.errors&&t.item.errors.length>0?t.item.errors[0].message:null}),u=e.computed(()=>{var b;return((b=t.item.upload)==null?void 0:b.progress)||0}),m=e.computed(()=>{var b;return t.item.name||((b=t.item.media)==null?void 0:b.file_name)||"Unknown file"}),p=e.computed(()=>{var $,N;const b=(($=t.item.media)==null?void 0:$.size)||((N=t.item.upload)==null?void 0:N.file.size);if(!b)return"";const g=1024,I=["Bytes","KB","MB","GB"],T=Math.floor(Math.log(b)/Math.log(g));return parseFloat((b/Math.pow(g,T)).toFixed(2))+" "+I[T]}),f=e.computed(()=>{var g,I;const b=((g=t.item.media)==null?void 0:g.mime_type)||((I=t.item.upload)==null?void 0:I.file.type);return b==null?void 0:b.startsWith("image/")}),h=e.computed(()=>({"media-item":!0,"media-item--uploading":l.value,"media-item--processing":s.value,"media-item--error":d.value,"media-item--disabled":t.disabled,"media-item--sortable":t.sortable}));function v(){t.disabled||n("remove",t.item)}function y(){t.disabled||n("edit",t.item)}function w(){t.disabled||n("retry",t.item)}function _(){t.disabled||n("cancel",t.item)}return(b,g)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(h.value),"data-index":b.index,onMouseenter:g[0]||(g[0]=I=>i.value=!0),onMouseleave:g[1]||(g[1]=I=>i.value=!1)},[b.sortable&&!b.disabled?(e.openBlock(),e.createElementBlock("div",D9,[...g[2]||(g[2]=[e.createStaticVNode('<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-v-ff81c9ec><circle cx="9" cy="5" r="1" data-v-ff81c9ec></circle><circle cx="9" cy="12" r="1" data-v-ff81c9ec></circle><circle cx="9" cy="19" r="1" data-v-ff81c9ec></circle><circle cx="15" cy="5" r="1" data-v-ff81c9ec></circle><circle cx="15" cy="12" r="1" data-v-ff81c9ec></circle><circle cx="15" cy="19" r="1" data-v-ff81c9ec></circle></svg>',1)])])):e.createCommentVNode("",!0),e.createElementVNode("div",A9,[r.value&&f.value?(e.openBlock(),e.createElementBlock("img",{key:0,src:r.value,alt:m.value,class:"media-item__image"},null,8,R9)):(e.openBlock(),e.createElementBlock("div",L9,[...g[3]||(g[3]=[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.createElementVNode("polyline",{points:"14 2 14 8 20 8"})],-1)])])),l.value?(e.openBlock(),e.createElementBlock("div",P9,[e.createElementVNode("div",{class:"media-item__progress-bar",style:e.normalizeStyle({width:`${u.value}%`})},null,4),e.createElementVNode("span",U9,e.toDisplayString(u.value)+"%",1)])):e.createCommentVNode("",!0),s.value?(e.openBlock(),e.createElementBlock("div",O9,[...g[4]||(g[4]=[e.createElementVNode("div",{class:"media-item__spinner","aria-label":"Processing"},null,-1)])])):e.createCommentVNode("",!0),d.value?(e.openBlock(),e.createElementBlock("div",z9,[...g[5]||(g[5]=[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("circle",{cx:"12",cy:"12",r:"10"}),e.createElementVNode("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.createElementVNode("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})],-1)])])):e.createCommentVNode("",!0)]),e.createElementVNode("div",j9,[e.createElementVNode("span",{class:"media-item__name",title:m.value},e.toDisplayString(m.value),9,W9),p.value?(e.openBlock(),e.createElementBlock("span",H9,e.toDisplayString(p.value),1)):e.createCommentVNode("",!0),c.value?(e.openBlock(),e.createElementBlock("span",Z9,e.toDisplayString(c.value),1)):e.createCommentVNode("",!0)]),e.createElementVNode("div",G9,[l.value?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"media-item__action media-item__action--cancel",disabled:b.disabled,"aria-label":"Cancel upload",onClick:_},[...g[6]||(g[6]=[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.createElementVNode("line",{x1:"6",y1:"6",x2:"18",y2:"18"})],-1)])],8,X9)):e.createCommentVNode("",!0),d.value?(e.openBlock(),e.createElementBlock("button",{key:1,type:"button",class:"media-item__action media-item__action--retry",disabled:b.disabled,"aria-label":"Retry upload",onClick:w},[...g[7]||(g[7]=[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("polyline",{points:"23 4 23 10 17 10"}),e.createElementVNode("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})],-1)])],8,K9)):e.createCommentVNode("",!0),b.showEdit&&b.item.media&&!l.value?(e.openBlock(),e.createElementBlock("button",{key:2,type:"button",class:"media-item__action media-item__action--edit",disabled:b.disabled,"aria-label":"Edit",onClick:y},[...g[8]||(g[8]=[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.createElementVNode("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})],-1)])],8,q9)):e.createCommentVNode("",!0),b.showRemove?(e.openBlock(),e.createElementBlock("button",{key:3,type:"button",class:"media-item__action media-item__action--remove",disabled:b.disabled,"aria-label":"Remove",onClick:v},[...g[9]||(g[9]=[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("polyline",{points:"3 6 5 6 21 6"}),e.createElementVNode("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})],-1)])],8,J9)):e.createCommentVNode("",!0)])],42,F9))}}),oc=Ae(Y9,[["__scopeId","data-v-ff81c9ec"]]),Q9=["aria-label"],eO=["draggable","data-index","onDragstart","onDragover","onDragend","onDrop"],tO={key:0,class:"media-collection__footer"},aO={class:"media-collection__count"},nO={key:0},oO={key:0,class:"media-collection__uploading"},iO=["name","value"],rO=["name","value"],lO=["name","value"],sO=["name","value"],dO={key:3,class:"media-collection__errors",role:"alert","aria-live":"polite"},cO=e.defineComponent({__name:"MediaCollection",props:{modelValue:{default:()=>[]},name:{default:"media"},modelType:{},modelId:{},collection:{default:"images"},maxItems:{},maxFileSize:{},acceptedMimeTypes:{},sortable:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},rules:{},adapter:{default:"mediables"},labels:{},showUploadZone:{type:Boolean,default:!0},generateFormFields:{type:Boolean,default:!0}},emits:["update:modelValue","change","upload","upload-complete","upload-error","remove","reorder","is-ready-to-submit-change","validation-error"],setup(o,{emit:a}){const t=o,n=a,i={initialItems:t.modelValue,modelType:t.modelType,modelId:t.modelId,collection:t.collection,maxItems:t.maxItems,maxFileSize:t.maxFileSize,acceptedMimeTypes:t.acceptedMimeTypes,sortable:t.sortable,disabled:t.disabled,rules:t.rules,adapterType:t.adapter,onChange:C=>{n("update:modelValue",C),n("change",C)},onUpload:C=>{n("upload",C)},onUploadComplete:C=>{n("upload-complete",C)},onUploadError:C=>{n("upload-error",C)},onRemove:C=>{n("remove",C)},onReorder:C=>{n("reorder",C)},onError:C=>{n("validation-error",C)},onReadyToSubmitChange:C=>{n("is-ready-to-submit-change",C)}},{items:r,setItems:l,addFiles:s,removeItem:d,reorderItems:c,cancelUpload:u,retryUpload:m,isLoading:p,isUploading:f,isAtMaxItems:h,errors:v,dragState:y,getDragProps:w,adapter:_,formValues:b,acceptString:g,count:I,remainingSlots:T}=Hl(i);e.provide("mediaAdapter",_),e.provide("mediaCollection",{items:r,addFiles:s,removeItem:d,reorderItems:c}),e.watch(()=>t.modelValue,C=>{C!==r.value&&l(C)},{deep:!0});const $=e.computed(()=>t.showUploadZone&&!t.disabled&&!t.readonly&&!h.value),N=e.computed(()=>({"media-collection":!0,"media-collection--disabled":t.disabled,"media-collection--readonly":t.readonly,"media-collection--loading":p.value,"media-collection--has-items":r.value.length>0,"media-collection--dragging":y.value.isDragging}));function B(C){s(C)}function P(C){d(C)}function x(C){m(C.clientId)}function M(C){u(C.clientId)}function E(C){}function D(C,A,O){if(!t.sortable||t.disabled)return;const K=w(A,O);K.onDragstart&&K.onDragstart(C)}function j(C,A){if(!t.sortable||t.disabled)return;C.preventDefault();const O=r.value[A],K=w(O,A);K.onDragover&&K.onDragover(C)}function L(C,A){const O=w(C,A);O.onDragend&&O.onDragend()}function z(C,A){C.preventDefault();const O=r.value[A],K=w(O,A);K.onDrop&&K.onDrop(C)}return(C,A)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(N.value)},[e.renderSlot(C.$slots,"dropzone",{addFiles:e.unref(s)},()=>[$.value?(e.openBlock(),e.createBlock(nc,{key:0,accept:e.unref(g),multiple:C.maxItems!==1,disabled:C.disabled,"max-file-size":C.maxFileSize,"max-items":e.unref(T),onFiles:B},null,8,["accept","multiple","disabled","max-file-size","max-items"])):e.createCommentVNode("",!0)],!0),e.unref(r).length>0?(e.openBlock(),e.createElementBlock("div",{key:0,class:"media-collection__list",role:"list","aria-label":`${e.unref(I)} media items`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(r),(O,K)=>e.renderSlot(C.$slots,"item",{key:O.clientId,item:O,index:K,remove:()=>P(O)},()=>[e.createElementVNode("div",{class:e.normalizeClass(["media-collection__item-wrapper",{"media-collection__item-wrapper--drag-over":e.unref(y).dropIndex===K}]),draggable:C.sortable&&!C.disabled,"data-index":K,onDragstart:se=>D(se,O,K),onDragover:se=>j(se,K),onDragend:se=>L(O,K),onDrop:se=>z(se,K)},[e.createVNode(oc,{item:O,adapter:e.unref(_),disabled:C.disabled,sortable:C.sortable,"show-remove":!C.readonly,"show-edit":!1,index:K,onRemove:P,onRetry:x,onCancel:M,onEdit:E},null,8,["item","adapter","disabled","sortable","show-remove","index"])],42,eO)],!0)),128))],8,Q9)):$.value?e.createCommentVNode("",!0):e.renderSlot(C.$slots,"empty",{key:1},()=>[A[0]||(A[0]=e.createElementVNode("div",{class:"media-collection__empty"},[e.createElementVNode("p",null,"No files uploaded")],-1))],!0),e.renderSlot(C.$slots,"footer",{count:e.unref(I),isUploading:e.unref(f)},()=>[e.unref(r).length>0?(e.openBlock(),e.createElementBlock("div",tO,[e.createElementVNode("span",aO,[e.createTextVNode(e.toDisplayString(e.unref(I))+" "+e.toDisplayString(e.unref(I)===1?"file":"files")+" ",1),C.maxItems?(e.openBlock(),e.createElementBlock("span",nO," / "+e.toDisplayString(C.maxItems)+" max",1)):e.createCommentVNode("",!0)]),e.unref(f)?(e.openBlock(),e.createElementBlock("span",oO," Uploading... ")):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)],!0),C.generateFormFields?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(b),(O,K)=>(e.openBlock(),e.createElementBlock("input",{key:`${C.name}-${O.uuid}`,type:"hidden",name:`${C.name}[${K}][uuid]`,value:O.uuid},null,8,iO))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(b),(O,K)=>(e.openBlock(),e.createElementBlock("input",{key:`${C.name}-${O.uuid}-name`,type:"hidden",name:`${C.name}[${K}][name]`,value:O.name},null,8,rO))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(b),(O,K)=>(e.openBlock(),e.createElementBlock("input",{key:`${C.name}-${O.uuid}-order`,type:"hidden",name:`${C.name}[${K}][order]`,value:O.order},null,8,lO))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(b),(O,K)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:`${C.name}-${O.uuid}-props`},[O.custom_properties?(e.openBlock(),e.createElementBlock("input",{key:0,type:"hidden",name:`${C.name}[${K}][custom_properties]`,value:JSON.stringify(O.custom_properties)},null,8,sO)):e.createCommentVNode("",!0)],64))),128))],64)):e.createCommentVNode("",!0),e.unref(v).length>0?(e.openBlock(),e.createElementBlock("div",dO,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(v),O=>(e.openBlock(),e.createElementBlock("p",{key:O.code||O.message,class:"media-collection__error"},e.toDisplayString(O.message),1))),128))])):e.createCommentVNode("",!0)],2))}}),uO=Ae(cO,[["__scopeId","data-v-10a5bfff"]]);function ic(o={}){const{initialItem:a,onChange:t,onReplace:n,onUpload:i,onUploadComplete:r,onUploadError:l,onRemove:s,onError:d,onReadyToSubmitChange:c,...u}=o,p={...u,initialItems:a?[a]:[],maxItems:1,sortable:!1,onChange:$=>{t==null||t($[0]||null)},onUpload:i,onUploadComplete:r,onUploadError:l,onRemove:s,onError:d,onReadyToSubmitChange:c},f=Hl(p),h=e.computed(()=>f.items.value[0]||null),v=e.computed(()=>h.value!==null),y=e.computed(()=>f.formValues.value[0]||null);function w($){$===null?f.clearAll():f.setItems([$])}async function _($){const N=h.value;N&&f.removeItem(N),await f.addFiles([$])}function b(){h.value&&f.removeItem(h.value)}async function g($){const N=h.value;N&&f.removeItem(N),await f.addFiles([$]);const B=f.items.value[0];B&&(n==null||n(N,B))}function I(){var $;($=h.value)!=null&&$.upload&&f.cancelUpload(h.value.clientId)}async function T(){var $,N;((N=($=h.value)==null?void 0:$.upload)==null?void 0:N.status)==="error"&&await f.retryUpload(h.value.clientId)}return{item:h,setItem:w,addFile:_,removeItem:b,replaceItem:g,cancelUpload:I,retryUpload:T,save:f.save,load:f.load,isLoading:f.isLoading,isUploading:f.isUploading,isReadyToSubmit:f.isReadyToSubmit,hasItem:v,errors:f.errors,adapter:f.adapter,formValue:y,acceptString:f.acceptString}}const mO=["accept","disabled"],pO={class:"media-attachment__preview"},fO=["name","value"],hO=["name","value"],vO=["name","value"],gO=["name","value"],bO={key:4,class:"media-attachment__errors",role:"alert","aria-live":"polite"},yO=e.defineComponent({__name:"MediaAttachment",props:{modelValue:{default:null},name:{default:"media"},modelType:{},modelId:{},collection:{default:"images"},maxFileSize:{},acceptedMimeTypes:{},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},rules:{},adapter:{default:"mediables"},labels:{},showUploadZone:{type:Boolean,default:!0},generateFormFields:{type:Boolean,default:!0},showReplaceButton:{type:Boolean,default:!0}},emits:["update:modelValue","change","upload","upload-complete","upload-error","remove","replace","is-ready-to-submit-change","validation-error"],setup(o,{emit:a}){const t=o,n=a,i=e.ref(null),r={initialItem:t.modelValue,modelType:t.modelType,modelId:t.modelId,collection:t.collection,maxFileSize:t.maxFileSize,acceptedMimeTypes:t.acceptedMimeTypes,disabled:t.disabled,rules:t.rules,adapterType:t.adapter,onChange:x=>{n("update:modelValue",x),n("change",x)},onUpload:x=>{n("upload",x)},onUploadComplete:x=>{n("upload-complete",x)},onUploadError:x=>{n("upload-error",x)},onRemove:x=>{n("remove",x)},onReplace:(x,M)=>{n("replace",M)},onError:x=>{n("validation-error",x)},onReadyToSubmitChange:x=>{n("is-ready-to-submit-change",x)}},{item:l,setItem:s,addFile:d,removeItem:c,replaceItem:u,cancelUpload:m,retryUpload:p,isLoading:f,hasItem:h,errors:v,adapter:y,formValue:w,acceptString:_}=ic(r);e.provide("mediaAdapter",y),e.watch(()=>t.modelValue,x=>{x!==l.value&&s(x)},{deep:!0});const b=e.computed(()=>t.showUploadZone&&!t.disabled&&!t.readonly&&!h.value),g=e.computed(()=>({"media-attachment":!0,"media-attachment--disabled":t.disabled,"media-attachment--readonly":t.readonly,"media-attachment--loading":f.value,"media-attachment--has-item":h.value}));function I(x){x.length>0&&d(x[0])}function T(){var x;(x=i.value)==null||x.click()}function $(x){const M=x.target,E=M.files;E&&E.length>0&&u(E[0]),M.value=""}function N(x){c()}function B(x){p()}function P(x){m()}return(x,M)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(g.value)},[e.createElementVNode("input",{ref_key:"fileInputRef",ref:i,type:"file",accept:e.unref(_),disabled:x.disabled,class:"media-attachment__hidden-input",onChange:$},null,40,mO),b.value?e.renderSlot(x.$slots,"dropzone",{key:0,addFile:e.unref(d)},()=>[e.createVNode(nc,{accept:e.unref(_),multiple:!1,disabled:x.disabled,"max-file-size":x.maxFileSize,onFiles:I},null,8,["accept","disabled","max-file-size"])],!0):e.unref(h)&&e.unref(l)?e.renderSlot(x.$slots,"preview",{key:1,item:e.unref(l),remove:e.unref(c),replace:T},()=>[e.createElementVNode("div",pO,[e.createVNode(oc,{item:e.unref(l),adapter:e.unref(y),disabled:x.disabled,sortable:!1,"show-remove":!x.readonly,"show-edit":!1,onRemove:N,onRetry:B,onCancel:P},null,8,["item","adapter","disabled","show-remove"]),x.showReplaceButton&&!x.readonly&&!x.disabled&&e.unref(l).media?(e.openBlock(),e.createElementBlock("button",{key:0,type:"button",class:"media-attachment__replace-button",onClick:T},[...M[0]||(M[0]=[e.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[e.createElementVNode("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.createElementVNode("polyline",{points:"17 8 12 3 7 8"}),e.createElementVNode("line",{x1:"12",y1:"3",x2:"12",y2:"15"})],-1),e.createTextVNode(" Replace ",-1)])])):e.createCommentVNode("",!0)])],!0):e.renderSlot(x.$slots,"empty",{key:2},()=>[M[1]||(M[1]=e.createElementVNode("div",{class:"media-attachment__empty"},[e.createElementVNode("p",null,"No file selected")],-1))],!0),x.generateFormFields&&e.unref(w)?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[e.createElementVNode("input",{type:"hidden",name:`${x.name}[uuid]`,value:e.unref(w).uuid},null,8,fO),e.createElementVNode("input",{type:"hidden",name:`${x.name}[name]`,value:e.unref(w).name},null,8,hO),e.createElementVNode("input",{type:"hidden",name:`${x.name}[order]`,value:e.unref(w).order},null,8,vO),e.unref(w).custom_properties?(e.openBlock(),e.createElementBlock("input",{key:0,type:"hidden",name:`${x.name}[custom_properties]`,value:JSON.stringify(e.unref(w).custom_properties)},null,8,gO)):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0),e.unref(v).length>0?(e.openBlock(),e.createElementBlock("div",bO,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(v),E=>(e.openBlock(),e.createElementBlock("p",{key:E.code||E.message,class:"media-attachment__error"},e.toDisplayString(E.message),1))),128))])):e.createCommentVNode("",!0)],2))}}),wO=Ae(yO,[["__scopeId","data-v-26911174"]]),oh={dropzone:{title:"Drop files here",subtitle:"or click to browse",button:"Select files"},item:{remove:"Remove",replace:"Replace",edit:"Edit",download:"Download"},errors:{maxItems:"Maximum {max} files allowed",maxFileSize:"File exceeds maximum size of {max}",invalidType:"File type not allowed",uploadFailed:"Upload failed"},status:{uploading:"Uploading...",processing:"Processing...",completed:"Complete",error:"Error"}},kO=e.defineComponent({__name:"MediaCollectionProvider",props:{modelValue:{default:()=>[]},name:{default:"media"},modelType:{},modelId:{},collection:{default:"images"},maxItems:{},maxFileSize:{},acceptedMimeTypes:{},sortable:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},rules:{},adapter:{default:"mediables"},labels:{},showUploadZone:{type:Boolean,default:!0},generateFormFields:{type:Boolean,default:!0}},emits:["update:modelValue","change","upload","upload-complete","upload-error","remove","reorder","is-ready-to-submit-change","validation-error"],setup(o,{expose:a,emit:t}){const n=o,i=t,r={initialItems:n.modelValue,modelType:n.modelType,modelId:n.modelId,collection:n.collection,maxItems:n.maxItems,maxFileSize:n.maxFileSize,acceptedMimeTypes:n.acceptedMimeTypes,sortable:n.sortable,disabled:n.disabled,rules:n.rules,adapterType:n.adapter,onChange:x=>{i("update:modelValue",x),i("change",x)},onUpload:x=>{i("upload",x)},onUploadComplete:x=>{i("upload-complete",x)},onUploadError:x=>{i("upload-error",x)},onRemove:x=>{i("remove",x)},onReorder:x=>{i("reorder",x)},onError:x=>{i("validation-error",x)},onReadyToSubmitChange:x=>{i("is-ready-to-submit-change",x)}},{items:l,setItems:s,addFiles:d,removeItem:c,reorderItems:u,updateItem:m,cancelUpload:p,retryUpload:f,isLoading:h,isUploading:v,isReadyToSubmit:y,isAtMaxItems:w,errors:_,dragState:b,getDragProps:g,adapter:I,formValues:T,acceptString:$}=Hl(r);e.provide("mediaAdapter",I),e.provide("mediaCollection",{items:l,addFiles:d,removeItem:c,reorderItems:u}),e.watch(()=>n.modelValue,x=>{x!==l.value&&s(x)},{deep:!0});const N=e.computed(()=>({...oh,...n.labels})),B=e.computed(()=>({accept:$.value,multiple:n.maxItems!==1,disabled:n.disabled||n.readonly||w.value})),P=e.computed(()=>({items:l.value,isLoading:h.value,isUploading:v.value,isReadyToSubmit:y.value,isAtMaxItems:w.value,errors:_.value,addFiles:d,removeItem:c,reorderItems:u,clearAll:()=>{l.value.forEach(x=>c(x))},cancelUpload:p,retryUpload:f,labels:N.value,dropzoneProps:B.value}));return a({items:l,addFiles:d,removeItem:c,reorderItems:u,updateItem:m,cancelUpload:p,retryUpload:f,isLoading:h,isUploading:v,isReadyToSubmit:y,isAtMaxItems:w,errors:_,dragState:b,getDragProps:g,adapter:I,formValues:T,acceptString:$}),(x,M)=>e.renderSlot(x.$slots,"default",e.normalizeProps(e.guardReactiveProps(P.value)))}}),_O=e.defineComponent({__name:"MediaAttachmentProvider",props:{modelValue:{default:null},name:{default:"media"},modelType:{},modelId:{},collection:{default:"images"},maxFileSize:{},acceptedMimeTypes:{},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},rules:{},adapter:{default:"mediables"},labels:{},showUploadZone:{type:Boolean,default:!0},generateFormFields:{type:Boolean,default:!0},showReplaceButton:{type:Boolean,default:!0}},emits:["update:modelValue","change","upload","upload-complete","upload-error","remove","replace","is-ready-to-submit-change","validation-error"],setup(o,{expose:a,emit:t}){const n=o,i=t,r={initialItem:n.modelValue,modelType:n.modelType,modelId:n.modelId,collection:n.collection,maxFileSize:n.maxFileSize,acceptedMimeTypes:n.acceptedMimeTypes,disabled:n.disabled,rules:n.rules,adapterType:n.adapter,onChange:N=>{i("update:modelValue",N),i("change",N)},onUpload:N=>{i("upload",N)},onUploadComplete:N=>{i("upload-complete",N)},onUploadError:N=>{i("upload-error",N)},onRemove:N=>{i("remove",N)},onReplace:(N,B)=>{i("replace",B)},onError:N=>{i("validation-error",N)},onReadyToSubmitChange:N=>{i("is-ready-to-submit-change",N)}},{item:l,setItem:s,addFile:d,removeItem:c,replaceItem:u,cancelUpload:m,retryUpload:p,isLoading:f,isUploading:h,isReadyToSubmit:v,hasItem:y,errors:w,adapter:_,formValue:b,acceptString:g}=ic(r);e.provide("mediaAdapter",_),e.watch(()=>n.modelValue,N=>{N!==l.value&&s(N)},{deep:!0});const I=e.computed(()=>({...oh,...n.labels})),T=e.computed(()=>({accept:g.value,multiple:!1,disabled:n.disabled||n.readonly||y.value})),$=e.computed(()=>({item:l.value,hasItem:y.value,isLoading:f.value,isUploading:h.value,isReadyToSubmit:v.value,errors:w.value,addFile:d,removeItem:c,replaceItem:u,cancelUpload:m,retryUpload:p,labels:I.value,dropzoneProps:T.value}));return a({item:l,setItem:s,addFile:d,removeItem:c,replaceItem:u,cancelUpload:m,retryUpload:p,isLoading:f,isUploading:h,isReadyToSubmit:v,hasItem:y,errors:w,adapter:_,formValue:b,acceptString:g}),(N,B)=>e.renderSlot(N.$slots,"default",e.normalizeProps(e.guardReactiveProps($.value)))}}),EO=["name","value"],SO=["name","value"],CO=["name","value"],xO=["name","value"],NO=e.defineComponent({__name:"MediaHiddenFields",props:{items:{default:()=>[]},item:{default:null},name:{default:"media"},format:{default:"mediables"}},setup(o){const a=o,t=e.computed(()=>a.item?[a.item]:a.items),n=e.computed(()=>ec(t.value));function i(s,d){var u;const c=((u=n.value[s])==null?void 0:u.uuid)||"";return`${a.name}[${c}][${d}]`}function r(s,d){return`${a.name}[${s}][${d}]`}function l(s,d){return a.format==="spatie"?i(s,d):r(s,d)}return(s,d)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.value,(c,u)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:c.uuid},[e.createElementVNode("input",{type:"hidden",name:l(u,"uuid"),value:c.uuid},null,8,EO),e.createElementVNode("input",{type:"hidden",name:l(u,"name"),value:c.name},null,8,SO),e.createElementVNode("input",{type:"hidden",name:l(u,"order"),value:c.order},null,8,CO),c.custom_properties&&Object.keys(c.custom_properties).length>0?(e.openBlock(),e.createElementBlock("input",{key:0,type:"hidden",name:l(u,"custom_properties"),value:JSON.stringify(c.custom_properties)},null,8,xO)):e.createCommentVNode("",!0)],64))),128))}}),VO=["data-testid"],TO=["data-testid"],BO=["id"],MO=["value","maxlength","disabled","aria-labelledby","placeholder","data-testid","onInput"],IO=e.defineComponent({__name:"MediaAttachmentMetadataFields",props:{items:{},disabled:{type:Boolean,default:!1},label:{default:"Caption"},placeholder:{default:"Add an optional caption"},maxLength:{default:500},testIdPrefix:{default:"media-attachment-metadata"},getItemLabel:{type:Function,default:(o,a)=>`${o.type==="video"?"video":"photo"} ${a+1}`}},emits:["update:items"],setup(o,{emit:a}){const t=o,n=a;function i(r,l){const s=l.target;s instanceof HTMLInputElement&&n("update:items",t.items.map((d,c)=>c!==r?d:{...d,caption:s.value===""?null:s.value}))}return(r,l)=>r.items.length>0?(e.openBlock(),e.createElementBlock("div",{key:0,class:"media-attachment-metadata-fields","data-testid":r.testIdPrefix},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.items,(s,d)=>(e.openBlock(),e.createElementBlock("div",{key:s._key??s.id??`${s.url}:${d}`,class:"media-attachment-metadata-fields__row","data-testid":`${r.testIdPrefix}-${d}`},[e.createElementVNode("p",{id:`${r.testIdPrefix}-label-${d}`,class:"media-attachment-metadata-fields__label"},e.toDisplayString(r.label)+" for "+e.toDisplayString(r.getItemLabel(s,d)),9,BO),e.createElementVNode("input",{value:s.caption??"",type:"text",class:"media-attachment-metadata-fields__input",maxlength:r.maxLength,disabled:r.disabled,"aria-labelledby":`${r.testIdPrefix}-label-${d}`,placeholder:r.placeholder,"data-testid":`input-${r.testIdPrefix}-${d}`,onInput:c=>i(d,c)},null,40,MO)],8,TO))),128))],8,VO)):e.createCommentVNode("",!0)}}),$O=Ae(IO,[["__scopeId","data-v-a153768a"]]);exports.AlbumBrowser=wf;exports.AlbumManager=nF;exports.AlbumMediaGrid=hF;exports.AlbumNavRail=a9;exports.AlbumTree=zl;exports.ArrayBufferTarget=yd;exports.ExistingMediaSelector=Tb;exports.ImageEditor=hm;exports.ImageEditorModal=vm;exports.LiveStreamManager=v5;exports.ManagedMediaGallery=rv;exports.MediaAlbumInlineCreate=jd;exports.MediaAlbumPickerModal=zf;exports.MediaAlbumUnavailableState=kf;exports.MediaAttachment=wO;exports.MediaAttachmentMetadataFields=$O;exports.MediaBulkActionBar=qd;exports.MediaCollection=uO;exports.MediaCollectionDropzone=nc;exports.MediaCollectionItem=oc;exports.MediaEmptyState=eh;exports.MediaFilterChips=Jf;exports.MediaInspectorPanel=qf;exports.MediaLibraryPicker=Of;exports.MediaLibraryPickerModal=HD;exports.MediaLibraryShell=zU;exports.MediaLibraryToolbar=jf;exports.MediaLibraryWorkspace=Qf;exports.MediaManagementView=Yf;exports.MediaPreviewSheet=Wd;exports.MediaSelectionTray=b9;exports.MediaShortcutHelp=Wf;exports.MediaSourceSheet=Vf;exports.MediaThumbnailCell=Bf;exports.MediaTrashWorkspace=th;exports.MediaUploadSheet=Tf;exports.MediaUsageList=Zf;exports.MediaVariantStrip=Gf;exports.MediaWorkspace=av;exports.ModelMediaManager=Jg;exports.Muxer=Pm;exports.RequiresConfirmationError=Wl;exports.VideoEditor=mf;exports.VideoEditorDialog=Q4;exports.VideoEditorSimple=EM;exports.VideoExportPanel=a3;exports.VideoJobClient=Ll;exports.VideoPlayer=vf;exports.VideoTimeline=GM;exports.VideoToolsPanel=AI;exports.VideoUploader=j3;exports.VirtualMediaGrid=Mf;exports._sfc_main=kO;exports._sfc_main$1=_O;exports._sfc_main$2=NO;exports.applyTemporaryMediaStoreConfig=lm;exports.configureAlbumStore=gf;exports.configureMediaStore=ai;exports.createAdapter=ah;exports.createImageEditor=w9;exports.createMediablesAdapter=tc;exports.createSpatieAdapter=ac;exports.formatFileSize=ul;exports.fromMediaArray=ud;exports.getFileExtension=If;exports.getImageDimensions=$f;exports.getMediablesAdapter=k9;exports.getSpatieAdapter=S9;exports.isImageFile=Hd;exports.normalizeRecipeForServerRender=F4;exports.recipeHasServerRenderableEdits=$4;exports.recipeHasUnsupportedServerEdits=hf;exports.resetMediablesAdapter=_9;exports.resetSpatieAdapter=C9;exports.restoreAlbumStoreConfig=x5;exports.restoreMediaStoreConfig=rm;exports.snapshotAlbumStoreConfig=C5;exports.snapshotMediaStoreConfig=im;exports.toFormValues=ec;exports.useAdminMediaStore=sm;exports.useAlbumDragDrop=yf;exports.useAlbumStore=Ul;exports.useAlbums=Ol;exports.useGlobalImageEditor=y9;exports.useImageEditorModal=Qd;exports.useMediaAttachment=ic;exports.useMediaCollection=Hl;exports.useMediaDeletion=Jd;exports.useMediaDragSort=nh;exports.useMediaLibraryPickerController=Uf;exports.useMediaLibraryQuery=Xd;exports.useMediaLibrarySession=Af;exports.useMediaLibraryStateMachine=Rf;exports.useMediaLibraryTelemetry=Lf;exports.useMediaLibraryUploads=Hf;exports.useMediaLibraryVisibility=l9;exports.useMediaMetadata=Kf;exports.useMediaSelection=fl;exports.useMediaStore=ja;exports.useMediaTrash=Yd;exports.useMediaUploadQueue=Gd;exports.useMediaValidation=Zd;exports.validateFile=Ff;
357
- //# sourceMappingURL=index-2jP5K__o.cjs.map
357
+ //# sourceMappingURL=index-LL2h0nsa.cjs.map