@plank-cms/plank 0.28.1 → 0.28.2

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.
@@ -216,7 +216,7 @@ ${n}`}}),s}var iq=new WeakMap;function aq(e,t){let n=iq.get(e);if(!n){let t={cal
216
216
  `):``,markdownTokenizer:{name:`orderedList`,level:`block`,start:e=>{let t=e.match(/^(\s*)(\d+)\.\s+/)?.index;return t===void 0?-1:t},tokenize:(e,t,n)=>{let r=e.split(`
217
217
  `),[i,a]=qZ(r);if(i.length===0)return;let o=JZ(i,0,n);if(o.length!==0)return{type:`list`,ordered:!0,start:i[0]?.number||1,items:o,raw:r.slice(0,a).join(`
218
218
  `)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(XZ,this.editor.getAttributes(ZZ)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let e=GK({find:QZ,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(e=GK({find:QZ,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(ZZ)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[e]}}),eQ=/^\s*(\[([( |x])?\])\s$/,tQ=cq.create({name:`taskItem`,addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:`taskList`,a11y:void 0}},content(){return this.options.nested?`paragraph block*`:`paragraph+`},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-checked`);return t===``||t===`true`},renderHTML:e=>({"data-checked":e.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51}]},renderHTML({node:e,HTMLAttributes:t}){return[`li`,rG(this.options.HTMLAttributes,t,{"data-type":this.name}),[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null}],[`span`]],[`div`,0]]},parseMarkdown:(e,t)=>{let n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode(`paragraph`,{},t.parseInline(e.tokens))):e.text?n.push(t.createNode(`paragraph`,{},[t.createNode(`text`,{text:e.text})])):n.push(t.createNode(`paragraph`,{},[])),e.nestedTokens&&e.nestedTokens.length>0){let r=t.parseChildren(e.nestedTokens);n.push(...r)}return t.createNode(`taskItem`,{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>rq(e,t,`- [${e.attrs?.checked?`x`:` `}] `),addKeyboardShortcuts(){let e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:r})=>{let i=document.createElement(`li`),a=document.createElement(`label`),o=document.createElement(`span`),s=document.createElement(`input`),c=document.createElement(`div`),l=e=>{var t;s.ariaLabel=((t=this.options.a11y)?.checkboxLabel)?.call(t,e,s.checked)||`Task item checkbox for ${e.textContent||`empty task item`}`};l(e),a.contentEditable=`false`,s.type=`checkbox`,s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`change`,t=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){s.checked=!s.checked;return}let{checked:i}=t.target;r.isEditable&&typeof n==`function`&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=n();if(typeof t!=`number`)return!1;let r=e.doc.nodeAt(t);return e.setNodeMarkup(t,void 0,{...r?.attrs,checked:i}),!0}).run(),!r.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(e,i)||(s.checked=!s.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([e,t])=>{i.setAttribute(e,t)}),i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,a.append(s,o),i.append(a,c),Object.entries(t).forEach(([e,t])=>{i.setAttribute(e,t)});let u=new Set(Object.keys(t));return{dom:i,contentDOM:c,update:e=>{if(e.type!==this.type)return!1;i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,l(e);let t=r.extensionManager.attributes,n=iG(e,t),a=new Set(Object.keys(n)),o=this.options.HTMLAttributes;return u.forEach(e=>{a.has(e)||(e in o?i.setAttribute(e,o[e]):i.removeAttribute(e))}),Object.entries(n).forEach(([e,t])=>{t==null?e in o?i.setAttribute(e,o[e]):i.removeAttribute(e):i.setAttribute(e,t)}),u=a,!0}}}},addInputRules(){return[GK({find:eQ,type:this.type,getAttributes:e=>({checked:e[e.length-1]===`x`})})]}}),nQ=cq.create({name:`taskList`,addOptions(){return{itemTypeName:`taskItem`,HTMLAttributes:{}}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return[`ul`,rG(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode(`taskList`,{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,`
219
- `):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=nq(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);return t?[{type:`taskList`,raw:t.raw,items:t.items}]:n.blockTokens(e)},i=nq(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});EK.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(AZ.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(jZ.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(HZ.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push($Z.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(tQ.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(nQ.configure(this.options.taskList)),e}});var rQ=`&nbsp;`,iQ=`\xA0`,aQ=cq.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,rG(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return n.length===1&&n[0].type===`text`&&(n[0].raw===rQ||n[0].text===rQ||n[0].raw===iQ||n[0].text===iQ)&&r.length===1&&r[0].type===`text`&&(r[0].text===rQ||r[0].text===iQ)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return``;let r=Array.isArray(e.content)?e.content:[];if(r.length===0){let e=Array.isArray(n?.previousNode?.content)?n.previousNode.content:[];return n?.previousNode?.type===`paragraph`&&e.length===0?rQ:``}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),oQ=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,sQ=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,cQ=_K.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,rG(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[HK({find:oQ,type:this.type})]},addPasteRules(){return[uq({find:sQ,type:this.type})]}}),lQ=cq.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),uQ=_K.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,rG(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`++${t.renderChildren(e)}++`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.indexOf(`++`)},tokenize(e,t,n){let r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(e);if(!r)return;let i=r[2].trim();return{type:`underline`,raw:r[0],text:i,tokens:n.inlineTokens(i)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}});function dQ(e={}){return new YL({view(t){return new fQ(t,e)}})}var fQ=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(t&&!i){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=oL(this.editorView.state.doc,e,this.editorView.dragging.slice);t!=null&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},pQ=class e extends DL{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):DL.near(r)}content(){return QP.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new mQ(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!gQ(e)||!_Q(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)<o.childCount:t.index(r)>0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}else if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!NL.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};pQ.prototype.visible=!1,pQ.findFrom=pQ.findGapCursorFrom,DL.jsonID(`gapcursor`,pQ);var mQ=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return pQ.valid(t)?new pQ(t):DL.near(t)}};function hQ(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function gQ(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||hQ(e.type))return!0;if(e.inlineContent)return!1}}return!0}function _Q(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||hQ(e.type))return!0;if(e.inlineContent)return!1}}return!0}function vQ(){return new YL({props:{decorations:CQ,createSelectionBetween(e,t,n){return t.pos==n.pos&&pQ.valid(n)?new pQ(n):null},handleClick:xQ,handleKeyDown:yQ,handleDOMEvents:{beforeinput:SQ}}})}var yQ=TU({ArrowLeft:bQ(`horiz`,-1),ArrowRight:bQ(`horiz`,1),ArrowUp:bQ(`vert`,-1),ArrowDown:bQ(`vert`,1)});function bQ(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof jL){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=pQ.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new pQ(c))),!0):!1}}function xQ(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!pQ.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&NL.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new pQ(r))),!0)}function SQ(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof pQ))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=Q.empty;for(let e=r.length-1;e>=0;e--)i=Q.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new QP(i,0,0));return a.setSelection(jL.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function CQ(e){if(!(e.selection instanceof pQ))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,wH.create(e.doc,[xH.widget(e.selection.head,t,{key:`gapcursor`})])}var wQ=200,TQ=function(){};TQ.prototype.append=function(e){return e.length?(e=TQ.from(e),!this.length&&e||e.length<wQ&&this.leafAppend(e)||this.length<wQ&&e.leafPrepend(this)||this.appendInner(e)):this},TQ.prototype.prepend=function(e){return e.length?TQ.from(e).append(this):this},TQ.prototype.appendInner=function(e){return new DQ(this,e)},TQ.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?TQ.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},TQ.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},TQ.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},TQ.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},TQ.from=function(e){return e instanceof TQ?e:e&&e.length?new EQ(e):TQ.empty};var EQ=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i<n;i++)if(e(this.values[i],r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){for(var i=t-1;i>=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=wQ)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=wQ)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(TQ);TQ.empty=new EQ([]);var DQ=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)},t.prototype.forEachInner=function(e,t,n,r){var i=this.left.length;if(t<i&&this.left.forEachInner(e,t,Math.min(n,i),r)===!1||n>i&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n<i&&this.left.forEachInvertedInner(e,Math.min(t,i),n,r)===!1)return!1},t.prototype.sliceInner=function(e,t){if(e==0&&t==this.length)return this;var n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(TQ),OQ=500,kQ=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step){i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);return}if(i){u.push(new jQ(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new jQ(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;e<t.steps.length;e++){let r=t.steps[e].invert(t.docs[e]),l=new jQ(t.mapping.maps[e],r,n),u;(u=c&&c.merge(l))&&(l=u,e?a.pop():s=s.slice(0,s.length-1)),a.push(l),n&&=(o++,void 0),i||(c=l)}let l=o-r.depth;return l>NQ&&(s=AQ(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new wI;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new jQ(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new jQ(i,o,l))}else r.push(new jQ(i))},i);let l=[];for(let e=n;e<o;e++)l.push(new jQ(a.maps[e]));let u=new e(this.items.slice(0,i).append(l).append(r),s);return u.emptyItemCount()>OQ&&(u=u.compress(this.items.length-r.length)),u}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new jQ(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(TQ.from(i.reverse()),a)}};kQ.empty=new kQ(TQ.empty,0);function AQ(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var jQ=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},MQ=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},NQ=20;function PQ(e,t,n,r){let i=n.getMeta(HQ),a;if(i)return i.historyState;n.getMeta(UQ)&&(e=new MQ(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(HQ))return o.getMeta(HQ).redo?new MQ(e.done.addTransform(n,void 0,r,VQ(t)),e.undone,IQ(n.mapping.maps),e.prevTime,e.prevComposition):new MQ(e.done,e.undone.addTransform(n,void 0,r,VQ(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!FQ(n,e.prevRanges)),s=o?LQ(e.prevRanges,n.mapping):IQ(n.mapping.maps);return new MQ(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,VQ(t)),kQ.empty,s,n.time,i??e.prevComposition)}else if(a=n.getMeta(`rebased`))return new MQ(e.done.rebased(n,a),e.undone.rebased(n,a),LQ(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new MQ(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),LQ(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function FQ(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i<t.length;i+=2)e<=t[i+1]&&r>=t[i]&&(n=!0)}),n}function IQ(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function LQ(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let i=t.map(e[r],1),a=t.map(e[r+1],-1);i<=a&&n.push(i,a)}return n}function RQ(e,t,n){let r=VQ(t),i=HQ.get(t).spec.config,a=(n?e.undone:e.done).popEvent(t,r);if(!a)return null;let o=a.selection.resolve(a.transform.doc),s=(n?e.done:e.undone).addTransform(a.transform,t.selection.getBookmark(),i,r),c=new MQ(n?s:a.remaining,n?a.remaining:s,null,0,-1);return a.transform.setSelection(o).setMeta(HQ,{redo:n,historyState:c})}var zQ=!1,BQ=null;function VQ(e){let t=e.plugins;if(BQ!=t){zQ=!1,BQ=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){zQ=!0;break}}return zQ}var HQ=new QL(`history`),UQ=new QL(`closeHistory`);function WQ(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new YL({key:HQ,state:{init(){return new MQ(kQ.empty,kQ.empty,null,0,-1)},apply(t,n,r){return PQ(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r=n==`historyUndo`?KQ:n==`historyRedo`?qQ:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function GQ(e,t){return(n,r)=>{let i=HQ.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=RQ(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var KQ=GQ(!1,!0),qQ=GQ(!0,!0);EK.create({name:`characterCount`,addOptions(){return{limit:null,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new YL({key:new QL(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit;if(i==null||i===0){e=!0;return}let a=this.storage.characters({node:r.doc});if(a>i){let t=a-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var JQ=EK.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[dQ(this.options)]}});EK.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new YL({key:new QL(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return wH.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(xH.node(t,t+e.nodeSize,{class:this.options.className}))}),wH.create(e,a)}}})]}});var YQ=EK.create({name:`gapCursor`,addProseMirrorPlugins(){return[vQ()]},extendNodeSchema(e){return{allowGapCursor:ZW(qW(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),XQ=`placeholder`;function ZQ(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}EK.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:XQ,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){let e=this.options.dataAttribute?`data-${ZQ(this.options.dataAttribute)}`:`data-${XQ}`;return[new YL({key:new QL(`placeholder`),props:{decorations:({doc:t,selection:n})=>{let r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=n,a=[];if(!r)return null;let o=this.editor.isEmpty;return t.descendants((t,n)=>{let r=i>=n&&i<=n+t.nodeSize,s=!t.isLeaf&&MG(t);if(!t.type.isTextblock)return this.options.includeChildren;if((r||!this.options.showOnlyCurrent)&&s){let i=[this.options.emptyNodeClass];o&&i.push(this.options.emptyEditorClass);let s=xH.node(n,n+t.nodeSize,{class:i.join(` `),[e]:typeof this.options.placeholder==`function`?this.options.placeholder({editor:this.editor,node:t,pos:n,hasAnchor:r}):this.options.placeholder});a.push(s)}return this.options.includeChildren}),wH.create(t,a)}}})]}}),EK.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new YL({key:new QL(`selection`),props:{decorations(n){return n.selection.empty||e.isFocused||!e.isEditable||NG(n.selection)||e.view.dragging?null:wH.create(n.doc,[xH.inline(n.selection.from,n.selection.to,{class:t.className})])}}})]}});function QQ({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var $Q=EK.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new QL(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new YL({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(!n.some(e=>e.getMeta(`skipTrailingNode`))&&c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!QQ({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!QQ({node:r,types:n})}}})]}}),e$=EK.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>KQ(e,t),redo:()=>({state:e,dispatch:t})=>qQ(e,t)}},addProseMirrorPlugins(){return[WQ(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),t$=EK.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push(qJ.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(HJ.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(AZ.configure(this.options.bulletList)),this.options.code!==!1&&e.push(XJ.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(eY.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(tY.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(JQ.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(YQ.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(nY.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push(rY.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(e$.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(iY.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(lY.configure(this.options.italic)),this.options.listItem!==!1&&e.push(jZ.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(HZ.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(wZ.configure(this.options?.link)),this.options.orderedList!==!1&&e.push($Z.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push(aQ.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(cQ.configure(this.options.strike)),this.options.text!==!1&&e.push(lQ.configure(this.options.text)),this.options.underline!==!1&&e.push(uQ.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push($Q.configure(this.options?.trailingNode)),e}}),n$=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,r$=cq.create({name:`image`,addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?`inline`:`block`},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?`img[src]`:`img[src]:not([src^="data:"])`}]},renderHTML({HTMLAttributes:e}){return[`img`,rG(this.options.HTMLAttributes,e)]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title,alt:e.text}),renderMarkdown:e=>{let t=e.attrs?.src??``,n=e.attrs?.alt??``,r=e.attrs?.title??``;return r?`![${n}](${t} "${r}")`:`![${n}](${t})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>`u`)return null;let{directions:e,minWidth:t,minHeight:n,alwaysPreserveAspectRatio:r}=this.options.resize;return({node:i,getPos:a,HTMLAttributes:o,editor:s})=>{let c=document.createElement(`img`);Object.entries(o).forEach(([e,t])=>{if(t!=null)switch(e){case`width`:case`height`:break;default:c.setAttribute(e,t);break}}),c.src=o.src;let l=new qK({element:c,editor:s,node:i,getPos:a,onResize:(e,t)=>{c.style.width=`${e}px`,c.style.height=`${t}px`},onCommit:(e,t)=>{let n=a();n!==void 0&&this.editor.chain().setNodeSelection(n).updateAttributes(this.name,{width:e,height:t}).run()},onUpdate:(e,t,n)=>e.type===i.type,options:{directions:e,min:{width:t,height:n},preserveAspectRatio:r===!0}}),u=l.dom;return u.style.visibility=`hidden`,u.style.pointerEvents=`none`,c.onload=()=>{u.style.visibility=``,u.style.pointerEvents=``},l}},addCommands(){return{setImage:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[UK({find:n$,type:this.type,getAttributes:e=>{let[,,t,n,r]=e;return{src:n,alt:t,title:r}}})]}});function i$({onClick:e,active:t,disabled:n,title:r,children:i}){return(0,H.jsx)(`button`,{type:`button`,title:r,disabled:n,onMouseDown:t=>{t.preventDefault(),e()},className:K(`flex size-7 items-center justify-center rounded transition-colors`,t?`bg-foreground text-background`:`text-muted-foreground hover:bg-accent hover:text-accent-foreground`,n&&`pointer-events-none opacity-40`),children:i})}function a$(){return(0,H.jsx)(`div`,{className:`mx-0.5 h-4 w-px bg-border`})}function o$(e,t){return!e||!t?null:`${e} × ${t}`}function s$(e){try{let t=new URL(e).pathname.split(`/`).filter(Boolean);return t[t.length-1]||`Image`}catch{let t=e.split(`?`)[0].split(`/`).filter(Boolean);return t[t.length-1]||`Image`}}async function c$(e,t){if(!(await fetch(`/cms/admin/media/${e}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({caption:t})})).ok)throw Error(`Could not update media caption.`)}function l$({node:e,deleteNode:t,selected:n,updateAttributes:r,editor:i}){let a=String(e.attrs.src??``),o=typeof e.attrs.mediaId==`string`?e.attrs.mediaId:null,s=typeof e.attrs.filename==`string`?e.attrs.filename:null,c=typeof e.attrs.alt==`string`?e.attrs.alt:null,l=typeof e.attrs.title==`string`?e.attrs.title:null,u=typeof e.attrs.width==`number`?e.attrs.width:null,d=typeof e.attrs.height==`number`?e.attrs.height:null,f=s||s$(a),p=o$(u,d),[m,h]=(0,v.useState)(l??``),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(!1),x=i.isEditable;(0,v.useEffect)(()=>{h(l??``)},[l]);async function S(){let e=m.trim()||null;if(e===(l?.trim()||null)){_(null);return}if(r({title:e}),_(null),o){b(!0);try{await c$(o,e)}catch(e){_(e instanceof Error?e.message:`Could not update media caption.`)}finally{b(!1)}}}return(0,H.jsx)(DJ,{className:K(`my-3`,`rounded-xl border bg-card shadow-xs transition-colors`,n?`border-primary ring-2 ring-primary/20`:`border-border`),contentEditable:!1,"data-drag-handle":!0,children:(0,H.jsxs)(`div`,{className:`flex items-start gap-3 p-3`,children:[(0,H.jsx)(`div`,{className:`size-18 shrink-0 overflow-hidden rounded-lg border bg-muted`,children:(0,H.jsx)(`img`,{src:a,alt:c??f,className:`h-full w-full object-cover`})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,H.jsx)(`p`,{className:`truncate text-sm font-medium text-foreground`,title:f,children:f}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[p&&(0,H.jsx)(`span`,{children:p}),c&&(0,H.jsxs)(`span`,{className:`truncate`,title:c,children:[`Alt: `,c]})]}),(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(zP,{value:m,onChange:e=>h(e.target.value),onBlur:S,placeholder:`Figcaption...`,disabled:!x,className:`min-h-8 resize-none border-0 bg-muted/60 px-2.5 py-1.5 text-xs text-muted-foreground shadow-none focus-visible:ring-1`}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:[(0,H.jsx)(`span`,{children:o?`Synced with Media Library`:`Local to this entry`}),y&&(0,H.jsx)(`span`,{children:`Saving…`})]}),g&&(0,H.jsx)(`p`,{className:`text-[11px] text-destructive`,children:g})]})]}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>t(),className:`flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive`,"aria-label":`Remove image`,children:(0,H.jsx)(es,{className:`size-4`})})]})})}function u$({value:e,onChange:t,placeholder:n,onInsertImage:r}){let[i,a]=(0,v.useState)(!e),o=CJ({extensions:[t$.configure({link:{openOnClick:!1,HTMLAttributes:{class:`text-primary underline`}}}),r$.extend({addAttributes(){return{...this.parent?.(),mediaId:{default:null},filename:{default:null},width:{default:null},height:{default:null}}},addNodeView(){return FJ(l$)}}).configure({inline:!1})],content:(()=>{if(!e)return``;try{return JSON.parse(e)}catch{return e}})(),editorProps:{attributes:{class:`h-128 px-3 py-2.5 focus:outline-none`}},onUpdate({editor:e}){a(e.isEmpty),t(JSON.stringify(e.getJSON()))}});(0,v.useEffect)(()=>{if(!o)return;let t=e?(()=>{try{return JSON.parse(e)}catch{return e}})():``;JSON.stringify(o.getJSON())!==e&&o.commands.setContent(t,{emitUpdate:!1}),a(o.isEmpty)},[e]);async function s(){if(!o||!r)return;let e=await r();if(!e||e.length===0)return;let t=e.map(e=>({type:`image`,attrs:{mediaId:e.id??void 0,src:e.src,filename:e.filename??void 0,alt:e.alt??void 0,title:e.title??void 0,width:e.width??void 0,height:e.height??void 0}}));o.chain().focus().insertContent(t).run()}function c(){if(!o)return;let e=o.getAttributes(`link`).href,t=window.prompt(`URL`,e??`https://`);if(t!==null){if(!t){o.chain().focus().unsetLink().run();return}o.chain().focus().setLink({href:t}).run()}}return o?(0,H.jsxs)(`div`,{className:`overflow-hidden rounded-md border border-input bg-background focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50`,children:[(0,H.jsxs)(`div`,{className:`sticky top-0 z-10 flex flex-wrap items-center gap-0.5 border-b border-border bg-background px-2 py-1.5`,children:[(0,H.jsx)(i$,{title:`Bold`,active:o.isActive(`bold`),onClick:()=>o.chain().focus().toggleBold().run(),children:(0,H.jsx)(Ra,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Italic`,active:o.isActive(`italic`),onClick:()=>o.chain().focus().toggleItalic().run(),children:(0,H.jsx)(Co,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Underline`,active:o.isActive(`underline`),onClick:()=>o.chain().focus().toggleUnderline().run(),children:(0,H.jsx)(rs,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Strikethrough`,active:o.isActive(`strike`),onClick:()=>o.chain().focus().toggleStrike().run(),children:(0,H.jsx)(Xo,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),(0,H.jsx)(i$,{title:`Heading 1`,active:o.isActive(`heading`,{level:1}),onClick:()=>o.chain().focus().toggleHeading({level:1}).run(),children:(0,H.jsx)(_o,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Heading 2`,active:o.isActive(`heading`,{level:2}),onClick:()=>o.chain().focus().toggleHeading({level:2}).run(),children:(0,H.jsx)(vo,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Heading 3`,active:o.isActive(`heading`,{level:3}),onClick:()=>o.chain().focus().toggleHeading({level:3}).run(),children:(0,H.jsx)(yo,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),(0,H.jsx)(i$,{title:`Bullet list`,active:o.isActive(`bulletList`),onClick:()=>o.chain().focus().toggleBulletList().run(),children:(0,H.jsx)(Mo,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Ordered list`,active:o.isActive(`orderedList`),onClick:()=>o.chain().focus().toggleOrderedList().run(),children:(0,H.jsx)(Ao,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),(0,H.jsx)(i$,{title:`Blockquote`,active:o.isActive(`blockquote`),onClick:()=>o.chain().focus().toggleBlockquote().run(),children:(0,H.jsx)(Ho,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Inline code`,active:o.isActive(`code`),onClick:()=>o.chain().focus().toggleCode().run(),children:(0,H.jsx)($a,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Code block`,active:o.isActive(`codeBlock`),onClick:()=>o.chain().focus().toggleCodeBlock().run(),children:(0,H.jsx)(Jo,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),(0,H.jsx)(i$,{title:`Add link`,active:o.isActive(`link`),onClick:c,children:(0,H.jsx)(ko,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Remove link`,disabled:!o.isActive(`link`),onClick:()=>o.chain().focus().unsetLink().run(),children:(0,H.jsx)(is,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),r&&(0,H.jsx)(i$,{title:`Insert image`,onClick:s,children:(0,H.jsx)(xo,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Hard break (Shift + Enter)`,onClick:()=>o.chain().focus().setHardBreak().run(),children:(0,H.jsx)(Qo,{className:`size-3.5`})})]}),(0,H.jsxs)(`div`,{className:`relative overflow-y-auto`,children:[i&&n&&(0,H.jsx)(`p`,{className:`pointer-events-none absolute left-3 top-2.5 text-muted-foreground select-none`,children:n}),(0,H.jsx)(hJ,{editor:o})]})]}):null}function d$(e){return{...e}}function f$(e){return e.type.startsWith(`image/`)?new Promise(t=>{let n=new Image,r=URL.createObjectURL(e);n.onload=()=>{URL.revokeObjectURL(r),t({width:n.naturalWidth,height:n.naturalHeight})},n.onerror=()=>{URL.revokeObjectURL(r),t(null)},n.src=r}):Promise.resolve(null)}async function p$(e,t){let n=await f$(e),r=await fetch(`/cms/admin/media/presign`,{method:`POST`,credentials:`include`,headers:d$({"Content-Type":`application/json`}),body:JSON.stringify({filename:e.name,mimeType:e.type,folderId:t?.folderId??null})});if(!r.ok)throw Error(`Upload failed.`);let i=await r.json();if(i.mode===`presigned`){if(!(await fetch(i.uploadUrl,{method:`PUT`,body:e,headers:{"Content-Type":e.type}})).ok)throw Error(`Upload failed.`);let r=await fetch(`/cms/admin/media/confirm`,{method:`POST`,credentials:`include`,headers:d$({"Content-Type":`application/json`}),body:JSON.stringify({key:i.key,filename:e.name,mimeType:e.type,size:e.size,folderId:t?.folderId??null,width:n?.width??null,height:n?.height??null})});if(!r.ok)throw Error(`Upload failed.`);return r.json()}let a=new FormData;a.append(`files`,e,e.name),t?.folderId&&a.append(`folder_id`,t.folderId),n?.width&&a.append(`width`,String(n.width)),n?.height&&a.append(`height`,String(n.height));let o=await fetch(`/cms/admin/media`,{method:`POST`,credentials:`include`,headers:d$(),body:a});if(!o.ok)throw Error(`Upload failed.`);return o.json()}async function m$(e){let t=await fetch(`/cms/admin/users/me/avatar/presign`,{method:`POST`,credentials:`include`,headers:d$({"Content-Type":`application/json`}),body:JSON.stringify({filename:e.name,mimeType:e.type})});if(!t.ok)throw Error(`Upload failed.`);let n=await t.json();if(n.mode===`presigned`){if(!(await fetch(n.uploadUrl,{method:`PUT`,body:e,headers:{"Content-Type":e.type}})).ok)throw Error(`Upload failed.`);let t=await fetch(`/cms/admin/users/me/avatar/confirm`,{method:`POST`,credentials:`include`,headers:d$({"Content-Type":`application/json`}),body:JSON.stringify({key:n.key})});if(!t.ok)throw Error(`Upload failed.`);return(await t.json()).avatarUrl}let r=new FormData;r.append(`file`,e);let i=await fetch(`/cms/admin/users/me/avatar`,{method:`POST`,credentials:`include`,headers:d$(),body:r});if(!i.ok)throw Error(`Upload failed.`);return(await i.json()).avatarUrl}var h$=1,g$=.9,_$=.8,v$=.17,y$=.1,b$=.999,x$=.9999,S$=.99,C$=/[\\\/_+.#"@\[\(\{&]/,w$=/[\\\/_+.#"@\[\(\{&]/g,T$=/[\s-]/,E$=/[\s-]/g;function D$(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?h$:S$;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=D$(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=h$:C$.test(e.charAt(l-1))?(d*=_$,p=e.slice(i,l-1).match(w$),p&&i>0&&(d*=b$**+p.length)):T$.test(e.charAt(l-1))?(d*=g$,m=e.slice(i,l-1).match(E$),m&&i>0&&(d*=b$**+m.length)):(d*=v$,i>0&&(d*=b$**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=x$)),(d<y$&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=D$(e,t,n,r,l+1,a+2,o),f*y$>d&&(d=f*y$)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function O$(e){return e.toLowerCase().replace(E$,` `)}function k$(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,D$(e,t,O$(e),O$(t),0,0,{})}var A$=`[cmdk-group=""]`,j$=`[cmdk-group-items=""]`,M$=`[cmdk-group-heading=""]`,N$=`[cmdk-item=""]`,P$=`${N$}:not([aria-disabled="true"])`,F$=`cmdk-item-select`,I$=`data-value`,L$=(e,t,n)=>k$(e,t,n),R$=v.createContext(void 0),z$=()=>v.useContext(R$),B$=v.createContext(void 0),V$=()=>v.useContext(B$),H$=v.createContext(void 0),U$=v.forwardRef((e,t)=>{let n=r1(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=r1(()=>new Set),i=r1(()=>new Map),a=r1(()=>new Map),o=r1(()=>new Set),s=t1(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,y=md(),b=md(),x=md(),S=v.useRef(null),C=o1();n1(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,w.emit()}},[u]),n1(()=>{C(6,A)},[]);let w=v.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)k(),D(),C(1,O);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(x);e?e.focus():(i=document.getElementById(y))==null||i.focus()}if(C(7,()=>{n.current.selectedItemId=j()?.id,w.emit()}),r||C(5,A),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}w.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),T=v.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,E(t,r)),C(2,()=>{D(),w.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),C(3,()=>{k(),D(),n.current.value||O(),w.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=j();C(4,()=>{k(),t?.getAttribute(`id`)===e&&O(),w.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:y,inputId:x,labelId:b,listInnerRef:S}),[]);function E(e,t){let r=s.current?.filter??L$;return e?r(e,n.current.search,t):0}function D(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=S.current;M().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest(j$);t?t.appendChild(e.parentElement===t?e:e.closest(`${j$} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${j$} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=S.current?.querySelector(`${A$}[${I$}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function O(){let e=M().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(I$);w.setState(`value`,e||void 0)}function k(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=E(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function A(){var e;let t=j();t&&(t.parentElement?.firstChild===t&&((e=t.closest(A$)?.querySelector(M$))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function j(){return S.current?.querySelector(`${N$}[aria-selected="true"]`)}function M(){return Array.from(S.current?.querySelectorAll(P$)||[])}function N(e){let t=M()[e];t&&w.setState(`value`,t.getAttribute(I$))}function P(e){var t;let n=j(),r=M(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&w.setState(`value`,a.getAttribute(I$))}function F(e){let t=j()?.closest(A$),n;for(;t&&!n;)t=e>0?$$(t,A$):e1(t,A$),n=t?.querySelector(P$);n?w.setState(`value`,n.getAttribute(I$)):P(e)}let I=()=>N(M().length-1),L=e=>{e.preventDefault(),e.metaKey?I():e.altKey?F(1):P(1)},R=e=>{e.preventDefault(),e.metaKey?N(0):e.altKey?F(-1):P(-1)};return v.createElement(cl.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&L(e);break;case`ArrowDown`:L(e);break;case`p`:case`k`:g&&e.ctrlKey&&R(e);break;case`ArrowUp`:R(e);break;case`Home`:e.preventDefault(),N(0);break;case`End`:e.preventDefault(),I();break;case`Enter`:{e.preventDefault();let t=j();if(t){let e=new Event(F$);t.dispatchEvent(e)}}}}},v.createElement(`label`,{"cmdk-label":``,htmlFor:T.inputId,id:T.labelId,style:l1},c),c1(e,e=>v.createElement(B$.Provider,{value:w},v.createElement(R$.Provider,{value:T},e))))}),W$=v.forwardRef((e,t)=>{let n=md(),r=v.useRef(null),i=v.useContext(H$),a=z$(),o=t1(e),s=o.current?.forceMount??i?.forceMount;n1(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=a1(n,r,[e.value,e.children,r],e.keywords),l=V$(),u=i1(e=>e.value&&e.value===c.current),d=i1(e=>s||a.filter()===!1?!0:e.search?e.filtered.items.get(n)>0:!0);v.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(F$,f),()=>t.removeEventListener(F$,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;p(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function p(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:m,value:h,onSelect:g,forceMount:_,keywords:y,...b}=e;return v.createElement(cl.div,{ref:hs(r,t),...b,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!m,"aria-selected":!!u,"data-disabled":!!m,"data-selected":!!u,onPointerMove:m||a.getDisablePointerSelection()?void 0:p,onClick:m?void 0:f},e.children)}),G$=v.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=md(),s=v.useRef(null),c=v.useRef(null),l=md(),u=z$(),d=i1(e=>i||u.filter()===!1?!0:e.search?e.filtered.groups.has(o):!0);n1(()=>u.group(o),[]),a1(o,s,[e.value,e.heading,c]);let f=v.useMemo(()=>({id:o,forceMount:i}),[i]);return v.createElement(cl.div,{ref:hs(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:d?void 0:!0},n&&v.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),c1(e,e=>v.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},v.createElement(H$.Provider,{value:f},e))))}),K$=v.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=v.useRef(null),a=i1(e=>!e.search);return!n&&!a?null:v.createElement(cl.div,{ref:hs(i,t),...r,"cmdk-separator":``,role:`separator`})}),q$=v.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=V$(),o=i1(e=>e.search),s=i1(e=>e.selectedItemId),c=z$();return v.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),v.createElement(cl.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),J$=v.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=v.useRef(null),o=v.useRef(null),s=i1(e=>e.selectedItemId),c=z$();return v.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),v.createElement(cl.div,{ref:hs(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},c1(e,e=>v.createElement(`div`,{ref:hs(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),Y$=v.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return v.createElement(dy,{open:n,onOpenChange:r},v.createElement(fy,{container:o},v.createElement(py,{"cmdk-overlay":``,className:i}),v.createElement(my,{"aria-label":e.label,"cmdk-dialog":``,className:a},v.createElement(U$,{ref:t,...s}))))}),X$=v.forwardRef((e,t)=>i1(e=>e.filtered.count===0)?v.createElement(cl.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),Z$=v.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return v.createElement(cl.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},c1(e,e=>v.createElement(`div`,{"aria-hidden":!0},e)))}),Q$=Object.assign(U$,{List:J$,Item:W$,Input:q$,Group:G$,Separator:K$,Dialog:Y$,Empty:X$,Loading:Z$});function $$(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function e1(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function t1(e){let t=v.useRef(e);return n1(()=>{t.current=e}),t}var n1=typeof window>`u`?v.useEffect:v.useLayoutEffect;function r1(e){let t=v.useRef();return t.current===void 0&&(t.current=e()),t}function i1(e){let t=V$(),n=()=>e(t.snapshot());return v.useSyncExternalStore(t.subscribe,n,n)}function a1(e,t,n,r=[]){let i=v.useRef(),a=z$();return n1(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(I$,s),i.current=s}),i}var o1=()=>{let[e,t]=v.useState(),n=r1(()=>new Map);return n1(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function s1(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function c1({asChild:e,children:t},n){return e&&v.isValidElement(t)?v.cloneElement(s1(t),{ref:t.ref},n(t.props.children)):n(t)}var l1={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`},u1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$,{ref:n,className:K(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...t}));u1.displayName=Q$.displayName;var d1=v.forwardRef(({className:e,...t},n)=>(0,H.jsxs)(`div`,{className:`flex items-center border-b px-3`,"data-cmdk-input-wrapper":``,children:[(0,H.jsx)(Go,{className:`mr-2 h-4 w-4 shrink-0 opacity-50`}),(0,H.jsx)(Q$.Input,{ref:n,className:K(`flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,e),...t})]}));d1.displayName=Q$.Input.displayName;var f1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$.List,{ref:n,className:K(`max-h-[300px] overflow-y-auto overflow-x-hidden`,e),...t}));f1.displayName=Q$.List.displayName;var p1=v.forwardRef((e,t)=>(0,H.jsx)(Q$.Empty,{ref:t,className:`py-6 text-center text-sm`,...e}));p1.displayName=Q$.Empty.displayName;var m1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$.Group,{ref:n,className:K(`overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground`,e),...t}));m1.displayName=Q$.Group.displayName;var h1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$.Separator,{ref:n,className:K(`-mx-1 h-px bg-border`,e),...t}));h1.displayName=Q$.Separator.displayName;var g1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$.Item,{ref:n,className:K(`relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,e),...t}));g1.displayName=Q$.Item.displayName;var _1=({className:e,...t})=>(0,H.jsx)(`span`,{className:K(`ml-auto text-xs tracking-widest text-muted-foreground`,e),...t});_1.displayName=`CommandShortcut`;var v1={image:`image/*`,video:`video/*`,audio:`audio/*`,document:`.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.csv`};function y1(e){return!e||e.length===0?`*/*`:e.map(e=>v1[e]).join(`,`)}function b1(e){let t=e.replace(/_/g,` `).trim();return t?t.charAt(0).toUpperCase()+t.slice(1):`Value`}function x1(e){return e?e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`:`—`}function S1(e){return e?.startsWith(`image/`)??!1}async function C1(e,t){return p$(e,{folderId:t})}function w1(e,t){if(!t||t.length===0)return!0;let n=e??``;return t.some(e=>e===`image`?n.startsWith(`image/`):e===`video`?n.startsWith(`video/`):e===`audio`?n.startsWith(`audio/`):e===`document`?n.startsWith(`application/`)||n.startsWith(`text/`):!1)}var T1=30;function E1({open:e,onOpenChange:t,allowedTypes:n,selectionMode:r=`single`,onSelect:i}){let[a,o]=(0,v.useState)([{id:null,name:`Media`}]),s=a[a.length-1].id,[c,l]=(0,v.useState)([]),[u,d]=(0,v.useState)([]),[f,p]=(0,v.useState)(1),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(1),[y,b]=(0,v.useState)(``),[x,S]=(0,v.useState)(``),[C,w]=(0,v.useState)([]);(0,v.useEffect)(()=>{let e=setTimeout(()=>{S(y),_(1)},300);return()=>clearTimeout(e)},[y]),(0,v.useEffect)(()=>{_(1),b(``),S(``)},[s]),(0,v.useEffect)(()=>{if(!e)return;h(!0);let t=s??``,n=x?`&search=${encodeURIComponent(x)}`:``;Promise.all([x?Promise.resolve([]):fetch(`/cms/admin/folders?parent_id=${t}`,{credentials:`include`}).then(e=>e.ok?e.json():{folders:[]}).then(e=>e.folders),fetch(`/cms/admin/media?folder_id=${t}&page=${g}&limit=${T1}${n}`,{credentials:`include`}).then(e=>e.ok?e.json():{items:[],pages:1})]).then(([e,t])=>{l(e),d(t.items),p(t.pages??1)}).catch(()=>{l([]),d([]),p(1)}).finally(()=>h(!1))},[e,s,g,x]),(0,v.useEffect)(()=>{e||(o([{id:null,name:`Media`}]),_(1),b(``),S(``),w([]))},[e]);function T(e){o(t=>[...t,{id:e.id,name:e.name}])}function E(e){o(t=>t.slice(0,e+1))}function D(e){if(r===`single`){i([e]),t(!1);return}w(t=>t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):[...t,e])}function O(e){let t=C.findIndex(t=>t.id===e);return t===-1?null:t+1}let k=u.filter(e=>w1(e.mime_type,n)),A=c.length===0&&k.length===0;return(0,H.jsx)(vy,{open:e,onOpenChange:t,children:(0,H.jsxs)(Sy,{className:`max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Media Library`})}),(0,H.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,H.jsx)(Go,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground pointer-events-none`}),(0,H.jsx)(J,{className:`pl-9 h-8`,placeholder:`Search media…`,value:y,onChange:e=>b(e.target.value)})]}),!x&&a.length>1&&(0,H.jsx)(`div`,{className:`flex items-center gap-1 text-sm shrink-0`,children:a.map((e,t)=>(0,H.jsxs)(`span`,{className:`flex items-center gap-1 text-muted-foreground`,children:[t>0&&(0,H.jsx)(`span`,{children:`/`}),t===a.length-1?(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:t===0?(0,H.jsx)(bo,{className:`size-3.5`}):e.name}):(0,H.jsx)(`button`,{onClick:()=>E(t),className:`hover:text-foreground transition-colors`,children:t===0?(0,H.jsx)(bo,{className:`size-3.5`}):e.name})]},`${e.id??`root`}:${e.name}`))}),m?(0,H.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-16`,children:(0,H.jsx)(ex,{className:`size-5`})}):A?(0,H.jsx)(`p`,{className:`flex-1 py-16 text-center text-sm text-muted-foreground`,children:x?`No matching files.`:u.length===0&&c.length===0?`No media found.`:`No matching files in this folder.`}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-0 overflow-y-auto pr-1`,children:[c.length>0&&(0,H.jsx)(`div`,{className:`grid grid-cols-1 gap-1.5 sm:grid-cols-2`,children:c.map(e=>(0,H.jsxs)(`button`,{type:`button`,onClick:()=>T(e),className:`flex items-center gap-2.5 rounded-md border bg-card px-2.5 py-2 text-left transition-colors hover:bg-muted/50 hover:border-primary`,children:[(0,H.jsx)(mo,{className:`size-7 shrink-0 text-muted-foreground`}),(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`p`,{className:`truncate text-xs font-bold leading-tight`,title:e.name,children:e.name}),(0,H.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[e.item_count,` `,e.item_count===1?`item`:`items`]})]})]},e.id))}),k.length>0&&(0,H.jsx)(`div`,{className:`grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-5`,children:k.map(e=>(0,H.jsxs)(`button`,{type:`button`,onClick:()=>D(e),className:K(`group relative overflow-hidden rounded-md border bg-card text-left transition-colors hover:border-primary`,O(e.id)!=null&&`border-primary ring-2 ring-primary/20`),children:[(0,H.jsx)(`div`,{className:`aspect-square bg-muted`,children:S1(e.mime_type)?(0,H.jsx)(`img`,{src:e.url,alt:e.filename,className:`h-full w-full object-cover`}):(0,H.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,H.jsx)(lo,{className:`size-6 text-muted-foreground`})})}),(0,H.jsxs)(`div`,{className:`p-1.5`,children:[(0,H.jsx)(`p`,{className:`truncate text-[11px] font-medium leading-tight`,title:e.filename,children:e.filename}),(0,H.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:x1(e.size)})]}),(0,H.jsx)(`div`,{className:K(`absolute inset-0 rounded-md ring-2 ring-primary ring-offset-1 transition-opacity pointer-events-none`,O(e.id)==null?`opacity-0 group-hover:opacity-100`:`opacity-100`)}),r===`multiple`&&O(e.id)!=null&&(0,H.jsx)(`div`,{className:`absolute right-1.5 top-1.5 flex size-6 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground shadow-sm`,children:O(e.id)})]},e.id))})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t pt-2 shrink-0`,children:[(0,H.jsx)(`div`,{className:`flex items-center gap-2`,children:r===`multiple`&&C.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[C.length,` selected`]}),(0,H.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 px-2 text-xs`,onClick:()=>w([]),children:`Clear`})]})}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[f>1&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`button`,{type:`button`,onClick:()=>_(e=>Math.max(1,e-1)),disabled:g===1,className:`text-sm text-muted-foreground hover:text-foreground disabled:opacity-40 disabled:pointer-events-none transition-colors`,children:`Previous`}),(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[g,` / `,f]}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>_(e=>Math.min(f,e+1)),disabled:g===f,className:`text-sm text-muted-foreground hover:text-foreground disabled:opacity-40 disabled:pointer-events-none transition-colors`,children:`Next`})]}),r===`multiple`&&(0,H.jsx)(q,{type:`button`,size:`sm`,disabled:C.length===0,onClick:()=>{i(C),t(!1)},children:`Insert selected`})]})]})]})})}function D1({value:e,onChange:t,allowedTypes:n,disabled:r=!1}){let i=(0,v.useRef)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(!1),p=typeof e==`string`&&e.startsWith(`http`);(0,v.useEffect)(()=>{if(!e){u(null);return}if(p){u(e);return}fetch(`/cms/admin/media/${e}/url`,{credentials:`include`}).then(e=>e.ok?e.json():null).then(e=>u(e?.url??null)).catch(()=>u(null))},[e,p]);async function m(e){o(!0),c(null);try{let n=await C1(e);u(n.url),t(n.id)}catch(e){c(e instanceof Error?e.message:`Upload failed.`),X.error(`Upload failed`)}finally{o(!1),i.current&&(i.current.value=``)}}let h=l&&/\.(jpe?g|png|gif|webp|avif|svg)(\?|$)/i.test(l);return e?(0,H.jsxs)(`div`,{className:`relative w-full rounded-md border bg-muted/30 overflow-hidden`,children:[l?h?(0,H.jsx)(`img`,{src:l,alt:`Media`,className:`max-h-72 w-full object-contain`}):(0,H.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,H.jsx)(xo,{className:`size-4 text-muted-foreground shrink-0`}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:l})]}):(0,H.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-muted-foreground`,children:[(0,H.jsx)(xo,{className:`size-4 shrink-0`}),(0,H.jsx)(`span`,{className:`text-xs`,children:`Loading…`})]}),(0,H.jsx)(q,{type:`button`,size:`icon`,variant:`secondary`,className:`absolute top-1.5 right-1.5 size-6`,onClick:()=>{t(null),u(null)},disabled:r,children:(0,H.jsx)(us,{className:`size-3.5`})})]}):(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`input`,{ref:i,type:`file`,accept:y1(n),className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&m(t)}}),(0,H.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{if(r)return;e.preventDefault();let t=e.dataTransfer.files[0];t&&m(t)},className:`flex w-full gap-2 rounded-md border border-dashed p-3`,children:[(0,H.jsxs)(`button`,{type:`button`,disabled:a||r,onClick:()=>i.current?.click(),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(as,{className:`size-4`}),a?`Uploading…`:`Upload`]}),(0,H.jsx)(`div`,{className:`w-px bg-border`}),(0,H.jsxs)(`button`,{type:`button`,disabled:a||r,onClick:()=>f(!0),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(fo,{className:`size-4`}),`Library`]})]}),s&&(0,H.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:s}),(0,H.jsx)(E1,{open:d,onOpenChange:f,allowedTypes:n,selectionMode:`single`,onSelect:e=>{let n=e[0];n&&(u(n.url),t(n.id))}})]})}function O1({id:e,previewUrl:t,filename:n,onRemove:r,disabled:i=!1}){let{attributes:a,listeners:o,setNodeRef:s,transform:c,transition:l,isDragging:u}=ok({id:e});return(0,H.jsxs)(`div`,{ref:s,style:{transform:yE.Transform.toString(c),transition:l,opacity:u?.4:1},className:`relative aspect-square overflow-hidden rounded-md border bg-muted`,children:[t?(0,H.jsx)(`img`,{src:t,alt:n,className:`h-full w-full object-cover`}):(0,H.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,H.jsx)(xo,{className:`size-5 text-muted-foreground`})}),n&&(0,H.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 bg-background/75 backdrop-blur-sm px-1.5 py-1 pointer-events-none`,children:(0,H.jsx)(`p`,{className:`truncate text-[10px] leading-none text-foreground`,children:n})}),(0,H.jsx)(`button`,{type:`button`,onClick:r,disabled:i,className:`absolute right-1 top-1 flex size-5 items-center justify-center rounded-full bg-background/80 text-foreground shadow-sm hover:bg-background`,children:(0,H.jsx)(us,{className:`size-3`})}),!i&&(0,H.jsx)(`button`,{type:`button`,className:`absolute bottom-6 left-1 flex size-5 cursor-grab items-center justify-center rounded-full bg-background/80 text-foreground shadow-sm active:cursor-grabbing`,...o,...a,children:(0,H.jsx)(ho,{className:`size-3`})})]})}function k1({value:e,onChange:t,disabled:n=!1}){let r=Array.isArray(e)?e:[],[,i]=(0,v.useState)(0),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(!1),d=(0,v.useRef)(null),f=(0,v.useRef)({}),p=(0,v.useRef)({}),m=r.join(`,`),h=FE(PE(FD,{activationConstraint:{distance:5}}));(0,v.useEffect)(()=>{let e=r.filter(e=>!e.startsWith(`http`)&&!(e in f.current));e.length!==0&&Promise.all(e.map(e=>fetch(`/cms/admin/media/${e}/url`,{credentials:`include`}).then(e=>e.ok?e.json():null).then(t=>t?[e,t.url]:null).catch(()=>null))).then(e=>{let t=!1;for(let n of e)n&&(f.current[n[0]]=n[1],t=!0);t&&i(e=>e+1)})},[m]),(0,v.useEffect)(()=>{let e=r.filter(e=>!e.startsWith(`http`)&&!(e in p.current));e.length!==0&&fetch(`/cms/admin/media`,{credentials:`include`}).then(e=>e.ok?e.json():{items:[]}).then(t=>{let n=!1;for(let r of t.items)e.includes(r.id)&&(p.current[r.id]=r.filename,n=!0);n&&i(e=>e+1)}).catch(()=>{})},[m]);function g(e){return e.startsWith(`http`)?e:f.current[e]??null}function _(e){return p.current[e]??``}function y(e){if(n)return;let{active:i,over:a}=e;!a||i.id===a.id||t(VO(r,r.indexOf(i.id),r.indexOf(a.id)))}async function b(e){if(e.length===0)return;o(!0),c(null);let n=r;try{for(let r of e){let e=await C1(r);f.current[e.id]=e.url,p.current[e.id]=r.name,i(e=>e+1),n=[...n,e.id],t(n)}}catch(e){c(e instanceof Error?e.message:`Upload failed.`),X.error(`Upload failed`)}finally{o(!1),d.current&&(d.current.value=``)}}return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`input`,{ref:d,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:e=>{b(Array.from(e.target.files??[]))}}),r.length>0&&(0,H.jsx)(MO,{sensors:h,collisionDetection:HE,onDragEnd:y,children:(0,H.jsx)(QO,{items:r,strategy:KO,children:(0,H.jsx)(`div`,{className:`grid grid-cols-3 gap-2 sm:grid-cols-4`,children:r.map(e=>(0,H.jsx)(O1,{id:e,previewUrl:g(e),filename:_(e),onRemove:()=>t(r.filter(t=>t!==e)),disabled:n},e))})})}),(0,H.jsxs)(`div`,{className:`flex w-full gap-2 rounded-md border border-dashed p-3`,children:[(0,H.jsxs)(`button`,{type:`button`,disabled:a||n,onClick:()=>d.current?.click(),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(as,{className:`size-4`}),a?`Uploading…`:`Upload`]}),(0,H.jsx)(`div`,{className:`w-px bg-border`}),(0,H.jsxs)(`button`,{type:`button`,disabled:a||n,onClick:()=>u(!0),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(fo,{className:`size-4`}),`Library`]})]}),s&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:s}),(0,H.jsx)(E1,{open:l,onOpenChange:u,allowedTypes:[`image`],selectionMode:`multiple`,onSelect:e=>{if(e.length===0)return;let n=new Set(r),i=[...r],a={},o={};for(let t of e)n.has(t.id)||(n.add(t.id),i.push(t.id),a[t.id]=t.url,o[t.id]=t.filename);Object.keys(a).length>0&&setUrlCache(e=>({...e,...a})),Object.keys(o).length>0&&setNameCache(e=>({...e,...o})),i.length!==r.length&&t(i)}})]})}function A1({value:e,onChange:t,disabled:n=!1}){let[r,i]=(0,v.useState)(()=>e!=null&&e!==``?String(e):``);(0,v.useEffect)(()=>{if(e==null||e===``){i(``);return}let t=typeof e==`number`?e:parseFloat(String(e));!isNaN(t)&&t!==parseFloat(r)&&i(String(t))},[e]);function a(e){let n=e.target.value.replace(`,`,`.`);if(i(n),n===``||n===`-`){t(null);return}let r=parseFloat(n);isNaN(r)||t(r)}return(0,H.jsx)(J,{type:`text`,inputMode:`decimal`,className:K(`w-full`,`text-base!`),value:r,placeholder:`0.00`,onChange:a,disabled:n})}function j1(e){if(typeof e==`object`&&e){let t=e;if(t.kind===`string`&&typeof t.value==`string`)return{kind:`string`,value:t.value};if(t.kind===`number`&&typeof t.value==`number`&&!isNaN(t.value))return{kind:`number`,value:t.value};if(t.kind===`boolean`&&typeof t.value==`boolean`)return{kind:`boolean`,value:t.value}}return typeof e==`number`&&!isNaN(e)?{kind:`number`,value:e}:typeof e==`boolean`?{kind:`boolean`,value:e}:{kind:`string`,value:typeof e==`string`?e:``}}function M1({value:e,onChange:t,inputId:n,disabled:r=!1}){let i=j1(e);function a(e){e===`string`&&t({kind:e,value:``}),e===`number`&&t({kind:e,value:0}),e===`boolean`&&t({kind:e,value:!1})}return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-md border border-border p-1`,children:[`string`,`number`,`boolean`].map(e=>(0,H.jsx)(`button`,{type:`button`,disabled:r,onClick:()=>a(e),className:K(`rounded px-2 py-1 text-xs transition-colors`,i.kind===e?`bg-accent text-accent-foreground`:`text-muted-foreground hover:bg-accent/60`),children:e===`string`?`Text`:e===`number`?`Number`:`Boolean`},e))}),i.kind===`string`&&(0,H.jsx)(J,{className:K(`w-full`,`text-base md:text-base`),value:String(i.value),placeholder:`Value`,onChange:e=>t({kind:`string`,value:e.target.value}),disabled:r}),i.kind===`number`&&(0,H.jsx)(A1,{value:i.value,onChange:e=>t({kind:`number`,value:typeof e==`number`&&!isNaN(e)?e:0}),disabled:r}),i.kind===`boolean`&&(0,H.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,H.jsx)(_k,{id:n,checked:!!i.value,onCheckedChange:e=>t({kind:`boolean`,value:!!e}),disabled:r}),(0,H.jsx)(Y,{htmlFor:n,className:`cursor-pointer font-normal text-base`,children:i.value?`True`:`False`})]})]})}function N1({value:e,onChange:t,timezone:n,disabled:r=!1}){let[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(`00:00`);(0,v.useEffect)(()=>{if(!e){s(void 0),l(`00:00`);return}let t=new Date(e);isNaN(t.getTime())||(s(t),l(ax(e,n)))},[e,n]);function u(e){s(e),a(!1),e&&t(ox(e,c,n))}function d(e){l(e),o&&t(ox(o,e,n))}return(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsxs)(IP,{open:i&&!r,onOpenChange:a,children:[(0,H.jsx)(LP,{asChild:!0,children:(0,H.jsxs)(q,{variant:`outline`,className:`w-40 justify-between font-normal text-base`,disabled:r,children:[o?Vj(o,`MMM d, yyyy`):`Select date`,(0,H.jsx)(Wa,{className:`size-4 opacity-50`})]})}),(0,H.jsx)(RP,{className:`w-auto overflow-hidden p-0`,align:`start`,children:(0,H.jsx)(PP,{mode:`single`,selected:o,captionLayout:`dropdown`,defaultMonth:o,onSelect:u})})]}),(0,H.jsx)(J,{type:`time`,className:`w-32 appearance-none bg-background [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none text-base!`,value:c,onChange:e=>d(e.target.value),disabled:r}),e&&(0,H.jsx)(q,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8 text-muted-foreground hover:text-foreground`,onClick:()=>{s(void 0),l(`00:00`),t(null)},disabled:r,children:(0,H.jsx)(us,{className:`size-3.5`})})]})}function P1(e){return e.find(e=>e.name===`title`)?.name??e.find(e=>e.name===`name`)?.name??e.find(e=>e.type===`uid`)?.name??e.find(e=>e.type===`string`)?.name??e.find(e=>e.type===`text`)?.name??null}var F1={data:null,promise:null};function I1(){return F1.data?Promise.resolve(F1.data):(F1.promise||=fetch(`/cms/admin/content-types`,{credentials:`include`}).then(e=>e.ok?e.json():[]).then(e=>(F1.data=e,e)).catch(()=>[]),F1.promise)}function L1(e,t){return e.find(e=>e.tableName===t)??null}function R1(e,t,n){return fetch(`/cms/admin/content-types/${e}/entries?page=${t}&limit=${n}`,{credentials:`include`}).then(e=>e.ok?e.json():{data:[],total:0,page:t,limit:n}).catch(()=>({data:[],total:0,page:t,limit:n}))}async function z1(e){let t=await R1(e,1,100),n=Math.max(1,Math.ceil(t.total/100));return n===1?{data:t.data}:{data:[t,...await Promise.all(Array.from({length:n-1},(t,n)=>R1(e,n+2,100)))].flatMap(e=>e.data)}}function B1(e){let[t,n]=(0,v.useState)([]),[r,i]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{e&&(i(!0),I1().then(t=>{let n=L1(t,e);return n?z1(n.slug).then(e=>({ctDef:n,res:e})):Promise.resolve({ctDef:null,res:{data:[]}})}).then(({ctDef:e,res:t})=>{let r=e?P1(e.fields??[]):null;n(t.data.map(e=>({id:String(e.id),label:String((r&&e[r])??e.title??e.name??e.id)})))}).catch(()=>n([])).finally(()=>i(!1)))},[e]),{entries:t,loading:r}}function V1(e,t,n){let[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{if(!e||!n){i([]);return}o(!0),I1().then(t=>{let n=L1(t,e);return n?z1(n.slug).then(e=>({ctDef:n,res:e})):Promise.resolve({ctDef:null,res:{data:[]}})}).then(({ctDef:e,res:r})=>{let a=e?P1(e.fields??[]):null;i(r.data.filter(e=>String(e[t]??``)===n).map(e=>({id:String(e.id),label:String((a&&e[a])??e.title??e.name??e.id)})))}).catch(()=>i([])).finally(()=>o(!1))},[e,t,n]),{entries:r,loading:a}}function H1({relatedTable:e,relatedField:t,currentId:n}){let{entries:r,loading:i}=V1(e,t,n);return n?i?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,H.jsx)(ex,{className:`size-3.5`}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Loading…`})]}):r.length===0?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No linked entries.`}):(0,H.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map(e=>(0,H.jsx)(`span`,{className:`inline-flex items-center rounded-md border bg-muted px-2 py-0.5 text-xs`,children:e.label},e.id))}):(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Save this entry first to see linked items.`})}function U1({relationType:e,relatedTable:t,relatedField:n,currentEntryId:r,value:i,onChange:a,disabled:o=!1}){let s=e===`many-to-many`,[c,l]=(0,v.useState)(!1),u=(0,v.useId)(),{entries:d,loading:f}=B1(t);if(e===`one-to-many`)return(0,H.jsx)(H1,{relatedTable:t,relatedField:n,currentId:r});let p=s?Array.isArray(i)?i:[]:i&&!Array.isArray(i)?[i]:[];function m(e){return d.find(t=>t.id===e)?.label??e}function h(e){if(s){let t=p.includes(e)?p.filter(t=>t!==e):[...p,e];a(t.length>0?t:null)}else a(p[0]===e?null:e),l(!1)}function g(e){if(s){let t=p.filter(t=>t!==e);a(t.length>0?t:null)}else a(null)}let _=s?p.length>0?`${p.length} selected`:`Select entries…`:p.length>0?m(p[0]):`Select entry…`;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsxs)(IP,{open:c&&!o,onOpenChange:l,children:[(0,H.jsx)(LP,{asChild:!0,children:(0,H.jsxs)(q,{variant:`outline`,role:`combobox`,"aria-expanded":c,"aria-controls":u,className:`w-full justify-between font-normal text-base`,disabled:o,children:[(0,H.jsx)(`span`,{className:`truncate text-left`,children:_}),(0,H.jsx)(Ja,{className:`ml-2 size-4 shrink-0 opacity-50`})]})}),(0,H.jsx)(RP,{className:`w-(--radix-popover-trigger-width) p-0`,align:`start`,children:(0,H.jsxs)(u1,{children:[(0,H.jsx)(d1,{placeholder:`Search…`}),(0,H.jsx)(f1,{id:u,children:f?(0,H.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,H.jsx)(ex,{className:`size-4`})}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(p1,{children:`No entries found.`}),(0,H.jsx)(m1,{children:d.map(e=>{let t=p.includes(e.id);return(0,H.jsxs)(g1,{value:e.label,onSelect:()=>{o||h(e.id)},children:[(0,H.jsx)(Ua,{className:`mr-2 size-4 ${t?`opacity-100`:`opacity-0`}`}),(0,H.jsx)(`span`,{className:`truncate`,children:e.label}),(0,H.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground opacity-60 shrink-0`,children:e.id.slice(0,8)})]},e.id)})})]})})]})})]}),p.length>0&&(0,H.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border bg-muted px-2 py-0.5 text-xs`,children:[m(e),(0,H.jsx)(`button`,{type:`button`,onClick:()=>g(e),disabled:o,className:`text-muted-foreground hover:text-foreground`,children:(0,H.jsx)(us,{className:`size-3`})})]},e))})]})}var W1={full:`col-span-6`,"two-thirds":`col-span-4`,half:`col-span-3`,third:`col-span-2`};function G1({field:e,value:t,onChange:n,disabled:r=!1}){let i=Array.isArray(t)?t:[],a=e.arrayFields??[];function o(){return Object.fromEntries(a.map(e=>[e.name,e.type===`boolean`?!1:null]))}function s(){n([...i,o()])}function c(e){n(i.filter((t,n)=>n!==e))}function l(e,t){let r=e+t;if(r<0||r>=i.length)return;let a=[...i];[a[e],a[r]]=[a[r],a[e]],n(a)}function u(e,t,r){n(i.map((n,i)=>i===e?{...n,[t]:r}:n))}return a.length===0?(0,H.jsx)(`div`,{className:`flex w-full items-center justify-center rounded-md border border-dashed p-4 text-xs text-muted-foreground`,children:`No sub-fields defined for this array.`}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(BP,{type:`single`,collapsible:!0,className:`w-full`,children:i.map((e,t)=>(0,H.jsxs)(VP,{value:`item-${t}`,className:`mb-2 rounded-md border border-dashed last:border-b transition-colors hover:bg-accent/50`,children:[(0,H.jsxs)(`div`,{className:`relative data-[state=open]:border-b data-[state=open]:border-border/50`,children:[(0,H.jsxs)(HP,{className:`w-full py-2 pl-3 pr-24 text-muted-foreground [&>svg]:hidden`,children:[`Item `,t+1]}),(0,H.jsxs)(`div`,{className:`absolute right-2 top-1/2 flex -translate-y-1/2 items-center gap-0.5`,children:[(0,H.jsx)(q,{size:`icon`,variant:`ghost`,disabled:r||t===0,onMouseDown:e=>e.stopPropagation(),onClick:()=>l(t,-1),className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-accent disabled:opacity-30`,children:(0,H.jsx)(qa,{className:`size-3.5`})}),(0,H.jsx)(q,{size:`icon`,variant:`ghost`,disabled:r||t===i.length-1,onMouseDown:e=>e.stopPropagation(),onClick:()=>l(t,1),className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-accent disabled:opacity-30`,children:(0,H.jsx)(Wa,{className:`size-3.5`})}),(0,H.jsx)(`button`,{type:`button`,onMouseDown:e=>e.stopPropagation(),onClick:()=>c(t),disabled:r,className:`flex size-6 items-center justify-center rounded text-destructive transition-colors hover:bg-destructive/10 hover:text-destructive`,children:(0,H.jsx)(es,{className:`size-3.5`})})]})]}),(0,H.jsx)(UP,{className:`px-3 pt-3`,children:(0,H.jsx)(`div`,{className:`grid grid-cols-6 gap-3`,children:a.map(n=>(0,H.jsxs)(`div`,{className:W1[n.width??`full`]??`col-span-6`,children:[(0,H.jsx)(`div`,{className:`mb-1 flex items-center gap-1`,children:(0,H.jsxs)(Y,{className:`text-xs font-medium`,children:[n.name,n.required&&(0,H.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`})]})}),(0,H.jsx)(Z1,{field:{...n,type:n.type},value:e[n.name]??null,onChange:e=>u(t,n.name,e),allValues:e,disabled:r})]},n.name))})})]},t))}),(0,H.jsxs)(`button`,{type:`button`,onClick:s,disabled:r,className:`flex w-full items-center justify-center gap-1.5 rounded-md border border-dashed py-2 text-xs text-muted-foreground transition-colors hover:bg-accent/50`,children:[(0,H.jsx)(Bo,{className:`size-3.5`}),`Add item`]})]})}var K1=3,q1=20;function J1({value:e,onChange:t,disabled:n=!1,depth:r=0}){let i=Array.isArray(e)?e:[],a=r+1<K1,o=i.length<q1;function s(){return{label:``,href:``}}function c(e,n){let r=(t,i)=>{let a=e[i];return t.map((t,o)=>{if(o!==a)return t;if(i===e.length-1)return n(t);let s=Array.isArray(t.items)?t.items:[];return{...t,items:r(s,i+1)}})};t(r(i,0))}function l(e,n){let r=(t,i)=>{if(i===e.length-1){let r=e[i],a=r+n;if(a<0||a>=t.length)return t;let o=[...t];return[o[r],o[a]]=[o[a],o[r]],o}let a=e[i];return t.map((e,t)=>{if(t!==a)return e;let n=Array.isArray(e.items)?e.items:[];return{...e,items:r(n,i+1)}})};t(r(i,0))}function u(e){let n=(t,r)=>{let i=e[r];return r===e.length-1?t.filter((e,t)=>t!==i):t.map((e,t)=>{if(t!==i)return e;let a=Array.isArray(e.items)?e.items:[];return{...e,items:n(a,r+1)}})};t(n(i,0))}function d(){o&&t([...i,s()])}return i.length===0?(0,H.jsxs)(`button`,{type:`button`,onClick:d,disabled:n||!o,className:`flex w-full items-center justify-center gap-1.5 rounded-md border border-dashed py-2 text-xs text-muted-foreground transition-colors hover:bg-accent/20`,children:[(0,H.jsx)(Bo,{className:`size-3.5`}),`Add item`]}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(BP,{type:`single`,collapsible:!0,className:`w-full`,children:i.map((e,t)=>{let o=[t],s=e.label?.trim()?e.label:`Item ${t+1}`;return(0,H.jsxs)(VP,{value:`navigation-item-${r}-${t}`,className:`mb-2 rounded-md border border-dashed last:border-b transition-colors hover:bg-accent/50`,children:[(0,H.jsxs)(`div`,{className:`relative data-[state=open]:border-b data-[state=open]:border-border/50`,children:[(0,H.jsx)(HP,{className:`w-full py-2 pl-3 pr-24 text-muted-foreground [&>svg]:hidden`,children:s}),(0,H.jsxs)(`div`,{className:`absolute right-2 top-1/2 flex -translate-y-1/2 items-center gap-0.5`,children:[(0,H.jsx)(q,{size:`icon`,variant:`ghost`,disabled:n||t===0,onMouseDown:e=>e.stopPropagation(),onClick:()=>l(o,-1),className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-accent disabled:opacity-30`,children:(0,H.jsx)(qa,{className:`size-3.5`})}),(0,H.jsx)(q,{size:`icon`,variant:`ghost`,disabled:n||t===i.length-1,onMouseDown:e=>e.stopPropagation(),onClick:()=>l(o,1),className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-accent disabled:opacity-30`,children:(0,H.jsx)(Wa,{className:`size-3.5`})}),(0,H.jsx)(`button`,{type:`button`,onMouseDown:e=>e.stopPropagation(),onClick:()=>u(o),disabled:n,className:`flex size-6 items-center justify-center rounded text-destructive transition-colors hover:bg-destructive/10 hover:text-destructive`,children:(0,H.jsx)(es,{className:`size-3.5`})})]})]}),(0,H.jsxs)(UP,{className:`px-3 pt-3`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-6 gap-3`,children:[(0,H.jsxs)(`div`,{className:`col-span-3`,children:[(0,H.jsx)(Y,{className:`mb-1 block text-xs font-medium`,children:`label`}),(0,H.jsx)(J,{className:`text-base`,value:e.label??``,onChange:e=>c(o,t=>({...t,label:e.target.value})),disabled:n})]}),(0,H.jsxs)(`div`,{className:`col-span-3`,children:[(0,H.jsx)(Y,{className:`mb-1 block text-xs font-medium`,children:`href`}),(0,H.jsx)(J,{className:`text-base`,value:e.href??``,onChange:e=>c(o,t=>({...t,href:e.target.value})),disabled:n})]})]}),a?(0,H.jsxs)(`div`,{className:`mt-3 border-l border-border pl-3`,children:[(0,H.jsx)(`p`,{className:`mb-2 text-[11px] uppercase tracking-wide text-muted-foreground`,children:`Child items`}),(0,H.jsx)(J1,{value:e.items??[],onChange:e=>c(o,t=>({...t,items:Array.isArray(e)&&e.length>0?e:void 0})),disabled:n,depth:r+1})]}):(0,H.jsxs)(`p`,{className:`mt-3 text-[11px] text-muted-foreground`,children:[`Maximum depth reached (`,K1,` levels).`]})]})]},t)})}),(0,H.jsxs)(`button`,{type:`button`,onClick:d,disabled:n,className:`flex w-full items-center justify-center gap-1.5 rounded-md border border-dashed py-2 text-xs text-muted-foreground transition-colors hover:bg-accent/50`,children:[(0,H.jsx)(Bo,{className:`size-3.5`}),`Add item`]}),!o&&(0,H.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Maximum `,q1,` items allowed per level.`]})]})}function Y1(e){return e.normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/^-+|-+$/g,``)}function X1({value:e,onChange:t,disabled:n=!1}){let r=(0,v.useRef)(null),i=(0,v.useRef)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(null);function p(){return o(!0),new Promise(e=>{i.current=e})}function m(e){i.current?.(e),i.current=null}function h(e){e||m(null),o(e)}async function g(e){u(!0),f(null);try{let t=await p$(e);m([{id:t.id,src:t.url,filename:t.filename,alt:t.alt,title:t.caption,width:t.width,height:t.height}]),o(!1)}catch(e){f(e instanceof Error?e.message:`Upload failed.`)}finally{u(!1),r.current&&(r.current.value=``)}}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:n?`pointer-events-none opacity-70`:``,children:(0,H.jsx)(u$,{value:String(e??``),onChange:t,placeholder:`Type or add your content here...`,onInsertImage:p})}),(0,H.jsx)(vy,{open:a,onOpenChange:h,children:(0,H.jsxs)(Sy,{className:`max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Insert Image`})}),(0,H.jsx)(`input`,{ref:r,type:`file`,accept:`image/*`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&g(t)}}),(0,H.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault();let t=e.dataTransfer.files[0];t&&g(t)},className:`flex w-full gap-2 rounded-md border border-dashed p-3`,children:[(0,H.jsxs)(`button`,{type:`button`,disabled:l,onClick:()=>r.current?.click(),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(as,{className:`size-4`}),l?`Uploading…`:`Upload`]}),(0,H.jsx)(`div`,{className:`w-px bg-border`}),(0,H.jsxs)(`button`,{type:`button`,disabled:l,onClick:()=>c(!0),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(fo,{className:`size-4`}),`Library`]})]}),d&&(0,H.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:d})]})}),(0,H.jsx)(E1,{open:s,onOpenChange:e=>{!e&&!a&&m(null),c(e)},allowedTypes:[`image`],selectionMode:`multiple`,onSelect:e=>{m(e.map(e=>({id:e.id,src:e.url,filename:e.filename,alt:e.alt,title:e.caption,width:e.width,height:e.height}))),c(!1),o(!1)}})]})}function Z1({field:e,value:t,onChange:n,allValues:r,disabled:i,errorMessage:a}){let o=(0,v.useRef)(null),{timezone:s}=ba();(0,v.useEffect)(()=>{if(e.type!==`uid`||!e.targetField)return;let i=String(t??``).trim(),a=i===``||i===o.current,s=r,c=e.targetField,l=!!s.__localizationEnabled,u=s[c];if(u!=null&&String(u).trim()!==``){if(!a)return;let e=Y1(String(u));e!==i&&(o.current=e,n(e));return}let d=s.localized&&typeof s.localized==`object`?s.localized:{};if(l){let e=typeof s.__defaultLocale==`string`?s.__defaultLocale:void 0,t=e&&d[e]&&typeof d[e]==`object`?d[e]:null;if(t&&t[c]!==void 0&&String(t[c]).trim()!==``){if(!a)return;let e=Y1(String(t[c]));e!==i&&(o.current=e,n(e))}return}let f=Object.keys(d).filter(e=>!e.startsWith(`_`));for(let e of f){let t=d[e]&&typeof d[e]==`object`?d[e]:null;if(t&&t[c]!==void 0&&String(t[c]).trim()!==``){if(!a)return;let e=Y1(String(t[c]));e!==i&&(o.current=e,n(e));return}}},[t,e.type,e.targetField,r[e.targetField??``],JSON.stringify(r.localized??{}),r.__localizationEnabled]);let c=`w-full`;return e.type===`boolean`?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,H.jsx)(_k,{id:`field-${e.name}`,checked:!!t,onCheckedChange:e=>n(!!e),disabled:!!i}),(0,H.jsx)(Y,{htmlFor:`field-${e.name}`,className:`cursor-pointer font-normal text-base`,children:t?`Yes`:`No`})]}):e.type===`richtext`?(0,H.jsx)(X1,{value:t,onChange:n,disabled:!!i}):e.type===`text`?(0,H.jsx)(zP,{className:K(c,`text-base`),value:String(t??``),placeholder:b1(e.name),onChange:e=>n(e.target.value),disabled:!!i}):e.type===`number`?e.subtype===`float`?(0,H.jsx)(A1,{value:t,onChange:n,disabled:!!i}):(0,H.jsx)(J,{type:`number`,className:K(c,`text-base!`),value:t==null?``:String(t),step:`1`,placeholder:`0`,onChange:e=>{let t=e.target.value;if(t===``){n(null);return}n(parseInt(t,10))},disabled:!!i}):e.type===`datetime`?(0,H.jsx)(N1,{value:t,onChange:n,timezone:s,disabled:!!i}):e.type===`uid`?(0,H.jsxs)(`div`,{children:[(0,H.jsx)(J,{className:K(c,`text-base md:text-base`,a?`border-destructive focus-visible:ring-destructive/20`:``),value:String(t??``),placeholder:`auto-generated`,onChange:e=>{n(e.target.value)},disabled:!!i}),a&&(0,H.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:a})]}):e.type===`media`?(0,H.jsx)(D1,{value:t,onChange:n,allowedTypes:e.allowedTypes,disabled:!!i}):e.type===`media-gallery`?(0,H.jsx)(k1,{value:t,onChange:n,disabled:!!i}):e.type===`relation`?(0,H.jsx)(U1,{relationType:e.relationType??`many-to-one`,relatedTable:e.relatedTable??``,relatedField:e.relatedField??``,currentEntryId:String(r.id??``),value:t,onChange:n,disabled:!!i}):e.type===`array`?(0,H.jsx)(G1,{field:e,value:t,onChange:n,disabled:!!i}):e.type===`mixed`?(0,H.jsx)(M1,{value:t,onChange:n,inputId:`field-${e.name}-mixed-boolean`,disabled:!!i}):e.type===`navigation`?(0,H.jsx)(J1,{value:t,onChange:n,disabled:!!i}):(0,H.jsx)(J,{className:K(c,`text-base md:text-base`),value:String(t??``),placeholder:b1(e.name),onChange:e=>n(e.target.value),disabled:!!i})}var Q1=`plank-preview`;function $1(e,t){let n=!1,r=e.replace(/\{(contentType|entryId|slug|status)\}/g,(e,r)=>{let i=t[r];return i==null||i===``?(n=!0,``):encodeURIComponent(i)});return n||/\{[^}]+\}/.test(r)?null:r}function e0(e){return{enabled:String(e?.enabled??`false`).toLowerCase()===`true`,syncUrl:e?.sync_url?.trim()??``,urlTemplate:e?.url_template?.trim()??``,slugField:e?.slug_field?.trim()||`slug`}}function t0(e){return{enabled:String(e?.preview_enabled??`false`).toLowerCase()===`true`,syncUrl:e?.preview_sync_url?.trim()??``,urlTemplate:e?.preview_url_template?.trim()??``,slugField:e?.preview_slug_field?.trim()||`slug`}}function n0(e,t){if(!e.enabled)return null;if(!e.urlTemplate)return`Set a preview URL template in Settings > Overview > Preview.`;if(e.syncUrl)try{new URL(e.syncUrl)}catch{return`Preview sync webhook URL must be an absolute URL.`}if(e.urlTemplate.includes(`{slug}`)&&!t.includes(e.slugField))return`Preview slug field "${e.slugField}" does not exist on this content type.`;let n=$1(e.urlTemplate,{contentType:`sample-content`,entryId:`sample-entry`,slug:`sample-slug`,status:`draft`});if(!n)return`Preview URL template contains unsupported or unresolved placeholders.`;try{return new URL(n),null}catch{return`Preview URL template must resolve to an absolute URL.`}}function r0(e){let{config:t,contentType:n,entry:r,status:i}=e;if(!t.enabled||!t.urlTemplate)return null;let a=r[t.slugField],o=$1(t.urlTemplate,{contentType:n,entryId:r.id?String(r.id):null,slug:typeof a==`string`&&a.trim()?a.trim():null,status:i??(typeof r.status==`string`?r.status:null)});if(!o)return null;try{return new URL(o).toString()}catch{return null}}var i0=null;function a0(e){return Array.isArray(e)?e.map(a0):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,a0(t)])):e}function o0(e){return JSON.stringify(a0(e))}function s0(e){let t=e.match(/Field "([^"]+)" already exists\.?/);return t?t[1]??null:null}function c0(){let{slug:e,id:t}=gr(),n=fr(),r=!t,{timezone:i,locales:a,defaultLocale:o,editorialMode:s}=ba(),{user:c,status:l}=_a(),u=c?.role?.toLowerCase()??``,{data:d,loading:f}=Ta(e?`/cms/admin/content-types/${e}`:null),{data:p}=Ta(`/cms/admin/client-settings`),{data:m,loading:h}=Ta(e&&t?`/cms/admin/entries/${e}/${t}`:null),{data:g}=Ta(s&&[`editor`,`admin`,`super admin`].includes(c?.role?.toLowerCase()??``)?`/cms/admin/users`:null),{loading:_,request:y}=Eb(),{loading:b,request:x}=Eb(),{loading:S,request:C}=Eb(),[w,T]=(0,v.useState)({}),[E,D]=(0,v.useState)([]),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(!1),[M,N]=(0,v.useState)(`draft`),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(!1),[R,ee]=(0,v.useState)(!1),[te,ne]=(0,v.useState)(!1),[z,B]=(0,v.useState)(null),[re,V]=(0,v.useState)(null),[ie,ae]=(0,v.useState)(null),[oe,se]=(0,v.useState)(null),[ce,le]=(0,v.useState)(!1),[ue,de]=(0,v.useState)(null),[fe,pe]=(0,v.useState)(!1),[me,he]=(0,v.useState)(!1),[ge,_e]=(0,v.useState)(),[ve,ye]=(0,v.useState)(`09:00`),be=(0,v.useRef)(`{}`),xe=(0,v.useRef)(!1),Se=t0(p),Ce=d?.kind===`collection`&&d.previewEnabled!==!1,we=d?n0(Se,d.fields.map(e=>e.name)):null,Te=Ce&&Se.enabled&&!we,Ee=Ce&&Se.enabled&&we?we:Ce&&Se.enabled?null:`Preview is disabled. Configure Settings > Overview > Preview to enable it.`;(0,v.useEffect)(()=>{if(r){let e={};d?.fields.forEach(t=>{e[t.name]=t.type===`boolean`?!1:``}),e.localized={};let t=a&&a.length>0?a:[`en`];D(t),k(o??t[0]),j(!1),T(e),N(`draft`),F(``),L(!1),ne(!1),B(null),V(null),ae(null),se(null),le(!1),de(null),be.current=o0(e);return}if(!m||!d)return;let e={};d.fields.forEach(t=>{e[t.name]=m[t.name]??(t.type===`boolean`?!1:``)});let t=m.localized,n=t&&typeof t==`object`?t:{};e.localized=n;let s=Object.keys(n).filter(e=>!e.startsWith(`_`)),c=(n._meta||{}).enabled??s.length>0;if(s.length>0)D(s),k(s[0]);else{let e=a&&a.length>0?a:[`en`];D(e),k(o??e[0])}if(j(!!c),T(e),N(m.status??`draft`),ne(!!m.review_rejected),B(m.editor_id??null),V(m._editor_first_name??null),ae(m._editor_last_name??null),se(m._editor_avatar_url??null),le(!1),de(null),be.current=o0(e),m.scheduled_for?(F(m.scheduled_for),_e(new Date(m.scheduled_for)),ye(ax(m.scheduled_for,i))):F(``),m.status===`published`&&m.published_data){let t=(e,t)=>{if(t===`datetime`&&e&&typeof e==`string`){let t=/Z|[+-]\d{2}:\d{2}$/.test(e)?e:e+`Z`,n=new Date(t);return isNaN(n.getTime())?e:n.toISOString()}return e},n={},r={};d.fields.forEach(i=>{i.name in m.published_data&&(n[i.name]=t(m.published_data[i.name]??(i.type===`boolean`?!1:``),i.type),r[i.name]=t(e[i.name],i.type))}),L(o0(r)!==o0(n))}else L(!1)},[m,d,r]);let De=o0(w)!==be.current,Oe=Ir((0,v.useCallback)(()=>xe.current?!1:De,[De]));function ke(e,t){T(n=>({...n,[e]:t}))}function Ae(e,t,n){T(r=>{let i={...r},a=i.localized&&typeof i.localized==`object`?i.localized:{},o=a[e]&&typeof a[e]==`object`?a[e]:{};return o[t]=n,a[e]=o,i.localized=a,i})}function je(e){j(e),T(t=>{let n={...t},r=n.localized&&typeof n.localized==`object`?n.localized:{};if(r._meta||={},e&&o){if(!(r[o]&&typeof r[o]==`object`&&r[o])&&(r[o]={},d&&d.fields)){let e=r[o];d.fields.forEach(t=>{if([`string`,`text`,`richtext`].includes(t.type)){let r=n[t.name];r!=null&&r!==``&&(e[t.name]=r)}})}r._meta.primary=o}else if(!e&&o){let e=r[o]&&typeof r[o]==`object`?r[o]:null;e&&d&&d.fields&&d.fields.forEach(t=>{if([`string`,`text`,`richtext`,`uid`].includes(t.type)){let r=e[t.name];r!==void 0&&(n[t.name]=r)}})}return r._meta.enabled=e,n.localized=r,n})}function Me(){if(P)_e(new Date(P)),ye(ax(P,i));else{let e=new Date;e.setDate(e.getDate()+1),_e(e),ye(`09:00`)}pe(!0)}async function Ne(){if(!e||!d)return null;de(null);let n={},i=A&&w.localized&&typeof w.localized==`object`&&w.localized[o]&&typeof w.localized[o]==`object`?w.localized[o]:null;if(d.fields.forEach(e=>{let t=w[e.name];(t==null||t===``)&&i&&i[e.name]!==void 0&&(t=i[e.name]),e.type===`media`&&t===null?n[e.name]=null:t!==``&&t!=null&&(n[e.name]=t)}),w.localized&&Object.keys(w.localized).length>0){let e=w.localized;e._meta||={},e._meta.enabled=A,e._meta.primary=o,n.localized=e}try{let i=await y(r?`/cms/admin/content-types/${e}/entries`:`/cms/admin/entries/${e}/${t}`,r?`POST`:`PUT`,n);return be.current=o0(w),i}catch(e){let t=s0(e instanceof Error?e.message:``);return t&&d.fields.some(e=>e.type===`uid`&&e.name===t)&&de(t),X.error(`Could not save draft`),null}}function Pe(e){!i0||i0.closed||(i0.location.href=e,i0.focus())}async function Fe(i){let a=await Ne();if(!a)return null;let o=a,s=M;if(M===`scheduled`){let n=r?a.id:t;try{o=await x(`/cms/admin/entries/${e}/${n}/status`,`PATCH`,{status:`draft`}),s=`draft`,N(`draft`),F(``),pe(!1)}catch{return X.error(`Could not save draft`),null}}else M===`published`&&(s=`published`,L(!0));if(i&&e&&Te&&!Se.syncUrl){let t=r0({config:Se,contentType:e,entry:o,status:s});t&&Pe(t)}return X.success(`Draft saved`),r&&(xe.current=!0,n(`/content/${e}/${o.id}`,{replace:!0})),{entry:o,status:s}}async function Ie(){await Fe(!0)}async function Le(){if(!e||!d||!Se.enabled||!ft)return;if(we){X.error(we);return}let n=m??null,i=M;if(r||De){let e=await Fe(!1);if(!e)return;n=e.entry,i=e.status}let a=r0({config:Se,contentType:e,entry:n??{...w,id:t,status:M},status:i});if(!a){X.error(`Preview URL could not be resolved for this entry.`);return}if(i0=window.open(a,Q1),!i0){X.error(`Preview window was blocked by the browser.`);return}i0.focus()}async function Re(){if(!e)return;let i=t;if(De||r){let e=await Ne();if(!e)return;i=r?e.id:t,r&&(xe.current=!0)}let a=s&&(u===`contributor`||u===``||l!==`authenticated`);try{let t=await x(`/cms/admin/entries/${e}/${i}/status`,`PATCH`,{status:a?`pending`:`published`,review_rejected:!1});N(t?.status??(a?`pending`:`published`)),ne(!!t?.review_rejected),B(t?.editor_id??z),V(t?._editor_first_name??re),ae(t?._editor_last_name??ie),se(t?._editor_avatar_url??oe),F(``),L(!1),pe(!1),le(!1),X.success(`Entry published`),r&&n(`/content/${e}/${i}`,{replace:!0})}catch{X.error(`Could not publish entry`),r&&i&&n(`/content/${e}/${i}`,{replace:!0})}}async function ze(){if(!e||!ge||!ve)return;let a=ox(ge,ve,i);if(new Date(a)<=new Date)return;let o=t;if(De||r){let e=await Ne();if(!e)return;o=r?e.id:t,r&&(xe.current=!0)}try{await x(`/cms/admin/entries/${e}/${o}/status`,`PATCH`,{status:`scheduled`,scheduled_for:a}),N(`scheduled`),F(a),pe(!1),X.success(`Entry scheduled`),r&&n(`/content/${e}/${o}`,{replace:!0})}catch{X.error(`Could not schedule entry`),r&&o&&n(`/content/${e}/${o}`,{replace:!0})}}async function Be(){if(!(!e||!t))try{await x(`/cms/admin/entries/${e}/${t}/status`,`PATCH`,{status:`draft`}),N(`draft`),F(``),L(!1),X.success(`Reverted to draft`)}catch{X.error(`Could not revert entry`)}}async function Ve(){if(!(!e||!t))try{await C(`/cms/admin/entries/${e}/${t}`,`DELETE`),X.success(`Entry deleted`),xe.current=!0,n(`/content/${e}`,{replace:!0})}catch{X.error(`Could not delete entry`)}}async function He(n){if(!e||!t)return;let r=n===`none`?null:n;try{let n=await x(`/cms/admin/entries/${e}/${t}/status`,`PATCH`,{status:`in_review`,editor_id:r,review_locked_by_editor:m?.review_locked_by_editor??!1});N(n?.status??`in_review`),ne(!!n?.review_rejected),B(n?.editor_id??r),V(n?._editor_first_name??null),ae(n?._editor_last_name??null),se(n?._editor_avatar_url??null),le(!1),X.success(`Editor assigned`)}catch{X.error(`Could not assign editor`)}}async function Ue(){le(e=>!e)}async function We(){if(!(!e||!t))try{let n=await x(`/cms/admin/entries/${e}/${t}/status`,`PATCH`,{status:`pending`,review_rejected:!0});N(n?.status??`pending`),ne(!!n?.review_rejected),le(!1),X.success(`Entry rejected`)}catch{X.error(`Could not reject entry`)}}let Ge=f||!r&&h,Ke=_||b,qe=c?.permissions??[],Je=qe.includes(`*`)||qe.includes(`entries:write`),Ye=qe.includes(`*`)||qe.includes(`entries:delete`),Xe=u===`contributor`,Ze=u===`editor`,Qe=[`admin`,`super admin`].includes(u),$e=u===`viewer`,et=Xe||Ze,tt=Xe&&d?.kind===`single`,nt=r||String(m?.created_by??``)===String(c?.id??``),rt=s&&Xe&&M===`in_review`,it=s&&(Ze||Qe)&&!!z&&z===c?.id,at=it&&(M===`pending`||M===`in_review`)&&!te,ot=$e||!Je||tt||Xe&&!nt||s&&Xe&&M===`pending`&&!te||rt||s&&(Ze||Qe)&&(M===`pending`||M===`in_review`)&&(!it||!ce),st=Ye&&(!et||nt),ct=s&&Xe&&M===`pending`&&(te?!0:De)||De||M===`draft`||M===`scheduled`||!s&&M===`pending`||s&&M===`pending`&&!Xe||s&&M===`in_review`&&!Xe||I,lt=!!(ge&&ve),ut=s&&Xe?`Review`:`Publish`,dt=Ce,ft=M===`draft`||M===`scheduled`||M===`pending`||M===`in_review`||M===`published`&&I;if(lk(`mod+s`,Ie,{enabled:!ot&&!Ke&&(M===`scheduled`?!0:De),label:`Save draft`}),lk(`mod+shift+p`,Re,{enabled:ct&&!Ke&&!ot,label:`Publish`}),Ge)return(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-12 text-muted-foreground`,children:[(0,H.jsx)(ex,{className:`size-4`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading…`})]});if(!d)return null;let pt;pt=M===`scheduled`?(0,H.jsxs)(dT,{variant:`outline`,className:`border-blue-500 text-blue-600`,children:[(0,H.jsx)(Ba,{className:`size-3 mr-1`}),P?`Scheduled · ${ix(P,i)}`:`Scheduled`]}):M===`pending`?te?(0,H.jsx)(dT,{variant:`destructive`,children:`Pending`}):(0,H.jsx)(dT,{className:`bg-amber-500 text-black hover:bg-amber-500`,children:`Pending`}):M===`in_review`?(0,H.jsx)(dT,{variant:`outline`,children:`In Review`}):M===`published`?(0,H.jsx)(dT,{variant:I?`secondary`:`default`,children:I?`Published (pending changes)`:`Published`}):(0,H.jsx)(dT,{variant:`secondary`,children:`Draft`});let mt=(g??[]).filter(e=>Ze?e.id===c?.id:Qe?e.id===c?.id||(e.role_name??``).toLowerCase()===`editor`:!1),ht=!r&&s&&(Ze||Qe)&&(M===`pending`||M===`in_review`),gt=s&&!r&&ht,_t=s&&!r&&!!z,vt=at,yt=at,bt=re||ie;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($b,{children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:r?`New entry`:`Edit entry`}),pt]}),(0,H.jsx)(`p`,{className:`text-muted-foreground text-xs mt-1`,children:d.name}),dt&&Se.enabled&&we&&(0,H.jsx)(`p`,{className:`mt-1 text-xs text-amber-600`,children:we})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!r&&st&&!tt&&(0,H.jsx)(q,{variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-destructive`,onClick:()=>ee(!0),disabled:S,children:(0,H.jsx)(es,{className:`size-4`})}),!r&&M===`published`&&!ot&&(0,H.jsxs)(q,{variant:`outline`,onClick:Be,disabled:Ke,children:[b?(0,H.jsx)(ex,{className:`size-4`}):null,`Revert to draft`]}),!r&&M===`scheduled`&&!ot&&(0,H.jsxs)(q,{variant:`outline`,onClick:Be,disabled:Ke,children:[b?(0,H.jsx)(ex,{className:`size-4`}):null,`Cancel schedule`]}),gt&&(0,H.jsxs)(_T,{value:z??`none`,onValueChange:He,disabled:!ht||Ke,children:[(0,H.jsx)(bT,{className:`h-10 min-h-10 max-h-10 w-42 py-0`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(Nl,{avatarUrl:oe??null,firstName:re??null,lastName:ie??null,className:`size-5`,fallbackClassName:`text-[9px]`}),(0,H.jsx)(yT,{placeholder:bt||`Assign editor`})]})}),(0,H.jsxs)(CT,{children:[!Ze&&(0,H.jsx)(TT,{value:`none`,children:`Unassign`}),mt.map(e=>(0,H.jsx)(TT,{value:e.id,children:e.first_name||e.last_name||e.id},e.id))]})]}),!ht&&_t&&(0,H.jsxs)(`div`,{className:`inline-flex h-10 items-center gap-2 rounded-md border border-input px-3 text-sm`,children:[(0,H.jsx)(Nl,{avatarUrl:oe??null,firstName:re??null,lastName:ie??null,className:`size-5`,fallbackClassName:`text-[9px]`}),(0,H.jsx)(`span`,{children:bt||`Assigned editor`})]}),vt&&(0,H.jsx)(q,{variant:`outline`,size:`icon`,onClick:Ue,disabled:Ke,children:(0,H.jsx)(zo,{className:`size-4`})}),yt&&(0,H.jsx)(q,{variant:`outline`,size:`icon`,onClick:We,disabled:Ke,children:(0,H.jsx)(us,{className:`size-4`})}),dt&&Se.enabled&&ft&&(0,H.jsx)(q,{variant:`outline`,onClick:Le,disabled:ot||Ke||!!we,title:Ee??void 0,children:`Open preview`}),(0,H.jsxs)(q,{variant:`outline`,onClick:Ie,size:s?`icon`:`default`,disabled:ot||(M===`scheduled`?Ke:!De||Ke),children:[_?(0,H.jsx)(ex,{className:`size-4`}):s?(0,H.jsx)(Wo,{className:`size-4`}):null,!s&&(M===`scheduled`?`Save draft (cancel schedule)`:`Save draft`)]}),M!==`scheduled`&&!(s&&Xe)&&(0,H.jsxs)(q,{variant:`outline`,onClick:Me,size:s?`icon`:`default`,disabled:ot||Ke,children:[(0,H.jsx)(Ba,{className:`size-4`}),!s&&`Schedule`]}),(0,H.jsxs)(q,{onClick:Re,disabled:ot||!ct||Ke,children:[b?(0,H.jsx)(ex,{className:`size-4`}):null,M===`scheduled`?s&&Xe?`Review`:`Publish now`:M===`published`&&!I?`Republish`:ut]})]})]})}),(0,H.jsxs)(`section`,{className:`mt-24`,children:[fe&&!ot&&(0,H.jsxs)(`div`,{className:`mb-6 flex items-end gap-2 rounded-lg border p-4 bg-muted/30`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{children:`Date`}),(0,H.jsxs)(IP,{open:me,onOpenChange:he,children:[(0,H.jsx)(LP,{asChild:!0,children:(0,H.jsxs)(q,{variant:`outline`,className:`w-40 justify-between font-normal`,children:[ge?Vj(ge,`MMM d, yyyy`):`Select date`,(0,H.jsx)(Wa,{className:`size-4 opacity-50`})]})}),(0,H.jsx)(RP,{className:`w-auto overflow-hidden p-0`,align:`start`,children:(0,H.jsx)(PP,{mode:`single`,selected:ge,captionLayout:`dropdown`,defaultMonth:ge??new Date,disabled:{before:new Date},onSelect:e=>{_e(e),he(!1)}})})]})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsxs)(Y,{children:[`Time `,(0,H.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(24h)`})]}),(0,H.jsx)(J,{type:`time`,className:`w-32 appearance-none bg-background [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none`,value:ve,onChange:e=>ye(e.target.value)})]}),(0,H.jsxs)(q,{onClick:ze,disabled:!lt||Ke,children:[b?(0,H.jsx)(ex,{className:`size-4`}):null,`Confirm`]}),(0,H.jsx)(q,{variant:`ghost`,onClick:()=>pe(!1),children:`Cancel`})]}),(0,H.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(uk,{checked:A,onCheckedChange:je,disabled:ot}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`text-sm font-medium`,children:`Localization`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Enable per-entry localization`})]})]}),(0,H.jsx)(`div`,{})]}),(0,H.jsx)(`div`,{children:A&&(0,H.jsx)(Qj,{value:O,onValueChange:e=>k(e),children:(0,H.jsx)($j,{children:E.map(e=>(0,H.jsx)(eM,{value:e,disabled:ot,children:e.toUpperCase()},e))})})})]}),(0,H.jsx)(`div`,{className:`grid grid-cols-6 gap-4`,children:d.fields.map(e=>{let n=[`string`,`text`,`richtext`].includes(e.type),r=w.localized&&w.localized[O]?w.localized[O][e.name]:void 0,i=n&&A?r:w[e.name],a=e.type===`uid`&&e.targetField&&A&&[`string`,`text`,`richtext`].includes(d.fields.find(t=>t.name===e.targetField)?.type??``);return(0,H.jsx)(`div`,{className:fk[e.width??`full`],children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsxs)(Y,{htmlFor:`entry-${e.name}`,className:`capitalize`,children:[e.name.replace(/_/g,` `),e.required&&(0,H.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,H.jsx)(Z1,{field:e,value:i,onChange:t=>{e.type===`uid`&&ue===e.name&&de(null),n&&A?Ae(O,e.name,t):ke(e.name,t)},allValues:{...w,id:t,__activeLocale:O,__localizationEnabled:A,__defaultLocale:o},disabled:!!a||ot,errorMessage:e.type===`uid`&&ue===e.name?`${e.name} already exists.`:void 0})]})},e.name)})}),(0,H.jsx)(vy,{open:R,onOpenChange:ee,children:(0,H.jsxs)(Sy,{className:`max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Delete this entry?`})}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This action cannot be undone.`}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>ee(!1),children:`Cancel`}),(0,H.jsxs)(q,{variant:`destructive`,onClick:Ve,disabled:S,children:[S?(0,H.jsx)(ex,{className:`size-4`}):null,`Delete`]})]})]})}),(0,H.jsx)(vy,{open:Oe.state===`blocked`,onOpenChange:()=>Oe.reset?.(),children:(0,H.jsxs)(Sy,{className:`max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Unsaved changes`})}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Leave without saving?`}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>Oe.reset?.(),children:`Stay`}),(0,H.jsx)(q,{variant:`destructive`,onClick:()=>Oe.proceed?.(),children:`Leave`})]})]})})]})]})}function l0({...e}){return(0,H.jsx)(`nav`,{"aria-label":`breadcrumb`,"data-slot":`breadcrumb`,...e})}function u0({className:e,...t}){return(0,H.jsx)(`ol`,{"data-slot":`breadcrumb-list`,className:K(`flex flex-wrap items-center gap-1.5 text-sm break-words text-muted-foreground sm:gap-2.5`,e),...t})}function d0({className:e,...t}){return(0,H.jsx)(`li`,{"data-slot":`breadcrumb-item`,className:K(`inline-flex items-center gap-1.5`,e),...t})}function f0({asChild:e,className:t,...n}){return(0,H.jsx)(e?xu:`a`,{"data-slot":`breadcrumb-link`,className:K(`transition-colors hover:text-foreground`,t),...n})}function p0({className:e,...t}){return(0,H.jsx)(`span`,{"data-slot":`breadcrumb-page`,role:`link`,"aria-disabled":`true`,"aria-current":`page`,className:K(`font-normal text-foreground`,e),...t})}function m0({children:e,className:t,...n}){return(0,H.jsx)(`li`,{"data-slot":`breadcrumb-separator`,role:`presentation`,"aria-hidden":`true`,className:K(`[&>svg]:size-3.5`,t),...n,children:e??(0,H.jsx)(Ka,{})})}function h0(e,t){e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),t())}function g0(e){return e?e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`:`—`}function _0(e){let t=e.split(`/`).pop()??e;return t.replace(/\.[^.]+$/,``).trim()||t.trim()}function v0(e){return!!e?.startsWith(`image/`)}function y0(e){return!!e?.startsWith(`video/`)}function b0(e){return!!e?.startsWith(`audio/`)}function x0(e){return e===`application/pdf`}function S0(e,t){return e.split(`?`)[0].endsWith(`.m3u8`)||t===`application/x-mpegurl`||t===`application/vnd.apple.mpegurl`}async function C0(e){if(e.isFile)return new Promise(t=>{e.file(n=>t([{file:n,relativePath:e.fullPath.replace(/^\//,``)}]))});if(e.isDirectory){let t=e.createReader(),n=[];return await new Promise(e=>{let r=()=>{t.readEntries(async t=>{if(t.length===0){e();return}let i=await Promise.all(t.map(C0));n.push(...i.flat()),r()})};r()}),n}return[]}function w0({url:e}){let t=(0,v.useRef)(null);return(0,v.useEffect)(()=>{let n=t.current;if(!n)return;if(n.canPlayType(`application/vnd.apple.mpegurl`)){n.src=e;return}let r=null;return L(async()=>{let{default:e}=await import(`./hls-0EiSYoTw.js`);return{default:e}},[]).then(({default:t})=>{if(!t.isSupported())return;let i=new t;r=i,i.loadSource(e),i.attachMedia(n)}),()=>{r?.destroy()}},[e]),(0,H.jsx)(`video`,{ref:t,controls:!0,className:`max-h-[70vh] w-full rounded-md bg-zinc-950`})}function T0({item:e}){let t=e.mime_type?.toLowerCase()??null;return v0(t)?(0,H.jsx)(`img`,{src:e.url,alt:e.alt??e.filename,className:`max-h-full max-w-full rounded-md object-contain`}):S0(e.url,t)?(0,H.jsx)(w0,{url:e.url}):y0(t)?(0,H.jsx)(`video`,{src:e.url,controls:!0,preload:`none`,className:`max-h-[70vh] w-full rounded-md bg-zinc-950`}):b0(t)?(0,H.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-6`,children:[(0,H.jsx)(oo,{className:`size-14 text-muted-foreground`}),(0,H.jsx)(`audio`,{src:e.url,controls:!0,className:`w-full`})]}):x0(t)?(0,H.jsx)(`iframe`,{src:e.url,title:e.filename,className:`h-[70vh] w-full rounded-md border`}):(0,H.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8 text-center`,children:[(0,H.jsx)(co,{className:`size-14 text-muted-foreground`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.mime_type??`Unknown type`}),(0,H.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,download:e.filename,children:(0,H.jsxs)(q,{variant:`outline`,size:`sm`,children:[(0,H.jsx)(no,{className:`size-4`}),`Download`]})})]})}function E0({folder:e,onOpen:t,onDelete:n,onRename:r,canDelete:i,canRename:a,selected:o,onToggle:s}){return(0,H.jsxs)(`div`,{className:`group relative flex items-center gap-3 rounded-lg border bg-card px-3 py-2.5 transition-colors cursor-pointer hover:bg-muted/50 ${o?`ring-2 ring-primary`:``}`,role:`button`,tabIndex:0,"aria-pressed":o,onClick:()=>{o||t(e)},onKeyDown:n=>{h0(n,()=>{o||t(e)})},children:[(0,H.jsxs)(`div`,{className:`relative shrink-0 size-7 flex items-center justify-center`,children:[(0,H.jsx)(mo,{className:`size-7 text-muted-foreground transition-opacity ${o?`opacity-0`:`group-hover:opacity-0`}`}),(0,H.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center transition-opacity ${o?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onPointerDown:e=>e.stopPropagation(),children:(0,H.jsx)(_k,{checked:o,onCheckedChange:()=>s(`folder:${e.id}`),"aria-label":`Select folder`})})]}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`p`,{className:`text-sm font-bold truncate`,title:e.name,children:e.name}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.item_count,` `,e.item_count===1?`item`:`items`]})]}),!o&&(a||i)&&(0,H.jsxs)(bv,{children:[(0,H.jsx)(xv,{asChild:!0,children:(0,H.jsx)(`button`,{type:`button`,className:`shrink-0 opacity-0 group-hover:opacity-100 transition-opacity flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground`,onClick:e=>e.stopPropagation(),children:(0,H.jsx)(ro,{className:`size-4`})})}),(0,H.jsxs)(wv,{align:`end`,onClick:e=>e.stopPropagation(),children:[a&&(0,H.jsxs)(Tv,{onSelect:()=>r(e),children:[(0,H.jsx)(zo,{className:`size-4`}),`Rename`]}),i&&(0,H.jsxs)(Tv,{onSelect:()=>n(e),className:`text-destructive focus:text-destructive`,children:[(0,H.jsx)(es,{className:`size-4`}),`Delete`]})]})]})]})}function D0({item:e,onDelete:t,onPreview:n,canDelete:r,selected:i,onToggle:a}){let o=e.mime_type?.toLowerCase()??null;return(0,H.jsxs)(`div`,{className:`group relative rounded-lg border bg-card overflow-hidden transition-colors ${i?`ring-2 ring-primary`:``}`,children:[(0,H.jsx)(`div`,{className:`aspect-square bg-muted flex items-center justify-center cursor-pointer`,role:`button`,tabIndex:0,"aria-pressed":i,onClick:()=>{i||n(e)},onKeyDown:t=>{h0(t,()=>{i||n(e)})},children:v0(o)?(0,H.jsx)(`img`,{src:e.url,alt:e.alt??e.filename,className:`h-full w-full object-cover`}):y0(o)||S0(e.url,o)?(0,H.jsx)(so,{className:`size-10 text-muted-foreground`}):b0(o)?(0,H.jsx)(oo,{className:`size-10 text-muted-foreground`}):x0(o)?(0,H.jsx)(co,{className:`size-10 text-muted-foreground`}):(0,H.jsx)(lo,{className:`size-10 text-muted-foreground`})}),(0,H.jsx)(`div`,{className:`absolute top-1.5 left-1.5 transition-opacity ${i?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,children:(0,H.jsx)(_k,{checked:i,onCheckedChange:()=>a(e.id),"aria-label":`Select file`,className:`bg-background/80 backdrop-blur-sm`})}),!i&&r&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>t(e),className:`absolute top-1.5 right-1.5 flex size-6 items-center justify-center rounded-md bg-background/80 text-muted-foreground opacity-0 backdrop-blur-sm transition-opacity hover:text-destructive group-hover:opacity-100`,children:(0,H.jsx)(es,{className:`size-3.5`})}),(0,H.jsxs)(`div`,{className:`p-2`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium truncate`,title:e.filename,children:e.filename}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:g0(e.size)})]})]})}function O0(){let{timezone:e}=ba(),t=(0,v.useRef)(null),{user:n}=_a(),r=n?.permissions??[],i=r.includes(`*`)||r.includes(`media:write`),a=r.includes(`*`)||r.includes(`media:delete`),[o,s]=(0,v.useState)([{id:null,name:`Media`}]),c=o[o.length-1].id,[l,u]=(0,v.useState)(1),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(``);(0,v.useEffect)(()=>{let e=setTimeout(()=>{m(d),u(1)},300);return()=>clearTimeout(e)},[d]),(0,v.useEffect)(()=>{u(1),f(``),m(``)},[c]);let{data:h,loading:g,refetch:_}=Ta(`/cms/admin/folders?parent_id=${c??``}`),{data:y,loading:b,refetch:x}=Ta(`/cms/admin/media?folder_id=${c??``}&page=${l}&limit=48${p?`&search=${encodeURIComponent(p)}`:``}`),S=(0,v.useCallback)(()=>{_(),x()},[_,x]),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(null),[D,O]=(0,v.useState)(new Set),[k,A]=(0,v.useState)(null),[j,M]=(0,v.useState)(``),[N,P]=(0,v.useState)(``),[F,I]=(0,v.useState)(``),[L,R]=(0,v.useState)(!1),[ee,te]=(0,v.useState)(null),[ne,z]=(0,v.useState)(null),[B,re]=(0,v.useState)(null),[V,ie]=(0,v.useState)(null),[ae,oe]=(0,v.useState)(``),[se,ce]=(0,v.useState)(!1),[le,ue]=(0,v.useState)(``),[de,fe]=(0,v.useState)(!1),[pe,me]=(0,v.useState)(!1),{loading:he,error:ge,request:_e}=Eb(),{loading:ve,error:ye,request:be}=Eb();async function xe(e){if(e.some(({relativePath:e})=>e.endsWith(`.m3u8`))){let t=new FormData;for(let{file:n,relativePath:r}of e)t.append(`files`,n,r);c&&t.append(`folder_id`,c),t.append(`bundle`,`true`);let n=await fetch(`/cms/admin/media`,{method:`POST`,credentials:`include`,body:t});if(!n.ok){let e=await n.text(),t=`Upload failed.`;try{t=JSON.parse(e).error??t}catch{}throw Error(t)}}else await Promise.all(e.map(({file:e})=>p$(e,{folderId:c})))}async function Se(e){if(i&&!(!e||e.length===0)){w(!0),E(null);try{await xe(Array.from(e).map(e=>({file:e,relativePath:e.webkitRelativePath||e.name}))),S(),X.success(`Upload complete`)}catch(e){E(e instanceof Error?e.message:`Upload failed.`),X.error(`Upload failed`)}finally{w(!1),t.current&&(t.current.value=``)}}}async function Ce(e){if(!i)return;e.preventDefault();let t=Array.from(e.dataTransfer.items);if(!t.some(e=>typeof e.webkitGetAsEntry==`function`)){Se(e.dataTransfer.files);return}w(!0),E(null);try{let e=t.map(e=>e.webkitGetAsEntry()).filter(e=>e!==null);await xe((await Promise.all(e.map(C0))).flat()),S(),X.success(`Upload complete`)}catch(e){E(e instanceof Error?e.message:`Upload failed.`),X.error(`Upload failed`)}finally{w(!1)}}function we(e){s(t=>[...t,{id:e.id,name:e.name}]),O(new Set)}function Te(e){s(t=>t.slice(0,e+1)),O(new Set)}async function Ee(){if(i&&le.trim())try{await be(`/cms/admin/folders`,`POST`,{name:le.trim(),parent_id:c}),ce(!1),ue(``),_(),X.success(`Folder created`)}catch{X.error(`Could not create folder`)}}async function De(){if(i&&!(!V||!ae.trim()))try{await be(`/cms/admin/folders/${V.id}`,`PATCH`,{name:ae.trim()}),ie(null),_(),X.success(`Folder renamed`)}catch{X.error(`Could not rename folder`)}}async function Oe(){if(a&&B)try{await _e(`/cms/admin/folders/${B.id}`,`DELETE`),re(null),_(),X.success(`Folder deleted`)}catch{X.error(`Could not delete folder`)}}async function ke(){if(a&&ne)try{await _e(`/cms/admin/media/${ne.id}`,`DELETE`),z(null),x(),X.success(`File deleted`)}catch{X.error(`Could not delete file`)}}function Ae(e){O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function je(e){A(e),M(e.filename),P(e.alt??_0(e.filename)),I(e.caption??``),te(null)}function Me(e){if(!k)return;let t=Ie.findIndex(e=>e.id===k.id);if(t===-1)return;let n=Ie[t+e];n&&je(n)}async function Ne(){if(k){R(!0),te(null);try{let e=await fetch(`/cms/admin/media/${k.id}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({filename:j||k.filename,alt:N.trim()||null,caption:F.trim()||null})});if(!e.ok)throw Error(`Save failed.`);je(await e.json()),x(),X.success(`File updated`)}catch(e){te(e instanceof Error?e.message:`Save failed.`),X.error(`Could not update file`)}finally{R(!1)}}}function Pe(e){M(e);let t=_0(j),n=_0(e);(!N.trim()||N===t)&&P(n)}let Fe=h?.folders??[],Ie=y?.items??[],Le=k?Ie.findIndex(e=>e.id===k.id):-1,Re=Le>0,ze=Le!==-1&&Le<Ie.length-1,Be=[...Fe.map(e=>`folder:${e.id}`),...Ie.map(e=>e.id)];(0,v.useEffect)(()=>{if(!k)return;function e(e){e.key===`ArrowLeft`&&Re&&(e.preventDefault(),Me(-1)),e.key===`ArrowRight`&&ze&&(e.preventDefault(),Me(1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[k,Re,ze,Ie]);async function Ve(){if(a&&!pe){me(!0);try{await Promise.all([...[...D].filter(e=>e.startsWith(`folder:`)).map(e=>fetch(`/cms/admin/folders/${e.slice(7)}`,{method:`DELETE`,credentials:`include`})),...[...D].filter(e=>!e.startsWith(`folder:`)).map(e=>fetch(`/cms/admin/media/${e}`,{method:`DELETE`,credentials:`include`}))]),X.success(`Files deleted`),fe(!1),O(new Set),S()}catch{X.error(`Could not delete files`)}finally{me(!1)}}}let He=g||b,Ue=Fe.length===0&&Ie.length===0;return(0,H.jsxs)(`div`,{children:[(0,H.jsx)($b,{children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,H.jsx)(`h1`,{className:`text-2xl font-semibold -mt-2`,children:`Media Library`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsxs)(q,{variant:`outline`,onClick:()=>{ue(``),ce(!0)},disabled:!i,children:[(0,H.jsx)(po,{className:`size-4`}),`New folder`]}),(0,H.jsxs)(q,{onClick:()=>t.current?.click(),disabled:C||!i,children:[C?(0,H.jsx)(ex,{className:`size-4`}):(0,H.jsx)(as,{className:`size-4`}),C?`Uploading…`:`Upload`]})]})]})}),(0,H.jsxs)(`section`,{className:`mt-24`,children:[o.length>1&&(0,H.jsx)(l0,{className:`mb-4`,children:(0,H.jsx)(u0,{children:o.map((e,t)=>(0,H.jsxs)(v.Fragment,{children:[t>0&&(0,H.jsx)(m0,{}),(0,H.jsx)(d0,{children:t===o.length-1?(0,H.jsx)(p0,{children:t===0?(0,H.jsx)(bo,{className:`size-3.5`}):e.name}):(0,H.jsx)(f0,{asChild:!0,children:(0,H.jsx)(`button`,{onClick:()=>Te(t),children:t===0?(0,H.jsx)(bo,{className:`size-3.5`}):e.name})})})]},`${e.id??`root`}:${e.name}`))})}),(0,H.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 rounded-lg border border-border bg-muted/50 p-2`,children:[(0,H.jsxs)(`div`,{className:`relative max-w-72 w-full`,children:[(0,H.jsx)(Go,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground pointer-events-none`}),(0,H.jsx)(J,{className:`pl-9 h-8 bg-background`,placeholder:`Search media…`,value:d,onChange:e=>f(e.target.value)})]}),!b&&y!=null&&(0,H.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[Ie.length,` / `,y.total,` `,y.total===1?`file`:`files`]}),(0,H.jsx)(`div`,{className:`ml-auto flex h-8 items-center gap-2`,children:D.size>0?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{className:`text-sm font-medium`,children:[D.size,` selected`]}),(0,H.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>O(new Set),children:`Clear`}),a&&(0,H.jsxs)(q,{variant:`destructive`,size:`sm`,disabled:pe,onClick:()=>fe(!0),children:[(0,H.jsx)(es,{className:`size-3.5`}),`Delete`]})]}):!Ue&&!He?(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors`,onClick:()=>O(new Set(Be)),children:[(0,H.jsx)(_k,{checked:!1,"aria-hidden":!0,className:`pointer-events-none`}),`Select all`]}):null})]}),(0,H.jsx)(`input`,{ref:t,type:`file`,multiple:!0,className:`hidden`,onChange:e=>Se(e.target.files)}),T&&(0,H.jsx)(`p`,{className:`mb-4 text-sm text-destructive`,children:T}),He?(0,H.jsx)(`div`,{className:`flex items-center gap-2 py-16 justify-center text-muted-foreground`,children:(0,H.jsx)(ex,{className:`size-5`})}):Ue?(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-lg border border-dashed py-20 text-center cursor-pointer hover:bg-muted/50 transition-colors`,onClick:()=>i&&t.current?.click(),onDragOver:e=>e.preventDefault(),onDrop:Ce,children:[(0,H.jsx)(as,{className:`size-8 text-muted-foreground mb-3`}),(0,H.jsx)(`p`,{className:`text-sm font-medium`,children:`Drop files or folders here, or click to upload`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Images, videos, audio, documents and more`})]}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-6`,onDragOver:e=>e.preventDefault(),onDrop:Ce,children:[Fe.length>0&&(0,H.jsx)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4`,children:Fe.map(e=>(0,H.jsx)(E0,{folder:e,onOpen:we,onDelete:re,onRename:e=>{ie(e),oe(e.name)},canDelete:a,canRename:i,selected:D.has(`folder:${e.id}`),onToggle:Ae},e.id))}),Ie.length>0&&(0,H.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6`,children:Ie.map(e=>(0,H.jsx)(D0,{item:e,onDelete:z,onPreview:je,canDelete:a,selected:D.has(e.id),onToggle:Ae},e.id))})]}),(y?.pages??0)>1&&(0,H.jsx)(`div`,{className:`mt-4`,children:(0,H.jsx)(zk,{className:`mx-0 w-auto justify-end`,children:(0,H.jsxs)(Bk,{children:[(0,H.jsx)(Vk,{children:(0,H.jsx)(Uk,{href:`#`,onClick:e=>{e.preventDefault(),l>1&&u(l-1)},"aria-disabled":l===1,className:l===1?`pointer-events-none opacity-50`:``})}),(0,H.jsx)(Vk,{children:(0,H.jsx)(Wk,{href:`#`,onClick:e=>{e.preventDefault(),l<(y?.pages??1)&&u(l+1)},"aria-disabled":l===(y?.pages??1),className:l===(y?.pages??1)?`pointer-events-none opacity-50`:``})})]})})}),(0,H.jsx)(vy,{open:!!k,onOpenChange:e=>{e||(A(null),te(null),I(``))},children:(0,H.jsxs)(Sy,{className:`sm:max-w-5xl max-h-[90vh] overflow-hidden p-0`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{className:`truncate px-6 pt-6 pr-12`,title:k?.filename,children:k?.filename})}),k&&(0,H.jsxs)(`div`,{className:`grid max-h-[calc(90vh-4rem)] min-h-0 gap-0 lg:grid-cols-[minmax(0,1fr)_320px]`,children:[(0,H.jsxs)(`div`,{className:`relative flex min-h-0 items-center justify-center overflow-hidden bg-muted/30 px-6 py-4`,children:[(0,H.jsx)(`div`,{className:`flex h-full w-full min-h-[280px] items-center justify-center overflow-hidden rounded-xl border bg-background/70 p-4`,children:(0,H.jsx)(T0,{item:k})}),(0,H.jsx)(q,{type:`button`,variant:`secondary`,size:`icon`,className:`absolute left-8 top-1/2 size-10 -translate-y-1/2 rounded-full shadow-sm`,onClick:()=>Me(-1),disabled:!Re,"aria-label":`Previous file`,children:(0,H.jsx)(Ga,{className:`size-4`})}),(0,H.jsx)(q,{type:`button`,variant:`secondary`,size:`icon`,className:`absolute right-8 top-1/2 size-10 -translate-y-1/2 rounded-full shadow-sm`,onClick:()=>Me(1),disabled:!ze,"aria-label":`Next file`,children:(0,H.jsx)(Ka,{className:`size-4`})})]}),(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-col border-t lg:border-l lg:border-t-0`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 border-b px-6 py-4 text-xs text-muted-foreground`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Type`}),(0,H.jsx)(`p`,{className:`break-all`,children:k.mime_type??`—`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Size`}),(0,H.jsx)(`p`,{children:g0(k.size??null)})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Dimensions`}),(0,H.jsx)(`p`,{children:k.width&&k.height?`${k.width} × ${k.height}`:`—`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Created`}),(0,H.jsx)(`p`,{children:ix(k.created_at,e)})]})]}),(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-6 py-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{className:`text-xs`,children:`Filename`}),(0,H.jsx)(J,{value:j,onChange:e=>Pe(e.target.value),placeholder:k.filename,className:`text-sm`,disabled:!i})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{className:`text-xs`,children:`Alt text`}),(0,H.jsx)(J,{value:N,onChange:e=>P(e.target.value),placeholder:_0(j||k.filename),className:`text-sm`,disabled:!i}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Defaulted from the filename without extension. You can override it.`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{className:`text-xs`,children:`Subtitle`}),(0,H.jsx)(zP,{value:F,onChange:e=>I(e.target.value),placeholder:`Used as figcaption in the frontend…`,className:`min-h-28 resize-none text-sm`,disabled:!i})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pt-2`,children:[(0,H.jsx)(`a`,{href:k.url,target:`_blank`,rel:`noreferrer`,download:k.filename,children:(0,H.jsxs)(q,{variant:`outline`,size:`sm`,type:`button`,children:[(0,H.jsx)(no,{className:`size-3.5`}),`Download`]})}),(0,H.jsx)(q,{type:`button`,size:`sm`,onClick:Ne,disabled:L||!i,children:L?`Saving…`:`Save`})]}),ee&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:ee})]})]})]})]})}),(0,H.jsx)(vy,{open:se,onOpenChange:e=>{e||ce(!1)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`New folder`})}),(0,H.jsx)(J,{placeholder:`Folder name`,value:le,onChange:e=>ue(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Ee()}}),ye&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:ye}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>ce(!1),children:`Cancel`}),(0,H.jsx)(q,{onClick:Ee,disabled:ve||!le.trim()||!i,children:ve?`Creating…`:`Create`})]})]})}),(0,H.jsx)(vy,{open:!!V,onOpenChange:e=>{e||ie(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Rename folder`})}),(0,H.jsx)(J,{value:ae,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`&&De()}}),ye&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:ye}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>ie(null),children:`Cancel`}),(0,H.jsx)(q,{onClick:De,disabled:ve||!ae.trim()||!i,children:ve?`Saving…`:`Save`})]})]})}),(0,H.jsx)(vy,{open:!!ne,onOpenChange:e=>{e||z(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Delete file`})}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Are you sure you want to delete`,` `,(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:ne?.filename}),`? This action cannot be undone.`]}),ge&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:ge}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>z(null),children:`Cancel`}),(0,H.jsx)(q,{variant:`destructive`,onClick:ke,disabled:he||!a,children:he?`Deleting…`:`Delete`})]})]})}),(0,H.jsx)(vy,{open:!!B,onOpenChange:e=>{e||re(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Delete folder`})}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Are you sure you want to delete`,` `,(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:B?.name}),`? The folder must be empty.`]}),ge&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:ge}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>re(null),children:`Cancel`}),(0,H.jsx)(q,{variant:`destructive`,onClick:Oe,disabled:he||!a,children:he?`Deleting…`:`Delete`})]})]})}),(0,H.jsx)(vy,{open:de,onOpenChange:e=>{e||fe(!1)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsxs)(Ty,{children:[`Delete `,D.size,` `,D.size===1?`item`:`items`,`?`]})}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This action cannot be undone. Non-empty folders will be skipped.`}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>fe(!1),children:`Cancel`}),(0,H.jsxs)(q,{variant:`destructive`,onClick:Ve,disabled:pe,children:[pe?(0,H.jsx)(ex,{className:`size-4`}):null,`Delete`]})]})]})})]})]})}var k0=`plank:addons-registry-updated`,A0=new Map;function j0(e){return e.installed&&e.enabled&&e.compatible&&e.hasAdminUi}function M0(){window.dispatchEvent(new CustomEvent(k0))}async function N0(e){let t=window.PlankAddonAdminModules?.[e];if(t)return t;let n=A0.get(e);if(n)return n;let r=new Promise((t,n)=>{let r=document.createElement(`script`);r.src=`/cms/admin/addons/${e}/admin-entry.js`,r.async=!0,r.dataset.plankAddonId=e,r.onload=()=>{t(window.PlankAddonAdminModules?.[e]??null)},r.onerror=()=>{r.remove(),A0.delete(e),n(Error(`Could not load admin runtime for ${e}`))},document.head.appendChild(r)});return A0.set(e,r),r}function P0({items:e}){let{pathname:t}=lr();function n(e){return t===e||t.startsWith(e+`/`)}return(0,H.jsx)(`nav`,{className:`flex flex-col gap-0.5 p-2`,children:e.map(({label:e,to:t,icon:r})=>(0,H.jsxs)(Ji,{to:t,className:[`flex items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm transition-colors`,n(t)?`bg-sidebar-accent text-sidebar-accent-foreground font-medium`:`text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-accent-foreground`].join(` `),children:[r&&(0,H.jsx)(r,{className:`size-3.5 shrink-0`}),(0,H.jsx)(`span`,{className:`truncate`,children:e})]},t))})}function F0(){let{data:e,refetch:t}=Ta(`/cms/admin/addons/registry`);(0,v.useEffect)(()=>{function e(){t()}return window.addEventListener(k0,e),()=>window.removeEventListener(k0,e)},[t]);let n=(e?.addons??[]).filter(j0),r=new Map((e?.slots.addonsSections??[]).map(e=>[e.addonId,e.title])),i=[{label:`Overview`,to:`/add-ons/overview`,icon:za},...n.map(e=>({label:r.get(e.id)??e.name,to:`/add-ons/${e.id}`,icon:Ro}))];return(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`div`,{className:`border-b border-sidebar-border px-4 py-3`,children:(0,H.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Add-ons`})}),(0,H.jsx)(P0,{items:i})]})}function I0(){return LT((0,H.jsx)(F0,{})),(0,H.jsx)($r,{})}function L0(e,t){return e?.permissions.includes(`*`)||e?.permissions.includes(t)||!1}function R0(){let{user:e}=_a(),t=[{label:`Overview`,to:`/settings/overview`,icon:Ko,permission:`settings:overview:read`},{label:`Users`,to:`/settings/users`,icon:cs,permission:`settings:users:read`},{label:`Roles`,to:`/settings/roles`,icon:qo,permission:`settings:roles:read`},{label:`API Tokens`,to:`/settings/api-tokens`,icon:wo,permission:`settings:api-tokens:read`},{label:`Webhooks`,to:`/settings/webhooks`,icon:ls,permission:`settings:webhooks:read`}].filter(({permission:t})=>L0(e,t));return(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`div`,{className:`border-b border-sidebar-border px-4 py-3`,children:(0,H.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Settings`})}),(0,H.jsx)(P0,{items:t})]})}function z0(){return LT((0,H.jsx)(R0,{})),(0,H.jsx)($r,{})}function B0(){let{addonId:e=``}=gr(),{data:t,loading:n}=Ta(`/cms/admin/addons/registry`),{data:r,loading:i}=Ta(e?`/cms/admin/addons/${e}/admin-module`:null),{data:a,loading:o,refetch:s}=Ta(e?`/cms/admin/addons/${e}/settings`:null),{data:c,loading:l}=Ta(`/cms/admin/content-types`),{request:u}=Eb(),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),_=t?.addons.find(t=>t.id===e)??null,y=(t?.slots.addonsSections??[]).filter(t=>t.addonId===e),b=(t?.slots.dashboardWidgets??[]).filter(t=>t.addonId===e);(0,v.useEffect)(()=>{if(!_||!j0(_)){f(null),g(null),m(!1);return}let e=!0;return m(!0),g(null),N0(_.id).then(t=>{e&&(f(t),t||g(`This add-on did not register an admin runtime.`))}).catch(t=>{e&&(f(null),g(t instanceof Error?t.message:`Could not load add-on admin runtime`))}).finally(()=>{e&&m(!1)}),()=>{e=!1}},[_]);let x=(0,v.useCallback)(async t=>{try{let n=await u(`/cms/admin/addons/${e}/settings`,`PUT`,t);return s(),X.success(`Add-on settings saved`),n}catch(e){throw X.error(e instanceof Error?e.message:`Could not save add-on settings`),e}},[e,s,u]),S=(0,v.useCallback)(async(t,n)=>(await u(`/cms/admin/addons/${e}/actions`,`POST`,{action:t,input:n})).result,[e,u]);if(n)return(0,H.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,H.jsx)(ex,{className:`size-8`})});if(!_)return(0,H.jsx)(`section`,{className:`mt-24`,children:(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Vo,{})}),(0,H.jsx)(WT,{children:`Add-on not found`}),(0,H.jsx)(GT,{children:`This add-on is not present in the current registry.`})]})})});let C=!!d?.DashboardPage,w=!!d?.AdminPage,T=C?`dashboard`:w?`admin`:`details`;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)($b,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:_.name}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:_.packageName})]}),(0,H.jsxs)(`section`,{className:`mt-24 space-y-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(dT,{variant:_.enabled?`secondary`:`outline`,children:_.enabled?`Enabled`:`Disabled`}),(0,H.jsx)(dT,{variant:_.compatible?`secondary`:`destructive`,children:_.compatible?`Compatible`:`Incompatible`})]}),(0,H.jsxs)(Qj,{defaultValue:T,children:[(0,H.jsxs)($j,{className:`mb-6`,children:[C&&(0,H.jsx)(eM,{value:`dashboard`,children:`Dashboard`}),w&&(0,H.jsx)(eM,{value:`admin`,children:`Admin`}),(0,H.jsx)(eM,{value:`details`,children:`Details`})]}),C&&(0,H.jsx)(tM,{value:`dashboard`,className:`space-y-4`,children:j0(_)?i||o||l||p?(0,H.jsx)(`div`,{className:`flex h-40 items-center justify-center rounded-lg border bg-background`,children:(0,H.jsx)(ex,{className:`size-6`})}):r&&a&&d?.DashboardPage?(0,H.jsx)(d.DashboardPage,{addon:_,definition:r,settings:a,contentTypes:c??[],runAction:S,saveSettings:x}):(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Ko,{})}),(0,H.jsx)(WT,{children:`Dashboard runtime unavailable`}),(0,H.jsx)(GT,{children:h??`This add-on does not expose a mountable dashboard runtime yet.`})]})}):(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Ko,{})}),(0,H.jsx)(WT,{children:`Dashboard unavailable`}),(0,H.jsx)(GT,{children:`Enable the add-on and make sure it exposes an admin entry before mounting its dashboard surface.`})]})})}),w&&(0,H.jsx)(tM,{value:`admin`,className:`space-y-4`,children:j0(_)?i||o||l||p?(0,H.jsx)(`div`,{className:`flex h-40 items-center justify-center rounded-lg border bg-background`,children:(0,H.jsx)(ex,{className:`size-6`})}):r&&a&&d?.AdminPage?(0,H.jsx)(d.AdminPage,{addon:_,definition:r,settings:a,contentTypes:c??[],runAction:S,saveSettings:x}):(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Ko,{})}),(0,H.jsx)(WT,{children:`Admin runtime unavailable`}),(0,H.jsx)(GT,{children:h??`This add-on does not expose a mountable admin runtime yet.`})]})}):(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Ko,{})}),(0,H.jsx)(WT,{children:`Admin view unavailable`}),(0,H.jsx)(GT,{children:`Enable the add-on and make sure it exposes an admin entry before mounting its admin surface.`})]})})}),(0,H.jsx)(tM,{value:`details`,children:(0,H.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,H.jsxs)(fT,{className:`bg-background`,children:[(0,H.jsx)(pT,{children:(0,H.jsx)(mT,{children:r?.title??`Metadata`})}),(0,H.jsxs)(gT,{className:`space-y-3 text-sm`,children:[r?.description&&(0,H.jsx)(`p`,{className:`text-muted-foreground`,children:r.description}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-muted-foreground`,children:`Version`}),(0,H.jsx)(`div`,{className:`font-medium`,children:_.version||`Unknown version`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-muted-foreground`,children:`Settings Namespace`}),(0,H.jsx)(`div`,{className:`font-medium`,children:_.settingsNamespace??`None`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-muted-foreground`,children:`State`}),(0,H.jsxs)(`div`,{className:`font-medium`,children:[_.installed?`Installed`:`Missing`,` · `,_.enabled?`Enabled`:`Disabled`]})]})]})]}),(0,H.jsxs)(fT,{className:`bg-background`,children:[(0,H.jsx)(pT,{children:(0,H.jsx)(mT,{children:`Slot Registration`})}),(0,H.jsxs)(gT,{className:`space-y-2`,children:[y.length>0?y.map(e=>(0,H.jsxs)(`div`,{className:`rounded-md border bg-background px-3 py-2 text-sm`,children:[(0,H.jsx)(`div`,{className:`font-medium`,children:`Section`}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.slotId})]},e.slotId)):(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No section slots registered.`}),b.length>0?b.map(e=>(0,H.jsxs)(`div`,{className:`rounded-md border bg-background px-3 py-2 text-sm`,children:[(0,H.jsx)(`div`,{className:`font-medium`,children:`Widget`}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.slotId})]},e.slotId)):(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No widget slots registered.`})]})]})]})})]},T)]})]})}function V0({children:e,variant:t}){return(0,H.jsx)(dT,{variant:t,children:e})}function H0(){let{data:e,loading:t,error:n,refetch:r}=Ta(`/cms/admin/addons/registry`),{request:i,loading:a}=Eb(),[o,s]=(0,v.useState)(null),c=e?.addons??[],l=(0,v.useMemo)(()=>({total:c.length,enabled:c.filter(e=>e.enabled).length,compatible:c.filter(e=>e.compatible).length,visibleAdmin:c.filter(j0).length}),[c]);async function u(e,t){s(e);try{await i(`/cms/admin/addons/${e}/${t?`disable`:`enable`}`,`POST`),r(),M0(),X.success(t?`Add-on disabled`:`Add-on enabled`)}catch(e){X.error(e instanceof Error?e.message:`Could not update add-on`)}finally{s(null)}}return t?(0,H.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,H.jsx)(ex,{className:`size-8`})}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)($b,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:`Add-ons`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Registry, activation state and admin surface for official extensions.`})]}),(0,H.jsxs)(`section`,{className:`mt-24 space-y-6`,children:[(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{className:`flex flex-row items-center justify-between space-y-0`,children:[(0,H.jsx)(mT,{className:`text-sm font-medium`,children:`Detected`}),(0,H.jsx)(Vo,{className:`size-4 text-muted-foreground`})]}),(0,H.jsx)(gT,{children:(0,H.jsx)(`div`,{className:`text-2xl font-semibold`,children:l.total})})]}),(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{className:`flex flex-row items-center justify-between space-y-0`,children:[(0,H.jsx)(mT,{className:`text-sm font-medium`,children:`Enabled`}),(0,H.jsx)(Lo,{className:`size-4 text-muted-foreground`})]}),(0,H.jsx)(gT,{children:(0,H.jsx)(`div`,{className:`text-2xl font-semibold`,children:l.enabled})})]}),(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{className:`flex flex-row items-center justify-between space-y-0`,children:[(0,H.jsx)(mT,{className:`text-sm font-medium`,children:`Compatible`}),(0,H.jsx)(za,{className:`size-4 text-muted-foreground`})]}),(0,H.jsx)(gT,{children:(0,H.jsx)(`div`,{className:`text-2xl font-semibold`,children:l.compatible})})]}),(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{className:`flex flex-row items-center justify-between space-y-0`,children:[(0,H.jsx)(mT,{className:`text-sm font-medium`,children:`Admin UI`}),(0,H.jsx)(Ko,{className:`size-4 text-muted-foreground`})]}),(0,H.jsx)(gT,{children:(0,H.jsx)(`div`,{className:`text-2xl font-semibold`,children:l.visibleAdmin})})]})]}),c.length===0?(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Vo,{})}),(0,H.jsx)(WT,{children:`No add-ons detected`}),(0,H.jsx)(GT,{children:"Install an official `@plank-cms/addon-*` package in the host project and restart the server to populate this registry."})]})}):(0,H.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:(0,H.jsxs)(DT,{className:`w-full text-sm`,children:[(0,H.jsxs)(OT,{className:`border-b border-border font-bold uppercase`,children:[(0,H.jsx)(AT,{className:`hover:bg-transparent`,children:(0,H.jsx)(jT,{colSpan:5,className:`h-auto px-4 py-3`,children:(0,H.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Registry`})})}),(0,H.jsxs)(AT,{className:`border-t border-border hover:bg-transparent`,children:[(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:`Add-on`}),(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:`Package`}),(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:`Status`}),(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:`Settings`}),(0,H.jsx)(jT,{className:`w-28 px-4 py-3 text-right font-medium text-muted-foreground`,children:`Enabled`})]})]}),(0,H.jsx)(kT,{children:c.map(e=>{let t=a&&o===e.id,n=e.installed&&e.compatible;return(0,H.jsxs)(AT,{children:[(0,H.jsx)(MT,{children:(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.version||`Unknown version`}),e.description&&(0,H.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:e.description})]})}),(0,H.jsx)(MT,{className:`font-mono text-xs`,children:e.packageName}),(0,H.jsx)(MT,{children:(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsx)(V0,{variant:e.installed?`secondary`:`outline`,children:e.installed?`Installed`:`Missing`}),(0,H.jsx)(V0,{variant:e.compatible?`secondary`:`destructive`,children:e.compatible?`Compatible`:`Incompatible`})]})}),(0,H.jsx)(MT,{children:e.settingsNamespace?(0,H.jsx)(dT,{variant:`outline`,children:e.settingsNamespace}):(0,H.jsx)(`span`,{className:`text-muted-foreground`,children:`None`})}),(0,H.jsx)(MT,{className:`text-right`,children:(0,H.jsxs)(`div`,{className:`inline-flex items-center gap-3`,children:[t&&(0,H.jsx)(ex,{className:`size-4`}),(0,H.jsx)(uk,{checked:e.enabled,disabled:!n||t,onCheckedChange:()=>u(e.id,e.enabled)})]})})]},e.id)})})]})}),n&&(0,H.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Could not load add-ons registry: `,n]})]})]})}var U0=`••••••••`;function W0({values:e,onChange:t,disabled:n=!1}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`local-uploads-dir`,children:`Upload directory`}),(0,H.jsx)(J,{id:`local-uploads-dir`,placeholder:`public/uploads`,value:e[`local.uploads_dir`]??``,onChange:e=>t(`local.uploads_dir`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Path on disk where files are stored. Relative to the server working directory.`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`local-public-url`,children:`Public URL`}),(0,H.jsx)(J,{id:`local-public-url`,placeholder:`http://localhost:1337`,value:e[`local.public_url`]??``,onChange:e=>t(`local.public_url`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Base URL used to build file URLs. Should match the server's public address.`})]})]})}function G0({id:e,label:t,fieldKey:n,values:r,onChange:i,placeholder:a,disabled:o=!1}){let[s,c]=(0,v.useState)(!1),l=r[n]===U0,u=r[n]??``;return(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:e,children:t}),(0,H.jsxs)(`div`,{className:`relative`,children:[(0,H.jsx)(J,{id:e,type:s?`text`:`password`,placeholder:l?`Leave blank to keep current value`:a,value:l?``:u,onChange:e=>i(n,e.target.value),className:`pr-9`,disabled:o}),(0,H.jsx)(`button`,{type:`button`,className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>c(e=>!e),tabIndex:-1,disabled:o,children:s?(0,H.jsx)(io,{className:`size-4`}):(0,H.jsx)(ao,{className:`size-4`})})]}),l&&(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`A value is already saved. Enter a new one to replace it.`})]})}function K0({values:e,onChange:t,disabled:n=!1}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-access-key`,children:`Access key ID`}),(0,H.jsx)(J,{id:`s3-access-key`,placeholder:`AKIAIOSFODNN7EXAMPLE`,value:e[`s3.access_key_id`]??``,onChange:e=>t(`s3.access_key_id`,e.target.value),disabled:n})]}),(0,H.jsx)(G0,{id:`s3-secret-key`,label:`Secret access key`,fieldKey:`s3.secret_access_key`,values:e,onChange:t,disabled:n})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-region`,children:`Region`}),(0,H.jsx)(J,{id:`s3-region`,placeholder:`us-east-1`,value:e[`s3.region`]??``,onChange:e=>t(`s3.region`,e.target.value),disabled:n})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-bucket`,children:`Bucket`}),(0,H.jsx)(J,{id:`s3-bucket`,placeholder:`my-bucket`,value:e[`s3.bucket`]??``,onChange:e=>t(`s3.bucket`,e.target.value),disabled:n})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-path-prefix`,children:`Path prefix`}),(0,H.jsx)(J,{id:`s3-path-prefix`,placeholder:`cms/media`,value:e[`s3.path_prefix`]??``,onChange:e=>t(`s3.path_prefix`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. Shared bucket subfolder.`})]})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-public-url`,children:`Public URL`}),(0,H.jsx)(J,{id:`s3-public-url`,placeholder:`https://cdn.example.com`,value:e[`s3.public_url`]??``,onChange:e=>t(`s3.public_url`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. Leave blank to use the default S3 URL.`})]})]})}function q0({values:e,onChange:t,disabled:n=!1}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`r2-access-key`,children:`Access key ID`}),(0,H.jsx)(J,{id:`r2-access-key`,placeholder:`R2 access key ID`,value:e[`r2.access_key_id`]??``,onChange:e=>t(`r2.access_key_id`,e.target.value),disabled:n})]}),(0,H.jsx)(G0,{id:`r2-secret-key`,label:`Secret access key`,fieldKey:`r2.secret_access_key`,values:e,onChange:t,disabled:n})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`r2-bucket`,children:`Bucket`}),(0,H.jsx)(J,{id:`r2-bucket`,placeholder:`my-bucket`,value:e[`r2.bucket`]??``,onChange:e=>t(`r2.bucket`,e.target.value),disabled:n})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`r2-path-prefix`,children:`Path prefix`}),(0,H.jsx)(J,{id:`r2-path-prefix`,placeholder:`cms/media`,value:e[`r2.path_prefix`]??``,onChange:e=>t(`r2.path_prefix`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. Shared bucket subfolder.`})]})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsxs)(Y,{htmlFor:`r2-public-url`,children:[`Public URL `,(0,H.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,H.jsx)(J,{id:`r2-public-url`,placeholder:`https://assets.example.com`,value:e[`r2.public_url`]??``,onChange:e=>t(`r2.public_url`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Required. R2 does not generate public URLs automatically.`})]})]})}function J0(){let{user:e}=_a(),{data:t,loading:n}=Ta(`/cms/admin/settings/media`),{loading:r,error:i,request:a}=Eb(),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(!1),u=o??t??{provider:`local`},d=u.provider||`local`,f=e?.permissions??[],p=f.includes(`*`)||f.includes(`settings:overview:write`);function m(e,t){s({...u,[e]:t})}function h(e){s({...u,provider:e})}async function g(e){e.preventDefault();try{await a(`/cms/admin/settings/media`,`PUT`,u),l(!0),setTimeout(()=>l(!1),2500),X.success(`Media settings saved`)}catch{X.error(`Could not save media settings`)}}return n?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-8 text-muted-foreground`,children:[(0,H.jsx)(ex,{className:`size-4`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading settings…`})]}):(0,H.jsxs)(`form`,{onSubmit:g,className:`space-y-8`,children:[(0,H.jsxs)(`div`,{className:`border-b pb-4`,children:[(0,H.jsx)(`h2`,{className:`text-2xl font-semibold`,children:`Storage`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure where uploaded files are stored.`})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`provider`,children:`Storage provider`}),(0,H.jsxs)(_T,{value:d,onValueChange:e=>h(e),children:[(0,H.jsx)(bT,{id:`provider`,disabled:!p,children:(0,H.jsx)(yT,{})}),(0,H.jsxs)(CT,{children:[(0,H.jsx)(TT,{value:`local`,children:`Local`}),(0,H.jsx)(TT,{value:`s3`,children:`Amazon S3`}),(0,H.jsx)(TT,{value:`r2`,children:`Cloudflare R2`})]})]})]}),d===`r2`&&(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`r2-account-id`,children:`Account ID`}),(0,H.jsx)(J,{id:`r2-account-id`,placeholder:`023e105f4ecef8ad9ca31a8372d0c353`,value:u[`r2.account_id`]??``,onChange:e=>m(`r2.account_id`,e.target.value),disabled:!p}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Found in the Cloudflare dashboard under R2 > Overview.`})]})]}),(0,H.jsxs)(`div`,{className:`border-t pt-6`,children:[d===`local`&&(0,H.jsx)(W0,{values:u,onChange:m,disabled:!p}),d===`s3`&&(0,H.jsx)(K0,{values:u,onChange:m,disabled:!p}),d===`r2`&&(0,H.jsx)(q0,{values:u,onChange:m,disabled:!p})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(q,{type:`submit`,disabled:r||!p,children:r?`Saving…`:`Save`}),c&&(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Changes saved.`}),i&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:i})]})]})}var Y0={name:`@plank-cms/admin`,version:`0.28.1`,type:`module`,scripts:{build:`vite build`,dev:`vite`,lint:`eslint src/`},dependencies:{"@dnd-kit/core":`6.3.1`,"@dnd-kit/sortable":`10.0.0`,"@dnd-kit/utilities":`3.2.2`,"@radix-ui/react-avatar":`1.1.11`,"@radix-ui/react-checkbox":`1.3.3`,"@radix-ui/react-dialog":`1.1.15`,"@radix-ui/react-dropdown-menu":`2.1.16`,"@radix-ui/react-label":`2.1.8`,"@radix-ui/react-popover":`1.1.15`,"@radix-ui/react-select":`2.2.6`,"@radix-ui/react-separator":`1.1.8`,"@radix-ui/react-slot":`1.2.4`,"@radix-ui/react-switch":`1.2.6`,"@radix-ui/react-tabs":`1.1.13`,"@radix-ui/react-tooltip":`1.2.8`,"@tanstack/react-table":`8.21.3`,"@tiptap/extension-image":`3.22.4`,"@tiptap/pm":`3.22.4`,"@tiptap/react":`3.22.4`,"@tiptap/starter-kit":`3.22.4`,"class-variance-authority":`0.7.1`,clsx:`2.1.1`,cmdk:`1.1.1`,"date-fns":`4.1.0`,"hls.js":`1.6.16`,"input-otp":`1.4.2`,"lucide-react":`1.8.0`,"next-themes":`0.4.6`,"qrcode.react":`4.2.0`,"radix-ui":`1.4.3`,react:`19.2.5`,"react-day-picker":`9.14.0`,"react-dom":`19.2.5`,"react-router-dom":`7.14.1`,sonner:`2.0.7`,"tailwind-merge":`3.5.0`},devDependencies:{"@tailwindcss/vite":`4.2.3`,"@types/react":`19.2.14`,"@types/react-dom":`19.2.3`,"@types/react-router-dom":`5.3.3`,"@vitejs/plugin-react":`6.0.1`,tailwindcss:`4.2.3`,vite:`8.0.9`}},X0=[{value:`UTC`,label:`UTC — Coordinated Universal Time`},{value:`America/New_York`,label:`America/New_York — Eastern Time (UTC-5/4)`},{value:`America/Chicago`,label:`America/Chicago — Central Time (UTC-6/5)`},{value:`America/Denver`,label:`America/Denver — Mountain Time (UTC-7/6)`},{value:`America/Los_Angeles`,label:`America/Los_Angeles — Pacific Time (UTC-8/7)`},{value:`America/Anchorage`,label:`America/Anchorage — Alaska Time (UTC-9/8)`},{value:`America/Honolulu`,label:`America/Honolulu — Hawaii Time (UTC-10)`},{value:`America/Mexico_City`,label:`America/Mexico_City — Mexico City (UTC-6/5)`},{value:`America/El_Salvador`,label:`America/El_Salvador — El Salvador (UTC-6)`},{value:`America/Bogota`,label:`America/Bogota — Colombia Time (UTC-5)`},{value:`America/Lima`,label:`America/Lima — Peru Time (UTC-5)`},{value:`America/Santiago`,label:`America/Santiago — Chile Time (UTC-4/3)`},{value:`America/Argentina/Buenos_Aires`,label:`America/Buenos_Aires — Argentina (UTC-3)`},{value:`America/Sao_Paulo`,label:`America/Sao_Paulo — Brasília Time (UTC-3/2)`},{value:`Atlantic/Reykjavik`,label:`Atlantic/Reykjavik — Iceland (UTC+0)`},{value:`Europe/London`,label:`Europe/London — GMT/BST (UTC+0/1)`},{value:`Europe/Paris`,label:`Europe/Paris — Central European Time (UTC+1/2)`},{value:`Europe/Berlin`,label:`Europe/Berlin — Central European Time (UTC+1/2)`},{value:`Europe/Madrid`,label:`Europe/Madrid — Central European Time (UTC+1/2)`},{value:`Europe/Rome`,label:`Europe/Rome — Central European Time (UTC+1/2)`},{value:`Europe/Helsinki`,label:`Europe/Helsinki — Eastern European Time (UTC+2/3)`},{value:`Europe/Istanbul`,label:`Europe/Istanbul — Turkey Time (UTC+3)`},{value:`Europe/Moscow`,label:`Europe/Moscow — Moscow Standard Time (UTC+3)`},{value:`Asia/Dubai`,label:`Asia/Dubai — Gulf Standard Time (UTC+4)`},{value:`Asia/Karachi`,label:`Asia/Karachi — Pakistan Standard Time (UTC+5)`},{value:`Asia/Kolkata`,label:`Asia/Kolkata — India Standard Time (UTC+5:30)`},{value:`Asia/Dhaka`,label:`Asia/Dhaka — Bangladesh Standard Time (UTC+6)`},{value:`Asia/Bangkok`,label:`Asia/Bangkok — Indochina Time (UTC+7)`},{value:`Asia/Singapore`,label:`Asia/Singapore — Singapore Time (UTC+8)`},{value:`Asia/Shanghai`,label:`Asia/Shanghai — China Standard Time (UTC+8)`},{value:`Asia/Tokyo`,label:`Asia/Tokyo — Japan Standard Time (UTC+9)`},{value:`Asia/Seoul`,label:`Asia/Seoul — Korea Standard Time (UTC+9)`},{value:`Australia/Sydney`,label:`Australia/Sydney — AEST/AEDT (UTC+10/11)`},{value:`Australia/Melbourne`,label:`Australia/Melbourne — AEST/AEDT (UTC+10/11)`},{value:`Pacific/Auckland`,label:`Pacific/Auckland — New Zealand (UTC+12/13)`}];function Z0(){let{user:e}=_a(),{data:t,loading:n}=Ta(`/cms/admin/settings/general`),{request:r,loading:i}=Eb(),{request:a,loading:o}=Eb(),{request:s,loading:c}=Eb(),{refreshSettings:l}=ba(),[u,d]=(0,v.useState)(`UTC`),[f,p]=(0,v.useState)([]),[m,h]=(0,v.useState)(`en`),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(!1),x=e?.permissions??[],S=x.includes(`*`)||x.includes(`settings:overview:write`);(0,v.useEffect)(()=>{if(t?.timezone&&d(t.timezone),t?.locales)try{let e=JSON.parse(t.locales);Array.isArray(e)&&p(e)}catch{p((t.locales||``).split(`,`).map(e=>e.trim()).filter(Boolean))}t?.default_locale&&h(t.default_locale),b(String(t?.editorial_mode??`false`).toLowerCase()===`true`)},[t]);async function C(){try{await a(`/cms/admin/settings/general`,`PUT`,{locales:JSON.stringify(f),default_locale:m}),l(),X.success(`Locales saved`)}catch{X.error(`Could not save locales`)}}return n?(0,H.jsx)(ex,{}):(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsx)(fT,{children:(0,H.jsxs)(gT,{className:`flex items-center gap-4 py-2`,children:[(0,H.jsx)(`img`,{src:`/admin/plank-logo-w.svg`,alt:`Plank CMS`,className:`h-10 w-auto`}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`font-bold`,children:`Plank CMS by AM25`}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Version `,Y0.version]})]})]})}),(0,H.jsxs)(`div`,{className:`border-b pb-4`,children:[(0,H.jsx)(`h2`,{className:`text-2xl font-semibold`,children:`Commons`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`General settings that apply across the CMS.`})]}),(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(Y,{htmlFor:`timezone`,children:`Timezone`}),(0,H.jsxs)(_T,{value:u,onValueChange:e=>{d(e),(async()=>{try{await r(`/cms/admin/settings/general`,`PUT`,{timezone:e}),l(),X.success(`Timezone saved`)}catch{X.error(`Could not save timezone`)}})()},children:[(0,H.jsx)(bT,{id:`timezone`,className:`w-full`,disabled:!S,children:(0,H.jsx)(yT,{})}),(0,H.jsx)(CT,{className:`max-h-72`,children:X0.map(e=>(0,H.jsx)(TT,{value:e.value,children:e.label},e.value))})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Used to display dates and times across the admin panel.`}),i&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Saving…`})]})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 md:grid-cols-2`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{children:`Locales`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(J,{placeholder:`E.g. "en"`,value:g,onChange:e=>_(e.target.value),className:`h-9 w-full`,disabled:!S}),(0,H.jsx)(q,{variant:`outline`,className:`h-9`,disabled:!S,onClick:()=>{let e=g.trim().toLowerCase();e&&(f.includes(e)||p(t=>[...t,e]),_(``))},children:`Add`})]}),(0,H.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:f.map(e=>(0,H.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>p(t=>t.filter(t=>t!==e)),disabled:!S,children:e.toUpperCase()},e))})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`default-locale`,children:`Default locale`}),(0,H.jsxs)(_T,{value:m,onValueChange:h,children:[(0,H.jsx)(bT,{id:`default-locale`,className:`w-full`,disabled:!S,children:(0,H.jsx)(yT,{})}),(0,H.jsx)(CT,{className:`max-h-72`,children:f.length===0?(0,H.jsx)(TT,{value:m,children:m}):f.map(e=>(0,H.jsx)(TT,{value:e,children:e.toUpperCase()},e))})]}),(0,H.jsx)(`div`,{className:`pt-2 flex justify-end`,children:(0,H.jsx)(q,{variant:`outline`,onClick:C,disabled:o||!S,children:o?`Saving…`:`Save`})})]})]}),(0,H.jsx)(Fk,{}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border p-3`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(Y,{htmlFor:`editorial-mode`,children:`Editorial Mode`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Enables Editor and Viewer workflows for editorial review.`})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(uk,{id:`editorial-mode`,checked:y,onCheckedChange:e=>{b(e),(async()=>{try{await s(`/cms/admin/settings/general`,`PUT`,{editorial_mode:String(e)}),l(),X.success(`Editorial Mode saved`)}catch{X.error(`Could not save Editorial Mode`)}})()},disabled:!S}),c&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Saving…`})]})]})]})}function Q0(){let{user:e}=_a(),{data:t,loading:n}=Ta(`/cms/admin/settings/preview`),{request:r,loading:i}=Eb(),a=e?.permissions??[],o=a.includes(`*`)||a.includes(`settings:overview:write`),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(`slug`);(0,v.useEffect)(()=>{let e=e0(t);c(e.enabled),u(e.syncUrl),f(e.urlTemplate),m(e.slugField)},[t]);async function h(e){e.preventDefault();try{await r(`/cms/admin/settings/preview`,`PUT`,{enabled:String(s),sync_url:l.trim(),url_template:d.trim(),slug_field:p.trim()||`slug`}),X.success(`Preview settings saved`)}catch{X.error(`Could not save preview settings`)}}return n?(0,H.jsx)(ex,{}):(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsxs)(`div`,{className:`border-b pb-4`,children:[(0,H.jsx)(`h2`,{className:`text-2xl font-semibold`,children:`Live Preview`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure a single frontend preview target that Plank can open and sync after saves.`})]}),(0,H.jsxs)(`form`,{onSubmit:h,className:`space-y-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border p-3`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(Y,{htmlFor:`preview-enabled`,children:`Enable preview integration`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Shows the preview action in the entry editor and syncs a connected frontend tab.`})]}),(0,H.jsx)(uk,{id:`preview-enabled`,checked:s,onCheckedChange:c,disabled:!o})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`preview-sync-url`,children:`Preview sync webhook URL`}),(0,H.jsx)(J,{id:`preview-sync-url`,value:l,onChange:e=>u(e.target.value),placeholder:`https://frontend.example.com/api/plank/preview-sync`,disabled:!o}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. When set, Plank will POST a preview sync payload to this endpoint on each entry save while preview is enabled.`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`preview-url-template`,children:`Preview URL template`}),(0,H.jsx)(J,{id:`preview-url-template`,value:d,onChange:e=>f(e.target.value),placeholder:`https://frontend.example.com/draft/{contentType}/{slug}`,disabled:!o}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Supported placeholders: `,`{contentType}`,`, `,`{entryId}`,`, `,`{slug}`,`, `,`{status}`,`. The final result must be an absolute URL.`]})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`preview-slug-field`,children:`Slug field`}),(0,H.jsx)(J,{id:`preview-slug-field`,value:p,onChange:e=>m(e.target.value),placeholder:`slug`,disabled:!o}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Used when the template contains `,`{slug}`,`. Defaults to `,(0,H.jsx)(`code`,{children:`slug`}),`.`]})]}),(0,H.jsxs)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[`Example: `,(0,H.jsxs)(`code`,{children:[`https://frontend.example.com/draft/`,`{contentType}`,`/`,`{slug}`]})]}),(0,H.jsx)(`div`,{className:`flex justify-end`,children:(0,H.jsx)(q,{type:`submit`,variant:`outline`,disabled:i||!o,children:i?`Saving…`:`Save`})})]})]})}function $0(){return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)($b,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:`Overview`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`General configuration for your CMS instance.`})]}),(0,H.jsxs)(Qj,{defaultValue:`general`,className:`mt-24`,children:[(0,H.jsxs)($j,{className:`mb-6`,children:[(0,H.jsx)(eM,{value:`general`,children:`General`}),(0,H.jsx)(eM,{value:`preview`,children:`Preview`}),(0,H.jsx)(eM,{value:`media`,children:`Media Library`})]}),(0,H.jsx)(tM,{value:`general`,children:(0,H.jsx)(Z0,{})}),(0,H.jsx)(tM,{value:`preview`,children:(0,H.jsx)(Q0,{})}),(0,H.jsx)(tM,{value:`media`,children:(0,H.jsx)(J0,{})})]})]})}function e2(e,t){return typeof e==`function`?e(t):e}function t2(e,t){return n=>{t.setState(t=>({...t,[e]:e2(n,t[e])}))}}function n2(e){return e instanceof Function}function r2(e){return Array.isArray(e)&&e.every(e=>typeof e==`number`)}function i2(e,t){let n=[],r=e=>{e.forEach(e=>{n.push(e);let i=t(e);i!=null&&i.length&&r(i)})};return r(e),n}function a2(e,t,n){let r=[],i;return a=>{let o;n.key&&n.debug&&(o=Date.now());let s=e(a);if(!(s.length!==r.length||s.some((e,t)=>r[t]!==e)))return i;r=s;let c;if(n.key&&n.debug&&(c=Date.now()),i=t(...s),n==null||n.onChange==null||n.onChange(i),n.key&&n.debug&&n!=null&&n.debug()){let e=Math.round((Date.now()-o)*100)/100,t=Math.round((Date.now()-c)*100)/100,r=t/16,i=(e,t)=>{for(e=String(e);e.length<t;)e=` `+e;return e};console.info(`%c⏱ ${i(t,5)} /${i(e,5)} ms`,`
219
+ `):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=nq(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);return t?[{type:`taskList`,raw:t.raw,items:t.items}]:n.blockTokens(e)},i=nq(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});EK.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(AZ.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(jZ.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(HZ.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push($Z.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(tQ.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(nQ.configure(this.options.taskList)),e}});var rQ=`&nbsp;`,iQ=`\xA0`,aQ=cq.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,rG(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return n.length===1&&n[0].type===`text`&&(n[0].raw===rQ||n[0].text===rQ||n[0].raw===iQ||n[0].text===iQ)&&r.length===1&&r[0].type===`text`&&(r[0].text===rQ||r[0].text===iQ)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return``;let r=Array.isArray(e.content)?e.content:[];if(r.length===0){let e=Array.isArray(n?.previousNode?.content)?n.previousNode.content:[];return n?.previousNode?.type===`paragraph`&&e.length===0?rQ:``}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),oQ=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,sQ=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,cQ=_K.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,rG(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[HK({find:oQ,type:this.type})]},addPasteRules(){return[uq({find:sQ,type:this.type})]}}),lQ=cq.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),uQ=_K.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,rG(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`++${t.renderChildren(e)}++`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.indexOf(`++`)},tokenize(e,t,n){let r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(e);if(!r)return;let i=r[2].trim();return{type:`underline`,raw:r[0],text:i,tokens:n.inlineTokens(i)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}});function dQ(e={}){return new YL({view(t){return new fQ(t,e)}})}var fQ=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(t&&!i){let e=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let t=oL(this.editorView.state.doc,e,this.editorView.dragging.slice);t!=null&&(e=t)}this.setCursor(e),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},pQ=class e extends DL{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):DL.near(r)}content(){return QP.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new mQ(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!gQ(e)||!_Q(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)<o.childCount:t.index(r)>0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}else if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!NL.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};pQ.prototype.visible=!1,pQ.findFrom=pQ.findGapCursorFrom,DL.jsonID(`gapcursor`,pQ);var mQ=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return pQ.valid(t)?new pQ(t):DL.near(t)}};function hQ(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function gQ(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||hQ(e.type))return!0;if(e.inlineContent)return!1}}return!0}function _Q(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0;continue}for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||hQ(e.type))return!0;if(e.inlineContent)return!1}}return!0}function vQ(){return new YL({props:{decorations:CQ,createSelectionBetween(e,t,n){return t.pos==n.pos&&pQ.valid(n)?new pQ(n):null},handleClick:xQ,handleKeyDown:yQ,handleDOMEvents:{beforeinput:SQ}}})}var yQ=TU({ArrowLeft:bQ(`horiz`,-1),ArrowRight:bQ(`horiz`,1),ArrowUp:bQ(`vert`,-1),ArrowDown:bQ(`vert`,1)});function bQ(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof jL){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=pQ.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new pQ(c))),!0):!1}}function xQ(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!pQ.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&NL.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new pQ(r))),!0)}function SQ(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof pQ))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=Q.empty;for(let e=r.length-1;e>=0;e--)i=Q.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new QP(i,0,0));return a.setSelection(jL.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function CQ(e){if(!(e.selection instanceof pQ))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,wH.create(e.doc,[xH.widget(e.selection.head,t,{key:`gapcursor`})])}var wQ=200,TQ=function(){};TQ.prototype.append=function(e){return e.length?(e=TQ.from(e),!this.length&&e||e.length<wQ&&this.leafAppend(e)||this.length<wQ&&e.leafPrepend(this)||this.appendInner(e)):this},TQ.prototype.prepend=function(e){return e.length?TQ.from(e).append(this):this},TQ.prototype.appendInner=function(e){return new DQ(this,e)},TQ.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?TQ.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},TQ.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},TQ.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},TQ.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},TQ.from=function(e){return e instanceof TQ?e:e&&e.length?new EQ(e):TQ.empty};var EQ=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i<n;i++)if(e(this.values[i],r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){for(var i=t-1;i>=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=wQ)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=wQ)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(TQ);TQ.empty=new EQ([]);var DQ=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return e<this.left.length?this.left.get(e):this.right.get(e-this.left.length)},t.prototype.forEachInner=function(e,t,n,r){var i=this.left.length;if(t<i&&this.left.forEachInner(e,t,Math.min(n,i),r)===!1||n>i&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n<i&&this.left.forEachInvertedInner(e,Math.min(t,i),n,r)===!1)return!1},t.prototype.sliceInner=function(e,t){if(e==0&&t==this.length)return this;var n=this.left.length;return t<=n?this.left.slice(e,t):e>=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(TQ),OQ=500,kQ=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step){i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);return}if(i){u.push(new jQ(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new jQ(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;e<t.steps.length;e++){let r=t.steps[e].invert(t.docs[e]),l=new jQ(t.mapping.maps[e],r,n),u;(u=c&&c.merge(l))&&(l=u,e?a.pop():s=s.slice(0,s.length-1)),a.push(l),n&&=(o++,void 0),i||(c=l)}let l=o-r.depth;return l>NQ&&(s=AQ(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new wI;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new jQ(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new jQ(i,o,l))}else r.push(new jQ(i))},i);let l=[];for(let e=n;e<o;e++)l.push(new jQ(a.maps[e]));let u=new e(this.items.slice(0,i).append(l).append(r),s);return u.emptyItemCount()>OQ&&(u=u.compress(this.items.length-r.length)),u}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new jQ(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(TQ.from(i.reverse()),a)}};kQ.empty=new kQ(TQ.empty,0);function AQ(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var jQ=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},MQ=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},NQ=20;function PQ(e,t,n,r){let i=n.getMeta(HQ),a;if(i)return i.historyState;n.getMeta(UQ)&&(e=new MQ(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(HQ))return o.getMeta(HQ).redo?new MQ(e.done.addTransform(n,void 0,r,VQ(t)),e.undone,IQ(n.mapping.maps),e.prevTime,e.prevComposition):new MQ(e.done,e.undone.addTransform(n,void 0,r,VQ(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!FQ(n,e.prevRanges)),s=o?LQ(e.prevRanges,n.mapping):IQ(n.mapping.maps);return new MQ(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,VQ(t)),kQ.empty,s,n.time,i??e.prevComposition)}else if(a=n.getMeta(`rebased`))return new MQ(e.done.rebased(n,a),e.undone.rebased(n,a),LQ(e.prevRanges,n.mapping),e.prevTime,e.prevComposition);else return new MQ(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),LQ(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function FQ(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i<t.length;i+=2)e<=t[i+1]&&r>=t[i]&&(n=!0)}),n}function IQ(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function LQ(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let i=t.map(e[r],1),a=t.map(e[r+1],-1);i<=a&&n.push(i,a)}return n}function RQ(e,t,n){let r=VQ(t),i=HQ.get(t).spec.config,a=(n?e.undone:e.done).popEvent(t,r);if(!a)return null;let o=a.selection.resolve(a.transform.doc),s=(n?e.done:e.undone).addTransform(a.transform,t.selection.getBookmark(),i,r),c=new MQ(n?s:a.remaining,n?a.remaining:s,null,0,-1);return a.transform.setSelection(o).setMeta(HQ,{redo:n,historyState:c})}var zQ=!1,BQ=null;function VQ(e){let t=e.plugins;if(BQ!=t){zQ=!1,BQ=t;for(let e=0;e<t.length;e++)if(t[e].spec.historyPreserveItems){zQ=!0;break}}return zQ}var HQ=new QL(`history`),UQ=new QL(`closeHistory`);function WQ(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new YL({key:HQ,state:{init(){return new MQ(kQ.empty,kQ.empty,null,0,-1)},apply(t,n,r){return PQ(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(e,t){let n=t.inputType,r=n==`historyUndo`?KQ:n==`historyRedo`?qQ:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function GQ(e,t){return(n,r)=>{let i=HQ.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=RQ(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var KQ=GQ(!1,!0),qQ=GQ(!0,!0);EK.create({name:`characterCount`,addOptions(){return{limit:null,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new YL({key:new QL(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit;if(i==null||i===0){e=!0;return}let a=this.storage.characters({node:r.doc});if(a>i){let t=a-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var JQ=EK.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[dQ(this.options)]}});EK.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new YL({key:new QL(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return wH.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(xH.node(t,t+e.nodeSize,{class:this.options.className}))}),wH.create(e,a)}}})]}});var YQ=EK.create({name:`gapCursor`,addProseMirrorPlugins(){return[vQ()]},extendNodeSchema(e){return{allowGapCursor:ZW(qW(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),XQ=`placeholder`;function ZQ(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}EK.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:XQ,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){let e=this.options.dataAttribute?`data-${ZQ(this.options.dataAttribute)}`:`data-${XQ}`;return[new YL({key:new QL(`placeholder`),props:{decorations:({doc:t,selection:n})=>{let r=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:i}=n,a=[];if(!r)return null;let o=this.editor.isEmpty;return t.descendants((t,n)=>{let r=i>=n&&i<=n+t.nodeSize,s=!t.isLeaf&&MG(t);if(!t.type.isTextblock)return this.options.includeChildren;if((r||!this.options.showOnlyCurrent)&&s){let i=[this.options.emptyNodeClass];o&&i.push(this.options.emptyEditorClass);let s=xH.node(n,n+t.nodeSize,{class:i.join(` `),[e]:typeof this.options.placeholder==`function`?this.options.placeholder({editor:this.editor,node:t,pos:n,hasAnchor:r}):this.options.placeholder});a.push(s)}return this.options.includeChildren}),wH.create(t,a)}}})]}}),EK.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new YL({key:new QL(`selection`),props:{decorations(n){return n.selection.empty||e.isFocused||!e.isEditable||NG(n.selection)||e.view.dragging?null:wH.create(n.doc,[xH.inline(n.selection.from,n.selection.to,{class:t.className})])}}})]}});function QQ({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var $Q=EK.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new QL(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new YL({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(!n.some(e=>e.getMeta(`skipTrailingNode`))&&c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!QQ({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!QQ({node:r,types:n})}}})]}}),e$=EK.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>KQ(e,t),redo:()=>({state:e,dispatch:t})=>qQ(e,t)}},addProseMirrorPlugins(){return[WQ(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),t$=EK.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push(qJ.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(HJ.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(AZ.configure(this.options.bulletList)),this.options.code!==!1&&e.push(XJ.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(eY.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(tY.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(JQ.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(YQ.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(nY.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push(rY.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(e$.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(iY.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(lY.configure(this.options.italic)),this.options.listItem!==!1&&e.push(jZ.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(HZ.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(wZ.configure(this.options?.link)),this.options.orderedList!==!1&&e.push($Z.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push(aQ.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(cQ.configure(this.options.strike)),this.options.text!==!1&&e.push(lQ.configure(this.options.text)),this.options.underline!==!1&&e.push(uQ.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push($Q.configure(this.options?.trailingNode)),e}}),n$=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,r$=cq.create({name:`image`,addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?`inline`:`block`},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?`img[src]`:`img[src]:not([src^="data:"])`}]},renderHTML({HTMLAttributes:e}){return[`img`,rG(this.options.HTMLAttributes,e)]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title,alt:e.text}),renderMarkdown:e=>{let t=e.attrs?.src??``,n=e.attrs?.alt??``,r=e.attrs?.title??``;return r?`![${n}](${t} "${r}")`:`![${n}](${t})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>`u`)return null;let{directions:e,minWidth:t,minHeight:n,alwaysPreserveAspectRatio:r}=this.options.resize;return({node:i,getPos:a,HTMLAttributes:o,editor:s})=>{let c=document.createElement(`img`);Object.entries(o).forEach(([e,t])=>{if(t!=null)switch(e){case`width`:case`height`:break;default:c.setAttribute(e,t);break}}),c.src=o.src;let l=new qK({element:c,editor:s,node:i,getPos:a,onResize:(e,t)=>{c.style.width=`${e}px`,c.style.height=`${t}px`},onCommit:(e,t)=>{let n=a();n!==void 0&&this.editor.chain().setNodeSelection(n).updateAttributes(this.name,{width:e,height:t}).run()},onUpdate:(e,t,n)=>e.type===i.type,options:{directions:e,min:{width:t,height:n},preserveAspectRatio:r===!0}}),u=l.dom;return u.style.visibility=`hidden`,u.style.pointerEvents=`none`,c.onload=()=>{u.style.visibility=``,u.style.pointerEvents=``},l}},addCommands(){return{setImage:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[UK({find:n$,type:this.type,getAttributes:e=>{let[,,t,n,r]=e;return{src:n,alt:t,title:r}}})]}});function i$({onClick:e,active:t,disabled:n,title:r,children:i}){return(0,H.jsx)(`button`,{type:`button`,title:r,disabled:n,onMouseDown:t=>{t.preventDefault(),e()},className:K(`flex size-7 items-center justify-center rounded transition-colors`,t?`bg-foreground text-background`:`text-muted-foreground hover:bg-accent hover:text-accent-foreground`,n&&`pointer-events-none opacity-40`),children:i})}function a$(){return(0,H.jsx)(`div`,{className:`mx-0.5 h-4 w-px bg-border`})}function o$(e,t){return!e||!t?null:`${e} × ${t}`}function s$(e){try{let t=new URL(e).pathname.split(`/`).filter(Boolean);return t[t.length-1]||`Image`}catch{let t=e.split(`?`)[0].split(`/`).filter(Boolean);return t[t.length-1]||`Image`}}async function c$(e,t){if(!(await fetch(`/cms/admin/media/${e}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({caption:t})})).ok)throw Error(`Could not update media caption.`)}function l$({node:e,deleteNode:t,selected:n,updateAttributes:r,editor:i}){let a=String(e.attrs.src??``),o=typeof e.attrs.mediaId==`string`?e.attrs.mediaId:null,s=typeof e.attrs.filename==`string`?e.attrs.filename:null,c=typeof e.attrs.alt==`string`?e.attrs.alt:null,l=typeof e.attrs.title==`string`?e.attrs.title:null,u=typeof e.attrs.width==`number`?e.attrs.width:null,d=typeof e.attrs.height==`number`?e.attrs.height:null,f=s||s$(a),p=o$(u,d),[m,h]=(0,v.useState)(l??``),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)(!1),x=i.isEditable;(0,v.useEffect)(()=>{h(l??``)},[l]);async function S(){let e=m.trim()||null;if(e===(l?.trim()||null)){_(null);return}if(r({title:e}),_(null),o){b(!0);try{await c$(o,e)}catch(e){_(e instanceof Error?e.message:`Could not update media caption.`)}finally{b(!1)}}}return(0,H.jsx)(DJ,{className:K(`my-3`,`rounded-xl border bg-card shadow-xs transition-colors`,n?`border-primary ring-2 ring-primary/20`:`border-border`),contentEditable:!1,"data-drag-handle":!0,children:(0,H.jsxs)(`div`,{className:`flex items-start gap-3 p-3`,children:[(0,H.jsx)(`div`,{className:`size-18 shrink-0 overflow-hidden rounded-lg border bg-muted`,children:(0,H.jsx)(`img`,{src:a,alt:c??f,className:`h-full w-full object-cover`})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,H.jsx)(`p`,{className:`truncate text-sm font-medium text-foreground`,title:f,children:f}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[p&&(0,H.jsx)(`span`,{children:p}),c&&(0,H.jsxs)(`span`,{className:`truncate`,title:c,children:[`Alt: `,c]})]}),(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(zP,{value:m,onChange:e=>h(e.target.value),onBlur:S,placeholder:`Figcaption...`,disabled:!x,className:`min-h-8 resize-none border-0 bg-muted/60 px-2.5 py-1.5 text-xs text-muted-foreground shadow-none focus-visible:ring-1`}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:[(0,H.jsx)(`span`,{children:o?`Synced with Media Library`:`Local to this entry`}),y&&(0,H.jsx)(`span`,{children:`Saving…`})]}),g&&(0,H.jsx)(`p`,{className:`text-[11px] text-destructive`,children:g})]})]}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>t(),className:`flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive`,"aria-label":`Remove image`,children:(0,H.jsx)(es,{className:`size-4`})})]})})}function u$({value:e,onChange:t,placeholder:n,onInsertImage:r}){let[i,a]=(0,v.useState)(!e),o=CJ({extensions:[t$.configure({link:{openOnClick:!1,HTMLAttributes:{class:`text-primary underline`}}}),r$.extend({addAttributes(){return{...this.parent?.(),mediaId:{default:null},filename:{default:null},width:{default:null},height:{default:null}}},addNodeView(){return FJ(l$)}}).configure({inline:!1})],content:(()=>{if(!e)return``;try{return JSON.parse(e)}catch{return e}})(),editorProps:{attributes:{class:`h-128 px-3 py-2.5 focus:outline-none`}},onUpdate({editor:e}){a(e.isEmpty),t(JSON.stringify(e.getJSON()))}});(0,v.useEffect)(()=>{if(!o)return;let t=e?(()=>{try{return JSON.parse(e)}catch{return e}})():``;JSON.stringify(o.getJSON())!==e&&o.commands.setContent(t,{emitUpdate:!1}),a(o.isEmpty)},[e]);async function s(){if(!o||!r)return;let e=await r();if(!e||e.length===0)return;let t=e.map(e=>({type:`image`,attrs:{mediaId:e.id??void 0,src:e.src,filename:e.filename??void 0,alt:e.alt??void 0,title:e.title??void 0,width:e.width??void 0,height:e.height??void 0}}));o.chain().focus().insertContent(t).run()}function c(){if(!o)return;let e=o.getAttributes(`link`).href,t=window.prompt(`URL`,e??`https://`);if(t!==null){if(!t){o.chain().focus().unsetLink().run();return}o.chain().focus().setLink({href:t}).run()}}return o?(0,H.jsxs)(`div`,{className:`overflow-hidden rounded-md border border-input bg-background focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50`,children:[(0,H.jsxs)(`div`,{className:`sticky top-0 z-10 flex flex-wrap items-center gap-0.5 border-b border-border bg-background px-2 py-1.5`,children:[(0,H.jsx)(i$,{title:`Bold`,active:o.isActive(`bold`),onClick:()=>o.chain().focus().toggleBold().run(),children:(0,H.jsx)(Ra,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Italic`,active:o.isActive(`italic`),onClick:()=>o.chain().focus().toggleItalic().run(),children:(0,H.jsx)(Co,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Underline`,active:o.isActive(`underline`),onClick:()=>o.chain().focus().toggleUnderline().run(),children:(0,H.jsx)(rs,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Strikethrough`,active:o.isActive(`strike`),onClick:()=>o.chain().focus().toggleStrike().run(),children:(0,H.jsx)(Xo,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),(0,H.jsx)(i$,{title:`Heading 1`,active:o.isActive(`heading`,{level:1}),onClick:()=>o.chain().focus().toggleHeading({level:1}).run(),children:(0,H.jsx)(_o,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Heading 2`,active:o.isActive(`heading`,{level:2}),onClick:()=>o.chain().focus().toggleHeading({level:2}).run(),children:(0,H.jsx)(vo,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Heading 3`,active:o.isActive(`heading`,{level:3}),onClick:()=>o.chain().focus().toggleHeading({level:3}).run(),children:(0,H.jsx)(yo,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),(0,H.jsx)(i$,{title:`Bullet list`,active:o.isActive(`bulletList`),onClick:()=>o.chain().focus().toggleBulletList().run(),children:(0,H.jsx)(Mo,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Ordered list`,active:o.isActive(`orderedList`),onClick:()=>o.chain().focus().toggleOrderedList().run(),children:(0,H.jsx)(Ao,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),(0,H.jsx)(i$,{title:`Blockquote`,active:o.isActive(`blockquote`),onClick:()=>o.chain().focus().toggleBlockquote().run(),children:(0,H.jsx)(Ho,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Inline code`,active:o.isActive(`code`),onClick:()=>o.chain().focus().toggleCode().run(),children:(0,H.jsx)($a,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Code block`,active:o.isActive(`codeBlock`),onClick:()=>o.chain().focus().toggleCodeBlock().run(),children:(0,H.jsx)(Jo,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),(0,H.jsx)(i$,{title:`Add link`,active:o.isActive(`link`),onClick:c,children:(0,H.jsx)(ko,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Remove link`,disabled:!o.isActive(`link`),onClick:()=>o.chain().focus().unsetLink().run(),children:(0,H.jsx)(is,{className:`size-3.5`})}),(0,H.jsx)(a$,{}),r&&(0,H.jsx)(i$,{title:`Insert image`,onClick:s,children:(0,H.jsx)(xo,{className:`size-3.5`})}),(0,H.jsx)(i$,{title:`Hard break (Shift + Enter)`,onClick:()=>o.chain().focus().setHardBreak().run(),children:(0,H.jsx)(Qo,{className:`size-3.5`})})]}),(0,H.jsxs)(`div`,{className:`relative overflow-y-auto`,children:[i&&n&&(0,H.jsx)(`p`,{className:`pointer-events-none absolute left-3 top-2.5 text-muted-foreground select-none`,children:n}),(0,H.jsx)(hJ,{editor:o})]})]}):null}function d$(e){return{...e}}function f$(e){return e.type.startsWith(`image/`)?new Promise(t=>{let n=new Image,r=URL.createObjectURL(e);n.onload=()=>{URL.revokeObjectURL(r),t({width:n.naturalWidth,height:n.naturalHeight})},n.onerror=()=>{URL.revokeObjectURL(r),t(null)},n.src=r}):Promise.resolve(null)}async function p$(e,t){let n=await f$(e),r=await fetch(`/cms/admin/media/presign`,{method:`POST`,credentials:`include`,headers:d$({"Content-Type":`application/json`}),body:JSON.stringify({filename:e.name,mimeType:e.type,folderId:t?.folderId??null})});if(!r.ok)throw Error(`Upload failed.`);let i=await r.json();if(i.mode===`presigned`){if(!(await fetch(i.uploadUrl,{method:`PUT`,body:e,headers:{"Content-Type":e.type}})).ok)throw Error(`Upload failed.`);let r=await fetch(`/cms/admin/media/confirm`,{method:`POST`,credentials:`include`,headers:d$({"Content-Type":`application/json`}),body:JSON.stringify({key:i.key,filename:e.name,mimeType:e.type,size:e.size,folderId:t?.folderId??null,width:n?.width??null,height:n?.height??null})});if(!r.ok)throw Error(`Upload failed.`);return r.json()}let a=new FormData;a.append(`files`,e,e.name),t?.folderId&&a.append(`folder_id`,t.folderId),n?.width&&a.append(`width`,String(n.width)),n?.height&&a.append(`height`,String(n.height));let o=await fetch(`/cms/admin/media`,{method:`POST`,credentials:`include`,headers:d$(),body:a});if(!o.ok)throw Error(`Upload failed.`);return o.json()}async function m$(e){let t=await fetch(`/cms/admin/users/me/avatar/presign`,{method:`POST`,credentials:`include`,headers:d$({"Content-Type":`application/json`}),body:JSON.stringify({filename:e.name,mimeType:e.type})});if(!t.ok)throw Error(`Upload failed.`);let n=await t.json();if(n.mode===`presigned`){if(!(await fetch(n.uploadUrl,{method:`PUT`,body:e,headers:{"Content-Type":e.type}})).ok)throw Error(`Upload failed.`);let t=await fetch(`/cms/admin/users/me/avatar/confirm`,{method:`POST`,credentials:`include`,headers:d$({"Content-Type":`application/json`}),body:JSON.stringify({key:n.key})});if(!t.ok)throw Error(`Upload failed.`);return(await t.json()).avatarUrl}let r=new FormData;r.append(`file`,e);let i=await fetch(`/cms/admin/users/me/avatar`,{method:`POST`,credentials:`include`,headers:d$(),body:r});if(!i.ok)throw Error(`Upload failed.`);return(await i.json()).avatarUrl}var h$=1,g$=.9,_$=.8,v$=.17,y$=.1,b$=.999,x$=.9999,S$=.99,C$=/[\\\/_+.#"@\[\(\{&]/,w$=/[\\\/_+.#"@\[\(\{&]/g,T$=/[\s-]/,E$=/[\s-]/g;function D$(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?h$:S$;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=D$(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=h$:C$.test(e.charAt(l-1))?(d*=_$,p=e.slice(i,l-1).match(w$),p&&i>0&&(d*=b$**+p.length)):T$.test(e.charAt(l-1))?(d*=g$,m=e.slice(i,l-1).match(E$),m&&i>0&&(d*=b$**+m.length)):(d*=v$,i>0&&(d*=b$**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=x$)),(d<y$&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=D$(e,t,n,r,l+1,a+2,o),f*y$>d&&(d=f*y$)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function O$(e){return e.toLowerCase().replace(E$,` `)}function k$(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,D$(e,t,O$(e),O$(t),0,0,{})}var A$=`[cmdk-group=""]`,j$=`[cmdk-group-items=""]`,M$=`[cmdk-group-heading=""]`,N$=`[cmdk-item=""]`,P$=`${N$}:not([aria-disabled="true"])`,F$=`cmdk-item-select`,I$=`data-value`,L$=(e,t,n)=>k$(e,t,n),R$=v.createContext(void 0),z$=()=>v.useContext(R$),B$=v.createContext(void 0),V$=()=>v.useContext(B$),H$=v.createContext(void 0),U$=v.forwardRef((e,t)=>{let n=r1(()=>({search:``,value:e.value??e.defaultValue??``,selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),r=r1(()=>new Set),i=r1(()=>new Map),a=r1(()=>new Map),o=r1(()=>new Set),s=t1(e),{label:c,children:l,value:u,onValueChange:d,filter:f,shouldFilter:p,loop:m,disablePointerSelection:h=!1,vimBindings:g=!0,..._}=e,y=md(),b=md(),x=md(),S=v.useRef(null),C=o1();n1(()=>{if(u!==void 0){let e=u.trim();n.current.value=e,w.emit()}},[u]),n1(()=>{C(6,A)},[]);let w=v.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,a,o;if(!Object.is(n.current[e],t)){if(n.current[e]=t,e===`search`)k(),D(),C(1,O);else if(e===`value`){if(document.activeElement.hasAttribute(`cmdk-input`)||document.activeElement.hasAttribute(`cmdk-root`)){let e=document.getElementById(x);e?e.focus():(i=document.getElementById(y))==null||i.focus()}if(C(7,()=>{n.current.selectedItemId=j()?.id,w.emit()}),r||C(5,A),s.current?.value!==void 0){let e=t??``;(o=(a=s.current).onValueChange)==null||o.call(a,e);return}}w.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),T=v.useMemo(()=>({value:(e,t,r)=>{t!==a.current.get(e)?.value&&(a.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,E(t,r)),C(2,()=>{D(),w.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),C(3,()=>{k(),D(),n.current.value||O(),w.emit()}),()=>{a.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=j();C(4,()=>{k(),t?.getAttribute(`id`)===e&&O(),w.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{a.current.delete(e),i.current.delete(e)}),filter:()=>s.current.shouldFilter,label:c||e[`aria-label`],getDisablePointerSelection:()=>s.current.disablePointerSelection,listId:y,inputId:x,labelId:b,listInnerRef:S}),[]);function E(e,t){let r=s.current?.filter??L$;return e?r(e,n.current.search,t):0}function D(){if(!n.current.search||s.current.shouldFilter===!1)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),a=0;r.forEach(t=>{let n=e.get(t);a=Math.max(n,a)}),t.push([n,a])});let r=S.current;M().sort((t,n)=>{let r=t.getAttribute(`id`),i=n.getAttribute(`id`);return(e.get(i)??0)-(e.get(r)??0)}).forEach(e=>{let t=e.closest(j$);t?t.appendChild(e.parentElement===t?e:e.closest(`${j$} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${j$} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{let t=S.current?.querySelector(`${A$}[${I$}="${encodeURIComponent(e[0])}"]`);t?.parentElement.appendChild(t)})}function O(){let e=M().find(e=>e.getAttribute(`aria-disabled`)!==`true`)?.getAttribute(I$);w.setState(`value`,e||void 0)}function k(){if(!n.current.search||s.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let e=0;for(let t of r.current){let r=E(a.current.get(t)?.value??``,a.current.get(t)?.keywords??[]);n.current.filtered.items.set(t,r),r>0&&e++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=e}function A(){var e;let t=j();t&&(t.parentElement?.firstChild===t&&((e=t.closest(A$)?.querySelector(M$))==null||e.scrollIntoView({block:`nearest`})),t.scrollIntoView({block:`nearest`}))}function j(){return S.current?.querySelector(`${N$}[aria-selected="true"]`)}function M(){return Array.from(S.current?.querySelectorAll(P$)||[])}function N(e){let t=M()[e];t&&w.setState(`value`,t.getAttribute(I$))}function P(e){var t;let n=j(),r=M(),i=r.findIndex(e=>e===n),a=r[i+e];(t=s.current)!=null&&t.loop&&(a=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),a&&w.setState(`value`,a.getAttribute(I$))}function F(e){let t=j()?.closest(A$),n;for(;t&&!n;)t=e>0?$$(t,A$):e1(t,A$),n=t?.querySelector(P$);n?w.setState(`value`,n.getAttribute(I$)):P(e)}let I=()=>N(M().length-1),L=e=>{e.preventDefault(),e.metaKey?I():e.altKey?F(1):P(1)},R=e=>{e.preventDefault(),e.metaKey?N(0):e.altKey?F(-1):P(-1)};return v.createElement(cl.div,{ref:t,tabIndex:-1,..._,"cmdk-root":``,onKeyDown:e=>{var t;(t=_.onKeyDown)==null||t.call(_,e);let n=e.nativeEvent.isComposing||e.keyCode===229;if(!(e.defaultPrevented||n))switch(e.key){case`n`:case`j`:g&&e.ctrlKey&&L(e);break;case`ArrowDown`:L(e);break;case`p`:case`k`:g&&e.ctrlKey&&R(e);break;case`ArrowUp`:R(e);break;case`Home`:e.preventDefault(),N(0);break;case`End`:e.preventDefault(),I();break;case`Enter`:{e.preventDefault();let t=j();if(t){let e=new Event(F$);t.dispatchEvent(e)}}}}},v.createElement(`label`,{"cmdk-label":``,htmlFor:T.inputId,id:T.labelId,style:l1},c),c1(e,e=>v.createElement(B$.Provider,{value:w},v.createElement(R$.Provider,{value:T},e))))}),W$=v.forwardRef((e,t)=>{let n=md(),r=v.useRef(null),i=v.useContext(H$),a=z$(),o=t1(e),s=o.current?.forceMount??i?.forceMount;n1(()=>{if(!s)return a.item(n,i?.id)},[s]);let c=a1(n,r,[e.value,e.children,r],e.keywords),l=V$(),u=i1(e=>e.value&&e.value===c.current),d=i1(e=>s||a.filter()===!1?!0:e.search?e.filtered.items.get(n)>0:!0);v.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(F$,f),()=>t.removeEventListener(F$,f)},[d,e.onSelect,e.disabled]);function f(){var e,t;p(),(t=(e=o.current).onSelect)==null||t.call(e,c.current)}function p(){l.setState(`value`,c.current,!0)}if(!d)return null;let{disabled:m,value:h,onSelect:g,forceMount:_,keywords:y,...b}=e;return v.createElement(cl.div,{ref:hs(r,t),...b,id:n,"cmdk-item":``,role:`option`,"aria-disabled":!!m,"aria-selected":!!u,"data-disabled":!!m,"data-selected":!!u,onPointerMove:m||a.getDisablePointerSelection()?void 0:p,onClick:m?void 0:f},e.children)}),G$=v.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...a}=e,o=md(),s=v.useRef(null),c=v.useRef(null),l=md(),u=z$(),d=i1(e=>i||u.filter()===!1?!0:e.search?e.filtered.groups.has(o):!0);n1(()=>u.group(o),[]),a1(o,s,[e.value,e.heading,c]);let f=v.useMemo(()=>({id:o,forceMount:i}),[i]);return v.createElement(cl.div,{ref:hs(s,t),...a,"cmdk-group":``,role:`presentation`,hidden:d?void 0:!0},n&&v.createElement(`div`,{ref:c,"cmdk-group-heading":``,"aria-hidden":!0,id:l},n),c1(e,e=>v.createElement(`div`,{"cmdk-group-items":``,role:`group`,"aria-labelledby":n?l:void 0},v.createElement(H$.Provider,{value:f},e))))}),K$=v.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=v.useRef(null),a=i1(e=>!e.search);return!n&&!a?null:v.createElement(cl.div,{ref:hs(i,t),...r,"cmdk-separator":``,role:`separator`})}),q$=v.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=e.value!=null,a=V$(),o=i1(e=>e.search),s=i1(e=>e.selectedItemId),c=z$();return v.useEffect(()=>{e.value!=null&&a.setState(`search`,e.value)},[e.value]),v.createElement(cl.input,{ref:t,...r,"cmdk-input":``,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,"aria-autocomplete":`list`,role:`combobox`,"aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":s,id:c.inputId,type:`text`,value:i?e.value:o,onChange:e=>{i||a.setState(`search`,e.target.value),n?.(e.target.value)}})}),J$=v.forwardRef((e,t)=>{let{children:n,label:r=`Suggestions`,...i}=e,a=v.useRef(null),o=v.useRef(null),s=i1(e=>e.selectedItemId),c=z$();return v.useEffect(()=>{if(o.current&&a.current){let e=o.current,t=a.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty(`--cmdk-list-height`,n.toFixed(1)+`px`)})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),v.createElement(cl.div,{ref:hs(a,t),...i,"cmdk-list":``,role:`listbox`,tabIndex:-1,"aria-activedescendant":s,"aria-label":r,id:c.listId},c1(e,e=>v.createElement(`div`,{ref:hs(o,c.listInnerRef),"cmdk-list-sizer":``},e)))}),Y$=v.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:a,container:o,...s}=e;return v.createElement(dy,{open:n,onOpenChange:r},v.createElement(fy,{container:o},v.createElement(py,{"cmdk-overlay":``,className:i}),v.createElement(my,{"aria-label":e.label,"cmdk-dialog":``,className:a},v.createElement(U$,{ref:t,...s}))))}),X$=v.forwardRef((e,t)=>i1(e=>e.filtered.count===0)?v.createElement(cl.div,{ref:t,...e,"cmdk-empty":``,role:`presentation`}):null),Z$=v.forwardRef((e,t)=>{let{progress:n,children:r,label:i=`Loading...`,...a}=e;return v.createElement(cl.div,{ref:t,...a,"cmdk-loading":``,role:`progressbar`,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},c1(e,e=>v.createElement(`div`,{"aria-hidden":!0},e)))}),Q$=Object.assign(U$,{List:J$,Item:W$,Input:q$,Group:G$,Separator:K$,Dialog:Y$,Empty:X$,Loading:Z$});function $$(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function e1(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function t1(e){let t=v.useRef(e);return n1(()=>{t.current=e}),t}var n1=typeof window>`u`?v.useEffect:v.useLayoutEffect;function r1(e){let t=v.useRef();return t.current===void 0&&(t.current=e()),t}function i1(e){let t=V$(),n=()=>e(t.snapshot());return v.useSyncExternalStore(t.subscribe,n,n)}function a1(e,t,n,r=[]){let i=v.useRef(),a=z$();return n1(()=>{var o;let s=(()=>{for(let e of n){if(typeof e==`string`)return e.trim();if(typeof e==`object`&&`current`in e)return e.current?e.current.textContent?.trim():i.current}})(),c=r.map(e=>e.trim());a.value(e,s,c),(o=t.current)==null||o.setAttribute(I$,s),i.current=s}),i}var o1=()=>{let[e,t]=v.useState(),n=r1(()=>new Map);return n1(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function s1(e){let t=e.type;return typeof t==`function`?t(e.props):`render`in t?t.render(e.props):e}function c1({asChild:e,children:t},n){return e&&v.isValidElement(t)?v.cloneElement(s1(t),{ref:t.ref},n(t.props.children)):n(t)}var l1={position:`absolute`,width:`1px`,height:`1px`,padding:`0`,margin:`-1px`,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,borderWidth:`0`},u1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$,{ref:n,className:K(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...t}));u1.displayName=Q$.displayName;var d1=v.forwardRef(({className:e,...t},n)=>(0,H.jsxs)(`div`,{className:`flex items-center border-b px-3`,"data-cmdk-input-wrapper":``,children:[(0,H.jsx)(Go,{className:`mr-2 h-4 w-4 shrink-0 opacity-50`}),(0,H.jsx)(Q$.Input,{ref:n,className:K(`flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,e),...t})]}));d1.displayName=Q$.Input.displayName;var f1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$.List,{ref:n,className:K(`max-h-[300px] overflow-y-auto overflow-x-hidden`,e),...t}));f1.displayName=Q$.List.displayName;var p1=v.forwardRef((e,t)=>(0,H.jsx)(Q$.Empty,{ref:t,className:`py-6 text-center text-sm`,...e}));p1.displayName=Q$.Empty.displayName;var m1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$.Group,{ref:n,className:K(`overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground`,e),...t}));m1.displayName=Q$.Group.displayName;var h1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$.Separator,{ref:n,className:K(`-mx-1 h-px bg-border`,e),...t}));h1.displayName=Q$.Separator.displayName;var g1=v.forwardRef(({className:e,...t},n)=>(0,H.jsx)(Q$.Item,{ref:n,className:K(`relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,e),...t}));g1.displayName=Q$.Item.displayName;var _1=({className:e,...t})=>(0,H.jsx)(`span`,{className:K(`ml-auto text-xs tracking-widest text-muted-foreground`,e),...t});_1.displayName=`CommandShortcut`;var v1={image:`image/*`,video:`video/*`,audio:`audio/*`,document:`.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.csv`};function y1(e){return!e||e.length===0?`*/*`:e.map(e=>v1[e]).join(`,`)}function b1(e){let t=e.replace(/_/g,` `).trim();return t?t.charAt(0).toUpperCase()+t.slice(1):`Value`}function x1(e){return e?e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`:`—`}function S1(e){return e?.startsWith(`image/`)??!1}async function C1(e,t){return p$(e,{folderId:t})}function w1(e,t){if(!t||t.length===0)return!0;let n=e??``;return t.some(e=>e===`image`?n.startsWith(`image/`):e===`video`?n.startsWith(`video/`):e===`audio`?n.startsWith(`audio/`):e===`document`?n.startsWith(`application/`)||n.startsWith(`text/`):!1)}var T1=30;function E1({open:e,onOpenChange:t,allowedTypes:n,selectionMode:r=`single`,onSelect:i}){let[a,o]=(0,v.useState)([{id:null,name:`Media`}]),s=a[a.length-1].id,[c,l]=(0,v.useState)([]),[u,d]=(0,v.useState)([]),[f,p]=(0,v.useState)(1),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(1),[y,b]=(0,v.useState)(``),[x,S]=(0,v.useState)(``),[C,w]=(0,v.useState)([]);(0,v.useEffect)(()=>{let e=setTimeout(()=>{S(y),_(1)},300);return()=>clearTimeout(e)},[y]),(0,v.useEffect)(()=>{_(1),b(``),S(``)},[s]),(0,v.useEffect)(()=>{if(!e)return;h(!0);let t=s??``,n=x?`&search=${encodeURIComponent(x)}`:``;Promise.all([x?Promise.resolve([]):fetch(`/cms/admin/folders?parent_id=${t}`,{credentials:`include`}).then(e=>e.ok?e.json():{folders:[]}).then(e=>e.folders),fetch(`/cms/admin/media?folder_id=${t}&page=${g}&limit=${T1}${n}`,{credentials:`include`}).then(e=>e.ok?e.json():{items:[],pages:1})]).then(([e,t])=>{l(e),d(t.items),p(t.pages??1)}).catch(()=>{l([]),d([]),p(1)}).finally(()=>h(!1))},[e,s,g,x]),(0,v.useEffect)(()=>{e||(o([{id:null,name:`Media`}]),_(1),b(``),S(``),w([]))},[e]);function T(e){o(t=>[...t,{id:e.id,name:e.name}])}function E(e){o(t=>t.slice(0,e+1))}function D(e){if(r===`single`){i([e]),t(!1);return}w(t=>t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):[...t,e])}function O(e){let t=C.findIndex(t=>t.id===e);return t===-1?null:t+1}let k=u.filter(e=>w1(e.mime_type,n)),A=c.length===0&&k.length===0;return(0,H.jsx)(vy,{open:e,onOpenChange:t,children:(0,H.jsxs)(Sy,{className:`max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Media Library`})}),(0,H.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,H.jsx)(Go,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground pointer-events-none`}),(0,H.jsx)(J,{className:`pl-9 h-8`,placeholder:`Search media…`,value:y,onChange:e=>b(e.target.value)})]}),!x&&a.length>1&&(0,H.jsx)(`div`,{className:`flex items-center gap-1 text-sm shrink-0`,children:a.map((e,t)=>(0,H.jsxs)(`span`,{className:`flex items-center gap-1 text-muted-foreground`,children:[t>0&&(0,H.jsx)(`span`,{children:`/`}),t===a.length-1?(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:t===0?(0,H.jsx)(bo,{className:`size-3.5`}):e.name}):(0,H.jsx)(`button`,{onClick:()=>E(t),className:`hover:text-foreground transition-colors`,children:t===0?(0,H.jsx)(bo,{className:`size-3.5`}):e.name})]},`${e.id??`root`}:${e.name}`))}),m?(0,H.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-16`,children:(0,H.jsx)(ex,{className:`size-5`})}):A?(0,H.jsx)(`p`,{className:`flex-1 py-16 text-center text-sm text-muted-foreground`,children:x?`No matching files.`:u.length===0&&c.length===0?`No media found.`:`No matching files in this folder.`}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-0 overflow-y-auto pr-1`,children:[c.length>0&&(0,H.jsx)(`div`,{className:`grid grid-cols-1 gap-1.5 sm:grid-cols-2`,children:c.map(e=>(0,H.jsxs)(`button`,{type:`button`,onClick:()=>T(e),className:`flex items-center gap-2.5 rounded-md border bg-card px-2.5 py-2 text-left transition-colors hover:bg-muted/50 hover:border-primary`,children:[(0,H.jsx)(mo,{className:`size-7 shrink-0 text-muted-foreground`}),(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`p`,{className:`truncate text-xs font-bold leading-tight`,title:e.name,children:e.name}),(0,H.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[e.item_count,` `,e.item_count===1?`item`:`items`]})]})]},e.id))}),k.length>0&&(0,H.jsx)(`div`,{className:`grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-5`,children:k.map(e=>(0,H.jsxs)(`button`,{type:`button`,onClick:()=>D(e),className:K(`group relative overflow-hidden rounded-md border bg-card text-left transition-colors hover:border-primary`,O(e.id)!=null&&`border-primary ring-2 ring-primary/20`),children:[(0,H.jsx)(`div`,{className:`aspect-square bg-muted`,children:S1(e.mime_type)?(0,H.jsx)(`img`,{src:e.url,alt:e.filename,className:`h-full w-full object-cover`}):(0,H.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,H.jsx)(lo,{className:`size-6 text-muted-foreground`})})}),(0,H.jsxs)(`div`,{className:`p-1.5`,children:[(0,H.jsx)(`p`,{className:`truncate text-[11px] font-medium leading-tight`,title:e.filename,children:e.filename}),(0,H.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:x1(e.size)})]}),(0,H.jsx)(`div`,{className:K(`absolute inset-0 rounded-md ring-2 ring-primary ring-offset-1 transition-opacity pointer-events-none`,O(e.id)==null?`opacity-0 group-hover:opacity-100`:`opacity-100`)}),r===`multiple`&&O(e.id)!=null&&(0,H.jsx)(`div`,{className:`absolute right-1.5 top-1.5 flex size-6 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground shadow-sm`,children:O(e.id)})]},e.id))})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t pt-2 shrink-0`,children:[(0,H.jsx)(`div`,{className:`flex items-center gap-2`,children:r===`multiple`&&C.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[C.length,` selected`]}),(0,H.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 px-2 text-xs`,onClick:()=>w([]),children:`Clear`})]})}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[f>1&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`button`,{type:`button`,onClick:()=>_(e=>Math.max(1,e-1)),disabled:g===1,className:`text-sm text-muted-foreground hover:text-foreground disabled:opacity-40 disabled:pointer-events-none transition-colors`,children:`Previous`}),(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[g,` / `,f]}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>_(e=>Math.min(f,e+1)),disabled:g===f,className:`text-sm text-muted-foreground hover:text-foreground disabled:opacity-40 disabled:pointer-events-none transition-colors`,children:`Next`})]}),r===`multiple`&&(0,H.jsx)(q,{type:`button`,size:`sm`,disabled:C.length===0,onClick:()=>{i(C),t(!1)},children:`Insert selected`})]})]})]})})}function D1({value:e,onChange:t,allowedTypes:n,disabled:r=!1}){let i=(0,v.useRef)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(!1),p=typeof e==`string`&&e.startsWith(`http`);(0,v.useEffect)(()=>{if(!e){u(null);return}if(p){u(e);return}fetch(`/cms/admin/media/${e}/url`,{credentials:`include`}).then(e=>e.ok?e.json():null).then(e=>u(e?.url??null)).catch(()=>u(null))},[e,p]);async function m(e){o(!0),c(null);try{let n=await C1(e);u(n.url),t(n.id)}catch(e){c(e instanceof Error?e.message:`Upload failed.`),X.error(`Upload failed`)}finally{o(!1),i.current&&(i.current.value=``)}}let h=l&&/\.(jpe?g|png|gif|webp|avif|svg)(\?|$)/i.test(l);return e?(0,H.jsxs)(`div`,{className:`relative w-full rounded-md border bg-muted/30 overflow-hidden`,children:[l?h?(0,H.jsx)(`img`,{src:l,alt:`Media`,className:`max-h-72 w-full object-contain`}):(0,H.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,H.jsx)(xo,{className:`size-4 text-muted-foreground shrink-0`}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:l})]}):(0,H.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-muted-foreground`,children:[(0,H.jsx)(xo,{className:`size-4 shrink-0`}),(0,H.jsx)(`span`,{className:`text-xs`,children:`Loading…`})]}),(0,H.jsx)(q,{type:`button`,size:`icon`,variant:`secondary`,className:`absolute top-1.5 right-1.5 size-6`,onClick:()=>{t(null),u(null)},disabled:r,children:(0,H.jsx)(us,{className:`size-3.5`})})]}):(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`input`,{ref:i,type:`file`,accept:y1(n),className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&m(t)}}),(0,H.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{if(r)return;e.preventDefault();let t=e.dataTransfer.files[0];t&&m(t)},className:`flex w-full gap-2 rounded-md border border-dashed p-3`,children:[(0,H.jsxs)(`button`,{type:`button`,disabled:a||r,onClick:()=>i.current?.click(),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(as,{className:`size-4`}),a?`Uploading…`:`Upload`]}),(0,H.jsx)(`div`,{className:`w-px bg-border`}),(0,H.jsxs)(`button`,{type:`button`,disabled:a||r,onClick:()=>f(!0),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(fo,{className:`size-4`}),`Library`]})]}),s&&(0,H.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:s}),(0,H.jsx)(E1,{open:d,onOpenChange:f,allowedTypes:n,selectionMode:`single`,onSelect:e=>{let n=e[0];n&&(u(n.url),t(n.id))}})]})}function O1({id:e,previewUrl:t,filename:n,onRemove:r,disabled:i=!1}){let{attributes:a,listeners:o,setNodeRef:s,transform:c,transition:l,isDragging:u}=ok({id:e});return(0,H.jsxs)(`div`,{ref:s,style:{transform:yE.Transform.toString(c),transition:l,opacity:u?.4:1},className:`relative aspect-square overflow-hidden rounded-md border bg-muted`,children:[t?(0,H.jsx)(`img`,{src:t,alt:n,className:`h-full w-full object-cover`}):(0,H.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,H.jsx)(xo,{className:`size-5 text-muted-foreground`})}),n&&(0,H.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 bg-background/75 backdrop-blur-sm px-1.5 py-1 pointer-events-none`,children:(0,H.jsx)(`p`,{className:`truncate text-[10px] leading-none text-foreground`,children:n})}),(0,H.jsx)(`button`,{type:`button`,onClick:r,disabled:i,className:`absolute right-1 top-1 flex size-5 items-center justify-center rounded-full bg-background/80 text-foreground shadow-sm hover:bg-background`,children:(0,H.jsx)(us,{className:`size-3`})}),!i&&(0,H.jsx)(`button`,{type:`button`,className:`absolute bottom-6 left-1 flex size-5 cursor-grab items-center justify-center rounded-full bg-background/80 text-foreground shadow-sm active:cursor-grabbing`,...o,...a,children:(0,H.jsx)(ho,{className:`size-3`})})]})}function k1({value:e,onChange:t,disabled:n=!1}){let r=Array.isArray(e)?e:[],[,i]=(0,v.useState)(0),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(null),[l,u]=(0,v.useState)(!1),d=(0,v.useRef)(null),f=(0,v.useRef)({}),p=(0,v.useRef)({}),m=r.join(`,`),h=FE(PE(FD,{activationConstraint:{distance:5}}));(0,v.useEffect)(()=>{let e=r.filter(e=>!e.startsWith(`http`)&&!(e in f.current));e.length!==0&&Promise.all(e.map(e=>fetch(`/cms/admin/media/${e}/url`,{credentials:`include`}).then(e=>e.ok?e.json():null).then(t=>t?[e,t.url]:null).catch(()=>null))).then(e=>{let t=!1;for(let n of e)n&&(f.current[n[0]]=n[1],t=!0);t&&i(e=>e+1)})},[m]),(0,v.useEffect)(()=>{let e=r.filter(e=>!e.startsWith(`http`)&&!(e in p.current));e.length!==0&&fetch(`/cms/admin/media`,{credentials:`include`}).then(e=>e.ok?e.json():{items:[]}).then(t=>{let n=!1;for(let r of t.items)e.includes(r.id)&&(p.current[r.id]=r.filename,n=!0);n&&i(e=>e+1)}).catch(()=>{})},[m]);function g(e){return e.startsWith(`http`)?e:f.current[e]??null}function _(e){return p.current[e]??``}function y(e){if(n)return;let{active:i,over:a}=e;!a||i.id===a.id||t(VO(r,r.indexOf(i.id),r.indexOf(a.id)))}async function b(e){if(e.length===0)return;o(!0),c(null);let n=r;try{for(let r of e){let e=await C1(r);f.current[e.id]=e.url,p.current[e.id]=r.name,i(e=>e+1),n=[...n,e.id],t(n)}}catch(e){c(e instanceof Error?e.message:`Upload failed.`),X.error(`Upload failed`)}finally{o(!1),d.current&&(d.current.value=``)}}return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`input`,{ref:d,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:e=>{b(Array.from(e.target.files??[]))}}),r.length>0&&(0,H.jsx)(MO,{sensors:h,collisionDetection:HE,onDragEnd:y,children:(0,H.jsx)(QO,{items:r,strategy:KO,children:(0,H.jsx)(`div`,{className:`grid grid-cols-3 gap-2 sm:grid-cols-4`,children:r.map(e=>(0,H.jsx)(O1,{id:e,previewUrl:g(e),filename:_(e),onRemove:()=>t(r.filter(t=>t!==e)),disabled:n},e))})})}),(0,H.jsxs)(`div`,{className:`flex w-full gap-2 rounded-md border border-dashed p-3`,children:[(0,H.jsxs)(`button`,{type:`button`,disabled:a||n,onClick:()=>d.current?.click(),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(as,{className:`size-4`}),a?`Uploading…`:`Upload`]}),(0,H.jsx)(`div`,{className:`w-px bg-border`}),(0,H.jsxs)(`button`,{type:`button`,disabled:a||n,onClick:()=>u(!0),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(fo,{className:`size-4`}),`Library`]})]}),s&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:s}),(0,H.jsx)(E1,{open:l,onOpenChange:u,allowedTypes:[`image`],selectionMode:`multiple`,onSelect:e=>{if(e.length===0)return;let n=new Set(r),i=[...r],a={},o={};for(let t of e)n.has(t.id)||(n.add(t.id),i.push(t.id),a[t.id]=t.url,o[t.id]=t.filename);Object.keys(a).length>0&&setUrlCache(e=>({...e,...a})),Object.keys(o).length>0&&setNameCache(e=>({...e,...o})),i.length!==r.length&&t(i)}})]})}function A1({value:e,onChange:t,disabled:n=!1}){let[r,i]=(0,v.useState)(()=>e!=null&&e!==``?String(e):``);(0,v.useEffect)(()=>{if(e==null||e===``){i(``);return}let t=typeof e==`number`?e:parseFloat(String(e));!isNaN(t)&&t!==parseFloat(r)&&i(String(t))},[e]);function a(e){let n=e.target.value.replace(`,`,`.`);if(i(n),n===``||n===`-`){t(null);return}let r=parseFloat(n);isNaN(r)||t(r)}return(0,H.jsx)(J,{type:`text`,inputMode:`decimal`,className:K(`w-full`,`text-base!`),value:r,placeholder:`0.00`,onChange:a,disabled:n})}function j1(e){if(typeof e==`object`&&e){let t=e;if(t.kind===`string`&&typeof t.value==`string`)return{kind:`string`,value:t.value};if(t.kind===`number`&&typeof t.value==`number`&&!isNaN(t.value))return{kind:`number`,value:t.value};if(t.kind===`boolean`&&typeof t.value==`boolean`)return{kind:`boolean`,value:t.value}}return typeof e==`number`&&!isNaN(e)?{kind:`number`,value:e}:typeof e==`boolean`?{kind:`boolean`,value:e}:{kind:`string`,value:typeof e==`string`?e:``}}function M1({value:e,onChange:t,inputId:n,disabled:r=!1}){let i=j1(e);function a(e){e===`string`&&t({kind:e,value:``}),e===`number`&&t({kind:e,value:0}),e===`boolean`&&t({kind:e,value:!1})}return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-md border border-border p-1`,children:[`string`,`number`,`boolean`].map(e=>(0,H.jsx)(`button`,{type:`button`,disabled:r,onClick:()=>a(e),className:K(`rounded px-2 py-1 text-xs transition-colors`,i.kind===e?`bg-accent text-accent-foreground`:`text-muted-foreground hover:bg-accent/60`),children:e===`string`?`Text`:e===`number`?`Number`:`Boolean`},e))}),i.kind===`string`&&(0,H.jsx)(J,{className:K(`w-full`,`text-base md:text-base`),value:String(i.value),placeholder:`Value`,onChange:e=>t({kind:`string`,value:e.target.value}),disabled:r}),i.kind===`number`&&(0,H.jsx)(A1,{value:i.value,onChange:e=>t({kind:`number`,value:typeof e==`number`&&!isNaN(e)?e:0}),disabled:r}),i.kind===`boolean`&&(0,H.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,H.jsx)(_k,{id:n,checked:!!i.value,onCheckedChange:e=>t({kind:`boolean`,value:!!e}),disabled:r}),(0,H.jsx)(Y,{htmlFor:n,className:`cursor-pointer font-normal text-base`,children:i.value?`True`:`False`})]})]})}function N1({value:e,onChange:t,timezone:n,disabled:r=!1}){let[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(),[c,l]=(0,v.useState)(`00:00`);(0,v.useEffect)(()=>{if(!e){s(void 0),l(`00:00`);return}let t=new Date(e);isNaN(t.getTime())||(s(t),l(ax(e,n)))},[e,n]);function u(e){s(e),a(!1),e&&t(ox(e,c,n))}function d(e){l(e),o&&t(ox(o,e,n))}return(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsxs)(IP,{open:i&&!r,onOpenChange:a,children:[(0,H.jsx)(LP,{asChild:!0,children:(0,H.jsxs)(q,{variant:`outline`,className:`w-40 justify-between font-normal text-base`,disabled:r,children:[o?Vj(o,`MMM d, yyyy`):`Select date`,(0,H.jsx)(Wa,{className:`size-4 opacity-50`})]})}),(0,H.jsx)(RP,{className:`w-auto overflow-hidden p-0`,align:`start`,children:(0,H.jsx)(PP,{mode:`single`,selected:o,captionLayout:`dropdown`,defaultMonth:o,onSelect:u})})]}),(0,H.jsx)(J,{type:`time`,className:`w-32 appearance-none bg-background [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none text-base!`,value:c,onChange:e=>d(e.target.value),disabled:r}),e&&(0,H.jsx)(q,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8 text-muted-foreground hover:text-foreground`,onClick:()=>{s(void 0),l(`00:00`),t(null)},disabled:r,children:(0,H.jsx)(us,{className:`size-3.5`})})]})}function P1(e){return e.find(e=>e.name===`title`)?.name??e.find(e=>e.name===`name`)?.name??e.find(e=>e.type===`uid`)?.name??e.find(e=>e.type===`string`)?.name??e.find(e=>e.type===`text`)?.name??null}var F1={data:null,promise:null};function I1(){return F1.data?Promise.resolve(F1.data):(F1.promise||=fetch(`/cms/admin/content-types`,{credentials:`include`}).then(e=>e.ok?e.json():[]).then(e=>(F1.data=e,e)).catch(()=>[]),F1.promise)}function L1(e,t){return e.find(e=>e.tableName===t)??null}function R1(e,t,n){return fetch(`/cms/admin/content-types/${e}/entries?page=${t}&limit=${n}`,{credentials:`include`}).then(e=>e.ok?e.json():{data:[],total:0,page:t,limit:n}).catch(()=>({data:[],total:0,page:t,limit:n}))}async function z1(e){let t=await R1(e,1,100),n=Math.max(1,Math.ceil(t.total/100));return n===1?{data:t.data}:{data:[t,...await Promise.all(Array.from({length:n-1},(t,n)=>R1(e,n+2,100)))].flatMap(e=>e.data)}}function B1(e){let[t,n]=(0,v.useState)([]),[r,i]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{e&&(i(!0),I1().then(t=>{let n=L1(t,e);return n?z1(n.slug).then(e=>({ctDef:n,res:e})):Promise.resolve({ctDef:null,res:{data:[]}})}).then(({ctDef:e,res:t})=>{let r=e?P1(e.fields??[]):null;n(t.data.map(e=>({id:String(e.id),label:String((r&&e[r])??e.title??e.name??e.id)})))}).catch(()=>n([])).finally(()=>i(!1)))},[e]),{entries:t,loading:r}}function V1(e,t,n){let[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(!1);return(0,v.useEffect)(()=>{if(!e||!n){i([]);return}o(!0),I1().then(t=>{let n=L1(t,e);return n?z1(n.slug).then(e=>({ctDef:n,res:e})):Promise.resolve({ctDef:null,res:{data:[]}})}).then(({ctDef:e,res:r})=>{let a=e?P1(e.fields??[]):null;i(r.data.filter(e=>String(e[t]??``)===n).map(e=>({id:String(e.id),label:String((a&&e[a])??e.title??e.name??e.id)})))}).catch(()=>i([])).finally(()=>o(!1))},[e,t,n]),{entries:r,loading:a}}function H1({relatedTable:e,relatedField:t,currentId:n}){let{entries:r,loading:i}=V1(e,t,n);return n?i?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,H.jsx)(ex,{className:`size-3.5`}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Loading…`})]}):r.length===0?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No linked entries.`}):(0,H.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.map(e=>(0,H.jsx)(`span`,{className:`inline-flex items-center rounded-md border bg-muted px-2 py-0.5 text-xs`,children:e.label},e.id))}):(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Save this entry first to see linked items.`})}function U1({relationType:e,relatedTable:t,relatedField:n,currentEntryId:r,value:i,onChange:a,disabled:o=!1}){let s=e===`many-to-many`,[c,l]=(0,v.useState)(!1),u=(0,v.useId)(),{entries:d,loading:f}=B1(t);if(e===`one-to-many`)return(0,H.jsx)(H1,{relatedTable:t,relatedField:n,currentId:r});let p=s?Array.isArray(i)?i:[]:i&&!Array.isArray(i)?[i]:[];function m(e){return d.find(t=>t.id===e)?.label??e}function h(e){if(s){let t=p.includes(e)?p.filter(t=>t!==e):[...p,e];a(t.length>0?t:null)}else a(p[0]===e?null:e),l(!1)}function g(e){if(s){let t=p.filter(t=>t!==e);a(t.length>0?t:null)}else a(null)}let _=s?p.length>0?`${p.length} selected`:`Select entries…`:p.length>0?m(p[0]):`Select entry…`;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsxs)(IP,{open:c&&!o,onOpenChange:l,children:[(0,H.jsx)(LP,{asChild:!0,children:(0,H.jsxs)(q,{variant:`outline`,role:`combobox`,"aria-expanded":c,"aria-controls":u,className:`w-full justify-between font-normal text-base`,disabled:o,children:[(0,H.jsx)(`span`,{className:`truncate text-left`,children:_}),(0,H.jsx)(Ja,{className:`ml-2 size-4 shrink-0 opacity-50`})]})}),(0,H.jsx)(RP,{className:`w-(--radix-popover-trigger-width) p-0`,align:`start`,children:(0,H.jsxs)(u1,{children:[(0,H.jsx)(d1,{placeholder:`Search…`}),(0,H.jsx)(f1,{id:u,children:f?(0,H.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,H.jsx)(ex,{className:`size-4`})}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(p1,{children:`No entries found.`}),(0,H.jsx)(m1,{children:d.map(e=>{let t=p.includes(e.id);return(0,H.jsxs)(g1,{value:e.label,onSelect:()=>{o||h(e.id)},children:[(0,H.jsx)(Ua,{className:`mr-2 size-4 ${t?`opacity-100`:`opacity-0`}`}),(0,H.jsx)(`span`,{className:`truncate`,children:e.label}),(0,H.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground opacity-60 shrink-0`,children:e.id.slice(0,8)})]},e.id)})})]})})]})})]}),p.length>0&&(0,H.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>(0,H.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border bg-muted px-2 py-0.5 text-xs`,children:[m(e),(0,H.jsx)(`button`,{type:`button`,onClick:()=>g(e),disabled:o,className:`text-muted-foreground hover:text-foreground`,children:(0,H.jsx)(us,{className:`size-3`})})]},e))})]})}var W1={full:`col-span-6`,"two-thirds":`col-span-4`,half:`col-span-3`,third:`col-span-2`};function G1({field:e,value:t,onChange:n,disabled:r=!1}){let i=Array.isArray(t)?t:[],a=e.arrayFields??[];function o(){return Object.fromEntries(a.map(e=>[e.name,e.type===`boolean`?!1:null]))}function s(){n([...i,o()])}function c(e){n(i.filter((t,n)=>n!==e))}function l(e,t){let r=e+t;if(r<0||r>=i.length)return;let a=[...i];[a[e],a[r]]=[a[r],a[e]],n(a)}function u(e,t,r){n(i.map((n,i)=>i===e?{...n,[t]:r}:n))}return a.length===0?(0,H.jsx)(`div`,{className:`flex w-full items-center justify-center rounded-md border border-dashed p-4 text-xs text-muted-foreground`,children:`No sub-fields defined for this array.`}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(BP,{type:`single`,collapsible:!0,className:`w-full`,children:i.map((e,t)=>(0,H.jsxs)(VP,{value:`item-${t}`,className:`mb-2 rounded-md border border-dashed last:border-b transition-colors hover:bg-accent/50`,children:[(0,H.jsxs)(`div`,{className:`relative data-[state=open]:border-b data-[state=open]:border-border/50`,children:[(0,H.jsxs)(HP,{className:`w-full py-2 pl-3 pr-24 text-muted-foreground [&>svg]:hidden`,children:[`Item `,t+1]}),(0,H.jsxs)(`div`,{className:`absolute right-2 top-1/2 flex -translate-y-1/2 items-center gap-0.5`,children:[(0,H.jsx)(q,{size:`icon`,variant:`ghost`,disabled:r||t===0,onMouseDown:e=>e.stopPropagation(),onClick:()=>l(t,-1),className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-accent disabled:opacity-30`,children:(0,H.jsx)(qa,{className:`size-3.5`})}),(0,H.jsx)(q,{size:`icon`,variant:`ghost`,disabled:r||t===i.length-1,onMouseDown:e=>e.stopPropagation(),onClick:()=>l(t,1),className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-accent disabled:opacity-30`,children:(0,H.jsx)(Wa,{className:`size-3.5`})}),(0,H.jsx)(`button`,{type:`button`,onMouseDown:e=>e.stopPropagation(),onClick:()=>c(t),disabled:r,className:`flex size-6 items-center justify-center rounded text-destructive transition-colors hover:bg-destructive/10 hover:text-destructive`,children:(0,H.jsx)(es,{className:`size-3.5`})})]})]}),(0,H.jsx)(UP,{className:`px-3 pt-3`,children:(0,H.jsx)(`div`,{className:`grid grid-cols-6 gap-3`,children:a.map(n=>(0,H.jsxs)(`div`,{className:W1[n.width??`full`]??`col-span-6`,children:[(0,H.jsx)(`div`,{className:`mb-1 flex items-center gap-1`,children:(0,H.jsxs)(Y,{className:`text-xs font-medium`,children:[n.name,n.required&&(0,H.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`})]})}),(0,H.jsx)(Z1,{field:{...n,type:n.type},value:e[n.name]??null,onChange:e=>u(t,n.name,e),allValues:e,disabled:r})]},n.name))})})]},t))}),(0,H.jsxs)(`button`,{type:`button`,onClick:s,disabled:r,className:`flex w-full items-center justify-center gap-1.5 rounded-md border border-dashed py-2 text-xs text-muted-foreground transition-colors hover:bg-accent/50`,children:[(0,H.jsx)(Bo,{className:`size-3.5`}),`Add item`]})]})}var K1=3,q1=20;function J1({value:e,onChange:t,disabled:n=!1,depth:r=0}){let i=Array.isArray(e)?e:[],a=r+1<K1,o=i.length<q1;function s(){return{label:``,href:``}}function c(e,n){let r=(t,i)=>{let a=e[i];return t.map((t,o)=>{if(o!==a)return t;if(i===e.length-1)return n(t);let s=Array.isArray(t.items)?t.items:[];return{...t,items:r(s,i+1)}})};t(r(i,0))}function l(e,n){let r=(t,i)=>{if(i===e.length-1){let r=e[i],a=r+n;if(a<0||a>=t.length)return t;let o=[...t];return[o[r],o[a]]=[o[a],o[r]],o}let a=e[i];return t.map((e,t)=>{if(t!==a)return e;let n=Array.isArray(e.items)?e.items:[];return{...e,items:r(n,i+1)}})};t(r(i,0))}function u(e){let n=(t,r)=>{let i=e[r];return r===e.length-1?t.filter((e,t)=>t!==i):t.map((e,t)=>{if(t!==i)return e;let a=Array.isArray(e.items)?e.items:[];return{...e,items:n(a,r+1)}})};t(n(i,0))}function d(){o&&t([...i,s()])}return i.length===0?(0,H.jsxs)(`button`,{type:`button`,onClick:d,disabled:n||!o,className:`flex w-full items-center justify-center gap-1.5 rounded-md border border-dashed py-2 text-xs text-muted-foreground transition-colors hover:bg-accent/20`,children:[(0,H.jsx)(Bo,{className:`size-3.5`}),`Add item`]}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(BP,{type:`single`,collapsible:!0,className:`w-full`,children:i.map((e,t)=>{let o=[t],s=e.label?.trim()?e.label:`Item ${t+1}`;return(0,H.jsxs)(VP,{value:`navigation-item-${r}-${t}`,className:`mb-2 rounded-md border border-dashed last:border-b transition-colors hover:bg-accent/50`,children:[(0,H.jsxs)(`div`,{className:`relative data-[state=open]:border-b data-[state=open]:border-border/50`,children:[(0,H.jsx)(HP,{className:`w-full py-2 pl-3 pr-24 text-muted-foreground [&>svg]:hidden`,children:s}),(0,H.jsxs)(`div`,{className:`absolute right-2 top-1/2 flex -translate-y-1/2 items-center gap-0.5`,children:[(0,H.jsx)(q,{size:`icon`,variant:`ghost`,disabled:n||t===0,onMouseDown:e=>e.stopPropagation(),onClick:()=>l(o,-1),className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-accent disabled:opacity-30`,children:(0,H.jsx)(qa,{className:`size-3.5`})}),(0,H.jsx)(q,{size:`icon`,variant:`ghost`,disabled:n||t===i.length-1,onMouseDown:e=>e.stopPropagation(),onClick:()=>l(o,1),className:`flex size-6 items-center justify-center rounded text-muted-foreground hover:bg-accent disabled:opacity-30`,children:(0,H.jsx)(Wa,{className:`size-3.5`})}),(0,H.jsx)(`button`,{type:`button`,onMouseDown:e=>e.stopPropagation(),onClick:()=>u(o),disabled:n,className:`flex size-6 items-center justify-center rounded text-destructive transition-colors hover:bg-destructive/10 hover:text-destructive`,children:(0,H.jsx)(es,{className:`size-3.5`})})]})]}),(0,H.jsxs)(UP,{className:`px-3 pt-3`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-6 gap-3`,children:[(0,H.jsxs)(`div`,{className:`col-span-3`,children:[(0,H.jsx)(Y,{className:`mb-1 block text-xs font-medium`,children:`label`}),(0,H.jsx)(J,{className:`text-base`,value:e.label??``,onChange:e=>c(o,t=>({...t,label:e.target.value})),disabled:n})]}),(0,H.jsxs)(`div`,{className:`col-span-3`,children:[(0,H.jsx)(Y,{className:`mb-1 block text-xs font-medium`,children:`href`}),(0,H.jsx)(J,{className:`text-base`,value:e.href??``,onChange:e=>c(o,t=>({...t,href:e.target.value})),disabled:n})]})]}),a?(0,H.jsxs)(`div`,{className:`mt-3 border-l border-border pl-3`,children:[(0,H.jsx)(`p`,{className:`mb-2 text-[11px] uppercase tracking-wide text-muted-foreground`,children:`Child items`}),(0,H.jsx)(J1,{value:e.items??[],onChange:e=>c(o,t=>({...t,items:Array.isArray(e)&&e.length>0?e:void 0})),disabled:n,depth:r+1})]}):(0,H.jsxs)(`p`,{className:`mt-3 text-[11px] text-muted-foreground`,children:[`Maximum depth reached (`,K1,` levels).`]})]})]},t)})}),(0,H.jsxs)(`button`,{type:`button`,onClick:d,disabled:n,className:`flex w-full items-center justify-center gap-1.5 rounded-md border border-dashed py-2 text-xs text-muted-foreground transition-colors hover:bg-accent/50`,children:[(0,H.jsx)(Bo,{className:`size-3.5`}),`Add item`]}),!o&&(0,H.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Maximum `,q1,` items allowed per level.`]})]})}function Y1(e){return e.normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/^-+|-+$/g,``)}function X1({value:e,onChange:t,disabled:n=!1}){let r=(0,v.useRef)(null),i=(0,v.useRef)(null),[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(null);function p(){return o(!0),new Promise(e=>{i.current=e})}function m(e){i.current?.(e),i.current=null}function h(e){e||m(null),o(e)}async function g(e){u(!0),f(null);try{let t=await p$(e);m([{id:t.id,src:t.url,filename:t.filename,alt:t.alt,title:t.caption,width:t.width,height:t.height}]),o(!1)}catch(e){f(e instanceof Error?e.message:`Upload failed.`)}finally{u(!1),r.current&&(r.current.value=``)}}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:n?`pointer-events-none opacity-70`:``,children:(0,H.jsx)(u$,{value:String(e??``),onChange:t,placeholder:`Type or add your content here...`,onInsertImage:p})}),(0,H.jsx)(vy,{open:a,onOpenChange:h,children:(0,H.jsxs)(Sy,{className:`max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Insert Image`})}),(0,H.jsx)(`input`,{ref:r,type:`file`,accept:`image/*`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&g(t)}}),(0,H.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault();let t=e.dataTransfer.files[0];t&&g(t)},className:`flex w-full gap-2 rounded-md border border-dashed p-3`,children:[(0,H.jsxs)(`button`,{type:`button`,disabled:l,onClick:()=>r.current?.click(),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(as,{className:`size-4`}),l?`Uploading…`:`Upload`]}),(0,H.jsx)(`div`,{className:`w-px bg-border`}),(0,H.jsxs)(`button`,{type:`button`,disabled:l,onClick:()=>c(!0),className:`flex flex-1 items-center justify-center gap-2 rounded-md py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50 disabled:opacity-50`,children:[(0,H.jsx)(fo,{className:`size-4`}),`Library`]})]}),d&&(0,H.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:d})]})}),(0,H.jsx)(E1,{open:s,onOpenChange:e=>{!e&&!a&&m(null),c(e)},allowedTypes:[`image`],selectionMode:`multiple`,onSelect:e=>{m(e.map(e=>({id:e.id,src:e.url,filename:e.filename,alt:e.alt,title:e.caption,width:e.width,height:e.height}))),c(!1),o(!1)}})]})}function Z1({field:e,value:t,onChange:n,allValues:r,disabled:i,errorMessage:a}){let o=(0,v.useRef)(null),{timezone:s}=ba();(0,v.useEffect)(()=>{if(e.type!==`uid`||!e.targetField)return;let i=String(t??``).trim(),a=i===``||i===o.current,s=r,c=e.targetField,l=!!s.__localizationEnabled,u=s[c];if(u!=null&&String(u).trim()!==``){if(!a)return;let e=Y1(String(u));e!==i&&(o.current=e,n(e));return}let d=s.localized&&typeof s.localized==`object`?s.localized:{};if(l){let e=typeof s.__defaultLocale==`string`?s.__defaultLocale:void 0,t=e&&d[e]&&typeof d[e]==`object`?d[e]:null;if(t&&t[c]!==void 0&&String(t[c]).trim()!==``){if(!a)return;let e=Y1(String(t[c]));e!==i&&(o.current=e,n(e))}return}let f=Object.keys(d).filter(e=>!e.startsWith(`_`));for(let e of f){let t=d[e]&&typeof d[e]==`object`?d[e]:null;if(t&&t[c]!==void 0&&String(t[c]).trim()!==``){if(!a)return;let e=Y1(String(t[c]));e!==i&&(o.current=e,n(e));return}}},[t,e.type,e.targetField,r[e.targetField??``],JSON.stringify(r.localized??{}),r.__localizationEnabled]);let c=`w-full`;return e.type===`boolean`?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,H.jsx)(_k,{id:`field-${e.name}`,checked:!!t,onCheckedChange:e=>n(!!e),disabled:!!i}),(0,H.jsx)(Y,{htmlFor:`field-${e.name}`,className:`cursor-pointer font-normal text-base`,children:t?`Yes`:`No`})]}):e.type===`richtext`?(0,H.jsx)(X1,{value:t,onChange:n,disabled:!!i}):e.type===`text`?(0,H.jsx)(zP,{className:K(c,`text-base`),value:String(t??``),placeholder:b1(e.name),onChange:e=>n(e.target.value),disabled:!!i}):e.type===`number`?e.subtype===`float`?(0,H.jsx)(A1,{value:t,onChange:n,disabled:!!i}):(0,H.jsx)(J,{type:`number`,className:K(c,`text-base!`),value:t==null?``:String(t),step:`1`,placeholder:`0`,onChange:e=>{let t=e.target.value;if(t===``){n(null);return}n(parseInt(t,10))},disabled:!!i}):e.type===`datetime`?(0,H.jsx)(N1,{value:t,onChange:n,timezone:s,disabled:!!i}):e.type===`uid`?(0,H.jsxs)(`div`,{children:[(0,H.jsx)(J,{className:K(c,`text-base md:text-base`,a?`border-destructive focus-visible:ring-destructive/20`:``),value:String(t??``),placeholder:`auto-generated`,onChange:e=>{n(e.target.value)},disabled:!!i}),a&&(0,H.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:a})]}):e.type===`media`?(0,H.jsx)(D1,{value:t,onChange:n,allowedTypes:e.allowedTypes,disabled:!!i}):e.type===`media-gallery`?(0,H.jsx)(k1,{value:t,onChange:n,disabled:!!i}):e.type===`relation`?(0,H.jsx)(U1,{relationType:e.relationType??`many-to-one`,relatedTable:e.relatedTable??``,relatedField:e.relatedField??``,currentEntryId:String(r.id??``),value:t,onChange:n,disabled:!!i}):e.type===`array`?(0,H.jsx)(G1,{field:e,value:t,onChange:n,disabled:!!i}):e.type===`mixed`?(0,H.jsx)(M1,{value:t,onChange:n,inputId:`field-${e.name}-mixed-boolean`,disabled:!!i}):e.type===`navigation`?(0,H.jsx)(J1,{value:t,onChange:n,disabled:!!i}):(0,H.jsx)(J,{className:K(c,`text-base md:text-base`),value:String(t??``),placeholder:b1(e.name),onChange:e=>n(e.target.value),disabled:!!i})}var Q1=`plank-preview`;function $1(e,t){let n=!1,r=e.replace(/\{(contentType|entryId|slug|status)\}/g,(e,r)=>{let i=t[r];return i==null||i===``?(n=!0,``):encodeURIComponent(i)});return n||/\{[^}]+\}/.test(r)?null:r}function e0(e){return{enabled:String(e?.enabled??`false`).toLowerCase()===`true`,syncUrl:e?.sync_url?.trim()??``,urlTemplate:e?.url_template?.trim()??``,slugField:e?.slug_field?.trim()||`slug`}}function t0(e){return{enabled:String(e?.preview_enabled??`false`).toLowerCase()===`true`,syncUrl:e?.preview_sync_url?.trim()??``,urlTemplate:e?.preview_url_template?.trim()??``,slugField:e?.preview_slug_field?.trim()||`slug`}}function n0(e,t){if(!e.enabled)return null;if(!e.urlTemplate)return`Set a preview URL template in Settings > Overview > Preview.`;if(e.syncUrl)try{new URL(e.syncUrl)}catch{return`Preview sync webhook URL must be an absolute URL.`}if(e.urlTemplate.includes(`{slug}`)&&!t.includes(e.slugField))return`Preview slug field "${e.slugField}" does not exist on this content type.`;let n=$1(e.urlTemplate,{contentType:`sample-content`,entryId:`sample-entry`,slug:`sample-slug`,status:`draft`});if(!n)return`Preview URL template contains unsupported or unresolved placeholders.`;try{return new URL(n),null}catch{return`Preview URL template must resolve to an absolute URL.`}}function r0(e){let{config:t,contentType:n,entry:r,status:i}=e;if(!t.enabled||!t.urlTemplate)return null;let a=r[t.slugField],o=$1(t.urlTemplate,{contentType:n,entryId:r.id?String(r.id):null,slug:typeof a==`string`&&a.trim()?a.trim():null,status:i??(typeof r.status==`string`?r.status:null)});if(!o)return null;try{return new URL(o).toString()}catch{return null}}var i0=null;function a0(e){return Array.isArray(e)?e.map(a0):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,a0(t)])):e}function o0(e){return JSON.stringify(a0(e))}function s0(e){let t=e.match(/Field "([^"]+)" already exists\.?/);return t?t[1]??null:null}function c0(){let{slug:e,id:t}=gr(),n=fr(),r=!t,{timezone:i,locales:a,defaultLocale:o,editorialMode:s}=ba(),{user:c,status:l}=_a(),u=c?.role?.toLowerCase()??``,{data:d,loading:f}=Ta(e?`/cms/admin/content-types/${e}`:null),{data:p}=Ta(`/cms/admin/client-settings`),{data:m,loading:h}=Ta(e&&t?`/cms/admin/entries/${e}/${t}`:null),{data:g}=Ta(s&&[`editor`,`admin`,`super admin`].includes(c?.role?.toLowerCase()??``)?`/cms/admin/users`:null),{loading:_,request:y}=Eb(),{loading:b,request:x}=Eb(),{loading:S,request:C}=Eb(),[w,T]=(0,v.useState)({}),[E,D]=(0,v.useState)([]),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(!1),[M,N]=(0,v.useState)(`draft`),[P,F]=(0,v.useState)(``),[I,L]=(0,v.useState)(!1),[R,ee]=(0,v.useState)(!1),[te,ne]=(0,v.useState)(!1),[z,B]=(0,v.useState)(null),[re,V]=(0,v.useState)(null),[ie,ae]=(0,v.useState)(null),[oe,se]=(0,v.useState)(null),[ce,le]=(0,v.useState)(!1),[ue,de]=(0,v.useState)(null),[fe,pe]=(0,v.useState)(!1),[me,he]=(0,v.useState)(!1),[ge,_e]=(0,v.useState)(),[ve,ye]=(0,v.useState)(`09:00`),be=(0,v.useRef)(`{}`),xe=(0,v.useRef)(!1),Se=t0(p),Ce=d?.kind===`collection`&&d.previewEnabled!==!1,we=d?n0(Se,d.fields.map(e=>e.name)):null,Te=Ce&&Se.enabled&&!we,Ee=Ce&&Se.enabled&&we?we:Ce&&Se.enabled?null:`Preview is disabled. Configure Settings > Overview > Preview to enable it.`;(0,v.useEffect)(()=>{if(r){let e={};d?.fields.forEach(t=>{e[t.name]=t.type===`boolean`?!1:``}),e.localized={};let t=a&&a.length>0?a:[`en`];D(t),k(o??t[0]),j(!1),T(e),N(`draft`),F(``),L(!1),ne(!1),B(null),V(null),ae(null),se(null),le(!1),de(null),be.current=o0(e);return}if(!m||!d)return;let e={};d.fields.forEach(t=>{e[t.name]=m[t.name]??(t.type===`boolean`?!1:``)});let t=m.localized,n=t&&typeof t==`object`?t:{};e.localized=n;let s=Object.keys(n).filter(e=>!e.startsWith(`_`)),c=(n._meta||{}).enabled??s.length>0;if(s.length>0)D(s),k(s[0]);else{let e=a&&a.length>0?a:[`en`];D(e),k(o??e[0])}if(j(!!c),T(e),N(m.status??`draft`),ne(!!m.review_rejected),B(m.editor_id??null),V(m._editor_first_name??null),ae(m._editor_last_name??null),se(m._editor_avatar_url??null),le(!1),de(null),be.current=o0(e),m.scheduled_for?(F(m.scheduled_for),_e(new Date(m.scheduled_for)),ye(ax(m.scheduled_for,i))):F(``),m.status===`published`&&m.published_data){let t=(e,t)=>{if(t===`datetime`&&e&&typeof e==`string`){let t=/Z|[+-]\d{2}:\d{2}$/.test(e)?e:e+`Z`,n=new Date(t);return isNaN(n.getTime())?e:n.toISOString()}return e},n={},r={};d.fields.forEach(i=>{i.name in m.published_data&&(n[i.name]=t(m.published_data[i.name]??(i.type===`boolean`?!1:``),i.type),r[i.name]=t(e[i.name],i.type))}),L(o0(r)!==o0(n))}else L(!1)},[m,d,r]);let De=o0(w)!==be.current,Oe=Ir((0,v.useCallback)(()=>xe.current?!1:De,[De]));function ke(e,t){T(n=>({...n,[e]:t}))}function Ae(e,t,n){T(r=>{let i={...r},a=i.localized&&typeof i.localized==`object`?i.localized:{},o=a[e]&&typeof a[e]==`object`?a[e]:{};return o[t]=n,a[e]=o,i.localized=a,i})}function je(e){j(e),T(t=>{let n={...t},r=n.localized&&typeof n.localized==`object`?n.localized:{};if(r._meta||={},e&&o){if(!(r[o]&&typeof r[o]==`object`&&r[o])&&(r[o]={},d&&d.fields)){let e=r[o];d.fields.forEach(t=>{if([`string`,`text`,`richtext`].includes(t.type)){let r=n[t.name];r!=null&&r!==``&&(e[t.name]=r)}})}r._meta.primary=o}else if(!e&&o){let e=r[o]&&typeof r[o]==`object`?r[o]:null;e&&d&&d.fields&&d.fields.forEach(t=>{if([`string`,`text`,`richtext`,`uid`].includes(t.type)){let r=e[t.name];r!==void 0&&(n[t.name]=r)}})}return r._meta.enabled=e,n.localized=r,n})}function Me(){if(P)_e(new Date(P)),ye(ax(P,i));else{let e=new Date;e.setDate(e.getDate()+1),_e(e),ye(`09:00`)}pe(!0)}async function Ne(){if(!e||!d)return null;de(null);let n={},i=A&&w.localized&&typeof w.localized==`object`&&w.localized[o]&&typeof w.localized[o]==`object`?w.localized[o]:null;if(d.fields.forEach(e=>{let t=w[e.name];(t==null||t===``)&&i&&i[e.name]!==void 0&&(t=i[e.name]),e.type===`media`&&t===null?n[e.name]=null:t!==``&&t!=null&&(n[e.name]=t)}),w.localized&&Object.keys(w.localized).length>0){let e=w.localized;e._meta||={},e._meta.enabled=A,e._meta.primary=o,n.localized=e}try{let i=await y(r?`/cms/admin/content-types/${e}/entries`:`/cms/admin/entries/${e}/${t}`,r?`POST`:`PUT`,n);return be.current=o0(w),i}catch(e){let t=s0(e instanceof Error?e.message:``);return t&&d.fields.some(e=>e.type===`uid`&&e.name===t)&&de(t),X.error(`Could not save draft`),null}}function Pe(e){!i0||i0.closed||(i0.location.href=e,i0.focus())}async function Fe(i){let a=await Ne();if(!a)return null;let o=a,s=M;if(M===`scheduled`){let n=r?a.id:t;try{o=await x(`/cms/admin/entries/${e}/${n}/status`,`PATCH`,{status:`draft`}),s=`draft`,N(`draft`),F(``),pe(!1)}catch{return X.error(`Could not save draft`),null}}else M===`published`&&(s=`published`,L(!0));if(i&&e&&Te&&!Se.syncUrl){let t=r0({config:Se,contentType:e,entry:o,status:s});t&&Pe(t)}return X.success(`Draft saved`),r&&(xe.current=!0,n(`/content/${e}/${o.id}`,{replace:!0})),{entry:o,status:s}}async function Ie(){await Fe(!0)}async function Le(){if(!e||!d||!Se.enabled||!ft)return;if(we){X.error(we);return}let n=m??null,i=M;if(r||De){let e=await Fe(!1);if(!e)return;n=e.entry,i=e.status}let a=r0({config:Se,contentType:e,entry:n??{...w,id:t,status:M},status:i});if(!a){X.error(`Preview URL could not be resolved for this entry.`);return}if(i0=window.open(a,Q1),!i0){X.error(`Preview window was blocked by the browser.`);return}i0.focus()}async function Re(){if(!e)return;let i=t;if(De||r){let e=await Ne();if(!e)return;i=r?e.id:t,r&&(xe.current=!0)}let a=s&&(u===`contributor`||u===``||l!==`authenticated`);try{let t=await x(`/cms/admin/entries/${e}/${i}/status`,`PATCH`,{status:a?`pending`:`published`,review_rejected:!1});N(t?.status??(a?`pending`:`published`)),ne(!!t?.review_rejected),B(t?.editor_id??z),V(t?._editor_first_name??re),ae(t?._editor_last_name??ie),se(t?._editor_avatar_url??oe),F(``),L(!1),pe(!1),le(!1),X.success(`Entry published`),r&&n(`/content/${e}/${i}`,{replace:!0})}catch{X.error(`Could not publish entry`),r&&i&&n(`/content/${e}/${i}`,{replace:!0})}}async function ze(){if(!e||!ge||!ve)return;let a=ox(ge,ve,i);if(new Date(a)<=new Date)return;let o=t;if(De||r){let e=await Ne();if(!e)return;o=r?e.id:t,r&&(xe.current=!0)}try{await x(`/cms/admin/entries/${e}/${o}/status`,`PATCH`,{status:`scheduled`,scheduled_for:a}),N(`scheduled`),F(a),pe(!1),X.success(`Entry scheduled`),r&&n(`/content/${e}/${o}`,{replace:!0})}catch{X.error(`Could not schedule entry`),r&&o&&n(`/content/${e}/${o}`,{replace:!0})}}async function Be(){if(!(!e||!t))try{await x(`/cms/admin/entries/${e}/${t}/status`,`PATCH`,{status:`draft`}),N(`draft`),F(``),L(!1),X.success(`Reverted to draft`)}catch{X.error(`Could not revert entry`)}}async function Ve(){if(!(!e||!t))try{await C(`/cms/admin/entries/${e}/${t}`,`DELETE`),X.success(`Entry deleted`),xe.current=!0,n(`/content/${e}`,{replace:!0})}catch{X.error(`Could not delete entry`)}}async function He(n){if(!e||!t)return;let r=n===`none`?null:n;try{let n=await x(`/cms/admin/entries/${e}/${t}/status`,`PATCH`,{status:`in_review`,editor_id:r,review_locked_by_editor:m?.review_locked_by_editor??!1});N(n?.status??`in_review`),ne(!!n?.review_rejected),B(n?.editor_id??r),V(n?._editor_first_name??null),ae(n?._editor_last_name??null),se(n?._editor_avatar_url??null),le(!1),X.success(`Editor assigned`)}catch{X.error(`Could not assign editor`)}}async function Ue(){le(e=>!e)}async function We(){if(!(!e||!t))try{let n=await x(`/cms/admin/entries/${e}/${t}/status`,`PATCH`,{status:`pending`,review_rejected:!0});N(n?.status??`pending`),ne(!!n?.review_rejected),le(!1),X.success(`Entry rejected`)}catch{X.error(`Could not reject entry`)}}let Ge=f||!r&&h,Ke=_||b,qe=c?.permissions??[],Je=qe.includes(`*`)||qe.includes(`entries:write`),Ye=qe.includes(`*`)||qe.includes(`entries:delete`),Xe=u===`contributor`,Ze=u===`editor`,Qe=[`admin`,`super admin`].includes(u),$e=u===`viewer`,et=Xe||Ze,tt=Xe&&d?.kind===`single`,nt=r||String(m?.created_by??``)===String(c?.id??``),rt=s&&Xe&&M===`in_review`,it=s&&(Ze||Qe)&&!!z&&z===c?.id,at=it&&(M===`pending`||M===`in_review`)&&!te,ot=$e||!Je||tt||Xe&&!nt||s&&Xe&&M===`pending`&&!te||rt||s&&(Ze||Qe)&&(M===`pending`||M===`in_review`)&&(!it||!ce),st=Ye&&(!et||nt),ct=s&&Xe&&M===`pending`&&(te?!0:De)||De||M===`draft`||M===`scheduled`||!s&&M===`pending`||s&&M===`pending`&&!Xe||s&&M===`in_review`&&!Xe||I,lt=!!(ge&&ve),ut=s&&Xe?`Review`:`Publish`,dt=Ce,ft=M===`draft`||M===`scheduled`||M===`pending`||M===`in_review`||M===`published`&&I;if(lk(`mod+s`,Ie,{enabled:!ot&&!Ke&&(M===`scheduled`?!0:De),label:`Save draft`}),lk(`mod+shift+p`,Re,{enabled:ct&&!Ke&&!ot,label:`Publish`}),Ge)return(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-12 text-muted-foreground`,children:[(0,H.jsx)(ex,{className:`size-4`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading…`})]});if(!d)return null;let pt;pt=M===`scheduled`?(0,H.jsxs)(dT,{variant:`outline`,className:`border-blue-500 text-blue-600`,children:[(0,H.jsx)(Ba,{className:`size-3 mr-1`}),P?`Scheduled · ${ix(P,i)}`:`Scheduled`]}):M===`pending`?te?(0,H.jsx)(dT,{variant:`destructive`,children:`Pending`}):(0,H.jsx)(dT,{className:`bg-amber-500 text-black hover:bg-amber-500`,children:`Pending`}):M===`in_review`?(0,H.jsx)(dT,{variant:`outline`,children:`In Review`}):M===`published`?(0,H.jsx)(dT,{variant:I?`secondary`:`default`,children:I?`Published (pending changes)`:`Published`}):(0,H.jsx)(dT,{variant:`secondary`,children:`Draft`});let mt=(g??[]).filter(e=>Ze?e.id===c?.id:Qe?e.id===c?.id||(e.role_name??``).toLowerCase()===`editor`:!1),ht=!r&&s&&(Ze||Qe)&&(M===`pending`||M===`in_review`),gt=s&&!r&&ht,_t=s&&!r&&!!z,vt=at,yt=at,bt=re||ie;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($b,{children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:r?`New entry`:`Edit entry`}),pt]}),(0,H.jsx)(`p`,{className:`text-muted-foreground text-xs mt-1`,children:d.name}),dt&&Se.enabled&&we&&(0,H.jsx)(`p`,{className:`mt-1 text-xs text-amber-600`,children:we})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!r&&st&&!tt&&(0,H.jsx)(q,{variant:`ghost`,size:`icon`,className:`text-muted-foreground hover:text-destructive`,onClick:()=>ee(!0),disabled:S,children:(0,H.jsx)(es,{className:`size-4`})}),!r&&M===`published`&&!ot&&(0,H.jsxs)(q,{variant:`outline`,onClick:Be,disabled:Ke,children:[b?(0,H.jsx)(ex,{className:`size-4`}):null,`Revert to draft`]}),!r&&M===`scheduled`&&!ot&&(0,H.jsxs)(q,{variant:`outline`,onClick:Be,disabled:Ke,children:[b?(0,H.jsx)(ex,{className:`size-4`}):null,`Cancel schedule`]}),gt&&(0,H.jsxs)(_T,{value:z??`none`,onValueChange:He,disabled:!ht||Ke,children:[(0,H.jsx)(bT,{className:`h-10 min-h-10 max-h-10 w-42 py-0`,children:(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(Nl,{avatarUrl:oe??null,firstName:re??null,lastName:ie??null,className:`size-5`,fallbackClassName:`text-[9px]`}),(0,H.jsx)(yT,{placeholder:bt||`Assign editor`})]})}),(0,H.jsxs)(CT,{children:[!Ze&&(0,H.jsx)(TT,{value:`none`,children:`Unassign`}),mt.map(e=>(0,H.jsx)(TT,{value:e.id,children:e.first_name||e.last_name||e.id},e.id))]})]}),!ht&&_t&&(0,H.jsxs)(`div`,{className:`inline-flex h-10 items-center gap-2 rounded-md border border-input px-3 text-sm`,children:[(0,H.jsx)(Nl,{avatarUrl:oe??null,firstName:re??null,lastName:ie??null,className:`size-5`,fallbackClassName:`text-[9px]`}),(0,H.jsx)(`span`,{children:bt||`Assigned editor`})]}),vt&&(0,H.jsx)(q,{variant:`outline`,size:`icon`,onClick:Ue,disabled:Ke,children:(0,H.jsx)(zo,{className:`size-4`})}),yt&&(0,H.jsx)(q,{variant:`outline`,size:`icon`,onClick:We,disabled:Ke,children:(0,H.jsx)(us,{className:`size-4`})}),dt&&Se.enabled&&ft&&(0,H.jsx)(q,{variant:`outline`,onClick:Le,disabled:ot||Ke||!!we,title:Ee??void 0,children:`Open preview`}),(0,H.jsxs)(q,{variant:`outline`,onClick:Ie,size:s?`icon`:`default`,disabled:ot||(M===`scheduled`?Ke:!De||Ke),children:[_?(0,H.jsx)(ex,{className:`size-4`}):s?(0,H.jsx)(Wo,{className:`size-4`}):null,!s&&(M===`scheduled`?`Save draft (cancel schedule)`:`Save draft`)]}),M!==`scheduled`&&!(s&&Xe)&&(0,H.jsxs)(q,{variant:`outline`,onClick:Me,size:s?`icon`:`default`,disabled:ot||Ke,children:[(0,H.jsx)(Ba,{className:`size-4`}),!s&&`Schedule`]}),(0,H.jsxs)(q,{onClick:Re,disabled:ot||!ct||Ke,children:[b?(0,H.jsx)(ex,{className:`size-4`}):null,M===`scheduled`?s&&Xe?`Review`:`Publish now`:M===`published`&&!I?`Republish`:ut]})]})]})}),(0,H.jsxs)(`section`,{className:`mt-24`,children:[fe&&!ot&&(0,H.jsxs)(`div`,{className:`mb-6 flex items-end gap-2 rounded-lg border p-4 bg-muted/30`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{children:`Date`}),(0,H.jsxs)(IP,{open:me,onOpenChange:he,children:[(0,H.jsx)(LP,{asChild:!0,children:(0,H.jsxs)(q,{variant:`outline`,className:`w-40 justify-between font-normal`,children:[ge?Vj(ge,`MMM d, yyyy`):`Select date`,(0,H.jsx)(Wa,{className:`size-4 opacity-50`})]})}),(0,H.jsx)(RP,{className:`w-auto overflow-hidden p-0`,align:`start`,children:(0,H.jsx)(PP,{mode:`single`,selected:ge,captionLayout:`dropdown`,defaultMonth:ge??new Date,disabled:{before:new Date},onSelect:e=>{_e(e),he(!1)}})})]})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsxs)(Y,{children:[`Time `,(0,H.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(24h)`})]}),(0,H.jsx)(J,{type:`time`,className:`w-32 appearance-none bg-background [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none`,value:ve,onChange:e=>ye(e.target.value)})]}),(0,H.jsxs)(q,{onClick:ze,disabled:!lt||Ke,children:[b?(0,H.jsx)(ex,{className:`size-4`}):null,`Confirm`]}),(0,H.jsx)(q,{variant:`ghost`,onClick:()=>pe(!1),children:`Cancel`})]}),(0,H.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(uk,{checked:A,onCheckedChange:je,disabled:ot}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`text-sm font-medium`,children:`Localization`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Enable per-entry localization`})]})]}),(0,H.jsx)(`div`,{})]}),(0,H.jsx)(`div`,{children:A&&(0,H.jsx)(Qj,{value:O,onValueChange:e=>k(e),children:(0,H.jsx)($j,{children:E.map(e=>(0,H.jsx)(eM,{value:e,disabled:ot,children:e.toUpperCase()},e))})})})]}),(0,H.jsx)(`div`,{className:`grid grid-cols-6 gap-4`,children:d.fields.map(e=>{let n=[`string`,`text`,`richtext`].includes(e.type),r=w.localized&&w.localized[O]?w.localized[O][e.name]:void 0,i=n&&A?r:w[e.name],a=e.type===`uid`&&e.targetField&&A&&[`string`,`text`,`richtext`].includes(d.fields.find(t=>t.name===e.targetField)?.type??``);return(0,H.jsx)(`div`,{className:fk[e.width??`full`],children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsxs)(Y,{htmlFor:`entry-${e.name}`,className:`capitalize`,children:[e.name.replace(/_/g,` `),e.required&&(0,H.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,H.jsx)(Z1,{field:e,value:i,onChange:t=>{e.type===`uid`&&ue===e.name&&de(null),n&&A?Ae(O,e.name,t):ke(e.name,t)},allValues:{...w,id:t,__activeLocale:O,__localizationEnabled:A,__defaultLocale:o},disabled:!!a||ot,errorMessage:e.type===`uid`&&ue===e.name?`${e.name} already exists.`:void 0})]})},e.name)})}),(0,H.jsx)(vy,{open:R,onOpenChange:ee,children:(0,H.jsxs)(Sy,{className:`max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Delete this entry?`})}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This action cannot be undone.`}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>ee(!1),children:`Cancel`}),(0,H.jsxs)(q,{variant:`destructive`,onClick:Ve,disabled:S,children:[S?(0,H.jsx)(ex,{className:`size-4`}):null,`Delete`]})]})]})}),(0,H.jsx)(vy,{open:Oe.state===`blocked`,onOpenChange:()=>Oe.reset?.(),children:(0,H.jsxs)(Sy,{className:`max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Unsaved changes`})}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Leave without saving?`}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>Oe.reset?.(),children:`Stay`}),(0,H.jsx)(q,{variant:`destructive`,onClick:()=>Oe.proceed?.(),children:`Leave`})]})]})})]})]})}function l0({...e}){return(0,H.jsx)(`nav`,{"aria-label":`breadcrumb`,"data-slot":`breadcrumb`,...e})}function u0({className:e,...t}){return(0,H.jsx)(`ol`,{"data-slot":`breadcrumb-list`,className:K(`flex flex-wrap items-center gap-1.5 text-sm break-words text-muted-foreground sm:gap-2.5`,e),...t})}function d0({className:e,...t}){return(0,H.jsx)(`li`,{"data-slot":`breadcrumb-item`,className:K(`inline-flex items-center gap-1.5`,e),...t})}function f0({asChild:e,className:t,...n}){return(0,H.jsx)(e?xu:`a`,{"data-slot":`breadcrumb-link`,className:K(`transition-colors hover:text-foreground`,t),...n})}function p0({className:e,...t}){return(0,H.jsx)(`span`,{"data-slot":`breadcrumb-page`,role:`link`,"aria-disabled":`true`,"aria-current":`page`,className:K(`font-normal text-foreground`,e),...t})}function m0({children:e,className:t,...n}){return(0,H.jsx)(`li`,{"data-slot":`breadcrumb-separator`,role:`presentation`,"aria-hidden":`true`,className:K(`[&>svg]:size-3.5`,t),...n,children:e??(0,H.jsx)(Ka,{})})}function h0(e,t){e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),t())}function g0(e){return e?e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`:`—`}function _0(e){let t=e.split(`/`).pop()??e;return t.replace(/\.[^.]+$/,``).trim()||t.trim()}function v0(e){return!!e?.startsWith(`image/`)}function y0(e){return!!e?.startsWith(`video/`)}function b0(e){return!!e?.startsWith(`audio/`)}function x0(e){return e===`application/pdf`}function S0(e,t){return e.split(`?`)[0].endsWith(`.m3u8`)||t===`application/x-mpegurl`||t===`application/vnd.apple.mpegurl`}async function C0(e){if(e.isFile)return new Promise(t=>{e.file(n=>t([{file:n,relativePath:e.fullPath.replace(/^\//,``)}]))});if(e.isDirectory){let t=e.createReader(),n=[];return await new Promise(e=>{let r=()=>{t.readEntries(async t=>{if(t.length===0){e();return}let i=await Promise.all(t.map(C0));n.push(...i.flat()),r()})};r()}),n}return[]}function w0({url:e}){let t=(0,v.useRef)(null);return(0,v.useEffect)(()=>{let n=t.current;if(!n)return;if(n.canPlayType(`application/vnd.apple.mpegurl`)){n.src=e;return}let r=null;return L(async()=>{let{default:e}=await import(`./hls-0EiSYoTw.js`);return{default:e}},[]).then(({default:t})=>{if(!t.isSupported())return;let i=new t;r=i,i.loadSource(e),i.attachMedia(n)}),()=>{r?.destroy()}},[e]),(0,H.jsx)(`video`,{ref:t,controls:!0,className:`max-h-[70vh] w-full rounded-md bg-zinc-950`})}function T0({item:e}){let t=e.mime_type?.toLowerCase()??null;return v0(t)?(0,H.jsx)(`img`,{src:e.url,alt:e.alt??e.filename,className:`max-h-full max-w-full rounded-md object-contain`}):S0(e.url,t)?(0,H.jsx)(w0,{url:e.url}):y0(t)?(0,H.jsx)(`video`,{src:e.url,controls:!0,preload:`none`,className:`max-h-[70vh] w-full rounded-md bg-zinc-950`}):b0(t)?(0,H.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-6`,children:[(0,H.jsx)(oo,{className:`size-14 text-muted-foreground`}),(0,H.jsx)(`audio`,{src:e.url,controls:!0,className:`w-full`})]}):x0(t)?(0,H.jsx)(`iframe`,{src:e.url,title:e.filename,className:`h-[70vh] w-full rounded-md border`}):(0,H.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8 text-center`,children:[(0,H.jsx)(co,{className:`size-14 text-muted-foreground`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.mime_type??`Unknown type`}),(0,H.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,download:e.filename,children:(0,H.jsxs)(q,{variant:`outline`,size:`sm`,children:[(0,H.jsx)(no,{className:`size-4`}),`Download`]})})]})}function E0({folder:e,onOpen:t,onDelete:n,onRename:r,canDelete:i,canRename:a,selected:o,onToggle:s}){return(0,H.jsxs)(`div`,{className:`group relative flex items-center gap-3 rounded-lg border bg-card px-3 py-2.5 transition-colors cursor-pointer hover:bg-muted/50 ${o?`ring-2 ring-primary`:``}`,role:`button`,tabIndex:0,"aria-pressed":o,onClick:()=>{o||t(e)},onKeyDown:n=>{h0(n,()=>{o||t(e)})},children:[(0,H.jsxs)(`div`,{className:`relative shrink-0 size-7 flex items-center justify-center`,children:[(0,H.jsx)(mo,{className:`size-7 text-muted-foreground transition-opacity ${o?`opacity-0`:`group-hover:opacity-0`}`}),(0,H.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center transition-opacity ${o?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onPointerDown:e=>e.stopPropagation(),children:(0,H.jsx)(_k,{checked:o,onCheckedChange:()=>s(`folder:${e.id}`),"aria-label":`Select folder`})})]}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`p`,{className:`text-sm font-bold truncate`,title:e.name,children:e.name}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.item_count,` `,e.item_count===1?`item`:`items`]})]}),!o&&(a||i)&&(0,H.jsxs)(bv,{children:[(0,H.jsx)(xv,{asChild:!0,children:(0,H.jsx)(`button`,{type:`button`,className:`shrink-0 opacity-0 group-hover:opacity-100 transition-opacity flex size-6 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground`,onClick:e=>e.stopPropagation(),children:(0,H.jsx)(ro,{className:`size-4`})})}),(0,H.jsxs)(wv,{align:`end`,onClick:e=>e.stopPropagation(),children:[a&&(0,H.jsxs)(Tv,{onSelect:()=>r(e),children:[(0,H.jsx)(zo,{className:`size-4`}),`Rename`]}),i&&(0,H.jsxs)(Tv,{onSelect:()=>n(e),className:`text-destructive focus:text-destructive`,children:[(0,H.jsx)(es,{className:`size-4`}),`Delete`]})]})]})]})}function D0({item:e,onDelete:t,onPreview:n,canDelete:r,selected:i,onToggle:a}){let o=e.mime_type?.toLowerCase()??null;return(0,H.jsxs)(`div`,{className:`group relative rounded-lg border bg-card overflow-hidden transition-colors ${i?`ring-2 ring-primary`:``}`,children:[(0,H.jsx)(`div`,{className:`aspect-square bg-muted flex items-center justify-center cursor-pointer`,role:`button`,tabIndex:0,"aria-pressed":i,onClick:()=>{i||n(e)},onKeyDown:t=>{h0(t,()=>{i||n(e)})},children:v0(o)?(0,H.jsx)(`img`,{src:e.url,alt:e.alt??e.filename,className:`h-full w-full object-cover`}):y0(o)||S0(e.url,o)?(0,H.jsx)(so,{className:`size-10 text-muted-foreground`}):b0(o)?(0,H.jsx)(oo,{className:`size-10 text-muted-foreground`}):x0(o)?(0,H.jsx)(co,{className:`size-10 text-muted-foreground`}):(0,H.jsx)(lo,{className:`size-10 text-muted-foreground`})}),(0,H.jsx)(`div`,{className:`absolute top-1.5 left-1.5 transition-opacity ${i?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,children:(0,H.jsx)(_k,{checked:i,onCheckedChange:()=>a(e.id),"aria-label":`Select file`,className:`bg-background/80 backdrop-blur-sm`})}),!i&&r&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>t(e),className:`absolute top-1.5 right-1.5 flex size-6 items-center justify-center rounded-md bg-background/80 text-muted-foreground opacity-0 backdrop-blur-sm transition-opacity hover:text-destructive group-hover:opacity-100`,children:(0,H.jsx)(es,{className:`size-3.5`})}),(0,H.jsxs)(`div`,{className:`p-2`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium truncate`,title:e.filename,children:e.filename}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:g0(e.size)})]})]})}function O0(){let{timezone:e}=ba(),t=(0,v.useRef)(null),{user:n}=_a(),r=n?.permissions??[],i=r.includes(`*`)||r.includes(`media:write`),a=r.includes(`*`)||r.includes(`media:delete`),[o,s]=(0,v.useState)([{id:null,name:`Media`}]),c=o[o.length-1].id,[l,u]=(0,v.useState)(1),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(``);(0,v.useEffect)(()=>{let e=setTimeout(()=>{m(d),u(1)},300);return()=>clearTimeout(e)},[d]),(0,v.useEffect)(()=>{u(1),f(``),m(``)},[c]);let{data:h,loading:g,refetch:_}=Ta(`/cms/admin/folders?parent_id=${c??``}`),{data:y,loading:b,refetch:x}=Ta(`/cms/admin/media?folder_id=${c??``}&page=${l}&limit=48${p?`&search=${encodeURIComponent(p)}`:``}`),S=(0,v.useCallback)(()=>{_(),x()},[_,x]),[C,w]=(0,v.useState)(!1),[T,E]=(0,v.useState)(null),[D,O]=(0,v.useState)(new Set),[k,A]=(0,v.useState)(null),[j,M]=(0,v.useState)(``),[N,P]=(0,v.useState)(``),[F,I]=(0,v.useState)(``),[L,R]=(0,v.useState)(!1),[ee,te]=(0,v.useState)(null),[ne,z]=(0,v.useState)(null),[B,re]=(0,v.useState)(null),[V,ie]=(0,v.useState)(null),[ae,oe]=(0,v.useState)(``),[se,ce]=(0,v.useState)(!1),[le,ue]=(0,v.useState)(``),[de,fe]=(0,v.useState)(!1),[pe,me]=(0,v.useState)(!1),{loading:he,error:ge,request:_e}=Eb(),{loading:ve,error:ye,request:be}=Eb();async function xe(e){if(e.some(({relativePath:e})=>e.endsWith(`.m3u8`))){let t=new FormData;for(let{file:n,relativePath:r}of e)t.append(`files`,n,r);c&&t.append(`folder_id`,c),t.append(`bundle`,`true`);let n=await fetch(`/cms/admin/media`,{method:`POST`,credentials:`include`,body:t});if(!n.ok){let e=await n.text(),t=`Upload failed.`;try{t=JSON.parse(e).error??t}catch{}throw Error(t)}}else await Promise.all(e.map(({file:e})=>p$(e,{folderId:c})))}async function Se(e){if(i&&!(!e||e.length===0)){w(!0),E(null);try{await xe(Array.from(e).map(e=>({file:e,relativePath:e.webkitRelativePath||e.name}))),S(),X.success(`Upload complete`)}catch(e){E(e instanceof Error?e.message:`Upload failed.`),X.error(`Upload failed`)}finally{w(!1),t.current&&(t.current.value=``)}}}async function Ce(e){if(!i)return;e.preventDefault();let t=Array.from(e.dataTransfer.items);if(!t.some(e=>typeof e.webkitGetAsEntry==`function`)){Se(e.dataTransfer.files);return}w(!0),E(null);try{let e=t.map(e=>e.webkitGetAsEntry()).filter(e=>e!==null);await xe((await Promise.all(e.map(C0))).flat()),S(),X.success(`Upload complete`)}catch(e){E(e instanceof Error?e.message:`Upload failed.`),X.error(`Upload failed`)}finally{w(!1)}}function we(e){s(t=>[...t,{id:e.id,name:e.name}]),O(new Set)}function Te(e){s(t=>t.slice(0,e+1)),O(new Set)}async function Ee(){if(i&&le.trim())try{await be(`/cms/admin/folders`,`POST`,{name:le.trim(),parent_id:c}),ce(!1),ue(``),_(),X.success(`Folder created`)}catch{X.error(`Could not create folder`)}}async function De(){if(i&&!(!V||!ae.trim()))try{await be(`/cms/admin/folders/${V.id}`,`PATCH`,{name:ae.trim()}),ie(null),_(),X.success(`Folder renamed`)}catch{X.error(`Could not rename folder`)}}async function Oe(){if(a&&B)try{await _e(`/cms/admin/folders/${B.id}`,`DELETE`),re(null),_(),X.success(`Folder deleted`)}catch{X.error(`Could not delete folder`)}}async function ke(){if(a&&ne)try{await _e(`/cms/admin/media/${ne.id}`,`DELETE`),z(null),x(),X.success(`File deleted`)}catch{X.error(`Could not delete file`)}}function Ae(e){O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function je(e){A(e),M(e.filename),P(e.alt??_0(e.filename)),I(e.caption??``),te(null)}function Me(e){if(!k)return;let t=Ie.findIndex(e=>e.id===k.id);if(t===-1)return;let n=Ie[t+e];n&&je(n)}async function Ne(){if(k){R(!0),te(null);try{let e=await fetch(`/cms/admin/media/${k.id}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({filename:j||k.filename,alt:N.trim()||null,caption:F.trim()||null})});if(!e.ok)throw Error(`Save failed.`);je(await e.json()),x(),X.success(`File updated`)}catch(e){te(e instanceof Error?e.message:`Save failed.`),X.error(`Could not update file`)}finally{R(!1)}}}function Pe(e){M(e);let t=_0(j),n=_0(e);(!N.trim()||N===t)&&P(n)}let Fe=h?.folders??[],Ie=y?.items??[],Le=k?Ie.findIndex(e=>e.id===k.id):-1,Re=Le>0,ze=Le!==-1&&Le<Ie.length-1,Be=[...Fe.map(e=>`folder:${e.id}`),...Ie.map(e=>e.id)];(0,v.useEffect)(()=>{if(!k)return;function e(e){e.key===`ArrowLeft`&&Re&&(e.preventDefault(),Me(-1)),e.key===`ArrowRight`&&ze&&(e.preventDefault(),Me(1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[k,Re,ze,Ie]);async function Ve(){if(a&&!pe){me(!0);try{await Promise.all([...[...D].filter(e=>e.startsWith(`folder:`)).map(e=>fetch(`/cms/admin/folders/${e.slice(7)}`,{method:`DELETE`,credentials:`include`})),...[...D].filter(e=>!e.startsWith(`folder:`)).map(e=>fetch(`/cms/admin/media/${e}`,{method:`DELETE`,credentials:`include`}))]),X.success(`Files deleted`),fe(!1),O(new Set),S()}catch{X.error(`Could not delete files`)}finally{me(!1)}}}let He=g||b,Ue=Fe.length===0&&Ie.length===0;return(0,H.jsxs)(`div`,{children:[(0,H.jsx)($b,{children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,H.jsx)(`h1`,{className:`text-2xl font-semibold -mt-2`,children:`Media Library`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsxs)(q,{variant:`outline`,onClick:()=>{ue(``),ce(!0)},disabled:!i,children:[(0,H.jsx)(po,{className:`size-4`}),`New folder`]}),(0,H.jsxs)(q,{onClick:()=>t.current?.click(),disabled:C||!i,children:[C?(0,H.jsx)(ex,{className:`size-4`}):(0,H.jsx)(as,{className:`size-4`}),C?`Uploading…`:`Upload`]})]})]})}),(0,H.jsxs)(`section`,{className:`mt-24`,children:[o.length>1&&(0,H.jsx)(l0,{className:`mb-4`,children:(0,H.jsx)(u0,{children:o.map((e,t)=>(0,H.jsxs)(v.Fragment,{children:[t>0&&(0,H.jsx)(m0,{}),(0,H.jsx)(d0,{children:t===o.length-1?(0,H.jsx)(p0,{children:t===0?(0,H.jsx)(bo,{className:`size-3.5`}):e.name}):(0,H.jsx)(f0,{asChild:!0,children:(0,H.jsx)(`button`,{onClick:()=>Te(t),children:t===0?(0,H.jsx)(bo,{className:`size-3.5`}):e.name})})})]},`${e.id??`root`}:${e.name}`))})}),(0,H.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 rounded-lg border border-border bg-muted/50 p-2`,children:[(0,H.jsxs)(`div`,{className:`relative max-w-72 w-full`,children:[(0,H.jsx)(Go,{className:`absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground pointer-events-none`}),(0,H.jsx)(J,{className:`pl-9 h-8 bg-background`,placeholder:`Search media…`,value:d,onChange:e=>f(e.target.value)})]}),!b&&y!=null&&(0,H.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[Ie.length,` / `,y.total,` `,y.total===1?`file`:`files`]}),(0,H.jsx)(`div`,{className:`ml-auto flex h-8 items-center gap-2`,children:D.size>0?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`span`,{className:`text-sm font-medium`,children:[D.size,` selected`]}),(0,H.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>O(new Set),children:`Clear`}),a&&(0,H.jsxs)(q,{variant:`destructive`,size:`sm`,disabled:pe,onClick:()=>fe(!0),children:[(0,H.jsx)(es,{className:`size-3.5`}),`Delete`]})]}):!Ue&&!He?(0,H.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors`,onClick:()=>O(new Set(Be)),children:[(0,H.jsx)(_k,{checked:!1,"aria-hidden":!0,className:`pointer-events-none`}),`Select all`]}):null})]}),(0,H.jsx)(`input`,{ref:t,type:`file`,multiple:!0,className:`hidden`,onChange:e=>Se(e.target.files)}),T&&(0,H.jsx)(`p`,{className:`mb-4 text-sm text-destructive`,children:T}),He?(0,H.jsx)(`div`,{className:`flex items-center gap-2 py-16 justify-center text-muted-foreground`,children:(0,H.jsx)(ex,{className:`size-5`})}):Ue?(0,H.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-lg border border-dashed py-20 text-center cursor-pointer hover:bg-muted/50 transition-colors`,onClick:()=>i&&t.current?.click(),onDragOver:e=>e.preventDefault(),onDrop:Ce,children:[(0,H.jsx)(as,{className:`size-8 text-muted-foreground mb-3`}),(0,H.jsx)(`p`,{className:`text-sm font-medium`,children:`Drop files or folders here, or click to upload`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Images, videos, audio, documents and more`})]}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-6`,onDragOver:e=>e.preventDefault(),onDrop:Ce,children:[Fe.length>0&&(0,H.jsx)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4`,children:Fe.map(e=>(0,H.jsx)(E0,{folder:e,onOpen:we,onDelete:re,onRename:e=>{ie(e),oe(e.name)},canDelete:a,canRename:i,selected:D.has(`folder:${e.id}`),onToggle:Ae},e.id))}),Ie.length>0&&(0,H.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6`,children:Ie.map(e=>(0,H.jsx)(D0,{item:e,onDelete:z,onPreview:je,canDelete:a,selected:D.has(e.id),onToggle:Ae},e.id))})]}),(y?.pages??0)>1&&(0,H.jsx)(`div`,{className:`mt-4`,children:(0,H.jsx)(zk,{className:`mx-0 w-auto justify-end`,children:(0,H.jsxs)(Bk,{children:[(0,H.jsx)(Vk,{children:(0,H.jsx)(Uk,{href:`#`,onClick:e=>{e.preventDefault(),l>1&&u(l-1)},"aria-disabled":l===1,className:l===1?`pointer-events-none opacity-50`:``})}),(0,H.jsx)(Vk,{children:(0,H.jsx)(Wk,{href:`#`,onClick:e=>{e.preventDefault(),l<(y?.pages??1)&&u(l+1)},"aria-disabled":l===(y?.pages??1),className:l===(y?.pages??1)?`pointer-events-none opacity-50`:``})})]})})}),(0,H.jsx)(vy,{open:!!k,onOpenChange:e=>{e||(A(null),te(null),I(``))},children:(0,H.jsxs)(Sy,{className:`sm:max-w-5xl max-h-[90vh] overflow-hidden p-0`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{className:`truncate px-6 pt-6 pr-12`,title:k?.filename,children:k?.filename})}),k&&(0,H.jsxs)(`div`,{className:`grid max-h-[calc(90vh-4rem)] min-h-0 gap-0 lg:grid-cols-[minmax(0,1fr)_320px]`,children:[(0,H.jsxs)(`div`,{className:`relative flex min-h-0 items-center justify-center overflow-hidden bg-muted/30 px-6 py-4`,children:[(0,H.jsx)(`div`,{className:`flex h-full w-full min-h-[280px] items-center justify-center overflow-hidden rounded-xl border bg-background/70 p-4`,children:(0,H.jsx)(T0,{item:k})}),(0,H.jsx)(q,{type:`button`,variant:`secondary`,size:`icon`,className:`absolute left-8 top-1/2 size-10 -translate-y-1/2 rounded-full shadow-sm`,onClick:()=>Me(-1),disabled:!Re,"aria-label":`Previous file`,children:(0,H.jsx)(Ga,{className:`size-4`})}),(0,H.jsx)(q,{type:`button`,variant:`secondary`,size:`icon`,className:`absolute right-8 top-1/2 size-10 -translate-y-1/2 rounded-full shadow-sm`,onClick:()=>Me(1),disabled:!ze,"aria-label":`Next file`,children:(0,H.jsx)(Ka,{className:`size-4`})})]}),(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-col border-t lg:border-l lg:border-t-0`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 border-b px-6 py-4 text-xs text-muted-foreground`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Type`}),(0,H.jsx)(`p`,{className:`break-all`,children:k.mime_type??`—`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Size`}),(0,H.jsx)(`p`,{children:g0(k.size??null)})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Dimensions`}),(0,H.jsx)(`p`,{children:k.width&&k.height?`${k.width} × ${k.height}`:`—`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`mb-1 font-medium text-foreground`,children:`Created`}),(0,H.jsx)(`p`,{children:ix(k.created_at,e)})]})]}),(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-6 py-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{className:`text-xs`,children:`Filename`}),(0,H.jsx)(J,{value:j,onChange:e=>Pe(e.target.value),placeholder:k.filename,className:`text-sm`,disabled:!i})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{className:`text-xs`,children:`Alt text`}),(0,H.jsx)(J,{value:N,onChange:e=>P(e.target.value),placeholder:_0(j||k.filename),className:`text-sm`,disabled:!i}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Defaulted from the filename without extension. You can override it.`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{className:`text-xs`,children:`Subtitle`}),(0,H.jsx)(zP,{value:F,onChange:e=>I(e.target.value),placeholder:`Used as figcaption in the frontend…`,className:`min-h-28 resize-none text-sm`,disabled:!i})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pt-2`,children:[(0,H.jsx)(`a`,{href:k.url,target:`_blank`,rel:`noreferrer`,download:k.filename,children:(0,H.jsxs)(q,{variant:`outline`,size:`sm`,type:`button`,children:[(0,H.jsx)(no,{className:`size-3.5`}),`Download`]})}),(0,H.jsx)(q,{type:`button`,size:`sm`,onClick:Ne,disabled:L||!i,children:L?`Saving…`:`Save`})]}),ee&&(0,H.jsx)(`p`,{className:`text-xs text-destructive`,children:ee})]})]})]})]})}),(0,H.jsx)(vy,{open:se,onOpenChange:e=>{e||ce(!1)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`New folder`})}),(0,H.jsx)(J,{placeholder:`Folder name`,value:le,onChange:e=>ue(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Ee()}}),ye&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:ye}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>ce(!1),children:`Cancel`}),(0,H.jsx)(q,{onClick:Ee,disabled:ve||!le.trim()||!i,children:ve?`Creating…`:`Create`})]})]})}),(0,H.jsx)(vy,{open:!!V,onOpenChange:e=>{e||ie(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Rename folder`})}),(0,H.jsx)(J,{value:ae,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`&&De()}}),ye&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:ye}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>ie(null),children:`Cancel`}),(0,H.jsx)(q,{onClick:De,disabled:ve||!ae.trim()||!i,children:ve?`Saving…`:`Save`})]})]})}),(0,H.jsx)(vy,{open:!!ne,onOpenChange:e=>{e||z(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Delete file`})}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Are you sure you want to delete`,` `,(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:ne?.filename}),`? This action cannot be undone.`]}),ge&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:ge}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>z(null),children:`Cancel`}),(0,H.jsx)(q,{variant:`destructive`,onClick:ke,disabled:he||!a,children:he?`Deleting…`:`Delete`})]})]})}),(0,H.jsx)(vy,{open:!!B,onOpenChange:e=>{e||re(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Delete folder`})}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Are you sure you want to delete`,` `,(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:B?.name}),`? The folder must be empty.`]}),ge&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:ge}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>re(null),children:`Cancel`}),(0,H.jsx)(q,{variant:`destructive`,onClick:Oe,disabled:he||!a,children:he?`Deleting…`:`Delete`})]})]})}),(0,H.jsx)(vy,{open:de,onOpenChange:e=>{e||fe(!1)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsxs)(Ty,{children:[`Delete `,D.size,` `,D.size===1?`item`:`items`,`?`]})}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This action cannot be undone. Non-empty folders will be skipped.`}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>fe(!1),children:`Cancel`}),(0,H.jsxs)(q,{variant:`destructive`,onClick:Ve,disabled:pe,children:[pe?(0,H.jsx)(ex,{className:`size-4`}):null,`Delete`]})]})]})})]})]})}var k0=`plank:addons-registry-updated`,A0=new Map;function j0(e){return e.installed&&e.enabled&&e.compatible&&e.hasAdminUi}function M0(){window.dispatchEvent(new CustomEvent(k0))}async function N0(e){let t=window.PlankAddonAdminModules?.[e];if(t)return t;let n=A0.get(e);if(n)return n;let r=new Promise((t,n)=>{let r=document.createElement(`script`);r.src=`/cms/admin/addons/${e}/admin-entry.js`,r.async=!0,r.dataset.plankAddonId=e,r.onload=()=>{t(window.PlankAddonAdminModules?.[e]??null)},r.onerror=()=>{r.remove(),A0.delete(e),n(Error(`Could not load admin runtime for ${e}`))},document.head.appendChild(r)});return A0.set(e,r),r}function P0({items:e}){let{pathname:t}=lr();function n(e){return t===e||t.startsWith(e+`/`)}return(0,H.jsx)(`nav`,{className:`flex flex-col gap-0.5 p-2`,children:e.map(({label:e,to:t,icon:r})=>(0,H.jsxs)(Ji,{to:t,className:[`flex items-center gap-2.5 rounded-md px-2.5 py-1.5 text-sm transition-colors`,n(t)?`bg-sidebar-accent text-sidebar-accent-foreground font-medium`:`text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-accent-foreground`].join(` `),children:[r&&(0,H.jsx)(r,{className:`size-3.5 shrink-0`}),(0,H.jsx)(`span`,{className:`truncate`,children:e})]},t))})}function F0(){let{data:e,refetch:t}=Ta(`/cms/admin/addons/registry`);(0,v.useEffect)(()=>{function e(){t()}return window.addEventListener(k0,e),()=>window.removeEventListener(k0,e)},[t]);let n=(e?.addons??[]).filter(j0),r=new Map((e?.slots.addonsSections??[]).map(e=>[e.addonId,e.title])),i=[{label:`Overview`,to:`/add-ons/overview`,icon:za},...n.map(e=>({label:r.get(e.id)??e.name,to:`/add-ons/${e.id}`,icon:Ro}))];return(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`div`,{className:`border-b border-sidebar-border px-4 py-3`,children:(0,H.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Add-ons`})}),(0,H.jsx)(P0,{items:i})]})}function I0(){return LT((0,H.jsx)(F0,{})),(0,H.jsx)($r,{})}function L0(e,t){return e?.permissions.includes(`*`)||e?.permissions.includes(t)||!1}function R0(){let{user:e}=_a(),t=[{label:`Overview`,to:`/settings/overview`,icon:Ko,permission:`settings:overview:read`},{label:`Users`,to:`/settings/users`,icon:cs,permission:`settings:users:read`},{label:`Roles`,to:`/settings/roles`,icon:qo,permission:`settings:roles:read`},{label:`API Tokens`,to:`/settings/api-tokens`,icon:wo,permission:`settings:api-tokens:read`},{label:`Webhooks`,to:`/settings/webhooks`,icon:ls,permission:`settings:webhooks:read`}].filter(({permission:t})=>L0(e,t));return(0,H.jsxs)(`div`,{className:`flex flex-col`,children:[(0,H.jsx)(`div`,{className:`border-b border-sidebar-border px-4 py-3`,children:(0,H.jsx)(`p`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Settings`})}),(0,H.jsx)(P0,{items:t})]})}function z0(){return LT((0,H.jsx)(R0,{})),(0,H.jsx)($r,{})}function B0(){let{addonId:e=``}=gr(),{data:t,loading:n}=Ta(`/cms/admin/addons/registry`),{data:r,loading:i}=Ta(e?`/cms/admin/addons/${e}/admin-module`:null),{data:a,loading:o,refetch:s}=Ta(e?`/cms/admin/addons/${e}/settings`:null),{data:c,loading:l}=Ta(`/cms/admin/content-types`),{request:u}=Eb(),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),_=t?.addons.find(t=>t.id===e)??null,y=(t?.slots.addonsSections??[]).filter(t=>t.addonId===e),b=(t?.slots.dashboardWidgets??[]).filter(t=>t.addonId===e);(0,v.useEffect)(()=>{if(!_||!j0(_)){f(null),g(null),m(!1);return}let e=!0;return m(!0),g(null),N0(_.id).then(t=>{e&&(f(t),t||g(`This add-on did not register an admin runtime.`))}).catch(t=>{e&&(f(null),g(t instanceof Error?t.message:`Could not load add-on admin runtime`))}).finally(()=>{e&&m(!1)}),()=>{e=!1}},[_]);let x=(0,v.useCallback)(async t=>{try{let n=await u(`/cms/admin/addons/${e}/settings`,`PUT`,t);return s(),X.success(`Add-on settings saved`),n}catch(e){throw X.error(e instanceof Error?e.message:`Could not save add-on settings`),e}},[e,s,u]),S=(0,v.useCallback)(async(t,n)=>(await u(`/cms/admin/addons/${e}/actions`,`POST`,{action:t,input:n})).result,[e,u]);if(n)return(0,H.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,H.jsx)(ex,{className:`size-8`})});if(!_)return(0,H.jsx)(`section`,{className:`mt-24`,children:(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Vo,{})}),(0,H.jsx)(WT,{children:`Add-on not found`}),(0,H.jsx)(GT,{children:`This add-on is not present in the current registry.`})]})})});let C=!!d?.DashboardPage,w=!!d?.AdminPage,T=C?`dashboard`:w?`admin`:`details`;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)($b,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:_.name}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:_.packageName})]}),(0,H.jsxs)(`section`,{className:`mt-24 space-y-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(dT,{variant:_.enabled?`secondary`:`outline`,children:_.enabled?`Enabled`:`Disabled`}),(0,H.jsx)(dT,{variant:_.compatible?`secondary`:`destructive`,children:_.compatible?`Compatible`:`Incompatible`})]}),(0,H.jsxs)(Qj,{defaultValue:T,children:[(0,H.jsxs)($j,{className:`mb-6`,children:[C&&(0,H.jsx)(eM,{value:`dashboard`,children:`Dashboard`}),w&&(0,H.jsx)(eM,{value:`admin`,children:`Admin`}),(0,H.jsx)(eM,{value:`details`,children:`Details`})]}),C&&(0,H.jsx)(tM,{value:`dashboard`,className:`space-y-4`,children:j0(_)?i||o||l||p?(0,H.jsx)(`div`,{className:`flex h-40 items-center justify-center rounded-lg border bg-background`,children:(0,H.jsx)(ex,{className:`size-6`})}):r&&a&&d?.DashboardPage?(0,H.jsx)(d.DashboardPage,{addon:_,definition:r,settings:a,contentTypes:c??[],runAction:S,saveSettings:x}):(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Ko,{})}),(0,H.jsx)(WT,{children:`Dashboard runtime unavailable`}),(0,H.jsx)(GT,{children:h??`This add-on does not expose a mountable dashboard runtime yet.`})]})}):(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Ko,{})}),(0,H.jsx)(WT,{children:`Dashboard unavailable`}),(0,H.jsx)(GT,{children:`Enable the add-on and make sure it exposes an admin entry before mounting its dashboard surface.`})]})})}),w&&(0,H.jsx)(tM,{value:`admin`,className:`space-y-4`,children:j0(_)?i||o||l||p?(0,H.jsx)(`div`,{className:`flex h-40 items-center justify-center rounded-lg border bg-background`,children:(0,H.jsx)(ex,{className:`size-6`})}):r&&a&&d?.AdminPage?(0,H.jsx)(d.AdminPage,{addon:_,definition:r,settings:a,contentTypes:c??[],runAction:S,saveSettings:x}):(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Ko,{})}),(0,H.jsx)(WT,{children:`Admin runtime unavailable`}),(0,H.jsx)(GT,{children:h??`This add-on does not expose a mountable admin runtime yet.`})]})}):(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Ko,{})}),(0,H.jsx)(WT,{children:`Admin view unavailable`}),(0,H.jsx)(GT,{children:`Enable the add-on and make sure it exposes an admin entry before mounting its admin surface.`})]})})}),(0,H.jsx)(tM,{value:`details`,children:(0,H.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,H.jsxs)(fT,{className:`bg-background`,children:[(0,H.jsx)(pT,{children:(0,H.jsx)(mT,{children:r?.title??`Metadata`})}),(0,H.jsxs)(gT,{className:`space-y-3 text-sm`,children:[r?.description&&(0,H.jsx)(`p`,{className:`text-muted-foreground`,children:r.description}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-muted-foreground`,children:`Version`}),(0,H.jsx)(`div`,{className:`font-medium`,children:_.version||`Unknown version`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-muted-foreground`,children:`Settings Namespace`}),(0,H.jsx)(`div`,{className:`font-medium`,children:_.settingsNamespace??`None`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-muted-foreground`,children:`State`}),(0,H.jsxs)(`div`,{className:`font-medium`,children:[_.installed?`Installed`:`Missing`,` · `,_.enabled?`Enabled`:`Disabled`]})]})]})]}),(0,H.jsxs)(fT,{className:`bg-background`,children:[(0,H.jsx)(pT,{children:(0,H.jsx)(mT,{children:`Slot Registration`})}),(0,H.jsxs)(gT,{className:`space-y-2`,children:[y.length>0?y.map(e=>(0,H.jsxs)(`div`,{className:`rounded-md border bg-background px-3 py-2 text-sm`,children:[(0,H.jsx)(`div`,{className:`font-medium`,children:`Section`}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.slotId})]},e.slotId)):(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No section slots registered.`}),b.length>0?b.map(e=>(0,H.jsxs)(`div`,{className:`rounded-md border bg-background px-3 py-2 text-sm`,children:[(0,H.jsx)(`div`,{className:`font-medium`,children:`Widget`}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.slotId})]},e.slotId)):(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No widget slots registered.`})]})]})]})})]},T)]})]})}function V0({children:e,variant:t}){return(0,H.jsx)(dT,{variant:t,children:e})}function H0(){let{data:e,loading:t,error:n,refetch:r}=Ta(`/cms/admin/addons/registry`),{request:i,loading:a}=Eb(),[o,s]=(0,v.useState)(null),c=e?.addons??[],l=(0,v.useMemo)(()=>({total:c.length,enabled:c.filter(e=>e.enabled).length,compatible:c.filter(e=>e.compatible).length,visibleAdmin:c.filter(j0).length}),[c]);async function u(e,t){s(e);try{await i(`/cms/admin/addons/${e}/${t?`disable`:`enable`}`,`POST`),r(),M0(),X.success(t?`Add-on disabled`:`Add-on enabled`)}catch(e){X.error(e instanceof Error?e.message:`Could not update add-on`)}finally{s(null)}}return t?(0,H.jsx)(`div`,{className:`flex h-full items-center justify-center`,children:(0,H.jsx)(ex,{className:`size-8`})}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)($b,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:`Add-ons`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Registry, activation state and admin surface for official extensions.`})]}),(0,H.jsxs)(`section`,{className:`mt-24 space-y-6`,children:[(0,H.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{className:`flex flex-row items-center justify-between space-y-0`,children:[(0,H.jsx)(mT,{className:`text-sm font-medium`,children:`Detected`}),(0,H.jsx)(Vo,{className:`size-4 text-muted-foreground`})]}),(0,H.jsx)(gT,{children:(0,H.jsx)(`div`,{className:`text-2xl font-semibold`,children:l.total})})]}),(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{className:`flex flex-row items-center justify-between space-y-0`,children:[(0,H.jsx)(mT,{className:`text-sm font-medium`,children:`Enabled`}),(0,H.jsx)(Lo,{className:`size-4 text-muted-foreground`})]}),(0,H.jsx)(gT,{children:(0,H.jsx)(`div`,{className:`text-2xl font-semibold`,children:l.enabled})})]}),(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{className:`flex flex-row items-center justify-between space-y-0`,children:[(0,H.jsx)(mT,{className:`text-sm font-medium`,children:`Compatible`}),(0,H.jsx)(za,{className:`size-4 text-muted-foreground`})]}),(0,H.jsx)(gT,{children:(0,H.jsx)(`div`,{className:`text-2xl font-semibold`,children:l.compatible})})]}),(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{className:`flex flex-row items-center justify-between space-y-0`,children:[(0,H.jsx)(mT,{className:`text-sm font-medium`,children:`Admin UI`}),(0,H.jsx)(Ko,{className:`size-4 text-muted-foreground`})]}),(0,H.jsx)(gT,{children:(0,H.jsx)(`div`,{className:`text-2xl font-semibold`,children:l.visibleAdmin})})]})]}),c.length===0?(0,H.jsx)(BT,{className:`border`,children:(0,H.jsxs)(VT,{children:[(0,H.jsx)(UT,{variant:`icon`,children:(0,H.jsx)(Vo,{})}),(0,H.jsx)(WT,{children:`No add-ons detected`}),(0,H.jsx)(GT,{children:"Install an official `@plank-cms/addon-*` package in the host project and restart the server to populate this registry."})]})}):(0,H.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:(0,H.jsxs)(DT,{className:`w-full text-sm`,children:[(0,H.jsxs)(OT,{className:`border-b border-border font-bold uppercase`,children:[(0,H.jsx)(AT,{className:`hover:bg-transparent`,children:(0,H.jsx)(jT,{colSpan:5,className:`h-auto px-4 py-3`,children:(0,H.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Registry`})})}),(0,H.jsxs)(AT,{className:`border-t border-border hover:bg-transparent`,children:[(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:`Add-on`}),(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:`Package`}),(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:`Status`}),(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:`Settings`}),(0,H.jsx)(jT,{className:`w-28 px-4 py-3 text-right font-medium text-muted-foreground`,children:`Enabled`})]})]}),(0,H.jsx)(kT,{children:c.map(e=>{let t=a&&o===e.id,n=e.installed&&e.compatible;return(0,H.jsxs)(AT,{children:[(0,H.jsx)(MT,{children:(0,H.jsxs)(`div`,{className:`space-y-1`,children:[(0,H.jsx)(`div`,{className:`font-medium`,children:e.name}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.version||`Unknown version`}),e.description&&(0,H.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:e.description})]})}),(0,H.jsx)(MT,{className:`font-mono text-xs`,children:e.packageName}),(0,H.jsx)(MT,{children:(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsx)(V0,{variant:e.installed?`secondary`:`outline`,children:e.installed?`Installed`:`Missing`}),(0,H.jsx)(V0,{variant:e.compatible?`secondary`:`destructive`,children:e.compatible?`Compatible`:`Incompatible`})]})}),(0,H.jsx)(MT,{children:e.settingsNamespace?(0,H.jsx)(dT,{variant:`outline`,children:e.settingsNamespace}):(0,H.jsx)(`span`,{className:`text-muted-foreground`,children:`None`})}),(0,H.jsx)(MT,{className:`text-right`,children:(0,H.jsxs)(`div`,{className:`inline-flex items-center gap-3`,children:[t&&(0,H.jsx)(ex,{className:`size-4`}),(0,H.jsx)(uk,{checked:e.enabled,disabled:!n||t,onCheckedChange:()=>u(e.id,e.enabled)})]})})]},e.id)})})]})}),n&&(0,H.jsxs)(`p`,{className:`text-sm text-destructive`,children:[`Could not load add-ons registry: `,n]})]})]})}var U0=`••••••••`;function W0({values:e,onChange:t,disabled:n=!1}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`local-uploads-dir`,children:`Upload directory`}),(0,H.jsx)(J,{id:`local-uploads-dir`,placeholder:`public/uploads`,value:e[`local.uploads_dir`]??``,onChange:e=>t(`local.uploads_dir`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Path on disk where files are stored. Relative to the server working directory.`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`local-public-url`,children:`Public URL`}),(0,H.jsx)(J,{id:`local-public-url`,placeholder:`http://localhost:1337`,value:e[`local.public_url`]??``,onChange:e=>t(`local.public_url`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Base URL used to build file URLs. Should match the server's public address.`})]})]})}function G0({id:e,label:t,fieldKey:n,values:r,onChange:i,placeholder:a,disabled:o=!1}){let[s,c]=(0,v.useState)(!1),l=r[n]===U0,u=r[n]??``;return(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:e,children:t}),(0,H.jsxs)(`div`,{className:`relative`,children:[(0,H.jsx)(J,{id:e,type:s?`text`:`password`,placeholder:l?`Leave blank to keep current value`:a,value:l?``:u,onChange:e=>i(n,e.target.value),className:`pr-9`,disabled:o}),(0,H.jsx)(`button`,{type:`button`,className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>c(e=>!e),tabIndex:-1,disabled:o,children:s?(0,H.jsx)(io,{className:`size-4`}):(0,H.jsx)(ao,{className:`size-4`})})]}),l&&(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`A value is already saved. Enter a new one to replace it.`})]})}function K0({values:e,onChange:t,disabled:n=!1}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-access-key`,children:`Access key ID`}),(0,H.jsx)(J,{id:`s3-access-key`,placeholder:`AKIAIOSFODNN7EXAMPLE`,value:e[`s3.access_key_id`]??``,onChange:e=>t(`s3.access_key_id`,e.target.value),disabled:n})]}),(0,H.jsx)(G0,{id:`s3-secret-key`,label:`Secret access key`,fieldKey:`s3.secret_access_key`,values:e,onChange:t,disabled:n})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-region`,children:`Region`}),(0,H.jsx)(J,{id:`s3-region`,placeholder:`us-east-1`,value:e[`s3.region`]??``,onChange:e=>t(`s3.region`,e.target.value),disabled:n})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-bucket`,children:`Bucket`}),(0,H.jsx)(J,{id:`s3-bucket`,placeholder:`my-bucket`,value:e[`s3.bucket`]??``,onChange:e=>t(`s3.bucket`,e.target.value),disabled:n})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-path-prefix`,children:`Path prefix`}),(0,H.jsx)(J,{id:`s3-path-prefix`,placeholder:`cms/media`,value:e[`s3.path_prefix`]??``,onChange:e=>t(`s3.path_prefix`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. Shared bucket subfolder.`})]})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`s3-public-url`,children:`Public URL`}),(0,H.jsx)(J,{id:`s3-public-url`,placeholder:`https://cdn.example.com`,value:e[`s3.public_url`]??``,onChange:e=>t(`s3.public_url`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. Leave blank to use the default S3 URL.`})]})]})}function q0({values:e,onChange:t,disabled:n=!1}){return(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`r2-access-key`,children:`Access key ID`}),(0,H.jsx)(J,{id:`r2-access-key`,placeholder:`R2 access key ID`,value:e[`r2.access_key_id`]??``,onChange:e=>t(`r2.access_key_id`,e.target.value),disabled:n})]}),(0,H.jsx)(G0,{id:`r2-secret-key`,label:`Secret access key`,fieldKey:`r2.secret_access_key`,values:e,onChange:t,disabled:n})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`r2-bucket`,children:`Bucket`}),(0,H.jsx)(J,{id:`r2-bucket`,placeholder:`my-bucket`,value:e[`r2.bucket`]??``,onChange:e=>t(`r2.bucket`,e.target.value),disabled:n})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`r2-path-prefix`,children:`Path prefix`}),(0,H.jsx)(J,{id:`r2-path-prefix`,placeholder:`cms/media`,value:e[`r2.path_prefix`]??``,onChange:e=>t(`r2.path_prefix`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. Shared bucket subfolder.`})]})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsxs)(Y,{htmlFor:`r2-public-url`,children:[`Public URL `,(0,H.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,H.jsx)(J,{id:`r2-public-url`,placeholder:`https://assets.example.com`,value:e[`r2.public_url`]??``,onChange:e=>t(`r2.public_url`,e.target.value),disabled:n}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Required. R2 does not generate public URLs automatically.`})]})]})}function J0(){let{user:e}=_a(),{data:t,loading:n}=Ta(`/cms/admin/settings/media`),{loading:r,error:i,request:a}=Eb(),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(!1),u=o??t??{provider:`local`},d=u.provider||`local`,f=e?.permissions??[],p=f.includes(`*`)||f.includes(`settings:overview:write`);function m(e,t){s({...u,[e]:t})}function h(e){s({...u,provider:e})}async function g(e){e.preventDefault();try{await a(`/cms/admin/settings/media`,`PUT`,u),l(!0),setTimeout(()=>l(!1),2500),X.success(`Media settings saved`)}catch{X.error(`Could not save media settings`)}}return n?(0,H.jsxs)(`div`,{className:`flex items-center gap-2 py-8 text-muted-foreground`,children:[(0,H.jsx)(ex,{className:`size-4`}),(0,H.jsx)(`span`,{className:`text-sm`,children:`Loading settings…`})]}):(0,H.jsxs)(`form`,{onSubmit:g,className:`space-y-8`,children:[(0,H.jsxs)(`div`,{className:`border-b pb-4`,children:[(0,H.jsx)(`h2`,{className:`text-2xl font-semibold`,children:`Storage`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure where uploaded files are stored.`})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`provider`,children:`Storage provider`}),(0,H.jsxs)(_T,{value:d,onValueChange:e=>h(e),children:[(0,H.jsx)(bT,{id:`provider`,disabled:!p,children:(0,H.jsx)(yT,{})}),(0,H.jsxs)(CT,{children:[(0,H.jsx)(TT,{value:`local`,children:`Local`}),(0,H.jsx)(TT,{value:`s3`,children:`Amazon S3`}),(0,H.jsx)(TT,{value:`r2`,children:`Cloudflare R2`})]})]})]}),d===`r2`&&(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`r2-account-id`,children:`Account ID`}),(0,H.jsx)(J,{id:`r2-account-id`,placeholder:`023e105f4ecef8ad9ca31a8372d0c353`,value:u[`r2.account_id`]??``,onChange:e=>m(`r2.account_id`,e.target.value),disabled:!p}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Found in the Cloudflare dashboard under R2 > Overview.`})]})]}),(0,H.jsxs)(`div`,{className:`border-t pt-6`,children:[d===`local`&&(0,H.jsx)(W0,{values:u,onChange:m,disabled:!p}),d===`s3`&&(0,H.jsx)(K0,{values:u,onChange:m,disabled:!p}),d===`r2`&&(0,H.jsx)(q0,{values:u,onChange:m,disabled:!p})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(q,{type:`submit`,disabled:r||!p,children:r?`Saving…`:`Save`}),c&&(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Changes saved.`}),i&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:i})]})]})}var Y0={name:`@plank-cms/admin`,version:`0.28.2`,type:`module`,scripts:{build:`vite build`,dev:`vite`,lint:`eslint src/`},dependencies:{"@dnd-kit/core":`6.3.1`,"@dnd-kit/sortable":`10.0.0`,"@dnd-kit/utilities":`3.2.2`,"@radix-ui/react-avatar":`1.1.11`,"@radix-ui/react-checkbox":`1.3.3`,"@radix-ui/react-dialog":`1.1.15`,"@radix-ui/react-dropdown-menu":`2.1.16`,"@radix-ui/react-label":`2.1.8`,"@radix-ui/react-popover":`1.1.15`,"@radix-ui/react-select":`2.2.6`,"@radix-ui/react-separator":`1.1.8`,"@radix-ui/react-slot":`1.2.4`,"@radix-ui/react-switch":`1.2.6`,"@radix-ui/react-tabs":`1.1.13`,"@radix-ui/react-tooltip":`1.2.8`,"@tanstack/react-table":`8.21.3`,"@tiptap/extension-image":`3.22.4`,"@tiptap/pm":`3.22.4`,"@tiptap/react":`3.22.4`,"@tiptap/starter-kit":`3.22.4`,"class-variance-authority":`0.7.1`,clsx:`2.1.1`,cmdk:`1.1.1`,"date-fns":`4.1.0`,"hls.js":`1.6.16`,"input-otp":`1.4.2`,"lucide-react":`1.8.0`,"next-themes":`0.4.6`,"qrcode.react":`4.2.0`,"radix-ui":`1.4.3`,react:`19.2.5`,"react-day-picker":`9.14.0`,"react-dom":`19.2.5`,"react-router-dom":`7.14.1`,sonner:`2.0.7`,"tailwind-merge":`3.5.0`},devDependencies:{"@tailwindcss/vite":`4.2.3`,"@types/react":`19.2.14`,"@types/react-dom":`19.2.3`,"@types/react-router-dom":`5.3.3`,"@vitejs/plugin-react":`6.0.1`,tailwindcss:`4.2.3`,vite:`8.0.9`}},X0=[{value:`UTC`,label:`UTC — Coordinated Universal Time`},{value:`America/New_York`,label:`America/New_York — Eastern Time (UTC-5/4)`},{value:`America/Chicago`,label:`America/Chicago — Central Time (UTC-6/5)`},{value:`America/Denver`,label:`America/Denver — Mountain Time (UTC-7/6)`},{value:`America/Los_Angeles`,label:`America/Los_Angeles — Pacific Time (UTC-8/7)`},{value:`America/Anchorage`,label:`America/Anchorage — Alaska Time (UTC-9/8)`},{value:`America/Honolulu`,label:`America/Honolulu — Hawaii Time (UTC-10)`},{value:`America/Mexico_City`,label:`America/Mexico_City — Mexico City (UTC-6/5)`},{value:`America/El_Salvador`,label:`America/El_Salvador — El Salvador (UTC-6)`},{value:`America/Bogota`,label:`America/Bogota — Colombia Time (UTC-5)`},{value:`America/Lima`,label:`America/Lima — Peru Time (UTC-5)`},{value:`America/Santiago`,label:`America/Santiago — Chile Time (UTC-4/3)`},{value:`America/Argentina/Buenos_Aires`,label:`America/Buenos_Aires — Argentina (UTC-3)`},{value:`America/Sao_Paulo`,label:`America/Sao_Paulo — Brasília Time (UTC-3/2)`},{value:`Atlantic/Reykjavik`,label:`Atlantic/Reykjavik — Iceland (UTC+0)`},{value:`Europe/London`,label:`Europe/London — GMT/BST (UTC+0/1)`},{value:`Europe/Paris`,label:`Europe/Paris — Central European Time (UTC+1/2)`},{value:`Europe/Berlin`,label:`Europe/Berlin — Central European Time (UTC+1/2)`},{value:`Europe/Madrid`,label:`Europe/Madrid — Central European Time (UTC+1/2)`},{value:`Europe/Rome`,label:`Europe/Rome — Central European Time (UTC+1/2)`},{value:`Europe/Helsinki`,label:`Europe/Helsinki — Eastern European Time (UTC+2/3)`},{value:`Europe/Istanbul`,label:`Europe/Istanbul — Turkey Time (UTC+3)`},{value:`Europe/Moscow`,label:`Europe/Moscow — Moscow Standard Time (UTC+3)`},{value:`Asia/Dubai`,label:`Asia/Dubai — Gulf Standard Time (UTC+4)`},{value:`Asia/Karachi`,label:`Asia/Karachi — Pakistan Standard Time (UTC+5)`},{value:`Asia/Kolkata`,label:`Asia/Kolkata — India Standard Time (UTC+5:30)`},{value:`Asia/Dhaka`,label:`Asia/Dhaka — Bangladesh Standard Time (UTC+6)`},{value:`Asia/Bangkok`,label:`Asia/Bangkok — Indochina Time (UTC+7)`},{value:`Asia/Singapore`,label:`Asia/Singapore — Singapore Time (UTC+8)`},{value:`Asia/Shanghai`,label:`Asia/Shanghai — China Standard Time (UTC+8)`},{value:`Asia/Tokyo`,label:`Asia/Tokyo — Japan Standard Time (UTC+9)`},{value:`Asia/Seoul`,label:`Asia/Seoul — Korea Standard Time (UTC+9)`},{value:`Australia/Sydney`,label:`Australia/Sydney — AEST/AEDT (UTC+10/11)`},{value:`Australia/Melbourne`,label:`Australia/Melbourne — AEST/AEDT (UTC+10/11)`},{value:`Pacific/Auckland`,label:`Pacific/Auckland — New Zealand (UTC+12/13)`}];function Z0(){let{user:e}=_a(),{data:t,loading:n}=Ta(`/cms/admin/settings/general`),{request:r,loading:i}=Eb(),{request:a,loading:o}=Eb(),{request:s,loading:c}=Eb(),{refreshSettings:l}=ba(),[u,d]=(0,v.useState)(`UTC`),[f,p]=(0,v.useState)([]),[m,h]=(0,v.useState)(`en`),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(!1),x=e?.permissions??[],S=x.includes(`*`)||x.includes(`settings:overview:write`);(0,v.useEffect)(()=>{if(t?.timezone&&d(t.timezone),t?.locales)try{let e=JSON.parse(t.locales);Array.isArray(e)&&p(e)}catch{p((t.locales||``).split(`,`).map(e=>e.trim()).filter(Boolean))}t?.default_locale&&h(t.default_locale),b(String(t?.editorial_mode??`false`).toLowerCase()===`true`)},[t]);async function C(){try{await a(`/cms/admin/settings/general`,`PUT`,{locales:JSON.stringify(f),default_locale:m}),l(),X.success(`Locales saved`)}catch{X.error(`Could not save locales`)}}return n?(0,H.jsx)(ex,{}):(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsx)(fT,{children:(0,H.jsxs)(gT,{className:`flex items-center gap-4 py-2`,children:[(0,H.jsx)(`img`,{src:`/admin/plank-logo-w.svg`,alt:`Plank CMS`,className:`h-10 w-auto`}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`p`,{className:`font-bold`,children:`Plank CMS by AM25`}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Version `,Y0.version]})]})]})}),(0,H.jsxs)(`div`,{className:`border-b pb-4`,children:[(0,H.jsx)(`h2`,{className:`text-2xl font-semibold`,children:`Commons`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`General settings that apply across the CMS.`})]}),(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(Y,{htmlFor:`timezone`,children:`Timezone`}),(0,H.jsxs)(_T,{value:u,onValueChange:e=>{d(e),(async()=>{try{await r(`/cms/admin/settings/general`,`PUT`,{timezone:e}),l(),X.success(`Timezone saved`)}catch{X.error(`Could not save timezone`)}})()},children:[(0,H.jsx)(bT,{id:`timezone`,className:`w-full`,disabled:!S,children:(0,H.jsx)(yT,{})}),(0,H.jsx)(CT,{className:`max-h-72`,children:X0.map(e=>(0,H.jsx)(TT,{value:e.value,children:e.label},e.value))})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Used to display dates and times across the admin panel.`}),i&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Saving…`})]})]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 md:grid-cols-2`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{children:`Locales`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(J,{placeholder:`E.g. "en"`,value:g,onChange:e=>_(e.target.value),className:`h-9 w-full`,disabled:!S}),(0,H.jsx)(q,{variant:`outline`,className:`h-9`,disabled:!S,onClick:()=>{let e=g.trim().toLowerCase();e&&(f.includes(e)||p(t=>[...t,e]),_(``))},children:`Add`})]}),(0,H.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:f.map(e=>(0,H.jsx)(q,{variant:`ghost`,size:`sm`,onClick:()=>p(t=>t.filter(t=>t!==e)),disabled:!S,children:e.toUpperCase()},e))})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`default-locale`,children:`Default locale`}),(0,H.jsxs)(_T,{value:m,onValueChange:h,children:[(0,H.jsx)(bT,{id:`default-locale`,className:`w-full`,disabled:!S,children:(0,H.jsx)(yT,{})}),(0,H.jsx)(CT,{className:`max-h-72`,children:f.length===0?(0,H.jsx)(TT,{value:m,children:m}):f.map(e=>(0,H.jsx)(TT,{value:e,children:e.toUpperCase()},e))})]}),(0,H.jsx)(`div`,{className:`pt-2 flex justify-end`,children:(0,H.jsx)(q,{variant:`outline`,onClick:C,disabled:o||!S,children:o?`Saving…`:`Save`})})]})]}),(0,H.jsx)(Fk,{}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border p-3`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(Y,{htmlFor:`editorial-mode`,children:`Editorial Mode`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Enables Editor and Viewer workflows for editorial review.`})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsx)(uk,{id:`editorial-mode`,checked:y,onCheckedChange:e=>{b(e),(async()=>{try{await s(`/cms/admin/settings/general`,`PUT`,{editorial_mode:String(e)}),l(),X.success(`Editorial Mode saved`)}catch{X.error(`Could not save Editorial Mode`)}})()},disabled:!S}),c&&(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Saving…`})]})]})]})}function Q0(){let{user:e}=_a(),{data:t,loading:n}=Ta(`/cms/admin/settings/preview`),{request:r,loading:i}=Eb(),a=e?.permissions??[],o=a.includes(`*`)||a.includes(`settings:overview:write`),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(`slug`);(0,v.useEffect)(()=>{let e=e0(t);c(e.enabled),u(e.syncUrl),f(e.urlTemplate),m(e.slugField)},[t]);async function h(e){e.preventDefault();try{await r(`/cms/admin/settings/preview`,`PUT`,{enabled:String(s),sync_url:l.trim(),url_template:d.trim(),slug_field:p.trim()||`slug`}),X.success(`Preview settings saved`)}catch{X.error(`Could not save preview settings`)}}return n?(0,H.jsx)(ex,{}):(0,H.jsxs)(`div`,{className:`space-y-6`,children:[(0,H.jsxs)(`div`,{className:`border-b pb-4`,children:[(0,H.jsx)(`h2`,{className:`text-2xl font-semibold`,children:`Live Preview`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure a single frontend preview target that Plank can open and sync after saves.`})]}),(0,H.jsxs)(`form`,{onSubmit:h,className:`space-y-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border p-3`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(Y,{htmlFor:`preview-enabled`,children:`Enable preview integration`}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Shows the preview action in the entry editor and syncs a connected frontend tab.`})]}),(0,H.jsx)(uk,{id:`preview-enabled`,checked:s,onCheckedChange:c,disabled:!o})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`preview-sync-url`,children:`Preview sync webhook URL`}),(0,H.jsx)(J,{id:`preview-sync-url`,value:l,onChange:e=>u(e.target.value),placeholder:`https://frontend.example.com/api/plank/preview-sync`,disabled:!o}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Optional. When set, Plank will POST a preview sync payload to this endpoint on each entry save while preview is enabled.`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`preview-url-template`,children:`Preview URL template`}),(0,H.jsx)(J,{id:`preview-url-template`,value:d,onChange:e=>f(e.target.value),placeholder:`https://frontend.example.com/draft/{contentType}/{slug}`,disabled:!o}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Supported placeholders: `,`{contentType}`,`, `,`{entryId}`,`, `,`{slug}`,`, `,`{status}`,`. The final result must be an absolute URL.`]})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`preview-slug-field`,children:`Slug field`}),(0,H.jsx)(J,{id:`preview-slug-field`,value:p,onChange:e=>m(e.target.value),placeholder:`slug`,disabled:!o}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Used when the template contains `,`{slug}`,`. Defaults to `,(0,H.jsx)(`code`,{children:`slug`}),`.`]})]}),(0,H.jsxs)(`div`,{className:`rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[`Example: `,(0,H.jsxs)(`code`,{children:[`https://frontend.example.com/draft/`,`{contentType}`,`/`,`{slug}`]})]}),(0,H.jsx)(`div`,{className:`flex justify-end`,children:(0,H.jsx)(q,{type:`submit`,variant:`outline`,disabled:i||!o,children:i?`Saving…`:`Save`})})]})]})}function $0(){return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)($b,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:`Overview`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`General configuration for your CMS instance.`})]}),(0,H.jsxs)(Qj,{defaultValue:`general`,className:`mt-24`,children:[(0,H.jsxs)($j,{className:`mb-6`,children:[(0,H.jsx)(eM,{value:`general`,children:`General`}),(0,H.jsx)(eM,{value:`preview`,children:`Preview`}),(0,H.jsx)(eM,{value:`media`,children:`Media Library`})]}),(0,H.jsx)(tM,{value:`general`,children:(0,H.jsx)(Z0,{})}),(0,H.jsx)(tM,{value:`preview`,children:(0,H.jsx)(Q0,{})}),(0,H.jsx)(tM,{value:`media`,children:(0,H.jsx)(J0,{})})]})]})}function e2(e,t){return typeof e==`function`?e(t):e}function t2(e,t){return n=>{t.setState(t=>({...t,[e]:e2(n,t[e])}))}}function n2(e){return e instanceof Function}function r2(e){return Array.isArray(e)&&e.every(e=>typeof e==`number`)}function i2(e,t){let n=[],r=e=>{e.forEach(e=>{n.push(e);let i=t(e);i!=null&&i.length&&r(i)})};return r(e),n}function a2(e,t,n){let r=[],i;return a=>{let o;n.key&&n.debug&&(o=Date.now());let s=e(a);if(!(s.length!==r.length||s.some((e,t)=>r[t]!==e)))return i;r=s;let c;if(n.key&&n.debug&&(c=Date.now()),i=t(...s),n==null||n.onChange==null||n.onChange(i),n.key&&n.debug&&n!=null&&n.debug()){let e=Math.round((Date.now()-o)*100)/100,t=Math.round((Date.now()-c)*100)/100,r=t/16,i=(e,t)=>{for(e=String(e);e.length<t;)e=` `+e;return e};console.info(`%c⏱ ${i(t,5)} /${i(e,5)} ms`,`
220
220
  font-size: .6rem;
221
221
  font-weight: bold;
222
222
  color: hsl(${Math.max(0,Math.min(120-120*r,120))}deg 100% 31%);`,n?.key)}return i}}function o2(e,t,n,r){return{debug:()=>e?.debugAll??e[t],key:!1,onChange:r}}function s2(e,t,n,r){let i={id:`${t.id}_${n.id}`,row:t,column:n,getValue:()=>t.getValue(r),renderValue:()=>i.getValue()??e.options.renderFallbackValue,getContext:a2(()=>[e,n,t,i],(e,t,n,r)=>({table:e,column:t,row:n,cell:r,getValue:r.getValue,renderValue:r.renderValue}),o2(e.options,`debugCells`,`cell.getContext`))};return e._features.forEach(r=>{r.createCell==null||r.createCell(i,n,t,e)},{}),i}function c2(e,t,n,r){let i={...e._getDefaultColumnDef(),...t},a=i.accessorKey,o=i.id??(a?typeof String.prototype.replaceAll==`function`?a.replaceAll(`.`,`_`):a.replace(/\./g,`_`):void 0)??(typeof i.header==`string`?i.header:void 0),s;if(i.accessorFn?s=i.accessorFn:a&&(s=a.includes(`.`)?e=>{let t=e;for(let e of a.split(`.`))t=t?.[e];return t}:e=>e[i.accessorKey]),!o)throw Error();let c={id:`${String(o)}`,accessorFn:s,parent:r,depth:n,columnDef:i,columns:[],getFlatColumns:a2(()=>[!0],()=>[c,...c.columns?.flatMap(e=>e.getFlatColumns())],o2(e.options,`debugColumns`,`column.getFlatColumns`)),getLeafColumns:a2(()=>[e._getOrderColumnsFn()],e=>{var t;return(t=c.columns)!=null&&t.length?e(c.columns.flatMap(e=>e.getLeafColumns())):[c]},o2(e.options,`debugColumns`,`column.getLeafColumns`))};for(let t of e._features)t.createColumn==null||t.createColumn(c,e);return c}var l2=`debugHeaders`;function u2(e,t,n){let r={id:n.id??t.id,column:t,index:n.index,isPlaceholder:!!n.isPlaceholder,placeholderId:n.placeholderId,depth:n.depth,subHeaders:[],colSpan:0,rowSpan:0,headerGroup:null,getLeafHeaders:()=>{let e=[],t=n=>{n.subHeaders&&n.subHeaders.length&&n.subHeaders.map(t),e.push(n)};return t(r),e},getContext:()=>({table:e,header:r,column:t})};return e._features.forEach(t=>{t.createHeader==null||t.createHeader(r,e)}),r}var d2={createTable:e=>{e.getHeaderGroups=a2(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(t,n,r,i)=>{let a=r?.map(e=>n.find(t=>t.id===e)).filter(Boolean)??[],o=i?.map(e=>n.find(t=>t.id===e)).filter(Boolean)??[],s=n.filter(e=>!(r!=null&&r.includes(e.id))&&!(i!=null&&i.includes(e.id)));return f2(t,[...a,...s,...o],e)},o2(e.options,l2,`getHeaderGroups`)),e.getCenterHeaderGroups=a2(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(t,n,r,i)=>(n=n.filter(e=>!(r!=null&&r.includes(e.id))&&!(i!=null&&i.includes(e.id))),f2(t,n,e,`center`)),o2(e.options,l2,`getCenterHeaderGroups`)),e.getLeftHeaderGroups=a2(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left],(t,n,r)=>f2(t,r?.map(e=>n.find(t=>t.id===e)).filter(Boolean)??[],e,`left`),o2(e.options,l2,`getLeftHeaderGroups`)),e.getRightHeaderGroups=a2(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.right],(t,n,r)=>f2(t,r?.map(e=>n.find(t=>t.id===e)).filter(Boolean)??[],e,`right`),o2(e.options,l2,`getRightHeaderGroups`)),e.getFooterGroups=a2(()=>[e.getHeaderGroups()],e=>[...e].reverse(),o2(e.options,l2,`getFooterGroups`)),e.getLeftFooterGroups=a2(()=>[e.getLeftHeaderGroups()],e=>[...e].reverse(),o2(e.options,l2,`getLeftFooterGroups`)),e.getCenterFooterGroups=a2(()=>[e.getCenterHeaderGroups()],e=>[...e].reverse(),o2(e.options,l2,`getCenterFooterGroups`)),e.getRightFooterGroups=a2(()=>[e.getRightHeaderGroups()],e=>[...e].reverse(),o2(e.options,l2,`getRightFooterGroups`)),e.getFlatHeaders=a2(()=>[e.getHeaderGroups()],e=>e.map(e=>e.headers).flat(),o2(e.options,l2,`getFlatHeaders`)),e.getLeftFlatHeaders=a2(()=>[e.getLeftHeaderGroups()],e=>e.map(e=>e.headers).flat(),o2(e.options,l2,`getLeftFlatHeaders`)),e.getCenterFlatHeaders=a2(()=>[e.getCenterHeaderGroups()],e=>e.map(e=>e.headers).flat(),o2(e.options,l2,`getCenterFlatHeaders`)),e.getRightFlatHeaders=a2(()=>[e.getRightHeaderGroups()],e=>e.map(e=>e.headers).flat(),o2(e.options,l2,`getRightFlatHeaders`)),e.getCenterLeafHeaders=a2(()=>[e.getCenterFlatHeaders()],e=>e.filter(e=>{var t;return!((t=e.subHeaders)!=null&&t.length)}),o2(e.options,l2,`getCenterLeafHeaders`)),e.getLeftLeafHeaders=a2(()=>[e.getLeftFlatHeaders()],e=>e.filter(e=>{var t;return!((t=e.subHeaders)!=null&&t.length)}),o2(e.options,l2,`getLeftLeafHeaders`)),e.getRightLeafHeaders=a2(()=>[e.getRightFlatHeaders()],e=>e.filter(e=>{var t;return!((t=e.subHeaders)!=null&&t.length)}),o2(e.options,l2,`getRightLeafHeaders`)),e.getLeafHeaders=a2(()=>[e.getLeftHeaderGroups(),e.getCenterHeaderGroups(),e.getRightHeaderGroups()],(e,t,n)=>[...e[0]?.headers??[],...t[0]?.headers??[],...n[0]?.headers??[]].map(e=>e.getLeafHeaders()).flat(),o2(e.options,l2,`getLeafHeaders`))}};function f2(e,t,n,r){let i=0,a=function(e,t){t===void 0&&(t=1),i=Math.max(i,t),e.filter(e=>e.getIsVisible()).forEach(e=>{var n;(n=e.columns)!=null&&n.length&&a(e.columns,t+1)},0)};a(e);let o=[],s=(e,t)=>{let i={depth:t,id:[r,`${t}`].filter(Boolean).join(`_`),headers:[]},a=[];e.forEach(e=>{let o=[...a].reverse()[0],s=e.column.depth===i.depth,c,l=!1;if(s&&e.column.parent?c=e.column.parent:(c=e.column,l=!0),o&&o?.column===c)o.subHeaders.push(e);else{let i=u2(n,c,{id:[r,t,c.id,e?.id].filter(Boolean).join(`_`),isPlaceholder:l,placeholderId:l?`${a.filter(e=>e.column===c).length}`:void 0,depth:t,index:a.length});i.subHeaders.push(e),a.push(i)}i.headers.push(e),e.headerGroup=i}),o.push(i),t>0&&s(a,t-1)};s(t.map((e,t)=>u2(n,e,{depth:i,index:t})),i-1),o.reverse();let c=e=>e.filter(e=>e.column.getIsVisible()).map(e=>{let t=0,n=0,r=[0];e.subHeaders&&e.subHeaders.length?(r=[],c(e.subHeaders).forEach(e=>{let{colSpan:n,rowSpan:i}=e;t+=n,r.push(i)})):t=1;let i=Math.min(...r);return n+=i,e.colSpan=t,e.rowSpan=n,{colSpan:t,rowSpan:n}});return c(o[0]?.headers??[]),o}var p2=(e,t,n,r,i,a,o)=>{let s={id:t,index:r,original:n,depth:i,parentId:o,_valuesCache:{},_uniqueValuesCache:{},getValue:t=>{if(s._valuesCache.hasOwnProperty(t))return s._valuesCache[t];let n=e.getColumn(t);if(n!=null&&n.accessorFn)return s._valuesCache[t]=n.accessorFn(s.original,r),s._valuesCache[t]},getUniqueValues:t=>{if(s._uniqueValuesCache.hasOwnProperty(t))return s._uniqueValuesCache[t];let n=e.getColumn(t);if(n!=null&&n.accessorFn)return n.columnDef.getUniqueValues?(s._uniqueValuesCache[t]=n.columnDef.getUniqueValues(s.original,r),s._uniqueValuesCache[t]):(s._uniqueValuesCache[t]=[s.getValue(t)],s._uniqueValuesCache[t])},renderValue:t=>s.getValue(t)??e.options.renderFallbackValue,subRows:a??[],getLeafRows:()=>i2(s.subRows,e=>e.subRows),getParentRow:()=>s.parentId?e.getRow(s.parentId,!0):void 0,getParentRows:()=>{let e=[],t=s;for(;;){let n=t.getParentRow();if(!n)break;e.push(n),t=n}return e.reverse()},getAllCells:a2(()=>[e.getAllLeafColumns()],t=>t.map(t=>s2(e,s,t,t.id)),o2(e.options,`debugRows`,`getAllCells`)),_getAllCellsByColumnId:a2(()=>[s.getAllCells()],e=>e.reduce((e,t)=>(e[t.column.id]=t,e),{}),o2(e.options,`debugRows`,`getAllCellsByColumnId`))};for(let t=0;t<e._features.length;t++){let n=e._features[t];n==null||n.createRow==null||n.createRow(s,e)}return s},m2={createColumn:(e,t)=>{e._getFacetedRowModel=t.options.getFacetedRowModel&&t.options.getFacetedRowModel(t,e.id),e.getFacetedRowModel=()=>e._getFacetedRowModel?e._getFacetedRowModel():t.getPreFilteredRowModel(),e._getFacetedUniqueValues=t.options.getFacetedUniqueValues&&t.options.getFacetedUniqueValues(t,e.id),e.getFacetedUniqueValues=()=>e._getFacetedUniqueValues?e._getFacetedUniqueValues():new Map,e._getFacetedMinMaxValues=t.options.getFacetedMinMaxValues&&t.options.getFacetedMinMaxValues(t,e.id),e.getFacetedMinMaxValues=()=>{if(e._getFacetedMinMaxValues)return e._getFacetedMinMaxValues()}}},h2=(e,t,n)=>{var r,i;let a=n==null||(r=n.toString())==null?void 0:r.toLowerCase();return!!(!((i=e.getValue(t))==null||(i=i.toString())==null||(i=i.toLowerCase())==null)&&i.includes(a))};h2.autoRemove=e=>T2(e);var g2=(e,t,n)=>{var r;return!!(!((r=e.getValue(t))==null||(r=r.toString())==null)&&r.includes(n))};g2.autoRemove=e=>T2(e);var _2=(e,t,n)=>{var r;return((r=e.getValue(t))==null||(r=r.toString())==null?void 0:r.toLowerCase())===n?.toLowerCase()};_2.autoRemove=e=>T2(e);var v2=(e,t,n)=>e.getValue(t)?.includes(n);v2.autoRemove=e=>T2(e);var y2=(e,t,n)=>!n.some(n=>{var r;return!((r=e.getValue(t))!=null&&r.includes(n))});y2.autoRemove=e=>T2(e)||!(e!=null&&e.length);var b2=(e,t,n)=>n.some(n=>e.getValue(t)?.includes(n));b2.autoRemove=e=>T2(e)||!(e!=null&&e.length);var x2=(e,t,n)=>e.getValue(t)===n;x2.autoRemove=e=>T2(e);var S2=(e,t,n)=>e.getValue(t)==n;S2.autoRemove=e=>T2(e);var C2=(e,t,n)=>{let[r,i]=n,a=e.getValue(t);return a>=r&&a<=i};C2.resolveFilterValue=e=>{let[t,n]=e,r=typeof t==`number`?t:parseFloat(t),i=typeof n==`number`?n:parseFloat(n),a=t===null||Number.isNaN(r)?-1/0:r,o=n===null||Number.isNaN(i)?1/0:i;if(a>o){let e=a;a=o,o=e}return[a,o]},C2.autoRemove=e=>T2(e)||T2(e[0])&&T2(e[1]);var w2={includesString:h2,includesStringSensitive:g2,equalsString:_2,arrIncludes:v2,arrIncludesAll:y2,arrIncludesSome:b2,equals:x2,weakEquals:S2,inNumberRange:C2};function T2(e){return e==null||e===``}var E2={getDefaultColumnDef:()=>({filterFn:`auto`}),getInitialState:e=>({columnFilters:[],...e}),getDefaultOptions:e=>({onColumnFiltersChange:t2(`columnFilters`,e),filterFromLeafRows:!1,maxLeafRowFilterDepth:100}),createColumn:(e,t)=>{e.getAutoFilterFn=()=>{let n=t.getCoreRowModel().flatRows[0]?.getValue(e.id);return typeof n==`string`?w2.includesString:typeof n==`number`?w2.inNumberRange:typeof n==`boolean`||typeof n==`object`&&n?w2.equals:Array.isArray(n)?w2.arrIncludes:w2.weakEquals},e.getFilterFn=()=>n2(e.columnDef.filterFn)?e.columnDef.filterFn:e.columnDef.filterFn===`auto`?e.getAutoFilterFn():t.options.filterFns?.[e.columnDef.filterFn]??w2[e.columnDef.filterFn],e.getCanFilter=()=>(e.columnDef.enableColumnFilter??!0)&&(t.options.enableColumnFilters??!0)&&(t.options.enableFilters??!0)&&!!e.accessorFn,e.getIsFiltered=()=>e.getFilterIndex()>-1,e.getFilterValue=()=>{var n;return(n=t.getState().columnFilters)==null||(n=n.find(t=>t.id===e.id))==null?void 0:n.value},e.getFilterIndex=()=>t.getState().columnFilters?.findIndex(t=>t.id===e.id)??-1,e.setFilterValue=n=>{t.setColumnFilters(t=>{let r=e.getFilterFn(),i=t?.find(t=>t.id===e.id),a=e2(n,i?i.value:void 0);if(D2(r,a,e))return t?.filter(t=>t.id!==e.id)??[];let o={id:e.id,value:a};return i?t?.map(t=>t.id===e.id?o:t)??[]:t!=null&&t.length?[...t,o]:[o]})}},createRow:(e,t)=>{e.columnFilters={},e.columnFiltersMeta={}},createTable:e=>{e.setColumnFilters=t=>{let n=e.getAllLeafColumns();e.options.onColumnFiltersChange==null||e.options.onColumnFiltersChange(e=>e2(t,e)?.filter(e=>{let t=n.find(t=>t.id===e.id);return!(t&&D2(t.getFilterFn(),e.value,t))}))},e.resetColumnFilters=t=>{e.setColumnFilters(t?[]:e.initialState?.columnFilters??[])},e.getPreFilteredRowModel=()=>e.getCoreRowModel(),e.getFilteredRowModel=()=>(!e._getFilteredRowModel&&e.options.getFilteredRowModel&&(e._getFilteredRowModel=e.options.getFilteredRowModel(e)),e.options.manualFiltering||!e._getFilteredRowModel?e.getPreFilteredRowModel():e._getFilteredRowModel())}};function D2(e,t,n){return(e&&e.autoRemove?e.autoRemove(t,n):!1)||t===void 0||typeof t==`string`&&!t}var O2={sum:(e,t,n)=>n.reduce((t,n)=>{let r=n.getValue(e);return t+(typeof r==`number`?r:0)},0),min:(e,t,n)=>{let r;return n.forEach(t=>{let n=t.getValue(e);n!=null&&(r>n||r===void 0&&n>=n)&&(r=n)}),r},max:(e,t,n)=>{let r;return n.forEach(t=>{let n=t.getValue(e);n!=null&&(r<n||r===void 0&&n>=n)&&(r=n)}),r},extent:(e,t,n)=>{let r,i;return n.forEach(t=>{let n=t.getValue(e);n!=null&&(r===void 0?n>=n&&(r=i=n):(r>n&&(r=n),i<n&&(i=n)))}),[r,i]},mean:(e,t)=>{let n=0,r=0;if(t.forEach(t=>{let i=t.getValue(e);i!=null&&(i=+i)>=i&&(++n,r+=i)}),n)return r/n},median:(e,t)=>{if(!t.length)return;let n=t.map(t=>t.getValue(e));if(!r2(n))return;if(n.length===1)return n[0];let r=Math.floor(n.length/2),i=n.sort((e,t)=>e-t);return n.length%2==0?(i[r-1]+i[r])/2:i[r]},unique:(e,t)=>Array.from(new Set(t.map(t=>t.getValue(e))).values()),uniqueCount:(e,t)=>new Set(t.map(t=>t.getValue(e))).size,count:(e,t)=>t.length},k2={getDefaultColumnDef:()=>({aggregatedCell:e=>{var t;return((t=e.getValue())==null||t.toString==null?void 0:t.toString())??null},aggregationFn:`auto`}),getInitialState:e=>({grouping:[],...e}),getDefaultOptions:e=>({onGroupingChange:t2(`grouping`,e),groupedColumnMode:`reorder`}),createColumn:(e,t)=>{e.toggleGrouping=()=>{t.setGrouping(t=>t!=null&&t.includes(e.id)?t.filter(t=>t!==e.id):[...t??[],e.id])},e.getCanGroup=()=>(e.columnDef.enableGrouping??!0)&&(t.options.enableGrouping??!0)&&(!!e.accessorFn||!!e.columnDef.getGroupingValue),e.getIsGrouped=()=>t.getState().grouping?.includes(e.id),e.getGroupedIndex=()=>t.getState().grouping?.indexOf(e.id),e.getToggleGroupingHandler=()=>{let t=e.getCanGroup();return()=>{t&&e.toggleGrouping()}},e.getAutoAggregationFn=()=>{let n=t.getCoreRowModel().flatRows[0]?.getValue(e.id);if(typeof n==`number`)return O2.sum;if(Object.prototype.toString.call(n)===`[object Date]`)return O2.extent},e.getAggregationFn=()=>{if(!e)throw Error();return n2(e.columnDef.aggregationFn)?e.columnDef.aggregationFn:e.columnDef.aggregationFn===`auto`?e.getAutoAggregationFn():t.options.aggregationFns?.[e.columnDef.aggregationFn]??O2[e.columnDef.aggregationFn]}},createTable:e=>{e.setGrouping=t=>e.options.onGroupingChange==null?void 0:e.options.onGroupingChange(t),e.resetGrouping=t=>{e.setGrouping(t?[]:e.initialState?.grouping??[])},e.getPreGroupedRowModel=()=>e.getFilteredRowModel(),e.getGroupedRowModel=()=>(!e._getGroupedRowModel&&e.options.getGroupedRowModel&&(e._getGroupedRowModel=e.options.getGroupedRowModel(e)),e.options.manualGrouping||!e._getGroupedRowModel?e.getPreGroupedRowModel():e._getGroupedRowModel())},createRow:(e,t)=>{e.getIsGrouped=()=>!!e.groupingColumnId,e.getGroupingValue=n=>{if(e._groupingValuesCache.hasOwnProperty(n))return e._groupingValuesCache[n];let r=t.getColumn(n);return r!=null&&r.columnDef.getGroupingValue?(e._groupingValuesCache[n]=r.columnDef.getGroupingValue(e.original),e._groupingValuesCache[n]):e.getValue(n)},e._groupingValuesCache={}},createCell:(e,t,n,r)=>{e.getIsGrouped=()=>t.getIsGrouped()&&t.id===n.groupingColumnId,e.getIsPlaceholder=()=>!e.getIsGrouped()&&t.getIsGrouped(),e.getIsAggregated=()=>{var t;return!e.getIsGrouped()&&!e.getIsPlaceholder()&&!!((t=n.subRows)!=null&&t.length)}}};function A2(e,t,n){if(!(t!=null&&t.length)||!n)return e;let r=e.filter(e=>!t.includes(e.id));return n===`remove`?r:[...t.map(t=>e.find(e=>e.id===t)).filter(Boolean),...r]}var j2={getInitialState:e=>({columnOrder:[],...e}),getDefaultOptions:e=>({onColumnOrderChange:t2(`columnOrder`,e)}),createColumn:(e,t)=>{e.getIndex=a2(e=>[H2(t,e)],t=>t.findIndex(t=>t.id===e.id),o2(t.options,`debugColumns`,`getIndex`)),e.getIsFirstColumn=n=>H2(t,n)[0]?.id===e.id,e.getIsLastColumn=n=>{let r=H2(t,n);return r[r.length-1]?.id===e.id}},createTable:e=>{e.setColumnOrder=t=>e.options.onColumnOrderChange==null?void 0:e.options.onColumnOrderChange(t),e.resetColumnOrder=t=>{e.setColumnOrder(t?[]:e.initialState.columnOrder??[])},e._getOrderColumnsFn=a2(()=>[e.getState().columnOrder,e.getState().grouping,e.options.groupedColumnMode],(e,t,n)=>r=>{let i=[];if(!(e!=null&&e.length))i=r;else{let t=[...e],n=[...r];for(;n.length&&t.length;){let e=t.shift(),r=n.findIndex(t=>t.id===e);r>-1&&i.push(n.splice(r,1)[0])}i=[...i,...n]}return A2(i,t,n)},o2(e.options,`debugTable`,`_getOrderColumnsFn`))}},M2=()=>({left:[],right:[]}),N2={getInitialState:e=>({columnPinning:M2(),...e}),getDefaultOptions:e=>({onColumnPinningChange:t2(`columnPinning`,e)}),createColumn:(e,t)=>{e.pin=n=>{let r=e.getLeafColumns().map(e=>e.id).filter(Boolean);t.setColumnPinning(e=>n===`right`?{left:(e?.left??[]).filter(e=>!(r!=null&&r.includes(e))),right:[...(e?.right??[]).filter(e=>!(r!=null&&r.includes(e))),...r]}:n===`left`?{left:[...(e?.left??[]).filter(e=>!(r!=null&&r.includes(e))),...r],right:(e?.right??[]).filter(e=>!(r!=null&&r.includes(e)))}:{left:(e?.left??[]).filter(e=>!(r!=null&&r.includes(e))),right:(e?.right??[]).filter(e=>!(r!=null&&r.includes(e)))})},e.getCanPin=()=>e.getLeafColumns().some(e=>(e.columnDef.enablePinning??!0)&&(t.options.enableColumnPinning??t.options.enablePinning??!0)),e.getIsPinned=()=>{let n=e.getLeafColumns().map(e=>e.id),{left:r,right:i}=t.getState().columnPinning,a=n.some(e=>r?.includes(e)),o=n.some(e=>i?.includes(e));return a?`left`:o?`right`:!1},e.getPinnedIndex=()=>{var n;let r=e.getIsPinned();return r?((n=t.getState().columnPinning)==null||(n=n[r])==null?void 0:n.indexOf(e.id))??-1:0}},createRow:(e,t)=>{e.getCenterVisibleCells=a2(()=>[e._getAllVisibleCells(),t.getState().columnPinning.left,t.getState().columnPinning.right],(e,t,n)=>{let r=[...t??[],...n??[]];return e.filter(e=>!r.includes(e.column.id))},o2(t.options,`debugRows`,`getCenterVisibleCells`)),e.getLeftVisibleCells=a2(()=>[e._getAllVisibleCells(),t.getState().columnPinning.left],(e,t)=>(t??[]).map(t=>e.find(e=>e.column.id===t)).filter(Boolean).map(e=>({...e,position:`left`})),o2(t.options,`debugRows`,`getLeftVisibleCells`)),e.getRightVisibleCells=a2(()=>[e._getAllVisibleCells(),t.getState().columnPinning.right],(e,t)=>(t??[]).map(t=>e.find(e=>e.column.id===t)).filter(Boolean).map(e=>({...e,position:`right`})),o2(t.options,`debugRows`,`getRightVisibleCells`))},createTable:e=>{e.setColumnPinning=t=>e.options.onColumnPinningChange==null?void 0:e.options.onColumnPinningChange(t),e.resetColumnPinning=t=>e.setColumnPinning(t?M2():e.initialState?.columnPinning??M2()),e.getIsSomeColumnsPinned=t=>{let n=e.getState().columnPinning;return t?!!n[t]?.length:!!(n.left?.length||n.right?.length)},e.getLeftLeafColumns=a2(()=>[e.getAllLeafColumns(),e.getState().columnPinning.left],(e,t)=>(t??[]).map(t=>e.find(e=>e.id===t)).filter(Boolean),o2(e.options,`debugColumns`,`getLeftLeafColumns`)),e.getRightLeafColumns=a2(()=>[e.getAllLeafColumns(),e.getState().columnPinning.right],(e,t)=>(t??[]).map(t=>e.find(e=>e.id===t)).filter(Boolean),o2(e.options,`debugColumns`,`getRightLeafColumns`)),e.getCenterLeafColumns=a2(()=>[e.getAllLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(e,t,n)=>{let r=[...t??[],...n??[]];return e.filter(e=>!r.includes(e.id))},o2(e.options,`debugColumns`,`getCenterLeafColumns`))}};function P2(e){return e||(typeof document<`u`?document:null)}var F2={size:150,minSize:20,maxSize:2**53-1},I2=()=>({startOffset:null,startSize:null,deltaOffset:null,deltaPercentage:null,isResizingColumn:!1,columnSizingStart:[]}),L2={getDefaultColumnDef:()=>F2,getInitialState:e=>({columnSizing:{},columnSizingInfo:I2(),...e}),getDefaultOptions:e=>({columnResizeMode:`onEnd`,columnResizeDirection:`ltr`,onColumnSizingChange:t2(`columnSizing`,e),onColumnSizingInfoChange:t2(`columnSizingInfo`,e)}),createColumn:(e,t)=>{e.getSize=()=>{let n=t.getState().columnSizing[e.id];return Math.min(Math.max(e.columnDef.minSize??F2.minSize,n??e.columnDef.size??F2.size),e.columnDef.maxSize??F2.maxSize)},e.getStart=a2(e=>[e,H2(t,e),t.getState().columnSizing],(t,n)=>n.slice(0,e.getIndex(t)).reduce((e,t)=>e+t.getSize(),0),o2(t.options,`debugColumns`,`getStart`)),e.getAfter=a2(e=>[e,H2(t,e),t.getState().columnSizing],(t,n)=>n.slice(e.getIndex(t)+1).reduce((e,t)=>e+t.getSize(),0),o2(t.options,`debugColumns`,`getAfter`)),e.resetSize=()=>{t.setColumnSizing(t=>{let{[e.id]:n,...r}=t;return r})},e.getCanResize=()=>(e.columnDef.enableResizing??!0)&&(t.options.enableColumnResizing??!0),e.getIsResizing=()=>t.getState().columnSizingInfo.isResizingColumn===e.id},createHeader:(e,t)=>{e.getSize=()=>{let t=0,n=e=>{e.subHeaders.length?e.subHeaders.forEach(n):t+=e.column.getSize()??0};return n(e),t},e.getStart=()=>{if(e.index>0){let t=e.headerGroup.headers[e.index-1];return t.getStart()+t.getSize()}return 0},e.getResizeHandler=n=>{let r=t.getColumn(e.column.id),i=r?.getCanResize();return a=>{if(!r||!i||(a.persist==null||a.persist(),B2(a)&&a.touches&&a.touches.length>1))return;let o=e.getSize(),s=e?e.getLeafHeaders().map(e=>[e.column.id,e.column.getSize()]):[[r.id,r.getSize()]],c=B2(a)?Math.round(a.touches[0].clientX):a.clientX,l={},u=(e,n)=>{typeof n==`number`&&(t.setColumnSizingInfo(e=>{let r=t.options.columnResizeDirection===`rtl`?-1:1,i=(n-(e?.startOffset??0))*r,a=Math.max(i/(e?.startSize??0),-.999999);return e.columnSizingStart.forEach(e=>{let[t,n]=e;l[t]=Math.round(Math.max(n+n*a,0)*100)/100}),{...e,deltaOffset:i,deltaPercentage:a}}),(t.options.columnResizeMode===`onChange`||e===`end`)&&t.setColumnSizing(e=>({...e,...l})))},d=e=>u(`move`,e),f=e=>{u(`end`,e),t.setColumnSizingInfo(e=>({...e,isResizingColumn:!1,startOffset:null,startSize:null,deltaOffset:null,deltaPercentage:null,columnSizingStart:[]}))},p=P2(n),m={moveHandler:e=>d(e.clientX),upHandler:e=>{p?.removeEventListener(`mousemove`,m.moveHandler),p?.removeEventListener(`mouseup`,m.upHandler),f(e.clientX)}},h={moveHandler:e=>(e.cancelable&&(e.preventDefault(),e.stopPropagation()),d(e.touches[0].clientX),!1),upHandler:e=>{p?.removeEventListener(`touchmove`,h.moveHandler),p?.removeEventListener(`touchend`,h.upHandler),e.cancelable&&(e.preventDefault(),e.stopPropagation()),f(e.touches[0]?.clientX)}},g=z2()?{passive:!1}:!1;B2(a)?(p?.addEventListener(`touchmove`,h.moveHandler,g),p?.addEventListener(`touchend`,h.upHandler,g)):(p?.addEventListener(`mousemove`,m.moveHandler,g),p?.addEventListener(`mouseup`,m.upHandler,g)),t.setColumnSizingInfo(e=>({...e,startOffset:c,startSize:o,deltaOffset:0,deltaPercentage:0,columnSizingStart:s,isResizingColumn:r.id}))}}},createTable:e=>{e.setColumnSizing=t=>e.options.onColumnSizingChange==null?void 0:e.options.onColumnSizingChange(t),e.setColumnSizingInfo=t=>e.options.onColumnSizingInfoChange==null?void 0:e.options.onColumnSizingInfoChange(t),e.resetColumnSizing=t=>{e.setColumnSizing(t?{}:e.initialState.columnSizing??{})},e.resetHeaderSizeInfo=t=>{e.setColumnSizingInfo(t?I2():e.initialState.columnSizingInfo??I2())},e.getTotalSize=()=>e.getHeaderGroups()[0]?.headers.reduce((e,t)=>e+t.getSize(),0)??0,e.getLeftTotalSize=()=>e.getLeftHeaderGroups()[0]?.headers.reduce((e,t)=>e+t.getSize(),0)??0,e.getCenterTotalSize=()=>e.getCenterHeaderGroups()[0]?.headers.reduce((e,t)=>e+t.getSize(),0)??0,e.getRightTotalSize=()=>e.getRightHeaderGroups()[0]?.headers.reduce((e,t)=>e+t.getSize(),0)??0}},R2=null;function z2(){if(typeof R2==`boolean`)return R2;let e=!1;try{let t={get passive(){return e=!0,!1}},n=()=>{};window.addEventListener(`test`,n,t),window.removeEventListener(`test`,n)}catch{e=!1}return R2=e,R2}function B2(e){return e.type===`touchstart`}var V2={getInitialState:e=>({columnVisibility:{},...e}),getDefaultOptions:e=>({onColumnVisibilityChange:t2(`columnVisibility`,e)}),createColumn:(e,t)=>{e.toggleVisibility=n=>{e.getCanHide()&&t.setColumnVisibility(t=>({...t,[e.id]:n??!e.getIsVisible()}))},e.getIsVisible=()=>{let n=e.columns;return(n.length?n.some(e=>e.getIsVisible()):t.getState().columnVisibility?.[e.id])??!0},e.getCanHide=()=>(e.columnDef.enableHiding??!0)&&(t.options.enableHiding??!0),e.getToggleVisibilityHandler=()=>t=>{e.toggleVisibility==null||e.toggleVisibility(t.target.checked)}},createRow:(e,t)=>{e._getAllVisibleCells=a2(()=>[e.getAllCells(),t.getState().columnVisibility],e=>e.filter(e=>e.column.getIsVisible()),o2(t.options,`debugRows`,`_getAllVisibleCells`)),e.getVisibleCells=a2(()=>[e.getLeftVisibleCells(),e.getCenterVisibleCells(),e.getRightVisibleCells()],(e,t,n)=>[...e,...t,...n],o2(t.options,`debugRows`,`getVisibleCells`))},createTable:e=>{let t=(t,n)=>a2(()=>[n(),n().filter(e=>e.getIsVisible()).map(e=>e.id).join(`_`)],e=>e.filter(e=>e.getIsVisible==null?void 0:e.getIsVisible()),o2(e.options,`debugColumns`,t));e.getVisibleFlatColumns=t(`getVisibleFlatColumns`,()=>e.getAllFlatColumns()),e.getVisibleLeafColumns=t(`getVisibleLeafColumns`,()=>e.getAllLeafColumns()),e.getLeftVisibleLeafColumns=t(`getLeftVisibleLeafColumns`,()=>e.getLeftLeafColumns()),e.getRightVisibleLeafColumns=t(`getRightVisibleLeafColumns`,()=>e.getRightLeafColumns()),e.getCenterVisibleLeafColumns=t(`getCenterVisibleLeafColumns`,()=>e.getCenterLeafColumns()),e.setColumnVisibility=t=>e.options.onColumnVisibilityChange==null?void 0:e.options.onColumnVisibilityChange(t),e.resetColumnVisibility=t=>{e.setColumnVisibility(t?{}:e.initialState.columnVisibility??{})},e.toggleAllColumnsVisible=t=>{t??=!e.getIsAllColumnsVisible(),e.setColumnVisibility(e.getAllLeafColumns().reduce((e,n)=>({...e,[n.id]:t||!(n.getCanHide!=null&&n.getCanHide())}),{}))},e.getIsAllColumnsVisible=()=>!e.getAllLeafColumns().some(e=>!(e.getIsVisible!=null&&e.getIsVisible())),e.getIsSomeColumnsVisible=()=>e.getAllLeafColumns().some(e=>e.getIsVisible==null?void 0:e.getIsVisible()),e.getToggleAllColumnsVisibilityHandler=()=>t=>{e.toggleAllColumnsVisible(t.target?.checked)}}};function H2(e,t){return t?t===`center`?e.getCenterVisibleLeafColumns():t===`left`?e.getLeftVisibleLeafColumns():e.getRightVisibleLeafColumns():e.getVisibleLeafColumns()}var U2={createTable:e=>{e._getGlobalFacetedRowModel=e.options.getFacetedRowModel&&e.options.getFacetedRowModel(e,`__global__`),e.getGlobalFacetedRowModel=()=>e.options.manualFiltering||!e._getGlobalFacetedRowModel?e.getPreFilteredRowModel():e._getGlobalFacetedRowModel(),e._getGlobalFacetedUniqueValues=e.options.getFacetedUniqueValues&&e.options.getFacetedUniqueValues(e,`__global__`),e.getGlobalFacetedUniqueValues=()=>e._getGlobalFacetedUniqueValues?e._getGlobalFacetedUniqueValues():new Map,e._getGlobalFacetedMinMaxValues=e.options.getFacetedMinMaxValues&&e.options.getFacetedMinMaxValues(e,`__global__`),e.getGlobalFacetedMinMaxValues=()=>{if(e._getGlobalFacetedMinMaxValues)return e._getGlobalFacetedMinMaxValues()}}},W2={getInitialState:e=>({globalFilter:void 0,...e}),getDefaultOptions:e=>({onGlobalFilterChange:t2(`globalFilter`,e),globalFilterFn:`auto`,getColumnCanGlobalFilter:t=>{var n;let r=(n=e.getCoreRowModel().flatRows[0])==null||(n=n._getAllCellsByColumnId()[t.id])==null?void 0:n.getValue();return typeof r==`string`||typeof r==`number`}}),createColumn:(e,t)=>{e.getCanGlobalFilter=()=>(e.columnDef.enableGlobalFilter??!0)&&(t.options.enableGlobalFilter??!0)&&(t.options.enableFilters??!0)&&((t.options.getColumnCanGlobalFilter==null?void 0:t.options.getColumnCanGlobalFilter(e))??!0)&&!!e.accessorFn},createTable:e=>{e.getGlobalAutoFilterFn=()=>w2.includesString,e.getGlobalFilterFn=()=>{let{globalFilterFn:t}=e.options;return n2(t)?t:t===`auto`?e.getGlobalAutoFilterFn():e.options.filterFns?.[t]??w2[t]},e.setGlobalFilter=t=>{e.options.onGlobalFilterChange==null||e.options.onGlobalFilterChange(t)},e.resetGlobalFilter=t=>{e.setGlobalFilter(t?void 0:e.initialState.globalFilter)}}},G2={getInitialState:e=>({expanded:{},...e}),getDefaultOptions:e=>({onExpandedChange:t2(`expanded`,e),paginateExpandedRows:!0}),createTable:e=>{let t=!1,n=!1;e._autoResetExpanded=()=>{if(!t){e._queue(()=>{t=!0});return}if(e.options.autoResetAll??e.options.autoResetExpanded??!e.options.manualExpanding){if(n)return;n=!0,e._queue(()=>{e.resetExpanded(),n=!1})}},e.setExpanded=t=>e.options.onExpandedChange==null?void 0:e.options.onExpandedChange(t),e.toggleAllRowsExpanded=t=>{t??!e.getIsAllRowsExpanded()?e.setExpanded(!0):e.setExpanded({})},e.resetExpanded=t=>{e.setExpanded(t?{}:e.initialState?.expanded??{})},e.getCanSomeRowsExpand=()=>e.getPrePaginationRowModel().flatRows.some(e=>e.getCanExpand()),e.getToggleAllRowsExpandedHandler=()=>t=>{t.persist==null||t.persist(),e.toggleAllRowsExpanded()},e.getIsSomeRowsExpanded=()=>{let t=e.getState().expanded;return t===!0||Object.values(t).some(Boolean)},e.getIsAllRowsExpanded=()=>{let t=e.getState().expanded;return typeof t==`boolean`?t===!0:!(!Object.keys(t).length||e.getRowModel().flatRows.some(e=>!e.getIsExpanded()))},e.getExpandedDepth=()=>{let t=0;return(e.getState().expanded===!0?Object.keys(e.getRowModel().rowsById):Object.keys(e.getState().expanded)).forEach(e=>{let n=e.split(`.`);t=Math.max(t,n.length)}),t},e.getPreExpandedRowModel=()=>e.getSortedRowModel(),e.getExpandedRowModel=()=>(!e._getExpandedRowModel&&e.options.getExpandedRowModel&&(e._getExpandedRowModel=e.options.getExpandedRowModel(e)),e.options.manualExpanding||!e._getExpandedRowModel?e.getPreExpandedRowModel():e._getExpandedRowModel())},createRow:(e,t)=>{e.toggleExpanded=n=>{t.setExpanded(r=>{let i=r===!0?!0:!!(r!=null&&r[e.id]),a={};if(r===!0?Object.keys(t.getRowModel().rowsById).forEach(e=>{a[e]=!0}):a=r,n??=!i,!i&&n)return{...a,[e.id]:!0};if(i&&!n){let{[e.id]:t,...n}=a;return n}return r})},e.getIsExpanded=()=>{let n=t.getState().expanded;return!!((t.options.getIsRowExpanded==null?void 0:t.options.getIsRowExpanded(e))??(n===!0||n?.[e.id]))},e.getCanExpand=()=>{var n;return(t.options.getRowCanExpand==null?void 0:t.options.getRowCanExpand(e))??((t.options.enableExpanding??!0)&&!!((n=e.subRows)!=null&&n.length))},e.getIsAllParentsExpanded=()=>{let n=!0,r=e;for(;n&&r.parentId;)r=t.getRow(r.parentId,!0),n=r.getIsExpanded();return n},e.getToggleExpandedHandler=()=>{let t=e.getCanExpand();return()=>{t&&e.toggleExpanded()}}}},K2=0,q2=10,J2=()=>({pageIndex:K2,pageSize:q2}),Y2={getInitialState:e=>({...e,pagination:{...J2(),...e?.pagination}}),getDefaultOptions:e=>({onPaginationChange:t2(`pagination`,e)}),createTable:e=>{let t=!1,n=!1;e._autoResetPageIndex=()=>{if(!t){e._queue(()=>{t=!0});return}if(e.options.autoResetAll??e.options.autoResetPageIndex??!e.options.manualPagination){if(n)return;n=!0,e._queue(()=>{e.resetPageIndex(),n=!1})}},e.setPagination=t=>e.options.onPaginationChange==null?void 0:e.options.onPaginationChange(e=>e2(t,e)),e.resetPagination=t=>{e.setPagination(t?J2():e.initialState.pagination??J2())},e.setPageIndex=t=>{e.setPagination(n=>{let r=e2(t,n.pageIndex),i=e.options.pageCount===void 0||e.options.pageCount===-1?2**53-1:e.options.pageCount-1;return r=Math.max(0,Math.min(r,i)),{...n,pageIndex:r}})},e.resetPageIndex=t=>{var n;e.setPageIndex(t?K2:((n=e.initialState)==null||(n=n.pagination)==null?void 0:n.pageIndex)??K2)},e.resetPageSize=t=>{var n;e.setPageSize(t?q2:((n=e.initialState)==null||(n=n.pagination)==null?void 0:n.pageSize)??q2)},e.setPageSize=t=>{e.setPagination(e=>{let n=Math.max(1,e2(t,e.pageSize)),r=e.pageSize*e.pageIndex,i=Math.floor(r/n);return{...e,pageIndex:i,pageSize:n}})},e.setPageCount=t=>e.setPagination(n=>{let r=e2(t,e.options.pageCount??-1);return typeof r==`number`&&(r=Math.max(-1,r)),{...n,pageCount:r}}),e.getPageOptions=a2(()=>[e.getPageCount()],e=>{let t=[];return e&&e>0&&(t=[...Array(e)].fill(null).map((e,t)=>t)),t},o2(e.options,`debugTable`,`getPageOptions`)),e.getCanPreviousPage=()=>e.getState().pagination.pageIndex>0,e.getCanNextPage=()=>{let{pageIndex:t}=e.getState().pagination,n=e.getPageCount();return n===-1?!0:n===0?!1:t<n-1},e.previousPage=()=>e.setPageIndex(e=>e-1),e.nextPage=()=>e.setPageIndex(e=>e+1),e.firstPage=()=>e.setPageIndex(0),e.lastPage=()=>e.setPageIndex(e.getPageCount()-1),e.getPrePaginationRowModel=()=>e.getExpandedRowModel(),e.getPaginationRowModel=()=>(!e._getPaginationRowModel&&e.options.getPaginationRowModel&&(e._getPaginationRowModel=e.options.getPaginationRowModel(e)),e.options.manualPagination||!e._getPaginationRowModel?e.getPrePaginationRowModel():e._getPaginationRowModel()),e.getPageCount=()=>e.options.pageCount??Math.ceil(e.getRowCount()/e.getState().pagination.pageSize),e.getRowCount=()=>e.options.rowCount??e.getPrePaginationRowModel().rows.length}},X2=()=>({top:[],bottom:[]}),Z2={getInitialState:e=>({rowPinning:X2(),...e}),getDefaultOptions:e=>({onRowPinningChange:t2(`rowPinning`,e)}),createRow:(e,t)=>{e.pin=(n,r,i)=>{let a=r?e.getLeafRows().map(e=>{let{id:t}=e;return t}):[],o=i?e.getParentRows().map(e=>{let{id:t}=e;return t}):[],s=new Set([...o,e.id,...a]);t.setRowPinning(e=>n===`bottom`?{top:(e?.top??[]).filter(e=>!(s!=null&&s.has(e))),bottom:[...(e?.bottom??[]).filter(e=>!(s!=null&&s.has(e))),...Array.from(s)]}:n===`top`?{top:[...(e?.top??[]).filter(e=>!(s!=null&&s.has(e))),...Array.from(s)],bottom:(e?.bottom??[]).filter(e=>!(s!=null&&s.has(e)))}:{top:(e?.top??[]).filter(e=>!(s!=null&&s.has(e))),bottom:(e?.bottom??[]).filter(e=>!(s!=null&&s.has(e)))})},e.getCanPin=()=>{let{enableRowPinning:n,enablePinning:r}=t.options;return typeof n==`function`?n(e):n??r??!0},e.getIsPinned=()=>{let n=[e.id],{top:r,bottom:i}=t.getState().rowPinning,a=n.some(e=>r?.includes(e)),o=n.some(e=>i?.includes(e));return a?`top`:o?`bottom`:!1},e.getPinnedIndex=()=>{let n=e.getIsPinned();return n?((n===`top`?t.getTopRows():t.getBottomRows())?.map(e=>{let{id:t}=e;return t}))?.indexOf(e.id)??-1:-1}},createTable:e=>{e.setRowPinning=t=>e.options.onRowPinningChange==null?void 0:e.options.onRowPinningChange(t),e.resetRowPinning=t=>e.setRowPinning(t?X2():e.initialState?.rowPinning??X2()),e.getIsSomeRowsPinned=t=>{let n=e.getState().rowPinning;return t?!!n[t]?.length:!!(n.top?.length||n.bottom?.length)},e._getPinnedRows=(t,n,r)=>(e.options.keepPinnedRows??!0?(n??[]).map(t=>{let n=e.getRow(t,!0);return n.getIsAllParentsExpanded()?n:null}):(n??[]).map(e=>t.find(t=>t.id===e))).filter(Boolean).map(e=>({...e,position:r})),e.getTopRows=a2(()=>[e.getRowModel().rows,e.getState().rowPinning.top],(t,n)=>e._getPinnedRows(t,n,`top`),o2(e.options,`debugRows`,`getTopRows`)),e.getBottomRows=a2(()=>[e.getRowModel().rows,e.getState().rowPinning.bottom],(t,n)=>e._getPinnedRows(t,n,`bottom`),o2(e.options,`debugRows`,`getBottomRows`)),e.getCenterRows=a2(()=>[e.getRowModel().rows,e.getState().rowPinning.top,e.getState().rowPinning.bottom],(e,t,n)=>{let r=new Set([...t??[],...n??[]]);return e.filter(e=>!r.has(e.id))},o2(e.options,`debugRows`,`getCenterRows`))}},Q2={getInitialState:e=>({rowSelection:{},...e}),getDefaultOptions:e=>({onRowSelectionChange:t2(`rowSelection`,e),enableRowSelection:!0,enableMultiRowSelection:!0,enableSubRowSelection:!0}),createTable:e=>{e.setRowSelection=t=>e.options.onRowSelectionChange==null?void 0:e.options.onRowSelectionChange(t),e.resetRowSelection=t=>e.setRowSelection(t?{}:e.initialState.rowSelection??{}),e.toggleAllRowsSelected=t=>{e.setRowSelection(n=>{t=t===void 0?!e.getIsAllRowsSelected():t;let r={...n},i=e.getPreGroupedRowModel().flatRows;return t?i.forEach(e=>{e.getCanSelect()&&(r[e.id]=!0)}):i.forEach(e=>{delete r[e.id]}),r})},e.toggleAllPageRowsSelected=t=>e.setRowSelection(n=>{let r=t===void 0?!e.getIsAllPageRowsSelected():t,i={...n};return e.getRowModel().rows.forEach(t=>{$2(i,t.id,r,!0,e)}),i}),e.getPreSelectedRowModel=()=>e.getCoreRowModel(),e.getSelectedRowModel=a2(()=>[e.getState().rowSelection,e.getCoreRowModel()],(t,n)=>Object.keys(t).length?e4(e,n):{rows:[],flatRows:[],rowsById:{}},o2(e.options,`debugTable`,`getSelectedRowModel`)),e.getFilteredSelectedRowModel=a2(()=>[e.getState().rowSelection,e.getFilteredRowModel()],(t,n)=>Object.keys(t).length?e4(e,n):{rows:[],flatRows:[],rowsById:{}},o2(e.options,`debugTable`,`getFilteredSelectedRowModel`)),e.getGroupedSelectedRowModel=a2(()=>[e.getState().rowSelection,e.getSortedRowModel()],(t,n)=>Object.keys(t).length?e4(e,n):{rows:[],flatRows:[],rowsById:{}},o2(e.options,`debugTable`,`getGroupedSelectedRowModel`)),e.getIsAllRowsSelected=()=>{let t=e.getFilteredRowModel().flatRows,{rowSelection:n}=e.getState(),r=!!(t.length&&Object.keys(n).length);return r&&t.some(e=>e.getCanSelect()&&!n[e.id])&&(r=!1),r},e.getIsAllPageRowsSelected=()=>{let t=e.getPaginationRowModel().flatRows.filter(e=>e.getCanSelect()),{rowSelection:n}=e.getState(),r=!!t.length;return r&&t.some(e=>!n[e.id])&&(r=!1),r},e.getIsSomeRowsSelected=()=>{let t=Object.keys(e.getState().rowSelection??{}).length;return t>0&&t<e.getFilteredRowModel().flatRows.length},e.getIsSomePageRowsSelected=()=>{let t=e.getPaginationRowModel().flatRows;return e.getIsAllPageRowsSelected()?!1:t.filter(e=>e.getCanSelect()).some(e=>e.getIsSelected()||e.getIsSomeSelected())},e.getToggleAllRowsSelectedHandler=()=>t=>{e.toggleAllRowsSelected(t.target.checked)},e.getToggleAllPageRowsSelectedHandler=()=>t=>{e.toggleAllPageRowsSelected(t.target.checked)}},createRow:(e,t)=>{e.toggleSelected=(n,r)=>{let i=e.getIsSelected();t.setRowSelection(a=>{if(n=n===void 0?!i:n,e.getCanSelect()&&i===n)return a;let o={...a};return $2(o,e.id,n,r?.selectChildren??!0,t),o})},e.getIsSelected=()=>{let{rowSelection:n}=t.getState();return t4(e,n)},e.getIsSomeSelected=()=>{let{rowSelection:n}=t.getState();return n4(e,n)===`some`},e.getIsAllSubRowsSelected=()=>{let{rowSelection:n}=t.getState();return n4(e,n)===`all`},e.getCanSelect=()=>typeof t.options.enableRowSelection==`function`?t.options.enableRowSelection(e):t.options.enableRowSelection??!0,e.getCanSelectSubRows=()=>typeof t.options.enableSubRowSelection==`function`?t.options.enableSubRowSelection(e):t.options.enableSubRowSelection??!0,e.getCanMultiSelect=()=>typeof t.options.enableMultiRowSelection==`function`?t.options.enableMultiRowSelection(e):t.options.enableMultiRowSelection??!0,e.getToggleSelectedHandler=()=>{let t=e.getCanSelect();return n=>{t&&e.toggleSelected(n.target?.checked)}}}},$2=(e,t,n,r,i)=>{var a;let o=i.getRow(t,!0);n?(o.getCanMultiSelect()||Object.keys(e).forEach(t=>delete e[t]),o.getCanSelect()&&(e[t]=!0)):delete e[t],r&&(a=o.subRows)!=null&&a.length&&o.getCanSelectSubRows()&&o.subRows.forEach(t=>$2(e,t.id,n,r,i))};function e4(e,t){let n=e.getState().rowSelection,r=[],i={},a=function(e,t){return e.map(e=>{var t;let o=t4(e,n);if(o&&(r.push(e),i[e.id]=e),(t=e.subRows)!=null&&t.length&&(e={...e,subRows:a(e.subRows)}),o)return e}).filter(Boolean)};return{rows:a(t.rows),flatRows:r,rowsById:i}}function t4(e,t){return t[e.id]??!1}function n4(e,t,n){var r;if(!((r=e.subRows)!=null&&r.length))return!1;let i=!0,a=!1;return e.subRows.forEach(e=>{if(!(a&&!i)&&(e.getCanSelect()&&(t4(e,t)?a=!0:i=!1),e.subRows&&e.subRows.length)){let n=n4(e,t);n===`all`?a=!0:(n===`some`&&(a=!0),i=!1)}}),i?`all`:a?`some`:!1}var r4=/([0-9]+)/gm,i4=(e,t,n)=>f4(d4(e.getValue(n)).toLowerCase(),d4(t.getValue(n)).toLowerCase()),a4=(e,t,n)=>f4(d4(e.getValue(n)),d4(t.getValue(n))),o4=(e,t,n)=>u4(d4(e.getValue(n)).toLowerCase(),d4(t.getValue(n)).toLowerCase()),s4=(e,t,n)=>u4(d4(e.getValue(n)),d4(t.getValue(n))),c4=(e,t,n)=>{let r=e.getValue(n),i=t.getValue(n);return r>i?1:r<i?-1:0},l4=(e,t,n)=>u4(e.getValue(n),t.getValue(n));function u4(e,t){return e===t?0:e>t?1:-1}function d4(e){return typeof e==`number`?isNaN(e)||e===1/0||e===-1/0?``:String(e):typeof e==`string`?e:``}function f4(e,t){let n=e.split(r4).filter(Boolean),r=t.split(r4).filter(Boolean);for(;n.length&&r.length;){let e=n.shift(),t=r.shift(),i=parseInt(e,10),a=parseInt(t,10),o=[i,a].sort();if(isNaN(o[0])){if(e>t)return 1;if(t>e)return-1;continue}if(isNaN(o[1]))return isNaN(i)?-1:1;if(i>a)return 1;if(a>i)return-1}return n.length-r.length}var p4={alphanumeric:i4,alphanumericCaseSensitive:a4,text:o4,textCaseSensitive:s4,datetime:c4,basic:l4},m4=[d2,V2,j2,N2,m2,E2,U2,W2,{getInitialState:e=>({sorting:[],...e}),getDefaultColumnDef:()=>({sortingFn:`auto`,sortUndefined:1}),getDefaultOptions:e=>({onSortingChange:t2(`sorting`,e),isMultiSortEvent:e=>e.shiftKey}),createColumn:(e,t)=>{e.getAutoSortingFn=()=>{let n=t.getFilteredRowModel().flatRows.slice(10),r=!1;for(let t of n){let n=t?.getValue(e.id);if(Object.prototype.toString.call(n)===`[object Date]`)return p4.datetime;if(typeof n==`string`&&(r=!0,n.split(r4).length>1))return p4.alphanumeric}return r?p4.text:p4.basic},e.getAutoSortDir=()=>typeof t.getFilteredRowModel().flatRows[0]?.getValue(e.id)==`string`?`asc`:`desc`,e.getSortingFn=()=>{if(!e)throw Error();return n2(e.columnDef.sortingFn)?e.columnDef.sortingFn:e.columnDef.sortingFn===`auto`?e.getAutoSortingFn():t.options.sortingFns?.[e.columnDef.sortingFn]??p4[e.columnDef.sortingFn]},e.toggleSorting=(n,r)=>{let i=e.getNextSortingOrder(),a=n!=null;t.setSorting(o=>{let s=o?.find(t=>t.id===e.id),c=o?.findIndex(t=>t.id===e.id),l=[],u,d=a?n:i===`desc`;return u=o!=null&&o.length&&e.getCanMultiSort()&&r?s?`toggle`:`add`:o!=null&&o.length&&c!==o.length-1?`replace`:s?`toggle`:`replace`,u===`toggle`&&(a||i||(u=`remove`)),u===`add`?(l=[...o,{id:e.id,desc:d}],l.splice(0,l.length-(t.options.maxMultiSortColCount??2**53-1))):l=u===`toggle`?o.map(t=>t.id===e.id?{...t,desc:d}:t):u===`remove`?o.filter(t=>t.id!==e.id):[{id:e.id,desc:d}],l})},e.getFirstSortDir=()=>e.columnDef.sortDescFirst??t.options.sortDescFirst??e.getAutoSortDir()===`desc`?`desc`:`asc`,e.getNextSortingOrder=n=>{let r=e.getFirstSortDir(),i=e.getIsSorted();return i?i!==r&&(t.options.enableSortingRemoval??!0)&&(!n||(t.options.enableMultiRemove??!0))?!1:i===`desc`?`asc`:`desc`:r},e.getCanSort=()=>(e.columnDef.enableSorting??!0)&&(t.options.enableSorting??!0)&&!!e.accessorFn,e.getCanMultiSort=()=>e.columnDef.enableMultiSort??t.options.enableMultiSort??!!e.accessorFn,e.getIsSorted=()=>{let n=t.getState().sorting?.find(t=>t.id===e.id);return n?n.desc?`desc`:`asc`:!1},e.getSortIndex=()=>t.getState().sorting?.findIndex(t=>t.id===e.id)??-1,e.clearSorting=()=>{t.setSorting(t=>t!=null&&t.length?t.filter(t=>t.id!==e.id):[])},e.getToggleSortingHandler=()=>{let n=e.getCanSort();return r=>{n&&(r.persist==null||r.persist(),e.toggleSorting==null||e.toggleSorting(void 0,e.getCanMultiSort()?t.options.isMultiSortEvent==null?void 0:t.options.isMultiSortEvent(r):!1))}}},createTable:e=>{e.setSorting=t=>e.options.onSortingChange==null?void 0:e.options.onSortingChange(t),e.resetSorting=t=>{e.setSorting(t?[]:e.initialState?.sorting??[])},e.getPreSortedRowModel=()=>e.getGroupedRowModel(),e.getSortedRowModel=()=>(!e._getSortedRowModel&&e.options.getSortedRowModel&&(e._getSortedRowModel=e.options.getSortedRowModel(e)),e.options.manualSorting||!e._getSortedRowModel?e.getPreSortedRowModel():e._getSortedRowModel())}},k2,G2,Y2,Z2,Q2,L2];function h4(e){let t=[...m4,...e._features??[]],n={_features:t},r=n._features.reduce((e,t)=>Object.assign(e,t.getDefaultOptions==null?void 0:t.getDefaultOptions(n)),{}),i=e=>n.options.mergeOptions?n.options.mergeOptions(r,e):{...r,...e},a={...e.initialState??{}};n._features.forEach(e=>{a=(e.getInitialState==null?void 0:e.getInitialState(a))??a});let o=[],s=!1,c={_features:t,options:{...r,...e},initialState:a,_queue:e=>{o.push(e),s||(s=!0,Promise.resolve().then(()=>{for(;o.length;)o.shift()();s=!1}).catch(e=>setTimeout(()=>{throw e})))},reset:()=>{n.setState(n.initialState)},setOptions:e=>{n.options=i(e2(e,n.options))},getState:()=>n.options.state,setState:e=>{n.options.onStateChange==null||n.options.onStateChange(e)},_getRowId:(e,t,r)=>(n.options.getRowId==null?void 0:n.options.getRowId(e,t,r))??`${r?[r.id,t].join(`.`):t}`,getCoreRowModel:()=>(n._getCoreRowModel||=n.options.getCoreRowModel(n),n._getCoreRowModel()),getRowModel:()=>n.getPaginationRowModel(),getRow:(e,t)=>{let r=(t?n.getPrePaginationRowModel():n.getRowModel()).rowsById[e];if(!r&&(r=n.getCoreRowModel().rowsById[e],!r))throw Error();return r},_getDefaultColumnDef:a2(()=>[n.options.defaultColumn],e=>(e??={},{header:e=>{let t=e.header.column.columnDef;return t.accessorKey?t.accessorKey:t.accessorFn?t.id:null},cell:e=>{var t;return((t=e.renderValue())==null||t.toString==null?void 0:t.toString())??null},...n._features.reduce((e,t)=>Object.assign(e,t.getDefaultColumnDef==null?void 0:t.getDefaultColumnDef()),{}),...e}),o2(e,`debugColumns`,`_getDefaultColumnDef`)),_getColumnDefs:()=>n.options.columns,getAllColumns:a2(()=>[n._getColumnDefs()],e=>{let t=function(e,r,i){return i===void 0&&(i=0),e.map(e=>{let a=c2(n,e,i,r),o=e;return a.columns=o.columns?t(o.columns,a,i+1):[],a})};return t(e)},o2(e,`debugColumns`,`getAllColumns`)),getAllFlatColumns:a2(()=>[n.getAllColumns()],e=>e.flatMap(e=>e.getFlatColumns()),o2(e,`debugColumns`,`getAllFlatColumns`)),_getAllFlatColumnsById:a2(()=>[n.getAllFlatColumns()],e=>e.reduce((e,t)=>(e[t.id]=t,e),{}),o2(e,`debugColumns`,`getAllFlatColumnsById`)),getAllLeafColumns:a2(()=>[n.getAllColumns(),n._getOrderColumnsFn()],(e,t)=>t(e.flatMap(e=>e.getLeafColumns())),o2(e,`debugColumns`,`getAllLeafColumns`)),getColumn:e=>n._getAllFlatColumnsById()[e]};Object.assign(n,c);for(let e=0;e<n._features.length;e++){let t=n._features[e];t==null||t.createTable==null||t.createTable(n)}return n}function g4(){return e=>a2(()=>[e.options.data],t=>{let n={rows:[],flatRows:[],rowsById:{}},r=function(t,i,a){i===void 0&&(i=0);let o=[];for(let c=0;c<t.length;c++){let l=p2(e,e._getRowId(t[c],c,a),t[c],c,i,void 0,a?.id);if(n.flatRows.push(l),n.rowsById[l.id]=l,o.push(l),e.options.getSubRows){var s;l.originalSubRows=e.options.getSubRows(t[c],c),(s=l.originalSubRows)!=null&&s.length&&(l.subRows=r(l.originalSubRows,i+1,l))}}return o};return n.rows=r(t),n},o2(e.options,`debugTable`,`getRowModel`,()=>e._autoResetPageIndex()))}function _4(e,t){return e?v4(e)?v.createElement(e,t):e:null}function v4(e){return y4(e)||typeof e==`function`||b4(e)}function y4(e){return typeof e==`function`&&(()=>{let t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}function b4(e){return typeof e==`object`&&typeof e.$$typeof==`symbol`&&[`react.memo`,`react.forward_ref`].includes(e.$$typeof.description)}function x4(e){let t={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[n]=v.useState(()=>({current:h4(t)})),[r,i]=v.useState(()=>n.current.initialState);return n.current.setOptions(t=>({...t,...e,state:{...r,...e.state},onStateChange:t=>{i(t),e.onStateChange==null||e.onStateChange(t)}})),n.current}var S4={"super admin":`default`,admin:`secondary`,contributor:`outline`,editor:`secondary`,viewer:`outline`};function C4({roleId:e,roleName:t,roles:n}){let r=n.find(t=>t.id===e),i=t??r?.name??e;return(0,H.jsx)(dT,{variant:S4[i.toLowerCase()]??`secondary`,children:i})}function w4({user:e,currentUserId:t,currentUserRole:n,onEdit:r,onDelete:i}){let a=e.id===t,o=(e.role_name??``).toLowerCase()===`super admin`,s=n.toLowerCase()===`super admin`;return(0,H.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,H.jsx)(q,{size:`icon`,variant:`ghost`,className:`flex size-7 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground`,disabled:o&&!a&&!s,onClick:()=>r(e),children:(0,H.jsx)(zo,{className:`size-3.5`})}),(0,H.jsx)(q,{size:`icon`,variant:`ghost`,className:`flex size-8 items-center justify-center rounded text-destructive hover:bg-destructive/10 hover:text-destructive`,disabled:a||o,onClick:()=>i(e),children:(0,H.jsx)(es,{className:`size-3.5`})})]})}var T4={email:``,password:``,firstName:``,lastName:``,roleId:``,enabled:!0};function E4(){let{user:e,updateUser:t}=_a(),{editorialMode:n}=ba(),{data:r,loading:i,refetch:a}=Ta(`/cms/admin/users`),{data:o,loading:s}=Ta(`/cms/admin/roles`),c=i||s,{request:l,loading:u,error:d}=Eb(),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(T4),[g,_]=(0,v.useState)(null),[y,b]=(0,v.useState)({email:``,roleId:``,firstName:``,lastName:``,enabled:!0}),[x,S]=(0,v.useState)(null),C=o??[],w=e?.role?.toLowerCase()===`super admin`,T=C.filter(e=>n||![`Editor`,`Viewer`].includes(e.name)),E=w?T:T.filter(e=>e.name.toLowerCase()!==`super admin`),D=(0,v.useMemo)(()=>[{id:`name`,header:`Name`,cell:({row:e})=>{let{first_name:t,last_name:n}=e.original;return!t&&!n?(0,H.jsx)(`span`,{className:`text-muted-foreground`,children:`—`}):(0,H.jsx)(`span`,{className:`font-bold`,children:[t,n].filter(Boolean).join(` `)})}},{accessorKey:`email`,header:`Email`},{accessorKey:`role_id`,header:`Role`,cell:({row:e,getValue:t})=>(0,H.jsx)(C4,{roleId:t(),roleName:e.original.role_name,roles:C})},{accessorKey:`enabled`,header:`Enabled`,cell:({row:t,getValue:n})=>(0,H.jsx)(uk,{checked:!!(n()??!0),onCheckedChange:async e=>{try{await l(`/cms/admin/users/${t.original.id}`,`PUT`,{enabled:e}),a(),X.success(`User updated`)}catch{X.error(`Could not update user`)}},disabled:t.original.id===e?.id||u})},{id:`actions`,header:``,cell:({row:t})=>(0,H.jsx)(w4,{user:t.original,currentUserId:e?.id??``,currentUserRole:e?.role??``,onEdit:e=>{_(e),b({email:e.email,roleId:e.role_id,firstName:e.first_name??``,lastName:e.last_name??``,enabled:e.enabled??!0})},onDelete:S})}],[C,e?.id,e?.role,l,a,u]),O=x4({data:(0,v.useMemo)(()=>[...r??[]].sort((e,t)=>{let n=[e.first_name,e.last_name].filter(Boolean).join(` `)||e.email,r=[t.first_name,t.last_name].filter(Boolean).join(` `)||t.email;return n.localeCompare(r)}),[r]),columns:D,getCoreRowModel:g4()});async function k(e){e.preventDefault();try{await l(`/cms/admin/users`,`POST`,m),p(!1),h(T4),a(),X.success(`User created`)}catch{X.error(`Could not create user`)}}async function A(n){n.preventDefault();try{await l(`/cms/admin/users/${g.id}`,`PUT`,y),g.id===e?.id&&t({email:y.email,firstName:y.firstName||null,lastName:y.lastName||null}),_(null),a(),X.success(`User updated`)}catch{X.error(`Could not update user`)}}async function j(){try{await l(`/cms/admin/users/${x.id}`,`DELETE`),S(null),a(),X.success(`User deleted`)}catch{X.error(`Could not delete user`)}}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($b,{children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:`Users`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Manage who has access to the admin panel.`})]}),(0,H.jsxs)(q,{onClick:()=>p(!0),children:[(0,H.jsx)(Bo,{className:`size-4`}),`New user`]})]})}),(0,H.jsxs)(`section`,{className:`mt-24`,children:[(0,H.jsx)(`div`,{className:`rounded-md border`,children:(0,H.jsxs)(DT,{children:[(0,H.jsx)(OT,{className:`font-bold uppercase`,children:O.getHeaderGroups().map(e=>(0,H.jsx)(AT,{className:`hover:bg-transparent`,children:e.headers.map(e=>(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:_4(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,H.jsx)(kT,{children:c?(0,H.jsx)(AT,{children:(0,H.jsx)(MT,{colSpan:D.length,className:`h-24`,children:(0,H.jsx)(ex,{className:`mx-auto size-5`})})}):O.getRowModel().rows.length===0?(0,H.jsx)(AT,{children:(0,H.jsx)(MT,{colSpan:D.length,className:`h-24 text-center text-muted-foreground`,children:`No users found.`})}):O.getRowModel().rows.map(e=>(0,H.jsx)(AT,{children:e.getVisibleCells().map(e=>(0,H.jsx)(MT,{className:`px-4 py-3`,children:_4(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})}),(0,H.jsx)(vy,{open:f,onOpenChange:p,children:(0,H.jsxs)(Sy,{className:`sm:max-w-md`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`New user`})}),(0,H.jsxs)(`form`,{id:`create-user-form`,onSubmit:k,className:`flex flex-col gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`c-email`,children:`Email`}),(0,H.jsx)(J,{id:`c-email`,type:`email`,placeholder:`user@example.com`,value:m.email,onChange:e=>h(t=>({...t,email:e.target.value})),required:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`c-password`,children:`Password`}),(0,H.jsx)(J,{id:`c-password`,type:`password`,placeholder:`Min. 8 characters`,value:m.password,onChange:e=>h(t=>({...t,password:e.target.value})),required:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`c-fname`,children:`First name`}),(0,H.jsx)(J,{id:`c-fname`,value:m.firstName,onChange:e=>h(t=>({...t,firstName:e.target.value})),required:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`c-lname`,children:`Last name`}),(0,H.jsx)(J,{id:`c-lname`,value:m.lastName,onChange:e=>h(t=>({...t,lastName:e.target.value})),required:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`c-role`,children:`Role`}),(0,H.jsxs)(_T,{value:m.roleId,onValueChange:e=>h(t=>({...t,roleId:e})),children:[(0,H.jsx)(bT,{id:`c-role`,children:(0,H.jsx)(yT,{placeholder:`Select a role`})}),(0,H.jsx)(CT,{children:E.map(e=>(0,H.jsx)(TT,{value:e.id,children:e.name.charAt(0).toUpperCase()+e.name.slice(1)},e.id))})]})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border p-3`,children:[(0,H.jsx)(Y,{htmlFor:`c-enabled`,children:`Enabled`}),(0,H.jsx)(uk,{id:`c-enabled`,checked:m.enabled,onCheckedChange:e=>h(t=>({...t,enabled:e}))})]}),d&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:d})]}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,type:`button`,onClick:()=>p(!1),children:`Cancel`}),(0,H.jsx)(q,{type:`submit`,form:`create-user-form`,disabled:u,children:u?`Creating…`:`Create user`})]})]})}),(0,H.jsx)(vy,{open:!!g,onOpenChange:e=>{e||_(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-md`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Edit user`})}),(0,H.jsxs)(`form`,{id:`edit-user-form`,onSubmit:A,className:`flex flex-col gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`e-email`,children:`Email`}),(0,H.jsx)(J,{id:`e-email`,type:`email`,value:y.email,onChange:e=>b(t=>({...t,email:e.target.value})),required:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`e-fname`,children:`First name`}),(0,H.jsx)(J,{id:`e-fname`,value:y.firstName,onChange:e=>b(t=>({...t,firstName:e.target.value}))})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`e-lname`,children:`Last name`}),(0,H.jsx)(J,{id:`e-lname`,value:y.lastName,onChange:e=>b(t=>({...t,lastName:e.target.value}))})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`e-role`,children:`Role`}),(0,H.jsxs)(_T,{value:y.roleId,onValueChange:e=>b(t=>({...t,roleId:e})),children:[(0,H.jsx)(bT,{id:`e-role`,children:(0,H.jsx)(yT,{placeholder:`Select a role`})}),(0,H.jsx)(CT,{children:E.map(e=>(0,H.jsx)(TT,{value:e.id,children:e.name.charAt(0).toUpperCase()+e.name.slice(1)},e.id))})]})]}),(0,H.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border p-3`,children:[(0,H.jsx)(Y,{htmlFor:`e-enabled`,children:`Enabled`}),(0,H.jsx)(uk,{id:`e-enabled`,checked:y.enabled,onCheckedChange:e=>b(t=>({...t,enabled:e}))})]}),d&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:d})]}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,type:`button`,onClick:()=>_(null),children:`Cancel`}),(0,H.jsx)(q,{type:`submit`,form:`edit-user-form`,disabled:u,children:u?`Saving…`:`Save changes`})]})]})}),(0,H.jsx)(vy,{open:!!x,onOpenChange:e=>{e||S(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Delete user`})}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Are you sure you want to delete`,` `,(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:x?.email}),`? This action cannot be undone.`]}),d&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:d}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>S(null),children:`Cancel`}),(0,H.jsx)(q,{variant:`destructive`,onClick:j,disabled:u,children:u?`Deleting…`:`Delete`})]})]})})]})]})}var D4=[{key:`content-types`,label:`Content Types`,actions:[`read`,`write`,`delete`]},{key:`entries`,label:`Entries`,actions:[`read`,`write`,`delete`]},{key:`media`,label:`Media`,actions:[`read`,`write`,`delete`]},{key:`addons`,label:`Add-ons`,actions:[`read`,`write`]},{key:`settings:overview`,label:`Settings / Overview`,actions:[`read`,`write`]},{key:`settings:users`,label:`Settings / Users`,actions:[`read`,`write`,`delete`]},{key:`settings:roles`,label:`Settings / Roles`,actions:[`read`,`write`]},{key:`settings:api-tokens`,label:`Settings / API Tokens`,actions:[`read`,`write`,`delete`]},{key:`settings:webhooks`,label:`Settings / Webhooks`,actions:[`read`,`write`,`delete`]}],O4=[{key:`read`,label:`R`},{key:`write`,label:`W`},{key:`delete`,label:`D`}],k4=[`Super Admin`,`Admin`,`Editor`,`Contributor`],A4=`w-44 min-w-44 max-w-44`;function j4(e){return Object.fromEntries(e.map(e=>[e.id,new Set(e.permissions)]))}function M4(e,t){return e.includes(t)}function N4(){let{user:e}=_a(),{editorialMode:t}=ba(),{data:n,loading:r,refetch:i}=Ta(`/cms/admin/roles`),{request:a,loading:o}=Eb(),[s,c]=(0,v.useState)({}),[l,u]=(0,v.useState)(new Set),[d,f]=(0,v.useState)(!1);(0,v.useEffect)(()=>{n&&c(j4(n))},[n]);function p(e,t){c(n=>{let r=new Set(n[e]);return r.has(t)?r.delete(t):r.add(t),{...n,[e]:r}}),u(t=>new Set(t).add(e))}async function m(e){try{await a(`/cms/admin/roles/${e.id}`,`PUT`,{permissions:Array.from(s[e.id]??[])}),u(t=>{let n=new Set(t);return n.delete(e.id),n}),X.success(`Permissions saved`)}catch{X.error(`Could not save permissions`)}}async function h(){try{await a(`/cms/admin/roles/reset`,`POST`),f(!1),u(new Set),i(),X.success(`Permissions reset to defaults`)}catch{X.error(`Could not reset permissions`)}}let g=e?.role===`Super Admin`,_=(n??[]).filter(e=>e.name!==`Super Admin`).filter(e=>e.name!==`Viewer`).filter(e=>t||![`Editor`,`Viewer`].includes(e.name)).sort((e,t)=>{let n=k4.indexOf(e.name),r=k4.indexOf(t.name),i=n===-1?2**53-1:n,a=r===-1?2**53-1:r;return i===a?e.name.localeCompare(t.name):i-a}),y=(n??[]).find(e=>e.name===`Super Admin`);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($b,{children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:`Roles`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Configure what each role can do across the CMS.`})]}),g&&(0,H.jsxs)(q,{variant:`outline`,onClick:()=>f(!0),children:[(0,H.jsx)(Uo,{className:`size-4`}),`Reset defaults`]})]})}),(0,H.jsxs)(`section`,{className:`mt-24`,children:[(0,H.jsx)(`div`,{className:`rounded-md border`,children:(0,H.jsxs)(DT,{children:[(0,H.jsxs)(OT,{children:[(0,H.jsxs)(AT,{className:`hover:bg-transparent`,children:[(0,H.jsx)(jT,{className:`w-40`,rowSpan:2}),y&&(0,H.jsx)(jT,{colSpan:3,className:`border-l text-center ${A4}`,children:y.name}),_.map(e=>(0,H.jsx)(jT,{colSpan:3,className:`border-l ${A4}`,children:(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{children:e.name}),(0,H.jsxs)(q,{size:`sm`,variant:l.has(e.id)?`default`:`ghost`,className:`h-6 px-2 text-xs`,disabled:!l.has(e.id)||o,onClick:()=>m(e),children:[(0,H.jsx)(Wo,{className:`size-3`}),`Save`]})]})},e.id))]}),(0,H.jsxs)(AT,{className:`hover:bg-transparent`,children:[y&&O4.map((e,t)=>(0,H.jsx)(jT,{className:`w-12 text-center font-normal ${t===0?`border-l`:``}`,children:e.label},e.key)),_.map(e=>O4.map((t,n)=>(0,H.jsx)(jT,{className:`w-12 text-center font-normal ${n===0?`border-l`:``}`,children:t.label},`${e.id}-${t.key}`)))]})]}),(0,H.jsx)(kT,{children:r?(0,H.jsx)(AT,{children:(0,H.jsx)(MT,{colSpan:99,className:`h-24`,children:(0,H.jsx)(ex,{className:`mx-auto size-5`})})}):D4.map(({key:e,label:t,actions:n})=>(0,H.jsxs)(AT,{children:[(0,H.jsx)(MT,{className:`font-medium`,children:t}),y&&O4.map((e,t)=>(0,H.jsx)(MT,{className:`text-center ${t===0?`border-l`:``}`,children:M4(n,e.key)?(0,H.jsx)(_k,{checked:!0,disabled:!0}):(0,H.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})},e.key)),_.map(t=>O4.map((r,i)=>{let a=M4(n,r.key),o=`${e}:${r.key}`;return(0,H.jsx)(MT,{className:`text-center ${i===0?`border-l`:``}`,children:a?(0,H.jsx)(_k,{checked:s[t.id]?.has(o)??!1,onCheckedChange:()=>p(t.id,o)}):(0,H.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})},`${t.id}-${r.key}`)}))]},e))})]})}),t&&(0,H.jsxs)(`div`,{className:`mt-3 rounded-md border bg-muted/30 p-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium`,children:`Viewer`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Read-only role intended for external reviewers (for example, clients validating content before approval).`})]}),t&&(0,H.jsx)(`p`,{className:`mt-3 text-sm text-muted-foreground`,children:`Note: Editor and Contributor can share the same base permissions, but their effective scope is different in the content layer. Contributors are restricted to their own entries for certain actions, while Editors can operate on entries more broadly depending on the configured rules.`}),(0,H.jsx)(vy,{open:d,onOpenChange:f,children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Reset to defaults`})}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This will restore all role permissions to their original configuration. Any custom changes will be lost.`}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>f(!1),children:`Cancel`}),(0,H.jsx)(q,{variant:`destructive`,onClick:h,disabled:o,children:o?`Resetting…`:`Reset`})]})]})})]})]})}var P4={"full-access":`default`,"read-only":`secondary`},F4={"full-access":`Full access`,"read-only":`Read only`};function I4({value:e}){let[t,n]=(0,v.useState)(!1);function r(){navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),2e3)}return(0,H.jsx)(q,{type:`button`,size:`icon`,variant:`outline`,className:`shrink-0`,onClick:r,children:t?(0,H.jsx)(Ua,{className:`size-4 text-green-500`}):(0,H.jsx)(to,{className:`size-4`})})}var L4={name:``,accessType:``};function R4(){let{user:e}=_a(),{data:t,loading:n,refetch:r}=Ta(`/cms/admin/api-tokens`),{request:i,loading:a,error:o}=Eb(),s=e?.permissions??[],c=s.includes(`*`)||s.includes(`settings:api-tokens:write`),l=s.includes(`*`)||s.includes(`settings:api-tokens:delete`),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(L4),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(null),y=[{accessorKey:`name`,header:`Name`},{accessorKey:`access_type`,header:`Access`,cell:({getValue:e})=>{let t=e();return(0,H.jsx)(dT,{variant:P4[t]??`secondary`,children:F4[t]??t})}},{accessorKey:`created_at`,header:`Created`,cell:({getValue:e})=>new Date(e()).toLocaleDateString(`en-US`,{year:`numeric`,month:`short`,day:`numeric`})},{id:`actions`,header:``,cell:({row:e})=>l?(0,H.jsx)(q,{size:`icon`,variant:`ghost`,className:`flex size-8 items-center justify-center rounded text-destructive hover:bg-destructive/10 hover:text-destructive`,onClick:()=>_(e.original),children:(0,H.jsx)(es,{className:`size-3.5`})}):null}],b=x4({data:t??[],columns:y,getCoreRowModel:g4()});async function x(e){e.preventDefault();try{h(await i(`/cms/admin/api-tokens`,`POST`,{name:f.name,accessType:f.accessType})),r(),X.success(`API token created`)}catch{X.error(`Could not create token`)}}function S(){d(!1),h(null),p(L4)}async function C(){try{await i(`/cms/admin/api-tokens/${g.id}`,`DELETE`),_(null),r(),X.success(`Token revoked`)}catch{X.error(`Could not revoke token`)}}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($b,{children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:`API Tokens`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Manage tokens for consuming the public API.`})]}),(0,H.jsxs)(q,{onClick:()=>d(!0),disabled:!c,children:[(0,H.jsx)(Bo,{className:`size-4`}),`New token`]})]})}),(0,H.jsxs)(`section`,{className:`mt-24`,children:[(0,H.jsx)(`div`,{className:`rounded-md border`,children:(0,H.jsxs)(DT,{children:[(0,H.jsx)(OT,{className:`font-bold uppercase`,children:b.getHeaderGroups().map(e=>(0,H.jsx)(AT,{className:`hover:bg-transparent`,children:e.headers.map(e=>(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:_4(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,H.jsx)(kT,{children:n?(0,H.jsx)(AT,{children:(0,H.jsx)(MT,{colSpan:y.length,className:`h-24`,children:(0,H.jsx)(ex,{className:`mx-auto size-5`})})}):b.getRowModel().rows.length===0?(0,H.jsx)(AT,{children:(0,H.jsx)(MT,{colSpan:y.length,className:`h-24 text-center text-muted-foreground`,children:`No tokens yet.`})}):b.getRowModel().rows.map(e=>(0,H.jsx)(AT,{children:e.getVisibleCells().map(e=>(0,H.jsx)(MT,{className:`px-4 py-3`,children:_4(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})}),(0,H.jsx)(vy,{open:u,onOpenChange:e=>{e||S()},children:(0,H.jsx)(Sy,{className:`sm:max-w-md`,children:m?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Token generated`})}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`div`,{className:`rounded-md border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-200`,children:`Make sure to copy your token now. You won't be able to see it again.`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{children:`Token`}),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(J,{readOnly:!0,value:m.token,className:`font-mono text-xs`}),(0,H.jsx)(I4,{value:m.token})]})]})]}),(0,H.jsx)(wy,{children:(0,H.jsx)(q,{onClick:S,children:`Done`})})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`New API token`})}),(0,H.jsxs)(`form`,{id:`create-token-form`,onSubmit:x,className:`flex flex-col gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`token-name`,children:`Name`}),(0,H.jsx)(J,{id:`token-name`,placeholder:`e.g. Production frontend`,value:f.name,onChange:e=>p(t=>({...t,name:e.target.value})),required:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`token-access`,children:`Access type`}),(0,H.jsxs)(_T,{value:f.accessType,onValueChange:e=>p(t=>({...t,accessType:e})),children:[(0,H.jsx)(bT,{id:`token-access`,children:(0,H.jsx)(yT,{placeholder:`Select access type`})}),(0,H.jsxs)(CT,{children:[(0,H.jsx)(TT,{value:`read-only`,children:`Read only`}),(0,H.jsx)(TT,{value:`full-access`,children:`Full access`})]})]})]}),o&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:o})]}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,type:`button`,onClick:S,children:`Cancel`}),(0,H.jsx)(q,{type:`submit`,form:`create-token-form`,disabled:a||!f.accessType||!c,children:a?`Generating…`:`Generate token`})]})]})})}),(0,H.jsx)(vy,{open:!!g,onOpenChange:e=>{e||_(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Revoke token`})}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Are you sure you want to revoke`,` `,(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:g?.name}),`? Any frontend using it will immediately lose access.`]}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>_(null),children:`Cancel`}),(0,H.jsx)(q,{variant:`destructive`,onClick:C,disabled:a||!l,children:a?`Revoking…`:`Revoke`})]})]})})]})]})}var z4=[{value:`entry.published`,label:`Entry published`},{value:`entry.unpublished`,label:`Entry unpublished`},{value:`entry.created`,label:`Entry created`},{value:`entry.updated`,label:`Entry updated`},{value:`entry.deleted`,label:`Entry deleted`}],B4={name:``,url:``,events:[]};function V4(){let{user:e}=_a(),{data:t,loading:n,refetch:r}=Ta(`/cms/admin/webhooks`),{request:i,loading:a,error:o}=Eb(),s=e?.permissions??[],c=s.includes(`*`)||s.includes(`settings:webhooks:write`),l=s.includes(`*`)||s.includes(`settings:webhooks:delete`),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(B4),[m,h]=(0,v.useState)(null),g=[{accessorKey:`name`,header:`Name`},{accessorKey:`url`,header:`URL`,cell:({getValue:e})=>(0,H.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground truncate max-w-xs block`,children:e()})},{accessorKey:`events`,header:`Events`,cell:({getValue:e})=>(0,H.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e().map(e=>(0,H.jsx)(dT,{variant:`secondary`,className:`text-xs font-mono`,children:e},e))})},{accessorKey:`created_at`,header:`Created`,cell:({getValue:e})=>new Date(e()).toLocaleDateString(`en-US`,{year:`numeric`,month:`short`,day:`numeric`})},{id:`actions`,header:``,cell:({row:e})=>l?(0,H.jsx)(q,{size:`icon`,variant:`ghost`,className:`size-8 text-destructive hover:text-destructive`,onClick:()=>h(e.original),children:(0,H.jsx)(es,{className:`size-3.5`})}):null}],_=x4({data:t??[],columns:g,getCoreRowModel:g4()});function y(e){p(t=>({...t,events:t.events.includes(e)?t.events.filter(t=>t!==e):[...t.events,e]}))}async function b(e){e.preventDefault();try{await i(`/cms/admin/webhooks`,`POST`,f),d(!1),p(B4),r(),X.success(`Webhook saved`)}catch{X.error(`Could not save webhook`)}}async function x(){try{await i(`/cms/admin/webhooks/${m.id}`,`DELETE`),h(null),r(),X.success(`Webhook deleted`)}catch{X.error(`Could not delete webhook`)}}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)($b,{children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`text-2xl font-bold -mt-2`,children:`Webhooks`}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Notify external services when content events occur.`})]}),(0,H.jsxs)(q,{onClick:()=>d(!0),disabled:!c,children:[(0,H.jsx)(Bo,{className:`size-4`}),`New webhook`]})]})}),(0,H.jsxs)(`section`,{className:`mt-24`,children:[(0,H.jsx)(`div`,{className:`rounded-md border`,children:(0,H.jsxs)(DT,{children:[(0,H.jsx)(OT,{className:`font-bold uppercase`,children:_.getHeaderGroups().map(e=>(0,H.jsx)(AT,{className:`hover:bg-transparent`,children:e.headers.map(e=>(0,H.jsx)(jT,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,children:_4(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,H.jsx)(kT,{children:n?(0,H.jsx)(AT,{children:(0,H.jsx)(MT,{colSpan:g.length,className:`h-24`,children:(0,H.jsx)(ex,{className:`mx-auto size-5`})})}):_.getRowModel().rows.length===0?(0,H.jsx)(AT,{children:(0,H.jsx)(MT,{colSpan:g.length,className:`h-24 text-center text-muted-foreground`,children:`No webhooks yet.`})}):_.getRowModel().rows.map(e=>(0,H.jsx)(AT,{children:e.getVisibleCells().map(e=>(0,H.jsx)(MT,{className:`px-4 py-3`,children:_4(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})}),(0,H.jsx)(vy,{open:u,onOpenChange:e=>{e||(d(!1),p(B4))},children:(0,H.jsxs)(Sy,{className:`sm:max-w-md`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`New webhook`})}),(0,H.jsxs)(`form`,{id:`create-webhook-form`,onSubmit:b,className:`flex flex-col gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`webhook-name`,children:`Name`}),(0,H.jsx)(J,{id:`webhook-name`,placeholder:`e.g. Dokploy deploy`,value:f.name,onChange:e=>p(t=>({...t,name:e.target.value})),required:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`webhook-url`,children:`URL`}),(0,H.jsx)(J,{id:`webhook-url`,type:`url`,placeholder:`https://...`,value:f.url,onChange:e=>p(t=>({...t,url:e.target.value})),required:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsx)(Y,{children:`Events`}),z4.map(({value:e,label:t})=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(_k,{id:`event-${e}`,checked:f.events.includes(e),onCheckedChange:()=>y(e)}),(0,H.jsxs)(`label`,{htmlFor:`event-${e}`,className:`text-sm cursor-pointer`,children:[t,(0,H.jsx)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:e})]})]},e))]}),o&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:o})]}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,type:`button`,onClick:()=>{d(!1),p(B4)},children:`Cancel`}),(0,H.jsx)(q,{type:`submit`,form:`create-webhook-form`,disabled:a||f.events.length===0||!c,children:a?`Creating…`:`Create webhook`})]})]})}),(0,H.jsx)(vy,{open:!!m,onOpenChange:e=>{e||h(null)},children:(0,H.jsxs)(Sy,{className:`sm:max-w-sm`,children:[(0,H.jsx)(Cy,{children:(0,H.jsx)(Ty,{children:`Delete webhook`})}),(0,H.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Are you sure you want to delete`,` `,(0,H.jsx)(`span`,{className:`font-medium text-foreground`,children:m?.name}),`? It will stop receiving events immediately.`]}),(0,H.jsxs)(wy,{children:[(0,H.jsx)(q,{variant:`outline`,onClick:()=>h(null),children:`Cancel`}),(0,H.jsx)(q,{variant:`destructive`,onClick:x,disabled:a||!l,children:a?`Deleting…`:`Delete`})]})]})})]})]})}function H4({...e}){return(0,H.jsx)(xx,{"data-slot":`collapsible`,...e})}function U4({...e}){return(0,H.jsx)(vx,{"data-slot":`collapsible-content`,...e})}function W4(){let{user:e,updateUser:t}=_a(),{loading:n,error:r,request:i}=Eb(),{request:a}=Eb(),o=(0,v.useRef)(null),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(e?.firstName??``),[_,y]=(0,v.useState)(e?.lastName??``),[b,x]=(0,v.useState)(e?.jobTitle??``),[S,C]=(0,v.useState)(e?.organization??``),[w,T]=(0,v.useState)(e?.country??``);function E(){p&&(g(e?.firstName??``),y(e?.lastName??``),x(e?.jobTitle??``),C(e?.organization??``),T(e?.country??``)),m(!p)}async function D(e){let n=e.target.files?.[0];if(n){c(!0),f(null);try{t({avatarUrl:await m$(n)}),X.success(`Avatar updated`)}catch(e){f(e instanceof Error?e.message:`Upload failed.`),X.error(`Could not update avatar`)}finally{c(!1),o.current&&(o.current.value=``)}}}async function O(){u(!0),f(null);try{await a(`/cms/admin/users/me/avatar`,`DELETE`),t({avatarUrl:null}),X.success(`Avatar removed`)}catch(e){f(e instanceof Error?e.message:`Delete failed.`),X.error(`Could not remove avatar`)}finally{u(!1)}}async function k(e){e.preventDefault();try{let e=await i(`/cms/admin/users/me`,`PATCH`,{firstName:h,lastName:_,jobTitle:b,organization:S,country:w});t({firstName:e.first_name,lastName:e.last_name,jobTitle:e.job_title,organization:e.organization,country:e.country}),m(!1),X.success(`Profile saved`)}catch{X.error(`Could not save profile`)}}return(0,H.jsx)(H4,{open:p,onOpenChange:m,children:(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{children:[(0,H.jsx)(mT,{className:`uppercase`,children:`Account`}),(0,H.jsx)(hT,{children:(0,H.jsx)(q,{variant:`ghost`,size:`icon`,onClick:E,children:p?(0,H.jsx)(us,{className:`size-4`}):(0,H.jsx)(zo,{className:`size-4`})})})]}),(0,H.jsxs)(gT,{children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-4 -mt-4`,children:[(0,H.jsxs)(`div`,{className:`group relative shrink-0`,children:[(0,H.jsxs)(`button`,{type:`button`,className:`block`,onClick:()=>o.current?.click(),disabled:s||l,title:`Change avatar`,children:[(0,H.jsx)(Nl,{avatarUrl:e?.avatarUrl,firstName:e?.firstName,lastName:e?.lastName,email:e?.email,className:`size-20`,fallbackClassName:`text-xl`}),(0,H.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-full bg-black/40 opacity-0 transition-opacity group-hover:opacity-100`,children:s||l?(0,H.jsx)(`div`,{className:`size-4 animate-spin rounded-full border-2 border-white border-t-transparent`}):(0,H.jsx)(Ha,{className:`size-5 text-white`})})]}),e?.avatarUrl&&!s&&!l&&(0,H.jsx)(`button`,{type:`button`,onClick:O,title:`Remove avatar`,className:`absolute -top-1 -right-1 flex size-5 items-center justify-center rounded-full bg-destructive text-destructive-foreground opacity-0 transition-opacity group-hover:opacity-100`,children:(0,H.jsx)(es,{className:`size-3`})})]}),(0,H.jsx)(`input`,{ref:o,type:`file`,accept:`image/*`,className:`hidden`,onChange:D}),(0,H.jsxs)(`div`,{children:[d&&(0,H.jsx)(`p`,{className:`text-xs text-destructive mb-1`,children:d}),(0,H.jsx)(`p`,{className:`font-bold text-xl`,children:e?.firstName||e?.lastName?`${e.firstName??``} ${e.lastName??``}`.trim():e?.email}),(e?.jobTitle||e?.organization)&&(0,H.jsx)(`p`,{className:`text-sm`,children:[e.jobTitle,e.organization].filter(Boolean).join(` · `)}),(0,H.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:e?.email}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2 mt-2`,children:[(0,H.jsx)(dT,{className:`capitalize`,children:e?.role}),e?.country&&(0,H.jsx)(dT,{variant:`outline`,children:e.country})]})]})]}),(0,H.jsx)(U4,{children:(0,H.jsxs)(`form`,{onSubmit:k,className:`space-y-4 mt-8`,children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`firstName`,children:`First name`}),(0,H.jsx)(J,{id:`firstName`,value:h,onChange:e=>g(e.target.value)})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`lastName`,children:`Last name`}),(0,H.jsx)(J,{id:`lastName`,value:_,onChange:e=>y(e.target.value)})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`jobTitle`,children:`Job title`}),(0,H.jsx)(J,{id:`jobTitle`,value:b,onChange:e=>x(e.target.value)})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`organization`,children:`Organization`}),(0,H.jsx)(J,{id:`organization`,value:S,onChange:e=>C(e.target.value)})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`country`,children:`Country`}),(0,H.jsx)(J,{id:`country`,value:w,onChange:e=>T(e.target.value)})]})]}),r&&(0,H.jsx)(`p`,{className:`text-destructive text-sm`,children:r}),(0,H.jsx)(q,{type:`submit`,disabled:n,children:n?`Saving…`:`Save changes`})]})})]})]})})}var G4=Object.defineProperty,K4=Object.getOwnPropertySymbols,q4=Object.prototype.hasOwnProperty,J4=Object.prototype.propertyIsEnumerable,Y4=(e,t,n)=>t in e?G4(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,X4=(e,t)=>{for(var n in t||={})q4.call(t,n)&&Y4(e,n,t[n]);if(K4)for(var n of K4(t))J4.call(t,n)&&Y4(e,n,t[n]);return e},Z4=(e,t)=>{var n={};for(var r in e)q4.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&K4)for(var r of K4(e))t.indexOf(r)<0&&J4.call(e,r)&&(n[r]=e[r]);return n},Q4;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e<this.size;e++)o.push(!1);for(let e=0;e<this.size;e++)this.modules.push(o.slice()),this.isFunction.push(o.slice());this.drawFunctionPatterns();let s=this.addEccAndInterleave(r);if(this.drawCodewords(s),a==-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(a=t,e=n),this.applyMask(t)}}i(0<=a&&a<=7),this.mask=a,this.applyMask(a),this.drawFormatBits(a),this.isFunction=[]}static encodeText(n,r){let i=e.QrSegment.makeSegments(n);return t.encodeSegments(i,r)}static encodeBinary(n,r){let i=e.QrSegment.makeBytes(n);return t.encodeSegments([i],r)}static encodeSegments(e,r,a=1,s=40,c=-1,l=!0){if(!(t.MIN_VERSION<=a&&a<=s&&s<=t.MAX_VERSION)||c<-1||c>7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.length<p;e^=253)n(e,8,f);let m=[];for(;m.length*8<f.length;)m.push(0);return f.forEach((e,t)=>m[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0),this.setFunctionModule(e,6,e%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n==0&&r==0||n==0&&r==t-1||n==t-1&&r==0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.errorCorrectionLevel.formatBits<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a<this.size&&0<=o&&o<this.size&&this.setFunctionModule(a,o,i!=2&&i!=4)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!=1)}setFunctionModule(e,t,n){this.modules[t][e]=n,this.isFunction[t][e]=!0}addEccAndInterleave(e){let n=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(n,r))throw RangeError(`Invalid argument`);let a=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][n],o=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][n],s=Math.floor(t.getNumRawDataModules(n)/8),c=a-s%a,l=Math.floor(s/a),u=[],d=t.reedSolomonComputeDivisor(o);for(let n=0,r=0;n<a;n++){let i=e.slice(r,r+l-o+(n<c?0:1));r+=i.length;let a=t.reedSolomonComputeRemainder(i,d);n<c&&i.push(0),u.push(i.concat(a))}let f=[];for(let e=0;e<u[0].length;e++)u.forEach((t,n)=>{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i<this.size;i++)for(let a=0;a<2;a++){let o=t-a,s=t+1&2?i:this.size-1-i;!this.isFunction[s][o]&&n<e.length*8&&(this.modules[s][o]=r(e[n>>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.isFunction[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[n][o]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size;n++){let r=!1,i=0,a=[0,0,0,0,0,0,0];for(let o=0;o<this.size;o++)this.modules[o][n]==r?(i++,i==5?e+=t.PENALTY_N1:i>5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n<this.size-1;n++)for(let r=0;r<this.size-1;r++){let i=this.modules[n][r];i==this.modules[n][r+1]&&i==this.modules[n+1][r]&&i==this.modules[n+1][r+1]&&(e+=t.PENALTY_N2)}let n=0;for(let e of this.modules)n=e.reduce((e,t)=>e+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t<e-1;t++)n.push(0);n.push(1);let r=1;for(let i=0;i<e;i++){for(let e=0;e<n.length;e++)n[e]=t.reedSolomonMultiply(n[e],r),e+1<n.length&&(n[e]^=n[e+1]);r=t.reedSolomonMultiply(r,2)}return n}static reedSolomonComputeRemainder(e,n){let r=n.map(e=>0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e<t.length;){let i=Math.min(t.length-e,3);n(parseInt(t.substring(e,e+i),10),i*3+1,r),e+=i}return new e(e.Mode.NUMERIC,t.length,r)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let r=[],i;for(i=0;i+2<=t.length;i+=2){let a=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i))*45;a+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i+1)),n(a,11,r)}return i<t.length&&n(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(i)),6,r),new e(e.Mode.ALPHANUMERIC,t.length,r)}static makeSegments(t){return t==``?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let r=[];if(t<0)throw RangeError(`ECI assignment value out of range`);if(t<128)n(t,8,r);else if(t<16384)n(2,2,r),n(t,14,r);else if(t<1e6)n(6,3,r),n(t,21,r);else throw RangeError(`ECI assignment value out of range`);return new e(e.Mode.ECI,0,r)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let n=0;for(let r of e){let e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)==`%`?(t.push(parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}};a.NUMERIC_REGEX=/^[0-9]*$/,a.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,a.ALPHANUMERIC_CHARSET=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`;let o=a;e.QrSegment=a})(Q4||={}),(e=>{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(Q4||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(Q4||={});var $4=Q4,e3={L:$4.QrCode.Ecc.LOW,M:$4.QrCode.Ecc.MEDIUM,Q:$4.QrCode.Ecc.QUARTILE,H:$4.QrCode.Ecc.HIGH},t3=128,n3=`L`,r3=`#FFFFFF`,i3=`#000000`,a3=!1,o3=1,s3=4,c3=0,l3=.1;function u3(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function d3(e,t){return e.slice().map((e,n)=>n<t.y||n>=t.y+t.h?e:e.map((e,n)=>n<t.x||n>=t.x+t.w?e:!1))}function f3(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*l3),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function p3(e,t){return t==null?e?s3:c3:Math.max(Math.floor(t),0)}function m3({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=v.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...$4.QrSegment.makeSegments(t)),e),[]);return $4.QrCode.encodeSegments(r,e3[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=v.useMemo(()=>{let e=c.getModules(),t=p3(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:f3(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var h3=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),g3=v.forwardRef(function(e,t){let n=e,{value:r,size:i=t3,level:a=n3,bgColor:o=r3,fgColor:s=i3,includeMargin:c=a3,minVersion:l=o3,boostLevel:u,marginSize:d,imageSettings:f}=n,p=Z4(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=Z4(p,[`style`]),g=f?.src,_=v.useRef(null),y=v.useRef(null),b=v.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=v.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=m3({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});v.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=y.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=d3(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,h3?t.fill(new Path2D(u3(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),v.useEffect(()=>{S(!1)},[g]);let D=X4({height:i,width:i},m),O=null;return g!=null&&(O=v.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:y,crossOrigin:E?.crossOrigin})),v.createElement(v.Fragment,null,v.createElement(`canvas`,X4({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});g3.displayName=`QRCodeCanvas`;var _3=v.forwardRef(function(e,t){let n=e,{value:r,size:i=t3,level:a=n3,bgColor:o=r3,fgColor:s=i3,includeMargin:c=a3,minVersion:l=o3,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=Z4(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:y}=m3({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&y!=null&&(y.excavation!=null&&(b=d3(g,y.excavation)),x=v.createElement(`image`,{href:p.src,height:y.h,width:y.w,x:y.x+h,y:y.y+h,preserveAspectRatio:`none`,opacity:y.opacity,crossOrigin:y.crossOrigin}));let S=u3(b,h);return v.createElement(`svg`,X4({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&v.createElement(`title`,null,d),v.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),v.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});_3.displayName=`QRCodeSVG`;function v3(){let{user:e,updateUser:t,logout:n}=_a(),{loading:r,error:i,request:a}=Eb(),{loading:o,error:s,request:c}=Eb(),[l,u]=(0,v.useState)(``),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(``),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(null),[w,T]=(0,v.useState)(``),[E,D]=(0,v.useState)(``),[O,k]=(0,v.useState)(!1),[A,j]=(0,v.useState)([]),[M,N]=(0,v.useState)(!1);(0,v.useEffect)(()=>{typeof e?.twoFactorEnabled==`boolean`&&x(e.twoFactorEnabled)},[e?.twoFactorEnabled]);function P(){u(``),f(``),m(``),g(``),y(null),C(null),T(``)}function F(){C(null),T(``),D(``),k(!1),N(!1)}async function I(e){if(e.preventDefault(),y(null),p!==h){y(`New passwords do not match`);return}try{await a(`/cms/admin/users/me/password`,`PATCH`,{currentPassword:d,newPassword:p}),P(),X.success(`Password updated`)}catch{X.error(`Could not update password`)}}async function L(){C(await c(`/cms/admin/users/me/2fa/setup`,`POST`))}async function R(){try{let e=await c(`/cms/admin/users/me/2fa/verify`,`POST`,{code:w});x(!0),t({twoFactorEnabled:!0}),C(null),T(``),k(!0),j(e.backupCodes??[]),X.success(`Two-factor authentication enabled`)}catch{X.error(`Could not enable 2FA`)}}async function ee(){try{await c(`/cms/admin/users/me/2fa/disable`,`POST`,{code:w,password:E}),x(!1),t({twoFactorEnabled:!1}),T(``),D(``),j([]),N(!1),X.success(`Two-factor authentication disabled`)}catch{X.error(`Could not disable 2FA`)}}return(0,H.jsxs)(fT,{children:[(0,H.jsxs)(pT,{children:[(0,H.jsx)(mT,{className:`uppercase`,children:`Security`}),(0,H.jsx)(hT,{})]}),(0,H.jsx)(gT,{className:`space-y-6`,children:(0,H.jsxs)(Qj,{value:l,children:[(0,H.jsxs)($j,{children:[(0,H.jsx)(eM,{value:`password`,onClick:()=>u(e=>e===`password`?``:`password`),children:`Password`}),(0,H.jsx)(eM,{value:`two-factor`,onClick:()=>u(e=>e===`two-factor`?``:`two-factor`),children:`2FA`})]}),(0,H.jsx)(tM,{value:`password`,className:`mt-4`,children:(0,H.jsxs)(`div`,{className:`space-y-4 rounded-md border border-border p-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Update your account password.`}),(0,H.jsx)(q,{variant:`ghost`,size:`icon`,onClick:P,children:(0,H.jsx)(us,{className:`size-4`})})]}),(0,H.jsxs)(`form`,{onSubmit:I,className:`space-y-4`,children:[(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`current`,children:`Current password`}),(0,H.jsx)(J,{id:`current`,type:`password`,value:d,onChange:e=>f(e.target.value),required:!0})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`new`,children:`New password`}),(0,H.jsx)(J,{id:`new`,type:`password`,value:p,onChange:e=>m(e.target.value),required:!0,minLength:8})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(Y,{htmlFor:`confirm`,children:`Confirm new password`}),(0,H.jsx)(J,{id:`confirm`,type:`password`,value:h,onChange:e=>g(e.target.value),required:!0})]}),(_??i)&&(0,H.jsx)(`p`,{className:`text-destructive text-sm`,children:_??i}),(0,H.jsx)(q,{type:`submit`,disabled:r,children:r?`Saving…`:`Update password`})]})]})}),(0,H.jsx)(tM,{value:`two-factor`,className:`mt-4`,children:(0,H.jsxs)(`div`,{className:`space-y-4`,children:[!b&&!S&&(0,H.jsx)(q,{variant:`secondary`,onClick:L,disabled:o,children:`Enable 2FA`}),S&&!b&&(0,H.jsxs)(`div`,{className:`space-y-3 rounded-md border border-border p-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Scan this QR code with your authenticator app and enter the 6-digit code.`}),(0,H.jsx)(q,{variant:`ghost`,size:`icon`,onClick:F,children:(0,H.jsx)(us,{className:`size-4`})})]}),(0,H.jsx)(`div`,{className:`inline-flex rounded-md bg-white p-2`,children:(0,H.jsx)(_3,{value:S.otpauthUri,size:176})}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Manual code: `,S.secret]}),(0,H.jsx)(Jb,{maxLength:6,value:w,onChange:T,containerClassName:`w-fit`,className:`w-fit`,children:(0,H.jsxs)(Yb,{className:`w-fit`,children:[(0,H.jsx)(Xb,{index:0}),(0,H.jsx)(Xb,{index:1}),(0,H.jsx)(Xb,{index:2}),(0,H.jsx)(Xb,{index:3}),(0,H.jsx)(Xb,{index:4}),(0,H.jsx)(Xb,{index:5})]})}),(0,H.jsx)(q,{onClick:R,disabled:o||w.length!==6,children:`Confirm and enable 2FA`}),s&&(0,H.jsx)(`p`,{className:`text-sm text-destructive`,children:s})]}),b&&(0,H.jsxs)(`div`,{className:`space-y-3 rounded-md border border-border p-4`,children:[O&&(0,H.jsxs)(`div`,{className:`space-y-3 rounded-md border border-emerald-500/40 bg-emerald-500/10 p-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-emerald-300`,children:`2FA is now enabled.`}),(0,H.jsx)(`p`,{className:`text-xs text-emerald-200/90`,children:`For security, re-login is recommended now. This prevents accidental changes and confirms your new security state.`}),(0,H.jsx)(q,{variant:`default`,onClick:()=>{n()},children:`Re-login now`}),A.length>0&&(0,H.jsxs)(`div`,{className:`space-y-2 rounded-md border border-emerald-400/30 bg-background/40 p-3`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium text-emerald-200`,children:`Save these backup codes now. Each code can be used once if you lose access to your authenticator.`}),(0,H.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:A.map(e=>(0,H.jsx)(`code`,{className:`rounded bg-black/20 px-2 py-1 text-xs text-emerald-100`,children:e},e))}),(0,H.jsx)(q,{variant:`outline`,onClick:async()=>{try{await navigator.clipboard.writeText(A.join(`
@@ -12,7 +12,7 @@
12
12
  href="https://fonts.googleapis.com/css2?family=Google+Sans:ital,opsz,wght@0,17..18,400..700;1,17..18,400..700&display=swap"
13
13
  rel="stylesheet"
14
14
  />
15
- <script type="module" crossorigin src="/admin/assets/index-B2XflQNa.js"></script>
15
+ <script type="module" crossorigin src="/admin/assets/index-DHHuGsHR.js"></script>
16
16
  <link rel="stylesheet" crossorigin href="/admin/assets/index-BhxOFNX5.css">
17
17
  </head>
18
18
  <body>
package/dist/index.js CHANGED
@@ -93,7 +93,7 @@ function getUpdateScriptCommand(name) {
93
93
  }
94
94
 
95
95
  // src/commands/init.ts
96
- var PACKAGE_VERSION = "0.28.1";
96
+ var PACKAGE_VERSION = "0.28.2";
97
97
  function generateSecret() {
98
98
  return randomBytes(32).toString("hex");
99
99
  }
@@ -202,7 +202,7 @@ import { dirname, join as join3, resolve as resolve2 } from "path";
202
202
  async function start() {
203
203
  config({ path: resolve2(process.cwd(), ".env") });
204
204
  process.env.PLANK_ADMIN_DIST = join3(dirname(fileURLToPath(import.meta.url)), "admin");
205
- const { start: startServer } = await import("./server-ZUY5LBM4.js");
205
+ const { start: startServer } = await import("./server-IIDIHQ5Y.js");
206
206
  await startServer();
207
207
  }
208
208
 
@@ -652,6 +652,7 @@ function validate(contentType, payload) {
652
652
  import express from "express";
653
653
  import cors from "cors";
654
654
  import helmet from "helmet";
655
+ import { readFile as readFile5 } from "fs/promises";
655
656
  import { join as join6, dirname as dirname3 } from "path";
656
657
  import { fileURLToPath as fileURLToPath4 } from "url";
657
658
 
@@ -6499,7 +6500,15 @@ if (isDev) {
6499
6500
  } else {
6500
6501
  const adminDist = process.env.PLANK_ADMIN_DIST ?? join6(dirname3(fileURLToPath4(import.meta.url)), "../public/admin");
6501
6502
  app.use("/admin", express.static(adminDist));
6502
- app.get("/admin/*path", (_req, res) => res.sendFile(join6(adminDist, "index.html")));
6503
+ app.get("/admin/*path", async (_req, res) => {
6504
+ try {
6505
+ const source = await readFile5(join6(adminDist, "index.html"), "utf8");
6506
+ res.type("text/html");
6507
+ res.send(source);
6508
+ } catch {
6509
+ res.status(404).send("Admin entry not found");
6510
+ }
6511
+ });
6503
6512
  }
6504
6513
  app.use(errorHandler);
6505
6514
  var app_default = app;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plank-cms/plank",
3
- "version": "0.28.1",
3
+ "version": "0.28.2",
4
4
  "description": "Self-hosted headless CMS. Deploy in minutes on your own infrastructure.",
5
5
  "type": "module",
6
6
  "files": [
@@ -55,9 +55,9 @@
55
55
  "devDependencies": {
56
56
  "@types/fs-extra": "^11.0.4",
57
57
  "tsup": "^8.5.0",
58
- "@plank-cms/core": "0.28.1",
59
- "@plank-cms/schema": "0.28.1",
60
- "@plank-cms/db": "0.28.1"
58
+ "@plank-cms/core": "0.28.2",
59
+ "@plank-cms/db": "0.28.2",
60
+ "@plank-cms/schema": "0.28.2"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsup",