@trokky/studio 2.0.5 → 2.0.7

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.
@@ -733,10 +733,10 @@ This field accepts the following values:
733
733
 
734
734
  See [documentation](https://example.com) for more details.`,options:{variant:`info`,markdown:!0,collapsible:!0,defaultCollapsed:!1}}}]}};function n$(){Jo.register($o,`builtin`),Jo.register(as,`builtin`),Jo.register(ds,`builtin`),Jo.register(gs,`builtin`),Jo.register(Es,`builtin`),Jo.register(Ns,`builtin`),Jo.register(Gs,`builtin`),Jo.register(Qs,`builtin`),Jo.register(Pc,`builtin`),Jo.register(Zc,`builtin`),Jo.register(Sl,`builtin`),Jo.register(El,`builtin`),Jo.register(Al,`builtin`),Jo.register(Nl,`builtin`),Jo.register(Ll,`builtin`),Jo.register(UR,`builtin`),Jo.register(vz,`builtin`),Jo.register(Ql,`builtin`),Jo.register(wz,`builtin`),Jo.register(fV,`builtin`),Jo.register(gV,`builtin`),Jo.register(qQ,`builtin`),Jo.register(t$,`builtin`),Jo.markInitialized()}if(typeof globalThis<`u`){let e=globalThis;e.__TROKKY_BUILTIN_FIELDS_REGISTERED__||=(n$(),!0)}else n$();function r$({fieldId:e,value:t,onChange:n,definition:r,hasError:i,error:a,validationState:o,isDisabled:s,isReadonly:c,documentContext:l,onValidationChange:u,onFocus:d,onBlur:f,mode:p=`edit`,compact:m=!1,maxLength:h,...g}){let _=Jo.get(r.type);if(!_){let t=`Unsupported field type: ${r.type}`;return p===`preview`?(0,V.jsx)(`span`,{className:`text-gray-500 dark:text-gray-400 italic text-sm`,children:t}):(0,V.jsx)(qc,{fieldId:e,definition:r,hasError:i,error:a,validationState:o,children:(0,V.jsx)(`div`,{className:`text-sm text-gray-500 italic`,children:t})})}if(p===`preview`){let p=_.previewComponent;return p?(0,V.jsx)(p,{fieldId:e,value:t,onChange:n,definition:r,hasError:i,error:a,validationState:o,isDisabled:s,isReadonly:c,documentContext:l,onValidationChange:u,onFocus:d,onBlur:f,compact:m,maxLength:h,...g}):(0,V.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 text-sm`,children:typeof t==`string`?t:JSON.stringify(t)})}let v=_.component;return(0,V.jsx)(qc,{fieldId:e,definition:r,hasError:i,error:a,validationState:o,children:(0,V.jsx)(v,{fieldId:e,value:t,onChange:n,definition:r,hasError:i,error:a,validationState:o,isDisabled:s,isReadonly:c,mode:p,documentContext:l,onValidationChange:u,onFocus:d,onBlur:f,...g})})}var i$=Fr(`DocumentForm`);function a$(e){return e.replace(/([A-Z])/g,` $1`).replace(/[_-]/g,` `).split(` `).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `).trim()}function o$(){i$.debug(`Component initializing`);let{t:e}=H(`studio`),{documentId:t}=s(),{schema:n,document:r,errors:i,onDocumentChange:a,onFieldBlur:o,onValidationChange:c,isNewDocument:l,isReadOnly:u}=Ko(),d=pa(),f=(0,B.useCallback)(e=>{if(i$.debug(`DocumentForm - Processing fields`,{fields:e,isArray:Array.isArray(e),isObject:e&&typeof e==`object`,keys:e?Object.keys(e):null}),Array.isArray(e))return i$.debug(`DocumentForm - Using array fields`,{count:e.length}),e;if(e&&typeof e==`object`){let t=Object.entries(e).map(([e,t])=>({name:e,title:t.title||a$(e),...t}));return i$.debug(`Converted object fields to array`,{originalFieldCount:Object.keys(e).length,convertedFieldCount:t.length}),t}return i$.warn(`No valid fields found`,{fieldsType:typeof e}),[]},[]),p=(0,B.useCallback)((e,t)=>{a({[e]:t})},[a]),m=(0,B.useCallback)(e=>{o([e])},[o]),h=(0,B.useCallback)(e=>{if(i[e])return i[e];let t=Object.keys(i).find(t=>t.startsWith(`${e}.`)||t.startsWith(`${e}[`));return t?i[t]:void 0},[i]),g=(0,B.useMemo)(()=>{if(n&&r)return{documentId:t||void 0,schema:n.name,isNewDocument:l||!1,allValues:r,nestingLevel:0}},[n,r,t,l]),_=(0,B.useCallback)(e=>{let t=r?.[e.name],n=h(e.name);return(0,V.jsx)(r$,{fieldId:e.name,value:t,onChange:u?()=>{}:t=>p(e.name,t),onBlur:u?()=>{}:()=>m(e.name),definition:e,hasError:!!n,error:n,mode:`edit`,isDisabled:u,disabled:u,studioContext:d||void 0,documentContext:g},e.name)},[r,h,p,m,d,g,u]),v=e=>(0,V.jsx)(`div`,{className:`space-y-6`,children:e.map(_)}),y=(0,B.useMemo)(()=>f(n?.fields),[n?.fields,f]),b=(0,B.useMemo)(()=>!y||!r?y||[]:y.filter(e=>{let t=Lc({name:e.name,conditional:e.conditional,hidden:e.hidden},r);return i$.debug(`Field visibility evaluation`,{fieldName:e.name,visible:t.visible,reason:t.reason}),t.visible}),[y,r]),x=(0,B.useMemo)(()=>new Set(b.map(e=>e.name)),[b]),S=(0,B.useMemo)(()=>Object.keys(i).filter(e=>{let[t]=e.split(/[.[]/);return x.has(t)}).length,[i,x]);return(0,B.useEffect)(()=>{c(S>0)},[S,c]),!n||!r?(i$.debug(`Waiting for schema or document to load`,{hasSchema:!!n,hasDocument:!!r}),(0,V.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,V.jsx)(`div`,{className:`text-gray-500 dark:text-gray-400`,children:e(`documentEditor.loadingForm`)})})):(i$.debug(`Schema loaded successfully`,{schemaName:n.name,fieldsType:typeof n.fields}),(0,V.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,V.jsx)(`div`,{className:`max-w-4xl mx-auto px-3 py-4 md:px-8 md:py-6`,children:(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700`,children:(0,V.jsxs)(`div`,{className:`px-4 py-4 md:px-8 md:py-6`,children:[b.length>0&&v(b),b.length===0&&(0,V.jsx)(`div`,{className:`text-center py-12`,children:(0,V.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`documentEditor.noFieldsDefined`)})})]})})})}))}function s$(e){return e.reduce((e,t)=>typeof t==`number`?`${e}[${t}]`:e?`${e}.${t}`:String(t),``)}function c$(e,t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}function l$(e,t,n){if(t.length===0)return n;let[r,...i]=t;if(typeof r==`string`&&!ac(r))return e;if(typeof r==`number`){let t=Array.isArray(e)?e:[],a=t.slice();return a[r]=l$(t[r],i,n),a}let a=e&&typeof e==`object`&&!Array.isArray(e)?e:{};return{...a,[r]:l$(a[r],i,n)}}var u$=new Set([rc]);function d$(e,t){return Object.keys(e).filter(n=>!t.has(n)&&e[n]!==void 0)}function f$(e,t,n=new Set){if(Object.is(e,t))return!0;if(e instanceof Date||t instanceof Date)return e instanceof Date&&t instanceof Date&&e.getTime()===t.getTime();if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!f$(e[r],t[r],n))return!1;return!0}if(e===null||t===null||typeof e!=`object`||typeof t!=`object`)return!1;let r=d$(e,n),i=d$(t,n);return r.length===i.length&&r.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&f$(e[r],t[r],n))}function p$(e=null){let t=e==null?e:cc(e);return{initial:t??null,current:t??null,errors:{},status:`idle`}}function m$(e,t){switch(t.type){case`load`:return p$(t.document);case`setValue`:{if(t.path.length===0)return e;let n=l$(e.current??{},t.path,cc(t.value));if(n===e.current)return e;let r=s$(t.path),i=e.errors;if(Object.keys(i).some(e=>e===r||e.startsWith(`${r}.`)||e.startsWith(`${r}[`))){i={};for(let[t,n]of Object.entries(e.errors))t===r||t.startsWith(`${r}.`)||t.startsWith(`${r}[`)||(i[t]=n)}return{...e,current:n,errors:i,status:`idle`}}case`reset`:return{...e,current:e.initial,errors:{},status:`idle`};case`resetField`:{if(t.path.length===0)return e;let n=c$(e.initial,t.path),r=l$(e.current??{},t.path,n),i=s$(t.path),a={...e.errors};return delete a[i],{...e,current:r,errors:a,status:`idle`}}case`setErrors`:return{...e,errors:t.errors};case`markSaved`:{let n=t.document===void 0?e.current:t.document,r=n==null?n:cc(n);return{initial:r??null,current:r??null,errors:{},status:`saved`}}case`setStatus`:return{...e,status:t.status};default:return e}}var h$=new WeakMap;function g$(e){let t=h$.get(e);if(t!==void 0)return t;let n=e.initial!==e.current&&!f$(e.initial,e.current,u$);return h$.set(e,n),n}function _$(e,t){return t?.title||e}function v$(e,t,n,r,i,a){let o=n?.type;if(n?.required&&dc(e)){i[s$(r)]=`${_$(t,n)} is required`;return}if(dc(e))return;if(o===`object`&&n?.fields){if(!e||typeof e!=`object`||Array.isArray(e))return;for(let t of ec(n))(!a.isVisible||a.isVisible({name:t.name,...t.definition},e))&&v$(e[t.name],t.name,t.definition,[...r,t.name],i,a);return}if(o===`array`){if(!Array.isArray(e))return;let o=n?.of;if(!o)return;e.forEach((e,s)=>{v$(e,`${_$(t,n)} item ${s+1}`,o,[...r,s],i,a)});return}let s=a.getPlugin?.(o);if(s&&typeof s.validate==`function`)try{let a=s.validate(e,{...n,title:_$(t,n)});a&&a.isValid===!1&&a.errors?.length&&(i[s$(r)]=a.errors[0])}catch{}}function y$(e,t,n={}){let r={},i=e&&typeof e==`object`?e:{},a=n.rootPath?.[0];for(let{name:e,definition:o}of ec(t))(a===void 0||e===a)&&(!n.isVisible||n.isVisible({name:e,...o},i))&&v$(i[e],e,o,[e],r,n);return r}function b$(){let[e,t]=(0,B.useReducer)(m$,null,()=>p$(null)),n=(0,B.useRef)(e);n.current=e;let r=(0,B.useMemo)(()=>({load:e=>t({type:`load`,document:e}),setValue:(e,n)=>t({type:`setValue`,path:e,value:n}),reset:()=>t({type:`reset`}),resetField:e=>t({type:`resetField`,path:e}),setErrors:e=>t({type:`setErrors`,errors:e}),markSaved:e=>t({type:`markSaved`,document:e}),setStatus:e=>t({type:`setStatus`,status:e})}),[]),i=g$(e),a=(0,B.useCallback)(()=>n.current,[]);return{state:e,document:e.current,errors:e.errors,status:e.status,isDirty:i,getState:a,...r}}function x$(){let{t:e}=H(`studio`),{schema:t,document:n,documentState:r,currentMode:i,isNewDocument:a,hasUnsavedChanges:o,hasValidationErrors:s,isReadOnly:c,hasPublishPermission:l,saving:u,onStateChange:d,onModeChange:f,onSave:p,onCancel:m,onToggleMobileSidebar:h}=Ko(),[g,_]=(0,B.useState)(!1),v=async t=>{(!qo.requiresConfirmation(r,t)||confirm(e(`documentEditor.confirmStateChange`,{from:qo.getStateName(r),to:qo.getStateName(t)})))&&(await d(t),_(!1))},y=(0,B.useMemo)(()=>{let r=t?.title||t?.name||`Document`;if(!n)return e(`documentEditor.newDocument`,{type:r});if(t?.fields){let e=(Array.isArray(t.fields)?t.fields:Object.entries(t.fields).map(([e,t])=>({name:e,...t})))[0];if(e&&n[e.name]){let t=n[e.name];if(typeof t==`string`&&t.trim()&&!t.startsWith(`New `))return t}}return n.title&&!n.title.startsWith(`New `)?n.title:n.name&&!n.name.startsWith(`New `)?n.name:n.slug?n.slug:e(`documentEditor.newDocument`,{type:r})},[n,t,e]),b=t?.singleton===!0,x=o,S=qo.getAvailableTransitions(r);return(0,V.jsxs)(`div`,{className:`flex-shrink-0 bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700`,children:[(0,V.jsxs)(`div`,{className:`px-6 py-3`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-4`,children:[!b&&(0,V.jsxs)(`button`,{onClick:m,className:`flex items-center text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors`,title:e(`documentEditor.backTo`,{type:t?.title||t?.name}),children:[(0,V.jsx)(be,{className:`h-4 w-4 mr-1`}),(0,V.jsx)(`span`,{className:`hidden sm:inline`,children:e(`documentEditor.backTo`,{type:t?.title||t?.name})}),(0,V.jsx)(`span`,{className:`sm:hidden`,children:e(`common.back`)})]}),(0,V.jsxs)(`span`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:[t?.title||t?.name,` `,a?`(New)`:``]}),l?(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsxs)(`button`,{onClick:()=>_(!g),className:`inline-flex items-center px-3 py-1.5 rounded-md text-sm font-medium border ${S$(r)}`,children:[(0,V.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full mr-2 ${C$(r)}`}),e(r===`published`?`documentEditor.published`:`documentEditor.draft`),(0,V.jsx)(ye,{className:`ml-1 h-4 w-4`})]}),g&&(0,V.jsx)(`div`,{className:`absolute top-full left-0 mt-1 w-48 bg-white dark:bg-gray-800 rounded-md shadow-lg border border-gray-200 dark:border-gray-700 z-10`,children:(0,V.jsx)(`div`,{className:`py-1`,children:S.map(t=>(0,V.jsxs)(`button`,{onClick:()=>v(t),className:`block w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700`,children:[(0,V.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full mr-2 ${C$(t)}`}),e(t===`published`?`documentEditor.published`:`documentEditor.draft`)]},t))})})]}):(0,V.jsxs)(`span`,{className:`inline-flex items-center px-3 py-1.5 rounded-md text-sm font-medium border ${S$(r)}`,children:[(0,V.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full mr-2 ${C$(r)}`}),e(r===`published`?`documentEditor.published`:`documentEditor.draft`)]})]}),(0,V.jsxs)(`div`,{className:`flex items-center space-x-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center bg-gray-100 dark:bg-gray-700 rounded-lg p-1`,children:[(0,V.jsxs)(`button`,{onClick:()=>f(`form`),className:`flex items-center px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${i===`form`?`bg-white dark:bg-gray-600 text-gray-900 dark:text-white shadow-sm`:`text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white`}`,children:[(0,V.jsx)(ct,{className:`h-4 w-4 mr-1.5`}),e(`documentEditor.edit`)]}),(0,V.jsxs)(`button`,{onClick:()=>f(`preview`),className:`flex items-center px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${i===`preview`?`bg-white dark:bg-gray-600 text-gray-900 dark:text-white shadow-sm`:`text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white`}`,children:[(0,V.jsx)(ce,{className:`h-4 w-4 mr-1.5`}),e(`documentEditor.preview`)]})]}),(0,V.jsxs)(`div`,{className:`flex items-center space-x-3`,children:[x&&(0,V.jsxs)(U,{variant:`outline`,onClick:m,children:[(0,V.jsx)(tt,{className:`h-4 w-4 mr-1.5`}),e(`common.cancel`)]}),(0,V.jsxs)(U,{onClick:p,loading:u,disabled:c||u||!o||s,title:c?e(`documentEditor.readOnlyMode`):void 0,children:[(0,V.jsx)(ve,{className:`h-4 w-4 mr-1.5`}),e(c?`documentEditor.readOnly`:a?`common.create`:`common.save`)]})]})]})]}),(0,V.jsx)(`div`,{className:`border-t border-gray-200 dark:border-gray-700 mb-2`}),(0,V.jsxs)(`div`,{className:`mb-2 flex items-start justify-between`,children:[(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsx)(`h1`,{className:`text-lg font-semibold text-gray-900 dark:text-white truncate`,children:y}),(o||s||c)&&(0,V.jsxs)(`div`,{className:`flex items-center space-x-2 mt-0.5`,children:[c&&(0,V.jsxs)(`span`,{className:`text-xs text-blue-600 dark:text-blue-400`,children:[`• `,e(`documentEditor.readOnlyMode`)]}),o&&(0,V.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-400`,children:[`• `,e(`documentEditor.unsavedChanges`)]}),s&&(0,V.jsxs)(`span`,{className:`text-xs text-red-600 dark:text-red-400`,children:[`• `,e(`documentEditor.validationErrors`)]})]})]}),(0,V.jsx)(`button`,{onClick:()=>h(!0),className:`md:hidden flex-shrink-0 ml-2 p-1.5 text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 hover:bg-blue-50 dark:hover:bg-blue-900/20 rounded-full transition-colors`,title:e(`documentEditor.documentInfo`),children:(0,V.jsx)(ue,{className:`h-6 w-6`})})]})]}),g&&(0,V.jsx)(`div`,{className:`fixed inset-0 z-0`,onClick:()=>_(!1)})]})}function S$(e){let t=`border`;switch(e){case`draft`:return`${t} border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-700 text-gray-700 dark:text-gray-300`;case`published`:return`${t} border-green-300 dark:border-green-600 bg-green-50 dark:bg-green-900 text-green-700 dark:text-green-300`;default:return`${t} border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-700 text-gray-700 dark:text-gray-300`}}function C$(e){switch(e){case`draft`:return`bg-gray-400 dark:bg-gray-500`;case`published`:return`bg-green-500 dark:bg-green-400`;default:return`bg-gray-400 dark:bg-gray-500`}}function w$({before:e,after:t,operation:n}){let{t:r}=H(`studio`),[i,a]=(0,B.useState)(!1),o=()=>{let r=[];return n===`create`&&t?(Object.entries(t).forEach(([e,t])=>{(i||!e.startsWith(`_`))&&r.push({field:e,beforeValue:void 0,afterValue:t,changeType:`added`})}),r):n===`delete`&&e?(Object.entries(e).forEach(([e,t])=>{(i||!e.startsWith(`_`))&&r.push({field:e,beforeValue:t,afterValue:void 0,changeType:`removed`})}),r):(e&&t&&new Set([...Object.keys(e),...Object.keys(t)]).forEach(n=>{if(!i&&n.startsWith(`_`))return;let a=e[n],o=t[n];if(!s(a,o)){let e;e=a===void 0?`added`:o===void 0?`removed`:`modified`,r.push({field:n,beforeValue:a,afterValue:o,changeType:e})}}),r)},s=(e,t)=>{if(e===t)return!0;if(e==null||t==null||typeof e!=typeof t)return!1;if(typeof e==`object`)try{return JSON.stringify(e)===JSON.stringify(t)}catch{return!1}return!1},c=e=>{if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`)return e.length>100?`${e.substring(0,100)}...`:e;if(typeof e==`boolean`||typeof e==`number`)return e.toString();if(typeof e==`object`)try{let t=JSON.stringify(e,null,2);return t.length>200?`${t.substring(0,200)}...`:t}catch{return`[Object]`}return String(e)},l=e=>{switch(e){case`added`:return{icon:Ne,bgColor:`bg-green-50 dark:bg-green-900/20`,textColor:`text-green-800 dark:text-green-200`,borderColor:`border-green-200 dark:border-green-800`};case`removed`:return{icon:Ne,bgColor:`bg-red-50 dark:bg-red-900/20`,textColor:`text-red-800 dark:text-red-200`,borderColor:`border-red-200 dark:border-red-800`};case`modified`:return{icon:Ne,bgColor:`bg-blue-50 dark:bg-blue-900/20`,textColor:`text-blue-800 dark:text-blue-200`,borderColor:`border-blue-200 dark:border-blue-800`}}},u=o();return u.length===0?(0,V.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400 text-center py-2`,children:r(`changesDiff.noVisibleChanges`)}):(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsx)(`span`,{className:`text-xs font-medium text-gray-700 dark:text-gray-300`,children:r(`changesDiff.changesCount`,{count:u.length})}),(0,V.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center space-x-1 text-xs text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`,children:[i?(0,V.jsx)(le,{className:`h-3 w-3`}):(0,V.jsx)(ce,{className:`h-3 w-3`}),(0,V.jsx)(`span`,{children:r(i?`changesDiff.hideSystemFields`:`changesDiff.showSystemFields`)})]})]}),(0,V.jsx)(`div`,{className:`space-y-2`,children:u.map((e,t)=>{let n=l(e.changeType),i=n.icon;return(0,V.jsx)(`div`,{className:`border rounded p-2 ${n.bgColor} ${n.borderColor}`,children:(0,V.jsxs)(`div`,{className:`flex items-start space-x-2`,children:[(0,V.jsx)(i,{className:`h-4 w-4 mt-0.5 flex-shrink-0 ${n.textColor}`}),(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsx)(`div`,{className:`text-xs font-medium ${n.textColor}`,children:e.field}),(e.changeType===`removed`||e.changeType===`modified`)&&e.beforeValue!==void 0&&(0,V.jsxs)(`div`,{className:`mt-1`,children:[(0,V.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400 font-medium`,children:[`- `,r(`changesDiff.before`)]}),(0,V.jsx)(`div`,{className:`text-xs text-gray-600 dark:text-gray-400 bg-red-100 dark:bg-red-900/30 rounded px-2 py-1 mt-1 font-mono`,children:c(e.beforeValue)})]}),(e.changeType===`added`||e.changeType===`modified`)&&e.afterValue!==void 0&&(0,V.jsxs)(`div`,{className:`mt-1`,children:[(0,V.jsxs)(`div`,{className:`text-xs text-green-600 dark:text-green-400 font-medium`,children:[`+ `,r(`changesDiff.after`)]}),(0,V.jsx)(`div`,{className:`text-xs text-gray-600 dark:text-gray-400 bg-green-100 dark:bg-green-900/30 rounded px-2 py-1 mt-1 font-mono`,children:c(e.afterValue)})]})]})]})},`${e.field}-${t}`)})})]})}var T$=Fr(`AuditLogEntry`);function E$({auditLog:e,isExpanded:t,onToggleExpansion:n,isLatest:r=!1}){let{t:i}=H(`studio`),{timeAgo:a,fullDate:o}=(e=>{try{let t=new Date(e);return{timeAgo:ko(t,{addSuffix:!0}),fullDate:t.toLocaleString()}}catch(t){return T$.warn(`Failed to format timestamp`,t),{timeAgo:`Unknown time`,fullDate:e}}})(e.timestamp),s=(e=>{switch(e){case`create`:return{icon:Ne,text:i(`auditEntry.created`),color:`text-green-600 dark:text-green-400`};case`update`:return{icon:ct,text:i(`auditEntry.updated`),color:`text-blue-600 dark:text-blue-400`};case`delete`:return{icon:Be,text:i(`auditEntry.deleted`),color:`text-red-600 dark:text-red-400`};case`publish`:return{icon:ce,text:i(`auditEntry.published`),color:`text-purple-600 dark:text-purple-400`};case`unpublish`:return{icon:ce,text:i(`auditEntry.unpublished`),color:`text-orange-600 dark:text-orange-400`};case`restore`:return{icon:re,text:i(`auditEntry.restored`),color:`text-indigo-600 dark:text-indigo-400`};default:return{icon:ct,text:e,color:`text-gray-600 dark:text-gray-400`}}})(e.operation),c=s.icon,l=(()=>{if(!e.changes?.fields||e.changes.fields.length===0)return null;let t=e.changes.fields;return t.length===1?i(`auditEntry.changedField`,{field:t[0]}):t.length<=3?i(`auditEntry.changedFieldsJoin`,{fields:t.join(`, `)}):i(`auditEntry.changedFieldsCount`,{count:t.length})})();return(0,V.jsxs)(`div`,{className:`rounded-lg ${r?`bg-blue-50 dark:bg-blue-900/20`:`bg-gray-50 dark:bg-gray-800/50`}`,children:[(0,V.jsx)(`div`,{className:`px-3 py-2`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-2 flex-1 min-w-0`,children:[(0,V.jsx)(`div`,{className:`flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center ${e.operation===`create`?`bg-green-100 dark:bg-green-900/50`:e.operation===`update`?`bg-blue-100 dark:bg-blue-900/50`:e.operation===`delete`?`bg-red-100 dark:bg-red-900/50`:`bg-gray-100 dark:bg-gray-700`}`,children:(0,V.jsx)(c,{className:`h-3 w-3 ${s.color}`})}),(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-1 text-xs`,children:[(0,V.jsx)(`span`,{className:`font-medium ${s.color}`,children:s.text}),(0,V.jsx)(`span`,{className:`text-gray-400`,children:i(`auditEntry.by`)}),(0,V.jsx)(`span`,{className:`text-gray-600 dark:text-gray-300 font-medium truncate`,children:e.actorUsername?e.actorUsername:e.actorId===`system`?`System`:e.actorId?.startsWith(`user-`)?`User`:e.actorId||`Unknown`}),r&&(0,V.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-blue-100 text-blue-700 dark:bg-blue-800 dark:text-blue-200`,children:i(`auditEntry.latest`)})]}),(0,V.jsxs)(`div`,{className:`flex items-center space-x-2 text-xs text-gray-500 dark:text-gray-400 mt-0.5`,children:[l&&(0,V.jsx)(`span`,{className:`truncate`,children:l}),(0,V.jsxs)(`span`,{title:o,children:[`• `,a]})]})]})]}),e.changes&&(e.changes.before||e.changes.after)&&(0,V.jsx)(`button`,{onClick:n,className:`flex-shrink-0 p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,title:i(t?`auditEntry.hideDetails`:`auditEntry.showDetails`),children:t?(0,V.jsx)(ye,{className:`h-3 w-3`}):(0,V.jsx)(z,{className:`h-3 w-3`})})]})}),t&&e.changes&&(0,V.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-gray-600 p-3 bg-gray-50 dark:bg-gray-750`,children:[(0,V.jsx)(w$,{before:e.changes.before,after:e.changes.after,operation:e.operation}),(0,V.jsx)(`div`,{className:`mt-3 pt-3 border-t border-gray-200 dark:border-gray-600`,children:(0,V.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 text-xs text-gray-500 dark:text-gray-400`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:i(`auditEntry.revision`)}),` `,e.revision]}),e.ipAddress&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:i(`auditEntry.ipAddress`)}),` `,e.ipAddress]}),e.userAgent&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:i(`auditEntry.userAgent`)}),` `,(0,V.jsx)(`span`,{className:`truncate`,title:e.userAgent,children:e.userAgent.length>50?`${e.userAgent.substring(0,50)}...`:e.userAgent})]})]})})]})]})}var D$=Fr(`DocumentHistoryPanel`);function O$({documentId:e,collection:t,isVisible:n=!0}){let{t:r}=H(`studio`),[i,a]=(0,B.useState)([]),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(new Set);(0,B.useEffect)(()=>{e&&n&&p()},[e,n]);let f=async(e,t)=>{if(t[e])return t[e];if(e===`system`)return`System`;try{let t=await W.get(`/users/${e}`);if(t.success&&t.data?.user){let e=t.data.user;return e.username||e.name||e.email||`User`}}catch{}return e.startsWith(`user-`)?`User`:e},p=async()=>{if(e){s(!0),l(null);try{D$.debug(`Loading audit logs for document`,{documentId:e,collection:t});let n=await W.get(`/audit-logs/documents/${e}`,{params:{limit:50,offset:0}});if(n.success&&n.data?.auditLogs){let t=n.data.auditLogs,r={},i=[...new Set(t.map(e=>e.actorId).filter(Boolean))];for(let e of i)r[e]=await f(e,r);let o=t.map(e=>({...e,actorUsername:r[e.actorId]||e.actorUsername}));a(o),D$.info(`Audit logs loaded successfully`,{documentId:e,count:o.length})}else D$.warn(`Failed to load audit logs`,n),l(r(`documentHistory.loadError`))}catch(e){D$.error(`Error loading audit logs`,e),e.response?.status===501?l(r(`documentHistory.notAvailable`)):l(r(`documentHistory.loadError`))}finally{s(!1)}}},m=e=>{let t=new Set(u);t.has(e)?t.delete(e):t.add(e),d(t)};return n?(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(re,{className:`h-4 w-4 mr-1.5 text-gray-500 dark:text-gray-400`}),(0,V.jsx)(`h3`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:r(`documentHistory.title`)})]}),(0,V.jsx)(`button`,{onClick:()=>{p()},disabled:o,className:`p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 disabled:opacity-50`,title:r(`documentHistory.refreshHistory`),children:(0,V.jsx)(ke,{className:`h-3.5 w-3.5 ${o?`animate-spin`:``}`})})]}),(0,V.jsxs)(`div`,{children:[o&&(0,V.jsxs)(`div`,{className:`flex items-center py-4`,children:[(0,V.jsx)(Ao,{}),(0,V.jsx)(`span`,{className:`ml-2 text-xs text-gray-500 dark:text-gray-400`,children:r(`documentHistory.loading`)})]}),c&&(0,V.jsx)(`div`,{className:`py-4`,children:(0,V.jsx)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:c})}),!o&&!c&&i.length===0&&(0,V.jsxs)(`div`,{className:`text-center py-4`,children:[(0,V.jsx)(re,{className:`h-6 w-6 mx-auto text-gray-300 dark:text-gray-600 mb-1`}),(0,V.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:r(`documentHistory.noHistory`)})]}),!o&&!c&&i.length>0&&(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[i.slice(0,10).map((e,t)=>(0,V.jsx)(E$,{auditLog:e,isExpanded:u.has(e.id),onToggleExpansion:()=>m(e.id),isLatest:t===0},e.id)),i.length>10&&(0,V.jsx)(`div`,{className:`text-center pt-1`,children:(0,V.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:r(`documentHistory.moreChanges`,{count:i.length-10})})})]})]})]}):null}var k$=Fr(`DocumentSidebar`);function A$(){let{t:e}=H(`studio`),t=r(),n=pa(),{schema:i,document:a,documentState:o,isNewDocument:s,isMobileSidebarOpen:c,onToggleMobileSidebar:l}=Ko(),{canDeleteDocument:u}=ci(),d=i?.name?u(i.name,a):!1,[f,p]=(0,B.useState)(()=>{try{return localStorage.getItem(`trokky_document_sidebar_collapsed`)===`true`}catch{return!1}});(0,B.useEffect)(()=>{if(c)return Ki(Wi(Ui.md),()=>l(!1))},[c,l]);let[m,h]=(0,B.useState)(null),[g,_]=(0,B.useState)(!1),[,v]=(0,B.useState)(null),[y,b]=(0,B.useState)([]),[x,S]=(0,B.useState)({}),C=e=>{p(e);try{localStorage.setItem(`trokky_document_sidebar_collapsed`,String(e))}catch(e){k$.warn(`Failed to save sidebar state`,e)}};(0,B.useEffect)(()=>{let e=a?._id||a?.id;!s&&e&&(D(),w(),T())},[a?._id,a?.id,a?.author,a?.category,s]);let w=async()=>{let e=await k();v(e)},T=async()=>{let e=a?._id||a?.id;if(e)try{let t=await W.get(`/audit-logs/documents/${e}`,{params:{limit:50}});if(t.success&&t.data?.auditLogs){let e=t.data.auditLogs,n=new Map;for(let t of e)if(t.actorId&&!n.has(t.actorId)){let e=t.actorUsername||await E(t.actorId),r=t.actorId===a?._createdBy?`Creator`:`Editor`;n.set(t.actorId,{id:t.actorId,username:e,role:r})}b(Array.from(n.values()))}}catch(e){k$.warn(`Failed to load contributors from audit logs`,e)}},E=async e=>{if(x[e])return x[e];if(e===`system`)return`System`;try{let t=await W.get(`/users/${e}`);if(t.success&&t.data?.user){let n=t.data.user,r=n.username||n.name||n.email||e;return S(t=>({...t,[e]:r})),r}}catch{k$.debug(`Could not resolve username for`,e)}return e.startsWith(`user-`)?`User`:e},D=async()=>{let e=a?._id||a?.id;if(e&&i)try{_(!0);let t=[];k$.debug(`Loading relationships for document`,{documentId:e,schemaName:i.name});let n=async(e,n,r,i)=>{let a=null,o=null;if(typeof e==`string`?a=e:typeof e==`object`&&e&&(a=e._ref||e._id||e.id,o=e._cached?.name||e._cached?.title||e.name||e.title),a){if(!o)try{let e=await W.getDocument(n,a);if(e.success&&e.data?.document){let t=e.data.document;o=t.name||t.title||t.label||a}}catch(e){k$.warn(`Failed to resolve reference for ${r}`,e),o=a}t.push({id:a,title:o||a,fieldName:r,fieldTitle:i,targetCollection:n,type:n})}},r=async(e,t,i=``,a=``)=>{if(!e||!t)return;let o=Array.isArray(e)?e.map(e=>[e.name,e]):Object.entries(e);for(let[e,s]of o){let o=s,c=i?`${i}.${e}`:e,l=a?`${a} > ${o.title||e}`:o.title||e,u=t[e];if(u){if(o.type===`reference`){let t=o.to||o.reference||e;await n(u,t,c,l)}else if(o.type===`array`&&o.of?.type===`reference`){let t=o.of.to||o.of.reference||e,r=o.title||e;if(Array.isArray(u)){for(let e=0;e<Math.min(u.length,5);e++)await n(u[e],t,`${c}[${e}]`,r);u.length>5&&k$.debug(`Truncated ${u.length-5} more references in ${c}`)}}else o.type===`object`&&o.fields&&await r(o.fields,u,c,o.title||e)}}};await r(i.fields,a),h({references:t,referencedBy:[],similar:[]}),k$.info(`Relationships loaded`,{documentId:e,relationshipCount:t.length,references:t.map(e=>({field:e.fieldName,title:e.title}))})}catch(e){k$.error(`Failed to load relationships`,e),h({references:[],referencedBy:[],similar:[]})}finally{_(!1)}},O=e=>e?new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`Unknown`,k=async()=>{if(!a||s)return null;try{let e=await W.get(`/config/settings`),t=window.location.origin;e.success&&e.data?.settings?.publicUrl&&(t=e.data.settings.publicUrl),t=t.replace(/\/$/,``);let n=a.slug||a.id;return i?.name===`page`||i?.type===`singleton`?n===`homepage`||n===`home`?t:`${t}/${n}`:`${t}/${i?.name}/${n}`}catch(e){k$.warn(`Failed to get settings for document URL, using fallback`,e);let t=window.location.origin.replace(/\/$/,``),n=a.slug||a.id;return i?.name===`page`||i?.type===`singleton`?n===`homepage`||n===`home`?t:`${t}/${n}`:`${t}/${i?.name}/${n}`}},A=(0,V.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[(0,V.jsxs)(`div`,{className:`p-4 space-y-4`,children:[!s&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2`,children:e(`documentEditor.created`)}),(0,V.jsxs)(`div`,{className:`flex items-center text-sm text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(re,{className:`h-4 w-4 mr-2`}),O(a?._createdAt)]}),a?._createdBy&&(0,V.jsxs)(`div`,{className:`flex items-center text-sm text-gray-600 dark:text-gray-400 mt-1`,children:[(0,V.jsx)(Ke,{className:`h-4 w-4 mr-2`}),a._createdBy]})]}),!s&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2`,children:e(`documentEditor.lastUpdated`)}),(0,V.jsxs)(`div`,{className:`flex items-center text-sm text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(re,{className:`h-4 w-4 mr-2`}),O(a?._updatedAt)]}),a?._updatedBy&&(0,V.jsxs)(`div`,{className:`flex items-center text-sm text-gray-600 dark:text-gray-400 mt-1`,children:[(0,V.jsx)(Ke,{className:`h-4 w-4 mr-2`}),a._updatedBy]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2`,children:e(`documentEditor.status`)}),(0,V.jsx)(`div`,{className:`text-sm`,children:(0,V.jsx)(`span`,{className:`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${j$(o)}`,children:e(o===`published`?`documentEditor.published`:`documentEditor.draft`)})}),o===`published`&&a?.publishedAt&&(0,V.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:e(`documentEditor.publishedOn`,{date:O(a.publishedAt)})})]}),a?.tags&&a.tags.length>0&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2`,children:e(`documentEditor.tags`)}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:a.tags.map((e,t)=>(0,V.jsxs)(`span`,{className:`inline-flex items-center px-2 py-1 rounded text-xs bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300`,children:[(0,V.jsx)(rt,{className:`h-3 w-3 mr-1`}),e]},t))})]}),!s&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2`,children:e(`documentEditor.contributors`)}),(0,V.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[y.length>0?y.slice(0,5).map(e=>(0,V.jsxs)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300`,title:`${e.username} (${e.role})`,children:[(0,V.jsx)(Ke,{className:`h-3 w-3 mr-1`}),e.username]},e.id)):(0,V.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`documentEditor.contributorsLoading`)}),y.length>5&&(0,V.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`documentEditor.contributorsMore`,{count:y.length-5})})]})]})]}),!s&&(0,V.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-gray-700 p-4`,children:[(0,V.jsx)(`h4`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2`,children:m?.references?.length>0?e(`documentEditor.referencesCount`,{count:m.references.length}):e(`documentEditor.references`)}),g?(0,V.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`common.loading`)}):m?.references?.length>0?(0,V.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[m.references.slice(0,8).map((e,n)=>(0,V.jsxs)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs bg-blue-50 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 hover:bg-blue-100 dark:hover:bg-blue-900/50 cursor-pointer transition-colors`,onClick:()=>t(`/content/${e.targetCollection}/${e.id}`),title:`${e.fieldTitle}: ${e.title}`,children:[(0,V.jsxs)(`span`,{className:`text-blue-500 dark:text-blue-400 mr-1`,children:[`[`,e.targetCollection,`]`]}),e.title.length>15?`${e.title.substring(0,15)}...`:e.title]},n)),m.references.length>8&&(0,V.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 self-center`,children:e(`documentEditor.referencesMore`,{count:m.references.length-8})})]}):(0,V.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`documentEditor.noReferences`)})]}),(0,V.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-gray-700 p-4`,children:[(0,V.jsx)(`h4`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-2`,children:e(`documentEditor.schema`)}),(0,V.jsxs)(`div`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(`div`,{className:`font-medium`,children:i?.title||i?.name}),i?.description&&(0,V.jsx)(`div`,{className:`text-xs mt-1`,children:i.description}),(0,V.jsx)(`div`,{className:`text-xs mt-1`,children:e(`documentEditor.fieldsCount`,{count:M$(i)})})]})]}),!s&&(0,V.jsx)(`div`,{className:`border-t border-gray-200 dark:border-gray-700 p-4`,children:(0,V.jsx)(O$,{documentId:a?._id||a?.id||``,collection:i?.name||``,isVisible:!0})}),!s&&d&&(0,V.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-gray-700 p-4`,children:[(0,V.jsx)(`h4`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider mb-3`,children:e(`documentEditor.dangerZone`)}),(0,V.jsxs)(`button`,{onClick:async()=>{if(!a||!i||s)return;let e=a._id||a.id;if(!e){k$.error(`Cannot delete document: no ID found`),n?.utils?.showToast?.(`Cannot delete document: no ID found`,`error`);return}let r=a.title||a.name||`this document`;if(await n?.utils?.showConfirm?.(`Are you sure you want to delete "${r}"? This action cannot be undone.`,{title:`Delete Document`,confirmText:`Delete`,cancelText:`Cancel`,variant:`danger`}))try{k$.info(`Deleting document`,{schema:i.name,documentId:e,title:r});let a=await W.deleteDocument(i.name,e);if(a.success)n?.utils?.showToast?.(`Document deleted`,`success`),k$.info(`Document deleted successfully`,{schema:i.name,documentId:e}),t(`/content/${i.name}`);else throw Error(a.error?.message||`Failed to delete document`)}catch(e){k$.error(`Failed to delete document`,e);let t=e instanceof Error?e.message:`Failed to delete document`;n?.utils?.showToast?.(t,`error`)}},className:`w-full flex items-center justify-center px-3 py-2 border border-red-300 dark:border-red-600 rounded-md text-sm font-medium text-red-700 dark:text-red-400 bg-white dark:bg-gray-800 hover:bg-red-50 dark:hover:bg-red-900/20 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 dark:focus:ring-offset-gray-800 transition-colors`,title:e(`documentEditor.deleteDocument`),children:[(0,V.jsx)(Be,{className:`h-4 w-4 mr-2`}),e(`documentEditor.deleteDocument`)]}),(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:e(`documentEditor.cannotBeUndone`)})]})]});return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(ia,{open:c,onClose:()=>l(!1),variant:`drawer-right`,size:`sm`,wrapperClassName:`md:hidden`,surface:`bg-gray-50 dark:bg-gray-900`,ariaLabel:e(`documentEditor.documentInfo`),children:[(0,V.jsx)(ia.Header,{padded:!1,className:`p-4`,children:(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:e(`documentEditor.documentInfo`)})}),(0,V.jsx)(ia.Body,{scroll:!1,padded:!1,className:`flex flex-col`,children:A})]}),f&&(0,V.jsx)(`div`,{className:`hidden md:block w-12 bg-gray-50 dark:bg-gray-900 border-l border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(`button`,{onClick:()=>C(!1),className:`w-full p-3 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,title:e(`documentEditor.expandSidebar`),children:(0,V.jsx)(z,{className:`h-5 w-5 mx-auto`})})}),!f&&(0,V.jsxs)(`div`,{className:`hidden md:flex w-80 bg-gray-50 dark:bg-gray-900 border-l border-gray-200 dark:border-gray-700 flex-col`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:e(`documentEditor.documentInfo`)}),(0,V.jsx)(`button`,{onClick:()=>C(!0),className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,title:e(`documentEditor.collapseSidebar`),children:(0,V.jsx)(ye,{className:`h-5 w-5`})})]}),A]})]})}function j$(e){switch(e){case`published`:return`bg-green-100 text-green-800 dark:bg-green-800 dark:text-green-100`;case`draft`:return`bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-100`;default:return`bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-100`}}function M$(e){return e?.fields?Array.isArray(e.fields)?e.fields.length:typeof e.fields==`object`?Object.keys(e.fields).length:0:0}var N$=Fr(`DocumentEditor`),P$=e=>[`schema`,e],F$=(e,t)=>[`document`,e,t];function I$(e,t){return e?t?.title?t.title:e.charAt(0).toUpperCase()+e.slice(1):`Document`}function L$(e,t){if(!Array.isArray(t)||t.length===0)return e;let n=t.map(e=>e?.field).filter(e=>typeof e==`string`&&e.length>0);return n.length===0?e:`${e}: ${n.join(`, `)}`}function R$({schemaName:e,documentId:t,mode:n=`form`,onSave:i,onCancel:a}){let{t:o}=H(`studio`),s=r(),c=P(),u=d();Uo();let f=pa(),p=ci(),m=u.state?.duplicateData;(0,B.useEffect)(()=>{N$.debug(`Permissions object state`,{hasPermissions:!!p,isAdmin:p?.isAdmin,userPermissions:p?.userPermissions,schemaName:e})},[p,e]);let h=f?.utils?.showToast||((e,t)=>console.log(`Toast: ${t} - ${e}`)),g=t===`new`||!t,_=(0,B.useMemo)(()=>p?p.hasSchemaPermission(e,`write`):!1,[p,e,p?.isAdmin,p?.userPermissions?.length]),v=(0,B.useMemo)(()=>p?p.hasSchemaPermission(e,`publish`):!1,[p,e,p?.isAdmin,p?.userPermissions?.length]);N$.debug(`Initializing document editor`,{schemaName:e,documentId:t,isNewDocument:g});let y=b$(),b=y.document,[x,S]=(0,B.useState)(null),[C,w]=(0,B.useState)(!0),[T,E]=(0,B.useState)(!1),[D,O]=(0,B.useState)(null),[k,A]=(0,B.useState)(n),[j,M]=(0,B.useState)(`draft`),N=y.isDirty,[F,I]=(0,B.useState)(!1),[L,ee]=(0,B.useState)(!1),R=(0,B.useRef)(!1),te=(0,B.useMemo)(()=>({getPlugin:e=>Jo.get(e),isVisible:(e,t)=>Lc(e,t||{}).visible}),[]);(0,B.useEffect)(()=>{if(!N)return;let e=e=>(e.preventDefault(),e.returnValue=``,``);return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[N]);let ne=l(({currentLocation:e,nextLocation:t})=>R.current?(R.current=!1,!1):N&&e.pathname!==t.pathname),re=(0,B.useRef)(ne);re.current=ne,(0,B.useEffect)(()=>{if(ne.state!==`blocked`)return;let e=!1;return(async()=>{let t=f?.utils?.showConfirm?await f.utils.showConfirm(`You have unsaved changes. Are you sure you want to leave?`,{title:`Unsaved Changes`,confirmText:`Discard Changes`,cancelText:`Keep Editing`,variant:`danger`}):window.confirm(`You have unsaved changes. Are you sure you want to leave?`);e||(t?re.current.proceed?.():re.current.reset?.())})(),()=>{e=!0}},[ne.state,f]),(0,B.useEffect)(()=>{e&&ie()},[e,t]);let ie=async()=>{try{N$.debug(`Loading editor data`,{schemaName:e,documentId:t}),w(!0),O(null);let n=await c.fetchQuery({queryKey:P$(e),queryFn:()=>W.getSchema(e),retry:!1});if(N$.debug(`Schema loaded`,{success:n.success,hasData:!!n.data}),!n.success||!n.data||!n.data.schema)throw Error(`Schema '${e}' not found`);let r=n.data.schema;if(N$.debug(`Schema loaded for editing`,{schemaName:e,hasFields:!!r.fields}),N$.debug(`Schema extracted`,{schemaName:r?.name,singleton:r?.singleton}),S(r),!g&&t){let n=await c.fetchQuery({queryKey:F$(e,t),queryFn:()=>W.getDocument(e,t),staleTime:0,retry:!1});if(N$.debug(`Document response received`,{success:n.success,hasData:!!n.data}),n.success&&n.data&&n.data.document){let e=n.data.document;y.load(e);let r=z(e);M(r),N$.debug(`Existing document loaded`,{documentId:t,state:r})}else{N$.warn(`Document not found, attempting auto-creation for singleton`,{schema:e,documentId:t});let n=ae(r);n.id=t,y.load(n),M(`draft`),N$.debug(`Singleton document initialized`,{documentId:t})}}else{let e=m?{...ae(r),...m}:ae(r);y.load(e),M(`draft`),N$.debug(`New document initialized`,{isDuplicate:!!m})}N$.info(`Editor data loaded successfully`,{schema:e,isNew:g})}catch(e){N$.error(`Failed to load editor data`,e),O(e instanceof Error?e.message:`Failed to load editor data`)}finally{w(!1)}},ae=t=>{let n={_type:e,_status:`draft`,_createdAt:new Date().toISOString(),_updatedAt:new Date().toISOString()};!n.title&&!n.name&&(n.title=n.id&&n.id!==`new`?I$(e,t):`New ${I$(e,t)}`);let r=e=>hc(e,e=>Jo.get(e));return t.fields&&(Array.isArray(t.fields)?t.fields.forEach(e=>{e.default!==void 0&&(n[e.name]=r(e))}):typeof t.fields==`object`&&Object.entries(t.fields).forEach(([e,t])=>{t.default!==void 0&&(n[e]=r({name:e,...t}))})),n},z=e=>e._status?e._status:e._state?e._state:e.status?e.status:e.published===!0?`published`:(e.published,`draft`),oe=(0,B.useCallback)(e=>{e&&typeof e==`object`&&Object.entries(e).forEach(([e,t])=>{y.setValue([e],t)})},[y.setValue]),se=(0,B.useCallback)(e=>{if(!x||e.length===0)return;let{current:t,errors:n}=y.getState(),r=y$(t,x,{...te,rootPath:e}),i=String(e[0]),a={};for(let[e,t]of Object.entries(n))e===i||e.startsWith(`${i}.`)||e.startsWith(`${i}[`)||(a[e]=t);Object.assign(a,r),y.setErrors(a)},[x,y.getState,y.setErrors,te]),ce=(0,B.useCallback)(e=>{I(e)},[]),le=(0,B.useCallback)(async n=>{if(!qo.canTransition(j,n)){N$.warn(`Invalid state transition`,{from:j,to:n});return}let r=n===`published`&&j!==`published`;if((r||n!==`published`&&j===`published`)&&!v){let e=o(r?`publish`:`unpublish`);h(o(`documentEditor.noPublishPermission`,{action:e}),`error`),N$.warn(`User lacks publish permission for state change`,{from:j,to:n,hasPublishPermission:v});return}try{y.setValue([`_status`],n),n===`published`?y.setValue([`publishedAt`],new Date().toISOString()):n===`draft`&&y.setValue([`publishedAt`],null),y.setValue([`_state`],void 0),y.setValue([`published`],void 0),M(n),N$.info(`Document state changed`,{schema:e,documentId:t,oldState:j,newState:n})}catch(e){N$.error(`Failed to change document state`,e),alert(`Failed to change document state`)}},[j,y.setValue,e,t,v,h,o]),ue=(0,B.useCallback)(async()=>{let n=y.getState().current;if(n&&x){if(!_){h(`You don't have permission to edit ${I$(e,x)}`,`error`);return}try{E(!0),O(null),y.setStatus(`saving`);let r=y$(n,x,te);if(y.setErrors(r),Object.keys(r).length>0){N$.warn(`Document validation failed - check inline field errors`,{errors:r}),h(Object.values(r).join(`, `),`error`),y.setStatus(`error`),E(!1);return}let a=fc(n,x,j,y.getState().initial),o;if(o=g?await W.createDocument(e,a):await W.updateDocument(e,t,a),o.success&&o.data){let n=o.data.document||o.data;N$.info(`Document saved successfully`,{schema:e,id:n.id||n._id,isNewDocument:g,savedDocumentData:n}),y.markSaved(n),c.invalidateQueries({queryKey:F$(e,t)}),h(`Saved`,`success`),i?.(n),g?(R.current=!0,s(`/content/${e}/${n.id||n._id}`)):N$.debug(`Updated existing document, refreshing UI state`)}else{let e=o.error?.message||`Failed to save document`;N$.error(`Save failed with API error`,{error:o.error,fullResponse:o,documentData:n}),y.setStatus(`error`),h(L$(e,o.error?.details),`error`)}}catch(e){N$.error(`Failed to save document`,e);let t=e instanceof jr?e.message:`Failed to save document`,n=e instanceof jr?e.details:void 0;y.setStatus(`error`),h(L$(t,n),`error`)}finally{E(!1)}}},[x,g,e,t,j,i,s,_,h,y.getState,y.setErrors,y.setStatus,y.markSaved,te]),de=(0,B.useCallback)(async()=>{(!N||await f?.utils?.showConfirm?.(`You have unsaved changes. Are you sure you want to cancel?`,{title:`Unsaved Changes`,confirmText:`Discard Changes`,cancelText:`Keep Editing`,variant:`danger`}))&&(R.current=!0,a?a():s(`/content/${e}`))},[N,a,s,e,f]),fe=(0,B.useMemo)(()=>({schema:x,document:b,documentState:j,currentMode:k,isNewDocument:g,hasUnsavedChanges:N,hasValidationErrors:F,errors:y.errors,isReadOnly:!_,hasPublishPermission:v,isMobileSidebarOpen:L,onToggleMobileSidebar:ee,loading:C,saving:T,error:D,onDocumentChange:oe,onFieldBlur:se,onStateChange:le,onModeChange:A,onSave:ue,onCancel:de,onValidationChange:ce}),[x,b,j,k,g,N,F,y.errors,_,v,L,C,T,D,oe,se,le,ue,de,ce]),pe=p?.loading===!0;return C||pe?(0,V.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:o(g?`documentEditor.loadingSchema`:`documentEditor.loadingDocument`)})]})}):D?(0,V.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`text-red-500 mb-4`,children:(0,V.jsx)(`h3`,{className:`text-lg font-medium`,children:o(`common.error`)})}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:D}),(0,V.jsx)(U,{onClick:de,children:o(`documentEditor.backToDocuments`)})]})}):(0,V.jsx)(Go,{value:fe,children:(0,V.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,V.jsx)(x$,{}),(0,V.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[(0,V.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[k===`form`&&(0,V.jsx)(o$,{}),k===`preview`&&(0,V.jsx)(z$,{})]}),(0,V.jsx)(A$,{})]})]})})}function z$(){let{t:e}=H(`studio`),{document:t}=Ko();return(0,V.jsx)(`div`,{className:`flex-1 p-6 overflow-auto`,children:(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-white mb-4`,children:e(`documentEditor.documentPreview`)}),(0,V.jsx)(`pre`,{className:`text-sm text-gray-600 dark:text-gray-400 whitespace-pre-wrap`,children:JSON.stringify(t,null,2)})]})})}function B$({availableViews:e,currentView:t,onViewChange:n,searchQuery:r,onSearchChange:i,searchPlaceholder:a,availableFilters:o,activeFilters:s,onFilterChange:c,onClearFilters:l,availableSorts:u,currentSort:d,onSortChange:f,onCreateNew:p,createNewLabel:m,totalItems:h=0,selectedItems:g=0,bulkActions:_=[],onBulkAction:v}){let{t:y}=H(`studio`),[b,x]=(0,B.useState)(!1),[S,C]=(0,B.useState)(!1),w=(0,B.useRef)(null),T=a||y(`nav.searchPlaceholder`),E=m||y(`common.create`),D=Object.values(s).filter(e=>e!=null&&e!==``).length,O=D>0;return(0,B.useEffect)(()=>{let e=e=>{w.current&&!w.current.contains(e.target)&&C(!1)};if(S)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[S]),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(`div`,{className:`px-6 py-4`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-4`,children:[(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(ee,{className:`absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400`}),(0,V.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:T,className:`pl-10 pr-4 py-2 w-64 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent`})]}),o.length>0&&(0,V.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>x(!b),className:wr(O&&`bg-blue-50 border-blue-200 text-blue-700 dark:bg-blue-900/20 dark:border-blue-800 dark:text-blue-300`),children:[(0,V.jsx)(Re,{className:`h-4 w-4 mr-2`}),y(`contentView.filters`),D>0&&(0,V.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs bg-blue-100 text-blue-700 dark:bg-blue-800 dark:text-blue-200 rounded-full`,children:D})]}),u.length>0&&(0,V.jsxs)(`div`,{ref:w,className:`relative`,children:[(0,V.jsxs)(U,{variant:`outline`,size:`sm`,onClick:()=>C(!S),className:wr(d&&`bg-blue-50 border-blue-200 text-blue-700 dark:bg-blue-900/20 dark:border-blue-800 dark:text-blue-300`),children:[(0,V.jsx)(qe,{className:`h-4 w-4 mr-2`}),y(`contentView.sort`),d&&(0,V.jsx)(`span`,{className:`ml-2 text-xs`,children:u.find(e=>e.field===d.field)?.label||d.field})]}),S&&(0,V.jsx)(`div`,{className:`absolute top-full left-0 mt-1 w-48 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg z-10`,children:(0,V.jsx)(`div`,{className:`py-1`,children:u.map(e=>(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`button`,{onClick:()=>{f(e.field,`asc`),C(!1)},className:wr(`w-full text-left px-4 py-2 text-sm text-gray-900 dark:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700`,d?.field===e.field&&d?.direction===`asc`&&`bg-blue-50 text-blue-700 dark:bg-blue-900/20 dark:text-blue-300`),children:y(`contentView.sortAsc`,{label:e.label})}),(0,V.jsx)(`button`,{onClick:()=>{f(e.field,`desc`),C(!1)},className:wr(`w-full text-left px-4 py-2 text-sm text-gray-900 dark:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700`,d?.field===e.field&&d?.direction===`desc`&&`bg-blue-50 text-blue-700 dark:bg-blue-900/20 dark:text-blue-300`),children:y(`contentView.sortDesc`,{label:e.label})})]},e.field))})})]}),O&&(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:l,className:`text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`,children:y(`contentView.clearAll`)})]}),(0,V.jsxs)(`div`,{className:`flex items-center space-x-4`,children:[(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:g>0?(0,V.jsx)(`span`,{children:y(`contentView.selectedOfTotal`,{selected:g,total:h,count:g})}):(0,V.jsx)(`span`,{children:y(`contentView.itemsCount`,{count:h})})}),g>0&&_.length>0&&(0,V.jsx)(`div`,{className:`flex items-center space-x-2`,children:_.map(e=>(0,V.jsxs)(U,{size:`sm`,variant:(e.variant,`outline`),onClick:()=>v?.(e.id),disabled:e.disabled,className:wr(e.variant===`destructive`&&`text-red-600 hover:text-red-700 border-red-200 hover:border-red-300 dark:text-red-400 dark:border-red-800 dark:hover:border-red-700`),children:[e.icon&&(0,V.jsx)(e.icon,{className:`h-4 w-4 mr-2`}),e.label]},e.id))}),e.filter(e=>e.enabled).length>1&&(0,V.jsx)(`div`,{className:`flex items-center bg-gray-100 dark:bg-gray-700 rounded-lg p-1`,children:e.filter(e=>e.enabled).map(e=>(0,V.jsx)(`button`,{onClick:()=>n(e.type),className:wr(`p-2 rounded-md transition-colors`,t===e.type?`bg-white dark:bg-gray-600 text-blue-600 dark:text-blue-400 shadow-sm`:`text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`),title:e.title,children:(0,V.jsx)(e.icon,{className:`h-4 w-4`})},e.type))}),p&&(0,V.jsxs)(U,{onClick:p,children:[(0,V.jsx)(Ne,{className:`h-4 w-4 mr-2`}),E]})]})]})}),b&&o.length>0&&(0,V.jsx)(`div`,{className:`px-6 py-4 bg-gray-50 dark:bg-gray-900 border-t border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:o.map(e=>(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e.label}),e.type===`text`&&(0,V.jsx)(`input`,{type:`text`,value:s[e.id]||``,onChange:t=>c(e.id,t.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,placeholder:y(`contentView.filterBy`,{label:e.label.toLowerCase()})}),e.type===`select`&&(0,V.jsxs)(`select`,{value:s[e.id]||``,onChange:t=>c(e.id,t.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:``,children:y(`contentView.allLabel`,{label:e.label})}),e.options?.map(e=>(0,V.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),e.type===`boolean`&&(0,V.jsxs)(`select`,{value:s[e.id]||``,onChange:t=>c(e.id,t.target.value===`true`||t.target.value!==`false`&&``),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:``,children:y(`contentView.all`)}),(0,V.jsx)(`option`,{value:`true`,children:y(`contentView.yes`)}),(0,V.jsx)(`option`,{value:`false`,children:y(`contentView.no`)})]}),e.type===`date`&&(0,V.jsx)(`input`,{type:`date`,value:s[e.id]||``,onChange:t=>c(e.id,t.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`})]},e.id))})})]})}function V$({checked:e=!1,onChange:t,disabled:n=!1,id:r,className:i,indeterminate:a=!1,"aria-label":o,...s}){return(0,V.jsxs)(`div`,{className:`relative inline-flex items-center`,children:[(0,V.jsx)(`input`,{type:`checkbox`,id:r,checked:e,onChange:e=>{t&&t(e.target.checked)},disabled:n,"aria-label":o,ref:e=>{e&&(e.indeterminate=a)},className:`sr-only`,...s}),(0,V.jsxs)(`div`,{className:wr(`h-4 w-4 rounded border-2 transition-all duration-200 relative cursor-pointer`,`focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-blue-500`,`border-gray-300 bg-white`,`dark:border-gray-600 dark:bg-gray-700`,!n&&`hover:border-gray-400 dark:hover:border-gray-500`,e&&`!border-blue-600 !bg-blue-600`,e&&`dark:!border-blue-600 dark:!bg-blue-600`,n&&`opacity-50 cursor-not-allowed`,i),onClick:r=>{!n&&t&&(r.preventDefault(),t(!e))},children:[e&&(0,V.jsx)(`svg`,{className:`absolute inset-0 w-4 h-4 pointer-events-none`,fill:`none`,viewBox:`0 0 24 24`,style:{stroke:`#ffffff`,strokeWidth:3},children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),a&&!e&&(0,V.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,V.jsx)(`div`,{className:`w-2 h-0.5 bg-white dark:bg-gray-300`})})]})]})}function H$(e,t){if(!e)return`Untitled`;if(t?.fields){let n=(Array.isArray(t.fields)?t.fields:Object.entries(t.fields).map(([e,t])=>({name:e,...t})))[0];if(n&&e[n.name]){let t=e[n.name];if(typeof t==`string`&&t.trim()&&!t.startsWith(`New `))return t}}return e.name&&!e.name.startsWith(`New `)?e.name:e.title&&!e.title.startsWith(`New `)?e.title:e.slug?e.slug:e.title||e.name||e.slug||`Untitled`}function U$(e,t){return t.split(`.`).reduce((e,t)=>e?.[t],e)}function W$({documents:e,columns:t,schemaName:n,loading:i=!1,selectedItems:a,onItemSelect:o,onSelectAll:s,sortField:c,sortDirection:l,onSort:u,onDocumentAction:d,canDelete:f}){let{t:p}=H(`studio`),m=r(),h=pa(),[g,_]=(0,B.useState)(null),[v,y]=(0,B.useState)(null),b=(0,B.useRef)(null),x=(0,B.useRef)(null),S=(0,B.useRef)(null),C=e.length>0&&a.length===e.length,w=a.length>0&&a.length<e.length;(0,B.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&(console.log(`Click outside dropdown detected, closing dropdown`),_(null))};if(g)return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[g]);let T=t=>{if(!t.sortable||!u)return;let n=t.key;t.key===`title`&&e&&e.length>0&&(n=e[0].name?`name`:`title`),u(n,c===n&&l===`asc`?`desc`:`asc`)},E=(e,t,n)=>{if(t.render)return t.render(e,n);if(t.key===`title`||t.key===`name`){let e=H$(n);if(e!==`Untitled`)return e}return e==null?(0,V.jsx)(`span`,{className:`text-gray-400`,children:`—`}):typeof e==`boolean`?(0,V.jsx)(`span`,{className:wr(`inline-flex px-2 py-1 text-xs font-semibold rounded-full`,e?`bg-green-100 text-green-800 dark:bg-green-800 dark:text-green-100`:`bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-100`),children:p(e?`contentViews.yes`:`contentViews.no`)}):e instanceof Date||typeof e==`string`&&!isNaN(Date.parse(e))?new Date(e).toLocaleDateString():Array.isArray(e)?e.length>0?e.join(`, `):(0,V.jsx)(`span`,{className:`text-gray-400`,children:p(`contentViews.empty`)}):String(e)},D=e=>e.id||e._id;return i?(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700`,children:(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:p(`contentViews.loadingDocuments`)})]})}):e.length===0?(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(`div`,{className:`p-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:p(`contentViews.noDocumentsFound`)})})}):(0,V.jsxs)(`div`,{ref:b,className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden`,children:[(0,V.jsx)(`div`,{className:`overflow-x-auto overflow-y-visible`,children:(0,V.jsxs)(`table`,{className:`w-full table-fixed`,children:[(0,V.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-700`,children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`px-3 py-3 text-left w-8`,children:(0,V.jsx)(V$,{checked:C,indeterminate:w,onChange:s})}),t.map((e,t)=>(0,V.jsx)(`th`,{className:wr(`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider`,e.sortable&&`cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600`,e.width&&`w-${e.width}`,t===0&&`w-96`,t===1&&`w-24`,t===2&&`w-24`,t===3&&`w-24`),onClick:()=>T(e),children:(0,V.jsxs)(`div`,{className:`flex items-center space-x-1`,children:[(0,V.jsx)(`span`,{children:e.title}),e.sortable&&(0,V.jsxs)(`div`,{className:`flex flex-col`,children:[(0,V.jsx)(Xe,{className:wr(`h-3 w-3 -mb-1`,c===e.key&&l===`asc`?`text-blue-600 dark:text-blue-400`:`text-gray-400`)}),(0,V.jsx)(ye,{className:wr(`h-3 w-3`,c===e.key&&l===`desc`?`text-blue-600 dark:text-blue-400`:`text-gray-400`)})]})]})},e.key)),(0,V.jsx)(`th`,{className:`px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider w-20`,children:p(`contentViews.actions`)})]})}),(0,V.jsx)(`tbody`,{className:`divide-y divide-gray-200 dark:divide-gray-600`,children:e.map(e=>{let r=D(e),i=a.includes(r);return(0,V.jsxs)(`tr`,{className:wr(`hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors`,i&&`bg-blue-50 dark:bg-blue-900/20`),children:[(0,V.jsx)(`td`,{className:`px-3 py-4 whitespace-nowrap`,children:(0,V.jsx)(V$,{checked:i,onChange:e=>o(r,e)})}),t.map(i=>{let a=U$(e,i.key),o=i===t[0];return(0,V.jsx)(`td`,{className:wr(`px-6 py-4`,o?`max-w-xs`:`whitespace-nowrap`),children:o?(0,V.jsxs)(`button`,{onClick:()=>m(`/content/${n}/${r}`),className:`text-left hover:text-blue-600 dark:hover:text-blue-400 transition-colors w-full`,children:[(0,V.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-white truncate`,title:String(E(a,i,e)),children:E(a,i,e)}),e.slug&&(0,V.jsxs)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400 truncate`,title:`/${e.slug}`,children:[`/`,e.slug]})]}):(0,V.jsx)(`div`,{className:`text-sm text-gray-900 dark:text-white`,children:E(a,i,e)})},i.key)}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap text-right text-sm font-medium`,children:(0,V.jsx)(`div`,{className:`relative`,children:(0,V.jsx)(`button`,{ref:S,onClick:e=>{if(g===r)_(null),y(null);else{let t=e.currentTarget.getBoundingClientRect(),n=t.bottom+window.scrollY+4,i=t.right+window.scrollX-192;t.bottom+200>window.innerHeight&&(n=t.top+window.scrollY-200-4),i<0&&(i=t.left+window.scrollX),y({top:n,left:i}),_(r)}},className:`p-1 rounded-full text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700`,children:(0,V.jsx)(ae,{className:`h-5 w-5`})})})})]},r)})})]})}),g&&v&&(0,Ht.createPortal)((0,V.jsx)(`div`,{ref:x,className:`absolute w-48 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg z-50`,style:{top:v.top,left:v.left},children:(0,V.jsxs)(`div`,{className:`py-1 flex flex-col`,children:[(0,V.jsx)(`button`,{onClick:()=>{m(`/content/${n}/${g}`),_(null),y(null)},className:`w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`,children:p(`contentViews.edit`)}),(0,V.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(g),_(null),y(null)},className:`w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`,children:p(`contentViews.copyId`)}),(0,V.jsx)(`button`,{onClick:()=>{d?.(g,`duplicate`),_(null),y(null)},className:`w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`,children:p(`contentViews.duplicate`)}),(()=>{let t=e.find(e=>(e._id||e.id)===g);return!f||t&&f(t)?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`hr`,{className:`my-1 border-gray-200 dark:border-gray-600`}),(0,V.jsx)(`button`,{onClick:async()=>{await h?.utils?.showConfirm?.(p(`contentViews.deleteConfirm`),{title:p(`contentViews.deleteTitle`),confirmText:p(`contentViews.confirmDelete`),cancelText:p(`common.cancel`),variant:`danger`})&&d?.(g,`delete`),_(null),y(null)},className:`w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`,children:p(`contentViews.delete`)})]}):null})()]})}),document.body)]})}var G$=()=>[{key:`title`,title:`Title`,sortable:!0,render:(e,t)=>H$(t)},{key:`_status`,title:`Status`,sortable:!0,render:(e,t)=>{let n=e||`draft`;return(0,V.jsx)(`span`,{className:wr(`inline-flex px-2 py-1 text-xs font-semibold rounded-full`,n===`published`?`bg-green-100 text-green-800 dark:bg-green-800 dark:text-green-100`:`bg-yellow-100 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-100`),children:n.charAt(0).toUpperCase()+n.slice(1)})}},{key:`_createdAt`,title:`Created`,sortable:!0,render:e=>e?new Date(e).toLocaleDateString():`—`},{key:`_updatedAt`,title:`Updated`,sortable:!0,render:e=>e?new Date(e).toLocaleDateString():`—`}];function K$({documents:e,schemaName:t,loading:n=!1,selectedItems:i,onItemSelect:a,onDocumentAction:o,canDelete:s,cardSize:c=`medium`,columnsPerRow:l,subtitleField:u=`subtitle`,descriptionField:d=`description`,dateField:f=`_updatedAt`,authorField:p=`author`}){let{t:m}=H(`studio`),h=r(),g=pa(),[_,v]=(0,B.useState)(null),y=()=>{if(l)return`grid-cols-${l}`;switch(c){case`small`:return`grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6`;case`medium`:return`grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4`;case`large`:return`grid-cols-1 sm:grid-cols-2 lg:grid-cols-3`;default:return`grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4`}},b=()=>{switch(c){case`small`:return`h-56`;case`medium`:return`h-72`;case`large`:return`h-80`;default:return`h-72`}},x=e=>e.id||e._id,S=e=>H$(e),C=e=>U$(e,u)||e.subtitle,w=e=>{let t=U$(e,d)||e.description||e.excerpt;if(typeof t==`string`){if(t.length>140){let e=t.substring(0,140),n=e.lastIndexOf(` `);return n>100?e.substring(0,n)+`...`:e+`...`}return t}return t},T=e=>{for(let t of[`featuredImage`,`image`,`thumbnail`,`cover`,`photo`,`mainImage`,`hero`]){let n=U$(e,t);if(n){if(n.asset?._ref||n._ref){let e=n.asset?._ref||n._ref;return console.log(`Found image reference in ${t}:`,e),W.getMediaUrl(e,`thumbnail`)}if(typeof n==`string`&&n.trim())return console.log(`Found direct image URL in ${t}:`,n),n;if(n?.url&&typeof n.url==`string`)return console.log(`Found image URL in ${t}.url:`,n.url),n.url;if(n?.src&&typeof n.src==`string`)return console.log(`Found image URL in ${t}.src:`,n.src),n.src}}return console.log(`No image found for document:`,e.title||e.name),null},E=e=>{let t=U$(e,f)||e._updatedAt||e._createdAt;return t?new Date(t).toLocaleDateString():null},D=e=>{let t=U$(e,p);return typeof t==`string`?t:t?.name?t.name:t?.title?t.title:null},O=e=>e.published||e._status===`published`?`bg-green-100 text-green-800 dark:bg-green-800 dark:text-green-100`:`bg-yellow-100 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-100`,k=e=>e.published||e._status===`published`?m(`documentEditor.published`):m(`documentEditor.draft`);return n?(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:m(`contentViews.loadingDocuments`)})]}):e.length===0?(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(pe,{className:`h-12 w-12 text-gray-400 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:m(`contentViews.noDocumentsFound`)})]}):(0,V.jsx)(`div`,{className:wr(`grid gap-6`,y()),children:e.map(e=>{let n=x(e),r=i.includes(n),c=T(e),l=S(e),u=C(e),d=w(e),f=E(e),p=D(e);return(0,V.jsxs)(`div`,{className:wr(`bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden transition-all duration-300 hover:shadow-xl hover:shadow-gray-200/50 dark:hover:shadow-gray-900/50 hover:-translate-y-1 group`,b(),r&&`ring-2 ring-blue-500 border-blue-500 shadow-lg`),children:[(0,V.jsx)(`div`,{className:`absolute top-3 left-3 z-10`,children:(0,V.jsx)(V$,{checked:r,onChange:e=>a(n,e),className:`bg-white/90 dark:bg-gray-700/90 backdrop-blur-sm`})}),(0,V.jsx)(`div`,{className:`absolute top-3 right-3 z-10`,children:(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(`button`,{onClick:()=>v(_===n?null:n),className:`p-1 rounded-full text-white/80 hover:text-white hover:bg-black/20 backdrop-blur-sm bg-black/10 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,V.jsx)(ae,{className:`h-5 w-5`})}),_===n&&(0,V.jsx)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg`,children:(0,V.jsxs)(`div`,{className:`py-1`,children:[(0,V.jsx)(`button`,{onClick:()=>{h(`/content/${t}/${n}`),v(null)},className:`w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`,children:m(`contentViews.edit`)}),(0,V.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(n),v(null)},className:`w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`,children:m(`contentViews.copyId`)}),(0,V.jsx)(`button`,{onClick:()=>{o?.(n,`duplicate`),v(null)},className:`w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`,children:m(`contentViews.duplicate`)}),(!s||s(e))&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`hr`,{className:`my-1 border-gray-200 dark:border-gray-600`}),(0,V.jsx)(`button`,{onClick:async()=>{await g?.utils?.showConfirm?.(m(`contentViews.deleteConfirm`),{title:m(`contentViews.deleteTitle`),confirmText:m(`contentViews.confirmDelete`),cancelText:m(`common.cancel`),variant:`danger`})&&o?.(n,`delete`),v(null)},className:`w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`,children:m(`contentViews.delete`)})]})]})})]})}),(0,V.jsxs)(`button`,{onClick:()=>h(`/content/${t}/${n}`),className:`w-full h-full flex flex-col text-left`,children:[(0,V.jsxs)(`div`,{className:`flex-shrink-0 h-40 relative overflow-hidden`,children:[c?(0,V.jsx)(`div`,{className:`w-full h-full bg-cover bg-center bg-no-repeat`,style:{backgroundImage:`url(${c})`},children:(0,V.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-t from-black/60 via-black/20 to-transparent`})}):(0,V.jsx)(`div`,{className:`w-full h-full bg-gradient-to-br from-gray-100 to-gray-200 dark:from-gray-700 dark:to-gray-800 flex items-center justify-center`,children:(0,V.jsx)(pe,{className:`h-12 w-12 text-gray-400`})}),(0,V.jsx)(`div`,{className:`absolute top-3 left-3`,children:(0,V.jsx)(`span`,{className:wr(`inline-flex px-2 py-1 text-xs font-semibold rounded-full backdrop-blur-sm`,O(e)),children:k(e)})})]}),(0,V.jsxs)(`div`,{className:`flex-1 p-4 flex flex-col min-h-0`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-white mb-2 leading-tight overflow-hidden`,style:{display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`},title:l,children:l}),u&&(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-2 font-medium overflow-hidden whitespace-nowrap text-ellipsis`,title:u,children:u}),d&&(0,V.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-300 leading-relaxed mb-3 flex-1 overflow-hidden`,style:{display:`-webkit-box`,WebkitLineClamp:3,WebkitBoxOrient:`vertical`},title:d,children:d}),(0,V.jsx)(`div`,{className:`flex items-center justify-between text-xs text-gray-500 dark:text-gray-400 mt-auto pt-2 border-t border-gray-100 dark:border-gray-700`,children:(0,V.jsxs)(`div`,{className:`flex items-center space-x-3 min-w-0`,children:[p&&(0,V.jsxs)(`div`,{className:`flex items-center space-x-1 min-w-0`,children:[(0,V.jsx)(Ke,{className:`h-3 w-3 flex-shrink-0`}),(0,V.jsx)(`span`,{className:`truncate`,children:p})]}),f&&(0,V.jsxs)(`div`,{className:`flex items-center space-x-1 flex-shrink-0`,children:[(0,V.jsx)(Ge,{className:`h-3 w-3`}),(0,V.jsx)(`span`,{children:f})]})]})})]})]})]},n)})})}function q$({documents:e,columns:t,schemaName:n,loading:i=!1,selectedItems:a,onItemSelect:o,onSelectAll:s,sortField:c,sortDirection:l,onSort:u,onDocumentAction:d,canDelete:f,onColumnResize:p,onColumnVisibilityChange:m,density:h=`comfortable`}){let{t:g}=H(`studio`),_=r(),v=pa(),[y,b]=(0,B.useState)(null),[x,S]=(0,B.useState)(!1),[C,w]=(0,B.useState)(null),T=(0,B.useRef)(null),E=e.length>0&&a.length===e.length,D=a.length>0&&a.length<e.length,O=t.filter(e=>e.visible!==!1);(0,B.useEffect)(()=>{let e=e=>{T.current&&!T.current.contains(e.target)&&(b(null),S(!1))};return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[]);let k=()=>{switch(h){case`compact`:return`py-2`;case`comfortable`:return`py-3`;case`spacious`:return`py-4`;default:return`py-3`}},A=e=>{if(!e.sortable||!u)return;let t=c===e.key&&l===`asc`?`desc`:`asc`;u(e.key,t)},j=(e,t,n)=>{if(!p)return;w(e);let r=r=>{let i=r.clientX-t;p(e,Math.max(50,n+i))},i=()=>{w(null),document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i)},M=(e,t,n)=>{if(t.render)return t.render(e,n);if(t.key===`title`||t.key===`name`){let e=H$(n);if(e!==`Untitled`)return e}return e==null?(0,V.jsx)(`span`,{className:`text-gray-400`,children:`—`}):typeof e==`boolean`?(0,V.jsx)(`span`,{className:wr(`inline-flex px-2 py-1 text-xs font-medium rounded-md`,e?`bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400`:`bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300`),children:g(e?`contentViews.yes`:`contentViews.no`)}):e instanceof Date||typeof e==`string`&&!isNaN(Date.parse(e))?new Date(e).toLocaleDateString():Array.isArray(e)?e.length>0?(0,V.jsxs)(`span`,{title:e.join(`, `),children:[e.slice(0,2).join(`, `),e.length>2?`...`:``]}):(0,V.jsx)(`span`,{className:`text-gray-400`,children:g(`contentViews.empty`)}):typeof e==`string`&&e.length>50?(0,V.jsxs)(`span`,{title:e,children:[e.substring(0,50),`...`]}):String(e)},N=e=>e.id||e._id;return i?(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700`,children:(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:g(`contentViews.loadingDocuments`)})]})}):e.length===0?(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(`div`,{className:`p-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:g(`contentViews.noDocumentsFound`)})})}):(0,V.jsxs)(`div`,{ref:T,className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden`,children:[(0,V.jsxs)(`div`,{className:`px-4 py-2 bg-gray-50 dark:bg-gray-700/50 border-b border-gray-200 dark:border-gray-600 flex items-center justify-between`,children:[(0,V.jsx)(`div`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:g(`contentViews.itemsCount`,{count:e.length})}),(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsxs)(U,{variant:`ghost`,size:`sm`,onClick:()=>S(!x),children:[(0,V.jsx)(Fe,{className:`h-4 w-4 mr-2`}),g(`contentViews.columns`)]}),x&&(0,V.jsx)(`div`,{className:`absolute right-0 top-full mt-1 w-64 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg z-10`,children:(0,V.jsxs)(`div`,{className:`p-3`,children:[(0,V.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-white mb-3`,children:g(`contentViews.showHideColumns`)}),(0,V.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>(0,V.jsxs)(`label`,{className:`flex items-center`,children:[(0,V.jsx)(V$,{checked:e.visible===!0,onChange:t=>m?.(e.key,t),className:`mr-2`}),(0,V.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:e.title})]},e.key))})]})})]})]}),(0,V.jsx)(`div`,{className:`overflow-x-auto overflow-y-visible`,children:(0,V.jsxs)(`table`,{className:`w-full`,children:[(0,V.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-700`,children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`px-4 py-3 text-left w-12`,children:(0,V.jsx)(V$,{checked:E,indeterminate:D,onChange:s})}),O.map(e=>(0,V.jsxs)(`th`,{className:wr(`px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider relative`,e.sortable&&`cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-600`,C===e.key&&`bg-blue-50 dark:bg-blue-900/20`),style:{width:e.width,minWidth:e.minWidth||100},onClick:()=>A(e),children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-1`,children:[(0,V.jsx)(`span`,{children:e.title}),e.sortable&&(0,V.jsxs)(`div`,{className:`flex flex-col`,children:[(0,V.jsx)(Xe,{className:wr(`h-3 w-3 -mb-1`,c===e.key&&l===`asc`?`text-blue-600 dark:text-blue-400`:`text-gray-400`)}),(0,V.jsx)(ye,{className:wr(`h-3 w-3`,c===e.key&&l===`desc`?`text-blue-600 dark:text-blue-400`:`text-gray-400`)})]})]}),e.resizable&&p&&(0,V.jsx)(`div`,{className:`absolute right-0 top-0 w-2 h-full cursor-col-resize hover:bg-blue-500/20 group`,onMouseDown:t=>{t.preventDefault(),t.stopPropagation();let n=t.currentTarget.closest(`th`).getBoundingClientRect();j(e.key,t.clientX,n.width)},children:(0,V.jsx)(`div`,{className:`w-0.5 h-full bg-gray-300 dark:bg-gray-600 ml-auto group-hover:bg-blue-500`})})]},e.key)),(0,V.jsx)(`th`,{className:`px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider w-20`,children:g(`contentViews.actions`)})]})}),(0,V.jsx)(`tbody`,{className:`divide-y divide-gray-200 dark:divide-gray-600`,children:e.map(e=>{let t=N(e),r=a.includes(t);return(0,V.jsxs)(`tr`,{className:wr(`hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors`,r&&`bg-blue-50 dark:bg-blue-900/20`),children:[(0,V.jsx)(`td`,{className:wr(`px-4 whitespace-nowrap`,k()),children:(0,V.jsx)(V$,{checked:r,onChange:e=>o(t,e)})}),O.map((r,i)=>{let a=U$(e,r.key),o=i===0;return(0,V.jsx)(`td`,{className:wr(`px-4 whitespace-nowrap`,k()),style:{width:r.width,minWidth:r.minWidth||100},children:o?(0,V.jsxs)(`button`,{onClick:()=>_(`/content/${n}/${t}`),className:`text-left hover:text-blue-600 dark:hover:text-blue-400 transition-colors`,children:[(0,V.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:M(a,r,e)}),e.slug&&(0,V.jsxs)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:[`/`,e.slug]})]}):(0,V.jsx)(`div`,{className:`text-sm text-gray-900 dark:text-white`,children:M(a,r,e)})},r.key)}),(0,V.jsx)(`td`,{className:wr(`px-4 whitespace-nowrap text-right text-sm font-medium`,k()),children:(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(`button`,{onClick:()=>b(y===t?null:t),className:`p-1 rounded-full text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700`,children:(0,V.jsx)(ae,{className:`h-5 w-5`})}),y===t&&(0,V.jsx)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg z-50 min-w-max`,children:(0,V.jsxs)(`div`,{className:`py-1`,children:[(0,V.jsx)(`button`,{onClick:()=>{_(`/content/${n}/${t}`),b(null)},className:`w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`,children:g(`contentViews.edit`)}),(0,V.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(t),b(null)},className:`w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`,children:g(`contentViews.copyId`)}),(0,V.jsx)(`button`,{onClick:()=>{d?.(t,`duplicate`),b(null)},className:`w-full text-left px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700`,children:g(`contentViews.duplicate`)}),(!f||f(e))&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`hr`,{className:`my-1 border-gray-200 dark:border-gray-600`}),(0,V.jsx)(`button`,{onClick:async()=>{await v?.utils?.showConfirm?.(g(`contentViews.deleteConfirm`),{title:g(`contentViews.deleteTitle`),confirmText:g(`contentViews.confirmDelete`),cancelText:g(`common.cancel`),variant:`danger`})&&d?.(t,`delete`),b(null)},className:`w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`,children:g(`contentViews.delete`)})]})]})})]})})]},t)})})]})})]})}function J$({currentPage:e,totalPages:t,pageSize:n,totalItems:r,onPageChange:i,onPageSizeChange:a,showPageSizeSelector:o=!0,pageSizeOptions:s=[10,25,50,100],showFirstLast:c=!0,maxVisiblePages:l=7}){let{t:u}=H(`studio`),d=(e-1)*n+1,f=Math.min(e*n,r),p=(()=>{let n=[];if(t<=l)for(let e=1;e<=t;e++)n.push(e);else{n.push(1);let r=Math.floor(l/2)-1,i=Math.max(2,e-r),a=Math.min(t-1,e+r);e<=r+2&&(a=Math.min(t-1,l-1)),e>=t-r-1&&(i=Math.max(2,t-l+2)),i>2&&n.push(`...`);for(let e=i;e<=a;e++)n.push(e);a<t-1&&n.push(`...`),t>1&&n.push(t)}return n})();return t<=1&&!o?null:(0,V.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-3 bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-6`,children:[(0,V.jsx)(`div`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:u(`pagination.showing`,{start:d,end:f,total:r})}),o&&a&&(0,V.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,V.jsx)(`label`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:u(`pagination.show`)}),(0,V.jsx)(`select`,{value:n,onChange:e=>a(Number(e.target.value)),className:`px-3 py-1 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-500 focus:border-transparent`,children:s.map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))})]})]}),t>1&&(0,V.jsxs)(`div`,{className:`flex items-center space-x-1`,children:[c&&(0,V.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>i(1),disabled:e===1,className:`p-2`,title:u(`pagination.firstPage`),children:(0,V.jsx)(fe,{className:`h-4 w-4`})}),(0,V.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>i(e-1),disabled:e===1,className:`p-2`,title:u(`pagination.previousPage`),children:(0,V.jsx)(be,{className:`h-4 w-4`})}),(0,V.jsx)(`div`,{className:`flex items-center space-x-1`,children:p.map((t,n)=>(0,V.jsx)(`div`,{children:t===`...`?(0,V.jsx)(`span`,{className:`px-3 py-2 text-sm text-gray-500 dark:text-gray-400`,children:`...`}):(0,V.jsx)(U,{variant:e===t?`primary`:`outline`,size:`sm`,onClick:()=>i(t),className:wr(`min-w-[2.5rem] px-3 py-2`,e===t&&`bg-blue-600 text-white border-blue-600 hover:bg-blue-700`),children:t})},n))}),(0,V.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>i(e+1),disabled:e===t,className:`p-2`,title:u(`pagination.nextPage`),children:(0,V.jsx)(z,{className:`h-4 w-4`})}),c&&(0,V.jsx)(U,{variant:`outline`,size:`sm`,onClick:()=>i(t),disabled:e===t,className:`p-2`,title:u(`pagination.lastPage`),children:(0,V.jsx)(xe,{className:`h-4 w-4`})})]})]})}function Y$({isOpen:e,onClose:t,onConfirm:n,selectedCount:r,loading:i=!1}){let{t:a}=H(`studio`),[o,s]=(0,B.useState)(`published`),c=[{value:`draft`,label:a(`changeStatus.draft`),description:a(`changeStatus.draftDesc`)},{value:`published`,label:a(`changeStatus.published`),description:a(`changeStatus.publishedDesc`)},{value:`archived`,label:a(`changeStatus.archived`),description:a(`changeStatus.archivedDesc`)}];return(0,V.jsxs)(ia,{open:e,onClose:t,variant:`center`,size:`sm`,title:a(`changeStatus.title`),children:[(0,V.jsxs)(ia.Body,{children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:a(`changeStatus.selectStatus`,{count:r})}),(0,V.jsx)(`div`,{className:`space-y-2`,children:c.map(e=>(0,V.jsxs)(`label`,{className:wr(`flex items-start p-4 border-2 rounded-lg cursor-pointer transition-all`,o===e.value?`border-blue-500 bg-blue-50 dark:bg-blue-900/20`:`border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600`),children:[(0,V.jsx)(`input`,{type:`radio`,name:`status`,value:e.value,checked:o===e.value,onChange:e=>s(e.target.value),className:`mt-1 h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300`}),(0,V.jsxs)(`div`,{className:`ml-3 flex-1`,children:[(0,V.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-white`,children:e.label}),(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e.description})]})]},e.value))})]}),(0,V.jsxs)(ia.Footer,{children:[(0,V.jsx)(U,{variant:`outline`,onClick:t,disabled:i,children:a(`common.cancel`)}),(0,V.jsx)(U,{onClick:async()=>{await n(o)},disabled:i,children:i?a(`changeStatus.updating`):a(`changeStatus.updateDocument`,{count:r})})]})]})}var X$=Fr(`ContentPage`);function Z$(e){return e?{article:`Article`,author:`Author`,category:`Category`,homePage:`Home Page`,post:`Post`}[e]||e.charAt(0).toUpperCase()+e.slice(1):`Document`}function Q$(){let{schemaName:e,documentId:t}=s(),n=r(),i=va(e||``);if(Uo(),t)return t===`new`&&ba(i.item)?(0,V.jsx)(n1,{schemaName:e}):(0,V.jsx)(R$,{schemaName:e,documentId:t,onCancel:()=>n(`/content/${e}`)});if(e){if(i.item?.type===`singleton`){let t=i.item.documentId||e;return(0,V.jsx)(e1,{schemaName:e,documentId:t,autoCreate:!1,onCancel:()=>n(`/content`)})}return(0,V.jsx)($$,{schemaName:e},e)}return(0,V.jsx)(t1,{})}function $$({schemaName:e}){let t=r(),{t:n}=H(`studio`),i=pa(),a=va(e),o=ci(),s=o.hasSchemaPermission(e,`publish`),c=t=>o.canDeleteDocument(e,t),[l,u]=(0,B.useState)([]),[d,f]=(0,B.useState)(!0),[p,m]=(0,B.useState)(null),[h,g]=(0,B.useState)([]),[_,v]=(0,B.useState)(!1),[y,b]=(0,B.useState)(!1),[x,S]=(0,B.useState)(()=>zr.getContentView(e,`list`)),[C,w]=(0,B.useState)(``),[T,E]=(0,B.useState)({}),[D,O]=(0,B.useState)(null),[k,A]=(0,B.useState)(()=>{let t=zr.getColumnVisibility(e,{}),n=G$(),r={...t};return n.forEach(e=>{r[e.key]===void 0&&(r[e.key]=!0)}),r}),[j]=(0,B.useState)(()=>zr.getGridSettings(e,{cardSize:`medium`,columnsPerRow:null})),[M]=(0,B.useState)(()=>zr.getTableSettings(e,{density:`comfortable`,columnWidths:{}})),[N,P]=(0,B.useState)(1),[F,I]=(0,B.useState)(25),[L,ee]=(0,B.useState)(0);(0,B.useEffect)(()=>{R()},[e,T,D,C,N,F]),(0,B.useEffect)(()=>{P(1)},[T,D,C]);let R=async()=>{try{f(!0),m(null);let t={page:N,limit:F,search:C||void 0,filter:Object.keys(T).length>0?T:void 0,sort:D?`${D.direction===`desc`?`-`:``}${D.field}`:void 0};X$.info(`Loading documents with filters`,{schemaName:e,activeFilters:T,queryParams:t});let n=await W.listDocuments(e,t);if(n.success&&n.data?.documents){u(n.data.documents),ee(n.data.pagination?.total||n.data.documents.length);let t=n.data.documents.reduce((e,t)=>{let n=t._status||`undefined`;return e[n]=(e[n]||0)+1,e},{});X$.info(`Documents loaded`,{schema:e,count:n.data.documents.length,total:n.data.pagination?.total,page:N,statusBreakdown:t,sampleStatuses:n.data.documents.slice(0,3).map(e=>({id:e.id||e._id,title:e.title,_status:e._status,published:e.published}))})}else u([]),ee(0)}catch(e){X$.error(`Failed to load documents`,e),m(e instanceof jr?e.message:`Failed to load documents`),u([])}finally{f(!1)}},te=async(r,a)=>{try{switch(a){case`delete`:if(!await i?.utils?.showConfirm?.(n(`content.confirmDelete`),{title:n(`content.deleteDocument`),confirmText:n(`common.delete`),cancelText:n(`common.cancel`),variant:`danger`}))return;await W.deleteDocument(e,r),X$.info(`Document deleted`,{schema:e,id:r}),await R(),g(e=>e.filter(e=>e!==r));break;case`duplicate`:let o=await W.getDocument(e,r);if(o.success&&o.data){let n={...o.data};delete n._id,delete n.id,delete n._createdAt,delete n._updatedAt,delete n._revision,delete n._collection,n._status=`draft`,n.name?n.name=`${n.name} (Copy)`:n.title&&=`${n.title} (Copy)`,delete n.slug,t(`/content/${e}/new`,{state:{duplicateData:n}})}break;default:X$.warn(`Unknown document action`,{action:a,documentId:r})}}catch(e){X$.error(`Document action failed`,{action:a,documentId:r,error:e}),alert(`Failed to ${a} document: ${e instanceof jr?e.message:`Unknown error`}`)}},ne=(e,t)=>{g(n=>t?[...n,e]:n.filter(t=>t!==e))},re=e=>{g(e?l.map(e=>e.id||e._id):[])},ie=(e,t)=>{E(n=>({...n,[e]:t}))},ae=()=>{E({}),w(``)},z=(e,t)=>{O({field:e,direction:t})},oe=t=>{S(t),zr.setContentView(e,t)},se=(t,n)=>{let r={...k,[t]:n};A(r),zr.setColumnVisibility(e,r)},ce=e=>e===`draft`||e===`published`||e===`archived`,le=async t=>{if(!ce(t))return;let r=h.map(e=>l.find(t=>t._id===e)?._status),a=t===`published`&&r.some(e=>e!==`published`),o=t!==`published`&&r.some(e=>e===`published`);if((a||o)&&!s){let e=n(a?`publish`:`unpublish`);i?.utils?.showToast?.(n(`content.noPublishPermission`,{action:e})||`You don't have permission to ${e} documents`,`error`),X$.warn(`User lacks publish permission for bulk status change`,{newStatus:t,isPublishing:a,isUnpublishing:o,hasPublishPermission:s});return}try{b(!0),await Promise.all(h.map(n=>W.updateDocument(e,n,{_status:t}))),X$.info(`Bulk status change completed`,{count:h.length,newStatus:t}),v(!1),g([]),await R()}catch(e){X$.error(`Bulk status change failed`,e),alert(`Failed to update document status: ${e instanceof jr?e.message:`Unknown error`}`)}finally{b(!1)}},ue=[{type:`list`,title:n(`content.views.list`),icon:we,enabled:!0},{type:`grid`,title:n(`content.views.grid`),icon:pe,enabled:!0},{type:`table`,title:n(`content.views.table`),icon:lt,enabled:!0}],de=[{id:`_status`,label:n(`content.filters.status`),field:`_status`,type:`select`,options:[{label:n(`content.filters.draft`),value:`draft`},{label:n(`content.filters.published`),value:`published`},{label:n(`content.filters.archived`),value:`archived`}]}],fe=[{field:l&&l.length>0&&l[0].name?`name`:`title`,direction:`asc`,label:n(`content.sort.title`)},{field:`_createdAt`,direction:`desc`,label:n(`content.sort.createdDate`)},{field:`_updatedAt`,direction:`desc`,label:n(`content.sort.updatedDate`)}],me=[...s?[{id:`change-status`,label:n(`content.bulkActions.changeStatus`),icon:ke}]:[],{id:`delete`,label:n(`content.bulkActions.delete`),icon:Be,variant:`destructive`}],he=G$().map(e=>e.key===`_status`?{...e,render:e=>{let t=(e||`draft`)===`published`;return(0,V.jsx)(`span`,{className:`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${t?`bg-green-100 text-green-800 dark:bg-green-800 dark:text-green-100`:`bg-yellow-100 text-yellow-800 dark:bg-yellow-800 dark:text-yellow-100`}`,children:n(t?`documentEditor.published`:`documentEditor.draft`)})}}:e);return p?(0,V.jsx)(`div`,{className:`p-6`,children:(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`text-red-500 mb-4`,children:(0,V.jsx)(`h3`,{className:`text-lg font-medium`,children:n(`content.error.loadingDocuments`)})}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:p}),(0,V.jsx)(U,{onClick:R,children:n(`content.tryAgain`)})]})}):(0,V.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,V.jsx)(`div`,{className:`flex-shrink-0 px-6 py-4 bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700`,children:(0,V.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:a?.item?.title||`${Z$(e)} Documents`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:a?.item?.type===`singleton`?n(`content.viewExisting`):n(`content.manageDocuments`)})]}),!ba(a?.item)&&(0,V.jsxs)(U,{onClick:()=>t(`/content/${e}/new`),children:[(0,V.jsx)(Ne,{className:`h-4 w-4 mr-2`}),n(`content.create`,{type:Z$(e)})]})]})}),(0,V.jsx)(B$,{availableViews:ue,currentView:x,onViewChange:oe,searchQuery:C,onSearchChange:w,searchPlaceholder:n(`content.search`,{type:e}),availableFilters:de,activeFilters:T,onFilterChange:ie,onClearFilters:ae,availableSorts:fe,currentSort:D,onSortChange:z,totalItems:L,selectedItems:h.length,bulkActions:me,onBulkAction:async t=>{if(h.length!==0)switch(t){case`change-status`:v(!0);break;case`duplicate`:try{b(!0);for(let e of h)await te(e,`duplicate`);g([]),await R()}catch(e){X$.error(`Bulk duplicate failed`,e),alert(`Failed to duplicate documents: ${e instanceof jr?e.message:`Unknown error`}`)}finally{b(!1)}break;case`delete`:if(!await i?.utils?.showConfirm?.(n(`content.confirmBulkDelete`,{count:h.length}),{title:n(`content.deleteDocument`),confirmText:n(`content.deleteAll`),cancelText:n(`common.cancel`),variant:`danger`}))return;try{b(!0),await Promise.all(h.map(t=>W.deleteDocument(e,t))),g([]),await R()}catch(e){X$.error(`Bulk delete failed`,e),alert(`Failed to delete documents: ${e instanceof jr?e.message:`Unknown error`}`)}finally{b(!1)}}}}),(0,V.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,V.jsxs)(`div`,{className:`flex-1 overflow-auto p-6`,children:[x===`list`&&(0,V.jsx)(W$,{documents:l,columns:he,schemaName:e,loading:d,selectedItems:h,onItemSelect:ne,onSelectAll:re,sortField:D?.field,sortDirection:D?.direction,onSort:z,onDocumentAction:te,canDelete:c}),x===`grid`&&(0,V.jsx)(K$,{documents:l,schemaName:e,loading:d,selectedItems:h,onItemSelect:ne,onDocumentAction:te,canDelete:c,cardSize:j?.cardSize||`medium`,columnsPerRow:j?.columnsPerRow||void 0}),x===`table`&&(0,V.jsx)(q$,{documents:l,columns:he.map(e=>({key:e.key,title:e.title,sortable:e.sortable,render:e.render,visible:k[e.key]===!0,resizable:!0,minWidth:100})),schemaName:e,loading:d,selectedItems:h,onItemSelect:ne,onSelectAll:re,sortField:D?.field,sortDirection:D?.direction,onSort:z,onDocumentAction:te,canDelete:c,onColumnVisibilityChange:se,density:M?.density||`comfortable`})]}),L>0&&(0,V.jsx)(J$,{currentPage:N,totalPages:Math.ceil(L/F),pageSize:F,totalItems:L,onPageChange:P,onPageSizeChange:e=>{I(e),P(1)},showPageSizeSelector:!0,pageSizeOptions:[10,25,50,100],showFirstLast:!0})]}),(0,V.jsx)(Y$,{isOpen:_,onClose:()=>v(!1),onConfirm:le,selectedCount:h.length,loading:y})]})}function e1({schemaName:e,documentId:t,autoCreate:n,onCancel:i}){let[a,o]=(0,B.useState)(!0),[s,c]=(0,B.useState)(null),l=r(),{t:u}=H(`studio`);(0,B.useEffect)(()=>{d()},[e,t]);let d=async()=>{try{o(!0),c(null);let r=await W.getDocument(e,t);r.success&&r.data?l(`/content/${e}/${t}`,{replace:!0}):n?await f():c(`Document '${t}' not found. Only existing documents can be viewed.`)}catch(e){X$.error(`Failed to check singleton document`,e),n&&e instanceof jr&&e.status===404?await f():c(e instanceof jr?`Document not found. Only existing documents can be viewed.`:`Failed to load document`)}finally{o(!1)}},f=async()=>{try{X$.info(`Auto-creating singleton document`,{schemaName:e,documentId:t}),(await W.createDocument(e,{id:t,title:`${e} Configuration`,_type:e})).success?(X$.info(`Singleton document created`,{schemaName:e,documentId:t}),l(`/content/${e}/${t}`,{replace:!0})):c(`Failed to create singleton document`)}catch(e){X$.error(`Failed to create singleton document`,e),c(e instanceof jr?e.message:`Failed to create singleton document`)}};return a?(0,V.jsx)(`div`,{className:`p-6`,children:(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:u(`content.loadingSingleton`)})]})}):s?(0,V.jsx)(`div`,{className:`p-6`,children:(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsxs)(`div`,{className:`text-amber-500 mb-4`,children:[(0,V.jsx)(pe,{className:`h-12 w-12 mx-auto mb-2`}),(0,V.jsx)(`h3`,{className:`text-lg font-medium`,children:u(`content.error.documentNotFound`)})]}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:s}),(0,V.jsxs)(`div`,{className:`flex justify-center space-x-4`,children:[(0,V.jsx)(U,{onClick:d,children:u(`content.tryAgain`)}),(0,V.jsx)(U,{variant:`outline`,onClick:i,children:u(`content.backToContent`)})]})]})}):(0,V.jsx)(R$,{schemaName:e,documentId:t,onCancel:i})}function t1(){let e=r(),{t}=H(`studio`),[n,i]=(0,B.useState)([]),[a,o]=(0,B.useState)(!0),[s,c]=(0,B.useState)(null);(0,B.useEffect)(()=>{l()},[]);let l=async()=>{try{o(!0),c(null);let e=await W.get(`/collections`);e.success&&e.data?.collections?(i(e.data.collections),X$.info(`Collections loaded`,{count:e.data.collections.length})):c(`No collections found`)}catch(e){X$.error(`Failed to load collections`,e),c(e instanceof jr?e.message:`Failed to load collections`)}finally{o(!1)}};return a?(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:t(`content.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:t(`content.subtitle`)})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:t(`content.loading`)})]})]}):s?(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:t(`content.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:t(`content.subtitle`)})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsxs)(`div`,{className:`text-red-500 mb-4`,children:[(0,V.jsx)(pe,{className:`h-12 w-12 mx-auto mb-2`}),(0,V.jsx)(`h3`,{className:`text-lg font-medium`,children:t(`content.error.loadingTypes`)})]}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:s}),(0,V.jsx)(U,{onClick:l,children:t(`content.tryAgain`)})]})]}):n.length===0?(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:t(`content.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:t(`content.subtitle`)})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsx)(pe,{className:`h-12 w-12 text-gray-400 mx-auto mb-4`}),(0,V.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-white mb-2`,children:t(`content.noTypes`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:t(`content.noTypesDescription`)}),(0,V.jsx)(U,{onClick:l,children:t(`content.refresh`)})]})]}):(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:t(`content.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:t(`content.subtitle`)})]}),(0,V.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:n.map(n=>(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 hover:shadow-md transition-shadow`,children:(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center mb-4`,children:[(0,V.jsx)(pe,{className:`h-8 w-8 text-blue-600 mr-3`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-white`,children:n.title}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:n.name})]})]}),(0,V.jsx)(`div`,{className:`flex space-x-2`,children:(0,V.jsx)(U,{size:`sm`,onClick:()=>e(`/content/${n.name}`),children:t(`content.viewDocuments`)})})]})},n.name))})]})}function n1({schemaName:e}){let t=r(),{t:n}=H(`studio`);return(0,B.useEffect)(()=>{t(`/content/${e}`,{replace:!0})},[t,e]),(0,V.jsx)(`div`,{className:`p-6`,children:(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:n(`content.redirecting`)})]})})}function r1(e,t){switch(t){case`images`:return e.contentType.startsWith(`image/`);case`videos`:return e.contentType.startsWith(`video/`);case`audio`:return e.contentType.startsWith(`audio/`);case`documents`:return e.contentType.includes(`pdf`)||e.contentType.includes(`text/`)||e.contentType.includes(`application/`);case`archives`:return e.contentType.includes(`zip`)||e.contentType.includes(`rar`)||e.contentType.includes(`tar`);default:return!0}}function i1(e,t){return!!(e.filename.toLowerCase().includes(t)||e.metadata?.title?.toLowerCase().includes(t)||e.metadata?.alt?.toLowerCase().includes(t)||e.metadata?.author?.toLowerCase().includes(t)||e.metadata?.credit?.toLowerCase().includes(t)||e.metadata?.tags?.some(e=>e.toLowerCase().includes(t)))}function a1(e,t,n,r,i){let a=e;if(t!==`all`&&(a=a.filter(e=>r1(e,t))),n.trim()){let e=n.toLowerCase();a=a.filter(t=>i1(t,e))}return a=[...a].sort((e,t)=>{let n=0;switch(r){case`date`:n=new Date(t._createdAt).getTime()-new Date(e._createdAt).getTime();break;case`name`:n=e.filename.localeCompare(t.filename);break;case`size`:n=t.size-e.size}return i===`asc`?-n:n}),a}function o1(e){return e.startsWith(`image/`)?at:e.startsWith(`video/`)?Ie:e.startsWith(`audio/`)?Je:e.includes(`zip`)||e.includes(`rar`)||e.includes(`tar`)?Ue:se}var s1={all:se,images:at,videos:Ie,audio:Je,documents:se,archives:Ue};function c1(e,t){return t===`all`?e.length:e.filter(e=>r1(e,t)).length}function l1(e){return e.metadata?.imageVariants?Object.keys(e.metadata.imageVariants).length:0}function u1(){let[e,t]=(0,B.useState)([]),[n,r]=(0,B.useState)([]),[i,a]=(0,B.useState)(!1),[o,s]=(0,B.useState)(()=>{try{let e=localStorage.getItem(`trokky-media-view-mode`);return e===`list`||e===`grid`?e:`grid`}catch{return`grid`}}),[c,l]=(0,B.useState)(``),[u,d]=(0,B.useState)(`all`),[f,p]=(0,B.useState)(1),[,m]=(0,B.useState)(0),[h,g]=(0,B.useState)(()=>{let e=[28,56,84,112];try{let t=localStorage.getItem(`trokky-media-items-per-page`),n=t?parseInt(t,10):56;return e.includes(n)?n:56}catch{return 56}}),[_,v]=(0,B.useState)(`date`),[y,b]=(0,B.useState)(`desc`),x=(0,B.useRef)(!1),S=Fr(`MediaPage`),C=(0,B.useCallback)(e=>{s(e);try{localStorage.setItem(`trokky-media-view-mode`,e)}catch(e){S.warn(`Failed to save view mode to localStorage:`,e)}},[S]),w=(0,B.useCallback)(e=>{g(e),p(1);try{localStorage.setItem(`trokky-media-items-per-page`,String(e))}catch{}},[]),T=(0,B.useCallback)(async()=>{if(!x.current){x.current=!0,a(!0);try{if(!W.hasFeature(`media`)){S.info(`Media feature not available, using empty state`),t([]);return}let e=await W.getMedia({limit:1e4});t(e.data||[]),m(e.meta?.total||e.data?.length||0),S.info(`Media files loaded successfully`,{count:e.data?.length||0,total:e.meta?.total})}catch(e){S.error(`Failed to load media files:`,e),t([])}finally{x.current=!1,a(!1)}}},[W]);(0,B.useEffect)(()=>{r(a1(e,u,c,_,y)),p(1)},[e,u,c,_,y]);let E=Math.ceil(n.length/h),D=(f-1)*h,O=D+h,k=n.slice(D,O);return(0,B.useEffect)(()=>{T()},[]),{mediaFiles:e,setMediaFiles:t,filteredFiles:n,isUploading:i,setIsUploading:a,viewMode:o,updateViewMode:C,searchQuery:c,setSearchQuery:l,selectedType:u,setSelectedType:d,currentPage:f,setCurrentPage:p,itemsPerPage:h,updateItemsPerPage:w,sortBy:_,setSortBy:v,sortDirection:y,setSortDirection:b,totalPages:E,startIndex:D,endIndex:O,paginatedFiles:k,loadMediaFiles:T,logger:S}}function d1({filteredFiles:e,selectedType:t,searchQuery:n,canDelete:r,isViewerOpen:i,isEditModalOpen:a,isDeleteModalOpen:o,isBulkDeleteModalOpen:s,setIsBulkDeleteModalOpen:c}){let[l,u]=(0,B.useState)(new Set),[d,f]=(0,B.useState)(null),p=(0,B.useCallback)((t,n,r=!1)=>{u(i=>{let a=new Set(i);if(r&&d&&n){let n=e.findIndex(e=>e.id===t),r=e.findIndex(e=>e.id===d);if(n!==-1&&r!==-1){let t=Math.min(n,r),i=Math.max(n,r);for(let n=t;n<=i;n++)a.add(e[n].id)}}else n?a.add(t):a.delete(t);return a}),n&&f(t)},[e,d]),m=(0,B.useCallback)(()=>{l.size===e.length?u(new Set):u(new Set(e.map(e=>e.id)))},[e,l.size]),h=(0,B.useCallback)(()=>{u(new Set),f(null)},[]),g=(0,B.useCallback)(()=>{l.size!==0&&r&&c(!0)},[l.size,r]);return(0,B.useEffect)(()=>{h()},[t,n,h]),(0,B.useEffect)(()=>{if(i||a||o||s)return;let e=e=>{let t=e.target;if(!(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)){if((e.metaKey||e.ctrlKey)&&e.key===`a`){e.preventDefault(),m();return}if(e.key===`Escape`&&l.size>0){e.preventDefault(),h();return}if((e.key===`Delete`||e.key===`Backspace`)&&l.size>0&&r){e.preventDefault(),g();return}}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i,a,o,s,l.size,r,m,h,g]),{selectedIds:l,handleItemSelect:p,handleSelectAll:m,clearSelection:h,handleBulkDelete:g}}function f1({canUpload:e,logger:t,showToast:n,setIsUploading:r,loadMediaFiles:i}){let[a,o]=(0,B.useState)(!1),s=(0,B.useRef)(null),c=t=>{t.preventDefault(),e&&W.hasFeature(`media`)&&o(!0)},l=e=>{e.preventDefault();let t=e.currentTarget.getBoundingClientRect(),n=e.clientX,r=e.clientY;(n<t.left||n>t.right||r<t.top||r>t.bottom)&&o(!1)},u=async t=>{if(t.preventDefault(),o(!1),!e||!W.hasFeature(`media`))return;let n=Array.from(t.dataTransfer.files);n.length>0&&await d(n)},d=async a=>{if(!e){n(`You do not have permission to upload files`,`error`);return}if(!W.hasFeature(`media`)){t.warn(`Upload attempted but media feature not available`),n(`Media upload feature is not available`,`error`);return}r(!0);try{for(let e of a)await W.uploadMedia(e);await i();let e=a.length===1?`Successfully uploaded "${a[0].name}"`:`Successfully uploaded ${a.length} files`;t.info(e),n(a.length===1?`Uploaded`:`${a.length} files uploaded`,`success`)}catch(e){let t=`Upload failed. Please try again.`;e instanceof Error&&(t=e.message.includes(`File size exceeds`)?`File size exceeds 100MB limit. Please choose a smaller file.`:e.message.includes(`File type`)&&e.message.includes(`not allowed`)?`File type not supported. Please choose a different file format.`:e.message.includes(`network`)||e.message.includes(`fetch`)?`Network error. Please check your connection and try again.`:e.message),n(t,`error`)}finally{r(!1)}};return{isDragging:a,fileInputRef:s,handleDragOver:c,handleDragLeave:l,handleDrop:u,handleFileInputChange:e=>{let t=Array.from(e.target.files||[]);t.length>0&&d(t)},handleUploadClick:()=>{if(!e){n(`You do not have permission to upload files`,`error`);return}if(!W.hasFeature(`media`)){t.warn(`Upload button clicked but media feature not available`),n(`Media upload feature is not available`,`error`);return}s.current?.click()}}}function p1({canEdit:e,canDelete:t,logger:n,loadMediaFiles:r,setMediaFiles:i,selectedFile:a,setSelectedFile:o,editingFile:s,setEditingFile:c,isViewerOpen:l,setIsViewerOpen:u,setIsEditModalOpen:d,setIsDeleteModalOpen:f,setIsBulkDeleteModalOpen:p,selectedIds:m,clearSelection:h,isDeleting:g,setIsDeleting:_,showToast:v}){return{handleEdit:async e=>{try{let t=await W.getMediaFile(e.id);t.success&&t.data?.file?c({...t.data.file}):c({...e}),d(!0)}catch(t){n.error(`Failed to fetch latest file data for editing:`,t),c({...e}),d(!0)}},handleDelete:e=>{c(e),f(!0)},confirmDelete:async()=>{if(s&&t){if(!W.hasFeature(`media`)){n.warn(`Delete attempted but media feature not available`);return}try{await W.deleteMedia(s.id),await r(),f(!1),c(null),l&&a?.id===s.id&&u(!1),n.info(`Successfully deleted media file: ${s.filename}`)}catch(e){n.error(`Delete failed:`,e)}}},saveEdit:async()=>{if(s&&e){if(!W.hasFeature(`media`)){n.warn(`Edit save attempted but media feature not available`);return}try{let e=await W.updateMedia(s.id,{title:s.metadata?.title||``,alt:s.metadata?.alt||``,author:s.metadata?.author||``,credit:s.metadata?.credit||``});n.info(`Media metadata updated successfully:`,e.data?.file),i(t=>t.map(t=>t.id===s.id?{...t,metadata:e.data?.file?.metadata||t.metadata}:t)),a?.id===s.id&&o({...a,metadata:e.data?.file?.metadata||a.metadata}),d(!1),c(null)}catch(e){n.error(`Save failed:`,e)}}},handleRegenerateVariants:async e=>{if(t){if(!W.hasFeature(`media`)){n.warn(`Regenerate variants attempted but media feature not available`);return}if(!e.contentType.startsWith(`image/`)){n.warn(`Regenerate variants attempted on non-image file`);return}try{n.info(`Regenerating variants for:`,e.filename);let t=await W.regenerateMediaVariants(e.id);t.success&&t.data?.file&&(i(n=>n.map(n=>n.id===e.id&&t.data?.file||n)),a?.id===e.id&&t.data?.file&&o(t.data.file),n.info(`Variants regenerated successfully`))}catch(e){n.error(`Failed to regenerate variants:`,e)}}},confirmBulkDelete:async()=>{if(m.size!==0&&t&&!g){if(!W.hasFeature(`media`)){n.warn(`Bulk delete attempted but media feature not available`);return}_(!0);try{let e=Array.from(m),t=await W.bulkDeleteMedia(e);if(t.success){let{successCount:e,errorCount:n}=t.data||{successCount:0,errorCount:0};n>0?v(`Deleted ${e} file(s), ${n} failed`,`warning`):v(e===1?`File deleted`:`${e} files deleted`,`success`),await r(),h(),l&&a&&m.has(a.id)&&u(!1)}}catch(e){n.error(`Bulk delete failed:`,e),v(`Failed to delete files`,`error`)}finally{_(!1),p(!1)}}}}}function m1({isDragging:e,isUploading:t,fileInputRef:n,onDragOver:r,onDragLeave:i,onDrop:a,onUploadClick:o,onFileInputChange:s}){let{t:c}=H(`studio`);return(0,V.jsx)(`div`,{className:`mb-8`,children:(0,V.jsxs)(`div`,{className:`relative border-2 border-dashed rounded-lg p-8 text-center transition-colors ${e?`border-primary-400 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:r,onDragLeave:i,onDrop:a,children:[(0,V.jsx)(at,{className:`h-16 w-16 text-gray-400 mx-auto mb-4`}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsxs)(`p`,{className:`text-lg font-medium text-gray-900 dark:text-white`,children:[(0,V.jsx)(U,{variant:`ghost`,className:`text-primary-600 hover:text-primary-500`,onClick:o,disabled:t,children:c(t?`common.loading`:`media.browseFiles`)}),` `,c(`media.or`),` `,c(`media.dragAndDrop`)]}),(0,V.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:`PNG, JPG, GIF, MP4, PDF up to 100MB`})]}),(0,V.jsx)(`input`,{ref:n,type:`file`,multiple:!0,className:`hidden`,accept:`image/*,video/*,audio/*,.pdf,.txt,.doc,.docx`,onChange:s})]})})}function h1({label:e,error:t,helperText:n,className:r,id:i,...a}){let o=i||`input-${Math.random().toString(36).substr(2,9)}`;return(0,V.jsxs)(`div`,{className:`w-full`,children:[e&&(0,V.jsx)(`label`,{htmlFor:o,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e}),(0,V.jsx)(`input`,{id:o,className:wr(`w-full px-3 py-2 border rounded-md transition-colors`,`bg-white dark:bg-gray-700`,`text-gray-900 dark:text-white`,`placeholder-gray-400 dark:placeholder-gray-500`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent`,t?`border-red-300 dark:border-red-600`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`,`disabled:opacity-50 disabled:cursor-not-allowed`,r),...a}),t&&(0,V.jsx)(`p`,{className:`mt-1 text-sm text-red-600 dark:text-red-400`,children:t}),n&&!t&&(0,V.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-gray-400`,children:n})]})}function g1({searchQuery:e,onSearchQueryChange:t,onToggleFilterSidebar:n,sortBy:r,sortDirection:i,onSortChange:a,itemsPerPage:o,onItemsPerPageChange:s,viewMode:c,onViewModeChange:l}){let{t:u}=H(`studio`);return(0,V.jsxs)(`div`,{className:`mb-6 flex flex-col sm:flex-row gap-4`,children:[(0,V.jsxs)(`div`,{className:`relative flex-1`,children:[(0,V.jsx)(ee,{className:`absolute left-3 top-1/2 transform -translate-y-1/2 h-5 w-5 text-gray-400`}),(0,V.jsx)(h1,{placeholder:u(`media.searchPlaceholder`),value:e,onChange:e=>t(e.target.value),className:`pl-10`})]}),(0,V.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,V.jsx)(U,{variant:`ghost`,size:`sm`,className:`lg:hidden`,onClick:n,children:(0,V.jsx)(Re,{className:`h-4 w-4`})}),(0,V.jsxs)(`select`,{value:`${r}-${i}`,onChange:e=>{let[t,n]=e.target.value.split(`-`);a(t,n)},className:`px-3 py-2 text-sm border border-gray-200 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-700 dark:text-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[(0,V.jsx)(`option`,{value:`date-desc`,children:u(`media.sort.dateDesc`)}),(0,V.jsx)(`option`,{value:`date-asc`,children:u(`media.sort.dateAsc`)}),(0,V.jsx)(`option`,{value:`name-asc`,children:u(`media.sort.nameAsc`)}),(0,V.jsx)(`option`,{value:`name-desc`,children:u(`media.sort.nameDesc`)}),(0,V.jsx)(`option`,{value:`size-desc`,children:u(`media.sort.sizeDesc`)}),(0,V.jsx)(`option`,{value:`size-asc`,children:u(`media.sort.sizeAsc`)})]}),(0,V.jsxs)(`select`,{value:o,onChange:e=>{s(parseInt(e.target.value,10))},className:`px-3 py-2 text-sm border border-gray-200 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-700 dark:text-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500`,children:[(0,V.jsxs)(`option`,{value:`28`,children:[`28 `,u(`media.perPage`)]}),(0,V.jsxs)(`option`,{value:`56`,children:[`56 `,u(`media.perPage`)]}),(0,V.jsxs)(`option`,{value:`84`,children:[`84 `,u(`media.perPage`)]}),(0,V.jsxs)(`option`,{value:`112`,children:[`112 `,u(`media.perPage`)]})]}),(0,V.jsxs)(`div`,{className:`flex border border-gray-200 dark:border-gray-600 rounded-lg overflow-hidden`,children:[(0,V.jsx)(`button`,{onClick:()=>l(`grid`),className:`px-3 py-2 text-sm transition-colors ${c===`grid`?`bg-gray-900 text-white dark:bg-gray-100 dark:text-gray-900`:`bg-white text-gray-700 hover:bg-gray-50 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600`}`,children:(0,V.jsx)(Ze,{className:`h-4 w-4`})}),(0,V.jsx)(`button`,{onClick:()=>l(`list`),className:`px-3 py-2 text-sm transition-colors border-l border-gray-200 dark:border-gray-600 ${c===`list`?`bg-gray-900 text-white dark:bg-gray-100 dark:text-gray-900`:`bg-white text-gray-700 hover:bg-gray-50 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600`}`,children:(0,V.jsx)(we,{className:`h-4 w-4`})})]})]})]})}function _1({isOpen:e,onClose:t,mediaTypes:n,selectedType:r,onSelectType:i}){let{t:a}=H(`studio`);return(0,V.jsx)(`div`,{className:`${e?`block`:`hidden`} lg:block w-48 lg:w-56 flex-shrink-0`,children:(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-3`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,V.jsxs)(`h3`,{className:`text-xs font-medium text-gray-900 dark:text-white uppercase tracking-wide`,children:[(0,V.jsx)(Re,{className:`h-3 w-3 inline mr-1`}),a(`media.filters`)]}),(0,V.jsx)(`button`,{onClick:t,className:`lg:hidden p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,children:(0,V.jsx)(tt,{className:`h-3 w-3`})})]}),(0,V.jsx)(`div`,{className:`space-y-0.5`,children:Object.entries(n).map(([e,t])=>{let n=t.icon;return(0,V.jsxs)(`button`,{onClick:()=>i(e),className:`w-full flex items-center justify-between px-2 py-1.5 text-xs rounded-md transition-colors ${r===e?`bg-primary-100 text-primary-700 dark:bg-primary-900 dark:text-primary-300`:`text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700`}`,children:[(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(n,{className:`h-3 w-3 mr-1.5`}),t.label]}),(0,V.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 font-medium`,children:t.count})]},e)})})]})})}function v1({selectedCount:e,totalCount:t,isDeleting:n,onSelectAll:r,onClearSelection:i,onBulkDelete:a}){let{t:o}=H(`studio`);return(0,V.jsxs)(`div`,{className:`mb-4 flex items-center justify-between bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg px-4 py-3`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,V.jsx)(V$,{checked:e===t,indeterminate:e>0&&e<t,onChange:r,"aria-label":o(`common.selectAll`)}),(0,V.jsx)(`span`,{className:`text-sm font-medium text-blue-800 dark:text-blue-200`,children:o(`media.selected`,{count:e})})]}),(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:i,className:`text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-200`,children:o(`common.deselectAll`)})]}),(0,V.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:r,className:`text-blue-600 dark:text-blue-400`,children:o(e===t?`common.deselectAll`:`common.selectAll`)}),(0,V.jsxs)(U,{variant:`danger`,size:`sm`,onClick:a,disabled:n,children:[(0,V.jsx)(Be,{className:`h-4 w-4 mr-2`}),o(n?`common.loading`:`media.deleteSelected`)]})]})]})}function y1({file:e,viewMode:t,isSelected:n,canEdit:r,canDelete:i,getMediaUrl:a,onItemSelect:o,onOpenViewer:s,onEdit:c,onDelete:l}){let u=o1(e.contentType),d=e.contentType.startsWith(`image/`),f=l1(e);return t===`grid`?(0,V.jsxs)(`div`,{className:`group relative bg-white dark:bg-gray-800 rounded-lg border overflow-hidden hover:shadow-md transition-all cursor-pointer ${n?`ring-2 ring-blue-500 border-blue-500 shadow-lg`:`border-gray-200 dark:border-gray-700`}`,onClick:t=>{t.shiftKey&&i?(t.preventDefault(),o(e.id,!0,!0)):s(e)},children:[i&&(0,V.jsx)(`div`,{className:`absolute top-2 left-2 z-10`,onClick:e=>e.stopPropagation(),children:(0,V.jsx)(V$,{checked:n,onChange:t=>o(e.id,t),"aria-label":`Select ${e.metadata?.title||e.filename}`})}),(0,V.jsx)(`div`,{className:`aspect-square flex items-center justify-center bg-gray-50 dark:bg-gray-900`,children:d?(0,V.jsx)(`img`,{src:a(e,gi(e)),alt:e.metadata?.alt||e.filename,className:`w-full h-full object-cover`,loading:`lazy`}):(0,V.jsx)(u,{className:`h-12 w-12 text-gray-400`})}),f>0&&(0,V.jsx)(`div`,{className:`absolute top-2 right-2 bg-primary-600 text-white text-xs px-2 py-1 rounded-full`,children:f}),(0,V.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-40 transition-opacity flex items-center justify-center opacity-0 group-hover:opacity-100`,children:(0,V.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,V.jsx)(U,{size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),s(e)},children:(0,V.jsx)(ce,{className:`h-4 w-4`})}),(r||i)&&(0,V.jsxs)(V.Fragment,{children:[r&&(0,V.jsx)(U,{size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),c(e)},children:(0,V.jsx)(ct,{className:`h-4 w-4`})}),i&&(0,V.jsx)(U,{size:`sm`,variant:`danger`,onClick:t=>{t.stopPropagation(),l(e)},children:(0,V.jsx)(Be,{className:`h-4 w-4`})})]})]})}),(0,V.jsxs)(`div`,{className:`p-3`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-white truncate`,children:e.metadata?.title||e.filename}),(0,V.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:hi(e.size)})})]})]}):(0,V.jsxs)(`div`,{className:`flex items-center space-x-4 p-4 bg-white dark:bg-gray-800 rounded-lg border hover:shadow-sm transition-all cursor-pointer ${n?`ring-2 ring-blue-500 border-blue-500 shadow-lg`:`border-gray-200 dark:border-gray-700`}`,onClick:t=>{t.shiftKey&&i?(t.preventDefault(),o(e.id,!0,!0)):s(e)},children:[i&&(0,V.jsx)(`div`,{className:`flex-shrink-0`,onClick:e=>e.stopPropagation(),children:(0,V.jsx)(V$,{checked:n,onChange:t=>o(e.id,t),"aria-label":`Select ${e.metadata?.title||e.filename}`})}),(0,V.jsx)(`div`,{className:`flex-shrink-0`,children:d?(0,V.jsx)(`img`,{src:a(e,gi(e)),alt:e.metadata?.alt||e.filename,className:`w-12 h-12 object-cover rounded`,loading:`lazy`}):(0,V.jsx)(`div`,{className:`w-12 h-12 bg-gray-100 dark:bg-gray-700 rounded flex items-center justify-center`,children:(0,V.jsx)(u,{className:`h-6 w-6 text-gray-400`})})}),(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-white truncate`,children:e.metadata?.title||e.filename}),(0,V.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[hi(e.size),` • `,e.contentType]}),e.metadata?.alt&&(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500 truncate`,children:e.metadata.alt})]}),(r||i)&&(0,V.jsxs)(`div`,{className:`flex space-x-1`,children:[r&&(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:t=>{t.stopPropagation(),c(e)},children:(0,V.jsx)(ct,{className:`h-4 w-4`})}),i&&(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:t=>{t.stopPropagation(),l(e)},children:(0,V.jsx)(Be,{className:`h-4 w-4`})})]})]})}function b1({isOpen:e,onClose:t,title:n,size:r=`md`,children:i,closeOnOverlayClick:a=!0}){return(0,V.jsx)(ia,{open:e,onClose:t,variant:`center`,size:r,title:n,closeOnBackdrop:a,children:(0,V.jsx)(ia.Body,{padded:!1,className:`p-6`,children:i})})}function x1({isOpen:e,editingFile:t,onEditingFileChange:n,onClose:r,onSave:i}){let{t:a}=H(`studio`);return(0,V.jsx)(b1,{isOpen:e,onClose:r,title:a(`media.editMetadata`),children:(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:a(`common.title`)||`Title`}),(0,V.jsx)(h1,{value:t.metadata?.title||``,onChange:e=>n({...t,metadata:{...t.metadata,title:e.target.value}})})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:`Alt Text`}),(0,V.jsx)(h1,{value:t.metadata?.alt||``,onChange:e=>n({...t,metadata:{...t.metadata,alt:e.target.value}})})]}),(0,V.jsxs)(`div`,{className:`flex space-x-3 pt-4`,children:[(0,V.jsx)(U,{onClick:i,className:`flex-1`,children:a(`common.save`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:r,className:`flex-1`,children:a(`common.cancel`)})]})]})})}function S1({isOpen:e,editingFile:t,onClose:n,onConfirm:r}){let{t:i}=H(`studio`);return(0,V.jsx)(b1,{isOpen:e,onClose:n,title:i(`media.delete`),children:(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-start space-x-3`,children:[(0,V.jsx)(de,{className:`h-6 w-6 text-red-600 mt-1`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-gray-900 dark:text-white`,children:i(`media.confirmDelete`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:(0,V.jsx)(`strong`,{children:t.metadata?.title||t.filename})})]})]}),(0,V.jsxs)(`div`,{className:`flex space-x-3 pt-4`,children:[(0,V.jsx)(U,{variant:`danger`,onClick:r,className:`flex-1`,children:i(`common.delete`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:n,className:`flex-1`,children:i(`common.cancel`)})]})]})})}function C1({isOpen:e,selectedCount:t,isDeleting:n,onClose:r,onConfirm:i}){let{t:a}=H(`studio`);return(0,V.jsx)(b1,{isOpen:e,onClose:r,title:a(`media.deleteSelected`),children:(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-start space-x-3`,children:[(0,V.jsx)(de,{className:`h-6 w-6 text-red-600 mt-1`}),(0,V.jsx)(`div`,{children:(0,V.jsx)(`p`,{className:`text-gray-900 dark:text-white`,children:a(`media.confirmBulkDelete`,{count:t})})})]}),(0,V.jsxs)(`div`,{className:`flex space-x-3 pt-4`,children:[(0,V.jsx)(U,{variant:`danger`,onClick:i,className:`flex-1`,disabled:n,children:a(n?`common.loading`:`common.delete`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:r,className:`flex-1`,disabled:n,children:a(`common.cancel`)})]})]})})}function w1(){let{t:e}=H(`studio`);za({page:`media`,title:e(`media.title`),defaultVisible:!1,defaultPosition:`left`});let t=pa(),[n,r]=(0,B.useState)(null),[i,a]=(0,B.useState)(!1),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(!1),[u,d]=(0,B.useState)(!1),[f,m]=(0,B.useState)(!1),[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)(0),[y,b]=(0,B.useState)(!1),{hasPermission:x}=ci(),S=x(li.UPLOAD),C=x(li.EDIT),w=x(li.DELETE),[T,E]=p(),{mediaFiles:D,setMediaFiles:O,filteredFiles:k,isUploading:A,setIsUploading:j,viewMode:M,updateViewMode:N,searchQuery:P,setSearchQuery:F,selectedType:I,setSelectedType:L,currentPage:ee,setCurrentPage:R,itemsPerPage:te,updateItemsPerPage:ne,sortBy:re,setSortBy:ie,sortDirection:ae,setSortDirection:oe,totalPages:se,startIndex:ce,endIndex:le,paginatedFiles:ue,loadMediaFiles:fe,logger:pe}=u1(),{selectedIds:me,handleItemSelect:he,handleSelectAll:ge,clearSelection:_e,handleBulkDelete:ve}=d1({filteredFiles:k,selectedType:I,searchQuery:P,canDelete:w,isViewerOpen:o,isEditModalOpen:c,isDeleteModalOpen:u,isBulkDeleteModalOpen:f,setIsBulkDeleteModalOpen:m}),{isDragging:ye,fileInputRef:xe,handleDragOver:Se,handleDragLeave:Ce,handleDrop:we,handleFileInputChange:Te,handleUploadClick:Ee}=f1({canUpload:S,logger:pe,showToast:(e,n)=>t?.utils.showToast(e,n),setIsUploading:j,loadMediaFiles:fe}),De={all:{label:e(`media.types.all`),icon:s1.all,count:c1(D,`all`)},images:{label:e(`media.types.images`),icon:s1.images,count:c1(D,`images`)},videos:{label:e(`media.types.videos`),icon:s1.videos,count:c1(D,`videos`)},audio:{label:e(`media.types.audio`),icon:s1.audio,count:c1(D,`audio`)},documents:{label:e(`media.types.documents`),icon:s1.documents,count:c1(D,`documents`)},archives:{label:e(`media.types.archives`),icon:s1.archives,count:c1(D,`archives`)}},Oe=e=>{let t=k.findIndex(t=>t.id===e.id);v(t>=0?t:-1),r(e),s(!0)},Ae=e=>{if(_===-1){let t=e===`prev`?k.length-1:0;k[t]&&(v(t),r(k[t]));return}let t=e===`prev`?Math.max(0,_-1):Math.min(k.length-1,_+1);k[t]&&(v(t),r(k[t]))};(0,B.useEffect)(()=>{let e=T.get(`file`);if(e&&D.length>0){let t=D.find(t=>t.id===e);t&&(!n||n.id!==e)&&(Oe(t),pe.debug(`Opening media file from URL parameter`,{fileId:e,filename:t.filename}))}},[T,D]),(0,B.useEffect)(()=>{if(o&&n){let e=new URLSearchParams(T);e.set(`file`,n.id),E(e,{replace:!0})}else if(!o&&D.length>0){let e=new URLSearchParams(T);e.has(`file`)&&(e.delete(`file`),E(e,{replace:!0}))}},[o,n,D.length]),(0,B.useEffect)(()=>{if(!o)return;let e=e=>{if(e.key===`Escape`){if(Di(e))return;s(!1)}else e.key===`ArrowLeft`?Ae(`prev`):e.key===`ArrowRight`&&Ae(`next`)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[o,_,k]);let{handleEdit:je,handleDelete:Me,confirmDelete:Pe,saveEdit:Fe,handleRegenerateVariants:Ie,confirmBulkDelete:Le}=p1({canEdit:C,canDelete:w,logger:pe,loadMediaFiles:fe,setMediaFiles:O,selectedFile:n,setSelectedFile:r,editingFile:h,setEditingFile:g,isViewerOpen:o,setIsViewerOpen:s,setIsEditModalOpen:l,setIsDeleteModalOpen:d,setIsBulkDeleteModalOpen:m,selectedIds:me,clearSelection:_e,isDeleting:y,setIsDeleting:b,showToast:(e,n)=>t?.utils.showToast(e,n)}),Re=(e,n)=>{let r=t?.mediaUrlGenerator;return r?r.getMediaUrl(e.id,n):(pe.warn(`MediaUrlGenerator not available in MediaPage, using fallback URL`,{mediaId:e.id,variant:n}),e.url)};return(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`media.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`media.subtitle`)})]}),S&&W.hasFeature(`media`)&&(0,V.jsx)(m1,{isDragging:ye,isUploading:A,fileInputRef:xe,onDragOver:Se,onDragLeave:Ce,onDrop:we,onUploadClick:Ee,onFileInputChange:Te}),!W.hasFeature(`media`)&&(0,V.jsx)(`div`,{className:`mb-8 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-6`,children:(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(de,{className:`h-6 w-6 text-yellow-600 dark:text-yellow-400 mr-3`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-yellow-800 dark:text-yellow-200`,children:`Media Management Not Available`}),(0,V.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300 mt-1`,children:`Media upload and management features are not enabled in this Studio instance. Contact your administrator to enable media capabilities.`})]})]})}),(0,V.jsx)(g1,{searchQuery:P,onSearchQueryChange:F,onToggleFilterSidebar:()=>a(!i),sortBy:re,sortDirection:ae,onSortChange:(e,t)=>{ie(e),oe(t)},itemsPerPage:te,onItemsPerPageChange:ne,viewMode:M,onViewModeChange:N}),me.size>0&&w&&(0,V.jsx)(v1,{selectedCount:me.size,totalCount:k.length,isDeleting:y,onSelectAll:ge,onClearSelection:_e,onBulkDelete:ve}),(0,V.jsxs)(`div`,{className:`flex gap-4 lg:gap-6`,children:[(0,V.jsx)(_1,{isOpen:i,onClose:()=>a(!1),mediaTypes:De,selectedType:I,onSelectType:e=>{L(e),window.innerWidth<1024&&a(!1)}}),(0,V.jsx)(`div`,{className:`flex-1`,children:k.length===0?(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsx)(at,{className:`h-12 w-12 text-gray-400 mx-auto mb-4`}),(0,V.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-white mb-2`,children:e(P||I!==`all`?`media.noResults`:`media.noMedia`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:e(P||I!==`all`?`media.noResults`:`media.subtitle`)}),S&&W.hasFeature(`media`)&&!P&&I===`all`&&(0,V.jsxs)(U,{onClick:Ee,children:[(0,V.jsx)(Ne,{className:`h-4 w-4 mr-2`}),e(`media.uploadFiles`)]})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{className:M===`grid`?`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-7 gap-3 lg:gap-4`:`space-y-2`,children:ue.map(e=>(0,V.jsx)(y1,{file:e,viewMode:M,isSelected:me.has(e.id),canEdit:C,canDelete:w,getMediaUrl:Re,onItemSelect:he,onOpenViewer:Oe,onEdit:je,onDelete:Me},e.id))}),k.length>te&&(0,V.jsxs)(`div`,{className:`mt-6 flex items-center justify-between px-4 py-3 bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700`,children:[(0,V.jsxs)(`div`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:[ce+1,`-`,Math.min(le,k.length),` / `,k.length]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(U,{variant:`secondary`,size:`sm`,onClick:()=>R(e=>Math.max(1,e-1)),disabled:ee===1,children:[(0,V.jsx)(be,{className:`h-4 w-4 mr-1`}),e(`common.previous`)]}),(0,V.jsxs)(`span`,{className:`text-sm text-gray-600 dark:text-gray-300 px-3`,children:[ee,` / `,se]}),(0,V.jsxs)(U,{variant:`secondary`,size:`sm`,onClick:()=>R(e=>Math.min(se,e+1)),disabled:ee===se,children:[e(`common.next`),(0,V.jsx)(z,{className:`h-4 w-4 ml-1`})]})]})]})]})})]}),o&&n&&(0,V.jsxs)(ia,{open:o,onClose:()=>s(!1),variant:`center`,size:`xl`,height:`tall`,className:`overflow-hidden`,ariaLabel:n.metadata?.title||n.filename,children:[(0,V.jsxs)(`div`,{className:`shrink-0 flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-4 min-w-0 flex-1`,children:[(0,V.jsxs)(`span`,{className:`text-sm text-gray-500 dark:text-gray-400 flex-shrink-0`,children:[_+1,` of `,k.length]}),(0,V.jsx)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-white truncate`,children:n.metadata?.title||n.filename})]}),(0,V.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>Ae(`prev`),disabled:_===0,children:(0,V.jsx)(be,{className:`h-4 w-4`})}),(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>Ae(`next`),disabled:_===k.length-1,children:(0,V.jsx)(z,{className:`h-4 w-4`})}),(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=Re(n),e.download=n.filename,document.body.appendChild(e),e.click(),document.body.removeChild(e)},children:(0,V.jsx)(Ye,{className:`h-4 w-4`})}),(C||w)&&(0,V.jsxs)(V.Fragment,{children:[C&&(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>{je(n),s(!1)},children:(0,V.jsx)(ct,{className:`h-4 w-4`})}),C&&n.contentType.startsWith(`image/`)&&(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>Ie(n),title:`Regenerate image variants`,children:(0,V.jsx)(ke,{className:`h-4 w-4`})}),w&&(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>{Me(n),s(!1)},children:(0,V.jsx)(Be,{className:`h-4 w-4`})})]}),(0,V.jsx)(U,{variant:`ghost`,size:`sm`,onClick:()=>s(!1),children:(0,V.jsx)(tt,{className:`h-4 w-4`})})]})]}),(0,V.jsxs)(ia.Body,{scroll:!1,padded:!1,className:`flex flex-col md:flex-row`,children:[(0,V.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 min-w-0`,children:[(0,V.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden flex items-center justify-center bg-gray-50 dark:bg-gray-900 p-4`,children:n.contentType.startsWith(`image/`)?(0,V.jsx)(`img`,{src:Re(n),alt:n.metadata?.alt||n.filename,className:`max-w-full max-h-full object-contain`}):n.contentType.startsWith(`video/`)?(0,V.jsx)(`video`,{src:Re(n),controls:!0,className:`max-w-full max-h-full`}):n.contentType.startsWith(`audio/`)?(0,V.jsx)(`audio`,{src:Re(n),controls:!0,className:`w-full max-w-md`}):(0,V.jsxs)(`div`,{className:`text-center`,children:[B.createElement(o1(n.contentType),{className:`h-24 w-24 text-gray-400 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-4`,children:e(`media.preview`)}),(0,V.jsxs)(U,{onClick:()=>{let e=document.createElement(`a`);e.href=Re(n),e.download=n.filename,document.body.appendChild(e),e.click(),document.body.removeChild(e)},children:[(0,V.jsx)(Ye,{className:`h-4 w-4 mr-2`}),e(`media.download`)]})]})}),n.contentType.startsWith(`image/`)&&n.metadata?.imageVariants&&Object.keys(n.metadata.imageVariants).length>0&&(0,V.jsxs)(`div`,{className:`shrink-0 border-t border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:`Image Variants`}),C&&(0,V.jsxs)(U,{variant:`ghost`,size:`sm`,onClick:()=>Ie(n),title:`Regenerate all variants`,className:`text-xs`,children:[(0,V.jsx)(ke,{className:`h-3 w-3 mr-1`}),`Regenerate`]})]}),(0,V.jsx)(`div`,{className:`flex space-x-3 overflow-x-auto pb-2`,children:Object.entries(n.metadata.imageVariants).map(([e,t])=>(0,V.jsxs)(`div`,{className:`flex-shrink-0 group relative`,children:[(0,V.jsx)(`img`,{src:Re(n,e),alt:`${e} variant`,className:`w-20 h-20 object-cover rounded border border-gray-200 dark:border-gray-600`,loading:`lazy`}),(0,V.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-opacity rounded flex items-center justify-center opacity-0 group-hover:opacity-100`,children:(0,V.jsxs)(`div`,{className:`flex space-x-1`,children:[(0,V.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(Re(n,e))},className:`text-[10px] bg-white bg-opacity-90 text-gray-800 px-1.5 py-0.5 rounded hover:bg-opacity-100 transition-all`,title:`Copy URL`,children:`Copy`}),(0,V.jsx)(`a`,{href:Re(n,e),target:`_blank`,rel:`noopener noreferrer`,className:`text-[10px] bg-primary-600 bg-opacity-90 text-white px-1.5 py-0.5 rounded hover:bg-opacity-100 transition-all`,children:`View`})]})}),(0,V.jsxs)(`div`,{className:`mt-1 text-center`,children:[(0,V.jsx)(`div`,{className:`text-xs text-gray-600 dark:text-gray-400 capitalize truncate`,children:e}),(0,V.jsxs)(`div`,{className:`text-[10px] text-gray-500 dark:text-gray-500`,children:[t.width,` × `,t.height]})]})]},e))})]}),n.contentType.startsWith(`image/`)&&(!n.metadata?.imageVariants||Object.keys(n.metadata.imageVariants).length===0)&&(0,V.jsx)(`div`,{className:`shrink-0 border-t border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-4`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white mb-2`,children:`Image Variants`}),(0,V.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mb-3`,children:`No variants generated for this image.`}),C&&(0,V.jsxs)(U,{variant:`primary`,size:`sm`,onClick:()=>Ie(n),className:`text-xs`,children:[(0,V.jsx)(ke,{className:`h-4 w-4 mr-2`}),`Generate Variants`]})]})})]}),(0,V.jsxs)(`div`,{className:`w-full md:w-80 shrink-0 overflow-y-auto bg-white dark:bg-gray-800 border-l border-gray-200 dark:border-gray-700 p-4 md:p-6`,children:[(0,V.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-white mb-4`,children:e(`media.details`)}),(0,V.jsxs)(`dl`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400`,children:e(`media.filename`)}),(0,V.jsx)(`dd`,{className:`text-sm text-gray-900 dark:text-white`,children:n.filename})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400`,children:e(`media.filesize`)}),(0,V.jsx)(`dd`,{className:`text-sm text-gray-900 dark:text-white`,children:hi(n.size)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400`,children:e(`media.mimeType`)}),(0,V.jsx)(`dd`,{className:`text-sm text-gray-900 dark:text-white`,children:n.contentType})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400`,children:e(`media.uploadedAt`)}),(0,V.jsx)(`dd`,{className:`text-sm text-gray-900 dark:text-white`,children:new Date(n._createdAt).toLocaleString()})]}),n.metadata?.width&&n.metadata?.height&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`dt`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400`,children:e(`media.dimensions`)}),(0,V.jsxs)(`dd`,{className:`text-sm text-gray-900 dark:text-white`,children:[n.metadata.width,` × `,n.metadata.height,`px`]})]})]})]})]})]}),c&&h&&(0,V.jsx)(x1,{isOpen:c,editingFile:h,onEditingFileChange:g,onClose:()=>l(!1),onSave:Fe}),u&&h&&(0,V.jsx)(S1,{isOpen:u,editingFile:h,onClose:()=>d(!1),onConfirm:Pe}),f&&me.size>0&&(0,V.jsx)(C1,{isOpen:f,selectedCount:me.size,isDeleting:y,onClose:()=>m(!1),onConfirm:Le})]})}var T1=Fr(`useDynamicPermissions`);function E1(){let[e,t]=(0,B.useState)([]),[n,r]=(0,B.useState)(!0),[i,a]=(0,B.useState)(null);return(0,B.useEffect)(()=>{async function e(){try{r(!0),a(null);let e=await W.get(`/config/structure`);if(e.success&&e.data?.structure?.items){let n=e.data.structure.items.filter(e=>(e.type===`documentList`||e.type===`singleton`)&&e.schemaType).map(e=>({type:e.type,title:e.title,schemaType:e.schemaType}));t(n),T1.debug(`Loaded schemas for dynamic permissions`,{count:n.length,schemas:n.map(e=>e.schemaType)})}else T1.warn(`No structure data found in API response`),t([])}catch(e){let n=e instanceof Error?e.message:`Failed to load schemas`;a(n),T1.error(`Failed to fetch schemas for permissions`,e),t([])}finally{r(!1)}}e()},[]),{dynamicPermissions:(0,B.useMemo)(()=>{let t=[];return e.forEach(e=>{let{schemaType:n,title:r,type:i}=e,a=`${r} (Content)`;t.push({value:`${n}:read`,label:`View ${r}`,group:a},{value:`${n}:write`,label:`Edit ${r}`,group:a}),i===`documentList`&&t.push({value:`${n}:delete`,label:`Delete ${r}`,group:a})}),t},[e]),schemas:e,loading:n,error:i,isReady:!n&&!i}}var D1={admin:[`content:*`,`media:read`,`media:upload`,`media:edit`,`media:delete`,`users:read`,`users:write`,`users:delete`,`users:invite`,`settings:read`,`settings:write`,`studio:access`,`tokens:read`,`tokens:write`,`tokens:delete`,`webhooks:read`,`webhooks:write`,`webhooks:delete`,`webhooks:test`],editor:[`content:*`,`media:read`,`media:upload`,`media:edit`,`media:delete`,`studio:access`,`webhooks:read`,`webhooks:test`],author:[`content:read`,`content:write`,`content:publish`,`media:read`,`media:upload`,`studio:access`],writer:[`content:read`,`content:write`,`media:read`,`media:upload`,`studio:access`],viewer:[`content:read`,`media:read`,`studio:access`]};function O1(e){if(e<=0)throw Error(`Max must be positive`);let t=new Uint32Array(1);crypto.getRandomValues(t);let n=Math.floor(4294967295/e)*e,r=t[0];for(;r>=n;)crypto.getRandomValues(t),r=t[0];return r%e}function k1(e){let t=[...e];for(let e=t.length-1;e>0;e--){let n=O1(e+1);[t[e],t[n]]=[t[n],t[e]]}return t}function A1(e={}){let{length:t=16,includeUppercase:n=!0,includeLowercase:r=!0,includeNumbers:i=!0,includeSpecialChars:a=!0,customChars:o=``,excludeSimilar:s=!1}=e;if(t<1)throw Error(`Password length must be at least 1`);if(t>1e3)throw Error(`Password length too large`);let c=``,l=[];if(r){let e=s?`abcdefghijkmnopqrstuvwxyz`:`abcdefghijklmnopqrstuvwxyz`;c+=e,l.push(e[O1(e.length)])}if(n){let e=s?`ABCDEFGHJKLMNPQRSTUVWXYZ`:`ABCDEFGHIJKLMNOPQRSTUVWXYZ`;c+=e,l.push(e[O1(e.length)])}if(i){let e=s?`23456789`:`0123456789`;c+=e,l.push(e[O1(e.length)])}if(a){let e=`!@#$%^&*()_+-=[]{}|;:,.<>?`;c+=e,l.push(e[O1(26)])}if(o&&(c+=o),!c)throw Error(`At least one character type must be included`);let u=c.split(``),d=[...l];for(;d.length<t;){let e=O1(u.length);d.push(u[e])}return k1(d).join(``)}var j1=Fr(`UserManagement`),M1=[`admin`,`editor`,`writer`,`author`,`viewer`],N1=[{value:`content:*`,labelKey:`userManagement.permissions.allContent`,group:`Content`},{value:`content:read`,labelKey:`userManagement.permissions.viewAllContent`,group:`Content`},{value:`content:write`,labelKey:`userManagement.permissions.editAllContent`,group:`Content`},{value:`content:delete`,labelKey:`userManagement.permissions.deleteAllContent`,group:`Content`},{value:`content:publish`,labelKey:`userManagement.permissions.publishAllContent`,group:`Content`},{value:`media:read`,labelKey:`userManagement.permissions.viewMedia`,group:`Media`},{value:`media:upload`,labelKey:`userManagement.permissions.uploadMedia`,group:`Media`},{value:`media:edit`,labelKey:`userManagement.permissions.editMedia`,group:`Media`},{value:`media:delete`,labelKey:`userManagement.permissions.deleteMedia`,group:`Media`},{value:`users:read`,labelKey:`userManagement.permissions.viewUsers`,group:`Users`},{value:`users:write`,labelKey:`userManagement.permissions.editUsers`,group:`Users`},{value:`users:delete`,labelKey:`userManagement.permissions.deleteUsers`,group:`Users`},{value:`users:invite`,labelKey:`userManagement.permissions.inviteUsers`,group:`Users`},{value:`settings:read`,labelKey:`userManagement.permissions.viewSettings`,group:`Settings`},{value:`settings:write`,labelKey:`userManagement.permissions.editSettings`,group:`Settings`},{value:`studio:access`,labelKey:`userManagement.permissions.studioAccess`,group:`Access`},{value:`tokens:read`,labelKey:`userManagement.permissions.viewTokens`,group:`Tokens`},{value:`tokens:write`,labelKey:`userManagement.permissions.createTokens`,group:`Tokens`},{value:`tokens:delete`,labelKey:`userManagement.permissions.deleteTokens`,group:`Tokens`},{value:`webhooks:read`,labelKey:`userManagement.permissions.viewWebhooks`,group:`Webhooks`},{value:`webhooks:write`,labelKey:`userManagement.permissions.createEditWebhooks`,group:`Webhooks`},{value:`webhooks:delete`,labelKey:`userManagement.permissions.deleteWebhooks`,group:`Webhooks`},{value:`webhooks:test`,labelKey:`userManagement.permissions.testWebhooks`,group:`Webhooks`}];function P1({user:e,isOpen:t,onClose:n,onSave:r}){let{t:i}=H(`studio`),[a,o]=(0,B.useState)({username:``,email:``,fullName:``,role:`viewer`,permissions:[],password:``,active:!0}),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(null),{dynamicPermissions:p,loading:m,error:h}=E1(),[g,_]=(0,B.useState)(!1),[v,y]=(0,B.useState)(``),b=(e,t)=>{let n=[...D1[e]||[]].sort(),r=[...t].sort();return n.join(`,`)!==r.join(`,`)},x=e=>{let t=D1[e]||[];o(n=>({...n,role:e,permissions:t})),_(!1)},S=e=>{o(t=>{let n=t.permissions.includes(e)?t.permissions.filter(t=>t!==e):[...t.permissions,e],r=b(t.role,n);return _(r),{...t,permissions:n}})},C=()=>{let e=D1[a.role]||[];o(t=>({...t,permissions:e})),_(!1)},w=()=>{if(!v.trim())return;if(!/^[a-z][a-z0-9_-]*:(read|write|delete|\*)$/i.test(v.trim())){alert(i(`userManagement.modal.permissionValidationError`));return}let e=v.trim();a.permissions.includes(e)||(o(t=>({...t,permissions:[...t.permissions,e]})),_(!0)),y(``)},T=e=>{o(t=>({...t,permissions:t.permissions.filter(t=>t!==e)}))},E=()=>{let e=A1({length:12,includeUppercase:!0,includeLowercase:!0,includeNumbers:!0,includeSpecialChars:!0,excludeSimilar:!0});o(t=>({...t,password:e}))};(0,B.useEffect)(()=>{if(f(null),e){let t=e.permissions||[],n=b(e.role,t);o({username:e.username,email:e.email,fullName:`${e.firstName} ${e.lastName}`,role:e.role,permissions:t,password:``,active:e.isActive}),_(n)}else{let e=D1.viewer;o({username:``,email:``,fullName:``,role:`viewer`,permissions:e,password:``,active:!0}),_(!1)}},[e,t]);let D=async e=>{e.preventDefault(),c(!0),f(null);try{await r(a),n()}catch(e){j1.error(`Failed to save user`,e);let t=e?.message||`Failed to save user. Please try again.`;f(t)}finally{c(!1)}},O=N1.map(e=>({value:e.value,label:i(e.labelKey),group:e.group})),k=O.filter(e=>e.group===`Content`),A=O.filter(e=>e.group!==`Content`&&e.value!==`studio:access`),j=[...k,...p,...A],M=j.reduce((e,t)=>(e[t.group]||(e[t.group]=[]),e[t.group].push(t),e),{});return t?(0,V.jsx)(b1,{isOpen:t,onClose:n,title:i(e?`userManagement.modal.editTitle`:`userManagement.modal.createTitle`),size:`xl`,children:(0,V.jsxs)(`form`,{onSubmit:D,className:`space-y-4`,children:[d&&(0,V.jsx)(`div`,{className:`p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-md`,children:(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(de,{className:`h-5 w-5 text-red-600 dark:text-red-400 mr-2 flex-shrink-0`}),(0,V.jsx)(`span`,{className:`text-sm text-red-800 dark:text-red-200`,children:d})]})}),(0,V.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,V.jsxs)(`div`,{className:`space-y-3`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white border-b border-gray-200 dark:border-gray-700 pb-1`,children:i(`userManagement.modal.basicInfo`)}),(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:[i(`userManagement.modal.username`),` *`]}),(0,V.jsx)(h1,{type:`text`,value:a.username,onChange:e=>o(t=>({...t,username:e.target.value})),required:!0,disabled:s})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:[i(`userManagement.modal.email`),` *`]}),(0,V.jsx)(h1,{type:`email`,value:a.email,onChange:e=>o(t=>({...t,email:e.target.value})),required:!0,disabled:s})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:[i(`userManagement.modal.fullName`),` *`]}),(0,V.jsx)(h1,{type:`text`,value:a.fullName,onChange:e=>o(t=>({...t,fullName:e.target.value})),required:!0,disabled:s})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e?i(`userManagement.modal.newPassword`):`${i(`userManagement.modal.password`)} *`}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsxs)(`div`,{className:`relative flex-1`,children:[(0,V.jsx)(h1,{type:l?`text`:`password`,value:a.password,onChange:e=>o(t=>({...t,password:e.target.value})),required:!e,disabled:s,className:`pr-10`}),(0,V.jsx)(`button`,{type:`button`,className:`absolute inset-y-0 right-0 flex items-center pr-3`,onClick:()=>u(!l),children:l?(0,V.jsx)(le,{className:`h-4 w-4 text-gray-400`}):(0,V.jsx)(ce,{className:`h-4 w-4 text-gray-400`})})]}),(0,V.jsx)(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:E,disabled:s,className:`px-3`,children:i(`userManagement.modal.generatePassword`)})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:i(`userManagement.modal.role`)}),(0,V.jsx)(`select`,{value:a.role,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm`,disabled:s,children:M1.map(e=>(0,V.jsxs)(`option`,{value:e,children:[i(`userManagement.roles.${e}`),` - `,i(`userManagement.roles.${e}Desc`)]},e))})]})]}),(0,V.jsxs)(`div`,{className:`space-y-3`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white border-b border-gray-200 dark:border-gray-700 pb-1`,children:i(`userManagement.modal.accessPermissions`)}),g&&(0,V.jsx)(`button`,{type:`button`,onClick:C,className:`text-xs text-primary-600 hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300`,children:i(`userManagement.modal.reset`)})]}),(0,V.jsx)(`div`,{className:`p-3 bg-gray-50 dark:bg-gray-900 rounded-md`,children:(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,V.jsxs)(`label`,{className:`flex items-center`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:a.active,onChange:e=>o(t=>({...t,active:e.target.checked})),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 rounded`}),(0,V.jsx)(`span`,{className:`ml-2 text-sm font-medium text-gray-700 dark:text-gray-300`,children:i(`userManagement.modal.activeAccount`)})]}),(0,V.jsxs)(`label`,{className:`flex items-center`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:a.permissions.includes(`studio:access`),onChange:()=>S(`studio:access`),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 rounded`}),(0,V.jsx)(`span`,{className:`ml-2 text-sm font-medium text-gray-700 dark:text-gray-300`,children:i(`userManagement.modal.studioAccess`)})]})]})}),g&&(0,V.jsx)(`div`,{className:`p-2 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-md`,children:(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(de,{className:`h-4 w-4 text-amber-600 dark:text-amber-400 mr-2`}),(0,V.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:i(`userManagement.modal.customPermissions`)})]})}),(0,V.jsxs)(`div`,{className:`border border-gray-300 dark:border-gray-600 rounded-md p-3 max-h-80 overflow-y-auto`,children:[m&&(0,V.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),(0,V.jsx)(`span`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:i(`userManagement.modal.loadingSchemaPermissions`)})]}),h&&(0,V.jsx)(`div`,{className:`p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-md mb-3`,children:(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(de,{className:`h-4 w-4 text-amber-600 dark:text-amber-400 mr-2`}),(0,V.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:i(`userManagement.modal.failedLoadSchemaPermissions`,{error:h})})]})}),!m&&Object.entries(M).map(([e,t])=>{let n=a.permissions.includes(`content:*`),r=e===`Content`,o=e.endsWith(`(Content)`);return(0,V.jsxs)(`div`,{className:`mb-3 last:mb-0`,children:[(0,V.jsxs)(`h4`,{className:`text-xs font-medium text-gray-900 dark:text-white mb-1 border-b border-gray-200 dark:border-gray-700 pb-1`,children:[e,(r||o)&&n&&(0,V.jsx)(`span`,{className:`ml-2 text-xs text-gray-500 dark:text-gray-400`,children:i(r?`userManagement.modal.allContentEnabled`:`userManagement.modal.coveredByAllContent`)})]}),(0,V.jsx)(`div`,{className:`grid grid-cols-1 gap-1`,children:t.map(e=>{let t=(r||o)&&n&&e.value!==`content:*`;return(0,V.jsxs)(`label`,{className:`flex items-center ${t?`opacity-50`:``}`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:a.permissions.includes(e.value),onChange:()=>S(e.value),disabled:t,className:`h-3 w-3 text-primary-600 focus:ring-primary-500 border-gray-300 rounded disabled:opacity-50 disabled:cursor-not-allowed`}),(0,V.jsx)(`span`,{className:`ml-2 text-xs text-gray-600 dark:text-gray-400`,children:e.label})]},e.value)})})]},e)})]}),!a.permissions.includes(`content:*`)&&(0,V.jsxs)(`div`,{className:`mt-4`,children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:i(`userManagement.modal.customSchemaPermissions`)}),(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(`input`,{type:`text`,value:v,onChange:e=>y(e.target.value),placeholder:i(`userManagement.modal.customPermissionPlaceholder`),className:`flex-1 rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-white text-sm`,onKeyPress:e=>e.key===`Enter`&&w()}),(0,V.jsx)(U,{type:`button`,size:`sm`,onClick:w,disabled:!v.trim(),children:i(`userManagement.modal.addPermission`)})]}),a.permissions.filter(e=>!j.some(t=>t.value===e)).length>0&&(0,V.jsxs)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-md p-2 bg-gray-50 dark:bg-gray-800`,children:[(0,V.jsx)(`div`,{className:`text-xs text-gray-600 dark:text-gray-400 mb-1`,children:i(`userManagement.modal.customPermissionsLabel`)}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:a.permissions.filter(e=>!j.some(t=>t.value===e)).map(e=>(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200 text-xs rounded`,children:[e,(0,V.jsx)(`button`,{type:`button`,onClick:()=>T(e),className:`hover:text-blue-600 dark:hover:text-blue-300`,children:`×`})]},e))})]}),(0,V.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`userManagement.modal.permissionFormatHelp`)})]})]})]})]}),(0,V.jsxs)(`div`,{className:`flex justify-end space-x-3 pt-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(U,{variant:`ghost`,onClick:n,disabled:s,children:i(`userManagement.modal.cancel`)}),(0,V.jsx)(U,{type:`submit`,onClick:D,disabled:s,children:s?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),i(e?`userManagement.modal.updating`:`userManagement.modal.creating`)]}):i(e?`userManagement.modal.updateUser`:`userManagement.createUser`)})]})]})}):null}function F1(){let{t:e}=H(`studio`),{user:t}=ri(),{hasPermission:n}=ci(),[r,i]=p(),[a,o]=(0,B.useState)([]),[s,c]=(0,B.useState)(!0),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1),[m,h]=(0,B.useState)(``),g=n(ui.WRITE)||n(ui.INVITE),_=n(ui.WRITE),v=n(ui.DELETE),y=async()=>{try{c(!0);let e=await W.get(`/users`);e.success&&e.data&&e.data.users&&o(e.data.users)}catch(e){j1.error(`Failed to load users`,e)}finally{c(!1)}};(0,B.useEffect)(()=>{y(),r.get(`action`)===`add`&&(b(),i(e=>(e.delete(`action`),e)))},[r,i]);let b=()=>{u(null),f(!0)},x=e=>{u(e),f(!0)},S=async e=>{try{if(l){let n=await W.put(`/users/${l.id}`,e);n.success&&n.data&&(await y(),t?.id===l.id&&(window.dispatchEvent(new CustomEvent(`trokky:user:updated`,{detail:{user:n.data}})),j1.debug(`Emitted user update event for current user`)))}else(await W.post(`/users`,e)).success&&await y()}catch(e){throw j1.error(`Failed to save user`,e),e}},C=async t=>{if(confirm(e(`userManagement.deleteConfirm`,{username:t.username})))try{(await W.delete(`/users/${t.id}`)).success&&await y()}catch(e){j1.error(`Failed to delete user`,e)}},w=async t=>{if(confirm(e(`userManagement.resetMfaConfirm`,{username:t.username})))try{(await W.post(`/admin/users/${t.id}/mfa/reset`,{})).success&&(await y(),j1.info(`MFA reset for user`,{userId:t.id,username:t.username}))}catch(t){j1.error(`Failed to reset MFA`,t),alert(e(`userManagement.failedResetMfa`))}},T=e=>e.mfa?.enabled&&e.mfa?.methods?.some(e=>e.enabled&&e.verified),E=Array.isArray(a)?a.filter(e=>e.username.toLowerCase().includes(m.toLowerCase())||e.email.toLowerCase().includes(m.toLowerCase())||(e.firstName&&e.lastName?`${e.firstName} ${e.lastName}`:``).toLowerCase().includes(m.toLowerCase())):[],D=e=>{switch(e){case`admin`:return`bg-red-100 text-red-800 dark:bg-red-900/20 dark:text-red-400`;case`editor`:return`bg-blue-100 text-blue-800 dark:bg-blue-900/20 dark:text-blue-400`;case`writer`:return`bg-purple-100 text-purple-800 dark:bg-purple-900/20 dark:text-purple-400`;case`author`:return`bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400`;case`viewer`:return`bg-gray-100 text-gray-800 dark:bg-gray-900/20 dark:text-gray-400`;default:return`bg-gray-100 text-gray-800 dark:bg-gray-900/20 dark:text-gray-400`}},O=e=>{let t=D1[e.role]||[],n=e.permissions||[],r=[...t].sort(),i=[...n].sort();return r.join(`,`)!==i.join(`,`)};return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`userManagement.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`userManagement.subtitle`)})]}),g&&(0,V.jsxs)(U,{onClick:b,children:[(0,V.jsx)(Ne,{className:`h-4 w-4 mr-2`}),e(`userManagement.addUser`)]})]}),(0,V.jsx)(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:(0,V.jsx)(`div`,{className:`flex-1`,children:(0,V.jsx)(h1,{placeholder:e(`userManagement.searchPlaceholder`),value:m,onChange:e=>h(e.target.value)})})}),s?(0,V.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,V.jsx)(Ao,{})}):(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden`,children:(0,V.jsx)(`div`,{className:`overflow-x-auto`,children:(0,V.jsxs)(`table`,{className:`min-w-full divide-y divide-gray-200 dark:divide-gray-700`,children:[(0,V.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-900`,children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`userManagement.tableHeaders.user`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`userManagement.tableHeaders.role`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`userManagement.tableHeaders.status`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`userManagement.tableHeaders.lastLogin`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`userManagement.tableHeaders.actions`)})]})}),(0,V.jsx)(`tbody`,{className:`bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700`,children:E.map(n=>(0,V.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-700`,children:[(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap`,children:(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:n.firstName&&n.lastName?`${n.firstName} ${n.lastName}`:n.username}),(0,V.jsxs)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:[n.username,` • `,n.email]})]})}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap`,children:(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${D(n.role)}`,children:n.role}),O(n)&&(0,V.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 text-xs font-medium bg-amber-100 text-amber-800 dark:bg-amber-900/20 dark:text-amber-400 rounded-full`,title:e(`userManagement.customPermissionsTooltip`),children:[(0,V.jsx)(de,{className:`h-3 w-3 mr-1`}),e(`userManagement.custom`)]})]})}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap`,children:(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${n.isActive?`bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400`:`bg-red-100 text-red-800 dark:bg-red-900/20 dark:text-red-400`}`,children:n.isActive?e(`userManagement.status.active`):e(`userManagement.status.inactive`)}),T(n)&&(0,V.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 text-xs font-medium bg-purple-100 text-purple-800 dark:bg-purple-900/20 dark:text-purple-400 rounded-full`,title:e(`userManagement.mfaEnabled`),children:[(0,V.jsx)(He,{className:`h-3 w-3 mr-1`}),e(`userManagement.mfa`)]})]})}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400`,children:n.lastLoginAt?new Date(n.lastLoginAt).toLocaleDateString():e(`userManagement.never`)}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap text-right text-sm font-medium`,children:(0,V.jsxs)(`div`,{className:`flex justify-end space-x-2`,children:[_&&(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>x(n),title:e(`userManagement.editUserTitle`),children:(0,V.jsx)(ct,{className:`h-4 w-4`})}),_&&T(n)&&t?.id!==n.id&&(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>w(n),className:`text-amber-600 hover:text-amber-700 dark:text-amber-400 dark:hover:text-amber-300`,title:e(`userManagement.resetMfaTitle`),children:(0,V.jsx)(ke,{className:`h-4 w-4`})}),v&&t?.id!==n.id&&(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>C(n),className:`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,title:e(`userManagement.deleteUserTitle`),children:(0,V.jsx)(Be,{className:`h-4 w-4`})})]})})]},n.id))})]})})}),(0,V.jsx)(P1,{user:l,isOpen:d,onClose:()=>f(!1),onSave:S})]})}var I1=Fr(`AppTokenManagement`),L1=[{value:`content:read`,labelKey:`appTokens.permissions.viewContent`,group:`Content`},{value:`content:write`,labelKey:`appTokens.permissions.editContent`,group:`Content`},{value:`content:delete`,labelKey:`appTokens.permissions.deleteContent`,group:`Content`},{value:`content:publish`,labelKey:`appTokens.permissions.publishContent`,group:`Content`},{value:`media:read`,labelKey:`appTokens.permissions.viewMedia`,group:`Media`},{value:`media:upload`,labelKey:`appTokens.permissions.uploadMedia`,group:`Media`},{value:`media:edit`,labelKey:`appTokens.permissions.editMedia`,group:`Media`},{value:`media:delete`,labelKey:`appTokens.permissions.deleteMedia`,group:`Media`}];function R1({isOpen:e,onClose:t,onSave:n}){let{t:r}=H(`studio`),[i,a]=(0,B.useState)({name:``,description:``,permissions:[`content:read`,`media:read`],expiresAt:void 0}),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(`90days`),[u,d]=(0,B.useState)(``);(0,B.useEffect)(()=>{e&&(a({name:``,description:``,permissions:[`content:read`,`media:read`],expiresAt:void 0}),l(`90days`),d(``))},[e]);let f=async e=>{e.preventDefault(),s(!0);try{let e;if(c===`never`)e=void 0;else if(c===`custom`)e=new Date(u);else{let t={"30days":30,"90days":90,"1year":365}[c];e=new Date(Date.now()+t*24*60*60*1e3)}await n({...i,expiresAt:e}),t()}catch(e){I1.error(`Failed to create token`,e)}finally{s(!1)}},p=e=>{a(t=>({...t,permissions:t.permissions.includes(e)?t.permissions.filter(t=>t!==e):[...t.permissions,e]}))},m=L1.map(e=>({value:e.value,label:r(e.labelKey),group:e.group})).reduce((e,t)=>(e[t.group]||(e[t.group]=[]),e[t.group].push(t),e),{});return(0,V.jsx)(b1,{isOpen:e,onClose:t,title:r(`appTokens.modal.title`),size:`lg`,children:(0,V.jsxs)(`form`,{onSubmit:f,className:`space-y-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[r(`appTokens.modal.tokenName`),` *`]}),(0,V.jsx)(h1,{type:`text`,value:i.name,onChange:e=>a(t=>({...t,name:e.target.value})),placeholder:r(`appTokens.modal.tokenNamePlaceholder`),required:!0,disabled:o})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:r(`appTokens.modal.description`)}),(0,V.jsx)(`textarea`,{value:i.description,onChange:e=>a(t=>({...t,description:e.target.value})),placeholder:r(`appTokens.modal.descriptionPlaceholder`),rows:3,className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white resize-none`,disabled:o})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:r(`appTokens.modal.expiration`)}),(0,V.jsxs)(`select`,{value:c,onChange:e=>l(e.target.value),className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,disabled:o,children:[(0,V.jsx)(`option`,{value:`30days`,children:r(`appTokens.modal.expiration30days`)}),(0,V.jsx)(`option`,{value:`90days`,children:r(`appTokens.modal.expiration90days`)}),(0,V.jsx)(`option`,{value:`1year`,children:r(`appTokens.modal.expiration1year`)}),(0,V.jsx)(`option`,{value:`never`,children:r(`appTokens.modal.expirationNever`)}),(0,V.jsx)(`option`,{value:`custom`,children:r(`appTokens.modal.expirationCustom`)})]}),c===`custom`&&(0,V.jsx)(h1,{type:`date`,value:u,onChange:e=>d(e.target.value),className:`mt-2`,min:new Date().toISOString().split(`T`)[0],required:!0,disabled:o})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:r(`appTokens.modal.permissions`)}),(0,V.jsx)(`div`,{className:`border border-gray-300 dark:border-gray-600 rounded-md p-3 space-y-3 max-h-48 overflow-y-auto`,children:Object.entries(m).map(([e,t])=>(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e}),(0,V.jsx)(`div`,{className:`space-y-1 ml-2`,children:t.map(e=>(0,V.jsxs)(`label`,{className:`flex items-center`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:i.permissions.includes(e.value),onChange:()=>p(e.value),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 rounded`}),(0,V.jsx)(`span`,{className:`ml-2 text-sm text-gray-600 dark:text-gray-400`,children:e.label})]},e.value))})]},e))})]}),(0,V.jsxs)(`div`,{className:`flex justify-end space-x-3 pt-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(U,{variant:`ghost`,onClick:t,disabled:o,children:r(`appTokens.modal.cancel`)}),(0,V.jsx)(U,{type:`submit`,onClick:f,disabled:o||!i.name,children:o?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),r(`appTokens.modal.creating`)]}):r(`appTokens.modal.createToken`)})]})]})})}function z1({token:e,isOpen:t,onClose:n}){let{t:r}=H(`studio`),[i,a]=(0,B.useState)(!1);return(0,V.jsx)(b1,{isOpen:t&&!!e,onClose:n,title:r(`appTokens.tokenCreated.title`),size:`md`,children:(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-md p-4 mb-4`,children:(0,V.jsxs)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:[(0,V.jsx)(`strong`,{children:r(`common.note`)}),` `,r(`appTokens.tokenCreated.warning`)]})}),(0,V.jsxs)(`div`,{className:`space-y-3`,children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`appTokens.tokenCreated.yourToken`)}),(0,V.jsxs)(`div`,{className:`flex`,children:[(0,V.jsx)(`input`,{type:`text`,value:e||``,readOnly:!0,className:`flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-l-md bg-gray-50 dark:bg-gray-700 text-gray-900 dark:text-white font-mono text-sm`}),(0,V.jsx)(U,{onClick:async()=>{e&&(await navigator.clipboard.writeText(e),a(!0),setTimeout(()=>a(!1),2e3))},className:`rounded-l-none`,variant:i?`secondary`:`primary`,children:i?r(`appTokens.tokenCreated.copied`):(0,V.jsx)(lt,{className:`h-4 w-4`})})]})]}),(0,V.jsx)(`div`,{className:`flex justify-end pt-4 border-t border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(U,{onClick:n,children:r(`appTokens.tokenCreated.close`)})})]})})}function B1(){let{t:e}=H(`studio`),{hasPermission:t}=ci(),[n,r]=(0,B.useState)([]),[i,a]=(0,B.useState)(!0),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(``),[f,p]=(0,B.useState)(new Set),m=t(fi.WRITE),h=t(fi.DELETE),g=async()=>{try{a(!0);let e=await W.get(`/tokens`);e.success&&e.data&&r(e.data)}catch(e){I1.error(`Failed to load tokens`,e)}finally{a(!1)}};(0,B.useEffect)(()=>{g()},[]);let _=async e=>{try{let t=await W.post(`/tokens`,e);if(t.success&&t.data)return l(t.data.token),await g(),{token:t.data.token};throw Error(`Failed to create token`)}catch(e){throw I1.error(`Failed to create token`,e),e}},v=async t=>{if(confirm(e(`appTokens.deleteConfirm`,{name:t.name})))try{(await W.delete(`/tokens/${t.id}`)).success&&await g()}catch(e){I1.error(`Failed to delete token`,e)}},y=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},b=e=>f.has(e.id)?`••••••••`:`••••••••••••••••••••••••••••••••`,x=n.filter(e=>e.name.toLowerCase().includes(u.toLowerCase())||e.description?.toLowerCase().includes(u.toLowerCase())),S=e=>e.isActive?e.expiresAt&&new Date(e.expiresAt)<new Date?`bg-red-100 text-red-800 dark:bg-red-900/20 dark:text-red-400`:`bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400`:`bg-gray-100 text-gray-800 dark:bg-gray-900/20 dark:text-gray-400`,C=t=>t.isActive?t.expiresAt&&new Date(t.expiresAt)<new Date?e(`appTokens.status.expired`):e(`appTokens.status.active`):e(`appTokens.status.inactive`);return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`appTokens.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`appTokens.subtitle`)})]}),m&&(0,V.jsxs)(U,{onClick:()=>s(!0),children:[(0,V.jsx)(Ne,{className:`h-4 w-4 mr-2`}),e(`appTokens.createToken`)]})]}),(0,V.jsx)(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:(0,V.jsx)(`div`,{className:`flex-1`,children:(0,V.jsx)(h1,{placeholder:e(`appTokens.searchPlaceholder`),value:u,onChange:e=>d(e.target.value)})})}),i?(0,V.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,V.jsx)(Ao,{})}):x.length===0?(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsx)(te,{className:`h-12 w-12 text-gray-400 mx-auto mb-4`}),(0,V.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-white mb-2`,children:e(`appTokens.noTokensTitle`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:e(`appTokens.noTokensDesc`)}),m&&(0,V.jsxs)(U,{onClick:()=>s(!0),children:[(0,V.jsx)(Ne,{className:`h-4 w-4 mr-2`}),e(`appTokens.createToken`)]})]}):(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden`,children:(0,V.jsx)(`div`,{className:`overflow-x-auto`,children:(0,V.jsxs)(`table`,{className:`min-w-full divide-y divide-gray-200 dark:divide-gray-700`,children:[(0,V.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-900`,children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`appTokens.tableHeaders.token`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`appTokens.tableHeaders.status`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`appTokens.tableHeaders.lastUsed`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`appTokens.tableHeaders.expires`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`appTokens.tableHeaders.actions`)})]})}),(0,V.jsx)(`tbody`,{className:`bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700`,children:x.map(t=>(0,V.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-700`,children:[(0,V.jsx)(`td`,{className:`px-6 py-4`,children:(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:t.name}),t.description&&(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t.description}),(0,V.jsxs)(`div`,{className:`text-xs text-gray-400 font-mono mt-1 flex items-center`,children:[(0,V.jsx)(`span`,{children:b(t)}),(0,V.jsx)(`button`,{onClick:()=>y(t.id),className:`ml-2 hover:text-gray-600 dark:hover:text-gray-300`,children:f.has(t.id)?(0,V.jsx)(le,{className:`h-3 w-3`}):(0,V.jsx)(ce,{className:`h-3 w-3`})})]})]})}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap`,children:(0,V.jsx)(`span`,{className:`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${S(t)}`,children:C(t)})}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400`,children:t.lastUsedAt?new Date(t.lastUsedAt).toLocaleDateString():e(`appTokens.never`)}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400`,children:t.expiresAt?(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(re,{className:`h-4 w-4 mr-1`}),new Date(t.expiresAt).toLocaleDateString()]}):e(`appTokens.never`)}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap text-right text-sm font-medium`,children:h&&(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>v(t),className:`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:(0,V.jsx)(Be,{className:`h-4 w-4`})})})]},t.id))})]})})}),(0,V.jsx)(R1,{isOpen:o,onClose:()=>s(!1),onSave:_}),(0,V.jsx)(z1,{token:c,isOpen:!!c,onClose:()=>l(null)})]})}var V1=Fr(`WebhookManagement`),H1=[{value:`document.*`,labelKey:`webhooks.events.allDocuments`,group:`Documents`},{value:`document.created`,labelKey:`webhooks.events.documentCreated`,group:`Documents`},{value:`document.updated`,labelKey:`webhooks.events.documentUpdated`,group:`Documents`},{value:`document.deleted`,labelKey:`webhooks.events.documentDeleted`,group:`Documents`},{value:`document.published`,labelKey:`webhooks.events.documentPublished`,group:`Documents`},{value:`document.unpublished`,labelKey:`webhooks.events.documentUnpublished`,group:`Documents`},{value:`media.*`,labelKey:`webhooks.events.allMedia`,group:`Media`},{value:`media.uploaded`,labelKey:`webhooks.events.mediaUploaded`,group:`Media`},{value:`media.updated`,labelKey:`webhooks.events.mediaUpdated`,group:`Media`},{value:`media.deleted`,labelKey:`webhooks.events.mediaDeleted`,group:`Media`},{value:`user.*`,labelKey:`webhooks.events.allUsers`,group:`Users`},{value:`user.created`,labelKey:`webhooks.events.userCreated`,group:`Users`},{value:`user.updated`,labelKey:`webhooks.events.userUpdated`,group:`Users`},{value:`user.login`,labelKey:`webhooks.events.userLogin`,group:`Users`},{value:`system.*`,labelKey:`webhooks.events.allSystem`,group:`System`},{value:`system.startup`,labelKey:`webhooks.events.systemStartup`,group:`System`},{value:`system.error`,labelKey:`webhooks.events.systemError`,group:`System`}];function U1({isOpen:e,onClose:t,onSave:n,webhook:r}){let{t:i}=H(`studio`),[a,o]=(0,B.useState)({name:``,url:``,events:[`document.created`,`document.updated`],secret:``,active:!0,headers:{},retryPolicy:{maxRetries:3,backoffType:`exponential`,baseDelay:1e3,maxDelay:3e4}}),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(``);(0,B.useEffect)(()=>{e&&(o(r?{name:r.name,url:r.url,events:r.events,secret:r.secret||``,active:r.active,headers:r.headers||{},retryPolicy:r.retryPolicy||{maxRetries:3,backoffType:`exponential`,baseDelay:1e3,maxDelay:3e4}}:{name:``,url:``,events:[`document.created`,`document.updated`],secret:``,active:!0,headers:{},retryPolicy:{maxRetries:3,backoffType:`exponential`,baseDelay:1e3,maxDelay:3e4}}),u(``),f(``))},[e,r]);let p=async e=>{e.preventDefault(),c(!0);try{await n(a),t()}catch(e){V1.error(`Failed to save webhook`,e)}finally{c(!1)}},m=e=>{o(t=>({...t,events:t.events.includes(e)?t.events.filter(t=>t!==e):[...t.events,e]}))},h=()=>{l.trim()&&d.trim()&&(o(e=>({...e,headers:{...e.headers,[l.trim()]:d.trim()}})),u(``),f(``))},g=e=>{o(t=>({...t,headers:Object.fromEntries(Object.entries(t.headers).filter(([t])=>t!==e))}))},_=()=>{let e=`wh_${Math.random().toString(36).substr(2,32)}`;o(t=>({...t,secret:e}))},v=H1.map(e=>({value:e.value,label:i(e.labelKey),group:e.group})).reduce((e,t)=>(e[t.group]||(e[t.group]=[]),e[t.group].push(t),e),{});return(0,V.jsx)(b1,{isOpen:e,onClose:t,title:i(r?`webhooks.modal.editTitle`:`webhooks.modal.createTitle`),size:`lg`,children:(0,V.jsxs)(`form`,{onSubmit:p,className:`space-y-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[i(`webhooks.modal.name`),` *`]}),(0,V.jsx)(h1,{type:`text`,value:a.name,onChange:e=>o(t=>({...t,name:e.target.value})),placeholder:i(`webhooks.modal.namePlaceholder`),required:!0,disabled:s})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:[i(`webhooks.modal.url`),` *`]}),(0,V.jsx)(h1,{type:`url`,value:a.url,onChange:e=>o(t=>({...t,url:e.target.value})),placeholder:i(`webhooks.modal.urlPlaceholder`),required:!0,disabled:s})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:i(`webhooks.modal.events`)}),(0,V.jsx)(`div`,{className:`border border-gray-300 dark:border-gray-600 rounded-md p-3 space-y-3 max-h-48 overflow-y-auto`,children:Object.entries(v).map(([e,t])=>(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e}),(0,V.jsx)(`div`,{className:`space-y-1 ml-2`,children:t.map(e=>(0,V.jsxs)(`label`,{className:`flex items-center`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:a.events.includes(e.value),onChange:()=>m(e.value),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 rounded`}),(0,V.jsx)(`span`,{className:`ml-2 text-sm text-gray-600 dark:text-gray-400`,children:e.label})]},e.value))})]},e))})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:i(`webhooks.modal.secret`)}),(0,V.jsxs)(`div`,{className:`flex`,children:[(0,V.jsx)(h1,{type:`text`,value:a.secret,onChange:e=>o(t=>({...t,secret:e.target.value})),placeholder:i(`webhooks.modal.secretPlaceholder`),disabled:s,className:`flex-1`}),(0,V.jsx)(U,{type:`button`,onClick:_,variant:`secondary`,className:`ml-2 whitespace-nowrap`,disabled:s,children:i(`common.generate`)})]}),(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:i(`webhooks.modal.secretDescription`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:i(`webhooks.modal.headers`)}),Object.entries(a.headers).length>0&&(0,V.jsx)(`div`,{className:`mb-3 space-y-1`,children:Object.entries(a.headers).map(([e,t])=>(0,V.jsxs)(`div`,{className:`flex items-center justify-between bg-gray-50 dark:bg-gray-700 p-2 rounded`,children:[(0,V.jsxs)(`span`,{className:`text-sm font-mono`,children:[e,`: `,t]}),(0,V.jsx)(U,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>g(e),className:`text-red-500 hover:text-red-700`,children:(0,V.jsx)(We,{className:`h-4 w-4`})})]},e))}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(h1,{placeholder:i(`webhooks.modal.headerNamePlaceholder`),value:l,onChange:e=>u(e.target.value),disabled:s,className:`flex-1`}),(0,V.jsx)(h1,{placeholder:i(`webhooks.modal.headerValuePlaceholder`),value:d,onChange:e=>f(e.target.value),disabled:s,className:`flex-1`}),(0,V.jsx)(U,{type:`button`,onClick:h,variant:`secondary`,disabled:s||!l.trim()||!d.trim(),children:i(`common.add`)})]})]}),(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:i(`webhooks.modal.maxRetries`)}),(0,V.jsx)(h1,{type:`number`,min:0,max:10,value:a.retryPolicy.maxRetries,onChange:e=>o(t=>({...t,retryPolicy:{...t.retryPolicy,maxRetries:parseInt(e.target.value)||0}})),disabled:s})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:i(`webhooks.modal.backoffStrategy`)}),(0,V.jsxs)(`select`,{value:a.retryPolicy.backoffType,onChange:e=>o(t=>({...t,retryPolicy:{...t.retryPolicy,backoffType:e.target.value}})),className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,disabled:s,children:[(0,V.jsx)(`option`,{value:`linear`,children:i(`webhooks.modal.linear`)}),(0,V.jsx)(`option`,{value:`exponential`,children:i(`webhooks.modal.exponential`)})]})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(`input`,{type:`checkbox`,id:`webhook-active`,checked:a.active,onChange:e=>o(t=>({...t,active:e.target.checked})),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded`,disabled:s}),(0,V.jsx)(`label`,{htmlFor:`webhook-active`,className:`ml-2 text-sm text-gray-700 dark:text-gray-300`,children:i(`webhooks.modal.active`)})]}),(0,V.jsxs)(`div`,{className:`flex justify-end space-x-3 pt-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(U,{variant:`ghost`,onClick:t,disabled:s,children:i(`common.cancel`)}),(0,V.jsx)(U,{type:`submit`,disabled:s||!a.name||!a.url||a.events.length===0,children:s?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),i(r?`webhooks.modal.updating`:`webhooks.modal.creating`)]}):i(r?`webhooks.modal.update`:`webhooks.modal.create`)})]})]})})}function W1({webhook:e,isOpen:t,onClose:n}){let{t:r}=H(`studio`),[i,a]=(0,B.useState)([]),[o,s]=(0,B.useState)(!1);(0,B.useEffect)(()=>{t&&e&&c()},[t,e]);let c=async()=>{if(e)try{s(!0);let t=await W.get(`/webhooks/${e.id}/deliveries`);t.success&&t.data&&a(t.data.deliveries||[])}catch(e){V1.error(`Failed to load deliveries`,e)}finally{s(!1)}};return(0,V.jsx)(b1,{isOpen:t&&!!e,onClose:n,title:r(`webhooks.deliveryModal.title`,{name:e?.name}),size:`xl`,children:(0,V.jsx)(`div`,{className:`space-y-4`,children:o?(0,V.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,V.jsx)(Ao,{})}):i.length===0?(0,V.jsxs)(`div`,{className:`text-center py-8`,children:[(0,V.jsx)(re,{className:`h-12 w-12 text-gray-400 mx-auto mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:r(`webhooks.deliveryModal.noDeliveries`)})]}):(0,V.jsx)(`div`,{className:`overflow-x-auto`,children:(0,V.jsxs)(`table`,{className:`min-w-full divide-y divide-gray-200 dark:divide-gray-700`,children:[(0,V.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-900`,children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:r(`webhooks.deliveryModal.status`)}),(0,V.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:r(`webhooks.deliveryModal.response`)}),(0,V.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:r(`webhooks.deliveryModal.timestamp`)}),(0,V.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:r(`webhooks.deliveryModal.attempt`)})]})}),(0,V.jsx)(`tbody`,{className:`bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700`,children:i.map(e=>(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`td`,{className:`px-4 py-4 whitespace-nowrap`,children:(0,V.jsxs)(`span`,{className:`inline-flex items-center px-2 py-1 text-xs font-semibold rounded-full ${e.success?`bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400`:`bg-red-100 text-red-800 dark:bg-red-900/20 dark:text-red-400`}`,children:[e.success?(0,V.jsx)(Ae,{className:`h-3 w-3 mr-1`}):(0,V.jsx)(We,{className:`h-3 w-3 mr-1`}),e.success?r(`webhooks.deliveryModal.success`):r(`webhooks.deliveryModal.failed`)]})}),(0,V.jsx)(`td`,{className:`px-4 py-4 whitespace-nowrap text-sm`,children:(0,V.jsxs)(`div`,{children:[e.statusCode&&(0,V.jsx)(`span`,{className:`font-mono text-gray-900 dark:text-white`,children:e.statusCode}),(0,V.jsxs)(`div`,{className:`text-xs text-gray-500`,children:[e.responseTime,`ms`]}),e.error&&(0,V.jsx)(`div`,{className:`text-xs text-red-500 max-w-xs truncate`,title:e.error,children:e.error})]})}),(0,V.jsx)(`td`,{className:`px-4 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400`,children:new Date(e.timestamp).toLocaleString()}),(0,V.jsxs)(`td`,{className:`px-4 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400`,children:[`#`,e.attempt]})]},e.deliveryId))})]})})})})}function G1(){let{t:e}=H(`studio`),{hasPermission:t}=ci(),[n,r]=(0,B.useState)([]),[i,a]=(0,B.useState)(!0),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(),[u,d]=(0,B.useState)(!1),[f,p]=(0,B.useState)(null),[m,h]=(0,B.useState)(``),[g,_]=(0,B.useState)(null),v=t(pi.WRITE),y=t(pi.WRITE),b=t(pi.DELETE),x=async()=>{try{a(!0);let e=await W.get(`/webhooks`);e.success&&e.data&&r(e.data.webhooks||[])}catch(e){V1.error(`Failed to load webhooks`,e)}finally{a(!1)}};(0,B.useEffect)(()=>{x()},[]);let S=async e=>{try{(await W.post(`/webhooks`,{webhookData:e})).success&&await x()}catch(e){throw V1.error(`Failed to create webhook`,e),e}},C=async e=>{if(c)try{(await W.put(`/webhooks/${c.id}`,{webhookData:e})).success&&(await x(),l(void 0))}catch(e){throw V1.error(`Failed to update webhook`,e),e}},w=async t=>{if(confirm(e(`webhooks.deleteConfirm`,{name:t.name})))try{(await W.delete(`/webhooks/${t.id}`)).success&&await x()}catch(e){V1.error(`Failed to delete webhook`,e)}},T=async e=>{try{_(e.id),(await W.post(`/webhooks/${e.id}/test`,{eventType:`system.test`})).success&&V1.info(`Test webhook sent successfully`)}catch(e){V1.error(`Failed to test webhook`,e)}finally{_(null)}},E=e=>{l(e),s(!0)},D=e=>{p(e),d(!0)},O=()=>{s(!1),l(void 0),d(!1),p(null)},k=n.filter(e=>e.name.toLowerCase().includes(m.toLowerCase())||e.url.toLowerCase().includes(m.toLowerCase())),A=e=>e.active?`bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400`:`bg-gray-100 text-gray-800 dark:bg-gray-900/20 dark:text-gray-400`,j=t=>t.active?e(`webhooks.status.active`):e(`webhooks.status.inactive`);return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`webhooks.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`webhooks.subtitle`)})]}),v&&(0,V.jsxs)(U,{onClick:()=>s(!0),children:[(0,V.jsx)(Ne,{className:`h-4 w-4 mr-2`}),e(`webhooks.createWebhook`)]})]}),(0,V.jsx)(`div`,{className:`flex flex-col sm:flex-row gap-4`,children:(0,V.jsx)(`div`,{className:`flex-1`,children:(0,V.jsx)(h1,{placeholder:e(`webhooks.searchPlaceholder`),value:m,onChange:e=>h(e.target.value)})})}),i?(0,V.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,V.jsx)(Ao,{})}):k.length===0?(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center`,children:[(0,V.jsx)(I,{className:`h-12 w-12 text-gray-400 mx-auto mb-4`}),(0,V.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-white mb-2`,children:e(`webhooks.noWebhooksTitle`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:e(`webhooks.noWebhooksDesc`)}),v&&(0,V.jsxs)(U,{onClick:()=>s(!0),children:[(0,V.jsx)(Ne,{className:`h-4 w-4 mr-2`}),e(`webhooks.createWebhook`)]})]}):(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden`,children:(0,V.jsx)(`div`,{className:`overflow-x-auto`,children:(0,V.jsxs)(`table`,{className:`min-w-full divide-y divide-gray-200 dark:divide-gray-700`,children:[(0,V.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-900`,children:(0,V.jsxs)(`tr`,{children:[(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`webhooks.tableHeaders.webhook`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`webhooks.tableHeaders.status`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`webhooks.tableHeaders.events`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`webhooks.tableHeaders.lastUpdated`)}),(0,V.jsx)(`th`,{className:`px-6 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider`,children:e(`webhooks.tableHeaders.actions`)})]})}),(0,V.jsx)(`tbody`,{className:`bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700`,children:k.map(t=>(0,V.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-700`,children:[(0,V.jsx)(`td`,{className:`px-6 py-4`,children:(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:t.name}),(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400 font-mono`,children:t.url})]})}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap`,children:(0,V.jsx)(`span`,{className:`inline-flex px-2 py-1 text-xs font-semibold rounded-full ${A(t)}`,children:j(t)})}),(0,V.jsxs)(`td`,{className:`px-6 py-4`,children:[(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`webhooks.eventsCount`,{count:t.events.length})}),(0,V.jsxs)(`div`,{className:`text-xs text-gray-400 max-w-xs`,children:[t.events.slice(0,3).join(`, `),t.events.length>3&&` ${e(`webhooks.moreEvents`,{count:t.events.length-3})}`]})]}),(0,V.jsx)(`td`,{className:`px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400`,children:new Date(t.updatedAt).toLocaleDateString()}),(0,V.jsxs)(`td`,{className:`px-6 py-4 whitespace-nowrap text-right text-sm font-medium space-x-2`,children:[(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>T(t),disabled:g===t.id||!t.active,title:e(`webhooks.testWebhook`),children:g===t.id?(0,V.jsx)(ke,{className:`h-4 w-4 animate-spin`}):(0,V.jsx)(Se,{className:`h-4 w-4`})}),(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>D(t),title:e(`webhooks.viewDeliveryHistory`),children:(0,V.jsx)(ce,{className:`h-4 w-4`})}),y&&(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>E(t),title:e(`webhooks.editWebhook`),children:(0,V.jsx)(ct,{className:`h-4 w-4`})}),b&&(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:()=>w(t),className:`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,title:e(`webhooks.deleteWebhook`),children:(0,V.jsx)(Be,{className:`h-4 w-4`})})]})]},t.id))})]})})}),(0,V.jsx)(U1,{isOpen:o,onClose:O,onSave:c?C:S,webhook:c}),(0,V.jsx)(W1,{webhook:f,isOpen:u,onClose:O})]})}function K1(){let{t:e}=H(`studio`);za({page:`users`,title:e(`users.title`),defaultVisible:!1,defaultPosition:`left`});let{hasPermission:t}=ci(),n=t(ui.READ),r=t(fi.READ),i=t(pi.READ),a=n||r||i,[o,s]=(0,B.useState)(`users`),[c,l]=(0,B.useState)(!1);return(0,B.useEffect)(()=>{c||(n?s(`users`):r?s(`tokens`):i&&s(`webhooks`),l(!0))},[n,r,i,c]),a?(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`usersPage.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`usersPage.subtitle`)})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden`,children:[(0,V.jsx)(`div`,{className:`border-b border-gray-200 dark:border-gray-700`,children:(0,V.jsxs)(`nav`,{className:`-mb-px flex`,children:[n&&(0,V.jsx)(`button`,{onClick:()=>s(`users`),className:`py-3 px-6 text-sm font-medium border-b-2 transition-colors ${o===`users`?`border-primary-500 text-primary-600 dark:text-primary-400`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300`}`,children:e(`usersPage.tabs.users`)}),r&&(0,V.jsx)(`button`,{onClick:()=>s(`tokens`),className:`py-3 px-6 text-sm font-medium border-b-2 transition-colors ${o===`tokens`?`border-primary-500 text-primary-600 dark:text-primary-400`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300`}`,children:e(`usersPage.tabs.tokens`)}),i&&(0,V.jsx)(`button`,{onClick:()=>s(`webhooks`),className:`py-3 px-6 text-sm font-medium border-b-2 transition-colors ${o===`webhooks`?`border-primary-500 text-primary-600 dark:text-primary-400`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300`}`,children:e(`usersPage.tabs.webhooks`)})]})}),(0,V.jsxs)(`div`,{className:`p-6`,children:[o===`users`&&n&&(0,V.jsx)(F1,{}),o===`tokens`&&r&&(0,V.jsx)(B1,{}),o===`webhooks`&&i&&(0,V.jsx)(G1,{})]})]})]}):(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`usersPage.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`usersPage.subtitle`)})]}),(0,V.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-6`,children:(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(de,{className:`h-6 w-6 text-yellow-600 dark:text-yellow-400 mr-3`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-yellow-800 dark:text-yellow-200`,children:e(`usersPage.accessDenied`)}),(0,V.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300 mt-1`,children:e(`usersPage.accessDeniedMessage`)})]})]})})]})}var q1=Fr(`config-service`),J1=class{client;cachedConfig=null;constructor(e){this.client=e}async fetchAndMergeConfig(){if(this.cachedConfig)return this.cachedConfig;try{let e=await this.client.get(`/config/studio`);if(e.success&&e.data&&e.data.studioConfig){let t=e.data.studioConfig,n=window.TROKKY_CONFIG||{},r={...n,branding:{...n.branding,...t.branding}};return window.TROKKY_CONFIG=r,this.cachedConfig=t,q1.debug(`Config updated from API`,{title:t.branding?.title,hasConfig:!!t}),t}}catch(e){q1.warn(`Failed to fetch config from API, falling back to window config`,e)}let e=window.TROKKY_CONFIG||{};return this.cachedConfig=e,e}async getBranding(){return(await this.fetchAndMergeConfig()).branding||{title:`Trokky Studio`}}clearCache(){this.cachedConfig=null}},Y1=null;function X1(e){return Y1||=new J1(e),Y1}function Z1(){let[e,t]=(0,B.useState)(null),[n,r]=(0,B.useState)({title:`Trokky Studio`}),[i,a]=(0,B.useState)(!0);return(0,B.useEffect)(()=>{(async()=>{try{let e=X1(W),[n,i]=await Promise.all([e.fetchAndMergeConfig(),e.getBranding()]);t(n),r(i)}catch(e){console.warn(`[useStudioConfig] Failed to fetch config:`,e);let t=window.TROKKY_CONFIG;r(t?.branding||{title:`Trokky Studio`})}finally{a(!1)}})()},[W]),{config:e,branding:n,loading:i}}function Q1(){let{branding:e,loading:t}=Z1();return{branding:e,loading:t}}var $1=Fr(`SettingsPage`);function e0(){let{t:e}=H(`studio`),t=za({page:`settings`,title:e(`settings.title`)}),{hasPermission:n}=ci(),{branding:r}=Q1(),i=pa()?.utils?.showToast||((e,t)=>console.log(`Toast: ${t} - ${e}`)),[a,o]=(0,B.useState)(``),[s,c]=(0,B.useState)(``),[l,u]=(0,B.useState)(``),[d,f]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[h,g]=(0,B.useState)(``),[_,v]=(0,B.useState)(`system`),[y,b]=(0,B.useState)(!0),[x,S]=(0,B.useState)(!1),[C,w]=(0,B.useState)(!1),[T,E]=(0,B.useState)([]),[D,O]=(0,B.useState)([`totp`,`email`]),k=n(di.READ),A=n(di.WRITE);if((0,B.useEffect)(()=>{t.configure({page:`settings`,title:e(`settings.title`),defaultVisible:!1})},[t.configure,e]),(0,B.useEffect)(()=>{k&&j()},[k]),!k)return(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`settings.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`settings.subtitle`)})]}),(0,V.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-6`,children:(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(de,{className:`h-6 w-6 text-yellow-600 dark:text-yellow-400 mr-3`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-yellow-800 dark:text-yellow-200`,children:e(`settings.accessDenied`)}),(0,V.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300 mt-1`,children:e(`settings.accessDeniedMessage`)})]})]})})]});let j=async()=>{try{b(!0),$1.debug(`Loading settings from API`);let e=await W.get(`/config/settings`);if(e.success&&e.data?.settings){let t=e.data.settings;o(t.publicUrl||M()),c(t.studioTitle||`Trokky Studio`),u(t.organizationName||``),f(t.primaryColor||``),m(t.secondaryColor||``),g(t.logo||``),v(t.defaultTheme||`system`),w(t.mfaRequired||!1),E(t.mfaEnforcedRoles||[]),O(t.mfaAllowedMethods||[`totp`,`email`]),$1.info(`Settings loaded successfully`,{settings:t})}else o(M()),c(r?.title||`Trokky Studio`),u(``),f(``),m(``),g(``),v(`system`),w(!1),E([]),O([`totp`,`email`]),$1.warn(`No settings found, using defaults`)}catch(t){$1.error(`Failed to load settings`,t),o(M()),c(r?.title||`Trokky Studio`),u(``),f(``),m(``),g(``),v(`system`),w(!1),E([]),O([`totp`,`email`]),i(e(`settings.loadError`),`error`)}finally{b(!1)}},M=()=>{let e=window.location.origin;return window.location.pathname.includes(`/studio`),e};return y?(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`settings.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`settings.subtitle`)})]}),(0,V.jsx)(`div`,{className:`max-w-4xl`,children:(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:(0,V.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,V.jsx)(`div`,{className:`text-gray-500 dark:text-gray-400`,children:e(`settings.loading`)})})})})]}):(0,V.jsxs)(`div`,{className:`p-6`,children:[(0,V.jsxs)(`div`,{className:`mb-8`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`settings.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`settings.subtitle`)})]}),(0,V.jsxs)(`div`,{className:`max-w-4xl`,children:[(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsx)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-white mb-6`,children:e(`settings.generalSettings`)}),(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.studioTitle`)}),(0,V.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),disabled:!A,className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed`,placeholder:`Trokky Studio`}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-1`,children:e(`settings.studioTitleDescription`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.organizationName`)}),(0,V.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),disabled:!A,className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed`,placeholder:`Your Organization Name`}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-1`,children:e(`settings.organizationNameDescription`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.primaryColor`)}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(`input`,{type:`color`,value:d||`#3B82F6`,onChange:e=>f(e.target.value),disabled:!A,className:`h-10 w-16 border border-gray-300 dark:border-gray-600 rounded-md disabled:opacity-50 disabled:cursor-not-allowed`}),(0,V.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),disabled:!A,className:`flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed`,placeholder:`#3B82F6`})]}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-1`,children:e(`settings.primaryColorDescription`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.secondaryColor`)}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(`input`,{type:`color`,value:p||`#6B7280`,onChange:e=>m(e.target.value),disabled:!A,className:`h-10 w-16 border border-gray-300 dark:border-gray-600 rounded-md disabled:opacity-50 disabled:cursor-not-allowed`}),(0,V.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),disabled:!A,className:`flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed`,placeholder:`#6B7280`})]}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-1`,children:e(`settings.secondaryColorDescription`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.logoUrl`)}),(0,V.jsx)(`input`,{type:`url`,value:h,onChange:e=>g(e.target.value),disabled:!A,className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed`,placeholder:`https://yoursite.com/logo.png`}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-1`,children:e(`settings.logoUrlDescription`)}),h&&(0,V.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-900 rounded border border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mb-2`,children:e(`settings.logoPreview`)}),(0,V.jsx)(`img`,{src:h,alt:`Logo preview`,className:`h-16 w-auto object-contain`})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.publicUrl`)}),(0,V.jsx)(`input`,{type:`url`,value:a,onChange:e=>o(e.target.value),disabled:!A,className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed`,placeholder:`https://yourwebsite.com`}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-1`,children:e(`settings.publicUrlDescription`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`settings.defaultTheme`)}),(0,V.jsxs)(`select`,{value:_,onChange:e=>v(e.target.value),disabled:!A,className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,V.jsx)(`option`,{value:`system`,children:e(`theme.system`)}),(0,V.jsx)(`option`,{value:`light`,children:e(`theme.light`)}),(0,V.jsx)(`option`,{value:`dark`,children:e(`theme.dark`)})]}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-1`,children:e(`settings.defaultThemeDescription`)})]})]})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 mt-6`,children:[(0,V.jsx)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-white mb-6`,children:e(`settings.securitySettings`)}),(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white mb-3`,children:e(`settings.mfa.title`)}),(0,V.jsxs)(`div`,{className:`flex items-center mb-4`,children:[(0,V.jsx)(`input`,{type:`checkbox`,id:`mfaRequired`,checked:C,onChange:e=>w(e.target.checked),disabled:!A,className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded disabled:opacity-50`}),(0,V.jsx)(`label`,{htmlFor:`mfaRequired`,className:`ml-2 text-sm text-gray-700 dark:text-gray-300`,children:e(`settings.mfa.requireAll`)})]}),(0,V.jsxs)(`div`,{className:`mb-4`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-2`,children:e(`settings.mfa.requireRoles`)}),(0,V.jsx)(`div`,{className:`space-y-2 ml-4`,children:[`admin`,`editor`,`author`,`viewer`].map(e=>(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(`input`,{type:`checkbox`,id:`mfa-role-${e}`,checked:T.includes(e),onChange:t=>{t.target.checked?E([...T,e]):E(T.filter(t=>t!==e))},disabled:!A||C,className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded disabled:opacity-50`}),(0,V.jsx)(`label`,{htmlFor:`mfa-role-${e}`,className:`ml-2 text-sm text-gray-700 dark:text-gray-300 capitalize`,children:e})]},e))}),C&&(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2 ml-4`,children:e(`settings.mfa.roleDisabledNote`)})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white mb-3`,children:e(`settings.mfa.allowedMethods`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-2`,children:e(`settings.mfa.allowedMethodsDescription`)}),(0,V.jsxs)(`div`,{className:`space-y-2 ml-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(`input`,{type:`checkbox`,id:`mfa-method-totp`,checked:D.includes(`totp`),onChange:e=>{e.target.checked?O([...D,`totp`]):D.length>1&&O(D.filter(e=>e!==`totp`))},disabled:!A||D.length===1&&D.includes(`totp`),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded disabled:opacity-50`}),(0,V.jsx)(`label`,{htmlFor:`mfa-method-totp`,className:`ml-2 text-sm text-gray-700 dark:text-gray-300`,children:e(`settings.mfa.totp`)})]}),(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(`input`,{type:`checkbox`,id:`mfa-method-email`,checked:D.includes(`email`),onChange:e=>{e.target.checked?O([...D,`email`]):D.length>1&&O(D.filter(e=>e!==`email`))},disabled:!A||D.length===1&&D.includes(`email`),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded disabled:opacity-50`}),(0,V.jsx)(`label`,{htmlFor:`mfa-method-email`,className:`ml-2 text-sm text-gray-700 dark:text-gray-300`,children:e(`settings.mfa.email`)})]})]}),(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2 ml-4`,children:e(`settings.mfa.atLeastOne`)})]}),(0,V.jsx)(`div`,{className:`bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4`,children:(0,V.jsxs)(`p`,{className:`text-sm text-blue-800 dark:text-blue-200`,children:[(0,V.jsx)(`strong`,{children:e(`common.note`)}),` `,e(`settings.mfa.enforcementNote`)]})})]})]}),(0,V.jsxs)(`div`,{className:`mt-6 pt-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(`button`,{onClick:async()=>{try{S(!0);let t=a.replace(/\/$/,``),n={publicUrl:t,studioTitle:s,organizationName:l,primaryColor:d,secondaryColor:p,logo:h,defaultTheme:_,mfaRequired:C,mfaEnforcedRoles:T,mfaAllowedMethods:D};$1.debug(`Saving settings via API`,n);let r=await W.put(`/config/settings`,{settings:n});if(r.success)o(t),window.dispatchEvent(new CustomEvent(`trokky:settings:updated`,{detail:{settings:n}})),$1.info(`Settings saved successfully`,{settings:n}),i(e(`settings.saveSuccess`),`success`);else throw Error(r.error?.message||`Failed to save settings`)}catch(t){$1.error(`Failed to save settings`,t);let n=t instanceof Error?t.message:`Unknown error`;i(e(`settings.saveError`,{error:n}),`error`)}finally{S(!1)}},disabled:x||!A,className:`px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:e(x?`settings.saving`:`settings.saveChanges`)}),!A&&(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mt-2`,children:e(`settings.readOnlyMessage`)})]})]})]})}function t0({mode:e=`login`,onError:t,disabled:n,className:r=``}){let{t:i}=H(`studio`),[a,o]=(0,B.useState)(!1);return(0,V.jsxs)(U,{type:`button`,onClick:async()=>{o(!0);try{let n=await W.post(`/auth/oauth/google/init`,{mode:e});if(n.success&&n.data)sessionStorage.setItem(`oauth_state`,n.data.state),sessionStorage.setItem(`oauth_code_verifier`,n.data.codeVerifier),sessionStorage.setItem(`oauth_mode`,e),window.location.href=n.data.authUrl;else{let e=n.error?.message||i(`oauth.google.initFailed`);t?.(e)}}catch(e){let n=e instanceof Error?e.message:i(`oauth.google.initFailed`);t?.(n)}finally{o(!1)}},disabled:n||a,variant:`outline`,className:`w-full flex items-center justify-center gap-3 h-12 border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors ${r}`,children:[a?(0,V.jsx)(Ao,{size:`sm`}):(0,V.jsx)(n0,{className:`w-5 h-5`}),(0,V.jsx)(`span`,{className:`text-gray-700 dark:text-gray-300`,children:i(e===`link`?`oauth.google.linkAccount`:`oauth.google.signIn`)})]})}function n0({className:e}){return(0,V.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,V.jsx)(`path`,{fill:`#4285F4`,d:`M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z`}),(0,V.jsx)(`path`,{fill:`#34A853`,d:`M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z`}),(0,V.jsx)(`path`,{fill:`#FBBC05`,d:`M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z`}),(0,V.jsx)(`path`,{fill:`#EA4335`,d:`M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z`})]})}function r0(){let{t:e}=H(`studio`),{user:t,refetch:n}=si(),[r,i]=(0,B.useState)(null),[a,o]=(0,B.useState)(!0),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(null),d=t?.oauthProviders||[];(0,B.useEffect)(()=>{f()},[]);let f=async()=>{try{let e=await W.get(`/auth/oauth/status`);e.success&&e.data&&i(e.data)}catch(e){console.error(`Failed to fetch OAuth status:`,e)}finally{o(!1)}},p=async t=>{c(t),u(null);try{let r=await W.delete(`/auth/oauth/${t}/unlink`);if(r.success)await n(),u({type:`success`,text:e(`oauth.unlinkSuccess`,{provider:g(t)})});else throw Error(r.error?.message||e(`oauth.unlinkFailed`))}catch(t){u({type:`error`,text:t instanceof Error?t.message:e(`oauth.unlinkFailed`)})}finally{c(null),setTimeout(()=>u(null),5e3)}},m=async()=>{u({type:`success`,text:e(`oauth.accountLinked`)}),await n()},h=e=>{u({type:`error`,text:e}),setTimeout(()=>u(null),5e3)},g=e=>({google:`Google`,github:`GitHub`,microsoft:`Microsoft`})[e]||e;return a?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,V.jsx)(Ao,{size:`md`})}):r?.providers?.google?(0,V.jsxs)(`div`,{className:`space-y-4`,children:[l&&(0,V.jsx)(`div`,{className:`p-3 rounded-lg text-sm ${l.type===`success`?`bg-green-50 text-green-800 border border-green-200 dark:bg-green-900/20 dark:text-green-400 dark:border-green-800`:`bg-red-50 text-red-800 border border-red-200 dark:bg-red-900/20 dark:text-red-400 dark:border-red-800`}`,children:l.text}),r?.providers?.google&&(0,V.jsx)(i0,{provider:`google`,isLinked:(e=>d.some(t=>t.provider===e))(`google`),linkedData:(e=>d.find(t=>t.provider===e))(`google`),isUnlinking:s===`google`,onUnlink:()=>p(`google`),onLinkSuccess:m,onLinkError:h,getProviderIcon:e=>{switch(e){case`google`:return(0,V.jsx)(a0,{className:`w-5 h-5`});case`github`:return(0,V.jsx)(o0,{className:`w-5 h-5`});case`microsoft`:return(0,V.jsx)(s0,{className:`w-5 h-5`});default:return null}},getProviderName:g,formatDate:e=>new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`}),t:e})]}):null}function i0({provider:e,isLinked:t,linkedData:n,isUnlinking:r,onUnlink:i,onLinkSuccess:a,onLinkError:o,getProviderIcon:s,getProviderName:c,formatDate:l,t:u}){return(0,V.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-3`,children:[(0,V.jsx)(`div`,{className:`flex-shrink-0`,children:s(e)}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:c(e)}),t&&n?(0,V.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n.email,` - `,u(`oauth.linked`,{date:l(n.linkedAt)})]}):(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u(`oauth.notConnected`)})]})]}),(0,V.jsx)(`div`,{children:t?(0,V.jsx)(U,{variant:`outline`,size:`sm`,onClick:i,disabled:r,className:`text-red-600 dark:text-red-400 border-red-300 dark:border-red-700 hover:bg-red-50 dark:hover:bg-red-900/20`,children:r?(0,V.jsx)(Ao,{size:`sm`}):u(`oauth.unlink`)}):e===`google`?(0,V.jsx)(t0,{mode:`link`,onSuccess:a,onError:o,className:`!w-auto !h-auto py-1.5 px-3 text-sm`}):(0,V.jsx)(U,{variant:`outline`,size:`sm`,disabled:!0,children:u(`oauth.comingSoon`)})})]})}function a0({className:e}){return(0,V.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,V.jsx)(`path`,{fill:`#4285F4`,d:`M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z`}),(0,V.jsx)(`path`,{fill:`#34A853`,d:`M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z`}),(0,V.jsx)(`path`,{fill:`#FBBC05`,d:`M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z`}),(0,V.jsx)(`path`,{fill:`#EA4335`,d:`M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z`})]})}function o0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,V.jsx)(`path`,{d:`M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z`})})}function s0({className:e}){return(0,V.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,children:[(0,V.jsx)(`path`,{fill:`#F25022`,d:`M1 1h10v10H1z`}),(0,V.jsx)(`path`,{fill:`#00A4EF`,d:`M1 13h10v10H1z`}),(0,V.jsx)(`path`,{fill:`#7FBA00`,d:`M13 1h10v10H13z`}),(0,V.jsx)(`path`,{fill:`#FFB900`,d:`M13 13h10v10H13z`})]})}function c0({totpSetupData:e,onCopy:t,onCancel:n,onNext:r}){let{t:i}=H(`studio`);return(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-white mb-4`,children:i(`mfa.setup.authenticator`)}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:i(`mfa.setup.scanQrCode`)}),(0,V.jsx)(`div`,{className:`flex justify-center`,children:(0,V.jsx)(`img`,{src:e.qrCode,alt:`TOTP QR Code`,className:`w-48 h-48 bg-white p-2 rounded`})}),(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-2`,children:i(`mfa.setup.orEnterManually`)}),(0,V.jsxs)(`div`,{className:`inline-flex items-center gap-2 bg-gray-100 dark:bg-gray-700 px-3 py-2 rounded font-mono text-sm`,children:[e.manualEntryKey,(0,V.jsx)(`button`,{onClick:()=>t(e.manualEntryKey),className:`text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`,children:(0,V.jsx)(oe,{className:`h-4 w-4`})})]})]}),(0,V.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,V.jsx)(U,{variant:`secondary`,onClick:n,children:i(`mfa.cancel`)}),(0,V.jsx)(U,{onClick:r,children:i(`mfa.next`)})]})]})]})}function l0({verificationCode:e,onVerificationCodeChange:t,error:n,isProcessing:r,onCancel:i,onVerify:a}){let{t:o}=H(`studio`);return(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-white mb-4`,children:o(`mfa.setup.verifyAuthenticatorCode`)}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:o(`mfa.setup.enterCodeToVerify`)}),n&&(0,V.jsx)(`div`,{className:`p-3 bg-red-50 dark:bg-red-900/20 rounded text-sm text-red-600 dark:text-red-400`,children:n}),(0,V.jsx)(h1,{type:`text`,value:e,onChange:e=>t(e.target.value.replace(/\D/g,``).slice(0,6)),placeholder:`000000`,className:`text-center text-2xl tracking-widest font-mono`,maxLength:6,autoFocus:!0}),(0,V.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,V.jsx)(U,{variant:`secondary`,onClick:i,children:o(`mfa.cancel`)}),(0,V.jsxs)(U,{onClick:a,disabled:r||e.length!==6,children:[r?(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}):null,o(`mfa.verify`)]})]})]})]})}function u0({verificationCode:e,onVerificationCodeChange:t,error:n,isProcessing:r,onCancel:i,onVerify:a}){let{t:o}=H(`studio`);return(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-white mb-4`,children:o(`mfa.setup.verifyEmailCode`)}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:o(`mfa.setup.enterEmailCode`)}),n&&(0,V.jsx)(`div`,{className:`p-3 bg-red-50 dark:bg-red-900/20 rounded text-sm text-red-600 dark:text-red-400`,children:n}),(0,V.jsx)(h1,{type:`text`,value:e,onChange:e=>t(e.target.value.replace(/\D/g,``).slice(0,6)),placeholder:`000000`,className:`text-center text-2xl tracking-widest font-mono`,maxLength:6,autoFocus:!0}),(0,V.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,V.jsx)(U,{variant:`secondary`,onClick:i,children:o(`mfa.cancel`)}),(0,V.jsxs)(U,{onClick:a,disabled:r||e.length!==6,children:[r?(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}):null,o(`mfa.verify`)]})]})]})]})}function d0({backupCodes:e,onCopy:t,onDone:n}){let{t:r}=H(`studio`);return(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-white mb-4`,children:r(`mfa.setup.saveBackupCodes`)}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`div`,{className:`p-4 bg-yellow-50 dark:bg-yellow-900/20 rounded-lg border border-yellow-200 dark:border-yellow-800`,children:(0,V.jsx)(`p`,{className:`text-sm text-yellow-800 dark:text-yellow-200`,children:r(`mfa.setup.backupCodesImportant`)})}),(0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-2 font-mono text-sm bg-gray-50 dark:bg-gray-900 p-4 rounded`,children:e.map((e,t)=>(0,V.jsx)(`div`,{className:`p-2 bg-white dark:bg-gray-800 rounded`,children:e},t))}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsxs)(U,{variant:`secondary`,onClick:()=>t(e.join(`
735
735
  `)),children:[(0,V.jsx)(oe,{className:`h-4 w-4 mr-2`}),r(`mfa.copyAll`)]}),(0,V.jsx)(U,{onClick:n,children:r(`mfa.done`)})]})]})]})}function f0({mfaStatus:e,totpMethod:t,emailMethod:n,isProcessing:r,showTrustedDevices:i,trustedDevices:a,isLoadingDevices:o,onSetupTOTP:s,onSetupEmailOTP:c,onDisableMethod:l,onRegenerateBackupCodes:u,onToggleTrustedDevices:d,onRevokeTrustedDevice:f,onRevokeAllTrustedDevices:p,onDisableAll:m}){let{t:h}=H(`studio`);return(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(L,{className:`h-8 w-8 text-gray-400`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-white`,children:h(`mfa.authenticatorApp`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:h(`mfa.authenticatorAppDesc`)})]})]}),t?.enabled?(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`text-sm text-green-600 dark:text-green-400`,children:h(`mfa.enabled`)}),(0,V.jsx)(U,{variant:`secondary`,size:`sm`,onClick:()=>l(`totp`),children:h(`mfa.disableMethod`)})]}):(0,V.jsx)(U,{size:`sm`,onClick:s,disabled:r,children:h(`mfa.setUp`)})]})}),(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(ne,{className:`h-8 w-8 text-gray-400`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-white`,children:h(`mfa.emailVerification`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:h(`mfa.emailVerificationDesc`)})]})]}),n?.enabled?(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`text-sm text-green-600 dark:text-green-400`,children:h(`mfa.enabled`)}),(0,V.jsx)(U,{variant:`secondary`,size:`sm`,onClick:()=>l(`email`),children:h(`mfa.disableMethod`)})]}):(0,V.jsx)(U,{size:`sm`,onClick:c,disabled:r,children:h(`mfa.setUp`)})]})}),e?.enabled&&(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(te,{className:`h-8 w-8 text-gray-400`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-white`,children:h(`mfa.backupCodes`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:h(`mfa.backupCodesRemaining`,{count:e.backupCodesRemaining})})]})]}),(0,V.jsxs)(U,{variant:`secondary`,size:`sm`,onClick:u,disabled:r,children:[(0,V.jsx)(ke,{className:`h-4 w-4 mr-1`}),h(`mfa.regenerate`)]})]})}),e?.enabled&&e.trustedDevicesCount>0&&(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(_e,{className:`h-8 w-8 text-gray-400`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-white`,children:h(`mfa.trustedDevices`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:h(`mfa.trustedDevicesCount`,{count:e.trustedDevicesCount})})]})]}),(0,V.jsx)(U,{variant:`secondary`,size:`sm`,onClick:d,children:h(i?`mfa.hide`:`mfa.manage`)})]}),i&&(0,V.jsx)(`div`,{className:`space-y-2 mt-4 pt-4 border-t border-gray-200 dark:border-gray-700`,children:o?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,V.jsx)(Ao,{size:`sm`})}):a.length>0?(0,V.jsxs)(V.Fragment,{children:[a.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-gray-50 dark:bg-gray-900 rounded`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:e.name}),(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:h(`mfa.trustedDevice.trusted`,{date:new Date(e.trustedAt).toLocaleDateString()})})]}),(0,V.jsx)(`button`,{onClick:()=>f(e.id),className:`p-1 text-gray-400 hover:text-red-500`,children:(0,V.jsx)(Be,{className:`h-4 w-4`})})]},e.id)),a.length>1&&(0,V.jsx)(U,{variant:`secondary`,size:`sm`,className:`w-full mt-2`,onClick:p,children:h(`mfa.revokeAll`)})]}):(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 text-center py-2`,children:h(`common.loading`)})})]}),e?.enabled&&(0,V.jsx)(`div`,{className:`mt-6 pt-6 border-t border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(`div`,{className:`bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800 p-4`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h4`,{className:`font-medium text-red-800 dark:text-red-200`,children:h(`mfa.disable.all`)}),(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h(`mfa.disable.allDesc`)})]}),(0,V.jsxs)(U,{variant:`danger`,size:`sm`,onClick:m,disabled:r,children:[(0,V.jsx)(We,{className:`h-4 w-4 mr-1`}),h(`mfa.disable.all`)]})]})})})]})}function p0({onToast:e}){let{t}=H(`studio`),[n,r]=(0,B.useState)(null),[i,a]=(0,B.useState)(!0),[o,s]=(0,B.useState)(`idle`),[c,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(``),[f,p]=(0,B.useState)([]),[m,h]=(0,B.useState)(!1),[g,_]=(0,B.useState)([]),[v,y]=(0,B.useState)(!1),[b,x]=(0,B.useState)(!1),[S,C]=(0,B.useState)(``),[w,T]=(0,B.useState)(null),[E,D]=(0,B.useState)(!1),[O,k]=(0,B.useState)(``),[A,j]=(0,B.useState)(!1),[M,N]=(0,B.useState)(``),[P,F]=(0,B.useState)(!1),[I,L]=(0,B.useState)(null),ee=e||((e,t)=>console.log(`${t}: ${e}`));(0,B.useEffect)(()=>{R()},[]);let R=async()=>{try{a(!0);let e=await W.get(`/auth/mfa/status`);e.success&&e.data&&r(e.data.data||e.data)}catch(e){console.error(`Failed to load MFA status:`,e),ee(t(`mfa.toast.loadFailed`),`error`)}finally{a(!1)}},te=async()=>{try{x(!0);let e=await W.get(`/auth/mfa/trusted-devices`);if(e.success&&e.data){let t=e.data,n=t.data?.devices||t.devices||[];_(n)}}catch(e){console.error(`Failed to load trusted devices:`,e)}finally{x(!1)}},ne=async()=>{try{F(!0),L(null);let e=await W.post(`/auth/mfa/setup/totp`,{});if(e.success&&e.data)l(e.data.data||e.data),s(`totp-qr`);else throw Error(e.error?.message||`Failed to initialize TOTP setup`)}catch(e){L(e instanceof Error?e.message:t(`mfa.toast.totpInitFailed`)),ee(t(`mfa.toast.totpInitFailed`),`error`)}finally{F(!1)}},re=async()=>{if(!u.trim()){L(t(`mfa.enterCode`));return}try{F(!0),L(null);let e=await W.post(`/auth/mfa/setup/totp/verify`,{code:u.trim()});if(e.success){let n=e.data;n.backupCodes?(p(n.backupCodes),s(`backup-codes`)):(s(`idle`),await R()),ee(t(`mfa.toast.totpEnabled`),`success`)}else throw Error(e.error?.message||`Invalid verification code`)}catch(e){L(e instanceof Error?e.message:t(`mfa.verifying`))}finally{F(!1),d(``)}},ie=async()=>{try{F(!0),L(null);let e=await W.post(`/auth/mfa/setup/email`,{});if(e.success)s(`email-verify`),ee(t(`mfa.toast.emailCodeSent`),`success`);else throw Error(e.error?.message||t(`mfa.toast.emailSendFailed`))}catch(e){L(e instanceof Error?e.message:t(`mfa.toast.emailSendFailed`)),ee(t(`mfa.toast.emailSendFailed`),`error`)}finally{F(!1)}},ae=async()=>{if(!u.trim()){L(t(`mfa.enterCode`));return}try{F(!0),L(null);let e=await W.post(`/auth/mfa/setup/email/verify`,{code:u.trim()});if(e.success){let n=e.data;n.backupCodes?(p(n.backupCodes),s(`backup-codes`)):(s(`idle`),await R()),ee(t(`mfa.toast.emailEnabled`),`success`)}else throw Error(e.error?.message||`Invalid verification code`)}catch(e){L(e instanceof Error?e.message:t(`mfa.verifying`))}finally{F(!1),d(``)}},z=async e=>{if(!S){L(t(`mfa.errors.passwordRequired`));return}try{F(!0),L(null);let n=await W.post(`/auth/mfa/disable`,{method:e,password:S});if(n.success)T(null),C(``),await R(),ee(t(e===`totp`?`mfa.toast.authenticatorDisabled`:`mfa.toast.emailDisabled`),`success`);else throw Error(n.error?.message||`Failed to disable MFA`)}catch(e){L(e instanceof Error?e.message:`Failed to disable MFA`)}finally{F(!1)}},se=async()=>{if(!M){L(t(`mfa.errors.passwordRequired`));return}try{F(!0),L(null);let e=await W.post(`/auth/mfa/disable-all`,{password:M});if(e.success)j(!1),N(``),await R(),ee(t(`mfa.toast.allDisabled`),`success`);else throw Error(e.error?.message||`Failed to disable MFA`)}catch(e){L(e instanceof Error?e.message:`Failed to disable MFA`)}finally{F(!1)}},ce=async()=>{if(!O){L(t(`mfa.errors.passwordRequired`));return}try{F(!0),L(null);let e=await W.post(`/auth/mfa/backup-codes/regenerate`,{password:O});if(e.success&&e.data){let n=e.data;p(n.backupCodes||[]),h(!0),D(!1),k(``),await R(),ee(t(`mfa.toast.backupCodesRegenerated`),`success`)}else throw Error(e.error?.message||`Failed to regenerate backup codes`)}catch(e){L(e instanceof Error?e.message:`Failed to regenerate backup codes`)}finally{F(!1)}},le=async e=>{try{(await W.delete(`/auth/mfa/trusted-devices/${e}`)).success&&(_(t=>t.filter(t=>t.id!==e)),await R(),ee(t(`mfa.toast.deviceRevoked`),`success`))}catch{ee(t(`mfa.toast.deviceRevokeFailed`),`error`)}},ue=async()=>{if(confirm(t(`mfa.trustedDevice.confirmRevokeAll`)))try{(await W.delete(`/auth/mfa/trusted-devices`)).success&&(_([]),await R(),ee(t(`mfa.toast.allDevicesRevoked`),`success`))}catch{ee(t(`mfa.toast.allDevicesRevokeFailed`),`error`)}},fe=e=>{navigator.clipboard.writeText(e),ee(t(`mfa.copiedToClipboard`),`info`)},pe=()=>{s(`idle`),l(null),d(``),L(null)},me=()=>{s(`idle`),p([]),R()};if(i)return(0,V.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,V.jsx)(Ao,{size:`lg`})});let he=n?.methods.find(e=>e.type===`totp`),ge=n?.methods.find(e=>e.type===`email`);return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(He,{className:`h-6 w-6 text-primary-500`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-white`,children:t(`mfa.title`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t(`mfa.subtitle`)})]})]}),(0,V.jsx)(`div`,{className:`flex items-center gap-2`,children:n?.enabled?(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400`,children:[(0,V.jsx)(Ae,{className:`h-4 w-4`}),t(`mfa.enabled`)]}):(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400`,children:[(0,V.jsx)(de,{className:`h-4 w-4`}),t(`mfa.notEnabled`)]})}),o===`totp-qr`&&c&&(0,V.jsx)(c0,{totpSetupData:c,onCopy:fe,onCancel:pe,onNext:()=>s(`totp-verify`)}),o===`totp-verify`&&(0,V.jsx)(l0,{verificationCode:u,onVerificationCodeChange:d,error:I,isProcessing:P,onCancel:pe,onVerify:re}),o===`email-verify`&&(0,V.jsx)(u0,{verificationCode:u,onVerificationCodeChange:d,error:I,isProcessing:P,onCancel:pe,onVerify:ae}),o===`backup-codes`&&f.length>0&&(0,V.jsx)(d0,{backupCodes:f,onCopy:fe,onDone:me}),o===`idle`&&(0,V.jsx)(f0,{mfaStatus:n,totpMethod:he,emailMethod:ge,isProcessing:P,showTrustedDevices:v,trustedDevices:g,isLoadingDevices:b,onSetupTOTP:ne,onSetupEmailOTP:ie,onDisableMethod:T,onRegenerateBackupCodes:()=>D(!0),onToggleTrustedDevices:()=>{y(!v),v||te()},onRevokeTrustedDevice:le,onRevokeAllTrustedDevices:ue,onDisableAll:()=>j(!0)}),w&&(0,V.jsx)(ia,{open:!0,onClose:()=>{T(null),C(``),L(null)},variant:`center`,size:`sm`,title:t(w===`totp`?`mfa.disableDialog.authenticator`:`mfa.disableDialog.email`),children:(0,V.jsxs)(ia.Body,{children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:t(`mfa.disableDialog.enterPassword`)}),I&&(0,V.jsx)(`div`,{className:`p-3 mb-4 bg-red-50 dark:bg-red-900/20 rounded text-sm text-red-600 dark:text-red-400`,children:I}),(0,V.jsx)(h1,{type:`password`,value:S,onChange:e=>C(e.target.value),placeholder:`Password`,className:`mb-4`}),(0,V.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,V.jsx)(U,{variant:`secondary`,onClick:()=>{T(null),C(``),L(null)},children:t(`mfa.cancel`)}),(0,V.jsxs)(U,{variant:`danger`,onClick:()=>z(w),disabled:P||!S,children:[P?(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}):null,t(`mfa.disableMethod`)]})]})]})}),E&&(0,V.jsx)(ia,{open:!0,onClose:()=>{D(!1),k(``),L(null)},variant:`center`,size:`sm`,title:t(`mfa.regenerateBackupCodes.title`),children:(0,V.jsxs)(ia.Body,{children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:t(`mfa.regenerateBackupCodes.description`)}),I&&(0,V.jsx)(`div`,{className:`p-3 mb-4 bg-red-50 dark:bg-red-900/20 rounded text-sm text-red-600 dark:text-red-400`,children:I}),(0,V.jsx)(h1,{type:`password`,value:O,onChange:e=>k(e.target.value),placeholder:`Password`,className:`mb-4`}),(0,V.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,V.jsx)(U,{variant:`secondary`,onClick:()=>{D(!1),k(``),L(null)},children:t(`mfa.cancel`)}),(0,V.jsxs)(U,{onClick:ce,disabled:P||!O,children:[P?(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}):null,t(`mfa.regenerate`)]})]})]})}),m&&f.length>0&&(0,V.jsx)(ia,{open:!0,onClose:()=>{h(!1),p([])},variant:`center`,size:`md`,title:t(`mfa.setup.newBackupCodes`),children:(0,V.jsx)(ia.Body,{children:(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`div`,{className:`p-4 bg-yellow-50 dark:bg-yellow-900/20 rounded-lg border border-yellow-200 dark:border-yellow-800`,children:(0,V.jsx)(`p`,{className:`text-sm text-yellow-800 dark:text-yellow-200`,children:t(`mfa.setup.newBackupCodesImportant`)})}),(0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-2 font-mono text-sm bg-gray-50 dark:bg-gray-900 p-4 rounded`,children:f.map((e,t)=>(0,V.jsx)(`div`,{className:`p-2 bg-white dark:bg-gray-800 rounded text-center`,children:e},t))}),(0,V.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,V.jsxs)(U,{variant:`secondary`,onClick:()=>fe(f.join(`
736
- `)),children:[(0,V.jsx)(oe,{className:`h-4 w-4 mr-2`}),t(`mfa.copyAll`)]}),(0,V.jsx)(U,{onClick:()=>{h(!1),p([])},children:t(`mfa.done`)})]})]})})}),A&&(0,V.jsxs)(ia,{open:!0,onClose:()=>{j(!1),N(``),L(null)},variant:`center`,size:`sm`,ariaLabel:t(`mfa.disableDialog.all`),children:[(0,V.jsx)(ia.Header,{children:(0,V.jsx)(`h3`,{className:`text-lg font-semibold text-red-600 dark:text-red-400`,children:t(`mfa.disableDialog.all`)})}),(0,V.jsxs)(ia.Body,{children:[(0,V.jsx)(`div`,{className:`p-4 mb-4 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-800 dark:text-red-200`,children:t(`mfa.disableDialog.allWarning`)})}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:t(`mfa.disableDialog.confirmPassword`)}),I&&(0,V.jsx)(`div`,{className:`p-3 mb-4 bg-red-50 dark:bg-red-900/20 rounded text-sm text-red-600 dark:text-red-400`,children:I}),(0,V.jsx)(h1,{type:`password`,value:M,onChange:e=>N(e.target.value),placeholder:`Password`,className:`mb-4`}),(0,V.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,V.jsx)(U,{variant:`secondary`,onClick:()=>{j(!1),N(``),L(null)},children:t(`mfa.cancel`)}),(0,V.jsxs)(U,{variant:`danger`,onClick:se,disabled:P||!M,children:[P?(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}):null,t(`mfa.disableDialog.all`)]})]})]})]})]})}function m0(e){let t=new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}function h0(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,`=`),i=atob(r),a=new ArrayBuffer(i.length),o=new Uint8Array(a);for(let e=0;e<i.length;e++)o[e]=i.charCodeAt(e);return a}function g0(){return _0.stubThis(globalThis?.PublicKeyCredential!==void 0&&typeof globalThis.PublicKeyCredential==`function`)}var _0={stubThis:e=>e};function v0(e){let{id:t}=e;return{...e,id:h0(t),transports:e.transports}}function y0(e){return e===`localhost`||/^((xn--[a-z0-9-]+|[a-z0-9]+(-[a-z0-9]+)*)\.)+([a-z]{2,}|xn--[a-z0-9-]+)$/i.test(e)}var b0=class extends Error{constructor({message:e,code:t,cause:n,name:r}){super(e,{cause:n}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=r??n.name,this.code=t}};function x0({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new b0({message:`Registration ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`ConstraintError`){if(n.authenticatorSelection?.requireResidentKey===!0)return new b0({message:`Discoverable credentials were required but no available authenticator supported it`,code:`ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT`,cause:e});if(t.mediation===`conditional`&&n.authenticatorSelection?.userVerification===`required`)return new b0({message:`User verification was required during automatic registration but it could not be performed`,code:`ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE`,cause:e});if(n.authenticatorSelection?.userVerification===`required`)return new b0({message:`User verification was required but no available authenticator supported it`,code:`ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT`,cause:e})}else if(e.name===`InvalidStateError`)return new b0({message:`The authenticator was previously registered`,code:`ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED`,cause:e});else if(e.name===`NotAllowedError`)return new b0({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`NotSupportedError`)return n.pubKeyCredParams.filter(e=>e.type===`public-key`).length===0?new b0({message:`No entry in pubKeyCredParams was of type "public-key"`,code:`ERROR_MALFORMED_PUBKEYCREDPARAMS`,cause:e}):new b0({message:`No available authenticator supported any of the specified pubKeyCredParams algorithms`,code:`ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG`,cause:e});else if(e.name===`SecurityError`){let t=globalThis.location.hostname;if(!y0(t))return new b0({message:`${globalThis.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rp.id!==t)return new b0({message:`The RP ID "${n.rp.id}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`TypeError`){if(n.user.id.byteLength<1||n.user.id.byteLength>64)return new b0({message:`User ID was not between 1 and 64 characters`,code:`ERROR_INVALID_USER_ID_LENGTH`,cause:e})}else if(e.name===`UnknownError`)return new b0({message:`The authenticator was unable to process the specified options, or could not create a new credential`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}var S0=new class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){let e=Error(`Cancelling existing WebAuthn API call for new one`);e.name=`AbortError`,this.controller.abort(e)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=Error(`Manually cancelling existing WebAuthn API call`);e.name=`AbortError`,this.controller.abort(e),this.controller=void 0}}},C0=[`cross-platform`,`platform`];function w0(e){if(e&&!(C0.indexOf(e)<0))return e}async function T0(e){!e.optionsJSON&&e.challenge&&(console.warn(`startRegistration() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.`),e={optionsJSON:e});let{optionsJSON:t,useAutoRegister:n=!1}=e;if(!g0())throw Error(`WebAuthn is not supported in this browser`);let r={...t,challenge:h0(t.challenge),user:{...t.user,id:h0(t.user.id)},excludeCredentials:t.excludeCredentials?.map(v0)},i={};n&&(i.mediation=`conditional`),i.publicKey=r,i.signal=S0.createNewAbortSignal();let a;try{a=await navigator.credentials.create(i)}catch(e){throw x0({error:e,options:i})}if(!a)throw Error(`Registration was not completed`);let{id:o,rawId:s,response:c,type:l}=a,u;typeof c.getTransports==`function`&&(u=c.getTransports());let d;if(typeof c.getPublicKeyAlgorithm==`function`)try{d=c.getPublicKeyAlgorithm()}catch(e){E0(`getPublicKeyAlgorithm()`,e)}let f;if(typeof c.getPublicKey==`function`)try{let e=c.getPublicKey();e!==null&&(f=m0(e))}catch(e){E0(`getPublicKey()`,e)}let p;if(typeof c.getAuthenticatorData==`function`)try{p=m0(c.getAuthenticatorData())}catch(e){E0(`getAuthenticatorData()`,e)}return{id:o,rawId:m0(s),response:{attestationObject:m0(c.attestationObject),clientDataJSON:m0(c.clientDataJSON),transports:u,publicKeyAlgorithm:d,publicKey:f,authenticatorData:p},type:l,clientExtensionResults:a.getClientExtensionResults(),authenticatorAttachment:w0(a.authenticatorAttachment)}}function E0(e,t){console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${e}. You should report this error to them.\n`,t)}function D0(){if(!g0())return O0.stubThis(new Promise(e=>e(!1)));let e=globalThis.PublicKeyCredential;return e?.isConditionalMediationAvailable===void 0?O0.stubThis(new Promise(e=>e(!1))):O0.stubThis(e.isConditionalMediationAvailable())}var O0={stubThis:e=>e};function k0({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new b0({message:`Authentication ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`NotAllowedError`)return new b0({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`SecurityError`){let t=globalThis.location.hostname;if(!y0(t))return new b0({message:`${globalThis.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rpId!==t)return new b0({message:`The RP ID "${n.rpId}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`UnknownError`)return new b0({message:`The authenticator was unable to process the specified options, or could not create a new assertion signature`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}async function A0(e){!e.optionsJSON&&e.challenge&&(console.warn(`startAuthentication() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.`),e={optionsJSON:e});let{optionsJSON:t,useBrowserAutofill:n=!1,verifyBrowserAutofillInput:r=!0}=e;if(!g0())throw Error(`WebAuthn is not supported in this browser`);let i;t.allowCredentials?.length!==0&&(i=t.allowCredentials?.map(v0));let a={...t,challenge:h0(t.challenge),allowCredentials:i},o={};if(n){if(!await D0())throw Error(`Browser does not support WebAuthn autofill`);if(document.querySelectorAll(`input[autocomplete$='webauthn']`).length<1&&r)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');o.mediation=`conditional`,a.allowCredentials=[]}o.publicKey=a,o.signal=S0.createNewAbortSignal();let s;try{s=await navigator.credentials.get(o)}catch(e){throw k0({error:e,options:o})}if(!s)throw Error(`Authentication was not completed`);let{id:c,rawId:l,response:u,type:d}=s,f;return u.userHandle&&(f=m0(u.userHandle)),{id:c,rawId:m0(l),response:{authenticatorData:m0(u.authenticatorData),clientDataJSON:m0(u.clientDataJSON),signature:m0(u.signature),userHandle:f},type:d,clientExtensionResults:s.getClientExtensionResults(),authenticatorAttachment:w0(s.authenticatorAttachment)}}var j0=Fr(`PasskeyRegistration`);function M0({onSuccess:e,onError:t,disabled:n,className:r=``}){let{t:i}=H(`studio`),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(``),[l,u]=(0,B.useState)(!1);return l?(0,V.jsxs)(`div`,{className:`space-y-3 ${r}`,children:[(0,V.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:i(`passkey.register.namePlaceholder`,`e.g., MacBook Pro Touch ID`),className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent`,disabled:a}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(U,{type:`button`,onClick:async()=>{o(!0);try{j0.debug(`Requesting passkey registration options`);let n=await W.post(`/auth/passkey/register/options`,{friendlyName:s||void 0});if(!n.success||!n.data){let e=n.error?.message||i(`passkey.register.optionsFailed`,`Failed to start passkey registration`);j0.error(`Failed to get registration options`,{error:e}),t?.(e);return}let{sessionId:r,...a}=n.data;j0.debug(`Received registration options`,{sessionId:r.substring(0,8)});let o;try{o=await T0({optionsJSON:a}),j0.debug(`Browser registration completed`)}catch(e){e.name===`NotAllowedError`?(j0.info(`User cancelled passkey registration`),t?.(i(`passkey.register.cancelled`,`Registration was cancelled`))):e.name===`InvalidStateError`?(j0.warn(`Passkey already registered`),t?.(i(`passkey.register.alreadyRegistered`,`This passkey is already registered`))):e.name===`NotSupportedError`?(j0.warn(`Passkeys not supported in this browser`),t?.(i(`passkey.register.notSupported`,`Passkeys are not supported in this browser`))):(j0.error(`Browser registration failed`,{error:e.message}),t?.(e.message||i(`passkey.register.failed`,`Passkey registration failed`)));return}j0.debug(`Verifying registration with server`);let l=await W.post(`/auth/passkey/register/verify`,{sessionId:r,credential:o,friendlyName:s||void 0});if(!l.success||!l.data){let e=l.error?.message||i(`passkey.register.verifyFailed`,`Passkey registration verification failed`);j0.error(`Registration verification failed`,{error:e}),t?.(e);return}j0.info(`Passkey registered successfully`,{credentialId:l.data.credential.id.substring(0,8)}),c(``),u(!1),e?.(l.data.credential)}catch(e){let n=e instanceof Error?e.message:i(`passkey.register.failed`,`Passkey registration failed`);j0.error(`Passkey registration error`,{error:n}),t?.(n)}finally{o(!1)}},disabled:n||a,variant:`primary`,className:`flex-1`,children:a?(0,V.jsx)(Ao,{size:`sm`}):i(`passkey.register.continue`,`Continue`)}),(0,V.jsx)(U,{type:`button`,onClick:()=>{u(!1),c(``)},disabled:a,variant:`outline`,children:i(`common.cancel`,`Cancel`)})]})]}):(0,V.jsxs)(U,{type:`button`,onClick:()=>u(!0),disabled:n||a,variant:`outline`,className:`flex items-center gap-2 ${r}`,children:[(0,V.jsx)(N0,{className:`w-4 h-4`}),i(`passkey.register.addPasskey`,`Add Passkey`)]})}function N0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:(0,V.jsx)(`path`,{fillRule:`evenodd`,d:`M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z`,clipRule:`evenodd`})})}var P0=Fr(`PasskeyManager`);function F0({className:e=``}){let{t}=H(`studio`),[n,r]=(0,B.useState)([]),[i,a]=(0,B.useState)(!0),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(null),[f,p]=(0,B.useState)(``),[m,h]=(0,B.useState)(null),g=(0,B.useCallback)(async()=>{try{let e=await W.get(`/auth/passkey/status`);return e.success&&e.data?(s(e.data.enabled),e.data.enabled):(s(!1),!1)}catch(e){return P0.warn(`Failed to check passkey status`,{error:e}),s(!1),!1}},[]),_=(0,B.useCallback)(async()=>{a(!0),l(null);try{let e=await W.get(`/auth/passkey/credentials`);e.success&&e.data?(r(e.data.credentials),P0.debug(`Loaded passkey credentials`,{count:e.data.credentials.length})):l(e.error?.message||t(`passkey.manager.loadFailed`,`Failed to load passkeys`))}catch(e){let n=e instanceof Error?e.message:t(`passkey.manager.loadFailed`,`Failed to load passkeys`);P0.error(`Failed to load credentials`,{error:n}),l(n)}finally{a(!1)}},[t]);(0,B.useEffect)(()=>{(async()=>{await g()?await _():a(!1)})()},[g,_]);let v=async e=>{if(!f.trim()){d(null);return}try{let n=await W.patch(`/auth/passkey/credentials/${e}`,{friendlyName:f.trim()});n.success?(P0.info(`Renamed passkey credential`),r(t=>t.map(t=>t.id===e?{...t,friendlyName:f.trim()}:t)),d(null),p(``)):(P0.error(`Failed to rename credential`,{error:n.error?.message}),l(n.error?.message||t(`passkey.manager.renameFailed`,`Failed to rename passkey`)))}catch(e){let n=e instanceof Error?e.message:t(`passkey.manager.renameFailed`,`Failed to rename passkey`);P0.error(`Rename error`,{error:n}),l(n)}},y=async e=>{try{h(e);let n=await W.delete(`/auth/passkey/credentials/${e}`);n.success?(P0.info(`Deleted passkey credential`),r(t=>t.filter(t=>t.id!==e))):(P0.error(`Failed to delete credential`,{error:n.error?.message}),l(n.error?.message||t(`passkey.manager.deleteFailed`,`Failed to delete passkey`)))}catch(e){let n=e instanceof Error?e.message:t(`passkey.manager.deleteFailed`,`Failed to delete passkey`);P0.error(`Delete error`,{error:n}),l(n)}finally{h(null)}},b=e=>{r(t=>[...t,e]),l(null)},x=e=>{l(e)},S=e=>{try{return new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}catch{return e}},C=(e,t)=>t?(0,V.jsx)(L0,{className:`w-5 h-5 text-blue-500`}):(0,V.jsx)(I0,{className:`w-5 h-5 text-gray-500 dark:text-gray-400`});return i?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-8 ${e}`,children:(0,V.jsx)(Ao,{})}):o===!1?(0,V.jsx)(`div`,{className:`space-y-4 ${e}`,children:(0,V.jsxs)(`div`,{className:`text-center py-6`,children:[(0,V.jsx)(I0,{className:`w-12 h-12 mx-auto text-gray-400 dark:text-gray-500 mb-3`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-2`,children:t(`passkey.manager.notConfigured`,`Passkey authentication is not enabled`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-500`,children:t(`passkey.manager.notConfiguredDescription`,`Passkey authentication needs to be configured by an administrator in the server settings.`)})]})}):(0,V.jsxs)(`div`,{className:`space-y-4 ${e}`,children:[c&&(0,V.jsx)(`div`,{className:`p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-md`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:c})}),n.length===0?(0,V.jsxs)(`div`,{className:`text-center py-6`,children:[(0,V.jsx)(I0,{className:`w-12 h-12 mx-auto text-gray-400 dark:text-gray-500 mb-3`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-4`,children:t(`passkey.manager.noPasskeys`,`You haven't set up any passkeys yet.`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-500 mb-4`,children:t(`passkey.manager.description`,`Passkeys let you sign in without a password using your fingerprint, face, or security key.`)})]}):(0,V.jsx)(`ul`,{className:`space-y-3`,children:n.map(e=>(0,V.jsxs)(`li`,{className:`flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-gray-700`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[C(e.deviceType,e.backedUp),(0,V.jsxs)(`div`,{children:[u===e.id?(0,V.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),onBlur:()=>v(e.id),onKeyDown:t=>{t.key===`Enter`&&v(e.id),t.key===`Escape`&&(d(null),p(``))},className:`px-2 py-1 text-sm border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-800 text-gray-900 dark:text-white`,autoFocus:!0}):(0,V.jsx)(`p`,{className:`font-medium text-gray-900 dark:text-white`,children:e.friendlyName||t(`passkey.manager.unnamed`,`Passkey`)}),(0,V.jsxs)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:[t(`passkey.manager.added`,`Added`),` `,S(e.createdAt),e.lastUsedAt&&(0,V.jsxs)(V.Fragment,{children:[` · `,t(`passkey.manager.lastUsed`,`Last used`),` `,S(e.lastUsedAt)]})]}),(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:e.backedUp?t(`passkey.manager.synced`,`Synced across devices`):t(`passkey.manager.deviceOnly`,`This device only`)})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u!==e.id&&(0,V.jsx)(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{d(e.id),p(e.friendlyName||``)},children:(0,V.jsx)(R0,{className:`w-4 h-4`})}),(0,V.jsx)(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>y(e.id),disabled:m===e.id,className:`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:m===e.id?(0,V.jsx)(Ao,{size:`sm`}):(0,V.jsx)(z0,{className:`w-4 h-4`})})]})]},e.id))}),(0,V.jsx)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(M0,{onSuccess:b,onError:x})})]})}function I0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`path`,{d:`M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4`})})}function L0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,V.jsx)(`path`,{d:`M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z`})})}function R0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,V.jsx)(`path`,{d:`M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z`})})}function z0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,V.jsx)(`path`,{fillRule:`evenodd`,d:`M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z`,clipRule:`evenodd`})})}var B0=Fr(`UserPreferences`);function V0(){let{user:e}=ri(),{t}=H(`studio`),{locale:n,setLocale:r,locales:i,getLocaleName:a}=xr(),o=za({page:`user-preferences`,title:t(`preferences.title`)}),s=pa()?.utils?.showToast||((e,t)=>console.log(`Toast: ${t} - ${e}`)),[c,l]=(0,B.useState)({theme:`system`,language:n,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,emailNotifications:!0,pushNotifications:!1}),[u,d]=(0,B.useState)(!1),[f,p]=(0,B.useState)(null);return(0,B.useEffect)(()=>{o.configure({page:`user-preferences`,title:t(`preferences.title`),defaultVisible:!1})},[o.configure,t]),(0,B.useEffect)(()=>{e&&l(t=>({...t,...e.preferences}))},[e]),(0,V.jsx)(`div`,{className:`p-6`,children:(0,V.jsxs)(`div`,{className:`max-w-2xl space-y-8`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:t(`preferences.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:t(`preferences.subtitle`)})]}),f&&(0,V.jsx)(`div`,{className:`p-4 rounded-lg ${f.type===`success`?`bg-green-50 text-green-800 border border-green-200 dark:bg-green-900/20 dark:text-green-400 dark:border-green-800`:`bg-red-50 text-red-800 border border-red-200 dark:bg-red-900/20 dark:text-red-400 dark:border-red-800`}`,children:f.text}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-3 mb-6`,children:[(0,V.jsx)(Te,{className:`h-6 w-6 text-gray-600 dark:text-gray-400`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:t(`preferences.appearance`)})]}),(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:t(`preferences.theme`)}),(0,V.jsxs)(`select`,{value:c.theme,onChange:e=>l(t=>({...t,theme:e.target.value})),className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:`system`,children:t(`preferences.themeSystem`)}),(0,V.jsx)(`option`,{value:`light`,children:t(`preferences.themeLight`)}),(0,V.jsx)(`option`,{value:`dark`,children:t(`preferences.themeDark`)})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:t(`language.title`)}),(0,V.jsx)(`select`,{value:c.language,onChange:e=>l(t=>({...t,language:e.target.value})),className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:i.map(e=>(0,V.jsx)(`option`,{value:e,children:a(e)},e))}),(0,V.jsxs)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-gray-400`,children:[t(`language.current`),`: `,a(n)]})]})]})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-3 mb-6`,children:[(0,V.jsx)(Le,{className:`h-6 w-6 text-gray-600 dark:text-gray-400`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:t(`preferences.notifications`)})]}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:t(`preferences.emailNotifications`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t(`preferences.emailNotificationsDescription`)})]}),(0,V.jsx)(`input`,{type:`checkbox`,checked:c.emailNotifications,onChange:e=>l(t=>({...t,emailNotifications:e.target.checked})),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 rounded`})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:t(`preferences.pushNotifications`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t(`preferences.pushNotificationsDescription`)})]}),(0,V.jsx)(`input`,{type:`checkbox`,checked:c.pushNotifications,onChange:e=>l(t=>({...t,pushNotifications:e.target.checked})),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 rounded`})]})]})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-3 mb-6`,children:[(0,V.jsx)(he,{className:`h-6 w-6 text-gray-600 dark:text-gray-400`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:t(`preferences.connectedAccounts`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t(`preferences.connectedAccountsDescription`)})]})]}),(0,V.jsx)(r0,{})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-3 mb-6`,children:[(0,V.jsx)(He,{className:`h-6 w-6 text-gray-600 dark:text-gray-400`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:t(`preferences.security`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t(`preferences.securityDescription`)})]})]}),(0,V.jsx)(p0,{onToast:s}),(0,V.jsxs)(`div`,{className:`mt-6 pt-6 border-t border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-white mb-2`,children:t(`preferences.passkeys`,`Passkeys`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mb-4`,children:t(`preferences.passkeysDescription`,`Sign in securely without a password using your fingerprint, face, or security key.`)}),(0,V.jsx)(F0,{})]})]}),(0,V.jsx)(`div`,{className:`flex justify-end`,children:(0,V.jsxs)(U,{onClick:async()=>{d(!0),p(null);try{c.theme&&(c.theme===`system`?document.documentElement.classList.remove(`light`,`dark`):(document.documentElement.classList.remove(`light`,`dark`),document.documentElement.classList.add(c.theme)),localStorage.setItem(`trokky_theme`,c.theme)),c.language&&c.language!==n&&r(c.language),p({type:`success`,text:t(`preferences.saveSuccess`)})}catch(e){B0.error(`Failed to update preferences`,e),p({type:`error`,text:t(`preferences.saveError`)})}finally{d(!1),setTimeout(()=>p(null),3e3)}},disabled:u,children:[u?(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}):null,t(`preferences.savePreferences`)]})})]})})}var H0=Fr(`AuditLogsPage`),U0=25;function W0(){let{t:e}=H(`studio`);za({page:`audit-logs`,title:e(`auditLogs.title`),defaultVisible:!1,defaultPosition:`left`});let[t,n]=(0,B.useState)([]),[r,i]=(0,B.useState)(!0),[a,o]=(0,B.useState)(null),[s,l]=(0,B.useState)(new Set),[u,d]=(0,B.useState)(1),[f,p]=(0,B.useState)(0),[m,h]=(0,B.useState)([]),[g,_]=(0,B.useState)([]),[v,y]=(0,B.useState)(``),[b,x]=(0,B.useState)(``),[S,C]=(0,B.useState)(``),[w,T]=(0,B.useState)(``),[E,D]=(0,B.useState)(!1),[O,k]=(0,B.useState)({});(0,B.useEffect)(()=>{A(),j()},[]),(0,B.useEffect)(()=>{(m.length>0||v)&&N()},[u,v,b,S,m.length]);let A=async()=>{try{let e=await W.get(`/config/structure`);if(e.success&&e.data?.structure){let t=e.data.structure,n=t.items||t,r=e=>{let t=[];for(let n of e)n.schemaType&&t.push(n.schemaType),n.items&&Array.isArray(n.items)&&t.push(...r(n.items));return t};Array.isArray(n)&&h([...new Set(r(n))].sort())}}catch(e){H0.warn(`Failed to load collections`,e)}},j=async()=>{try{let e=await W.get(`/users`);e.success&&e.data?.users&&_(e.data.users)}catch(e){H0.warn(`Failed to load users`,e)}},M=async e=>{if(O[e])return O[e];if(e===`system`)return`System`;try{let t=await W.get(`/users/${e}`);if(t.success&&t.data?.user){let n=t.data.user,r=n.username||n.name||n.email||`User`;return k(t=>({...t,[e]:r})),r}}catch{}return e.startsWith(`user-`)?`User`:e},N=async()=>{i(!0),o(null);try{let e=(u-1)*U0,t=[];if(v){let e=await W.get(`/audit-logs/collections/${v}`,{limit:200,offset:0});e.success&&e.data?.auditLogs&&(t=e.data.auditLogs)}else for(let e of m)try{let n=await W.get(`/audit-logs/collections/${e}`,{limit:100,offset:0});n.success&&n.data?.auditLogs&&t.push(...n.data.auditLogs)}catch{}let r=t;if(b&&(r=r.filter(e=>e.actorId===b)),S&&(r=r.filter(e=>e.operation===S)),w.trim()){let e=w.toLowerCase();r=r.filter(t=>{let n=t.changes?.after,r=t.changes?.before;return(n?.title||n?.name||r?.title||r?.name||``).toLowerCase().includes(e)||t.documentId.toLowerCase().includes(e)||t.collection.toLowerCase().includes(e)})}r.sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime()),p(r.length);let i=r.slice(e,e+U0),a=[...new Set(i.map(e=>e.actorId).filter(Boolean))];for(let e of a)await M(e);let o=i.map(e=>({...e,actorUsername:O[e.actorId]||e.actorUsername}));n(o),H0.info(`Audit logs loaded`,{count:o.length,total:r.length})}catch(e){H0.error(`Failed to load audit logs`,e),o(`Failed to load audit logs`)}finally{i(!1)}},P=(0,B.useCallback)(()=>{d(1),N()},[w]),F=e=>{e.key===`Enter`&&P()},I=()=>{y(``),x(``),C(``),T(``),d(1)},L=e=>{let t=new Set(s);t.has(e)?t.delete(e):t.add(e),l(t)},R=t=>{switch(t){case`create`:return{icon:Ne,text:e(`auditLogs.operations.create`),color:`text-green-600 dark:text-green-400`,bgColor:`bg-green-100 dark:bg-green-900/30`};case`update`:return{icon:ct,text:e(`auditLogs.operations.update`),color:`text-blue-600 dark:text-blue-400`,bgColor:`bg-blue-100 dark:bg-blue-900/30`};case`delete`:return{icon:Be,text:e(`auditLogs.operations.delete`),color:`text-red-600 dark:text-red-400`,bgColor:`bg-red-100 dark:bg-red-900/30`};case`publish`:return{icon:ce,text:e(`auditLogs.operations.publish`),color:`text-purple-600 dark:text-purple-400`,bgColor:`bg-purple-100 dark:bg-purple-900/30`};case`unpublish`:return{icon:ce,text:e(`auditLogs.operations.unpublish`),color:`text-orange-600 dark:text-orange-400`,bgColor:`bg-orange-100 dark:bg-orange-900/30`};case`restore`:return{icon:re,text:e(`auditLogs.operations.restore`),color:`text-indigo-600 dark:text-indigo-400`,bgColor:`bg-indigo-100 dark:bg-indigo-900/30`};default:return{icon:ct,text:t,color:`text-gray-600 dark:text-gray-400`,bgColor:`bg-gray-100 dark:bg-gray-700`}}},te=e=>{try{let t=new Date(e);return{relative:ko(t,{addSuffix:!0}),full:t.toLocaleString()}}catch{return{relative:`Unknown`,full:e}}},ne=e=>{let t=e.changes?.after,n=e.changes?.before;return t?.title||t?.name||n?.title||n?.name||e.documentId},ie=t=>{if(!t.changes?.fields||t.changes.fields.length===0)return null;let n=t.changes.fields;return n.length===1?e(`auditLogs.changedField`,{field:n[0]}):e(`auditLogs.changedFields`,{count:n.length})},ae=Math.ceil(f/U0),oe=v||b||S||w;return(0,V.jsxs)(`div`,{className:`p-6 max-w-7xl mx-auto`,children:[(0,V.jsx)(`div`,{className:`mb-6`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white flex items-center`,children:[(0,V.jsx)(re,{className:`h-7 w-7 mr-3 text-gray-500`}),e(`auditLogs.title`)]}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`auditLogs.subtitle`)})]}),(0,V.jsxs)(`button`,{onClick:()=>N(),disabled:r,className:`flex items-center px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50`,children:[(0,V.jsx)(ke,{className:`h-4 w-4 mr-2 ${r?`animate-spin`:``}`}),e(`auditLogs.refresh`)]})]})}),(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 mb-6`,children:(0,V.jsxs)(`div`,{className:`p-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,V.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,V.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-gray-400`}),(0,V.jsx)(`input`,{type:`text`,placeholder:e(`auditLogs.searchPlaceholder`),value:w,onChange:e=>T(e.target.value),onKeyPress:F,className:`w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 focus:ring-2 focus:ring-primary-500 focus:border-transparent`})]}),(0,V.jsx)(`button`,{onClick:P,className:`px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 font-medium`,children:e(`auditLogs.search`)}),(0,V.jsxs)(`button`,{onClick:()=>D(!E),className:`flex items-center px-4 py-2 border rounded-lg font-medium ${E||oe?`border-primary-500 text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700`}`,children:[(0,V.jsx)(Re,{className:`h-4 w-4 mr-2`}),e(`auditLogs.filters`),oe&&(0,V.jsx)(`span`,{className:`ml-2 px-1.5 py-0.5 text-xs bg-primary-600 text-white rounded-full`,children:[v,b,S].filter(Boolean).length})]})]}),E&&(0,V.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,V.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`auditLogs.collection`)}),(0,V.jsxs)(`select`,{value:v,onChange:e=>{y(e.target.value),d(1)},className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:``,children:e(`auditLogs.allCollections`)}),m.map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`auditLogs.user`)}),(0,V.jsxs)(`select`,{value:b,onChange:e=>{x(e.target.value),d(1)},className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:``,children:e(`auditLogs.allUsers`)}),g.map(e=>(0,V.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`auditLogs.operation`)}),(0,V.jsxs)(`select`,{value:S,onChange:e=>{C(e.target.value),d(1)},className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:``,children:e(`auditLogs.allOperations`)}),(0,V.jsx)(`option`,{value:`create`,children:e(`auditLogs.operations.create`)}),(0,V.jsx)(`option`,{value:`update`,children:e(`auditLogs.operations.update`)}),(0,V.jsx)(`option`,{value:`delete`,children:e(`auditLogs.operations.delete`)}),(0,V.jsx)(`option`,{value:`publish`,children:e(`auditLogs.operations.publish`)}),(0,V.jsx)(`option`,{value:`unpublish`,children:e(`auditLogs.operations.unpublish`)})]})]})]}),oe&&(0,V.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,V.jsxs)(`button`,{onClick:I,className:`flex items-center text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white`,children:[(0,V.jsx)(tt,{className:`h-4 w-4 mr-1`}),e(`auditLogs.clearFilters`)]})})]})]})}),(0,V.jsx)(`div`,{className:`mb-4 text-sm text-gray-600 dark:text-gray-400`,children:f>0?(0,V.jsx)(V.Fragment,{children:e(`auditLogs.showingResults`,{start:(u-1)*U0+1,end:Math.min(u*U0,f),total:f})}):e(r?`auditLogs.loading`:`auditLogs.noResults`)}),(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden`,children:r&&t.length===0?(0,V.jsxs)(`div`,{className:`flex items-center justify-center py-12`,children:[(0,V.jsx)(Ao,{}),(0,V.jsx)(`span`,{className:`ml-3 text-gray-500 dark:text-gray-400`,children:e(`auditLogs.loading`)})]}):a?(0,V.jsxs)(`div`,{className:`p-6 text-center`,children:[(0,V.jsx)(`p`,{className:`text-red-600 dark:text-red-400`,children:a}),(0,V.jsx)(`button`,{onClick:()=>N(),className:`mt-4 text-primary-600 dark:text-primary-400 hover:underline`,children:e(`auditLogs.tryAgain`)})]}):t.length===0?(0,V.jsxs)(`div`,{className:`p-12 text-center`,children:[(0,V.jsx)(re,{className:`h-12 w-12 mx-auto text-gray-300 dark:text-gray-600 mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`auditLogs.noLogs`)}),oe&&(0,V.jsx)(`button`,{onClick:I,className:`mt-4 text-primary-600 dark:text-primary-400 hover:underline`,children:e(`auditLogs.clearFilters`)})]}):(0,V.jsx)(`div`,{className:`divide-y divide-gray-200 dark:divide-gray-700`,children:t.map(t=>{let n=R(t.operation),r=n.icon,i=te(t.timestamp),a=s.has(t.id),o=ie(t);return(0,V.jsxs)(`div`,{className:`hover:bg-gray-50 dark:hover:bg-gray-750`,children:[(0,V.jsx)(`div`,{className:`p-4`,children:(0,V.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,V.jsx)(`div`,{className:`flex-shrink-0 w-10 h-10 rounded-full flex items-center justify-center ${n.bgColor}`,children:(0,V.jsx)(r,{className:`h-5 w-5 ${n.color}`})}),(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,V.jsx)(`span`,{className:`font-medium ${n.color}`,children:n.text}),(0,V.jsx)(c,{to:`/content/${t.collection}/${t.documentId}`,className:`font-medium text-gray-900 dark:text-white hover:text-primary-600 dark:hover:text-primary-400 truncate`,children:ne(t)}),(0,V.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-400 rounded`,children:t.collection})]}),(0,V.jsxs)(`div`,{className:`mt-1 flex items-center gap-4 text-sm text-gray-500 dark:text-gray-400`,children:[(0,V.jsxs)(`span`,{className:`flex items-center`,children:[(0,V.jsx)(Ke,{className:`h-4 w-4 mr-1`}),O[t.actorId]||t.actorUsername||t.actorId]}),(0,V.jsx)(`span`,{title:i.full,children:i.relative}),o&&(0,V.jsx)(`span`,{className:`text-gray-400 dark:text-gray-500`,children:o})]})]}),t.changes&&(t.changes.before||t.changes.after)&&(0,V.jsx)(`button`,{onClick:()=>L(t.id),className:`flex-shrink-0 p-2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700`,title:e(a?`auditLogs.hideDetails`:`auditLogs.showDetails`),children:a?(0,V.jsx)(ye,{className:`h-5 w-5`}):(0,V.jsx)(z,{className:`h-5 w-5`})})]})}),a&&t.changes&&(0,V.jsx)(`div`,{className:`px-4 pb-4 ml-14`,children:(0,V.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-900 rounded-lg p-4 border border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(w$,{before:t.changes.before,after:t.changes.after,operation:t.operation}),(0,V.jsx)(`div`,{className:`mt-4 pt-4 border-t border-gray-200 dark:border-gray-700`,children:(0,V.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 text-xs text-gray-500 dark:text-gray-400`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e(`auditLogs.technical.revision`)}),` `,t.revision]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e(`auditLogs.technical.documentId`)}),` `,t.documentId]}),t.ipAddress&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e(`auditLogs.technical.ip`)}),` `,t.ipAddress]}),t.actorType&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e(`auditLogs.technical.actorType`)}),` `,t.actorType]})]})})]})})]},t.id)})})}),ae>1&&(0,V.jsxs)(`div`,{className:`mt-6 flex items-center justify-between`,children:[(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`auditLogs.page`,{current:u,total:ae})}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(`button`,{onClick:()=>d(e=>Math.max(1,e-1)),disabled:u===1,className:`flex items-center px-3 py-2 text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,V.jsx)(be,{className:`h-4 w-4 mr-1`}),e(`auditLogs.previous`)]}),(0,V.jsxs)(`button`,{onClick:()=>d(e=>Math.min(ae,e+1)),disabled:u===ae,className:`flex items-center px-3 py-2 text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed`,children:[e(`auditLogs.next`),(0,V.jsx)(z,{className:`h-4 w-4 ml-1`})]})]})]})]})}function G0(){let{t:e}=H(`studio`);return(0,V.jsx)(`div`,{className:`min-h-full flex items-center justify-center p-6`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`text-6xl font-bold text-gray-300 dark:text-gray-600 mb-4`,children:`404`}),(0,V.jsx)(`h1`,{className:`text-2xl font-semibold text-gray-900 dark:text-white mb-2`,children:e(`notFound.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:e(`notFound.message`)}),(0,V.jsx)(U,{asChild:!0,children:(0,V.jsxs)(c,{to:`/`,children:[(0,V.jsx)(ze,{className:`h-4 w-4 mr-2`}),e(`notFound.goToDashboard`)]})})]})})}function K0(){return window.TROKKY_CONFIG?.basePath||``}function q0(e){return`${K0()}${e.startsWith(`/`)?e:`/${e}`}`}function J0(e){window.location.href=q0(e)}var Y0=3e4,X0=!1;function Z0(){if(X0)return;X0=!0;let e={en:{auth:{oauth:{notCompleted:`Sign-in could not be completed. Please try again.`}}},fr:{auth:{oauth:{notCompleted:`La connexion n'a pas pu aboutir. Veuillez réessayer.`}}}},t=yr();for(let n of ur){let r=e[n];r&&t.addResourceBundle(n,`studio`,r,!0,!1)}}function Q0({onLoginSuccess:e}){Z0();let{t}=H(`studio`),[n,r]=(0,B.useState)(`processing`),[i,a]=(0,B.useState)(null),[o,s]=(0,B.useState)(null),c=(0,B.useRef)(!1);(0,B.useEffect)(()=>{if(!c.current)try{if(!sessionStorage.getItem(`oauth_state`)){if(Ar.getToken()){c.current=!0,r(`success`),s(t(`auth.oauth.loginSuccess`)),setTimeout(()=>{e()},100);return}c.current=!0,r(`error`),a(t(`auth.oauth.notCompleted`));return}c.current=!0,l()}catch{c.current=!0,r(`error`),a(t(`auth.oauth.notCompleted`))}},[]);let l=async()=>{let n=new AbortController,i=setTimeout(()=>n.abort(),Y0);try{let i=new URLSearchParams(window.location.search),a=i.get(`code`),o=i.get(`state`);if(i.get(`error`)){let e=i.get(`error_description`)||`Authentication was denied`;throw Error(e)}if(!a||!o)throw Error(`Missing authorization code or state parameter`);let c=sessionStorage.getItem(`oauth_state`),l=sessionStorage.getItem(`oauth_code_verifier`),u=sessionStorage.getItem(`oauth_mode`)||`login`;if(o!==c)throw Error(`Invalid state parameter. This may be a security issue.`);if(!l)throw Error(`Missing code verifier. Please try again.`);let d=$0(),f=await W.post(`/auth/oauth/google/callback`,{code:a,state:o,codeVerifier:l,mode:u,deviceId:d},{signal:n.signal});if(sessionStorage.removeItem(`oauth_state`),sessionStorage.removeItem(`oauth_code_verifier`),sessionStorage.removeItem(`oauth_mode`),f.success&&f.data){if(u===`login`){if(f.data.requiresMFA&&f.data.mfaToken){sessionStorage.setItem(`oauth_mfa_token`,f.data.mfaToken),sessionStorage.setItem(`oauth_mfa_methods`,JSON.stringify(f.data.methods||[])),r(`success`),s(t(`auth.oauth.mfaRequired`)),setTimeout(()=>{window.location.href=K0()+`/?mfa=verify`},500);return}if(f.data.requiresMFASetup&&f.data.setupToken){sessionStorage.setItem(`oauth_mfa_setup_token`,f.data.setupToken),sessionStorage.setItem(`oauth_mfa_allowed_methods`,JSON.stringify(f.data.allowedMethods||[])),sessionStorage.setItem(`oauth_mfa_message`,f.data.message||`MFA setup required`),r(`success`),s(t(`auth.oauth.mfaSetupRequired`)),setTimeout(()=>{window.location.href=K0()+`/?mfa=setup`},500);return}let{token:n,refreshToken:i,user:a}=f.data;if(n&&a)Ar.persist(n,i),r(`success`),s(t(`auth.oauth.loginSuccess`)),setTimeout(()=>{e()},500);else throw Error(t(`auth.oauth.invalidResponse`))}else r(`success`),s(f.data.message||`${t(`auth.oauth.accountLinked`)} (${f.data.provider?.email})`),setTimeout(()=>{window.location.href=K0()+`/user/preferences`},2e3)}else throw Error(f.error?.message||`OAuth callback failed`)}catch(e){console.error(`OAuth callback error:`,e);let i=n.signal.aborted;r(`error`),a(i?t(`auth.oauth.notCompleted`):e instanceof Error?e.message:`An unexpected error occurred`),sessionStorage.removeItem(`oauth_state`),sessionStorage.removeItem(`oauth_code_verifier`),sessionStorage.removeItem(`oauth_mode`)}finally{clearTimeout(i)}};return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsx)(`div`,{className:`w-full max-w-sm`,children:(0,V.jsxs)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl text-center`,children:[n===`processing`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`lg`,className:`mx-auto mb-4`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white mb-2`,children:t(`auth.oauth.processing`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:t(`auth.oauth.completingAuth`)})]}),n===`success`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{className:`w-16 h-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-8 h-8 text-green-600 dark:text-green-400`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white mb-2`,children:t(`auth.oauth.success`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:o})]}),n===`error`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{className:`w-16 h-16 mx-auto mb-4 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-8 h-8 text-red-600 dark:text-red-400`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white mb-2`,children:t(`auth.oauth.failed`)}),(0,V.jsx)(`p`,{className:`text-red-600 dark:text-red-400 mb-4`,children:i}),(0,V.jsx)(`button`,{onClick:()=>{window.location.href=K0()+`/`},className:`px-6 py-2 bg-gray-900 dark:bg-white text-white dark:text-gray-900 rounded-lg font-medium hover:bg-gray-800 dark:hover:bg-gray-100 transition-colors`,children:t(`auth.oauth.returnToLogin`)})]})]})})})}function $0(){let e=localStorage.getItem(`trokky_device_id`);if(e)return e;let t=crypto.randomUUID();return localStorage.setItem(`trokky_device_id`,t),t}function e2(){let{t:e}=H(`studio`),[t]=p(),n=r(),i=t.get(`code`),[a,o]=(0,B.useState)(`loading`),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1);(0,B.useEffect)(()=>{if(!i){o(`error`),u(e(`auth.device.noCode`));return}m()},[i]);let m=async()=>{try{let t=await W.get(`/auth/device/verify?code=${i}`);if(t.success&&t.data)c(t.data),o(`pending`);else{o(`error`);let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.device.fetchError`);u(n)}}catch(t){o(`error`);let n=t?.message||e(`auth.device.connectError`);u(n)}},h=async()=>{if(i){f(!0);try{let t=await W.post(`/auth/device/verify`,{user_code:i,action:`authorize`});if(t.success)o(`authorized`);else{let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.device.authError`);u(n),o(`error`)}}catch(t){let n=t?.message||e(`auth.device.authError`);u(n),o(`error`)}finally{f(!1)}}},g=async()=>{if(i){f(!0);try{let t=await W.post(`/auth/device/verify`,{user_code:i,action:`deny`});if(t.success)o(`denied`);else{let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.device.denyError`);u(n),o(`error`)}}catch(t){let n=t?.message||e(`auth.device.denyError`);u(n),o(`error`)}finally{f(!1)}}},_=t=>t.split(` `).filter(Boolean).map(t=>{switch(t){case`openid`:return e(`auth.device.scopes.openid`);case`profile`:return e(`auth.device.scopes.profile`);case`content:read`:return e(`auth.device.scopes.contentRead`);case`content:write`:return e(`auth.device.scopes.contentWrite`);case`content:delete`:return e(`auth.device.scopes.contentDelete`);case`media:read`:return e(`auth.device.scopes.mediaRead`);case`media:write`:return e(`auth.device.scopes.mediaWrite`);case`offline_access`:return e(`auth.device.scopes.offlineAccess`);default:return t}});return(0,V.jsx)(`div`,{className:`min-h-screen bg-gray-100 dark:bg-gray-900 flex items-center justify-center p-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md bg-white dark:bg-gray-800 rounded-xl shadow-lg p-8`,children:[(0,V.jsx)(`div`,{className:`text-center mb-6`,children:(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`auth.device.pageTitle`)})}),(()=>{switch(a){case`loading`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`p`,{className:`mt-4 text-gray-600 dark:text-gray-400`,children:e(`auth.device.loading`)})]});case`pending`:return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,V.jsx)(`div`,{className:`w-16 h-16 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(_e,{className:`w-8 h-8 text-blue-600 dark:text-blue-400`})})}),(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.authorizeDevice`)}),(0,V.jsxs)(`p`,{className:`mt-2 text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(`span`,{className:`font-mono font-bold text-lg text-blue-600 dark:text-blue-400`,children:s?.clientName||s?.clientId||`Trokky CLI`}),` `,e(`auth.device.requestingAccess`)]})]}),(0,V.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 rounded-lg p-4`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`auth.device.deviceCode`)}),(0,V.jsx)(`p`,{className:`font-mono text-2xl font-bold text-center text-gray-900 dark:text-white tracking-wider`,children:i})]}),s?.scopes&&s.scopes.length>0&&(0,V.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 rounded-lg p-4`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:e(`auth.device.allowApplication`)}),(0,V.jsx)(`ul`,{className:`space-y-2`,children:_(s.scopes.join(` `)).map((e,t)=>(0,V.jsxs)(`li`,{className:`flex items-center text-sm text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(Ae,{className:`w-4 h-4 mr-2 text-green-500`}),e]},t))})]}),(0,V.jsxs)(`div`,{className:`flex gap-3`,children:[(0,V.jsx)(U,{variant:`secondary`,className:`flex-1`,onClick:g,disabled:d,children:e(`auth.device.deny`)}),(0,V.jsx)(U,{variant:`primary`,className:`flex-1`,onClick:h,disabled:d,children:d?(0,V.jsx)(Ao,{size:`sm`}):e(`auth.device.authorize`)})]})]});case`authorized`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(Ae,{className:`w-10 h-10 text-green-600 dark:text-green-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.authorized`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:e(`auth.device.authorizedMessage`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:()=>window.close(),children:e(`auth.device.closeWindow`)})]});case`denied`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(We,{className:`w-10 h-10 text-red-600 dark:text-red-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.denied`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:e(`auth.device.deniedMessage`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:()=>window.close(),children:e(`auth.device.closeWindow`)})]});case`expired`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-yellow-100 dark:bg-yellow-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(We,{className:`w-10 h-10 text-yellow-600 dark:text-yellow-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.expired`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:e(`auth.device.expiredMessage`)})]});case`error`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(We,{className:`w-10 h-10 text-red-600 dark:text-red-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.error`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:l||e(`common.error`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:()=>n(`/`),children:e(`auth.device.returnToStudio`)})]})}})()]})})}function t2(){let{t:e}=H(`studio`),[t]=p(),n=r(),[i,a]=(0,B.useState)(`loading`),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(!1),f=t.get(`client_id`),m=t.get(`redirect_uri`),h=t.get(`response_type`),g=t.get(`scope`),_=t.get(`state`),v=t.get(`code_challenge`),y=t.get(`code_challenge_method`);(0,B.useEffect)(()=>{if(!f||!m||!h||!_||!v){a(`error`),l(e(`auth.authorize.missingParams`));return}b()},[f,m,h,g,_,v]);let b=async()=>{try{let t=new URLSearchParams;t.set(`response_type`,h||``),t.set(`client_id`,f||``),t.set(`redirect_uri`,m||``),g&&t.set(`scope`,g),t.set(`state`,_||``),t.set(`code_challenge`,v||``),t.set(`code_challenge_method`,y||`S256`);let n=await W.get(`/auth/authorize?${t.toString()}`);if(n.success&&n.data)s(n.data),n.data.hasExistingConsent?await x(n.data):a(`pending`);else{a(`error`);let t=typeof n.error==`string`?n.error:n.error?.message||e(`auth.authorize.invalidRequest`);l(t)}}catch(t){a(`error`);let n=t?.message||e(`auth.authorize.validateError`);l(n)}},x=async e=>{try{let t=await W.post(`/auth/authorize`,{action:`approve`,client_id:e.client.id,redirect_uri:e.redirectUri,scopes:e.scopes,state:e.state,code_challenge:e.codeChallenge});t.success&&t.data?.redirectUrl?window.location.href=t.data.redirectUrl:a(`pending`)}catch{a(`pending`)}},S=async()=>{if(o){d(!0);try{let t=await W.post(`/auth/authorize`,{action:`approve`,client_id:o.client.id,redirect_uri:o.redirectUri,scopes:o.scopes,state:o.state,code_challenge:o.codeChallenge});if(t.success&&t.data?.redirectUrl)a(`redirecting`),window.location.href=t.data.redirectUrl;else{let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.authorize.authFailed`);l(n),a(`error`)}}catch(t){let n=t?.message||e(`auth.authorize.authFailed`);l(n),a(`error`)}finally{d(!1)}}},C=async()=>{if(o){d(!0);try{let t=await W.post(`/auth/authorize`,{action:`deny`,client_id:o.client.id,redirect_uri:o.redirectUri,scopes:o.scopes,state:o.state,code_challenge:o.codeChallenge});if(t.success&&t.data?.redirectUrl)a(`redirecting`),window.location.href=t.data.redirectUrl;else{let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.authorize.denyFailed`);l(n),a(`error`)}}catch(t){let n=t?.message||e(`auth.authorize.denyFailed`);l(n),a(`error`)}finally{d(!1)}}},w=t=>{switch(t){case`openid`:return e(`auth.device.scopes.openid`);case`profile`:return e(`auth.device.scopes.profile`);case`content:read`:return e(`auth.device.scopes.contentRead`);case`content:write`:return e(`auth.device.scopes.contentWrite`);case`content:delete`:return e(`auth.device.scopes.contentDelete`);case`media:read`:return e(`auth.device.scopes.mediaRead`);case`media:write`:return e(`auth.device.scopes.mediaWrite`);case`offline_access`:return e(`auth.device.scopes.offlineAccess`);default:return t}};return(0,V.jsx)(`div`,{className:`min-h-screen bg-gray-100 dark:bg-gray-900 flex items-center justify-center p-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md bg-white dark:bg-gray-800 rounded-xl shadow-lg p-8`,children:[(0,V.jsx)(`div`,{className:`text-center mb-6`,children:(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`auth.authorize.pageTitle`)})}),(()=>{switch(i){case`loading`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`p`,{className:`mt-4 text-gray-600 dark:text-gray-400`,children:e(`auth.authorize.validating`)})]});case`pending`:return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,V.jsx)(`div`,{className:`w-16 h-16 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(He,{className:`w-8 h-8 text-blue-600 dark:text-blue-400`})})}),(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.authorize.authorizeApp`)}),(0,V.jsxs)(`p`,{className:`mt-2 text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(`span`,{className:`font-semibold text-blue-600 dark:text-blue-400`,children:o?.client.name}),` `,e(`auth.authorize.wantsAccess`)]}),o?.client.description&&(0,V.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-gray-500`,children:o.client.description})]}),o?.scopes&&o.scopes.length>0&&(0,V.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 rounded-lg p-4`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:e(`auth.authorize.allowApplication`)}),(0,V.jsx)(`ul`,{className:`space-y-2`,children:o.scopes.map((e,t)=>(0,V.jsxs)(`li`,{className:`flex items-center text-sm text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(Ae,{className:`w-4 h-4 mr-2 text-green-500 flex-shrink-0`}),w(e)]},t))})]}),o?.client.homepageUrl&&(0,V.jsx)(`div`,{className:`text-center text-sm`,children:(0,V.jsx)(`a`,{href:o.client.homepageUrl,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:e(`auth.authorize.visitWebsite`)})}),(0,V.jsxs)(`div`,{className:`flex gap-3`,children:[(0,V.jsx)(U,{variant:`secondary`,className:`flex-1`,onClick:C,disabled:u,children:e(`auth.authorize.deny`)}),(0,V.jsx)(U,{variant:`primary`,className:`flex-1`,onClick:S,disabled:u,children:u?(0,V.jsx)(Ao,{size:`sm`}):e(`auth.authorize.authorize`)})]}),(0,V.jsx)(`p`,{className:`text-xs text-center text-gray-500 dark:text-gray-500`,children:e(`auth.authorize.consentNote`)})]});case`redirecting`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.authorize.redirecting`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:e(`auth.authorize.redirectingMessage`)})]});case`error`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(We,{className:`w-10 h-10 text-red-600 dark:text-red-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.authorize.error`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:c||e(`common.error`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:()=>n(`/`),children:e(`auth.authorize.returnToStudio`)})]})}})()]})})}var n2=()=>window.TROKKY_CONFIG?.basePath||``,r2=n([{path:`/oauth/callback`,element:(0,V.jsx)(Wa,{children:(0,V.jsx)(Q0,{onLoginSuccess:()=>window.location.href=n2()+`/`})})},{path:`/auth/device`,element:(0,V.jsx)(Wa,{children:(0,V.jsx)(e2,{})})},{path:`/auth/authorize`,element:(0,V.jsx)(Wa,{children:(0,V.jsx)(t2,{})})},{path:`/`,element:(0,V.jsx)(Wa,{children:(0,V.jsx)(Ha,{})}),errorElement:(0,V.jsx)(Wa,{children:(0,V.jsx)(`div`,{children:`Error occurred`})}),children:[{index:!0,element:(0,V.jsx)(Ro,{})},{path:`content`,element:(0,V.jsx)(Q$,{})},{path:`content/:schemaName`,element:(0,V.jsx)(Q$,{})},{path:`content/:schemaName/:documentId`,element:(0,V.jsx)(Q$,{})},{path:`media`,element:(0,V.jsx)(w1,{})},{path:`users`,element:(0,V.jsx)(K1,{})},{path:`users/:userId`,element:(0,V.jsx)(K1,{})},{path:`settings`,element:(0,V.jsx)(e0,{})},{path:`settings/:section`,element:(0,V.jsx)(e0,{})},{path:`user/preferences`,element:(0,V.jsx)(V0,{})},{path:`audit-logs`,element:(0,V.jsx)(W0,{})},{path:`*`,element:(0,V.jsx)(G0,{})}]}],{basename:n2()});function i2(){return(0,V.jsx)(f,{router:r2})}function a2(e){return e=e.replace(/^#/,``),e.length===3&&(e=e.split(``).map(e=>e+e).join(``)),e.length===6?`${parseInt(e.substring(0,2),16)} ${parseInt(e.substring(2,4),16)} ${parseInt(e.substring(4,6),16)}`:null}function o2(e){let t=document.documentElement;if(e.primaryColor){let n=a2(e.primaryColor);n&&(t.style.setProperty(`--color-primary-500`,n),t.style.setProperty(`--color-primary-600`,n),t.style.setProperty(`--color-primary-700`,n))}if(e.secondaryColor){let n=a2(e.secondaryColor);n&&(t.style.setProperty(`--color-secondary-500`,n),t.style.setProperty(`--color-secondary-600`,n),t.style.setProperty(`--color-secondary-700`,n))}}async function s2(){try{let e=await W.get(`/config/studio`);if(e.success&&e.data?.studioConfig?.branding)return e.data.studioConfig.branding}catch(e){console.error(`Failed to fetch branding:`,e)}return window.TROKKY_CONFIG?.branding||{title:`Trokky Studio`}}var c2=Fr(`PasskeyLoginButton`);function l2({onSuccess:e,onMFARequired:t,onMFASetupRequired:n,onError:r,disabled:i,className:a=``}){let{t:o}=H(`studio`),[s,c]=(0,B.useState)(!1);return(0,V.jsxs)(U,{type:`button`,onClick:async()=>{c(!0);try{c2.debug(`Requesting passkey authentication options`);let i=await W.post(`/auth/passkey/login/options`,{});if(!i.success||!i.data){let e=i.error?.message||o(`passkey.optionsFailed`,`Failed to start passkey authentication`);c2.error(`Failed to get passkey options`,{error:e}),r?.(e);return}let{sessionId:a,...s}=i.data;c2.debug(`Received passkey options`,{sessionId:a.substring(0,8)});let c;try{c=await A0({optionsJSON:s}),c2.debug(`Browser authentication completed`)}catch(e){e.name===`NotAllowedError`?(c2.info(`User cancelled passkey authentication`),r?.(o(`passkey.cancelled`,`Authentication was cancelled`))):e.name===`NotSupportedError`?(c2.warn(`Passkeys not supported in this browser`),r?.(o(`passkey.notSupported`,`Passkeys are not supported in this browser`))):(c2.error(`Browser authentication failed`,{error:e.message}),r?.(e.message||o(`passkey.authFailed`,`Passkey authentication failed`)));return}c2.debug(`Verifying passkey with server`);let l=await W.post(`/auth/passkey/login/verify`,{sessionId:a,credential:c,deviceId:u2()});if(!l.success||!l.data){let e=l.error?.message||o(`passkey.verifyFailed`,`Passkey verification failed`);c2.error(`Passkey verification failed`,{error:e}),r?.(e);return}let u=l.data;u.requiresMFA&&u.mfaToken?(c2.info(`MFA required after passkey authentication`),t?.({mfaToken:u.mfaToken,methods:u.methods||[],expiresIn:u.expiresIn||300})):u.requiresMFASetup&&u.setupToken?(c2.info(`MFA setup required after passkey authentication`),n?.({setupToken:u.setupToken,allowedMethods:u.allowedMethods||[],message:u.message||``,expiresIn:u.expiresIn||900})):u.token&&u.refreshToken&&u.user?(c2.info(`Passkey authentication successful`,{userId:u.user.id}),e?.({token:u.token,refreshToken:u.refreshToken,user:u.user,expiresAt:u.expiresAt||``})):(c2.error(`Unexpected response from passkey verification`),r?.(o(`passkey.unexpectedResponse`,`Unexpected response from server`)))}catch(e){let t=e instanceof Error?e.message:o(`passkey.authFailed`,`Passkey authentication failed`);c2.error(`Passkey authentication error`,{error:t}),r?.(t)}finally{c(!1)}},disabled:i||s,variant:`outline`,className:`w-full flex items-center justify-center gap-3 h-12 border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors ${a}`,children:[s?(0,V.jsx)(Ao,{size:`sm`}):(0,V.jsx)(d2,{className:`w-5 h-5`}),(0,V.jsx)(`span`,{className:`text-gray-700 dark:text-gray-300`,children:o(`passkey.signIn`,`Sign in with Passkey`)})]})}function u2(){let e=`trokky_device_id`,t=localStorage.getItem(e);if(!t){let n=new Uint8Array(16);crypto.getRandomValues(n),t=Array.from(n,e=>e.toString(16).padStart(2,`0`)).join(``),localStorage.setItem(e,t)}return t}function d2({className:e}){return(0,V.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,V.jsx)(`path`,{d:`M12 2C8.13 2 5 5.13 5 9c0 2.38 1.19 4.47 3 5.74V17a1 1 0 001 1h1v1a1 1 0 001 1h1v1a1 1 0 001 1h2a1 1 0 001-1v-4.26c1.81-1.27 3-3.36 3-5.74 0-3.87-3.13-7-7-7z`,className:`fill-current text-gray-600 dark:text-gray-300`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`9`,r:`2`,className:`fill-current text-white dark:text-gray-800`})]})}function f2({mfaToken:e,methods:t,onSuccess:n,onBack:r}){let{t:i}=H(`studio`),[a,o]=(0,B.useState)(``),[s,c]=(0,B.useState)(t.includes(`totp`)?`totp`:t[0]),[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(!1),[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)(!1),y=(0,B.useRef)(null);(0,B.useEffect)(()=>{y.current?.focus()},[s]),(0,B.useEffect)(()=>{s===`email`&&!_&&b()},[s]);let b=async()=>{f(!0),g(null);try{let t=await W.post(`/auth/mfa/send-code`,{mfaToken:e});t.success?v(!0):g(t.error?.message||`Failed to send code`)}catch(e){g(e instanceof Error?e.message:`Failed to send code`)}finally{f(!1)}},x=async t=>{if(t.preventDefault(),!a.trim()){g(i(`mfa.enterCode`));return}u(!0),g(null);try{let t=p?p2():void 0,r=p?m2():void 0,i=s===`backup`?`/auth/mfa/verify-backup`:`/auth/mfa/verify`,c=await W.post(i,{mfaToken:e,code:a.trim(),method:s===`backup`?void 0:s,trustDevice:p,deviceId:t,deviceName:r});c.success&&c.data?(c.data.token&&await W.storeTokens(c.data.token,c.data.refreshToken),c.data.warning&&console.warn(`MFA Warning:`,c.data.warning),n(c.data.token,c.data.user)):(g(c.error?.message||`Verification failed`),o(``))}catch(e){g(e instanceof Error?e.message:`Verification failed`),o(``)}finally{u(!1)}},S=e=>{let t=s===`backup`?e.target.value.replace(/[^A-Za-z0-9-]/g,``).toUpperCase():e.target.value.replace(/[^0-9]/g,``);o(t)},C=e=>{switch(e){case`totp`:return(0,V.jsx)(L,{className:`h-5 w-5`});case`email`:return(0,V.jsx)(ne,{className:`h-5 w-5`});case`backup`:return(0,V.jsx)(te,{className:`h-5 w-5`})}},w=e=>{switch(e){case`totp`:return i(`mfa.authenticatorApp`);case`email`:return i(`mfa.emailCode`);case`backup`:return i(`mfa.backupCode`)}},T=e=>{switch(e){case`totp`:return i(`mfa.totpDescription`);case`email`:return i(_?`mfa.emailDescriptionSent`:`mfa.emailDescriptionPending`);case`backup`:return i(`mfa.backupDescription`)}},E=[...t,`backup`];return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:r,className:`p-2 -ml-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors`,children:(0,V.jsx)(Me,{className:`h-5 w-5`})}),(0,V.jsx)(`h2`,{className:`ml-2 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:i(`mfa.title`)})]}),E.length>1&&(0,V.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:E.map(e=>(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{c(e),o(``),g(null),e===`email`&&v(!1)},className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium transition-colors ${s===e?`bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300 border border-primary-300 dark:border-primary-700`:`bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 border border-transparent hover:bg-gray-200 dark:hover:bg-gray-600`}`,children:[C(e),w(e)]},e))}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:T(s)}),h&&(0,V.jsx)(`div`,{className:`p-3 bg-red-50/80 dark:bg-red-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h})}),(0,V.jsxs)(`form`,{onSubmit:x,className:`space-y-4`,children:[(0,V.jsx)(`div`,{className:`relative`,children:(0,V.jsx)(h1,{ref:y,type:`text`,value:a,onChange:S,placeholder:s===`backup`?`XXXX-XXXX`:`000000`,required:!0,disabled:l||s===`email`&&d,autoComplete:`one-time-code`,inputMode:`numeric`,pattern:s===`backup`?`[A-Z0-9]{4}-[A-Z0-9]{4}`:`[0-9]{6}`,maxLength:s===`backup`?9:6,className:`w-full text-center text-2xl tracking-widest font-mono bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 focus:border-primary-500 focus:ring-0 transition-colors`})}),(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(V$,{id:`trust-device`,checked:p,onChange:m,className:`mr-2`}),(0,V.jsx)(`label`,{htmlFor:`trust-device`,className:`text-sm text-gray-600 dark:text-gray-400 cursor-pointer`,children:i(`mfa.trustDevice`)})]}),(0,V.jsx)(U,{type:`submit`,className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium text-base transition-colors`,disabled:l||!a.trim(),children:l?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),i(`mfa.verifying`)]}):i(`mfa.verify`)}),s===`email`&&_&&(0,V.jsx)(`button`,{type:`button`,onClick:b,disabled:d,className:`w-full text-sm text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 transition-colors`,children:i(d?`mfa.sendingCode`:`mfa.resendCode`)})]})]})}function p2(){let e=localStorage.getItem(`trokky_device_id`);if(e)return e;let t=crypto.randomUUID();return localStorage.setItem(`trokky_device_id`,t),t}function m2(){let e=navigator.userAgent,t=`Browser`,n=`Unknown`;return e.includes(`Firefox`)?t=`Firefox`:e.includes(`Edge`)?t=`Edge`:e.includes(`Chrome`)?t=`Chrome`:e.includes(`Safari`)&&(t=`Safari`),e.includes(`Windows`)?n=`Windows`:e.includes(`Mac`)?n=`macOS`:e.includes(`Linux`)?n=`Linux`:e.includes(`Android`)?n=`Android`:(e.includes(`iPhone`)||e.includes(`iPad`))&&(n=`iOS`),`${t} on ${n}`}var h2={turnstile:`https://challenges.cloudflare.com/turnstile/v0/api.js`,recaptcha:`https://www.google.com/recaptcha/api.js`},g2={turnstile:`script[src*="challenges.cloudflare.com/turnstile"]`,recaptcha:`script[src*="google.com/recaptcha/api.js"]`};function _2({provider:e,siteKey:t,options:n={},onVerify:r,onError:i,onExpire:a,className:o=``}){let{t:s}=H(`studio`),c=(0,B.useRef)(null),l=(0,B.useRef)(null),u=(0,B.useRef)({onVerify:r,onError:i,onExpire:a}),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(null);return(0,B.useEffect)(()=>{u.current={onVerify:r,onError:i,onExpire:a}},[r,i,a]),(0,B.useEffect)(()=>{if(e===`hcaptcha`){m(s(`captcha.errors.hcaptchaNotSupported`));return}let t=h2[e],n=g2[e];if(!t){m(s(`captcha.errors.providerNotSupported`,{provider:e}));return}if(e===`turnstile`&&window.turnstile){f(!0);return}if(e===`recaptcha`&&window.grecaptcha){f(!0);return}let r=document.querySelector(n);if(r){let t=()=>{e===`recaptcha`&&window.grecaptcha?window.grecaptcha.ready(()=>f(!0)):f(!0)},n=()=>m(s(`captcha.errors.scriptLoadFailed`));return r.addEventListener(`load`,t),r.addEventListener(`error`,n),()=>{r.removeEventListener(`load`,t),r.removeEventListener(`error`,n)}}let i=document.createElement(`script`);i.src=t,i.async=!0,i.onload=()=>{e===`recaptcha`&&window.grecaptcha?window.grecaptcha.ready(()=>f(!0)):f(!0)},i.onerror=()=>{m(s(`captcha.errors.scriptLoadFailed`))},document.head.appendChild(i)},[e]),(0,B.useEffect)(()=>{if(!d||!c.current||e!==`turnstile`)return;if(!window.turnstile){m(s(`captcha.errors.notAvailable`,{provider:`Turnstile`}));return}if(l.current!==null)return;let r=setTimeout(()=>{if(c.current&&l.current===null)try{l.current=window.turnstile.render(c.current,{sitekey:t,callback:e=>u.current.onVerify(e),"error-callback":e=>u.current.onError?.(e),"expired-callback":()=>u.current.onExpire?.(),theme:n.theme||`auto`,size:n.size||`normal`,language:n.language})}catch(e){console.error(`Failed to render Turnstile widget:`,e),m(s(`captcha.errors.renderFailed`))}},100);return()=>{if(clearTimeout(r),l.current!==null&&window.turnstile){try{window.turnstile.remove(l.current)}catch{}l.current=null}}},[d,e,t,n.theme,n.size]),(0,B.useEffect)(()=>{if(!d||!c.current||e!==`recaptcha`)return;if(!window.grecaptcha){m(s(`captcha.errors.notAvailable`,{provider:`reCAPTCHA`}));return}if(l.current!==null)return;let r=setTimeout(()=>{if(c.current&&l.current===null)try{let e=n.theme===`auto`?`light`:n.theme||`light`,r=n.size===`invisible`?`normal`:n.size||`normal`;l.current=window.grecaptcha.render(c.current,{sitekey:t,callback:e=>u.current.onVerify(e),"error-callback":()=>u.current.onError?.(`reCAPTCHA error`),"expired-callback":()=>u.current.onExpire?.(),theme:e,size:r})}catch(e){console.error(`Failed to render reCAPTCHA widget:`,e),m(s(`captcha.errors.renderFailed`))}},100);return()=>{if(clearTimeout(r),l.current!==null&&window.grecaptcha){try{window.grecaptcha.reset(l.current)}catch{}l.current=null}}},[d,e,t,n.theme,n.size]),p?(0,V.jsx)(`div`,{className:`captcha-widget captcha-error ${o}`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600`,children:p})}):d?(0,V.jsx)(`div`,{ref:c,className:`captcha-widget ${o}`,"data-provider":e}):(0,V.jsx)(`div`,{className:`captcha-widget captcha-loading ${o}`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,V.jsx)(`div`,{className:`w-5 h-5 border-2 border-gray-300 border-t-blue-600 rounded-full animate-spin`}),(0,V.jsx)(`span`,{className:`ml-2 text-sm text-gray-500`,children:s(`captcha.loading`)})]})})}function v2({endpoint:e}){let[t,n]=(0,B.useState)({isLoading:!0,config:null,isRequired:!1,token:null,error:null});(0,B.useEffect)(()=>{(async()=>{try{let t=await W.get(`/auth/captcha/status`);if(t.success&&t.data){let{enabled:r,config:i,protectedEndpoints:a}=t.data;n(t=>({...t,isLoading:!1,config:r&&i?i:null,isRequired:r&&a[e]}))}else n(e=>({...e,isLoading:!1,isRequired:!1}))}catch(e){console.warn(`Failed to fetch CAPTCHA status:`,e),n(e=>({...e,isLoading:!1,isRequired:!1}))}})()},[e]);let r=(0,B.useCallback)(e=>{n(t=>({...t,token:e,error:null}))},[]),i=(0,B.useCallback)(e=>{n(t=>({...t,token:null,error:e}))},[]),a=(0,B.useCallback)(()=>{n(e=>({...e,token:null}))},[]),o=(0,B.useCallback)(()=>{n(e=>({...e,token:null,error:null}))},[]);return{...t,onVerify:r,onError:i,onExpire:a,reset:o}}function y2({onLoginSuccess:e,onMFASetupRequired:t}){let{t:n}=H(`auth`),[r,i]=(0,B.useState)({username:``,password:``}),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(``),[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)(!1),[y,b]=(0,B.useState)(!1),[x,S]=(0,B.useState)(!1),[C,w]=(0,B.useState)({required:!1,setupRequired:!1}),[T,E]=(0,B.useState)({step:`select`,verificationCode:``,isLoading:!1}),D=v2({endpoint:`login`}),O=async()=>{if(C.setupToken){E(e=>({...e,isLoading:!0,error:void 0}));try{let e=await W.post(`/auth/mfa/setup/totp`,{},{headers:{"X-MFA-Setup-Token":C.setupToken}});if(e.success&&e.data){let t=e.data;E(e=>({...e,step:`totp-setup`,selectedMethod:`totp`,totpSecret:t.secret,totpQrCode:t.qrCode,isLoading:!1}))}else throw Error(e.error?.message||`Failed to initialize TOTP setup`)}catch(e){E(t=>({...t,isLoading:!1,error:e instanceof Error?e.message:`Setup failed`}))}}},k=async()=>{if(C.setupToken){E(e=>({...e,isLoading:!0,error:void 0}));try{let e=await W.post(`/auth/mfa/setup/email`,{},{headers:{"X-MFA-Setup-Token":C.setupToken}});if(e.success)E(e=>({...e,step:`email-setup`,selectedMethod:`email`,isLoading:!1}));else throw Error(e.error?.message||`Failed to send verification email`)}catch(e){E(t=>({...t,isLoading:!1,error:e instanceof Error?e.message:`Setup failed`}))}}},A=()=>{T.pendingToken&&T.pendingUser&&(Ar.persist(T.pendingToken,T.pendingRefreshToken),e(T.pendingToken,T.pendingUser))},j=()=>{if(T.backupCodes){let e=T.backupCodes.join(`
737
- `);navigator.clipboard.writeText(e)}},M=async()=>{if(C.setupToken&&T.verificationCode){E(e=>({...e,isLoading:!0,error:void 0}));try{let t=T.selectedMethod===`totp`?`/auth/mfa/setup/totp/verify`:`/auth/mfa/setup/email/verify`,n=await W.post(t,{code:T.verificationCode},{headers:{"X-MFA-Setup-Token":C.setupToken}});if(n.success&&n.data){let t=n.data;t.backupCodes&&t.backupCodes.length>0?E(e=>({...e,step:`backup-codes`,backupCodes:t.backupCodes,pendingToken:t.token,pendingRefreshToken:t.refreshToken,pendingUser:t.user,isLoading:!1})):t.token&&t.user?(Ar.persist(t.token,t.refreshToken),e(t.token,t.user)):E(e=>({...e,step:`verify`,isLoading:!1}))}else throw Error(n.error?.message||`Verification failed`)}catch(e){E(t=>({...t,isLoading:!1,error:e instanceof Error?e.message:`Verification failed`}))}}};(0,B.useEffect)(()=>{let e=()=>{let e=localStorage.getItem(`theme`),t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;e===`dark`||!e&&t?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`)};e(),(async()=>{let e=await s2();g(e),o2(e)})(),(async()=>{try{let e=await W.get(`/auth/oauth/status`);e.success&&e.data?.providers?.google&&b(!0)}catch(e){console.debug(`OAuth status check failed:`,e)}})(),(async()=>{try{if(!window.PublicKeyCredential){console.debug(`WebAuthn not supported in this browser`);return}let e=await W.get(`/auth/passkey/status`);e.success&&e.data?.enabled&&S(!0)}catch(e){console.debug(`Passkey status check failed:`,e)}})();let t=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>{localStorage.getItem(`theme`)||e()};t.addEventListener(`change`,n);let r=window.TROKKY_CONFIG?.backendUrl;if(r)m(r||void 0);else{let e=Rr.get(Lr.BACKEND_URL);if(e)m(e);else{let e=`${window.location.origin}/api`;m(e)}}return()=>{t.removeEventListener(`change`,n)}},[]),(0,B.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get(`mfa`);if(e===`verify`){let e=sessionStorage.getItem(`oauth_mfa_token`),t=sessionStorage.getItem(`oauth_mfa_methods`);if(e&&t){let n=JSON.parse(t);sessionStorage.removeItem(`oauth_mfa_token`),sessionStorage.removeItem(`oauth_mfa_methods`),w({required:!0,setupRequired:!1,mfaToken:e,methods:n}),window.history.replaceState({},``,window.location.pathname)}}else if(e===`setup`){let e=sessionStorage.getItem(`oauth_mfa_setup_token`),t=sessionStorage.getItem(`oauth_mfa_allowed_methods`),n=sessionStorage.getItem(`oauth_mfa_message`);if(e&&t){let r=JSON.parse(t);sessionStorage.removeItem(`oauth_mfa_setup_token`),sessionStorage.removeItem(`oauth_mfa_allowed_methods`),sessionStorage.removeItem(`oauth_mfa_message`),w({required:!1,setupRequired:!0,setupToken:e,allowedMethods:r,message:n||`Your organization requires MFA. Please set up multi-factor authentication.`}),window.history.replaceState({},``,window.location.pathname)}}},[]);let N=async i=>{if(i.preventDefault(),c(!0),u(null),D.isRequired&&!D.token){u(n(`errors.captchaRequired`)),c(!1);return}try{let n=window.TROKKY_CONFIG?.backendUrl;p&&!n&&(Rr.set(Lr.BACKEND_URL,p),W.setBackendUrl(p));let i=b2(),o=await W.login(r.username,r.password,a,i,D.token||void 0);if(o.success&&o.data){let n=o.data;if(n.requiresMFA&&n.mfaToken){w({required:!0,setupRequired:!1,mfaToken:n.mfaToken,methods:n.methods||[`totp`]});return}if(n.requiresMFASetup&&n.setupToken){w({required:!1,setupRequired:!0,setupToken:n.setupToken,allowedMethods:n.allowedMethods||[`totp`,`email`],message:n.message}),t&&t(n.setupToken,n.allowedMethods||[`totp`,`email`]);return}n.token&&n.user?e(n.token,n.user):u(`Invalid login response`)}else u(o.error?.message||`Login failed`)}catch(e){u(e instanceof Error?e.message:`Login failed`)}finally{c(!1)}},P=(t,n)=>{e(t,n)},F=()=>{w({required:!1,setupRequired:!1}),i({username:r.username,password:``})},I=e=>t=>{i(n=>({...n,[e]:t.target.value}))},L=h||{title:`Trokky Studio`};return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-sm`,children:[(0,V.jsxs)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:[!C.required&&(0,V.jsx)(`div`,{className:`mb-8 text-center`,children:L.logo?(0,V.jsx)(`div`,{className:`flex justify-center`,children:(0,V.jsx)(`img`,{src:L.logo,alt:L.organizationName||L.title,className:`h-20 w-auto object-contain`})}):(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-primary-600 dark:text-primary-400`,children:L.organizationName||L.title})}),C.required&&C.mfaToken&&C.methods&&(0,V.jsx)(f2,{mfaToken:C.mfaToken,methods:C.methods,onSuccess:P,onBack:F,onError:u}),C.setupRequired&&(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`text-center mb-4 p-4 bg-amber-50 dark:bg-amber-900/20 rounded-lg border border-amber-200 dark:border-amber-800`,children:[(0,V.jsx)(`h2`,{className:`text-lg font-semibold text-amber-800 dark:text-amber-200 mb-2`,children:n(`mfa.required`)}),(0,V.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:C.message||n(`mfa.setupRequired`)})]}),T.error&&(0,V.jsx)(`div`,{className:`p-3 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:T.error})}),T.step===`select`&&(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 text-center`,children:n(`mfa.chooseMethod`)}),C.allowedMethods?.includes(`totp`)&&(0,V.jsx)(`button`,{onClick:O,disabled:T.isLoading,className:`w-full p-4 border-2 border-gray-200 dark:border-gray-700 rounded-lg hover:border-primary-500 dark:hover:border-primary-500 transition-colors text-left disabled:opacity-50`,children:(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(`div`,{className:`w-10 h-10 bg-primary-100 dark:bg-primary-900 rounded-lg flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-6 h-6 text-primary-600 dark:text-primary-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z`})})}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-white`,children:n(`mfa.authenticatorApp`)}),(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:n(`mfa.authenticatorAppDesc`)})]})]})}),C.allowedMethods?.includes(`email`)&&(0,V.jsx)(`button`,{onClick:k,disabled:T.isLoading,className:`w-full p-4 border-2 border-gray-200 dark:border-gray-700 rounded-lg hover:border-primary-500 dark:hover:border-primary-500 transition-colors text-left disabled:opacity-50`,children:(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(`div`,{className:`w-10 h-10 bg-blue-100 dark:bg-blue-900 rounded-lg flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-6 h-6 text-blue-600 dark:text-blue-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z`})})}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-white`,children:n(`mfa.emailCode`)}),(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:n(`mfa.emailCodeDesc`)})]})]})}),T.isLoading&&(0,V.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,V.jsx)(Ao,{size:`md`})})]}),T.step===`totp-setup`&&(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:n(`mfa.scanQR`)}),T.totpQrCode&&(0,V.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,V.jsx)(`img`,{src:T.totpQrCode,alt:`TOTP QR Code`,className:`w-48 h-48 bg-white p-2 rounded-lg`})}),T.totpSecret&&(0,V.jsxs)(`div`,{className:`mb-4`,children:[(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-1`,children:n(`mfa.manualEntry`)}),(0,V.jsx)(`code`,{className:`text-sm bg-gray-100 dark:bg-gray-800 px-3 py-1 rounded font-mono`,children:T.totpSecret})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:n(`mfa.enterCode`)}),(0,V.jsx)(h1,{type:`text`,value:T.verificationCode,onChange:e=>E(t=>({...t,verificationCode:e.target.value.replace(/\D/g,``).slice(0,6)})),placeholder:`000000`,maxLength:6,className:`text-center text-2xl tracking-widest font-mono`,autoFocus:!0})]}),(0,V.jsx)(U,{onClick:M,disabled:T.isLoading||T.verificationCode.length!==6,className:`w-full h-12 bg-primary-600 hover:bg-primary-700 text-white rounded-lg font-medium disabled:opacity-50`,children:T.isLoading?(0,V.jsx)(Ao,{size:`sm`}):n(`mfa.verifyComplete`)}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>E(e=>({...e,step:`select`,verificationCode:``,error:void 0})),className:`w-full text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`,children:n(`mfa.chooseDifferent`)})]}),T.step===`email-setup`&&(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 mx-auto mb-4 bg-blue-100 dark:bg-blue-900 rounded-full flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-8 h-8 text-blue-600 dark:text-blue-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z`})})}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`mfa.emailSent`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:n(`mfa.enterEmailCode`)}),(0,V.jsx)(h1,{type:`text`,value:T.verificationCode,onChange:e=>E(t=>({...t,verificationCode:e.target.value.replace(/\D/g,``).slice(0,6)})),placeholder:`000000`,maxLength:6,className:`text-center text-2xl tracking-widest font-mono`,autoFocus:!0})]}),(0,V.jsx)(U,{onClick:M,disabled:T.isLoading||T.verificationCode.length!==6,className:`w-full h-12 bg-primary-600 hover:bg-primary-700 text-white rounded-lg font-medium disabled:opacity-50`,children:T.isLoading?(0,V.jsx)(Ao,{size:`sm`}):n(`mfa.verifyComplete`)}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>E(e=>({...e,step:`select`,verificationCode:``,error:void 0})),className:`w-full text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`,children:n(`mfa.chooseDifferent`)})]}),T.step===`backup-codes`&&T.backupCodes&&(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 mx-auto mb-4 bg-green-100 dark:bg-green-900 rounded-full flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-8 h-8 text-green-600 dark:text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z`})})}),(0,V.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-white mb-2`,children:n(`mfa.backupCodes.title`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`mfa.backupCodes.description`)})]}),(0,V.jsx)(`div`,{className:`p-4 bg-gray-50 dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-2 font-mono text-sm`,children:T.backupCodes.map((e,t)=>(0,V.jsx)(`div`,{className:`text-center py-1 px-2 bg-white dark:bg-gray-800 rounded border border-gray-200 dark:border-gray-600`,children:e},t))})}),(0,V.jsx)(`div`,{className:`flex gap-2`,children:(0,V.jsxs)(U,{onClick:j,variant:`outline`,className:`flex-1 h-10`,children:[(0,V.jsx)(`svg`,{className:`w-4 h-4 mr-2`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})}),n(`mfa.backupCodes.copy`)]})}),(0,V.jsx)(`div`,{className:`p-3 bg-amber-50 dark:bg-amber-900/20 rounded-lg border border-amber-200 dark:border-amber-800`,children:(0,V.jsxs)(`p`,{className:`text-xs text-amber-700 dark:text-amber-300`,children:[(0,V.jsxs)(`strong`,{children:[n(`mfa.backupCodes.warning`).split(`:`)[0],`:`]}),` `,n(`mfa.backupCodes.warning`).split(`:`).slice(1).join(`:`)]})}),(0,V.jsx)(U,{onClick:A,className:`w-full h-12 bg-primary-600 hover:bg-primary-700 text-white rounded-lg font-medium`,children:n(`mfa.backupCodes.continue`)})]}),T.step!==`backup-codes`&&(0,V.jsx)(`button`,{type:`button`,onClick:F,className:`w-full text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`,children:n(`login.backToLogin`)})]}),!C.required&&!C.setupRequired&&(0,V.jsxs)(V.Fragment,{children:[l&&(0,V.jsx)(`div`,{className:`mb-6 p-3 bg-red-50/80 dark:bg-red-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:l})}),(0,V.jsxs)(`form`,{onSubmit:N,className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(h1,{type:`text`,value:r.username,onChange:I(`username`),placeholder:n(`login.emailOrUsername`),required:!0,disabled:s,autoComplete:`username`,autoFocus:!0,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`})}),(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(h1,{type:_?`text`:`password`,value:r.password,onChange:I(`password`),placeholder:n(`login.password`),required:!0,disabled:s,autoComplete:`current-password`,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 pr-12 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>v(!_),className:`absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300 transition-colors`,tabIndex:-1,"aria-label":_?`Hide password`:`Show password`,children:_?(0,V.jsx)(le,{className:`h-5 w-5`}):(0,V.jsx)(ce,{className:`h-5 w-5`})})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,V.jsxs)(`label`,{className:`flex items-center`,children:[(0,V.jsx)(V$,{id:`remember-me`,checked:a,onChange:o,className:`mr-2`}),(0,V.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:n(`login.rememberMe`)})]}),(0,V.jsx)(`a`,{href:q0(`/forgot-password`),className:`text-sm text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 transition-colors`,children:n(`login.forgotPassword`)})]}),!window.TROKKY_CONFIG?.backendUrl&&(0,V.jsx)(`div`,{className:`flex justify-end`,children:(0,V.jsxs)(`button`,{type:`button`,onClick:()=>f(!d),className:`flex items-center text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors`,children:[d?(0,V.jsx)(ye,{className:`h-3 w-3 mr-1`}):(0,V.jsx)(z,{className:`h-3 w-3 mr-1`}),n(`advanced.title`)]})}),!window.TROKKY_CONFIG?.backendUrl&&d&&(0,V.jsxs)(`div`,{className:`mt-4 p-4 bg-gray-50/50 dark:bg-gray-900/30 rounded-lg border border-gray-200/30 dark:border-gray-700/30`,children:[(0,V.jsx)(h1,{type:`url`,value:p,onChange:e=>m(e.target.value),placeholder:n(`advanced.backendUrl`),disabled:s,className:`text-sm bg-transparent border-gray-300 dark:border-gray-600 px-4 py-2`}),(0,V.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-gray-400`,children:n(`advanced.customEndpoint`)})]}),D.isRequired&&D.config&&(0,V.jsx)(`div`,{className:`flex justify-center my-4`,children:(0,V.jsx)(_2,{provider:D.config.provider,siteKey:D.config.siteKey,options:D.config.options,onVerify:D.onVerify,onError:D.onError,onExpire:D.onExpire})}),(0,V.jsx)(U,{type:`submit`,className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium text-base transition-colors`,disabled:s||!r.username||!r.password||D.isRequired&&!D.token,children:s?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),n(`login.signingIn`)]}):n(`login.signIn`)}),(x||y)&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`relative my-6`,children:[(0,V.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,V.jsx)(`div`,{className:`w-full border-t border-gray-300 dark:border-gray-600`})}),(0,V.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,V.jsx)(`span`,{className:`px-4 bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400`,children:n(`login.orContinueWith`)})})]}),(0,V.jsxs)(`div`,{className:`space-y-3`,children:[x&&(0,V.jsx)(l2,{onSuccess:t=>{Rr.set(Lr.AUTH_TOKEN,t.token),Rr.set(Lr.REFRESH_TOKEN,t.refreshToken),e(t.token,t.user)},onMFARequired:e=>{w({required:!0,setupRequired:!1,mfaToken:e.mfaToken,methods:e.methods})},onMFASetupRequired:e=>{w({required:!1,setupRequired:!0,setupToken:e.setupToken,allowedMethods:e.allowedMethods,message:e.message})},onError:e=>u(e),disabled:s}),y&&(0,V.jsx)(t0,{mode:`login`,onError:e=>u(e),disabled:s})]})]})]})]})]}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:L.title})})]})})}function b2(){let e=localStorage.getItem(`trokky_device_id`);if(e)return e;let t=crypto.randomUUID();return localStorage.setItem(`trokky_device_id`,t),t}function x2(){let{t:e}=H(`studio`),[t,n]=(0,B.useState)(``),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(null),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(null),d=v2({endpoint:`passwordResetRequest`});(0,B.useEffect)(()=>{let e=localStorage.getItem(`theme`),t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;e===`dark`||!e&&t?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`),(async()=>{let e=await s2();u(e),o2(e)})()},[]);let f=async n=>{if(n.preventDefault(),i(!0),o(null),d.isRequired&&!d.token){o(e(`auth.forgotPassword.captchaRequired`)),i(!1);return}try{let n=await W.post(`/auth/request-reset`,{email:t,captchaToken:d.token||void 0});n.success?c(!0):o(n.error?.message||e(`auth.forgotPassword.sendError`))}catch(t){o(t instanceof Error?t.message:e(`auth.forgotPassword.sendError`))}finally{i(!1)}},p=l||{title:`Trokky Studio`};return s?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsx)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,V.jsx)(Ae,{className:`h-16 w-16 text-green-500 dark:text-green-400`})}),(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-primary-600 dark:text-primary-400 mb-3`,children:e(`auth.forgotPassword.checkEmail`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-6`,dangerouslySetInnerHTML:{__html:e(`auth.forgotPassword.emailSentMessage`,{email:t})}}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mb-8`,children:e(`auth.forgotPassword.linkExpires`)}),(0,V.jsx)(U,{onClick:()=>J0(`/`),className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium transition-colors`,children:e(`auth.forgotPassword.backToSignIn`)})]})}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:p.title})})]})}):(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsxs)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:[(0,V.jsx)(`div`,{className:`mb-6`,children:(0,V.jsxs)(`a`,{href:q0(`/`),className:`inline-flex items-center text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,V.jsx)(Me,{className:`h-4 w-4 mr-2`}),e(`auth.forgotPassword.backToSignIn`)]})}),(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-primary-600 dark:text-primary-400 mb-2`,children:e(`auth.forgotPassword.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-8`,children:e(`auth.forgotPassword.subtitle`)}),a&&(0,V.jsx)(`div`,{className:`mb-6 p-3 bg-red-50/80 dark:bg-red-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:a})}),(0,V.jsxs)(`form`,{onSubmit:f,className:`space-y-6`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(h1,{type:`email`,value:t,onChange:e=>n(e.target.value),placeholder:`your@email.com`,required:!0,disabled:r,autoComplete:`email`,autoFocus:!0,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`})}),d.isRequired&&d.config&&(0,V.jsx)(`div`,{className:`flex justify-center my-4`,children:(0,V.jsx)(_2,{provider:d.config.provider,siteKey:d.config.siteKey,options:d.config.options,onVerify:d.onVerify,onError:d.onError,onExpire:d.onExpire})}),(0,V.jsx)(U,{type:`submit`,className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium text-base transition-colors`,disabled:r||!t||d.isRequired&&!d.token,children:r?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),e(`auth.forgotPassword.sending`)]}):e(`auth.forgotPassword.sendResetLink`)})]})]}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:p.title})})]})})}function S2(){let{t:e}=H(`studio`),[t,n]=(0,B.useState)(``),[r,i]=(0,B.useState)(``),[a,o]=(0,B.useState)(``),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(!0),[h,g]=(0,B.useState)(!1),[_,v]=(0,B.useState)(null),[y,b]=(0,B.useState)(!1),[x,S]=(0,B.useState)(null),C=v2({endpoint:`passwordResetVerify`});(0,B.useEffect)(()=>{let e=localStorage.getItem(`trokky_theme`),t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;e===`dark`||e===`system`&&t||!e&&t?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`)},[]),(0,B.useEffect)(()=>{let t=new URLSearchParams(window.location.search).get(`token`);if(!t){v(e(`auth.resetPassword.noToken`)),m(!1);return}n(t),(async()=>{try{let n=await W.post(`/auth/verify-reset-token`,{token:t});n.success&&n.data?.valid?(g(!0),S(n.data.expiresIn??null)):v(n.data?.message||e(`auth.resetPassword.tokenInvalid`))}catch{v(e(`auth.resetPassword.tokenVerifyError`))}finally{m(!1)}})()},[]);let w=async n=>{if(n.preventDefault(),v(null),r.length<8){v(e(`auth.resetPassword.passwordMinLength`));return}if(r!==a){v(e(`auth.resetPassword.passwordMismatch`));return}if(C.isRequired&&!C.token){v(e(`auth.resetPassword.captchaRequired`));return}f(!0);try{let n=await W.post(`/auth/reset-password`,{token:t,newPassword:r,captchaToken:C.token||void 0});n.success?b(!0):v(n.error?.message||e(`auth.resetPassword.resetError`))}catch(t){v(t instanceof Error?t.message:e(`auth.resetPassword.resetError`))}finally{f(!1)}},T=r?(t=>t.length<8?e(`auth.resetPassword.strengthTooShort`):t.length<12?e(`auth.resetPassword.strengthWeak`):t.length<16&&/[A-Z]/.test(t)&&/[0-9]/.test(t)?e(`auth.resetPassword.strengthGood`):t.length>=16&&/[A-Z]/.test(t)&&/[0-9]/.test(t)&&/[^A-Za-z0-9]/.test(t)?e(`auth.resetPassword.strengthStrong`):e(`auth.resetPassword.strengthMedium`))(r):null,E=window.TROKKY_CONFIG?.branding||{title:`Trokky Studio`};return p?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`p`,{className:`mt-4 text-gray-600 dark:text-gray-400`,children:e(`auth.resetPassword.verifying`)})]})}):y?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsx)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,V.jsx)(Ae,{className:`h-16 w-16 text-green-500 dark:text-green-400`})}),(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-gray-900 dark:text-white mb-3`,children:e(`auth.resetPassword.success`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-8`,children:e(`auth.resetPassword.successMessage`)}),(0,V.jsx)(U,{onClick:()=>J0(`/`),className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium transition-colors`,children:e(`auth.resetPassword.signIn`)})]})}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:E.title})})]})}):h?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsxs)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:[(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-gray-900 dark:text-white mb-2`,children:e(`auth.resetPassword.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-6`,children:e(`auth.resetPassword.subtitle`)}),x&&x<10&&(0,V.jsx)(`div`,{className:`mb-4 p-3 bg-yellow-50/80 dark:bg-yellow-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-yellow-800 dark:text-yellow-200`,children:e(`auth.resetPassword.linkExpiresIn`,{minutes:x,count:x})})}),_&&(0,V.jsx)(`div`,{className:`mb-6 p-3 bg-red-50/80 dark:bg-red-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:_})}),(0,V.jsxs)(`form`,{onSubmit:w,className:`space-y-6`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(h1,{type:s?`text`:`password`,value:r,onChange:e=>i(e.target.value),placeholder:e(`auth.resetPassword.newPassword`),required:!0,disabled:d,autoComplete:`new-password`,autoFocus:!0,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 pr-12 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>c(!s),className:`absolute right-4 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,children:s?(0,V.jsx)(le,{className:`h-5 w-5`}):(0,V.jsx)(ce,{className:`h-5 w-5`})})]}),r&&(0,V.jsxs)(`p`,{className:`mt-2 text-xs ${T===e(`auth.resetPassword.strengthStrong`)?`text-green-600 dark:text-green-400`:T===e(`auth.resetPassword.strengthGood`)?`text-blue-600 dark:text-blue-400`:T===e(`auth.resetPassword.strengthMedium`)?`text-yellow-600 dark:text-yellow-400`:`text-red-600 dark:text-red-400`}`,children:[e(`auth.resetPassword.strength`),`: `,T]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(h1,{type:l?`text`:`password`,value:a,onChange:e=>o(e.target.value),placeholder:e(`auth.resetPassword.confirmPassword`),required:!0,disabled:d,autoComplete:`new-password`,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 pr-12 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>u(!l),className:`absolute right-4 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,children:l?(0,V.jsx)(le,{className:`h-5 w-5`}):(0,V.jsx)(ce,{className:`h-5 w-5`})})]}),a&&a!==r&&(0,V.jsx)(`p`,{className:`mt-2 text-xs text-red-600 dark:text-red-400`,children:e(`auth.resetPassword.passwordMismatch`)})]}),(0,V.jsxs)(`div`,{className:`text-sm text-gray-600 dark:text-gray-400 space-y-1`,children:[(0,V.jsx)(`p`,{children:e(`auth.resetPassword.requirements`)}),(0,V.jsxs)(`ul`,{className:`list-disc list-inside space-y-1 ml-2`,children:[(0,V.jsx)(`li`,{className:r.length>=8?`text-green-600 dark:text-green-400`:``,children:e(`auth.resetPassword.requireLength`)}),(0,V.jsx)(`li`,{className:/[A-Z]/.test(r)?`text-green-600 dark:text-green-400`:``,children:e(`auth.resetPassword.requireUppercase`)}),(0,V.jsx)(`li`,{className:/[0-9]/.test(r)?`text-green-600 dark:text-green-400`:``,children:e(`auth.resetPassword.requireNumber`)})]})]}),C.isRequired&&C.config&&(0,V.jsx)(`div`,{className:`flex justify-center my-4`,children:(0,V.jsx)(_2,{provider:C.config.provider,siteKey:C.config.siteKey,options:C.config.options,onVerify:C.onVerify,onError:C.onError,onExpire:C.onExpire})}),(0,V.jsx)(U,{type:`submit`,className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium text-base transition-colors`,disabled:d||!r||!a||r!==a||C.isRequired&&!C.token,children:d?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),e(`auth.resetPassword.resetting`)]}):e(`auth.resetPassword.resetButton`)})]})]}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:E.title})})]})}):(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsx)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,V.jsx)(We,{className:`h-16 w-16 text-red-500 dark:text-red-400`})}),(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-gray-900 dark:text-white mb-3`,children:e(`auth.resetPassword.invalidLink`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-2`,children:_||e(`auth.resetPassword.invalidLinkMessage`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mb-8`,children:e(`auth.resetPassword.linkExpireNote`)}),(0,V.jsx)(U,{onClick:()=>J0(`/forgot-password`),className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium transition-colors`,children:e(`auth.resetPassword.requestNewLink`)})]})}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:E.title})})]})})}function C2({show:e,onDismiss:t,onRefresh:n,expiresAt:r}){let{t:i}=H(`studio`),[a,o]=(0,B.useState)(``);return(0,B.useEffect)(()=>{if(!e||!r)return;let t=()=>{let e=new Date,t=r.getTime()-e.getTime();if(t<=0){o(`Session expired`);return}let n=Math.floor(t/6e4),i=Math.floor(t%6e4/1e3);o(n>0?`${n} minute${n>1?`s`:``}`:`${i} second${i>1?`s`:``}`)};t();let n=setInterval(t,1e3);return()=>clearInterval(n)},[e,r]),e?(0,V.jsx)(`div`,{className:`fixed top-4 right-4 z-toast max-w-sm`,children:(0,V.jsx)(`div`,{className:`bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-4 shadow-lg`,children:(0,V.jsxs)(`div`,{className:`flex items-start`,children:[(0,V.jsx)(`div`,{className:`flex-shrink-0`,children:(0,V.jsx)(de,{className:`h-5 w-5 text-amber-400`})}),(0,V.jsxs)(`div`,{className:`ml-3 flex-1`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-amber-800 dark:text-amber-200`,children:i(`sessionTimeout.title`)}),(0,V.jsx)(`div`,{className:`mt-1 text-sm text-amber-700 dark:text-amber-300`,children:(0,V.jsx)(`p`,{children:i(`sessionTimeout.expireIn`,{time:a})})}),(0,V.jsxs)(`div`,{className:`mt-3 flex space-x-2`,children:[(0,V.jsx)(U,{size:`sm`,onClick:()=>{console.log(`Extend Session button clicked!`),n()},className:`bg-amber-600 hover:bg-amber-700 text-white`,children:i(`sessionTimeout.stayLoggedIn`)}),(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:t,className:`text-amber-800 dark:text-amber-200 hover:bg-amber-100 dark:hover:bg-amber-800/20`,children:i(`common.dismiss`)})]})]}),(0,V.jsx)(`div`,{className:`ml-auto flex-shrink-0`,children:(0,V.jsxs)(`button`,{type:`button`,className:`inline-flex rounded-md text-amber-400 hover:text-amber-500 focus:outline-none focus:ring-2 focus:ring-amber-500 focus:ring-offset-2 focus:ring-offset-amber-50`,onClick:t,children:[(0,V.jsx)(`span`,{className:`sr-only`,children:i(`common.close`)}),(0,V.jsx)(tt,{className:`h-5 w-5`})]})})]})})}):null}function w2(){let{showTimeoutWarning:e,sessionExpiresAt:t,dismissTimeoutWarning:n,refreshSession:r}=ri();return(0,V.jsx)(C2,{show:e,expiresAt:t,onDismiss:n,onRefresh:r})}var T2=({toast:e,onRemove:t})=>{let{t:n}=H(`studio`),{id:r,message:i,type:a,duration:o=3e3}=e;return(0,B.useEffect)(()=>{let e=setTimeout(()=>{t(r)},o);return()=>{clearTimeout(e)}},[r,o,t]),(0,V.jsxs)(`div`,{className:`
736
+ `)),children:[(0,V.jsx)(oe,{className:`h-4 w-4 mr-2`}),t(`mfa.copyAll`)]}),(0,V.jsx)(U,{onClick:()=>{h(!1),p([])},children:t(`mfa.done`)})]})]})})}),A&&(0,V.jsxs)(ia,{open:!0,onClose:()=>{j(!1),N(``),L(null)},variant:`center`,size:`sm`,ariaLabel:t(`mfa.disableDialog.all`),children:[(0,V.jsx)(ia.Header,{children:(0,V.jsx)(`h3`,{className:`text-lg font-semibold text-red-600 dark:text-red-400`,children:t(`mfa.disableDialog.all`)})}),(0,V.jsxs)(ia.Body,{children:[(0,V.jsx)(`div`,{className:`p-4 mb-4 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-800 dark:text-red-200`,children:t(`mfa.disableDialog.allWarning`)})}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:t(`mfa.disableDialog.confirmPassword`)}),I&&(0,V.jsx)(`div`,{className:`p-3 mb-4 bg-red-50 dark:bg-red-900/20 rounded text-sm text-red-600 dark:text-red-400`,children:I}),(0,V.jsx)(h1,{type:`password`,value:M,onChange:e=>N(e.target.value),placeholder:`Password`,className:`mb-4`}),(0,V.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,V.jsx)(U,{variant:`secondary`,onClick:()=>{j(!1),N(``),L(null)},children:t(`mfa.cancel`)}),(0,V.jsxs)(U,{variant:`danger`,onClick:se,disabled:P||!M,children:[P?(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}):null,t(`mfa.disableDialog.all`)]})]})]})]})]})}function m0(e){let t=new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}function h0(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,`=`),i=atob(r),a=new ArrayBuffer(i.length),o=new Uint8Array(a);for(let e=0;e<i.length;e++)o[e]=i.charCodeAt(e);return a}function g0(){return _0.stubThis(globalThis?.PublicKeyCredential!==void 0&&typeof globalThis.PublicKeyCredential==`function`)}var _0={stubThis:e=>e};function v0(e){let{id:t}=e;return{...e,id:h0(t),transports:e.transports}}function y0(e){return e===`localhost`||/^((xn--[a-z0-9-]+|[a-z0-9]+(-[a-z0-9]+)*)\.)+([a-z]{2,}|xn--[a-z0-9-]+)$/i.test(e)}var b0=class extends Error{constructor({message:e,code:t,cause:n,name:r}){super(e,{cause:n}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=r??n.name,this.code=t}};function x0({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new b0({message:`Registration ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`ConstraintError`){if(n.authenticatorSelection?.requireResidentKey===!0)return new b0({message:`Discoverable credentials were required but no available authenticator supported it`,code:`ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT`,cause:e});if(t.mediation===`conditional`&&n.authenticatorSelection?.userVerification===`required`)return new b0({message:`User verification was required during automatic registration but it could not be performed`,code:`ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE`,cause:e});if(n.authenticatorSelection?.userVerification===`required`)return new b0({message:`User verification was required but no available authenticator supported it`,code:`ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT`,cause:e})}else if(e.name===`InvalidStateError`)return new b0({message:`The authenticator was previously registered`,code:`ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED`,cause:e});else if(e.name===`NotAllowedError`)return new b0({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`NotSupportedError`)return n.pubKeyCredParams.filter(e=>e.type===`public-key`).length===0?new b0({message:`No entry in pubKeyCredParams was of type "public-key"`,code:`ERROR_MALFORMED_PUBKEYCREDPARAMS`,cause:e}):new b0({message:`No available authenticator supported any of the specified pubKeyCredParams algorithms`,code:`ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG`,cause:e});else if(e.name===`SecurityError`){let t=globalThis.location.hostname;if(!y0(t))return new b0({message:`${globalThis.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rp.id!==t)return new b0({message:`The RP ID "${n.rp.id}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`TypeError`){if(n.user.id.byteLength<1||n.user.id.byteLength>64)return new b0({message:`User ID was not between 1 and 64 characters`,code:`ERROR_INVALID_USER_ID_LENGTH`,cause:e})}else if(e.name===`UnknownError`)return new b0({message:`The authenticator was unable to process the specified options, or could not create a new credential`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}var S0=new class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){let e=Error(`Cancelling existing WebAuthn API call for new one`);e.name=`AbortError`,this.controller.abort(e)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=Error(`Manually cancelling existing WebAuthn API call`);e.name=`AbortError`,this.controller.abort(e),this.controller=void 0}}},C0=[`cross-platform`,`platform`];function w0(e){if(e&&!(C0.indexOf(e)<0))return e}async function T0(e){!e.optionsJSON&&e.challenge&&(console.warn(`startRegistration() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.`),e={optionsJSON:e});let{optionsJSON:t,useAutoRegister:n=!1}=e;if(!g0())throw Error(`WebAuthn is not supported in this browser`);let r={...t,challenge:h0(t.challenge),user:{...t.user,id:h0(t.user.id)},excludeCredentials:t.excludeCredentials?.map(v0)},i={};n&&(i.mediation=`conditional`),i.publicKey=r,i.signal=S0.createNewAbortSignal();let a;try{a=await navigator.credentials.create(i)}catch(e){throw x0({error:e,options:i})}if(!a)throw Error(`Registration was not completed`);let{id:o,rawId:s,response:c,type:l}=a,u;typeof c.getTransports==`function`&&(u=c.getTransports());let d;if(typeof c.getPublicKeyAlgorithm==`function`)try{d=c.getPublicKeyAlgorithm()}catch(e){E0(`getPublicKeyAlgorithm()`,e)}let f;if(typeof c.getPublicKey==`function`)try{let e=c.getPublicKey();e!==null&&(f=m0(e))}catch(e){E0(`getPublicKey()`,e)}let p;if(typeof c.getAuthenticatorData==`function`)try{p=m0(c.getAuthenticatorData())}catch(e){E0(`getAuthenticatorData()`,e)}return{id:o,rawId:m0(s),response:{attestationObject:m0(c.attestationObject),clientDataJSON:m0(c.clientDataJSON),transports:u,publicKeyAlgorithm:d,publicKey:f,authenticatorData:p},type:l,clientExtensionResults:a.getClientExtensionResults(),authenticatorAttachment:w0(a.authenticatorAttachment)}}function E0(e,t){console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${e}. You should report this error to them.\n`,t)}function D0(){if(!g0())return O0.stubThis(new Promise(e=>e(!1)));let e=globalThis.PublicKeyCredential;return e?.isConditionalMediationAvailable===void 0?O0.stubThis(new Promise(e=>e(!1))):O0.stubThis(e.isConditionalMediationAvailable())}var O0={stubThis:e=>e};function k0({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new b0({message:`Authentication ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`NotAllowedError`)return new b0({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`SecurityError`){let t=globalThis.location.hostname;if(!y0(t))return new b0({message:`${globalThis.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rpId!==t)return new b0({message:`The RP ID "${n.rpId}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`UnknownError`)return new b0({message:`The authenticator was unable to process the specified options, or could not create a new assertion signature`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}async function A0(e){!e.optionsJSON&&e.challenge&&(console.warn(`startAuthentication() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.`),e={optionsJSON:e});let{optionsJSON:t,useBrowserAutofill:n=!1,verifyBrowserAutofillInput:r=!0}=e;if(!g0())throw Error(`WebAuthn is not supported in this browser`);let i;t.allowCredentials?.length!==0&&(i=t.allowCredentials?.map(v0));let a={...t,challenge:h0(t.challenge),allowCredentials:i},o={};if(n){if(!await D0())throw Error(`Browser does not support WebAuthn autofill`);if(document.querySelectorAll(`input[autocomplete$='webauthn']`).length<1&&r)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');o.mediation=`conditional`,a.allowCredentials=[]}o.publicKey=a,o.signal=S0.createNewAbortSignal();let s;try{s=await navigator.credentials.get(o)}catch(e){throw k0({error:e,options:o})}if(!s)throw Error(`Authentication was not completed`);let{id:c,rawId:l,response:u,type:d}=s,f;return u.userHandle&&(f=m0(u.userHandle)),{id:c,rawId:m0(l),response:{authenticatorData:m0(u.authenticatorData),clientDataJSON:m0(u.clientDataJSON),signature:m0(u.signature),userHandle:f},type:d,clientExtensionResults:s.getClientExtensionResults(),authenticatorAttachment:w0(s.authenticatorAttachment)}}var j0=Fr(`PasskeyRegistration`);function M0({onSuccess:e,onError:t,disabled:n,className:r=``}){let{t:i}=H(`studio`),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(``),[l,u]=(0,B.useState)(!1);return l?(0,V.jsxs)(`div`,{className:`space-y-3 ${r}`,children:[(0,V.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:i(`passkey.register.namePlaceholder`,`e.g., MacBook Pro Touch ID`),className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent`,disabled:a}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(U,{type:`button`,onClick:async()=>{o(!0);try{j0.debug(`Requesting passkey registration options`);let n=await W.post(`/auth/passkey/register/options`,{friendlyName:s||void 0});if(!n.success||!n.data){let e=n.error?.message||i(`passkey.register.optionsFailed`,`Failed to start passkey registration`);j0.error(`Failed to get registration options`,{error:e}),t?.(e);return}let{sessionId:r,...a}=n.data;j0.debug(`Received registration options`,{sessionId:r.substring(0,8)});let o;try{o=await T0({optionsJSON:a}),j0.debug(`Browser registration completed`)}catch(e){e.name===`NotAllowedError`?(j0.info(`User cancelled passkey registration`),t?.(i(`passkey.register.cancelled`,`Registration was cancelled`))):e.name===`InvalidStateError`?(j0.warn(`Passkey already registered`),t?.(i(`passkey.register.alreadyRegistered`,`This passkey is already registered`))):e.name===`NotSupportedError`?(j0.warn(`Passkeys not supported in this browser`),t?.(i(`passkey.register.notSupported`,`Passkeys are not supported in this browser`))):(j0.error(`Browser registration failed`,{error:e.message}),t?.(e.message||i(`passkey.register.failed`,`Passkey registration failed`)));return}j0.debug(`Verifying registration with server`);let l=await W.post(`/auth/passkey/register/verify`,{sessionId:r,credential:o,friendlyName:s||void 0});if(!l.success||!l.data){let e=l.error?.message||i(`passkey.register.verifyFailed`,`Passkey registration verification failed`);j0.error(`Registration verification failed`,{error:e}),t?.(e);return}j0.info(`Passkey registered successfully`,{credentialId:l.data.credential.id.substring(0,8)}),c(``),u(!1),e?.(l.data.credential)}catch(e){let n=e instanceof Error?e.message:i(`passkey.register.failed`,`Passkey registration failed`);j0.error(`Passkey registration error`,{error:n}),t?.(n)}finally{o(!1)}},disabled:n||a,variant:`primary`,className:`flex-1`,children:a?(0,V.jsx)(Ao,{size:`sm`}):i(`passkey.register.continue`,`Continue`)}),(0,V.jsx)(U,{type:`button`,onClick:()=>{u(!1),c(``)},disabled:a,variant:`outline`,children:i(`common.cancel`,`Cancel`)})]})]}):(0,V.jsxs)(U,{type:`button`,onClick:()=>u(!0),disabled:n||a,variant:`outline`,className:`flex items-center gap-2 ${r}`,children:[(0,V.jsx)(N0,{className:`w-4 h-4`}),i(`passkey.register.addPasskey`,`Add Passkey`)]})}function N0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,children:(0,V.jsx)(`path`,{fillRule:`evenodd`,d:`M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z`,clipRule:`evenodd`})})}var P0=Fr(`PasskeyManager`);function F0({className:e=``}){let{t}=H(`studio`),[n,r]=(0,B.useState)([]),[i,a]=(0,B.useState)(!0),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(null),[f,p]=(0,B.useState)(``),[m,h]=(0,B.useState)(null),g=(0,B.useCallback)(async()=>{try{let e=await W.get(`/auth/passkey/status`);return e.success&&e.data?(s(e.data.enabled),e.data.enabled):(s(!1),!1)}catch(e){return P0.warn(`Failed to check passkey status`,{error:e}),s(!1),!1}},[]),_=(0,B.useCallback)(async()=>{a(!0),l(null);try{let e=await W.get(`/auth/passkey/credentials`);e.success&&e.data?(r(e.data.credentials),P0.debug(`Loaded passkey credentials`,{count:e.data.credentials.length})):l(e.error?.message||t(`passkey.manager.loadFailed`,`Failed to load passkeys`))}catch(e){let n=e instanceof Error?e.message:t(`passkey.manager.loadFailed`,`Failed to load passkeys`);P0.error(`Failed to load credentials`,{error:n}),l(n)}finally{a(!1)}},[t]);(0,B.useEffect)(()=>{(async()=>{await g()?await _():a(!1)})()},[g,_]);let v=async e=>{if(!f.trim()){d(null);return}try{let n=await W.patch(`/auth/passkey/credentials/${e}`,{friendlyName:f.trim()});n.success?(P0.info(`Renamed passkey credential`),r(t=>t.map(t=>t.id===e?{...t,friendlyName:f.trim()}:t)),d(null),p(``)):(P0.error(`Failed to rename credential`,{error:n.error?.message}),l(n.error?.message||t(`passkey.manager.renameFailed`,`Failed to rename passkey`)))}catch(e){let n=e instanceof Error?e.message:t(`passkey.manager.renameFailed`,`Failed to rename passkey`);P0.error(`Rename error`,{error:n}),l(n)}},y=async e=>{try{h(e);let n=await W.delete(`/auth/passkey/credentials/${e}`);n.success?(P0.info(`Deleted passkey credential`),r(t=>t.filter(t=>t.id!==e))):(P0.error(`Failed to delete credential`,{error:n.error?.message}),l(n.error?.message||t(`passkey.manager.deleteFailed`,`Failed to delete passkey`)))}catch(e){let n=e instanceof Error?e.message:t(`passkey.manager.deleteFailed`,`Failed to delete passkey`);P0.error(`Delete error`,{error:n}),l(n)}finally{h(null)}},b=e=>{r(t=>[...t,e]),l(null)},x=e=>{l(e)},S=e=>{try{return new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}catch{return e}},C=(e,t)=>t?(0,V.jsx)(L0,{className:`w-5 h-5 text-blue-500`}):(0,V.jsx)(I0,{className:`w-5 h-5 text-gray-500 dark:text-gray-400`});return i?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-8 ${e}`,children:(0,V.jsx)(Ao,{})}):o===!1?(0,V.jsx)(`div`,{className:`space-y-4 ${e}`,children:(0,V.jsxs)(`div`,{className:`text-center py-6`,children:[(0,V.jsx)(I0,{className:`w-12 h-12 mx-auto text-gray-400 dark:text-gray-500 mb-3`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-2`,children:t(`passkey.manager.notConfigured`,`Passkey authentication is not enabled`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-500`,children:t(`passkey.manager.notConfiguredDescription`,`Passkey authentication needs to be configured by an administrator in the server settings.`)})]})}):(0,V.jsxs)(`div`,{className:`space-y-4 ${e}`,children:[c&&(0,V.jsx)(`div`,{className:`p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-md`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:c})}),n.length===0?(0,V.jsxs)(`div`,{className:`text-center py-6`,children:[(0,V.jsx)(I0,{className:`w-12 h-12 mx-auto text-gray-400 dark:text-gray-500 mb-3`}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-4`,children:t(`passkey.manager.noPasskeys`,`You haven't set up any passkeys yet.`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-500 mb-4`,children:t(`passkey.manager.description`,`Passkeys let you sign in without a password using your fingerprint, face, or security key.`)})]}):(0,V.jsx)(`ul`,{className:`space-y-3`,children:n.map(e=>(0,V.jsxs)(`li`,{className:`flex items-center justify-between p-4 bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-gray-700`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[C(e.deviceType,e.backedUp),(0,V.jsxs)(`div`,{children:[u===e.id?(0,V.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),onBlur:()=>v(e.id),onKeyDown:t=>{t.key===`Enter`&&v(e.id),t.key===`Escape`&&(d(null),p(``))},className:`px-2 py-1 text-sm border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-800 text-gray-900 dark:text-white`,autoFocus:!0}):(0,V.jsx)(`p`,{className:`font-medium text-gray-900 dark:text-white`,children:e.friendlyName||t(`passkey.manager.unnamed`,`Passkey`)}),(0,V.jsxs)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:[t(`passkey.manager.added`,`Added`),` `,S(e.createdAt),e.lastUsedAt&&(0,V.jsxs)(V.Fragment,{children:[` · `,t(`passkey.manager.lastUsed`,`Last used`),` `,S(e.lastUsedAt)]})]}),(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:e.backedUp?t(`passkey.manager.synced`,`Synced across devices`):t(`passkey.manager.deviceOnly`,`This device only`)})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[u!==e.id&&(0,V.jsx)(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{d(e.id),p(e.friendlyName||``)},children:(0,V.jsx)(R0,{className:`w-4 h-4`})}),(0,V.jsx)(U,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>y(e.id),disabled:m===e.id,className:`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:m===e.id?(0,V.jsx)(Ao,{size:`sm`}):(0,V.jsx)(z0,{className:`w-4 h-4`})})]})]},e.id))}),(0,V.jsx)(`div`,{className:`pt-4 border-t border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(M0,{onSuccess:b,onError:x})})]})}function I0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,V.jsx)(`path`,{d:`M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4`})})}function L0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,V.jsx)(`path`,{d:`M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z`})})}function R0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,V.jsx)(`path`,{d:`M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z`})})}function z0({className:e}){return(0,V.jsx)(`svg`,{className:e,viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,V.jsx)(`path`,{fillRule:`evenodd`,d:`M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z`,clipRule:`evenodd`})})}var B0=Fr(`UserPreferences`);function V0(){let{user:e}=ri(),{t}=H(`studio`),{locale:n,setLocale:r,locales:i,getLocaleName:a}=xr(),o=za({page:`user-preferences`,title:t(`preferences.title`)}),s=pa()?.utils?.showToast||((e,t)=>console.log(`Toast: ${t} - ${e}`)),[c,l]=(0,B.useState)({theme:`system`,language:n,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,emailNotifications:!0,pushNotifications:!1}),[u,d]=(0,B.useState)(!1),[f,p]=(0,B.useState)(null);return(0,B.useEffect)(()=>{o.configure({page:`user-preferences`,title:t(`preferences.title`),defaultVisible:!1})},[o.configure,t]),(0,B.useEffect)(()=>{e&&l(t=>({...t,...e.preferences}))},[e]),(0,V.jsx)(`div`,{className:`p-6`,children:(0,V.jsxs)(`div`,{className:`max-w-2xl space-y-8`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:t(`preferences.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:t(`preferences.subtitle`)})]}),f&&(0,V.jsx)(`div`,{className:`p-4 rounded-lg ${f.type===`success`?`bg-green-50 text-green-800 border border-green-200 dark:bg-green-900/20 dark:text-green-400 dark:border-green-800`:`bg-red-50 text-red-800 border border-red-200 dark:bg-red-900/20 dark:text-red-400 dark:border-red-800`}`,children:f.text}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-3 mb-6`,children:[(0,V.jsx)(Te,{className:`h-6 w-6 text-gray-600 dark:text-gray-400`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:t(`preferences.appearance`)})]}),(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:t(`preferences.theme`)}),(0,V.jsxs)(`select`,{value:c.theme,onChange:e=>l(t=>({...t,theme:e.target.value})),className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:`system`,children:t(`preferences.themeSystem`)}),(0,V.jsx)(`option`,{value:`light`,children:t(`preferences.themeLight`)}),(0,V.jsx)(`option`,{value:`dark`,children:t(`preferences.themeDark`)})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:t(`language.title`)}),(0,V.jsx)(`select`,{value:c.language,onChange:e=>l(t=>({...t,language:e.target.value})),className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:i.map(e=>(0,V.jsx)(`option`,{value:e,children:a(e)},e))}),(0,V.jsxs)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-gray-400`,children:[t(`language.current`),`: `,a(n)]})]})]})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-3 mb-6`,children:[(0,V.jsx)(Le,{className:`h-6 w-6 text-gray-600 dark:text-gray-400`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:t(`preferences.notifications`)})]}),(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:t(`preferences.emailNotifications`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t(`preferences.emailNotificationsDescription`)})]}),(0,V.jsx)(`input`,{type:`checkbox`,checked:c.emailNotifications,onChange:e=>l(t=>({...t,emailNotifications:e.target.checked})),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 rounded`})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-white`,children:t(`preferences.pushNotifications`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t(`preferences.pushNotificationsDescription`)})]}),(0,V.jsx)(`input`,{type:`checkbox`,checked:c.pushNotifications,onChange:e=>l(t=>({...t,pushNotifications:e.target.checked})),className:`h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 rounded`})]})]})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-3 mb-6`,children:[(0,V.jsx)(he,{className:`h-6 w-6 text-gray-600 dark:text-gray-400`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:t(`preferences.connectedAccounts`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t(`preferences.connectedAccountsDescription`)})]})]}),(0,V.jsx)(r0,{})]}),(0,V.jsxs)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center space-x-3 mb-6`,children:[(0,V.jsx)(He,{className:`h-6 w-6 text-gray-600 dark:text-gray-400`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:t(`preferences.security`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:t(`preferences.securityDescription`)})]})]}),(0,V.jsx)(p0,{onToast:s}),(0,V.jsxs)(`div`,{className:`mt-6 pt-6 border-t border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-white mb-2`,children:t(`preferences.passkeys`,`Passkeys`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mb-4`,children:t(`preferences.passkeysDescription`,`Sign in securely without a password using your fingerprint, face, or security key.`)}),(0,V.jsx)(F0,{})]})]}),(0,V.jsx)(`div`,{className:`flex justify-end`,children:(0,V.jsxs)(U,{onClick:async()=>{d(!0),p(null);try{c.theme&&(c.theme===`system`?document.documentElement.classList.remove(`light`,`dark`):(document.documentElement.classList.remove(`light`,`dark`),document.documentElement.classList.add(c.theme)),localStorage.setItem(`trokky_theme`,c.theme)),c.language&&c.language!==n&&r(c.language),p({type:`success`,text:t(`preferences.saveSuccess`)})}catch(e){B0.error(`Failed to update preferences`,e),p({type:`error`,text:t(`preferences.saveError`)})}finally{d(!1),setTimeout(()=>p(null),3e3)}},disabled:u,children:[u?(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}):null,t(`preferences.savePreferences`)]})})]})})}var H0=Fr(`AuditLogsPage`),U0=25;function W0(){let{t:e}=H(`studio`);za({page:`audit-logs`,title:e(`auditLogs.title`),defaultVisible:!1,defaultPosition:`left`});let[t,n]=(0,B.useState)([]),[r,i]=(0,B.useState)(!0),[a,o]=(0,B.useState)(null),[s,l]=(0,B.useState)(new Set),[u,d]=(0,B.useState)(1),[f,p]=(0,B.useState)(0),[m,h]=(0,B.useState)([]),[g,_]=(0,B.useState)([]),[v,y]=(0,B.useState)(``),[b,x]=(0,B.useState)(``),[S,C]=(0,B.useState)(``),[w,T]=(0,B.useState)(``),[E,D]=(0,B.useState)(!1),[O,k]=(0,B.useState)({});(0,B.useEffect)(()=>{A(),j()},[]),(0,B.useEffect)(()=>{(m.length>0||v)&&N()},[u,v,b,S,m.length]);let A=async()=>{try{let e=await W.get(`/config/structure`);if(e.success&&e.data?.structure){let t=e.data.structure,n=t.items||t,r=e=>{let t=[];for(let n of e)n.schemaType&&t.push(n.schemaType),n.items&&Array.isArray(n.items)&&t.push(...r(n.items));return t};Array.isArray(n)&&h([...new Set(r(n))].sort())}}catch(e){H0.warn(`Failed to load collections`,e)}},j=async()=>{try{let e=await W.get(`/users`);e.success&&e.data?.users&&_(e.data.users)}catch(e){H0.warn(`Failed to load users`,e)}},M=async e=>{if(O[e])return O[e];if(e===`system`)return`System`;try{let t=await W.get(`/users/${e}`);if(t.success&&t.data?.user){let n=t.data.user,r=n.username||n.name||n.email||`User`;return k(t=>({...t,[e]:r})),r}}catch{}return e.startsWith(`user-`)?`User`:e},N=async()=>{i(!0),o(null);try{let e=(u-1)*U0,t=[];if(v){let e=await W.get(`/audit-logs/collections/${v}`,{limit:200,offset:0});e.success&&e.data?.auditLogs&&(t=e.data.auditLogs)}else for(let e of m)try{let n=await W.get(`/audit-logs/collections/${e}`,{limit:100,offset:0});n.success&&n.data?.auditLogs&&t.push(...n.data.auditLogs)}catch{}let r=t;if(b&&(r=r.filter(e=>e.actorId===b)),S&&(r=r.filter(e=>e.operation===S)),w.trim()){let e=w.toLowerCase();r=r.filter(t=>{let n=t.changes?.after,r=t.changes?.before;return(n?.title||n?.name||r?.title||r?.name||``).toLowerCase().includes(e)||t.documentId.toLowerCase().includes(e)||t.collection.toLowerCase().includes(e)})}r.sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime()),p(r.length);let i=r.slice(e,e+U0),a=[...new Set(i.map(e=>e.actorId).filter(Boolean))];for(let e of a)await M(e);let o=i.map(e=>({...e,actorUsername:O[e.actorId]||e.actorUsername}));n(o),H0.info(`Audit logs loaded`,{count:o.length,total:r.length})}catch(e){H0.error(`Failed to load audit logs`,e),o(`Failed to load audit logs`)}finally{i(!1)}},P=(0,B.useCallback)(()=>{d(1),N()},[w]),F=e=>{e.key===`Enter`&&P()},I=()=>{y(``),x(``),C(``),T(``),d(1)},L=e=>{let t=new Set(s);t.has(e)?t.delete(e):t.add(e),l(t)},R=t=>{switch(t){case`create`:return{icon:Ne,text:e(`auditLogs.operations.create`),color:`text-green-600 dark:text-green-400`,bgColor:`bg-green-100 dark:bg-green-900/30`};case`update`:return{icon:ct,text:e(`auditLogs.operations.update`),color:`text-blue-600 dark:text-blue-400`,bgColor:`bg-blue-100 dark:bg-blue-900/30`};case`delete`:return{icon:Be,text:e(`auditLogs.operations.delete`),color:`text-red-600 dark:text-red-400`,bgColor:`bg-red-100 dark:bg-red-900/30`};case`publish`:return{icon:ce,text:e(`auditLogs.operations.publish`),color:`text-purple-600 dark:text-purple-400`,bgColor:`bg-purple-100 dark:bg-purple-900/30`};case`unpublish`:return{icon:ce,text:e(`auditLogs.operations.unpublish`),color:`text-orange-600 dark:text-orange-400`,bgColor:`bg-orange-100 dark:bg-orange-900/30`};case`restore`:return{icon:re,text:e(`auditLogs.operations.restore`),color:`text-indigo-600 dark:text-indigo-400`,bgColor:`bg-indigo-100 dark:bg-indigo-900/30`};default:return{icon:ct,text:t,color:`text-gray-600 dark:text-gray-400`,bgColor:`bg-gray-100 dark:bg-gray-700`}}},te=e=>{try{let t=new Date(e);return{relative:ko(t,{addSuffix:!0}),full:t.toLocaleString()}}catch{return{relative:`Unknown`,full:e}}},ne=e=>{let t=e.changes?.after,n=e.changes?.before;return t?.title||t?.name||n?.title||n?.name||e.documentId},ie=t=>{if(!t.changes?.fields||t.changes.fields.length===0)return null;let n=t.changes.fields;return n.length===1?e(`auditLogs.changedField`,{field:n[0]}):e(`auditLogs.changedFields`,{count:n.length})},ae=Math.ceil(f/U0),oe=v||b||S||w;return(0,V.jsxs)(`div`,{className:`p-6 max-w-7xl mx-auto`,children:[(0,V.jsx)(`div`,{className:`mb-6`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white flex items-center`,children:[(0,V.jsx)(re,{className:`h-7 w-7 mr-3 text-gray-500`}),e(`auditLogs.title`)]}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mt-1`,children:e(`auditLogs.subtitle`)})]}),(0,V.jsxs)(`button`,{onClick:()=>N(),disabled:r,className:`flex items-center px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50`,children:[(0,V.jsx)(ke,{className:`h-4 w-4 mr-2 ${r?`animate-spin`:``}`}),e(`auditLogs.refresh`)]})]})}),(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 mb-6`,children:(0,V.jsxs)(`div`,{className:`p-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,V.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,V.jsx)(ee,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-gray-400`}),(0,V.jsx)(`input`,{type:`text`,placeholder:e(`auditLogs.searchPlaceholder`),value:w,onChange:e=>T(e.target.value),onKeyPress:F,className:`w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 focus:ring-2 focus:ring-primary-500 focus:border-transparent`})]}),(0,V.jsx)(`button`,{onClick:P,className:`px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 font-medium`,children:e(`auditLogs.search`)}),(0,V.jsxs)(`button`,{onClick:()=>D(!E),className:`flex items-center px-4 py-2 border rounded-lg font-medium ${E||oe?`border-primary-500 text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700`}`,children:[(0,V.jsx)(Re,{className:`h-4 w-4 mr-2`}),e(`auditLogs.filters`),oe&&(0,V.jsx)(`span`,{className:`ml-2 px-1.5 py-0.5 text-xs bg-primary-600 text-white rounded-full`,children:[v,b,S].filter(Boolean).length})]})]}),E&&(0,V.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,V.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`auditLogs.collection`)}),(0,V.jsxs)(`select`,{value:v,onChange:e=>{y(e.target.value),d(1)},className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:``,children:e(`auditLogs.allCollections`)}),m.map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`auditLogs.user`)}),(0,V.jsxs)(`select`,{value:b,onChange:e=>{x(e.target.value),d(1)},className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:``,children:e(`auditLogs.allUsers`)}),g.map(e=>(0,V.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:e(`auditLogs.operation`)}),(0,V.jsxs)(`select`,{value:S,onChange:e=>{C(e.target.value),d(1)},className:`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white`,children:[(0,V.jsx)(`option`,{value:``,children:e(`auditLogs.allOperations`)}),(0,V.jsx)(`option`,{value:`create`,children:e(`auditLogs.operations.create`)}),(0,V.jsx)(`option`,{value:`update`,children:e(`auditLogs.operations.update`)}),(0,V.jsx)(`option`,{value:`delete`,children:e(`auditLogs.operations.delete`)}),(0,V.jsx)(`option`,{value:`publish`,children:e(`auditLogs.operations.publish`)}),(0,V.jsx)(`option`,{value:`unpublish`,children:e(`auditLogs.operations.unpublish`)})]})]})]}),oe&&(0,V.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,V.jsxs)(`button`,{onClick:I,className:`flex items-center text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white`,children:[(0,V.jsx)(tt,{className:`h-4 w-4 mr-1`}),e(`auditLogs.clearFilters`)]})})]})]})}),(0,V.jsx)(`div`,{className:`mb-4 text-sm text-gray-600 dark:text-gray-400`,children:f>0?(0,V.jsx)(V.Fragment,{children:e(`auditLogs.showingResults`,{start:(u-1)*U0+1,end:Math.min(u*U0,f),total:f})}):e(r?`auditLogs.loading`:`auditLogs.noResults`)}),(0,V.jsx)(`div`,{className:`bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden`,children:r&&t.length===0?(0,V.jsxs)(`div`,{className:`flex items-center justify-center py-12`,children:[(0,V.jsx)(Ao,{}),(0,V.jsx)(`span`,{className:`ml-3 text-gray-500 dark:text-gray-400`,children:e(`auditLogs.loading`)})]}):a?(0,V.jsxs)(`div`,{className:`p-6 text-center`,children:[(0,V.jsx)(`p`,{className:`text-red-600 dark:text-red-400`,children:a}),(0,V.jsx)(`button`,{onClick:()=>N(),className:`mt-4 text-primary-600 dark:text-primary-400 hover:underline`,children:e(`auditLogs.tryAgain`)})]}):t.length===0?(0,V.jsxs)(`div`,{className:`p-12 text-center`,children:[(0,V.jsx)(re,{className:`h-12 w-12 mx-auto text-gray-300 dark:text-gray-600 mb-4`}),(0,V.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`auditLogs.noLogs`)}),oe&&(0,V.jsx)(`button`,{onClick:I,className:`mt-4 text-primary-600 dark:text-primary-400 hover:underline`,children:e(`auditLogs.clearFilters`)})]}):(0,V.jsx)(`div`,{className:`divide-y divide-gray-200 dark:divide-gray-700`,children:t.map(t=>{let n=R(t.operation),r=n.icon,i=te(t.timestamp),a=s.has(t.id),o=ie(t);return(0,V.jsxs)(`div`,{className:`hover:bg-gray-50 dark:hover:bg-gray-750`,children:[(0,V.jsx)(`div`,{className:`p-4`,children:(0,V.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,V.jsx)(`div`,{className:`flex-shrink-0 w-10 h-10 rounded-full flex items-center justify-center ${n.bgColor}`,children:(0,V.jsx)(r,{className:`h-5 w-5 ${n.color}`})}),(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,V.jsx)(`span`,{className:`font-medium ${n.color}`,children:n.text}),(0,V.jsx)(c,{to:`/content/${t.collection}/${t.documentId}`,className:`font-medium text-gray-900 dark:text-white hover:text-primary-600 dark:hover:text-primary-400 truncate`,children:ne(t)}),(0,V.jsx)(`span`,{className:`text-xs px-2 py-0.5 bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-400 rounded`,children:t.collection})]}),(0,V.jsxs)(`div`,{className:`mt-1 flex items-center gap-4 text-sm text-gray-500 dark:text-gray-400`,children:[(0,V.jsxs)(`span`,{className:`flex items-center`,children:[(0,V.jsx)(Ke,{className:`h-4 w-4 mr-1`}),O[t.actorId]||t.actorUsername||t.actorId]}),(0,V.jsx)(`span`,{title:i.full,children:i.relative}),o&&(0,V.jsx)(`span`,{className:`text-gray-400 dark:text-gray-500`,children:o})]})]}),t.changes&&(t.changes.before||t.changes.after)&&(0,V.jsx)(`button`,{onClick:()=>L(t.id),className:`flex-shrink-0 p-2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700`,title:e(a?`auditLogs.hideDetails`:`auditLogs.showDetails`),children:a?(0,V.jsx)(ye,{className:`h-5 w-5`}):(0,V.jsx)(z,{className:`h-5 w-5`})})]})}),a&&t.changes&&(0,V.jsx)(`div`,{className:`px-4 pb-4 ml-14`,children:(0,V.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-900 rounded-lg p-4 border border-gray-200 dark:border-gray-700`,children:[(0,V.jsx)(w$,{before:t.changes.before,after:t.changes.after,operation:t.operation}),(0,V.jsx)(`div`,{className:`mt-4 pt-4 border-t border-gray-200 dark:border-gray-700`,children:(0,V.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 text-xs text-gray-500 dark:text-gray-400`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e(`auditLogs.technical.revision`)}),` `,t.revision]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e(`auditLogs.technical.documentId`)}),` `,t.documentId]}),t.ipAddress&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e(`auditLogs.technical.ip`)}),` `,t.ipAddress]}),t.actorType&&(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e(`auditLogs.technical.actorType`)}),` `,t.actorType]})]})})]})})]},t.id)})})}),ae>1&&(0,V.jsxs)(`div`,{className:`mt-6 flex items-center justify-between`,children:[(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:e(`auditLogs.page`,{current:u,total:ae})}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(`button`,{onClick:()=>d(e=>Math.max(1,e-1)),disabled:u===1,className:`flex items-center px-3 py-2 text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,V.jsx)(be,{className:`h-4 w-4 mr-1`}),e(`auditLogs.previous`)]}),(0,V.jsxs)(`button`,{onClick:()=>d(e=>Math.min(ae,e+1)),disabled:u===ae,className:`flex items-center px-3 py-2 text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed`,children:[e(`auditLogs.next`),(0,V.jsx)(z,{className:`h-4 w-4 ml-1`})]})]})]})]})}function G0(){let{t:e}=H(`studio`);return(0,V.jsx)(`div`,{className:`min-h-full flex items-center justify-center p-6`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`text-6xl font-bold text-gray-300 dark:text-gray-600 mb-4`,children:`404`}),(0,V.jsx)(`h1`,{className:`text-2xl font-semibold text-gray-900 dark:text-white mb-2`,children:e(`notFound.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 mb-6`,children:e(`notFound.message`)}),(0,V.jsx)(U,{asChild:!0,children:(0,V.jsxs)(c,{to:`/`,children:[(0,V.jsx)(ze,{className:`h-4 w-4 mr-2`}),e(`notFound.goToDashboard`)]})})]})})}function K0(){return window.TROKKY_CONFIG?.basePath||``}function q0(e){return`${K0()}${e.startsWith(`/`)?e:`/${e}`}`}function J0(e){window.location.href=q0(e)}var Y0=3e4,X0=class extends Error{constructor(){super(`OAuth callback timed out`),this.name=`OAuthCallbackTimeoutError`}},Z0=!1;function Q0(){if(Z0)return;Z0=!0;let e={en:{auth:{oauth:{notCompleted:`Sign-in could not be completed. Please try again.`}}},fr:{auth:{oauth:{notCompleted:`La connexion n'a pas pu aboutir. Veuillez réessayer.`}}}},t=yr();for(let n of ur){let r=e[n];r&&t.addResourceBundle(n,`studio`,r,!0,!1)}}function $0({onLoginSuccess:e}){Q0();let{t}=H(`studio`),[n,r]=(0,B.useState)(`processing`),[i,a]=(0,B.useState)(null),[o,s]=(0,B.useState)(null),c=(0,B.useRef)(!1);(0,B.useEffect)(()=>{if(!c.current)try{if(!sessionStorage.getItem(`oauth_state`)){if(Ar.getToken()){c.current=!0,r(`success`),s(t(`auth.oauth.loginSuccess`)),setTimeout(()=>{e()},100);return}c.current=!0,r(`error`),a(t(`auth.oauth.notCompleted`));return}c.current=!0,l()}catch{c.current=!0,r(`error`),a(t(`auth.oauth.notCompleted`))}},[]);let l=async()=>{let n=new AbortController,i,o=!1,c=new Promise((e,t)=>{i=setTimeout(()=>{t(new X0),n.abort()},Y0)});try{let i=new URLSearchParams(window.location.search),a=i.get(`code`),l=i.get(`state`);if(i.get(`error`)){let e=i.get(`error_description`)||`Authentication was denied`;throw Error(e)}if(!a||!l)throw Error(`Missing authorization code or state parameter`);let u=sessionStorage.getItem(`oauth_state`),d=sessionStorage.getItem(`oauth_code_verifier`),f=sessionStorage.getItem(`oauth_mode`)||`login`;if(l!==u)throw Error(`Invalid state parameter. This may be a security issue.`);if(!d)throw Error(`Missing code verifier. Please try again.`);let p=e2(),m=await Promise.race([W.post(`/auth/oauth/google/callback`,{code:a,state:l,codeVerifier:d,mode:f,deviceId:p},{signal:n.signal}),c]);if(o=!0,sessionStorage.removeItem(`oauth_state`),sessionStorage.removeItem(`oauth_code_verifier`),sessionStorage.removeItem(`oauth_mode`),m.success&&m.data){if(f===`login`){if(m.data.requiresMFA&&m.data.mfaToken){sessionStorage.setItem(`oauth_mfa_token`,m.data.mfaToken),sessionStorage.setItem(`oauth_mfa_methods`,JSON.stringify(m.data.methods||[])),r(`success`),s(t(`auth.oauth.mfaRequired`)),setTimeout(()=>{window.location.href=K0()+`/?mfa=verify`},500);return}if(m.data.requiresMFASetup&&m.data.setupToken){sessionStorage.setItem(`oauth_mfa_setup_token`,m.data.setupToken),sessionStorage.setItem(`oauth_mfa_allowed_methods`,JSON.stringify(m.data.allowedMethods||[])),sessionStorage.setItem(`oauth_mfa_message`,m.data.message||`MFA setup required`),r(`success`),s(t(`auth.oauth.mfaSetupRequired`)),setTimeout(()=>{window.location.href=K0()+`/?mfa=setup`},500);return}let{token:n,refreshToken:i,user:a}=m.data;if(n&&a)Ar.persist(n,i),r(`success`),s(t(`auth.oauth.loginSuccess`)),setTimeout(()=>{e()},500);else throw Error(t(`auth.oauth.invalidResponse`))}else r(`success`),s(m.data.message||`${t(`auth.oauth.accountLinked`)} (${m.data.provider?.email})`),setTimeout(()=>{window.location.href=K0()+`/user/preferences`},2e3)}else throw Error(m.error?.message||`OAuth callback failed`)}catch(e){if(o)return;o=!0,console.error(`OAuth callback error:`,e);let n=e instanceof X0;r(`error`),a(n?t(`auth.oauth.notCompleted`):e instanceof Error?e.message:`An unexpected error occurred`),sessionStorage.removeItem(`oauth_state`),sessionStorage.removeItem(`oauth_code_verifier`),sessionStorage.removeItem(`oauth_mode`)}finally{clearTimeout(i),c.catch(()=>void 0)}};return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsx)(`div`,{className:`w-full max-w-sm`,children:(0,V.jsxs)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl text-center`,children:[n===`processing`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`lg`,className:`mx-auto mb-4`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white mb-2`,children:t(`auth.oauth.processing`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:t(`auth.oauth.completingAuth`)})]}),n===`success`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{className:`w-16 h-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-8 h-8 text-green-600 dark:text-green-400`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white mb-2`,children:t(`auth.oauth.success`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400`,children:o})]}),n===`error`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{className:`w-16 h-16 mx-auto mb-4 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-8 h-8 text-red-600 dark:text-red-400`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white mb-2`,children:t(`auth.oauth.failed`)}),(0,V.jsx)(`p`,{className:`text-red-600 dark:text-red-400 mb-4`,children:i}),(0,V.jsx)(`button`,{onClick:()=>{window.location.href=K0()+`/`},className:`px-6 py-2 bg-gray-900 dark:bg-white text-white dark:text-gray-900 rounded-lg font-medium hover:bg-gray-800 dark:hover:bg-gray-100 transition-colors`,children:t(`auth.oauth.returnToLogin`)})]})]})})})}function e2(){let e=localStorage.getItem(`trokky_device_id`);if(e)return e;let t=crypto.randomUUID();return localStorage.setItem(`trokky_device_id`,t),t}function t2(){let{t:e}=H(`studio`),[t]=p(),n=r(),i=t.get(`code`),[a,o]=(0,B.useState)(`loading`),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1);(0,B.useEffect)(()=>{if(!i){o(`error`),u(e(`auth.device.noCode`));return}m()},[i]);let m=async()=>{try{let t=await W.get(`/auth/device/verify?code=${i}`);if(t.success&&t.data)c(t.data),o(`pending`);else{o(`error`);let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.device.fetchError`);u(n)}}catch(t){o(`error`);let n=t?.message||e(`auth.device.connectError`);u(n)}},h=async()=>{if(i){f(!0);try{let t=await W.post(`/auth/device/verify`,{user_code:i,action:`authorize`});if(t.success)o(`authorized`);else{let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.device.authError`);u(n),o(`error`)}}catch(t){let n=t?.message||e(`auth.device.authError`);u(n),o(`error`)}finally{f(!1)}}},g=async()=>{if(i){f(!0);try{let t=await W.post(`/auth/device/verify`,{user_code:i,action:`deny`});if(t.success)o(`denied`);else{let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.device.denyError`);u(n),o(`error`)}}catch(t){let n=t?.message||e(`auth.device.denyError`);u(n),o(`error`)}finally{f(!1)}}},_=t=>t.split(` `).filter(Boolean).map(t=>{switch(t){case`openid`:return e(`auth.device.scopes.openid`);case`profile`:return e(`auth.device.scopes.profile`);case`content:read`:return e(`auth.device.scopes.contentRead`);case`content:write`:return e(`auth.device.scopes.contentWrite`);case`content:delete`:return e(`auth.device.scopes.contentDelete`);case`media:read`:return e(`auth.device.scopes.mediaRead`);case`media:write`:return e(`auth.device.scopes.mediaWrite`);case`offline_access`:return e(`auth.device.scopes.offlineAccess`);default:return t}});return(0,V.jsx)(`div`,{className:`min-h-screen bg-gray-100 dark:bg-gray-900 flex items-center justify-center p-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md bg-white dark:bg-gray-800 rounded-xl shadow-lg p-8`,children:[(0,V.jsx)(`div`,{className:`text-center mb-6`,children:(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`auth.device.pageTitle`)})}),(()=>{switch(a){case`loading`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`p`,{className:`mt-4 text-gray-600 dark:text-gray-400`,children:e(`auth.device.loading`)})]});case`pending`:return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,V.jsx)(`div`,{className:`w-16 h-16 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(_e,{className:`w-8 h-8 text-blue-600 dark:text-blue-400`})})}),(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.authorizeDevice`)}),(0,V.jsxs)(`p`,{className:`mt-2 text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(`span`,{className:`font-mono font-bold text-lg text-blue-600 dark:text-blue-400`,children:s?.clientName||s?.clientId||`Trokky CLI`}),` `,e(`auth.device.requestingAccess`)]})]}),(0,V.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 rounded-lg p-4`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:e(`auth.device.deviceCode`)}),(0,V.jsx)(`p`,{className:`font-mono text-2xl font-bold text-center text-gray-900 dark:text-white tracking-wider`,children:i})]}),s?.scopes&&s.scopes.length>0&&(0,V.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 rounded-lg p-4`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:e(`auth.device.allowApplication`)}),(0,V.jsx)(`ul`,{className:`space-y-2`,children:_(s.scopes.join(` `)).map((e,t)=>(0,V.jsxs)(`li`,{className:`flex items-center text-sm text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(Ae,{className:`w-4 h-4 mr-2 text-green-500`}),e]},t))})]}),(0,V.jsxs)(`div`,{className:`flex gap-3`,children:[(0,V.jsx)(U,{variant:`secondary`,className:`flex-1`,onClick:g,disabled:d,children:e(`auth.device.deny`)}),(0,V.jsx)(U,{variant:`primary`,className:`flex-1`,onClick:h,disabled:d,children:d?(0,V.jsx)(Ao,{size:`sm`}):e(`auth.device.authorize`)})]})]});case`authorized`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(Ae,{className:`w-10 h-10 text-green-600 dark:text-green-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.authorized`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:e(`auth.device.authorizedMessage`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:()=>window.close(),children:e(`auth.device.closeWindow`)})]});case`denied`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(We,{className:`w-10 h-10 text-red-600 dark:text-red-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.denied`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:e(`auth.device.deniedMessage`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:()=>window.close(),children:e(`auth.device.closeWindow`)})]});case`expired`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-yellow-100 dark:bg-yellow-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(We,{className:`w-10 h-10 text-yellow-600 dark:text-yellow-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.expired`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:e(`auth.device.expiredMessage`)})]});case`error`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(We,{className:`w-10 h-10 text-red-600 dark:text-red-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.device.error`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:l||e(`common.error`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:()=>n(`/`),children:e(`auth.device.returnToStudio`)})]})}})()]})})}function n2(){let{t:e}=H(`studio`),[t]=p(),n=r(),[i,a]=(0,B.useState)(`loading`),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(!1),f=t.get(`client_id`),m=t.get(`redirect_uri`),h=t.get(`response_type`),g=t.get(`scope`),_=t.get(`state`),v=t.get(`code_challenge`),y=t.get(`code_challenge_method`);(0,B.useEffect)(()=>{if(!f||!m||!h||!_||!v){a(`error`),l(e(`auth.authorize.missingParams`));return}b()},[f,m,h,g,_,v]);let b=async()=>{try{let t=new URLSearchParams;t.set(`response_type`,h||``),t.set(`client_id`,f||``),t.set(`redirect_uri`,m||``),g&&t.set(`scope`,g),t.set(`state`,_||``),t.set(`code_challenge`,v||``),t.set(`code_challenge_method`,y||`S256`);let n=await W.get(`/auth/authorize?${t.toString()}`);if(n.success&&n.data)s(n.data),n.data.hasExistingConsent?await x(n.data):a(`pending`);else{a(`error`);let t=typeof n.error==`string`?n.error:n.error?.message||e(`auth.authorize.invalidRequest`);l(t)}}catch(t){a(`error`);let n=t?.message||e(`auth.authorize.validateError`);l(n)}},x=async e=>{try{let t=await W.post(`/auth/authorize`,{action:`approve`,client_id:e.client.id,redirect_uri:e.redirectUri,scopes:e.scopes,state:e.state,code_challenge:e.codeChallenge});t.success&&t.data?.redirectUrl?window.location.href=t.data.redirectUrl:a(`pending`)}catch{a(`pending`)}},S=async()=>{if(o){d(!0);try{let t=await W.post(`/auth/authorize`,{action:`approve`,client_id:o.client.id,redirect_uri:o.redirectUri,scopes:o.scopes,state:o.state,code_challenge:o.codeChallenge});if(t.success&&t.data?.redirectUrl)a(`redirecting`),window.location.href=t.data.redirectUrl;else{let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.authorize.authFailed`);l(n),a(`error`)}}catch(t){let n=t?.message||e(`auth.authorize.authFailed`);l(n),a(`error`)}finally{d(!1)}}},C=async()=>{if(o){d(!0);try{let t=await W.post(`/auth/authorize`,{action:`deny`,client_id:o.client.id,redirect_uri:o.redirectUri,scopes:o.scopes,state:o.state,code_challenge:o.codeChallenge});if(t.success&&t.data?.redirectUrl)a(`redirecting`),window.location.href=t.data.redirectUrl;else{let n=typeof t.error==`string`?t.error:t.error?.message||e(`auth.authorize.denyFailed`);l(n),a(`error`)}}catch(t){let n=t?.message||e(`auth.authorize.denyFailed`);l(n),a(`error`)}finally{d(!1)}}},w=t=>{switch(t){case`openid`:return e(`auth.device.scopes.openid`);case`profile`:return e(`auth.device.scopes.profile`);case`content:read`:return e(`auth.device.scopes.contentRead`);case`content:write`:return e(`auth.device.scopes.contentWrite`);case`content:delete`:return e(`auth.device.scopes.contentDelete`);case`media:read`:return e(`auth.device.scopes.mediaRead`);case`media:write`:return e(`auth.device.scopes.mediaWrite`);case`offline_access`:return e(`auth.device.scopes.offlineAccess`);default:return t}};return(0,V.jsx)(`div`,{className:`min-h-screen bg-gray-100 dark:bg-gray-900 flex items-center justify-center p-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md bg-white dark:bg-gray-800 rounded-xl shadow-lg p-8`,children:[(0,V.jsx)(`div`,{className:`text-center mb-6`,children:(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-white`,children:e(`auth.authorize.pageTitle`)})}),(()=>{switch(i){case`loading`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`p`,{className:`mt-4 text-gray-600 dark:text-gray-400`,children:e(`auth.authorize.validating`)})]});case`pending`:return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,V.jsx)(`div`,{className:`w-16 h-16 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(He,{className:`w-8 h-8 text-blue-600 dark:text-blue-400`})})}),(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.authorize.authorizeApp`)}),(0,V.jsxs)(`p`,{className:`mt-2 text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(`span`,{className:`font-semibold text-blue-600 dark:text-blue-400`,children:o?.client.name}),` `,e(`auth.authorize.wantsAccess`)]}),o?.client.description&&(0,V.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-gray-500`,children:o.client.description})]}),o?.scopes&&o.scopes.length>0&&(0,V.jsxs)(`div`,{className:`bg-gray-50 dark:bg-gray-800 rounded-lg p-4`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300 mb-3`,children:e(`auth.authorize.allowApplication`)}),(0,V.jsx)(`ul`,{className:`space-y-2`,children:o.scopes.map((e,t)=>(0,V.jsxs)(`li`,{className:`flex items-center text-sm text-gray-600 dark:text-gray-400`,children:[(0,V.jsx)(Ae,{className:`w-4 h-4 mr-2 text-green-500 flex-shrink-0`}),w(e)]},t))})]}),o?.client.homepageUrl&&(0,V.jsx)(`div`,{className:`text-center text-sm`,children:(0,V.jsx)(`a`,{href:o.client.homepageUrl,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:e(`auth.authorize.visitWebsite`)})}),(0,V.jsxs)(`div`,{className:`flex gap-3`,children:[(0,V.jsx)(U,{variant:`secondary`,className:`flex-1`,onClick:C,disabled:u,children:e(`auth.authorize.deny`)}),(0,V.jsx)(U,{variant:`primary`,className:`flex-1`,onClick:S,disabled:u,children:u?(0,V.jsx)(Ao,{size:`sm`}):e(`auth.authorize.authorize`)})]}),(0,V.jsx)(`p`,{className:`text-xs text-center text-gray-500 dark:text-gray-500`,children:e(`auth.authorize.consentNote`)})]});case`redirecting`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.authorize.redirecting`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:e(`auth.authorize.redirectingMessage`)})]});case`error`:return(0,V.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 space-y-4`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center`,children:(0,V.jsx)(We,{className:`w-10 h-10 text-red-600 dark:text-red-400`})}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-white`,children:e(`auth.authorize.error`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:c||e(`common.error`)}),(0,V.jsx)(U,{variant:`secondary`,onClick:()=>n(`/`),children:e(`auth.authorize.returnToStudio`)})]})}})()]})})}var r2=()=>window.TROKKY_CONFIG?.basePath||``,i2=n([{path:`/oauth/callback`,element:(0,V.jsx)(Wa,{children:(0,V.jsx)($0,{onLoginSuccess:()=>window.location.href=r2()+`/`})})},{path:`/auth/device`,element:(0,V.jsx)(Wa,{children:(0,V.jsx)(t2,{})})},{path:`/auth/authorize`,element:(0,V.jsx)(Wa,{children:(0,V.jsx)(n2,{})})},{path:`/`,element:(0,V.jsx)(Wa,{children:(0,V.jsx)(Ha,{})}),errorElement:(0,V.jsx)(Wa,{children:(0,V.jsx)(`div`,{children:`Error occurred`})}),children:[{index:!0,element:(0,V.jsx)(Ro,{})},{path:`content`,element:(0,V.jsx)(Q$,{})},{path:`content/:schemaName`,element:(0,V.jsx)(Q$,{})},{path:`content/:schemaName/:documentId`,element:(0,V.jsx)(Q$,{})},{path:`media`,element:(0,V.jsx)(w1,{})},{path:`users`,element:(0,V.jsx)(K1,{})},{path:`users/:userId`,element:(0,V.jsx)(K1,{})},{path:`settings`,element:(0,V.jsx)(e0,{})},{path:`settings/:section`,element:(0,V.jsx)(e0,{})},{path:`user/preferences`,element:(0,V.jsx)(V0,{})},{path:`audit-logs`,element:(0,V.jsx)(W0,{})},{path:`*`,element:(0,V.jsx)(G0,{})}]}],{basename:r2()});function a2(){return(0,V.jsx)(f,{router:i2})}function o2(e){return e=e.replace(/^#/,``),e.length===3&&(e=e.split(``).map(e=>e+e).join(``)),e.length===6?`${parseInt(e.substring(0,2),16)} ${parseInt(e.substring(2,4),16)} ${parseInt(e.substring(4,6),16)}`:null}function s2(e){let t=document.documentElement;if(e.primaryColor){let n=o2(e.primaryColor);n&&(t.style.setProperty(`--color-primary-500`,n),t.style.setProperty(`--color-primary-600`,n),t.style.setProperty(`--color-primary-700`,n))}if(e.secondaryColor){let n=o2(e.secondaryColor);n&&(t.style.setProperty(`--color-secondary-500`,n),t.style.setProperty(`--color-secondary-600`,n),t.style.setProperty(`--color-secondary-700`,n))}}async function c2(){try{let e=await W.get(`/config/studio`);if(e.success&&e.data?.studioConfig?.branding)return e.data.studioConfig.branding}catch(e){console.error(`Failed to fetch branding:`,e)}return window.TROKKY_CONFIG?.branding||{title:`Trokky Studio`}}var l2=Fr(`PasskeyLoginButton`);function u2({onSuccess:e,onMFARequired:t,onMFASetupRequired:n,onError:r,disabled:i,className:a=``}){let{t:o}=H(`studio`),[s,c]=(0,B.useState)(!1);return(0,V.jsxs)(U,{type:`button`,onClick:async()=>{c(!0);try{l2.debug(`Requesting passkey authentication options`);let i=await W.post(`/auth/passkey/login/options`,{});if(!i.success||!i.data){let e=i.error?.message||o(`passkey.optionsFailed`,`Failed to start passkey authentication`);l2.error(`Failed to get passkey options`,{error:e}),r?.(e);return}let{sessionId:a,...s}=i.data;l2.debug(`Received passkey options`,{sessionId:a.substring(0,8)});let c;try{c=await A0({optionsJSON:s}),l2.debug(`Browser authentication completed`)}catch(e){e.name===`NotAllowedError`?(l2.info(`User cancelled passkey authentication`),r?.(o(`passkey.cancelled`,`Authentication was cancelled`))):e.name===`NotSupportedError`?(l2.warn(`Passkeys not supported in this browser`),r?.(o(`passkey.notSupported`,`Passkeys are not supported in this browser`))):(l2.error(`Browser authentication failed`,{error:e.message}),r?.(e.message||o(`passkey.authFailed`,`Passkey authentication failed`)));return}l2.debug(`Verifying passkey with server`);let l=await W.post(`/auth/passkey/login/verify`,{sessionId:a,credential:c,deviceId:d2()});if(!l.success||!l.data){let e=l.error?.message||o(`passkey.verifyFailed`,`Passkey verification failed`);l2.error(`Passkey verification failed`,{error:e}),r?.(e);return}let u=l.data;u.requiresMFA&&u.mfaToken?(l2.info(`MFA required after passkey authentication`),t?.({mfaToken:u.mfaToken,methods:u.methods||[],expiresIn:u.expiresIn||300})):u.requiresMFASetup&&u.setupToken?(l2.info(`MFA setup required after passkey authentication`),n?.({setupToken:u.setupToken,allowedMethods:u.allowedMethods||[],message:u.message||``,expiresIn:u.expiresIn||900})):u.token&&u.refreshToken&&u.user?(l2.info(`Passkey authentication successful`,{userId:u.user.id}),e?.({token:u.token,refreshToken:u.refreshToken,user:u.user,expiresAt:u.expiresAt||``})):(l2.error(`Unexpected response from passkey verification`),r?.(o(`passkey.unexpectedResponse`,`Unexpected response from server`)))}catch(e){let t=e instanceof Error?e.message:o(`passkey.authFailed`,`Passkey authentication failed`);l2.error(`Passkey authentication error`,{error:t}),r?.(t)}finally{c(!1)}},disabled:i||s,variant:`outline`,className:`w-full flex items-center justify-center gap-3 h-12 border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors ${a}`,children:[s?(0,V.jsx)(Ao,{size:`sm`}):(0,V.jsx)(f2,{className:`w-5 h-5`}),(0,V.jsx)(`span`,{className:`text-gray-700 dark:text-gray-300`,children:o(`passkey.signIn`,`Sign in with Passkey`)})]})}function d2(){let e=`trokky_device_id`,t=localStorage.getItem(e);if(!t){let n=new Uint8Array(16);crypto.getRandomValues(n),t=Array.from(n,e=>e.toString(16).padStart(2,`0`)).join(``),localStorage.setItem(e,t)}return t}function f2({className:e}){return(0,V.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,V.jsx)(`path`,{d:`M12 2C8.13 2 5 5.13 5 9c0 2.38 1.19 4.47 3 5.74V17a1 1 0 001 1h1v1a1 1 0 001 1h1v1a1 1 0 001 1h2a1 1 0 001-1v-4.26c1.81-1.27 3-3.36 3-5.74 0-3.87-3.13-7-7-7z`,className:`fill-current text-gray-600 dark:text-gray-300`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`9`,r:`2`,className:`fill-current text-white dark:text-gray-800`})]})}function p2({mfaToken:e,methods:t,onSuccess:n,onBack:r}){let{t:i}=H(`studio`),[a,o]=(0,B.useState)(``),[s,c]=(0,B.useState)(t.includes(`totp`)?`totp`:t[0]),[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(!1),[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)(!1),y=(0,B.useRef)(null);(0,B.useEffect)(()=>{y.current?.focus()},[s]),(0,B.useEffect)(()=>{s===`email`&&!_&&b()},[s]);let b=async()=>{f(!0),g(null);try{let t=await W.post(`/auth/mfa/send-code`,{mfaToken:e});t.success?v(!0):g(t.error?.message||`Failed to send code`)}catch(e){g(e instanceof Error?e.message:`Failed to send code`)}finally{f(!1)}},x=async t=>{if(t.preventDefault(),!a.trim()){g(i(`mfa.enterCode`));return}u(!0),g(null);try{let t=p?m2():void 0,r=p?h2():void 0,i=s===`backup`?`/auth/mfa/verify-backup`:`/auth/mfa/verify`,c=await W.post(i,{mfaToken:e,code:a.trim(),method:s===`backup`?void 0:s,trustDevice:p,deviceId:t,deviceName:r});c.success&&c.data?(c.data.token&&await W.storeTokens(c.data.token,c.data.refreshToken),c.data.warning&&console.warn(`MFA Warning:`,c.data.warning),n(c.data.token,c.data.user)):(g(c.error?.message||`Verification failed`),o(``))}catch(e){g(e instanceof Error?e.message:`Verification failed`),o(``)}finally{u(!1)}},S=e=>{let t=s===`backup`?e.target.value.replace(/[^A-Za-z0-9-]/g,``).toUpperCase():e.target.value.replace(/[^0-9]/g,``);o(t)},C=e=>{switch(e){case`totp`:return(0,V.jsx)(L,{className:`h-5 w-5`});case`email`:return(0,V.jsx)(ne,{className:`h-5 w-5`});case`backup`:return(0,V.jsx)(te,{className:`h-5 w-5`})}},w=e=>{switch(e){case`totp`:return i(`mfa.authenticatorApp`);case`email`:return i(`mfa.emailCode`);case`backup`:return i(`mfa.backupCode`)}},T=e=>{switch(e){case`totp`:return i(`mfa.totpDescription`);case`email`:return i(_?`mfa.emailDescriptionSent`:`mfa.emailDescriptionPending`);case`backup`:return i(`mfa.backupDescription`)}},E=[...t,`backup`];return(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:r,className:`p-2 -ml-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors`,children:(0,V.jsx)(Me,{className:`h-5 w-5`})}),(0,V.jsx)(`h2`,{className:`ml-2 text-xl font-semibold text-gray-900 dark:text-gray-100`,children:i(`mfa.title`)})]}),E.length>1&&(0,V.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:E.map(e=>(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{c(e),o(``),g(null),e===`email`&&v(!1)},className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium transition-colors ${s===e?`bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300 border border-primary-300 dark:border-primary-700`:`bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 border border-transparent hover:bg-gray-200 dark:hover:bg-gray-600`}`,children:[C(e),w(e)]},e))}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:T(s)}),h&&(0,V.jsx)(`div`,{className:`p-3 bg-red-50/80 dark:bg-red-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h})}),(0,V.jsxs)(`form`,{onSubmit:x,className:`space-y-4`,children:[(0,V.jsx)(`div`,{className:`relative`,children:(0,V.jsx)(h1,{ref:y,type:`text`,value:a,onChange:S,placeholder:s===`backup`?`XXXX-XXXX`:`000000`,required:!0,disabled:l||s===`email`&&d,autoComplete:`one-time-code`,inputMode:`numeric`,pattern:s===`backup`?`[A-Z0-9]{4}-[A-Z0-9]{4}`:`[0-9]{6}`,maxLength:s===`backup`?9:6,className:`w-full text-center text-2xl tracking-widest font-mono bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 focus:border-primary-500 focus:ring-0 transition-colors`})}),(0,V.jsxs)(`div`,{className:`flex items-center`,children:[(0,V.jsx)(V$,{id:`trust-device`,checked:p,onChange:m,className:`mr-2`}),(0,V.jsx)(`label`,{htmlFor:`trust-device`,className:`text-sm text-gray-600 dark:text-gray-400 cursor-pointer`,children:i(`mfa.trustDevice`)})]}),(0,V.jsx)(U,{type:`submit`,className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium text-base transition-colors`,disabled:l||!a.trim(),children:l?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),i(`mfa.verifying`)]}):i(`mfa.verify`)}),s===`email`&&_&&(0,V.jsx)(`button`,{type:`button`,onClick:b,disabled:d,className:`w-full text-sm text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 transition-colors`,children:i(d?`mfa.sendingCode`:`mfa.resendCode`)})]})]})}function m2(){let e=localStorage.getItem(`trokky_device_id`);if(e)return e;let t=crypto.randomUUID();return localStorage.setItem(`trokky_device_id`,t),t}function h2(){let e=navigator.userAgent,t=`Browser`,n=`Unknown`;return e.includes(`Firefox`)?t=`Firefox`:e.includes(`Edge`)?t=`Edge`:e.includes(`Chrome`)?t=`Chrome`:e.includes(`Safari`)&&(t=`Safari`),e.includes(`Windows`)?n=`Windows`:e.includes(`Mac`)?n=`macOS`:e.includes(`Linux`)?n=`Linux`:e.includes(`Android`)?n=`Android`:(e.includes(`iPhone`)||e.includes(`iPad`))&&(n=`iOS`),`${t} on ${n}`}var g2={turnstile:`https://challenges.cloudflare.com/turnstile/v0/api.js`,recaptcha:`https://www.google.com/recaptcha/api.js`},_2={turnstile:`script[src*="challenges.cloudflare.com/turnstile"]`,recaptcha:`script[src*="google.com/recaptcha/api.js"]`};function v2({provider:e,siteKey:t,options:n={},onVerify:r,onError:i,onExpire:a,className:o=``}){let{t:s}=H(`studio`),c=(0,B.useRef)(null),l=(0,B.useRef)(null),u=(0,B.useRef)({onVerify:r,onError:i,onExpire:a}),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(null);return(0,B.useEffect)(()=>{u.current={onVerify:r,onError:i,onExpire:a}},[r,i,a]),(0,B.useEffect)(()=>{if(e===`hcaptcha`){m(s(`captcha.errors.hcaptchaNotSupported`));return}let t=g2[e],n=_2[e];if(!t){m(s(`captcha.errors.providerNotSupported`,{provider:e}));return}if(e===`turnstile`&&window.turnstile){f(!0);return}if(e===`recaptcha`&&window.grecaptcha){f(!0);return}let r=document.querySelector(n);if(r){let t=()=>{e===`recaptcha`&&window.grecaptcha?window.grecaptcha.ready(()=>f(!0)):f(!0)},n=()=>m(s(`captcha.errors.scriptLoadFailed`));return r.addEventListener(`load`,t),r.addEventListener(`error`,n),()=>{r.removeEventListener(`load`,t),r.removeEventListener(`error`,n)}}let i=document.createElement(`script`);i.src=t,i.async=!0,i.onload=()=>{e===`recaptcha`&&window.grecaptcha?window.grecaptcha.ready(()=>f(!0)):f(!0)},i.onerror=()=>{m(s(`captcha.errors.scriptLoadFailed`))},document.head.appendChild(i)},[e]),(0,B.useEffect)(()=>{if(!d||!c.current||e!==`turnstile`)return;if(!window.turnstile){m(s(`captcha.errors.notAvailable`,{provider:`Turnstile`}));return}if(l.current!==null)return;let r=setTimeout(()=>{if(c.current&&l.current===null)try{l.current=window.turnstile.render(c.current,{sitekey:t,callback:e=>u.current.onVerify(e),"error-callback":e=>u.current.onError?.(e),"expired-callback":()=>u.current.onExpire?.(),theme:n.theme||`auto`,size:n.size||`normal`,language:n.language})}catch(e){console.error(`Failed to render Turnstile widget:`,e),m(s(`captcha.errors.renderFailed`))}},100);return()=>{if(clearTimeout(r),l.current!==null&&window.turnstile){try{window.turnstile.remove(l.current)}catch{}l.current=null}}},[d,e,t,n.theme,n.size]),(0,B.useEffect)(()=>{if(!d||!c.current||e!==`recaptcha`)return;if(!window.grecaptcha){m(s(`captcha.errors.notAvailable`,{provider:`reCAPTCHA`}));return}if(l.current!==null)return;let r=setTimeout(()=>{if(c.current&&l.current===null)try{let e=n.theme===`auto`?`light`:n.theme||`light`,r=n.size===`invisible`?`normal`:n.size||`normal`;l.current=window.grecaptcha.render(c.current,{sitekey:t,callback:e=>u.current.onVerify(e),"error-callback":()=>u.current.onError?.(`reCAPTCHA error`),"expired-callback":()=>u.current.onExpire?.(),theme:e,size:r})}catch(e){console.error(`Failed to render reCAPTCHA widget:`,e),m(s(`captcha.errors.renderFailed`))}},100);return()=>{if(clearTimeout(r),l.current!==null&&window.grecaptcha){try{window.grecaptcha.reset(l.current)}catch{}l.current=null}}},[d,e,t,n.theme,n.size]),p?(0,V.jsx)(`div`,{className:`captcha-widget captcha-error ${o}`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600`,children:p})}):d?(0,V.jsx)(`div`,{ref:c,className:`captcha-widget ${o}`,"data-provider":e}):(0,V.jsx)(`div`,{className:`captcha-widget captcha-loading ${o}`,children:(0,V.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,V.jsx)(`div`,{className:`w-5 h-5 border-2 border-gray-300 border-t-blue-600 rounded-full animate-spin`}),(0,V.jsx)(`span`,{className:`ml-2 text-sm text-gray-500`,children:s(`captcha.loading`)})]})})}function y2({endpoint:e}){let[t,n]=(0,B.useState)({isLoading:!0,config:null,isRequired:!1,token:null,error:null});(0,B.useEffect)(()=>{(async()=>{try{let t=await W.get(`/auth/captcha/status`);if(t.success&&t.data){let{enabled:r,config:i,protectedEndpoints:a}=t.data;n(t=>({...t,isLoading:!1,config:r&&i?i:null,isRequired:r&&a[e]}))}else n(e=>({...e,isLoading:!1,isRequired:!1}))}catch(e){console.warn(`Failed to fetch CAPTCHA status:`,e),n(e=>({...e,isLoading:!1,isRequired:!1}))}})()},[e]);let r=(0,B.useCallback)(e=>{n(t=>({...t,token:e,error:null}))},[]),i=(0,B.useCallback)(e=>{n(t=>({...t,token:null,error:e}))},[]),a=(0,B.useCallback)(()=>{n(e=>({...e,token:null}))},[]),o=(0,B.useCallback)(()=>{n(e=>({...e,token:null,error:null}))},[]);return{...t,onVerify:r,onError:i,onExpire:a,reset:o}}function b2({onLoginSuccess:e,onMFASetupRequired:t}){let{t:n}=H(`auth`),[r,i]=(0,B.useState)({username:``,password:``}),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(``),[h,g]=(0,B.useState)(null),[_,v]=(0,B.useState)(!1),[y,b]=(0,B.useState)(!1),[x,S]=(0,B.useState)(!1),[C,w]=(0,B.useState)({required:!1,setupRequired:!1}),[T,E]=(0,B.useState)({step:`select`,verificationCode:``,isLoading:!1}),D=y2({endpoint:`login`}),O=async()=>{if(C.setupToken){E(e=>({...e,isLoading:!0,error:void 0}));try{let e=await W.post(`/auth/mfa/setup/totp`,{},{headers:{"X-MFA-Setup-Token":C.setupToken}});if(e.success&&e.data){let t=e.data;E(e=>({...e,step:`totp-setup`,selectedMethod:`totp`,totpSecret:t.secret,totpQrCode:t.qrCode,isLoading:!1}))}else throw Error(e.error?.message||`Failed to initialize TOTP setup`)}catch(e){E(t=>({...t,isLoading:!1,error:e instanceof Error?e.message:`Setup failed`}))}}},k=async()=>{if(C.setupToken){E(e=>({...e,isLoading:!0,error:void 0}));try{let e=await W.post(`/auth/mfa/setup/email`,{},{headers:{"X-MFA-Setup-Token":C.setupToken}});if(e.success)E(e=>({...e,step:`email-setup`,selectedMethod:`email`,isLoading:!1}));else throw Error(e.error?.message||`Failed to send verification email`)}catch(e){E(t=>({...t,isLoading:!1,error:e instanceof Error?e.message:`Setup failed`}))}}},A=()=>{T.pendingToken&&T.pendingUser&&(Ar.persist(T.pendingToken,T.pendingRefreshToken),e(T.pendingToken,T.pendingUser))},j=()=>{if(T.backupCodes){let e=T.backupCodes.join(`
737
+ `);navigator.clipboard.writeText(e)}},M=async()=>{if(C.setupToken&&T.verificationCode){E(e=>({...e,isLoading:!0,error:void 0}));try{let t=T.selectedMethod===`totp`?`/auth/mfa/setup/totp/verify`:`/auth/mfa/setup/email/verify`,n=await W.post(t,{code:T.verificationCode},{headers:{"X-MFA-Setup-Token":C.setupToken}});if(n.success&&n.data){let t=n.data;t.backupCodes&&t.backupCodes.length>0?E(e=>({...e,step:`backup-codes`,backupCodes:t.backupCodes,pendingToken:t.token,pendingRefreshToken:t.refreshToken,pendingUser:t.user,isLoading:!1})):t.token&&t.user?(Ar.persist(t.token,t.refreshToken),e(t.token,t.user)):E(e=>({...e,step:`verify`,isLoading:!1}))}else throw Error(n.error?.message||`Verification failed`)}catch(e){E(t=>({...t,isLoading:!1,error:e instanceof Error?e.message:`Verification failed`}))}}};(0,B.useEffect)(()=>{let e=()=>{let e=localStorage.getItem(`theme`),t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;e===`dark`||!e&&t?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`)};e(),(async()=>{let e=await c2();g(e),s2(e)})(),(async()=>{try{let e=await W.get(`/auth/oauth/status`);e.success&&e.data?.providers?.google&&b(!0)}catch(e){console.debug(`OAuth status check failed:`,e)}})(),(async()=>{try{if(!window.PublicKeyCredential){console.debug(`WebAuthn not supported in this browser`);return}let e=await W.get(`/auth/passkey/status`);e.success&&e.data?.enabled&&S(!0)}catch(e){console.debug(`Passkey status check failed:`,e)}})();let t=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>{localStorage.getItem(`theme`)||e()};t.addEventListener(`change`,n);let r=window.TROKKY_CONFIG?.backendUrl;if(r)m(r||void 0);else{let e=Rr.get(Lr.BACKEND_URL);if(e)m(e);else{let e=`${window.location.origin}/api`;m(e)}}return()=>{t.removeEventListener(`change`,n)}},[]),(0,B.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get(`mfa`);if(e===`verify`){let e=sessionStorage.getItem(`oauth_mfa_token`),t=sessionStorage.getItem(`oauth_mfa_methods`);if(e&&t){let n=JSON.parse(t);sessionStorage.removeItem(`oauth_mfa_token`),sessionStorage.removeItem(`oauth_mfa_methods`),w({required:!0,setupRequired:!1,mfaToken:e,methods:n}),window.history.replaceState({},``,window.location.pathname)}}else if(e===`setup`){let e=sessionStorage.getItem(`oauth_mfa_setup_token`),t=sessionStorage.getItem(`oauth_mfa_allowed_methods`),n=sessionStorage.getItem(`oauth_mfa_message`);if(e&&t){let r=JSON.parse(t);sessionStorage.removeItem(`oauth_mfa_setup_token`),sessionStorage.removeItem(`oauth_mfa_allowed_methods`),sessionStorage.removeItem(`oauth_mfa_message`),w({required:!1,setupRequired:!0,setupToken:e,allowedMethods:r,message:n||`Your organization requires MFA. Please set up multi-factor authentication.`}),window.history.replaceState({},``,window.location.pathname)}}},[]);let N=async i=>{if(i.preventDefault(),c(!0),u(null),D.isRequired&&!D.token){u(n(`errors.captchaRequired`)),c(!1);return}try{let n=window.TROKKY_CONFIG?.backendUrl;p&&!n&&(Rr.set(Lr.BACKEND_URL,p),W.setBackendUrl(p));let i=x2(),o=await W.login(r.username,r.password,a,i,D.token||void 0);if(o.success&&o.data){let n=o.data;if(n.requiresMFA&&n.mfaToken){w({required:!0,setupRequired:!1,mfaToken:n.mfaToken,methods:n.methods||[`totp`]});return}if(n.requiresMFASetup&&n.setupToken){w({required:!1,setupRequired:!0,setupToken:n.setupToken,allowedMethods:n.allowedMethods||[`totp`,`email`],message:n.message}),t&&t(n.setupToken,n.allowedMethods||[`totp`,`email`]);return}n.token&&n.user?e(n.token,n.user):u(`Invalid login response`)}else u(o.error?.message||`Login failed`)}catch(e){u(e instanceof Error?e.message:`Login failed`)}finally{c(!1)}},P=(t,n)=>{e(t,n)},F=()=>{w({required:!1,setupRequired:!1}),i({username:r.username,password:``})},I=e=>t=>{i(n=>({...n,[e]:t.target.value}))},L=h||{title:`Trokky Studio`};return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-sm`,children:[(0,V.jsxs)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:[!C.required&&(0,V.jsx)(`div`,{className:`mb-8 text-center`,children:L.logo?(0,V.jsx)(`div`,{className:`flex justify-center`,children:(0,V.jsx)(`img`,{src:L.logo,alt:L.organizationName||L.title,className:`h-20 w-auto object-contain`})}):(0,V.jsx)(`h1`,{className:`text-2xl font-bold text-primary-600 dark:text-primary-400`,children:L.organizationName||L.title})}),C.required&&C.mfaToken&&C.methods&&(0,V.jsx)(p2,{mfaToken:C.mfaToken,methods:C.methods,onSuccess:P,onBack:F,onError:u}),C.setupRequired&&(0,V.jsxs)(`div`,{className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`text-center mb-4 p-4 bg-amber-50 dark:bg-amber-900/20 rounded-lg border border-amber-200 dark:border-amber-800`,children:[(0,V.jsx)(`h2`,{className:`text-lg font-semibold text-amber-800 dark:text-amber-200 mb-2`,children:n(`mfa.required`)}),(0,V.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:C.message||n(`mfa.setupRequired`)})]}),T.error&&(0,V.jsx)(`div`,{className:`p-3 bg-red-50 dark:bg-red-900/20 rounded-lg border border-red-200 dark:border-red-800`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:T.error})}),T.step===`select`&&(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 text-center`,children:n(`mfa.chooseMethod`)}),C.allowedMethods?.includes(`totp`)&&(0,V.jsx)(`button`,{onClick:O,disabled:T.isLoading,className:`w-full p-4 border-2 border-gray-200 dark:border-gray-700 rounded-lg hover:border-primary-500 dark:hover:border-primary-500 transition-colors text-left disabled:opacity-50`,children:(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(`div`,{className:`w-10 h-10 bg-primary-100 dark:bg-primary-900 rounded-lg flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-6 h-6 text-primary-600 dark:text-primary-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z`})})}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-white`,children:n(`mfa.authenticatorApp`)}),(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:n(`mfa.authenticatorAppDesc`)})]})]})}),C.allowedMethods?.includes(`email`)&&(0,V.jsx)(`button`,{onClick:k,disabled:T.isLoading,className:`w-full p-4 border-2 border-gray-200 dark:border-gray-700 rounded-lg hover:border-primary-500 dark:hover:border-primary-500 transition-colors text-left disabled:opacity-50`,children:(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(`div`,{className:`w-10 h-10 bg-blue-100 dark:bg-blue-900 rounded-lg flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-6 h-6 text-blue-600 dark:text-blue-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z`})})}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-white`,children:n(`mfa.emailCode`)}),(0,V.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:n(`mfa.emailCodeDesc`)})]})]})}),T.isLoading&&(0,V.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,V.jsx)(Ao,{size:`md`})})]}),T.step===`totp-setup`&&(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:n(`mfa.scanQR`)}),T.totpQrCode&&(0,V.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,V.jsx)(`img`,{src:T.totpQrCode,alt:`TOTP QR Code`,className:`w-48 h-48 bg-white p-2 rounded-lg`})}),T.totpSecret&&(0,V.jsxs)(`div`,{className:`mb-4`,children:[(0,V.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-1`,children:n(`mfa.manualEntry`)}),(0,V.jsx)(`code`,{className:`text-sm bg-gray-100 dark:bg-gray-800 px-3 py-1 rounded font-mono`,children:T.totpSecret})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:n(`mfa.enterCode`)}),(0,V.jsx)(h1,{type:`text`,value:T.verificationCode,onChange:e=>E(t=>({...t,verificationCode:e.target.value.replace(/\D/g,``).slice(0,6)})),placeholder:`000000`,maxLength:6,className:`text-center text-2xl tracking-widest font-mono`,autoFocus:!0})]}),(0,V.jsx)(U,{onClick:M,disabled:T.isLoading||T.verificationCode.length!==6,className:`w-full h-12 bg-primary-600 hover:bg-primary-700 text-white rounded-lg font-medium disabled:opacity-50`,children:T.isLoading?(0,V.jsx)(Ao,{size:`sm`}):n(`mfa.verifyComplete`)}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>E(e=>({...e,step:`select`,verificationCode:``,error:void 0})),className:`w-full text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`,children:n(`mfa.chooseDifferent`)})]}),T.step===`email-setup`&&(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 mx-auto mb-4 bg-blue-100 dark:bg-blue-900 rounded-full flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-8 h-8 text-blue-600 dark:text-blue-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z`})})}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`mfa.emailSent`)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2`,children:n(`mfa.enterEmailCode`)}),(0,V.jsx)(h1,{type:`text`,value:T.verificationCode,onChange:e=>E(t=>({...t,verificationCode:e.target.value.replace(/\D/g,``).slice(0,6)})),placeholder:`000000`,maxLength:6,className:`text-center text-2xl tracking-widest font-mono`,autoFocus:!0})]}),(0,V.jsx)(U,{onClick:M,disabled:T.isLoading||T.verificationCode.length!==6,className:`w-full h-12 bg-primary-600 hover:bg-primary-700 text-white rounded-lg font-medium disabled:opacity-50`,children:T.isLoading?(0,V.jsx)(Ao,{size:`sm`}):n(`mfa.verifyComplete`)}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>E(e=>({...e,step:`select`,verificationCode:``,error:void 0})),className:`w-full text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`,children:n(`mfa.chooseDifferent`)})]}),T.step===`backup-codes`&&T.backupCodes&&(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`w-16 h-16 mx-auto mb-4 bg-green-100 dark:bg-green-900 rounded-full flex items-center justify-center`,children:(0,V.jsx)(`svg`,{className:`w-8 h-8 text-green-600 dark:text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z`})})}),(0,V.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-white mb-2`,children:n(`mfa.backupCodes.title`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`mfa.backupCodes.description`)})]}),(0,V.jsx)(`div`,{className:`p-4 bg-gray-50 dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-700`,children:(0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-2 font-mono text-sm`,children:T.backupCodes.map((e,t)=>(0,V.jsx)(`div`,{className:`text-center py-1 px-2 bg-white dark:bg-gray-800 rounded border border-gray-200 dark:border-gray-600`,children:e},t))})}),(0,V.jsx)(`div`,{className:`flex gap-2`,children:(0,V.jsxs)(U,{onClick:j,variant:`outline`,className:`flex-1 h-10`,children:[(0,V.jsx)(`svg`,{className:`w-4 h-4 mr-2`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z`})}),n(`mfa.backupCodes.copy`)]})}),(0,V.jsx)(`div`,{className:`p-3 bg-amber-50 dark:bg-amber-900/20 rounded-lg border border-amber-200 dark:border-amber-800`,children:(0,V.jsxs)(`p`,{className:`text-xs text-amber-700 dark:text-amber-300`,children:[(0,V.jsxs)(`strong`,{children:[n(`mfa.backupCodes.warning`).split(`:`)[0],`:`]}),` `,n(`mfa.backupCodes.warning`).split(`:`).slice(1).join(`:`)]})}),(0,V.jsx)(U,{onClick:A,className:`w-full h-12 bg-primary-600 hover:bg-primary-700 text-white rounded-lg font-medium`,children:n(`mfa.backupCodes.continue`)})]}),T.step!==`backup-codes`&&(0,V.jsx)(`button`,{type:`button`,onClick:F,className:`w-full text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`,children:n(`login.backToLogin`)})]}),!C.required&&!C.setupRequired&&(0,V.jsxs)(V.Fragment,{children:[l&&(0,V.jsx)(`div`,{className:`mb-6 p-3 bg-red-50/80 dark:bg-red-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:l})}),(0,V.jsxs)(`form`,{onSubmit:N,className:`space-y-6`,children:[(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(h1,{type:`text`,value:r.username,onChange:I(`username`),placeholder:n(`login.emailOrUsername`),required:!0,disabled:s,autoComplete:`username`,autoFocus:!0,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`})}),(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(h1,{type:_?`text`:`password`,value:r.password,onChange:I(`password`),placeholder:n(`login.password`),required:!0,disabled:s,autoComplete:`current-password`,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 pr-12 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>v(!_),className:`absolute right-2 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300 transition-colors`,tabIndex:-1,"aria-label":_?`Hide password`:`Show password`,children:_?(0,V.jsx)(le,{className:`h-5 w-5`}):(0,V.jsx)(ce,{className:`h-5 w-5`})})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,V.jsxs)(`label`,{className:`flex items-center`,children:[(0,V.jsx)(V$,{id:`remember-me`,checked:a,onChange:o,className:`mr-2`}),(0,V.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:n(`login.rememberMe`)})]}),(0,V.jsx)(`a`,{href:q0(`/forgot-password`),className:`text-sm text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 transition-colors`,children:n(`login.forgotPassword`)})]}),!window.TROKKY_CONFIG?.backendUrl&&(0,V.jsx)(`div`,{className:`flex justify-end`,children:(0,V.jsxs)(`button`,{type:`button`,onClick:()=>f(!d),className:`flex items-center text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors`,children:[d?(0,V.jsx)(ye,{className:`h-3 w-3 mr-1`}):(0,V.jsx)(z,{className:`h-3 w-3 mr-1`}),n(`advanced.title`)]})}),!window.TROKKY_CONFIG?.backendUrl&&d&&(0,V.jsxs)(`div`,{className:`mt-4 p-4 bg-gray-50/50 dark:bg-gray-900/30 rounded-lg border border-gray-200/30 dark:border-gray-700/30`,children:[(0,V.jsx)(h1,{type:`url`,value:p,onChange:e=>m(e.target.value),placeholder:n(`advanced.backendUrl`),disabled:s,className:`text-sm bg-transparent border-gray-300 dark:border-gray-600 px-4 py-2`}),(0,V.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-gray-400`,children:n(`advanced.customEndpoint`)})]}),D.isRequired&&D.config&&(0,V.jsx)(`div`,{className:`flex justify-center my-4`,children:(0,V.jsx)(v2,{provider:D.config.provider,siteKey:D.config.siteKey,options:D.config.options,onVerify:D.onVerify,onError:D.onError,onExpire:D.onExpire})}),(0,V.jsx)(U,{type:`submit`,className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium text-base transition-colors`,disabled:s||!r.username||!r.password||D.isRequired&&!D.token,children:s?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),n(`login.signingIn`)]}):n(`login.signIn`)}),(x||y)&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`relative my-6`,children:[(0,V.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,V.jsx)(`div`,{className:`w-full border-t border-gray-300 dark:border-gray-600`})}),(0,V.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,V.jsx)(`span`,{className:`px-4 bg-white dark:bg-gray-800 text-gray-500 dark:text-gray-400`,children:n(`login.orContinueWith`)})})]}),(0,V.jsxs)(`div`,{className:`space-y-3`,children:[x&&(0,V.jsx)(u2,{onSuccess:t=>{Rr.set(Lr.AUTH_TOKEN,t.token),Rr.set(Lr.REFRESH_TOKEN,t.refreshToken),e(t.token,t.user)},onMFARequired:e=>{w({required:!0,setupRequired:!1,mfaToken:e.mfaToken,methods:e.methods})},onMFASetupRequired:e=>{w({required:!1,setupRequired:!0,setupToken:e.setupToken,allowedMethods:e.allowedMethods,message:e.message})},onError:e=>u(e),disabled:s}),y&&(0,V.jsx)(t0,{mode:`login`,onError:e=>u(e),disabled:s})]})]})]})]})]}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:L.title})})]})})}function x2(){let e=localStorage.getItem(`trokky_device_id`);if(e)return e;let t=crypto.randomUUID();return localStorage.setItem(`trokky_device_id`,t),t}function S2(){let{t:e}=H(`studio`),[t,n]=(0,B.useState)(``),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(null),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(null),d=y2({endpoint:`passwordResetRequest`});(0,B.useEffect)(()=>{let e=localStorage.getItem(`theme`),t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;e===`dark`||!e&&t?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`),(async()=>{let e=await c2();u(e),s2(e)})()},[]);let f=async n=>{if(n.preventDefault(),i(!0),o(null),d.isRequired&&!d.token){o(e(`auth.forgotPassword.captchaRequired`)),i(!1);return}try{let n=await W.post(`/auth/request-reset`,{email:t,captchaToken:d.token||void 0});n.success?c(!0):o(n.error?.message||e(`auth.forgotPassword.sendError`))}catch(t){o(t instanceof Error?t.message:e(`auth.forgotPassword.sendError`))}finally{i(!1)}},p=l||{title:`Trokky Studio`};return s?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsx)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,V.jsx)(Ae,{className:`h-16 w-16 text-green-500 dark:text-green-400`})}),(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-primary-600 dark:text-primary-400 mb-3`,children:e(`auth.forgotPassword.checkEmail`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-6`,dangerouslySetInnerHTML:{__html:e(`auth.forgotPassword.emailSentMessage`,{email:t})}}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mb-8`,children:e(`auth.forgotPassword.linkExpires`)}),(0,V.jsx)(U,{onClick:()=>J0(`/`),className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium transition-colors`,children:e(`auth.forgotPassword.backToSignIn`)})]})}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:p.title})})]})}):(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsxs)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:[(0,V.jsx)(`div`,{className:`mb-6`,children:(0,V.jsxs)(`a`,{href:q0(`/`),className:`inline-flex items-center text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,V.jsx)(Me,{className:`h-4 w-4 mr-2`}),e(`auth.forgotPassword.backToSignIn`)]})}),(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-primary-600 dark:text-primary-400 mb-2`,children:e(`auth.forgotPassword.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-8`,children:e(`auth.forgotPassword.subtitle`)}),a&&(0,V.jsx)(`div`,{className:`mb-6 p-3 bg-red-50/80 dark:bg-red-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:a})}),(0,V.jsxs)(`form`,{onSubmit:f,className:`space-y-6`,children:[(0,V.jsx)(`div`,{children:(0,V.jsx)(h1,{type:`email`,value:t,onChange:e=>n(e.target.value),placeholder:`your@email.com`,required:!0,disabled:r,autoComplete:`email`,autoFocus:!0,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`})}),d.isRequired&&d.config&&(0,V.jsx)(`div`,{className:`flex justify-center my-4`,children:(0,V.jsx)(v2,{provider:d.config.provider,siteKey:d.config.siteKey,options:d.config.options,onVerify:d.onVerify,onError:d.onError,onExpire:d.onExpire})}),(0,V.jsx)(U,{type:`submit`,className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium text-base transition-colors`,disabled:r||!t||d.isRequired&&!d.token,children:r?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),e(`auth.forgotPassword.sending`)]}):e(`auth.forgotPassword.sendResetLink`)})]})]}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:p.title})})]})})}function C2(){let{t:e}=H(`studio`),[t,n]=(0,B.useState)(``),[r,i]=(0,B.useState)(``),[a,o]=(0,B.useState)(``),[s,c]=(0,B.useState)(!1),[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(!0),[h,g]=(0,B.useState)(!1),[_,v]=(0,B.useState)(null),[y,b]=(0,B.useState)(!1),[x,S]=(0,B.useState)(null),C=y2({endpoint:`passwordResetVerify`});(0,B.useEffect)(()=>{let e=localStorage.getItem(`trokky_theme`),t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;e===`dark`||e===`system`&&t||!e&&t?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`)},[]),(0,B.useEffect)(()=>{let t=new URLSearchParams(window.location.search).get(`token`);if(!t){v(e(`auth.resetPassword.noToken`)),m(!1);return}n(t),(async()=>{try{let n=await W.post(`/auth/verify-reset-token`,{token:t});n.success&&n.data?.valid?(g(!0),S(n.data.expiresIn??null)):v(n.data?.message||e(`auth.resetPassword.tokenInvalid`))}catch{v(e(`auth.resetPassword.tokenVerifyError`))}finally{m(!1)}})()},[]);let w=async n=>{if(n.preventDefault(),v(null),r.length<8){v(e(`auth.resetPassword.passwordMinLength`));return}if(r!==a){v(e(`auth.resetPassword.passwordMismatch`));return}if(C.isRequired&&!C.token){v(e(`auth.resetPassword.captchaRequired`));return}f(!0);try{let n=await W.post(`/auth/reset-password`,{token:t,newPassword:r,captchaToken:C.token||void 0});n.success?b(!0):v(n.error?.message||e(`auth.resetPassword.resetError`))}catch(t){v(t instanceof Error?t.message:e(`auth.resetPassword.resetError`))}finally{f(!1)}},T=r?(t=>t.length<8?e(`auth.resetPassword.strengthTooShort`):t.length<12?e(`auth.resetPassword.strengthWeak`):t.length<16&&/[A-Z]/.test(t)&&/[0-9]/.test(t)?e(`auth.resetPassword.strengthGood`):t.length>=16&&/[A-Z]/.test(t)&&/[0-9]/.test(t)&&/[^A-Za-z0-9]/.test(t)?e(`auth.resetPassword.strengthStrong`):e(`auth.resetPassword.strengthMedium`))(r):null,E=window.TROKKY_CONFIG?.branding||{title:`Trokky Studio`};return p?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`p`,{className:`mt-4 text-gray-600 dark:text-gray-400`,children:e(`auth.resetPassword.verifying`)})]})}):y?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsx)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,V.jsx)(Ae,{className:`h-16 w-16 text-green-500 dark:text-green-400`})}),(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-gray-900 dark:text-white mb-3`,children:e(`auth.resetPassword.success`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-8`,children:e(`auth.resetPassword.successMessage`)}),(0,V.jsx)(U,{onClick:()=>J0(`/`),className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium transition-colors`,children:e(`auth.resetPassword.signIn`)})]})}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:E.title})})]})}):h?(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsxs)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:[(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-gray-900 dark:text-white mb-2`,children:e(`auth.resetPassword.title`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-6`,children:e(`auth.resetPassword.subtitle`)}),x&&x<10&&(0,V.jsx)(`div`,{className:`mb-4 p-3 bg-yellow-50/80 dark:bg-yellow-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-yellow-800 dark:text-yellow-200`,children:e(`auth.resetPassword.linkExpiresIn`,{minutes:x,count:x})})}),_&&(0,V.jsx)(`div`,{className:`mb-6 p-3 bg-red-50/80 dark:bg-red-900/20 rounded-lg`,children:(0,V.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:_})}),(0,V.jsxs)(`form`,{onSubmit:w,className:`space-y-6`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(h1,{type:s?`text`:`password`,value:r,onChange:e=>i(e.target.value),placeholder:e(`auth.resetPassword.newPassword`),required:!0,disabled:d,autoComplete:`new-password`,autoFocus:!0,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 pr-12 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>c(!s),className:`absolute right-4 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,children:s?(0,V.jsx)(le,{className:`h-5 w-5`}):(0,V.jsx)(ce,{className:`h-5 w-5`})})]}),r&&(0,V.jsxs)(`p`,{className:`mt-2 text-xs ${T===e(`auth.resetPassword.strengthStrong`)?`text-green-600 dark:text-green-400`:T===e(`auth.resetPassword.strengthGood`)?`text-blue-600 dark:text-blue-400`:T===e(`auth.resetPassword.strengthMedium`)?`text-yellow-600 dark:text-yellow-400`:`text-red-600 dark:text-red-400`}`,children:[e(`auth.resetPassword.strength`),`: `,T]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`div`,{className:`relative`,children:[(0,V.jsx)(h1,{type:l?`text`:`password`,value:a,onChange:e=>o(e.target.value),placeholder:e(`auth.resetPassword.confirmPassword`),required:!0,disabled:d,autoComplete:`new-password`,className:`w-full bg-transparent border-0 border-b-2 border-gray-200 dark:border-gray-600 rounded-none px-4 py-3 pr-12 text-base placeholder-gray-400 dark:placeholder-gray-500 focus:border-primary-500 focus:ring-0 transition-colors`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>u(!l),className:`absolute right-4 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,children:l?(0,V.jsx)(le,{className:`h-5 w-5`}):(0,V.jsx)(ce,{className:`h-5 w-5`})})]}),a&&a!==r&&(0,V.jsx)(`p`,{className:`mt-2 text-xs text-red-600 dark:text-red-400`,children:e(`auth.resetPassword.passwordMismatch`)})]}),(0,V.jsxs)(`div`,{className:`text-sm text-gray-600 dark:text-gray-400 space-y-1`,children:[(0,V.jsx)(`p`,{children:e(`auth.resetPassword.requirements`)}),(0,V.jsxs)(`ul`,{className:`list-disc list-inside space-y-1 ml-2`,children:[(0,V.jsx)(`li`,{className:r.length>=8?`text-green-600 dark:text-green-400`:``,children:e(`auth.resetPassword.requireLength`)}),(0,V.jsx)(`li`,{className:/[A-Z]/.test(r)?`text-green-600 dark:text-green-400`:``,children:e(`auth.resetPassword.requireUppercase`)}),(0,V.jsx)(`li`,{className:/[0-9]/.test(r)?`text-green-600 dark:text-green-400`:``,children:e(`auth.resetPassword.requireNumber`)})]})]}),C.isRequired&&C.config&&(0,V.jsx)(`div`,{className:`flex justify-center my-4`,children:(0,V.jsx)(v2,{provider:C.config.provider,siteKey:C.config.siteKey,options:C.config.options,onVerify:C.onVerify,onError:C.onError,onExpire:C.onExpire})}),(0,V.jsx)(U,{type:`submit`,className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium text-base transition-colors`,disabled:d||!r||!a||r!==a||C.isRequired&&!C.token,children:d?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ao,{size:`sm`,className:`mr-2`}),e(`auth.resetPassword.resetting`)]}):e(`auth.resetPassword.resetButton`)})]})]}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:E.title})})]})}):(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 dark:from-gray-900 dark:to-gray-800 px-4`,children:(0,V.jsxs)(`div`,{className:`w-full max-w-md`,children:[(0,V.jsx)(`div`,{className:`bg-white/60 dark:bg-gray-800/60 backdrop-blur-sm rounded-2xl border border-white/20 dark:border-gray-700/20 p-8 shadow-xl`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,V.jsx)(We,{className:`h-16 w-16 text-red-500 dark:text-red-400`})}),(0,V.jsx)(`h2`,{className:`text-2xl font-semibold text-gray-900 dark:text-white mb-3`,children:e(`auth.resetPassword.invalidLink`)}),(0,V.jsx)(`p`,{className:`text-gray-600 dark:text-gray-300 mb-2`,children:_||e(`auth.resetPassword.invalidLinkMessage`)}),(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400 mb-8`,children:e(`auth.resetPassword.linkExpireNote`)}),(0,V.jsx)(U,{onClick:()=>J0(`/forgot-password`),className:`w-full h-12 bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-lg font-medium transition-colors`,children:e(`auth.resetPassword.requestNewLink`)})]})}),(0,V.jsx)(`div`,{className:`mt-8 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-gray-400 dark:text-gray-500`,children:E.title})})]})})}function w2({show:e,onDismiss:t,onRefresh:n,expiresAt:r}){let{t:i}=H(`studio`),[a,o]=(0,B.useState)(``);return(0,B.useEffect)(()=>{if(!e||!r)return;let t=()=>{let e=new Date,t=r.getTime()-e.getTime();if(t<=0){o(`Session expired`);return}let n=Math.floor(t/6e4),i=Math.floor(t%6e4/1e3);o(n>0?`${n} minute${n>1?`s`:``}`:`${i} second${i>1?`s`:``}`)};t();let n=setInterval(t,1e3);return()=>clearInterval(n)},[e,r]),e?(0,V.jsx)(`div`,{className:`fixed top-4 right-4 z-toast max-w-sm`,children:(0,V.jsx)(`div`,{className:`bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-4 shadow-lg`,children:(0,V.jsxs)(`div`,{className:`flex items-start`,children:[(0,V.jsx)(`div`,{className:`flex-shrink-0`,children:(0,V.jsx)(de,{className:`h-5 w-5 text-amber-400`})}),(0,V.jsxs)(`div`,{className:`ml-3 flex-1`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium text-amber-800 dark:text-amber-200`,children:i(`sessionTimeout.title`)}),(0,V.jsx)(`div`,{className:`mt-1 text-sm text-amber-700 dark:text-amber-300`,children:(0,V.jsx)(`p`,{children:i(`sessionTimeout.expireIn`,{time:a})})}),(0,V.jsxs)(`div`,{className:`mt-3 flex space-x-2`,children:[(0,V.jsx)(U,{size:`sm`,onClick:()=>{console.log(`Extend Session button clicked!`),n()},className:`bg-amber-600 hover:bg-amber-700 text-white`,children:i(`sessionTimeout.stayLoggedIn`)}),(0,V.jsx)(U,{size:`sm`,variant:`ghost`,onClick:t,className:`text-amber-800 dark:text-amber-200 hover:bg-amber-100 dark:hover:bg-amber-800/20`,children:i(`common.dismiss`)})]})]}),(0,V.jsx)(`div`,{className:`ml-auto flex-shrink-0`,children:(0,V.jsxs)(`button`,{type:`button`,className:`inline-flex rounded-md text-amber-400 hover:text-amber-500 focus:outline-none focus:ring-2 focus:ring-amber-500 focus:ring-offset-2 focus:ring-offset-amber-50`,onClick:t,children:[(0,V.jsx)(`span`,{className:`sr-only`,children:i(`common.close`)}),(0,V.jsx)(tt,{className:`h-5 w-5`})]})})]})})}):null}function T2(){let{showTimeoutWarning:e,sessionExpiresAt:t,dismissTimeoutWarning:n,refreshSession:r}=ri();return(0,V.jsx)(w2,{show:e,expiresAt:t,onDismiss:n,onRefresh:r})}var E2=({toast:e,onRemove:t})=>{let{t:n}=H(`studio`),{id:r,message:i,type:a,duration:o=3e3}=e;return(0,B.useEffect)(()=>{let e=setTimeout(()=>{t(r)},o);return()=>{clearTimeout(e)}},[r,o,t]),(0,V.jsxs)(`div`,{className:`
738
738
  flex items-center px-3 py-2 rounded-lg border shadow-lg backdrop-blur-sm
739
739
  transition-all duration-300 ease-in-out transform animate-in slide-in-from-top-2
740
740
  ${(()=>{switch(a){case`success`:return`bg-white dark:bg-gray-800 border-green-200 dark:border-green-800 text-gray-800 dark:text-gray-200`;case`error`:return`bg-white dark:bg-gray-800 border-red-200 dark:border-red-800 text-gray-800 dark:text-gray-200`;case`warning`:return`bg-white dark:bg-gray-800 border-amber-200 dark:border-amber-800 text-gray-800 dark:text-gray-200`;default:return`bg-white dark:bg-gray-800 border-blue-200 dark:border-blue-800 text-gray-800 dark:text-gray-200`}})()}
741
- `,role:`alert`,children:[(()=>{switch(a){case`success`:return(0,V.jsx)(F,{className:`w-4 h-4 text-green-500`});case`error`:return(0,V.jsx)(tt,{className:`w-4 h-4 text-red-500`});case`warning`:return(0,V.jsx)(de,{className:`w-4 h-4 text-amber-500`});default:return(0,V.jsx)(ue,{className:`w-4 h-4 text-blue-500`})}})(),(0,V.jsx)(`div`,{className:`ml-2 flex-1`,children:(0,V.jsx)(`p`,{className:`text-sm font-medium`,children:i})}),(0,V.jsx)(`button`,{onClick:()=>t(r),className:`ml-3 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors opacity-60 hover:opacity-100`,"aria-label":n(`toast.closeNotification`),children:(0,V.jsx)(tt,{className:`w-3 h-3`})})]})},E2=()=>{let{t:e}=H(`studio`),[t,n]=(0,B.useState)([]);(0,B.useEffect)(()=>{let e=e=>{let{message:t,type:r}=e.detail,i={id:`toast-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,message:t,type:r,duration:r===`error`?4e3:3e3};n(e=>[...e,i].slice(-3))};return window.addEventListener(`studio:toast`,e),()=>{window.removeEventListener(`studio:toast`,e)}},[]);let r=(0,B.useCallback)(e=>{n(t=>t.filter(t=>t.id!==e))},[]);return t.length===0?null:(0,V.jsx)(`div`,{className:`fixed bottom-4 right-4 z-toast space-y-2 max-w-xs w-full pointer-events-none`,"aria-live":`polite`,"aria-label":e(`toast.notifications`),children:t.map(e=>(0,V.jsx)(`div`,{className:`pointer-events-auto`,children:(0,V.jsx)(T2,{toast:e,onRemove:r})},e.id))})},D2=({isOpen:e,title:t,message:n,confirmText:r,cancelText:i,variant:a=`default`,onConfirm:o,onCancel:s})=>{let{t:c}=H(`studio`),l=r||c(`confirmDialog.defaultConfirm`),u=i||c(`confirmDialog.defaultCancel`),d=a===`danger`?{icon:(0,V.jsx)(de,{className:`h-6 w-6 text-red-600`}),iconBg:`bg-red-100 dark:bg-red-900/20`,confirmButton:`bg-red-600 hover:bg-red-700 focus:ring-red-500 text-white`}:{icon:(0,V.jsx)(de,{className:`h-6 w-6 text-amber-600`}),iconBg:`bg-amber-100 dark:bg-amber-900/20`,confirmButton:`bg-blue-600 hover:bg-blue-700 focus:ring-blue-500 text-white`};return(0,V.jsx)(ia,{open:e,onClose:s,variant:`center`,size:`md`,ariaLabel:t||n,children:(0,V.jsxs)(ia.Body,{padded:!1,className:`px-4 pb-4 pt-5 sm:p-6`,children:[(0,V.jsx)(`button`,{onClick:s,className:`absolute right-4 top-4 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,"aria-label":u,children:(0,V.jsx)(tt,{className:`h-5 w-5`})}),(0,V.jsxs)(`div`,{className:`sm:flex sm:items-start`,children:[(0,V.jsx)(`div`,{className:`mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full ${d.iconBg} sm:mx-0 sm:h-10 sm:w-10`,children:d.icon}),(0,V.jsxs)(`div`,{className:`mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left`,children:[t&&(0,V.jsx)(`h3`,{className:`text-base font-semibold leading-6 text-gray-900 dark:text-white`,children:t}),(0,V.jsx)(`div`,{className:`mt-2`,children:(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:n})})]})]}),(0,V.jsxs)(`div`,{className:`mt-5 sm:mt-4 sm:flex sm:flex-row-reverse gap-3`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:o,className:`inline-flex w-full justify-center rounded-md px-3 py-2 text-sm font-semibold shadow-sm sm:w-auto ${d.confirmButton} focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-800`,children:l}),(0,V.jsx)(`button`,{type:`button`,onClick:s,className:`mt-3 inline-flex w-full justify-center rounded-md bg-white dark:bg-gray-700 px-3 py-2 text-sm font-semibold text-gray-900 dark:text-gray-200 shadow-sm ring-1 ring-inset ring-gray-300 dark:ring-gray-600 hover:bg-gray-50 dark:hover:bg-gray-600 sm:mt-0 sm:w-auto focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-800`,children:u})]})]})})},O2=()=>{let[e,t]=(0,B.useState)({isOpen:!1,message:``});(0,B.useEffect)(()=>{let e=e=>{let{message:n,title:r,confirmText:i,cancelText:a,variant:o,resolve:s}=e.detail;t({isOpen:!0,message:n,title:r,confirmText:i,cancelText:a,variant:o,resolve:s})};return window.addEventListener(`studio:confirm`,e),()=>{window.removeEventListener(`studio:confirm`,e)}},[]);let n=(0,B.useCallback)(()=>{e.resolve?.(!0),t(e=>({...e,isOpen:!1}))},[e.resolve]),r=(0,B.useCallback)(()=>{e.resolve?.(!1),t(e=>({...e,isOpen:!1}))},[e.resolve]);return(0,V.jsx)(D2,{isOpen:e.isOpen,title:e.title,message:e.message,confirmText:e.confirmText,cancelText:e.cancelText,variant:e.variant,onConfirm:n,onCancel:r})},k2=Fr(`useDocumentTitle`);function A2(e=!1){let t=async()=>{try{let e=await W.get(`/config/studio`);if(e.success&&e.data?.studioConfig?.branding){let t=e.data.studioConfig.branding;if(t.title){document.title=t.title,k2.debug(`Document title updated from branding`,{title:t.title});return}}}catch(e){k2.warn(`Failed to load studio config for document title`,e)}document.title=`Trokky Studio`,k2.debug(`Document title updated from default`,{title:`Trokky Studio`})};(0,B.useEffect)(()=>{t();let e=()=>{k2.debug(`Settings changed, updating document title`),t()};return window.addEventListener(`trokky:settings:updated`,e),()=>{window.removeEventListener(`trokky:settings:updated`,e)}},[e])}var j2=Fr(`Debug`);typeof window<`u`&&(window.TrokkyDebug={clearStructureCache(){try{Xr().clearCache(),j2.info(`✅ Structure cache cleared`);try{localStorage.removeItem(`trokky_structure_cache`),sessionStorage.removeItem(`trokky_structure_cache`),j2.info(`✅ Browser structure cache cleared`)}catch(e){j2.warn(`⚠️ Could not clear browser cache:`,e)}}catch(e){j2.error(`❌ Failed to clear structure cache:`,e)}},async refreshStructure(){try{let e=await Xr().refreshFromEndpoint();e?j2.info(`✅ Structure refreshed from endpoint:`,{title:e.title,itemsCount:e.items?.length||0}):j2.warn(`⚠️ No structure returned from endpoint, falling back to defaults`)}catch(e){j2.error(`❌ Failed to refresh structure:`,e)}},async getStructureInfo(){try{let e=Xr(),t=await e.getStructure(),n={cached:e.isCached(),title:t.title,itemsCount:t.items?.length||0,metadata:t.metadata,items:t.items?.map(e=>({type:e.type,title:e.title,schemaType:e.schemaType,hasChildren:!!e.items?.length}))};return j2.info(`📊 Current structure info:`,n),n}catch(e){return j2.error(`❌ Failed to get structure info:`,e),{error:e instanceof Error?e.message:String(e)}}},clearAllCache(){try{this.clearStructureCache(),Ar.clear(),[`trokky_user_data`,`trokky_theme`,`trokky_sidebar_collapsed`,`trokky_studio_config`].forEach(e=>{try{localStorage.removeItem(e),sessionStorage.removeItem(e)}catch{}}),j2.info(`✅ All browser cache cleared`)}catch(e){j2.error(`❌ Failed to clear all cache:`,e)}},enableDebugLogging(){try{localStorage.setItem(`trokky_debug_enabled`,`true`),window.TrokkyLogger?.setLevel&&window.TrokkyLogger.setLevel(`debug`),j2.info(`✅ Debug logging enabled`)}catch(e){j2.error(`❌ Failed to enable debug logging:`,e)}},disableDebugLogging(){try{localStorage.removeItem(`trokky_debug_enabled`),window.TrokkyLogger?.setLevel&&window.TrokkyLogger.setLevel(`info`),j2.info(`✅ Debug logging disabled`)}catch(e){j2.error(`❌ Failed to disable debug logging:`,e)}}});function M2(){let e=window.TROKKY_CONFIG?.i18n;return{defaultLocale:e?.defaultLocale||`en`,supportedLocales:e?.supportedLocales||[`en`,`fr`],fallbackLocale:e?.fallbackLocale||`en`,detectBrowserLanguage:e?.detectBrowserLanguage??!0,debug:e?.debug??!1}}W.initialize();var N2=new ht({defaultOptions:{queries:{retry:2,staleTime:3e5}}});function P2(){let{t:e}=H(`common`),{isAuthenticated:t,isLoading:n,checkAuth:r}=ri(),i=Fr(`AppContent`),a=(0,B.useRef)({});A2(t),(0,B.useEffect)(()=>{let e={isAuthenticated:t,isLoading:n},r=a.current;(r.isAuthenticated!==t||r.isLoading!==n)&&(i.debug(`Auth state changed`,e),a.current=e)},[t,n,i]);let o=()=>{i.info(`Login successful, rechecking auth state`);let e=sessionStorage.getItem(`trokky_oauth_redirect`);if(e){sessionStorage.removeItem(`trokky_oauth_redirect`),i.info(`Redirecting to OAuth flow`,{url:e}),window.location.href=e;return}r()};if(n)return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`h2`,{className:`mt-4 text-lg font-semibold text-gray-900 dark:text-white`,children:e(`app.loadingStudio`)})]})});if(!t){let e=window.location.pathname,t=window.TROKKY_CONFIG?.basePath||``,n=e.replace(t,``);if(n===`/forgot-password`)return(0,V.jsx)(x2,{});if(n===`/reset-password`)return(0,V.jsx)(S2,{});if(n===`/oauth/callback`)return(0,V.jsx)(Q0,{onLoginSuccess:o});if(n===`/auth/authorize`||n===`/auth/device`){let e=window.location.href;return sessionStorage.setItem(`trokky_oauth_redirect`,e),(0,V.jsx)(y2,{onLoginSuccess:o})}return(0,V.jsx)(y2,{onLoginSuccess:o})}return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(i2,{}),(0,V.jsx)(w2,{}),(0,Ht.createPortal)((0,V.jsxs)(`div`,{"data-dialog-exempt":``,children:[(0,V.jsx)(E2,{}),(0,V.jsx)(O2,{})]}),document.body)]})}function F2(){let[e,t]=(0,B.useState)(null),n=(0,B.useMemo)(()=>M2(),[]);return(0,B.useEffect)(()=>{Fr(`App`).info(`Trokky Studio started`),(async()=>{let e=await s2();t(e),o2(e),e.title&&(document.title=e.title)})();let e=async e=>{let n=e.detail?.settings;if(n){let e={title:n.studioTitle,organizationName:n.organizationName,primaryColor:n.primaryColor,secondaryColor:n.secondaryColor,logo:n.logo};t(e),o2(e),e.title&&(document.title=e.title)}};return window.addEventListener(`trokky:settings:updated`,e),()=>{window.removeEventListener(`trokky:settings:updated`,e)}},[]),(0,V.jsx)(br,{config:n,children:(0,V.jsx)(N,{client:N2,children:(0,V.jsx)(ni,{children:(0,V.jsx)(fa,{branding:e,children:(0,V.jsx)(`div`,{className:`App`,children:(0,V.jsx)(P2,{})})})})})})}(()=>{try{let e=localStorage.getItem(`trokky_theme`),t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;e===`dark`||e===`system`&&t||!e&&t?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`)}catch(e){console.warn(`Failed to initialize theme:`,e)}})(),window.matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,e=>{let t=localStorage.getItem(`trokky_theme`);(!t||t===`system`)&&(e.matches?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`))}),Ut.createRoot(document.getElementById(`root`)).render((0,V.jsx)(B.StrictMode,{children:(0,V.jsx)(F2,{})}));
742
- //# sourceMappingURL=index-DJY6ibrL.js.map
741
+ `,role:`alert`,children:[(()=>{switch(a){case`success`:return(0,V.jsx)(F,{className:`w-4 h-4 text-green-500`});case`error`:return(0,V.jsx)(tt,{className:`w-4 h-4 text-red-500`});case`warning`:return(0,V.jsx)(de,{className:`w-4 h-4 text-amber-500`});default:return(0,V.jsx)(ue,{className:`w-4 h-4 text-blue-500`})}})(),(0,V.jsx)(`div`,{className:`ml-2 flex-1`,children:(0,V.jsx)(`p`,{className:`text-sm font-medium`,children:i})}),(0,V.jsx)(`button`,{onClick:()=>t(r),className:`ml-3 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors opacity-60 hover:opacity-100`,"aria-label":n(`toast.closeNotification`),children:(0,V.jsx)(tt,{className:`w-3 h-3`})})]})},D2=()=>{let{t:e}=H(`studio`),[t,n]=(0,B.useState)([]);(0,B.useEffect)(()=>{let e=e=>{let{message:t,type:r}=e.detail,i={id:`toast-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,message:t,type:r,duration:r===`error`?4e3:3e3};n(e=>[...e,i].slice(-3))};return window.addEventListener(`studio:toast`,e),()=>{window.removeEventListener(`studio:toast`,e)}},[]);let r=(0,B.useCallback)(e=>{n(t=>t.filter(t=>t.id!==e))},[]);return t.length===0?null:(0,V.jsx)(`div`,{className:`fixed bottom-4 right-4 z-toast space-y-2 max-w-xs w-full pointer-events-none`,"aria-live":`polite`,"aria-label":e(`toast.notifications`),children:t.map(e=>(0,V.jsx)(`div`,{className:`pointer-events-auto`,children:(0,V.jsx)(E2,{toast:e,onRemove:r})},e.id))})},O2=({isOpen:e,title:t,message:n,confirmText:r,cancelText:i,variant:a=`default`,onConfirm:o,onCancel:s})=>{let{t:c}=H(`studio`),l=r||c(`confirmDialog.defaultConfirm`),u=i||c(`confirmDialog.defaultCancel`),d=a===`danger`?{icon:(0,V.jsx)(de,{className:`h-6 w-6 text-red-600`}),iconBg:`bg-red-100 dark:bg-red-900/20`,confirmButton:`bg-red-600 hover:bg-red-700 focus:ring-red-500 text-white`}:{icon:(0,V.jsx)(de,{className:`h-6 w-6 text-amber-600`}),iconBg:`bg-amber-100 dark:bg-amber-900/20`,confirmButton:`bg-blue-600 hover:bg-blue-700 focus:ring-blue-500 text-white`};return(0,V.jsx)(ia,{open:e,onClose:s,variant:`center`,size:`md`,ariaLabel:t||n,children:(0,V.jsxs)(ia.Body,{padded:!1,className:`px-4 pb-4 pt-5 sm:p-6`,children:[(0,V.jsx)(`button`,{onClick:s,className:`absolute right-4 top-4 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300`,"aria-label":u,children:(0,V.jsx)(tt,{className:`h-5 w-5`})}),(0,V.jsxs)(`div`,{className:`sm:flex sm:items-start`,children:[(0,V.jsx)(`div`,{className:`mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full ${d.iconBg} sm:mx-0 sm:h-10 sm:w-10`,children:d.icon}),(0,V.jsxs)(`div`,{className:`mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left`,children:[t&&(0,V.jsx)(`h3`,{className:`text-base font-semibold leading-6 text-gray-900 dark:text-white`,children:t}),(0,V.jsx)(`div`,{className:`mt-2`,children:(0,V.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:n})})]})]}),(0,V.jsxs)(`div`,{className:`mt-5 sm:mt-4 sm:flex sm:flex-row-reverse gap-3`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:o,className:`inline-flex w-full justify-center rounded-md px-3 py-2 text-sm font-semibold shadow-sm sm:w-auto ${d.confirmButton} focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-800`,children:l}),(0,V.jsx)(`button`,{type:`button`,onClick:s,className:`mt-3 inline-flex w-full justify-center rounded-md bg-white dark:bg-gray-700 px-3 py-2 text-sm font-semibold text-gray-900 dark:text-gray-200 shadow-sm ring-1 ring-inset ring-gray-300 dark:ring-gray-600 hover:bg-gray-50 dark:hover:bg-gray-600 sm:mt-0 sm:w-auto focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-800`,children:u})]})]})})},k2=()=>{let[e,t]=(0,B.useState)({isOpen:!1,message:``});(0,B.useEffect)(()=>{let e=e=>{let{message:n,title:r,confirmText:i,cancelText:a,variant:o,resolve:s}=e.detail;t({isOpen:!0,message:n,title:r,confirmText:i,cancelText:a,variant:o,resolve:s})};return window.addEventListener(`studio:confirm`,e),()=>{window.removeEventListener(`studio:confirm`,e)}},[]);let n=(0,B.useCallback)(()=>{e.resolve?.(!0),t(e=>({...e,isOpen:!1}))},[e.resolve]),r=(0,B.useCallback)(()=>{e.resolve?.(!1),t(e=>({...e,isOpen:!1}))},[e.resolve]);return(0,V.jsx)(O2,{isOpen:e.isOpen,title:e.title,message:e.message,confirmText:e.confirmText,cancelText:e.cancelText,variant:e.variant,onConfirm:n,onCancel:r})},A2=Fr(`useDocumentTitle`);function j2(e=!1){let t=async()=>{try{let e=await W.get(`/config/studio`);if(e.success&&e.data?.studioConfig?.branding){let t=e.data.studioConfig.branding;if(t.title){document.title=t.title,A2.debug(`Document title updated from branding`,{title:t.title});return}}}catch(e){A2.warn(`Failed to load studio config for document title`,e)}document.title=`Trokky Studio`,A2.debug(`Document title updated from default`,{title:`Trokky Studio`})};(0,B.useEffect)(()=>{t();let e=()=>{A2.debug(`Settings changed, updating document title`),t()};return window.addEventListener(`trokky:settings:updated`,e),()=>{window.removeEventListener(`trokky:settings:updated`,e)}},[e])}var M2=Fr(`Debug`);typeof window<`u`&&(window.TrokkyDebug={clearStructureCache(){try{Xr().clearCache(),M2.info(`✅ Structure cache cleared`);try{localStorage.removeItem(`trokky_structure_cache`),sessionStorage.removeItem(`trokky_structure_cache`),M2.info(`✅ Browser structure cache cleared`)}catch(e){M2.warn(`⚠️ Could not clear browser cache:`,e)}}catch(e){M2.error(`❌ Failed to clear structure cache:`,e)}},async refreshStructure(){try{let e=await Xr().refreshFromEndpoint();e?M2.info(`✅ Structure refreshed from endpoint:`,{title:e.title,itemsCount:e.items?.length||0}):M2.warn(`⚠️ No structure returned from endpoint, falling back to defaults`)}catch(e){M2.error(`❌ Failed to refresh structure:`,e)}},async getStructureInfo(){try{let e=Xr(),t=await e.getStructure(),n={cached:e.isCached(),title:t.title,itemsCount:t.items?.length||0,metadata:t.metadata,items:t.items?.map(e=>({type:e.type,title:e.title,schemaType:e.schemaType,hasChildren:!!e.items?.length}))};return M2.info(`📊 Current structure info:`,n),n}catch(e){return M2.error(`❌ Failed to get structure info:`,e),{error:e instanceof Error?e.message:String(e)}}},clearAllCache(){try{this.clearStructureCache(),Ar.clear(),[`trokky_user_data`,`trokky_theme`,`trokky_sidebar_collapsed`,`trokky_studio_config`].forEach(e=>{try{localStorage.removeItem(e),sessionStorage.removeItem(e)}catch{}}),M2.info(`✅ All browser cache cleared`)}catch(e){M2.error(`❌ Failed to clear all cache:`,e)}},enableDebugLogging(){try{localStorage.setItem(`trokky_debug_enabled`,`true`),window.TrokkyLogger?.setLevel&&window.TrokkyLogger.setLevel(`debug`),M2.info(`✅ Debug logging enabled`)}catch(e){M2.error(`❌ Failed to enable debug logging:`,e)}},disableDebugLogging(){try{localStorage.removeItem(`trokky_debug_enabled`),window.TrokkyLogger?.setLevel&&window.TrokkyLogger.setLevel(`info`),M2.info(`✅ Debug logging disabled`)}catch(e){M2.error(`❌ Failed to disable debug logging:`,e)}}});function N2(){let e=window.TROKKY_CONFIG?.i18n;return{defaultLocale:e?.defaultLocale||`en`,supportedLocales:e?.supportedLocales||[`en`,`fr`],fallbackLocale:e?.fallbackLocale||`en`,detectBrowserLanguage:e?.detectBrowserLanguage??!0,debug:e?.debug??!1}}W.initialize();var P2=new ht({defaultOptions:{queries:{retry:2,staleTime:3e5}}});function F2(){let{t:e}=H(`common`),{isAuthenticated:t,isLoading:n,checkAuth:r}=ri(),i=Fr(`AppContent`),a=(0,B.useRef)({});j2(t),(0,B.useEffect)(()=>{let e={isAuthenticated:t,isLoading:n},r=a.current;(r.isAuthenticated!==t||r.isLoading!==n)&&(i.debug(`Auth state changed`,e),a.current=e)},[t,n,i]);let o=()=>{i.info(`Login successful, rechecking auth state`);let e=sessionStorage.getItem(`trokky_oauth_redirect`);if(e){sessionStorage.removeItem(`trokky_oauth_redirect`),i.info(`Redirecting to OAuth flow`,{url:e}),window.location.href=e;return}r()};if(n)return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900`,children:(0,V.jsxs)(`div`,{className:`text-center`,children:[(0,V.jsx)(Ao,{size:`lg`}),(0,V.jsx)(`h2`,{className:`mt-4 text-lg font-semibold text-gray-900 dark:text-white`,children:e(`app.loadingStudio`)})]})});if(!t){let e=window.location.pathname,t=window.TROKKY_CONFIG?.basePath||``,n=e.replace(t,``);if(n===`/forgot-password`)return(0,V.jsx)(S2,{});if(n===`/reset-password`)return(0,V.jsx)(C2,{});if(n===`/oauth/callback`)return(0,V.jsx)($0,{onLoginSuccess:o});if(n===`/auth/authorize`||n===`/auth/device`){let e=window.location.href;return sessionStorage.setItem(`trokky_oauth_redirect`,e),(0,V.jsx)(b2,{onLoginSuccess:o})}return(0,V.jsx)(b2,{onLoginSuccess:o})}return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(a2,{}),(0,V.jsx)(T2,{}),(0,Ht.createPortal)((0,V.jsxs)(`div`,{"data-dialog-exempt":``,children:[(0,V.jsx)(D2,{}),(0,V.jsx)(k2,{})]}),document.body)]})}function I2(){let[e,t]=(0,B.useState)(null),n=(0,B.useMemo)(()=>N2(),[]);return(0,B.useEffect)(()=>{Fr(`App`).info(`Trokky Studio started`),(async()=>{let e=await c2();t(e),s2(e),e.title&&(document.title=e.title)})();let e=async e=>{let n=e.detail?.settings;if(n){let e={title:n.studioTitle,organizationName:n.organizationName,primaryColor:n.primaryColor,secondaryColor:n.secondaryColor,logo:n.logo};t(e),s2(e),e.title&&(document.title=e.title)}};return window.addEventListener(`trokky:settings:updated`,e),()=>{window.removeEventListener(`trokky:settings:updated`,e)}},[]),(0,V.jsx)(br,{config:n,children:(0,V.jsx)(N,{client:P2,children:(0,V.jsx)(ni,{children:(0,V.jsx)(fa,{branding:e,children:(0,V.jsx)(`div`,{className:`App`,children:(0,V.jsx)(F2,{})})})})})})}(()=>{try{let e=localStorage.getItem(`trokky_theme`),t=window.matchMedia(`(prefers-color-scheme: dark)`).matches;e===`dark`||e===`system`&&t||!e&&t?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`)}catch(e){console.warn(`Failed to initialize theme:`,e)}})(),window.matchMedia(`(prefers-color-scheme: dark)`).addEventListener(`change`,e=>{let t=localStorage.getItem(`trokky_theme`);(!t||t===`system`)&&(e.matches?document.documentElement.classList.add(`dark`):document.documentElement.classList.remove(`dark`))}),Ut.createRoot(document.getElementById(`root`)).render((0,V.jsx)(B.StrictMode,{children:(0,V.jsx)(I2,{})}));
742
+ //# sourceMappingURL=index-D0f8OCEI.js.map