openwriter 0.29.0 → 0.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var U0;function sM(){if(U0)return At;U0=1;var t=Symbol.for("react.element"),e=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),o=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),m=Symbol.iterator;function g(M){return M===null||typeof M!="object"?null:(M=m&&M[m]||M["@@iterator"],typeof M=="function"?M:null)}var v={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},b=Object.assign,k={};function w(M,L,ee){this.props=M,this.context=L,this.refs=k,this.updater=ee||v}w.prototype.isReactComponent={},w.prototype.setState=function(M,L){if(typeof M!="object"&&typeof M!="function"&&M!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,M,L,"setState")},w.prototype.forceUpdate=function(M){this.updater.enqueueForceUpdate(this,M,"forceUpdate")};function E(){}E.prototype=w.prototype;function C(M,L,ee){this.props=M,this.context=L,this.refs=k,this.updater=ee||v}var T=C.prototype=new E;T.constructor=C,b(T,w.prototype),T.isPureReactComponent=!0;var j=Array.isArray,_=Object.prototype.hasOwnProperty,A={current:null},O={key:!0,ref:!0,__self:!0,__source:!0};function B(M,L,ee){var fe,ge={},oe=null,we=null;if(L!=null)for(fe in L.ref!==void 0&&(we=L.ref),L.key!==void 0&&(oe=""+L.key),L)_.call(L,fe)&&!O.hasOwnProperty(fe)&&(ge[fe]=L[fe]);var xe=arguments.length-2;if(xe===1)ge.children=ee;else if(1<xe){for(var We=Array(xe),He=0;He<xe;He++)We[He]=arguments[He+2];ge.children=We}if(M&&M.defaultProps)for(fe in xe=M.defaultProps,xe)ge[fe]===void 0&&(ge[fe]=xe[fe]);return{$$typeof:t,type:M,key:oe,ref:we,props:ge,_owner:A.current}}function $(M,L){return{$$typeof:t,type:M.type,key:L,ref:M.ref,props:M.props,_owner:M._owner}}function W(M){return typeof M=="object"&&M!==null&&M.$$typeof===t}function J(M){var L={"=":"=0",":":"=2"};return"$"+M.replace(/[=:]/g,function(ee){return L[ee]})}var z=/\/+/g;function G(M,L){return typeof M=="object"&&M!==null&&M.key!=null?J(""+M.key):L.toString(36)}function D(M,L,ee,fe,ge){var oe=typeof M;(oe==="undefined"||oe==="boolean")&&(M=null);var we=!1;if(M===null)we=!0;else switch(oe){case"string":case"number":we=!0;break;case"object":switch(M.$$typeof){case t:case e:we=!0}}if(we)return we=M,ge=ge(we),M=fe===""?"."+G(we,0):fe,j(ge)?(ee="",M!=null&&(ee=M.replace(z,"$&/")+"/"),D(ge,L,ee,"",function(He){return He})):ge!=null&&(W(ge)&&(ge=$(ge,ee+(!ge.key||we&&we.key===ge.key?"":(""+ge.key).replace(z,"$&/")+"/")+M)),L.push(ge)),1;if(we=0,fe=fe===""?".":fe+":",j(M))for(var xe=0;xe<M.length;xe++){oe=M[xe];var We=fe+G(oe,xe);we+=D(oe,L,ee,We,ge)}else if(We=g(M),typeof We=="function")for(M=We.call(M),xe=0;!(oe=M.next()).done;)oe=oe.value,We=fe+G(oe,xe++),we+=D(oe,L,ee,We,ge);else if(oe==="object")throw L=String(M),Error("Objects are not valid as a React child (found: "+(L==="[object Object]"?"object with keys {"+Object.keys(M).join(", ")+"}":L)+"). If you meant to render a collection of children, use an array instead.");return we}function U(M,L,ee){if(M==null)return M;var fe=[],ge=0;return D(M,fe,"","",function(oe){return L.call(ee,oe,ge++)}),fe}function q(M){if(M._status===-1){var L=M._result;L=L(),L.then(function(ee){(M._status===0||M._status===-1)&&(M._status=1,M._result=ee)},function(ee){(M._status===0||M._status===-1)&&(M._status=2,M._result=ee)}),M._status===-1&&(M._status=0,M._result=L)}if(M._status===1)return M._result.default;throw M._result}var se={current:null},V={transition:null},te={ReactCurrentDispatcher:se,ReactCurrentBatchConfig:V,ReactCurrentOwner:A};function K(){throw Error("act(...) is not supported in production builds of React.")}return At.Children={map:U,forEach:function(M,L,ee){U(M,function(){L.apply(this,arguments)},ee)},count:function(M){var L=0;return U(M,function(){L++}),L},toArray:function(M){return U(M,function(L){return L})||[]},only:function(M){if(!W(M))throw Error("React.Children.only expected to receive a single React element child.");return M}},At.Component=w,At.Fragment=n,At.Profiler=s,At.PureComponent=C,At.StrictMode=r,At.Suspense=d,At.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=te,At.act=K,At.cloneElement=function(M,L,ee){if(M==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+M+".");var fe=b({},M.props),ge=M.key,oe=M.ref,we=M._owner;if(L!=null){if(L.ref!==void 0&&(oe=L.ref,we=A.current),L.key!==void 0&&(ge=""+L.key),M.type&&M.type.defaultProps)var xe=M.type.defaultProps;for(We in L)_.call(L,We)&&!O.hasOwnProperty(We)&&(fe[We]=L[We]===void 0&&xe!==void 0?xe[We]:L[We])}var We=arguments.length-2;if(We===1)fe.children=ee;else if(1<We){xe=Array(We);for(var He=0;He<We;He++)xe[He]=arguments[He+2];fe.children=xe}return{$$typeof:t,type:M.type,key:ge,ref:oe,props:fe,_owner:we}},At.createContext=function(M){return M={$$typeof:o,_currentValue:M,_currentValue2:M,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},M.Provider={$$typeof:i,_context:M},M.Consumer=M},At.createElement=B,At.createFactory=function(M){var L=B.bind(null,M);return L.type=M,L},At.createRef=function(){return{current:null}},At.forwardRef=function(M){return{$$typeof:l,render:M}},At.isValidElement=W,At.lazy=function(M){return{$$typeof:h,_payload:{_status:-1,_result:M},_init:q}},At.memo=function(M,L){return{$$typeof:f,type:M,compare:L===void 0?null:L}},At.startTransition=function(M){var L=V.transition;V.transition={};try{M()}finally{V.transition=L}},At.unstable_act=K,At.useCallback=function(M,L){return se.current.useCallback(M,L)},At.useContext=function(M){return se.current.useContext(M)},At.useDebugValue=function(){},At.useDeferredValue=function(M){return se.current.useDeferredValue(M)},At.useEffect=function(M,L){return se.current.useEffect(M,L)},At.useId=function(){return se.current.useId()},At.useImperativeHandle=function(M,L,ee){return se.current.useImperativeHandle(M,L,ee)},At.useInsertionEffect=function(M,L){return se.current.useInsertionEffect(M,L)},At.useLayoutEffect=function(M,L){return se.current.useLayoutEffect(M,L)},At.useMemo=function(M,L){return se.current.useMemo(M,L)},At.useReducer=function(M,L,ee){return se.current.useReducer(M,L,ee)},At.useRef=function(M){return se.current.useRef(M)},At.useState=function(M){return se.current.useState(M)},At.useSyncExternalStore=function(M,L,ee){return se.current.useSyncExternalStore(M,L,ee)},At.useTransition=function(){return se.current.useTransition()},At.version="18.3.1",At}var H0;function Ml(){return H0||(H0=1,Fh.exports=sM()),Fh.exports}/**
9
+ */var U0;function sM(){if(U0)return At;U0=1;var t=Symbol.for("react.element"),e=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),o=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),m=Symbol.iterator;function g(M){return M===null||typeof M!="object"?null:(M=m&&M[m]||M["@@iterator"],typeof M=="function"?M:null)}var v={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},b=Object.assign,k={};function w(M,L,ee){this.props=M,this.context=L,this.refs=k,this.updater=ee||v}w.prototype.isReactComponent={},w.prototype.setState=function(M,L){if(typeof M!="object"&&typeof M!="function"&&M!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,M,L,"setState")},w.prototype.forceUpdate=function(M){this.updater.enqueueForceUpdate(this,M,"forceUpdate")};function E(){}E.prototype=w.prototype;function C(M,L,ee){this.props=M,this.context=L,this.refs=k,this.updater=ee||v}var T=C.prototype=new E;T.constructor=C,b(T,w.prototype),T.isPureReactComponent=!0;var j=Array.isArray,_=Object.prototype.hasOwnProperty,A={current:null},O={key:!0,ref:!0,__self:!0,__source:!0};function B(M,L,ee){var fe,ge={},oe=null,xe=null;if(L!=null)for(fe in L.ref!==void 0&&(xe=L.ref),L.key!==void 0&&(oe=""+L.key),L)_.call(L,fe)&&!O.hasOwnProperty(fe)&&(ge[fe]=L[fe]);var we=arguments.length-2;if(we===1)ge.children=ee;else if(1<we){for(var We=Array(we),He=0;He<we;He++)We[He]=arguments[He+2];ge.children=We}if(M&&M.defaultProps)for(fe in we=M.defaultProps,we)ge[fe]===void 0&&(ge[fe]=we[fe]);return{$$typeof:t,type:M,key:oe,ref:xe,props:ge,_owner:A.current}}function $(M,L){return{$$typeof:t,type:M.type,key:L,ref:M.ref,props:M.props,_owner:M._owner}}function W(M){return typeof M=="object"&&M!==null&&M.$$typeof===t}function J(M){var L={"=":"=0",":":"=2"};return"$"+M.replace(/[=:]/g,function(ee){return L[ee]})}var z=/\/+/g;function G(M,L){return typeof M=="object"&&M!==null&&M.key!=null?J(""+M.key):L.toString(36)}function D(M,L,ee,fe,ge){var oe=typeof M;(oe==="undefined"||oe==="boolean")&&(M=null);var xe=!1;if(M===null)xe=!0;else switch(oe){case"string":case"number":xe=!0;break;case"object":switch(M.$$typeof){case t:case e:xe=!0}}if(xe)return xe=M,ge=ge(xe),M=fe===""?"."+G(xe,0):fe,j(ge)?(ee="",M!=null&&(ee=M.replace(z,"$&/")+"/"),D(ge,L,ee,"",function(He){return He})):ge!=null&&(W(ge)&&(ge=$(ge,ee+(!ge.key||xe&&xe.key===ge.key?"":(""+ge.key).replace(z,"$&/")+"/")+M)),L.push(ge)),1;if(xe=0,fe=fe===""?".":fe+":",j(M))for(var we=0;we<M.length;we++){oe=M[we];var We=fe+G(oe,we);xe+=D(oe,L,ee,We,ge)}else if(We=g(M),typeof We=="function")for(M=We.call(M),we=0;!(oe=M.next()).done;)oe=oe.value,We=fe+G(oe,we++),xe+=D(oe,L,ee,We,ge);else if(oe==="object")throw L=String(M),Error("Objects are not valid as a React child (found: "+(L==="[object Object]"?"object with keys {"+Object.keys(M).join(", ")+"}":L)+"). If you meant to render a collection of children, use an array instead.");return xe}function U(M,L,ee){if(M==null)return M;var fe=[],ge=0;return D(M,fe,"","",function(oe){return L.call(ee,oe,ge++)}),fe}function q(M){if(M._status===-1){var L=M._result;L=L(),L.then(function(ee){(M._status===0||M._status===-1)&&(M._status=1,M._result=ee)},function(ee){(M._status===0||M._status===-1)&&(M._status=2,M._result=ee)}),M._status===-1&&(M._status=0,M._result=L)}if(M._status===1)return M._result.default;throw M._result}var se={current:null},V={transition:null},te={ReactCurrentDispatcher:se,ReactCurrentBatchConfig:V,ReactCurrentOwner:A};function K(){throw Error("act(...) is not supported in production builds of React.")}return At.Children={map:U,forEach:function(M,L,ee){U(M,function(){L.apply(this,arguments)},ee)},count:function(M){var L=0;return U(M,function(){L++}),L},toArray:function(M){return U(M,function(L){return L})||[]},only:function(M){if(!W(M))throw Error("React.Children.only expected to receive a single React element child.");return M}},At.Component=w,At.Fragment=n,At.Profiler=s,At.PureComponent=C,At.StrictMode=r,At.Suspense=d,At.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=te,At.act=K,At.cloneElement=function(M,L,ee){if(M==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+M+".");var fe=b({},M.props),ge=M.key,oe=M.ref,xe=M._owner;if(L!=null){if(L.ref!==void 0&&(oe=L.ref,xe=A.current),L.key!==void 0&&(ge=""+L.key),M.type&&M.type.defaultProps)var we=M.type.defaultProps;for(We in L)_.call(L,We)&&!O.hasOwnProperty(We)&&(fe[We]=L[We]===void 0&&we!==void 0?we[We]:L[We])}var We=arguments.length-2;if(We===1)fe.children=ee;else if(1<We){we=Array(We);for(var He=0;He<We;He++)we[He]=arguments[He+2];fe.children=we}return{$$typeof:t,type:M.type,key:ge,ref:oe,props:fe,_owner:xe}},At.createContext=function(M){return M={$$typeof:o,_currentValue:M,_currentValue2:M,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},M.Provider={$$typeof:i,_context:M},M.Consumer=M},At.createElement=B,At.createFactory=function(M){var L=B.bind(null,M);return L.type=M,L},At.createRef=function(){return{current:null}},At.forwardRef=function(M){return{$$typeof:l,render:M}},At.isValidElement=W,At.lazy=function(M){return{$$typeof:h,_payload:{_status:-1,_result:M},_init:q}},At.memo=function(M,L){return{$$typeof:f,type:M,compare:L===void 0?null:L}},At.startTransition=function(M){var L=V.transition;V.transition={};try{M()}finally{V.transition=L}},At.unstable_act=K,At.useCallback=function(M,L){return se.current.useCallback(M,L)},At.useContext=function(M){return se.current.useContext(M)},At.useDebugValue=function(){},At.useDeferredValue=function(M){return se.current.useDeferredValue(M)},At.useEffect=function(M,L){return se.current.useEffect(M,L)},At.useId=function(){return se.current.useId()},At.useImperativeHandle=function(M,L,ee){return se.current.useImperativeHandle(M,L,ee)},At.useInsertionEffect=function(M,L){return se.current.useInsertionEffect(M,L)},At.useLayoutEffect=function(M,L){return se.current.useLayoutEffect(M,L)},At.useMemo=function(M,L){return se.current.useMemo(M,L)},At.useReducer=function(M,L,ee){return se.current.useReducer(M,L,ee)},At.useRef=function(M){return se.current.useRef(M)},At.useState=function(M){return se.current.useState(M)},At.useSyncExternalStore=function(M,L,ee){return se.current.useSyncExternalStore(M,L,ee)},At.useTransition=function(){return se.current.useTransition()},At.version="18.3.1",At}var H0;function Ml(){return H0||(H0=1,Fh.exports=sM()),Fh.exports}/**
10
10
  * @license React
11
11
  * react-jsx-runtime.production.min.js
12
12
  *
@@ -22,7 +22,7 @@
22
22
  *
23
23
  * This source code is licensed under the MIT license found in the
24
24
  * LICENSE file in the root directory of this source tree.
25
- */var V0;function aM(){return V0||(V0=1,(function(t){function e(V,te){var K=V.length;V.push(te);e:for(;0<K;){var M=K-1>>>1,L=V[M];if(0<s(L,te))V[M]=te,V[K]=L,K=M;else break e}}function n(V){return V.length===0?null:V[0]}function r(V){if(V.length===0)return null;var te=V[0],K=V.pop();if(K!==te){V[0]=K;e:for(var M=0,L=V.length,ee=L>>>1;M<ee;){var fe=2*(M+1)-1,ge=V[fe],oe=fe+1,we=V[oe];if(0>s(ge,K))oe<L&&0>s(we,ge)?(V[M]=we,V[oe]=K,M=oe):(V[M]=ge,V[fe]=K,M=fe);else if(oe<L&&0>s(we,K))V[M]=we,V[oe]=K,M=oe;else break e}}return te}function s(V,te){var K=V.sortIndex-te.sortIndex;return K!==0?K:V.id-te.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;t.unstable_now=function(){return i.now()}}else{var o=Date,l=o.now();t.unstable_now=function(){return o.now()-l}}var d=[],f=[],h=1,m=null,g=3,v=!1,b=!1,k=!1,w=typeof setTimeout=="function"?setTimeout:null,E=typeof clearTimeout=="function"?clearTimeout:null,C=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function T(V){for(var te=n(f);te!==null;){if(te.callback===null)r(f);else if(te.startTime<=V)r(f),te.sortIndex=te.expirationTime,e(d,te);else break;te=n(f)}}function j(V){if(k=!1,T(V),!b)if(n(d)!==null)b=!0,q(_);else{var te=n(f);te!==null&&se(j,te.startTime-V)}}function _(V,te){b=!1,k&&(k=!1,E(B),B=-1),v=!0;var K=g;try{for(T(te),m=n(d);m!==null&&(!(m.expirationTime>te)||V&&!J());){var M=m.callback;if(typeof M=="function"){m.callback=null,g=m.priorityLevel;var L=M(m.expirationTime<=te);te=t.unstable_now(),typeof L=="function"?m.callback=L:m===n(d)&&r(d),T(te)}else r(d);m=n(d)}if(m!==null)var ee=!0;else{var fe=n(f);fe!==null&&se(j,fe.startTime-te),ee=!1}return ee}finally{m=null,g=K,v=!1}}var A=!1,O=null,B=-1,$=5,W=-1;function J(){return!(t.unstable_now()-W<$)}function z(){if(O!==null){var V=t.unstable_now();W=V;var te=!0;try{te=O(!0,V)}finally{te?G():(A=!1,O=null)}}else A=!1}var G;if(typeof C=="function")G=function(){C(z)};else if(typeof MessageChannel<"u"){var D=new MessageChannel,U=D.port2;D.port1.onmessage=z,G=function(){U.postMessage(null)}}else G=function(){w(z,0)};function q(V){O=V,A||(A=!0,G())}function se(V,te){B=w(function(){V(t.unstable_now())},te)}t.unstable_IdlePriority=5,t.unstable_ImmediatePriority=1,t.unstable_LowPriority=4,t.unstable_NormalPriority=3,t.unstable_Profiling=null,t.unstable_UserBlockingPriority=2,t.unstable_cancelCallback=function(V){V.callback=null},t.unstable_continueExecution=function(){b||v||(b=!0,q(_))},t.unstable_forceFrameRate=function(V){0>V||125<V?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<V?Math.floor(1e3/V):5},t.unstable_getCurrentPriorityLevel=function(){return g},t.unstable_getFirstCallbackNode=function(){return n(d)},t.unstable_next=function(V){switch(g){case 1:case 2:case 3:var te=3;break;default:te=g}var K=g;g=te;try{return V()}finally{g=K}},t.unstable_pauseExecution=function(){},t.unstable_requestPaint=function(){},t.unstable_runWithPriority=function(V,te){switch(V){case 1:case 2:case 3:case 4:case 5:break;default:V=3}var K=g;g=V;try{return te()}finally{g=K}},t.unstable_scheduleCallback=function(V,te,K){var M=t.unstable_now();switch(typeof K=="object"&&K!==null?(K=K.delay,K=typeof K=="number"&&0<K?M+K:M):K=M,V){case 1:var L=-1;break;case 2:L=250;break;case 5:L=1073741823;break;case 4:L=1e4;break;default:L=5e3}return L=K+L,V={id:h++,callback:te,priorityLevel:V,startTime:K,expirationTime:L,sortIndex:-1},K>M?(V.sortIndex=K,e(f,V),n(d)===null&&V===n(f)&&(k?(E(B),B=-1):k=!0,se(j,K-M))):(V.sortIndex=L,e(d,V),b||v||(b=!0,q(_))),V},t.unstable_shouldYield=J,t.unstable_wrapCallback=function(V){var te=g;return function(){var K=g;g=te;try{return V.apply(this,arguments)}finally{g=K}}}})(Wh)),Wh}var K0;function lM(){return K0||(K0=1,Hh.exports=aM()),Hh.exports}/**
25
+ */var V0;function aM(){return V0||(V0=1,(function(t){function e(V,te){var K=V.length;V.push(te);e:for(;0<K;){var M=K-1>>>1,L=V[M];if(0<s(L,te))V[M]=te,V[K]=L,K=M;else break e}}function n(V){return V.length===0?null:V[0]}function r(V){if(V.length===0)return null;var te=V[0],K=V.pop();if(K!==te){V[0]=K;e:for(var M=0,L=V.length,ee=L>>>1;M<ee;){var fe=2*(M+1)-1,ge=V[fe],oe=fe+1,xe=V[oe];if(0>s(ge,K))oe<L&&0>s(xe,ge)?(V[M]=xe,V[oe]=K,M=oe):(V[M]=ge,V[fe]=K,M=fe);else if(oe<L&&0>s(xe,K))V[M]=xe,V[oe]=K,M=oe;else break e}}return te}function s(V,te){var K=V.sortIndex-te.sortIndex;return K!==0?K:V.id-te.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;t.unstable_now=function(){return i.now()}}else{var o=Date,l=o.now();t.unstable_now=function(){return o.now()-l}}var d=[],f=[],h=1,m=null,g=3,v=!1,b=!1,k=!1,w=typeof setTimeout=="function"?setTimeout:null,E=typeof clearTimeout=="function"?clearTimeout:null,C=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function T(V){for(var te=n(f);te!==null;){if(te.callback===null)r(f);else if(te.startTime<=V)r(f),te.sortIndex=te.expirationTime,e(d,te);else break;te=n(f)}}function j(V){if(k=!1,T(V),!b)if(n(d)!==null)b=!0,q(_);else{var te=n(f);te!==null&&se(j,te.startTime-V)}}function _(V,te){b=!1,k&&(k=!1,E(B),B=-1),v=!0;var K=g;try{for(T(te),m=n(d);m!==null&&(!(m.expirationTime>te)||V&&!J());){var M=m.callback;if(typeof M=="function"){m.callback=null,g=m.priorityLevel;var L=M(m.expirationTime<=te);te=t.unstable_now(),typeof L=="function"?m.callback=L:m===n(d)&&r(d),T(te)}else r(d);m=n(d)}if(m!==null)var ee=!0;else{var fe=n(f);fe!==null&&se(j,fe.startTime-te),ee=!1}return ee}finally{m=null,g=K,v=!1}}var A=!1,O=null,B=-1,$=5,W=-1;function J(){return!(t.unstable_now()-W<$)}function z(){if(O!==null){var V=t.unstable_now();W=V;var te=!0;try{te=O(!0,V)}finally{te?G():(A=!1,O=null)}}else A=!1}var G;if(typeof C=="function")G=function(){C(z)};else if(typeof MessageChannel<"u"){var D=new MessageChannel,U=D.port2;D.port1.onmessage=z,G=function(){U.postMessage(null)}}else G=function(){w(z,0)};function q(V){O=V,A||(A=!0,G())}function se(V,te){B=w(function(){V(t.unstable_now())},te)}t.unstable_IdlePriority=5,t.unstable_ImmediatePriority=1,t.unstable_LowPriority=4,t.unstable_NormalPriority=3,t.unstable_Profiling=null,t.unstable_UserBlockingPriority=2,t.unstable_cancelCallback=function(V){V.callback=null},t.unstable_continueExecution=function(){b||v||(b=!0,q(_))},t.unstable_forceFrameRate=function(V){0>V||125<V?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<V?Math.floor(1e3/V):5},t.unstable_getCurrentPriorityLevel=function(){return g},t.unstable_getFirstCallbackNode=function(){return n(d)},t.unstable_next=function(V){switch(g){case 1:case 2:case 3:var te=3;break;default:te=g}var K=g;g=te;try{return V()}finally{g=K}},t.unstable_pauseExecution=function(){},t.unstable_requestPaint=function(){},t.unstable_runWithPriority=function(V,te){switch(V){case 1:case 2:case 3:case 4:case 5:break;default:V=3}var K=g;g=V;try{return te()}finally{g=K}},t.unstable_scheduleCallback=function(V,te,K){var M=t.unstable_now();switch(typeof K=="object"&&K!==null?(K=K.delay,K=typeof K=="number"&&0<K?M+K:M):K=M,V){case 1:var L=-1;break;case 2:L=250;break;case 5:L=1073741823;break;case 4:L=1e4;break;default:L=5e3}return L=K+L,V={id:h++,callback:te,priorityLevel:V,startTime:K,expirationTime:L,sortIndex:-1},K>M?(V.sortIndex=K,e(f,V),n(d)===null&&V===n(f)&&(k?(E(B),B=-1):k=!0,se(j,K-M))):(V.sortIndex=L,e(d,V),b||v||(b=!0,q(_))),V},t.unstable_shouldYield=J,t.unstable_wrapCallback=function(V){var te=g;return function(){var K=g;g=te;try{return V.apply(this,arguments)}finally{g=K}}}})(Wh)),Wh}var K0;function lM(){return K0||(K0=1,Hh.exports=aM()),Hh.exports}/**
26
26
  * @license React
27
27
  * react-dom.production.min.js
28
28
  *
@@ -34,10 +34,10 @@
34
34
  `+M+a}var ee=!1;function fe(a,u){if(!a||ee)return"";ee=!0;var p=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(u)if(u=function(){throw Error()},Object.defineProperty(u.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(u,[])}catch(ue){var y=ue}Reflect.construct(a,[],u)}else{try{u.call()}catch(ue){y=ue}a.call(u.prototype)}else{try{throw Error()}catch(ue){y=ue}a()}}catch(ue){if(ue&&y&&typeof ue.stack=="string"){for(var S=ue.stack.split(`
35
35
  `),N=y.stack.split(`
36
36
  `),R=S.length-1,H=N.length-1;1<=R&&0<=H&&S[R]!==N[H];)H--;for(;1<=R&&0<=H;R--,H--)if(S[R]!==N[H]){if(R!==1||H!==1)do if(R--,H--,0>H||S[R]!==N[H]){var Y=`
37
- `+S[R].replace(" at new "," at ");return a.displayName&&Y.includes("<anonymous>")&&(Y=Y.replace("<anonymous>",a.displayName)),Y}while(1<=R&&0<=H);break}}}finally{ee=!1,Error.prepareStackTrace=p}return(a=a?a.displayName||a.name:"")?L(a):""}function ge(a){switch(a.tag){case 5:return L(a.type);case 16:return L("Lazy");case 13:return L("Suspense");case 19:return L("SuspenseList");case 0:case 2:case 15:return a=fe(a.type,!1),a;case 11:return a=fe(a.type.render,!1),a;case 1:return a=fe(a.type,!0),a;default:return""}}function oe(a){if(a==null)return null;if(typeof a=="function")return a.displayName||a.name||null;if(typeof a=="string")return a;switch(a){case O:return"Fragment";case A:return"Portal";case $:return"Profiler";case B:return"StrictMode";case G:return"Suspense";case D:return"SuspenseList"}if(typeof a=="object")switch(a.$$typeof){case J:return(a.displayName||"Context")+".Consumer";case W:return(a._context.displayName||"Context")+".Provider";case z:var u=a.render;return a=a.displayName,a||(a=u.displayName||u.name||"",a=a!==""?"ForwardRef("+a+")":"ForwardRef"),a;case U:return u=a.displayName||null,u!==null?u:oe(a.type)||"Memo";case q:u=a._payload,a=a._init;try{return oe(a(u))}catch{}}return null}function we(a){var u=a.type;switch(a.tag){case 24:return"Cache";case 9:return(u.displayName||"Context")+".Consumer";case 10:return(u._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return a=u.render,a=a.displayName||a.name||"",u.displayName||(a!==""?"ForwardRef("+a+")":"ForwardRef");case 7:return"Fragment";case 5:return u;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return oe(u);case 8:return u===B?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof u=="function")return u.displayName||u.name||null;if(typeof u=="string")return u}return null}function xe(a){switch(typeof a){case"boolean":case"number":case"string":case"undefined":return a;case"object":return a;default:return""}}function We(a){var u=a.type;return(a=a.nodeName)&&a.toLowerCase()==="input"&&(u==="checkbox"||u==="radio")}function He(a){var u=We(a)?"checked":"value",p=Object.getOwnPropertyDescriptor(a.constructor.prototype,u),y=""+a[u];if(!a.hasOwnProperty(u)&&typeof p<"u"&&typeof p.get=="function"&&typeof p.set=="function"){var S=p.get,N=p.set;return Object.defineProperty(a,u,{configurable:!0,get:function(){return S.call(this)},set:function(R){y=""+R,N.call(this,R)}}),Object.defineProperty(a,u,{enumerable:p.enumerable}),{getValue:function(){return y},setValue:function(R){y=""+R},stopTracking:function(){a._valueTracker=null,delete a[u]}}}}function Ze(a){a._valueTracker||(a._valueTracker=He(a))}function Oe(a){if(!a)return!1;var u=a._valueTracker;if(!u)return!0;var p=u.getValue(),y="";return a&&(y=We(a)?a.checked?"true":"false":a.value),a=y,a!==p?(u.setValue(a),!0):!1}function Ke(a){if(a=a||(typeof document<"u"?document:void 0),typeof a>"u")return null;try{return a.activeElement||a.body}catch{return a.body}}function pt(a,u){var p=u.checked;return K({},u,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:p??a._wrapperState.initialChecked})}function Je(a,u){var p=u.defaultValue==null?"":u.defaultValue,y=u.checked!=null?u.checked:u.defaultChecked;p=xe(u.value!=null?u.value:p),a._wrapperState={initialChecked:y,initialValue:p,controlled:u.type==="checkbox"||u.type==="radio"?u.checked!=null:u.value!=null}}function pe(a,u){u=u.checked,u!=null&&T(a,"checked",u,!1)}function mt(a,u){pe(a,u);var p=xe(u.value),y=u.type;if(p!=null)y==="number"?(p===0&&a.value===""||a.value!=p)&&(a.value=""+p):a.value!==""+p&&(a.value=""+p);else if(y==="submit"||y==="reset"){a.removeAttribute("value");return}u.hasOwnProperty("value")?at(a,u.type,p):u.hasOwnProperty("defaultValue")&&at(a,u.type,xe(u.defaultValue)),u.checked==null&&u.defaultChecked!=null&&(a.defaultChecked=!!u.defaultChecked)}function ft(a,u,p){if(u.hasOwnProperty("value")||u.hasOwnProperty("defaultValue")){var y=u.type;if(!(y!=="submit"&&y!=="reset"||u.value!==void 0&&u.value!==null))return;u=""+a._wrapperState.initialValue,p||u===a.value||(a.value=u),a.defaultValue=u}p=a.name,p!==""&&(a.name=""),a.defaultChecked=!!a._wrapperState.initialChecked,p!==""&&(a.name=p)}function at(a,u,p){(u!=="number"||Ke(a.ownerDocument)!==a)&&(p==null?a.defaultValue=""+a._wrapperState.initialValue:a.defaultValue!==""+p&&(a.defaultValue=""+p))}var nt=Array.isArray;function ht(a,u,p,y){if(a=a.options,u){u={};for(var S=0;S<p.length;S++)u["$"+p[S]]=!0;for(p=0;p<a.length;p++)S=u.hasOwnProperty("$"+a[p].value),a[p].selected!==S&&(a[p].selected=S),S&&y&&(a[p].defaultSelected=!0)}else{for(p=""+xe(p),u=null,S=0;S<a.length;S++){if(a[S].value===p){a[S].selected=!0,y&&(a[S].defaultSelected=!0);return}u!==null||a[S].disabled||(u=a[S])}u!==null&&(u.selected=!0)}}function Fe(a,u){if(u.dangerouslySetInnerHTML!=null)throw Error(n(91));return K({},u,{value:void 0,defaultValue:void 0,children:""+a._wrapperState.initialValue})}function ve(a,u){var p=u.value;if(p==null){if(p=u.children,u=u.defaultValue,p!=null){if(u!=null)throw Error(n(92));if(nt(p)){if(1<p.length)throw Error(n(93));p=p[0]}u=p}u==null&&(u=""),p=u}a._wrapperState={initialValue:xe(p)}}function X(a,u){var p=xe(u.value),y=xe(u.defaultValue);p!=null&&(p=""+p,p!==a.value&&(a.value=p),u.defaultValue==null&&a.defaultValue!==p&&(a.defaultValue=p)),y!=null&&(a.defaultValue=""+y)}function Be(a){var u=a.textContent;u===a._wrapperState.initialValue&&u!==""&&u!==null&&(a.value=u)}function ne(a){switch(a){case"svg":return"http://www.w3.org/2000/svg";case"math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function de(a,u){return a==null||a==="http://www.w3.org/1999/xhtml"?ne(u):a==="http://www.w3.org/2000/svg"&&u==="foreignObject"?"http://www.w3.org/1999/xhtml":a}var he,Ge=(function(a){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(u,p,y,S){MSApp.execUnsafeLocalFunction(function(){return a(u,p,y,S)})}:a})(function(a,u){if(a.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in a)a.innerHTML=u;else{for(he=he||document.createElement("div"),he.innerHTML="<svg>"+u.valueOf().toString()+"</svg>",u=he.firstChild;a.firstChild;)a.removeChild(a.firstChild);for(;u.firstChild;)a.appendChild(u.firstChild)}});function Pe(a,u){if(u){var p=a.firstChild;if(p&&p===a.lastChild&&p.nodeType===3){p.nodeValue=u;return}}a.textContent=u}var et={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},ot=["Webkit","ms","Moz","O"];Object.keys(et).forEach(function(a){ot.forEach(function(u){u=u+a.charAt(0).toUpperCase()+a.substring(1),et[u]=et[a]})});function bt(a,u,p){return u==null||typeof u=="boolean"||u===""?"":p||typeof u!="number"||u===0||et.hasOwnProperty(a)&&et[a]?(""+u).trim():u+"px"}function Ye(a,u){a=a.style;for(var p in u)if(u.hasOwnProperty(p)){var y=p.indexOf("--")===0,S=bt(p,u[p],y);p==="float"&&(p="cssFloat"),y?a.setProperty(p,S):a[p]=S}}var it=K({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function gt(a,u){if(u){if(it[a]&&(u.children!=null||u.dangerouslySetInnerHTML!=null))throw Error(n(137,a));if(u.dangerouslySetInnerHTML!=null){if(u.children!=null)throw Error(n(60));if(typeof u.dangerouslySetInnerHTML!="object"||!("__html"in u.dangerouslySetInnerHTML))throw Error(n(61))}if(u.style!=null&&typeof u.style!="object")throw Error(n(62))}}function Nt(a,u){if(a.indexOf("-")===-1)return typeof u.is=="string";switch(a){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Ie=null;function Me(a){return a=a.target||a.srcElement||window,a.correspondingUseElement&&(a=a.correspondingUseElement),a.nodeType===3?a.parentNode:a}var qe=null,F=null,ce=null;function Ne(a){if(a=Ma(a)){if(typeof qe!="function")throw Error(n(280));var u=a.stateNode;u&&(u=sc(u),qe(a.stateNode,a.type,u))}}function P(a){F?ce?ce.push(a):ce=[a]:F=a}function Z(){if(F){var a=F,u=ce;if(ce=F=null,Ne(a),u)for(a=0;a<u.length;a++)Ne(u[a])}}function I(a,u){return a(u)}function re(){}var ye=!1;function Te(a,u,p){if(ye)return a(u,p);ye=!0;try{return I(a,u,p)}finally{ye=!1,(F!==null||ce!==null)&&(re(),Z())}}function Se(a,u){var p=a.stateNode;if(p===null)return null;var y=sc(p);if(y===null)return null;p=y[u];e:switch(u){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(y=!y.disabled)||(a=a.type,y=!(a==="button"||a==="input"||a==="select"||a==="textarea")),a=!y;break e;default:a=!1}if(a)return null;if(p&&typeof p!="function")throw Error(n(231,u,typeof p));return p}var Ee=!1;if(l)try{var me={};Object.defineProperty(me,"passive",{get:function(){Ee=!0}}),window.addEventListener("test",me,me),window.removeEventListener("test",me,me)}catch{Ee=!1}function ke(a,u,p,y,S,N,R,H,Y){var ue=Array.prototype.slice.call(arguments,3);try{u.apply(p,ue)}catch(_e){this.onError(_e)}}var Ct=!1,en=null,on=!1,Wt=null,Ft={onError:function(a){Ct=!0,en=a}};function xt(a,u,p,y,S,N,R,H,Y){Ct=!1,en=null,ke.apply(Ft,arguments)}function Pn(a,u,p,y,S,N,R,H,Y){if(xt.apply(this,arguments),Ct){if(Ct){var ue=en;Ct=!1,en=null}else throw Error(n(198));on||(on=!0,Wt=ue)}}function un(a){var u=a,p=a;if(a.alternate)for(;u.return;)u=u.return;else{a=u;do u=a,(u.flags&4098)!==0&&(p=u.return),a=u.return;while(a)}return u.tag===3?p:null}function yr(a){if(a.tag===13){var u=a.memoizedState;if(u===null&&(a=a.alternate,a!==null&&(u=a.memoizedState)),u!==null)return u.dehydrated}return null}function _r(a){if(un(a)!==a)throw Error(n(188))}function Wr(a){var u=a.alternate;if(!u){if(u=un(a),u===null)throw Error(n(188));return u!==a?null:a}for(var p=a,y=u;;){var S=p.return;if(S===null)break;var N=S.alternate;if(N===null){if(y=S.return,y!==null){p=y;continue}break}if(S.child===N.child){for(N=S.child;N;){if(N===p)return _r(S),a;if(N===y)return _r(S),u;N=N.sibling}throw Error(n(188))}if(p.return!==y.return)p=S,y=N;else{for(var R=!1,H=S.child;H;){if(H===p){R=!0,p=S,y=N;break}if(H===y){R=!0,y=S,p=N;break}H=H.sibling}if(!R){for(H=N.child;H;){if(H===p){R=!0,p=N,y=S;break}if(H===y){R=!0,y=N,p=S;break}H=H.sibling}if(!R)throw Error(n(189))}}if(p.alternate!==y)throw Error(n(190))}if(p.tag!==3)throw Error(n(188));return p.stateNode.current===p?a:u}function is(a){return a=Wr(a),a!==null?ie(a):null}function ie(a){if(a.tag===5||a.tag===6)return a;for(a=a.child;a!==null;){var u=ie(a);if(u!==null)return u;a=a.sibling}return null}var je=e.unstable_scheduleCallback,ze=e.unstable_cancelCallback,_t=e.unstable_shouldYield,Rt=e.unstable_requestPaint,It=e.unstable_now,tr=e.unstable_getCurrentPriorityLevel,qr=e.unstable_ImmediatePriority,Kt=e.unstable_UserBlockingPriority,Vn=e.unstable_NormalPriority,Le=e.unstable_LowPriority,lt=e.unstable_IdlePriority,Tt=null,Ot=null;function yn(a){if(Ot&&typeof Ot.onCommitFiberRoot=="function")try{Ot.onCommitFiberRoot(Tt,a,void 0,(a.current.flags&128)===128)}catch{}}var an=Math.clz32?Math.clz32:nr,as=Math.log,yo=Math.LN2;function nr(a){return a>>>=0,a===0?32:31-(as(a)/yo|0)|0}var rr=64,Ai=4194304;function Fs(a){switch(a&-a){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return a&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return a&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return a}}function Ri(a,u){var p=a.pendingLanes;if(p===0)return 0;var y=0,S=a.suspendedLanes,N=a.pingedLanes,R=p&268435455;if(R!==0){var H=R&~S;H!==0?y=Fs(H):(N&=R,N!==0&&(y=Fs(N)))}else R=p&~S,R!==0?y=Fs(R):N!==0&&(y=Fs(N));if(y===0)return 0;if(u!==0&&u!==y&&(u&S)===0&&(S=y&-y,N=u&-u,S>=N||S===16&&(N&4194240)!==0))return u;if((y&4)!==0&&(y|=p&16),u=a.entangledLanes,u!==0)for(a=a.entanglements,u&=y;0<u;)p=31-an(u),S=1<<p,y|=a[p],u&=~S;return y}function cf(a,u){switch(a){case 1:case 2:case 4:return u+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return u+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function uf(a,u){for(var p=a.suspendedLanes,y=a.pingedLanes,S=a.expirationTimes,N=a.pendingLanes;0<N;){var R=31-an(N),H=1<<R,Y=S[R];Y===-1?((H&p)===0||(H&y)!==0)&&(S[R]=cf(H,u)):Y<=u&&(a.expiredLanes|=H),N&=~H}}function ha(a){return a=a.pendingLanes&-1073741825,a!==0?a:a&1073741824?1073741824:0}function Ul(){var a=rr;return rr<<=1,(rr&4194240)===0&&(rr=64),a}function Us(a){for(var u=[],p=0;31>p;p++)u.push(a);return u}function Hs(a,u,p){a.pendingLanes|=u,u!==536870912&&(a.suspendedLanes=0,a.pingedLanes=0),a=a.eventTimes,u=31-an(u),a[u]=p}function Tr(a,u){var p=a.pendingLanes&~u;a.pendingLanes=u,a.suspendedLanes=0,a.pingedLanes=0,a.expiredLanes&=u,a.mutableReadLanes&=u,a.entangledLanes&=u,u=a.entanglements;var y=a.eventTimes;for(a=a.expirationTimes;0<p;){var S=31-an(p),N=1<<S;u[S]=0,y[S]=-1,a[S]=-1,p&=~N}}function pa(a,u){var p=a.entangledLanes|=u;for(a=a.entanglements;p;){var y=31-an(p),S=1<<y;S&u|a[y]&u&&(a[y]|=u),p&=~S}}var Bt=0;function Et(a){return a&=-a,1<a?4<a?(a&268435455)!==0?16:536870912:4:1}var ma,bn,Gt,Oi,ls,Ii=!1,Ws=[],$e=null,Xe=null,kt=null,Lt=new Map,dn=new Map,Tn=[],df="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset submit".split(" ");function Hl(a,u){switch(a){case"focusin":case"focusout":$e=null;break;case"dragenter":case"dragleave":Xe=null;break;case"mouseover":case"mouseout":kt=null;break;case"pointerover":case"pointerout":Lt.delete(u.pointerId);break;case"gotpointercapture":case"lostpointercapture":dn.delete(u.pointerId)}}function ga(a,u,p,y,S,N){return a===null||a.nativeEvent!==N?(a={blockedOn:u,domEventName:p,eventSystemFlags:y,nativeEvent:N,targetContainers:[S]},u!==null&&(u=Ma(u),u!==null&&bn(u)),a):(a.eventSystemFlags|=y,u=a.targetContainers,S!==null&&u.indexOf(S)===-1&&u.push(S),a)}function _T(a,u,p,y,S){switch(u){case"focusin":return $e=ga($e,a,u,p,y,S),!0;case"dragenter":return Xe=ga(Xe,a,u,p,y,S),!0;case"mouseover":return kt=ga(kt,a,u,p,y,S),!0;case"pointerover":var N=S.pointerId;return Lt.set(N,ga(Lt.get(N)||null,a,u,p,y,S)),!0;case"gotpointercapture":return N=S.pointerId,dn.set(N,ga(dn.get(N)||null,a,u,p,y,S)),!0}return!1}function Ny(a){var u=Li(a.target);if(u!==null){var p=un(u);if(p!==null){if(u=p.tag,u===13){if(u=yr(p),u!==null){a.blockedOn=u,ls(a.priority,function(){Gt(p)});return}}else if(u===3&&p.stateNode.current.memoizedState.isDehydrated){a.blockedOn=p.tag===3?p.stateNode.containerInfo:null;return}}}a.blockedOn=null}function Wl(a){if(a.blockedOn!==null)return!1;for(var u=a.targetContainers;0<u.length;){var p=hf(a.domEventName,a.eventSystemFlags,u[0],a.nativeEvent);if(p===null){p=a.nativeEvent;var y=new p.constructor(p.type,p);Ie=y,p.target.dispatchEvent(y),Ie=null}else return u=Ma(p),u!==null&&bn(u),a.blockedOn=p,!1;u.shift()}return!0}function Cy(a,u,p){Wl(a)&&p.delete(u)}function TT(){Ii=!1,$e!==null&&Wl($e)&&($e=null),Xe!==null&&Wl(Xe)&&(Xe=null),kt!==null&&Wl(kt)&&(kt=null),Lt.forEach(Cy),dn.forEach(Cy)}function va(a,u){a.blockedOn===u&&(a.blockedOn=null,Ii||(Ii=!0,e.unstable_scheduleCallback(e.unstable_NormalPriority,TT)))}function ya(a){function u(S){return va(S,a)}if(0<Ws.length){va(Ws[0],a);for(var p=1;p<Ws.length;p++){var y=Ws[p];y.blockedOn===a&&(y.blockedOn=null)}}for($e!==null&&va($e,a),Xe!==null&&va(Xe,a),kt!==null&&va(kt,a),Lt.forEach(u),dn.forEach(u),p=0;p<Tn.length;p++)y=Tn[p],y.blockedOn===a&&(y.blockedOn=null);for(;0<Tn.length&&(p=Tn[0],p.blockedOn===null);)Ny(p),p.blockedOn===null&&Tn.shift()}var bo=j.ReactCurrentBatchConfig,ql=!0;function jT(a,u,p,y){var S=Bt,N=bo.transition;bo.transition=null;try{Bt=1,ff(a,u,p,y)}finally{Bt=S,bo.transition=N}}function MT(a,u,p,y){var S=Bt,N=bo.transition;bo.transition=null;try{Bt=4,ff(a,u,p,y)}finally{Bt=S,bo.transition=N}}function ff(a,u,p,y){if(ql){var S=hf(a,u,p,y);if(S===null)Mf(a,u,y,Vl,p),Hl(a,y);else if(_T(S,a,u,p,y))y.stopPropagation();else if(Hl(a,y),u&4&&-1<df.indexOf(a)){for(;S!==null;){var N=Ma(S);if(N!==null&&ma(N),N=hf(a,u,p,y),N===null&&Mf(a,u,y,Vl,p),N===S)break;S=N}S!==null&&y.stopPropagation()}else Mf(a,u,y,null,p)}}var Vl=null;function hf(a,u,p,y){if(Vl=null,a=Me(y),a=Li(a),a!==null)if(u=un(a),u===null)a=null;else if(p=u.tag,p===13){if(a=yr(u),a!==null)return a;a=null}else if(p===3){if(u.stateNode.current.memoizedState.isDehydrated)return u.tag===3?u.stateNode.containerInfo:null;a=null}else u!==a&&(a=null);return Vl=a,null}function _y(a){switch(a){case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 1;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"toggle":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 4;case"message":switch(tr()){case qr:return 1;case Kt:return 4;case Vn:case Le:return 16;case lt:return 536870912;default:return 16}default:return 16}}var qs=null,pf=null,Kl=null;function Ty(){if(Kl)return Kl;var a,u=pf,p=u.length,y,S="value"in qs?qs.value:qs.textContent,N=S.length;for(a=0;a<p&&u[a]===S[a];a++);var R=p-a;for(y=1;y<=R&&u[p-y]===S[N-y];y++);return Kl=S.slice(a,1<y?1-y:void 0)}function Gl(a){var u=a.keyCode;return"charCode"in a?(a=a.charCode,a===0&&u===13&&(a=13)):a=u,a===10&&(a=13),32<=a||a===13?a:0}function Jl(){return!0}function jy(){return!1}function br(a){function u(p,y,S,N,R){this._reactName=p,this._targetInst=S,this.type=y,this.nativeEvent=N,this.target=R,this.currentTarget=null;for(var H in a)a.hasOwnProperty(H)&&(p=a[H],this[H]=p?p(N):N[H]);return this.isDefaultPrevented=(N.defaultPrevented!=null?N.defaultPrevented:N.returnValue===!1)?Jl:jy,this.isPropagationStopped=jy,this}return K(u.prototype,{preventDefault:function(){this.defaultPrevented=!0;var p=this.nativeEvent;p&&(p.preventDefault?p.preventDefault():typeof p.returnValue!="unknown"&&(p.returnValue=!1),this.isDefaultPrevented=Jl)},stopPropagation:function(){var p=this.nativeEvent;p&&(p.stopPropagation?p.stopPropagation():typeof p.cancelBubble!="unknown"&&(p.cancelBubble=!0),this.isPropagationStopped=Jl)},persist:function(){},isPersistent:Jl}),u}var xo={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(a){return a.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},mf=br(xo),ba=K({},xo,{view:0,detail:0}),AT=br(ba),gf,vf,xa,Yl=K({},ba,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:bf,button:0,buttons:0,relatedTarget:function(a){return a.relatedTarget===void 0?a.fromElement===a.srcElement?a.toElement:a.fromElement:a.relatedTarget},movementX:function(a){return"movementX"in a?a.movementX:(a!==xa&&(xa&&a.type==="mousemove"?(gf=a.screenX-xa.screenX,vf=a.screenY-xa.screenY):vf=gf=0,xa=a),gf)},movementY:function(a){return"movementY"in a?a.movementY:vf}}),My=br(Yl),RT=K({},Yl,{dataTransfer:0}),OT=br(RT),IT=K({},ba,{relatedTarget:0}),yf=br(IT),LT=K({},xo,{animationName:0,elapsedTime:0,pseudoElement:0}),DT=br(LT),PT=K({},xo,{clipboardData:function(a){return"clipboardData"in a?a.clipboardData:window.clipboardData}}),BT=br(PT),$T=K({},xo,{data:0}),Ay=br($T),zT={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},FT={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},UT={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function HT(a){var u=this.nativeEvent;return u.getModifierState?u.getModifierState(a):(a=UT[a])?!!u[a]:!1}function bf(){return HT}var WT=K({},ba,{key:function(a){if(a.key){var u=zT[a.key]||a.key;if(u!=="Unidentified")return u}return a.type==="keypress"?(a=Gl(a),a===13?"Enter":String.fromCharCode(a)):a.type==="keydown"||a.type==="keyup"?FT[a.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:bf,charCode:function(a){return a.type==="keypress"?Gl(a):0},keyCode:function(a){return a.type==="keydown"||a.type==="keyup"?a.keyCode:0},which:function(a){return a.type==="keypress"?Gl(a):a.type==="keydown"||a.type==="keyup"?a.keyCode:0}}),qT=br(WT),VT=K({},Yl,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Ry=br(VT),KT=K({},ba,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:bf}),GT=br(KT),JT=K({},xo,{propertyName:0,elapsedTime:0,pseudoElement:0}),YT=br(JT),XT=K({},Yl,{deltaX:function(a){return"deltaX"in a?a.deltaX:"wheelDeltaX"in a?-a.wheelDeltaX:0},deltaY:function(a){return"deltaY"in a?a.deltaY:"wheelDeltaY"in a?-a.wheelDeltaY:"wheelDelta"in a?-a.wheelDelta:0},deltaZ:0,deltaMode:0}),QT=br(XT),ZT=[9,13,27,32],xf=l&&"CompositionEvent"in window,wa=null;l&&"documentMode"in document&&(wa=document.documentMode);var ej=l&&"TextEvent"in window&&!wa,Oy=l&&(!xf||wa&&8<wa&&11>=wa),Iy=" ",Ly=!1;function Dy(a,u){switch(a){case"keyup":return ZT.indexOf(u.keyCode)!==-1;case"keydown":return u.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Py(a){return a=a.detail,typeof a=="object"&&"data"in a?a.data:null}var wo=!1;function tj(a,u){switch(a){case"compositionend":return Py(u);case"keypress":return u.which!==32?null:(Ly=!0,Iy);case"textInput":return a=u.data,a===Iy&&Ly?null:a;default:return null}}function nj(a,u){if(wo)return a==="compositionend"||!xf&&Dy(a,u)?(a=Ty(),Kl=pf=qs=null,wo=!1,a):null;switch(a){case"paste":return null;case"keypress":if(!(u.ctrlKey||u.altKey||u.metaKey)||u.ctrlKey&&u.altKey){if(u.char&&1<u.char.length)return u.char;if(u.which)return String.fromCharCode(u.which)}return null;case"compositionend":return Oy&&u.locale!=="ko"?null:u.data;default:return null}}var rj={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function By(a){var u=a&&a.nodeName&&a.nodeName.toLowerCase();return u==="input"?!!rj[a.type]:u==="textarea"}function $y(a,u,p,y){P(y),u=tc(u,"onChange"),0<u.length&&(p=new mf("onChange","change",null,p,y),a.push({event:p,listeners:u}))}var ka=null,Sa=null;function sj(a){rb(a,0)}function Xl(a){var u=Co(a);if(Oe(u))return a}function ij(a,u){if(a==="change")return u}var zy=!1;if(l){var wf;if(l){var kf="oninput"in document;if(!kf){var Fy=document.createElement("div");Fy.setAttribute("oninput","return;"),kf=typeof Fy.oninput=="function"}wf=kf}else wf=!1;zy=wf&&(!document.documentMode||9<document.documentMode)}function Uy(){ka&&(ka.detachEvent("onpropertychange",Hy),Sa=ka=null)}function Hy(a){if(a.propertyName==="value"&&Xl(Sa)){var u=[];$y(u,Sa,a,Me(a)),Te(sj,u)}}function oj(a,u,p){a==="focusin"?(Uy(),ka=u,Sa=p,ka.attachEvent("onpropertychange",Hy)):a==="focusout"&&Uy()}function aj(a){if(a==="selectionchange"||a==="keyup"||a==="keydown")return Xl(Sa)}function lj(a,u){if(a==="click")return Xl(u)}function cj(a,u){if(a==="input"||a==="change")return Xl(u)}function uj(a,u){return a===u&&(a!==0||1/a===1/u)||a!==a&&u!==u}var Vr=typeof Object.is=="function"?Object.is:uj;function Ea(a,u){if(Vr(a,u))return!0;if(typeof a!="object"||a===null||typeof u!="object"||u===null)return!1;var p=Object.keys(a),y=Object.keys(u);if(p.length!==y.length)return!1;for(y=0;y<p.length;y++){var S=p[y];if(!d.call(u,S)||!Vr(a[S],u[S]))return!1}return!0}function Wy(a){for(;a&&a.firstChild;)a=a.firstChild;return a}function qy(a,u){var p=Wy(a);a=0;for(var y;p;){if(p.nodeType===3){if(y=a+p.textContent.length,a<=u&&y>=u)return{node:p,offset:u-a};a=y}e:{for(;p;){if(p.nextSibling){p=p.nextSibling;break e}p=p.parentNode}p=void 0}p=Wy(p)}}function Vy(a,u){return a&&u?a===u?!0:a&&a.nodeType===3?!1:u&&u.nodeType===3?Vy(a,u.parentNode):"contains"in a?a.contains(u):a.compareDocumentPosition?!!(a.compareDocumentPosition(u)&16):!1:!1}function Ky(){for(var a=window,u=Ke();u instanceof a.HTMLIFrameElement;){try{var p=typeof u.contentWindow.location.href=="string"}catch{p=!1}if(p)a=u.contentWindow;else break;u=Ke(a.document)}return u}function Sf(a){var u=a&&a.nodeName&&a.nodeName.toLowerCase();return u&&(u==="input"&&(a.type==="text"||a.type==="search"||a.type==="tel"||a.type==="url"||a.type==="password")||u==="textarea"||a.contentEditable==="true")}function dj(a){var u=Ky(),p=a.focusedElem,y=a.selectionRange;if(u!==p&&p&&p.ownerDocument&&Vy(p.ownerDocument.documentElement,p)){if(y!==null&&Sf(p)){if(u=y.start,a=y.end,a===void 0&&(a=u),"selectionStart"in p)p.selectionStart=u,p.selectionEnd=Math.min(a,p.value.length);else if(a=(u=p.ownerDocument||document)&&u.defaultView||window,a.getSelection){a=a.getSelection();var S=p.textContent.length,N=Math.min(y.start,S);y=y.end===void 0?N:Math.min(y.end,S),!a.extend&&N>y&&(S=y,y=N,N=S),S=qy(p,N);var R=qy(p,y);S&&R&&(a.rangeCount!==1||a.anchorNode!==S.node||a.anchorOffset!==S.offset||a.focusNode!==R.node||a.focusOffset!==R.offset)&&(u=u.createRange(),u.setStart(S.node,S.offset),a.removeAllRanges(),N>y?(a.addRange(u),a.extend(R.node,R.offset)):(u.setEnd(R.node,R.offset),a.addRange(u)))}}for(u=[],a=p;a=a.parentNode;)a.nodeType===1&&u.push({element:a,left:a.scrollLeft,top:a.scrollTop});for(typeof p.focus=="function"&&p.focus(),p=0;p<u.length;p++)a=u[p],a.element.scrollLeft=a.left,a.element.scrollTop=a.top}}var fj=l&&"documentMode"in document&&11>=document.documentMode,ko=null,Ef=null,Na=null,Nf=!1;function Gy(a,u,p){var y=p.window===p?p.document:p.nodeType===9?p:p.ownerDocument;Nf||ko==null||ko!==Ke(y)||(y=ko,"selectionStart"in y&&Sf(y)?y={start:y.selectionStart,end:y.selectionEnd}:(y=(y.ownerDocument&&y.ownerDocument.defaultView||window).getSelection(),y={anchorNode:y.anchorNode,anchorOffset:y.anchorOffset,focusNode:y.focusNode,focusOffset:y.focusOffset}),Na&&Ea(Na,y)||(Na=y,y=tc(Ef,"onSelect"),0<y.length&&(u=new mf("onSelect","select",null,u,p),a.push({event:u,listeners:y}),u.target=ko)))}function Ql(a,u){var p={};return p[a.toLowerCase()]=u.toLowerCase(),p["Webkit"+a]="webkit"+u,p["Moz"+a]="moz"+u,p}var So={animationend:Ql("Animation","AnimationEnd"),animationiteration:Ql("Animation","AnimationIteration"),animationstart:Ql("Animation","AnimationStart"),transitionend:Ql("Transition","TransitionEnd")},Cf={},Jy={};l&&(Jy=document.createElement("div").style,"AnimationEvent"in window||(delete So.animationend.animation,delete So.animationiteration.animation,delete So.animationstart.animation),"TransitionEvent"in window||delete So.transitionend.transition);function Zl(a){if(Cf[a])return Cf[a];if(!So[a])return a;var u=So[a],p;for(p in u)if(u.hasOwnProperty(p)&&p in Jy)return Cf[a]=u[p];return a}var Yy=Zl("animationend"),Xy=Zl("animationiteration"),Qy=Zl("animationstart"),Zy=Zl("transitionend"),eb=new Map,tb="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function Vs(a,u){eb.set(a,u),i(u,[a])}for(var _f=0;_f<tb.length;_f++){var Tf=tb[_f],hj=Tf.toLowerCase(),pj=Tf[0].toUpperCase()+Tf.slice(1);Vs(hj,"on"+pj)}Vs(Yy,"onAnimationEnd"),Vs(Xy,"onAnimationIteration"),Vs(Qy,"onAnimationStart"),Vs("dblclick","onDoubleClick"),Vs("focusin","onFocus"),Vs("focusout","onBlur"),Vs(Zy,"onTransitionEnd"),o("onMouseEnter",["mouseout","mouseover"]),o("onMouseLeave",["mouseout","mouseover"]),o("onPointerEnter",["pointerout","pointerover"]),o("onPointerLeave",["pointerout","pointerover"]),i("onChange","change click focusin focusout input keydown keyup selectionchange".split(" ")),i("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" ")),i("onBeforeInput",["compositionend","keypress","textInput","paste"]),i("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" ")),i("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" ")),i("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Ca="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),mj=new Set("cancel close invalid load scroll toggle".split(" ").concat(Ca));function nb(a,u,p){var y=a.type||"unknown-event";a.currentTarget=p,Pn(y,u,void 0,a),a.currentTarget=null}function rb(a,u){u=(u&4)!==0;for(var p=0;p<a.length;p++){var y=a[p],S=y.event;y=y.listeners;e:{var N=void 0;if(u)for(var R=y.length-1;0<=R;R--){var H=y[R],Y=H.instance,ue=H.currentTarget;if(H=H.listener,Y!==N&&S.isPropagationStopped())break e;nb(S,H,ue),N=Y}else for(R=0;R<y.length;R++){if(H=y[R],Y=H.instance,ue=H.currentTarget,H=H.listener,Y!==N&&S.isPropagationStopped())break e;nb(S,H,ue),N=Y}}}if(on)throw a=Wt,on=!1,Wt=null,a}function tn(a,u){var p=u[Df];p===void 0&&(p=u[Df]=new Set);var y=a+"__bubble";p.has(y)||(sb(u,a,2,!1),p.add(y))}function jf(a,u,p){var y=0;u&&(y|=4),sb(p,a,y,u)}var ec="_reactListening"+Math.random().toString(36).slice(2);function _a(a){if(!a[ec]){a[ec]=!0,r.forEach(function(p){p!=="selectionchange"&&(mj.has(p)||jf(p,!1,a),jf(p,!0,a))});var u=a.nodeType===9?a:a.ownerDocument;u===null||u[ec]||(u[ec]=!0,jf("selectionchange",!1,u))}}function sb(a,u,p,y){switch(_y(u)){case 1:var S=jT;break;case 4:S=MT;break;default:S=ff}p=S.bind(null,u,p,a),S=void 0,!Ee||u!=="touchstart"&&u!=="touchmove"&&u!=="wheel"||(S=!0),y?S!==void 0?a.addEventListener(u,p,{capture:!0,passive:S}):a.addEventListener(u,p,!0):S!==void 0?a.addEventListener(u,p,{passive:S}):a.addEventListener(u,p,!1)}function Mf(a,u,p,y,S){var N=y;if((u&1)===0&&(u&2)===0&&y!==null)e:for(;;){if(y===null)return;var R=y.tag;if(R===3||R===4){var H=y.stateNode.containerInfo;if(H===S||H.nodeType===8&&H.parentNode===S)break;if(R===4)for(R=y.return;R!==null;){var Y=R.tag;if((Y===3||Y===4)&&(Y=R.stateNode.containerInfo,Y===S||Y.nodeType===8&&Y.parentNode===S))return;R=R.return}for(;H!==null;){if(R=Li(H),R===null)return;if(Y=R.tag,Y===5||Y===6){y=N=R;continue e}H=H.parentNode}}y=y.return}Te(function(){var ue=N,_e=Me(p),Ae=[];e:{var Ce=eb.get(a);if(Ce!==void 0){var Ve=mf,tt=a;switch(a){case"keypress":if(Gl(p)===0)break e;case"keydown":case"keyup":Ve=qT;break;case"focusin":tt="focus",Ve=yf;break;case"focusout":tt="blur",Ve=yf;break;case"beforeblur":case"afterblur":Ve=yf;break;case"click":if(p.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":Ve=My;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":Ve=OT;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":Ve=GT;break;case Yy:case Xy:case Qy:Ve=DT;break;case Zy:Ve=YT;break;case"scroll":Ve=AT;break;case"wheel":Ve=QT;break;case"copy":case"cut":case"paste":Ve=BT;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":Ve=Ry}var rt=(u&4)!==0,xn=!rt&&a==="scroll",ae=rt?Ce!==null?Ce+"Capture":null:Ce;rt=[];for(var Q=ue,le;Q!==null;){le=Q;var De=le.stateNode;if(le.tag===5&&De!==null&&(le=De,ae!==null&&(De=Se(Q,ae),De!=null&&rt.push(Ta(Q,De,le)))),xn)break;Q=Q.return}0<rt.length&&(Ce=new Ve(Ce,tt,null,p,_e),Ae.push({event:Ce,listeners:rt}))}}if((u&7)===0){e:{if(Ce=a==="mouseover"||a==="pointerover",Ve=a==="mouseout"||a==="pointerout",Ce&&p!==Ie&&(tt=p.relatedTarget||p.fromElement)&&(Li(tt)||tt[xs]))break e;if((Ve||Ce)&&(Ce=_e.window===_e?_e:(Ce=_e.ownerDocument)?Ce.defaultView||Ce.parentWindow:window,Ve?(tt=p.relatedTarget||p.toElement,Ve=ue,tt=tt?Li(tt):null,tt!==null&&(xn=un(tt),tt!==xn||tt.tag!==5&&tt.tag!==6)&&(tt=null)):(Ve=null,tt=ue),Ve!==tt)){if(rt=My,De="onMouseLeave",ae="onMouseEnter",Q="mouse",(a==="pointerout"||a==="pointerover")&&(rt=Ry,De="onPointerLeave",ae="onPointerEnter",Q="pointer"),xn=Ve==null?Ce:Co(Ve),le=tt==null?Ce:Co(tt),Ce=new rt(De,Q+"leave",Ve,p,_e),Ce.target=xn,Ce.relatedTarget=le,De=null,Li(_e)===ue&&(rt=new rt(ae,Q+"enter",tt,p,_e),rt.target=le,rt.relatedTarget=xn,De=rt),xn=De,Ve&&tt)t:{for(rt=Ve,ae=tt,Q=0,le=rt;le;le=Eo(le))Q++;for(le=0,De=ae;De;De=Eo(De))le++;for(;0<Q-le;)rt=Eo(rt),Q--;for(;0<le-Q;)ae=Eo(ae),le--;for(;Q--;){if(rt===ae||ae!==null&&rt===ae.alternate)break t;rt=Eo(rt),ae=Eo(ae)}rt=null}else rt=null;Ve!==null&&ib(Ae,Ce,Ve,rt,!1),tt!==null&&xn!==null&&ib(Ae,xn,tt,rt,!0)}}e:{if(Ce=ue?Co(ue):window,Ve=Ce.nodeName&&Ce.nodeName.toLowerCase(),Ve==="select"||Ve==="input"&&Ce.type==="file")var st=ij;else if(By(Ce))if(zy)st=cj;else{st=aj;var vt=oj}else(Ve=Ce.nodeName)&&Ve.toLowerCase()==="input"&&(Ce.type==="checkbox"||Ce.type==="radio")&&(st=lj);if(st&&(st=st(a,ue))){$y(Ae,st,p,_e);break e}vt&&vt(a,Ce,ue),a==="focusout"&&(vt=Ce._wrapperState)&&vt.controlled&&Ce.type==="number"&&at(Ce,"number",Ce.value)}switch(vt=ue?Co(ue):window,a){case"focusin":(By(vt)||vt.contentEditable==="true")&&(ko=vt,Ef=ue,Na=null);break;case"focusout":Na=Ef=ko=null;break;case"mousedown":Nf=!0;break;case"contextmenu":case"mouseup":case"dragend":Nf=!1,Gy(Ae,p,_e);break;case"selectionchange":if(fj)break;case"keydown":case"keyup":Gy(Ae,p,_e)}var yt;if(xf)e:{switch(a){case"compositionstart":var St="onCompositionStart";break e;case"compositionend":St="onCompositionEnd";break e;case"compositionupdate":St="onCompositionUpdate";break e}St=void 0}else wo?Dy(a,p)&&(St="onCompositionEnd"):a==="keydown"&&p.keyCode===229&&(St="onCompositionStart");St&&(Oy&&p.locale!=="ko"&&(wo||St!=="onCompositionStart"?St==="onCompositionEnd"&&wo&&(yt=Ty()):(qs=_e,pf="value"in qs?qs.value:qs.textContent,wo=!0)),vt=tc(ue,St),0<vt.length&&(St=new Ay(St,a,null,p,_e),Ae.push({event:St,listeners:vt}),yt?St.data=yt:(yt=Py(p),yt!==null&&(St.data=yt)))),(yt=ej?tj(a,p):nj(a,p))&&(ue=tc(ue,"onBeforeInput"),0<ue.length&&(_e=new Ay("onBeforeInput","beforeinput",null,p,_e),Ae.push({event:_e,listeners:ue}),_e.data=yt))}rb(Ae,u)})}function Ta(a,u,p){return{instance:a,listener:u,currentTarget:p}}function tc(a,u){for(var p=u+"Capture",y=[];a!==null;){var S=a,N=S.stateNode;S.tag===5&&N!==null&&(S=N,N=Se(a,p),N!=null&&y.unshift(Ta(a,N,S)),N=Se(a,u),N!=null&&y.push(Ta(a,N,S))),a=a.return}return y}function Eo(a){if(a===null)return null;do a=a.return;while(a&&a.tag!==5);return a||null}function ib(a,u,p,y,S){for(var N=u._reactName,R=[];p!==null&&p!==y;){var H=p,Y=H.alternate,ue=H.stateNode;if(Y!==null&&Y===y)break;H.tag===5&&ue!==null&&(H=ue,S?(Y=Se(p,N),Y!=null&&R.unshift(Ta(p,Y,H))):S||(Y=Se(p,N),Y!=null&&R.push(Ta(p,Y,H)))),p=p.return}R.length!==0&&a.push({event:u,listeners:R})}var gj=/\r\n?/g,vj=/\u0000|\uFFFD/g;function ob(a){return(typeof a=="string"?a:""+a).replace(gj,`
38
- `).replace(vj,"")}function nc(a,u,p){if(u=ob(u),ob(a)!==u&&p)throw Error(n(425))}function rc(){}var Af=null,Rf=null;function Of(a,u){return a==="textarea"||a==="noscript"||typeof u.children=="string"||typeof u.children=="number"||typeof u.dangerouslySetInnerHTML=="object"&&u.dangerouslySetInnerHTML!==null&&u.dangerouslySetInnerHTML.__html!=null}var If=typeof setTimeout=="function"?setTimeout:void 0,yj=typeof clearTimeout=="function"?clearTimeout:void 0,ab=typeof Promise=="function"?Promise:void 0,bj=typeof queueMicrotask=="function"?queueMicrotask:typeof ab<"u"?function(a){return ab.resolve(null).then(a).catch(xj)}:If;function xj(a){setTimeout(function(){throw a})}function Lf(a,u){var p=u,y=0;do{var S=p.nextSibling;if(a.removeChild(p),S&&S.nodeType===8)if(p=S.data,p==="/$"){if(y===0){a.removeChild(S),ya(u);return}y--}else p!=="$"&&p!=="$?"&&p!=="$!"||y++;p=S}while(p);ya(u)}function Ks(a){for(;a!=null;a=a.nextSibling){var u=a.nodeType;if(u===1||u===3)break;if(u===8){if(u=a.data,u==="$"||u==="$!"||u==="$?")break;if(u==="/$")return null}}return a}function lb(a){a=a.previousSibling;for(var u=0;a;){if(a.nodeType===8){var p=a.data;if(p==="$"||p==="$!"||p==="$?"){if(u===0)return a;u--}else p==="/$"&&u++}a=a.previousSibling}return null}var No=Math.random().toString(36).slice(2),cs="__reactFiber$"+No,ja="__reactProps$"+No,xs="__reactContainer$"+No,Df="__reactEvents$"+No,wj="__reactListeners$"+No,kj="__reactHandles$"+No;function Li(a){var u=a[cs];if(u)return u;for(var p=a.parentNode;p;){if(u=p[xs]||p[cs]){if(p=u.alternate,u.child!==null||p!==null&&p.child!==null)for(a=lb(a);a!==null;){if(p=a[cs])return p;a=lb(a)}return u}a=p,p=a.parentNode}return null}function Ma(a){return a=a[cs]||a[xs],!a||a.tag!==5&&a.tag!==6&&a.tag!==13&&a.tag!==3?null:a}function Co(a){if(a.tag===5||a.tag===6)return a.stateNode;throw Error(n(33))}function sc(a){return a[ja]||null}var Pf=[],_o=-1;function Gs(a){return{current:a}}function nn(a){0>_o||(a.current=Pf[_o],Pf[_o]=null,_o--)}function Qt(a,u){_o++,Pf[_o]=a.current,a.current=u}var Js={},Kn=Gs(Js),cr=Gs(!1),Di=Js;function To(a,u){var p=a.type.contextTypes;if(!p)return Js;var y=a.stateNode;if(y&&y.__reactInternalMemoizedUnmaskedChildContext===u)return y.__reactInternalMemoizedMaskedChildContext;var S={},N;for(N in p)S[N]=u[N];return y&&(a=a.stateNode,a.__reactInternalMemoizedUnmaskedChildContext=u,a.__reactInternalMemoizedMaskedChildContext=S),S}function ur(a){return a=a.childContextTypes,a!=null}function ic(){nn(cr),nn(Kn)}function cb(a,u,p){if(Kn.current!==Js)throw Error(n(168));Qt(Kn,u),Qt(cr,p)}function ub(a,u,p){var y=a.stateNode;if(u=u.childContextTypes,typeof y.getChildContext!="function")return p;y=y.getChildContext();for(var S in y)if(!(S in u))throw Error(n(108,we(a)||"Unknown",S));return K({},p,y)}function oc(a){return a=(a=a.stateNode)&&a.__reactInternalMemoizedMergedChildContext||Js,Di=Kn.current,Qt(Kn,a),Qt(cr,cr.current),!0}function db(a,u,p){var y=a.stateNode;if(!y)throw Error(n(169));p?(a=ub(a,u,Di),y.__reactInternalMemoizedMergedChildContext=a,nn(cr),nn(Kn),Qt(Kn,a)):nn(cr),Qt(cr,p)}var ws=null,ac=!1,Bf=!1;function fb(a){ws===null?ws=[a]:ws.push(a)}function Sj(a){ac=!0,fb(a)}function Ys(){if(!Bf&&ws!==null){Bf=!0;var a=0,u=Bt;try{var p=ws;for(Bt=1;a<p.length;a++){var y=p[a];do y=y(!0);while(y!==null)}ws=null,ac=!1}catch(S){throw ws!==null&&(ws=ws.slice(a+1)),je(qr,Ys),S}finally{Bt=u,Bf=!1}}return null}var jo=[],Mo=0,lc=null,cc=0,jr=[],Mr=0,Pi=null,ks=1,Ss="";function Bi(a,u){jo[Mo++]=cc,jo[Mo++]=lc,lc=a,cc=u}function hb(a,u,p){jr[Mr++]=ks,jr[Mr++]=Ss,jr[Mr++]=Pi,Pi=a;var y=ks;a=Ss;var S=32-an(y)-1;y&=~(1<<S),p+=1;var N=32-an(u)+S;if(30<N){var R=S-S%5;N=(y&(1<<R)-1).toString(32),y>>=R,S-=R,ks=1<<32-an(u)+S|p<<S|y,Ss=N+a}else ks=1<<N|p<<S|y,Ss=a}function $f(a){a.return!==null&&(Bi(a,1),hb(a,1,0))}function zf(a){for(;a===lc;)lc=jo[--Mo],jo[Mo]=null,cc=jo[--Mo],jo[Mo]=null;for(;a===Pi;)Pi=jr[--Mr],jr[Mr]=null,Ss=jr[--Mr],jr[Mr]=null,ks=jr[--Mr],jr[Mr]=null}var xr=null,wr=null,sn=!1,Kr=null;function pb(a,u){var p=Ir(5,null,null,0);p.elementType="DELETED",p.stateNode=u,p.return=a,u=a.deletions,u===null?(a.deletions=[p],a.flags|=16):u.push(p)}function mb(a,u){switch(a.tag){case 5:var p=a.type;return u=u.nodeType!==1||p.toLowerCase()!==u.nodeName.toLowerCase()?null:u,u!==null?(a.stateNode=u,xr=a,wr=Ks(u.firstChild),!0):!1;case 6:return u=a.pendingProps===""||u.nodeType!==3?null:u,u!==null?(a.stateNode=u,xr=a,wr=null,!0):!1;case 13:return u=u.nodeType!==8?null:u,u!==null?(p=Pi!==null?{id:ks,overflow:Ss}:null,a.memoizedState={dehydrated:u,treeContext:p,retryLane:1073741824},p=Ir(18,null,null,0),p.stateNode=u,p.return=a,a.child=p,xr=a,wr=null,!0):!1;default:return!1}}function Ff(a){return(a.mode&1)!==0&&(a.flags&128)===0}function Uf(a){if(sn){var u=wr;if(u){var p=u;if(!mb(a,u)){if(Ff(a))throw Error(n(418));u=Ks(p.nextSibling);var y=xr;u&&mb(a,u)?pb(y,p):(a.flags=a.flags&-4097|2,sn=!1,xr=a)}}else{if(Ff(a))throw Error(n(418));a.flags=a.flags&-4097|2,sn=!1,xr=a}}}function gb(a){for(a=a.return;a!==null&&a.tag!==5&&a.tag!==3&&a.tag!==13;)a=a.return;xr=a}function uc(a){if(a!==xr)return!1;if(!sn)return gb(a),sn=!0,!1;var u;if((u=a.tag!==3)&&!(u=a.tag!==5)&&(u=a.type,u=u!=="head"&&u!=="body"&&!Of(a.type,a.memoizedProps)),u&&(u=wr)){if(Ff(a))throw vb(),Error(n(418));for(;u;)pb(a,u),u=Ks(u.nextSibling)}if(gb(a),a.tag===13){if(a=a.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(n(317));e:{for(a=a.nextSibling,u=0;a;){if(a.nodeType===8){var p=a.data;if(p==="/$"){if(u===0){wr=Ks(a.nextSibling);break e}u--}else p!=="$"&&p!=="$!"&&p!=="$?"||u++}a=a.nextSibling}wr=null}}else wr=xr?Ks(a.stateNode.nextSibling):null;return!0}function vb(){for(var a=wr;a;)a=Ks(a.nextSibling)}function Ao(){wr=xr=null,sn=!1}function Hf(a){Kr===null?Kr=[a]:Kr.push(a)}var Ej=j.ReactCurrentBatchConfig;function Aa(a,u,p){if(a=p.ref,a!==null&&typeof a!="function"&&typeof a!="object"){if(p._owner){if(p=p._owner,p){if(p.tag!==1)throw Error(n(309));var y=p.stateNode}if(!y)throw Error(n(147,a));var S=y,N=""+a;return u!==null&&u.ref!==null&&typeof u.ref=="function"&&u.ref._stringRef===N?u.ref:(u=function(R){var H=S.refs;R===null?delete H[N]:H[N]=R},u._stringRef=N,u)}if(typeof a!="string")throw Error(n(284));if(!p._owner)throw Error(n(290,a))}return a}function dc(a,u){throw a=Object.prototype.toString.call(u),Error(n(31,a==="[object Object]"?"object with keys {"+Object.keys(u).join(", ")+"}":a))}function yb(a){var u=a._init;return u(a._payload)}function bb(a){function u(ae,Q){if(a){var le=ae.deletions;le===null?(ae.deletions=[Q],ae.flags|=16):le.push(Q)}}function p(ae,Q){if(!a)return null;for(;Q!==null;)u(ae,Q),Q=Q.sibling;return null}function y(ae,Q){for(ae=new Map;Q!==null;)Q.key!==null?ae.set(Q.key,Q):ae.set(Q.index,Q),Q=Q.sibling;return ae}function S(ae,Q){return ae=si(ae,Q),ae.index=0,ae.sibling=null,ae}function N(ae,Q,le){return ae.index=le,a?(le=ae.alternate,le!==null?(le=le.index,le<Q?(ae.flags|=2,Q):le):(ae.flags|=2,Q)):(ae.flags|=1048576,Q)}function R(ae){return a&&ae.alternate===null&&(ae.flags|=2),ae}function H(ae,Q,le,De){return Q===null||Q.tag!==6?(Q=Ih(le,ae.mode,De),Q.return=ae,Q):(Q=S(Q,le),Q.return=ae,Q)}function Y(ae,Q,le,De){var st=le.type;return st===O?_e(ae,Q,le.props.children,De,le.key):Q!==null&&(Q.elementType===st||typeof st=="object"&&st!==null&&st.$$typeof===q&&yb(st)===Q.type)?(De=S(Q,le.props),De.ref=Aa(ae,Q,le),De.return=ae,De):(De=Lc(le.type,le.key,le.props,null,ae.mode,De),De.ref=Aa(ae,Q,le),De.return=ae,De)}function ue(ae,Q,le,De){return Q===null||Q.tag!==4||Q.stateNode.containerInfo!==le.containerInfo||Q.stateNode.implementation!==le.implementation?(Q=Lh(le,ae.mode,De),Q.return=ae,Q):(Q=S(Q,le.children||[]),Q.return=ae,Q)}function _e(ae,Q,le,De,st){return Q===null||Q.tag!==7?(Q=Vi(le,ae.mode,De,st),Q.return=ae,Q):(Q=S(Q,le),Q.return=ae,Q)}function Ae(ae,Q,le){if(typeof Q=="string"&&Q!==""||typeof Q=="number")return Q=Ih(""+Q,ae.mode,le),Q.return=ae,Q;if(typeof Q=="object"&&Q!==null){switch(Q.$$typeof){case _:return le=Lc(Q.type,Q.key,Q.props,null,ae.mode,le),le.ref=Aa(ae,null,Q),le.return=ae,le;case A:return Q=Lh(Q,ae.mode,le),Q.return=ae,Q;case q:var De=Q._init;return Ae(ae,De(Q._payload),le)}if(nt(Q)||te(Q))return Q=Vi(Q,ae.mode,le,null),Q.return=ae,Q;dc(ae,Q)}return null}function Ce(ae,Q,le,De){var st=Q!==null?Q.key:null;if(typeof le=="string"&&le!==""||typeof le=="number")return st!==null?null:H(ae,Q,""+le,De);if(typeof le=="object"&&le!==null){switch(le.$$typeof){case _:return le.key===st?Y(ae,Q,le,De):null;case A:return le.key===st?ue(ae,Q,le,De):null;case q:return st=le._init,Ce(ae,Q,st(le._payload),De)}if(nt(le)||te(le))return st!==null?null:_e(ae,Q,le,De,null);dc(ae,le)}return null}function Ve(ae,Q,le,De,st){if(typeof De=="string"&&De!==""||typeof De=="number")return ae=ae.get(le)||null,H(Q,ae,""+De,st);if(typeof De=="object"&&De!==null){switch(De.$$typeof){case _:return ae=ae.get(De.key===null?le:De.key)||null,Y(Q,ae,De,st);case A:return ae=ae.get(De.key===null?le:De.key)||null,ue(Q,ae,De,st);case q:var vt=De._init;return Ve(ae,Q,le,vt(De._payload),st)}if(nt(De)||te(De))return ae=ae.get(le)||null,_e(Q,ae,De,st,null);dc(Q,De)}return null}function tt(ae,Q,le,De){for(var st=null,vt=null,yt=Q,St=Q=0,An=null;yt!==null&&St<le.length;St++){yt.index>St?(An=yt,yt=null):An=yt.sibling;var Ut=Ce(ae,yt,le[St],De);if(Ut===null){yt===null&&(yt=An);break}a&&yt&&Ut.alternate===null&&u(ae,yt),Q=N(Ut,Q,St),vt===null?st=Ut:vt.sibling=Ut,vt=Ut,yt=An}if(St===le.length)return p(ae,yt),sn&&Bi(ae,St),st;if(yt===null){for(;St<le.length;St++)yt=Ae(ae,le[St],De),yt!==null&&(Q=N(yt,Q,St),vt===null?st=yt:vt.sibling=yt,vt=yt);return sn&&Bi(ae,St),st}for(yt=y(ae,yt);St<le.length;St++)An=Ve(yt,ae,St,le[St],De),An!==null&&(a&&An.alternate!==null&&yt.delete(An.key===null?St:An.key),Q=N(An,Q,St),vt===null?st=An:vt.sibling=An,vt=An);return a&&yt.forEach(function(ii){return u(ae,ii)}),sn&&Bi(ae,St),st}function rt(ae,Q,le,De){var st=te(le);if(typeof st!="function")throw Error(n(150));if(le=st.call(le),le==null)throw Error(n(151));for(var vt=st=null,yt=Q,St=Q=0,An=null,Ut=le.next();yt!==null&&!Ut.done;St++,Ut=le.next()){yt.index>St?(An=yt,yt=null):An=yt.sibling;var ii=Ce(ae,yt,Ut.value,De);if(ii===null){yt===null&&(yt=An);break}a&&yt&&ii.alternate===null&&u(ae,yt),Q=N(ii,Q,St),vt===null?st=ii:vt.sibling=ii,vt=ii,yt=An}if(Ut.done)return p(ae,yt),sn&&Bi(ae,St),st;if(yt===null){for(;!Ut.done;St++,Ut=le.next())Ut=Ae(ae,Ut.value,De),Ut!==null&&(Q=N(Ut,Q,St),vt===null?st=Ut:vt.sibling=Ut,vt=Ut);return sn&&Bi(ae,St),st}for(yt=y(ae,yt);!Ut.done;St++,Ut=le.next())Ut=Ve(yt,ae,St,Ut.value,De),Ut!==null&&(a&&Ut.alternate!==null&&yt.delete(Ut.key===null?St:Ut.key),Q=N(Ut,Q,St),vt===null?st=Ut:vt.sibling=Ut,vt=Ut);return a&&yt.forEach(function(rM){return u(ae,rM)}),sn&&Bi(ae,St),st}function xn(ae,Q,le,De){if(typeof le=="object"&&le!==null&&le.type===O&&le.key===null&&(le=le.props.children),typeof le=="object"&&le!==null){switch(le.$$typeof){case _:e:{for(var st=le.key,vt=Q;vt!==null;){if(vt.key===st){if(st=le.type,st===O){if(vt.tag===7){p(ae,vt.sibling),Q=S(vt,le.props.children),Q.return=ae,ae=Q;break e}}else if(vt.elementType===st||typeof st=="object"&&st!==null&&st.$$typeof===q&&yb(st)===vt.type){p(ae,vt.sibling),Q=S(vt,le.props),Q.ref=Aa(ae,vt,le),Q.return=ae,ae=Q;break e}p(ae,vt);break}else u(ae,vt);vt=vt.sibling}le.type===O?(Q=Vi(le.props.children,ae.mode,De,le.key),Q.return=ae,ae=Q):(De=Lc(le.type,le.key,le.props,null,ae.mode,De),De.ref=Aa(ae,Q,le),De.return=ae,ae=De)}return R(ae);case A:e:{for(vt=le.key;Q!==null;){if(Q.key===vt)if(Q.tag===4&&Q.stateNode.containerInfo===le.containerInfo&&Q.stateNode.implementation===le.implementation){p(ae,Q.sibling),Q=S(Q,le.children||[]),Q.return=ae,ae=Q;break e}else{p(ae,Q);break}else u(ae,Q);Q=Q.sibling}Q=Lh(le,ae.mode,De),Q.return=ae,ae=Q}return R(ae);case q:return vt=le._init,xn(ae,Q,vt(le._payload),De)}if(nt(le))return tt(ae,Q,le,De);if(te(le))return rt(ae,Q,le,De);dc(ae,le)}return typeof le=="string"&&le!==""||typeof le=="number"?(le=""+le,Q!==null&&Q.tag===6?(p(ae,Q.sibling),Q=S(Q,le),Q.return=ae,ae=Q):(p(ae,Q),Q=Ih(le,ae.mode,De),Q.return=ae,ae=Q),R(ae)):p(ae,Q)}return xn}var Ro=bb(!0),xb=bb(!1),fc=Gs(null),hc=null,Oo=null,Wf=null;function qf(){Wf=Oo=hc=null}function Vf(a){var u=fc.current;nn(fc),a._currentValue=u}function Kf(a,u,p){for(;a!==null;){var y=a.alternate;if((a.childLanes&u)!==u?(a.childLanes|=u,y!==null&&(y.childLanes|=u)):y!==null&&(y.childLanes&u)!==u&&(y.childLanes|=u),a===p)break;a=a.return}}function Io(a,u){hc=a,Wf=Oo=null,a=a.dependencies,a!==null&&a.firstContext!==null&&((a.lanes&u)!==0&&(dr=!0),a.firstContext=null)}function Ar(a){var u=a._currentValue;if(Wf!==a)if(a={context:a,memoizedValue:u,next:null},Oo===null){if(hc===null)throw Error(n(308));Oo=a,hc.dependencies={lanes:0,firstContext:a}}else Oo=Oo.next=a;return u}var $i=null;function Gf(a){$i===null?$i=[a]:$i.push(a)}function wb(a,u,p,y){var S=u.interleaved;return S===null?(p.next=p,Gf(u)):(p.next=S.next,S.next=p),u.interleaved=p,Es(a,y)}function Es(a,u){a.lanes|=u;var p=a.alternate;for(p!==null&&(p.lanes|=u),p=a,a=a.return;a!==null;)a.childLanes|=u,p=a.alternate,p!==null&&(p.childLanes|=u),p=a,a=a.return;return p.tag===3?p.stateNode:null}var Xs=!1;function Jf(a){a.updateQueue={baseState:a.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function kb(a,u){a=a.updateQueue,u.updateQueue===a&&(u.updateQueue={baseState:a.baseState,firstBaseUpdate:a.firstBaseUpdate,lastBaseUpdate:a.lastBaseUpdate,shared:a.shared,effects:a.effects})}function Ns(a,u){return{eventTime:a,lane:u,tag:0,payload:null,callback:null,next:null}}function Qs(a,u,p){var y=a.updateQueue;if(y===null)return null;if(y=y.shared,($t&2)!==0){var S=y.pending;return S===null?u.next=u:(u.next=S.next,S.next=u),y.pending=u,Es(a,p)}return S=y.interleaved,S===null?(u.next=u,Gf(y)):(u.next=S.next,S.next=u),y.interleaved=u,Es(a,p)}function pc(a,u,p){if(u=u.updateQueue,u!==null&&(u=u.shared,(p&4194240)!==0)){var y=u.lanes;y&=a.pendingLanes,p|=y,u.lanes=p,pa(a,p)}}function Sb(a,u){var p=a.updateQueue,y=a.alternate;if(y!==null&&(y=y.updateQueue,p===y)){var S=null,N=null;if(p=p.firstBaseUpdate,p!==null){do{var R={eventTime:p.eventTime,lane:p.lane,tag:p.tag,payload:p.payload,callback:p.callback,next:null};N===null?S=N=R:N=N.next=R,p=p.next}while(p!==null);N===null?S=N=u:N=N.next=u}else S=N=u;p={baseState:y.baseState,firstBaseUpdate:S,lastBaseUpdate:N,shared:y.shared,effects:y.effects},a.updateQueue=p;return}a=p.lastBaseUpdate,a===null?p.firstBaseUpdate=u:a.next=u,p.lastBaseUpdate=u}function mc(a,u,p,y){var S=a.updateQueue;Xs=!1;var N=S.firstBaseUpdate,R=S.lastBaseUpdate,H=S.shared.pending;if(H!==null){S.shared.pending=null;var Y=H,ue=Y.next;Y.next=null,R===null?N=ue:R.next=ue,R=Y;var _e=a.alternate;_e!==null&&(_e=_e.updateQueue,H=_e.lastBaseUpdate,H!==R&&(H===null?_e.firstBaseUpdate=ue:H.next=ue,_e.lastBaseUpdate=Y))}if(N!==null){var Ae=S.baseState;R=0,_e=ue=Y=null,H=N;do{var Ce=H.lane,Ve=H.eventTime;if((y&Ce)===Ce){_e!==null&&(_e=_e.next={eventTime:Ve,lane:0,tag:H.tag,payload:H.payload,callback:H.callback,next:null});e:{var tt=a,rt=H;switch(Ce=u,Ve=p,rt.tag){case 1:if(tt=rt.payload,typeof tt=="function"){Ae=tt.call(Ve,Ae,Ce);break e}Ae=tt;break e;case 3:tt.flags=tt.flags&-65537|128;case 0:if(tt=rt.payload,Ce=typeof tt=="function"?tt.call(Ve,Ae,Ce):tt,Ce==null)break e;Ae=K({},Ae,Ce);break e;case 2:Xs=!0}}H.callback!==null&&H.lane!==0&&(a.flags|=64,Ce=S.effects,Ce===null?S.effects=[H]:Ce.push(H))}else Ve={eventTime:Ve,lane:Ce,tag:H.tag,payload:H.payload,callback:H.callback,next:null},_e===null?(ue=_e=Ve,Y=Ae):_e=_e.next=Ve,R|=Ce;if(H=H.next,H===null){if(H=S.shared.pending,H===null)break;Ce=H,H=Ce.next,Ce.next=null,S.lastBaseUpdate=Ce,S.shared.pending=null}}while(!0);if(_e===null&&(Y=Ae),S.baseState=Y,S.firstBaseUpdate=ue,S.lastBaseUpdate=_e,u=S.shared.interleaved,u!==null){S=u;do R|=S.lane,S=S.next;while(S!==u)}else N===null&&(S.shared.lanes=0);Ui|=R,a.lanes=R,a.memoizedState=Ae}}function Eb(a,u,p){if(a=u.effects,u.effects=null,a!==null)for(u=0;u<a.length;u++){var y=a[u],S=y.callback;if(S!==null){if(y.callback=null,y=p,typeof S!="function")throw Error(n(191,S));S.call(y)}}}var Ra={},us=Gs(Ra),Oa=Gs(Ra),Ia=Gs(Ra);function zi(a){if(a===Ra)throw Error(n(174));return a}function Yf(a,u){switch(Qt(Ia,u),Qt(Oa,a),Qt(us,Ra),a=u.nodeType,a){case 9:case 11:u=(u=u.documentElement)?u.namespaceURI:de(null,"");break;default:a=a===8?u.parentNode:u,u=a.namespaceURI||null,a=a.tagName,u=de(u,a)}nn(us),Qt(us,u)}function Lo(){nn(us),nn(Oa),nn(Ia)}function Nb(a){zi(Ia.current);var u=zi(us.current),p=de(u,a.type);u!==p&&(Qt(Oa,a),Qt(us,p))}function Xf(a){Oa.current===a&&(nn(us),nn(Oa))}var ln=Gs(0);function gc(a){for(var u=a;u!==null;){if(u.tag===13){var p=u.memoizedState;if(p!==null&&(p=p.dehydrated,p===null||p.data==="$?"||p.data==="$!"))return u}else if(u.tag===19&&u.memoizedProps.revealOrder!==void 0){if((u.flags&128)!==0)return u}else if(u.child!==null){u.child.return=u,u=u.child;continue}if(u===a)break;for(;u.sibling===null;){if(u.return===null||u.return===a)return null;u=u.return}u.sibling.return=u.return,u=u.sibling}return null}var Qf=[];function Zf(){for(var a=0;a<Qf.length;a++)Qf[a]._workInProgressVersionPrimary=null;Qf.length=0}var vc=j.ReactCurrentDispatcher,eh=j.ReactCurrentBatchConfig,Fi=0,cn=null,Cn=null,jn=null,yc=!1,La=!1,Da=0,Nj=0;function Gn(){throw Error(n(321))}function th(a,u){if(u===null)return!1;for(var p=0;p<u.length&&p<a.length;p++)if(!Vr(a[p],u[p]))return!1;return!0}function nh(a,u,p,y,S,N){if(Fi=N,cn=u,u.memoizedState=null,u.updateQueue=null,u.lanes=0,vc.current=a===null||a.memoizedState===null?jj:Mj,a=p(y,S),La){N=0;do{if(La=!1,Da=0,25<=N)throw Error(n(301));N+=1,jn=Cn=null,u.updateQueue=null,vc.current=Aj,a=p(y,S)}while(La)}if(vc.current=wc,u=Cn!==null&&Cn.next!==null,Fi=0,jn=Cn=cn=null,yc=!1,u)throw Error(n(300));return a}function rh(){var a=Da!==0;return Da=0,a}function ds(){var a={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return jn===null?cn.memoizedState=jn=a:jn=jn.next=a,jn}function Rr(){if(Cn===null){var a=cn.alternate;a=a!==null?a.memoizedState:null}else a=Cn.next;var u=jn===null?cn.memoizedState:jn.next;if(u!==null)jn=u,Cn=a;else{if(a===null)throw Error(n(310));Cn=a,a={memoizedState:Cn.memoizedState,baseState:Cn.baseState,baseQueue:Cn.baseQueue,queue:Cn.queue,next:null},jn===null?cn.memoizedState=jn=a:jn=jn.next=a}return jn}function Pa(a,u){return typeof u=="function"?u(a):u}function sh(a){var u=Rr(),p=u.queue;if(p===null)throw Error(n(311));p.lastRenderedReducer=a;var y=Cn,S=y.baseQueue,N=p.pending;if(N!==null){if(S!==null){var R=S.next;S.next=N.next,N.next=R}y.baseQueue=S=N,p.pending=null}if(S!==null){N=S.next,y=y.baseState;var H=R=null,Y=null,ue=N;do{var _e=ue.lane;if((Fi&_e)===_e)Y!==null&&(Y=Y.next={lane:0,action:ue.action,hasEagerState:ue.hasEagerState,eagerState:ue.eagerState,next:null}),y=ue.hasEagerState?ue.eagerState:a(y,ue.action);else{var Ae={lane:_e,action:ue.action,hasEagerState:ue.hasEagerState,eagerState:ue.eagerState,next:null};Y===null?(H=Y=Ae,R=y):Y=Y.next=Ae,cn.lanes|=_e,Ui|=_e}ue=ue.next}while(ue!==null&&ue!==N);Y===null?R=y:Y.next=H,Vr(y,u.memoizedState)||(dr=!0),u.memoizedState=y,u.baseState=R,u.baseQueue=Y,p.lastRenderedState=y}if(a=p.interleaved,a!==null){S=a;do N=S.lane,cn.lanes|=N,Ui|=N,S=S.next;while(S!==a)}else S===null&&(p.lanes=0);return[u.memoizedState,p.dispatch]}function ih(a){var u=Rr(),p=u.queue;if(p===null)throw Error(n(311));p.lastRenderedReducer=a;var y=p.dispatch,S=p.pending,N=u.memoizedState;if(S!==null){p.pending=null;var R=S=S.next;do N=a(N,R.action),R=R.next;while(R!==S);Vr(N,u.memoizedState)||(dr=!0),u.memoizedState=N,u.baseQueue===null&&(u.baseState=N),p.lastRenderedState=N}return[N,y]}function Cb(){}function _b(a,u){var p=cn,y=Rr(),S=u(),N=!Vr(y.memoizedState,S);if(N&&(y.memoizedState=S,dr=!0),y=y.queue,oh(Mb.bind(null,p,y,a),[a]),y.getSnapshot!==u||N||jn!==null&&jn.memoizedState.tag&1){if(p.flags|=2048,Ba(9,jb.bind(null,p,y,S,u),void 0,null),Mn===null)throw Error(n(349));(Fi&30)!==0||Tb(p,u,S)}return S}function Tb(a,u,p){a.flags|=16384,a={getSnapshot:u,value:p},u=cn.updateQueue,u===null?(u={lastEffect:null,stores:null},cn.updateQueue=u,u.stores=[a]):(p=u.stores,p===null?u.stores=[a]:p.push(a))}function jb(a,u,p,y){u.value=p,u.getSnapshot=y,Ab(u)&&Rb(a)}function Mb(a,u,p){return p(function(){Ab(u)&&Rb(a)})}function Ab(a){var u=a.getSnapshot;a=a.value;try{var p=u();return!Vr(a,p)}catch{return!0}}function Rb(a){var u=Es(a,1);u!==null&&Xr(u,a,1,-1)}function Ob(a){var u=ds();return typeof a=="function"&&(a=a()),u.memoizedState=u.baseState=a,a={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Pa,lastRenderedState:a},u.queue=a,a=a.dispatch=Tj.bind(null,cn,a),[u.memoizedState,a]}function Ba(a,u,p,y){return a={tag:a,create:u,destroy:p,deps:y,next:null},u=cn.updateQueue,u===null?(u={lastEffect:null,stores:null},cn.updateQueue=u,u.lastEffect=a.next=a):(p=u.lastEffect,p===null?u.lastEffect=a.next=a:(y=p.next,p.next=a,a.next=y,u.lastEffect=a)),a}function Ib(){return Rr().memoizedState}function bc(a,u,p,y){var S=ds();cn.flags|=a,S.memoizedState=Ba(1|u,p,void 0,y===void 0?null:y)}function xc(a,u,p,y){var S=Rr();y=y===void 0?null:y;var N=void 0;if(Cn!==null){var R=Cn.memoizedState;if(N=R.destroy,y!==null&&th(y,R.deps)){S.memoizedState=Ba(u,p,N,y);return}}cn.flags|=a,S.memoizedState=Ba(1|u,p,N,y)}function Lb(a,u){return bc(8390656,8,a,u)}function oh(a,u){return xc(2048,8,a,u)}function Db(a,u){return xc(4,2,a,u)}function Pb(a,u){return xc(4,4,a,u)}function Bb(a,u){if(typeof u=="function")return a=a(),u(a),function(){u(null)};if(u!=null)return a=a(),u.current=a,function(){u.current=null}}function $b(a,u,p){return p=p!=null?p.concat([a]):null,xc(4,4,Bb.bind(null,u,a),p)}function ah(){}function zb(a,u){var p=Rr();u=u===void 0?null:u;var y=p.memoizedState;return y!==null&&u!==null&&th(u,y[1])?y[0]:(p.memoizedState=[a,u],a)}function Fb(a,u){var p=Rr();u=u===void 0?null:u;var y=p.memoizedState;return y!==null&&u!==null&&th(u,y[1])?y[0]:(a=a(),p.memoizedState=[a,u],a)}function Ub(a,u,p){return(Fi&21)===0?(a.baseState&&(a.baseState=!1,dr=!0),a.memoizedState=p):(Vr(p,u)||(p=Ul(),cn.lanes|=p,Ui|=p,a.baseState=!0),u)}function Cj(a,u){var p=Bt;Bt=p!==0&&4>p?p:4,a(!0);var y=eh.transition;eh.transition={};try{a(!1),u()}finally{Bt=p,eh.transition=y}}function Hb(){return Rr().memoizedState}function _j(a,u,p){var y=ni(a);if(p={lane:y,action:p,hasEagerState:!1,eagerState:null,next:null},Wb(a))qb(u,p);else if(p=wb(a,u,p,y),p!==null){var S=ir();Xr(p,a,y,S),Vb(p,u,y)}}function Tj(a,u,p){var y=ni(a),S={lane:y,action:p,hasEagerState:!1,eagerState:null,next:null};if(Wb(a))qb(u,S);else{var N=a.alternate;if(a.lanes===0&&(N===null||N.lanes===0)&&(N=u.lastRenderedReducer,N!==null))try{var R=u.lastRenderedState,H=N(R,p);if(S.hasEagerState=!0,S.eagerState=H,Vr(H,R)){var Y=u.interleaved;Y===null?(S.next=S,Gf(u)):(S.next=Y.next,Y.next=S),u.interleaved=S;return}}catch{}finally{}p=wb(a,u,S,y),p!==null&&(S=ir(),Xr(p,a,y,S),Vb(p,u,y))}}function Wb(a){var u=a.alternate;return a===cn||u!==null&&u===cn}function qb(a,u){La=yc=!0;var p=a.pending;p===null?u.next=u:(u.next=p.next,p.next=u),a.pending=u}function Vb(a,u,p){if((p&4194240)!==0){var y=u.lanes;y&=a.pendingLanes,p|=y,u.lanes=p,pa(a,p)}}var wc={readContext:Ar,useCallback:Gn,useContext:Gn,useEffect:Gn,useImperativeHandle:Gn,useInsertionEffect:Gn,useLayoutEffect:Gn,useMemo:Gn,useReducer:Gn,useRef:Gn,useState:Gn,useDebugValue:Gn,useDeferredValue:Gn,useTransition:Gn,useMutableSource:Gn,useSyncExternalStore:Gn,useId:Gn,unstable_isNewReconciler:!1},jj={readContext:Ar,useCallback:function(a,u){return ds().memoizedState=[a,u===void 0?null:u],a},useContext:Ar,useEffect:Lb,useImperativeHandle:function(a,u,p){return p=p!=null?p.concat([a]):null,bc(4194308,4,Bb.bind(null,u,a),p)},useLayoutEffect:function(a,u){return bc(4194308,4,a,u)},useInsertionEffect:function(a,u){return bc(4,2,a,u)},useMemo:function(a,u){var p=ds();return u=u===void 0?null:u,a=a(),p.memoizedState=[a,u],a},useReducer:function(a,u,p){var y=ds();return u=p!==void 0?p(u):u,y.memoizedState=y.baseState=u,a={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:a,lastRenderedState:u},y.queue=a,a=a.dispatch=_j.bind(null,cn,a),[y.memoizedState,a]},useRef:function(a){var u=ds();return a={current:a},u.memoizedState=a},useState:Ob,useDebugValue:ah,useDeferredValue:function(a){return ds().memoizedState=a},useTransition:function(){var a=Ob(!1),u=a[0];return a=Cj.bind(null,a[1]),ds().memoizedState=a,[u,a]},useMutableSource:function(){},useSyncExternalStore:function(a,u,p){var y=cn,S=ds();if(sn){if(p===void 0)throw Error(n(407));p=p()}else{if(p=u(),Mn===null)throw Error(n(349));(Fi&30)!==0||Tb(y,u,p)}S.memoizedState=p;var N={value:p,getSnapshot:u};return S.queue=N,Lb(Mb.bind(null,y,N,a),[a]),y.flags|=2048,Ba(9,jb.bind(null,y,N,p,u),void 0,null),p},useId:function(){var a=ds(),u=Mn.identifierPrefix;if(sn){var p=Ss,y=ks;p=(y&~(1<<32-an(y)-1)).toString(32)+p,u=":"+u+"R"+p,p=Da++,0<p&&(u+="H"+p.toString(32)),u+=":"}else p=Nj++,u=":"+u+"r"+p.toString(32)+":";return a.memoizedState=u},unstable_isNewReconciler:!1},Mj={readContext:Ar,useCallback:zb,useContext:Ar,useEffect:oh,useImperativeHandle:$b,useInsertionEffect:Db,useLayoutEffect:Pb,useMemo:Fb,useReducer:sh,useRef:Ib,useState:function(){return sh(Pa)},useDebugValue:ah,useDeferredValue:function(a){var u=Rr();return Ub(u,Cn.memoizedState,a)},useTransition:function(){var a=sh(Pa)[0],u=Rr().memoizedState;return[a,u]},useMutableSource:Cb,useSyncExternalStore:_b,useId:Hb,unstable_isNewReconciler:!1},Aj={readContext:Ar,useCallback:zb,useContext:Ar,useEffect:oh,useImperativeHandle:$b,useInsertionEffect:Db,useLayoutEffect:Pb,useMemo:Fb,useReducer:ih,useRef:Ib,useState:function(){return ih(Pa)},useDebugValue:ah,useDeferredValue:function(a){var u=Rr();return Cn===null?u.memoizedState=a:Ub(u,Cn.memoizedState,a)},useTransition:function(){var a=ih(Pa)[0],u=Rr().memoizedState;return[a,u]},useMutableSource:Cb,useSyncExternalStore:_b,useId:Hb,unstable_isNewReconciler:!1};function Gr(a,u){if(a&&a.defaultProps){u=K({},u),a=a.defaultProps;for(var p in a)u[p]===void 0&&(u[p]=a[p]);return u}return u}function lh(a,u,p,y){u=a.memoizedState,p=p(y,u),p=p==null?u:K({},u,p),a.memoizedState=p,a.lanes===0&&(a.updateQueue.baseState=p)}var kc={isMounted:function(a){return(a=a._reactInternals)?un(a)===a:!1},enqueueSetState:function(a,u,p){a=a._reactInternals;var y=ir(),S=ni(a),N=Ns(y,S);N.payload=u,p!=null&&(N.callback=p),u=Qs(a,N,S),u!==null&&(Xr(u,a,S,y),pc(u,a,S))},enqueueReplaceState:function(a,u,p){a=a._reactInternals;var y=ir(),S=ni(a),N=Ns(y,S);N.tag=1,N.payload=u,p!=null&&(N.callback=p),u=Qs(a,N,S),u!==null&&(Xr(u,a,S,y),pc(u,a,S))},enqueueForceUpdate:function(a,u){a=a._reactInternals;var p=ir(),y=ni(a),S=Ns(p,y);S.tag=2,u!=null&&(S.callback=u),u=Qs(a,S,y),u!==null&&(Xr(u,a,y,p),pc(u,a,y))}};function Kb(a,u,p,y,S,N,R){return a=a.stateNode,typeof a.shouldComponentUpdate=="function"?a.shouldComponentUpdate(y,N,R):u.prototype&&u.prototype.isPureReactComponent?!Ea(p,y)||!Ea(S,N):!0}function Gb(a,u,p){var y=!1,S=Js,N=u.contextType;return typeof N=="object"&&N!==null?N=Ar(N):(S=ur(u)?Di:Kn.current,y=u.contextTypes,N=(y=y!=null)?To(a,S):Js),u=new u(p,N),a.memoizedState=u.state!==null&&u.state!==void 0?u.state:null,u.updater=kc,a.stateNode=u,u._reactInternals=a,y&&(a=a.stateNode,a.__reactInternalMemoizedUnmaskedChildContext=S,a.__reactInternalMemoizedMaskedChildContext=N),u}function Jb(a,u,p,y){a=u.state,typeof u.componentWillReceiveProps=="function"&&u.componentWillReceiveProps(p,y),typeof u.UNSAFE_componentWillReceiveProps=="function"&&u.UNSAFE_componentWillReceiveProps(p,y),u.state!==a&&kc.enqueueReplaceState(u,u.state,null)}function ch(a,u,p,y){var S=a.stateNode;S.props=p,S.state=a.memoizedState,S.refs={},Jf(a);var N=u.contextType;typeof N=="object"&&N!==null?S.context=Ar(N):(N=ur(u)?Di:Kn.current,S.context=To(a,N)),S.state=a.memoizedState,N=u.getDerivedStateFromProps,typeof N=="function"&&(lh(a,u,N,p),S.state=a.memoizedState),typeof u.getDerivedStateFromProps=="function"||typeof S.getSnapshotBeforeUpdate=="function"||typeof S.UNSAFE_componentWillMount!="function"&&typeof S.componentWillMount!="function"||(u=S.state,typeof S.componentWillMount=="function"&&S.componentWillMount(),typeof S.UNSAFE_componentWillMount=="function"&&S.UNSAFE_componentWillMount(),u!==S.state&&kc.enqueueReplaceState(S,S.state,null),mc(a,p,S,y),S.state=a.memoizedState),typeof S.componentDidMount=="function"&&(a.flags|=4194308)}function Do(a,u){try{var p="",y=u;do p+=ge(y),y=y.return;while(y);var S=p}catch(N){S=`
37
+ `+S[R].replace(" at new "," at ");return a.displayName&&Y.includes("<anonymous>")&&(Y=Y.replace("<anonymous>",a.displayName)),Y}while(1<=R&&0<=H);break}}}finally{ee=!1,Error.prepareStackTrace=p}return(a=a?a.displayName||a.name:"")?L(a):""}function ge(a){switch(a.tag){case 5:return L(a.type);case 16:return L("Lazy");case 13:return L("Suspense");case 19:return L("SuspenseList");case 0:case 2:case 15:return a=fe(a.type,!1),a;case 11:return a=fe(a.type.render,!1),a;case 1:return a=fe(a.type,!0),a;default:return""}}function oe(a){if(a==null)return null;if(typeof a=="function")return a.displayName||a.name||null;if(typeof a=="string")return a;switch(a){case O:return"Fragment";case A:return"Portal";case $:return"Profiler";case B:return"StrictMode";case G:return"Suspense";case D:return"SuspenseList"}if(typeof a=="object")switch(a.$$typeof){case J:return(a.displayName||"Context")+".Consumer";case W:return(a._context.displayName||"Context")+".Provider";case z:var u=a.render;return a=a.displayName,a||(a=u.displayName||u.name||"",a=a!==""?"ForwardRef("+a+")":"ForwardRef"),a;case U:return u=a.displayName||null,u!==null?u:oe(a.type)||"Memo";case q:u=a._payload,a=a._init;try{return oe(a(u))}catch{}}return null}function xe(a){var u=a.type;switch(a.tag){case 24:return"Cache";case 9:return(u.displayName||"Context")+".Consumer";case 10:return(u._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return a=u.render,a=a.displayName||a.name||"",u.displayName||(a!==""?"ForwardRef("+a+")":"ForwardRef");case 7:return"Fragment";case 5:return u;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return oe(u);case 8:return u===B?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof u=="function")return u.displayName||u.name||null;if(typeof u=="string")return u}return null}function we(a){switch(typeof a){case"boolean":case"number":case"string":case"undefined":return a;case"object":return a;default:return""}}function We(a){var u=a.type;return(a=a.nodeName)&&a.toLowerCase()==="input"&&(u==="checkbox"||u==="radio")}function He(a){var u=We(a)?"checked":"value",p=Object.getOwnPropertyDescriptor(a.constructor.prototype,u),y=""+a[u];if(!a.hasOwnProperty(u)&&typeof p<"u"&&typeof p.get=="function"&&typeof p.set=="function"){var S=p.get,N=p.set;return Object.defineProperty(a,u,{configurable:!0,get:function(){return S.call(this)},set:function(R){y=""+R,N.call(this,R)}}),Object.defineProperty(a,u,{enumerable:p.enumerable}),{getValue:function(){return y},setValue:function(R){y=""+R},stopTracking:function(){a._valueTracker=null,delete a[u]}}}}function Ze(a){a._valueTracker||(a._valueTracker=He(a))}function Oe(a){if(!a)return!1;var u=a._valueTracker;if(!u)return!0;var p=u.getValue(),y="";return a&&(y=We(a)?a.checked?"true":"false":a.value),a=y,a!==p?(u.setValue(a),!0):!1}function Ke(a){if(a=a||(typeof document<"u"?document:void 0),typeof a>"u")return null;try{return a.activeElement||a.body}catch{return a.body}}function pt(a,u){var p=u.checked;return K({},u,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:p??a._wrapperState.initialChecked})}function Je(a,u){var p=u.defaultValue==null?"":u.defaultValue,y=u.checked!=null?u.checked:u.defaultChecked;p=we(u.value!=null?u.value:p),a._wrapperState={initialChecked:y,initialValue:p,controlled:u.type==="checkbox"||u.type==="radio"?u.checked!=null:u.value!=null}}function pe(a,u){u=u.checked,u!=null&&T(a,"checked",u,!1)}function mt(a,u){pe(a,u);var p=we(u.value),y=u.type;if(p!=null)y==="number"?(p===0&&a.value===""||a.value!=p)&&(a.value=""+p):a.value!==""+p&&(a.value=""+p);else if(y==="submit"||y==="reset"){a.removeAttribute("value");return}u.hasOwnProperty("value")?at(a,u.type,p):u.hasOwnProperty("defaultValue")&&at(a,u.type,we(u.defaultValue)),u.checked==null&&u.defaultChecked!=null&&(a.defaultChecked=!!u.defaultChecked)}function ft(a,u,p){if(u.hasOwnProperty("value")||u.hasOwnProperty("defaultValue")){var y=u.type;if(!(y!=="submit"&&y!=="reset"||u.value!==void 0&&u.value!==null))return;u=""+a._wrapperState.initialValue,p||u===a.value||(a.value=u),a.defaultValue=u}p=a.name,p!==""&&(a.name=""),a.defaultChecked=!!a._wrapperState.initialChecked,p!==""&&(a.name=p)}function at(a,u,p){(u!=="number"||Ke(a.ownerDocument)!==a)&&(p==null?a.defaultValue=""+a._wrapperState.initialValue:a.defaultValue!==""+p&&(a.defaultValue=""+p))}var nt=Array.isArray;function ht(a,u,p,y){if(a=a.options,u){u={};for(var S=0;S<p.length;S++)u["$"+p[S]]=!0;for(p=0;p<a.length;p++)S=u.hasOwnProperty("$"+a[p].value),a[p].selected!==S&&(a[p].selected=S),S&&y&&(a[p].defaultSelected=!0)}else{for(p=""+we(p),u=null,S=0;S<a.length;S++){if(a[S].value===p){a[S].selected=!0,y&&(a[S].defaultSelected=!0);return}u!==null||a[S].disabled||(u=a[S])}u!==null&&(u.selected=!0)}}function Fe(a,u){if(u.dangerouslySetInnerHTML!=null)throw Error(n(91));return K({},u,{value:void 0,defaultValue:void 0,children:""+a._wrapperState.initialValue})}function ve(a,u){var p=u.value;if(p==null){if(p=u.children,u=u.defaultValue,p!=null){if(u!=null)throw Error(n(92));if(nt(p)){if(1<p.length)throw Error(n(93));p=p[0]}u=p}u==null&&(u=""),p=u}a._wrapperState={initialValue:we(p)}}function X(a,u){var p=we(u.value),y=we(u.defaultValue);p!=null&&(p=""+p,p!==a.value&&(a.value=p),u.defaultValue==null&&a.defaultValue!==p&&(a.defaultValue=p)),y!=null&&(a.defaultValue=""+y)}function Be(a){var u=a.textContent;u===a._wrapperState.initialValue&&u!==""&&u!==null&&(a.value=u)}function ne(a){switch(a){case"svg":return"http://www.w3.org/2000/svg";case"math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function de(a,u){return a==null||a==="http://www.w3.org/1999/xhtml"?ne(u):a==="http://www.w3.org/2000/svg"&&u==="foreignObject"?"http://www.w3.org/1999/xhtml":a}var he,Ge=(function(a){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(u,p,y,S){MSApp.execUnsafeLocalFunction(function(){return a(u,p,y,S)})}:a})(function(a,u){if(a.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in a)a.innerHTML=u;else{for(he=he||document.createElement("div"),he.innerHTML="<svg>"+u.valueOf().toString()+"</svg>",u=he.firstChild;a.firstChild;)a.removeChild(a.firstChild);for(;u.firstChild;)a.appendChild(u.firstChild)}});function Pe(a,u){if(u){var p=a.firstChild;if(p&&p===a.lastChild&&p.nodeType===3){p.nodeValue=u;return}}a.textContent=u}var et={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},ot=["Webkit","ms","Moz","O"];Object.keys(et).forEach(function(a){ot.forEach(function(u){u=u+a.charAt(0).toUpperCase()+a.substring(1),et[u]=et[a]})});function bt(a,u,p){return u==null||typeof u=="boolean"||u===""?"":p||typeof u!="number"||u===0||et.hasOwnProperty(a)&&et[a]?(""+u).trim():u+"px"}function Ye(a,u){a=a.style;for(var p in u)if(u.hasOwnProperty(p)){var y=p.indexOf("--")===0,S=bt(p,u[p],y);p==="float"&&(p="cssFloat"),y?a.setProperty(p,S):a[p]=S}}var it=K({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function gt(a,u){if(u){if(it[a]&&(u.children!=null||u.dangerouslySetInnerHTML!=null))throw Error(n(137,a));if(u.dangerouslySetInnerHTML!=null){if(u.children!=null)throw Error(n(60));if(typeof u.dangerouslySetInnerHTML!="object"||!("__html"in u.dangerouslySetInnerHTML))throw Error(n(61))}if(u.style!=null&&typeof u.style!="object")throw Error(n(62))}}function Nt(a,u){if(a.indexOf("-")===-1)return typeof u.is=="string";switch(a){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Ie=null;function Me(a){return a=a.target||a.srcElement||window,a.correspondingUseElement&&(a=a.correspondingUseElement),a.nodeType===3?a.parentNode:a}var qe=null,F=null,ce=null;function Ne(a){if(a=Ma(a)){if(typeof qe!="function")throw Error(n(280));var u=a.stateNode;u&&(u=sc(u),qe(a.stateNode,a.type,u))}}function P(a){F?ce?ce.push(a):ce=[a]:F=a}function Z(){if(F){var a=F,u=ce;if(ce=F=null,Ne(a),u)for(a=0;a<u.length;a++)Ne(u[a])}}function I(a,u){return a(u)}function re(){}var ye=!1;function Te(a,u,p){if(ye)return a(u,p);ye=!0;try{return I(a,u,p)}finally{ye=!1,(F!==null||ce!==null)&&(re(),Z())}}function Se(a,u){var p=a.stateNode;if(p===null)return null;var y=sc(p);if(y===null)return null;p=y[u];e:switch(u){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(y=!y.disabled)||(a=a.type,y=!(a==="button"||a==="input"||a==="select"||a==="textarea")),a=!y;break e;default:a=!1}if(a)return null;if(p&&typeof p!="function")throw Error(n(231,u,typeof p));return p}var Ee=!1;if(l)try{var me={};Object.defineProperty(me,"passive",{get:function(){Ee=!0}}),window.addEventListener("test",me,me),window.removeEventListener("test",me,me)}catch{Ee=!1}function ke(a,u,p,y,S,N,R,H,Y){var ue=Array.prototype.slice.call(arguments,3);try{u.apply(p,ue)}catch(_e){this.onError(_e)}}var Ct=!1,en=null,on=!1,Wt=null,Ft={onError:function(a){Ct=!0,en=a}};function xt(a,u,p,y,S,N,R,H,Y){Ct=!1,en=null,ke.apply(Ft,arguments)}function Pn(a,u,p,y,S,N,R,H,Y){if(xt.apply(this,arguments),Ct){if(Ct){var ue=en;Ct=!1,en=null}else throw Error(n(198));on||(on=!0,Wt=ue)}}function un(a){var u=a,p=a;if(a.alternate)for(;u.return;)u=u.return;else{a=u;do u=a,(u.flags&4098)!==0&&(p=u.return),a=u.return;while(a)}return u.tag===3?p:null}function yr(a){if(a.tag===13){var u=a.memoizedState;if(u===null&&(a=a.alternate,a!==null&&(u=a.memoizedState)),u!==null)return u.dehydrated}return null}function _r(a){if(un(a)!==a)throw Error(n(188))}function Wr(a){var u=a.alternate;if(!u){if(u=un(a),u===null)throw Error(n(188));return u!==a?null:a}for(var p=a,y=u;;){var S=p.return;if(S===null)break;var N=S.alternate;if(N===null){if(y=S.return,y!==null){p=y;continue}break}if(S.child===N.child){for(N=S.child;N;){if(N===p)return _r(S),a;if(N===y)return _r(S),u;N=N.sibling}throw Error(n(188))}if(p.return!==y.return)p=S,y=N;else{for(var R=!1,H=S.child;H;){if(H===p){R=!0,p=S,y=N;break}if(H===y){R=!0,y=S,p=N;break}H=H.sibling}if(!R){for(H=N.child;H;){if(H===p){R=!0,p=N,y=S;break}if(H===y){R=!0,y=N,p=S;break}H=H.sibling}if(!R)throw Error(n(189))}}if(p.alternate!==y)throw Error(n(190))}if(p.tag!==3)throw Error(n(188));return p.stateNode.current===p?a:u}function is(a){return a=Wr(a),a!==null?ie(a):null}function ie(a){if(a.tag===5||a.tag===6)return a;for(a=a.child;a!==null;){var u=ie(a);if(u!==null)return u;a=a.sibling}return null}var je=e.unstable_scheduleCallback,ze=e.unstable_cancelCallback,_t=e.unstable_shouldYield,Rt=e.unstable_requestPaint,It=e.unstable_now,tr=e.unstable_getCurrentPriorityLevel,qr=e.unstable_ImmediatePriority,Kt=e.unstable_UserBlockingPriority,Vn=e.unstable_NormalPriority,Le=e.unstable_LowPriority,lt=e.unstable_IdlePriority,Tt=null,Ot=null;function yn(a){if(Ot&&typeof Ot.onCommitFiberRoot=="function")try{Ot.onCommitFiberRoot(Tt,a,void 0,(a.current.flags&128)===128)}catch{}}var an=Math.clz32?Math.clz32:nr,as=Math.log,yo=Math.LN2;function nr(a){return a>>>=0,a===0?32:31-(as(a)/yo|0)|0}var rr=64,Ai=4194304;function Fs(a){switch(a&-a){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return a&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return a&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return a}}function Ri(a,u){var p=a.pendingLanes;if(p===0)return 0;var y=0,S=a.suspendedLanes,N=a.pingedLanes,R=p&268435455;if(R!==0){var H=R&~S;H!==0?y=Fs(H):(N&=R,N!==0&&(y=Fs(N)))}else R=p&~S,R!==0?y=Fs(R):N!==0&&(y=Fs(N));if(y===0)return 0;if(u!==0&&u!==y&&(u&S)===0&&(S=y&-y,N=u&-u,S>=N||S===16&&(N&4194240)!==0))return u;if((y&4)!==0&&(y|=p&16),u=a.entangledLanes,u!==0)for(a=a.entanglements,u&=y;0<u;)p=31-an(u),S=1<<p,y|=a[p],u&=~S;return y}function cf(a,u){switch(a){case 1:case 2:case 4:return u+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return u+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function uf(a,u){for(var p=a.suspendedLanes,y=a.pingedLanes,S=a.expirationTimes,N=a.pendingLanes;0<N;){var R=31-an(N),H=1<<R,Y=S[R];Y===-1?((H&p)===0||(H&y)!==0)&&(S[R]=cf(H,u)):Y<=u&&(a.expiredLanes|=H),N&=~H}}function ha(a){return a=a.pendingLanes&-1073741825,a!==0?a:a&1073741824?1073741824:0}function Ul(){var a=rr;return rr<<=1,(rr&4194240)===0&&(rr=64),a}function Us(a){for(var u=[],p=0;31>p;p++)u.push(a);return u}function Hs(a,u,p){a.pendingLanes|=u,u!==536870912&&(a.suspendedLanes=0,a.pingedLanes=0),a=a.eventTimes,u=31-an(u),a[u]=p}function Tr(a,u){var p=a.pendingLanes&~u;a.pendingLanes=u,a.suspendedLanes=0,a.pingedLanes=0,a.expiredLanes&=u,a.mutableReadLanes&=u,a.entangledLanes&=u,u=a.entanglements;var y=a.eventTimes;for(a=a.expirationTimes;0<p;){var S=31-an(p),N=1<<S;u[S]=0,y[S]=-1,a[S]=-1,p&=~N}}function pa(a,u){var p=a.entangledLanes|=u;for(a=a.entanglements;p;){var y=31-an(p),S=1<<y;S&u|a[y]&u&&(a[y]|=u),p&=~S}}var Bt=0;function Et(a){return a&=-a,1<a?4<a?(a&268435455)!==0?16:536870912:4:1}var ma,bn,Gt,Oi,ls,Ii=!1,Ws=[],$e=null,Xe=null,kt=null,Lt=new Map,dn=new Map,Tn=[],df="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset submit".split(" ");function Hl(a,u){switch(a){case"focusin":case"focusout":$e=null;break;case"dragenter":case"dragleave":Xe=null;break;case"mouseover":case"mouseout":kt=null;break;case"pointerover":case"pointerout":Lt.delete(u.pointerId);break;case"gotpointercapture":case"lostpointercapture":dn.delete(u.pointerId)}}function ga(a,u,p,y,S,N){return a===null||a.nativeEvent!==N?(a={blockedOn:u,domEventName:p,eventSystemFlags:y,nativeEvent:N,targetContainers:[S]},u!==null&&(u=Ma(u),u!==null&&bn(u)),a):(a.eventSystemFlags|=y,u=a.targetContainers,S!==null&&u.indexOf(S)===-1&&u.push(S),a)}function _T(a,u,p,y,S){switch(u){case"focusin":return $e=ga($e,a,u,p,y,S),!0;case"dragenter":return Xe=ga(Xe,a,u,p,y,S),!0;case"mouseover":return kt=ga(kt,a,u,p,y,S),!0;case"pointerover":var N=S.pointerId;return Lt.set(N,ga(Lt.get(N)||null,a,u,p,y,S)),!0;case"gotpointercapture":return N=S.pointerId,dn.set(N,ga(dn.get(N)||null,a,u,p,y,S)),!0}return!1}function Ny(a){var u=Li(a.target);if(u!==null){var p=un(u);if(p!==null){if(u=p.tag,u===13){if(u=yr(p),u!==null){a.blockedOn=u,ls(a.priority,function(){Gt(p)});return}}else if(u===3&&p.stateNode.current.memoizedState.isDehydrated){a.blockedOn=p.tag===3?p.stateNode.containerInfo:null;return}}}a.blockedOn=null}function Wl(a){if(a.blockedOn!==null)return!1;for(var u=a.targetContainers;0<u.length;){var p=hf(a.domEventName,a.eventSystemFlags,u[0],a.nativeEvent);if(p===null){p=a.nativeEvent;var y=new p.constructor(p.type,p);Ie=y,p.target.dispatchEvent(y),Ie=null}else return u=Ma(p),u!==null&&bn(u),a.blockedOn=p,!1;u.shift()}return!0}function Cy(a,u,p){Wl(a)&&p.delete(u)}function TT(){Ii=!1,$e!==null&&Wl($e)&&($e=null),Xe!==null&&Wl(Xe)&&(Xe=null),kt!==null&&Wl(kt)&&(kt=null),Lt.forEach(Cy),dn.forEach(Cy)}function va(a,u){a.blockedOn===u&&(a.blockedOn=null,Ii||(Ii=!0,e.unstable_scheduleCallback(e.unstable_NormalPriority,TT)))}function ya(a){function u(S){return va(S,a)}if(0<Ws.length){va(Ws[0],a);for(var p=1;p<Ws.length;p++){var y=Ws[p];y.blockedOn===a&&(y.blockedOn=null)}}for($e!==null&&va($e,a),Xe!==null&&va(Xe,a),kt!==null&&va(kt,a),Lt.forEach(u),dn.forEach(u),p=0;p<Tn.length;p++)y=Tn[p],y.blockedOn===a&&(y.blockedOn=null);for(;0<Tn.length&&(p=Tn[0],p.blockedOn===null);)Ny(p),p.blockedOn===null&&Tn.shift()}var bo=j.ReactCurrentBatchConfig,ql=!0;function jT(a,u,p,y){var S=Bt,N=bo.transition;bo.transition=null;try{Bt=1,ff(a,u,p,y)}finally{Bt=S,bo.transition=N}}function MT(a,u,p,y){var S=Bt,N=bo.transition;bo.transition=null;try{Bt=4,ff(a,u,p,y)}finally{Bt=S,bo.transition=N}}function ff(a,u,p,y){if(ql){var S=hf(a,u,p,y);if(S===null)Mf(a,u,y,Vl,p),Hl(a,y);else if(_T(S,a,u,p,y))y.stopPropagation();else if(Hl(a,y),u&4&&-1<df.indexOf(a)){for(;S!==null;){var N=Ma(S);if(N!==null&&ma(N),N=hf(a,u,p,y),N===null&&Mf(a,u,y,Vl,p),N===S)break;S=N}S!==null&&y.stopPropagation()}else Mf(a,u,y,null,p)}}var Vl=null;function hf(a,u,p,y){if(Vl=null,a=Me(y),a=Li(a),a!==null)if(u=un(a),u===null)a=null;else if(p=u.tag,p===13){if(a=yr(u),a!==null)return a;a=null}else if(p===3){if(u.stateNode.current.memoizedState.isDehydrated)return u.tag===3?u.stateNode.containerInfo:null;a=null}else u!==a&&(a=null);return Vl=a,null}function _y(a){switch(a){case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 1;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"toggle":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 4;case"message":switch(tr()){case qr:return 1;case Kt:return 4;case Vn:case Le:return 16;case lt:return 536870912;default:return 16}default:return 16}}var qs=null,pf=null,Kl=null;function Ty(){if(Kl)return Kl;var a,u=pf,p=u.length,y,S="value"in qs?qs.value:qs.textContent,N=S.length;for(a=0;a<p&&u[a]===S[a];a++);var R=p-a;for(y=1;y<=R&&u[p-y]===S[N-y];y++);return Kl=S.slice(a,1<y?1-y:void 0)}function Gl(a){var u=a.keyCode;return"charCode"in a?(a=a.charCode,a===0&&u===13&&(a=13)):a=u,a===10&&(a=13),32<=a||a===13?a:0}function Jl(){return!0}function jy(){return!1}function br(a){function u(p,y,S,N,R){this._reactName=p,this._targetInst=S,this.type=y,this.nativeEvent=N,this.target=R,this.currentTarget=null;for(var H in a)a.hasOwnProperty(H)&&(p=a[H],this[H]=p?p(N):N[H]);return this.isDefaultPrevented=(N.defaultPrevented!=null?N.defaultPrevented:N.returnValue===!1)?Jl:jy,this.isPropagationStopped=jy,this}return K(u.prototype,{preventDefault:function(){this.defaultPrevented=!0;var p=this.nativeEvent;p&&(p.preventDefault?p.preventDefault():typeof p.returnValue!="unknown"&&(p.returnValue=!1),this.isDefaultPrevented=Jl)},stopPropagation:function(){var p=this.nativeEvent;p&&(p.stopPropagation?p.stopPropagation():typeof p.cancelBubble!="unknown"&&(p.cancelBubble=!0),this.isPropagationStopped=Jl)},persist:function(){},isPersistent:Jl}),u}var xo={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(a){return a.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},mf=br(xo),ba=K({},xo,{view:0,detail:0}),AT=br(ba),gf,vf,xa,Yl=K({},ba,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:bf,button:0,buttons:0,relatedTarget:function(a){return a.relatedTarget===void 0?a.fromElement===a.srcElement?a.toElement:a.fromElement:a.relatedTarget},movementX:function(a){return"movementX"in a?a.movementX:(a!==xa&&(xa&&a.type==="mousemove"?(gf=a.screenX-xa.screenX,vf=a.screenY-xa.screenY):vf=gf=0,xa=a),gf)},movementY:function(a){return"movementY"in a?a.movementY:vf}}),My=br(Yl),RT=K({},Yl,{dataTransfer:0}),OT=br(RT),IT=K({},ba,{relatedTarget:0}),yf=br(IT),LT=K({},xo,{animationName:0,elapsedTime:0,pseudoElement:0}),DT=br(LT),PT=K({},xo,{clipboardData:function(a){return"clipboardData"in a?a.clipboardData:window.clipboardData}}),BT=br(PT),$T=K({},xo,{data:0}),Ay=br($T),zT={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},FT={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},UT={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function HT(a){var u=this.nativeEvent;return u.getModifierState?u.getModifierState(a):(a=UT[a])?!!u[a]:!1}function bf(){return HT}var WT=K({},ba,{key:function(a){if(a.key){var u=zT[a.key]||a.key;if(u!=="Unidentified")return u}return a.type==="keypress"?(a=Gl(a),a===13?"Enter":String.fromCharCode(a)):a.type==="keydown"||a.type==="keyup"?FT[a.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:bf,charCode:function(a){return a.type==="keypress"?Gl(a):0},keyCode:function(a){return a.type==="keydown"||a.type==="keyup"?a.keyCode:0},which:function(a){return a.type==="keypress"?Gl(a):a.type==="keydown"||a.type==="keyup"?a.keyCode:0}}),qT=br(WT),VT=K({},Yl,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Ry=br(VT),KT=K({},ba,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:bf}),GT=br(KT),JT=K({},xo,{propertyName:0,elapsedTime:0,pseudoElement:0}),YT=br(JT),XT=K({},Yl,{deltaX:function(a){return"deltaX"in a?a.deltaX:"wheelDeltaX"in a?-a.wheelDeltaX:0},deltaY:function(a){return"deltaY"in a?a.deltaY:"wheelDeltaY"in a?-a.wheelDeltaY:"wheelDelta"in a?-a.wheelDelta:0},deltaZ:0,deltaMode:0}),QT=br(XT),ZT=[9,13,27,32],xf=l&&"CompositionEvent"in window,wa=null;l&&"documentMode"in document&&(wa=document.documentMode);var ej=l&&"TextEvent"in window&&!wa,Oy=l&&(!xf||wa&&8<wa&&11>=wa),Iy=" ",Ly=!1;function Dy(a,u){switch(a){case"keyup":return ZT.indexOf(u.keyCode)!==-1;case"keydown":return u.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Py(a){return a=a.detail,typeof a=="object"&&"data"in a?a.data:null}var wo=!1;function tj(a,u){switch(a){case"compositionend":return Py(u);case"keypress":return u.which!==32?null:(Ly=!0,Iy);case"textInput":return a=u.data,a===Iy&&Ly?null:a;default:return null}}function nj(a,u){if(wo)return a==="compositionend"||!xf&&Dy(a,u)?(a=Ty(),Kl=pf=qs=null,wo=!1,a):null;switch(a){case"paste":return null;case"keypress":if(!(u.ctrlKey||u.altKey||u.metaKey)||u.ctrlKey&&u.altKey){if(u.char&&1<u.char.length)return u.char;if(u.which)return String.fromCharCode(u.which)}return null;case"compositionend":return Oy&&u.locale!=="ko"?null:u.data;default:return null}}var rj={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function By(a){var u=a&&a.nodeName&&a.nodeName.toLowerCase();return u==="input"?!!rj[a.type]:u==="textarea"}function $y(a,u,p,y){P(y),u=tc(u,"onChange"),0<u.length&&(p=new mf("onChange","change",null,p,y),a.push({event:p,listeners:u}))}var ka=null,Sa=null;function sj(a){rb(a,0)}function Xl(a){var u=Co(a);if(Oe(u))return a}function ij(a,u){if(a==="change")return u}var zy=!1;if(l){var wf;if(l){var kf="oninput"in document;if(!kf){var Fy=document.createElement("div");Fy.setAttribute("oninput","return;"),kf=typeof Fy.oninput=="function"}wf=kf}else wf=!1;zy=wf&&(!document.documentMode||9<document.documentMode)}function Uy(){ka&&(ka.detachEvent("onpropertychange",Hy),Sa=ka=null)}function Hy(a){if(a.propertyName==="value"&&Xl(Sa)){var u=[];$y(u,Sa,a,Me(a)),Te(sj,u)}}function oj(a,u,p){a==="focusin"?(Uy(),ka=u,Sa=p,ka.attachEvent("onpropertychange",Hy)):a==="focusout"&&Uy()}function aj(a){if(a==="selectionchange"||a==="keyup"||a==="keydown")return Xl(Sa)}function lj(a,u){if(a==="click")return Xl(u)}function cj(a,u){if(a==="input"||a==="change")return Xl(u)}function uj(a,u){return a===u&&(a!==0||1/a===1/u)||a!==a&&u!==u}var Vr=typeof Object.is=="function"?Object.is:uj;function Ea(a,u){if(Vr(a,u))return!0;if(typeof a!="object"||a===null||typeof u!="object"||u===null)return!1;var p=Object.keys(a),y=Object.keys(u);if(p.length!==y.length)return!1;for(y=0;y<p.length;y++){var S=p[y];if(!d.call(u,S)||!Vr(a[S],u[S]))return!1}return!0}function Wy(a){for(;a&&a.firstChild;)a=a.firstChild;return a}function qy(a,u){var p=Wy(a);a=0;for(var y;p;){if(p.nodeType===3){if(y=a+p.textContent.length,a<=u&&y>=u)return{node:p,offset:u-a};a=y}e:{for(;p;){if(p.nextSibling){p=p.nextSibling;break e}p=p.parentNode}p=void 0}p=Wy(p)}}function Vy(a,u){return a&&u?a===u?!0:a&&a.nodeType===3?!1:u&&u.nodeType===3?Vy(a,u.parentNode):"contains"in a?a.contains(u):a.compareDocumentPosition?!!(a.compareDocumentPosition(u)&16):!1:!1}function Ky(){for(var a=window,u=Ke();u instanceof a.HTMLIFrameElement;){try{var p=typeof u.contentWindow.location.href=="string"}catch{p=!1}if(p)a=u.contentWindow;else break;u=Ke(a.document)}return u}function Sf(a){var u=a&&a.nodeName&&a.nodeName.toLowerCase();return u&&(u==="input"&&(a.type==="text"||a.type==="search"||a.type==="tel"||a.type==="url"||a.type==="password")||u==="textarea"||a.contentEditable==="true")}function dj(a){var u=Ky(),p=a.focusedElem,y=a.selectionRange;if(u!==p&&p&&p.ownerDocument&&Vy(p.ownerDocument.documentElement,p)){if(y!==null&&Sf(p)){if(u=y.start,a=y.end,a===void 0&&(a=u),"selectionStart"in p)p.selectionStart=u,p.selectionEnd=Math.min(a,p.value.length);else if(a=(u=p.ownerDocument||document)&&u.defaultView||window,a.getSelection){a=a.getSelection();var S=p.textContent.length,N=Math.min(y.start,S);y=y.end===void 0?N:Math.min(y.end,S),!a.extend&&N>y&&(S=y,y=N,N=S),S=qy(p,N);var R=qy(p,y);S&&R&&(a.rangeCount!==1||a.anchorNode!==S.node||a.anchorOffset!==S.offset||a.focusNode!==R.node||a.focusOffset!==R.offset)&&(u=u.createRange(),u.setStart(S.node,S.offset),a.removeAllRanges(),N>y?(a.addRange(u),a.extend(R.node,R.offset)):(u.setEnd(R.node,R.offset),a.addRange(u)))}}for(u=[],a=p;a=a.parentNode;)a.nodeType===1&&u.push({element:a,left:a.scrollLeft,top:a.scrollTop});for(typeof p.focus=="function"&&p.focus(),p=0;p<u.length;p++)a=u[p],a.element.scrollLeft=a.left,a.element.scrollTop=a.top}}var fj=l&&"documentMode"in document&&11>=document.documentMode,ko=null,Ef=null,Na=null,Nf=!1;function Gy(a,u,p){var y=p.window===p?p.document:p.nodeType===9?p:p.ownerDocument;Nf||ko==null||ko!==Ke(y)||(y=ko,"selectionStart"in y&&Sf(y)?y={start:y.selectionStart,end:y.selectionEnd}:(y=(y.ownerDocument&&y.ownerDocument.defaultView||window).getSelection(),y={anchorNode:y.anchorNode,anchorOffset:y.anchorOffset,focusNode:y.focusNode,focusOffset:y.focusOffset}),Na&&Ea(Na,y)||(Na=y,y=tc(Ef,"onSelect"),0<y.length&&(u=new mf("onSelect","select",null,u,p),a.push({event:u,listeners:y}),u.target=ko)))}function Ql(a,u){var p={};return p[a.toLowerCase()]=u.toLowerCase(),p["Webkit"+a]="webkit"+u,p["Moz"+a]="moz"+u,p}var So={animationend:Ql("Animation","AnimationEnd"),animationiteration:Ql("Animation","AnimationIteration"),animationstart:Ql("Animation","AnimationStart"),transitionend:Ql("Transition","TransitionEnd")},Cf={},Jy={};l&&(Jy=document.createElement("div").style,"AnimationEvent"in window||(delete So.animationend.animation,delete So.animationiteration.animation,delete So.animationstart.animation),"TransitionEvent"in window||delete So.transitionend.transition);function Zl(a){if(Cf[a])return Cf[a];if(!So[a])return a;var u=So[a],p;for(p in u)if(u.hasOwnProperty(p)&&p in Jy)return Cf[a]=u[p];return a}var Yy=Zl("animationend"),Xy=Zl("animationiteration"),Qy=Zl("animationstart"),Zy=Zl("transitionend"),eb=new Map,tb="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function Vs(a,u){eb.set(a,u),i(u,[a])}for(var _f=0;_f<tb.length;_f++){var Tf=tb[_f],hj=Tf.toLowerCase(),pj=Tf[0].toUpperCase()+Tf.slice(1);Vs(hj,"on"+pj)}Vs(Yy,"onAnimationEnd"),Vs(Xy,"onAnimationIteration"),Vs(Qy,"onAnimationStart"),Vs("dblclick","onDoubleClick"),Vs("focusin","onFocus"),Vs("focusout","onBlur"),Vs(Zy,"onTransitionEnd"),o("onMouseEnter",["mouseout","mouseover"]),o("onMouseLeave",["mouseout","mouseover"]),o("onPointerEnter",["pointerout","pointerover"]),o("onPointerLeave",["pointerout","pointerover"]),i("onChange","change click focusin focusout input keydown keyup selectionchange".split(" ")),i("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" ")),i("onBeforeInput",["compositionend","keypress","textInput","paste"]),i("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" ")),i("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" ")),i("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Ca="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),mj=new Set("cancel close invalid load scroll toggle".split(" ").concat(Ca));function nb(a,u,p){var y=a.type||"unknown-event";a.currentTarget=p,Pn(y,u,void 0,a),a.currentTarget=null}function rb(a,u){u=(u&4)!==0;for(var p=0;p<a.length;p++){var y=a[p],S=y.event;y=y.listeners;e:{var N=void 0;if(u)for(var R=y.length-1;0<=R;R--){var H=y[R],Y=H.instance,ue=H.currentTarget;if(H=H.listener,Y!==N&&S.isPropagationStopped())break e;nb(S,H,ue),N=Y}else for(R=0;R<y.length;R++){if(H=y[R],Y=H.instance,ue=H.currentTarget,H=H.listener,Y!==N&&S.isPropagationStopped())break e;nb(S,H,ue),N=Y}}}if(on)throw a=Wt,on=!1,Wt=null,a}function tn(a,u){var p=u[Df];p===void 0&&(p=u[Df]=new Set);var y=a+"__bubble";p.has(y)||(sb(u,a,2,!1),p.add(y))}function jf(a,u,p){var y=0;u&&(y|=4),sb(p,a,y,u)}var ec="_reactListening"+Math.random().toString(36).slice(2);function _a(a){if(!a[ec]){a[ec]=!0,r.forEach(function(p){p!=="selectionchange"&&(mj.has(p)||jf(p,!1,a),jf(p,!0,a))});var u=a.nodeType===9?a:a.ownerDocument;u===null||u[ec]||(u[ec]=!0,jf("selectionchange",!1,u))}}function sb(a,u,p,y){switch(_y(u)){case 1:var S=jT;break;case 4:S=MT;break;default:S=ff}p=S.bind(null,u,p,a),S=void 0,!Ee||u!=="touchstart"&&u!=="touchmove"&&u!=="wheel"||(S=!0),y?S!==void 0?a.addEventListener(u,p,{capture:!0,passive:S}):a.addEventListener(u,p,!0):S!==void 0?a.addEventListener(u,p,{passive:S}):a.addEventListener(u,p,!1)}function Mf(a,u,p,y,S){var N=y;if((u&1)===0&&(u&2)===0&&y!==null)e:for(;;){if(y===null)return;var R=y.tag;if(R===3||R===4){var H=y.stateNode.containerInfo;if(H===S||H.nodeType===8&&H.parentNode===S)break;if(R===4)for(R=y.return;R!==null;){var Y=R.tag;if((Y===3||Y===4)&&(Y=R.stateNode.containerInfo,Y===S||Y.nodeType===8&&Y.parentNode===S))return;R=R.return}for(;H!==null;){if(R=Li(H),R===null)return;if(Y=R.tag,Y===5||Y===6){y=N=R;continue e}H=H.parentNode}}y=y.return}Te(function(){var ue=N,_e=Me(p),Ae=[];e:{var Ce=eb.get(a);if(Ce!==void 0){var Ve=mf,tt=a;switch(a){case"keypress":if(Gl(p)===0)break e;case"keydown":case"keyup":Ve=qT;break;case"focusin":tt="focus",Ve=yf;break;case"focusout":tt="blur",Ve=yf;break;case"beforeblur":case"afterblur":Ve=yf;break;case"click":if(p.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":Ve=My;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":Ve=OT;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":Ve=GT;break;case Yy:case Xy:case Qy:Ve=DT;break;case Zy:Ve=YT;break;case"scroll":Ve=AT;break;case"wheel":Ve=QT;break;case"copy":case"cut":case"paste":Ve=BT;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":Ve=Ry}var rt=(u&4)!==0,xn=!rt&&a==="scroll",ae=rt?Ce!==null?Ce+"Capture":null:Ce;rt=[];for(var Q=ue,le;Q!==null;){le=Q;var De=le.stateNode;if(le.tag===5&&De!==null&&(le=De,ae!==null&&(De=Se(Q,ae),De!=null&&rt.push(Ta(Q,De,le)))),xn)break;Q=Q.return}0<rt.length&&(Ce=new Ve(Ce,tt,null,p,_e),Ae.push({event:Ce,listeners:rt}))}}if((u&7)===0){e:{if(Ce=a==="mouseover"||a==="pointerover",Ve=a==="mouseout"||a==="pointerout",Ce&&p!==Ie&&(tt=p.relatedTarget||p.fromElement)&&(Li(tt)||tt[xs]))break e;if((Ve||Ce)&&(Ce=_e.window===_e?_e:(Ce=_e.ownerDocument)?Ce.defaultView||Ce.parentWindow:window,Ve?(tt=p.relatedTarget||p.toElement,Ve=ue,tt=tt?Li(tt):null,tt!==null&&(xn=un(tt),tt!==xn||tt.tag!==5&&tt.tag!==6)&&(tt=null)):(Ve=null,tt=ue),Ve!==tt)){if(rt=My,De="onMouseLeave",ae="onMouseEnter",Q="mouse",(a==="pointerout"||a==="pointerover")&&(rt=Ry,De="onPointerLeave",ae="onPointerEnter",Q="pointer"),xn=Ve==null?Ce:Co(Ve),le=tt==null?Ce:Co(tt),Ce=new rt(De,Q+"leave",Ve,p,_e),Ce.target=xn,Ce.relatedTarget=le,De=null,Li(_e)===ue&&(rt=new rt(ae,Q+"enter",tt,p,_e),rt.target=le,rt.relatedTarget=xn,De=rt),xn=De,Ve&&tt)t:{for(rt=Ve,ae=tt,Q=0,le=rt;le;le=Eo(le))Q++;for(le=0,De=ae;De;De=Eo(De))le++;for(;0<Q-le;)rt=Eo(rt),Q--;for(;0<le-Q;)ae=Eo(ae),le--;for(;Q--;){if(rt===ae||ae!==null&&rt===ae.alternate)break t;rt=Eo(rt),ae=Eo(ae)}rt=null}else rt=null;Ve!==null&&ib(Ae,Ce,Ve,rt,!1),tt!==null&&xn!==null&&ib(Ae,xn,tt,rt,!0)}}e:{if(Ce=ue?Co(ue):window,Ve=Ce.nodeName&&Ce.nodeName.toLowerCase(),Ve==="select"||Ve==="input"&&Ce.type==="file")var st=ij;else if(By(Ce))if(zy)st=cj;else{st=aj;var vt=oj}else(Ve=Ce.nodeName)&&Ve.toLowerCase()==="input"&&(Ce.type==="checkbox"||Ce.type==="radio")&&(st=lj);if(st&&(st=st(a,ue))){$y(Ae,st,p,_e);break e}vt&&vt(a,Ce,ue),a==="focusout"&&(vt=Ce._wrapperState)&&vt.controlled&&Ce.type==="number"&&at(Ce,"number",Ce.value)}switch(vt=ue?Co(ue):window,a){case"focusin":(By(vt)||vt.contentEditable==="true")&&(ko=vt,Ef=ue,Na=null);break;case"focusout":Na=Ef=ko=null;break;case"mousedown":Nf=!0;break;case"contextmenu":case"mouseup":case"dragend":Nf=!1,Gy(Ae,p,_e);break;case"selectionchange":if(fj)break;case"keydown":case"keyup":Gy(Ae,p,_e)}var yt;if(xf)e:{switch(a){case"compositionstart":var St="onCompositionStart";break e;case"compositionend":St="onCompositionEnd";break e;case"compositionupdate":St="onCompositionUpdate";break e}St=void 0}else wo?Dy(a,p)&&(St="onCompositionEnd"):a==="keydown"&&p.keyCode===229&&(St="onCompositionStart");St&&(Oy&&p.locale!=="ko"&&(wo||St!=="onCompositionStart"?St==="onCompositionEnd"&&wo&&(yt=Ty()):(qs=_e,pf="value"in qs?qs.value:qs.textContent,wo=!0)),vt=tc(ue,St),0<vt.length&&(St=new Ay(St,a,null,p,_e),Ae.push({event:St,listeners:vt}),yt?St.data=yt:(yt=Py(p),yt!==null&&(St.data=yt)))),(yt=ej?tj(a,p):nj(a,p))&&(ue=tc(ue,"onBeforeInput"),0<ue.length&&(_e=new Ay("onBeforeInput","beforeinput",null,p,_e),Ae.push({event:_e,listeners:ue}),_e.data=yt))}rb(Ae,u)})}function Ta(a,u,p){return{instance:a,listener:u,currentTarget:p}}function tc(a,u){for(var p=u+"Capture",y=[];a!==null;){var S=a,N=S.stateNode;S.tag===5&&N!==null&&(S=N,N=Se(a,p),N!=null&&y.unshift(Ta(a,N,S)),N=Se(a,u),N!=null&&y.push(Ta(a,N,S))),a=a.return}return y}function Eo(a){if(a===null)return null;do a=a.return;while(a&&a.tag!==5);return a||null}function ib(a,u,p,y,S){for(var N=u._reactName,R=[];p!==null&&p!==y;){var H=p,Y=H.alternate,ue=H.stateNode;if(Y!==null&&Y===y)break;H.tag===5&&ue!==null&&(H=ue,S?(Y=Se(p,N),Y!=null&&R.unshift(Ta(p,Y,H))):S||(Y=Se(p,N),Y!=null&&R.push(Ta(p,Y,H)))),p=p.return}R.length!==0&&a.push({event:u,listeners:R})}var gj=/\r\n?/g,vj=/\u0000|\uFFFD/g;function ob(a){return(typeof a=="string"?a:""+a).replace(gj,`
38
+ `).replace(vj,"")}function nc(a,u,p){if(u=ob(u),ob(a)!==u&&p)throw Error(n(425))}function rc(){}var Af=null,Rf=null;function Of(a,u){return a==="textarea"||a==="noscript"||typeof u.children=="string"||typeof u.children=="number"||typeof u.dangerouslySetInnerHTML=="object"&&u.dangerouslySetInnerHTML!==null&&u.dangerouslySetInnerHTML.__html!=null}var If=typeof setTimeout=="function"?setTimeout:void 0,yj=typeof clearTimeout=="function"?clearTimeout:void 0,ab=typeof Promise=="function"?Promise:void 0,bj=typeof queueMicrotask=="function"?queueMicrotask:typeof ab<"u"?function(a){return ab.resolve(null).then(a).catch(xj)}:If;function xj(a){setTimeout(function(){throw a})}function Lf(a,u){var p=u,y=0;do{var S=p.nextSibling;if(a.removeChild(p),S&&S.nodeType===8)if(p=S.data,p==="/$"){if(y===0){a.removeChild(S),ya(u);return}y--}else p!=="$"&&p!=="$?"&&p!=="$!"||y++;p=S}while(p);ya(u)}function Ks(a){for(;a!=null;a=a.nextSibling){var u=a.nodeType;if(u===1||u===3)break;if(u===8){if(u=a.data,u==="$"||u==="$!"||u==="$?")break;if(u==="/$")return null}}return a}function lb(a){a=a.previousSibling;for(var u=0;a;){if(a.nodeType===8){var p=a.data;if(p==="$"||p==="$!"||p==="$?"){if(u===0)return a;u--}else p==="/$"&&u++}a=a.previousSibling}return null}var No=Math.random().toString(36).slice(2),cs="__reactFiber$"+No,ja="__reactProps$"+No,xs="__reactContainer$"+No,Df="__reactEvents$"+No,wj="__reactListeners$"+No,kj="__reactHandles$"+No;function Li(a){var u=a[cs];if(u)return u;for(var p=a.parentNode;p;){if(u=p[xs]||p[cs]){if(p=u.alternate,u.child!==null||p!==null&&p.child!==null)for(a=lb(a);a!==null;){if(p=a[cs])return p;a=lb(a)}return u}a=p,p=a.parentNode}return null}function Ma(a){return a=a[cs]||a[xs],!a||a.tag!==5&&a.tag!==6&&a.tag!==13&&a.tag!==3?null:a}function Co(a){if(a.tag===5||a.tag===6)return a.stateNode;throw Error(n(33))}function sc(a){return a[ja]||null}var Pf=[],_o=-1;function Gs(a){return{current:a}}function nn(a){0>_o||(a.current=Pf[_o],Pf[_o]=null,_o--)}function Qt(a,u){_o++,Pf[_o]=a.current,a.current=u}var Js={},Kn=Gs(Js),cr=Gs(!1),Di=Js;function To(a,u){var p=a.type.contextTypes;if(!p)return Js;var y=a.stateNode;if(y&&y.__reactInternalMemoizedUnmaskedChildContext===u)return y.__reactInternalMemoizedMaskedChildContext;var S={},N;for(N in p)S[N]=u[N];return y&&(a=a.stateNode,a.__reactInternalMemoizedUnmaskedChildContext=u,a.__reactInternalMemoizedMaskedChildContext=S),S}function ur(a){return a=a.childContextTypes,a!=null}function ic(){nn(cr),nn(Kn)}function cb(a,u,p){if(Kn.current!==Js)throw Error(n(168));Qt(Kn,u),Qt(cr,p)}function ub(a,u,p){var y=a.stateNode;if(u=u.childContextTypes,typeof y.getChildContext!="function")return p;y=y.getChildContext();for(var S in y)if(!(S in u))throw Error(n(108,xe(a)||"Unknown",S));return K({},p,y)}function oc(a){return a=(a=a.stateNode)&&a.__reactInternalMemoizedMergedChildContext||Js,Di=Kn.current,Qt(Kn,a),Qt(cr,cr.current),!0}function db(a,u,p){var y=a.stateNode;if(!y)throw Error(n(169));p?(a=ub(a,u,Di),y.__reactInternalMemoizedMergedChildContext=a,nn(cr),nn(Kn),Qt(Kn,a)):nn(cr),Qt(cr,p)}var ws=null,ac=!1,Bf=!1;function fb(a){ws===null?ws=[a]:ws.push(a)}function Sj(a){ac=!0,fb(a)}function Ys(){if(!Bf&&ws!==null){Bf=!0;var a=0,u=Bt;try{var p=ws;for(Bt=1;a<p.length;a++){var y=p[a];do y=y(!0);while(y!==null)}ws=null,ac=!1}catch(S){throw ws!==null&&(ws=ws.slice(a+1)),je(qr,Ys),S}finally{Bt=u,Bf=!1}}return null}var jo=[],Mo=0,lc=null,cc=0,jr=[],Mr=0,Pi=null,ks=1,Ss="";function Bi(a,u){jo[Mo++]=cc,jo[Mo++]=lc,lc=a,cc=u}function hb(a,u,p){jr[Mr++]=ks,jr[Mr++]=Ss,jr[Mr++]=Pi,Pi=a;var y=ks;a=Ss;var S=32-an(y)-1;y&=~(1<<S),p+=1;var N=32-an(u)+S;if(30<N){var R=S-S%5;N=(y&(1<<R)-1).toString(32),y>>=R,S-=R,ks=1<<32-an(u)+S|p<<S|y,Ss=N+a}else ks=1<<N|p<<S|y,Ss=a}function $f(a){a.return!==null&&(Bi(a,1),hb(a,1,0))}function zf(a){for(;a===lc;)lc=jo[--Mo],jo[Mo]=null,cc=jo[--Mo],jo[Mo]=null;for(;a===Pi;)Pi=jr[--Mr],jr[Mr]=null,Ss=jr[--Mr],jr[Mr]=null,ks=jr[--Mr],jr[Mr]=null}var xr=null,wr=null,sn=!1,Kr=null;function pb(a,u){var p=Ir(5,null,null,0);p.elementType="DELETED",p.stateNode=u,p.return=a,u=a.deletions,u===null?(a.deletions=[p],a.flags|=16):u.push(p)}function mb(a,u){switch(a.tag){case 5:var p=a.type;return u=u.nodeType!==1||p.toLowerCase()!==u.nodeName.toLowerCase()?null:u,u!==null?(a.stateNode=u,xr=a,wr=Ks(u.firstChild),!0):!1;case 6:return u=a.pendingProps===""||u.nodeType!==3?null:u,u!==null?(a.stateNode=u,xr=a,wr=null,!0):!1;case 13:return u=u.nodeType!==8?null:u,u!==null?(p=Pi!==null?{id:ks,overflow:Ss}:null,a.memoizedState={dehydrated:u,treeContext:p,retryLane:1073741824},p=Ir(18,null,null,0),p.stateNode=u,p.return=a,a.child=p,xr=a,wr=null,!0):!1;default:return!1}}function Ff(a){return(a.mode&1)!==0&&(a.flags&128)===0}function Uf(a){if(sn){var u=wr;if(u){var p=u;if(!mb(a,u)){if(Ff(a))throw Error(n(418));u=Ks(p.nextSibling);var y=xr;u&&mb(a,u)?pb(y,p):(a.flags=a.flags&-4097|2,sn=!1,xr=a)}}else{if(Ff(a))throw Error(n(418));a.flags=a.flags&-4097|2,sn=!1,xr=a}}}function gb(a){for(a=a.return;a!==null&&a.tag!==5&&a.tag!==3&&a.tag!==13;)a=a.return;xr=a}function uc(a){if(a!==xr)return!1;if(!sn)return gb(a),sn=!0,!1;var u;if((u=a.tag!==3)&&!(u=a.tag!==5)&&(u=a.type,u=u!=="head"&&u!=="body"&&!Of(a.type,a.memoizedProps)),u&&(u=wr)){if(Ff(a))throw vb(),Error(n(418));for(;u;)pb(a,u),u=Ks(u.nextSibling)}if(gb(a),a.tag===13){if(a=a.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(n(317));e:{for(a=a.nextSibling,u=0;a;){if(a.nodeType===8){var p=a.data;if(p==="/$"){if(u===0){wr=Ks(a.nextSibling);break e}u--}else p!=="$"&&p!=="$!"&&p!=="$?"||u++}a=a.nextSibling}wr=null}}else wr=xr?Ks(a.stateNode.nextSibling):null;return!0}function vb(){for(var a=wr;a;)a=Ks(a.nextSibling)}function Ao(){wr=xr=null,sn=!1}function Hf(a){Kr===null?Kr=[a]:Kr.push(a)}var Ej=j.ReactCurrentBatchConfig;function Aa(a,u,p){if(a=p.ref,a!==null&&typeof a!="function"&&typeof a!="object"){if(p._owner){if(p=p._owner,p){if(p.tag!==1)throw Error(n(309));var y=p.stateNode}if(!y)throw Error(n(147,a));var S=y,N=""+a;return u!==null&&u.ref!==null&&typeof u.ref=="function"&&u.ref._stringRef===N?u.ref:(u=function(R){var H=S.refs;R===null?delete H[N]:H[N]=R},u._stringRef=N,u)}if(typeof a!="string")throw Error(n(284));if(!p._owner)throw Error(n(290,a))}return a}function dc(a,u){throw a=Object.prototype.toString.call(u),Error(n(31,a==="[object Object]"?"object with keys {"+Object.keys(u).join(", ")+"}":a))}function yb(a){var u=a._init;return u(a._payload)}function bb(a){function u(ae,Q){if(a){var le=ae.deletions;le===null?(ae.deletions=[Q],ae.flags|=16):le.push(Q)}}function p(ae,Q){if(!a)return null;for(;Q!==null;)u(ae,Q),Q=Q.sibling;return null}function y(ae,Q){for(ae=new Map;Q!==null;)Q.key!==null?ae.set(Q.key,Q):ae.set(Q.index,Q),Q=Q.sibling;return ae}function S(ae,Q){return ae=si(ae,Q),ae.index=0,ae.sibling=null,ae}function N(ae,Q,le){return ae.index=le,a?(le=ae.alternate,le!==null?(le=le.index,le<Q?(ae.flags|=2,Q):le):(ae.flags|=2,Q)):(ae.flags|=1048576,Q)}function R(ae){return a&&ae.alternate===null&&(ae.flags|=2),ae}function H(ae,Q,le,De){return Q===null||Q.tag!==6?(Q=Ih(le,ae.mode,De),Q.return=ae,Q):(Q=S(Q,le),Q.return=ae,Q)}function Y(ae,Q,le,De){var st=le.type;return st===O?_e(ae,Q,le.props.children,De,le.key):Q!==null&&(Q.elementType===st||typeof st=="object"&&st!==null&&st.$$typeof===q&&yb(st)===Q.type)?(De=S(Q,le.props),De.ref=Aa(ae,Q,le),De.return=ae,De):(De=Lc(le.type,le.key,le.props,null,ae.mode,De),De.ref=Aa(ae,Q,le),De.return=ae,De)}function ue(ae,Q,le,De){return Q===null||Q.tag!==4||Q.stateNode.containerInfo!==le.containerInfo||Q.stateNode.implementation!==le.implementation?(Q=Lh(le,ae.mode,De),Q.return=ae,Q):(Q=S(Q,le.children||[]),Q.return=ae,Q)}function _e(ae,Q,le,De,st){return Q===null||Q.tag!==7?(Q=Vi(le,ae.mode,De,st),Q.return=ae,Q):(Q=S(Q,le),Q.return=ae,Q)}function Ae(ae,Q,le){if(typeof Q=="string"&&Q!==""||typeof Q=="number")return Q=Ih(""+Q,ae.mode,le),Q.return=ae,Q;if(typeof Q=="object"&&Q!==null){switch(Q.$$typeof){case _:return le=Lc(Q.type,Q.key,Q.props,null,ae.mode,le),le.ref=Aa(ae,null,Q),le.return=ae,le;case A:return Q=Lh(Q,ae.mode,le),Q.return=ae,Q;case q:var De=Q._init;return Ae(ae,De(Q._payload),le)}if(nt(Q)||te(Q))return Q=Vi(Q,ae.mode,le,null),Q.return=ae,Q;dc(ae,Q)}return null}function Ce(ae,Q,le,De){var st=Q!==null?Q.key:null;if(typeof le=="string"&&le!==""||typeof le=="number")return st!==null?null:H(ae,Q,""+le,De);if(typeof le=="object"&&le!==null){switch(le.$$typeof){case _:return le.key===st?Y(ae,Q,le,De):null;case A:return le.key===st?ue(ae,Q,le,De):null;case q:return st=le._init,Ce(ae,Q,st(le._payload),De)}if(nt(le)||te(le))return st!==null?null:_e(ae,Q,le,De,null);dc(ae,le)}return null}function Ve(ae,Q,le,De,st){if(typeof De=="string"&&De!==""||typeof De=="number")return ae=ae.get(le)||null,H(Q,ae,""+De,st);if(typeof De=="object"&&De!==null){switch(De.$$typeof){case _:return ae=ae.get(De.key===null?le:De.key)||null,Y(Q,ae,De,st);case A:return ae=ae.get(De.key===null?le:De.key)||null,ue(Q,ae,De,st);case q:var vt=De._init;return Ve(ae,Q,le,vt(De._payload),st)}if(nt(De)||te(De))return ae=ae.get(le)||null,_e(Q,ae,De,st,null);dc(Q,De)}return null}function tt(ae,Q,le,De){for(var st=null,vt=null,yt=Q,St=Q=0,An=null;yt!==null&&St<le.length;St++){yt.index>St?(An=yt,yt=null):An=yt.sibling;var Ut=Ce(ae,yt,le[St],De);if(Ut===null){yt===null&&(yt=An);break}a&&yt&&Ut.alternate===null&&u(ae,yt),Q=N(Ut,Q,St),vt===null?st=Ut:vt.sibling=Ut,vt=Ut,yt=An}if(St===le.length)return p(ae,yt),sn&&Bi(ae,St),st;if(yt===null){for(;St<le.length;St++)yt=Ae(ae,le[St],De),yt!==null&&(Q=N(yt,Q,St),vt===null?st=yt:vt.sibling=yt,vt=yt);return sn&&Bi(ae,St),st}for(yt=y(ae,yt);St<le.length;St++)An=Ve(yt,ae,St,le[St],De),An!==null&&(a&&An.alternate!==null&&yt.delete(An.key===null?St:An.key),Q=N(An,Q,St),vt===null?st=An:vt.sibling=An,vt=An);return a&&yt.forEach(function(ii){return u(ae,ii)}),sn&&Bi(ae,St),st}function rt(ae,Q,le,De){var st=te(le);if(typeof st!="function")throw Error(n(150));if(le=st.call(le),le==null)throw Error(n(151));for(var vt=st=null,yt=Q,St=Q=0,An=null,Ut=le.next();yt!==null&&!Ut.done;St++,Ut=le.next()){yt.index>St?(An=yt,yt=null):An=yt.sibling;var ii=Ce(ae,yt,Ut.value,De);if(ii===null){yt===null&&(yt=An);break}a&&yt&&ii.alternate===null&&u(ae,yt),Q=N(ii,Q,St),vt===null?st=ii:vt.sibling=ii,vt=ii,yt=An}if(Ut.done)return p(ae,yt),sn&&Bi(ae,St),st;if(yt===null){for(;!Ut.done;St++,Ut=le.next())Ut=Ae(ae,Ut.value,De),Ut!==null&&(Q=N(Ut,Q,St),vt===null?st=Ut:vt.sibling=Ut,vt=Ut);return sn&&Bi(ae,St),st}for(yt=y(ae,yt);!Ut.done;St++,Ut=le.next())Ut=Ve(yt,ae,St,Ut.value,De),Ut!==null&&(a&&Ut.alternate!==null&&yt.delete(Ut.key===null?St:Ut.key),Q=N(Ut,Q,St),vt===null?st=Ut:vt.sibling=Ut,vt=Ut);return a&&yt.forEach(function(rM){return u(ae,rM)}),sn&&Bi(ae,St),st}function xn(ae,Q,le,De){if(typeof le=="object"&&le!==null&&le.type===O&&le.key===null&&(le=le.props.children),typeof le=="object"&&le!==null){switch(le.$$typeof){case _:e:{for(var st=le.key,vt=Q;vt!==null;){if(vt.key===st){if(st=le.type,st===O){if(vt.tag===7){p(ae,vt.sibling),Q=S(vt,le.props.children),Q.return=ae,ae=Q;break e}}else if(vt.elementType===st||typeof st=="object"&&st!==null&&st.$$typeof===q&&yb(st)===vt.type){p(ae,vt.sibling),Q=S(vt,le.props),Q.ref=Aa(ae,vt,le),Q.return=ae,ae=Q;break e}p(ae,vt);break}else u(ae,vt);vt=vt.sibling}le.type===O?(Q=Vi(le.props.children,ae.mode,De,le.key),Q.return=ae,ae=Q):(De=Lc(le.type,le.key,le.props,null,ae.mode,De),De.ref=Aa(ae,Q,le),De.return=ae,ae=De)}return R(ae);case A:e:{for(vt=le.key;Q!==null;){if(Q.key===vt)if(Q.tag===4&&Q.stateNode.containerInfo===le.containerInfo&&Q.stateNode.implementation===le.implementation){p(ae,Q.sibling),Q=S(Q,le.children||[]),Q.return=ae,ae=Q;break e}else{p(ae,Q);break}else u(ae,Q);Q=Q.sibling}Q=Lh(le,ae.mode,De),Q.return=ae,ae=Q}return R(ae);case q:return vt=le._init,xn(ae,Q,vt(le._payload),De)}if(nt(le))return tt(ae,Q,le,De);if(te(le))return rt(ae,Q,le,De);dc(ae,le)}return typeof le=="string"&&le!==""||typeof le=="number"?(le=""+le,Q!==null&&Q.tag===6?(p(ae,Q.sibling),Q=S(Q,le),Q.return=ae,ae=Q):(p(ae,Q),Q=Ih(le,ae.mode,De),Q.return=ae,ae=Q),R(ae)):p(ae,Q)}return xn}var Ro=bb(!0),xb=bb(!1),fc=Gs(null),hc=null,Oo=null,Wf=null;function qf(){Wf=Oo=hc=null}function Vf(a){var u=fc.current;nn(fc),a._currentValue=u}function Kf(a,u,p){for(;a!==null;){var y=a.alternate;if((a.childLanes&u)!==u?(a.childLanes|=u,y!==null&&(y.childLanes|=u)):y!==null&&(y.childLanes&u)!==u&&(y.childLanes|=u),a===p)break;a=a.return}}function Io(a,u){hc=a,Wf=Oo=null,a=a.dependencies,a!==null&&a.firstContext!==null&&((a.lanes&u)!==0&&(dr=!0),a.firstContext=null)}function Ar(a){var u=a._currentValue;if(Wf!==a)if(a={context:a,memoizedValue:u,next:null},Oo===null){if(hc===null)throw Error(n(308));Oo=a,hc.dependencies={lanes:0,firstContext:a}}else Oo=Oo.next=a;return u}var $i=null;function Gf(a){$i===null?$i=[a]:$i.push(a)}function wb(a,u,p,y){var S=u.interleaved;return S===null?(p.next=p,Gf(u)):(p.next=S.next,S.next=p),u.interleaved=p,Es(a,y)}function Es(a,u){a.lanes|=u;var p=a.alternate;for(p!==null&&(p.lanes|=u),p=a,a=a.return;a!==null;)a.childLanes|=u,p=a.alternate,p!==null&&(p.childLanes|=u),p=a,a=a.return;return p.tag===3?p.stateNode:null}var Xs=!1;function Jf(a){a.updateQueue={baseState:a.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function kb(a,u){a=a.updateQueue,u.updateQueue===a&&(u.updateQueue={baseState:a.baseState,firstBaseUpdate:a.firstBaseUpdate,lastBaseUpdate:a.lastBaseUpdate,shared:a.shared,effects:a.effects})}function Ns(a,u){return{eventTime:a,lane:u,tag:0,payload:null,callback:null,next:null}}function Qs(a,u,p){var y=a.updateQueue;if(y===null)return null;if(y=y.shared,($t&2)!==0){var S=y.pending;return S===null?u.next=u:(u.next=S.next,S.next=u),y.pending=u,Es(a,p)}return S=y.interleaved,S===null?(u.next=u,Gf(y)):(u.next=S.next,S.next=u),y.interleaved=u,Es(a,p)}function pc(a,u,p){if(u=u.updateQueue,u!==null&&(u=u.shared,(p&4194240)!==0)){var y=u.lanes;y&=a.pendingLanes,p|=y,u.lanes=p,pa(a,p)}}function Sb(a,u){var p=a.updateQueue,y=a.alternate;if(y!==null&&(y=y.updateQueue,p===y)){var S=null,N=null;if(p=p.firstBaseUpdate,p!==null){do{var R={eventTime:p.eventTime,lane:p.lane,tag:p.tag,payload:p.payload,callback:p.callback,next:null};N===null?S=N=R:N=N.next=R,p=p.next}while(p!==null);N===null?S=N=u:N=N.next=u}else S=N=u;p={baseState:y.baseState,firstBaseUpdate:S,lastBaseUpdate:N,shared:y.shared,effects:y.effects},a.updateQueue=p;return}a=p.lastBaseUpdate,a===null?p.firstBaseUpdate=u:a.next=u,p.lastBaseUpdate=u}function mc(a,u,p,y){var S=a.updateQueue;Xs=!1;var N=S.firstBaseUpdate,R=S.lastBaseUpdate,H=S.shared.pending;if(H!==null){S.shared.pending=null;var Y=H,ue=Y.next;Y.next=null,R===null?N=ue:R.next=ue,R=Y;var _e=a.alternate;_e!==null&&(_e=_e.updateQueue,H=_e.lastBaseUpdate,H!==R&&(H===null?_e.firstBaseUpdate=ue:H.next=ue,_e.lastBaseUpdate=Y))}if(N!==null){var Ae=S.baseState;R=0,_e=ue=Y=null,H=N;do{var Ce=H.lane,Ve=H.eventTime;if((y&Ce)===Ce){_e!==null&&(_e=_e.next={eventTime:Ve,lane:0,tag:H.tag,payload:H.payload,callback:H.callback,next:null});e:{var tt=a,rt=H;switch(Ce=u,Ve=p,rt.tag){case 1:if(tt=rt.payload,typeof tt=="function"){Ae=tt.call(Ve,Ae,Ce);break e}Ae=tt;break e;case 3:tt.flags=tt.flags&-65537|128;case 0:if(tt=rt.payload,Ce=typeof tt=="function"?tt.call(Ve,Ae,Ce):tt,Ce==null)break e;Ae=K({},Ae,Ce);break e;case 2:Xs=!0}}H.callback!==null&&H.lane!==0&&(a.flags|=64,Ce=S.effects,Ce===null?S.effects=[H]:Ce.push(H))}else Ve={eventTime:Ve,lane:Ce,tag:H.tag,payload:H.payload,callback:H.callback,next:null},_e===null?(ue=_e=Ve,Y=Ae):_e=_e.next=Ve,R|=Ce;if(H=H.next,H===null){if(H=S.shared.pending,H===null)break;Ce=H,H=Ce.next,Ce.next=null,S.lastBaseUpdate=Ce,S.shared.pending=null}}while(!0);if(_e===null&&(Y=Ae),S.baseState=Y,S.firstBaseUpdate=ue,S.lastBaseUpdate=_e,u=S.shared.interleaved,u!==null){S=u;do R|=S.lane,S=S.next;while(S!==u)}else N===null&&(S.shared.lanes=0);Ui|=R,a.lanes=R,a.memoizedState=Ae}}function Eb(a,u,p){if(a=u.effects,u.effects=null,a!==null)for(u=0;u<a.length;u++){var y=a[u],S=y.callback;if(S!==null){if(y.callback=null,y=p,typeof S!="function")throw Error(n(191,S));S.call(y)}}}var Ra={},us=Gs(Ra),Oa=Gs(Ra),Ia=Gs(Ra);function zi(a){if(a===Ra)throw Error(n(174));return a}function Yf(a,u){switch(Qt(Ia,u),Qt(Oa,a),Qt(us,Ra),a=u.nodeType,a){case 9:case 11:u=(u=u.documentElement)?u.namespaceURI:de(null,"");break;default:a=a===8?u.parentNode:u,u=a.namespaceURI||null,a=a.tagName,u=de(u,a)}nn(us),Qt(us,u)}function Lo(){nn(us),nn(Oa),nn(Ia)}function Nb(a){zi(Ia.current);var u=zi(us.current),p=de(u,a.type);u!==p&&(Qt(Oa,a),Qt(us,p))}function Xf(a){Oa.current===a&&(nn(us),nn(Oa))}var ln=Gs(0);function gc(a){for(var u=a;u!==null;){if(u.tag===13){var p=u.memoizedState;if(p!==null&&(p=p.dehydrated,p===null||p.data==="$?"||p.data==="$!"))return u}else if(u.tag===19&&u.memoizedProps.revealOrder!==void 0){if((u.flags&128)!==0)return u}else if(u.child!==null){u.child.return=u,u=u.child;continue}if(u===a)break;for(;u.sibling===null;){if(u.return===null||u.return===a)return null;u=u.return}u.sibling.return=u.return,u=u.sibling}return null}var Qf=[];function Zf(){for(var a=0;a<Qf.length;a++)Qf[a]._workInProgressVersionPrimary=null;Qf.length=0}var vc=j.ReactCurrentDispatcher,eh=j.ReactCurrentBatchConfig,Fi=0,cn=null,Cn=null,jn=null,yc=!1,La=!1,Da=0,Nj=0;function Gn(){throw Error(n(321))}function th(a,u){if(u===null)return!1;for(var p=0;p<u.length&&p<a.length;p++)if(!Vr(a[p],u[p]))return!1;return!0}function nh(a,u,p,y,S,N){if(Fi=N,cn=u,u.memoizedState=null,u.updateQueue=null,u.lanes=0,vc.current=a===null||a.memoizedState===null?jj:Mj,a=p(y,S),La){N=0;do{if(La=!1,Da=0,25<=N)throw Error(n(301));N+=1,jn=Cn=null,u.updateQueue=null,vc.current=Aj,a=p(y,S)}while(La)}if(vc.current=wc,u=Cn!==null&&Cn.next!==null,Fi=0,jn=Cn=cn=null,yc=!1,u)throw Error(n(300));return a}function rh(){var a=Da!==0;return Da=0,a}function ds(){var a={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return jn===null?cn.memoizedState=jn=a:jn=jn.next=a,jn}function Rr(){if(Cn===null){var a=cn.alternate;a=a!==null?a.memoizedState:null}else a=Cn.next;var u=jn===null?cn.memoizedState:jn.next;if(u!==null)jn=u,Cn=a;else{if(a===null)throw Error(n(310));Cn=a,a={memoizedState:Cn.memoizedState,baseState:Cn.baseState,baseQueue:Cn.baseQueue,queue:Cn.queue,next:null},jn===null?cn.memoizedState=jn=a:jn=jn.next=a}return jn}function Pa(a,u){return typeof u=="function"?u(a):u}function sh(a){var u=Rr(),p=u.queue;if(p===null)throw Error(n(311));p.lastRenderedReducer=a;var y=Cn,S=y.baseQueue,N=p.pending;if(N!==null){if(S!==null){var R=S.next;S.next=N.next,N.next=R}y.baseQueue=S=N,p.pending=null}if(S!==null){N=S.next,y=y.baseState;var H=R=null,Y=null,ue=N;do{var _e=ue.lane;if((Fi&_e)===_e)Y!==null&&(Y=Y.next={lane:0,action:ue.action,hasEagerState:ue.hasEagerState,eagerState:ue.eagerState,next:null}),y=ue.hasEagerState?ue.eagerState:a(y,ue.action);else{var Ae={lane:_e,action:ue.action,hasEagerState:ue.hasEagerState,eagerState:ue.eagerState,next:null};Y===null?(H=Y=Ae,R=y):Y=Y.next=Ae,cn.lanes|=_e,Ui|=_e}ue=ue.next}while(ue!==null&&ue!==N);Y===null?R=y:Y.next=H,Vr(y,u.memoizedState)||(dr=!0),u.memoizedState=y,u.baseState=R,u.baseQueue=Y,p.lastRenderedState=y}if(a=p.interleaved,a!==null){S=a;do N=S.lane,cn.lanes|=N,Ui|=N,S=S.next;while(S!==a)}else S===null&&(p.lanes=0);return[u.memoizedState,p.dispatch]}function ih(a){var u=Rr(),p=u.queue;if(p===null)throw Error(n(311));p.lastRenderedReducer=a;var y=p.dispatch,S=p.pending,N=u.memoizedState;if(S!==null){p.pending=null;var R=S=S.next;do N=a(N,R.action),R=R.next;while(R!==S);Vr(N,u.memoizedState)||(dr=!0),u.memoizedState=N,u.baseQueue===null&&(u.baseState=N),p.lastRenderedState=N}return[N,y]}function Cb(){}function _b(a,u){var p=cn,y=Rr(),S=u(),N=!Vr(y.memoizedState,S);if(N&&(y.memoizedState=S,dr=!0),y=y.queue,oh(Mb.bind(null,p,y,a),[a]),y.getSnapshot!==u||N||jn!==null&&jn.memoizedState.tag&1){if(p.flags|=2048,Ba(9,jb.bind(null,p,y,S,u),void 0,null),Mn===null)throw Error(n(349));(Fi&30)!==0||Tb(p,u,S)}return S}function Tb(a,u,p){a.flags|=16384,a={getSnapshot:u,value:p},u=cn.updateQueue,u===null?(u={lastEffect:null,stores:null},cn.updateQueue=u,u.stores=[a]):(p=u.stores,p===null?u.stores=[a]:p.push(a))}function jb(a,u,p,y){u.value=p,u.getSnapshot=y,Ab(u)&&Rb(a)}function Mb(a,u,p){return p(function(){Ab(u)&&Rb(a)})}function Ab(a){var u=a.getSnapshot;a=a.value;try{var p=u();return!Vr(a,p)}catch{return!0}}function Rb(a){var u=Es(a,1);u!==null&&Xr(u,a,1,-1)}function Ob(a){var u=ds();return typeof a=="function"&&(a=a()),u.memoizedState=u.baseState=a,a={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Pa,lastRenderedState:a},u.queue=a,a=a.dispatch=Tj.bind(null,cn,a),[u.memoizedState,a]}function Ba(a,u,p,y){return a={tag:a,create:u,destroy:p,deps:y,next:null},u=cn.updateQueue,u===null?(u={lastEffect:null,stores:null},cn.updateQueue=u,u.lastEffect=a.next=a):(p=u.lastEffect,p===null?u.lastEffect=a.next=a:(y=p.next,p.next=a,a.next=y,u.lastEffect=a)),a}function Ib(){return Rr().memoizedState}function bc(a,u,p,y){var S=ds();cn.flags|=a,S.memoizedState=Ba(1|u,p,void 0,y===void 0?null:y)}function xc(a,u,p,y){var S=Rr();y=y===void 0?null:y;var N=void 0;if(Cn!==null){var R=Cn.memoizedState;if(N=R.destroy,y!==null&&th(y,R.deps)){S.memoizedState=Ba(u,p,N,y);return}}cn.flags|=a,S.memoizedState=Ba(1|u,p,N,y)}function Lb(a,u){return bc(8390656,8,a,u)}function oh(a,u){return xc(2048,8,a,u)}function Db(a,u){return xc(4,2,a,u)}function Pb(a,u){return xc(4,4,a,u)}function Bb(a,u){if(typeof u=="function")return a=a(),u(a),function(){u(null)};if(u!=null)return a=a(),u.current=a,function(){u.current=null}}function $b(a,u,p){return p=p!=null?p.concat([a]):null,xc(4,4,Bb.bind(null,u,a),p)}function ah(){}function zb(a,u){var p=Rr();u=u===void 0?null:u;var y=p.memoizedState;return y!==null&&u!==null&&th(u,y[1])?y[0]:(p.memoizedState=[a,u],a)}function Fb(a,u){var p=Rr();u=u===void 0?null:u;var y=p.memoizedState;return y!==null&&u!==null&&th(u,y[1])?y[0]:(a=a(),p.memoizedState=[a,u],a)}function Ub(a,u,p){return(Fi&21)===0?(a.baseState&&(a.baseState=!1,dr=!0),a.memoizedState=p):(Vr(p,u)||(p=Ul(),cn.lanes|=p,Ui|=p,a.baseState=!0),u)}function Cj(a,u){var p=Bt;Bt=p!==0&&4>p?p:4,a(!0);var y=eh.transition;eh.transition={};try{a(!1),u()}finally{Bt=p,eh.transition=y}}function Hb(){return Rr().memoizedState}function _j(a,u,p){var y=ni(a);if(p={lane:y,action:p,hasEagerState:!1,eagerState:null,next:null},Wb(a))qb(u,p);else if(p=wb(a,u,p,y),p!==null){var S=ir();Xr(p,a,y,S),Vb(p,u,y)}}function Tj(a,u,p){var y=ni(a),S={lane:y,action:p,hasEagerState:!1,eagerState:null,next:null};if(Wb(a))qb(u,S);else{var N=a.alternate;if(a.lanes===0&&(N===null||N.lanes===0)&&(N=u.lastRenderedReducer,N!==null))try{var R=u.lastRenderedState,H=N(R,p);if(S.hasEagerState=!0,S.eagerState=H,Vr(H,R)){var Y=u.interleaved;Y===null?(S.next=S,Gf(u)):(S.next=Y.next,Y.next=S),u.interleaved=S;return}}catch{}finally{}p=wb(a,u,S,y),p!==null&&(S=ir(),Xr(p,a,y,S),Vb(p,u,y))}}function Wb(a){var u=a.alternate;return a===cn||u!==null&&u===cn}function qb(a,u){La=yc=!0;var p=a.pending;p===null?u.next=u:(u.next=p.next,p.next=u),a.pending=u}function Vb(a,u,p){if((p&4194240)!==0){var y=u.lanes;y&=a.pendingLanes,p|=y,u.lanes=p,pa(a,p)}}var wc={readContext:Ar,useCallback:Gn,useContext:Gn,useEffect:Gn,useImperativeHandle:Gn,useInsertionEffect:Gn,useLayoutEffect:Gn,useMemo:Gn,useReducer:Gn,useRef:Gn,useState:Gn,useDebugValue:Gn,useDeferredValue:Gn,useTransition:Gn,useMutableSource:Gn,useSyncExternalStore:Gn,useId:Gn,unstable_isNewReconciler:!1},jj={readContext:Ar,useCallback:function(a,u){return ds().memoizedState=[a,u===void 0?null:u],a},useContext:Ar,useEffect:Lb,useImperativeHandle:function(a,u,p){return p=p!=null?p.concat([a]):null,bc(4194308,4,Bb.bind(null,u,a),p)},useLayoutEffect:function(a,u){return bc(4194308,4,a,u)},useInsertionEffect:function(a,u){return bc(4,2,a,u)},useMemo:function(a,u){var p=ds();return u=u===void 0?null:u,a=a(),p.memoizedState=[a,u],a},useReducer:function(a,u,p){var y=ds();return u=p!==void 0?p(u):u,y.memoizedState=y.baseState=u,a={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:a,lastRenderedState:u},y.queue=a,a=a.dispatch=_j.bind(null,cn,a),[y.memoizedState,a]},useRef:function(a){var u=ds();return a={current:a},u.memoizedState=a},useState:Ob,useDebugValue:ah,useDeferredValue:function(a){return ds().memoizedState=a},useTransition:function(){var a=Ob(!1),u=a[0];return a=Cj.bind(null,a[1]),ds().memoizedState=a,[u,a]},useMutableSource:function(){},useSyncExternalStore:function(a,u,p){var y=cn,S=ds();if(sn){if(p===void 0)throw Error(n(407));p=p()}else{if(p=u(),Mn===null)throw Error(n(349));(Fi&30)!==0||Tb(y,u,p)}S.memoizedState=p;var N={value:p,getSnapshot:u};return S.queue=N,Lb(Mb.bind(null,y,N,a),[a]),y.flags|=2048,Ba(9,jb.bind(null,y,N,p,u),void 0,null),p},useId:function(){var a=ds(),u=Mn.identifierPrefix;if(sn){var p=Ss,y=ks;p=(y&~(1<<32-an(y)-1)).toString(32)+p,u=":"+u+"R"+p,p=Da++,0<p&&(u+="H"+p.toString(32)),u+=":"}else p=Nj++,u=":"+u+"r"+p.toString(32)+":";return a.memoizedState=u},unstable_isNewReconciler:!1},Mj={readContext:Ar,useCallback:zb,useContext:Ar,useEffect:oh,useImperativeHandle:$b,useInsertionEffect:Db,useLayoutEffect:Pb,useMemo:Fb,useReducer:sh,useRef:Ib,useState:function(){return sh(Pa)},useDebugValue:ah,useDeferredValue:function(a){var u=Rr();return Ub(u,Cn.memoizedState,a)},useTransition:function(){var a=sh(Pa)[0],u=Rr().memoizedState;return[a,u]},useMutableSource:Cb,useSyncExternalStore:_b,useId:Hb,unstable_isNewReconciler:!1},Aj={readContext:Ar,useCallback:zb,useContext:Ar,useEffect:oh,useImperativeHandle:$b,useInsertionEffect:Db,useLayoutEffect:Pb,useMemo:Fb,useReducer:ih,useRef:Ib,useState:function(){return ih(Pa)},useDebugValue:ah,useDeferredValue:function(a){var u=Rr();return Cn===null?u.memoizedState=a:Ub(u,Cn.memoizedState,a)},useTransition:function(){var a=ih(Pa)[0],u=Rr().memoizedState;return[a,u]},useMutableSource:Cb,useSyncExternalStore:_b,useId:Hb,unstable_isNewReconciler:!1};function Gr(a,u){if(a&&a.defaultProps){u=K({},u),a=a.defaultProps;for(var p in a)u[p]===void 0&&(u[p]=a[p]);return u}return u}function lh(a,u,p,y){u=a.memoizedState,p=p(y,u),p=p==null?u:K({},u,p),a.memoizedState=p,a.lanes===0&&(a.updateQueue.baseState=p)}var kc={isMounted:function(a){return(a=a._reactInternals)?un(a)===a:!1},enqueueSetState:function(a,u,p){a=a._reactInternals;var y=ir(),S=ni(a),N=Ns(y,S);N.payload=u,p!=null&&(N.callback=p),u=Qs(a,N,S),u!==null&&(Xr(u,a,S,y),pc(u,a,S))},enqueueReplaceState:function(a,u,p){a=a._reactInternals;var y=ir(),S=ni(a),N=Ns(y,S);N.tag=1,N.payload=u,p!=null&&(N.callback=p),u=Qs(a,N,S),u!==null&&(Xr(u,a,S,y),pc(u,a,S))},enqueueForceUpdate:function(a,u){a=a._reactInternals;var p=ir(),y=ni(a),S=Ns(p,y);S.tag=2,u!=null&&(S.callback=u),u=Qs(a,S,y),u!==null&&(Xr(u,a,y,p),pc(u,a,y))}};function Kb(a,u,p,y,S,N,R){return a=a.stateNode,typeof a.shouldComponentUpdate=="function"?a.shouldComponentUpdate(y,N,R):u.prototype&&u.prototype.isPureReactComponent?!Ea(p,y)||!Ea(S,N):!0}function Gb(a,u,p){var y=!1,S=Js,N=u.contextType;return typeof N=="object"&&N!==null?N=Ar(N):(S=ur(u)?Di:Kn.current,y=u.contextTypes,N=(y=y!=null)?To(a,S):Js),u=new u(p,N),a.memoizedState=u.state!==null&&u.state!==void 0?u.state:null,u.updater=kc,a.stateNode=u,u._reactInternals=a,y&&(a=a.stateNode,a.__reactInternalMemoizedUnmaskedChildContext=S,a.__reactInternalMemoizedMaskedChildContext=N),u}function Jb(a,u,p,y){a=u.state,typeof u.componentWillReceiveProps=="function"&&u.componentWillReceiveProps(p,y),typeof u.UNSAFE_componentWillReceiveProps=="function"&&u.UNSAFE_componentWillReceiveProps(p,y),u.state!==a&&kc.enqueueReplaceState(u,u.state,null)}function ch(a,u,p,y){var S=a.stateNode;S.props=p,S.state=a.memoizedState,S.refs={},Jf(a);var N=u.contextType;typeof N=="object"&&N!==null?S.context=Ar(N):(N=ur(u)?Di:Kn.current,S.context=To(a,N)),S.state=a.memoizedState,N=u.getDerivedStateFromProps,typeof N=="function"&&(lh(a,u,N,p),S.state=a.memoizedState),typeof u.getDerivedStateFromProps=="function"||typeof S.getSnapshotBeforeUpdate=="function"||typeof S.UNSAFE_componentWillMount!="function"&&typeof S.componentWillMount!="function"||(u=S.state,typeof S.componentWillMount=="function"&&S.componentWillMount(),typeof S.UNSAFE_componentWillMount=="function"&&S.UNSAFE_componentWillMount(),u!==S.state&&kc.enqueueReplaceState(S,S.state,null),mc(a,p,S,y),S.state=a.memoizedState),typeof S.componentDidMount=="function"&&(a.flags|=4194308)}function Do(a,u){try{var p="",y=u;do p+=ge(y),y=y.return;while(y);var S=p}catch(N){S=`
39
39
  Error generating stack: `+N.message+`
40
- `+N.stack}return{value:a,source:u,stack:S,digest:null}}function uh(a,u,p){return{value:a,source:null,stack:p??null,digest:u??null}}function dh(a,u){try{console.error(u.value)}catch(p){setTimeout(function(){throw p})}}var Rj=typeof WeakMap=="function"?WeakMap:Map;function Yb(a,u,p){p=Ns(-1,p),p.tag=3,p.payload={element:null};var y=u.value;return p.callback=function(){jc||(jc=!0,Ch=y),dh(a,u)},p}function Xb(a,u,p){p=Ns(-1,p),p.tag=3;var y=a.type.getDerivedStateFromError;if(typeof y=="function"){var S=u.value;p.payload=function(){return y(S)},p.callback=function(){dh(a,u)}}var N=a.stateNode;return N!==null&&typeof N.componentDidCatch=="function"&&(p.callback=function(){dh(a,u),typeof y!="function"&&(ei===null?ei=new Set([this]):ei.add(this));var R=u.stack;this.componentDidCatch(u.value,{componentStack:R!==null?R:""})}),p}function Qb(a,u,p){var y=a.pingCache;if(y===null){y=a.pingCache=new Rj;var S=new Set;y.set(u,S)}else S=y.get(u),S===void 0&&(S=new Set,y.set(u,S));S.has(p)||(S.add(p),a=Vj.bind(null,a,u,p),u.then(a,a))}function Zb(a){do{var u;if((u=a.tag===13)&&(u=a.memoizedState,u=u!==null?u.dehydrated!==null:!0),u)return a;a=a.return}while(a!==null);return null}function e0(a,u,p,y,S){return(a.mode&1)===0?(a===u?a.flags|=65536:(a.flags|=128,p.flags|=131072,p.flags&=-52805,p.tag===1&&(p.alternate===null?p.tag=17:(u=Ns(-1,1),u.tag=2,Qs(p,u,1))),p.lanes|=1),a):(a.flags|=65536,a.lanes=S,a)}var Oj=j.ReactCurrentOwner,dr=!1;function sr(a,u,p,y){u.child=a===null?xb(u,null,p,y):Ro(u,a.child,p,y)}function t0(a,u,p,y,S){p=p.render;var N=u.ref;return Io(u,S),y=nh(a,u,p,y,N,S),p=rh(),a!==null&&!dr?(u.updateQueue=a.updateQueue,u.flags&=-2053,a.lanes&=~S,Cs(a,u,S)):(sn&&p&&$f(u),u.flags|=1,sr(a,u,y,S),u.child)}function n0(a,u,p,y,S){if(a===null){var N=p.type;return typeof N=="function"&&!Oh(N)&&N.defaultProps===void 0&&p.compare===null&&p.defaultProps===void 0?(u.tag=15,u.type=N,r0(a,u,N,y,S)):(a=Lc(p.type,null,y,u,u.mode,S),a.ref=u.ref,a.return=u,u.child=a)}if(N=a.child,(a.lanes&S)===0){var R=N.memoizedProps;if(p=p.compare,p=p!==null?p:Ea,p(R,y)&&a.ref===u.ref)return Cs(a,u,S)}return u.flags|=1,a=si(N,y),a.ref=u.ref,a.return=u,u.child=a}function r0(a,u,p,y,S){if(a!==null){var N=a.memoizedProps;if(Ea(N,y)&&a.ref===u.ref)if(dr=!1,u.pendingProps=y=N,(a.lanes&S)!==0)(a.flags&131072)!==0&&(dr=!0);else return u.lanes=a.lanes,Cs(a,u,S)}return fh(a,u,p,y,S)}function s0(a,u,p){var y=u.pendingProps,S=y.children,N=a!==null?a.memoizedState:null;if(y.mode==="hidden")if((u.mode&1)===0)u.memoizedState={baseLanes:0,cachePool:null,transitions:null},Qt(Bo,kr),kr|=p;else{if((p&1073741824)===0)return a=N!==null?N.baseLanes|p:p,u.lanes=u.childLanes=1073741824,u.memoizedState={baseLanes:a,cachePool:null,transitions:null},u.updateQueue=null,Qt(Bo,kr),kr|=a,null;u.memoizedState={baseLanes:0,cachePool:null,transitions:null},y=N!==null?N.baseLanes:p,Qt(Bo,kr),kr|=y}else N!==null?(y=N.baseLanes|p,u.memoizedState=null):y=p,Qt(Bo,kr),kr|=y;return sr(a,u,S,p),u.child}function i0(a,u){var p=u.ref;(a===null&&p!==null||a!==null&&a.ref!==p)&&(u.flags|=512,u.flags|=2097152)}function fh(a,u,p,y,S){var N=ur(p)?Di:Kn.current;return N=To(u,N),Io(u,S),p=nh(a,u,p,y,N,S),y=rh(),a!==null&&!dr?(u.updateQueue=a.updateQueue,u.flags&=-2053,a.lanes&=~S,Cs(a,u,S)):(sn&&y&&$f(u),u.flags|=1,sr(a,u,p,S),u.child)}function o0(a,u,p,y,S){if(ur(p)){var N=!0;oc(u)}else N=!1;if(Io(u,S),u.stateNode===null)Ec(a,u),Gb(u,p,y),ch(u,p,y,S),y=!0;else if(a===null){var R=u.stateNode,H=u.memoizedProps;R.props=H;var Y=R.context,ue=p.contextType;typeof ue=="object"&&ue!==null?ue=Ar(ue):(ue=ur(p)?Di:Kn.current,ue=To(u,ue));var _e=p.getDerivedStateFromProps,Ae=typeof _e=="function"||typeof R.getSnapshotBeforeUpdate=="function";Ae||typeof R.UNSAFE_componentWillReceiveProps!="function"&&typeof R.componentWillReceiveProps!="function"||(H!==y||Y!==ue)&&Jb(u,R,y,ue),Xs=!1;var Ce=u.memoizedState;R.state=Ce,mc(u,y,R,S),Y=u.memoizedState,H!==y||Ce!==Y||cr.current||Xs?(typeof _e=="function"&&(lh(u,p,_e,y),Y=u.memoizedState),(H=Xs||Kb(u,p,H,y,Ce,Y,ue))?(Ae||typeof R.UNSAFE_componentWillMount!="function"&&typeof R.componentWillMount!="function"||(typeof R.componentWillMount=="function"&&R.componentWillMount(),typeof R.UNSAFE_componentWillMount=="function"&&R.UNSAFE_componentWillMount()),typeof R.componentDidMount=="function"&&(u.flags|=4194308)):(typeof R.componentDidMount=="function"&&(u.flags|=4194308),u.memoizedProps=y,u.memoizedState=Y),R.props=y,R.state=Y,R.context=ue,y=H):(typeof R.componentDidMount=="function"&&(u.flags|=4194308),y=!1)}else{R=u.stateNode,kb(a,u),H=u.memoizedProps,ue=u.type===u.elementType?H:Gr(u.type,H),R.props=ue,Ae=u.pendingProps,Ce=R.context,Y=p.contextType,typeof Y=="object"&&Y!==null?Y=Ar(Y):(Y=ur(p)?Di:Kn.current,Y=To(u,Y));var Ve=p.getDerivedStateFromProps;(_e=typeof Ve=="function"||typeof R.getSnapshotBeforeUpdate=="function")||typeof R.UNSAFE_componentWillReceiveProps!="function"&&typeof R.componentWillReceiveProps!="function"||(H!==Ae||Ce!==Y)&&Jb(u,R,y,Y),Xs=!1,Ce=u.memoizedState,R.state=Ce,mc(u,y,R,S);var tt=u.memoizedState;H!==Ae||Ce!==tt||cr.current||Xs?(typeof Ve=="function"&&(lh(u,p,Ve,y),tt=u.memoizedState),(ue=Xs||Kb(u,p,ue,y,Ce,tt,Y)||!1)?(_e||typeof R.UNSAFE_componentWillUpdate!="function"&&typeof R.componentWillUpdate!="function"||(typeof R.componentWillUpdate=="function"&&R.componentWillUpdate(y,tt,Y),typeof R.UNSAFE_componentWillUpdate=="function"&&R.UNSAFE_componentWillUpdate(y,tt,Y)),typeof R.componentDidUpdate=="function"&&(u.flags|=4),typeof R.getSnapshotBeforeUpdate=="function"&&(u.flags|=1024)):(typeof R.componentDidUpdate!="function"||H===a.memoizedProps&&Ce===a.memoizedState||(u.flags|=4),typeof R.getSnapshotBeforeUpdate!="function"||H===a.memoizedProps&&Ce===a.memoizedState||(u.flags|=1024),u.memoizedProps=y,u.memoizedState=tt),R.props=y,R.state=tt,R.context=Y,y=ue):(typeof R.componentDidUpdate!="function"||H===a.memoizedProps&&Ce===a.memoizedState||(u.flags|=4),typeof R.getSnapshotBeforeUpdate!="function"||H===a.memoizedProps&&Ce===a.memoizedState||(u.flags|=1024),y=!1)}return hh(a,u,p,y,N,S)}function hh(a,u,p,y,S,N){i0(a,u);var R=(u.flags&128)!==0;if(!y&&!R)return S&&db(u,p,!1),Cs(a,u,N);y=u.stateNode,Oj.current=u;var H=R&&typeof p.getDerivedStateFromError!="function"?null:y.render();return u.flags|=1,a!==null&&R?(u.child=Ro(u,a.child,null,N),u.child=Ro(u,null,H,N)):sr(a,u,H,N),u.memoizedState=y.state,S&&db(u,p,!0),u.child}function a0(a){var u=a.stateNode;u.pendingContext?cb(a,u.pendingContext,u.pendingContext!==u.context):u.context&&cb(a,u.context,!1),Yf(a,u.containerInfo)}function l0(a,u,p,y,S){return Ao(),Hf(S),u.flags|=256,sr(a,u,p,y),u.child}var ph={dehydrated:null,treeContext:null,retryLane:0};function mh(a){return{baseLanes:a,cachePool:null,transitions:null}}function c0(a,u,p){var y=u.pendingProps,S=ln.current,N=!1,R=(u.flags&128)!==0,H;if((H=R)||(H=a!==null&&a.memoizedState===null?!1:(S&2)!==0),H?(N=!0,u.flags&=-129):(a===null||a.memoizedState!==null)&&(S|=1),Qt(ln,S&1),a===null)return Uf(u),a=u.memoizedState,a!==null&&(a=a.dehydrated,a!==null)?((u.mode&1)===0?u.lanes=1:a.data==="$!"?u.lanes=8:u.lanes=1073741824,null):(R=y.children,a=y.fallback,N?(y=u.mode,N=u.child,R={mode:"hidden",children:R},(y&1)===0&&N!==null?(N.childLanes=0,N.pendingProps=R):N=Dc(R,y,0,null),a=Vi(a,y,p,null),N.return=u,a.return=u,N.sibling=a,u.child=N,u.child.memoizedState=mh(p),u.memoizedState=ph,a):gh(u,R));if(S=a.memoizedState,S!==null&&(H=S.dehydrated,H!==null))return Ij(a,u,R,y,H,S,p);if(N){N=y.fallback,R=u.mode,S=a.child,H=S.sibling;var Y={mode:"hidden",children:y.children};return(R&1)===0&&u.child!==S?(y=u.child,y.childLanes=0,y.pendingProps=Y,u.deletions=null):(y=si(S,Y),y.subtreeFlags=S.subtreeFlags&14680064),H!==null?N=si(H,N):(N=Vi(N,R,p,null),N.flags|=2),N.return=u,y.return=u,y.sibling=N,u.child=y,y=N,N=u.child,R=a.child.memoizedState,R=R===null?mh(p):{baseLanes:R.baseLanes|p,cachePool:null,transitions:R.transitions},N.memoizedState=R,N.childLanes=a.childLanes&~p,u.memoizedState=ph,y}return N=a.child,a=N.sibling,y=si(N,{mode:"visible",children:y.children}),(u.mode&1)===0&&(y.lanes=p),y.return=u,y.sibling=null,a!==null&&(p=u.deletions,p===null?(u.deletions=[a],u.flags|=16):p.push(a)),u.child=y,u.memoizedState=null,y}function gh(a,u){return u=Dc({mode:"visible",children:u},a.mode,0,null),u.return=a,a.child=u}function Sc(a,u,p,y){return y!==null&&Hf(y),Ro(u,a.child,null,p),a=gh(u,u.pendingProps.children),a.flags|=2,u.memoizedState=null,a}function Ij(a,u,p,y,S,N,R){if(p)return u.flags&256?(u.flags&=-257,y=uh(Error(n(422))),Sc(a,u,R,y)):u.memoizedState!==null?(u.child=a.child,u.flags|=128,null):(N=y.fallback,S=u.mode,y=Dc({mode:"visible",children:y.children},S,0,null),N=Vi(N,S,R,null),N.flags|=2,y.return=u,N.return=u,y.sibling=N,u.child=y,(u.mode&1)!==0&&Ro(u,a.child,null,R),u.child.memoizedState=mh(R),u.memoizedState=ph,N);if((u.mode&1)===0)return Sc(a,u,R,null);if(S.data==="$!"){if(y=S.nextSibling&&S.nextSibling.dataset,y)var H=y.dgst;return y=H,N=Error(n(419)),y=uh(N,y,void 0),Sc(a,u,R,y)}if(H=(R&a.childLanes)!==0,dr||H){if(y=Mn,y!==null){switch(R&-R){case 4:S=2;break;case 16:S=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:S=32;break;case 536870912:S=268435456;break;default:S=0}S=(S&(y.suspendedLanes|R))!==0?0:S,S!==0&&S!==N.retryLane&&(N.retryLane=S,Es(a,S),Xr(y,a,S,-1))}return Rh(),y=uh(Error(n(421))),Sc(a,u,R,y)}return S.data==="$?"?(u.flags|=128,u.child=a.child,u=Kj.bind(null,a),S._reactRetry=u,null):(a=N.treeContext,wr=Ks(S.nextSibling),xr=u,sn=!0,Kr=null,a!==null&&(jr[Mr++]=ks,jr[Mr++]=Ss,jr[Mr++]=Pi,ks=a.id,Ss=a.overflow,Pi=u),u=gh(u,y.children),u.flags|=4096,u)}function u0(a,u,p){a.lanes|=u;var y=a.alternate;y!==null&&(y.lanes|=u),Kf(a.return,u,p)}function vh(a,u,p,y,S){var N=a.memoizedState;N===null?a.memoizedState={isBackwards:u,rendering:null,renderingStartTime:0,last:y,tail:p,tailMode:S}:(N.isBackwards=u,N.rendering=null,N.renderingStartTime=0,N.last=y,N.tail=p,N.tailMode=S)}function d0(a,u,p){var y=u.pendingProps,S=y.revealOrder,N=y.tail;if(sr(a,u,y.children,p),y=ln.current,(y&2)!==0)y=y&1|2,u.flags|=128;else{if(a!==null&&(a.flags&128)!==0)e:for(a=u.child;a!==null;){if(a.tag===13)a.memoizedState!==null&&u0(a,p,u);else if(a.tag===19)u0(a,p,u);else if(a.child!==null){a.child.return=a,a=a.child;continue}if(a===u)break e;for(;a.sibling===null;){if(a.return===null||a.return===u)break e;a=a.return}a.sibling.return=a.return,a=a.sibling}y&=1}if(Qt(ln,y),(u.mode&1)===0)u.memoizedState=null;else switch(S){case"forwards":for(p=u.child,S=null;p!==null;)a=p.alternate,a!==null&&gc(a)===null&&(S=p),p=p.sibling;p=S,p===null?(S=u.child,u.child=null):(S=p.sibling,p.sibling=null),vh(u,!1,S,p,N);break;case"backwards":for(p=null,S=u.child,u.child=null;S!==null;){if(a=S.alternate,a!==null&&gc(a)===null){u.child=S;break}a=S.sibling,S.sibling=p,p=S,S=a}vh(u,!0,p,null,N);break;case"together":vh(u,!1,null,null,void 0);break;default:u.memoizedState=null}return u.child}function Ec(a,u){(u.mode&1)===0&&a!==null&&(a.alternate=null,u.alternate=null,u.flags|=2)}function Cs(a,u,p){if(a!==null&&(u.dependencies=a.dependencies),Ui|=u.lanes,(p&u.childLanes)===0)return null;if(a!==null&&u.child!==a.child)throw Error(n(153));if(u.child!==null){for(a=u.child,p=si(a,a.pendingProps),u.child=p,p.return=u;a.sibling!==null;)a=a.sibling,p=p.sibling=si(a,a.pendingProps),p.return=u;p.sibling=null}return u.child}function Lj(a,u,p){switch(u.tag){case 3:a0(u),Ao();break;case 5:Nb(u);break;case 1:ur(u.type)&&oc(u);break;case 4:Yf(u,u.stateNode.containerInfo);break;case 10:var y=u.type._context,S=u.memoizedProps.value;Qt(fc,y._currentValue),y._currentValue=S;break;case 13:if(y=u.memoizedState,y!==null)return y.dehydrated!==null?(Qt(ln,ln.current&1),u.flags|=128,null):(p&u.child.childLanes)!==0?c0(a,u,p):(Qt(ln,ln.current&1),a=Cs(a,u,p),a!==null?a.sibling:null);Qt(ln,ln.current&1);break;case 19:if(y=(p&u.childLanes)!==0,(a.flags&128)!==0){if(y)return d0(a,u,p);u.flags|=128}if(S=u.memoizedState,S!==null&&(S.rendering=null,S.tail=null,S.lastEffect=null),Qt(ln,ln.current),y)break;return null;case 22:case 23:return u.lanes=0,s0(a,u,p)}return Cs(a,u,p)}var f0,yh,h0,p0;f0=function(a,u){for(var p=u.child;p!==null;){if(p.tag===5||p.tag===6)a.appendChild(p.stateNode);else if(p.tag!==4&&p.child!==null){p.child.return=p,p=p.child;continue}if(p===u)break;for(;p.sibling===null;){if(p.return===null||p.return===u)return;p=p.return}p.sibling.return=p.return,p=p.sibling}},yh=function(){},h0=function(a,u,p,y){var S=a.memoizedProps;if(S!==y){a=u.stateNode,zi(us.current);var N=null;switch(p){case"input":S=pt(a,S),y=pt(a,y),N=[];break;case"select":S=K({},S,{value:void 0}),y=K({},y,{value:void 0}),N=[];break;case"textarea":S=Fe(a,S),y=Fe(a,y),N=[];break;default:typeof S.onClick!="function"&&typeof y.onClick=="function"&&(a.onclick=rc)}gt(p,y);var R;p=null;for(ue in S)if(!y.hasOwnProperty(ue)&&S.hasOwnProperty(ue)&&S[ue]!=null)if(ue==="style"){var H=S[ue];for(R in H)H.hasOwnProperty(R)&&(p||(p={}),p[R]="")}else ue!=="dangerouslySetInnerHTML"&&ue!=="children"&&ue!=="suppressContentEditableWarning"&&ue!=="suppressHydrationWarning"&&ue!=="autoFocus"&&(s.hasOwnProperty(ue)?N||(N=[]):(N=N||[]).push(ue,null));for(ue in y){var Y=y[ue];if(H=S!=null?S[ue]:void 0,y.hasOwnProperty(ue)&&Y!==H&&(Y!=null||H!=null))if(ue==="style")if(H){for(R in H)!H.hasOwnProperty(R)||Y&&Y.hasOwnProperty(R)||(p||(p={}),p[R]="");for(R in Y)Y.hasOwnProperty(R)&&H[R]!==Y[R]&&(p||(p={}),p[R]=Y[R])}else p||(N||(N=[]),N.push(ue,p)),p=Y;else ue==="dangerouslySetInnerHTML"?(Y=Y?Y.__html:void 0,H=H?H.__html:void 0,Y!=null&&H!==Y&&(N=N||[]).push(ue,Y)):ue==="children"?typeof Y!="string"&&typeof Y!="number"||(N=N||[]).push(ue,""+Y):ue!=="suppressContentEditableWarning"&&ue!=="suppressHydrationWarning"&&(s.hasOwnProperty(ue)?(Y!=null&&ue==="onScroll"&&tn("scroll",a),N||H===Y||(N=[])):(N=N||[]).push(ue,Y))}p&&(N=N||[]).push("style",p);var ue=N;(u.updateQueue=ue)&&(u.flags|=4)}},p0=function(a,u,p,y){p!==y&&(u.flags|=4)};function $a(a,u){if(!sn)switch(a.tailMode){case"hidden":u=a.tail;for(var p=null;u!==null;)u.alternate!==null&&(p=u),u=u.sibling;p===null?a.tail=null:p.sibling=null;break;case"collapsed":p=a.tail;for(var y=null;p!==null;)p.alternate!==null&&(y=p),p=p.sibling;y===null?u||a.tail===null?a.tail=null:a.tail.sibling=null:y.sibling=null}}function Jn(a){var u=a.alternate!==null&&a.alternate.child===a.child,p=0,y=0;if(u)for(var S=a.child;S!==null;)p|=S.lanes|S.childLanes,y|=S.subtreeFlags&14680064,y|=S.flags&14680064,S.return=a,S=S.sibling;else for(S=a.child;S!==null;)p|=S.lanes|S.childLanes,y|=S.subtreeFlags,y|=S.flags,S.return=a,S=S.sibling;return a.subtreeFlags|=y,a.childLanes=p,u}function Dj(a,u,p){var y=u.pendingProps;switch(zf(u),u.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Jn(u),null;case 1:return ur(u.type)&&ic(),Jn(u),null;case 3:return y=u.stateNode,Lo(),nn(cr),nn(Kn),Zf(),y.pendingContext&&(y.context=y.pendingContext,y.pendingContext=null),(a===null||a.child===null)&&(uc(u)?u.flags|=4:a===null||a.memoizedState.isDehydrated&&(u.flags&256)===0||(u.flags|=1024,Kr!==null&&(jh(Kr),Kr=null))),yh(a,u),Jn(u),null;case 5:Xf(u);var S=zi(Ia.current);if(p=u.type,a!==null&&u.stateNode!=null)h0(a,u,p,y,S),a.ref!==u.ref&&(u.flags|=512,u.flags|=2097152);else{if(!y){if(u.stateNode===null)throw Error(n(166));return Jn(u),null}if(a=zi(us.current),uc(u)){y=u.stateNode,p=u.type;var N=u.memoizedProps;switch(y[cs]=u,y[ja]=N,a=(u.mode&1)!==0,p){case"dialog":tn("cancel",y),tn("close",y);break;case"iframe":case"object":case"embed":tn("load",y);break;case"video":case"audio":for(S=0;S<Ca.length;S++)tn(Ca[S],y);break;case"source":tn("error",y);break;case"img":case"image":case"link":tn("error",y),tn("load",y);break;case"details":tn("toggle",y);break;case"input":Je(y,N),tn("invalid",y);break;case"select":y._wrapperState={wasMultiple:!!N.multiple},tn("invalid",y);break;case"textarea":ve(y,N),tn("invalid",y)}gt(p,N),S=null;for(var R in N)if(N.hasOwnProperty(R)){var H=N[R];R==="children"?typeof H=="string"?y.textContent!==H&&(N.suppressHydrationWarning!==!0&&nc(y.textContent,H,a),S=["children",H]):typeof H=="number"&&y.textContent!==""+H&&(N.suppressHydrationWarning!==!0&&nc(y.textContent,H,a),S=["children",""+H]):s.hasOwnProperty(R)&&H!=null&&R==="onScroll"&&tn("scroll",y)}switch(p){case"input":Ze(y),ft(y,N,!0);break;case"textarea":Ze(y),Be(y);break;case"select":case"option":break;default:typeof N.onClick=="function"&&(y.onclick=rc)}y=S,u.updateQueue=y,y!==null&&(u.flags|=4)}else{R=S.nodeType===9?S:S.ownerDocument,a==="http://www.w3.org/1999/xhtml"&&(a=ne(p)),a==="http://www.w3.org/1999/xhtml"?p==="script"?(a=R.createElement("div"),a.innerHTML="<script><\/script>",a=a.removeChild(a.firstChild)):typeof y.is=="string"?a=R.createElement(p,{is:y.is}):(a=R.createElement(p),p==="select"&&(R=a,y.multiple?R.multiple=!0:y.size&&(R.size=y.size))):a=R.createElementNS(a,p),a[cs]=u,a[ja]=y,f0(a,u,!1,!1),u.stateNode=a;e:{switch(R=Nt(p,y),p){case"dialog":tn("cancel",a),tn("close",a),S=y;break;case"iframe":case"object":case"embed":tn("load",a),S=y;break;case"video":case"audio":for(S=0;S<Ca.length;S++)tn(Ca[S],a);S=y;break;case"source":tn("error",a),S=y;break;case"img":case"image":case"link":tn("error",a),tn("load",a),S=y;break;case"details":tn("toggle",a),S=y;break;case"input":Je(a,y),S=pt(a,y),tn("invalid",a);break;case"option":S=y;break;case"select":a._wrapperState={wasMultiple:!!y.multiple},S=K({},y,{value:void 0}),tn("invalid",a);break;case"textarea":ve(a,y),S=Fe(a,y),tn("invalid",a);break;default:S=y}gt(p,S),H=S;for(N in H)if(H.hasOwnProperty(N)){var Y=H[N];N==="style"?Ye(a,Y):N==="dangerouslySetInnerHTML"?(Y=Y?Y.__html:void 0,Y!=null&&Ge(a,Y)):N==="children"?typeof Y=="string"?(p!=="textarea"||Y!=="")&&Pe(a,Y):typeof Y=="number"&&Pe(a,""+Y):N!=="suppressContentEditableWarning"&&N!=="suppressHydrationWarning"&&N!=="autoFocus"&&(s.hasOwnProperty(N)?Y!=null&&N==="onScroll"&&tn("scroll",a):Y!=null&&T(a,N,Y,R))}switch(p){case"input":Ze(a),ft(a,y,!1);break;case"textarea":Ze(a),Be(a);break;case"option":y.value!=null&&a.setAttribute("value",""+xe(y.value));break;case"select":a.multiple=!!y.multiple,N=y.value,N!=null?ht(a,!!y.multiple,N,!1):y.defaultValue!=null&&ht(a,!!y.multiple,y.defaultValue,!0);break;default:typeof S.onClick=="function"&&(a.onclick=rc)}switch(p){case"button":case"input":case"select":case"textarea":y=!!y.autoFocus;break e;case"img":y=!0;break e;default:y=!1}}y&&(u.flags|=4)}u.ref!==null&&(u.flags|=512,u.flags|=2097152)}return Jn(u),null;case 6:if(a&&u.stateNode!=null)p0(a,u,a.memoizedProps,y);else{if(typeof y!="string"&&u.stateNode===null)throw Error(n(166));if(p=zi(Ia.current),zi(us.current),uc(u)){if(y=u.stateNode,p=u.memoizedProps,y[cs]=u,(N=y.nodeValue!==p)&&(a=xr,a!==null))switch(a.tag){case 3:nc(y.nodeValue,p,(a.mode&1)!==0);break;case 5:a.memoizedProps.suppressHydrationWarning!==!0&&nc(y.nodeValue,p,(a.mode&1)!==0)}N&&(u.flags|=4)}else y=(p.nodeType===9?p:p.ownerDocument).createTextNode(y),y[cs]=u,u.stateNode=y}return Jn(u),null;case 13:if(nn(ln),y=u.memoizedState,a===null||a.memoizedState!==null&&a.memoizedState.dehydrated!==null){if(sn&&wr!==null&&(u.mode&1)!==0&&(u.flags&128)===0)vb(),Ao(),u.flags|=98560,N=!1;else if(N=uc(u),y!==null&&y.dehydrated!==null){if(a===null){if(!N)throw Error(n(318));if(N=u.memoizedState,N=N!==null?N.dehydrated:null,!N)throw Error(n(317));N[cs]=u}else Ao(),(u.flags&128)===0&&(u.memoizedState=null),u.flags|=4;Jn(u),N=!1}else Kr!==null&&(jh(Kr),Kr=null),N=!0;if(!N)return u.flags&65536?u:null}return(u.flags&128)!==0?(u.lanes=p,u):(y=y!==null,y!==(a!==null&&a.memoizedState!==null)&&y&&(u.child.flags|=8192,(u.mode&1)!==0&&(a===null||(ln.current&1)!==0?_n===0&&(_n=3):Rh())),u.updateQueue!==null&&(u.flags|=4),Jn(u),null);case 4:return Lo(),yh(a,u),a===null&&_a(u.stateNode.containerInfo),Jn(u),null;case 10:return Vf(u.type._context),Jn(u),null;case 17:return ur(u.type)&&ic(),Jn(u),null;case 19:if(nn(ln),N=u.memoizedState,N===null)return Jn(u),null;if(y=(u.flags&128)!==0,R=N.rendering,R===null)if(y)$a(N,!1);else{if(_n!==0||a!==null&&(a.flags&128)!==0)for(a=u.child;a!==null;){if(R=gc(a),R!==null){for(u.flags|=128,$a(N,!1),y=R.updateQueue,y!==null&&(u.updateQueue=y,u.flags|=4),u.subtreeFlags=0,y=p,p=u.child;p!==null;)N=p,a=y,N.flags&=14680066,R=N.alternate,R===null?(N.childLanes=0,N.lanes=a,N.child=null,N.subtreeFlags=0,N.memoizedProps=null,N.memoizedState=null,N.updateQueue=null,N.dependencies=null,N.stateNode=null):(N.childLanes=R.childLanes,N.lanes=R.lanes,N.child=R.child,N.subtreeFlags=0,N.deletions=null,N.memoizedProps=R.memoizedProps,N.memoizedState=R.memoizedState,N.updateQueue=R.updateQueue,N.type=R.type,a=R.dependencies,N.dependencies=a===null?null:{lanes:a.lanes,firstContext:a.firstContext}),p=p.sibling;return Qt(ln,ln.current&1|2),u.child}a=a.sibling}N.tail!==null&&It()>$o&&(u.flags|=128,y=!0,$a(N,!1),u.lanes=4194304)}else{if(!y)if(a=gc(R),a!==null){if(u.flags|=128,y=!0,p=a.updateQueue,p!==null&&(u.updateQueue=p,u.flags|=4),$a(N,!0),N.tail===null&&N.tailMode==="hidden"&&!R.alternate&&!sn)return Jn(u),null}else 2*It()-N.renderingStartTime>$o&&p!==1073741824&&(u.flags|=128,y=!0,$a(N,!1),u.lanes=4194304);N.isBackwards?(R.sibling=u.child,u.child=R):(p=N.last,p!==null?p.sibling=R:u.child=R,N.last=R)}return N.tail!==null?(u=N.tail,N.rendering=u,N.tail=u.sibling,N.renderingStartTime=It(),u.sibling=null,p=ln.current,Qt(ln,y?p&1|2:p&1),u):(Jn(u),null);case 22:case 23:return Ah(),y=u.memoizedState!==null,a!==null&&a.memoizedState!==null!==y&&(u.flags|=8192),y&&(u.mode&1)!==0?(kr&1073741824)!==0&&(Jn(u),u.subtreeFlags&6&&(u.flags|=8192)):Jn(u),null;case 24:return null;case 25:return null}throw Error(n(156,u.tag))}function Pj(a,u){switch(zf(u),u.tag){case 1:return ur(u.type)&&ic(),a=u.flags,a&65536?(u.flags=a&-65537|128,u):null;case 3:return Lo(),nn(cr),nn(Kn),Zf(),a=u.flags,(a&65536)!==0&&(a&128)===0?(u.flags=a&-65537|128,u):null;case 5:return Xf(u),null;case 13:if(nn(ln),a=u.memoizedState,a!==null&&a.dehydrated!==null){if(u.alternate===null)throw Error(n(340));Ao()}return a=u.flags,a&65536?(u.flags=a&-65537|128,u):null;case 19:return nn(ln),null;case 4:return Lo(),null;case 10:return Vf(u.type._context),null;case 22:case 23:return Ah(),null;case 24:return null;default:return null}}var Nc=!1,Yn=!1,Bj=typeof WeakSet=="function"?WeakSet:Set,Qe=null;function Po(a,u){var p=a.ref;if(p!==null)if(typeof p=="function")try{p(null)}catch(y){fn(a,u,y)}else p.current=null}function bh(a,u,p){try{p()}catch(y){fn(a,u,y)}}var m0=!1;function $j(a,u){if(Af=ql,a=Ky(),Sf(a)){if("selectionStart"in a)var p={start:a.selectionStart,end:a.selectionEnd};else e:{p=(p=a.ownerDocument)&&p.defaultView||window;var y=p.getSelection&&p.getSelection();if(y&&y.rangeCount!==0){p=y.anchorNode;var S=y.anchorOffset,N=y.focusNode;y=y.focusOffset;try{p.nodeType,N.nodeType}catch{p=null;break e}var R=0,H=-1,Y=-1,ue=0,_e=0,Ae=a,Ce=null;t:for(;;){for(var Ve;Ae!==p||S!==0&&Ae.nodeType!==3||(H=R+S),Ae!==N||y!==0&&Ae.nodeType!==3||(Y=R+y),Ae.nodeType===3&&(R+=Ae.nodeValue.length),(Ve=Ae.firstChild)!==null;)Ce=Ae,Ae=Ve;for(;;){if(Ae===a)break t;if(Ce===p&&++ue===S&&(H=R),Ce===N&&++_e===y&&(Y=R),(Ve=Ae.nextSibling)!==null)break;Ae=Ce,Ce=Ae.parentNode}Ae=Ve}p=H===-1||Y===-1?null:{start:H,end:Y}}else p=null}p=p||{start:0,end:0}}else p=null;for(Rf={focusedElem:a,selectionRange:p},ql=!1,Qe=u;Qe!==null;)if(u=Qe,a=u.child,(u.subtreeFlags&1028)!==0&&a!==null)a.return=u,Qe=a;else for(;Qe!==null;){u=Qe;try{var tt=u.alternate;if((u.flags&1024)!==0)switch(u.tag){case 0:case 11:case 15:break;case 1:if(tt!==null){var rt=tt.memoizedProps,xn=tt.memoizedState,ae=u.stateNode,Q=ae.getSnapshotBeforeUpdate(u.elementType===u.type?rt:Gr(u.type,rt),xn);ae.__reactInternalSnapshotBeforeUpdate=Q}break;case 3:var le=u.stateNode.containerInfo;le.nodeType===1?le.textContent="":le.nodeType===9&&le.documentElement&&le.removeChild(le.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(n(163))}}catch(De){fn(u,u.return,De)}if(a=u.sibling,a!==null){a.return=u.return,Qe=a;break}Qe=u.return}return tt=m0,m0=!1,tt}function za(a,u,p){var y=u.updateQueue;if(y=y!==null?y.lastEffect:null,y!==null){var S=y=y.next;do{if((S.tag&a)===a){var N=S.destroy;S.destroy=void 0,N!==void 0&&bh(u,p,N)}S=S.next}while(S!==y)}}function Cc(a,u){if(u=u.updateQueue,u=u!==null?u.lastEffect:null,u!==null){var p=u=u.next;do{if((p.tag&a)===a){var y=p.create;p.destroy=y()}p=p.next}while(p!==u)}}function xh(a){var u=a.ref;if(u!==null){var p=a.stateNode;switch(a.tag){case 5:a=p;break;default:a=p}typeof u=="function"?u(a):u.current=a}}function g0(a){var u=a.alternate;u!==null&&(a.alternate=null,g0(u)),a.child=null,a.deletions=null,a.sibling=null,a.tag===5&&(u=a.stateNode,u!==null&&(delete u[cs],delete u[ja],delete u[Df],delete u[wj],delete u[kj])),a.stateNode=null,a.return=null,a.dependencies=null,a.memoizedProps=null,a.memoizedState=null,a.pendingProps=null,a.stateNode=null,a.updateQueue=null}function v0(a){return a.tag===5||a.tag===3||a.tag===4}function y0(a){e:for(;;){for(;a.sibling===null;){if(a.return===null||v0(a.return))return null;a=a.return}for(a.sibling.return=a.return,a=a.sibling;a.tag!==5&&a.tag!==6&&a.tag!==18;){if(a.flags&2||a.child===null||a.tag===4)continue e;a.child.return=a,a=a.child}if(!(a.flags&2))return a.stateNode}}function wh(a,u,p){var y=a.tag;if(y===5||y===6)a=a.stateNode,u?p.nodeType===8?p.parentNode.insertBefore(a,u):p.insertBefore(a,u):(p.nodeType===8?(u=p.parentNode,u.insertBefore(a,p)):(u=p,u.appendChild(a)),p=p._reactRootContainer,p!=null||u.onclick!==null||(u.onclick=rc));else if(y!==4&&(a=a.child,a!==null))for(wh(a,u,p),a=a.sibling;a!==null;)wh(a,u,p),a=a.sibling}function kh(a,u,p){var y=a.tag;if(y===5||y===6)a=a.stateNode,u?p.insertBefore(a,u):p.appendChild(a);else if(y!==4&&(a=a.child,a!==null))for(kh(a,u,p),a=a.sibling;a!==null;)kh(a,u,p),a=a.sibling}var Bn=null,Jr=!1;function Zs(a,u,p){for(p=p.child;p!==null;)b0(a,u,p),p=p.sibling}function b0(a,u,p){if(Ot&&typeof Ot.onCommitFiberUnmount=="function")try{Ot.onCommitFiberUnmount(Tt,p)}catch{}switch(p.tag){case 5:Yn||Po(p,u);case 6:var y=Bn,S=Jr;Bn=null,Zs(a,u,p),Bn=y,Jr=S,Bn!==null&&(Jr?(a=Bn,p=p.stateNode,a.nodeType===8?a.parentNode.removeChild(p):a.removeChild(p)):Bn.removeChild(p.stateNode));break;case 18:Bn!==null&&(Jr?(a=Bn,p=p.stateNode,a.nodeType===8?Lf(a.parentNode,p):a.nodeType===1&&Lf(a,p),ya(a)):Lf(Bn,p.stateNode));break;case 4:y=Bn,S=Jr,Bn=p.stateNode.containerInfo,Jr=!0,Zs(a,u,p),Bn=y,Jr=S;break;case 0:case 11:case 14:case 15:if(!Yn&&(y=p.updateQueue,y!==null&&(y=y.lastEffect,y!==null))){S=y=y.next;do{var N=S,R=N.destroy;N=N.tag,R!==void 0&&((N&2)!==0||(N&4)!==0)&&bh(p,u,R),S=S.next}while(S!==y)}Zs(a,u,p);break;case 1:if(!Yn&&(Po(p,u),y=p.stateNode,typeof y.componentWillUnmount=="function"))try{y.props=p.memoizedProps,y.state=p.memoizedState,y.componentWillUnmount()}catch(H){fn(p,u,H)}Zs(a,u,p);break;case 21:Zs(a,u,p);break;case 22:p.mode&1?(Yn=(y=Yn)||p.memoizedState!==null,Zs(a,u,p),Yn=y):Zs(a,u,p);break;default:Zs(a,u,p)}}function x0(a){var u=a.updateQueue;if(u!==null){a.updateQueue=null;var p=a.stateNode;p===null&&(p=a.stateNode=new Bj),u.forEach(function(y){var S=Gj.bind(null,a,y);p.has(y)||(p.add(y),y.then(S,S))})}}function Yr(a,u){var p=u.deletions;if(p!==null)for(var y=0;y<p.length;y++){var S=p[y];try{var N=a,R=u,H=R;e:for(;H!==null;){switch(H.tag){case 5:Bn=H.stateNode,Jr=!1;break e;case 3:Bn=H.stateNode.containerInfo,Jr=!0;break e;case 4:Bn=H.stateNode.containerInfo,Jr=!0;break e}H=H.return}if(Bn===null)throw Error(n(160));b0(N,R,S),Bn=null,Jr=!1;var Y=S.alternate;Y!==null&&(Y.return=null),S.return=null}catch(ue){fn(S,u,ue)}}if(u.subtreeFlags&12854)for(u=u.child;u!==null;)w0(u,a),u=u.sibling}function w0(a,u){var p=a.alternate,y=a.flags;switch(a.tag){case 0:case 11:case 14:case 15:if(Yr(u,a),fs(a),y&4){try{za(3,a,a.return),Cc(3,a)}catch(rt){fn(a,a.return,rt)}try{za(5,a,a.return)}catch(rt){fn(a,a.return,rt)}}break;case 1:Yr(u,a),fs(a),y&512&&p!==null&&Po(p,p.return);break;case 5:if(Yr(u,a),fs(a),y&512&&p!==null&&Po(p,p.return),a.flags&32){var S=a.stateNode;try{Pe(S,"")}catch(rt){fn(a,a.return,rt)}}if(y&4&&(S=a.stateNode,S!=null)){var N=a.memoizedProps,R=p!==null?p.memoizedProps:N,H=a.type,Y=a.updateQueue;if(a.updateQueue=null,Y!==null)try{H==="input"&&N.type==="radio"&&N.name!=null&&pe(S,N),Nt(H,R);var ue=Nt(H,N);for(R=0;R<Y.length;R+=2){var _e=Y[R],Ae=Y[R+1];_e==="style"?Ye(S,Ae):_e==="dangerouslySetInnerHTML"?Ge(S,Ae):_e==="children"?Pe(S,Ae):T(S,_e,Ae,ue)}switch(H){case"input":mt(S,N);break;case"textarea":X(S,N);break;case"select":var Ce=S._wrapperState.wasMultiple;S._wrapperState.wasMultiple=!!N.multiple;var Ve=N.value;Ve!=null?ht(S,!!N.multiple,Ve,!1):Ce!==!!N.multiple&&(N.defaultValue!=null?ht(S,!!N.multiple,N.defaultValue,!0):ht(S,!!N.multiple,N.multiple?[]:"",!1))}S[ja]=N}catch(rt){fn(a,a.return,rt)}}break;case 6:if(Yr(u,a),fs(a),y&4){if(a.stateNode===null)throw Error(n(162));S=a.stateNode,N=a.memoizedProps;try{S.nodeValue=N}catch(rt){fn(a,a.return,rt)}}break;case 3:if(Yr(u,a),fs(a),y&4&&p!==null&&p.memoizedState.isDehydrated)try{ya(u.containerInfo)}catch(rt){fn(a,a.return,rt)}break;case 4:Yr(u,a),fs(a);break;case 13:Yr(u,a),fs(a),S=a.child,S.flags&8192&&(N=S.memoizedState!==null,S.stateNode.isHidden=N,!N||S.alternate!==null&&S.alternate.memoizedState!==null||(Nh=It())),y&4&&x0(a);break;case 22:if(_e=p!==null&&p.memoizedState!==null,a.mode&1?(Yn=(ue=Yn)||_e,Yr(u,a),Yn=ue):Yr(u,a),fs(a),y&8192){if(ue=a.memoizedState!==null,(a.stateNode.isHidden=ue)&&!_e&&(a.mode&1)!==0)for(Qe=a,_e=a.child;_e!==null;){for(Ae=Qe=_e;Qe!==null;){switch(Ce=Qe,Ve=Ce.child,Ce.tag){case 0:case 11:case 14:case 15:za(4,Ce,Ce.return);break;case 1:Po(Ce,Ce.return);var tt=Ce.stateNode;if(typeof tt.componentWillUnmount=="function"){y=Ce,p=Ce.return;try{u=y,tt.props=u.memoizedProps,tt.state=u.memoizedState,tt.componentWillUnmount()}catch(rt){fn(y,p,rt)}}break;case 5:Po(Ce,Ce.return);break;case 22:if(Ce.memoizedState!==null){E0(Ae);continue}}Ve!==null?(Ve.return=Ce,Qe=Ve):E0(Ae)}_e=_e.sibling}e:for(_e=null,Ae=a;;){if(Ae.tag===5){if(_e===null){_e=Ae;try{S=Ae.stateNode,ue?(N=S.style,typeof N.setProperty=="function"?N.setProperty("display","none","important"):N.display="none"):(H=Ae.stateNode,Y=Ae.memoizedProps.style,R=Y!=null&&Y.hasOwnProperty("display")?Y.display:null,H.style.display=bt("display",R))}catch(rt){fn(a,a.return,rt)}}}else if(Ae.tag===6){if(_e===null)try{Ae.stateNode.nodeValue=ue?"":Ae.memoizedProps}catch(rt){fn(a,a.return,rt)}}else if((Ae.tag!==22&&Ae.tag!==23||Ae.memoizedState===null||Ae===a)&&Ae.child!==null){Ae.child.return=Ae,Ae=Ae.child;continue}if(Ae===a)break e;for(;Ae.sibling===null;){if(Ae.return===null||Ae.return===a)break e;_e===Ae&&(_e=null),Ae=Ae.return}_e===Ae&&(_e=null),Ae.sibling.return=Ae.return,Ae=Ae.sibling}}break;case 19:Yr(u,a),fs(a),y&4&&x0(a);break;case 21:break;default:Yr(u,a),fs(a)}}function fs(a){var u=a.flags;if(u&2){try{e:{for(var p=a.return;p!==null;){if(v0(p)){var y=p;break e}p=p.return}throw Error(n(160))}switch(y.tag){case 5:var S=y.stateNode;y.flags&32&&(Pe(S,""),y.flags&=-33);var N=y0(a);kh(a,N,S);break;case 3:case 4:var R=y.stateNode.containerInfo,H=y0(a);wh(a,H,R);break;default:throw Error(n(161))}}catch(Y){fn(a,a.return,Y)}a.flags&=-3}u&4096&&(a.flags&=-4097)}function zj(a,u,p){Qe=a,k0(a)}function k0(a,u,p){for(var y=(a.mode&1)!==0;Qe!==null;){var S=Qe,N=S.child;if(S.tag===22&&y){var R=S.memoizedState!==null||Nc;if(!R){var H=S.alternate,Y=H!==null&&H.memoizedState!==null||Yn;H=Nc;var ue=Yn;if(Nc=R,(Yn=Y)&&!ue)for(Qe=S;Qe!==null;)R=Qe,Y=R.child,R.tag===22&&R.memoizedState!==null?N0(S):Y!==null?(Y.return=R,Qe=Y):N0(S);for(;N!==null;)Qe=N,k0(N),N=N.sibling;Qe=S,Nc=H,Yn=ue}S0(a)}else(S.subtreeFlags&8772)!==0&&N!==null?(N.return=S,Qe=N):S0(a)}}function S0(a){for(;Qe!==null;){var u=Qe;if((u.flags&8772)!==0){var p=u.alternate;try{if((u.flags&8772)!==0)switch(u.tag){case 0:case 11:case 15:Yn||Cc(5,u);break;case 1:var y=u.stateNode;if(u.flags&4&&!Yn)if(p===null)y.componentDidMount();else{var S=u.elementType===u.type?p.memoizedProps:Gr(u.type,p.memoizedProps);y.componentDidUpdate(S,p.memoizedState,y.__reactInternalSnapshotBeforeUpdate)}var N=u.updateQueue;N!==null&&Eb(u,N,y);break;case 3:var R=u.updateQueue;if(R!==null){if(p=null,u.child!==null)switch(u.child.tag){case 5:p=u.child.stateNode;break;case 1:p=u.child.stateNode}Eb(u,R,p)}break;case 5:var H=u.stateNode;if(p===null&&u.flags&4){p=H;var Y=u.memoizedProps;switch(u.type){case"button":case"input":case"select":case"textarea":Y.autoFocus&&p.focus();break;case"img":Y.src&&(p.src=Y.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(u.memoizedState===null){var ue=u.alternate;if(ue!==null){var _e=ue.memoizedState;if(_e!==null){var Ae=_e.dehydrated;Ae!==null&&ya(Ae)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(n(163))}Yn||u.flags&512&&xh(u)}catch(Ce){fn(u,u.return,Ce)}}if(u===a){Qe=null;break}if(p=u.sibling,p!==null){p.return=u.return,Qe=p;break}Qe=u.return}}function E0(a){for(;Qe!==null;){var u=Qe;if(u===a){Qe=null;break}var p=u.sibling;if(p!==null){p.return=u.return,Qe=p;break}Qe=u.return}}function N0(a){for(;Qe!==null;){var u=Qe;try{switch(u.tag){case 0:case 11:case 15:var p=u.return;try{Cc(4,u)}catch(Y){fn(u,p,Y)}break;case 1:var y=u.stateNode;if(typeof y.componentDidMount=="function"){var S=u.return;try{y.componentDidMount()}catch(Y){fn(u,S,Y)}}var N=u.return;try{xh(u)}catch(Y){fn(u,N,Y)}break;case 5:var R=u.return;try{xh(u)}catch(Y){fn(u,R,Y)}}}catch(Y){fn(u,u.return,Y)}if(u===a){Qe=null;break}var H=u.sibling;if(H!==null){H.return=u.return,Qe=H;break}Qe=u.return}}var Fj=Math.ceil,_c=j.ReactCurrentDispatcher,Sh=j.ReactCurrentOwner,Or=j.ReactCurrentBatchConfig,$t=0,Mn=null,kn=null,$n=0,kr=0,Bo=Gs(0),_n=0,Fa=null,Ui=0,Tc=0,Eh=0,Ua=null,fr=null,Nh=0,$o=1/0,_s=null,jc=!1,Ch=null,ei=null,Mc=!1,ti=null,Ac=0,Ha=0,_h=null,Rc=-1,Oc=0;function ir(){return($t&6)!==0?It():Rc!==-1?Rc:Rc=It()}function ni(a){return(a.mode&1)===0?1:($t&2)!==0&&$n!==0?$n&-$n:Ej.transition!==null?(Oc===0&&(Oc=Ul()),Oc):(a=Bt,a!==0||(a=window.event,a=a===void 0?16:_y(a.type)),a)}function Xr(a,u,p,y){if(50<Ha)throw Ha=0,_h=null,Error(n(185));Hs(a,p,y),(($t&2)===0||a!==Mn)&&(a===Mn&&(($t&2)===0&&(Tc|=p),_n===4&&ri(a,$n)),hr(a,y),p===1&&$t===0&&(u.mode&1)===0&&($o=It()+500,ac&&Ys()))}function hr(a,u){var p=a.callbackNode;uf(a,u);var y=Ri(a,a===Mn?$n:0);if(y===0)p!==null&&ze(p),a.callbackNode=null,a.callbackPriority=0;else if(u=y&-y,a.callbackPriority!==u){if(p!=null&&ze(p),u===1)a.tag===0?Sj(_0.bind(null,a)):fb(_0.bind(null,a)),bj(function(){($t&6)===0&&Ys()}),p=null;else{switch(Et(y)){case 1:p=qr;break;case 4:p=Kt;break;case 16:p=Vn;break;case 536870912:p=lt;break;default:p=Vn}p=L0(p,C0.bind(null,a))}a.callbackPriority=u,a.callbackNode=p}}function C0(a,u){if(Rc=-1,Oc=0,($t&6)!==0)throw Error(n(327));var p=a.callbackNode;if(zo()&&a.callbackNode!==p)return null;var y=Ri(a,a===Mn?$n:0);if(y===0)return null;if((y&30)!==0||(y&a.expiredLanes)!==0||u)u=Ic(a,y);else{u=y;var S=$t;$t|=2;var N=j0();(Mn!==a||$n!==u)&&(_s=null,$o=It()+500,Wi(a,u));do try{Wj();break}catch(H){T0(a,H)}while(!0);qf(),_c.current=N,$t=S,kn!==null?u=0:(Mn=null,$n=0,u=_n)}if(u!==0){if(u===2&&(S=ha(a),S!==0&&(y=S,u=Th(a,S))),u===1)throw p=Fa,Wi(a,0),ri(a,y),hr(a,It()),p;if(u===6)ri(a,y);else{if(S=a.current.alternate,(y&30)===0&&!Uj(S)&&(u=Ic(a,y),u===2&&(N=ha(a),N!==0&&(y=N,u=Th(a,N))),u===1))throw p=Fa,Wi(a,0),ri(a,y),hr(a,It()),p;switch(a.finishedWork=S,a.finishedLanes=y,u){case 0:case 1:throw Error(n(345));case 2:qi(a,fr,_s);break;case 3:if(ri(a,y),(y&130023424)===y&&(u=Nh+500-It(),10<u)){if(Ri(a,0)!==0)break;if(S=a.suspendedLanes,(S&y)!==y){ir(),a.pingedLanes|=a.suspendedLanes&S;break}a.timeoutHandle=If(qi.bind(null,a,fr,_s),u);break}qi(a,fr,_s);break;case 4:if(ri(a,y),(y&4194240)===y)break;for(u=a.eventTimes,S=-1;0<y;){var R=31-an(y);N=1<<R,R=u[R],R>S&&(S=R),y&=~N}if(y=S,y=It()-y,y=(120>y?120:480>y?480:1080>y?1080:1920>y?1920:3e3>y?3e3:4320>y?4320:1960*Fj(y/1960))-y,10<y){a.timeoutHandle=If(qi.bind(null,a,fr,_s),y);break}qi(a,fr,_s);break;case 5:qi(a,fr,_s);break;default:throw Error(n(329))}}}return hr(a,It()),a.callbackNode===p?C0.bind(null,a):null}function Th(a,u){var p=Ua;return a.current.memoizedState.isDehydrated&&(Wi(a,u).flags|=256),a=Ic(a,u),a!==2&&(u=fr,fr=p,u!==null&&jh(u)),a}function jh(a){fr===null?fr=a:fr.push.apply(fr,a)}function Uj(a){for(var u=a;;){if(u.flags&16384){var p=u.updateQueue;if(p!==null&&(p=p.stores,p!==null))for(var y=0;y<p.length;y++){var S=p[y],N=S.getSnapshot;S=S.value;try{if(!Vr(N(),S))return!1}catch{return!1}}}if(p=u.child,u.subtreeFlags&16384&&p!==null)p.return=u,u=p;else{if(u===a)break;for(;u.sibling===null;){if(u.return===null||u.return===a)return!0;u=u.return}u.sibling.return=u.return,u=u.sibling}}return!0}function ri(a,u){for(u&=~Eh,u&=~Tc,a.suspendedLanes|=u,a.pingedLanes&=~u,a=a.expirationTimes;0<u;){var p=31-an(u),y=1<<p;a[p]=-1,u&=~y}}function _0(a){if(($t&6)!==0)throw Error(n(327));zo();var u=Ri(a,0);if((u&1)===0)return hr(a,It()),null;var p=Ic(a,u);if(a.tag!==0&&p===2){var y=ha(a);y!==0&&(u=y,p=Th(a,y))}if(p===1)throw p=Fa,Wi(a,0),ri(a,u),hr(a,It()),p;if(p===6)throw Error(n(345));return a.finishedWork=a.current.alternate,a.finishedLanes=u,qi(a,fr,_s),hr(a,It()),null}function Mh(a,u){var p=$t;$t|=1;try{return a(u)}finally{$t=p,$t===0&&($o=It()+500,ac&&Ys())}}function Hi(a){ti!==null&&ti.tag===0&&($t&6)===0&&zo();var u=$t;$t|=1;var p=Or.transition,y=Bt;try{if(Or.transition=null,Bt=1,a)return a()}finally{Bt=y,Or.transition=p,$t=u,($t&6)===0&&Ys()}}function Ah(){kr=Bo.current,nn(Bo)}function Wi(a,u){a.finishedWork=null,a.finishedLanes=0;var p=a.timeoutHandle;if(p!==-1&&(a.timeoutHandle=-1,yj(p)),kn!==null)for(p=kn.return;p!==null;){var y=p;switch(zf(y),y.tag){case 1:y=y.type.childContextTypes,y!=null&&ic();break;case 3:Lo(),nn(cr),nn(Kn),Zf();break;case 5:Xf(y);break;case 4:Lo();break;case 13:nn(ln);break;case 19:nn(ln);break;case 10:Vf(y.type._context);break;case 22:case 23:Ah()}p=p.return}if(Mn=a,kn=a=si(a.current,null),$n=kr=u,_n=0,Fa=null,Eh=Tc=Ui=0,fr=Ua=null,$i!==null){for(u=0;u<$i.length;u++)if(p=$i[u],y=p.interleaved,y!==null){p.interleaved=null;var S=y.next,N=p.pending;if(N!==null){var R=N.next;N.next=S,y.next=R}p.pending=y}$i=null}return a}function T0(a,u){do{var p=kn;try{if(qf(),vc.current=wc,yc){for(var y=cn.memoizedState;y!==null;){var S=y.queue;S!==null&&(S.pending=null),y=y.next}yc=!1}if(Fi=0,jn=Cn=cn=null,La=!1,Da=0,Sh.current=null,p===null||p.return===null){_n=1,Fa=u,kn=null;break}e:{var N=a,R=p.return,H=p,Y=u;if(u=$n,H.flags|=32768,Y!==null&&typeof Y=="object"&&typeof Y.then=="function"){var ue=Y,_e=H,Ae=_e.tag;if((_e.mode&1)===0&&(Ae===0||Ae===11||Ae===15)){var Ce=_e.alternate;Ce?(_e.updateQueue=Ce.updateQueue,_e.memoizedState=Ce.memoizedState,_e.lanes=Ce.lanes):(_e.updateQueue=null,_e.memoizedState=null)}var Ve=Zb(R);if(Ve!==null){Ve.flags&=-257,e0(Ve,R,H,N,u),Ve.mode&1&&Qb(N,ue,u),u=Ve,Y=ue;var tt=u.updateQueue;if(tt===null){var rt=new Set;rt.add(Y),u.updateQueue=rt}else tt.add(Y);break e}else{if((u&1)===0){Qb(N,ue,u),Rh();break e}Y=Error(n(426))}}else if(sn&&H.mode&1){var xn=Zb(R);if(xn!==null){(xn.flags&65536)===0&&(xn.flags|=256),e0(xn,R,H,N,u),Hf(Do(Y,H));break e}}N=Y=Do(Y,H),_n!==4&&(_n=2),Ua===null?Ua=[N]:Ua.push(N),N=R;do{switch(N.tag){case 3:N.flags|=65536,u&=-u,N.lanes|=u;var ae=Yb(N,Y,u);Sb(N,ae);break e;case 1:H=Y;var Q=N.type,le=N.stateNode;if((N.flags&128)===0&&(typeof Q.getDerivedStateFromError=="function"||le!==null&&typeof le.componentDidCatch=="function"&&(ei===null||!ei.has(le)))){N.flags|=65536,u&=-u,N.lanes|=u;var De=Xb(N,H,u);Sb(N,De);break e}}N=N.return}while(N!==null)}A0(p)}catch(st){u=st,kn===p&&p!==null&&(kn=p=p.return);continue}break}while(!0)}function j0(){var a=_c.current;return _c.current=wc,a===null?wc:a}function Rh(){(_n===0||_n===3||_n===2)&&(_n=4),Mn===null||(Ui&268435455)===0&&(Tc&268435455)===0||ri(Mn,$n)}function Ic(a,u){var p=$t;$t|=2;var y=j0();(Mn!==a||$n!==u)&&(_s=null,Wi(a,u));do try{Hj();break}catch(S){T0(a,S)}while(!0);if(qf(),$t=p,_c.current=y,kn!==null)throw Error(n(261));return Mn=null,$n=0,_n}function Hj(){for(;kn!==null;)M0(kn)}function Wj(){for(;kn!==null&&!_t();)M0(kn)}function M0(a){var u=I0(a.alternate,a,kr);a.memoizedProps=a.pendingProps,u===null?A0(a):kn=u,Sh.current=null}function A0(a){var u=a;do{var p=u.alternate;if(a=u.return,(u.flags&32768)===0){if(p=Dj(p,u,kr),p!==null){kn=p;return}}else{if(p=Pj(p,u),p!==null){p.flags&=32767,kn=p;return}if(a!==null)a.flags|=32768,a.subtreeFlags=0,a.deletions=null;else{_n=6,kn=null;return}}if(u=u.sibling,u!==null){kn=u;return}kn=u=a}while(u!==null);_n===0&&(_n=5)}function qi(a,u,p){var y=Bt,S=Or.transition;try{Or.transition=null,Bt=1,qj(a,u,p,y)}finally{Or.transition=S,Bt=y}return null}function qj(a,u,p,y){do zo();while(ti!==null);if(($t&6)!==0)throw Error(n(327));p=a.finishedWork;var S=a.finishedLanes;if(p===null)return null;if(a.finishedWork=null,a.finishedLanes=0,p===a.current)throw Error(n(177));a.callbackNode=null,a.callbackPriority=0;var N=p.lanes|p.childLanes;if(Tr(a,N),a===Mn&&(kn=Mn=null,$n=0),(p.subtreeFlags&2064)===0&&(p.flags&2064)===0||Mc||(Mc=!0,L0(Vn,function(){return zo(),null})),N=(p.flags&15990)!==0,(p.subtreeFlags&15990)!==0||N){N=Or.transition,Or.transition=null;var R=Bt;Bt=1;var H=$t;$t|=4,Sh.current=null,$j(a,p),w0(p,a),dj(Rf),ql=!!Af,Rf=Af=null,a.current=p,zj(p),Rt(),$t=H,Bt=R,Or.transition=N}else a.current=p;if(Mc&&(Mc=!1,ti=a,Ac=S),N=a.pendingLanes,N===0&&(ei=null),yn(p.stateNode),hr(a,It()),u!==null)for(y=a.onRecoverableError,p=0;p<u.length;p++)S=u[p],y(S.value,{componentStack:S.stack,digest:S.digest});if(jc)throw jc=!1,a=Ch,Ch=null,a;return(Ac&1)!==0&&a.tag!==0&&zo(),N=a.pendingLanes,(N&1)!==0?a===_h?Ha++:(Ha=0,_h=a):Ha=0,Ys(),null}function zo(){if(ti!==null){var a=Et(Ac),u=Or.transition,p=Bt;try{if(Or.transition=null,Bt=16>a?16:a,ti===null)var y=!1;else{if(a=ti,ti=null,Ac=0,($t&6)!==0)throw Error(n(331));var S=$t;for($t|=4,Qe=a.current;Qe!==null;){var N=Qe,R=N.child;if((Qe.flags&16)!==0){var H=N.deletions;if(H!==null){for(var Y=0;Y<H.length;Y++){var ue=H[Y];for(Qe=ue;Qe!==null;){var _e=Qe;switch(_e.tag){case 0:case 11:case 15:za(8,_e,N)}var Ae=_e.child;if(Ae!==null)Ae.return=_e,Qe=Ae;else for(;Qe!==null;){_e=Qe;var Ce=_e.sibling,Ve=_e.return;if(g0(_e),_e===ue){Qe=null;break}if(Ce!==null){Ce.return=Ve,Qe=Ce;break}Qe=Ve}}}var tt=N.alternate;if(tt!==null){var rt=tt.child;if(rt!==null){tt.child=null;do{var xn=rt.sibling;rt.sibling=null,rt=xn}while(rt!==null)}}Qe=N}}if((N.subtreeFlags&2064)!==0&&R!==null)R.return=N,Qe=R;else e:for(;Qe!==null;){if(N=Qe,(N.flags&2048)!==0)switch(N.tag){case 0:case 11:case 15:za(9,N,N.return)}var ae=N.sibling;if(ae!==null){ae.return=N.return,Qe=ae;break e}Qe=N.return}}var Q=a.current;for(Qe=Q;Qe!==null;){R=Qe;var le=R.child;if((R.subtreeFlags&2064)!==0&&le!==null)le.return=R,Qe=le;else e:for(R=Q;Qe!==null;){if(H=Qe,(H.flags&2048)!==0)try{switch(H.tag){case 0:case 11:case 15:Cc(9,H)}}catch(st){fn(H,H.return,st)}if(H===R){Qe=null;break e}var De=H.sibling;if(De!==null){De.return=H.return,Qe=De;break e}Qe=H.return}}if($t=S,Ys(),Ot&&typeof Ot.onPostCommitFiberRoot=="function")try{Ot.onPostCommitFiberRoot(Tt,a)}catch{}y=!0}return y}finally{Bt=p,Or.transition=u}}return!1}function R0(a,u,p){u=Do(p,u),u=Yb(a,u,1),a=Qs(a,u,1),u=ir(),a!==null&&(Hs(a,1,u),hr(a,u))}function fn(a,u,p){if(a.tag===3)R0(a,a,p);else for(;u!==null;){if(u.tag===3){R0(u,a,p);break}else if(u.tag===1){var y=u.stateNode;if(typeof u.type.getDerivedStateFromError=="function"||typeof y.componentDidCatch=="function"&&(ei===null||!ei.has(y))){a=Do(p,a),a=Xb(u,a,1),u=Qs(u,a,1),a=ir(),u!==null&&(Hs(u,1,a),hr(u,a));break}}u=u.return}}function Vj(a,u,p){var y=a.pingCache;y!==null&&y.delete(u),u=ir(),a.pingedLanes|=a.suspendedLanes&p,Mn===a&&($n&p)===p&&(_n===4||_n===3&&($n&130023424)===$n&&500>It()-Nh?Wi(a,0):Eh|=p),hr(a,u)}function O0(a,u){u===0&&((a.mode&1)===0?u=1:(u=Ai,Ai<<=1,(Ai&130023424)===0&&(Ai=4194304)));var p=ir();a=Es(a,u),a!==null&&(Hs(a,u,p),hr(a,p))}function Kj(a){var u=a.memoizedState,p=0;u!==null&&(p=u.retryLane),O0(a,p)}function Gj(a,u){var p=0;switch(a.tag){case 13:var y=a.stateNode,S=a.memoizedState;S!==null&&(p=S.retryLane);break;case 19:y=a.stateNode;break;default:throw Error(n(314))}y!==null&&y.delete(u),O0(a,p)}var I0;I0=function(a,u,p){if(a!==null)if(a.memoizedProps!==u.pendingProps||cr.current)dr=!0;else{if((a.lanes&p)===0&&(u.flags&128)===0)return dr=!1,Lj(a,u,p);dr=(a.flags&131072)!==0}else dr=!1,sn&&(u.flags&1048576)!==0&&hb(u,cc,u.index);switch(u.lanes=0,u.tag){case 2:var y=u.type;Ec(a,u),a=u.pendingProps;var S=To(u,Kn.current);Io(u,p),S=nh(null,u,y,a,S,p);var N=rh();return u.flags|=1,typeof S=="object"&&S!==null&&typeof S.render=="function"&&S.$$typeof===void 0?(u.tag=1,u.memoizedState=null,u.updateQueue=null,ur(y)?(N=!0,oc(u)):N=!1,u.memoizedState=S.state!==null&&S.state!==void 0?S.state:null,Jf(u),S.updater=kc,u.stateNode=S,S._reactInternals=u,ch(u,y,a,p),u=hh(null,u,y,!0,N,p)):(u.tag=0,sn&&N&&$f(u),sr(null,u,S,p),u=u.child),u;case 16:y=u.elementType;e:{switch(Ec(a,u),a=u.pendingProps,S=y._init,y=S(y._payload),u.type=y,S=u.tag=Yj(y),a=Gr(y,a),S){case 0:u=fh(null,u,y,a,p);break e;case 1:u=o0(null,u,y,a,p);break e;case 11:u=t0(null,u,y,a,p);break e;case 14:u=n0(null,u,y,Gr(y.type,a),p);break e}throw Error(n(306,y,""))}return u;case 0:return y=u.type,S=u.pendingProps,S=u.elementType===y?S:Gr(y,S),fh(a,u,y,S,p);case 1:return y=u.type,S=u.pendingProps,S=u.elementType===y?S:Gr(y,S),o0(a,u,y,S,p);case 3:e:{if(a0(u),a===null)throw Error(n(387));y=u.pendingProps,N=u.memoizedState,S=N.element,kb(a,u),mc(u,y,null,p);var R=u.memoizedState;if(y=R.element,N.isDehydrated)if(N={element:y,isDehydrated:!1,cache:R.cache,pendingSuspenseBoundaries:R.pendingSuspenseBoundaries,transitions:R.transitions},u.updateQueue.baseState=N,u.memoizedState=N,u.flags&256){S=Do(Error(n(423)),u),u=l0(a,u,y,p,S);break e}else if(y!==S){S=Do(Error(n(424)),u),u=l0(a,u,y,p,S);break e}else for(wr=Ks(u.stateNode.containerInfo.firstChild),xr=u,sn=!0,Kr=null,p=xb(u,null,y,p),u.child=p;p;)p.flags=p.flags&-3|4096,p=p.sibling;else{if(Ao(),y===S){u=Cs(a,u,p);break e}sr(a,u,y,p)}u=u.child}return u;case 5:return Nb(u),a===null&&Uf(u),y=u.type,S=u.pendingProps,N=a!==null?a.memoizedProps:null,R=S.children,Of(y,S)?R=null:N!==null&&Of(y,N)&&(u.flags|=32),i0(a,u),sr(a,u,R,p),u.child;case 6:return a===null&&Uf(u),null;case 13:return c0(a,u,p);case 4:return Yf(u,u.stateNode.containerInfo),y=u.pendingProps,a===null?u.child=Ro(u,null,y,p):sr(a,u,y,p),u.child;case 11:return y=u.type,S=u.pendingProps,S=u.elementType===y?S:Gr(y,S),t0(a,u,y,S,p);case 7:return sr(a,u,u.pendingProps,p),u.child;case 8:return sr(a,u,u.pendingProps.children,p),u.child;case 12:return sr(a,u,u.pendingProps.children,p),u.child;case 10:e:{if(y=u.type._context,S=u.pendingProps,N=u.memoizedProps,R=S.value,Qt(fc,y._currentValue),y._currentValue=R,N!==null)if(Vr(N.value,R)){if(N.children===S.children&&!cr.current){u=Cs(a,u,p);break e}}else for(N=u.child,N!==null&&(N.return=u);N!==null;){var H=N.dependencies;if(H!==null){R=N.child;for(var Y=H.firstContext;Y!==null;){if(Y.context===y){if(N.tag===1){Y=Ns(-1,p&-p),Y.tag=2;var ue=N.updateQueue;if(ue!==null){ue=ue.shared;var _e=ue.pending;_e===null?Y.next=Y:(Y.next=_e.next,_e.next=Y),ue.pending=Y}}N.lanes|=p,Y=N.alternate,Y!==null&&(Y.lanes|=p),Kf(N.return,p,u),H.lanes|=p;break}Y=Y.next}}else if(N.tag===10)R=N.type===u.type?null:N.child;else if(N.tag===18){if(R=N.return,R===null)throw Error(n(341));R.lanes|=p,H=R.alternate,H!==null&&(H.lanes|=p),Kf(R,p,u),R=N.sibling}else R=N.child;if(R!==null)R.return=N;else for(R=N;R!==null;){if(R===u){R=null;break}if(N=R.sibling,N!==null){N.return=R.return,R=N;break}R=R.return}N=R}sr(a,u,S.children,p),u=u.child}return u;case 9:return S=u.type,y=u.pendingProps.children,Io(u,p),S=Ar(S),y=y(S),u.flags|=1,sr(a,u,y,p),u.child;case 14:return y=u.type,S=Gr(y,u.pendingProps),S=Gr(y.type,S),n0(a,u,y,S,p);case 15:return r0(a,u,u.type,u.pendingProps,p);case 17:return y=u.type,S=u.pendingProps,S=u.elementType===y?S:Gr(y,S),Ec(a,u),u.tag=1,ur(y)?(a=!0,oc(u)):a=!1,Io(u,p),Gb(u,y,S),ch(u,y,S,p),hh(null,u,y,!0,a,p);case 19:return d0(a,u,p);case 22:return s0(a,u,p)}throw Error(n(156,u.tag))};function L0(a,u){return je(a,u)}function Jj(a,u,p,y){this.tag=a,this.key=p,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=u,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=y,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ir(a,u,p,y){return new Jj(a,u,p,y)}function Oh(a){return a=a.prototype,!(!a||!a.isReactComponent)}function Yj(a){if(typeof a=="function")return Oh(a)?1:0;if(a!=null){if(a=a.$$typeof,a===z)return 11;if(a===U)return 14}return 2}function si(a,u){var p=a.alternate;return p===null?(p=Ir(a.tag,u,a.key,a.mode),p.elementType=a.elementType,p.type=a.type,p.stateNode=a.stateNode,p.alternate=a,a.alternate=p):(p.pendingProps=u,p.type=a.type,p.flags=0,p.subtreeFlags=0,p.deletions=null),p.flags=a.flags&14680064,p.childLanes=a.childLanes,p.lanes=a.lanes,p.child=a.child,p.memoizedProps=a.memoizedProps,p.memoizedState=a.memoizedState,p.updateQueue=a.updateQueue,u=a.dependencies,p.dependencies=u===null?null:{lanes:u.lanes,firstContext:u.firstContext},p.sibling=a.sibling,p.index=a.index,p.ref=a.ref,p}function Lc(a,u,p,y,S,N){var R=2;if(y=a,typeof a=="function")Oh(a)&&(R=1);else if(typeof a=="string")R=5;else e:switch(a){case O:return Vi(p.children,S,N,u);case B:R=8,S|=8;break;case $:return a=Ir(12,p,u,S|2),a.elementType=$,a.lanes=N,a;case G:return a=Ir(13,p,u,S),a.elementType=G,a.lanes=N,a;case D:return a=Ir(19,p,u,S),a.elementType=D,a.lanes=N,a;case se:return Dc(p,S,N,u);default:if(typeof a=="object"&&a!==null)switch(a.$$typeof){case W:R=10;break e;case J:R=9;break e;case z:R=11;break e;case U:R=14;break e;case q:R=16,y=null;break e}throw Error(n(130,a==null?a:typeof a,""))}return u=Ir(R,p,u,S),u.elementType=a,u.type=y,u.lanes=N,u}function Vi(a,u,p,y){return a=Ir(7,a,y,u),a.lanes=p,a}function Dc(a,u,p,y){return a=Ir(22,a,y,u),a.elementType=se,a.lanes=p,a.stateNode={isHidden:!1},a}function Ih(a,u,p){return a=Ir(6,a,null,u),a.lanes=p,a}function Lh(a,u,p){return u=Ir(4,a.children!==null?a.children:[],a.key,u),u.lanes=p,u.stateNode={containerInfo:a.containerInfo,pendingChildren:null,implementation:a.implementation},u}function Xj(a,u,p,y,S){this.tag=u,this.containerInfo=a,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Us(0),this.expirationTimes=Us(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Us(0),this.identifierPrefix=y,this.onRecoverableError=S,this.mutableSourceEagerHydrationData=null}function Dh(a,u,p,y,S,N,R,H,Y){return a=new Xj(a,u,p,H,Y),u===1?(u=1,N===!0&&(u|=8)):u=0,N=Ir(3,null,null,u),a.current=N,N.stateNode=a,N.memoizedState={element:y,isDehydrated:p,cache:null,transitions:null,pendingSuspenseBoundaries:null},Jf(N),a}function Qj(a,u,p){var y=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:A,key:y==null?null:""+y,children:a,containerInfo:u,implementation:p}}function D0(a){if(!a)return Js;a=a._reactInternals;e:{if(un(a)!==a||a.tag!==1)throw Error(n(170));var u=a;do{switch(u.tag){case 3:u=u.stateNode.context;break e;case 1:if(ur(u.type)){u=u.stateNode.__reactInternalMemoizedMergedChildContext;break e}}u=u.return}while(u!==null);throw Error(n(171))}if(a.tag===1){var p=a.type;if(ur(p))return ub(a,p,u)}return u}function P0(a,u,p,y,S,N,R,H,Y){return a=Dh(p,y,!0,a,S,N,R,H,Y),a.context=D0(null),p=a.current,y=ir(),S=ni(p),N=Ns(y,S),N.callback=u??null,Qs(p,N,S),a.current.lanes=S,Hs(a,S,y),hr(a,y),a}function Pc(a,u,p,y){var S=u.current,N=ir(),R=ni(S);return p=D0(p),u.context===null?u.context=p:u.pendingContext=p,u=Ns(N,R),u.payload={element:a},y=y===void 0?null:y,y!==null&&(u.callback=y),a=Qs(S,u,R),a!==null&&(Xr(a,S,R,N),pc(a,S,R)),R}function Bc(a){if(a=a.current,!a.child)return null;switch(a.child.tag){case 5:return a.child.stateNode;default:return a.child.stateNode}}function B0(a,u){if(a=a.memoizedState,a!==null&&a.dehydrated!==null){var p=a.retryLane;a.retryLane=p!==0&&p<u?p:u}}function Ph(a,u){B0(a,u),(a=a.alternate)&&B0(a,u)}function Zj(){return null}var $0=typeof reportError=="function"?reportError:function(a){console.error(a)};function Bh(a){this._internalRoot=a}$c.prototype.render=Bh.prototype.render=function(a){var u=this._internalRoot;if(u===null)throw Error(n(409));Pc(a,u,null,null)},$c.prototype.unmount=Bh.prototype.unmount=function(){var a=this._internalRoot;if(a!==null){this._internalRoot=null;var u=a.containerInfo;Hi(function(){Pc(null,a,null,null)}),u[xs]=null}};function $c(a){this._internalRoot=a}$c.prototype.unstable_scheduleHydration=function(a){if(a){var u=Oi();a={blockedOn:null,target:a,priority:u};for(var p=0;p<Tn.length&&u!==0&&u<Tn[p].priority;p++);Tn.splice(p,0,a),p===0&&Ny(a)}};function $h(a){return!(!a||a.nodeType!==1&&a.nodeType!==9&&a.nodeType!==11)}function zc(a){return!(!a||a.nodeType!==1&&a.nodeType!==9&&a.nodeType!==11&&(a.nodeType!==8||a.nodeValue!==" react-mount-point-unstable "))}function z0(){}function eM(a,u,p,y,S){if(S){if(typeof y=="function"){var N=y;y=function(){var ue=Bc(R);N.call(ue)}}var R=P0(u,y,a,0,null,!1,!1,"",z0);return a._reactRootContainer=R,a[xs]=R.current,_a(a.nodeType===8?a.parentNode:a),Hi(),R}for(;S=a.lastChild;)a.removeChild(S);if(typeof y=="function"){var H=y;y=function(){var ue=Bc(Y);H.call(ue)}}var Y=Dh(a,0,!1,null,null,!1,!1,"",z0);return a._reactRootContainer=Y,a[xs]=Y.current,_a(a.nodeType===8?a.parentNode:a),Hi(function(){Pc(u,Y,p,y)}),Y}function Fc(a,u,p,y,S){var N=p._reactRootContainer;if(N){var R=N;if(typeof S=="function"){var H=S;S=function(){var Y=Bc(R);H.call(Y)}}Pc(u,R,a,S)}else R=eM(p,u,a,S,y);return Bc(R)}ma=function(a){switch(a.tag){case 3:var u=a.stateNode;if(u.current.memoizedState.isDehydrated){var p=Fs(u.pendingLanes);p!==0&&(pa(u,p|1),hr(u,It()),($t&6)===0&&($o=It()+500,Ys()))}break;case 13:Hi(function(){var y=Es(a,1);if(y!==null){var S=ir();Xr(y,a,1,S)}}),Ph(a,1)}},bn=function(a){if(a.tag===13){var u=Es(a,134217728);if(u!==null){var p=ir();Xr(u,a,134217728,p)}Ph(a,134217728)}},Gt=function(a){if(a.tag===13){var u=ni(a),p=Es(a,u);if(p!==null){var y=ir();Xr(p,a,u,y)}Ph(a,u)}},Oi=function(){return Bt},ls=function(a,u){var p=Bt;try{return Bt=a,u()}finally{Bt=p}},qe=function(a,u,p){switch(u){case"input":if(mt(a,p),u=p.name,p.type==="radio"&&u!=null){for(p=a;p.parentNode;)p=p.parentNode;for(p=p.querySelectorAll("input[name="+JSON.stringify(""+u)+'][type="radio"]'),u=0;u<p.length;u++){var y=p[u];if(y!==a&&y.form===a.form){var S=sc(y);if(!S)throw Error(n(90));Oe(y),mt(y,S)}}}break;case"textarea":X(a,p);break;case"select":u=p.value,u!=null&&ht(a,!!p.multiple,u,!1)}},I=Mh,re=Hi;var tM={usingClientEntryPoint:!1,Events:[Ma,Co,sc,P,Z,Mh]},Wa={findFiberByHostInstance:Li,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},nM={bundleType:Wa.bundleType,version:Wa.version,rendererPackageName:Wa.rendererPackageName,rendererConfig:Wa.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:j.ReactCurrentDispatcher,findHostInstanceByFiber:function(a){return a=is(a),a===null?null:a.stateNode},findFiberByHostInstance:Wa.findFiberByHostInstance||Zj,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var Uc=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Uc.isDisabled&&Uc.supportsFiber)try{Tt=Uc.inject(nM),Ot=Uc}catch{}}return pr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=tM,pr.createPortal=function(a,u){var p=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!$h(u))throw Error(n(200));return Qj(a,u,null,p)},pr.createRoot=function(a,u){if(!$h(a))throw Error(n(299));var p=!1,y="",S=$0;return u!=null&&(u.unstable_strictMode===!0&&(p=!0),u.identifierPrefix!==void 0&&(y=u.identifierPrefix),u.onRecoverableError!==void 0&&(S=u.onRecoverableError)),u=Dh(a,1,!1,null,null,p,!1,y,S),a[xs]=u.current,_a(a.nodeType===8?a.parentNode:a),new Bh(u)},pr.findDOMNode=function(a){if(a==null)return null;if(a.nodeType===1)return a;var u=a._reactInternals;if(u===void 0)throw typeof a.render=="function"?Error(n(188)):(a=Object.keys(a).join(","),Error(n(268,a)));return a=is(u),a=a===null?null:a.stateNode,a},pr.flushSync=function(a){return Hi(a)},pr.hydrate=function(a,u,p){if(!zc(u))throw Error(n(200));return Fc(null,a,u,!0,p)},pr.hydrateRoot=function(a,u,p){if(!$h(a))throw Error(n(405));var y=p!=null&&p.hydratedSources||null,S=!1,N="",R=$0;if(p!=null&&(p.unstable_strictMode===!0&&(S=!0),p.identifierPrefix!==void 0&&(N=p.identifierPrefix),p.onRecoverableError!==void 0&&(R=p.onRecoverableError)),u=P0(u,null,a,1,p??null,S,!1,N,R),a[xs]=u.current,_a(a),y)for(a=0;a<y.length;a++)p=y[a],S=p._getVersion,S=S(p._source),u.mutableSourceEagerHydrationData==null?u.mutableSourceEagerHydrationData=[p,S]:u.mutableSourceEagerHydrationData.push(p,S);return new $c(u)},pr.render=function(a,u,p){if(!zc(u))throw Error(n(200));return Fc(null,a,u,!1,p)},pr.unmountComponentAtNode=function(a){if(!zc(a))throw Error(n(40));return a._reactRootContainer?(Hi(function(){Fc(null,null,a,!1,function(){a._reactRootContainer=null,a[xs]=null})}),!0):!1},pr.unstable_batchedUpdates=Mh,pr.unstable_renderSubtreeIntoContainer=function(a,u,p,y){if(!zc(p))throw Error(n(200));if(a==null||a._reactInternals===void 0)throw Error(n(38));return Fc(a,u,p,!1,y)},pr.version="18.3.1-next-f1338f8080-20240426",pr}var J0;function vE(){if(J0)return Uh.exports;J0=1;function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(e){console.error(e)}}return t(),Uh.exports=cM(),Uh.exports}var Y0;function uM(){if(Y0)return Hc;Y0=1;var t=vE();return Hc.createRoot=t.createRoot,Hc.hydrateRoot=t.hydrateRoot,Hc}var dM=uM();const fM=jl(dM),yE=[{id:"charter",label:"Charter",description:"Charter serif"},{id:"source-serif",label:"Source Serif",description:"Source Serif 4"},{id:"plex-mono",label:"Plex Mono",description:"IBM Plex Mono"},{id:"crimson",label:"Crimson",description:"Crimson Pro"},{id:"inter",label:"Inter",description:"Inter sans-serif"},{id:"baskerville",label:"Baskerville",description:"Libre Baskerville"},{id:"grotesk",label:"Grotesk",description:"Space Grotesk"},{id:"literata",label:"Literata",description:"Literata serif"},{id:"dm-sans",label:"DM Sans",description:"DM Sans + Serif"}],bE=[{id:"files",label:"Files",icon:"files"},{id:"default",label:"Tree",icon:"tree"},{id:"timeline",label:"Timeline",icon:"timeline"},{id:"board",label:"Board",icon:"board"}],xE=[{id:"seamless",label:"Seamless"},{id:"outline",label:"Outline"},{id:"page",label:"Page"},{id:"paper",label:"Paper"}],wE=[{id:"default",label:"Default"},{id:"web",label:"Web"},{id:"blog",label:"Blog"},{id:"butterick",label:"Butterick"}],hM=["full","compact","minimal"],Un={typeface:"ow-typeface",mode:"ow-theme-mode",sidebarMode:"ow-sidebar-mode",sidebarStyle:"ow-sidebar-style",sidebarDensity:"ow-sidebar-density",spacing:"ow-spacing",canvas:"ow-canvas"},pM={ink:"charter",novel:"source-serif",mono:"plex-mono",editorial:"crimson",studio:"inter",prose:"baskerville"};function mM(){const t=localStorage.getItem("ow-theme");if(t&&!localStorage.getItem(Un.typeface)){const n=pM[t];n&&localStorage.setItem(Un.typeface,n),localStorage.removeItem("ow-theme")}localStorage.removeItem("ow-color");const e=localStorage.getItem("ow-typography");e&&!localStorage.getItem(Un.spacing)&&(localStorage.setItem(Un.spacing,e),localStorage.removeItem("ow-typography"))}function kE(){const t=localStorage.getItem(Un.typeface);return t&&yE.some(e=>e.id===t)?t:"charter"}function SE(){const t=localStorage.getItem(Un.mode);return t==="light"||t==="dark"?t:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Rd(){const t=localStorage.getItem(Un.sidebarMode);return t&&bE.some(e=>e.id===t)?t:"files"}function EE(){return"cards"}function NE(){const t=localStorage.getItem(Un.sidebarDensity);return t&&hM.includes(t)?t:"full"}function gM(t){localStorage.setItem(Un.sidebarDensity,t),document.documentElement.setAttribute("data-sidebar-density",t)}function CE(){const t=localStorage.getItem(Un.spacing);return t&&wE.some(e=>e.id===t)?t:"default"}function _E(){const t=localStorage.getItem(Un.canvas);return t&&xE.some(e=>e.id===t)?t:"seamless"}function TE(t,e,n,r,s="default",i="seamless"){const o=document.documentElement;o.setAttribute("data-typeface",t),o.setAttribute("data-mode",e),o.setAttribute("data-sidebar-mode",n),o.setAttribute("data-sidebar-style",r),s==="default"?o.removeAttribute("data-spacing"):o.setAttribute("data-spacing",s),i==="seamless"?o.removeAttribute("data-canvas"):o.setAttribute("data-canvas",i),o.removeAttribute("data-color"),localStorage.setItem(Un.typeface,t),localStorage.setItem(Un.mode,e),localStorage.setItem(Un.sidebarMode,n),localStorage.setItem(Un.sidebarStyle,r),localStorage.setItem(Un.spacing,s),localStorage.setItem(Un.canvas,i)}function vM(){mM(),TE(kE(),SE(),Rd(),EE(),CE(),_E()),document.documentElement.setAttribute("data-sidebar-density",NE())}var jE=vE();const yM=jl(jE);var qh={exports:{}},Vh={};/**
40
+ `+N.stack}return{value:a,source:u,stack:S,digest:null}}function uh(a,u,p){return{value:a,source:null,stack:p??null,digest:u??null}}function dh(a,u){try{console.error(u.value)}catch(p){setTimeout(function(){throw p})}}var Rj=typeof WeakMap=="function"?WeakMap:Map;function Yb(a,u,p){p=Ns(-1,p),p.tag=3,p.payload={element:null};var y=u.value;return p.callback=function(){jc||(jc=!0,Ch=y),dh(a,u)},p}function Xb(a,u,p){p=Ns(-1,p),p.tag=3;var y=a.type.getDerivedStateFromError;if(typeof y=="function"){var S=u.value;p.payload=function(){return y(S)},p.callback=function(){dh(a,u)}}var N=a.stateNode;return N!==null&&typeof N.componentDidCatch=="function"&&(p.callback=function(){dh(a,u),typeof y!="function"&&(ei===null?ei=new Set([this]):ei.add(this));var R=u.stack;this.componentDidCatch(u.value,{componentStack:R!==null?R:""})}),p}function Qb(a,u,p){var y=a.pingCache;if(y===null){y=a.pingCache=new Rj;var S=new Set;y.set(u,S)}else S=y.get(u),S===void 0&&(S=new Set,y.set(u,S));S.has(p)||(S.add(p),a=Vj.bind(null,a,u,p),u.then(a,a))}function Zb(a){do{var u;if((u=a.tag===13)&&(u=a.memoizedState,u=u!==null?u.dehydrated!==null:!0),u)return a;a=a.return}while(a!==null);return null}function e0(a,u,p,y,S){return(a.mode&1)===0?(a===u?a.flags|=65536:(a.flags|=128,p.flags|=131072,p.flags&=-52805,p.tag===1&&(p.alternate===null?p.tag=17:(u=Ns(-1,1),u.tag=2,Qs(p,u,1))),p.lanes|=1),a):(a.flags|=65536,a.lanes=S,a)}var Oj=j.ReactCurrentOwner,dr=!1;function sr(a,u,p,y){u.child=a===null?xb(u,null,p,y):Ro(u,a.child,p,y)}function t0(a,u,p,y,S){p=p.render;var N=u.ref;return Io(u,S),y=nh(a,u,p,y,N,S),p=rh(),a!==null&&!dr?(u.updateQueue=a.updateQueue,u.flags&=-2053,a.lanes&=~S,Cs(a,u,S)):(sn&&p&&$f(u),u.flags|=1,sr(a,u,y,S),u.child)}function n0(a,u,p,y,S){if(a===null){var N=p.type;return typeof N=="function"&&!Oh(N)&&N.defaultProps===void 0&&p.compare===null&&p.defaultProps===void 0?(u.tag=15,u.type=N,r0(a,u,N,y,S)):(a=Lc(p.type,null,y,u,u.mode,S),a.ref=u.ref,a.return=u,u.child=a)}if(N=a.child,(a.lanes&S)===0){var R=N.memoizedProps;if(p=p.compare,p=p!==null?p:Ea,p(R,y)&&a.ref===u.ref)return Cs(a,u,S)}return u.flags|=1,a=si(N,y),a.ref=u.ref,a.return=u,u.child=a}function r0(a,u,p,y,S){if(a!==null){var N=a.memoizedProps;if(Ea(N,y)&&a.ref===u.ref)if(dr=!1,u.pendingProps=y=N,(a.lanes&S)!==0)(a.flags&131072)!==0&&(dr=!0);else return u.lanes=a.lanes,Cs(a,u,S)}return fh(a,u,p,y,S)}function s0(a,u,p){var y=u.pendingProps,S=y.children,N=a!==null?a.memoizedState:null;if(y.mode==="hidden")if((u.mode&1)===0)u.memoizedState={baseLanes:0,cachePool:null,transitions:null},Qt(Bo,kr),kr|=p;else{if((p&1073741824)===0)return a=N!==null?N.baseLanes|p:p,u.lanes=u.childLanes=1073741824,u.memoizedState={baseLanes:a,cachePool:null,transitions:null},u.updateQueue=null,Qt(Bo,kr),kr|=a,null;u.memoizedState={baseLanes:0,cachePool:null,transitions:null},y=N!==null?N.baseLanes:p,Qt(Bo,kr),kr|=y}else N!==null?(y=N.baseLanes|p,u.memoizedState=null):y=p,Qt(Bo,kr),kr|=y;return sr(a,u,S,p),u.child}function i0(a,u){var p=u.ref;(a===null&&p!==null||a!==null&&a.ref!==p)&&(u.flags|=512,u.flags|=2097152)}function fh(a,u,p,y,S){var N=ur(p)?Di:Kn.current;return N=To(u,N),Io(u,S),p=nh(a,u,p,y,N,S),y=rh(),a!==null&&!dr?(u.updateQueue=a.updateQueue,u.flags&=-2053,a.lanes&=~S,Cs(a,u,S)):(sn&&y&&$f(u),u.flags|=1,sr(a,u,p,S),u.child)}function o0(a,u,p,y,S){if(ur(p)){var N=!0;oc(u)}else N=!1;if(Io(u,S),u.stateNode===null)Ec(a,u),Gb(u,p,y),ch(u,p,y,S),y=!0;else if(a===null){var R=u.stateNode,H=u.memoizedProps;R.props=H;var Y=R.context,ue=p.contextType;typeof ue=="object"&&ue!==null?ue=Ar(ue):(ue=ur(p)?Di:Kn.current,ue=To(u,ue));var _e=p.getDerivedStateFromProps,Ae=typeof _e=="function"||typeof R.getSnapshotBeforeUpdate=="function";Ae||typeof R.UNSAFE_componentWillReceiveProps!="function"&&typeof R.componentWillReceiveProps!="function"||(H!==y||Y!==ue)&&Jb(u,R,y,ue),Xs=!1;var Ce=u.memoizedState;R.state=Ce,mc(u,y,R,S),Y=u.memoizedState,H!==y||Ce!==Y||cr.current||Xs?(typeof _e=="function"&&(lh(u,p,_e,y),Y=u.memoizedState),(H=Xs||Kb(u,p,H,y,Ce,Y,ue))?(Ae||typeof R.UNSAFE_componentWillMount!="function"&&typeof R.componentWillMount!="function"||(typeof R.componentWillMount=="function"&&R.componentWillMount(),typeof R.UNSAFE_componentWillMount=="function"&&R.UNSAFE_componentWillMount()),typeof R.componentDidMount=="function"&&(u.flags|=4194308)):(typeof R.componentDidMount=="function"&&(u.flags|=4194308),u.memoizedProps=y,u.memoizedState=Y),R.props=y,R.state=Y,R.context=ue,y=H):(typeof R.componentDidMount=="function"&&(u.flags|=4194308),y=!1)}else{R=u.stateNode,kb(a,u),H=u.memoizedProps,ue=u.type===u.elementType?H:Gr(u.type,H),R.props=ue,Ae=u.pendingProps,Ce=R.context,Y=p.contextType,typeof Y=="object"&&Y!==null?Y=Ar(Y):(Y=ur(p)?Di:Kn.current,Y=To(u,Y));var Ve=p.getDerivedStateFromProps;(_e=typeof Ve=="function"||typeof R.getSnapshotBeforeUpdate=="function")||typeof R.UNSAFE_componentWillReceiveProps!="function"&&typeof R.componentWillReceiveProps!="function"||(H!==Ae||Ce!==Y)&&Jb(u,R,y,Y),Xs=!1,Ce=u.memoizedState,R.state=Ce,mc(u,y,R,S);var tt=u.memoizedState;H!==Ae||Ce!==tt||cr.current||Xs?(typeof Ve=="function"&&(lh(u,p,Ve,y),tt=u.memoizedState),(ue=Xs||Kb(u,p,ue,y,Ce,tt,Y)||!1)?(_e||typeof R.UNSAFE_componentWillUpdate!="function"&&typeof R.componentWillUpdate!="function"||(typeof R.componentWillUpdate=="function"&&R.componentWillUpdate(y,tt,Y),typeof R.UNSAFE_componentWillUpdate=="function"&&R.UNSAFE_componentWillUpdate(y,tt,Y)),typeof R.componentDidUpdate=="function"&&(u.flags|=4),typeof R.getSnapshotBeforeUpdate=="function"&&(u.flags|=1024)):(typeof R.componentDidUpdate!="function"||H===a.memoizedProps&&Ce===a.memoizedState||(u.flags|=4),typeof R.getSnapshotBeforeUpdate!="function"||H===a.memoizedProps&&Ce===a.memoizedState||(u.flags|=1024),u.memoizedProps=y,u.memoizedState=tt),R.props=y,R.state=tt,R.context=Y,y=ue):(typeof R.componentDidUpdate!="function"||H===a.memoizedProps&&Ce===a.memoizedState||(u.flags|=4),typeof R.getSnapshotBeforeUpdate!="function"||H===a.memoizedProps&&Ce===a.memoizedState||(u.flags|=1024),y=!1)}return hh(a,u,p,y,N,S)}function hh(a,u,p,y,S,N){i0(a,u);var R=(u.flags&128)!==0;if(!y&&!R)return S&&db(u,p,!1),Cs(a,u,N);y=u.stateNode,Oj.current=u;var H=R&&typeof p.getDerivedStateFromError!="function"?null:y.render();return u.flags|=1,a!==null&&R?(u.child=Ro(u,a.child,null,N),u.child=Ro(u,null,H,N)):sr(a,u,H,N),u.memoizedState=y.state,S&&db(u,p,!0),u.child}function a0(a){var u=a.stateNode;u.pendingContext?cb(a,u.pendingContext,u.pendingContext!==u.context):u.context&&cb(a,u.context,!1),Yf(a,u.containerInfo)}function l0(a,u,p,y,S){return Ao(),Hf(S),u.flags|=256,sr(a,u,p,y),u.child}var ph={dehydrated:null,treeContext:null,retryLane:0};function mh(a){return{baseLanes:a,cachePool:null,transitions:null}}function c0(a,u,p){var y=u.pendingProps,S=ln.current,N=!1,R=(u.flags&128)!==0,H;if((H=R)||(H=a!==null&&a.memoizedState===null?!1:(S&2)!==0),H?(N=!0,u.flags&=-129):(a===null||a.memoizedState!==null)&&(S|=1),Qt(ln,S&1),a===null)return Uf(u),a=u.memoizedState,a!==null&&(a=a.dehydrated,a!==null)?((u.mode&1)===0?u.lanes=1:a.data==="$!"?u.lanes=8:u.lanes=1073741824,null):(R=y.children,a=y.fallback,N?(y=u.mode,N=u.child,R={mode:"hidden",children:R},(y&1)===0&&N!==null?(N.childLanes=0,N.pendingProps=R):N=Dc(R,y,0,null),a=Vi(a,y,p,null),N.return=u,a.return=u,N.sibling=a,u.child=N,u.child.memoizedState=mh(p),u.memoizedState=ph,a):gh(u,R));if(S=a.memoizedState,S!==null&&(H=S.dehydrated,H!==null))return Ij(a,u,R,y,H,S,p);if(N){N=y.fallback,R=u.mode,S=a.child,H=S.sibling;var Y={mode:"hidden",children:y.children};return(R&1)===0&&u.child!==S?(y=u.child,y.childLanes=0,y.pendingProps=Y,u.deletions=null):(y=si(S,Y),y.subtreeFlags=S.subtreeFlags&14680064),H!==null?N=si(H,N):(N=Vi(N,R,p,null),N.flags|=2),N.return=u,y.return=u,y.sibling=N,u.child=y,y=N,N=u.child,R=a.child.memoizedState,R=R===null?mh(p):{baseLanes:R.baseLanes|p,cachePool:null,transitions:R.transitions},N.memoizedState=R,N.childLanes=a.childLanes&~p,u.memoizedState=ph,y}return N=a.child,a=N.sibling,y=si(N,{mode:"visible",children:y.children}),(u.mode&1)===0&&(y.lanes=p),y.return=u,y.sibling=null,a!==null&&(p=u.deletions,p===null?(u.deletions=[a],u.flags|=16):p.push(a)),u.child=y,u.memoizedState=null,y}function gh(a,u){return u=Dc({mode:"visible",children:u},a.mode,0,null),u.return=a,a.child=u}function Sc(a,u,p,y){return y!==null&&Hf(y),Ro(u,a.child,null,p),a=gh(u,u.pendingProps.children),a.flags|=2,u.memoizedState=null,a}function Ij(a,u,p,y,S,N,R){if(p)return u.flags&256?(u.flags&=-257,y=uh(Error(n(422))),Sc(a,u,R,y)):u.memoizedState!==null?(u.child=a.child,u.flags|=128,null):(N=y.fallback,S=u.mode,y=Dc({mode:"visible",children:y.children},S,0,null),N=Vi(N,S,R,null),N.flags|=2,y.return=u,N.return=u,y.sibling=N,u.child=y,(u.mode&1)!==0&&Ro(u,a.child,null,R),u.child.memoizedState=mh(R),u.memoizedState=ph,N);if((u.mode&1)===0)return Sc(a,u,R,null);if(S.data==="$!"){if(y=S.nextSibling&&S.nextSibling.dataset,y)var H=y.dgst;return y=H,N=Error(n(419)),y=uh(N,y,void 0),Sc(a,u,R,y)}if(H=(R&a.childLanes)!==0,dr||H){if(y=Mn,y!==null){switch(R&-R){case 4:S=2;break;case 16:S=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:S=32;break;case 536870912:S=268435456;break;default:S=0}S=(S&(y.suspendedLanes|R))!==0?0:S,S!==0&&S!==N.retryLane&&(N.retryLane=S,Es(a,S),Xr(y,a,S,-1))}return Rh(),y=uh(Error(n(421))),Sc(a,u,R,y)}return S.data==="$?"?(u.flags|=128,u.child=a.child,u=Kj.bind(null,a),S._reactRetry=u,null):(a=N.treeContext,wr=Ks(S.nextSibling),xr=u,sn=!0,Kr=null,a!==null&&(jr[Mr++]=ks,jr[Mr++]=Ss,jr[Mr++]=Pi,ks=a.id,Ss=a.overflow,Pi=u),u=gh(u,y.children),u.flags|=4096,u)}function u0(a,u,p){a.lanes|=u;var y=a.alternate;y!==null&&(y.lanes|=u),Kf(a.return,u,p)}function vh(a,u,p,y,S){var N=a.memoizedState;N===null?a.memoizedState={isBackwards:u,rendering:null,renderingStartTime:0,last:y,tail:p,tailMode:S}:(N.isBackwards=u,N.rendering=null,N.renderingStartTime=0,N.last=y,N.tail=p,N.tailMode=S)}function d0(a,u,p){var y=u.pendingProps,S=y.revealOrder,N=y.tail;if(sr(a,u,y.children,p),y=ln.current,(y&2)!==0)y=y&1|2,u.flags|=128;else{if(a!==null&&(a.flags&128)!==0)e:for(a=u.child;a!==null;){if(a.tag===13)a.memoizedState!==null&&u0(a,p,u);else if(a.tag===19)u0(a,p,u);else if(a.child!==null){a.child.return=a,a=a.child;continue}if(a===u)break e;for(;a.sibling===null;){if(a.return===null||a.return===u)break e;a=a.return}a.sibling.return=a.return,a=a.sibling}y&=1}if(Qt(ln,y),(u.mode&1)===0)u.memoizedState=null;else switch(S){case"forwards":for(p=u.child,S=null;p!==null;)a=p.alternate,a!==null&&gc(a)===null&&(S=p),p=p.sibling;p=S,p===null?(S=u.child,u.child=null):(S=p.sibling,p.sibling=null),vh(u,!1,S,p,N);break;case"backwards":for(p=null,S=u.child,u.child=null;S!==null;){if(a=S.alternate,a!==null&&gc(a)===null){u.child=S;break}a=S.sibling,S.sibling=p,p=S,S=a}vh(u,!0,p,null,N);break;case"together":vh(u,!1,null,null,void 0);break;default:u.memoizedState=null}return u.child}function Ec(a,u){(u.mode&1)===0&&a!==null&&(a.alternate=null,u.alternate=null,u.flags|=2)}function Cs(a,u,p){if(a!==null&&(u.dependencies=a.dependencies),Ui|=u.lanes,(p&u.childLanes)===0)return null;if(a!==null&&u.child!==a.child)throw Error(n(153));if(u.child!==null){for(a=u.child,p=si(a,a.pendingProps),u.child=p,p.return=u;a.sibling!==null;)a=a.sibling,p=p.sibling=si(a,a.pendingProps),p.return=u;p.sibling=null}return u.child}function Lj(a,u,p){switch(u.tag){case 3:a0(u),Ao();break;case 5:Nb(u);break;case 1:ur(u.type)&&oc(u);break;case 4:Yf(u,u.stateNode.containerInfo);break;case 10:var y=u.type._context,S=u.memoizedProps.value;Qt(fc,y._currentValue),y._currentValue=S;break;case 13:if(y=u.memoizedState,y!==null)return y.dehydrated!==null?(Qt(ln,ln.current&1),u.flags|=128,null):(p&u.child.childLanes)!==0?c0(a,u,p):(Qt(ln,ln.current&1),a=Cs(a,u,p),a!==null?a.sibling:null);Qt(ln,ln.current&1);break;case 19:if(y=(p&u.childLanes)!==0,(a.flags&128)!==0){if(y)return d0(a,u,p);u.flags|=128}if(S=u.memoizedState,S!==null&&(S.rendering=null,S.tail=null,S.lastEffect=null),Qt(ln,ln.current),y)break;return null;case 22:case 23:return u.lanes=0,s0(a,u,p)}return Cs(a,u,p)}var f0,yh,h0,p0;f0=function(a,u){for(var p=u.child;p!==null;){if(p.tag===5||p.tag===6)a.appendChild(p.stateNode);else if(p.tag!==4&&p.child!==null){p.child.return=p,p=p.child;continue}if(p===u)break;for(;p.sibling===null;){if(p.return===null||p.return===u)return;p=p.return}p.sibling.return=p.return,p=p.sibling}},yh=function(){},h0=function(a,u,p,y){var S=a.memoizedProps;if(S!==y){a=u.stateNode,zi(us.current);var N=null;switch(p){case"input":S=pt(a,S),y=pt(a,y),N=[];break;case"select":S=K({},S,{value:void 0}),y=K({},y,{value:void 0}),N=[];break;case"textarea":S=Fe(a,S),y=Fe(a,y),N=[];break;default:typeof S.onClick!="function"&&typeof y.onClick=="function"&&(a.onclick=rc)}gt(p,y);var R;p=null;for(ue in S)if(!y.hasOwnProperty(ue)&&S.hasOwnProperty(ue)&&S[ue]!=null)if(ue==="style"){var H=S[ue];for(R in H)H.hasOwnProperty(R)&&(p||(p={}),p[R]="")}else ue!=="dangerouslySetInnerHTML"&&ue!=="children"&&ue!=="suppressContentEditableWarning"&&ue!=="suppressHydrationWarning"&&ue!=="autoFocus"&&(s.hasOwnProperty(ue)?N||(N=[]):(N=N||[]).push(ue,null));for(ue in y){var Y=y[ue];if(H=S!=null?S[ue]:void 0,y.hasOwnProperty(ue)&&Y!==H&&(Y!=null||H!=null))if(ue==="style")if(H){for(R in H)!H.hasOwnProperty(R)||Y&&Y.hasOwnProperty(R)||(p||(p={}),p[R]="");for(R in Y)Y.hasOwnProperty(R)&&H[R]!==Y[R]&&(p||(p={}),p[R]=Y[R])}else p||(N||(N=[]),N.push(ue,p)),p=Y;else ue==="dangerouslySetInnerHTML"?(Y=Y?Y.__html:void 0,H=H?H.__html:void 0,Y!=null&&H!==Y&&(N=N||[]).push(ue,Y)):ue==="children"?typeof Y!="string"&&typeof Y!="number"||(N=N||[]).push(ue,""+Y):ue!=="suppressContentEditableWarning"&&ue!=="suppressHydrationWarning"&&(s.hasOwnProperty(ue)?(Y!=null&&ue==="onScroll"&&tn("scroll",a),N||H===Y||(N=[])):(N=N||[]).push(ue,Y))}p&&(N=N||[]).push("style",p);var ue=N;(u.updateQueue=ue)&&(u.flags|=4)}},p0=function(a,u,p,y){p!==y&&(u.flags|=4)};function $a(a,u){if(!sn)switch(a.tailMode){case"hidden":u=a.tail;for(var p=null;u!==null;)u.alternate!==null&&(p=u),u=u.sibling;p===null?a.tail=null:p.sibling=null;break;case"collapsed":p=a.tail;for(var y=null;p!==null;)p.alternate!==null&&(y=p),p=p.sibling;y===null?u||a.tail===null?a.tail=null:a.tail.sibling=null:y.sibling=null}}function Jn(a){var u=a.alternate!==null&&a.alternate.child===a.child,p=0,y=0;if(u)for(var S=a.child;S!==null;)p|=S.lanes|S.childLanes,y|=S.subtreeFlags&14680064,y|=S.flags&14680064,S.return=a,S=S.sibling;else for(S=a.child;S!==null;)p|=S.lanes|S.childLanes,y|=S.subtreeFlags,y|=S.flags,S.return=a,S=S.sibling;return a.subtreeFlags|=y,a.childLanes=p,u}function Dj(a,u,p){var y=u.pendingProps;switch(zf(u),u.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Jn(u),null;case 1:return ur(u.type)&&ic(),Jn(u),null;case 3:return y=u.stateNode,Lo(),nn(cr),nn(Kn),Zf(),y.pendingContext&&(y.context=y.pendingContext,y.pendingContext=null),(a===null||a.child===null)&&(uc(u)?u.flags|=4:a===null||a.memoizedState.isDehydrated&&(u.flags&256)===0||(u.flags|=1024,Kr!==null&&(jh(Kr),Kr=null))),yh(a,u),Jn(u),null;case 5:Xf(u);var S=zi(Ia.current);if(p=u.type,a!==null&&u.stateNode!=null)h0(a,u,p,y,S),a.ref!==u.ref&&(u.flags|=512,u.flags|=2097152);else{if(!y){if(u.stateNode===null)throw Error(n(166));return Jn(u),null}if(a=zi(us.current),uc(u)){y=u.stateNode,p=u.type;var N=u.memoizedProps;switch(y[cs]=u,y[ja]=N,a=(u.mode&1)!==0,p){case"dialog":tn("cancel",y),tn("close",y);break;case"iframe":case"object":case"embed":tn("load",y);break;case"video":case"audio":for(S=0;S<Ca.length;S++)tn(Ca[S],y);break;case"source":tn("error",y);break;case"img":case"image":case"link":tn("error",y),tn("load",y);break;case"details":tn("toggle",y);break;case"input":Je(y,N),tn("invalid",y);break;case"select":y._wrapperState={wasMultiple:!!N.multiple},tn("invalid",y);break;case"textarea":ve(y,N),tn("invalid",y)}gt(p,N),S=null;for(var R in N)if(N.hasOwnProperty(R)){var H=N[R];R==="children"?typeof H=="string"?y.textContent!==H&&(N.suppressHydrationWarning!==!0&&nc(y.textContent,H,a),S=["children",H]):typeof H=="number"&&y.textContent!==""+H&&(N.suppressHydrationWarning!==!0&&nc(y.textContent,H,a),S=["children",""+H]):s.hasOwnProperty(R)&&H!=null&&R==="onScroll"&&tn("scroll",y)}switch(p){case"input":Ze(y),ft(y,N,!0);break;case"textarea":Ze(y),Be(y);break;case"select":case"option":break;default:typeof N.onClick=="function"&&(y.onclick=rc)}y=S,u.updateQueue=y,y!==null&&(u.flags|=4)}else{R=S.nodeType===9?S:S.ownerDocument,a==="http://www.w3.org/1999/xhtml"&&(a=ne(p)),a==="http://www.w3.org/1999/xhtml"?p==="script"?(a=R.createElement("div"),a.innerHTML="<script><\/script>",a=a.removeChild(a.firstChild)):typeof y.is=="string"?a=R.createElement(p,{is:y.is}):(a=R.createElement(p),p==="select"&&(R=a,y.multiple?R.multiple=!0:y.size&&(R.size=y.size))):a=R.createElementNS(a,p),a[cs]=u,a[ja]=y,f0(a,u,!1,!1),u.stateNode=a;e:{switch(R=Nt(p,y),p){case"dialog":tn("cancel",a),tn("close",a),S=y;break;case"iframe":case"object":case"embed":tn("load",a),S=y;break;case"video":case"audio":for(S=0;S<Ca.length;S++)tn(Ca[S],a);S=y;break;case"source":tn("error",a),S=y;break;case"img":case"image":case"link":tn("error",a),tn("load",a),S=y;break;case"details":tn("toggle",a),S=y;break;case"input":Je(a,y),S=pt(a,y),tn("invalid",a);break;case"option":S=y;break;case"select":a._wrapperState={wasMultiple:!!y.multiple},S=K({},y,{value:void 0}),tn("invalid",a);break;case"textarea":ve(a,y),S=Fe(a,y),tn("invalid",a);break;default:S=y}gt(p,S),H=S;for(N in H)if(H.hasOwnProperty(N)){var Y=H[N];N==="style"?Ye(a,Y):N==="dangerouslySetInnerHTML"?(Y=Y?Y.__html:void 0,Y!=null&&Ge(a,Y)):N==="children"?typeof Y=="string"?(p!=="textarea"||Y!=="")&&Pe(a,Y):typeof Y=="number"&&Pe(a,""+Y):N!=="suppressContentEditableWarning"&&N!=="suppressHydrationWarning"&&N!=="autoFocus"&&(s.hasOwnProperty(N)?Y!=null&&N==="onScroll"&&tn("scroll",a):Y!=null&&T(a,N,Y,R))}switch(p){case"input":Ze(a),ft(a,y,!1);break;case"textarea":Ze(a),Be(a);break;case"option":y.value!=null&&a.setAttribute("value",""+we(y.value));break;case"select":a.multiple=!!y.multiple,N=y.value,N!=null?ht(a,!!y.multiple,N,!1):y.defaultValue!=null&&ht(a,!!y.multiple,y.defaultValue,!0);break;default:typeof S.onClick=="function"&&(a.onclick=rc)}switch(p){case"button":case"input":case"select":case"textarea":y=!!y.autoFocus;break e;case"img":y=!0;break e;default:y=!1}}y&&(u.flags|=4)}u.ref!==null&&(u.flags|=512,u.flags|=2097152)}return Jn(u),null;case 6:if(a&&u.stateNode!=null)p0(a,u,a.memoizedProps,y);else{if(typeof y!="string"&&u.stateNode===null)throw Error(n(166));if(p=zi(Ia.current),zi(us.current),uc(u)){if(y=u.stateNode,p=u.memoizedProps,y[cs]=u,(N=y.nodeValue!==p)&&(a=xr,a!==null))switch(a.tag){case 3:nc(y.nodeValue,p,(a.mode&1)!==0);break;case 5:a.memoizedProps.suppressHydrationWarning!==!0&&nc(y.nodeValue,p,(a.mode&1)!==0)}N&&(u.flags|=4)}else y=(p.nodeType===9?p:p.ownerDocument).createTextNode(y),y[cs]=u,u.stateNode=y}return Jn(u),null;case 13:if(nn(ln),y=u.memoizedState,a===null||a.memoizedState!==null&&a.memoizedState.dehydrated!==null){if(sn&&wr!==null&&(u.mode&1)!==0&&(u.flags&128)===0)vb(),Ao(),u.flags|=98560,N=!1;else if(N=uc(u),y!==null&&y.dehydrated!==null){if(a===null){if(!N)throw Error(n(318));if(N=u.memoizedState,N=N!==null?N.dehydrated:null,!N)throw Error(n(317));N[cs]=u}else Ao(),(u.flags&128)===0&&(u.memoizedState=null),u.flags|=4;Jn(u),N=!1}else Kr!==null&&(jh(Kr),Kr=null),N=!0;if(!N)return u.flags&65536?u:null}return(u.flags&128)!==0?(u.lanes=p,u):(y=y!==null,y!==(a!==null&&a.memoizedState!==null)&&y&&(u.child.flags|=8192,(u.mode&1)!==0&&(a===null||(ln.current&1)!==0?_n===0&&(_n=3):Rh())),u.updateQueue!==null&&(u.flags|=4),Jn(u),null);case 4:return Lo(),yh(a,u),a===null&&_a(u.stateNode.containerInfo),Jn(u),null;case 10:return Vf(u.type._context),Jn(u),null;case 17:return ur(u.type)&&ic(),Jn(u),null;case 19:if(nn(ln),N=u.memoizedState,N===null)return Jn(u),null;if(y=(u.flags&128)!==0,R=N.rendering,R===null)if(y)$a(N,!1);else{if(_n!==0||a!==null&&(a.flags&128)!==0)for(a=u.child;a!==null;){if(R=gc(a),R!==null){for(u.flags|=128,$a(N,!1),y=R.updateQueue,y!==null&&(u.updateQueue=y,u.flags|=4),u.subtreeFlags=0,y=p,p=u.child;p!==null;)N=p,a=y,N.flags&=14680066,R=N.alternate,R===null?(N.childLanes=0,N.lanes=a,N.child=null,N.subtreeFlags=0,N.memoizedProps=null,N.memoizedState=null,N.updateQueue=null,N.dependencies=null,N.stateNode=null):(N.childLanes=R.childLanes,N.lanes=R.lanes,N.child=R.child,N.subtreeFlags=0,N.deletions=null,N.memoizedProps=R.memoizedProps,N.memoizedState=R.memoizedState,N.updateQueue=R.updateQueue,N.type=R.type,a=R.dependencies,N.dependencies=a===null?null:{lanes:a.lanes,firstContext:a.firstContext}),p=p.sibling;return Qt(ln,ln.current&1|2),u.child}a=a.sibling}N.tail!==null&&It()>$o&&(u.flags|=128,y=!0,$a(N,!1),u.lanes=4194304)}else{if(!y)if(a=gc(R),a!==null){if(u.flags|=128,y=!0,p=a.updateQueue,p!==null&&(u.updateQueue=p,u.flags|=4),$a(N,!0),N.tail===null&&N.tailMode==="hidden"&&!R.alternate&&!sn)return Jn(u),null}else 2*It()-N.renderingStartTime>$o&&p!==1073741824&&(u.flags|=128,y=!0,$a(N,!1),u.lanes=4194304);N.isBackwards?(R.sibling=u.child,u.child=R):(p=N.last,p!==null?p.sibling=R:u.child=R,N.last=R)}return N.tail!==null?(u=N.tail,N.rendering=u,N.tail=u.sibling,N.renderingStartTime=It(),u.sibling=null,p=ln.current,Qt(ln,y?p&1|2:p&1),u):(Jn(u),null);case 22:case 23:return Ah(),y=u.memoizedState!==null,a!==null&&a.memoizedState!==null!==y&&(u.flags|=8192),y&&(u.mode&1)!==0?(kr&1073741824)!==0&&(Jn(u),u.subtreeFlags&6&&(u.flags|=8192)):Jn(u),null;case 24:return null;case 25:return null}throw Error(n(156,u.tag))}function Pj(a,u){switch(zf(u),u.tag){case 1:return ur(u.type)&&ic(),a=u.flags,a&65536?(u.flags=a&-65537|128,u):null;case 3:return Lo(),nn(cr),nn(Kn),Zf(),a=u.flags,(a&65536)!==0&&(a&128)===0?(u.flags=a&-65537|128,u):null;case 5:return Xf(u),null;case 13:if(nn(ln),a=u.memoizedState,a!==null&&a.dehydrated!==null){if(u.alternate===null)throw Error(n(340));Ao()}return a=u.flags,a&65536?(u.flags=a&-65537|128,u):null;case 19:return nn(ln),null;case 4:return Lo(),null;case 10:return Vf(u.type._context),null;case 22:case 23:return Ah(),null;case 24:return null;default:return null}}var Nc=!1,Yn=!1,Bj=typeof WeakSet=="function"?WeakSet:Set,Qe=null;function Po(a,u){var p=a.ref;if(p!==null)if(typeof p=="function")try{p(null)}catch(y){fn(a,u,y)}else p.current=null}function bh(a,u,p){try{p()}catch(y){fn(a,u,y)}}var m0=!1;function $j(a,u){if(Af=ql,a=Ky(),Sf(a)){if("selectionStart"in a)var p={start:a.selectionStart,end:a.selectionEnd};else e:{p=(p=a.ownerDocument)&&p.defaultView||window;var y=p.getSelection&&p.getSelection();if(y&&y.rangeCount!==0){p=y.anchorNode;var S=y.anchorOffset,N=y.focusNode;y=y.focusOffset;try{p.nodeType,N.nodeType}catch{p=null;break e}var R=0,H=-1,Y=-1,ue=0,_e=0,Ae=a,Ce=null;t:for(;;){for(var Ve;Ae!==p||S!==0&&Ae.nodeType!==3||(H=R+S),Ae!==N||y!==0&&Ae.nodeType!==3||(Y=R+y),Ae.nodeType===3&&(R+=Ae.nodeValue.length),(Ve=Ae.firstChild)!==null;)Ce=Ae,Ae=Ve;for(;;){if(Ae===a)break t;if(Ce===p&&++ue===S&&(H=R),Ce===N&&++_e===y&&(Y=R),(Ve=Ae.nextSibling)!==null)break;Ae=Ce,Ce=Ae.parentNode}Ae=Ve}p=H===-1||Y===-1?null:{start:H,end:Y}}else p=null}p=p||{start:0,end:0}}else p=null;for(Rf={focusedElem:a,selectionRange:p},ql=!1,Qe=u;Qe!==null;)if(u=Qe,a=u.child,(u.subtreeFlags&1028)!==0&&a!==null)a.return=u,Qe=a;else for(;Qe!==null;){u=Qe;try{var tt=u.alternate;if((u.flags&1024)!==0)switch(u.tag){case 0:case 11:case 15:break;case 1:if(tt!==null){var rt=tt.memoizedProps,xn=tt.memoizedState,ae=u.stateNode,Q=ae.getSnapshotBeforeUpdate(u.elementType===u.type?rt:Gr(u.type,rt),xn);ae.__reactInternalSnapshotBeforeUpdate=Q}break;case 3:var le=u.stateNode.containerInfo;le.nodeType===1?le.textContent="":le.nodeType===9&&le.documentElement&&le.removeChild(le.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(n(163))}}catch(De){fn(u,u.return,De)}if(a=u.sibling,a!==null){a.return=u.return,Qe=a;break}Qe=u.return}return tt=m0,m0=!1,tt}function za(a,u,p){var y=u.updateQueue;if(y=y!==null?y.lastEffect:null,y!==null){var S=y=y.next;do{if((S.tag&a)===a){var N=S.destroy;S.destroy=void 0,N!==void 0&&bh(u,p,N)}S=S.next}while(S!==y)}}function Cc(a,u){if(u=u.updateQueue,u=u!==null?u.lastEffect:null,u!==null){var p=u=u.next;do{if((p.tag&a)===a){var y=p.create;p.destroy=y()}p=p.next}while(p!==u)}}function xh(a){var u=a.ref;if(u!==null){var p=a.stateNode;switch(a.tag){case 5:a=p;break;default:a=p}typeof u=="function"?u(a):u.current=a}}function g0(a){var u=a.alternate;u!==null&&(a.alternate=null,g0(u)),a.child=null,a.deletions=null,a.sibling=null,a.tag===5&&(u=a.stateNode,u!==null&&(delete u[cs],delete u[ja],delete u[Df],delete u[wj],delete u[kj])),a.stateNode=null,a.return=null,a.dependencies=null,a.memoizedProps=null,a.memoizedState=null,a.pendingProps=null,a.stateNode=null,a.updateQueue=null}function v0(a){return a.tag===5||a.tag===3||a.tag===4}function y0(a){e:for(;;){for(;a.sibling===null;){if(a.return===null||v0(a.return))return null;a=a.return}for(a.sibling.return=a.return,a=a.sibling;a.tag!==5&&a.tag!==6&&a.tag!==18;){if(a.flags&2||a.child===null||a.tag===4)continue e;a.child.return=a,a=a.child}if(!(a.flags&2))return a.stateNode}}function wh(a,u,p){var y=a.tag;if(y===5||y===6)a=a.stateNode,u?p.nodeType===8?p.parentNode.insertBefore(a,u):p.insertBefore(a,u):(p.nodeType===8?(u=p.parentNode,u.insertBefore(a,p)):(u=p,u.appendChild(a)),p=p._reactRootContainer,p!=null||u.onclick!==null||(u.onclick=rc));else if(y!==4&&(a=a.child,a!==null))for(wh(a,u,p),a=a.sibling;a!==null;)wh(a,u,p),a=a.sibling}function kh(a,u,p){var y=a.tag;if(y===5||y===6)a=a.stateNode,u?p.insertBefore(a,u):p.appendChild(a);else if(y!==4&&(a=a.child,a!==null))for(kh(a,u,p),a=a.sibling;a!==null;)kh(a,u,p),a=a.sibling}var Bn=null,Jr=!1;function Zs(a,u,p){for(p=p.child;p!==null;)b0(a,u,p),p=p.sibling}function b0(a,u,p){if(Ot&&typeof Ot.onCommitFiberUnmount=="function")try{Ot.onCommitFiberUnmount(Tt,p)}catch{}switch(p.tag){case 5:Yn||Po(p,u);case 6:var y=Bn,S=Jr;Bn=null,Zs(a,u,p),Bn=y,Jr=S,Bn!==null&&(Jr?(a=Bn,p=p.stateNode,a.nodeType===8?a.parentNode.removeChild(p):a.removeChild(p)):Bn.removeChild(p.stateNode));break;case 18:Bn!==null&&(Jr?(a=Bn,p=p.stateNode,a.nodeType===8?Lf(a.parentNode,p):a.nodeType===1&&Lf(a,p),ya(a)):Lf(Bn,p.stateNode));break;case 4:y=Bn,S=Jr,Bn=p.stateNode.containerInfo,Jr=!0,Zs(a,u,p),Bn=y,Jr=S;break;case 0:case 11:case 14:case 15:if(!Yn&&(y=p.updateQueue,y!==null&&(y=y.lastEffect,y!==null))){S=y=y.next;do{var N=S,R=N.destroy;N=N.tag,R!==void 0&&((N&2)!==0||(N&4)!==0)&&bh(p,u,R),S=S.next}while(S!==y)}Zs(a,u,p);break;case 1:if(!Yn&&(Po(p,u),y=p.stateNode,typeof y.componentWillUnmount=="function"))try{y.props=p.memoizedProps,y.state=p.memoizedState,y.componentWillUnmount()}catch(H){fn(p,u,H)}Zs(a,u,p);break;case 21:Zs(a,u,p);break;case 22:p.mode&1?(Yn=(y=Yn)||p.memoizedState!==null,Zs(a,u,p),Yn=y):Zs(a,u,p);break;default:Zs(a,u,p)}}function x0(a){var u=a.updateQueue;if(u!==null){a.updateQueue=null;var p=a.stateNode;p===null&&(p=a.stateNode=new Bj),u.forEach(function(y){var S=Gj.bind(null,a,y);p.has(y)||(p.add(y),y.then(S,S))})}}function Yr(a,u){var p=u.deletions;if(p!==null)for(var y=0;y<p.length;y++){var S=p[y];try{var N=a,R=u,H=R;e:for(;H!==null;){switch(H.tag){case 5:Bn=H.stateNode,Jr=!1;break e;case 3:Bn=H.stateNode.containerInfo,Jr=!0;break e;case 4:Bn=H.stateNode.containerInfo,Jr=!0;break e}H=H.return}if(Bn===null)throw Error(n(160));b0(N,R,S),Bn=null,Jr=!1;var Y=S.alternate;Y!==null&&(Y.return=null),S.return=null}catch(ue){fn(S,u,ue)}}if(u.subtreeFlags&12854)for(u=u.child;u!==null;)w0(u,a),u=u.sibling}function w0(a,u){var p=a.alternate,y=a.flags;switch(a.tag){case 0:case 11:case 14:case 15:if(Yr(u,a),fs(a),y&4){try{za(3,a,a.return),Cc(3,a)}catch(rt){fn(a,a.return,rt)}try{za(5,a,a.return)}catch(rt){fn(a,a.return,rt)}}break;case 1:Yr(u,a),fs(a),y&512&&p!==null&&Po(p,p.return);break;case 5:if(Yr(u,a),fs(a),y&512&&p!==null&&Po(p,p.return),a.flags&32){var S=a.stateNode;try{Pe(S,"")}catch(rt){fn(a,a.return,rt)}}if(y&4&&(S=a.stateNode,S!=null)){var N=a.memoizedProps,R=p!==null?p.memoizedProps:N,H=a.type,Y=a.updateQueue;if(a.updateQueue=null,Y!==null)try{H==="input"&&N.type==="radio"&&N.name!=null&&pe(S,N),Nt(H,R);var ue=Nt(H,N);for(R=0;R<Y.length;R+=2){var _e=Y[R],Ae=Y[R+1];_e==="style"?Ye(S,Ae):_e==="dangerouslySetInnerHTML"?Ge(S,Ae):_e==="children"?Pe(S,Ae):T(S,_e,Ae,ue)}switch(H){case"input":mt(S,N);break;case"textarea":X(S,N);break;case"select":var Ce=S._wrapperState.wasMultiple;S._wrapperState.wasMultiple=!!N.multiple;var Ve=N.value;Ve!=null?ht(S,!!N.multiple,Ve,!1):Ce!==!!N.multiple&&(N.defaultValue!=null?ht(S,!!N.multiple,N.defaultValue,!0):ht(S,!!N.multiple,N.multiple?[]:"",!1))}S[ja]=N}catch(rt){fn(a,a.return,rt)}}break;case 6:if(Yr(u,a),fs(a),y&4){if(a.stateNode===null)throw Error(n(162));S=a.stateNode,N=a.memoizedProps;try{S.nodeValue=N}catch(rt){fn(a,a.return,rt)}}break;case 3:if(Yr(u,a),fs(a),y&4&&p!==null&&p.memoizedState.isDehydrated)try{ya(u.containerInfo)}catch(rt){fn(a,a.return,rt)}break;case 4:Yr(u,a),fs(a);break;case 13:Yr(u,a),fs(a),S=a.child,S.flags&8192&&(N=S.memoizedState!==null,S.stateNode.isHidden=N,!N||S.alternate!==null&&S.alternate.memoizedState!==null||(Nh=It())),y&4&&x0(a);break;case 22:if(_e=p!==null&&p.memoizedState!==null,a.mode&1?(Yn=(ue=Yn)||_e,Yr(u,a),Yn=ue):Yr(u,a),fs(a),y&8192){if(ue=a.memoizedState!==null,(a.stateNode.isHidden=ue)&&!_e&&(a.mode&1)!==0)for(Qe=a,_e=a.child;_e!==null;){for(Ae=Qe=_e;Qe!==null;){switch(Ce=Qe,Ve=Ce.child,Ce.tag){case 0:case 11:case 14:case 15:za(4,Ce,Ce.return);break;case 1:Po(Ce,Ce.return);var tt=Ce.stateNode;if(typeof tt.componentWillUnmount=="function"){y=Ce,p=Ce.return;try{u=y,tt.props=u.memoizedProps,tt.state=u.memoizedState,tt.componentWillUnmount()}catch(rt){fn(y,p,rt)}}break;case 5:Po(Ce,Ce.return);break;case 22:if(Ce.memoizedState!==null){E0(Ae);continue}}Ve!==null?(Ve.return=Ce,Qe=Ve):E0(Ae)}_e=_e.sibling}e:for(_e=null,Ae=a;;){if(Ae.tag===5){if(_e===null){_e=Ae;try{S=Ae.stateNode,ue?(N=S.style,typeof N.setProperty=="function"?N.setProperty("display","none","important"):N.display="none"):(H=Ae.stateNode,Y=Ae.memoizedProps.style,R=Y!=null&&Y.hasOwnProperty("display")?Y.display:null,H.style.display=bt("display",R))}catch(rt){fn(a,a.return,rt)}}}else if(Ae.tag===6){if(_e===null)try{Ae.stateNode.nodeValue=ue?"":Ae.memoizedProps}catch(rt){fn(a,a.return,rt)}}else if((Ae.tag!==22&&Ae.tag!==23||Ae.memoizedState===null||Ae===a)&&Ae.child!==null){Ae.child.return=Ae,Ae=Ae.child;continue}if(Ae===a)break e;for(;Ae.sibling===null;){if(Ae.return===null||Ae.return===a)break e;_e===Ae&&(_e=null),Ae=Ae.return}_e===Ae&&(_e=null),Ae.sibling.return=Ae.return,Ae=Ae.sibling}}break;case 19:Yr(u,a),fs(a),y&4&&x0(a);break;case 21:break;default:Yr(u,a),fs(a)}}function fs(a){var u=a.flags;if(u&2){try{e:{for(var p=a.return;p!==null;){if(v0(p)){var y=p;break e}p=p.return}throw Error(n(160))}switch(y.tag){case 5:var S=y.stateNode;y.flags&32&&(Pe(S,""),y.flags&=-33);var N=y0(a);kh(a,N,S);break;case 3:case 4:var R=y.stateNode.containerInfo,H=y0(a);wh(a,H,R);break;default:throw Error(n(161))}}catch(Y){fn(a,a.return,Y)}a.flags&=-3}u&4096&&(a.flags&=-4097)}function zj(a,u,p){Qe=a,k0(a)}function k0(a,u,p){for(var y=(a.mode&1)!==0;Qe!==null;){var S=Qe,N=S.child;if(S.tag===22&&y){var R=S.memoizedState!==null||Nc;if(!R){var H=S.alternate,Y=H!==null&&H.memoizedState!==null||Yn;H=Nc;var ue=Yn;if(Nc=R,(Yn=Y)&&!ue)for(Qe=S;Qe!==null;)R=Qe,Y=R.child,R.tag===22&&R.memoizedState!==null?N0(S):Y!==null?(Y.return=R,Qe=Y):N0(S);for(;N!==null;)Qe=N,k0(N),N=N.sibling;Qe=S,Nc=H,Yn=ue}S0(a)}else(S.subtreeFlags&8772)!==0&&N!==null?(N.return=S,Qe=N):S0(a)}}function S0(a){for(;Qe!==null;){var u=Qe;if((u.flags&8772)!==0){var p=u.alternate;try{if((u.flags&8772)!==0)switch(u.tag){case 0:case 11:case 15:Yn||Cc(5,u);break;case 1:var y=u.stateNode;if(u.flags&4&&!Yn)if(p===null)y.componentDidMount();else{var S=u.elementType===u.type?p.memoizedProps:Gr(u.type,p.memoizedProps);y.componentDidUpdate(S,p.memoizedState,y.__reactInternalSnapshotBeforeUpdate)}var N=u.updateQueue;N!==null&&Eb(u,N,y);break;case 3:var R=u.updateQueue;if(R!==null){if(p=null,u.child!==null)switch(u.child.tag){case 5:p=u.child.stateNode;break;case 1:p=u.child.stateNode}Eb(u,R,p)}break;case 5:var H=u.stateNode;if(p===null&&u.flags&4){p=H;var Y=u.memoizedProps;switch(u.type){case"button":case"input":case"select":case"textarea":Y.autoFocus&&p.focus();break;case"img":Y.src&&(p.src=Y.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(u.memoizedState===null){var ue=u.alternate;if(ue!==null){var _e=ue.memoizedState;if(_e!==null){var Ae=_e.dehydrated;Ae!==null&&ya(Ae)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(n(163))}Yn||u.flags&512&&xh(u)}catch(Ce){fn(u,u.return,Ce)}}if(u===a){Qe=null;break}if(p=u.sibling,p!==null){p.return=u.return,Qe=p;break}Qe=u.return}}function E0(a){for(;Qe!==null;){var u=Qe;if(u===a){Qe=null;break}var p=u.sibling;if(p!==null){p.return=u.return,Qe=p;break}Qe=u.return}}function N0(a){for(;Qe!==null;){var u=Qe;try{switch(u.tag){case 0:case 11:case 15:var p=u.return;try{Cc(4,u)}catch(Y){fn(u,p,Y)}break;case 1:var y=u.stateNode;if(typeof y.componentDidMount=="function"){var S=u.return;try{y.componentDidMount()}catch(Y){fn(u,S,Y)}}var N=u.return;try{xh(u)}catch(Y){fn(u,N,Y)}break;case 5:var R=u.return;try{xh(u)}catch(Y){fn(u,R,Y)}}}catch(Y){fn(u,u.return,Y)}if(u===a){Qe=null;break}var H=u.sibling;if(H!==null){H.return=u.return,Qe=H;break}Qe=u.return}}var Fj=Math.ceil,_c=j.ReactCurrentDispatcher,Sh=j.ReactCurrentOwner,Or=j.ReactCurrentBatchConfig,$t=0,Mn=null,kn=null,$n=0,kr=0,Bo=Gs(0),_n=0,Fa=null,Ui=0,Tc=0,Eh=0,Ua=null,fr=null,Nh=0,$o=1/0,_s=null,jc=!1,Ch=null,ei=null,Mc=!1,ti=null,Ac=0,Ha=0,_h=null,Rc=-1,Oc=0;function ir(){return($t&6)!==0?It():Rc!==-1?Rc:Rc=It()}function ni(a){return(a.mode&1)===0?1:($t&2)!==0&&$n!==0?$n&-$n:Ej.transition!==null?(Oc===0&&(Oc=Ul()),Oc):(a=Bt,a!==0||(a=window.event,a=a===void 0?16:_y(a.type)),a)}function Xr(a,u,p,y){if(50<Ha)throw Ha=0,_h=null,Error(n(185));Hs(a,p,y),(($t&2)===0||a!==Mn)&&(a===Mn&&(($t&2)===0&&(Tc|=p),_n===4&&ri(a,$n)),hr(a,y),p===1&&$t===0&&(u.mode&1)===0&&($o=It()+500,ac&&Ys()))}function hr(a,u){var p=a.callbackNode;uf(a,u);var y=Ri(a,a===Mn?$n:0);if(y===0)p!==null&&ze(p),a.callbackNode=null,a.callbackPriority=0;else if(u=y&-y,a.callbackPriority!==u){if(p!=null&&ze(p),u===1)a.tag===0?Sj(_0.bind(null,a)):fb(_0.bind(null,a)),bj(function(){($t&6)===0&&Ys()}),p=null;else{switch(Et(y)){case 1:p=qr;break;case 4:p=Kt;break;case 16:p=Vn;break;case 536870912:p=lt;break;default:p=Vn}p=L0(p,C0.bind(null,a))}a.callbackPriority=u,a.callbackNode=p}}function C0(a,u){if(Rc=-1,Oc=0,($t&6)!==0)throw Error(n(327));var p=a.callbackNode;if(zo()&&a.callbackNode!==p)return null;var y=Ri(a,a===Mn?$n:0);if(y===0)return null;if((y&30)!==0||(y&a.expiredLanes)!==0||u)u=Ic(a,y);else{u=y;var S=$t;$t|=2;var N=j0();(Mn!==a||$n!==u)&&(_s=null,$o=It()+500,Wi(a,u));do try{Wj();break}catch(H){T0(a,H)}while(!0);qf(),_c.current=N,$t=S,kn!==null?u=0:(Mn=null,$n=0,u=_n)}if(u!==0){if(u===2&&(S=ha(a),S!==0&&(y=S,u=Th(a,S))),u===1)throw p=Fa,Wi(a,0),ri(a,y),hr(a,It()),p;if(u===6)ri(a,y);else{if(S=a.current.alternate,(y&30)===0&&!Uj(S)&&(u=Ic(a,y),u===2&&(N=ha(a),N!==0&&(y=N,u=Th(a,N))),u===1))throw p=Fa,Wi(a,0),ri(a,y),hr(a,It()),p;switch(a.finishedWork=S,a.finishedLanes=y,u){case 0:case 1:throw Error(n(345));case 2:qi(a,fr,_s);break;case 3:if(ri(a,y),(y&130023424)===y&&(u=Nh+500-It(),10<u)){if(Ri(a,0)!==0)break;if(S=a.suspendedLanes,(S&y)!==y){ir(),a.pingedLanes|=a.suspendedLanes&S;break}a.timeoutHandle=If(qi.bind(null,a,fr,_s),u);break}qi(a,fr,_s);break;case 4:if(ri(a,y),(y&4194240)===y)break;for(u=a.eventTimes,S=-1;0<y;){var R=31-an(y);N=1<<R,R=u[R],R>S&&(S=R),y&=~N}if(y=S,y=It()-y,y=(120>y?120:480>y?480:1080>y?1080:1920>y?1920:3e3>y?3e3:4320>y?4320:1960*Fj(y/1960))-y,10<y){a.timeoutHandle=If(qi.bind(null,a,fr,_s),y);break}qi(a,fr,_s);break;case 5:qi(a,fr,_s);break;default:throw Error(n(329))}}}return hr(a,It()),a.callbackNode===p?C0.bind(null,a):null}function Th(a,u){var p=Ua;return a.current.memoizedState.isDehydrated&&(Wi(a,u).flags|=256),a=Ic(a,u),a!==2&&(u=fr,fr=p,u!==null&&jh(u)),a}function jh(a){fr===null?fr=a:fr.push.apply(fr,a)}function Uj(a){for(var u=a;;){if(u.flags&16384){var p=u.updateQueue;if(p!==null&&(p=p.stores,p!==null))for(var y=0;y<p.length;y++){var S=p[y],N=S.getSnapshot;S=S.value;try{if(!Vr(N(),S))return!1}catch{return!1}}}if(p=u.child,u.subtreeFlags&16384&&p!==null)p.return=u,u=p;else{if(u===a)break;for(;u.sibling===null;){if(u.return===null||u.return===a)return!0;u=u.return}u.sibling.return=u.return,u=u.sibling}}return!0}function ri(a,u){for(u&=~Eh,u&=~Tc,a.suspendedLanes|=u,a.pingedLanes&=~u,a=a.expirationTimes;0<u;){var p=31-an(u),y=1<<p;a[p]=-1,u&=~y}}function _0(a){if(($t&6)!==0)throw Error(n(327));zo();var u=Ri(a,0);if((u&1)===0)return hr(a,It()),null;var p=Ic(a,u);if(a.tag!==0&&p===2){var y=ha(a);y!==0&&(u=y,p=Th(a,y))}if(p===1)throw p=Fa,Wi(a,0),ri(a,u),hr(a,It()),p;if(p===6)throw Error(n(345));return a.finishedWork=a.current.alternate,a.finishedLanes=u,qi(a,fr,_s),hr(a,It()),null}function Mh(a,u){var p=$t;$t|=1;try{return a(u)}finally{$t=p,$t===0&&($o=It()+500,ac&&Ys())}}function Hi(a){ti!==null&&ti.tag===0&&($t&6)===0&&zo();var u=$t;$t|=1;var p=Or.transition,y=Bt;try{if(Or.transition=null,Bt=1,a)return a()}finally{Bt=y,Or.transition=p,$t=u,($t&6)===0&&Ys()}}function Ah(){kr=Bo.current,nn(Bo)}function Wi(a,u){a.finishedWork=null,a.finishedLanes=0;var p=a.timeoutHandle;if(p!==-1&&(a.timeoutHandle=-1,yj(p)),kn!==null)for(p=kn.return;p!==null;){var y=p;switch(zf(y),y.tag){case 1:y=y.type.childContextTypes,y!=null&&ic();break;case 3:Lo(),nn(cr),nn(Kn),Zf();break;case 5:Xf(y);break;case 4:Lo();break;case 13:nn(ln);break;case 19:nn(ln);break;case 10:Vf(y.type._context);break;case 22:case 23:Ah()}p=p.return}if(Mn=a,kn=a=si(a.current,null),$n=kr=u,_n=0,Fa=null,Eh=Tc=Ui=0,fr=Ua=null,$i!==null){for(u=0;u<$i.length;u++)if(p=$i[u],y=p.interleaved,y!==null){p.interleaved=null;var S=y.next,N=p.pending;if(N!==null){var R=N.next;N.next=S,y.next=R}p.pending=y}$i=null}return a}function T0(a,u){do{var p=kn;try{if(qf(),vc.current=wc,yc){for(var y=cn.memoizedState;y!==null;){var S=y.queue;S!==null&&(S.pending=null),y=y.next}yc=!1}if(Fi=0,jn=Cn=cn=null,La=!1,Da=0,Sh.current=null,p===null||p.return===null){_n=1,Fa=u,kn=null;break}e:{var N=a,R=p.return,H=p,Y=u;if(u=$n,H.flags|=32768,Y!==null&&typeof Y=="object"&&typeof Y.then=="function"){var ue=Y,_e=H,Ae=_e.tag;if((_e.mode&1)===0&&(Ae===0||Ae===11||Ae===15)){var Ce=_e.alternate;Ce?(_e.updateQueue=Ce.updateQueue,_e.memoizedState=Ce.memoizedState,_e.lanes=Ce.lanes):(_e.updateQueue=null,_e.memoizedState=null)}var Ve=Zb(R);if(Ve!==null){Ve.flags&=-257,e0(Ve,R,H,N,u),Ve.mode&1&&Qb(N,ue,u),u=Ve,Y=ue;var tt=u.updateQueue;if(tt===null){var rt=new Set;rt.add(Y),u.updateQueue=rt}else tt.add(Y);break e}else{if((u&1)===0){Qb(N,ue,u),Rh();break e}Y=Error(n(426))}}else if(sn&&H.mode&1){var xn=Zb(R);if(xn!==null){(xn.flags&65536)===0&&(xn.flags|=256),e0(xn,R,H,N,u),Hf(Do(Y,H));break e}}N=Y=Do(Y,H),_n!==4&&(_n=2),Ua===null?Ua=[N]:Ua.push(N),N=R;do{switch(N.tag){case 3:N.flags|=65536,u&=-u,N.lanes|=u;var ae=Yb(N,Y,u);Sb(N,ae);break e;case 1:H=Y;var Q=N.type,le=N.stateNode;if((N.flags&128)===0&&(typeof Q.getDerivedStateFromError=="function"||le!==null&&typeof le.componentDidCatch=="function"&&(ei===null||!ei.has(le)))){N.flags|=65536,u&=-u,N.lanes|=u;var De=Xb(N,H,u);Sb(N,De);break e}}N=N.return}while(N!==null)}A0(p)}catch(st){u=st,kn===p&&p!==null&&(kn=p=p.return);continue}break}while(!0)}function j0(){var a=_c.current;return _c.current=wc,a===null?wc:a}function Rh(){(_n===0||_n===3||_n===2)&&(_n=4),Mn===null||(Ui&268435455)===0&&(Tc&268435455)===0||ri(Mn,$n)}function Ic(a,u){var p=$t;$t|=2;var y=j0();(Mn!==a||$n!==u)&&(_s=null,Wi(a,u));do try{Hj();break}catch(S){T0(a,S)}while(!0);if(qf(),$t=p,_c.current=y,kn!==null)throw Error(n(261));return Mn=null,$n=0,_n}function Hj(){for(;kn!==null;)M0(kn)}function Wj(){for(;kn!==null&&!_t();)M0(kn)}function M0(a){var u=I0(a.alternate,a,kr);a.memoizedProps=a.pendingProps,u===null?A0(a):kn=u,Sh.current=null}function A0(a){var u=a;do{var p=u.alternate;if(a=u.return,(u.flags&32768)===0){if(p=Dj(p,u,kr),p!==null){kn=p;return}}else{if(p=Pj(p,u),p!==null){p.flags&=32767,kn=p;return}if(a!==null)a.flags|=32768,a.subtreeFlags=0,a.deletions=null;else{_n=6,kn=null;return}}if(u=u.sibling,u!==null){kn=u;return}kn=u=a}while(u!==null);_n===0&&(_n=5)}function qi(a,u,p){var y=Bt,S=Or.transition;try{Or.transition=null,Bt=1,qj(a,u,p,y)}finally{Or.transition=S,Bt=y}return null}function qj(a,u,p,y){do zo();while(ti!==null);if(($t&6)!==0)throw Error(n(327));p=a.finishedWork;var S=a.finishedLanes;if(p===null)return null;if(a.finishedWork=null,a.finishedLanes=0,p===a.current)throw Error(n(177));a.callbackNode=null,a.callbackPriority=0;var N=p.lanes|p.childLanes;if(Tr(a,N),a===Mn&&(kn=Mn=null,$n=0),(p.subtreeFlags&2064)===0&&(p.flags&2064)===0||Mc||(Mc=!0,L0(Vn,function(){return zo(),null})),N=(p.flags&15990)!==0,(p.subtreeFlags&15990)!==0||N){N=Or.transition,Or.transition=null;var R=Bt;Bt=1;var H=$t;$t|=4,Sh.current=null,$j(a,p),w0(p,a),dj(Rf),ql=!!Af,Rf=Af=null,a.current=p,zj(p),Rt(),$t=H,Bt=R,Or.transition=N}else a.current=p;if(Mc&&(Mc=!1,ti=a,Ac=S),N=a.pendingLanes,N===0&&(ei=null),yn(p.stateNode),hr(a,It()),u!==null)for(y=a.onRecoverableError,p=0;p<u.length;p++)S=u[p],y(S.value,{componentStack:S.stack,digest:S.digest});if(jc)throw jc=!1,a=Ch,Ch=null,a;return(Ac&1)!==0&&a.tag!==0&&zo(),N=a.pendingLanes,(N&1)!==0?a===_h?Ha++:(Ha=0,_h=a):Ha=0,Ys(),null}function zo(){if(ti!==null){var a=Et(Ac),u=Or.transition,p=Bt;try{if(Or.transition=null,Bt=16>a?16:a,ti===null)var y=!1;else{if(a=ti,ti=null,Ac=0,($t&6)!==0)throw Error(n(331));var S=$t;for($t|=4,Qe=a.current;Qe!==null;){var N=Qe,R=N.child;if((Qe.flags&16)!==0){var H=N.deletions;if(H!==null){for(var Y=0;Y<H.length;Y++){var ue=H[Y];for(Qe=ue;Qe!==null;){var _e=Qe;switch(_e.tag){case 0:case 11:case 15:za(8,_e,N)}var Ae=_e.child;if(Ae!==null)Ae.return=_e,Qe=Ae;else for(;Qe!==null;){_e=Qe;var Ce=_e.sibling,Ve=_e.return;if(g0(_e),_e===ue){Qe=null;break}if(Ce!==null){Ce.return=Ve,Qe=Ce;break}Qe=Ve}}}var tt=N.alternate;if(tt!==null){var rt=tt.child;if(rt!==null){tt.child=null;do{var xn=rt.sibling;rt.sibling=null,rt=xn}while(rt!==null)}}Qe=N}}if((N.subtreeFlags&2064)!==0&&R!==null)R.return=N,Qe=R;else e:for(;Qe!==null;){if(N=Qe,(N.flags&2048)!==0)switch(N.tag){case 0:case 11:case 15:za(9,N,N.return)}var ae=N.sibling;if(ae!==null){ae.return=N.return,Qe=ae;break e}Qe=N.return}}var Q=a.current;for(Qe=Q;Qe!==null;){R=Qe;var le=R.child;if((R.subtreeFlags&2064)!==0&&le!==null)le.return=R,Qe=le;else e:for(R=Q;Qe!==null;){if(H=Qe,(H.flags&2048)!==0)try{switch(H.tag){case 0:case 11:case 15:Cc(9,H)}}catch(st){fn(H,H.return,st)}if(H===R){Qe=null;break e}var De=H.sibling;if(De!==null){De.return=H.return,Qe=De;break e}Qe=H.return}}if($t=S,Ys(),Ot&&typeof Ot.onPostCommitFiberRoot=="function")try{Ot.onPostCommitFiberRoot(Tt,a)}catch{}y=!0}return y}finally{Bt=p,Or.transition=u}}return!1}function R0(a,u,p){u=Do(p,u),u=Yb(a,u,1),a=Qs(a,u,1),u=ir(),a!==null&&(Hs(a,1,u),hr(a,u))}function fn(a,u,p){if(a.tag===3)R0(a,a,p);else for(;u!==null;){if(u.tag===3){R0(u,a,p);break}else if(u.tag===1){var y=u.stateNode;if(typeof u.type.getDerivedStateFromError=="function"||typeof y.componentDidCatch=="function"&&(ei===null||!ei.has(y))){a=Do(p,a),a=Xb(u,a,1),u=Qs(u,a,1),a=ir(),u!==null&&(Hs(u,1,a),hr(u,a));break}}u=u.return}}function Vj(a,u,p){var y=a.pingCache;y!==null&&y.delete(u),u=ir(),a.pingedLanes|=a.suspendedLanes&p,Mn===a&&($n&p)===p&&(_n===4||_n===3&&($n&130023424)===$n&&500>It()-Nh?Wi(a,0):Eh|=p),hr(a,u)}function O0(a,u){u===0&&((a.mode&1)===0?u=1:(u=Ai,Ai<<=1,(Ai&130023424)===0&&(Ai=4194304)));var p=ir();a=Es(a,u),a!==null&&(Hs(a,u,p),hr(a,p))}function Kj(a){var u=a.memoizedState,p=0;u!==null&&(p=u.retryLane),O0(a,p)}function Gj(a,u){var p=0;switch(a.tag){case 13:var y=a.stateNode,S=a.memoizedState;S!==null&&(p=S.retryLane);break;case 19:y=a.stateNode;break;default:throw Error(n(314))}y!==null&&y.delete(u),O0(a,p)}var I0;I0=function(a,u,p){if(a!==null)if(a.memoizedProps!==u.pendingProps||cr.current)dr=!0;else{if((a.lanes&p)===0&&(u.flags&128)===0)return dr=!1,Lj(a,u,p);dr=(a.flags&131072)!==0}else dr=!1,sn&&(u.flags&1048576)!==0&&hb(u,cc,u.index);switch(u.lanes=0,u.tag){case 2:var y=u.type;Ec(a,u),a=u.pendingProps;var S=To(u,Kn.current);Io(u,p),S=nh(null,u,y,a,S,p);var N=rh();return u.flags|=1,typeof S=="object"&&S!==null&&typeof S.render=="function"&&S.$$typeof===void 0?(u.tag=1,u.memoizedState=null,u.updateQueue=null,ur(y)?(N=!0,oc(u)):N=!1,u.memoizedState=S.state!==null&&S.state!==void 0?S.state:null,Jf(u),S.updater=kc,u.stateNode=S,S._reactInternals=u,ch(u,y,a,p),u=hh(null,u,y,!0,N,p)):(u.tag=0,sn&&N&&$f(u),sr(null,u,S,p),u=u.child),u;case 16:y=u.elementType;e:{switch(Ec(a,u),a=u.pendingProps,S=y._init,y=S(y._payload),u.type=y,S=u.tag=Yj(y),a=Gr(y,a),S){case 0:u=fh(null,u,y,a,p);break e;case 1:u=o0(null,u,y,a,p);break e;case 11:u=t0(null,u,y,a,p);break e;case 14:u=n0(null,u,y,Gr(y.type,a),p);break e}throw Error(n(306,y,""))}return u;case 0:return y=u.type,S=u.pendingProps,S=u.elementType===y?S:Gr(y,S),fh(a,u,y,S,p);case 1:return y=u.type,S=u.pendingProps,S=u.elementType===y?S:Gr(y,S),o0(a,u,y,S,p);case 3:e:{if(a0(u),a===null)throw Error(n(387));y=u.pendingProps,N=u.memoizedState,S=N.element,kb(a,u),mc(u,y,null,p);var R=u.memoizedState;if(y=R.element,N.isDehydrated)if(N={element:y,isDehydrated:!1,cache:R.cache,pendingSuspenseBoundaries:R.pendingSuspenseBoundaries,transitions:R.transitions},u.updateQueue.baseState=N,u.memoizedState=N,u.flags&256){S=Do(Error(n(423)),u),u=l0(a,u,y,p,S);break e}else if(y!==S){S=Do(Error(n(424)),u),u=l0(a,u,y,p,S);break e}else for(wr=Ks(u.stateNode.containerInfo.firstChild),xr=u,sn=!0,Kr=null,p=xb(u,null,y,p),u.child=p;p;)p.flags=p.flags&-3|4096,p=p.sibling;else{if(Ao(),y===S){u=Cs(a,u,p);break e}sr(a,u,y,p)}u=u.child}return u;case 5:return Nb(u),a===null&&Uf(u),y=u.type,S=u.pendingProps,N=a!==null?a.memoizedProps:null,R=S.children,Of(y,S)?R=null:N!==null&&Of(y,N)&&(u.flags|=32),i0(a,u),sr(a,u,R,p),u.child;case 6:return a===null&&Uf(u),null;case 13:return c0(a,u,p);case 4:return Yf(u,u.stateNode.containerInfo),y=u.pendingProps,a===null?u.child=Ro(u,null,y,p):sr(a,u,y,p),u.child;case 11:return y=u.type,S=u.pendingProps,S=u.elementType===y?S:Gr(y,S),t0(a,u,y,S,p);case 7:return sr(a,u,u.pendingProps,p),u.child;case 8:return sr(a,u,u.pendingProps.children,p),u.child;case 12:return sr(a,u,u.pendingProps.children,p),u.child;case 10:e:{if(y=u.type._context,S=u.pendingProps,N=u.memoizedProps,R=S.value,Qt(fc,y._currentValue),y._currentValue=R,N!==null)if(Vr(N.value,R)){if(N.children===S.children&&!cr.current){u=Cs(a,u,p);break e}}else for(N=u.child,N!==null&&(N.return=u);N!==null;){var H=N.dependencies;if(H!==null){R=N.child;for(var Y=H.firstContext;Y!==null;){if(Y.context===y){if(N.tag===1){Y=Ns(-1,p&-p),Y.tag=2;var ue=N.updateQueue;if(ue!==null){ue=ue.shared;var _e=ue.pending;_e===null?Y.next=Y:(Y.next=_e.next,_e.next=Y),ue.pending=Y}}N.lanes|=p,Y=N.alternate,Y!==null&&(Y.lanes|=p),Kf(N.return,p,u),H.lanes|=p;break}Y=Y.next}}else if(N.tag===10)R=N.type===u.type?null:N.child;else if(N.tag===18){if(R=N.return,R===null)throw Error(n(341));R.lanes|=p,H=R.alternate,H!==null&&(H.lanes|=p),Kf(R,p,u),R=N.sibling}else R=N.child;if(R!==null)R.return=N;else for(R=N;R!==null;){if(R===u){R=null;break}if(N=R.sibling,N!==null){N.return=R.return,R=N;break}R=R.return}N=R}sr(a,u,S.children,p),u=u.child}return u;case 9:return S=u.type,y=u.pendingProps.children,Io(u,p),S=Ar(S),y=y(S),u.flags|=1,sr(a,u,y,p),u.child;case 14:return y=u.type,S=Gr(y,u.pendingProps),S=Gr(y.type,S),n0(a,u,y,S,p);case 15:return r0(a,u,u.type,u.pendingProps,p);case 17:return y=u.type,S=u.pendingProps,S=u.elementType===y?S:Gr(y,S),Ec(a,u),u.tag=1,ur(y)?(a=!0,oc(u)):a=!1,Io(u,p),Gb(u,y,S),ch(u,y,S,p),hh(null,u,y,!0,a,p);case 19:return d0(a,u,p);case 22:return s0(a,u,p)}throw Error(n(156,u.tag))};function L0(a,u){return je(a,u)}function Jj(a,u,p,y){this.tag=a,this.key=p,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=u,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=y,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Ir(a,u,p,y){return new Jj(a,u,p,y)}function Oh(a){return a=a.prototype,!(!a||!a.isReactComponent)}function Yj(a){if(typeof a=="function")return Oh(a)?1:0;if(a!=null){if(a=a.$$typeof,a===z)return 11;if(a===U)return 14}return 2}function si(a,u){var p=a.alternate;return p===null?(p=Ir(a.tag,u,a.key,a.mode),p.elementType=a.elementType,p.type=a.type,p.stateNode=a.stateNode,p.alternate=a,a.alternate=p):(p.pendingProps=u,p.type=a.type,p.flags=0,p.subtreeFlags=0,p.deletions=null),p.flags=a.flags&14680064,p.childLanes=a.childLanes,p.lanes=a.lanes,p.child=a.child,p.memoizedProps=a.memoizedProps,p.memoizedState=a.memoizedState,p.updateQueue=a.updateQueue,u=a.dependencies,p.dependencies=u===null?null:{lanes:u.lanes,firstContext:u.firstContext},p.sibling=a.sibling,p.index=a.index,p.ref=a.ref,p}function Lc(a,u,p,y,S,N){var R=2;if(y=a,typeof a=="function")Oh(a)&&(R=1);else if(typeof a=="string")R=5;else e:switch(a){case O:return Vi(p.children,S,N,u);case B:R=8,S|=8;break;case $:return a=Ir(12,p,u,S|2),a.elementType=$,a.lanes=N,a;case G:return a=Ir(13,p,u,S),a.elementType=G,a.lanes=N,a;case D:return a=Ir(19,p,u,S),a.elementType=D,a.lanes=N,a;case se:return Dc(p,S,N,u);default:if(typeof a=="object"&&a!==null)switch(a.$$typeof){case W:R=10;break e;case J:R=9;break e;case z:R=11;break e;case U:R=14;break e;case q:R=16,y=null;break e}throw Error(n(130,a==null?a:typeof a,""))}return u=Ir(R,p,u,S),u.elementType=a,u.type=y,u.lanes=N,u}function Vi(a,u,p,y){return a=Ir(7,a,y,u),a.lanes=p,a}function Dc(a,u,p,y){return a=Ir(22,a,y,u),a.elementType=se,a.lanes=p,a.stateNode={isHidden:!1},a}function Ih(a,u,p){return a=Ir(6,a,null,u),a.lanes=p,a}function Lh(a,u,p){return u=Ir(4,a.children!==null?a.children:[],a.key,u),u.lanes=p,u.stateNode={containerInfo:a.containerInfo,pendingChildren:null,implementation:a.implementation},u}function Xj(a,u,p,y,S){this.tag=u,this.containerInfo=a,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=Us(0),this.expirationTimes=Us(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Us(0),this.identifierPrefix=y,this.onRecoverableError=S,this.mutableSourceEagerHydrationData=null}function Dh(a,u,p,y,S,N,R,H,Y){return a=new Xj(a,u,p,H,Y),u===1?(u=1,N===!0&&(u|=8)):u=0,N=Ir(3,null,null,u),a.current=N,N.stateNode=a,N.memoizedState={element:y,isDehydrated:p,cache:null,transitions:null,pendingSuspenseBoundaries:null},Jf(N),a}function Qj(a,u,p){var y=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:A,key:y==null?null:""+y,children:a,containerInfo:u,implementation:p}}function D0(a){if(!a)return Js;a=a._reactInternals;e:{if(un(a)!==a||a.tag!==1)throw Error(n(170));var u=a;do{switch(u.tag){case 3:u=u.stateNode.context;break e;case 1:if(ur(u.type)){u=u.stateNode.__reactInternalMemoizedMergedChildContext;break e}}u=u.return}while(u!==null);throw Error(n(171))}if(a.tag===1){var p=a.type;if(ur(p))return ub(a,p,u)}return u}function P0(a,u,p,y,S,N,R,H,Y){return a=Dh(p,y,!0,a,S,N,R,H,Y),a.context=D0(null),p=a.current,y=ir(),S=ni(p),N=Ns(y,S),N.callback=u??null,Qs(p,N,S),a.current.lanes=S,Hs(a,S,y),hr(a,y),a}function Pc(a,u,p,y){var S=u.current,N=ir(),R=ni(S);return p=D0(p),u.context===null?u.context=p:u.pendingContext=p,u=Ns(N,R),u.payload={element:a},y=y===void 0?null:y,y!==null&&(u.callback=y),a=Qs(S,u,R),a!==null&&(Xr(a,S,R,N),pc(a,S,R)),R}function Bc(a){if(a=a.current,!a.child)return null;switch(a.child.tag){case 5:return a.child.stateNode;default:return a.child.stateNode}}function B0(a,u){if(a=a.memoizedState,a!==null&&a.dehydrated!==null){var p=a.retryLane;a.retryLane=p!==0&&p<u?p:u}}function Ph(a,u){B0(a,u),(a=a.alternate)&&B0(a,u)}function Zj(){return null}var $0=typeof reportError=="function"?reportError:function(a){console.error(a)};function Bh(a){this._internalRoot=a}$c.prototype.render=Bh.prototype.render=function(a){var u=this._internalRoot;if(u===null)throw Error(n(409));Pc(a,u,null,null)},$c.prototype.unmount=Bh.prototype.unmount=function(){var a=this._internalRoot;if(a!==null){this._internalRoot=null;var u=a.containerInfo;Hi(function(){Pc(null,a,null,null)}),u[xs]=null}};function $c(a){this._internalRoot=a}$c.prototype.unstable_scheduleHydration=function(a){if(a){var u=Oi();a={blockedOn:null,target:a,priority:u};for(var p=0;p<Tn.length&&u!==0&&u<Tn[p].priority;p++);Tn.splice(p,0,a),p===0&&Ny(a)}};function $h(a){return!(!a||a.nodeType!==1&&a.nodeType!==9&&a.nodeType!==11)}function zc(a){return!(!a||a.nodeType!==1&&a.nodeType!==9&&a.nodeType!==11&&(a.nodeType!==8||a.nodeValue!==" react-mount-point-unstable "))}function z0(){}function eM(a,u,p,y,S){if(S){if(typeof y=="function"){var N=y;y=function(){var ue=Bc(R);N.call(ue)}}var R=P0(u,y,a,0,null,!1,!1,"",z0);return a._reactRootContainer=R,a[xs]=R.current,_a(a.nodeType===8?a.parentNode:a),Hi(),R}for(;S=a.lastChild;)a.removeChild(S);if(typeof y=="function"){var H=y;y=function(){var ue=Bc(Y);H.call(ue)}}var Y=Dh(a,0,!1,null,null,!1,!1,"",z0);return a._reactRootContainer=Y,a[xs]=Y.current,_a(a.nodeType===8?a.parentNode:a),Hi(function(){Pc(u,Y,p,y)}),Y}function Fc(a,u,p,y,S){var N=p._reactRootContainer;if(N){var R=N;if(typeof S=="function"){var H=S;S=function(){var Y=Bc(R);H.call(Y)}}Pc(u,R,a,S)}else R=eM(p,u,a,S,y);return Bc(R)}ma=function(a){switch(a.tag){case 3:var u=a.stateNode;if(u.current.memoizedState.isDehydrated){var p=Fs(u.pendingLanes);p!==0&&(pa(u,p|1),hr(u,It()),($t&6)===0&&($o=It()+500,Ys()))}break;case 13:Hi(function(){var y=Es(a,1);if(y!==null){var S=ir();Xr(y,a,1,S)}}),Ph(a,1)}},bn=function(a){if(a.tag===13){var u=Es(a,134217728);if(u!==null){var p=ir();Xr(u,a,134217728,p)}Ph(a,134217728)}},Gt=function(a){if(a.tag===13){var u=ni(a),p=Es(a,u);if(p!==null){var y=ir();Xr(p,a,u,y)}Ph(a,u)}},Oi=function(){return Bt},ls=function(a,u){var p=Bt;try{return Bt=a,u()}finally{Bt=p}},qe=function(a,u,p){switch(u){case"input":if(mt(a,p),u=p.name,p.type==="radio"&&u!=null){for(p=a;p.parentNode;)p=p.parentNode;for(p=p.querySelectorAll("input[name="+JSON.stringify(""+u)+'][type="radio"]'),u=0;u<p.length;u++){var y=p[u];if(y!==a&&y.form===a.form){var S=sc(y);if(!S)throw Error(n(90));Oe(y),mt(y,S)}}}break;case"textarea":X(a,p);break;case"select":u=p.value,u!=null&&ht(a,!!p.multiple,u,!1)}},I=Mh,re=Hi;var tM={usingClientEntryPoint:!1,Events:[Ma,Co,sc,P,Z,Mh]},Wa={findFiberByHostInstance:Li,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},nM={bundleType:Wa.bundleType,version:Wa.version,rendererPackageName:Wa.rendererPackageName,rendererConfig:Wa.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:j.ReactCurrentDispatcher,findHostInstanceByFiber:function(a){return a=is(a),a===null?null:a.stateNode},findFiberByHostInstance:Wa.findFiberByHostInstance||Zj,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var Uc=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Uc.isDisabled&&Uc.supportsFiber)try{Tt=Uc.inject(nM),Ot=Uc}catch{}}return pr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=tM,pr.createPortal=function(a,u){var p=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!$h(u))throw Error(n(200));return Qj(a,u,null,p)},pr.createRoot=function(a,u){if(!$h(a))throw Error(n(299));var p=!1,y="",S=$0;return u!=null&&(u.unstable_strictMode===!0&&(p=!0),u.identifierPrefix!==void 0&&(y=u.identifierPrefix),u.onRecoverableError!==void 0&&(S=u.onRecoverableError)),u=Dh(a,1,!1,null,null,p,!1,y,S),a[xs]=u.current,_a(a.nodeType===8?a.parentNode:a),new Bh(u)},pr.findDOMNode=function(a){if(a==null)return null;if(a.nodeType===1)return a;var u=a._reactInternals;if(u===void 0)throw typeof a.render=="function"?Error(n(188)):(a=Object.keys(a).join(","),Error(n(268,a)));return a=is(u),a=a===null?null:a.stateNode,a},pr.flushSync=function(a){return Hi(a)},pr.hydrate=function(a,u,p){if(!zc(u))throw Error(n(200));return Fc(null,a,u,!0,p)},pr.hydrateRoot=function(a,u,p){if(!$h(a))throw Error(n(405));var y=p!=null&&p.hydratedSources||null,S=!1,N="",R=$0;if(p!=null&&(p.unstable_strictMode===!0&&(S=!0),p.identifierPrefix!==void 0&&(N=p.identifierPrefix),p.onRecoverableError!==void 0&&(R=p.onRecoverableError)),u=P0(u,null,a,1,p??null,S,!1,N,R),a[xs]=u.current,_a(a),y)for(a=0;a<y.length;a++)p=y[a],S=p._getVersion,S=S(p._source),u.mutableSourceEagerHydrationData==null?u.mutableSourceEagerHydrationData=[p,S]:u.mutableSourceEagerHydrationData.push(p,S);return new $c(u)},pr.render=function(a,u,p){if(!zc(u))throw Error(n(200));return Fc(null,a,u,!1,p)},pr.unmountComponentAtNode=function(a){if(!zc(a))throw Error(n(40));return a._reactRootContainer?(Hi(function(){Fc(null,null,a,!1,function(){a._reactRootContainer=null,a[xs]=null})}),!0):!1},pr.unstable_batchedUpdates=Mh,pr.unstable_renderSubtreeIntoContainer=function(a,u,p,y){if(!zc(p))throw Error(n(200));if(a==null||a._reactInternals===void 0)throw Error(n(38));return Fc(a,u,p,!1,y)},pr.version="18.3.1-next-f1338f8080-20240426",pr}var J0;function vE(){if(J0)return Uh.exports;J0=1;function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(e){console.error(e)}}return t(),Uh.exports=cM(),Uh.exports}var Y0;function uM(){if(Y0)return Hc;Y0=1;var t=vE();return Hc.createRoot=t.createRoot,Hc.hydrateRoot=t.hydrateRoot,Hc}var dM=uM();const fM=jl(dM),yE=[{id:"charter",label:"Charter",description:"Charter serif"},{id:"source-serif",label:"Source Serif",description:"Source Serif 4"},{id:"plex-mono",label:"Plex Mono",description:"IBM Plex Mono"},{id:"crimson",label:"Crimson",description:"Crimson Pro"},{id:"inter",label:"Inter",description:"Inter sans-serif"},{id:"baskerville",label:"Baskerville",description:"Libre Baskerville"},{id:"grotesk",label:"Grotesk",description:"Space Grotesk"},{id:"literata",label:"Literata",description:"Literata serif"},{id:"dm-sans",label:"DM Sans",description:"DM Sans + Serif"}],bE=[{id:"files",label:"Files",icon:"files"},{id:"default",label:"Tree",icon:"tree"},{id:"timeline",label:"Timeline",icon:"timeline"},{id:"board",label:"Board",icon:"board"}],xE=[{id:"seamless",label:"Seamless"},{id:"outline",label:"Outline"},{id:"page",label:"Page"},{id:"paper",label:"Paper"}],wE=[{id:"default",label:"Default"},{id:"web",label:"Web"},{id:"blog",label:"Blog"},{id:"butterick",label:"Butterick"}],hM=["full","compact","minimal"],Un={typeface:"ow-typeface",mode:"ow-theme-mode",sidebarMode:"ow-sidebar-mode",sidebarStyle:"ow-sidebar-style",sidebarDensity:"ow-sidebar-density",spacing:"ow-spacing",canvas:"ow-canvas"},pM={ink:"charter",novel:"source-serif",mono:"plex-mono",editorial:"crimson",studio:"inter",prose:"baskerville"};function mM(){const t=localStorage.getItem("ow-theme");if(t&&!localStorage.getItem(Un.typeface)){const n=pM[t];n&&localStorage.setItem(Un.typeface,n),localStorage.removeItem("ow-theme")}localStorage.removeItem("ow-color");const e=localStorage.getItem("ow-typography");e&&!localStorage.getItem(Un.spacing)&&(localStorage.setItem(Un.spacing,e),localStorage.removeItem("ow-typography"))}function kE(){const t=localStorage.getItem(Un.typeface);return t&&yE.some(e=>e.id===t)?t:"charter"}function SE(){const t=localStorage.getItem(Un.mode);return t==="light"||t==="dark"?t:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Rd(){const t=localStorage.getItem(Un.sidebarMode);return t&&bE.some(e=>e.id===t)?t:"files"}function EE(){return"cards"}function NE(){const t=localStorage.getItem(Un.sidebarDensity);return t&&hM.includes(t)?t:"full"}function gM(t){localStorage.setItem(Un.sidebarDensity,t),document.documentElement.setAttribute("data-sidebar-density",t)}function CE(){const t=localStorage.getItem(Un.spacing);return t&&wE.some(e=>e.id===t)?t:"default"}function _E(){const t=localStorage.getItem(Un.canvas);return t&&xE.some(e=>e.id===t)?t:"seamless"}function TE(t,e,n,r,s="default",i="seamless"){const o=document.documentElement;o.setAttribute("data-typeface",t),o.setAttribute("data-mode",e),o.setAttribute("data-sidebar-mode",n),o.setAttribute("data-sidebar-style",r),s==="default"?o.removeAttribute("data-spacing"):o.setAttribute("data-spacing",s),i==="seamless"?o.removeAttribute("data-canvas"):o.setAttribute("data-canvas",i),o.removeAttribute("data-color"),localStorage.setItem(Un.typeface,t),localStorage.setItem(Un.mode,e),localStorage.setItem(Un.sidebarMode,n),localStorage.setItem(Un.sidebarStyle,r),localStorage.setItem(Un.spacing,s),localStorage.setItem(Un.canvas,i)}function vM(){mM(),TE(kE(),SE(),Rd(),EE(),CE(),_E()),document.documentElement.setAttribute("data-sidebar-density",NE())}var jE=vE();const yM=jl(jE);var qh={exports:{}},Vh={};/**
41
41
  * @license React
42
42
  * use-sync-external-store-shim.production.js
43
43
  *
@@ -196,19 +196,19 @@ ${n}
196
196
 
197
197
  `):""}),e6=vn.create({name:"hardBreak",markdownTokenName:"br",addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:t}){return["br",zt(this.options.HTMLAttributes,t)]},renderText(){return`
198
198
  `},renderMarkdown:()=>`
199
- `,parseMarkdown:()=>({type:"hardBreak"}),addCommands(){return{setHardBreak:()=>({commands:t,chain:e,state:n,editor:r})=>t.first([()=>t.exitCode(),()=>t.command(()=>{const{selection:s,storedMarks:i}=n;if(s.$from.parent.type.spec.isolating)return!1;const{keepMarks:o}=this.options,{splittableMarks:l}=r.extensionManager,d=i||s.$to.parentOffset&&s.$from.marks();return e().insertContent({type:this.name}).command(({tr:f,dispatch:h})=>{if(h&&d&&o){const m=d.filter(g=>l.includes(g.type.name));f.ensureMarks(m)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),t6=vn.create({name:"heading",addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:"inline*",group:"block",defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(t=>({tag:`h${t}`,attrs:{level:t}}))},renderHTML({node:t,HTMLAttributes:e}){return[`h${this.options.levels.includes(t.attrs.level)?t.attrs.level:this.options.levels[0]}`,zt(this.options.HTMLAttributes,e),0]},parseMarkdown:(t,e)=>e.createNode("heading",{level:t.depth||1},e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>{var n;const r=(n=t.attrs)!=null&&n.level?parseInt(t.attrs.level,10):1,s="#".repeat(r);return t.content?`${s} ${e.renderChildren(t.content)}`:""},addCommands(){return{setHeading:t=>({commands:e})=>this.options.levels.includes(t.level)?e.setNode(this.name,t):!1,toggleHeading:t=>({commands:e})=>this.options.levels.includes(t.level)?e.toggleNode(this.name,"paragraph",t):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((t,e)=>({...t,[`Mod-Alt-${e}`]:()=>this.editor.commands.toggleHeading({level:e})}),{})},addInputRules(){return this.options.levels.map(t=>Mg({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${t}})\\s$`),type:this.type,getAttributes:{level:t}}))}}),n6=vn.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{},nextNodeType:"paragraph"}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:t}){return["hr",zt(this.options.HTMLAttributes,t)]},markdownTokenName:"hr",parseMarkdown:(t,e)=>e.createNode("horizontalRule"),renderMarkdown:()=>"---",addCommands(){return{setHorizontalRule:()=>({chain:t,state:e})=>{if(!mL(e,e.schema.nodes[this.name]))return!1;const{selection:n}=e,{$to:r}=n,s=t();return xC(n)?s.insertContentAt(r.pos,{type:this.name}):s.insertContent({type:this.name}),s.command(({state:i,tr:o,dispatch:l})=>{if(l){const{$to:d}=o.selection,f=d.end();if(d.nodeAfter)d.nodeAfter.isTextblock?o.setSelection(dt.create(o.doc,d.pos+1)):d.nodeAfter.isBlock?o.setSelection(ut.create(o.doc,d.pos)):o.setSelection(dt.create(o.doc,d.pos));else{const h=i.schema.nodes[this.options.nextNodeType]||d.parent.type.contentMatch.defaultType,m=h==null?void 0:h.create();m&&(o.insert(f,m),o.setSelection(dt.create(o.doc,f+1)))}o.scrollIntoView()}return!0}).run()}}},addInputRules(){return[PC({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),r6=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,s6=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,i6=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,o6=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,a6=ts.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:t=>t.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:t=>t.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:t}){return["em",zt(this.options.HTMLAttributes,t),0]},addCommands(){return{setItalic:()=>({commands:t})=>t.setMark(this.name),toggleItalic:()=>({commands:t})=>t.toggleMark(this.name),unsetItalic:()=>({commands:t})=>t.unsetMark(this.name)}},markdownTokenName:"em",parseMarkdown:(t,e)=>e.applyMark("italic",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`*${e.renderChildren(t)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[co({find:r6,type:this.type}),co({find:i6,type:this.type})]},addPasteRules(){return[Ni({find:s6,type:this.type}),Ni({find:o6,type:this.type})]}}),Vw="&nbsp;",l6=" ",c6=vn.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:t}){return["p",zt(this.options.HTMLAttributes,t),0]},parseMarkdown:(t,e)=>{const n=t.tokens||[];if(n.length===1&&n[0].type==="image")return e.parseChildren([n[0]]);const r=e.parseInline(n);return r.length===1&&r[0].type==="text"&&(r[0].text===Vw||r[0].text===l6)?e.createNode("paragraph",void 0,[]):e.createNode("paragraph",void 0,r)},renderMarkdown:(t,e)=>{if(!t)return"";const n=Array.isArray(t.content)?t.content:[];return n.length===0?Vw:e.renderChildren(n)},addCommands(){return{setParagraph:()=>({commands:t})=>t.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),u6=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,d6=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,f6=ts.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["s",zt(this.options.HTMLAttributes,t),0]},markdownTokenName:"del",parseMarkdown:(t,e)=>e.applyMark("strike",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`~~${e.renderChildren(t)}~~`,addCommands(){return{setStrike:()=>({commands:t})=>t.setMark(this.name),toggleStrike:()=>({commands:t})=>t.toggleMark(this.name),unsetStrike:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[co({find:u6,type:this.type})]},addPasteRules(){return[Ni({find:d6,type:this.type})]}}),h6=vn.create({name:"text",group:"inline",parseMarkdown:t=>({type:"text",text:t.text||""}),renderMarkdown:t=>t.text||""}),p6=Pt.create({name:"starterKit",addExtensions(){var t,e,n,r;const s=[];return this.options.bold!==!1&&s.push(V3.configure(this.options.bold)),this.options.blockquote!==!1&&s.push(F3.configure(this.options.blockquote)),this.options.bulletList!==!1&&s.push(x_.configure(this.options.bulletList)),this.options.code!==!1&&s.push(J3.configure(this.options.code)),this.options.codeBlock!==!1&&s.push(L_.configure(this.options.codeBlock)),this.options.document!==!1&&s.push(Z3.configure(this.options.document)),this.options.dropcursor!==!1&&s.push(_P.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&s.push(TP.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&s.push(e6.configure(this.options.hardBreak)),this.options.heading!==!1&&s.push(t6.configure(this.options.heading)),this.options.undoRedo!==!1&&s.push(RP.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&s.push(n6.configure(this.options.horizontalRule)),this.options.italic!==!1&&s.push(a6.configure(this.options.italic)),this.options.listItem!==!1&&s.push(w_.configure(this.options.listItem)),this.options.listKeymap!==!1&&s.push(__.configure((t=this.options)==null?void 0:t.listKeymap)),this.options.link!==!1&&s.push(t_.configure((e=this.options)==null?void 0:e.link)),this.options.orderedList!==!1&&s.push(j_.configure(this.options.orderedList)),this.options.paragraph!==!1&&s.push(c6.configure(this.options.paragraph)),this.options.strike!==!1&&s.push(f6.configure(this.options.strike)),this.options.text!==!1&&s.push(h6.configure(this.options.text)),this.options.underline!==!1&&s.push(I_.configure((n=this.options)==null?void 0:n.underline)),this.options.trailingNode!==!1&&s.push(AP.configure((r=this.options)==null?void 0:r.trailingNode)),s}}),Gv=p6,Ep,Kw;function m6(){if(Kw)return Ep;Kw=1;function t(P){return P instanceof Map?P.clear=P.delete=P.set=function(){throw new Error("map is read-only")}:P instanceof Set&&(P.add=P.clear=P.delete=function(){throw new Error("set is read-only")}),Object.freeze(P),Object.getOwnPropertyNames(P).forEach(Z=>{const I=P[Z],re=typeof I;(re==="object"||re==="function")&&!Object.isFrozen(I)&&t(I)}),P}class e{constructor(Z){Z.data===void 0&&(Z.data={}),this.data=Z.data,this.isMatchIgnored=!1}ignoreMatch(){this.isMatchIgnored=!0}}function n(P){return P.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;")}function r(P,...Z){const I=Object.create(null);for(const re in P)I[re]=P[re];return Z.forEach(function(re){for(const ye in re)I[ye]=re[ye]}),I}const s="</span>",i=P=>!!P.scope,o=(P,{prefix:Z})=>{if(P.startsWith("language:"))return P.replace("language:","language-");if(P.includes(".")){const I=P.split(".");return[`${Z}${I.shift()}`,...I.map((re,ye)=>`${re}${"_".repeat(ye+1)}`)].join(" ")}return`${Z}${P}`};class l{constructor(Z,I){this.buffer="",this.classPrefix=I.classPrefix,Z.walk(this)}addText(Z){this.buffer+=n(Z)}openNode(Z){if(!i(Z))return;const I=o(Z.scope,{prefix:this.classPrefix});this.span(I)}closeNode(Z){i(Z)&&(this.buffer+=s)}value(){return this.buffer}span(Z){this.buffer+=`<span class="${Z}">`}}const d=(P={})=>{const Z={children:[]};return Object.assign(Z,P),Z};class f{constructor(){this.rootNode=d(),this.stack=[this.rootNode]}get top(){return this.stack[this.stack.length-1]}get root(){return this.rootNode}add(Z){this.top.children.push(Z)}openNode(Z){const I=d({scope:Z});this.add(I),this.stack.push(I)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(Z){return this.constructor._walk(Z,this.rootNode)}static _walk(Z,I){return typeof I=="string"?Z.addText(I):I.children&&(Z.openNode(I),I.children.forEach(re=>this._walk(Z,re)),Z.closeNode(I)),Z}static _collapse(Z){typeof Z!="string"&&Z.children&&(Z.children.every(I=>typeof I=="string")?Z.children=[Z.children.join("")]:Z.children.forEach(I=>{f._collapse(I)}))}}class h extends f{constructor(Z){super(),this.options=Z}addText(Z){Z!==""&&this.add(Z)}startScope(Z){this.openNode(Z)}endScope(){this.closeNode()}__addSublanguage(Z,I){const re=Z.root;I&&(re.scope=`language:${I}`),this.add(re)}toHTML(){return new l(this,this.options).value()}finalize(){return this.closeAllNodes(),!0}}function m(P){return P?typeof P=="string"?P:P.source:null}function g(P){return k("(?=",P,")")}function v(P){return k("(?:",P,")*")}function b(P){return k("(?:",P,")?")}function k(...P){return P.map(I=>m(I)).join("")}function w(P){const Z=P[P.length-1];return typeof Z=="object"&&Z.constructor===Object?(P.splice(P.length-1,1),Z):{}}function E(...P){return"("+(w(P).capture?"":"?:")+P.map(re=>m(re)).join("|")+")"}function C(P){return new RegExp(P.toString()+"|").exec("").length-1}function T(P,Z){const I=P&&P.exec(Z);return I&&I.index===0}const j=/\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;function _(P,{joinWith:Z}){let I=0;return P.map(re=>{I+=1;const ye=I;let Te=m(re),Se="";for(;Te.length>0;){const Ee=j.exec(Te);if(!Ee){Se+=Te;break}Se+=Te.substring(0,Ee.index),Te=Te.substring(Ee.index+Ee[0].length),Ee[0][0]==="\\"&&Ee[1]?Se+="\\"+String(Number(Ee[1])+ye):(Se+=Ee[0],Ee[0]==="("&&I++)}return Se}).map(re=>`(${re})`).join(Z)}const A=/\b\B/,O="[a-zA-Z]\\w*",B="[a-zA-Z_]\\w*",$="\\b\\d+(\\.\\d+)?",W="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",J="\\b(0b[01]+)",z="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",G=(P={})=>{const Z=/^#![ ]*\//;return P.binary&&(P.begin=k(Z,/.*\b/,P.binary,/\b.*/)),r({scope:"meta",begin:Z,end:/$/,relevance:0,"on:begin":(I,re)=>{I.index!==0&&re.ignoreMatch()}},P)},D={begin:"\\\\[\\s\\S]",relevance:0},U={scope:"string",begin:"'",end:"'",illegal:"\\n",contains:[D]},q={scope:"string",begin:'"',end:'"',illegal:"\\n",contains:[D]},se={begin:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},V=function(P,Z,I={}){const re=r({scope:"comment",begin:P,end:Z,contains:[]},I);re.contains.push({scope:"doctag",begin:"[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",end:/(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,excludeBegin:!0,relevance:0});const ye=E("I","a","is","so","us","to","at","if","in","it","on",/[A-Za-z]+['](d|ve|re|ll|t|s|n)/,/[A-Za-z]+[-][a-z]+/,/[A-Za-z][a-z]{2,}/);return re.contains.push({begin:k(/[ ]+/,"(",ye,/[.]?[:]?([.][ ]|[ ])/,"){3}")}),re},te=V("//","$"),K=V("/\\*","\\*/"),M=V("#","$"),L={scope:"number",begin:$,relevance:0},ee={scope:"number",begin:W,relevance:0},fe={scope:"number",begin:J,relevance:0},ge={scope:"regexp",begin:/\/(?=[^/\n]*\/)/,end:/\/[gimuy]*/,contains:[D,{begin:/\[/,end:/\]/,relevance:0,contains:[D]}]},oe={scope:"title",begin:O,relevance:0},we={scope:"title",begin:B,relevance:0},xe={begin:"\\.\\s*"+B,relevance:0};var He=Object.freeze({__proto__:null,APOS_STRING_MODE:U,BACKSLASH_ESCAPE:D,BINARY_NUMBER_MODE:fe,BINARY_NUMBER_RE:J,COMMENT:V,C_BLOCK_COMMENT_MODE:K,C_LINE_COMMENT_MODE:te,C_NUMBER_MODE:ee,C_NUMBER_RE:W,END_SAME_AS_BEGIN:function(P){return Object.assign(P,{"on:begin":(Z,I)=>{I.data._beginMatch=Z[1]},"on:end":(Z,I)=>{I.data._beginMatch!==Z[1]&&I.ignoreMatch()}})},HASH_COMMENT_MODE:M,IDENT_RE:O,MATCH_NOTHING_RE:A,METHOD_GUARD:xe,NUMBER_MODE:L,NUMBER_RE:$,PHRASAL_WORDS_MODE:se,QUOTE_STRING_MODE:q,REGEXP_MODE:ge,RE_STARTERS_RE:z,SHEBANG:G,TITLE_MODE:oe,UNDERSCORE_IDENT_RE:B,UNDERSCORE_TITLE_MODE:we});function Ze(P,Z){P.input[P.index-1]==="."&&Z.ignoreMatch()}function Oe(P,Z){P.className!==void 0&&(P.scope=P.className,delete P.className)}function Ke(P,Z){Z&&P.beginKeywords&&(P.begin="\\b("+P.beginKeywords.split(" ").join("|")+")(?!\\.)(?=\\b|\\s)",P.__beforeBegin=Ze,P.keywords=P.keywords||P.beginKeywords,delete P.beginKeywords,P.relevance===void 0&&(P.relevance=0))}function pt(P,Z){Array.isArray(P.illegal)&&(P.illegal=E(...P.illegal))}function Je(P,Z){if(P.match){if(P.begin||P.end)throw new Error("begin & end are not supported with match");P.begin=P.match,delete P.match}}function pe(P,Z){P.relevance===void 0&&(P.relevance=1)}const mt=(P,Z)=>{if(!P.beforeMatch)return;if(P.starts)throw new Error("beforeMatch cannot be used with starts");const I=Object.assign({},P);Object.keys(P).forEach(re=>{delete P[re]}),P.keywords=I.keywords,P.begin=k(I.beforeMatch,g(I.begin)),P.starts={relevance:0,contains:[Object.assign(I,{endsParent:!0})]},P.relevance=0,delete I.beforeMatch},ft=["of","and","for","in","not","or","if","then","parent","list","value"],at="keyword";function nt(P,Z,I=at){const re=Object.create(null);return typeof P=="string"?ye(I,P.split(" ")):Array.isArray(P)?ye(I,P):Object.keys(P).forEach(function(Te){Object.assign(re,nt(P[Te],Z,Te))}),re;function ye(Te,Se){Z&&(Se=Se.map(Ee=>Ee.toLowerCase())),Se.forEach(function(Ee){const me=Ee.split("|");re[me[0]]=[Te,ht(me[0],me[1])]})}}function ht(P,Z){return Z?Number(Z):Fe(P)?0:1}function Fe(P){return ft.includes(P.toLowerCase())}const ve={},X=P=>{console.error(P)},Be=(P,...Z)=>{console.log(`WARN: ${P}`,...Z)},ne=(P,Z)=>{ve[`${P}/${Z}`]||(console.log(`Deprecated as of ${P}. ${Z}`),ve[`${P}/${Z}`]=!0)},de=new Error;function he(P,Z,{key:I}){let re=0;const ye=P[I],Te={},Se={};for(let Ee=1;Ee<=Z.length;Ee++)Se[Ee+re]=ye[Ee],Te[Ee+re]=!0,re+=C(Z[Ee-1]);P[I]=Se,P[I]._emit=Te,P[I]._multi=!0}function Ge(P){if(Array.isArray(P.begin)){if(P.skip||P.excludeBegin||P.returnBegin)throw X("skip, excludeBegin, returnBegin not compatible with beginScope: {}"),de;if(typeof P.beginScope!="object"||P.beginScope===null)throw X("beginScope must be object"),de;he(P,P.begin,{key:"beginScope"}),P.begin=_(P.begin,{joinWith:""})}}function Pe(P){if(Array.isArray(P.end)){if(P.skip||P.excludeEnd||P.returnEnd)throw X("skip, excludeEnd, returnEnd not compatible with endScope: {}"),de;if(typeof P.endScope!="object"||P.endScope===null)throw X("endScope must be object"),de;he(P,P.end,{key:"endScope"}),P.end=_(P.end,{joinWith:""})}}function et(P){P.scope&&typeof P.scope=="object"&&P.scope!==null&&(P.beginScope=P.scope,delete P.scope)}function ot(P){et(P),typeof P.beginScope=="string"&&(P.beginScope={_wrap:P.beginScope}),typeof P.endScope=="string"&&(P.endScope={_wrap:P.endScope}),Ge(P),Pe(P)}function bt(P){function Z(Se,Ee){return new RegExp(m(Se),"m"+(P.case_insensitive?"i":"")+(P.unicodeRegex?"u":"")+(Ee?"g":""))}class I{constructor(){this.matchIndexes={},this.regexes=[],this.matchAt=1,this.position=0}addRule(Ee,me){me.position=this.position++,this.matchIndexes[this.matchAt]=me,this.regexes.push([me,Ee]),this.matchAt+=C(Ee)+1}compile(){this.regexes.length===0&&(this.exec=()=>null);const Ee=this.regexes.map(me=>me[1]);this.matcherRe=Z(_(Ee,{joinWith:"|"}),!0),this.lastIndex=0}exec(Ee){this.matcherRe.lastIndex=this.lastIndex;const me=this.matcherRe.exec(Ee);if(!me)return null;const ke=me.findIndex((en,on)=>on>0&&en!==void 0),Ct=this.matchIndexes[ke];return me.splice(0,ke),Object.assign(me,Ct)}}class re{constructor(){this.rules=[],this.multiRegexes=[],this.count=0,this.lastIndex=0,this.regexIndex=0}getMatcher(Ee){if(this.multiRegexes[Ee])return this.multiRegexes[Ee];const me=new I;return this.rules.slice(Ee).forEach(([ke,Ct])=>me.addRule(ke,Ct)),me.compile(),this.multiRegexes[Ee]=me,me}resumingScanAtSamePosition(){return this.regexIndex!==0}considerAll(){this.regexIndex=0}addRule(Ee,me){this.rules.push([Ee,me]),me.type==="begin"&&this.count++}exec(Ee){const me=this.getMatcher(this.regexIndex);me.lastIndex=this.lastIndex;let ke=me.exec(Ee);if(this.resumingScanAtSamePosition()&&!(ke&&ke.index===this.lastIndex)){const Ct=this.getMatcher(0);Ct.lastIndex=this.lastIndex+1,ke=Ct.exec(Ee)}return ke&&(this.regexIndex+=ke.position+1,this.regexIndex===this.count&&this.considerAll()),ke}}function ye(Se){const Ee=new re;return Se.contains.forEach(me=>Ee.addRule(me.begin,{rule:me,type:"begin"})),Se.terminatorEnd&&Ee.addRule(Se.terminatorEnd,{type:"end"}),Se.illegal&&Ee.addRule(Se.illegal,{type:"illegal"}),Ee}function Te(Se,Ee){const me=Se;if(Se.isCompiled)return me;[Oe,Je,ot,mt].forEach(Ct=>Ct(Se,Ee)),P.compilerExtensions.forEach(Ct=>Ct(Se,Ee)),Se.__beforeBegin=null,[Ke,pt,pe].forEach(Ct=>Ct(Se,Ee)),Se.isCompiled=!0;let ke=null;return typeof Se.keywords=="object"&&Se.keywords.$pattern&&(Se.keywords=Object.assign({},Se.keywords),ke=Se.keywords.$pattern,delete Se.keywords.$pattern),ke=ke||/\w+/,Se.keywords&&(Se.keywords=nt(Se.keywords,P.case_insensitive)),me.keywordPatternRe=Z(ke,!0),Ee&&(Se.begin||(Se.begin=/\B|\b/),me.beginRe=Z(me.begin),!Se.end&&!Se.endsWithParent&&(Se.end=/\B|\b/),Se.end&&(me.endRe=Z(me.end)),me.terminatorEnd=m(me.end)||"",Se.endsWithParent&&Ee.terminatorEnd&&(me.terminatorEnd+=(Se.end?"|":"")+Ee.terminatorEnd)),Se.illegal&&(me.illegalRe=Z(Se.illegal)),Se.contains||(Se.contains=[]),Se.contains=[].concat(...Se.contains.map(function(Ct){return it(Ct==="self"?Se:Ct)})),Se.contains.forEach(function(Ct){Te(Ct,me)}),Se.starts&&Te(Se.starts,Ee),me.matcher=ye(me),me}if(P.compilerExtensions||(P.compilerExtensions=[]),P.contains&&P.contains.includes("self"))throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");return P.classNameAliases=r(P.classNameAliases||{}),Te(P)}function Ye(P){return P?P.endsWithParent||Ye(P.starts):!1}function it(P){return P.variants&&!P.cachedVariants&&(P.cachedVariants=P.variants.map(function(Z){return r(P,{variants:null},Z)})),P.cachedVariants?P.cachedVariants:Ye(P)?r(P,{starts:P.starts?r(P.starts):null}):Object.isFrozen(P)?r(P):P}var gt="11.11.1";class Nt extends Error{constructor(Z,I){super(Z),this.name="HTMLInjectionError",this.html=I}}const Ie=n,Me=r,qe=Symbol("nomatch"),F=7,ce=function(P){const Z=Object.create(null),I=Object.create(null),re=[];let ye=!0;const Te="Could not find the language '{}', did you forget to load/include a language module?",Se={disableAutodetect:!0,name:"Plain text",contains:[]};let Ee={ignoreUnescapedHTML:!1,throwUnescapedHTML:!1,noHighlightRe:/^(no-?highlight)$/i,languageDetectRe:/\blang(?:uage)?-([\w-]+)\b/i,classPrefix:"hljs-",cssSelector:"pre code",languages:null,__emitter:h};function me(Le){return Ee.noHighlightRe.test(Le)}function ke(Le){let lt=Le.className+" ";lt+=Le.parentNode?Le.parentNode.className:"";const Tt=Ee.languageDetectRe.exec(lt);if(Tt){const Ot=ze(Tt[1]);return Ot||(Be(Te.replace("{}",Tt[1])),Be("Falling back to no-highlight mode for this block.",Le)),Ot?Tt[1]:"no-highlight"}return lt.split(/\s+/).find(Ot=>me(Ot)||ze(Ot))}function Ct(Le,lt,Tt){let Ot="",yn="";typeof lt=="object"?(Ot=Le,Tt=lt.ignoreIllegals,yn=lt.language):(ne("10.7.0","highlight(lang, code, ...args) has been deprecated."),ne("10.7.0",`Please use highlight(code, options) instead.
199
+ `,parseMarkdown:()=>({type:"hardBreak"}),addCommands(){return{setHardBreak:()=>({commands:t,chain:e,state:n,editor:r})=>t.first([()=>t.exitCode(),()=>t.command(()=>{const{selection:s,storedMarks:i}=n;if(s.$from.parent.type.spec.isolating)return!1;const{keepMarks:o}=this.options,{splittableMarks:l}=r.extensionManager,d=i||s.$to.parentOffset&&s.$from.marks();return e().insertContent({type:this.name}).command(({tr:f,dispatch:h})=>{if(h&&d&&o){const m=d.filter(g=>l.includes(g.type.name));f.ensureMarks(m)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),t6=vn.create({name:"heading",addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:"inline*",group:"block",defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(t=>({tag:`h${t}`,attrs:{level:t}}))},renderHTML({node:t,HTMLAttributes:e}){return[`h${this.options.levels.includes(t.attrs.level)?t.attrs.level:this.options.levels[0]}`,zt(this.options.HTMLAttributes,e),0]},parseMarkdown:(t,e)=>e.createNode("heading",{level:t.depth||1},e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>{var n;const r=(n=t.attrs)!=null&&n.level?parseInt(t.attrs.level,10):1,s="#".repeat(r);return t.content?`${s} ${e.renderChildren(t.content)}`:""},addCommands(){return{setHeading:t=>({commands:e})=>this.options.levels.includes(t.level)?e.setNode(this.name,t):!1,toggleHeading:t=>({commands:e})=>this.options.levels.includes(t.level)?e.toggleNode(this.name,"paragraph",t):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((t,e)=>({...t,[`Mod-Alt-${e}`]:()=>this.editor.commands.toggleHeading({level:e})}),{})},addInputRules(){return this.options.levels.map(t=>Mg({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${t}})\\s$`),type:this.type,getAttributes:{level:t}}))}}),n6=vn.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{},nextNodeType:"paragraph"}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:t}){return["hr",zt(this.options.HTMLAttributes,t)]},markdownTokenName:"hr",parseMarkdown:(t,e)=>e.createNode("horizontalRule"),renderMarkdown:()=>"---",addCommands(){return{setHorizontalRule:()=>({chain:t,state:e})=>{if(!mL(e,e.schema.nodes[this.name]))return!1;const{selection:n}=e,{$to:r}=n,s=t();return xC(n)?s.insertContentAt(r.pos,{type:this.name}):s.insertContent({type:this.name}),s.command(({state:i,tr:o,dispatch:l})=>{if(l){const{$to:d}=o.selection,f=d.end();if(d.nodeAfter)d.nodeAfter.isTextblock?o.setSelection(dt.create(o.doc,d.pos+1)):d.nodeAfter.isBlock?o.setSelection(ut.create(o.doc,d.pos)):o.setSelection(dt.create(o.doc,d.pos));else{const h=i.schema.nodes[this.options.nextNodeType]||d.parent.type.contentMatch.defaultType,m=h==null?void 0:h.create();m&&(o.insert(f,m),o.setSelection(dt.create(o.doc,f+1)))}o.scrollIntoView()}return!0}).run()}}},addInputRules(){return[PC({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),r6=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,s6=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,i6=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,o6=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,a6=ts.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:t=>t.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:t=>t.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:t}){return["em",zt(this.options.HTMLAttributes,t),0]},addCommands(){return{setItalic:()=>({commands:t})=>t.setMark(this.name),toggleItalic:()=>({commands:t})=>t.toggleMark(this.name),unsetItalic:()=>({commands:t})=>t.unsetMark(this.name)}},markdownTokenName:"em",parseMarkdown:(t,e)=>e.applyMark("italic",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`*${e.renderChildren(t)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[co({find:r6,type:this.type}),co({find:i6,type:this.type})]},addPasteRules(){return[Ni({find:s6,type:this.type}),Ni({find:o6,type:this.type})]}}),Vw="&nbsp;",l6=" ",c6=vn.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:t}){return["p",zt(this.options.HTMLAttributes,t),0]},parseMarkdown:(t,e)=>{const n=t.tokens||[];if(n.length===1&&n[0].type==="image")return e.parseChildren([n[0]]);const r=e.parseInline(n);return r.length===1&&r[0].type==="text"&&(r[0].text===Vw||r[0].text===l6)?e.createNode("paragraph",void 0,[]):e.createNode("paragraph",void 0,r)},renderMarkdown:(t,e)=>{if(!t)return"";const n=Array.isArray(t.content)?t.content:[];return n.length===0?Vw:e.renderChildren(n)},addCommands(){return{setParagraph:()=>({commands:t})=>t.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),u6=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,d6=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,f6=ts.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:t=>t.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:t}){return["s",zt(this.options.HTMLAttributes,t),0]},markdownTokenName:"del",parseMarkdown:(t,e)=>e.applyMark("strike",e.parseInline(t.tokens||[])),renderMarkdown:(t,e)=>`~~${e.renderChildren(t)}~~`,addCommands(){return{setStrike:()=>({commands:t})=>t.setMark(this.name),toggleStrike:()=>({commands:t})=>t.toggleMark(this.name),unsetStrike:()=>({commands:t})=>t.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[co({find:u6,type:this.type})]},addPasteRules(){return[Ni({find:d6,type:this.type})]}}),h6=vn.create({name:"text",group:"inline",parseMarkdown:t=>({type:"text",text:t.text||""}),renderMarkdown:t=>t.text||""}),p6=Pt.create({name:"starterKit",addExtensions(){var t,e,n,r;const s=[];return this.options.bold!==!1&&s.push(V3.configure(this.options.bold)),this.options.blockquote!==!1&&s.push(F3.configure(this.options.blockquote)),this.options.bulletList!==!1&&s.push(x_.configure(this.options.bulletList)),this.options.code!==!1&&s.push(J3.configure(this.options.code)),this.options.codeBlock!==!1&&s.push(L_.configure(this.options.codeBlock)),this.options.document!==!1&&s.push(Z3.configure(this.options.document)),this.options.dropcursor!==!1&&s.push(_P.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&s.push(TP.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&s.push(e6.configure(this.options.hardBreak)),this.options.heading!==!1&&s.push(t6.configure(this.options.heading)),this.options.undoRedo!==!1&&s.push(RP.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&s.push(n6.configure(this.options.horizontalRule)),this.options.italic!==!1&&s.push(a6.configure(this.options.italic)),this.options.listItem!==!1&&s.push(w_.configure(this.options.listItem)),this.options.listKeymap!==!1&&s.push(__.configure((t=this.options)==null?void 0:t.listKeymap)),this.options.link!==!1&&s.push(t_.configure((e=this.options)==null?void 0:e.link)),this.options.orderedList!==!1&&s.push(j_.configure(this.options.orderedList)),this.options.paragraph!==!1&&s.push(c6.configure(this.options.paragraph)),this.options.strike!==!1&&s.push(f6.configure(this.options.strike)),this.options.text!==!1&&s.push(h6.configure(this.options.text)),this.options.underline!==!1&&s.push(I_.configure((n=this.options)==null?void 0:n.underline)),this.options.trailingNode!==!1&&s.push(AP.configure((r=this.options)==null?void 0:r.trailingNode)),s}}),Gv=p6,Ep,Kw;function m6(){if(Kw)return Ep;Kw=1;function t(P){return P instanceof Map?P.clear=P.delete=P.set=function(){throw new Error("map is read-only")}:P instanceof Set&&(P.add=P.clear=P.delete=function(){throw new Error("set is read-only")}),Object.freeze(P),Object.getOwnPropertyNames(P).forEach(Z=>{const I=P[Z],re=typeof I;(re==="object"||re==="function")&&!Object.isFrozen(I)&&t(I)}),P}class e{constructor(Z){Z.data===void 0&&(Z.data={}),this.data=Z.data,this.isMatchIgnored=!1}ignoreMatch(){this.isMatchIgnored=!0}}function n(P){return P.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;")}function r(P,...Z){const I=Object.create(null);for(const re in P)I[re]=P[re];return Z.forEach(function(re){for(const ye in re)I[ye]=re[ye]}),I}const s="</span>",i=P=>!!P.scope,o=(P,{prefix:Z})=>{if(P.startsWith("language:"))return P.replace("language:","language-");if(P.includes(".")){const I=P.split(".");return[`${Z}${I.shift()}`,...I.map((re,ye)=>`${re}${"_".repeat(ye+1)}`)].join(" ")}return`${Z}${P}`};class l{constructor(Z,I){this.buffer="",this.classPrefix=I.classPrefix,Z.walk(this)}addText(Z){this.buffer+=n(Z)}openNode(Z){if(!i(Z))return;const I=o(Z.scope,{prefix:this.classPrefix});this.span(I)}closeNode(Z){i(Z)&&(this.buffer+=s)}value(){return this.buffer}span(Z){this.buffer+=`<span class="${Z}">`}}const d=(P={})=>{const Z={children:[]};return Object.assign(Z,P),Z};class f{constructor(){this.rootNode=d(),this.stack=[this.rootNode]}get top(){return this.stack[this.stack.length-1]}get root(){return this.rootNode}add(Z){this.top.children.push(Z)}openNode(Z){const I=d({scope:Z});this.add(I),this.stack.push(I)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(Z){return this.constructor._walk(Z,this.rootNode)}static _walk(Z,I){return typeof I=="string"?Z.addText(I):I.children&&(Z.openNode(I),I.children.forEach(re=>this._walk(Z,re)),Z.closeNode(I)),Z}static _collapse(Z){typeof Z!="string"&&Z.children&&(Z.children.every(I=>typeof I=="string")?Z.children=[Z.children.join("")]:Z.children.forEach(I=>{f._collapse(I)}))}}class h extends f{constructor(Z){super(),this.options=Z}addText(Z){Z!==""&&this.add(Z)}startScope(Z){this.openNode(Z)}endScope(){this.closeNode()}__addSublanguage(Z,I){const re=Z.root;I&&(re.scope=`language:${I}`),this.add(re)}toHTML(){return new l(this,this.options).value()}finalize(){return this.closeAllNodes(),!0}}function m(P){return P?typeof P=="string"?P:P.source:null}function g(P){return k("(?=",P,")")}function v(P){return k("(?:",P,")*")}function b(P){return k("(?:",P,")?")}function k(...P){return P.map(I=>m(I)).join("")}function w(P){const Z=P[P.length-1];return typeof Z=="object"&&Z.constructor===Object?(P.splice(P.length-1,1),Z):{}}function E(...P){return"("+(w(P).capture?"":"?:")+P.map(re=>m(re)).join("|")+")"}function C(P){return new RegExp(P.toString()+"|").exec("").length-1}function T(P,Z){const I=P&&P.exec(Z);return I&&I.index===0}const j=/\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;function _(P,{joinWith:Z}){let I=0;return P.map(re=>{I+=1;const ye=I;let Te=m(re),Se="";for(;Te.length>0;){const Ee=j.exec(Te);if(!Ee){Se+=Te;break}Se+=Te.substring(0,Ee.index),Te=Te.substring(Ee.index+Ee[0].length),Ee[0][0]==="\\"&&Ee[1]?Se+="\\"+String(Number(Ee[1])+ye):(Se+=Ee[0],Ee[0]==="("&&I++)}return Se}).map(re=>`(${re})`).join(Z)}const A=/\b\B/,O="[a-zA-Z]\\w*",B="[a-zA-Z_]\\w*",$="\\b\\d+(\\.\\d+)?",W="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",J="\\b(0b[01]+)",z="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",G=(P={})=>{const Z=/^#![ ]*\//;return P.binary&&(P.begin=k(Z,/.*\b/,P.binary,/\b.*/)),r({scope:"meta",begin:Z,end:/$/,relevance:0,"on:begin":(I,re)=>{I.index!==0&&re.ignoreMatch()}},P)},D={begin:"\\\\[\\s\\S]",relevance:0},U={scope:"string",begin:"'",end:"'",illegal:"\\n",contains:[D]},q={scope:"string",begin:'"',end:'"',illegal:"\\n",contains:[D]},se={begin:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},V=function(P,Z,I={}){const re=r({scope:"comment",begin:P,end:Z,contains:[]},I);re.contains.push({scope:"doctag",begin:"[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",end:/(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,excludeBegin:!0,relevance:0});const ye=E("I","a","is","so","us","to","at","if","in","it","on",/[A-Za-z]+['](d|ve|re|ll|t|s|n)/,/[A-Za-z]+[-][a-z]+/,/[A-Za-z][a-z]{2,}/);return re.contains.push({begin:k(/[ ]+/,"(",ye,/[.]?[:]?([.][ ]|[ ])/,"){3}")}),re},te=V("//","$"),K=V("/\\*","\\*/"),M=V("#","$"),L={scope:"number",begin:$,relevance:0},ee={scope:"number",begin:W,relevance:0},fe={scope:"number",begin:J,relevance:0},ge={scope:"regexp",begin:/\/(?=[^/\n]*\/)/,end:/\/[gimuy]*/,contains:[D,{begin:/\[/,end:/\]/,relevance:0,contains:[D]}]},oe={scope:"title",begin:O,relevance:0},xe={scope:"title",begin:B,relevance:0},we={begin:"\\.\\s*"+B,relevance:0};var He=Object.freeze({__proto__:null,APOS_STRING_MODE:U,BACKSLASH_ESCAPE:D,BINARY_NUMBER_MODE:fe,BINARY_NUMBER_RE:J,COMMENT:V,C_BLOCK_COMMENT_MODE:K,C_LINE_COMMENT_MODE:te,C_NUMBER_MODE:ee,C_NUMBER_RE:W,END_SAME_AS_BEGIN:function(P){return Object.assign(P,{"on:begin":(Z,I)=>{I.data._beginMatch=Z[1]},"on:end":(Z,I)=>{I.data._beginMatch!==Z[1]&&I.ignoreMatch()}})},HASH_COMMENT_MODE:M,IDENT_RE:O,MATCH_NOTHING_RE:A,METHOD_GUARD:we,NUMBER_MODE:L,NUMBER_RE:$,PHRASAL_WORDS_MODE:se,QUOTE_STRING_MODE:q,REGEXP_MODE:ge,RE_STARTERS_RE:z,SHEBANG:G,TITLE_MODE:oe,UNDERSCORE_IDENT_RE:B,UNDERSCORE_TITLE_MODE:xe});function Ze(P,Z){P.input[P.index-1]==="."&&Z.ignoreMatch()}function Oe(P,Z){P.className!==void 0&&(P.scope=P.className,delete P.className)}function Ke(P,Z){Z&&P.beginKeywords&&(P.begin="\\b("+P.beginKeywords.split(" ").join("|")+")(?!\\.)(?=\\b|\\s)",P.__beforeBegin=Ze,P.keywords=P.keywords||P.beginKeywords,delete P.beginKeywords,P.relevance===void 0&&(P.relevance=0))}function pt(P,Z){Array.isArray(P.illegal)&&(P.illegal=E(...P.illegal))}function Je(P,Z){if(P.match){if(P.begin||P.end)throw new Error("begin & end are not supported with match");P.begin=P.match,delete P.match}}function pe(P,Z){P.relevance===void 0&&(P.relevance=1)}const mt=(P,Z)=>{if(!P.beforeMatch)return;if(P.starts)throw new Error("beforeMatch cannot be used with starts");const I=Object.assign({},P);Object.keys(P).forEach(re=>{delete P[re]}),P.keywords=I.keywords,P.begin=k(I.beforeMatch,g(I.begin)),P.starts={relevance:0,contains:[Object.assign(I,{endsParent:!0})]},P.relevance=0,delete I.beforeMatch},ft=["of","and","for","in","not","or","if","then","parent","list","value"],at="keyword";function nt(P,Z,I=at){const re=Object.create(null);return typeof P=="string"?ye(I,P.split(" ")):Array.isArray(P)?ye(I,P):Object.keys(P).forEach(function(Te){Object.assign(re,nt(P[Te],Z,Te))}),re;function ye(Te,Se){Z&&(Se=Se.map(Ee=>Ee.toLowerCase())),Se.forEach(function(Ee){const me=Ee.split("|");re[me[0]]=[Te,ht(me[0],me[1])]})}}function ht(P,Z){return Z?Number(Z):Fe(P)?0:1}function Fe(P){return ft.includes(P.toLowerCase())}const ve={},X=P=>{console.error(P)},Be=(P,...Z)=>{console.log(`WARN: ${P}`,...Z)},ne=(P,Z)=>{ve[`${P}/${Z}`]||(console.log(`Deprecated as of ${P}. ${Z}`),ve[`${P}/${Z}`]=!0)},de=new Error;function he(P,Z,{key:I}){let re=0;const ye=P[I],Te={},Se={};for(let Ee=1;Ee<=Z.length;Ee++)Se[Ee+re]=ye[Ee],Te[Ee+re]=!0,re+=C(Z[Ee-1]);P[I]=Se,P[I]._emit=Te,P[I]._multi=!0}function Ge(P){if(Array.isArray(P.begin)){if(P.skip||P.excludeBegin||P.returnBegin)throw X("skip, excludeBegin, returnBegin not compatible with beginScope: {}"),de;if(typeof P.beginScope!="object"||P.beginScope===null)throw X("beginScope must be object"),de;he(P,P.begin,{key:"beginScope"}),P.begin=_(P.begin,{joinWith:""})}}function Pe(P){if(Array.isArray(P.end)){if(P.skip||P.excludeEnd||P.returnEnd)throw X("skip, excludeEnd, returnEnd not compatible with endScope: {}"),de;if(typeof P.endScope!="object"||P.endScope===null)throw X("endScope must be object"),de;he(P,P.end,{key:"endScope"}),P.end=_(P.end,{joinWith:""})}}function et(P){P.scope&&typeof P.scope=="object"&&P.scope!==null&&(P.beginScope=P.scope,delete P.scope)}function ot(P){et(P),typeof P.beginScope=="string"&&(P.beginScope={_wrap:P.beginScope}),typeof P.endScope=="string"&&(P.endScope={_wrap:P.endScope}),Ge(P),Pe(P)}function bt(P){function Z(Se,Ee){return new RegExp(m(Se),"m"+(P.case_insensitive?"i":"")+(P.unicodeRegex?"u":"")+(Ee?"g":""))}class I{constructor(){this.matchIndexes={},this.regexes=[],this.matchAt=1,this.position=0}addRule(Ee,me){me.position=this.position++,this.matchIndexes[this.matchAt]=me,this.regexes.push([me,Ee]),this.matchAt+=C(Ee)+1}compile(){this.regexes.length===0&&(this.exec=()=>null);const Ee=this.regexes.map(me=>me[1]);this.matcherRe=Z(_(Ee,{joinWith:"|"}),!0),this.lastIndex=0}exec(Ee){this.matcherRe.lastIndex=this.lastIndex;const me=this.matcherRe.exec(Ee);if(!me)return null;const ke=me.findIndex((en,on)=>on>0&&en!==void 0),Ct=this.matchIndexes[ke];return me.splice(0,ke),Object.assign(me,Ct)}}class re{constructor(){this.rules=[],this.multiRegexes=[],this.count=0,this.lastIndex=0,this.regexIndex=0}getMatcher(Ee){if(this.multiRegexes[Ee])return this.multiRegexes[Ee];const me=new I;return this.rules.slice(Ee).forEach(([ke,Ct])=>me.addRule(ke,Ct)),me.compile(),this.multiRegexes[Ee]=me,me}resumingScanAtSamePosition(){return this.regexIndex!==0}considerAll(){this.regexIndex=0}addRule(Ee,me){this.rules.push([Ee,me]),me.type==="begin"&&this.count++}exec(Ee){const me=this.getMatcher(this.regexIndex);me.lastIndex=this.lastIndex;let ke=me.exec(Ee);if(this.resumingScanAtSamePosition()&&!(ke&&ke.index===this.lastIndex)){const Ct=this.getMatcher(0);Ct.lastIndex=this.lastIndex+1,ke=Ct.exec(Ee)}return ke&&(this.regexIndex+=ke.position+1,this.regexIndex===this.count&&this.considerAll()),ke}}function ye(Se){const Ee=new re;return Se.contains.forEach(me=>Ee.addRule(me.begin,{rule:me,type:"begin"})),Se.terminatorEnd&&Ee.addRule(Se.terminatorEnd,{type:"end"}),Se.illegal&&Ee.addRule(Se.illegal,{type:"illegal"}),Ee}function Te(Se,Ee){const me=Se;if(Se.isCompiled)return me;[Oe,Je,ot,mt].forEach(Ct=>Ct(Se,Ee)),P.compilerExtensions.forEach(Ct=>Ct(Se,Ee)),Se.__beforeBegin=null,[Ke,pt,pe].forEach(Ct=>Ct(Se,Ee)),Se.isCompiled=!0;let ke=null;return typeof Se.keywords=="object"&&Se.keywords.$pattern&&(Se.keywords=Object.assign({},Se.keywords),ke=Se.keywords.$pattern,delete Se.keywords.$pattern),ke=ke||/\w+/,Se.keywords&&(Se.keywords=nt(Se.keywords,P.case_insensitive)),me.keywordPatternRe=Z(ke,!0),Ee&&(Se.begin||(Se.begin=/\B|\b/),me.beginRe=Z(me.begin),!Se.end&&!Se.endsWithParent&&(Se.end=/\B|\b/),Se.end&&(me.endRe=Z(me.end)),me.terminatorEnd=m(me.end)||"",Se.endsWithParent&&Ee.terminatorEnd&&(me.terminatorEnd+=(Se.end?"|":"")+Ee.terminatorEnd)),Se.illegal&&(me.illegalRe=Z(Se.illegal)),Se.contains||(Se.contains=[]),Se.contains=[].concat(...Se.contains.map(function(Ct){return it(Ct==="self"?Se:Ct)})),Se.contains.forEach(function(Ct){Te(Ct,me)}),Se.starts&&Te(Se.starts,Ee),me.matcher=ye(me),me}if(P.compilerExtensions||(P.compilerExtensions=[]),P.contains&&P.contains.includes("self"))throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");return P.classNameAliases=r(P.classNameAliases||{}),Te(P)}function Ye(P){return P?P.endsWithParent||Ye(P.starts):!1}function it(P){return P.variants&&!P.cachedVariants&&(P.cachedVariants=P.variants.map(function(Z){return r(P,{variants:null},Z)})),P.cachedVariants?P.cachedVariants:Ye(P)?r(P,{starts:P.starts?r(P.starts):null}):Object.isFrozen(P)?r(P):P}var gt="11.11.1";class Nt extends Error{constructor(Z,I){super(Z),this.name="HTMLInjectionError",this.html=I}}const Ie=n,Me=r,qe=Symbol("nomatch"),F=7,ce=function(P){const Z=Object.create(null),I=Object.create(null),re=[];let ye=!0;const Te="Could not find the language '{}', did you forget to load/include a language module?",Se={disableAutodetect:!0,name:"Plain text",contains:[]};let Ee={ignoreUnescapedHTML:!1,throwUnescapedHTML:!1,noHighlightRe:/^(no-?highlight)$/i,languageDetectRe:/\blang(?:uage)?-([\w-]+)\b/i,classPrefix:"hljs-",cssSelector:"pre code",languages:null,__emitter:h};function me(Le){return Ee.noHighlightRe.test(Le)}function ke(Le){let lt=Le.className+" ";lt+=Le.parentNode?Le.parentNode.className:"";const Tt=Ee.languageDetectRe.exec(lt);if(Tt){const Ot=ze(Tt[1]);return Ot||(Be(Te.replace("{}",Tt[1])),Be("Falling back to no-highlight mode for this block.",Le)),Ot?Tt[1]:"no-highlight"}return lt.split(/\s+/).find(Ot=>me(Ot)||ze(Ot))}function Ct(Le,lt,Tt){let Ot="",yn="";typeof lt=="object"?(Ot=Le,Tt=lt.ignoreIllegals,yn=lt.language):(ne("10.7.0","highlight(lang, code, ...args) has been deprecated."),ne("10.7.0",`Please use highlight(code, options) instead.
200
200
  https://github.com/highlightjs/highlight.js/issues/2277`),yn=Le,Ot=lt),Tt===void 0&&(Tt=!0);const an={code:Ot,language:yn};Kt("before:highlight",an);const as=an.result?an.result:en(an.language,an.code,Tt);return as.code=an.code,Kt("after:highlight",as),as}function en(Le,lt,Tt,Ot){const yn=Object.create(null);function an($e,Xe){return $e.keywords[Xe]}function as(){if(!Et.keywords){bn.addText(Gt);return}let $e=0;Et.keywordPatternRe.lastIndex=0;let Xe=Et.keywordPatternRe.exec(Gt),kt="";for(;Xe;){kt+=Gt.substring($e,Xe.index);const Lt=Tr.case_insensitive?Xe[0].toLowerCase():Xe[0],dn=an(Et,Lt);if(dn){const[Tn,df]=dn;if(bn.addText(kt),kt="",yn[Lt]=(yn[Lt]||0)+1,yn[Lt]<=F&&(Oi+=df),Tn.startsWith("_"))kt+=Xe[0];else{const Hl=Tr.classNameAliases[Tn]||Tn;rr(Xe[0],Hl)}}else kt+=Xe[0];$e=Et.keywordPatternRe.lastIndex,Xe=Et.keywordPatternRe.exec(Gt)}kt+=Gt.substring($e),bn.addText(kt)}function yo(){if(Gt==="")return;let $e=null;if(typeof Et.subLanguage=="string"){if(!Z[Et.subLanguage]){bn.addText(Gt);return}$e=en(Et.subLanguage,Gt,!0,ma[Et.subLanguage]),ma[Et.subLanguage]=$e._top}else $e=Wt(Gt,Et.subLanguage.length?Et.subLanguage:null);Et.relevance>0&&(Oi+=$e.relevance),bn.__addSublanguage($e._emitter,$e.language)}function nr(){Et.subLanguage!=null?yo():as(),Gt=""}function rr($e,Xe){$e!==""&&(bn.startScope(Xe),bn.addText($e),bn.endScope())}function Ai($e,Xe){let kt=1;const Lt=Xe.length-1;for(;kt<=Lt;){if(!$e._emit[kt]){kt++;continue}const dn=Tr.classNameAliases[$e[kt]]||$e[kt],Tn=Xe[kt];dn?rr(Tn,dn):(Gt=Tn,as(),Gt=""),kt++}}function Fs($e,Xe){return $e.scope&&typeof $e.scope=="string"&&bn.openNode(Tr.classNameAliases[$e.scope]||$e.scope),$e.beginScope&&($e.beginScope._wrap?(rr(Gt,Tr.classNameAliases[$e.beginScope._wrap]||$e.beginScope._wrap),Gt=""):$e.beginScope._multi&&(Ai($e.beginScope,Xe),Gt="")),Et=Object.create($e,{parent:{value:Et}}),Et}function Ri($e,Xe,kt){let Lt=T($e.endRe,kt);if(Lt){if($e["on:end"]){const dn=new e($e);$e["on:end"](Xe,dn),dn.isMatchIgnored&&(Lt=!1)}if(Lt){for(;$e.endsParent&&$e.parent;)$e=$e.parent;return $e}}if($e.endsWithParent)return Ri($e.parent,Xe,kt)}function cf($e){return Et.matcher.regexIndex===0?(Gt+=$e[0],1):(Ws=!0,0)}function uf($e){const Xe=$e[0],kt=$e.rule,Lt=new e(kt),dn=[kt.__beforeBegin,kt["on:begin"]];for(const Tn of dn)if(Tn&&(Tn($e,Lt),Lt.isMatchIgnored))return cf(Xe);return kt.skip?Gt+=Xe:(kt.excludeBegin&&(Gt+=Xe),nr(),!kt.returnBegin&&!kt.excludeBegin&&(Gt=Xe)),Fs(kt,$e),kt.returnBegin?0:Xe.length}function ha($e){const Xe=$e[0],kt=lt.substring($e.index),Lt=Ri(Et,$e,kt);if(!Lt)return qe;const dn=Et;Et.endScope&&Et.endScope._wrap?(nr(),rr(Xe,Et.endScope._wrap)):Et.endScope&&Et.endScope._multi?(nr(),Ai(Et.endScope,$e)):dn.skip?Gt+=Xe:(dn.returnEnd||dn.excludeEnd||(Gt+=Xe),nr(),dn.excludeEnd&&(Gt=Xe));do Et.scope&&bn.closeNode(),!Et.skip&&!Et.subLanguage&&(Oi+=Et.relevance),Et=Et.parent;while(Et!==Lt.parent);return Lt.starts&&Fs(Lt.starts,$e),dn.returnEnd?0:Xe.length}function Ul(){const $e=[];for(let Xe=Et;Xe!==Tr;Xe=Xe.parent)Xe.scope&&$e.unshift(Xe.scope);$e.forEach(Xe=>bn.openNode(Xe))}let Us={};function Hs($e,Xe){const kt=Xe&&Xe[0];if(Gt+=$e,kt==null)return nr(),0;if(Us.type==="begin"&&Xe.type==="end"&&Us.index===Xe.index&&kt===""){if(Gt+=lt.slice(Xe.index,Xe.index+1),!ye){const Lt=new Error(`0 width match regex (${Le})`);throw Lt.languageName=Le,Lt.badRule=Us.rule,Lt}return 1}if(Us=Xe,Xe.type==="begin")return uf(Xe);if(Xe.type==="illegal"&&!Tt){const Lt=new Error('Illegal lexeme "'+kt+'" for mode "'+(Et.scope||"<unnamed>")+'"');throw Lt.mode=Et,Lt}else if(Xe.type==="end"){const Lt=ha(Xe);if(Lt!==qe)return Lt}if(Xe.type==="illegal"&&kt==="")return Gt+=`
201
201
  `,1;if(Ii>1e5&&Ii>Xe.index*3)throw new Error("potential infinite loop, way more iterations than matches");return Gt+=kt,kt.length}const Tr=ze(Le);if(!Tr)throw X(Te.replace("{}",Le)),new Error('Unknown language: "'+Le+'"');const pa=bt(Tr);let Bt="",Et=Ot||pa;const ma={},bn=new Ee.__emitter(Ee);Ul();let Gt="",Oi=0,ls=0,Ii=0,Ws=!1;try{if(Tr.__emitTokens)Tr.__emitTokens(lt,bn);else{for(Et.matcher.considerAll();;){Ii++,Ws?Ws=!1:Et.matcher.considerAll(),Et.matcher.lastIndex=ls;const $e=Et.matcher.exec(lt);if(!$e)break;const Xe=lt.substring(ls,$e.index),kt=Hs(Xe,$e);ls=$e.index+kt}Hs(lt.substring(ls))}return bn.finalize(),Bt=bn.toHTML(),{language:Le,value:Bt,relevance:Oi,illegal:!1,_emitter:bn,_top:Et}}catch($e){if($e.message&&$e.message.includes("Illegal"))return{language:Le,value:Ie(lt),illegal:!0,relevance:0,_illegalBy:{message:$e.message,index:ls,context:lt.slice(ls-100,ls+100),mode:$e.mode,resultSoFar:Bt},_emitter:bn};if(ye)return{language:Le,value:Ie(lt),illegal:!1,relevance:0,errorRaised:$e,_emitter:bn,_top:Et};throw $e}}function on(Le){const lt={value:Ie(Le),illegal:!1,relevance:0,_top:Se,_emitter:new Ee.__emitter(Ee)};return lt._emitter.addText(Le),lt}function Wt(Le,lt){lt=lt||Ee.languages||Object.keys(Z);const Tt=on(Le),Ot=lt.filter(ze).filter(Rt).map(nr=>en(nr,Le,!1));Ot.unshift(Tt);const yn=Ot.sort((nr,rr)=>{if(nr.relevance!==rr.relevance)return rr.relevance-nr.relevance;if(nr.language&&rr.language){if(ze(nr.language).supersetOf===rr.language)return 1;if(ze(rr.language).supersetOf===nr.language)return-1}return 0}),[an,as]=yn,yo=an;return yo.secondBest=as,yo}function Ft(Le,lt,Tt){const Ot=lt&&I[lt]||Tt;Le.classList.add("hljs"),Le.classList.add(`language-${Ot}`)}function xt(Le){let lt=null;const Tt=ke(Le);if(me(Tt))return;if(Kt("before:highlightElement",{el:Le,language:Tt}),Le.dataset.highlighted){console.log("Element previously highlighted. To highlight again, first unset `dataset.highlighted`.",Le);return}if(Le.children.length>0&&(Ee.ignoreUnescapedHTML||(console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk."),console.warn("https://github.com/highlightjs/highlight.js/wiki/security"),console.warn("The element with unescaped HTML:"),console.warn(Le)),Ee.throwUnescapedHTML))throw new Nt("One of your code blocks includes unescaped HTML.",Le.innerHTML);lt=Le;const Ot=lt.textContent,yn=Tt?Ct(Ot,{language:Tt,ignoreIllegals:!0}):Wt(Ot);Le.innerHTML=yn.value,Le.dataset.highlighted="yes",Ft(Le,Tt,yn.language),Le.result={language:yn.language,re:yn.relevance,relevance:yn.relevance},yn.secondBest&&(Le.secondBest={language:yn.secondBest.language,relevance:yn.secondBest.relevance}),Kt("after:highlightElement",{el:Le,result:yn,text:Ot})}function Pn(Le){Ee=Me(Ee,Le)}const un=()=>{Wr(),ne("10.6.0","initHighlighting() deprecated. Use highlightAll() now.")};function yr(){Wr(),ne("10.6.0","initHighlightingOnLoad() deprecated. Use highlightAll() now.")}let _r=!1;function Wr(){function Le(){Wr()}if(document.readyState==="loading"){_r||window.addEventListener("DOMContentLoaded",Le,!1),_r=!0;return}document.querySelectorAll(Ee.cssSelector).forEach(xt)}function is(Le,lt){let Tt=null;try{Tt=lt(P)}catch(Ot){if(X("Language definition for '{}' could not be registered.".replace("{}",Le)),ye)X(Ot);else throw Ot;Tt=Se}Tt.name||(Tt.name=Le),Z[Le]=Tt,Tt.rawDefinition=lt.bind(null,P),Tt.aliases&&_t(Tt.aliases,{languageName:Le})}function ie(Le){delete Z[Le];for(const lt of Object.keys(I))I[lt]===Le&&delete I[lt]}function je(){return Object.keys(Z)}function ze(Le){return Le=(Le||"").toLowerCase(),Z[Le]||Z[I[Le]]}function _t(Le,{languageName:lt}){typeof Le=="string"&&(Le=[Le]),Le.forEach(Tt=>{I[Tt.toLowerCase()]=lt})}function Rt(Le){const lt=ze(Le);return lt&&!lt.disableAutodetect}function It(Le){Le["before:highlightBlock"]&&!Le["before:highlightElement"]&&(Le["before:highlightElement"]=lt=>{Le["before:highlightBlock"](Object.assign({block:lt.el},lt))}),Le["after:highlightBlock"]&&!Le["after:highlightElement"]&&(Le["after:highlightElement"]=lt=>{Le["after:highlightBlock"](Object.assign({block:lt.el},lt))})}function tr(Le){It(Le),re.push(Le)}function qr(Le){const lt=re.indexOf(Le);lt!==-1&&re.splice(lt,1)}function Kt(Le,lt){const Tt=Le;re.forEach(function(Ot){Ot[Tt]&&Ot[Tt](lt)})}function Vn(Le){return ne("10.7.0","highlightBlock will be removed entirely in v12.0"),ne("10.7.0","Please use highlightElement now."),xt(Le)}Object.assign(P,{highlight:Ct,highlightAuto:Wt,highlightAll:Wr,highlightElement:xt,highlightBlock:Vn,configure:Pn,initHighlighting:un,initHighlightingOnLoad:yr,registerLanguage:is,unregisterLanguage:ie,listLanguages:je,getLanguage:ze,registerAliases:_t,autoDetection:Rt,inherit:Me,addPlugin:tr,removePlugin:qr}),P.debugMode=function(){ye=!1},P.safeMode=function(){ye=!0},P.versionString=gt,P.regex={concat:k,lookahead:g,either:E,optional:b,anyNumberOfTimes:v};for(const Le in He)typeof He[Le]=="object"&&t(He[Le]);return Object.assign(P,He),P},Ne=ce({});return Ne.newInstance=()=>ce({}),Ep=Ne,Ne.HighlightJS=Ne,Ne.default=Ne,Ep}var g6=m6();const D_=jl(g6);function P_(t,e=[]){return t.flatMap(n=>{const r=[...e,...n.properties?n.properties.className:[]];return n.children?P_(n.children,r):{text:n.value,classes:r}})}function Gw(t){return t.value||t.children||[]}function v6(t){return!!D_.getLanguage(t)}function Jw({doc:t,name:e,lowlight:n,defaultLanguage:r}){const s=[];return Vu(t,i=>i.type.name===e).forEach(i=>{var o;let l=i.pos+1;const d=i.node.attrs.language||r,f=n.listLanguages(),h=d&&(f.includes(d)||v6(d)||(o=n.registered)!=null&&o.call(n,d))?Gw(n.highlight(d,i.node.textContent)):Gw(n.highlightAuto(i.node.textContent));P_(h).forEach(m=>{const g=l+m.text.length;if(m.classes.length){const v=Vt.inline(l,g,{class:m.classes.join(" ")});s.push(v)}l=g})}),Dt.create(t,s)}function y6(t){return typeof t=="function"}function b6({name:t,lowlight:e,defaultLanguage:n}){if(!["highlight","highlightAuto","listLanguages"].every(s=>y6(e[s])))throw Error("You should provide an instance of lowlight to use the code-block-lowlight extension");const r=new Ht({key:new Jt("lowlight"),state:{init:(s,{doc:i})=>Jw({doc:i,name:t,lowlight:e,defaultLanguage:n}),apply:(s,i,o,l)=>{const d=o.selection.$head.parent.type.name,f=l.selection.$head.parent.type.name,h=Vu(o.doc,g=>g.type.name===t),m=Vu(l.doc,g=>g.type.name===t);return s.docChanged&&([d,f].includes(t)||m.length!==h.length||s.steps.some(g=>g.from!==void 0&&g.to!==void 0&&h.some(v=>v.pos>=g.from&&v.pos+v.node.nodeSize<=g.to)))?Jw({doc:s.doc,name:t,lowlight:e,defaultLanguage:n}):i.map(s.mapping,s.doc)}},props:{decorations(s){return r.getState(s)}}});return r}var x6=Q3.extend({addOptions(){var t;return{...(t=this.parent)==null?void 0:t.call(this),lowlight:{},languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:4,HTMLAttributes:{}}},addProseMirrorPlugins(){var t;return[...((t=this.parent)==null?void 0:t.call(this))||[],b6({name:this.name,lowlight:this.options.lowlight,defaultLanguage:this.options.defaultLanguage})]}}),w6=x6;function k6(t){const e=t.regex,n=t.COMMENT("//","$",{contains:[{begin:/\\\n/}]}),r="decltype\\(auto\\)",s="[a-zA-Z_]\\w*::",o="(?!struct)("+r+"|"+e.optional(s)+"[a-zA-Z_]\\w*"+e.optional("<[^<>]+>")+")",l={className:"type",begin:"\\b[a-z\\d_]*_t\\b"},f={className:"string",variants:[{begin:'(u8?|U|L)?"',end:'"',illegal:"\\n",contains:[t.BACKSLASH_ESCAPE]},{begin:"(u8?|U|L)?'("+"\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)"+"|.)",end:"'",illegal:"."},t.END_SAME_AS_BEGIN({begin:/(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,end:/\)([^()\\ ]{0,16})"/})]},h={className:"number",variants:[{begin:"[+-]?(?:(?:[0-9](?:'?[0-9])*\\.(?:[0-9](?:'?[0-9])*)?|\\.[0-9](?:'?[0-9])*)(?:[Ee][+-]?[0-9](?:'?[0-9])*)?|[0-9](?:'?[0-9])*[Ee][+-]?[0-9](?:'?[0-9])*|0[Xx](?:[0-9A-Fa-f](?:'?[0-9A-Fa-f])*(?:\\.(?:[0-9A-Fa-f](?:'?[0-9A-Fa-f])*)?)?|\\.[0-9A-Fa-f](?:'?[0-9A-Fa-f])*)[Pp][+-]?[0-9](?:'?[0-9])*)(?:[Ff](?:16|32|64|128)?|(BF|bf)16|[Ll]|)"},{begin:"[+-]?\\b(?:0[Bb][01](?:'?[01])*|0[Xx][0-9A-Fa-f](?:'?[0-9A-Fa-f])*|0(?:'?[0-7])*|[1-9](?:'?[0-9])*)(?:[Uu](?:LL?|ll?)|[Uu][Zz]?|(?:LL?|ll?)[Uu]?|[Zz][Uu]|)"}],relevance:0},m={className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{keyword:"if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include"},contains:[{begin:/\\\n/,relevance:0},t.inherit(f,{className:"string"}),{className:"string",begin:/<.*?>/},n,t.C_BLOCK_COMMENT_MODE]},g={className:"title",begin:e.optional(s)+t.IDENT_RE,relevance:0},v=e.optional(s)+t.IDENT_RE+"\\s*\\(",b=["alignas","alignof","and","and_eq","asm","atomic_cancel","atomic_commit","atomic_noexcept","auto","bitand","bitor","break","case","catch","class","co_await","co_return","co_yield","compl","concept","const_cast|10","consteval","constexpr","constinit","continue","decltype","default","delete","do","dynamic_cast|10","else","enum","explicit","export","extern","false","final","for","friend","goto","if","import","inline","module","mutable","namespace","new","noexcept","not","not_eq","nullptr","operator","or","or_eq","override","private","protected","public","reflexpr","register","reinterpret_cast|10","requires","return","sizeof","static_assert","static_cast|10","struct","switch","synchronized","template","this","thread_local","throw","transaction_safe","transaction_safe_dynamic","true","try","typedef","typeid","typename","union","using","virtual","volatile","while","xor","xor_eq"],k=["bool","char","char16_t","char32_t","char8_t","double","float","int","long","short","void","wchar_t","unsigned","signed","const","static"],w=["any","auto_ptr","barrier","binary_semaphore","bitset","complex","condition_variable","condition_variable_any","counting_semaphore","deque","false_type","flat_map","flat_set","future","imaginary","initializer_list","istringstream","jthread","latch","lock_guard","multimap","multiset","mutex","optional","ostringstream","packaged_task","pair","promise","priority_queue","queue","recursive_mutex","recursive_timed_mutex","scoped_lock","set","shared_future","shared_lock","shared_mutex","shared_timed_mutex","shared_ptr","stack","string_view","stringstream","timed_mutex","thread","true_type","tuple","unique_lock","unique_ptr","unordered_map","unordered_multimap","unordered_multiset","unordered_set","variant","vector","weak_ptr","wstring","wstring_view"],E=["abort","abs","acos","apply","as_const","asin","atan","atan2","calloc","ceil","cerr","cin","clog","cos","cosh","cout","declval","endl","exchange","exit","exp","fabs","floor","fmod","forward","fprintf","fputs","free","frexp","fscanf","future","invoke","isalnum","isalpha","iscntrl","isdigit","isgraph","islower","isprint","ispunct","isspace","isupper","isxdigit","labs","launder","ldexp","log","log10","make_pair","make_shared","make_shared_for_overwrite","make_tuple","make_unique","malloc","memchr","memcmp","memcpy","memset","modf","move","pow","printf","putchar","puts","realloc","scanf","sin","sinh","snprintf","sprintf","sqrt","sscanf","std","stderr","stdin","stdout","strcat","strchr","strcmp","strcpy","strcspn","strlen","strncat","strncmp","strncpy","strpbrk","strrchr","strspn","strstr","swap","tan","tanh","terminate","to_underlying","tolower","toupper","vfprintf","visit","vprintf","vsprintf"],j={type:k,keyword:b,literal:["NULL","false","nullopt","nullptr","true"],built_in:["_Pragma"],_type_hints:w},_={className:"function.dispatch",relevance:0,keywords:{_hint:E},begin:e.concat(/\b/,/(?!decltype)/,/(?!if)/,/(?!for)/,/(?!switch)/,/(?!while)/,t.IDENT_RE,e.lookahead(/(<[^<>]+>|)\s*\(/))},A=[_,m,l,n,t.C_BLOCK_COMMENT_MODE,h,f],O={variants:[{begin:/=/,end:/;/},{begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],keywords:j,contains:A.concat([{begin:/\(/,end:/\)/,keywords:j,contains:A.concat(["self"]),relevance:0}]),relevance:0},B={className:"function",begin:"("+o+"[\\*&\\s]+)+"+v,returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:j,illegal:/[^\w\s\*&:<>.]/,contains:[{begin:r,keywords:j,relevance:0},{begin:v,returnBegin:!0,contains:[g],relevance:0},{begin:/::/,relevance:0},{begin:/:/,endsWithParent:!0,contains:[f,h]},{relevance:0,match:/,/},{className:"params",begin:/\(/,end:/\)/,keywords:j,relevance:0,contains:[n,t.C_BLOCK_COMMENT_MODE,f,h,l,{begin:/\(/,end:/\)/,keywords:j,relevance:0,contains:["self",n,t.C_BLOCK_COMMENT_MODE,f,h,l]}]},l,n,t.C_BLOCK_COMMENT_MODE,m]};return{name:"C++",aliases:["cc","c++","h++","hpp","hh","hxx","cxx"],keywords:j,illegal:"</",classNameAliases:{"function.dispatch":"built_in"},contains:[].concat(O,B,_,A,[m,{begin:"\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array|tuple|optional|variant|function|flat_map|flat_set)\\s*<(?!<)",end:">",keywords:j,contains:["self",l]},{begin:t.IDENT_RE+"::",keywords:j},{match:[/\b(?:enum(?:\s+(?:class|struct))?|class|struct|union)/,/\s+/,/\w+/],className:{1:"keyword",3:"title.class"}}])}}function S6(t){const e={type:["boolean","byte","word","String"],built_in:["KeyboardController","MouseController","SoftwareSerial","EthernetServer","EthernetClient","LiquidCrystal","RobotControl","GSMVoiceCall","EthernetUDP","EsploraTFT","HttpClient","RobotMotor","WiFiClient","GSMScanner","FileSystem","Scheduler","GSMServer","YunClient","YunServer","IPAddress","GSMClient","GSMModem","Keyboard","Ethernet","Console","GSMBand","Esplora","Stepper","Process","WiFiUDP","GSM_SMS","Mailbox","USBHost","Firmata","PImage","Client","Server","GSMPIN","FileIO","Bridge","Serial","EEPROM","Stream","Mouse","Audio","Servo","File","Task","GPRS","WiFi","Wire","TFT","GSM","SPI","SD"],_hints:["setup","loop","runShellCommandAsynchronously","analogWriteResolution","retrieveCallingNumber","printFirmwareVersion","analogReadResolution","sendDigitalPortPair","noListenOnLocalhost","readJoystickButton","setFirmwareVersion","readJoystickSwitch","scrollDisplayRight","getVoiceCallStatus","scrollDisplayLeft","writeMicroseconds","delayMicroseconds","beginTransmission","getSignalStrength","runAsynchronously","getAsynchronously","listenOnLocalhost","getCurrentCarrier","readAccelerometer","messageAvailable","sendDigitalPorts","lineFollowConfig","countryNameWrite","runShellCommand","readStringUntil","rewindDirectory","readTemperature","setClockDivider","readLightSensor","endTransmission","analogReference","detachInterrupt","countryNameRead","attachInterrupt","encryptionType","readBytesUntil","robotNameWrite","readMicrophone","robotNameRead","cityNameWrite","userNameWrite","readJoystickY","readJoystickX","mouseReleased","openNextFile","scanNetworks","noInterrupts","digitalWrite","beginSpeaker","mousePressed","isActionDone","mouseDragged","displayLogos","noAutoscroll","addParameter","remoteNumber","getModifiers","keyboardRead","userNameRead","waitContinue","processInput","parseCommand","printVersion","readNetworks","writeMessage","blinkVersion","cityNameRead","readMessage","setDataMode","parsePacket","isListening","setBitOrder","beginPacket","isDirectory","motorsWrite","drawCompass","digitalRead","clearScreen","serialEvent","rightToLeft","setTextSize","leftToRight","requestFrom","keyReleased","compassRead","analogWrite","interrupts","WiFiServer","disconnect","playMelody","parseFloat","autoscroll","getPINUsed","setPINUsed","setTimeout","sendAnalog","readSlider","analogRead","beginWrite","createChar","motorsStop","keyPressed","tempoWrite","readButton","subnetMask","debugPrint","macAddress","writeGreen","randomSeed","attachGPRS","readString","sendString","remotePort","releaseAll","mouseMoved","background","getXChange","getYChange","answerCall","getResult","voiceCall","endPacket","constrain","getSocket","writeJSON","getButton","available","connected","findUntil","readBytes","exitValue","readGreen","writeBlue","startLoop","IPAddress","isPressed","sendSysex","pauseMode","gatewayIP","setCursor","getOemKey","tuneWrite","noDisplay","loadImage","switchPIN","onRequest","onReceive","changePIN","playFile","noBuffer","parseInt","overflow","checkPIN","knobRead","beginTFT","bitClear","updateIR","bitWrite","position","writeRGB","highByte","writeRed","setSpeed","readBlue","noStroke","remoteIP","transfer","shutdown","hangCall","beginSMS","endWrite","attached","maintain","noCursor","checkReg","checkPUK","shiftOut","isValid","shiftIn","pulseIn","connect","println","localIP","pinMode","getIMEI","display","noBlink","process","getBand","running","beginSD","drawBMP","lowByte","setBand","release","bitRead","prepare","pointTo","readRed","setMode","noFill","remove","listen","stroke","detach","attach","noTone","exists","buffer","height","bitSet","circle","config","cursor","random","IRread","setDNS","endSMS","getKey","micros","millis","begin","print","write","ready","flush","width","isPIN","blink","clear","press","mkdir","rmdir","close","point","yield","image","BSSID","click","delay","read","text","move","peek","beep","rect","line","open","seek","fill","size","turn","stop","home","find","step","tone","sqrt","RSSI","SSID","end","bit","tan","cos","sin","pow","map","abs","max","min","get","run","put"],literal:["DIGITAL_MESSAGE","FIRMATA_STRING","ANALOG_MESSAGE","REPORT_DIGITAL","REPORT_ANALOG","INPUT_PULLUP","SET_PIN_MODE","INTERNAL2V56","SYSTEM_RESET","LED_BUILTIN","INTERNAL1V1","SYSEX_START","INTERNAL","EXTERNAL","DEFAULT","OUTPUT","INPUT","HIGH","LOW"]},n=k6(t),r=n.keywords;return r.type=[...r.type,...e.type],r.literal=[...r.literal,...e.literal],r.built_in=[...r.built_in,...e.built_in],r._hints=e._hints,n.name="Arduino",n.aliases=["ino"],n.supersetOf="cpp",n}function E6(t){const e=t.regex,n={},r={begin:/\$\{/,end:/\}/,contains:["self",{begin:/:-/,contains:[n]}]};Object.assign(n,{className:"variable",variants:[{begin:e.concat(/\$[\w\d#@][\w\d_]*/,"(?![\\w\\d])(?![$])")},r]});const s={className:"subst",begin:/\$\(/,end:/\)/,contains:[t.BACKSLASH_ESCAPE]},i=t.inherit(t.COMMENT(),{match:[/(^|\s)/,/#.*$/],scope:{2:"comment"}}),o={begin:/<<-?\s*(?=\w+)/,starts:{contains:[t.END_SAME_AS_BEGIN({begin:/(\w+)/,end:/(\w+)/,className:"string"})]}},l={className:"string",begin:/"/,end:/"/,contains:[t.BACKSLASH_ESCAPE,n,s]};s.contains.push(l);const d={match:/\\"/},f={className:"string",begin:/'/,end:/'/},h={match:/\\'/},m={begin:/\$?\(\(/,end:/\)\)/,contains:[{begin:/\d+#[0-9a-f]+/,className:"number"},t.NUMBER_MODE,n]},g=["fish","bash","zsh","sh","csh","ksh","tcsh","dash","scsh"],v=t.SHEBANG({binary:`(${g.join("|")})`,relevance:10}),b={className:"function",begin:/\w[\w\d_]*\s*\(\s*\)\s*\{/,returnBegin:!0,contains:[t.inherit(t.TITLE_MODE,{begin:/\w[\w\d_]*/})],relevance:0},k=["if","then","else","elif","fi","time","for","while","until","in","do","done","case","esac","coproc","function","select"],w=["true","false"],E={match:/(\/[a-z._-]+)+/},C=["break","cd","continue","eval","exec","exit","export","getopts","hash","pwd","readonly","return","shift","test","times","trap","umask","unset"],T=["alias","bind","builtin","caller","command","declare","echo","enable","help","let","local","logout","mapfile","printf","read","readarray","source","sudo","type","typeset","ulimit","unalias"],j=["autoload","bg","bindkey","bye","cap","chdir","clone","comparguments","compcall","compctl","compdescribe","compfiles","compgroups","compquote","comptags","comptry","compvalues","dirs","disable","disown","echotc","echoti","emulate","fc","fg","float","functions","getcap","getln","history","integer","jobs","kill","limit","log","noglob","popd","print","pushd","pushln","rehash","sched","setcap","setopt","stat","suspend","ttyctl","unfunction","unhash","unlimit","unsetopt","vared","wait","whence","where","which","zcompile","zformat","zftp","zle","zmodload","zparseopts","zprof","zpty","zregexparse","zsocket","zstyle","ztcp"],_=["chcon","chgrp","chown","chmod","cp","dd","df","dir","dircolors","ln","ls","mkdir","mkfifo","mknod","mktemp","mv","realpath","rm","rmdir","shred","sync","touch","truncate","vdir","b2sum","base32","base64","cat","cksum","comm","csplit","cut","expand","fmt","fold","head","join","md5sum","nl","numfmt","od","paste","ptx","pr","sha1sum","sha224sum","sha256sum","sha384sum","sha512sum","shuf","sort","split","sum","tac","tail","tr","tsort","unexpand","uniq","wc","arch","basename","chroot","date","dirname","du","echo","env","expr","factor","groups","hostid","id","link","logname","nice","nohup","nproc","pathchk","pinky","printenv","printf","pwd","readlink","runcon","seq","sleep","stat","stdbuf","stty","tee","test","timeout","tty","uname","unlink","uptime","users","who","whoami","yes"];return{name:"Bash",aliases:["sh","zsh"],keywords:{$pattern:/\b[a-z][a-z0-9._-]+\b/,keyword:k,literal:w,built_in:[...C,...T,"set","shopt",...j,..._]},contains:[v,t.SHEBANG(),b,m,i,o,E,l,d,f,h,n]}}function N6(t){const e=t.regex,n=t.COMMENT("//","$",{contains:[{begin:/\\\n/}]}),r="decltype\\(auto\\)",s="[a-zA-Z_]\\w*::",o="("+r+"|"+e.optional(s)+"[a-zA-Z_]\\w*"+e.optional("<[^<>]+>")+")",l={className:"type",variants:[{begin:"\\b[a-z\\d_]*_t\\b"},{match:/\batomic_[a-z]{3,6}\b/}]},f={className:"string",variants:[{begin:'(u8?|U|L)?"',end:'"',illegal:"\\n",contains:[t.BACKSLASH_ESCAPE]},{begin:"(u8?|U|L)?'("+"\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)"+"|.)",end:"'",illegal:"."},t.END_SAME_AS_BEGIN({begin:/(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,end:/\)([^()\\ ]{0,16})"/})]},h={className:"number",variants:[{match:/\b(0b[01']+)/},{match:/(-?)\b([\d']+(\.[\d']*)?|\.[\d']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)/},{match:/(-?)\b(0[xX][a-fA-F0-9]+(?:'[a-fA-F0-9]+)*(?:\.[a-fA-F0-9]*(?:'[a-fA-F0-9]*)*)?(?:[pP][-+]?[0-9]+)?(l|L)?(u|U)?)/},{match:/(-?)\b\d+(?:'\d+)*(?:\.\d*(?:'\d*)*)?(?:[eE][-+]?\d+)?/}],relevance:0},m={className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{keyword:"if else elif endif define undef warning error line pragma _Pragma ifdef ifndef elifdef elifndef include"},contains:[{begin:/\\\n/,relevance:0},t.inherit(f,{className:"string"}),{className:"string",begin:/<.*?>/},n,t.C_BLOCK_COMMENT_MODE]},g={className:"title",begin:e.optional(s)+t.IDENT_RE,relevance:0},v=e.optional(s)+t.IDENT_RE+"\\s*\\(",w={keyword:["asm","auto","break","case","continue","default","do","else","enum","extern","for","fortran","goto","if","inline","register","restrict","return","sizeof","typeof","typeof_unqual","struct","switch","typedef","union","volatile","while","_Alignas","_Alignof","_Atomic","_Generic","_Noreturn","_Static_assert","_Thread_local","alignas","alignof","noreturn","static_assert","thread_local","_Pragma"],type:["float","double","signed","unsigned","int","short","long","char","void","_Bool","_BitInt","_Complex","_Imaginary","_Decimal32","_Decimal64","_Decimal96","_Decimal128","_Decimal64x","_Decimal128x","_Float16","_Float32","_Float64","_Float128","_Float32x","_Float64x","_Float128x","const","static","constexpr","complex","bool","imaginary"],literal:"true false NULL",built_in:"std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr"},E=[m,l,n,t.C_BLOCK_COMMENT_MODE,h,f],C={variants:[{begin:/=/,end:/;/},{begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],keywords:w,contains:E.concat([{begin:/\(/,end:/\)/,keywords:w,contains:E.concat(["self"]),relevance:0}]),relevance:0},T={begin:"("+o+"[\\*&\\s]+)+"+v,returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:w,illegal:/[^\w\s\*&:<>.]/,contains:[{begin:r,keywords:w,relevance:0},{begin:v,returnBegin:!0,contains:[t.inherit(g,{className:"title.function"})],relevance:0},{relevance:0,match:/,/},{className:"params",begin:/\(/,end:/\)/,keywords:w,relevance:0,contains:[n,t.C_BLOCK_COMMENT_MODE,f,h,l,{begin:/\(/,end:/\)/,keywords:w,relevance:0,contains:["self",n,t.C_BLOCK_COMMENT_MODE,f,h,l]}]},l,n,t.C_BLOCK_COMMENT_MODE,m]};return{name:"C",aliases:["h"],keywords:w,disableAutodetect:!0,illegal:"</",contains:[].concat(C,T,E,[m,{begin:t.IDENT_RE+"::",keywords:w},{className:"class",beginKeywords:"enum class struct union",end:/[{;:<>=]/,contains:[{beginKeywords:"final class struct"},t.TITLE_MODE]}]),exports:{preprocessor:m,strings:f,keywords:w}}}function C6(t){const e=t.regex,n=t.COMMENT("//","$",{contains:[{begin:/\\\n/}]}),r="decltype\\(auto\\)",s="[a-zA-Z_]\\w*::",o="(?!struct)("+r+"|"+e.optional(s)+"[a-zA-Z_]\\w*"+e.optional("<[^<>]+>")+")",l={className:"type",begin:"\\b[a-z\\d_]*_t\\b"},f={className:"string",variants:[{begin:'(u8?|U|L)?"',end:'"',illegal:"\\n",contains:[t.BACKSLASH_ESCAPE]},{begin:"(u8?|U|L)?'("+"\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)"+"|.)",end:"'",illegal:"."},t.END_SAME_AS_BEGIN({begin:/(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,end:/\)([^()\\ ]{0,16})"/})]},h={className:"number",variants:[{begin:"[+-]?(?:(?:[0-9](?:'?[0-9])*\\.(?:[0-9](?:'?[0-9])*)?|\\.[0-9](?:'?[0-9])*)(?:[Ee][+-]?[0-9](?:'?[0-9])*)?|[0-9](?:'?[0-9])*[Ee][+-]?[0-9](?:'?[0-9])*|0[Xx](?:[0-9A-Fa-f](?:'?[0-9A-Fa-f])*(?:\\.(?:[0-9A-Fa-f](?:'?[0-9A-Fa-f])*)?)?|\\.[0-9A-Fa-f](?:'?[0-9A-Fa-f])*)[Pp][+-]?[0-9](?:'?[0-9])*)(?:[Ff](?:16|32|64|128)?|(BF|bf)16|[Ll]|)"},{begin:"[+-]?\\b(?:0[Bb][01](?:'?[01])*|0[Xx][0-9A-Fa-f](?:'?[0-9A-Fa-f])*|0(?:'?[0-7])*|[1-9](?:'?[0-9])*)(?:[Uu](?:LL?|ll?)|[Uu][Zz]?|(?:LL?|ll?)[Uu]?|[Zz][Uu]|)"}],relevance:0},m={className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{keyword:"if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include"},contains:[{begin:/\\\n/,relevance:0},t.inherit(f,{className:"string"}),{className:"string",begin:/<.*?>/},n,t.C_BLOCK_COMMENT_MODE]},g={className:"title",begin:e.optional(s)+t.IDENT_RE,relevance:0},v=e.optional(s)+t.IDENT_RE+"\\s*\\(",b=["alignas","alignof","and","and_eq","asm","atomic_cancel","atomic_commit","atomic_noexcept","auto","bitand","bitor","break","case","catch","class","co_await","co_return","co_yield","compl","concept","const_cast|10","consteval","constexpr","constinit","continue","decltype","default","delete","do","dynamic_cast|10","else","enum","explicit","export","extern","false","final","for","friend","goto","if","import","inline","module","mutable","namespace","new","noexcept","not","not_eq","nullptr","operator","or","or_eq","override","private","protected","public","reflexpr","register","reinterpret_cast|10","requires","return","sizeof","static_assert","static_cast|10","struct","switch","synchronized","template","this","thread_local","throw","transaction_safe","transaction_safe_dynamic","true","try","typedef","typeid","typename","union","using","virtual","volatile","while","xor","xor_eq"],k=["bool","char","char16_t","char32_t","char8_t","double","float","int","long","short","void","wchar_t","unsigned","signed","const","static"],w=["any","auto_ptr","barrier","binary_semaphore","bitset","complex","condition_variable","condition_variable_any","counting_semaphore","deque","false_type","flat_map","flat_set","future","imaginary","initializer_list","istringstream","jthread","latch","lock_guard","multimap","multiset","mutex","optional","ostringstream","packaged_task","pair","promise","priority_queue","queue","recursive_mutex","recursive_timed_mutex","scoped_lock","set","shared_future","shared_lock","shared_mutex","shared_timed_mutex","shared_ptr","stack","string_view","stringstream","timed_mutex","thread","true_type","tuple","unique_lock","unique_ptr","unordered_map","unordered_multimap","unordered_multiset","unordered_set","variant","vector","weak_ptr","wstring","wstring_view"],E=["abort","abs","acos","apply","as_const","asin","atan","atan2","calloc","ceil","cerr","cin","clog","cos","cosh","cout","declval","endl","exchange","exit","exp","fabs","floor","fmod","forward","fprintf","fputs","free","frexp","fscanf","future","invoke","isalnum","isalpha","iscntrl","isdigit","isgraph","islower","isprint","ispunct","isspace","isupper","isxdigit","labs","launder","ldexp","log","log10","make_pair","make_shared","make_shared_for_overwrite","make_tuple","make_unique","malloc","memchr","memcmp","memcpy","memset","modf","move","pow","printf","putchar","puts","realloc","scanf","sin","sinh","snprintf","sprintf","sqrt","sscanf","std","stderr","stdin","stdout","strcat","strchr","strcmp","strcpy","strcspn","strlen","strncat","strncmp","strncpy","strpbrk","strrchr","strspn","strstr","swap","tan","tanh","terminate","to_underlying","tolower","toupper","vfprintf","visit","vprintf","vsprintf"],j={type:k,keyword:b,literal:["NULL","false","nullopt","nullptr","true"],built_in:["_Pragma"],_type_hints:w},_={className:"function.dispatch",relevance:0,keywords:{_hint:E},begin:e.concat(/\b/,/(?!decltype)/,/(?!if)/,/(?!for)/,/(?!switch)/,/(?!while)/,t.IDENT_RE,e.lookahead(/(<[^<>]+>|)\s*\(/))},A=[_,m,l,n,t.C_BLOCK_COMMENT_MODE,h,f],O={variants:[{begin:/=/,end:/;/},{begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],keywords:j,contains:A.concat([{begin:/\(/,end:/\)/,keywords:j,contains:A.concat(["self"]),relevance:0}]),relevance:0},B={className:"function",begin:"("+o+"[\\*&\\s]+)+"+v,returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:j,illegal:/[^\w\s\*&:<>.]/,contains:[{begin:r,keywords:j,relevance:0},{begin:v,returnBegin:!0,contains:[g],relevance:0},{begin:/::/,relevance:0},{begin:/:/,endsWithParent:!0,contains:[f,h]},{relevance:0,match:/,/},{className:"params",begin:/\(/,end:/\)/,keywords:j,relevance:0,contains:[n,t.C_BLOCK_COMMENT_MODE,f,h,l,{begin:/\(/,end:/\)/,keywords:j,relevance:0,contains:["self",n,t.C_BLOCK_COMMENT_MODE,f,h,l]}]},l,n,t.C_BLOCK_COMMENT_MODE,m]};return{name:"C++",aliases:["cc","c++","h++","hpp","hh","hxx","cxx"],keywords:j,illegal:"</",classNameAliases:{"function.dispatch":"built_in"},contains:[].concat(O,B,_,A,[m,{begin:"\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array|tuple|optional|variant|function|flat_map|flat_set)\\s*<(?!<)",end:">",keywords:j,contains:["self",l]},{begin:t.IDENT_RE+"::",keywords:j},{match:[/\b(?:enum(?:\s+(?:class|struct))?|class|struct|union)/,/\s+/,/\w+/],className:{1:"keyword",3:"title.class"}}])}}function _6(t){const e=["bool","byte","char","decimal","delegate","double","dynamic","enum","float","int","long","nint","nuint","object","sbyte","short","string","ulong","uint","ushort"],n=["public","private","protected","static","internal","protected","abstract","async","extern","override","unsafe","virtual","new","sealed","partial"],r=["default","false","null","true"],s=["abstract","as","base","break","case","catch","class","const","continue","do","else","event","explicit","extern","finally","fixed","for","foreach","goto","if","implicit","in","interface","internal","is","lock","namespace","new","operator","out","override","params","private","protected","public","readonly","record","ref","return","scoped","sealed","sizeof","stackalloc","static","struct","switch","this","throw","try","typeof","unchecked","unsafe","using","virtual","void","volatile","while"],i=["add","alias","and","ascending","args","async","await","by","descending","dynamic","equals","file","from","get","global","group","init","into","join","let","nameof","not","notnull","on","or","orderby","partial","record","remove","required","scoped","select","set","unmanaged","value|0","var","when","where","with","yield"],o={keyword:s.concat(i),built_in:e,literal:r},l=t.inherit(t.TITLE_MODE,{begin:"[a-zA-Z](\\.?\\w)*"}),d={className:"number",variants:[{begin:"\\b(0b[01']+)"},{begin:"(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)(u|U|l|L|ul|UL|f|F|b|B)"},{begin:"(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)"}],relevance:0},f={className:"string",begin:/"""("*)(?!")(.|\n)*?"""\1/,relevance:1},h={className:"string",begin:'@"',end:'"',contains:[{begin:'""'}]},m=t.inherit(h,{illegal:/\n/}),g={className:"subst",begin:/\{/,end:/\}/,keywords:o},v=t.inherit(g,{illegal:/\n/}),b={className:"string",begin:/\$"/,end:'"',illegal:/\n/,contains:[{begin:/\{\{/},{begin:/\}\}/},t.BACKSLASH_ESCAPE,v]},k={className:"string",begin:/\$@"/,end:'"',contains:[{begin:/\{\{/},{begin:/\}\}/},{begin:'""'},g]},w=t.inherit(k,{illegal:/\n/,contains:[{begin:/\{\{/},{begin:/\}\}/},{begin:'""'},v]});g.contains=[k,b,h,t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,d,t.C_BLOCK_COMMENT_MODE],v.contains=[w,b,m,t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,d,t.inherit(t.C_BLOCK_COMMENT_MODE,{illegal:/\n/})];const E={variants:[f,k,b,h,t.APOS_STRING_MODE,t.QUOTE_STRING_MODE]},C={begin:"<",end:">",contains:[{beginKeywords:"in out"},l]},T=t.IDENT_RE+"(<"+t.IDENT_RE+"(\\s*,\\s*"+t.IDENT_RE+")*>)?(\\[\\])?",j={begin:"@"+t.IDENT_RE,relevance:0};return{name:"C#",aliases:["cs","c#"],keywords:o,illegal:/::/,contains:[t.COMMENT("///","$",{returnBegin:!0,contains:[{className:"doctag",variants:[{begin:"///",relevance:0},{begin:"<!--|-->"},{begin:"</?",end:">"}]}]}),t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,{className:"meta",begin:"#",end:"$",keywords:{keyword:"if else elif endif define undef warning error line region endregion pragma checksum"}},E,d,{beginKeywords:"class interface",relevance:0,end:/[{;=]/,illegal:/[^\s:,]/,contains:[{beginKeywords:"where class"},l,C,t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE]},{beginKeywords:"namespace",relevance:0,end:/[{;=]/,illegal:/[^\s:]/,contains:[l,t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE]},{beginKeywords:"record",relevance:0,end:/[{;=]/,illegal:/[^\s:]/,contains:[l,C,t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE]},{className:"meta",begin:"^\\s*\\[(?=[\\w])",excludeBegin:!0,end:"\\]",excludeEnd:!0,contains:[{className:"string",begin:/"/,end:/"/}]},{beginKeywords:"new return throw await else",relevance:0},{className:"function",begin:"("+T+"\\s+)+"+t.IDENT_RE+"\\s*(<[^=]+>\\s*)?\\(",returnBegin:!0,end:/\s*[{;=]/,excludeEnd:!0,keywords:o,contains:[{beginKeywords:n.join(" "),relevance:0},{begin:t.IDENT_RE+"\\s*(<[^=]+>\\s*)?\\(",returnBegin:!0,contains:[t.TITLE_MODE,C],relevance:0},{match:/\(\)/},{className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:o,relevance:0,contains:[E,d,t.C_BLOCK_COMMENT_MODE]},t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE]},j]}}const T6=t=>({IMPORTANT:{scope:"meta",begin:"!important"},BLOCK_COMMENT:t.C_BLOCK_COMMENT_MODE,HEXCOLOR:{scope:"number",begin:/#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/},FUNCTION_DISPATCH:{className:"built_in",begin:/[\w-]+(?=\()/},ATTRIBUTE_SELECTOR_MODE:{scope:"selector-attr",begin:/\[/,end:/\]/,illegal:"$",contains:[t.APOS_STRING_MODE,t.QUOTE_STRING_MODE]},CSS_NUMBER_MODE:{scope:"number",begin:t.NUMBER_RE+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",relevance:0},CSS_VARIABLE:{className:"attr",begin:/--[A-Za-z_][A-Za-z0-9_-]*/}}),j6=["a","abbr","address","article","aside","audio","b","blockquote","body","button","canvas","caption","cite","code","dd","del","details","dfn","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","html","i","iframe","img","input","ins","kbd","label","legend","li","main","mark","menu","nav","object","ol","optgroup","option","p","picture","q","quote","samp","section","select","source","span","strong","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","tr","ul","var","video"],M6=["defs","g","marker","mask","pattern","svg","switch","symbol","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feFlood","feGaussianBlur","feImage","feMerge","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence","linearGradient","radialGradient","stop","circle","ellipse","image","line","path","polygon","polyline","rect","text","use","textPath","tspan","foreignObject","clipPath"],A6=[...j6,...M6],R6=["any-hover","any-pointer","aspect-ratio","color","color-gamut","color-index","device-aspect-ratio","device-height","device-width","display-mode","forced-colors","grid","height","hover","inverted-colors","monochrome","orientation","overflow-block","overflow-inline","pointer","prefers-color-scheme","prefers-contrast","prefers-reduced-motion","prefers-reduced-transparency","resolution","scan","scripting","update","width","min-width","max-width","min-height","max-height"].sort().reverse(),O6=["active","any-link","blank","checked","current","default","defined","dir","disabled","drop","empty","enabled","first","first-child","first-of-type","fullscreen","future","focus","focus-visible","focus-within","has","host","host-context","hover","indeterminate","in-range","invalid","is","lang","last-child","last-of-type","left","link","local-link","not","nth-child","nth-col","nth-last-child","nth-last-col","nth-last-of-type","nth-of-type","only-child","only-of-type","optional","out-of-range","past","placeholder-shown","read-only","read-write","required","right","root","scope","target","target-within","user-invalid","valid","visited","where"].sort().reverse(),I6=["after","backdrop","before","cue","cue-region","first-letter","first-line","grammar-error","marker","part","placeholder","selection","slotted","spelling-error"].sort().reverse(),L6=["accent-color","align-content","align-items","align-self","alignment-baseline","all","anchor-name","animation","animation-composition","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-range","animation-range-end","animation-range-start","animation-timeline","animation-timing-function","appearance","aspect-ratio","backdrop-filter","backface-visibility","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-origin","background-position","background-position-x","background-position-y","background-repeat","background-size","baseline-shift","block-size","border","border-block","border-block-color","border-block-end","border-block-end-color","border-block-end-style","border-block-end-width","border-block-start","border-block-start-color","border-block-start-style","border-block-start-width","border-block-style","border-block-width","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-end-end-radius","border-end-start-radius","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-inline","border-inline-color","border-inline-end","border-inline-end-color","border-inline-end-style","border-inline-end-width","border-inline-start","border-inline-start-color","border-inline-start-style","border-inline-start-width","border-inline-style","border-inline-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-start-end-radius","border-start-start-radius","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-align","box-decoration-break","box-direction","box-flex","box-flex-group","box-lines","box-ordinal-group","box-orient","box-pack","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","caret-color","clear","clip","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","color-scheme","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","contain-intrinsic-block-size","contain-intrinsic-height","contain-intrinsic-inline-size","contain-intrinsic-size","contain-intrinsic-width","container","container-name","container-type","content","content-visibility","counter-increment","counter-reset","counter-set","cue","cue-after","cue-before","cursor","cx","cy","direction","display","dominant-baseline","empty-cells","enable-background","field-sizing","fill","fill-opacity","fill-rule","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","flood-color","flood-opacity","flow","font","font-display","font-family","font-feature-settings","font-kerning","font-language-override","font-optical-sizing","font-palette","font-size","font-size-adjust","font-smooth","font-smoothing","font-stretch","font-style","font-synthesis","font-synthesis-position","font-synthesis-small-caps","font-synthesis-style","font-synthesis-weight","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-emoji","font-variant-ligatures","font-variant-numeric","font-variant-position","font-variation-settings","font-weight","forced-color-adjust","gap","glyph-orientation-horizontal","glyph-orientation-vertical","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-gap","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphenate-character","hyphenate-limit-chars","hyphens","icon","image-orientation","image-rendering","image-resolution","ime-mode","initial-letter","initial-letter-align","inline-size","inset","inset-area","inset-block","inset-block-end","inset-block-start","inset-inline","inset-inline-end","inset-inline-start","isolation","justify-content","justify-items","justify-self","kerning","left","letter-spacing","lighting-color","line-break","line-height","line-height-step","list-style","list-style-image","list-style-position","list-style-type","margin","margin-block","margin-block-end","margin-block-start","margin-bottom","margin-inline","margin-inline-end","margin-inline-start","margin-left","margin-right","margin-top","margin-trim","marker","marker-end","marker-mid","marker-start","marks","mask","mask-border","mask-border-mode","mask-border-outset","mask-border-repeat","mask-border-slice","mask-border-source","mask-border-width","mask-clip","mask-composite","mask-image","mask-mode","mask-origin","mask-position","mask-repeat","mask-size","mask-type","masonry-auto-flow","math-depth","math-shift","math-style","max-block-size","max-height","max-inline-size","max-width","min-block-size","min-height","min-inline-size","min-width","mix-blend-mode","nav-down","nav-index","nav-left","nav-right","nav-up","none","normal","object-fit","object-position","offset","offset-anchor","offset-distance","offset-path","offset-position","offset-rotate","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-anchor","overflow-block","overflow-clip-margin","overflow-inline","overflow-wrap","overflow-x","overflow-y","overlay","overscroll-behavior","overscroll-behavior-block","overscroll-behavior-inline","overscroll-behavior-x","overscroll-behavior-y","padding","padding-block","padding-block-end","padding-block-start","padding-bottom","padding-inline","padding-inline-end","padding-inline-start","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","paint-order","pause","pause-after","pause-before","perspective","perspective-origin","place-content","place-items","place-self","pointer-events","position","position-anchor","position-visibility","print-color-adjust","quotes","r","resize","rest","rest-after","rest-before","right","rotate","row-gap","ruby-align","ruby-position","scale","scroll-behavior","scroll-margin","scroll-margin-block","scroll-margin-block-end","scroll-margin-block-start","scroll-margin-bottom","scroll-margin-inline","scroll-margin-inline-end","scroll-margin-inline-start","scroll-margin-left","scroll-margin-right","scroll-margin-top","scroll-padding","scroll-padding-block","scroll-padding-block-end","scroll-padding-block-start","scroll-padding-bottom","scroll-padding-inline","scroll-padding-inline-end","scroll-padding-inline-start","scroll-padding-left","scroll-padding-right","scroll-padding-top","scroll-snap-align","scroll-snap-stop","scroll-snap-type","scroll-timeline","scroll-timeline-axis","scroll-timeline-name","scrollbar-color","scrollbar-gutter","scrollbar-width","shape-image-threshold","shape-margin","shape-outside","shape-rendering","speak","speak-as","src","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","tab-size","table-layout","text-align","text-align-all","text-align-last","text-anchor","text-combine-upright","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-indent","text-justify","text-orientation","text-overflow","text-rendering","text-shadow","text-size-adjust","text-transform","text-underline-offset","text-underline-position","text-wrap","text-wrap-mode","text-wrap-style","timeline-scope","top","touch-action","transform","transform-box","transform-origin","transform-style","transition","transition-behavior","transition-delay","transition-duration","transition-property","transition-timing-function","translate","unicode-bidi","user-modify","user-select","vector-effect","vertical-align","view-timeline","view-timeline-axis","view-timeline-inset","view-timeline-name","view-transition-name","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","white-space","white-space-collapse","widows","width","will-change","word-break","word-spacing","word-wrap","writing-mode","x","y","z-index","zoom"].sort().reverse();function D6(t){const e=t.regex,n=T6(t),r={begin:/-(webkit|moz|ms|o)-(?=[a-z])/},s="and or not only",i=/@-?\w[\w]*(-\w+)*/,o="[a-zA-Z-][a-zA-Z0-9_-]*",l=[t.APOS_STRING_MODE,t.QUOTE_STRING_MODE];return{name:"CSS",case_insensitive:!0,illegal:/[=|'\$]/,keywords:{keyframePosition:"from to"},classNameAliases:{keyframePosition:"selector-tag"},contains:[n.BLOCK_COMMENT,r,n.CSS_NUMBER_MODE,{className:"selector-id",begin:/#[A-Za-z0-9_-]+/,relevance:0},{className:"selector-class",begin:"\\."+o,relevance:0},n.ATTRIBUTE_SELECTOR_MODE,{className:"selector-pseudo",variants:[{begin:":("+O6.join("|")+")"},{begin:":(:)?("+I6.join("|")+")"}]},n.CSS_VARIABLE,{className:"attribute",begin:"\\b("+L6.join("|")+")\\b"},{begin:/:/,end:/[;}{]/,contains:[n.BLOCK_COMMENT,n.HEXCOLOR,n.IMPORTANT,n.CSS_NUMBER_MODE,...l,{begin:/(url|data-uri)\(/,end:/\)/,relevance:0,keywords:{built_in:"url data-uri"},contains:[...l,{className:"string",begin:/[^)]/,endsWithParent:!0,excludeEnd:!0}]},n.FUNCTION_DISPATCH]},{begin:e.lookahead(/@/),end:"[{;]",relevance:0,illegal:/:/,contains:[{className:"keyword",begin:i},{begin:/\s/,endsWithParent:!0,excludeEnd:!0,relevance:0,keywords:{$pattern:/[a-z-]+/,keyword:s,attribute:R6.join(" ")},contains:[{begin:/[a-z-]+(?=:)/,className:"attribute"},...l,n.CSS_NUMBER_MODE]}]},{className:"selector-tag",begin:"\\b("+A6.join("|")+")\\b"}]}}function P6(t){const e=t.regex;return{name:"Diff",aliases:["patch"],contains:[{className:"meta",relevance:10,match:e.either(/^@@ +-\d+,\d+ +\+\d+,\d+ +@@/,/^\*\*\* +\d+,\d+ +\*\*\*\*$/,/^--- +\d+,\d+ +----$/)},{className:"comment",variants:[{begin:e.either(/Index: /,/^index/,/={3,}/,/^-{3}/,/^\*{3} /,/^\+{3}/,/^diff --git/),end:/$/},{match:/^\*{15}$/}]},{className:"addition",begin:/^\+/,end:/$/},{className:"deletion",begin:/^-/,end:/$/},{className:"addition",begin:/^!/,end:/$/}]}}function B6(t){const i={keyword:["break","case","chan","const","continue","default","defer","else","fallthrough","for","func","go","goto","if","import","interface","map","package","range","return","select","struct","switch","type","var"],type:["bool","byte","complex64","complex128","error","float32","float64","int8","int16","int32","int64","string","uint8","uint16","uint32","uint64","int","uint","uintptr","rune"],literal:["true","false","iota","nil"],built_in:["append","cap","close","complex","copy","imag","len","make","new","panic","print","println","real","recover","delete"]};return{name:"Go",aliases:["golang"],keywords:i,illegal:"</",contains:[t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,{className:"string",variants:[t.QUOTE_STRING_MODE,t.APOS_STRING_MODE,{begin:"`",end:"`"}]},{className:"number",variants:[{match:/-?\b0[xX]\.[a-fA-F0-9](_?[a-fA-F0-9])*[pP][+-]?\d(_?\d)*i?/,relevance:0},{match:/-?\b0[xX](_?[a-fA-F0-9])+((\.([a-fA-F0-9](_?[a-fA-F0-9])*)?)?[pP][+-]?\d(_?\d)*)?i?/,relevance:0},{match:/-?\b0[oO](_?[0-7])*i?/,relevance:0},{match:/-?\.\d(_?\d)*([eE][+-]?\d(_?\d)*)?i?/,relevance:0},{match:/-?\b\d(_?\d)*(\.(\d(_?\d)*)?)?([eE][+-]?\d(_?\d)*)?i?/,relevance:0}]},{begin:/:=/},{className:"function",beginKeywords:"func",end:"\\s*(\\{|$)",excludeEnd:!0,contains:[t.TITLE_MODE,{className:"params",begin:/\(/,end:/\)/,endsParent:!0,keywords:i,illegal:/["']/}]}]}}function $6(t){const e=t.regex,n=/[_A-Za-z][_0-9A-Za-z]*/;return{name:"GraphQL",aliases:["gql"],case_insensitive:!0,disableAutodetect:!1,keywords:{keyword:["query","mutation","subscription","type","input","schema","directive","interface","union","scalar","fragment","enum","on"],literal:["true","false","null"]},contains:[t.HASH_COMMENT_MODE,t.QUOTE_STRING_MODE,t.NUMBER_MODE,{scope:"punctuation",match:/[.]{3}/,relevance:0},{scope:"punctuation",begin:/[\!\(\)\:\=\[\]\{\|\}]{1}/,relevance:0},{scope:"variable",begin:/\$/,end:/\W/,excludeEnd:!0,relevance:0},{scope:"meta",match:/@\w+/,excludeEnd:!0},{scope:"symbol",begin:e.concat(n,e.lookahead(/\s*:/)),relevance:0}],illegal:[/[;<']/,/BEGIN/]}}function z6(t){const e=t.regex,n={className:"number",relevance:0,variants:[{begin:/([+-]+)?[\d]+_[\d_]+/},{begin:t.NUMBER_RE}]},r=t.COMMENT();r.variants=[{begin:/;/,end:/$/},{begin:/#/,end:/$/}];const s={className:"variable",variants:[{begin:/\$[\w\d"][\w\d_]*/},{begin:/\$\{(.*?)\}/}]},i={className:"literal",begin:/\bon|off|true|false|yes|no\b/},o={className:"string",contains:[t.BACKSLASH_ESCAPE],variants:[{begin:"'''",end:"'''",relevance:10},{begin:'"""',end:'"""',relevance:10},{begin:'"',end:'"'},{begin:"'",end:"'"}]},l={begin:/\[/,end:/\]/,contains:[r,i,s,o,n,"self"],relevance:0},d=/[A-Za-z0-9_-]+/,f=/"(\\"|[^"])*"/,h=/'[^']*'/,m=e.either(d,f,h),g=e.concat(m,"(\\s*\\.\\s*",m,")*",e.lookahead(/\s*=\s*[^#\s]/));return{name:"TOML, also INI",aliases:["toml"],case_insensitive:!0,illegal:/\S/,contains:[r,{className:"section",begin:/\[+/,end:/\]+/},{begin:g,className:"attr",starts:{end:/$/,contains:[r,l,i,s,o,n]}}]}}var Go="[0-9](_*[0-9])*",lu=`\\.(${Go})`,cu="[0-9a-fA-F](_*[0-9a-fA-F])*",Yw={className:"number",variants:[{begin:`(\\b(${Go})((${lu})|\\.)?|(${lu}))[eE][+-]?(${Go})[fFdD]?\\b`},{begin:`\\b(${Go})((${lu})[fFdD]?\\b|\\.([fFdD]\\b)?)`},{begin:`(${lu})[fFdD]?\\b`},{begin:`\\b(${Go})[fFdD]\\b`},{begin:`\\b0[xX]((${cu})\\.?|(${cu})?\\.(${cu}))[pP][+-]?(${Go})[fFdD]?\\b`},{begin:"\\b(0|[1-9](_*[0-9])*)[lL]?\\b"},{begin:`\\b0[xX](${cu})[lL]?\\b`},{begin:"\\b0(_*[0-7])*[lL]?\\b"},{begin:"\\b0[bB][01](_*[01])*[lL]?\\b"}],relevance:0};function B_(t,e,n){return n===-1?"":t.replace(e,r=>B_(t,e,n-1))}function F6(t){const e=t.regex,n="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",r=n+B_("(?:<"+n+"~~~(?:\\s*,\\s*"+n+"~~~)*>)?",/~~~/g,2),d={keyword:["synchronized","abstract","private","var","static","if","const ","for","while","strictfp","finally","protected","import","native","final","void","enum","else","break","transient","catch","instanceof","volatile","case","assert","package","default","public","try","switch","continue","throws","protected","public","private","module","requires","exports","do","sealed","yield","permits","goto","when"],literal:["false","true","null"],type:["char","boolean","long","float","int","byte","short","double"],built_in:["super","this"]},f={className:"meta",begin:"@"+n,contains:[{begin:/\(/,end:/\)/,contains:["self"]}]},h={className:"params",begin:/\(/,end:/\)/,keywords:d,relevance:0,contains:[t.C_BLOCK_COMMENT_MODE],endsParent:!0};return{name:"Java",aliases:["jsp"],keywords:d,illegal:/<\/|#/,contains:[t.COMMENT("/\\*\\*","\\*/",{relevance:0,contains:[{begin:/\w+@/,relevance:0},{className:"doctag",begin:"@[A-Za-z]+"}]}),{begin:/import java\.[a-z]+\./,keywords:"import",relevance:2},t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,{begin:/"""/,end:/"""/,className:"string",contains:[t.BACKSLASH_ESCAPE]},t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,{match:[/\b(?:class|interface|enum|extends|implements|new)/,/\s+/,n],className:{1:"keyword",3:"title.class"}},{match:/non-sealed/,scope:"keyword"},{begin:[e.concat(/(?!else)/,n),/\s+/,n,/\s+/,/=(?!=)/],className:{1:"type",3:"variable",5:"operator"}},{begin:[/record/,/\s+/,n],className:{1:"keyword",3:"title.class"},contains:[h,t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE]},{beginKeywords:"new throw return else",relevance:0},{begin:["(?:"+r+"\\s+)",t.UNDERSCORE_IDENT_RE,/\s*(?=\()/],className:{2:"title.function"},keywords:d,contains:[{className:"params",begin:/\(/,end:/\)/,keywords:d,relevance:0,contains:[f,t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,Yw,t.C_BLOCK_COMMENT_MODE]},t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE]},Yw,f]}}const Xw="[A-Za-z$_][0-9A-Za-z$_]*",U6=["as","in","of","if","for","while","finally","var","new","function","do","return","void","else","break","catch","instanceof","with","throw","case","default","try","switch","continue","typeof","delete","let","yield","const","class","debugger","async","await","static","import","from","export","extends","using"],H6=["true","false","null","undefined","NaN","Infinity"],$_=["Object","Function","Boolean","Symbol","Math","Date","Number","BigInt","String","RegExp","Array","Float32Array","Float64Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Int32Array","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array","Set","Map","WeakSet","WeakMap","ArrayBuffer","SharedArrayBuffer","Atomics","DataView","JSON","Promise","Generator","GeneratorFunction","AsyncFunction","Reflect","Proxy","Intl","WebAssembly"],z_=["Error","EvalError","InternalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError"],F_=["setInterval","setTimeout","clearInterval","clearTimeout","require","exports","eval","isFinite","isNaN","parseFloat","parseInt","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape"],W6=["arguments","this","super","console","window","document","localStorage","sessionStorage","module","global"],q6=[].concat(F_,$_,z_);function V6(t){const e=t.regex,n=(V,{after:te})=>{const K="</"+V[0].slice(1);return V.input.indexOf(K,te)!==-1},r=Xw,s={begin:"<>",end:"</>"},i=/<[A-Za-z0-9\\._:-]+\s*\/>/,o={begin:/<[A-Za-z0-9\\._:-]+/,end:/\/[A-Za-z0-9\\._:-]+>|\/>/,isTrulyOpeningTag:(V,te)=>{const K=V[0].length+V.index,M=V.input[K];if(M==="<"||M===","){te.ignoreMatch();return}M===">"&&(n(V,{after:K})||te.ignoreMatch());let L;const ee=V.input.substring(K);if(L=ee.match(/^\s*=/)){te.ignoreMatch();return}if((L=ee.match(/^\s+extends\s+/))&&L.index===0){te.ignoreMatch();return}}},l={$pattern:Xw,keyword:U6,literal:H6,built_in:q6,"variable.language":W6},d="[0-9](_?[0-9])*",f=`\\.(${d})`,h="0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*",m={className:"number",variants:[{begin:`(\\b(${h})((${f})|\\.)?|(${f}))[eE][+-]?(${d})\\b`},{begin:`\\b(${h})\\b((${f})\\b|\\.)?|(${f})\\b`},{begin:"\\b(0|[1-9](_?[0-9])*)n\\b"},{begin:"\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b"},{begin:"\\b0[bB][0-1](_?[0-1])*n?\\b"},{begin:"\\b0[oO][0-7](_?[0-7])*n?\\b"},{begin:"\\b0[0-7]+n?\\b"}],relevance:0},g={className:"subst",begin:"\\$\\{",end:"\\}",keywords:l,contains:[]},v={begin:".?html`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,g],subLanguage:"xml"}},b={begin:".?css`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,g],subLanguage:"css"}},k={begin:".?gql`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,g],subLanguage:"graphql"}},w={className:"string",begin:"`",end:"`",contains:[t.BACKSLASH_ESCAPE,g]},C={className:"comment",variants:[t.COMMENT(/\/\*\*(?!\/)/,"\\*/",{relevance:0,contains:[{begin:"(?=@[A-Za-z]+)",relevance:0,contains:[{className:"doctag",begin:"@[A-Za-z]+"},{className:"type",begin:"\\{",end:"\\}",excludeEnd:!0,excludeBegin:!0,relevance:0},{className:"variable",begin:r+"(?=\\s*(-)|$)",endsParent:!0,relevance:0},{begin:/(?=[^\n])\s/,relevance:0}]}]}),t.C_BLOCK_COMMENT_MODE,t.C_LINE_COMMENT_MODE]},T=[t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,v,b,k,w,{match:/\$\d+/},m];g.contains=T.concat({begin:/\{/,end:/\}/,keywords:l,contains:["self"].concat(T)});const j=[].concat(C,g.contains),_=j.concat([{begin:/(\s*)\(/,end:/\)/,keywords:l,contains:["self"].concat(j)}]),A={className:"params",begin:/(\s*)\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:l,contains:_},O={variants:[{match:[/class/,/\s+/,r,/\s+/,/extends/,/\s+/,e.concat(r,"(",e.concat(/\./,r),")*")],scope:{1:"keyword",3:"title.class",5:"keyword",7:"title.class.inherited"}},{match:[/class/,/\s+/,r],scope:{1:"keyword",3:"title.class"}}]},B={relevance:0,match:e.either(/\bJSON/,/\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,/\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,/\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/),className:"title.class",keywords:{_:[...$_,...z_]}},$={label:"use_strict",className:"meta",relevance:10,begin:/^\s*['"]use (strict|asm)['"]/},W={variants:[{match:[/function/,/\s+/,r,/(?=\s*\()/]},{match:[/function/,/\s*(?=\()/]}],className:{1:"keyword",3:"title.function"},label:"func.def",contains:[A],illegal:/%/},J={relevance:0,match:/\b[A-Z][A-Z_0-9]+\b/,className:"variable.constant"};function z(V){return e.concat("(?!",V.join("|"),")")}const G={match:e.concat(/\b/,z([...F_,"super","import"].map(V=>`${V}\\s*\\(`)),r,e.lookahead(/\s*\(/)),className:"title.function",relevance:0},D={begin:e.concat(/\./,e.lookahead(e.concat(r,/(?![0-9A-Za-z$_(])/))),end:r,excludeBegin:!0,keywords:"prototype",className:"property",relevance:0},U={match:[/get|set/,/\s+/,r,/(?=\()/],className:{1:"keyword",3:"title.function"},contains:[{begin:/\(\)/},A]},q="(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|"+t.UNDERSCORE_IDENT_RE+")\\s*=>",se={match:[/const|var|let/,/\s+/,r,/\s*/,/=\s*/,/(async\s*)?/,e.lookahead(q)],keywords:"async",className:{1:"keyword",3:"title.function"},contains:[A]};return{name:"JavaScript",aliases:["js","jsx","mjs","cjs"],keywords:l,exports:{PARAMS_CONTAINS:_,CLASS_REFERENCE:B},illegal:/#(?![$_A-z])/,contains:[t.SHEBANG({label:"shebang",binary:"node",relevance:5}),$,t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,v,b,k,w,C,{match:/\$\d+/},m,B,{scope:"attr",match:r+e.lookahead(":"),relevance:0},se,{begin:"("+t.RE_STARTERS_RE+"|\\b(case|return|throw)\\b)\\s*",keywords:"return throw case",relevance:0,contains:[C,t.REGEXP_MODE,{className:"function",begin:q,returnBegin:!0,end:"\\s*=>",contains:[{className:"params",variants:[{begin:t.UNDERSCORE_IDENT_RE,relevance:0},{className:null,begin:/\(\s*\)/,skip:!0},{begin:/(\s*)\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:l,contains:_}]}]},{begin:/,/,relevance:0},{match:/\s+/,relevance:0},{variants:[{begin:s.begin,end:s.end},{match:i},{begin:o.begin,"on:begin":o.isTrulyOpeningTag,end:o.end}],subLanguage:"xml",contains:[{begin:o.begin,end:o.end,skip:!0,contains:["self"]}]}]},W,{beginKeywords:"while if switch catch for"},{begin:"\\b(?!function)"+t.UNDERSCORE_IDENT_RE+"\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",returnBegin:!0,label:"func.def",contains:[A,t.inherit(t.TITLE_MODE,{begin:r,className:"title.function"})]},{match:/\.\.\./,relevance:0},D,{match:"\\$"+r,relevance:0},{match:[/\bconstructor(?=\s*\()/],className:{1:"title.function"},contains:[A]},G,J,O,U,{match:/\$[(.]/}]}}function K6(t){const e={className:"attr",begin:/"(\\.|[^\\"\r\n])*"(?=\s*:)/,relevance:1.01},n={match:/[{}[\],:]/,className:"punctuation",relevance:0},r=["true","false","null"],s={scope:"literal",beginKeywords:r.join(" ")};return{name:"JSON",aliases:["jsonc"],keywords:{literal:r},contains:[e,n,t.QUOTE_STRING_MODE,s,t.C_NUMBER_MODE,t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE],illegal:"\\S"}}var Jo="[0-9](_*[0-9])*",uu=`\\.(${Jo})`,du="[0-9a-fA-F](_*[0-9a-fA-F])*",G6={className:"number",variants:[{begin:`(\\b(${Jo})((${uu})|\\.)?|(${uu}))[eE][+-]?(${Jo})[fFdD]?\\b`},{begin:`\\b(${Jo})((${uu})[fFdD]?\\b|\\.([fFdD]\\b)?)`},{begin:`(${uu})[fFdD]?\\b`},{begin:`\\b(${Jo})[fFdD]\\b`},{begin:`\\b0[xX]((${du})\\.?|(${du})?\\.(${du}))[pP][+-]?(${Jo})[fFdD]?\\b`},{begin:"\\b(0|[1-9](_*[0-9])*)[lL]?\\b"},{begin:`\\b0[xX](${du})[lL]?\\b`},{begin:"\\b0(_*[0-7])*[lL]?\\b"},{begin:"\\b0[bB][01](_*[01])*[lL]?\\b"}],relevance:0};function J6(t){const e={keyword:"abstract as val var vararg get set class object open private protected public noinline crossinline dynamic final enum if else do while for when throw try catch finally import package is in fun override companion reified inline lateinit init interface annotation data sealed internal infix operator out by constructor super tailrec where const inner suspend typealias external expect actual",built_in:"Byte Short Char Int Long Boolean Float Double Void Unit Nothing",literal:"true false null"},n={className:"keyword",begin:/\b(break|continue|return|this)\b/,starts:{contains:[{className:"symbol",begin:/@\w+/}]}},r={className:"symbol",begin:t.UNDERSCORE_IDENT_RE+"@"},s={className:"subst",begin:/\$\{/,end:/\}/,contains:[t.C_NUMBER_MODE]},i={className:"variable",begin:"\\$"+t.UNDERSCORE_IDENT_RE},o={className:"string",variants:[{begin:'"""',end:'"""(?=[^"])',contains:[i,s]},{begin:"'",end:"'",illegal:/\n/,contains:[t.BACKSLASH_ESCAPE]},{begin:'"',end:'"',illegal:/\n/,contains:[t.BACKSLASH_ESCAPE,i,s]}]};s.contains.push(o);const l={className:"meta",begin:"@(?:file|property|field|get|set|receiver|param|setparam|delegate)\\s*:(?:\\s*"+t.UNDERSCORE_IDENT_RE+")?"},d={className:"meta",begin:"@"+t.UNDERSCORE_IDENT_RE,contains:[{begin:/\(/,end:/\)/,contains:[t.inherit(o,{className:"string"}),"self"]}]},f=G6,h=t.COMMENT("/\\*","\\*/",{contains:[t.C_BLOCK_COMMENT_MODE]}),m={variants:[{className:"type",begin:t.UNDERSCORE_IDENT_RE},{begin:/\(/,end:/\)/,contains:[]}]},g=m;return g.variants[1].contains=[m],m.variants[1].contains=[g],{name:"Kotlin",aliases:["kt","kts"],keywords:e,contains:[t.COMMENT("/\\*\\*","\\*/",{relevance:0,contains:[{className:"doctag",begin:"@[A-Za-z]+"}]}),t.C_LINE_COMMENT_MODE,h,n,r,l,d,{className:"function",beginKeywords:"fun",end:"[(]|$",returnBegin:!0,excludeEnd:!0,keywords:e,relevance:5,contains:[{begin:t.UNDERSCORE_IDENT_RE+"\\s*\\(",returnBegin:!0,relevance:0,contains:[t.UNDERSCORE_TITLE_MODE]},{className:"type",begin:/</,end:/>/,keywords:"reified",relevance:0},{className:"params",begin:/\(/,end:/\)/,endsParent:!0,keywords:e,relevance:0,contains:[{begin:/:/,end:/[=,\/]/,endsWithParent:!0,contains:[m,t.C_LINE_COMMENT_MODE,h],relevance:0},t.C_LINE_COMMENT_MODE,h,l,d,o,t.C_NUMBER_MODE]},h]},{begin:[/class|interface|trait/,/\s+/,t.UNDERSCORE_IDENT_RE],beginScope:{3:"title.class"},keywords:"class interface trait",end:/[:\{(]|$/,excludeEnd:!0,illegal:"extends implements",contains:[{beginKeywords:"public protected internal private constructor"},t.UNDERSCORE_TITLE_MODE,{className:"type",begin:/</,end:/>/,excludeBegin:!0,excludeEnd:!0,relevance:0},{className:"type",begin:/[,:]\s*/,end:/[<\(,){\s]|$/,excludeBegin:!0,returnEnd:!0},l,d]},o,{className:"meta",begin:"^#!/usr/bin/env",end:"$",illegal:`
202
202
  `},f]}}const Y6=t=>({IMPORTANT:{scope:"meta",begin:"!important"},BLOCK_COMMENT:t.C_BLOCK_COMMENT_MODE,HEXCOLOR:{scope:"number",begin:/#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/},FUNCTION_DISPATCH:{className:"built_in",begin:/[\w-]+(?=\()/},ATTRIBUTE_SELECTOR_MODE:{scope:"selector-attr",begin:/\[/,end:/\]/,illegal:"$",contains:[t.APOS_STRING_MODE,t.QUOTE_STRING_MODE]},CSS_NUMBER_MODE:{scope:"number",begin:t.NUMBER_RE+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",relevance:0},CSS_VARIABLE:{className:"attr",begin:/--[A-Za-z_][A-Za-z0-9_-]*/}}),X6=["a","abbr","address","article","aside","audio","b","blockquote","body","button","canvas","caption","cite","code","dd","del","details","dfn","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","html","i","iframe","img","input","ins","kbd","label","legend","li","main","mark","menu","nav","object","ol","optgroup","option","p","picture","q","quote","samp","section","select","source","span","strong","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","tr","ul","var","video"],Q6=["defs","g","marker","mask","pattern","svg","switch","symbol","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feFlood","feGaussianBlur","feImage","feMerge","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence","linearGradient","radialGradient","stop","circle","ellipse","image","line","path","polygon","polyline","rect","text","use","textPath","tspan","foreignObject","clipPath"],Z6=[...X6,...Q6],eB=["any-hover","any-pointer","aspect-ratio","color","color-gamut","color-index","device-aspect-ratio","device-height","device-width","display-mode","forced-colors","grid","height","hover","inverted-colors","monochrome","orientation","overflow-block","overflow-inline","pointer","prefers-color-scheme","prefers-contrast","prefers-reduced-motion","prefers-reduced-transparency","resolution","scan","scripting","update","width","min-width","max-width","min-height","max-height"].sort().reverse(),U_=["active","any-link","blank","checked","current","default","defined","dir","disabled","drop","empty","enabled","first","first-child","first-of-type","fullscreen","future","focus","focus-visible","focus-within","has","host","host-context","hover","indeterminate","in-range","invalid","is","lang","last-child","last-of-type","left","link","local-link","not","nth-child","nth-col","nth-last-child","nth-last-col","nth-last-of-type","nth-of-type","only-child","only-of-type","optional","out-of-range","past","placeholder-shown","read-only","read-write","required","right","root","scope","target","target-within","user-invalid","valid","visited","where"].sort().reverse(),H_=["after","backdrop","before","cue","cue-region","first-letter","first-line","grammar-error","marker","part","placeholder","selection","slotted","spelling-error"].sort().reverse(),tB=["accent-color","align-content","align-items","align-self","alignment-baseline","all","anchor-name","animation","animation-composition","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-range","animation-range-end","animation-range-start","animation-timeline","animation-timing-function","appearance","aspect-ratio","backdrop-filter","backface-visibility","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-origin","background-position","background-position-x","background-position-y","background-repeat","background-size","baseline-shift","block-size","border","border-block","border-block-color","border-block-end","border-block-end-color","border-block-end-style","border-block-end-width","border-block-start","border-block-start-color","border-block-start-style","border-block-start-width","border-block-style","border-block-width","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-end-end-radius","border-end-start-radius","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-inline","border-inline-color","border-inline-end","border-inline-end-color","border-inline-end-style","border-inline-end-width","border-inline-start","border-inline-start-color","border-inline-start-style","border-inline-start-width","border-inline-style","border-inline-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-start-end-radius","border-start-start-radius","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-align","box-decoration-break","box-direction","box-flex","box-flex-group","box-lines","box-ordinal-group","box-orient","box-pack","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","caret-color","clear","clip","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","color-scheme","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","contain-intrinsic-block-size","contain-intrinsic-height","contain-intrinsic-inline-size","contain-intrinsic-size","contain-intrinsic-width","container","container-name","container-type","content","content-visibility","counter-increment","counter-reset","counter-set","cue","cue-after","cue-before","cursor","cx","cy","direction","display","dominant-baseline","empty-cells","enable-background","field-sizing","fill","fill-opacity","fill-rule","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","flood-color","flood-opacity","flow","font","font-display","font-family","font-feature-settings","font-kerning","font-language-override","font-optical-sizing","font-palette","font-size","font-size-adjust","font-smooth","font-smoothing","font-stretch","font-style","font-synthesis","font-synthesis-position","font-synthesis-small-caps","font-synthesis-style","font-synthesis-weight","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-emoji","font-variant-ligatures","font-variant-numeric","font-variant-position","font-variation-settings","font-weight","forced-color-adjust","gap","glyph-orientation-horizontal","glyph-orientation-vertical","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-gap","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphenate-character","hyphenate-limit-chars","hyphens","icon","image-orientation","image-rendering","image-resolution","ime-mode","initial-letter","initial-letter-align","inline-size","inset","inset-area","inset-block","inset-block-end","inset-block-start","inset-inline","inset-inline-end","inset-inline-start","isolation","justify-content","justify-items","justify-self","kerning","left","letter-spacing","lighting-color","line-break","line-height","line-height-step","list-style","list-style-image","list-style-position","list-style-type","margin","margin-block","margin-block-end","margin-block-start","margin-bottom","margin-inline","margin-inline-end","margin-inline-start","margin-left","margin-right","margin-top","margin-trim","marker","marker-end","marker-mid","marker-start","marks","mask","mask-border","mask-border-mode","mask-border-outset","mask-border-repeat","mask-border-slice","mask-border-source","mask-border-width","mask-clip","mask-composite","mask-image","mask-mode","mask-origin","mask-position","mask-repeat","mask-size","mask-type","masonry-auto-flow","math-depth","math-shift","math-style","max-block-size","max-height","max-inline-size","max-width","min-block-size","min-height","min-inline-size","min-width","mix-blend-mode","nav-down","nav-index","nav-left","nav-right","nav-up","none","normal","object-fit","object-position","offset","offset-anchor","offset-distance","offset-path","offset-position","offset-rotate","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-anchor","overflow-block","overflow-clip-margin","overflow-inline","overflow-wrap","overflow-x","overflow-y","overlay","overscroll-behavior","overscroll-behavior-block","overscroll-behavior-inline","overscroll-behavior-x","overscroll-behavior-y","padding","padding-block","padding-block-end","padding-block-start","padding-bottom","padding-inline","padding-inline-end","padding-inline-start","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","paint-order","pause","pause-after","pause-before","perspective","perspective-origin","place-content","place-items","place-self","pointer-events","position","position-anchor","position-visibility","print-color-adjust","quotes","r","resize","rest","rest-after","rest-before","right","rotate","row-gap","ruby-align","ruby-position","scale","scroll-behavior","scroll-margin","scroll-margin-block","scroll-margin-block-end","scroll-margin-block-start","scroll-margin-bottom","scroll-margin-inline","scroll-margin-inline-end","scroll-margin-inline-start","scroll-margin-left","scroll-margin-right","scroll-margin-top","scroll-padding","scroll-padding-block","scroll-padding-block-end","scroll-padding-block-start","scroll-padding-bottom","scroll-padding-inline","scroll-padding-inline-end","scroll-padding-inline-start","scroll-padding-left","scroll-padding-right","scroll-padding-top","scroll-snap-align","scroll-snap-stop","scroll-snap-type","scroll-timeline","scroll-timeline-axis","scroll-timeline-name","scrollbar-color","scrollbar-gutter","scrollbar-width","shape-image-threshold","shape-margin","shape-outside","shape-rendering","speak","speak-as","src","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","tab-size","table-layout","text-align","text-align-all","text-align-last","text-anchor","text-combine-upright","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-indent","text-justify","text-orientation","text-overflow","text-rendering","text-shadow","text-size-adjust","text-transform","text-underline-offset","text-underline-position","text-wrap","text-wrap-mode","text-wrap-style","timeline-scope","top","touch-action","transform","transform-box","transform-origin","transform-style","transition","transition-behavior","transition-delay","transition-duration","transition-property","transition-timing-function","translate","unicode-bidi","user-modify","user-select","vector-effect","vertical-align","view-timeline","view-timeline-axis","view-timeline-inset","view-timeline-name","view-transition-name","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","white-space","white-space-collapse","widows","width","will-change","word-break","word-spacing","word-wrap","writing-mode","x","y","z-index","zoom"].sort().reverse(),nB=U_.concat(H_).sort().reverse();function rB(t){const e=Y6(t),n=nB,r="and or not only",s="[\\w-]+",i="("+s+"|@\\{"+s+"\\})",o=[],l=[],d=function(T){return{className:"string",begin:"~?"+T+".*?"+T}},f=function(T,j,_){return{className:T,begin:j,relevance:_}},h={$pattern:/[a-z-]+/,keyword:r,attribute:eB.join(" ")},m={begin:"\\(",end:"\\)",contains:l,keywords:h,relevance:0};l.push(t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,d("'"),d('"'),e.CSS_NUMBER_MODE,{begin:"(url|data-uri)\\(",starts:{className:"string",end:"[\\)\\n]",excludeEnd:!0}},e.HEXCOLOR,m,f("variable","@@?"+s,10),f("variable","@\\{"+s+"\\}"),f("built_in","~?`[^`]*?`"),{className:"attribute",begin:s+"\\s*:",end:":",returnBegin:!0,excludeEnd:!0},e.IMPORTANT,{beginKeywords:"and not"},e.FUNCTION_DISPATCH);const g=l.concat({begin:/\{/,end:/\}/,contains:o}),v={beginKeywords:"when",endsWithParent:!0,contains:[{beginKeywords:"and not"}].concat(l)},b={begin:i+"\\s*:",returnBegin:!0,end:/[;}]/,relevance:0,contains:[{begin:/-(webkit|moz|ms|o)-/},e.CSS_VARIABLE,{className:"attribute",begin:"\\b("+tB.join("|")+")\\b",end:/(?=:)/,starts:{endsWithParent:!0,illegal:"[<=$]",relevance:0,contains:l}}]},k={className:"keyword",begin:"@(import|media|charset|font-face|(-[a-z]+-)?keyframes|supports|document|namespace|page|viewport|host)\\b",starts:{end:"[;{}]",keywords:h,returnEnd:!0,contains:l,relevance:0}},w={className:"variable",variants:[{begin:"@"+s+"\\s*:",relevance:15},{begin:"@"+s}],starts:{end:"[;}]",returnEnd:!0,contains:g}},E={variants:[{begin:"[\\.#:&\\[>]",end:"[;{}]"},{begin:i,end:/\{/}],returnBegin:!0,returnEnd:!0,illegal:`[<='$"]`,relevance:0,contains:[t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,v,f("keyword","all\\b"),f("variable","@\\{"+s+"\\}"),{begin:"\\b("+Z6.join("|")+")\\b",className:"selector-tag"},e.CSS_NUMBER_MODE,f("selector-tag",i,0),f("selector-id","#"+i),f("selector-class","\\."+i,0),f("selector-tag","&",0),e.ATTRIBUTE_SELECTOR_MODE,{className:"selector-pseudo",begin:":("+U_.join("|")+")"},{className:"selector-pseudo",begin:":(:)?("+H_.join("|")+")"},{begin:/\(/,end:/\)/,relevance:0,contains:g},{begin:"!important"},e.FUNCTION_DISPATCH]},C={begin:s+`:(:)?(${n.join("|")})`,returnBegin:!0,contains:[E]};return o.push(t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,k,w,C,b,E,v,e.FUNCTION_DISPATCH),{name:"Less",case_insensitive:!0,illegal:`[=>'/<($"]`,contains:o}}function sB(t){const e="\\[=*\\[",n="\\]=*\\]",r={begin:e,end:n,contains:["self"]},s=[t.COMMENT("--(?!"+e+")","$"),t.COMMENT("--"+e,n,{contains:[r],relevance:10})];return{name:"Lua",aliases:["pluto"],keywords:{$pattern:t.UNDERSCORE_IDENT_RE,literal:"true false nil",keyword:"and break do else elseif end for goto if in local not or repeat return then until while",built_in:"_G _ENV _VERSION __index __newindex __mode __call __metatable __tostring __len __gc __add __sub __mul __div __mod __pow __concat __unm __eq __lt __le assert collectgarbage dofile error getfenv getmetatable ipairs load loadfile loadstring module next pairs pcall print rawequal rawget rawset require select setfenv setmetatable tonumber tostring type unpack xpcall arg self coroutine resume yield status wrap create running debug getupvalue debug sethook getmetatable gethook setmetatable setlocal traceback setfenv getinfo setupvalue getlocal getregistry getfenv io lines write close flush open output type read stderr stdin input stdout popen tmpfile math log max acos huge ldexp pi cos tanh pow deg tan cosh sinh random randomseed frexp ceil floor rad abs sqrt modf asin min mod fmod log10 atan2 exp sin atan os exit setlocale date getenv difftime remove time clock tmpname rename execute package preload loadlib loaded loaders cpath config path seeall string sub upper len gfind rep find match char dump gmatch reverse byte format gsub lower table setn insert getn foreachi maxn foreach concat sort remove"},contains:s.concat([{className:"function",beginKeywords:"function",end:"\\)",contains:[t.inherit(t.TITLE_MODE,{begin:"([_a-zA-Z]\\w*\\.)*([_a-zA-Z]\\w*:)?[_a-zA-Z]\\w*"}),{className:"params",begin:"\\(",endsWithParent:!0,contains:s}].concat(s)},t.C_NUMBER_MODE,t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,{className:"string",begin:e,end:n,contains:[r],relevance:5}])}}function iB(t){const e={className:"variable",variants:[{begin:"\\$\\("+t.UNDERSCORE_IDENT_RE+"\\)",contains:[t.BACKSLASH_ESCAPE]},{begin:/\$[@%<?\^\+\*]/}]},n={className:"string",begin:/"/,end:/"/,contains:[t.BACKSLASH_ESCAPE,e]},r={className:"variable",begin:/\$\([\w-]+\s/,end:/\)/,keywords:{built_in:"subst patsubst strip findstring filter filter-out sort word wordlist firstword lastword dir notdir suffix basename addsuffix addprefix join wildcard realpath abspath error warning shell origin flavor foreach if or and call eval file value"},contains:[e,n]},s={begin:"^"+t.UNDERSCORE_IDENT_RE+"\\s*(?=[:+?]?=)"},i={className:"meta",begin:/^\.PHONY:/,end:/$/,keywords:{$pattern:/[\.\w]+/,keyword:".PHONY"}},o={className:"section",begin:/^[^\s]+:/,end:/$/,contains:[e]};return{name:"Makefile",aliases:["mk","mak","make"],keywords:{$pattern:/[\w-]+/,keyword:"define endef undefine ifdef ifndef ifeq ifneq else endif include -include sinclude override export unexport private vpath"},contains:[t.HASH_COMMENT_MODE,e,n,r,s,i,o]}}function oB(t){const e=t.regex,n={begin:/<\/?[A-Za-z_]/,end:">",subLanguage:"xml",relevance:0},r={begin:"^[-\\*]{3,}",end:"$"},s={className:"code",variants:[{begin:"(`{3,})[^`](.|\\n)*?\\1`*[ ]*"},{begin:"(~{3,})[^~](.|\\n)*?\\1~*[ ]*"},{begin:"```",end:"```+[ ]*$"},{begin:"~~~",end:"~~~+[ ]*$"},{begin:"`.+?`"},{begin:"(?=^( {4}|\\t))",contains:[{begin:"^( {4}|\\t)",end:"(\\n)$"}],relevance:0}]},i={className:"bullet",begin:"^[ ]*([*+-]|(\\d+\\.))(?=\\s+)",end:"\\s+",excludeEnd:!0},o={begin:/^\[[^\n]+\]:/,returnBegin:!0,contains:[{className:"symbol",begin:/\[/,end:/\]/,excludeBegin:!0,excludeEnd:!0},{className:"link",begin:/:\s*/,end:/$/,excludeBegin:!0}]},l=/[A-Za-z][A-Za-z0-9+.-]*/,d={variants:[{begin:/\[.+?\]\[.*?\]/,relevance:0},{begin:/\[.+?\]\(((data|javascript|mailto):|(?:http|ftp)s?:\/\/).*?\)/,relevance:2},{begin:e.concat(/\[.+?\]\(/,l,/:\/\/.*?\)/),relevance:2},{begin:/\[.+?\]\([./?&#].*?\)/,relevance:1},{begin:/\[.*?\]\(.*?\)/,relevance:0}],returnBegin:!0,contains:[{match:/\[(?=\])/},{className:"string",relevance:0,begin:"\\[",end:"\\]",excludeBegin:!0,returnEnd:!0},{className:"link",relevance:0,begin:"\\]\\(",end:"\\)",excludeBegin:!0,excludeEnd:!0},{className:"symbol",relevance:0,begin:"\\]\\[",end:"\\]",excludeBegin:!0,excludeEnd:!0}]},f={className:"strong",contains:[],variants:[{begin:/_{2}(?!\s)/,end:/_{2}/},{begin:/\*{2}(?!\s)/,end:/\*{2}/}]},h={className:"emphasis",contains:[],variants:[{begin:/\*(?![*\s])/,end:/\*/},{begin:/_(?![_\s])/,end:/_/,relevance:0}]},m=t.inherit(f,{contains:[]}),g=t.inherit(h,{contains:[]});f.contains.push(g),h.contains.push(m);let v=[n,d];return[f,h,m,g].forEach(E=>{E.contains=E.contains.concat(v)}),v=v.concat(f,h),{name:"Markdown",aliases:["md","mkdown","mkd"],contains:[{className:"section",variants:[{begin:"^#{1,6}",end:"$",contains:v},{begin:"(?=^.+?\\n[=-]{2,}$)",contains:[{begin:"^[=-]*$"},{begin:"^",end:"\\n",contains:v}]}]},n,i,f,h,{className:"quote",begin:"^>\\s+",contains:v,end:"$"},s,r,d,o,{scope:"literal",match:/&([a-zA-Z0-9]+|#[0-9]{1,7}|#[Xx][0-9a-fA-F]{1,6});/}]}}function aB(t){const e={className:"built_in",begin:"\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+"},n=/[a-zA-Z@][a-zA-Z0-9_]*/,l={"variable.language":["this","super"],$pattern:n,keyword:["while","export","sizeof","typedef","const","struct","for","union","volatile","static","mutable","if","do","return","goto","enum","else","break","extern","asm","case","default","register","explicit","typename","switch","continue","inline","readonly","assign","readwrite","self","@synchronized","id","typeof","nonatomic","IBOutlet","IBAction","strong","weak","copy","in","out","inout","bycopy","byref","oneway","__strong","__weak","__block","__autoreleasing","@private","@protected","@public","@try","@property","@end","@throw","@catch","@finally","@autoreleasepool","@synthesize","@dynamic","@selector","@optional","@required","@encode","@package","@import","@defs","@compatibility_alias","__bridge","__bridge_transfer","__bridge_retained","__bridge_retain","__covariant","__contravariant","__kindof","_Nonnull","_Nullable","_Null_unspecified","__FUNCTION__","__PRETTY_FUNCTION__","__attribute__","getter","setter","retain","unsafe_unretained","nonnull","nullable","null_unspecified","null_resettable","class","instancetype","NS_DESIGNATED_INITIALIZER","NS_UNAVAILABLE","NS_REQUIRES_SUPER","NS_RETURNS_INNER_POINTER","NS_INLINE","NS_AVAILABLE","NS_DEPRECATED","NS_ENUM","NS_OPTIONS","NS_SWIFT_UNAVAILABLE","NS_ASSUME_NONNULL_BEGIN","NS_ASSUME_NONNULL_END","NS_REFINED_FOR_SWIFT","NS_SWIFT_NAME","NS_SWIFT_NOTHROW","NS_DURING","NS_HANDLER","NS_ENDHANDLER","NS_VALUERETURN","NS_VOIDRETURN"],literal:["false","true","FALSE","TRUE","nil","YES","NO","NULL"],built_in:["dispatch_once_t","dispatch_queue_t","dispatch_sync","dispatch_async","dispatch_once"],type:["int","float","char","unsigned","signed","short","long","double","wchar_t","unichar","void","bool","BOOL","id|0","_Bool"]},d={$pattern:n,keyword:["@interface","@class","@protocol","@implementation"]};return{name:"Objective-C",aliases:["mm","objc","obj-c","obj-c++","objective-c++"],keywords:l,illegal:"</",contains:[e,t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,t.C_NUMBER_MODE,t.QUOTE_STRING_MODE,t.APOS_STRING_MODE,{className:"string",variants:[{begin:'@"',end:'"',illegal:"\\n",contains:[t.BACKSLASH_ESCAPE]}]},{className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{keyword:"if else elif endif define undef warning error line pragma ifdef ifndef include"},contains:[{begin:/\\\n/,relevance:0},t.inherit(t.QUOTE_STRING_MODE,{className:"string"}),{className:"string",begin:/<.*?>/,end:/$/,illegal:"\\n"},t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE]},{className:"class",begin:"("+d.keyword.join("|")+")\\b",end:/(\{|$)/,excludeEnd:!0,keywords:d,contains:[t.UNDERSCORE_TITLE_MODE]},{begin:"\\."+t.UNDERSCORE_IDENT_RE,relevance:0}]}}function lB(t){const e=t.regex,n=["abs","accept","alarm","and","atan2","bind","binmode","bless","break","caller","chdir","chmod","chomp","chop","chown","chr","chroot","class","close","closedir","connect","continue","cos","crypt","dbmclose","dbmopen","defined","delete","die","do","dump","each","else","elsif","endgrent","endhostent","endnetent","endprotoent","endpwent","endservent","eof","eval","exec","exists","exit","exp","fcntl","field","fileno","flock","for","foreach","fork","format","formline","getc","getgrent","getgrgid","getgrnam","gethostbyaddr","gethostbyname","gethostent","getlogin","getnetbyaddr","getnetbyname","getnetent","getpeername","getpgrp","getpriority","getprotobyname","getprotobynumber","getprotoent","getpwent","getpwnam","getpwuid","getservbyname","getservbyport","getservent","getsockname","getsockopt","given","glob","gmtime","goto","grep","gt","hex","if","index","int","ioctl","join","keys","kill","last","lc","lcfirst","length","link","listen","local","localtime","log","lstat","lt","ma","map","method","mkdir","msgctl","msgget","msgrcv","msgsnd","my","ne","next","no","not","oct","open","opendir","or","ord","our","pack","package","pipe","pop","pos","print","printf","prototype","push","q|0","qq","quotemeta","qw","qx","rand","read","readdir","readline","readlink","readpipe","recv","redo","ref","rename","require","reset","return","reverse","rewinddir","rindex","rmdir","say","scalar","seek","seekdir","select","semctl","semget","semop","send","setgrent","sethostent","setnetent","setpgrp","setpriority","setprotoent","setpwent","setservent","setsockopt","shift","shmctl","shmget","shmread","shmwrite","shutdown","sin","sleep","socket","socketpair","sort","splice","split","sprintf","sqrt","srand","stat","state","study","sub","substr","symlink","syscall","sysopen","sysread","sysseek","system","syswrite","tell","telldir","tie","tied","time","times","tr","truncate","uc","ucfirst","umask","undef","unless","unlink","unpack","unshift","untie","until","use","utime","values","vec","wait","waitpid","wantarray","warn","when","while","write","x|0","xor","y|0"],r=/[dualxmsipngr]{0,12}/,s={$pattern:/[\w.]+/,keyword:n.join(" ")},i={className:"subst",begin:"[$@]\\{",end:"\\}",keywords:s},o={begin:/->\{/,end:/\}/},l={scope:"attr",match:/\s+:\s*\w+(\s*\(.*?\))?/},d={scope:"variable",variants:[{begin:/\$\d/},{begin:e.concat(/[$%@](?!")(\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,"(?![A-Za-z])(?![@$%])")},{begin:/[$%@](?!")[^\s\w{=]|\$=/,relevance:0}],contains:[l]},f={className:"number",variants:[{match:/0?\.[0-9][0-9_]+\b/},{match:/\bv?(0|[1-9][0-9_]*(\.[0-9_]+)?|[1-9][0-9_]*)\b/},{match:/\b0[0-7][0-7_]*\b/},{match:/\b0x[0-9a-fA-F][0-9a-fA-F_]*\b/},{match:/\b0b[0-1][0-1_]*\b/}],relevance:0},h=[t.BACKSLASH_ESCAPE,i,d],m=[/!/,/\//,/\|/,/\?/,/'/,/"/,/#/],g=(k,w,E="\\1")=>{const C=E==="\\1"?E:e.concat(E,w);return e.concat(e.concat("(?:",k,")"),w,/(?:\\.|[^\\\/])*?/,C,/(?:\\.|[^\\\/])*?/,E,r)},v=(k,w,E)=>e.concat(e.concat("(?:",k,")"),w,/(?:\\.|[^\\\/])*?/,E,r),b=[d,t.HASH_COMMENT_MODE,t.COMMENT(/^=\w/,/=cut/,{endsWithParent:!0}),o,{className:"string",contains:h,variants:[{begin:"q[qwxr]?\\s*\\(",end:"\\)",relevance:5},{begin:"q[qwxr]?\\s*\\[",end:"\\]",relevance:5},{begin:"q[qwxr]?\\s*\\{",end:"\\}",relevance:5},{begin:"q[qwxr]?\\s*\\|",end:"\\|",relevance:5},{begin:"q[qwxr]?\\s*<",end:">",relevance:5},{begin:"qw\\s+q",end:"q",relevance:5},{begin:"'",end:"'",contains:[t.BACKSLASH_ESCAPE]},{begin:'"',end:'"'},{begin:"`",end:"`",contains:[t.BACKSLASH_ESCAPE]},{begin:/\{\w+\}/,relevance:0},{begin:"-?\\w+\\s*=>",relevance:0}]},f,{begin:"(\\/\\/|"+t.RE_STARTERS_RE+"|\\b(split|return|print|reverse|grep)\\b)\\s*",keywords:"split return print reverse grep",relevance:0,contains:[t.HASH_COMMENT_MODE,{className:"regexp",variants:[{begin:g("s|tr|y",e.either(...m,{capture:!0}))},{begin:g("s|tr|y","\\(","\\)")},{begin:g("s|tr|y","\\[","\\]")},{begin:g("s|tr|y","\\{","\\}")}],relevance:2},{className:"regexp",variants:[{begin:/(m|qr)\/\//,relevance:0},{begin:v("(?:m|qr)?",/\//,/\//)},{begin:v("m|qr",e.either(...m,{capture:!0}),/\1/)},{begin:v("m|qr",/\(/,/\)/)},{begin:v("m|qr",/\[/,/\]/)},{begin:v("m|qr",/\{/,/\}/)}]}]},{className:"function",beginKeywords:"sub method",end:"(\\s*\\(.*?\\))?[;{]",excludeEnd:!0,relevance:5,contains:[t.TITLE_MODE,l]},{className:"class",beginKeywords:"class",end:"[;{]",excludeEnd:!0,relevance:5,contains:[t.TITLE_MODE,l,f]},{begin:"-\\w\\b",relevance:0},{begin:"^__DATA__$",end:"^__END__$",subLanguage:"mojolicious",contains:[{begin:"^@@.*",end:"$",className:"comment"}]}];return i.contains=b,o.contains=b,{name:"Perl",aliases:["pl","pm"],keywords:s,contains:b}}function cB(t){const e=t.regex,n=/(?![A-Za-z0-9])(?![$])/,r=e.concat(/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/,n),s=e.concat(/(\\?[A-Z][a-z0-9_\x7f-\xff]+|\\?[A-Z]+(?=[A-Z][a-z0-9_\x7f-\xff])){1,}/,n),i=e.concat(/[A-Z]+/,n),o={scope:"variable",match:"\\$+"+r},l={scope:"meta",variants:[{begin:/<\?php/,relevance:10},{begin:/<\?=/},{begin:/<\?/,relevance:.1},{begin:/\?>/}]},d={scope:"subst",variants:[{begin:/\$\w+/},{begin:/\{\$/,end:/\}/}]},f=t.inherit(t.APOS_STRING_MODE,{illegal:null}),h=t.inherit(t.QUOTE_STRING_MODE,{illegal:null,contains:t.QUOTE_STRING_MODE.contains.concat(d)}),m={begin:/<<<[ \t]*(?:(\w+)|"(\w+)")\n/,end:/[ \t]*(\w+)\b/,contains:t.QUOTE_STRING_MODE.contains.concat(d),"on:begin":(D,U)=>{U.data._beginMatch=D[1]||D[2]},"on:end":(D,U)=>{U.data._beginMatch!==D[1]&&U.ignoreMatch()}},g=t.END_SAME_AS_BEGIN({begin:/<<<[ \t]*'(\w+)'\n/,end:/[ \t]*(\w+)\b/}),v=`[
203
- ]`,b={scope:"string",variants:[h,f,m,g]},k={scope:"number",variants:[{begin:"\\b0[bB][01]+(?:_[01]+)*\\b"},{begin:"\\b0[oO][0-7]+(?:_[0-7]+)*\\b"},{begin:"\\b0[xX][\\da-fA-F]+(?:_[\\da-fA-F]+)*\\b"},{begin:"(?:\\b\\d+(?:_\\d+)*(\\.(?:\\d+(?:_\\d+)*))?|\\B\\.\\d+)(?:[eE][+-]?\\d+)?"}],relevance:0},w=["false","null","true"],E=["__CLASS__","__DIR__","__FILE__","__FUNCTION__","__COMPILER_HALT_OFFSET__","__LINE__","__METHOD__","__NAMESPACE__","__TRAIT__","die","echo","exit","include","include_once","print","require","require_once","array","abstract","and","as","binary","bool","boolean","break","callable","case","catch","class","clone","const","continue","declare","default","do","double","else","elseif","empty","enddeclare","endfor","endforeach","endif","endswitch","endwhile","enum","eval","extends","final","finally","float","for","foreach","from","global","goto","if","implements","instanceof","insteadof","int","integer","interface","isset","iterable","list","match|0","mixed","new","never","object","or","private","protected","public","readonly","real","return","string","switch","throw","trait","try","unset","use","var","void","while","xor","yield"],C=["Error|0","AppendIterator","ArgumentCountError","ArithmeticError","ArrayIterator","ArrayObject","AssertionError","BadFunctionCallException","BadMethodCallException","CachingIterator","CallbackFilterIterator","CompileError","Countable","DirectoryIterator","DivisionByZeroError","DomainException","EmptyIterator","ErrorException","Exception","FilesystemIterator","FilterIterator","GlobIterator","InfiniteIterator","InvalidArgumentException","IteratorIterator","LengthException","LimitIterator","LogicException","MultipleIterator","NoRewindIterator","OutOfBoundsException","OutOfRangeException","OuterIterator","OverflowException","ParentIterator","ParseError","RangeException","RecursiveArrayIterator","RecursiveCachingIterator","RecursiveCallbackFilterIterator","RecursiveDirectoryIterator","RecursiveFilterIterator","RecursiveIterator","RecursiveIteratorIterator","RecursiveRegexIterator","RecursiveTreeIterator","RegexIterator","RuntimeException","SeekableIterator","SplDoublyLinkedList","SplFileInfo","SplFileObject","SplFixedArray","SplHeap","SplMaxHeap","SplMinHeap","SplObjectStorage","SplObserver","SplPriorityQueue","SplQueue","SplStack","SplSubject","SplTempFileObject","TypeError","UnderflowException","UnexpectedValueException","UnhandledMatchError","ArrayAccess","BackedEnum","Closure","Fiber","Generator","Iterator","IteratorAggregate","Serializable","Stringable","Throwable","Traversable","UnitEnum","WeakReference","WeakMap","Directory","__PHP_Incomplete_Class","parent","php_user_filter","self","static","stdClass"],j={keyword:E,literal:(D=>{const U=[];return D.forEach(q=>{U.push(q),q.toLowerCase()===q?U.push(q.toUpperCase()):U.push(q.toLowerCase())}),U})(w),built_in:C},_=D=>D.map(U=>U.replace(/\|\d+$/,"")),A={variants:[{match:[/new/,e.concat(v,"+"),e.concat("(?!",_(C).join("\\b|"),"\\b)"),s],scope:{1:"keyword",4:"title.class"}}]},O=e.concat(r,"\\b(?!\\()"),B={variants:[{match:[e.concat(/::/,e.lookahead(/(?!class\b)/)),O],scope:{2:"variable.constant"}},{match:[/::/,/class/],scope:{2:"variable.language"}},{match:[s,e.concat(/::/,e.lookahead(/(?!class\b)/)),O],scope:{1:"title.class",3:"variable.constant"}},{match:[s,e.concat("::",e.lookahead(/(?!class\b)/))],scope:{1:"title.class"}},{match:[s,/::/,/class/],scope:{1:"title.class",3:"variable.language"}}]},$={scope:"attr",match:e.concat(r,e.lookahead(":"),e.lookahead(/(?!::)/))},W={relevance:0,begin:/\(/,end:/\)/,keywords:j,contains:[$,o,B,t.C_BLOCK_COMMENT_MODE,b,k,A]},J={relevance:0,match:[/\b/,e.concat("(?!fn\\b|function\\b|",_(E).join("\\b|"),"|",_(C).join("\\b|"),"\\b)"),r,e.concat(v,"*"),e.lookahead(/(?=\()/)],scope:{3:"title.function.invoke"},contains:[W]};W.contains.push(J);const z=[$,B,t.C_BLOCK_COMMENT_MODE,b,k,A],G={begin:e.concat(/#\[\s*\\?/,e.either(s,i)),beginScope:"meta",end:/]/,endScope:"meta",keywords:{literal:w,keyword:["new","array"]},contains:[{begin:/\[/,end:/]/,keywords:{literal:w,keyword:["new","array"]},contains:["self",...z]},...z,{scope:"meta",variants:[{match:s},{match:i}]}]};return{case_insensitive:!1,keywords:j,contains:[G,t.HASH_COMMENT_MODE,t.COMMENT("//","$"),t.COMMENT("/\\*","\\*/",{contains:[{scope:"doctag",match:"@[A-Za-z]+"}]}),{match:/__halt_compiler\(\);/,keywords:"__halt_compiler",starts:{scope:"comment",end:t.MATCH_NOTHING_RE,contains:[{match:/\?>/,scope:"meta",endsParent:!0}]}},l,{scope:"variable.language",match:/\$this\b/},o,J,B,{match:[/const/,/\s/,r],scope:{1:"keyword",3:"variable.constant"}},A,{scope:"function",relevance:0,beginKeywords:"fn function",end:/[;{]/,excludeEnd:!0,illegal:"[$%\\[]",contains:[{beginKeywords:"use"},t.UNDERSCORE_TITLE_MODE,{begin:"=>",endsParent:!0},{scope:"params",begin:"\\(",end:"\\)",excludeBegin:!0,excludeEnd:!0,keywords:j,contains:["self",G,o,B,t.C_BLOCK_COMMENT_MODE,b,k]}]},{scope:"class",variants:[{beginKeywords:"enum",illegal:/[($"]/},{beginKeywords:"class interface trait",illegal:/[:($"]/}],relevance:0,end:/\{/,excludeEnd:!0,contains:[{beginKeywords:"extends implements"},t.UNDERSCORE_TITLE_MODE]},{beginKeywords:"namespace",relevance:0,end:";",illegal:/[.']/,contains:[t.inherit(t.UNDERSCORE_TITLE_MODE,{scope:"title.class"})]},{beginKeywords:"use",relevance:0,end:";",contains:[{match:/\b(as|const|function)\b/,scope:"keyword"},t.UNDERSCORE_TITLE_MODE]},b,k]}}function uB(t){return{name:"PHP template",subLanguage:"xml",contains:[{begin:/<\?(php|=)?/,end:/\?>/,subLanguage:"php",contains:[{begin:"/\\*",end:"\\*/",skip:!0},{begin:'b"',end:'"',skip:!0},{begin:"b'",end:"'",skip:!0},t.inherit(t.APOS_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0}),t.inherit(t.QUOTE_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0})]}]}}function dB(t){return{name:"Plain text",aliases:["text","txt"],disableAutodetect:!0}}function fB(t){const e=t.regex,n=new RegExp("[\\p{XID_Start}_]\\p{XID_Continue}*","u"),r=["and","as","assert","async","await","break","case","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","match","nonlocal|10","not","or","pass","raise","return","try","while","with","yield"],l={$pattern:/[A-Za-z]\w+|__\w+__/,keyword:r,built_in:["__import__","abs","all","any","ascii","bin","bool","breakpoint","bytearray","bytes","callable","chr","classmethod","compile","complex","delattr","dict","dir","divmod","enumerate","eval","exec","filter","float","format","frozenset","getattr","globals","hasattr","hash","help","hex","id","input","int","isinstance","issubclass","iter","len","list","locals","map","max","memoryview","min","next","object","oct","open","ord","pow","print","property","range","repr","reversed","round","set","setattr","slice","sorted","staticmethod","str","sum","super","tuple","type","vars","zip"],literal:["__debug__","Ellipsis","False","None","NotImplemented","True"],type:["Any","Callable","Coroutine","Dict","List","Literal","Generic","Optional","Sequence","Set","Tuple","Type","Union"]},d={className:"meta",begin:/^(>>>|\.\.\.) /},f={className:"subst",begin:/\{/,end:/\}/,keywords:l,illegal:/#/},h={begin:/\{\{/,relevance:0},m={className:"string",contains:[t.BACKSLASH_ESCAPE],variants:[{begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?'''/,end:/'''/,contains:[t.BACKSLASH_ESCAPE,d],relevance:10},{begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?"""/,end:/"""/,contains:[t.BACKSLASH_ESCAPE,d],relevance:10},{begin:/([fF][rR]|[rR][fF]|[fF])'''/,end:/'''/,contains:[t.BACKSLASH_ESCAPE,d,h,f]},{begin:/([fF][rR]|[rR][fF]|[fF])"""/,end:/"""/,contains:[t.BACKSLASH_ESCAPE,d,h,f]},{begin:/([uU]|[rR])'/,end:/'/,relevance:10},{begin:/([uU]|[rR])"/,end:/"/,relevance:10},{begin:/([bB]|[bB][rR]|[rR][bB])'/,end:/'/},{begin:/([bB]|[bB][rR]|[rR][bB])"/,end:/"/},{begin:/([fF][rR]|[rR][fF]|[fF])'/,end:/'/,contains:[t.BACKSLASH_ESCAPE,h,f]},{begin:/([fF][rR]|[rR][fF]|[fF])"/,end:/"/,contains:[t.BACKSLASH_ESCAPE,h,f]},t.APOS_STRING_MODE,t.QUOTE_STRING_MODE]},g="[0-9](_?[0-9])*",v=`(\\b(${g}))?\\.(${g})|\\b(${g})\\.`,b=`\\b|${r.join("|")}`,k={className:"number",relevance:0,variants:[{begin:`(\\b(${g})|(${v}))[eE][+-]?(${g})[jJ]?(?=${b})`},{begin:`(${v})[jJ]?`},{begin:`\\b([1-9](_?[0-9])*|0+(_?0)*)[lLjJ]?(?=${b})`},{begin:`\\b0[bB](_?[01])+[lL]?(?=${b})`},{begin:`\\b0[oO](_?[0-7])+[lL]?(?=${b})`},{begin:`\\b0[xX](_?[0-9a-fA-F])+[lL]?(?=${b})`},{begin:`\\b(${g})[jJ](?=${b})`}]},w={className:"comment",begin:e.lookahead(/# type:/),end:/$/,keywords:l,contains:[{begin:/# type:/},{begin:/#/,end:/\b\B/,endsWithParent:!0}]},E={className:"params",variants:[{className:"",begin:/\(\s*\)/,skip:!0},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:l,contains:["self",d,k,m,t.HASH_COMMENT_MODE]}]};return f.contains=[m,k,d],{name:"Python",aliases:["py","gyp","ipython"],unicodeRegex:!0,keywords:l,illegal:/(<\/|\?)|=>/,contains:[d,k,{scope:"variable.language",match:/\bself\b/},{beginKeywords:"if",relevance:0},{match:/\bor\b/,scope:"keyword"},m,w,t.HASH_COMMENT_MODE,{match:[/\bdef/,/\s+/,n],scope:{1:"keyword",3:"title.function"},contains:[E]},{variants:[{match:[/\bclass/,/\s+/,n,/\s*/,/\(\s*/,n,/\s*\)/]},{match:[/\bclass/,/\s+/,n]}],scope:{1:"keyword",3:"title.class",6:"title.class.inherited"}},{className:"meta",begin:/^[\t ]*@/,end:/(?=#)|$/,contains:[k,E,m]}]}}function hB(t){return{aliases:["pycon"],contains:[{className:"meta.prompt",starts:{end:/ |$/,starts:{end:"$",subLanguage:"python"}},variants:[{begin:/^>>>(?=[ ]|$)/},{begin:/^\.\.\.(?=[ ]|$)/}]}]}}function pB(t){const e=t.regex,n=/(?:(?:[a-zA-Z]|\.[._a-zA-Z])[._a-zA-Z0-9]*)|\.(?!\d)/,r=e.either(/0[xX][0-9a-fA-F]+\.[0-9a-fA-F]*[pP][+-]?\d+i?/,/0[xX][0-9a-fA-F]+(?:[pP][+-]?\d+)?[Li]?/,/(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?[Li]?/),s=/[=!<>:]=|\|\||&&|:::?|<-|<<-|->>|->|\|>|[-+*\/?!$&|:<=>@^~]|\*\*/,i=e.either(/[()]/,/[{}]/,/\[\[/,/[[\]]/,/\\/,/,/);return{name:"R",keywords:{$pattern:n,keyword:"function if in break next repeat else for while",literal:"NULL NA TRUE FALSE Inf NaN NA_integer_|10 NA_real_|10 NA_character_|10 NA_complex_|10",built_in:"LETTERS letters month.abb month.name pi T F abs acos acosh all any anyNA Arg as.call as.character as.complex as.double as.environment as.integer as.logical as.null.default as.numeric as.raw asin asinh atan atanh attr attributes baseenv browser c call ceiling class Conj cos cosh cospi cummax cummin cumprod cumsum digamma dim dimnames emptyenv exp expression floor forceAndCall gamma gc.time globalenv Im interactive invisible is.array is.atomic is.call is.character is.complex is.double is.environment is.expression is.finite is.function is.infinite is.integer is.language is.list is.logical is.matrix is.na is.name is.nan is.null is.numeric is.object is.pairlist is.raw is.recursive is.single is.symbol lazyLoadDBfetch length lgamma list log max min missing Mod names nargs nzchar oldClass on.exit pos.to.env proc.time prod quote range Re rep retracemem return round seq_along seq_len seq.int sign signif sin sinh sinpi sqrt standardGeneric substitute sum switch tan tanh tanpi tracemem trigamma trunc unclass untracemem UseMethod xtfrm"},contains:[t.COMMENT(/#'/,/$/,{contains:[{scope:"doctag",match:/@examples/,starts:{end:e.lookahead(e.either(/\n^#'\s*(?=@[a-zA-Z]+)/,/\n^(?!#')/)),endsParent:!0}},{scope:"doctag",begin:"@param",end:/$/,contains:[{scope:"variable",variants:[{match:n},{match:/`(?:\\.|[^`\\])+`/}],endsParent:!0}]},{scope:"doctag",match:/@[a-zA-Z]+/},{scope:"keyword",match:/\\[a-zA-Z]+/}]}),t.HASH_COMMENT_MODE,{scope:"string",contains:[t.BACKSLASH_ESCAPE],variants:[t.END_SAME_AS_BEGIN({begin:/[rR]"(-*)\(/,end:/\)(-*)"/}),t.END_SAME_AS_BEGIN({begin:/[rR]"(-*)\{/,end:/\}(-*)"/}),t.END_SAME_AS_BEGIN({begin:/[rR]"(-*)\[/,end:/\](-*)"/}),t.END_SAME_AS_BEGIN({begin:/[rR]'(-*)\(/,end:/\)(-*)'/}),t.END_SAME_AS_BEGIN({begin:/[rR]'(-*)\{/,end:/\}(-*)'/}),t.END_SAME_AS_BEGIN({begin:/[rR]'(-*)\[/,end:/\](-*)'/}),{begin:'"',end:'"',relevance:0},{begin:"'",end:"'",relevance:0}]},{relevance:0,variants:[{scope:{1:"operator",2:"number"},match:[s,r]},{scope:{1:"operator",2:"number"},match:[/%[^%]*%/,r]},{scope:{1:"punctuation",2:"number"},match:[i,r]},{scope:{2:"number"},match:[/[^a-zA-Z0-9._]|^/,r]}]},{scope:{3:"operator"},match:[n,/\s+/,/<-/,/\s+/]},{scope:"operator",relevance:0,variants:[{match:s},{match:/%[^%]*%/}]},{scope:"punctuation",relevance:0,match:i},{begin:"`",end:"`",contains:[{begin:/\\./}]}]}}function mB(t){const e=t.regex,n="([a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?)",r=e.either(/\b([A-Z]+[a-z0-9]+)+/,/\b([A-Z]+[a-z0-9]+)+[A-Z]+/),s=e.concat(r,/(::\w+)*/),o={"variable.constant":["__FILE__","__LINE__","__ENCODING__"],"variable.language":["self","super"],keyword:["alias","and","begin","BEGIN","break","case","class","defined","do","else","elsif","end","END","ensure","for","if","in","module","next","not","or","redo","require","rescue","retry","return","then","undef","unless","until","when","while","yield",...["include","extend","prepend","public","private","protected","raise","throw"]],built_in:["proc","lambda","attr_accessor","attr_reader","attr_writer","define_method","private_constant","module_function"],literal:["true","false","nil"]},l={className:"doctag",begin:"@[A-Za-z]+"},d={begin:"#<",end:">"},f=[t.COMMENT("#","$",{contains:[l]}),t.COMMENT("^=begin","^=end",{contains:[l],relevance:10}),t.COMMENT("^__END__",t.MATCH_NOTHING_RE)],h={className:"subst",begin:/#\{/,end:/\}/,keywords:o},m={className:"string",contains:[t.BACKSLASH_ESCAPE,h],variants:[{begin:/'/,end:/'/},{begin:/"/,end:/"/},{begin:/`/,end:/`/},{begin:/%[qQwWx]?\(/,end:/\)/},{begin:/%[qQwWx]?\[/,end:/\]/},{begin:/%[qQwWx]?\{/,end:/\}/},{begin:/%[qQwWx]?</,end:/>/},{begin:/%[qQwWx]?\//,end:/\//},{begin:/%[qQwWx]?%/,end:/%/},{begin:/%[qQwWx]?-/,end:/-/},{begin:/%[qQwWx]?\|/,end:/\|/},{begin:/\B\?(\\\d{1,3})/},{begin:/\B\?(\\x[A-Fa-f0-9]{1,2})/},{begin:/\B\?(\\u\{?[A-Fa-f0-9]{1,6}\}?)/},{begin:/\B\?(\\M-\\C-|\\M-\\c|\\c\\M-|\\M-|\\C-\\M-)[\x20-\x7e]/},{begin:/\B\?\\(c|C-)[\x20-\x7e]/},{begin:/\B\?\\?\S/},{begin:e.concat(/<<[-~]?'?/,e.lookahead(/(\w+)(?=\W)[^\n]*\n(?:[^\n]*\n)*?\s*\1\b/)),contains:[t.END_SAME_AS_BEGIN({begin:/(\w+)/,end:/(\w+)/,contains:[t.BACKSLASH_ESCAPE,h]})]}]},g="[1-9](_?[0-9])*|0",v="[0-9](_?[0-9])*",b={className:"number",relevance:0,variants:[{begin:`\\b(${g})(\\.(${v}))?([eE][+-]?(${v})|r)?i?\\b`},{begin:"\\b0[dD][0-9](_?[0-9])*r?i?\\b"},{begin:"\\b0[bB][0-1](_?[0-1])*r?i?\\b"},{begin:"\\b0[oO][0-7](_?[0-7])*r?i?\\b"},{begin:"\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*r?i?\\b"},{begin:"\\b0(_?[0-7])+r?i?\\b"}]},k={variants:[{match:/\(\)/},{className:"params",begin:/\(/,end:/(?=\))/,excludeBegin:!0,endsParent:!0,keywords:o}]},A=[m,{variants:[{match:[/class\s+/,s,/\s+<\s+/,s]},{match:[/\b(class|module)\s+/,s]}],scope:{2:"title.class",4:"title.class.inherited"},keywords:o},{match:[/(include|extend)\s+/,s],scope:{2:"title.class"},keywords:o},{relevance:0,match:[s,/\.new[. (]/],scope:{1:"title.class"}},{relevance:0,match:/\b[A-Z][A-Z_0-9]+\b/,className:"variable.constant"},{relevance:0,match:r,scope:"title.class"},{match:[/def/,/\s+/,n],scope:{1:"keyword",3:"title.function"},contains:[k]},{begin:t.IDENT_RE+"::"},{className:"symbol",begin:t.UNDERSCORE_IDENT_RE+"(!|\\?)?:",relevance:0},{className:"symbol",begin:":(?!\\s)",contains:[m,{begin:n}],relevance:0},b,{className:"variable",begin:"(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])(?![A-Za-z])(?![@$?'])"},{className:"params",begin:/\|(?!=)/,end:/\|/,excludeBegin:!0,excludeEnd:!0,relevance:0,keywords:o},{begin:"("+t.RE_STARTERS_RE+"|unless)\\s*",keywords:"unless",contains:[{className:"regexp",contains:[t.BACKSLASH_ESCAPE,h],illegal:/\n/,variants:[{begin:"/",end:"/[a-z]*"},{begin:/%r\{/,end:/\}[a-z]*/},{begin:"%r\\(",end:"\\)[a-z]*"},{begin:"%r!",end:"![a-z]*"},{begin:"%r\\[",end:"\\][a-z]*"}]}].concat(d,f),relevance:0}].concat(d,f);h.contains=A,k.contains=A;const W=[{begin:/^\s*=>/,starts:{end:"$",contains:A}},{className:"meta.prompt",begin:"^("+"[>?]>"+"|"+"[\\w#]+\\(\\w+\\):\\d+:\\d+[>*]"+"|"+"(\\w+-)?\\d+\\.\\d+\\.\\d+(p\\d+)?[^\\d][^>]+>"+")(?=[ ])",starts:{end:"$",keywords:o,contains:A}}];return f.unshift(d),{name:"Ruby",aliases:["rb","gemspec","podspec","thor","irb"],keywords:o,illegal:/\/\*/,contains:[t.SHEBANG({binary:"ruby"})].concat(W).concat(f).concat(A)}}function gB(t){const e=t.regex,n=/(r#)?/,r=e.concat(n,t.UNDERSCORE_IDENT_RE),s=e.concat(n,t.IDENT_RE),i={className:"title.function.invoke",relevance:0,begin:e.concat(/\b/,/(?!let|for|while|if|else|match\b)/,s,e.lookahead(/\s*\(/))},o="([ui](8|16|32|64|128|size)|f(32|64))?",l=["abstract","as","async","await","become","box","break","const","continue","crate","do","dyn","else","enum","extern","false","final","fn","for","if","impl","in","let","loop","macro","match","mod","move","mut","override","priv","pub","ref","return","self","Self","static","struct","super","trait","true","try","type","typeof","union","unsafe","unsized","use","virtual","where","while","yield"],d=["true","false","Some","None","Ok","Err"],f=["drop ","Copy","Send","Sized","Sync","Drop","Fn","FnMut","FnOnce","ToOwned","Clone","Debug","PartialEq","PartialOrd","Eq","Ord","AsRef","AsMut","Into","From","Default","Iterator","Extend","IntoIterator","DoubleEndedIterator","ExactSizeIterator","SliceConcatExt","ToString","assert!","assert_eq!","bitflags!","bytes!","cfg!","col!","concat!","concat_idents!","debug_assert!","debug_assert_eq!","env!","eprintln!","panic!","file!","format!","format_args!","include_bytes!","include_str!","line!","local_data_key!","module_path!","option_env!","print!","println!","select!","stringify!","try!","unimplemented!","unreachable!","vec!","write!","writeln!","macro_rules!","assert_ne!","debug_assert_ne!"],h=["i8","i16","i32","i64","i128","isize","u8","u16","u32","u64","u128","usize","f32","f64","str","char","bool","Box","Option","Result","String","Vec"];return{name:"Rust",aliases:["rs"],keywords:{$pattern:t.IDENT_RE+"!?",type:h,keyword:l,literal:d,built_in:f},illegal:"</",contains:[t.C_LINE_COMMENT_MODE,t.COMMENT("/\\*","\\*/",{contains:["self"]}),t.inherit(t.QUOTE_STRING_MODE,{begin:/b?"/,illegal:null}),{className:"symbol",begin:/'[a-zA-Z_][a-zA-Z0-9_]*(?!')/},{scope:"string",variants:[{begin:/b?r(#*)"(.|\n)*?"\1(?!#)/},{begin:/b?'/,end:/'/,contains:[{scope:"char.escape",match:/\\('|\w|x\w{2}|u\w{4}|U\w{8})/}]}]},{className:"number",variants:[{begin:"\\b0b([01_]+)"+o},{begin:"\\b0o([0-7_]+)"+o},{begin:"\\b0x([A-Fa-f0-9_]+)"+o},{begin:"\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)"+o}],relevance:0},{begin:[/fn/,/\s+/,r],className:{1:"keyword",3:"title.function"}},{className:"meta",begin:"#!?\\[",end:"\\]",contains:[{className:"string",begin:/"/,end:/"/,contains:[t.BACKSLASH_ESCAPE]}]},{begin:[/let/,/\s+/,/(?:mut\s+)?/,r],className:{1:"keyword",3:"keyword",4:"variable"}},{begin:[/for/,/\s+/,r,/\s+/,/in/],className:{1:"keyword",3:"variable",5:"keyword"}},{begin:[/type/,/\s+/,r],className:{1:"keyword",3:"title.class"}},{begin:[/(?:trait|enum|struct|union|impl|for)/,/\s+/,r],className:{1:"keyword",3:"title.class"}},{begin:t.IDENT_RE+"::",keywords:{keyword:"Self",built_in:f,type:h}},{className:"punctuation",begin:"->"},i]}}const vB=t=>({IMPORTANT:{scope:"meta",begin:"!important"},BLOCK_COMMENT:t.C_BLOCK_COMMENT_MODE,HEXCOLOR:{scope:"number",begin:/#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/},FUNCTION_DISPATCH:{className:"built_in",begin:/[\w-]+(?=\()/},ATTRIBUTE_SELECTOR_MODE:{scope:"selector-attr",begin:/\[/,end:/\]/,illegal:"$",contains:[t.APOS_STRING_MODE,t.QUOTE_STRING_MODE]},CSS_NUMBER_MODE:{scope:"number",begin:t.NUMBER_RE+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",relevance:0},CSS_VARIABLE:{className:"attr",begin:/--[A-Za-z_][A-Za-z0-9_-]*/}}),yB=["a","abbr","address","article","aside","audio","b","blockquote","body","button","canvas","caption","cite","code","dd","del","details","dfn","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","html","i","iframe","img","input","ins","kbd","label","legend","li","main","mark","menu","nav","object","ol","optgroup","option","p","picture","q","quote","samp","section","select","source","span","strong","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","tr","ul","var","video"],bB=["defs","g","marker","mask","pattern","svg","switch","symbol","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feFlood","feGaussianBlur","feImage","feMerge","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence","linearGradient","radialGradient","stop","circle","ellipse","image","line","path","polygon","polyline","rect","text","use","textPath","tspan","foreignObject","clipPath"],xB=[...yB,...bB],wB=["any-hover","any-pointer","aspect-ratio","color","color-gamut","color-index","device-aspect-ratio","device-height","device-width","display-mode","forced-colors","grid","height","hover","inverted-colors","monochrome","orientation","overflow-block","overflow-inline","pointer","prefers-color-scheme","prefers-contrast","prefers-reduced-motion","prefers-reduced-transparency","resolution","scan","scripting","update","width","min-width","max-width","min-height","max-height"].sort().reverse(),kB=["active","any-link","blank","checked","current","default","defined","dir","disabled","drop","empty","enabled","first","first-child","first-of-type","fullscreen","future","focus","focus-visible","focus-within","has","host","host-context","hover","indeterminate","in-range","invalid","is","lang","last-child","last-of-type","left","link","local-link","not","nth-child","nth-col","nth-last-child","nth-last-col","nth-last-of-type","nth-of-type","only-child","only-of-type","optional","out-of-range","past","placeholder-shown","read-only","read-write","required","right","root","scope","target","target-within","user-invalid","valid","visited","where"].sort().reverse(),SB=["after","backdrop","before","cue","cue-region","first-letter","first-line","grammar-error","marker","part","placeholder","selection","slotted","spelling-error"].sort().reverse(),EB=["accent-color","align-content","align-items","align-self","alignment-baseline","all","anchor-name","animation","animation-composition","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-range","animation-range-end","animation-range-start","animation-timeline","animation-timing-function","appearance","aspect-ratio","backdrop-filter","backface-visibility","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-origin","background-position","background-position-x","background-position-y","background-repeat","background-size","baseline-shift","block-size","border","border-block","border-block-color","border-block-end","border-block-end-color","border-block-end-style","border-block-end-width","border-block-start","border-block-start-color","border-block-start-style","border-block-start-width","border-block-style","border-block-width","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-end-end-radius","border-end-start-radius","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-inline","border-inline-color","border-inline-end","border-inline-end-color","border-inline-end-style","border-inline-end-width","border-inline-start","border-inline-start-color","border-inline-start-style","border-inline-start-width","border-inline-style","border-inline-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-start-end-radius","border-start-start-radius","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-align","box-decoration-break","box-direction","box-flex","box-flex-group","box-lines","box-ordinal-group","box-orient","box-pack","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","caret-color","clear","clip","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","color-scheme","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","contain-intrinsic-block-size","contain-intrinsic-height","contain-intrinsic-inline-size","contain-intrinsic-size","contain-intrinsic-width","container","container-name","container-type","content","content-visibility","counter-increment","counter-reset","counter-set","cue","cue-after","cue-before","cursor","cx","cy","direction","display","dominant-baseline","empty-cells","enable-background","field-sizing","fill","fill-opacity","fill-rule","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","flood-color","flood-opacity","flow","font","font-display","font-family","font-feature-settings","font-kerning","font-language-override","font-optical-sizing","font-palette","font-size","font-size-adjust","font-smooth","font-smoothing","font-stretch","font-style","font-synthesis","font-synthesis-position","font-synthesis-small-caps","font-synthesis-style","font-synthesis-weight","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-emoji","font-variant-ligatures","font-variant-numeric","font-variant-position","font-variation-settings","font-weight","forced-color-adjust","gap","glyph-orientation-horizontal","glyph-orientation-vertical","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-gap","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphenate-character","hyphenate-limit-chars","hyphens","icon","image-orientation","image-rendering","image-resolution","ime-mode","initial-letter","initial-letter-align","inline-size","inset","inset-area","inset-block","inset-block-end","inset-block-start","inset-inline","inset-inline-end","inset-inline-start","isolation","justify-content","justify-items","justify-self","kerning","left","letter-spacing","lighting-color","line-break","line-height","line-height-step","list-style","list-style-image","list-style-position","list-style-type","margin","margin-block","margin-block-end","margin-block-start","margin-bottom","margin-inline","margin-inline-end","margin-inline-start","margin-left","margin-right","margin-top","margin-trim","marker","marker-end","marker-mid","marker-start","marks","mask","mask-border","mask-border-mode","mask-border-outset","mask-border-repeat","mask-border-slice","mask-border-source","mask-border-width","mask-clip","mask-composite","mask-image","mask-mode","mask-origin","mask-position","mask-repeat","mask-size","mask-type","masonry-auto-flow","math-depth","math-shift","math-style","max-block-size","max-height","max-inline-size","max-width","min-block-size","min-height","min-inline-size","min-width","mix-blend-mode","nav-down","nav-index","nav-left","nav-right","nav-up","none","normal","object-fit","object-position","offset","offset-anchor","offset-distance","offset-path","offset-position","offset-rotate","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-anchor","overflow-block","overflow-clip-margin","overflow-inline","overflow-wrap","overflow-x","overflow-y","overlay","overscroll-behavior","overscroll-behavior-block","overscroll-behavior-inline","overscroll-behavior-x","overscroll-behavior-y","padding","padding-block","padding-block-end","padding-block-start","padding-bottom","padding-inline","padding-inline-end","padding-inline-start","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","paint-order","pause","pause-after","pause-before","perspective","perspective-origin","place-content","place-items","place-self","pointer-events","position","position-anchor","position-visibility","print-color-adjust","quotes","r","resize","rest","rest-after","rest-before","right","rotate","row-gap","ruby-align","ruby-position","scale","scroll-behavior","scroll-margin","scroll-margin-block","scroll-margin-block-end","scroll-margin-block-start","scroll-margin-bottom","scroll-margin-inline","scroll-margin-inline-end","scroll-margin-inline-start","scroll-margin-left","scroll-margin-right","scroll-margin-top","scroll-padding","scroll-padding-block","scroll-padding-block-end","scroll-padding-block-start","scroll-padding-bottom","scroll-padding-inline","scroll-padding-inline-end","scroll-padding-inline-start","scroll-padding-left","scroll-padding-right","scroll-padding-top","scroll-snap-align","scroll-snap-stop","scroll-snap-type","scroll-timeline","scroll-timeline-axis","scroll-timeline-name","scrollbar-color","scrollbar-gutter","scrollbar-width","shape-image-threshold","shape-margin","shape-outside","shape-rendering","speak","speak-as","src","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","tab-size","table-layout","text-align","text-align-all","text-align-last","text-anchor","text-combine-upright","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-indent","text-justify","text-orientation","text-overflow","text-rendering","text-shadow","text-size-adjust","text-transform","text-underline-offset","text-underline-position","text-wrap","text-wrap-mode","text-wrap-style","timeline-scope","top","touch-action","transform","transform-box","transform-origin","transform-style","transition","transition-behavior","transition-delay","transition-duration","transition-property","transition-timing-function","translate","unicode-bidi","user-modify","user-select","vector-effect","vertical-align","view-timeline","view-timeline-axis","view-timeline-inset","view-timeline-name","view-transition-name","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","white-space","white-space-collapse","widows","width","will-change","word-break","word-spacing","word-wrap","writing-mode","x","y","z-index","zoom"].sort().reverse();function NB(t){const e=vB(t),n=SB,r=kB,s="@[a-z-]+",i="and or not only",l={className:"variable",begin:"(\\$"+"[a-zA-Z-][a-zA-Z0-9_-]*"+")\\b",relevance:0};return{name:"SCSS",case_insensitive:!0,illegal:"[=/|']",contains:[t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,e.CSS_NUMBER_MODE,{className:"selector-id",begin:"#[A-Za-z0-9_-]+",relevance:0},{className:"selector-class",begin:"\\.[A-Za-z0-9_-]+",relevance:0},e.ATTRIBUTE_SELECTOR_MODE,{className:"selector-tag",begin:"\\b("+xB.join("|")+")\\b",relevance:0},{className:"selector-pseudo",begin:":("+r.join("|")+")"},{className:"selector-pseudo",begin:":(:)?("+n.join("|")+")"},l,{begin:/\(/,end:/\)/,contains:[e.CSS_NUMBER_MODE]},e.CSS_VARIABLE,{className:"attribute",begin:"\\b("+EB.join("|")+")\\b"},{begin:"\\b(whitespace|wait|w-resize|visible|vertical-text|vertical-ideographic|uppercase|upper-roman|upper-alpha|underline|transparent|top|thin|thick|text|text-top|text-bottom|tb-rl|table-header-group|table-footer-group|sw-resize|super|strict|static|square|solid|small-caps|separate|se-resize|scroll|s-resize|rtl|row-resize|ridge|right|repeat|repeat-y|repeat-x|relative|progress|pointer|overline|outside|outset|oblique|nowrap|not-allowed|normal|none|nw-resize|no-repeat|no-drop|newspaper|ne-resize|n-resize|move|middle|medium|ltr|lr-tb|lowercase|lower-roman|lower-alpha|loose|list-item|line|line-through|line-edge|lighter|left|keep-all|justify|italic|inter-word|inter-ideograph|inside|inset|inline|inline-block|inherit|inactive|ideograph-space|ideograph-parenthesis|ideograph-numeric|ideograph-alpha|horizontal|hidden|help|hand|groove|fixed|ellipsis|e-resize|double|dotted|distribute|distribute-space|distribute-letter|distribute-all-lines|disc|disabled|default|decimal|dashed|crosshair|collapse|col-resize|circle|char|center|capitalize|break-word|break-all|bottom|both|bolder|bold|block|bidi-override|below|baseline|auto|always|all-scroll|absolute|table|table-cell)\\b"},{begin:/:/,end:/[;}{]/,relevance:0,contains:[e.BLOCK_COMMENT,l,e.HEXCOLOR,e.CSS_NUMBER_MODE,t.QUOTE_STRING_MODE,t.APOS_STRING_MODE,e.IMPORTANT,e.FUNCTION_DISPATCH]},{begin:"@(page|font-face)",keywords:{$pattern:s,keyword:"@page @font-face"}},{begin:"@",end:"[{;]",returnBegin:!0,keywords:{$pattern:/[a-z-]+/,keyword:i,attribute:wB.join(" ")},contains:[{begin:s,className:"keyword"},{begin:/[a-z-]+(?=:)/,className:"attribute"},l,t.QUOTE_STRING_MODE,t.APOS_STRING_MODE,e.HEXCOLOR,e.CSS_NUMBER_MODE]},e.FUNCTION_DISPATCH]}}function CB(t){return{name:"Shell Session",aliases:["console","shellsession"],contains:[{className:"meta.prompt",begin:/^\s{0,3}[/~\w\d[\]()@-]*[>%$#][ ]?/,starts:{end:/[^\\](?=\s*$)/,subLanguage:"bash"}}]}}function _B(t){const e=t.regex,n=t.COMMENT("--","$"),r={scope:"string",variants:[{begin:/'/,end:/'/,contains:[{match:/''/}]}]},s={begin:/"/,end:/"/,contains:[{match:/""/}]},i=["true","false","unknown"],o=["double precision","large object","with timezone","without timezone"],l=["bigint","binary","blob","boolean","char","character","clob","date","dec","decfloat","decimal","float","int","integer","interval","nchar","nclob","national","numeric","real","row","smallint","time","timestamp","varchar","varying","varbinary"],d=["add","asc","collation","desc","final","first","last","view"],f=["abs","acos","all","allocate","alter","and","any","are","array","array_agg","array_max_cardinality","as","asensitive","asin","asymmetric","at","atan","atomic","authorization","avg","begin","begin_frame","begin_partition","between","bigint","binary","blob","boolean","both","by","call","called","cardinality","cascaded","case","cast","ceil","ceiling","char","char_length","character","character_length","check","classifier","clob","close","coalesce","collate","collect","column","commit","condition","connect","constraint","contains","convert","copy","corr","corresponding","cos","cosh","count","covar_pop","covar_samp","create","cross","cube","cume_dist","current","current_catalog","current_date","current_default_transform_group","current_path","current_role","current_row","current_schema","current_time","current_timestamp","current_path","current_role","current_transform_group_for_type","current_user","cursor","cycle","date","day","deallocate","dec","decimal","decfloat","declare","default","define","delete","dense_rank","deref","describe","deterministic","disconnect","distinct","double","drop","dynamic","each","element","else","empty","end","end_frame","end_partition","end-exec","equals","escape","every","except","exec","execute","exists","exp","external","extract","false","fetch","filter","first_value","float","floor","for","foreign","frame_row","free","from","full","function","fusion","get","global","grant","group","grouping","groups","having","hold","hour","identity","in","indicator","initial","inner","inout","insensitive","insert","int","integer","intersect","intersection","interval","into","is","join","json_array","json_arrayagg","json_exists","json_object","json_objectagg","json_query","json_table","json_table_primitive","json_value","lag","language","large","last_value","lateral","lead","leading","left","like","like_regex","listagg","ln","local","localtime","localtimestamp","log","log10","lower","match","match_number","match_recognize","matches","max","member","merge","method","min","minute","mod","modifies","module","month","multiset","national","natural","nchar","nclob","new","no","none","normalize","not","nth_value","ntile","null","nullif","numeric","octet_length","occurrences_regex","of","offset","old","omit","on","one","only","open","or","order","out","outer","over","overlaps","overlay","parameter","partition","pattern","per","percent","percent_rank","percentile_cont","percentile_disc","period","portion","position","position_regex","power","precedes","precision","prepare","primary","procedure","ptf","range","rank","reads","real","recursive","ref","references","referencing","regr_avgx","regr_avgy","regr_count","regr_intercept","regr_r2","regr_slope","regr_sxx","regr_sxy","regr_syy","release","result","return","returns","revoke","right","rollback","rollup","row","row_number","rows","running","savepoint","scope","scroll","search","second","seek","select","sensitive","session_user","set","show","similar","sin","sinh","skip","smallint","some","specific","specifictype","sql","sqlexception","sqlstate","sqlwarning","sqrt","start","static","stddev_pop","stddev_samp","submultiset","subset","substring","substring_regex","succeeds","sum","symmetric","system","system_time","system_user","table","tablesample","tan","tanh","then","time","timestamp","timezone_hour","timezone_minute","to","trailing","translate","translate_regex","translation","treat","trigger","trim","trim_array","true","truncate","uescape","union","unique","unknown","unnest","update","upper","user","using","value","values","value_of","var_pop","var_samp","varbinary","varchar","varying","versioning","when","whenever","where","width_bucket","window","with","within","without","year"],h=["abs","acos","array_agg","asin","atan","avg","cast","ceil","ceiling","coalesce","corr","cos","cosh","count","covar_pop","covar_samp","cume_dist","dense_rank","deref","element","exp","extract","first_value","floor","json_array","json_arrayagg","json_exists","json_object","json_objectagg","json_query","json_table","json_table_primitive","json_value","lag","last_value","lead","listagg","ln","log","log10","lower","max","min","mod","nth_value","ntile","nullif","percent_rank","percentile_cont","percentile_disc","position","position_regex","power","rank","regr_avgx","regr_avgy","regr_count","regr_intercept","regr_r2","regr_slope","regr_sxx","regr_sxy","regr_syy","row_number","sin","sinh","sqrt","stddev_pop","stddev_samp","substring","substring_regex","sum","tan","tanh","translate","translate_regex","treat","trim","trim_array","unnest","upper","value_of","var_pop","var_samp","width_bucket"],m=["current_catalog","current_date","current_default_transform_group","current_path","current_role","current_schema","current_transform_group_for_type","current_user","session_user","system_time","system_user","current_time","localtime","current_timestamp","localtimestamp"],g=["create table","insert into","primary key","foreign key","not null","alter table","add constraint","grouping sets","on overflow","character set","respect nulls","ignore nulls","nulls first","nulls last","depth first","breadth first"],v=h,b=[...f,...d].filter(_=>!h.includes(_)),k={scope:"variable",match:/@[a-z0-9][a-z0-9_]*/},w={scope:"operator",match:/[-+*/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?/,relevance:0},E={match:e.concat(/\b/,e.either(...v),/\s*\(/),relevance:0,keywords:{built_in:v}};function C(_){return e.concat(/\b/,e.either(..._.map(A=>A.replace(/\s+/,"\\s+"))),/\b/)}const T={scope:"keyword",match:C(g),relevance:0};function j(_,{exceptions:A,when:O}={}){const B=O;return A=A||[],_.map($=>$.match(/\|\d+$/)||A.includes($)?$:B($)?`${$}|0`:$)}return{name:"SQL",case_insensitive:!0,illegal:/[{}]|<\//,keywords:{$pattern:/\b[\w\.]+/,keyword:j(b,{when:_=>_.length<3}),literal:i,type:l,built_in:m},contains:[{scope:"type",match:C(o)},T,E,k,r,s,t.C_NUMBER_MODE,t.C_BLOCK_COMMENT_MODE,n,w]}}function W_(t){return t?typeof t=="string"?t:t.source:null}function Ja(t){return Yt("(?=",t,")")}function Yt(...t){return t.map(n=>W_(n)).join("")}function TB(t){const e=t[t.length-1];return typeof e=="object"&&e.constructor===Object?(t.splice(t.length-1,1),e):{}}function or(...t){return"("+(TB(t).capture?"":"?:")+t.map(r=>W_(r)).join("|")+")"}const Jv=t=>Yt(/\b/,t,/\w$/.test(t)?/\b/:/\B/),jB=["Protocol","Type"].map(Jv),Qw=["init","self"].map(Jv),MB=["Any","Self"],Np=["actor","any","associatedtype","async","await",/as\?/,/as!/,"as","borrowing","break","case","catch","class","consume","consuming","continue","convenience","copy","default","defer","deinit","didSet","distributed","do","dynamic","each","else","enum","extension","fallthrough",/fileprivate\(set\)/,"fileprivate","final","for","func","get","guard","if","import","indirect","infix",/init\?/,/init!/,"inout",/internal\(set\)/,"internal","in","is","isolated","nonisolated","lazy","let","macro","mutating","nonmutating",/open\(set\)/,"open","operator","optional","override","package","postfix","precedencegroup","prefix",/private\(set\)/,"private","protocol",/public\(set\)/,"public","repeat","required","rethrows","return","set","some","static","struct","subscript","super","switch","throws","throw",/try\?/,/try!/,"try","typealias",/unowned\(safe\)/,/unowned\(unsafe\)/,"unowned","var","weak","where","while","willSet"],Zw=["false","nil","true"],AB=["assignment","associativity","higherThan","left","lowerThan","none","right"],RB=["#colorLiteral","#column","#dsohandle","#else","#elseif","#endif","#error","#file","#fileID","#fileLiteral","#filePath","#function","#if","#imageLiteral","#keyPath","#line","#selector","#sourceLocation","#warning"],ek=["abs","all","any","assert","assertionFailure","debugPrint","dump","fatalError","getVaList","isKnownUniquelyReferenced","max","min","numericCast","pointwiseMax","pointwiseMin","precondition","preconditionFailure","print","readLine","repeatElement","sequence","stride","swap","swift_unboxFromSwiftValueWithType","transcode","type","unsafeBitCast","unsafeDowncast","withExtendedLifetime","withUnsafeMutablePointer","withUnsafePointer","withVaList","withoutActuallyEscaping","zip"],q_=or(/[/=\-+!*%<>&|^~?]/,/[\u00A1-\u00A7]/,/[\u00A9\u00AB]/,/[\u00AC\u00AE]/,/[\u00B0\u00B1]/,/[\u00B6\u00BB\u00BF\u00D7\u00F7]/,/[\u2016-\u2017]/,/[\u2020-\u2027]/,/[\u2030-\u203E]/,/[\u2041-\u2053]/,/[\u2055-\u205E]/,/[\u2190-\u23FF]/,/[\u2500-\u2775]/,/[\u2794-\u2BFF]/,/[\u2E00-\u2E7F]/,/[\u3001-\u3003]/,/[\u3008-\u3020]/,/[\u3030]/),V_=or(q_,/[\u0300-\u036F]/,/[\u1DC0-\u1DFF]/,/[\u20D0-\u20FF]/,/[\uFE00-\uFE0F]/,/[\uFE20-\uFE2F]/),Cp=Yt(q_,V_,"*"),K_=or(/[a-zA-Z_]/,/[\u00A8\u00AA\u00AD\u00AF\u00B2-\u00B5\u00B7-\u00BA]/,/[\u00BC-\u00BE\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]/,/[\u0100-\u02FF\u0370-\u167F\u1681-\u180D\u180F-\u1DBF]/,/[\u1E00-\u1FFF]/,/[\u200B-\u200D\u202A-\u202E\u203F-\u2040\u2054\u2060-\u206F]/,/[\u2070-\u20CF\u2100-\u218F\u2460-\u24FF\u2776-\u2793]/,/[\u2C00-\u2DFF\u2E80-\u2FFF]/,/[\u3004-\u3007\u3021-\u302F\u3031-\u303F\u3040-\uD7FF]/,/[\uF900-\uFD3D\uFD40-\uFDCF\uFDF0-\uFE1F\uFE30-\uFE44]/,/[\uFE47-\uFEFE\uFF00-\uFFFD]/),Ed=or(K_,/\d/,/[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/),hs=Yt(K_,Ed,"*"),fu=Yt(/[A-Z]/,Ed,"*"),OB=["attached","autoclosure",Yt(/convention\(/,or("swift","block","c"),/\)/),"discardableResult","dynamicCallable","dynamicMemberLookup","escaping","freestanding","frozen","GKInspectable","IBAction","IBDesignable","IBInspectable","IBOutlet","IBSegueAction","inlinable","main","nonobjc","NSApplicationMain","NSCopying","NSManaged",Yt(/objc\(/,hs,/\)/),"objc","objcMembers","propertyWrapper","requires_stored_property_inits","resultBuilder","Sendable","testable","UIApplicationMain","unchecked","unknown","usableFromInline","warn_unqualified_access"],IB=["iOS","iOSApplicationExtension","macOS","macOSApplicationExtension","macCatalyst","macCatalystApplicationExtension","watchOS","watchOSApplicationExtension","tvOS","tvOSApplicationExtension","swift"];function LB(t){const e={match:/\s+/,relevance:0},n=t.COMMENT("/\\*","\\*/",{contains:["self"]}),r=[t.C_LINE_COMMENT_MODE,n],s={match:[/\./,or(...jB,...Qw)],className:{2:"keyword"}},i={match:Yt(/\./,or(...Np)),relevance:0},o=Np.filter(pe=>typeof pe=="string").concat(["_|0"]),l=Np.filter(pe=>typeof pe!="string").concat(MB).map(Jv),d={variants:[{className:"keyword",match:or(...l,...Qw)}]},f={$pattern:or(/\b\w+/,/#\w+/),keyword:o.concat(RB),literal:Zw},h=[s,i,d],m={match:Yt(/\./,or(...ek)),relevance:0},g={className:"built_in",match:Yt(/\b/,or(...ek),/(?=\()/)},v=[m,g],b={match:/->/,relevance:0},k={className:"operator",relevance:0,variants:[{match:Cp},{match:`\\.(\\.|${V_})+`}]},w=[b,k],E="([0-9]_*)+",C="([0-9a-fA-F]_*)+",T={className:"number",relevance:0,variants:[{match:`\\b(${E})(\\.(${E}))?([eE][+-]?(${E}))?\\b`},{match:`\\b0x(${C})(\\.(${C}))?([pP][+-]?(${E}))?\\b`},{match:/\b0o([0-7]_*)+\b/},{match:/\b0b([01]_*)+\b/}]},j=(pe="")=>({className:"subst",variants:[{match:Yt(/\\/,pe,/[0\\tnr"']/)},{match:Yt(/\\/,pe,/u\{[0-9a-fA-F]{1,8}\}/)}]}),_=(pe="")=>({className:"subst",match:Yt(/\\/,pe,/[\t ]*(?:[\r\n]|\r\n)/)}),A=(pe="")=>({className:"subst",label:"interpol",begin:Yt(/\\/,pe,/\(/),end:/\)/}),O=(pe="")=>({begin:Yt(pe,/"""/),end:Yt(/"""/,pe),contains:[j(pe),_(pe),A(pe)]}),B=(pe="")=>({begin:Yt(pe,/"/),end:Yt(/"/,pe),contains:[j(pe),A(pe)]}),$={className:"string",variants:[O(),O("#"),O("##"),O("###"),B(),B("#"),B("##"),B("###")]},W=[t.BACKSLASH_ESCAPE,{begin:/\[/,end:/\]/,relevance:0,contains:[t.BACKSLASH_ESCAPE]}],J={begin:/\/[^\s](?=[^/\n]*\/)/,end:/\//,contains:W},z=pe=>{const mt=Yt(pe,/\//),ft=Yt(/\//,pe);return{begin:mt,end:ft,contains:[...W,{scope:"comment",begin:`#(?!.*${ft})`,end:/$/}]}},G={scope:"regexp",variants:[z("###"),z("##"),z("#"),J]},D={match:Yt(/`/,hs,/`/)},U={className:"variable",match:/\$\d+/},q={className:"variable",match:`\\$${Ed}+`},se=[D,U,q],V={match:/(@|#(un)?)available/,scope:"keyword",starts:{contains:[{begin:/\(/,end:/\)/,keywords:IB,contains:[...w,T,$]}]}},te={scope:"keyword",match:Yt(/@/,or(...OB),Ja(or(/\(/,/\s+/)))},K={scope:"meta",match:Yt(/@/,hs)},M=[V,te,K],L={match:Ja(/\b[A-Z]/),relevance:0,contains:[{className:"type",match:Yt(/(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)/,Ed,"+")},{className:"type",match:fu,relevance:0},{match:/[?!]+/,relevance:0},{match:/\.\.\./,relevance:0},{match:Yt(/\s+&\s+/,Ja(fu)),relevance:0}]},ee={begin:/</,end:/>/,keywords:f,contains:[...r,...h,...M,b,L]};L.contains.push(ee);const fe={match:Yt(hs,/\s*:/),keywords:"_|0",relevance:0},ge={begin:/\(/,end:/\)/,relevance:0,keywords:f,contains:["self",fe,...r,G,...h,...v,...w,T,$,...se,...M,L]},oe={begin:/</,end:/>/,keywords:"repeat each",contains:[...r,L]},we={begin:or(Ja(Yt(hs,/\s*:/)),Ja(Yt(hs,/\s+/,hs,/\s*:/))),end:/:/,relevance:0,contains:[{className:"keyword",match:/\b_\b/},{className:"params",match:hs}]},xe={begin:/\(/,end:/\)/,keywords:f,contains:[we,...r,...h,...w,T,$,...M,L,ge],endsParent:!0,illegal:/["']/},We={match:[/(func|macro)/,/\s+/,or(D.match,hs,Cp)],className:{1:"keyword",3:"title.function"},contains:[oe,xe,e],illegal:[/\[/,/%/]},He={match:[/\b(?:subscript|init[?!]?)/,/\s*(?=[<(])/],className:{1:"keyword"},contains:[oe,xe,e],illegal:/\[|%/},Ze={match:[/operator/,/\s+/,Cp],className:{1:"keyword",3:"title"}},Oe={begin:[/precedencegroup/,/\s+/,fu],className:{1:"keyword",3:"title"},contains:[L],keywords:[...AB,...Zw],end:/}/},Ke={match:[/class\b/,/\s+/,/func\b/,/\s+/,/\b[A-Za-z_][A-Za-z0-9_]*\b/],scope:{1:"keyword",3:"keyword",5:"title.function"}},pt={match:[/class\b/,/\s+/,/var\b/],scope:{1:"keyword",3:"keyword"}},Je={begin:[/(struct|protocol|class|extension|enum|actor)/,/\s+/,hs,/\s*/],beginScope:{1:"keyword",3:"title.class"},keywords:f,contains:[oe,...h,{begin:/:/,end:/\{/,keywords:f,contains:[{scope:"title.class.inherited",match:fu},...h],relevance:0}]};for(const pe of $.variants){const mt=pe.contains.find(at=>at.label==="interpol");mt.keywords=f;const ft=[...h,...v,...w,T,$,...se];mt.contains=[...ft,{begin:/\(/,end:/\)/,contains:["self",...ft]}]}return{name:"Swift",keywords:f,contains:[...r,We,He,Ke,pt,Je,Ze,Oe,{beginKeywords:"import",end:/$/,contains:[...r],relevance:0},G,...h,...v,...w,T,$,...se,...M,L,ge]}}const Nd="[A-Za-z$_][0-9A-Za-z$_]*",G_=["as","in","of","if","for","while","finally","var","new","function","do","return","void","else","break","catch","instanceof","with","throw","case","default","try","switch","continue","typeof","delete","let","yield","const","class","debugger","async","await","static","import","from","export","extends","using"],J_=["true","false","null","undefined","NaN","Infinity"],Y_=["Object","Function","Boolean","Symbol","Math","Date","Number","BigInt","String","RegExp","Array","Float32Array","Float64Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Int32Array","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array","Set","Map","WeakSet","WeakMap","ArrayBuffer","SharedArrayBuffer","Atomics","DataView","JSON","Promise","Generator","GeneratorFunction","AsyncFunction","Reflect","Proxy","Intl","WebAssembly"],X_=["Error","EvalError","InternalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError"],Q_=["setInterval","setTimeout","clearInterval","clearTimeout","require","exports","eval","isFinite","isNaN","parseFloat","parseInt","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape"],Z_=["arguments","this","super","console","window","document","localStorage","sessionStorage","module","global"],e2=[].concat(Q_,Y_,X_);function DB(t){const e=t.regex,n=(V,{after:te})=>{const K="</"+V[0].slice(1);return V.input.indexOf(K,te)!==-1},r=Nd,s={begin:"<>",end:"</>"},i=/<[A-Za-z0-9\\._:-]+\s*\/>/,o={begin:/<[A-Za-z0-9\\._:-]+/,end:/\/[A-Za-z0-9\\._:-]+>|\/>/,isTrulyOpeningTag:(V,te)=>{const K=V[0].length+V.index,M=V.input[K];if(M==="<"||M===","){te.ignoreMatch();return}M===">"&&(n(V,{after:K})||te.ignoreMatch());let L;const ee=V.input.substring(K);if(L=ee.match(/^\s*=/)){te.ignoreMatch();return}if((L=ee.match(/^\s+extends\s+/))&&L.index===0){te.ignoreMatch();return}}},l={$pattern:Nd,keyword:G_,literal:J_,built_in:e2,"variable.language":Z_},d="[0-9](_?[0-9])*",f=`\\.(${d})`,h="0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*",m={className:"number",variants:[{begin:`(\\b(${h})((${f})|\\.)?|(${f}))[eE][+-]?(${d})\\b`},{begin:`\\b(${h})\\b((${f})\\b|\\.)?|(${f})\\b`},{begin:"\\b(0|[1-9](_?[0-9])*)n\\b"},{begin:"\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b"},{begin:"\\b0[bB][0-1](_?[0-1])*n?\\b"},{begin:"\\b0[oO][0-7](_?[0-7])*n?\\b"},{begin:"\\b0[0-7]+n?\\b"}],relevance:0},g={className:"subst",begin:"\\$\\{",end:"\\}",keywords:l,contains:[]},v={begin:".?html`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,g],subLanguage:"xml"}},b={begin:".?css`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,g],subLanguage:"css"}},k={begin:".?gql`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,g],subLanguage:"graphql"}},w={className:"string",begin:"`",end:"`",contains:[t.BACKSLASH_ESCAPE,g]},C={className:"comment",variants:[t.COMMENT(/\/\*\*(?!\/)/,"\\*/",{relevance:0,contains:[{begin:"(?=@[A-Za-z]+)",relevance:0,contains:[{className:"doctag",begin:"@[A-Za-z]+"},{className:"type",begin:"\\{",end:"\\}",excludeEnd:!0,excludeBegin:!0,relevance:0},{className:"variable",begin:r+"(?=\\s*(-)|$)",endsParent:!0,relevance:0},{begin:/(?=[^\n])\s/,relevance:0}]}]}),t.C_BLOCK_COMMENT_MODE,t.C_LINE_COMMENT_MODE]},T=[t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,v,b,k,w,{match:/\$\d+/},m];g.contains=T.concat({begin:/\{/,end:/\}/,keywords:l,contains:["self"].concat(T)});const j=[].concat(C,g.contains),_=j.concat([{begin:/(\s*)\(/,end:/\)/,keywords:l,contains:["self"].concat(j)}]),A={className:"params",begin:/(\s*)\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:l,contains:_},O={variants:[{match:[/class/,/\s+/,r,/\s+/,/extends/,/\s+/,e.concat(r,"(",e.concat(/\./,r),")*")],scope:{1:"keyword",3:"title.class",5:"keyword",7:"title.class.inherited"}},{match:[/class/,/\s+/,r],scope:{1:"keyword",3:"title.class"}}]},B={relevance:0,match:e.either(/\bJSON/,/\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,/\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,/\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/),className:"title.class",keywords:{_:[...Y_,...X_]}},$={label:"use_strict",className:"meta",relevance:10,begin:/^\s*['"]use (strict|asm)['"]/},W={variants:[{match:[/function/,/\s+/,r,/(?=\s*\()/]},{match:[/function/,/\s*(?=\()/]}],className:{1:"keyword",3:"title.function"},label:"func.def",contains:[A],illegal:/%/},J={relevance:0,match:/\b[A-Z][A-Z_0-9]+\b/,className:"variable.constant"};function z(V){return e.concat("(?!",V.join("|"),")")}const G={match:e.concat(/\b/,z([...Q_,"super","import"].map(V=>`${V}\\s*\\(`)),r,e.lookahead(/\s*\(/)),className:"title.function",relevance:0},D={begin:e.concat(/\./,e.lookahead(e.concat(r,/(?![0-9A-Za-z$_(])/))),end:r,excludeBegin:!0,keywords:"prototype",className:"property",relevance:0},U={match:[/get|set/,/\s+/,r,/(?=\()/],className:{1:"keyword",3:"title.function"},contains:[{begin:/\(\)/},A]},q="(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|"+t.UNDERSCORE_IDENT_RE+")\\s*=>",se={match:[/const|var|let/,/\s+/,r,/\s*/,/=\s*/,/(async\s*)?/,e.lookahead(q)],keywords:"async",className:{1:"keyword",3:"title.function"},contains:[A]};return{name:"JavaScript",aliases:["js","jsx","mjs","cjs"],keywords:l,exports:{PARAMS_CONTAINS:_,CLASS_REFERENCE:B},illegal:/#(?![$_A-z])/,contains:[t.SHEBANG({label:"shebang",binary:"node",relevance:5}),$,t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,v,b,k,w,C,{match:/\$\d+/},m,B,{scope:"attr",match:r+e.lookahead(":"),relevance:0},se,{begin:"("+t.RE_STARTERS_RE+"|\\b(case|return|throw)\\b)\\s*",keywords:"return throw case",relevance:0,contains:[C,t.REGEXP_MODE,{className:"function",begin:q,returnBegin:!0,end:"\\s*=>",contains:[{className:"params",variants:[{begin:t.UNDERSCORE_IDENT_RE,relevance:0},{className:null,begin:/\(\s*\)/,skip:!0},{begin:/(\s*)\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:l,contains:_}]}]},{begin:/,/,relevance:0},{match:/\s+/,relevance:0},{variants:[{begin:s.begin,end:s.end},{match:i},{begin:o.begin,"on:begin":o.isTrulyOpeningTag,end:o.end}],subLanguage:"xml",contains:[{begin:o.begin,end:o.end,skip:!0,contains:["self"]}]}]},W,{beginKeywords:"while if switch catch for"},{begin:"\\b(?!function)"+t.UNDERSCORE_IDENT_RE+"\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",returnBegin:!0,label:"func.def",contains:[A,t.inherit(t.TITLE_MODE,{begin:r,className:"title.function"})]},{match:/\.\.\./,relevance:0},D,{match:"\\$"+r,relevance:0},{match:[/\bconstructor(?=\s*\()/],className:{1:"title.function"},contains:[A]},G,J,O,U,{match:/\$[(.]/}]}}function PB(t){const e=t.regex,n=DB(t),r=Nd,s=["any","void","number","boolean","string","object","never","symbol","bigint","unknown"],i={begin:[/namespace/,/\s+/,t.IDENT_RE],beginScope:{1:"keyword",3:"title.class"}},o={beginKeywords:"interface",end:/\{/,excludeEnd:!0,keywords:{keyword:"interface extends",built_in:s},contains:[n.exports.CLASS_REFERENCE]},l={className:"meta",relevance:10,begin:/^\s*['"]use strict['"]/},d=["type","interface","public","private","protected","implements","declare","abstract","readonly","enum","override","satisfies"],f={$pattern:Nd,keyword:G_.concat(d),literal:J_,built_in:e2.concat(s),"variable.language":Z_},h={className:"meta",begin:"@"+r},m=(k,w,E)=>{const C=k.contains.findIndex(T=>T.label===w);if(C===-1)throw new Error("can not find mode to replace");k.contains.splice(C,1,E)};Object.assign(n.keywords,f),n.exports.PARAMS_CONTAINS.push(h);const g=n.contains.find(k=>k.scope==="attr"),v=Object.assign({},g,{match:e.concat(r,e.lookahead(/\s*\?:/))});n.exports.PARAMS_CONTAINS.push([n.exports.CLASS_REFERENCE,g,v]),n.contains=n.contains.concat([h,i,o,v]),m(n,"shebang",t.SHEBANG()),m(n,"use_strict",l);const b=n.contains.find(k=>k.label==="func.def");return b.relevance=0,Object.assign(n,{name:"TypeScript",aliases:["ts","tsx","mts","cts"]}),n}function BB(t){const e=t.regex,n={className:"string",begin:/"(""|[^/n])"C\b/},r={className:"string",begin:/"/,end:/"/,illegal:/\n/,contains:[{begin:/""/}]},s=/\d{1,2}\/\d{1,2}\/\d{4}/,i=/\d{4}-\d{1,2}-\d{1,2}/,o=/(\d|1[012])(:\d+){0,2} *(AM|PM)/,l=/\d{1,2}(:\d{1,2}){1,2}/,d={className:"literal",variants:[{begin:e.concat(/# */,e.either(i,s),/ *#/)},{begin:e.concat(/# */,l,/ *#/)},{begin:e.concat(/# */,o,/ *#/)},{begin:e.concat(/# */,e.either(i,s),/ +/,e.either(o,l),/ *#/)}]},f={className:"number",relevance:0,variants:[{begin:/\b\d[\d_]*((\.[\d_]+(E[+-]?[\d_]+)?)|(E[+-]?[\d_]+))[RFD@!#]?/},{begin:/\b\d[\d_]*((U?[SIL])|[%&])?/},{begin:/&H[\dA-F_]+((U?[SIL])|[%&])?/},{begin:/&O[0-7_]+((U?[SIL])|[%&])?/},{begin:/&B[01_]+((U?[SIL])|[%&])?/}]},h={className:"label",begin:/^\w+:/},m=t.COMMENT(/'''/,/$/,{contains:[{className:"doctag",begin:/<\/?/,end:/>/}]}),g=t.COMMENT(null,/$/,{variants:[{begin:/'/},{begin:/([\t ]|^)REM(?=\s)/}]});return{name:"Visual Basic .NET",aliases:["vb"],case_insensitive:!0,classNameAliases:{label:"symbol"},keywords:{keyword:"addhandler alias aggregate ansi as async assembly auto binary by byref byval call case catch class compare const continue custom declare default delegate dim distinct do each equals else elseif end enum erase error event exit explicit finally for friend from function get global goto group handles if implements imports in inherits interface into iterator join key let lib loop me mid module mustinherit mustoverride mybase myclass namespace narrowing new next notinheritable notoverridable of off on operator option optional order overloads overridable overrides paramarray partial preserve private property protected public raiseevent readonly redim removehandler resume return select set shadows shared skip static step stop structure strict sub synclock take text then throw to try unicode until using when where while widening with withevents writeonly yield",built_in:"addressof and andalso await directcast gettype getxmlnamespace is isfalse isnot istrue like mod nameof new not or orelse trycast typeof xor cbool cbyte cchar cdate cdbl cdec cint clng cobj csbyte cshort csng cstr cuint culng cushort",type:"boolean byte char date decimal double integer long object sbyte short single string uinteger ulong ushort",literal:"true false nothing"},illegal:"//|\\{|\\}|endif|gosub|variant|wend|^\\$ ",contains:[n,r,d,f,h,m,g,{className:"meta",begin:/[\t ]*#(const|disable|else|elseif|enable|end|externalsource|if|region)\b/,end:/$/,keywords:{keyword:"const disable else elseif enable end externalsource if region then"},contains:[g]}]}}function $B(t){t.regex;const e=t.COMMENT(/\(;/,/;\)/);e.contains.push("self");const n=t.COMMENT(/;;/,/$/),r=["anyfunc","block","br","br_if","br_table","call","call_indirect","data","drop","elem","else","end","export","func","global.get","global.set","local.get","local.set","local.tee","get_global","get_local","global","if","import","local","loop","memory","memory.grow","memory.size","module","mut","nop","offset","param","result","return","select","set_global","set_local","start","table","tee_local","then","type","unreachable"],s={begin:[/(?:func|call|call_indirect)/,/\s+/,/\$[^\s)]+/],className:{1:"keyword",3:"title.function"}},i={className:"variable",begin:/\$[\w_]+/},o={match:/(\((?!;)|\))+/,className:"punctuation",relevance:0},l={className:"number",relevance:0,match:/[+-]?\b(?:\d(?:_?\d)*(?:\.\d(?:_?\d)*)?(?:[eE][+-]?\d(?:_?\d)*)?|0x[\da-fA-F](?:_?[\da-fA-F])*(?:\.[\da-fA-F](?:_?[\da-fA-D])*)?(?:[pP][+-]?\d(?:_?\d)*)?)\b|\binf\b|\bnan(?::0x[\da-fA-F](?:_?[\da-fA-D])*)?\b/},d={match:/(i32|i64|f32|f64)(?!\.)/,className:"type"},f={className:"keyword",match:/\b(f32|f64|i32|i64)(?:\.(?:abs|add|and|ceil|clz|const|convert_[su]\/i(?:32|64)|copysign|ctz|demote\/f64|div(?:_[su])?|eqz?|extend_[su]\/i32|floor|ge(?:_[su])?|gt(?:_[su])?|le(?:_[su])?|load(?:(?:8|16|32)_[su])?|lt(?:_[su])?|max|min|mul|nearest|neg?|or|popcnt|promote\/f32|reinterpret\/[fi](?:32|64)|rem_[su]|rot[lr]|shl|shr_[su]|store(?:8|16|32)?|sqrt|sub|trunc(?:_[su]\/f(?:32|64))?|wrap\/i64|xor))\b/};return{name:"WebAssembly",keywords:{$pattern:/[\w.]+/,keyword:r},contains:[n,e,{match:[/(?:offset|align)/,/\s*/,/=/],className:{1:"keyword",3:"operator"}},i,o,s,t.QUOTE_STRING_MODE,d,f,l]}}function zB(t){const e=t.regex,n=e.concat(/[\p{L}_]/u,e.optional(/[\p{L}0-9_.-]*:/u),/[\p{L}0-9_.-]*/u),r=/[\p{L}0-9._:-]+/u,s={className:"symbol",begin:/&[a-z]+;|&#[0-9]+;|&#x[a-f0-9]+;/},i={begin:/\s/,contains:[{className:"keyword",begin:/#?[a-z_][a-z1-9_-]+/,illegal:/\n/}]},o=t.inherit(i,{begin:/\(/,end:/\)/}),l=t.inherit(t.APOS_STRING_MODE,{className:"string"}),d=t.inherit(t.QUOTE_STRING_MODE,{className:"string"}),f={endsWithParent:!0,illegal:/</,relevance:0,contains:[{className:"attr",begin:r,relevance:0},{begin:/=\s*/,relevance:0,contains:[{className:"string",endsParent:!0,variants:[{begin:/"/,end:/"/,contains:[s]},{begin:/'/,end:/'/,contains:[s]},{begin:/[^\s"'=<>`]+/}]}]}]};return{name:"HTML, XML",aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist","wsf","svg"],case_insensitive:!0,unicodeRegex:!0,contains:[{className:"meta",begin:/<![a-z]/,end:/>/,relevance:10,contains:[i,d,l,o,{begin:/\[/,end:/\]/,contains:[{className:"meta",begin:/<![a-z]/,end:/>/,contains:[i,o,d,l]}]}]},t.COMMENT(/<!--/,/-->/,{relevance:10}),{begin:/<!\[CDATA\[/,end:/\]\]>/,relevance:10},s,{className:"meta",end:/\?>/,variants:[{begin:/<\?xml/,relevance:10,contains:[d]},{begin:/<\?[a-z][a-z0-9]+/}]},{className:"tag",begin:/<style(?=\s|>)/,end:/>/,keywords:{name:"style"},contains:[f],starts:{end:/<\/style>/,returnEnd:!0,subLanguage:["css","xml"]}},{className:"tag",begin:/<script(?=\s|>)/,end:/>/,keywords:{name:"script"},contains:[f],starts:{end:/<\/script>/,returnEnd:!0,subLanguage:["javascript","handlebars","xml"]}},{className:"tag",begin:/<>|<\/>/},{className:"tag",begin:e.concat(/</,e.lookahead(e.concat(n,e.either(/\/>/,/>/,/\s/)))),end:/\/?>/,contains:[{className:"name",begin:n,relevance:0,starts:f}]},{className:"tag",begin:e.concat(/<\//,e.lookahead(e.concat(n,/>/))),contains:[{className:"name",begin:n,relevance:0},{begin:/>/,relevance:0,endsParent:!0}]}]}}function FB(t){const e="true false yes no null",n="[\\w#;/?:@&=+$,.~*'()[\\]]+",r={className:"attr",variants:[{begin:/[\w*@][\w*@ :()\./-]*:(?=[ \t]|$)/},{begin:/"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/},{begin:/'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/}]},s={className:"template-variable",variants:[{begin:/\{\{/,end:/\}\}/},{begin:/%\{/,end:/\}/}]},i={className:"string",relevance:0,begin:/'/,end:/'/,contains:[{match:/''/,scope:"char.escape",relevance:0}]},o={className:"string",relevance:0,variants:[{begin:/"/,end:/"/},{begin:/\S+/}],contains:[t.BACKSLASH_ESCAPE,s]},l=t.inherit(o,{variants:[{begin:/'/,end:/'/,contains:[{begin:/''/,relevance:0}]},{begin:/"/,end:/"/},{begin:/[^\s,{}[\]]+/}]}),g={className:"number",begin:"\\b"+"[0-9]{4}(-[0-9][0-9]){0,2}"+"([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?"+"(\\.[0-9]*)?"+"([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?"+"\\b"},v={end:",",endsWithParent:!0,excludeEnd:!0,keywords:e,relevance:0},b={begin:/\{/,end:/\}/,contains:[v],illegal:"\\n",relevance:0},k={begin:"\\[",end:"\\]",contains:[v],illegal:"\\n",relevance:0},w=[r,{className:"meta",begin:"^---\\s*$",relevance:10},{className:"string",begin:"[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*"},{begin:"<%[%=-]?",end:"[%-]?%>",subLanguage:"ruby",excludeBegin:!0,excludeEnd:!0,relevance:0},{className:"type",begin:"!\\w+!"+n},{className:"type",begin:"!<"+n+">"},{className:"type",begin:"!"+n},{className:"type",begin:"!!"+n},{className:"meta",begin:"&"+t.UNDERSCORE_IDENT_RE+"$"},{className:"meta",begin:"\\*"+t.UNDERSCORE_IDENT_RE+"$"},{className:"bullet",begin:"-(?=[ ]|$)",relevance:0},t.HASH_COMMENT_MODE,{beginKeywords:e,keywords:{literal:e}},g,{className:"number",begin:t.C_NUMBER_RE+"\\b",relevance:0},b,k,i,o],E=[...w];return E.pop(),E.push(l),v.contains=E,{name:"YAML",case_insensitive:!0,aliases:["yml"],contains:w}}const UB={arduino:S6,bash:E6,c:N6,cpp:C6,csharp:_6,css:D6,diff:P6,go:B6,graphql:$6,ini:z6,java:F6,javascript:V6,json:K6,kotlin:J6,less:rB,lua:sB,makefile:iB,markdown:oB,objectivec:aB,perl:lB,php:cB,"php-template":uB,plaintext:dB,python:fB,"python-repl":hB,r:pB,ruby:mB,rust:gB,scss:NB,shell:CB,sql:_B,swift:LB,typescript:PB,vbnet:BB,wasm:$B,xml:zB,yaml:FB},tk={},HB="hljs-";function WB(t){const e=D_.newInstance();return t&&i(t),{highlight:n,highlightAuto:r,listLanguages:s,register:i,registerAlias:o,registered:l};function n(d,f,h){const m=h||tk,g=typeof m.prefix=="string"?m.prefix:HB;if(!e.getLanguage(d))throw new Error("Unknown language: `"+d+"` is not registered");e.configure({__emitter:qB,classPrefix:g});const v=e.highlight(f,{ignoreIllegals:!0,language:d});if(v.errorRaised)throw new Error("Could not highlight with `Highlight.js`",{cause:v.errorRaised});const b=v._emitter.root,k=b.data;return k.language=v.language,k.relevance=v.relevance,b}function r(d,f){const m=(f||tk).subset||s();let g=-1,v=0,b;for(;++g<m.length;){const k=m[g];if(!e.getLanguage(k))continue;const w=n(k,d,f);w.data&&w.data.relevance!==void 0&&w.data.relevance>v&&(v=w.data.relevance,b=w)}return b||{type:"root",children:[],data:{language:void 0,relevance:v}}}function s(){return e.listLanguages()}function i(d,f){if(typeof d=="string")e.registerLanguage(d,f);else{let h;for(h in d)Object.hasOwn(d,h)&&e.registerLanguage(h,d[h])}}function o(d,f){if(typeof d=="string")e.registerAliases(typeof f=="string"?f:[...f],{languageName:d});else{let h;for(h in d)if(Object.hasOwn(d,h)){const m=d[h];e.registerAliases(typeof m=="string"?m:[...m],{languageName:h})}}}function l(d){return!!e.getLanguage(d)}}class qB{constructor(e){this.options=e,this.root={type:"root",children:[],data:{language:void 0,relevance:0}},this.stack=[this.root]}addText(e){if(e==="")return;const n=this.stack[this.stack.length-1],r=n.children[n.children.length-1];r&&r.type==="text"?r.value+=e:n.children.push({type:"text",value:e})}startScope(e){this.openNode(String(e))}endScope(){this.closeNode()}__addSublanguage(e,n){const r=this.stack[this.stack.length-1],s=e.root.children;n?r.children.push({type:"element",tagName:"span",properties:{className:[n]},children:s}):r.children.push(...s)}openNode(e){const n=this,r=e.split(".").map(function(o,l){return l?o+"_".repeat(l):n.options.classPrefix+o}),s=this.stack[this.stack.length-1],i={type:"element",tagName:"span",properties:{className:r},children:[]};s.children.push(i),this.stack.push(i)}closeNode(){this.stack.pop()}finalize(){}toHTML(){return""}}const VB=new Jt("blurredLoadingNode"),Yv=Pt.create({name:"blurredLoadingNode",addStorage(){return{loadingNodes:{}}},addCommands(){return{applyLoadingEffect:(t,e,n,r="paragraph")=>({editor:s})=>{const i={...this.storage.loadingNodes};return i[t]={from:e,to:n,id:t,active:!0,type:r},this.storage.loadingNodes=i,s.view.dispatch(s.view.state.tr),setTimeout(()=>{s.isFocused&&s.commands.setTextSelection({from:e,to:e})},0),!0},removeLoadingEffect:t=>({editor:e})=>{const n={...this.storage.loadingNodes};return n[t]&&(delete n[t],this.storage.loadingNodes=n,e.view.dispatch(e.view.state.tr),e.isFocused||setTimeout(()=>{e.commands.focus()},0)),!0}}},addProseMirrorPlugins(){return[new Ht({key:VB,props:{decorations:t=>{const e=this.storage.loadingNodes,n=[];return Object.entries(e).forEach(([,r])=>{const s=r;if(!s.active)return;const{from:i,to:o,type:l}=s;l==="selection"?n.push(Vt.inline(i,o,{class:"node-blur-selection"})):t.doc.nodesBetween(i,o,(d,f)=>["paragraph","heading","blockquote","listItem","codeBlock"].includes(d.type.name)?(n.push(Vt.node(f,f+d.nodeSize,{class:"node-blur-effect"})),!1):!0)}),Dt.create(t.doc,n)}}})]}}),Xv=vn.create({name:"imageLoading",group:"block",atom:!0,addAttributes(){return{id:{default:null}}},parseHTML(){return[{tag:'div[data-type="image-loading"]'}]},renderHTML(){return["div",{"data-type":"image-loading",class:"image-loading-placeholder",contenteditable:"false"}]}}),KB=new Jt("insertionLoadingNode"),hu=new Map,Qv=Pt.create({name:"insertionLoadingNode",addStorage(){return{insertionPoints:{}}},addCommands(){return{showInsertionLoading:(t,e)=>({editor:n})=>(this.storage.insertionPoints={},hu.clear(),this.storage.insertionPoints={[t]:{position:e,id:t,active:!0}},n.view.dom.classList.add("has-insertion-loading"),n.view.dispatch(n.view.state.tr),!0),removeInsertionLoading:t=>({editor:e})=>{const n={...this.storage.insertionPoints};return n[t]&&(delete n[t],this.storage.insertionPoints=n,hu.delete(t),Object.keys(n).length===0&&e.view.dom.classList.remove("has-insertion-loading"),e.view.dispatch(e.view.state.tr)),!0}}},addProseMirrorPlugins(){return[new Ht({key:KB,props:{decorations:t=>{const e=this.storage.insertionPoints,n=[];return Object.entries(e).forEach(([,r])=>{const s=r;s.active&&n.push(Vt.widget(s.position,()=>{const i=hu.get(s.id);if(i)return i;const o=document.createElement("span");o.className="inline-insertion-indicator";const l=document.createElement("span");l.className="inline-insertion-spinner";const d=document.createElement("div");d.className="bounce1";const f=document.createElement("div");f.className="bounce2";const h=document.createElement("div");return l.appendChild(d),l.appendChild(f),l.appendChild(h),o.appendChild(l),hu.set(s.id,o),o},{id:`insertion-${s.id}`}))}),Dt.create(t.doc,n)}}})]}}),GB=["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","horizontalRule","table","taskList","taskItem","image"],Zv=Pt.create({name:"pendingAttributes",addGlobalAttributes(){return[{types:GB,attributes:{pendingStatus:{default:null,parseHTML:t=>t.getAttribute("data-pending-status")||null,renderHTML:t=>t.pendingStatus?{"data-pending-status":t.pendingStatus}:{}},pendingOriginalContent:{default:null,rendered:!1},pendingSelectionFrom:{default:null,rendered:!1},pendingSelectionTo:{default:null,rendered:!1},pendingOriginalFrom:{default:null,rendered:!1},pendingOriginalTo:{default:null,rendered:!1},pendingGroupId:{default:null,rendered:!1},pendingOrphan:{default:null,rendered:!1},pendingStaleBaseline:{default:null,rendered:!1}}}]}}),JB=vn.create({name:"footnoteReference",group:"inline",inline:!0,atom:!0,selectable:!0,draggable:!1,addAttributes(){return{label:{default:"",parseHTML:t=>t.getAttribute("data-label")||"",renderHTML:t=>({"data-label":t.label})}}},parseHTML(){return[{tag:"sup.footnote-ref",getAttrs:t=>{const e=t.getAttribute("data-label");return e?{label:e}:!1}}]},renderHTML({HTMLAttributes:t}){return["sup",zt({class:"footnote-ref"},t)]},addKeyboardShortcuts(){return{"Mod-Shift-f":()=>(t2(this.editor),!0)}}}),YB=vn.create({name:"footnoteSection",group:"block",content:"footnoteDefinition+",defining:!0,isolating:!0,addAttributes(){return{id:{default:null}}},parseHTML(){return[{tag:"section.footnotes"}]},renderHTML({HTMLAttributes:t}){return["section",zt({class:"footnotes"},t),0]}}),XB=vn.create({name:"footnoteDefinition",group:"block",content:"paragraph+",defining:!0,isolating:!0,addAttributes(){return{id:{default:null},label:{default:"",parseHTML:t=>t.getAttribute("data-label")||"",renderHTML:t=>({"data-label":t.label})}}},parseHTML(){return[{tag:"div.footnote-def",getAttrs:t=>{const e=t.getAttribute("data-label");return e?{label:e}:!1}}]},renderHTML({HTMLAttributes:t}){return["div",zt({class:"footnote-def"},t),0]}});function t2(t){const{state:e}=t,{schema:n,doc:r}=e,s=n.nodes.footnoteReference,i=n.nodes.footnoteSection,o=n.nodes.footnoteDefinition,l=n.nodes.paragraph;if(!s||!i||!o||!l)return;const d=new Set;r.descendants(T=>{(T.type.name==="footnoteReference"||T.type.name==="footnoteDefinition")&&T.attrs.label&&d.add(String(T.attrs.label))});let f=1;for(;d.has(String(f));)f++;const h=String(f);let m=-1,g=null;r.forEach((T,j)=>{T.type.name==="footnoteSection"&&(m=j,g=T)});const v=o.create({label:h},l.create()),b=s.create({label:h}),k=e.selection.to,w=e.tr;w.insert(k,b);let E;if(m>=0&&g){const T=b.nodeSize,_=(k<=m?m+T+g.nodeSize:m+g.nodeSize)-1;w.insert(_,v),E=_+2}else{const T=i.create(null,v),j=w.doc.content.size;w.insert(j,T),E=j+3}const C=Math.min(E,w.doc.content.size);w.setSelection(dt.near(w.doc.resolve(C))),w.scrollIntoView(),t.view.dispatch(w),t.view.focus()}function QB({node:t,deleteNode:e}){return c.jsxs(ED,{as:"div",className:"tweet-image-card",draggable:!0,"data-drag-handle":!0,children:[c.jsx("img",{className:"tweet-image-card-img",src:t.attrs.src,alt:t.attrs.alt||"",draggable:!1}),c.jsx("button",{className:"tweet-image-card-remove",onClick:e,title:"Remove image",contentEditable:!1,children:"×"})]})}const ZB=Iv.extend({addNodeView(){return MD(QB)}}),e5=WB(UB),ey=lP.extend({addAttributes(){var t;return{...(t=this.parent)==null?void 0:t.call(this),target:{default:null}}},renderHTML({HTMLAttributes:t}){var r;const{target:e,...n}=t;if((r=n.href)!=null&&r.startsWith("doc:")){const{href:s,...i}=n;return["span",{...i,"data-doc":s.slice(4),class:"doc-link"},0]}return["a",zt(this.options.HTMLAttributes,n),0]}}),t5=[Gv.configure({codeBlock:!1,link:!1,underline:!1}),w6.configure({lowlight:e5}),ey.configure({openOnClick:!1,isAllowedUri:(t,e)=>t.startsWith("doc:")?!0:e.defaultValidate(t),HTMLAttributes:{rel:"noopener noreferrer nofollow"}}),O_,R3,LD,IP,DP,e3,Z4.configure({nested:!0}),Iv,A3,b_.configure({resizable:!1}),y_,v_,g_,Yv,Xv,Qv,Zv,JB,YB,XB,Kd.configure({placeholder:"Start writing..."}),Kv.configure({types:["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","horizontalRule","table","tableRow","tableHeader","tableCell","taskList","taskItem","image","imageLoading","footnoteSection","footnoteDefinition"],attributeName:"id",generateID:()=>crypto.randomUUID().replace(/-/g,"").slice(0,8)})],n5=[Gv.configure({codeBlock:!1,horizontalRule:!0,heading:{levels:[1,2,3]},link:!1,underline:!1}),ey.configure({openOnClick:!1,isAllowedUri:(t,e)=>t.startsWith("doc:")?!0:e.defaultValidate(t),HTMLAttributes:{rel:"noopener noreferrer nofollow"}}),Iv,Yv,Xv,Qv,Zv,Kd.configure({placeholder:"Start writing..."}),Kv.configure({types:["paragraph","heading","bulletList","orderedList","listItem","blockquote","image","imageLoading","horizontalRule"],attributeName:"id",generateID:()=>crypto.randomUUID().replace(/-/g,"").slice(0,8)})],r5=Pt.create({name:"tweetEnterHardBreak",addKeyboardShortcuts(){return{Enter:()=>{const{state:t}=this.editor,{$from:e}=t.selection,n=e.pos,r=n>0?t.doc.resolve(n).nodeBefore:null;if((r==null?void 0:r.type.name)==="hardBreak"){const{tr:s}=t;return s.delete(n-r.nodeSize,n),s.split(s.mapping.map(n)),this.editor.view.dispatch(s),!0}return this.editor.commands.setHardBreak()}}}}),n2=[Gv.configure({codeBlock:!1,horizontalRule:!1,heading:!1,blockquote:!1,bulletList:!1,orderedList:!1,listItem:!1,link:!1,underline:!1}),ey.configure({openOnClick:!1,isAllowedUri:(t,e)=>t.startsWith("doc:")?!0:e.defaultValidate(t),HTMLAttributes:{rel:"noopener noreferrer nofollow"}}),ZB,Yv,Xv,Qv,Zv,r5,Kv.configure({types:["paragraph","image","imageLoading"],attributeName:"id",generateID:()=>crypto.randomUUID().replace(/-/g,"").slice(0,8)})];[...n2,Kd.configure({placeholder:"What is happening?!"})];function Dr({onClick:t,active:e,disabled:n,title:r,children:s}){return c.jsx("button",{className:`floating-toolbar__btn${e?" active":""}${n?" disabled":""}`,onMouseDown:i=>{i.preventDefault(),t()},disabled:n,title:r,children:s})}function nk(){return c.jsx("div",{className:"floating-toolbar__divider"})}function s5({editor:t}){const[e,n]=x.useState(!1),[r,s]=x.useState({top:0,left:0}),[,i]=x.useState(0),o=x.useRef(-1),l=x.useRef(-1),d=x.useRef(!1);return x.useEffect(()=>{const f=t.view.dom,h=()=>{d.current=!0},m=()=>{if(!d.current)return;d.current=!1;const{from:g,to:v}=t.state.selection,b=g!==v&&t.state.selection.node;if(g!==v&&!b){const k=t.isActive("codeBlock"),w=!!document.querySelector(".context-menu");if(!k&&!w){o.current=g,l.current=v;const E=t.view.coordsAtPos(g),C=t.view.coordsAtPos(v,1),T=(E.left+C.right)/2;s({top:E.top,left:T}),n(!0)}}};return f.addEventListener("mousedown",h),document.addEventListener("mouseup",m),()=>{f.removeEventListener("mousedown",h),document.removeEventListener("mouseup",m)}},[t]),x.useEffect(()=>{const f=()=>{d.current=!1,n(!1),o.current=-1,l.current=-1};return t.on("blur",f),()=>{t.off("blur",f)}},[t]),x.useEffect(()=>{const f=()=>{const{from:h,to:m}=t.state.selection,g=h===m,v=t.isActive("codeBlock"),b=!!document.querySelector(".context-menu"),k=t.view.hasFocus(),w=!g&&t.state.selection.node;if(g||w||v||b||!k)n(!1),o.current=-1,l.current=-1;else if(!d.current&&(n(!0),h!==o.current||m!==l.current)){o.current=h,l.current=m;const E=t.view.coordsAtPos(h),C=t.view.coordsAtPos(m,1),T=(E.left+C.right)/2;s({top:E.top,left:T})}i(E=>E+1)};return t.on("transaction",f),()=>{t.off("transaction",f)}},[t]),e?c.jsxs("div",{className:"floating-toolbar",style:{position:"fixed",top:r.top,left:r.left,transform:"translate(-50%, -100%) translateY(-8px)",zIndex:1500},children:[c.jsx(Dr,{onClick:()=>t.chain().focus().toggleBold().run(),active:t.isActive("bold"),title:"Bold (Ctrl+B)",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"})})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleItalic().run(),active:t.isActive("italic"),title:"Italic (Ctrl+I)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"19",x2:"10",y1:"4",y2:"4"}),c.jsx("line",{x1:"14",x2:"5",y1:"20",y2:"20"}),c.jsx("line",{x1:"15",x2:"9",y1:"4",y2:"20"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleUnderline().run(),active:t.isActive("underline"),title:"Underline (Ctrl+U)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M6 4v6a6 6 0 0 0 12 0V4"}),c.jsx("line",{x1:"4",x2:"20",y1:"20",y2:"20"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleStrike().run(),active:t.isActive("strike"),title:"Strikethrough",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M16 4H9a3 3 0 0 0-2.83 4"}),c.jsx("path",{d:"M14 12a4 4 0 0 1 0 8H6"}),c.jsx("line",{x1:"4",x2:"20",y1:"12",y2:"12"})]})}),c.jsx(Dr,{onClick:()=>{const f=t.getAttributes("link").href||"",h=window.prompt("Link URL:",f);h!==null&&(h===""?t.chain().focus().unsetLink().run():t.chain().focus().setLink({href:h}).run())},active:t.isActive("link"),title:"Link (Ctrl+K)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),c.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}),c.jsx(nk,{}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleHeading({level:1}).run(),active:t.isActive("heading",{level:1}),title:"Heading 1",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 12h8"}),c.jsx("path",{d:"M4 18V6"}),c.jsx("path",{d:"M12 18V6"}),c.jsx("path",{d:"m17 12 3-2v8"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleHeading({level:2}).run(),active:t.isActive("heading",{level:2}),title:"Heading 2",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 12h8"}),c.jsx("path",{d:"M4 18V6"}),c.jsx("path",{d:"M12 18V6"}),c.jsx("path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleHeading({level:3}).run(),active:t.isActive("heading",{level:3}),title:"Heading 3",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 12h8"}),c.jsx("path",{d:"M4 18V6"}),c.jsx("path",{d:"M12 18V6"}),c.jsx("path",{d:"M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2"}),c.jsx("path",{d:"M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"})]})}),c.jsx(nk,{}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleBulletList().run(),active:t.isActive("bulletList"),title:"Bullet List",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M3 12h.01"}),c.jsx("path",{d:"M3 18h.01"}),c.jsx("path",{d:"M3 6h.01"}),c.jsx("path",{d:"M8 12h13"}),c.jsx("path",{d:"M8 18h13"}),c.jsx("path",{d:"M8 6h13"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleOrderedList().run(),active:t.isActive("orderedList"),title:"Ordered List",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M11 12h9"}),c.jsx("path",{d:"M11 18h9"}),c.jsx("path",{d:"M11 6h9"}),c.jsx("path",{d:"M4 10V4h1"}),c.jsx("path",{d:"M4 10h2"}),c.jsx("path",{d:"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleBlockquote().run(),active:t.isActive("blockquote"),title:"Blockquote",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 6H3"}),c.jsx("path",{d:"M21 12H8"}),c.jsx("path",{d:"M21 18H8"}),c.jsx("path",{d:"M3 12v6"})]})}),c.jsx(Dr,{onClick:()=>t2(t),title:"Footnote (Ctrl+Shift+F)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 6h12"}),c.jsx("path",{d:"M4 12h12"}),c.jsx("path",{d:"M4 18h8"}),c.jsx("text",{x:"18",y:"9",fontSize:"9",fontWeight:"bold",stroke:"none",fill:"currentColor",children:"N"})]})})]}):null}const i5=new Jt("pendingDecoration");let r2=null,s2=null;function rk(t,e){r2=t,s2=e??null}let Cd=!1,i2=null,ty=null,o2=null;function ny(){return Cd}function o5(){return ty}function a5(){return o2}function rl(t,e,n,r){Cd=t,i2=t?e??null:null,ty=t?r??null:null,o2=t?n??null:null}function l5(t){switch(t){case"insert":return"pending-insert";case"rewrite":return"pending-rewrite";case"delete":return"pending-delete";default:return""}}function sk(t,e,n){let r=0,s=e+1;for(let i=0;i<t.childCount;i++){const o=t.child(i);if(o.isText){if(r+o.text.length>=n)return s+(n-r);r+=o.text.length,s+=o.nodeSize}else{const l=o.type.name==="hardBreak"?1:o.type.spec.leafText?o.type.spec.leafText(o).length:0;if(l>0&&r+l>=n)return s;r+=l,s+=o.nodeSize}}return n===r?s:null}function ik(t){const e=[];return t.descendants((n,r)=>{var w,E,C,T,j,_,A,O,B;const s=(w=n.attrs)==null?void 0:w.pendingStatus;if(!s)return!0;const i=(E=n.attrs)==null?void 0:E.id,o=(C=n.attrs)==null?void 0:C.pendingGroupId,l=o&&o===s2,f=Cd&&i===i2||o&&Cd&&o===ty,h=f?(T=n.attrs)==null?void 0:T.pendingOriginalFrom:(j=n.attrs)==null?void 0:j.pendingSelectionFrom,m=f?(_=n.attrs)==null?void 0:_.pendingOriginalTo:(A=n.attrs)==null?void 0:A.pendingSelectionTo,g=h!=null&&m!=null,v=f?"pending-original":l5(s),b=[];(O=n.attrs)!=null&&O.pendingOrphan&&b.push("pending-orphan"),(B=n.attrs)!=null&&B.pendingStaleBaseline&&b.push("pending-stale");const k=v+(b.length?" "+b.join(" "):"");if(g&&n.isTextblock&&k){const $=sk(n,r,h),W=sk(n,r,m);$!==null&&W!==null&&$<W&&e.push(Vt.inline($,W,{class:k}))}else k&&(n.isTextblock&&r+1<r+n.nodeSize-1?e.push(Vt.inline(r+1,r+n.nodeSize-1,{class:k})):e.push(Vt.node(r,r+n.nodeSize,{class:k})));if(i&&(i===r2||l)){const $=f?"original":s;e.push(Vt.node(r,r+n.nodeSize,{class:`pending-active pending-active--${$}`}))}return!0}),Dt.create(t,e)}function a2(){return new Ht({key:i5,state:{init(t,e){return ik(e.doc)},apply(t,e,n,r){return t.docChanged||t.getMeta("forceDecorationUpdate")?ik(r.doc):e.map(t.mapping,t.doc)}},props:{decorations(t){return this.getState(t)}}})}function ry(t){const{state:e,dispatch:n}=t,r=e.tr.setMeta("forceDecorationUpdate",!0);n(r)}const c5=new Jt("commentDecoration");let Xo=[];function ok(t){Xo=t}function Ru(){return Xo}function l2(t){return{class:"ow-comment","data-comment-id":t.id}}function ak(t,e,n){const s=e.textContent.indexOf(t.text);if(s===-1)return null;const i=Qo(e,n,s),o=Qo(e,n,s+t.text.length);return i===null||o===null||i>=o?null:Vt.inline(i,o,l2(t))}function u5(t,e){const n=t.nodeIds,r=t.text.split(`
203
+ ]`,b={scope:"string",variants:[h,f,m,g]},k={scope:"number",variants:[{begin:"\\b0[bB][01]+(?:_[01]+)*\\b"},{begin:"\\b0[oO][0-7]+(?:_[0-7]+)*\\b"},{begin:"\\b0[xX][\\da-fA-F]+(?:_[\\da-fA-F]+)*\\b"},{begin:"(?:\\b\\d+(?:_\\d+)*(\\.(?:\\d+(?:_\\d+)*))?|\\B\\.\\d+)(?:[eE][+-]?\\d+)?"}],relevance:0},w=["false","null","true"],E=["__CLASS__","__DIR__","__FILE__","__FUNCTION__","__COMPILER_HALT_OFFSET__","__LINE__","__METHOD__","__NAMESPACE__","__TRAIT__","die","echo","exit","include","include_once","print","require","require_once","array","abstract","and","as","binary","bool","boolean","break","callable","case","catch","class","clone","const","continue","declare","default","do","double","else","elseif","empty","enddeclare","endfor","endforeach","endif","endswitch","endwhile","enum","eval","extends","final","finally","float","for","foreach","from","global","goto","if","implements","instanceof","insteadof","int","integer","interface","isset","iterable","list","match|0","mixed","new","never","object","or","private","protected","public","readonly","real","return","string","switch","throw","trait","try","unset","use","var","void","while","xor","yield"],C=["Error|0","AppendIterator","ArgumentCountError","ArithmeticError","ArrayIterator","ArrayObject","AssertionError","BadFunctionCallException","BadMethodCallException","CachingIterator","CallbackFilterIterator","CompileError","Countable","DirectoryIterator","DivisionByZeroError","DomainException","EmptyIterator","ErrorException","Exception","FilesystemIterator","FilterIterator","GlobIterator","InfiniteIterator","InvalidArgumentException","IteratorIterator","LengthException","LimitIterator","LogicException","MultipleIterator","NoRewindIterator","OutOfBoundsException","OutOfRangeException","OuterIterator","OverflowException","ParentIterator","ParseError","RangeException","RecursiveArrayIterator","RecursiveCachingIterator","RecursiveCallbackFilterIterator","RecursiveDirectoryIterator","RecursiveFilterIterator","RecursiveIterator","RecursiveIteratorIterator","RecursiveRegexIterator","RecursiveTreeIterator","RegexIterator","RuntimeException","SeekableIterator","SplDoublyLinkedList","SplFileInfo","SplFileObject","SplFixedArray","SplHeap","SplMaxHeap","SplMinHeap","SplObjectStorage","SplObserver","SplPriorityQueue","SplQueue","SplStack","SplSubject","SplTempFileObject","TypeError","UnderflowException","UnexpectedValueException","UnhandledMatchError","ArrayAccess","BackedEnum","Closure","Fiber","Generator","Iterator","IteratorAggregate","Serializable","Stringable","Throwable","Traversable","UnitEnum","WeakReference","WeakMap","Directory","__PHP_Incomplete_Class","parent","php_user_filter","self","static","stdClass"],j={keyword:E,literal:(D=>{const U=[];return D.forEach(q=>{U.push(q),q.toLowerCase()===q?U.push(q.toUpperCase()):U.push(q.toLowerCase())}),U})(w),built_in:C},_=D=>D.map(U=>U.replace(/\|\d+$/,"")),A={variants:[{match:[/new/,e.concat(v,"+"),e.concat("(?!",_(C).join("\\b|"),"\\b)"),s],scope:{1:"keyword",4:"title.class"}}]},O=e.concat(r,"\\b(?!\\()"),B={variants:[{match:[e.concat(/::/,e.lookahead(/(?!class\b)/)),O],scope:{2:"variable.constant"}},{match:[/::/,/class/],scope:{2:"variable.language"}},{match:[s,e.concat(/::/,e.lookahead(/(?!class\b)/)),O],scope:{1:"title.class",3:"variable.constant"}},{match:[s,e.concat("::",e.lookahead(/(?!class\b)/))],scope:{1:"title.class"}},{match:[s,/::/,/class/],scope:{1:"title.class",3:"variable.language"}}]},$={scope:"attr",match:e.concat(r,e.lookahead(":"),e.lookahead(/(?!::)/))},W={relevance:0,begin:/\(/,end:/\)/,keywords:j,contains:[$,o,B,t.C_BLOCK_COMMENT_MODE,b,k,A]},J={relevance:0,match:[/\b/,e.concat("(?!fn\\b|function\\b|",_(E).join("\\b|"),"|",_(C).join("\\b|"),"\\b)"),r,e.concat(v,"*"),e.lookahead(/(?=\()/)],scope:{3:"title.function.invoke"},contains:[W]};W.contains.push(J);const z=[$,B,t.C_BLOCK_COMMENT_MODE,b,k,A],G={begin:e.concat(/#\[\s*\\?/,e.either(s,i)),beginScope:"meta",end:/]/,endScope:"meta",keywords:{literal:w,keyword:["new","array"]},contains:[{begin:/\[/,end:/]/,keywords:{literal:w,keyword:["new","array"]},contains:["self",...z]},...z,{scope:"meta",variants:[{match:s},{match:i}]}]};return{case_insensitive:!1,keywords:j,contains:[G,t.HASH_COMMENT_MODE,t.COMMENT("//","$"),t.COMMENT("/\\*","\\*/",{contains:[{scope:"doctag",match:"@[A-Za-z]+"}]}),{match:/__halt_compiler\(\);/,keywords:"__halt_compiler",starts:{scope:"comment",end:t.MATCH_NOTHING_RE,contains:[{match:/\?>/,scope:"meta",endsParent:!0}]}},l,{scope:"variable.language",match:/\$this\b/},o,J,B,{match:[/const/,/\s/,r],scope:{1:"keyword",3:"variable.constant"}},A,{scope:"function",relevance:0,beginKeywords:"fn function",end:/[;{]/,excludeEnd:!0,illegal:"[$%\\[]",contains:[{beginKeywords:"use"},t.UNDERSCORE_TITLE_MODE,{begin:"=>",endsParent:!0},{scope:"params",begin:"\\(",end:"\\)",excludeBegin:!0,excludeEnd:!0,keywords:j,contains:["self",G,o,B,t.C_BLOCK_COMMENT_MODE,b,k]}]},{scope:"class",variants:[{beginKeywords:"enum",illegal:/[($"]/},{beginKeywords:"class interface trait",illegal:/[:($"]/}],relevance:0,end:/\{/,excludeEnd:!0,contains:[{beginKeywords:"extends implements"},t.UNDERSCORE_TITLE_MODE]},{beginKeywords:"namespace",relevance:0,end:";",illegal:/[.']/,contains:[t.inherit(t.UNDERSCORE_TITLE_MODE,{scope:"title.class"})]},{beginKeywords:"use",relevance:0,end:";",contains:[{match:/\b(as|const|function)\b/,scope:"keyword"},t.UNDERSCORE_TITLE_MODE]},b,k]}}function uB(t){return{name:"PHP template",subLanguage:"xml",contains:[{begin:/<\?(php|=)?/,end:/\?>/,subLanguage:"php",contains:[{begin:"/\\*",end:"\\*/",skip:!0},{begin:'b"',end:'"',skip:!0},{begin:"b'",end:"'",skip:!0},t.inherit(t.APOS_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0}),t.inherit(t.QUOTE_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0})]}]}}function dB(t){return{name:"Plain text",aliases:["text","txt"],disableAutodetect:!0}}function fB(t){const e=t.regex,n=new RegExp("[\\p{XID_Start}_]\\p{XID_Continue}*","u"),r=["and","as","assert","async","await","break","case","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","match","nonlocal|10","not","or","pass","raise","return","try","while","with","yield"],l={$pattern:/[A-Za-z]\w+|__\w+__/,keyword:r,built_in:["__import__","abs","all","any","ascii","bin","bool","breakpoint","bytearray","bytes","callable","chr","classmethod","compile","complex","delattr","dict","dir","divmod","enumerate","eval","exec","filter","float","format","frozenset","getattr","globals","hasattr","hash","help","hex","id","input","int","isinstance","issubclass","iter","len","list","locals","map","max","memoryview","min","next","object","oct","open","ord","pow","print","property","range","repr","reversed","round","set","setattr","slice","sorted","staticmethod","str","sum","super","tuple","type","vars","zip"],literal:["__debug__","Ellipsis","False","None","NotImplemented","True"],type:["Any","Callable","Coroutine","Dict","List","Literal","Generic","Optional","Sequence","Set","Tuple","Type","Union"]},d={className:"meta",begin:/^(>>>|\.\.\.) /},f={className:"subst",begin:/\{/,end:/\}/,keywords:l,illegal:/#/},h={begin:/\{\{/,relevance:0},m={className:"string",contains:[t.BACKSLASH_ESCAPE],variants:[{begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?'''/,end:/'''/,contains:[t.BACKSLASH_ESCAPE,d],relevance:10},{begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?"""/,end:/"""/,contains:[t.BACKSLASH_ESCAPE,d],relevance:10},{begin:/([fF][rR]|[rR][fF]|[fF])'''/,end:/'''/,contains:[t.BACKSLASH_ESCAPE,d,h,f]},{begin:/([fF][rR]|[rR][fF]|[fF])"""/,end:/"""/,contains:[t.BACKSLASH_ESCAPE,d,h,f]},{begin:/([uU]|[rR])'/,end:/'/,relevance:10},{begin:/([uU]|[rR])"/,end:/"/,relevance:10},{begin:/([bB]|[bB][rR]|[rR][bB])'/,end:/'/},{begin:/([bB]|[bB][rR]|[rR][bB])"/,end:/"/},{begin:/([fF][rR]|[rR][fF]|[fF])'/,end:/'/,contains:[t.BACKSLASH_ESCAPE,h,f]},{begin:/([fF][rR]|[rR][fF]|[fF])"/,end:/"/,contains:[t.BACKSLASH_ESCAPE,h,f]},t.APOS_STRING_MODE,t.QUOTE_STRING_MODE]},g="[0-9](_?[0-9])*",v=`(\\b(${g}))?\\.(${g})|\\b(${g})\\.`,b=`\\b|${r.join("|")}`,k={className:"number",relevance:0,variants:[{begin:`(\\b(${g})|(${v}))[eE][+-]?(${g})[jJ]?(?=${b})`},{begin:`(${v})[jJ]?`},{begin:`\\b([1-9](_?[0-9])*|0+(_?0)*)[lLjJ]?(?=${b})`},{begin:`\\b0[bB](_?[01])+[lL]?(?=${b})`},{begin:`\\b0[oO](_?[0-7])+[lL]?(?=${b})`},{begin:`\\b0[xX](_?[0-9a-fA-F])+[lL]?(?=${b})`},{begin:`\\b(${g})[jJ](?=${b})`}]},w={className:"comment",begin:e.lookahead(/# type:/),end:/$/,keywords:l,contains:[{begin:/# type:/},{begin:/#/,end:/\b\B/,endsWithParent:!0}]},E={className:"params",variants:[{className:"",begin:/\(\s*\)/,skip:!0},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:l,contains:["self",d,k,m,t.HASH_COMMENT_MODE]}]};return f.contains=[m,k,d],{name:"Python",aliases:["py","gyp","ipython"],unicodeRegex:!0,keywords:l,illegal:/(<\/|\?)|=>/,contains:[d,k,{scope:"variable.language",match:/\bself\b/},{beginKeywords:"if",relevance:0},{match:/\bor\b/,scope:"keyword"},m,w,t.HASH_COMMENT_MODE,{match:[/\bdef/,/\s+/,n],scope:{1:"keyword",3:"title.function"},contains:[E]},{variants:[{match:[/\bclass/,/\s+/,n,/\s*/,/\(\s*/,n,/\s*\)/]},{match:[/\bclass/,/\s+/,n]}],scope:{1:"keyword",3:"title.class",6:"title.class.inherited"}},{className:"meta",begin:/^[\t ]*@/,end:/(?=#)|$/,contains:[k,E,m]}]}}function hB(t){return{aliases:["pycon"],contains:[{className:"meta.prompt",starts:{end:/ |$/,starts:{end:"$",subLanguage:"python"}},variants:[{begin:/^>>>(?=[ ]|$)/},{begin:/^\.\.\.(?=[ ]|$)/}]}]}}function pB(t){const e=t.regex,n=/(?:(?:[a-zA-Z]|\.[._a-zA-Z])[._a-zA-Z0-9]*)|\.(?!\d)/,r=e.either(/0[xX][0-9a-fA-F]+\.[0-9a-fA-F]*[pP][+-]?\d+i?/,/0[xX][0-9a-fA-F]+(?:[pP][+-]?\d+)?[Li]?/,/(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?[Li]?/),s=/[=!<>:]=|\|\||&&|:::?|<-|<<-|->>|->|\|>|[-+*\/?!$&|:<=>@^~]|\*\*/,i=e.either(/[()]/,/[{}]/,/\[\[/,/[[\]]/,/\\/,/,/);return{name:"R",keywords:{$pattern:n,keyword:"function if in break next repeat else for while",literal:"NULL NA TRUE FALSE Inf NaN NA_integer_|10 NA_real_|10 NA_character_|10 NA_complex_|10",built_in:"LETTERS letters month.abb month.name pi T F abs acos acosh all any anyNA Arg as.call as.character as.complex as.double as.environment as.integer as.logical as.null.default as.numeric as.raw asin asinh atan atanh attr attributes baseenv browser c call ceiling class Conj cos cosh cospi cummax cummin cumprod cumsum digamma dim dimnames emptyenv exp expression floor forceAndCall gamma gc.time globalenv Im interactive invisible is.array is.atomic is.call is.character is.complex is.double is.environment is.expression is.finite is.function is.infinite is.integer is.language is.list is.logical is.matrix is.na is.name is.nan is.null is.numeric is.object is.pairlist is.raw is.recursive is.single is.symbol lazyLoadDBfetch length lgamma list log max min missing Mod names nargs nzchar oldClass on.exit pos.to.env proc.time prod quote range Re rep retracemem return round seq_along seq_len seq.int sign signif sin sinh sinpi sqrt standardGeneric substitute sum switch tan tanh tanpi tracemem trigamma trunc unclass untracemem UseMethod xtfrm"},contains:[t.COMMENT(/#'/,/$/,{contains:[{scope:"doctag",match:/@examples/,starts:{end:e.lookahead(e.either(/\n^#'\s*(?=@[a-zA-Z]+)/,/\n^(?!#')/)),endsParent:!0}},{scope:"doctag",begin:"@param",end:/$/,contains:[{scope:"variable",variants:[{match:n},{match:/`(?:\\.|[^`\\])+`/}],endsParent:!0}]},{scope:"doctag",match:/@[a-zA-Z]+/},{scope:"keyword",match:/\\[a-zA-Z]+/}]}),t.HASH_COMMENT_MODE,{scope:"string",contains:[t.BACKSLASH_ESCAPE],variants:[t.END_SAME_AS_BEGIN({begin:/[rR]"(-*)\(/,end:/\)(-*)"/}),t.END_SAME_AS_BEGIN({begin:/[rR]"(-*)\{/,end:/\}(-*)"/}),t.END_SAME_AS_BEGIN({begin:/[rR]"(-*)\[/,end:/\](-*)"/}),t.END_SAME_AS_BEGIN({begin:/[rR]'(-*)\(/,end:/\)(-*)'/}),t.END_SAME_AS_BEGIN({begin:/[rR]'(-*)\{/,end:/\}(-*)'/}),t.END_SAME_AS_BEGIN({begin:/[rR]'(-*)\[/,end:/\](-*)'/}),{begin:'"',end:'"',relevance:0},{begin:"'",end:"'",relevance:0}]},{relevance:0,variants:[{scope:{1:"operator",2:"number"},match:[s,r]},{scope:{1:"operator",2:"number"},match:[/%[^%]*%/,r]},{scope:{1:"punctuation",2:"number"},match:[i,r]},{scope:{2:"number"},match:[/[^a-zA-Z0-9._]|^/,r]}]},{scope:{3:"operator"},match:[n,/\s+/,/<-/,/\s+/]},{scope:"operator",relevance:0,variants:[{match:s},{match:/%[^%]*%/}]},{scope:"punctuation",relevance:0,match:i},{begin:"`",end:"`",contains:[{begin:/\\./}]}]}}function mB(t){const e=t.regex,n="([a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?)",r=e.either(/\b([A-Z]+[a-z0-9]+)+/,/\b([A-Z]+[a-z0-9]+)+[A-Z]+/),s=e.concat(r,/(::\w+)*/),o={"variable.constant":["__FILE__","__LINE__","__ENCODING__"],"variable.language":["self","super"],keyword:["alias","and","begin","BEGIN","break","case","class","defined","do","else","elsif","end","END","ensure","for","if","in","module","next","not","or","redo","require","rescue","retry","return","then","undef","unless","until","when","while","yield",...["include","extend","prepend","public","private","protected","raise","throw"]],built_in:["proc","lambda","attr_accessor","attr_reader","attr_writer","define_method","private_constant","module_function"],literal:["true","false","nil"]},l={className:"doctag",begin:"@[A-Za-z]+"},d={begin:"#<",end:">"},f=[t.COMMENT("#","$",{contains:[l]}),t.COMMENT("^=begin","^=end",{contains:[l],relevance:10}),t.COMMENT("^__END__",t.MATCH_NOTHING_RE)],h={className:"subst",begin:/#\{/,end:/\}/,keywords:o},m={className:"string",contains:[t.BACKSLASH_ESCAPE,h],variants:[{begin:/'/,end:/'/},{begin:/"/,end:/"/},{begin:/`/,end:/`/},{begin:/%[qQwWx]?\(/,end:/\)/},{begin:/%[qQwWx]?\[/,end:/\]/},{begin:/%[qQwWx]?\{/,end:/\}/},{begin:/%[qQwWx]?</,end:/>/},{begin:/%[qQwWx]?\//,end:/\//},{begin:/%[qQwWx]?%/,end:/%/},{begin:/%[qQwWx]?-/,end:/-/},{begin:/%[qQwWx]?\|/,end:/\|/},{begin:/\B\?(\\\d{1,3})/},{begin:/\B\?(\\x[A-Fa-f0-9]{1,2})/},{begin:/\B\?(\\u\{?[A-Fa-f0-9]{1,6}\}?)/},{begin:/\B\?(\\M-\\C-|\\M-\\c|\\c\\M-|\\M-|\\C-\\M-)[\x20-\x7e]/},{begin:/\B\?\\(c|C-)[\x20-\x7e]/},{begin:/\B\?\\?\S/},{begin:e.concat(/<<[-~]?'?/,e.lookahead(/(\w+)(?=\W)[^\n]*\n(?:[^\n]*\n)*?\s*\1\b/)),contains:[t.END_SAME_AS_BEGIN({begin:/(\w+)/,end:/(\w+)/,contains:[t.BACKSLASH_ESCAPE,h]})]}]},g="[1-9](_?[0-9])*|0",v="[0-9](_?[0-9])*",b={className:"number",relevance:0,variants:[{begin:`\\b(${g})(\\.(${v}))?([eE][+-]?(${v})|r)?i?\\b`},{begin:"\\b0[dD][0-9](_?[0-9])*r?i?\\b"},{begin:"\\b0[bB][0-1](_?[0-1])*r?i?\\b"},{begin:"\\b0[oO][0-7](_?[0-7])*r?i?\\b"},{begin:"\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*r?i?\\b"},{begin:"\\b0(_?[0-7])+r?i?\\b"}]},k={variants:[{match:/\(\)/},{className:"params",begin:/\(/,end:/(?=\))/,excludeBegin:!0,endsParent:!0,keywords:o}]},A=[m,{variants:[{match:[/class\s+/,s,/\s+<\s+/,s]},{match:[/\b(class|module)\s+/,s]}],scope:{2:"title.class",4:"title.class.inherited"},keywords:o},{match:[/(include|extend)\s+/,s],scope:{2:"title.class"},keywords:o},{relevance:0,match:[s,/\.new[. (]/],scope:{1:"title.class"}},{relevance:0,match:/\b[A-Z][A-Z_0-9]+\b/,className:"variable.constant"},{relevance:0,match:r,scope:"title.class"},{match:[/def/,/\s+/,n],scope:{1:"keyword",3:"title.function"},contains:[k]},{begin:t.IDENT_RE+"::"},{className:"symbol",begin:t.UNDERSCORE_IDENT_RE+"(!|\\?)?:",relevance:0},{className:"symbol",begin:":(?!\\s)",contains:[m,{begin:n}],relevance:0},b,{className:"variable",begin:"(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])(?![A-Za-z])(?![@$?'])"},{className:"params",begin:/\|(?!=)/,end:/\|/,excludeBegin:!0,excludeEnd:!0,relevance:0,keywords:o},{begin:"("+t.RE_STARTERS_RE+"|unless)\\s*",keywords:"unless",contains:[{className:"regexp",contains:[t.BACKSLASH_ESCAPE,h],illegal:/\n/,variants:[{begin:"/",end:"/[a-z]*"},{begin:/%r\{/,end:/\}[a-z]*/},{begin:"%r\\(",end:"\\)[a-z]*"},{begin:"%r!",end:"![a-z]*"},{begin:"%r\\[",end:"\\][a-z]*"}]}].concat(d,f),relevance:0}].concat(d,f);h.contains=A,k.contains=A;const W=[{begin:/^\s*=>/,starts:{end:"$",contains:A}},{className:"meta.prompt",begin:"^("+"[>?]>"+"|"+"[\\w#]+\\(\\w+\\):\\d+:\\d+[>*]"+"|"+"(\\w+-)?\\d+\\.\\d+\\.\\d+(p\\d+)?[^\\d][^>]+>"+")(?=[ ])",starts:{end:"$",keywords:o,contains:A}}];return f.unshift(d),{name:"Ruby",aliases:["rb","gemspec","podspec","thor","irb"],keywords:o,illegal:/\/\*/,contains:[t.SHEBANG({binary:"ruby"})].concat(W).concat(f).concat(A)}}function gB(t){const e=t.regex,n=/(r#)?/,r=e.concat(n,t.UNDERSCORE_IDENT_RE),s=e.concat(n,t.IDENT_RE),i={className:"title.function.invoke",relevance:0,begin:e.concat(/\b/,/(?!let|for|while|if|else|match\b)/,s,e.lookahead(/\s*\(/))},o="([ui](8|16|32|64|128|size)|f(32|64))?",l=["abstract","as","async","await","become","box","break","const","continue","crate","do","dyn","else","enum","extern","false","final","fn","for","if","impl","in","let","loop","macro","match","mod","move","mut","override","priv","pub","ref","return","self","Self","static","struct","super","trait","true","try","type","typeof","union","unsafe","unsized","use","virtual","where","while","yield"],d=["true","false","Some","None","Ok","Err"],f=["drop ","Copy","Send","Sized","Sync","Drop","Fn","FnMut","FnOnce","ToOwned","Clone","Debug","PartialEq","PartialOrd","Eq","Ord","AsRef","AsMut","Into","From","Default","Iterator","Extend","IntoIterator","DoubleEndedIterator","ExactSizeIterator","SliceConcatExt","ToString","assert!","assert_eq!","bitflags!","bytes!","cfg!","col!","concat!","concat_idents!","debug_assert!","debug_assert_eq!","env!","eprintln!","panic!","file!","format!","format_args!","include_bytes!","include_str!","line!","local_data_key!","module_path!","option_env!","print!","println!","select!","stringify!","try!","unimplemented!","unreachable!","vec!","write!","writeln!","macro_rules!","assert_ne!","debug_assert_ne!"],h=["i8","i16","i32","i64","i128","isize","u8","u16","u32","u64","u128","usize","f32","f64","str","char","bool","Box","Option","Result","String","Vec"];return{name:"Rust",aliases:["rs"],keywords:{$pattern:t.IDENT_RE+"!?",type:h,keyword:l,literal:d,built_in:f},illegal:"</",contains:[t.C_LINE_COMMENT_MODE,t.COMMENT("/\\*","\\*/",{contains:["self"]}),t.inherit(t.QUOTE_STRING_MODE,{begin:/b?"/,illegal:null}),{className:"symbol",begin:/'[a-zA-Z_][a-zA-Z0-9_]*(?!')/},{scope:"string",variants:[{begin:/b?r(#*)"(.|\n)*?"\1(?!#)/},{begin:/b?'/,end:/'/,contains:[{scope:"char.escape",match:/\\('|\w|x\w{2}|u\w{4}|U\w{8})/}]}]},{className:"number",variants:[{begin:"\\b0b([01_]+)"+o},{begin:"\\b0o([0-7_]+)"+o},{begin:"\\b0x([A-Fa-f0-9_]+)"+o},{begin:"\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)"+o}],relevance:0},{begin:[/fn/,/\s+/,r],className:{1:"keyword",3:"title.function"}},{className:"meta",begin:"#!?\\[",end:"\\]",contains:[{className:"string",begin:/"/,end:/"/,contains:[t.BACKSLASH_ESCAPE]}]},{begin:[/let/,/\s+/,/(?:mut\s+)?/,r],className:{1:"keyword",3:"keyword",4:"variable"}},{begin:[/for/,/\s+/,r,/\s+/,/in/],className:{1:"keyword",3:"variable",5:"keyword"}},{begin:[/type/,/\s+/,r],className:{1:"keyword",3:"title.class"}},{begin:[/(?:trait|enum|struct|union|impl|for)/,/\s+/,r],className:{1:"keyword",3:"title.class"}},{begin:t.IDENT_RE+"::",keywords:{keyword:"Self",built_in:f,type:h}},{className:"punctuation",begin:"->"},i]}}const vB=t=>({IMPORTANT:{scope:"meta",begin:"!important"},BLOCK_COMMENT:t.C_BLOCK_COMMENT_MODE,HEXCOLOR:{scope:"number",begin:/#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/},FUNCTION_DISPATCH:{className:"built_in",begin:/[\w-]+(?=\()/},ATTRIBUTE_SELECTOR_MODE:{scope:"selector-attr",begin:/\[/,end:/\]/,illegal:"$",contains:[t.APOS_STRING_MODE,t.QUOTE_STRING_MODE]},CSS_NUMBER_MODE:{scope:"number",begin:t.NUMBER_RE+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",relevance:0},CSS_VARIABLE:{className:"attr",begin:/--[A-Za-z_][A-Za-z0-9_-]*/}}),yB=["a","abbr","address","article","aside","audio","b","blockquote","body","button","canvas","caption","cite","code","dd","del","details","dfn","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","html","i","iframe","img","input","ins","kbd","label","legend","li","main","mark","menu","nav","object","ol","optgroup","option","p","picture","q","quote","samp","section","select","source","span","strong","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","tr","ul","var","video"],bB=["defs","g","marker","mask","pattern","svg","switch","symbol","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feFlood","feGaussianBlur","feImage","feMerge","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence","linearGradient","radialGradient","stop","circle","ellipse","image","line","path","polygon","polyline","rect","text","use","textPath","tspan","foreignObject","clipPath"],xB=[...yB,...bB],wB=["any-hover","any-pointer","aspect-ratio","color","color-gamut","color-index","device-aspect-ratio","device-height","device-width","display-mode","forced-colors","grid","height","hover","inverted-colors","monochrome","orientation","overflow-block","overflow-inline","pointer","prefers-color-scheme","prefers-contrast","prefers-reduced-motion","prefers-reduced-transparency","resolution","scan","scripting","update","width","min-width","max-width","min-height","max-height"].sort().reverse(),kB=["active","any-link","blank","checked","current","default","defined","dir","disabled","drop","empty","enabled","first","first-child","first-of-type","fullscreen","future","focus","focus-visible","focus-within","has","host","host-context","hover","indeterminate","in-range","invalid","is","lang","last-child","last-of-type","left","link","local-link","not","nth-child","nth-col","nth-last-child","nth-last-col","nth-last-of-type","nth-of-type","only-child","only-of-type","optional","out-of-range","past","placeholder-shown","read-only","read-write","required","right","root","scope","target","target-within","user-invalid","valid","visited","where"].sort().reverse(),SB=["after","backdrop","before","cue","cue-region","first-letter","first-line","grammar-error","marker","part","placeholder","selection","slotted","spelling-error"].sort().reverse(),EB=["accent-color","align-content","align-items","align-self","alignment-baseline","all","anchor-name","animation","animation-composition","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-range","animation-range-end","animation-range-start","animation-timeline","animation-timing-function","appearance","aspect-ratio","backdrop-filter","backface-visibility","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-origin","background-position","background-position-x","background-position-y","background-repeat","background-size","baseline-shift","block-size","border","border-block","border-block-color","border-block-end","border-block-end-color","border-block-end-style","border-block-end-width","border-block-start","border-block-start-color","border-block-start-style","border-block-start-width","border-block-style","border-block-width","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-end-end-radius","border-end-start-radius","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-inline","border-inline-color","border-inline-end","border-inline-end-color","border-inline-end-style","border-inline-end-width","border-inline-start","border-inline-start-color","border-inline-start-style","border-inline-start-width","border-inline-style","border-inline-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-start-end-radius","border-start-start-radius","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-align","box-decoration-break","box-direction","box-flex","box-flex-group","box-lines","box-ordinal-group","box-orient","box-pack","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","caret-color","clear","clip","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","color-scheme","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","contain-intrinsic-block-size","contain-intrinsic-height","contain-intrinsic-inline-size","contain-intrinsic-size","contain-intrinsic-width","container","container-name","container-type","content","content-visibility","counter-increment","counter-reset","counter-set","cue","cue-after","cue-before","cursor","cx","cy","direction","display","dominant-baseline","empty-cells","enable-background","field-sizing","fill","fill-opacity","fill-rule","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","flood-color","flood-opacity","flow","font","font-display","font-family","font-feature-settings","font-kerning","font-language-override","font-optical-sizing","font-palette","font-size","font-size-adjust","font-smooth","font-smoothing","font-stretch","font-style","font-synthesis","font-synthesis-position","font-synthesis-small-caps","font-synthesis-style","font-synthesis-weight","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-emoji","font-variant-ligatures","font-variant-numeric","font-variant-position","font-variation-settings","font-weight","forced-color-adjust","gap","glyph-orientation-horizontal","glyph-orientation-vertical","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-gap","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphenate-character","hyphenate-limit-chars","hyphens","icon","image-orientation","image-rendering","image-resolution","ime-mode","initial-letter","initial-letter-align","inline-size","inset","inset-area","inset-block","inset-block-end","inset-block-start","inset-inline","inset-inline-end","inset-inline-start","isolation","justify-content","justify-items","justify-self","kerning","left","letter-spacing","lighting-color","line-break","line-height","line-height-step","list-style","list-style-image","list-style-position","list-style-type","margin","margin-block","margin-block-end","margin-block-start","margin-bottom","margin-inline","margin-inline-end","margin-inline-start","margin-left","margin-right","margin-top","margin-trim","marker","marker-end","marker-mid","marker-start","marks","mask","mask-border","mask-border-mode","mask-border-outset","mask-border-repeat","mask-border-slice","mask-border-source","mask-border-width","mask-clip","mask-composite","mask-image","mask-mode","mask-origin","mask-position","mask-repeat","mask-size","mask-type","masonry-auto-flow","math-depth","math-shift","math-style","max-block-size","max-height","max-inline-size","max-width","min-block-size","min-height","min-inline-size","min-width","mix-blend-mode","nav-down","nav-index","nav-left","nav-right","nav-up","none","normal","object-fit","object-position","offset","offset-anchor","offset-distance","offset-path","offset-position","offset-rotate","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-anchor","overflow-block","overflow-clip-margin","overflow-inline","overflow-wrap","overflow-x","overflow-y","overlay","overscroll-behavior","overscroll-behavior-block","overscroll-behavior-inline","overscroll-behavior-x","overscroll-behavior-y","padding","padding-block","padding-block-end","padding-block-start","padding-bottom","padding-inline","padding-inline-end","padding-inline-start","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","paint-order","pause","pause-after","pause-before","perspective","perspective-origin","place-content","place-items","place-self","pointer-events","position","position-anchor","position-visibility","print-color-adjust","quotes","r","resize","rest","rest-after","rest-before","right","rotate","row-gap","ruby-align","ruby-position","scale","scroll-behavior","scroll-margin","scroll-margin-block","scroll-margin-block-end","scroll-margin-block-start","scroll-margin-bottom","scroll-margin-inline","scroll-margin-inline-end","scroll-margin-inline-start","scroll-margin-left","scroll-margin-right","scroll-margin-top","scroll-padding","scroll-padding-block","scroll-padding-block-end","scroll-padding-block-start","scroll-padding-bottom","scroll-padding-inline","scroll-padding-inline-end","scroll-padding-inline-start","scroll-padding-left","scroll-padding-right","scroll-padding-top","scroll-snap-align","scroll-snap-stop","scroll-snap-type","scroll-timeline","scroll-timeline-axis","scroll-timeline-name","scrollbar-color","scrollbar-gutter","scrollbar-width","shape-image-threshold","shape-margin","shape-outside","shape-rendering","speak","speak-as","src","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","tab-size","table-layout","text-align","text-align-all","text-align-last","text-anchor","text-combine-upright","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-indent","text-justify","text-orientation","text-overflow","text-rendering","text-shadow","text-size-adjust","text-transform","text-underline-offset","text-underline-position","text-wrap","text-wrap-mode","text-wrap-style","timeline-scope","top","touch-action","transform","transform-box","transform-origin","transform-style","transition","transition-behavior","transition-delay","transition-duration","transition-property","transition-timing-function","translate","unicode-bidi","user-modify","user-select","vector-effect","vertical-align","view-timeline","view-timeline-axis","view-timeline-inset","view-timeline-name","view-transition-name","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","white-space","white-space-collapse","widows","width","will-change","word-break","word-spacing","word-wrap","writing-mode","x","y","z-index","zoom"].sort().reverse();function NB(t){const e=vB(t),n=SB,r=kB,s="@[a-z-]+",i="and or not only",l={className:"variable",begin:"(\\$"+"[a-zA-Z-][a-zA-Z0-9_-]*"+")\\b",relevance:0};return{name:"SCSS",case_insensitive:!0,illegal:"[=/|']",contains:[t.C_LINE_COMMENT_MODE,t.C_BLOCK_COMMENT_MODE,e.CSS_NUMBER_MODE,{className:"selector-id",begin:"#[A-Za-z0-9_-]+",relevance:0},{className:"selector-class",begin:"\\.[A-Za-z0-9_-]+",relevance:0},e.ATTRIBUTE_SELECTOR_MODE,{className:"selector-tag",begin:"\\b("+xB.join("|")+")\\b",relevance:0},{className:"selector-pseudo",begin:":("+r.join("|")+")"},{className:"selector-pseudo",begin:":(:)?("+n.join("|")+")"},l,{begin:/\(/,end:/\)/,contains:[e.CSS_NUMBER_MODE]},e.CSS_VARIABLE,{className:"attribute",begin:"\\b("+EB.join("|")+")\\b"},{begin:"\\b(whitespace|wait|w-resize|visible|vertical-text|vertical-ideographic|uppercase|upper-roman|upper-alpha|underline|transparent|top|thin|thick|text|text-top|text-bottom|tb-rl|table-header-group|table-footer-group|sw-resize|super|strict|static|square|solid|small-caps|separate|se-resize|scroll|s-resize|rtl|row-resize|ridge|right|repeat|repeat-y|repeat-x|relative|progress|pointer|overline|outside|outset|oblique|nowrap|not-allowed|normal|none|nw-resize|no-repeat|no-drop|newspaper|ne-resize|n-resize|move|middle|medium|ltr|lr-tb|lowercase|lower-roman|lower-alpha|loose|list-item|line|line-through|line-edge|lighter|left|keep-all|justify|italic|inter-word|inter-ideograph|inside|inset|inline|inline-block|inherit|inactive|ideograph-space|ideograph-parenthesis|ideograph-numeric|ideograph-alpha|horizontal|hidden|help|hand|groove|fixed|ellipsis|e-resize|double|dotted|distribute|distribute-space|distribute-letter|distribute-all-lines|disc|disabled|default|decimal|dashed|crosshair|collapse|col-resize|circle|char|center|capitalize|break-word|break-all|bottom|both|bolder|bold|block|bidi-override|below|baseline|auto|always|all-scroll|absolute|table|table-cell)\\b"},{begin:/:/,end:/[;}{]/,relevance:0,contains:[e.BLOCK_COMMENT,l,e.HEXCOLOR,e.CSS_NUMBER_MODE,t.QUOTE_STRING_MODE,t.APOS_STRING_MODE,e.IMPORTANT,e.FUNCTION_DISPATCH]},{begin:"@(page|font-face)",keywords:{$pattern:s,keyword:"@page @font-face"}},{begin:"@",end:"[{;]",returnBegin:!0,keywords:{$pattern:/[a-z-]+/,keyword:i,attribute:wB.join(" ")},contains:[{begin:s,className:"keyword"},{begin:/[a-z-]+(?=:)/,className:"attribute"},l,t.QUOTE_STRING_MODE,t.APOS_STRING_MODE,e.HEXCOLOR,e.CSS_NUMBER_MODE]},e.FUNCTION_DISPATCH]}}function CB(t){return{name:"Shell Session",aliases:["console","shellsession"],contains:[{className:"meta.prompt",begin:/^\s{0,3}[/~\w\d[\]()@-]*[>%$#][ ]?/,starts:{end:/[^\\](?=\s*$)/,subLanguage:"bash"}}]}}function _B(t){const e=t.regex,n=t.COMMENT("--","$"),r={scope:"string",variants:[{begin:/'/,end:/'/,contains:[{match:/''/}]}]},s={begin:/"/,end:/"/,contains:[{match:/""/}]},i=["true","false","unknown"],o=["double precision","large object","with timezone","without timezone"],l=["bigint","binary","blob","boolean","char","character","clob","date","dec","decfloat","decimal","float","int","integer","interval","nchar","nclob","national","numeric","real","row","smallint","time","timestamp","varchar","varying","varbinary"],d=["add","asc","collation","desc","final","first","last","view"],f=["abs","acos","all","allocate","alter","and","any","are","array","array_agg","array_max_cardinality","as","asensitive","asin","asymmetric","at","atan","atomic","authorization","avg","begin","begin_frame","begin_partition","between","bigint","binary","blob","boolean","both","by","call","called","cardinality","cascaded","case","cast","ceil","ceiling","char","char_length","character","character_length","check","classifier","clob","close","coalesce","collate","collect","column","commit","condition","connect","constraint","contains","convert","copy","corr","corresponding","cos","cosh","count","covar_pop","covar_samp","create","cross","cube","cume_dist","current","current_catalog","current_date","current_default_transform_group","current_path","current_role","current_row","current_schema","current_time","current_timestamp","current_path","current_role","current_transform_group_for_type","current_user","cursor","cycle","date","day","deallocate","dec","decimal","decfloat","declare","default","define","delete","dense_rank","deref","describe","deterministic","disconnect","distinct","double","drop","dynamic","each","element","else","empty","end","end_frame","end_partition","end-exec","equals","escape","every","except","exec","execute","exists","exp","external","extract","false","fetch","filter","first_value","float","floor","for","foreign","frame_row","free","from","full","function","fusion","get","global","grant","group","grouping","groups","having","hold","hour","identity","in","indicator","initial","inner","inout","insensitive","insert","int","integer","intersect","intersection","interval","into","is","join","json_array","json_arrayagg","json_exists","json_object","json_objectagg","json_query","json_table","json_table_primitive","json_value","lag","language","large","last_value","lateral","lead","leading","left","like","like_regex","listagg","ln","local","localtime","localtimestamp","log","log10","lower","match","match_number","match_recognize","matches","max","member","merge","method","min","minute","mod","modifies","module","month","multiset","national","natural","nchar","nclob","new","no","none","normalize","not","nth_value","ntile","null","nullif","numeric","octet_length","occurrences_regex","of","offset","old","omit","on","one","only","open","or","order","out","outer","over","overlaps","overlay","parameter","partition","pattern","per","percent","percent_rank","percentile_cont","percentile_disc","period","portion","position","position_regex","power","precedes","precision","prepare","primary","procedure","ptf","range","rank","reads","real","recursive","ref","references","referencing","regr_avgx","regr_avgy","regr_count","regr_intercept","regr_r2","regr_slope","regr_sxx","regr_sxy","regr_syy","release","result","return","returns","revoke","right","rollback","rollup","row","row_number","rows","running","savepoint","scope","scroll","search","second","seek","select","sensitive","session_user","set","show","similar","sin","sinh","skip","smallint","some","specific","specifictype","sql","sqlexception","sqlstate","sqlwarning","sqrt","start","static","stddev_pop","stddev_samp","submultiset","subset","substring","substring_regex","succeeds","sum","symmetric","system","system_time","system_user","table","tablesample","tan","tanh","then","time","timestamp","timezone_hour","timezone_minute","to","trailing","translate","translate_regex","translation","treat","trigger","trim","trim_array","true","truncate","uescape","union","unique","unknown","unnest","update","upper","user","using","value","values","value_of","var_pop","var_samp","varbinary","varchar","varying","versioning","when","whenever","where","width_bucket","window","with","within","without","year"],h=["abs","acos","array_agg","asin","atan","avg","cast","ceil","ceiling","coalesce","corr","cos","cosh","count","covar_pop","covar_samp","cume_dist","dense_rank","deref","element","exp","extract","first_value","floor","json_array","json_arrayagg","json_exists","json_object","json_objectagg","json_query","json_table","json_table_primitive","json_value","lag","last_value","lead","listagg","ln","log","log10","lower","max","min","mod","nth_value","ntile","nullif","percent_rank","percentile_cont","percentile_disc","position","position_regex","power","rank","regr_avgx","regr_avgy","regr_count","regr_intercept","regr_r2","regr_slope","regr_sxx","regr_sxy","regr_syy","row_number","sin","sinh","sqrt","stddev_pop","stddev_samp","substring","substring_regex","sum","tan","tanh","translate","translate_regex","treat","trim","trim_array","unnest","upper","value_of","var_pop","var_samp","width_bucket"],m=["current_catalog","current_date","current_default_transform_group","current_path","current_role","current_schema","current_transform_group_for_type","current_user","session_user","system_time","system_user","current_time","localtime","current_timestamp","localtimestamp"],g=["create table","insert into","primary key","foreign key","not null","alter table","add constraint","grouping sets","on overflow","character set","respect nulls","ignore nulls","nulls first","nulls last","depth first","breadth first"],v=h,b=[...f,...d].filter(_=>!h.includes(_)),k={scope:"variable",match:/@[a-z0-9][a-z0-9_]*/},w={scope:"operator",match:/[-+*/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?/,relevance:0},E={match:e.concat(/\b/,e.either(...v),/\s*\(/),relevance:0,keywords:{built_in:v}};function C(_){return e.concat(/\b/,e.either(..._.map(A=>A.replace(/\s+/,"\\s+"))),/\b/)}const T={scope:"keyword",match:C(g),relevance:0};function j(_,{exceptions:A,when:O}={}){const B=O;return A=A||[],_.map($=>$.match(/\|\d+$/)||A.includes($)?$:B($)?`${$}|0`:$)}return{name:"SQL",case_insensitive:!0,illegal:/[{}]|<\//,keywords:{$pattern:/\b[\w\.]+/,keyword:j(b,{when:_=>_.length<3}),literal:i,type:l,built_in:m},contains:[{scope:"type",match:C(o)},T,E,k,r,s,t.C_NUMBER_MODE,t.C_BLOCK_COMMENT_MODE,n,w]}}function W_(t){return t?typeof t=="string"?t:t.source:null}function Ja(t){return Yt("(?=",t,")")}function Yt(...t){return t.map(n=>W_(n)).join("")}function TB(t){const e=t[t.length-1];return typeof e=="object"&&e.constructor===Object?(t.splice(t.length-1,1),e):{}}function or(...t){return"("+(TB(t).capture?"":"?:")+t.map(r=>W_(r)).join("|")+")"}const Jv=t=>Yt(/\b/,t,/\w$/.test(t)?/\b/:/\B/),jB=["Protocol","Type"].map(Jv),Qw=["init","self"].map(Jv),MB=["Any","Self"],Np=["actor","any","associatedtype","async","await",/as\?/,/as!/,"as","borrowing","break","case","catch","class","consume","consuming","continue","convenience","copy","default","defer","deinit","didSet","distributed","do","dynamic","each","else","enum","extension","fallthrough",/fileprivate\(set\)/,"fileprivate","final","for","func","get","guard","if","import","indirect","infix",/init\?/,/init!/,"inout",/internal\(set\)/,"internal","in","is","isolated","nonisolated","lazy","let","macro","mutating","nonmutating",/open\(set\)/,"open","operator","optional","override","package","postfix","precedencegroup","prefix",/private\(set\)/,"private","protocol",/public\(set\)/,"public","repeat","required","rethrows","return","set","some","static","struct","subscript","super","switch","throws","throw",/try\?/,/try!/,"try","typealias",/unowned\(safe\)/,/unowned\(unsafe\)/,"unowned","var","weak","where","while","willSet"],Zw=["false","nil","true"],AB=["assignment","associativity","higherThan","left","lowerThan","none","right"],RB=["#colorLiteral","#column","#dsohandle","#else","#elseif","#endif","#error","#file","#fileID","#fileLiteral","#filePath","#function","#if","#imageLiteral","#keyPath","#line","#selector","#sourceLocation","#warning"],ek=["abs","all","any","assert","assertionFailure","debugPrint","dump","fatalError","getVaList","isKnownUniquelyReferenced","max","min","numericCast","pointwiseMax","pointwiseMin","precondition","preconditionFailure","print","readLine","repeatElement","sequence","stride","swap","swift_unboxFromSwiftValueWithType","transcode","type","unsafeBitCast","unsafeDowncast","withExtendedLifetime","withUnsafeMutablePointer","withUnsafePointer","withVaList","withoutActuallyEscaping","zip"],q_=or(/[/=\-+!*%<>&|^~?]/,/[\u00A1-\u00A7]/,/[\u00A9\u00AB]/,/[\u00AC\u00AE]/,/[\u00B0\u00B1]/,/[\u00B6\u00BB\u00BF\u00D7\u00F7]/,/[\u2016-\u2017]/,/[\u2020-\u2027]/,/[\u2030-\u203E]/,/[\u2041-\u2053]/,/[\u2055-\u205E]/,/[\u2190-\u23FF]/,/[\u2500-\u2775]/,/[\u2794-\u2BFF]/,/[\u2E00-\u2E7F]/,/[\u3001-\u3003]/,/[\u3008-\u3020]/,/[\u3030]/),V_=or(q_,/[\u0300-\u036F]/,/[\u1DC0-\u1DFF]/,/[\u20D0-\u20FF]/,/[\uFE00-\uFE0F]/,/[\uFE20-\uFE2F]/),Cp=Yt(q_,V_,"*"),K_=or(/[a-zA-Z_]/,/[\u00A8\u00AA\u00AD\u00AF\u00B2-\u00B5\u00B7-\u00BA]/,/[\u00BC-\u00BE\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]/,/[\u0100-\u02FF\u0370-\u167F\u1681-\u180D\u180F-\u1DBF]/,/[\u1E00-\u1FFF]/,/[\u200B-\u200D\u202A-\u202E\u203F-\u2040\u2054\u2060-\u206F]/,/[\u2070-\u20CF\u2100-\u218F\u2460-\u24FF\u2776-\u2793]/,/[\u2C00-\u2DFF\u2E80-\u2FFF]/,/[\u3004-\u3007\u3021-\u302F\u3031-\u303F\u3040-\uD7FF]/,/[\uF900-\uFD3D\uFD40-\uFDCF\uFDF0-\uFE1F\uFE30-\uFE44]/,/[\uFE47-\uFEFE\uFF00-\uFFFD]/),Ed=or(K_,/\d/,/[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/),hs=Yt(K_,Ed,"*"),fu=Yt(/[A-Z]/,Ed,"*"),OB=["attached","autoclosure",Yt(/convention\(/,or("swift","block","c"),/\)/),"discardableResult","dynamicCallable","dynamicMemberLookup","escaping","freestanding","frozen","GKInspectable","IBAction","IBDesignable","IBInspectable","IBOutlet","IBSegueAction","inlinable","main","nonobjc","NSApplicationMain","NSCopying","NSManaged",Yt(/objc\(/,hs,/\)/),"objc","objcMembers","propertyWrapper","requires_stored_property_inits","resultBuilder","Sendable","testable","UIApplicationMain","unchecked","unknown","usableFromInline","warn_unqualified_access"],IB=["iOS","iOSApplicationExtension","macOS","macOSApplicationExtension","macCatalyst","macCatalystApplicationExtension","watchOS","watchOSApplicationExtension","tvOS","tvOSApplicationExtension","swift"];function LB(t){const e={match:/\s+/,relevance:0},n=t.COMMENT("/\\*","\\*/",{contains:["self"]}),r=[t.C_LINE_COMMENT_MODE,n],s={match:[/\./,or(...jB,...Qw)],className:{2:"keyword"}},i={match:Yt(/\./,or(...Np)),relevance:0},o=Np.filter(pe=>typeof pe=="string").concat(["_|0"]),l=Np.filter(pe=>typeof pe!="string").concat(MB).map(Jv),d={variants:[{className:"keyword",match:or(...l,...Qw)}]},f={$pattern:or(/\b\w+/,/#\w+/),keyword:o.concat(RB),literal:Zw},h=[s,i,d],m={match:Yt(/\./,or(...ek)),relevance:0},g={className:"built_in",match:Yt(/\b/,or(...ek),/(?=\()/)},v=[m,g],b={match:/->/,relevance:0},k={className:"operator",relevance:0,variants:[{match:Cp},{match:`\\.(\\.|${V_})+`}]},w=[b,k],E="([0-9]_*)+",C="([0-9a-fA-F]_*)+",T={className:"number",relevance:0,variants:[{match:`\\b(${E})(\\.(${E}))?([eE][+-]?(${E}))?\\b`},{match:`\\b0x(${C})(\\.(${C}))?([pP][+-]?(${E}))?\\b`},{match:/\b0o([0-7]_*)+\b/},{match:/\b0b([01]_*)+\b/}]},j=(pe="")=>({className:"subst",variants:[{match:Yt(/\\/,pe,/[0\\tnr"']/)},{match:Yt(/\\/,pe,/u\{[0-9a-fA-F]{1,8}\}/)}]}),_=(pe="")=>({className:"subst",match:Yt(/\\/,pe,/[\t ]*(?:[\r\n]|\r\n)/)}),A=(pe="")=>({className:"subst",label:"interpol",begin:Yt(/\\/,pe,/\(/),end:/\)/}),O=(pe="")=>({begin:Yt(pe,/"""/),end:Yt(/"""/,pe),contains:[j(pe),_(pe),A(pe)]}),B=(pe="")=>({begin:Yt(pe,/"/),end:Yt(/"/,pe),contains:[j(pe),A(pe)]}),$={className:"string",variants:[O(),O("#"),O("##"),O("###"),B(),B("#"),B("##"),B("###")]},W=[t.BACKSLASH_ESCAPE,{begin:/\[/,end:/\]/,relevance:0,contains:[t.BACKSLASH_ESCAPE]}],J={begin:/\/[^\s](?=[^/\n]*\/)/,end:/\//,contains:W},z=pe=>{const mt=Yt(pe,/\//),ft=Yt(/\//,pe);return{begin:mt,end:ft,contains:[...W,{scope:"comment",begin:`#(?!.*${ft})`,end:/$/}]}},G={scope:"regexp",variants:[z("###"),z("##"),z("#"),J]},D={match:Yt(/`/,hs,/`/)},U={className:"variable",match:/\$\d+/},q={className:"variable",match:`\\$${Ed}+`},se=[D,U,q],V={match:/(@|#(un)?)available/,scope:"keyword",starts:{contains:[{begin:/\(/,end:/\)/,keywords:IB,contains:[...w,T,$]}]}},te={scope:"keyword",match:Yt(/@/,or(...OB),Ja(or(/\(/,/\s+/)))},K={scope:"meta",match:Yt(/@/,hs)},M=[V,te,K],L={match:Ja(/\b[A-Z]/),relevance:0,contains:[{className:"type",match:Yt(/(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)/,Ed,"+")},{className:"type",match:fu,relevance:0},{match:/[?!]+/,relevance:0},{match:/\.\.\./,relevance:0},{match:Yt(/\s+&\s+/,Ja(fu)),relevance:0}]},ee={begin:/</,end:/>/,keywords:f,contains:[...r,...h,...M,b,L]};L.contains.push(ee);const fe={match:Yt(hs,/\s*:/),keywords:"_|0",relevance:0},ge={begin:/\(/,end:/\)/,relevance:0,keywords:f,contains:["self",fe,...r,G,...h,...v,...w,T,$,...se,...M,L]},oe={begin:/</,end:/>/,keywords:"repeat each",contains:[...r,L]},xe={begin:or(Ja(Yt(hs,/\s*:/)),Ja(Yt(hs,/\s+/,hs,/\s*:/))),end:/:/,relevance:0,contains:[{className:"keyword",match:/\b_\b/},{className:"params",match:hs}]},we={begin:/\(/,end:/\)/,keywords:f,contains:[xe,...r,...h,...w,T,$,...M,L,ge],endsParent:!0,illegal:/["']/},We={match:[/(func|macro)/,/\s+/,or(D.match,hs,Cp)],className:{1:"keyword",3:"title.function"},contains:[oe,we,e],illegal:[/\[/,/%/]},He={match:[/\b(?:subscript|init[?!]?)/,/\s*(?=[<(])/],className:{1:"keyword"},contains:[oe,we,e],illegal:/\[|%/},Ze={match:[/operator/,/\s+/,Cp],className:{1:"keyword",3:"title"}},Oe={begin:[/precedencegroup/,/\s+/,fu],className:{1:"keyword",3:"title"},contains:[L],keywords:[...AB,...Zw],end:/}/},Ke={match:[/class\b/,/\s+/,/func\b/,/\s+/,/\b[A-Za-z_][A-Za-z0-9_]*\b/],scope:{1:"keyword",3:"keyword",5:"title.function"}},pt={match:[/class\b/,/\s+/,/var\b/],scope:{1:"keyword",3:"keyword"}},Je={begin:[/(struct|protocol|class|extension|enum|actor)/,/\s+/,hs,/\s*/],beginScope:{1:"keyword",3:"title.class"},keywords:f,contains:[oe,...h,{begin:/:/,end:/\{/,keywords:f,contains:[{scope:"title.class.inherited",match:fu},...h],relevance:0}]};for(const pe of $.variants){const mt=pe.contains.find(at=>at.label==="interpol");mt.keywords=f;const ft=[...h,...v,...w,T,$,...se];mt.contains=[...ft,{begin:/\(/,end:/\)/,contains:["self",...ft]}]}return{name:"Swift",keywords:f,contains:[...r,We,He,Ke,pt,Je,Ze,Oe,{beginKeywords:"import",end:/$/,contains:[...r],relevance:0},G,...h,...v,...w,T,$,...se,...M,L,ge]}}const Nd="[A-Za-z$_][0-9A-Za-z$_]*",G_=["as","in","of","if","for","while","finally","var","new","function","do","return","void","else","break","catch","instanceof","with","throw","case","default","try","switch","continue","typeof","delete","let","yield","const","class","debugger","async","await","static","import","from","export","extends","using"],J_=["true","false","null","undefined","NaN","Infinity"],Y_=["Object","Function","Boolean","Symbol","Math","Date","Number","BigInt","String","RegExp","Array","Float32Array","Float64Array","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Int32Array","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array","Set","Map","WeakSet","WeakMap","ArrayBuffer","SharedArrayBuffer","Atomics","DataView","JSON","Promise","Generator","GeneratorFunction","AsyncFunction","Reflect","Proxy","Intl","WebAssembly"],X_=["Error","EvalError","InternalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError"],Q_=["setInterval","setTimeout","clearInterval","clearTimeout","require","exports","eval","isFinite","isNaN","parseFloat","parseInt","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","escape","unescape"],Z_=["arguments","this","super","console","window","document","localStorage","sessionStorage","module","global"],e2=[].concat(Q_,Y_,X_);function DB(t){const e=t.regex,n=(V,{after:te})=>{const K="</"+V[0].slice(1);return V.input.indexOf(K,te)!==-1},r=Nd,s={begin:"<>",end:"</>"},i=/<[A-Za-z0-9\\._:-]+\s*\/>/,o={begin:/<[A-Za-z0-9\\._:-]+/,end:/\/[A-Za-z0-9\\._:-]+>|\/>/,isTrulyOpeningTag:(V,te)=>{const K=V[0].length+V.index,M=V.input[K];if(M==="<"||M===","){te.ignoreMatch();return}M===">"&&(n(V,{after:K})||te.ignoreMatch());let L;const ee=V.input.substring(K);if(L=ee.match(/^\s*=/)){te.ignoreMatch();return}if((L=ee.match(/^\s+extends\s+/))&&L.index===0){te.ignoreMatch();return}}},l={$pattern:Nd,keyword:G_,literal:J_,built_in:e2,"variable.language":Z_},d="[0-9](_?[0-9])*",f=`\\.(${d})`,h="0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*",m={className:"number",variants:[{begin:`(\\b(${h})((${f})|\\.)?|(${f}))[eE][+-]?(${d})\\b`},{begin:`\\b(${h})\\b((${f})\\b|\\.)?|(${f})\\b`},{begin:"\\b(0|[1-9](_?[0-9])*)n\\b"},{begin:"\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b"},{begin:"\\b0[bB][0-1](_?[0-1])*n?\\b"},{begin:"\\b0[oO][0-7](_?[0-7])*n?\\b"},{begin:"\\b0[0-7]+n?\\b"}],relevance:0},g={className:"subst",begin:"\\$\\{",end:"\\}",keywords:l,contains:[]},v={begin:".?html`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,g],subLanguage:"xml"}},b={begin:".?css`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,g],subLanguage:"css"}},k={begin:".?gql`",end:"",starts:{end:"`",returnEnd:!1,contains:[t.BACKSLASH_ESCAPE,g],subLanguage:"graphql"}},w={className:"string",begin:"`",end:"`",contains:[t.BACKSLASH_ESCAPE,g]},C={className:"comment",variants:[t.COMMENT(/\/\*\*(?!\/)/,"\\*/",{relevance:0,contains:[{begin:"(?=@[A-Za-z]+)",relevance:0,contains:[{className:"doctag",begin:"@[A-Za-z]+"},{className:"type",begin:"\\{",end:"\\}",excludeEnd:!0,excludeBegin:!0,relevance:0},{className:"variable",begin:r+"(?=\\s*(-)|$)",endsParent:!0,relevance:0},{begin:/(?=[^\n])\s/,relevance:0}]}]}),t.C_BLOCK_COMMENT_MODE,t.C_LINE_COMMENT_MODE]},T=[t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,v,b,k,w,{match:/\$\d+/},m];g.contains=T.concat({begin:/\{/,end:/\}/,keywords:l,contains:["self"].concat(T)});const j=[].concat(C,g.contains),_=j.concat([{begin:/(\s*)\(/,end:/\)/,keywords:l,contains:["self"].concat(j)}]),A={className:"params",begin:/(\s*)\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:l,contains:_},O={variants:[{match:[/class/,/\s+/,r,/\s+/,/extends/,/\s+/,e.concat(r,"(",e.concat(/\./,r),")*")],scope:{1:"keyword",3:"title.class",5:"keyword",7:"title.class.inherited"}},{match:[/class/,/\s+/,r],scope:{1:"keyword",3:"title.class"}}]},B={relevance:0,match:e.either(/\bJSON/,/\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,/\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,/\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/),className:"title.class",keywords:{_:[...Y_,...X_]}},$={label:"use_strict",className:"meta",relevance:10,begin:/^\s*['"]use (strict|asm)['"]/},W={variants:[{match:[/function/,/\s+/,r,/(?=\s*\()/]},{match:[/function/,/\s*(?=\()/]}],className:{1:"keyword",3:"title.function"},label:"func.def",contains:[A],illegal:/%/},J={relevance:0,match:/\b[A-Z][A-Z_0-9]+\b/,className:"variable.constant"};function z(V){return e.concat("(?!",V.join("|"),")")}const G={match:e.concat(/\b/,z([...Q_,"super","import"].map(V=>`${V}\\s*\\(`)),r,e.lookahead(/\s*\(/)),className:"title.function",relevance:0},D={begin:e.concat(/\./,e.lookahead(e.concat(r,/(?![0-9A-Za-z$_(])/))),end:r,excludeBegin:!0,keywords:"prototype",className:"property",relevance:0},U={match:[/get|set/,/\s+/,r,/(?=\()/],className:{1:"keyword",3:"title.function"},contains:[{begin:/\(\)/},A]},q="(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|"+t.UNDERSCORE_IDENT_RE+")\\s*=>",se={match:[/const|var|let/,/\s+/,r,/\s*/,/=\s*/,/(async\s*)?/,e.lookahead(q)],keywords:"async",className:{1:"keyword",3:"title.function"},contains:[A]};return{name:"JavaScript",aliases:["js","jsx","mjs","cjs"],keywords:l,exports:{PARAMS_CONTAINS:_,CLASS_REFERENCE:B},illegal:/#(?![$_A-z])/,contains:[t.SHEBANG({label:"shebang",binary:"node",relevance:5}),$,t.APOS_STRING_MODE,t.QUOTE_STRING_MODE,v,b,k,w,C,{match:/\$\d+/},m,B,{scope:"attr",match:r+e.lookahead(":"),relevance:0},se,{begin:"("+t.RE_STARTERS_RE+"|\\b(case|return|throw)\\b)\\s*",keywords:"return throw case",relevance:0,contains:[C,t.REGEXP_MODE,{className:"function",begin:q,returnBegin:!0,end:"\\s*=>",contains:[{className:"params",variants:[{begin:t.UNDERSCORE_IDENT_RE,relevance:0},{className:null,begin:/\(\s*\)/,skip:!0},{begin:/(\s*)\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:l,contains:_}]}]},{begin:/,/,relevance:0},{match:/\s+/,relevance:0},{variants:[{begin:s.begin,end:s.end},{match:i},{begin:o.begin,"on:begin":o.isTrulyOpeningTag,end:o.end}],subLanguage:"xml",contains:[{begin:o.begin,end:o.end,skip:!0,contains:["self"]}]}]},W,{beginKeywords:"while if switch catch for"},{begin:"\\b(?!function)"+t.UNDERSCORE_IDENT_RE+"\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",returnBegin:!0,label:"func.def",contains:[A,t.inherit(t.TITLE_MODE,{begin:r,className:"title.function"})]},{match:/\.\.\./,relevance:0},D,{match:"\\$"+r,relevance:0},{match:[/\bconstructor(?=\s*\()/],className:{1:"title.function"},contains:[A]},G,J,O,U,{match:/\$[(.]/}]}}function PB(t){const e=t.regex,n=DB(t),r=Nd,s=["any","void","number","boolean","string","object","never","symbol","bigint","unknown"],i={begin:[/namespace/,/\s+/,t.IDENT_RE],beginScope:{1:"keyword",3:"title.class"}},o={beginKeywords:"interface",end:/\{/,excludeEnd:!0,keywords:{keyword:"interface extends",built_in:s},contains:[n.exports.CLASS_REFERENCE]},l={className:"meta",relevance:10,begin:/^\s*['"]use strict['"]/},d=["type","interface","public","private","protected","implements","declare","abstract","readonly","enum","override","satisfies"],f={$pattern:Nd,keyword:G_.concat(d),literal:J_,built_in:e2.concat(s),"variable.language":Z_},h={className:"meta",begin:"@"+r},m=(k,w,E)=>{const C=k.contains.findIndex(T=>T.label===w);if(C===-1)throw new Error("can not find mode to replace");k.contains.splice(C,1,E)};Object.assign(n.keywords,f),n.exports.PARAMS_CONTAINS.push(h);const g=n.contains.find(k=>k.scope==="attr"),v=Object.assign({},g,{match:e.concat(r,e.lookahead(/\s*\?:/))});n.exports.PARAMS_CONTAINS.push([n.exports.CLASS_REFERENCE,g,v]),n.contains=n.contains.concat([h,i,o,v]),m(n,"shebang",t.SHEBANG()),m(n,"use_strict",l);const b=n.contains.find(k=>k.label==="func.def");return b.relevance=0,Object.assign(n,{name:"TypeScript",aliases:["ts","tsx","mts","cts"]}),n}function BB(t){const e=t.regex,n={className:"string",begin:/"(""|[^/n])"C\b/},r={className:"string",begin:/"/,end:/"/,illegal:/\n/,contains:[{begin:/""/}]},s=/\d{1,2}\/\d{1,2}\/\d{4}/,i=/\d{4}-\d{1,2}-\d{1,2}/,o=/(\d|1[012])(:\d+){0,2} *(AM|PM)/,l=/\d{1,2}(:\d{1,2}){1,2}/,d={className:"literal",variants:[{begin:e.concat(/# */,e.either(i,s),/ *#/)},{begin:e.concat(/# */,l,/ *#/)},{begin:e.concat(/# */,o,/ *#/)},{begin:e.concat(/# */,e.either(i,s),/ +/,e.either(o,l),/ *#/)}]},f={className:"number",relevance:0,variants:[{begin:/\b\d[\d_]*((\.[\d_]+(E[+-]?[\d_]+)?)|(E[+-]?[\d_]+))[RFD@!#]?/},{begin:/\b\d[\d_]*((U?[SIL])|[%&])?/},{begin:/&H[\dA-F_]+((U?[SIL])|[%&])?/},{begin:/&O[0-7_]+((U?[SIL])|[%&])?/},{begin:/&B[01_]+((U?[SIL])|[%&])?/}]},h={className:"label",begin:/^\w+:/},m=t.COMMENT(/'''/,/$/,{contains:[{className:"doctag",begin:/<\/?/,end:/>/}]}),g=t.COMMENT(null,/$/,{variants:[{begin:/'/},{begin:/([\t ]|^)REM(?=\s)/}]});return{name:"Visual Basic .NET",aliases:["vb"],case_insensitive:!0,classNameAliases:{label:"symbol"},keywords:{keyword:"addhandler alias aggregate ansi as async assembly auto binary by byref byval call case catch class compare const continue custom declare default delegate dim distinct do each equals else elseif end enum erase error event exit explicit finally for friend from function get global goto group handles if implements imports in inherits interface into iterator join key let lib loop me mid module mustinherit mustoverride mybase myclass namespace narrowing new next notinheritable notoverridable of off on operator option optional order overloads overridable overrides paramarray partial preserve private property protected public raiseevent readonly redim removehandler resume return select set shadows shared skip static step stop structure strict sub synclock take text then throw to try unicode until using when where while widening with withevents writeonly yield",built_in:"addressof and andalso await directcast gettype getxmlnamespace is isfalse isnot istrue like mod nameof new not or orelse trycast typeof xor cbool cbyte cchar cdate cdbl cdec cint clng cobj csbyte cshort csng cstr cuint culng cushort",type:"boolean byte char date decimal double integer long object sbyte short single string uinteger ulong ushort",literal:"true false nothing"},illegal:"//|\\{|\\}|endif|gosub|variant|wend|^\\$ ",contains:[n,r,d,f,h,m,g,{className:"meta",begin:/[\t ]*#(const|disable|else|elseif|enable|end|externalsource|if|region)\b/,end:/$/,keywords:{keyword:"const disable else elseif enable end externalsource if region then"},contains:[g]}]}}function $B(t){t.regex;const e=t.COMMENT(/\(;/,/;\)/);e.contains.push("self");const n=t.COMMENT(/;;/,/$/),r=["anyfunc","block","br","br_if","br_table","call","call_indirect","data","drop","elem","else","end","export","func","global.get","global.set","local.get","local.set","local.tee","get_global","get_local","global","if","import","local","loop","memory","memory.grow","memory.size","module","mut","nop","offset","param","result","return","select","set_global","set_local","start","table","tee_local","then","type","unreachable"],s={begin:[/(?:func|call|call_indirect)/,/\s+/,/\$[^\s)]+/],className:{1:"keyword",3:"title.function"}},i={className:"variable",begin:/\$[\w_]+/},o={match:/(\((?!;)|\))+/,className:"punctuation",relevance:0},l={className:"number",relevance:0,match:/[+-]?\b(?:\d(?:_?\d)*(?:\.\d(?:_?\d)*)?(?:[eE][+-]?\d(?:_?\d)*)?|0x[\da-fA-F](?:_?[\da-fA-F])*(?:\.[\da-fA-F](?:_?[\da-fA-D])*)?(?:[pP][+-]?\d(?:_?\d)*)?)\b|\binf\b|\bnan(?::0x[\da-fA-F](?:_?[\da-fA-D])*)?\b/},d={match:/(i32|i64|f32|f64)(?!\.)/,className:"type"},f={className:"keyword",match:/\b(f32|f64|i32|i64)(?:\.(?:abs|add|and|ceil|clz|const|convert_[su]\/i(?:32|64)|copysign|ctz|demote\/f64|div(?:_[su])?|eqz?|extend_[su]\/i32|floor|ge(?:_[su])?|gt(?:_[su])?|le(?:_[su])?|load(?:(?:8|16|32)_[su])?|lt(?:_[su])?|max|min|mul|nearest|neg?|or|popcnt|promote\/f32|reinterpret\/[fi](?:32|64)|rem_[su]|rot[lr]|shl|shr_[su]|store(?:8|16|32)?|sqrt|sub|trunc(?:_[su]\/f(?:32|64))?|wrap\/i64|xor))\b/};return{name:"WebAssembly",keywords:{$pattern:/[\w.]+/,keyword:r},contains:[n,e,{match:[/(?:offset|align)/,/\s*/,/=/],className:{1:"keyword",3:"operator"}},i,o,s,t.QUOTE_STRING_MODE,d,f,l]}}function zB(t){const e=t.regex,n=e.concat(/[\p{L}_]/u,e.optional(/[\p{L}0-9_.-]*:/u),/[\p{L}0-9_.-]*/u),r=/[\p{L}0-9._:-]+/u,s={className:"symbol",begin:/&[a-z]+;|&#[0-9]+;|&#x[a-f0-9]+;/},i={begin:/\s/,contains:[{className:"keyword",begin:/#?[a-z_][a-z1-9_-]+/,illegal:/\n/}]},o=t.inherit(i,{begin:/\(/,end:/\)/}),l=t.inherit(t.APOS_STRING_MODE,{className:"string"}),d=t.inherit(t.QUOTE_STRING_MODE,{className:"string"}),f={endsWithParent:!0,illegal:/</,relevance:0,contains:[{className:"attr",begin:r,relevance:0},{begin:/=\s*/,relevance:0,contains:[{className:"string",endsParent:!0,variants:[{begin:/"/,end:/"/,contains:[s]},{begin:/'/,end:/'/,contains:[s]},{begin:/[^\s"'=<>`]+/}]}]}]};return{name:"HTML, XML",aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist","wsf","svg"],case_insensitive:!0,unicodeRegex:!0,contains:[{className:"meta",begin:/<![a-z]/,end:/>/,relevance:10,contains:[i,d,l,o,{begin:/\[/,end:/\]/,contains:[{className:"meta",begin:/<![a-z]/,end:/>/,contains:[i,o,d,l]}]}]},t.COMMENT(/<!--/,/-->/,{relevance:10}),{begin:/<!\[CDATA\[/,end:/\]\]>/,relevance:10},s,{className:"meta",end:/\?>/,variants:[{begin:/<\?xml/,relevance:10,contains:[d]},{begin:/<\?[a-z][a-z0-9]+/}]},{className:"tag",begin:/<style(?=\s|>)/,end:/>/,keywords:{name:"style"},contains:[f],starts:{end:/<\/style>/,returnEnd:!0,subLanguage:["css","xml"]}},{className:"tag",begin:/<script(?=\s|>)/,end:/>/,keywords:{name:"script"},contains:[f],starts:{end:/<\/script>/,returnEnd:!0,subLanguage:["javascript","handlebars","xml"]}},{className:"tag",begin:/<>|<\/>/},{className:"tag",begin:e.concat(/</,e.lookahead(e.concat(n,e.either(/\/>/,/>/,/\s/)))),end:/\/?>/,contains:[{className:"name",begin:n,relevance:0,starts:f}]},{className:"tag",begin:e.concat(/<\//,e.lookahead(e.concat(n,/>/))),contains:[{className:"name",begin:n,relevance:0},{begin:/>/,relevance:0,endsParent:!0}]}]}}function FB(t){const e="true false yes no null",n="[\\w#;/?:@&=+$,.~*'()[\\]]+",r={className:"attr",variants:[{begin:/[\w*@][\w*@ :()\./-]*:(?=[ \t]|$)/},{begin:/"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/},{begin:/'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/}]},s={className:"template-variable",variants:[{begin:/\{\{/,end:/\}\}/},{begin:/%\{/,end:/\}/}]},i={className:"string",relevance:0,begin:/'/,end:/'/,contains:[{match:/''/,scope:"char.escape",relevance:0}]},o={className:"string",relevance:0,variants:[{begin:/"/,end:/"/},{begin:/\S+/}],contains:[t.BACKSLASH_ESCAPE,s]},l=t.inherit(o,{variants:[{begin:/'/,end:/'/,contains:[{begin:/''/,relevance:0}]},{begin:/"/,end:/"/},{begin:/[^\s,{}[\]]+/}]}),g={className:"number",begin:"\\b"+"[0-9]{4}(-[0-9][0-9]){0,2}"+"([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?"+"(\\.[0-9]*)?"+"([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?"+"\\b"},v={end:",",endsWithParent:!0,excludeEnd:!0,keywords:e,relevance:0},b={begin:/\{/,end:/\}/,contains:[v],illegal:"\\n",relevance:0},k={begin:"\\[",end:"\\]",contains:[v],illegal:"\\n",relevance:0},w=[r,{className:"meta",begin:"^---\\s*$",relevance:10},{className:"string",begin:"[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*"},{begin:"<%[%=-]?",end:"[%-]?%>",subLanguage:"ruby",excludeBegin:!0,excludeEnd:!0,relevance:0},{className:"type",begin:"!\\w+!"+n},{className:"type",begin:"!<"+n+">"},{className:"type",begin:"!"+n},{className:"type",begin:"!!"+n},{className:"meta",begin:"&"+t.UNDERSCORE_IDENT_RE+"$"},{className:"meta",begin:"\\*"+t.UNDERSCORE_IDENT_RE+"$"},{className:"bullet",begin:"-(?=[ ]|$)",relevance:0},t.HASH_COMMENT_MODE,{beginKeywords:e,keywords:{literal:e}},g,{className:"number",begin:t.C_NUMBER_RE+"\\b",relevance:0},b,k,i,o],E=[...w];return E.pop(),E.push(l),v.contains=E,{name:"YAML",case_insensitive:!0,aliases:["yml"],contains:w}}const UB={arduino:S6,bash:E6,c:N6,cpp:C6,csharp:_6,css:D6,diff:P6,go:B6,graphql:$6,ini:z6,java:F6,javascript:V6,json:K6,kotlin:J6,less:rB,lua:sB,makefile:iB,markdown:oB,objectivec:aB,perl:lB,php:cB,"php-template":uB,plaintext:dB,python:fB,"python-repl":hB,r:pB,ruby:mB,rust:gB,scss:NB,shell:CB,sql:_B,swift:LB,typescript:PB,vbnet:BB,wasm:$B,xml:zB,yaml:FB},tk={},HB="hljs-";function WB(t){const e=D_.newInstance();return t&&i(t),{highlight:n,highlightAuto:r,listLanguages:s,register:i,registerAlias:o,registered:l};function n(d,f,h){const m=h||tk,g=typeof m.prefix=="string"?m.prefix:HB;if(!e.getLanguage(d))throw new Error("Unknown language: `"+d+"` is not registered");e.configure({__emitter:qB,classPrefix:g});const v=e.highlight(f,{ignoreIllegals:!0,language:d});if(v.errorRaised)throw new Error("Could not highlight with `Highlight.js`",{cause:v.errorRaised});const b=v._emitter.root,k=b.data;return k.language=v.language,k.relevance=v.relevance,b}function r(d,f){const m=(f||tk).subset||s();let g=-1,v=0,b;for(;++g<m.length;){const k=m[g];if(!e.getLanguage(k))continue;const w=n(k,d,f);w.data&&w.data.relevance!==void 0&&w.data.relevance>v&&(v=w.data.relevance,b=w)}return b||{type:"root",children:[],data:{language:void 0,relevance:v}}}function s(){return e.listLanguages()}function i(d,f){if(typeof d=="string")e.registerLanguage(d,f);else{let h;for(h in d)Object.hasOwn(d,h)&&e.registerLanguage(h,d[h])}}function o(d,f){if(typeof d=="string")e.registerAliases(typeof f=="string"?f:[...f],{languageName:d});else{let h;for(h in d)if(Object.hasOwn(d,h)){const m=d[h];e.registerAliases(typeof m=="string"?m:[...m],{languageName:h})}}}function l(d){return!!e.getLanguage(d)}}class qB{constructor(e){this.options=e,this.root={type:"root",children:[],data:{language:void 0,relevance:0}},this.stack=[this.root]}addText(e){if(e==="")return;const n=this.stack[this.stack.length-1],r=n.children[n.children.length-1];r&&r.type==="text"?r.value+=e:n.children.push({type:"text",value:e})}startScope(e){this.openNode(String(e))}endScope(){this.closeNode()}__addSublanguage(e,n){const r=this.stack[this.stack.length-1],s=e.root.children;n?r.children.push({type:"element",tagName:"span",properties:{className:[n]},children:s}):r.children.push(...s)}openNode(e){const n=this,r=e.split(".").map(function(o,l){return l?o+"_".repeat(l):n.options.classPrefix+o}),s=this.stack[this.stack.length-1],i={type:"element",tagName:"span",properties:{className:r},children:[]};s.children.push(i),this.stack.push(i)}closeNode(){this.stack.pop()}finalize(){}toHTML(){return""}}const VB=new Jt("blurredLoadingNode"),Yv=Pt.create({name:"blurredLoadingNode",addStorage(){return{loadingNodes:{}}},addCommands(){return{applyLoadingEffect:(t,e,n,r="paragraph")=>({editor:s})=>{const i={...this.storage.loadingNodes};return i[t]={from:e,to:n,id:t,active:!0,type:r},this.storage.loadingNodes=i,s.view.dispatch(s.view.state.tr),setTimeout(()=>{s.isFocused&&s.commands.setTextSelection({from:e,to:e})},0),!0},removeLoadingEffect:t=>({editor:e})=>{const n={...this.storage.loadingNodes};return n[t]&&(delete n[t],this.storage.loadingNodes=n,e.view.dispatch(e.view.state.tr),e.isFocused||setTimeout(()=>{e.commands.focus()},0)),!0}}},addProseMirrorPlugins(){return[new Ht({key:VB,props:{decorations:t=>{const e=this.storage.loadingNodes,n=[];return Object.entries(e).forEach(([,r])=>{const s=r;if(!s.active)return;const{from:i,to:o,type:l}=s;l==="selection"?n.push(Vt.inline(i,o,{class:"node-blur-selection"})):t.doc.nodesBetween(i,o,(d,f)=>["paragraph","heading","blockquote","listItem","codeBlock"].includes(d.type.name)?(n.push(Vt.node(f,f+d.nodeSize,{class:"node-blur-effect"})),!1):!0)}),Dt.create(t.doc,n)}}})]}}),Xv=vn.create({name:"imageLoading",group:"block",atom:!0,addAttributes(){return{id:{default:null}}},parseHTML(){return[{tag:'div[data-type="image-loading"]'}]},renderHTML(){return["div",{"data-type":"image-loading",class:"image-loading-placeholder",contenteditable:"false"}]}}),KB=new Jt("insertionLoadingNode"),hu=new Map,Qv=Pt.create({name:"insertionLoadingNode",addStorage(){return{insertionPoints:{}}},addCommands(){return{showInsertionLoading:(t,e)=>({editor:n})=>(this.storage.insertionPoints={},hu.clear(),this.storage.insertionPoints={[t]:{position:e,id:t,active:!0}},n.view.dom.classList.add("has-insertion-loading"),n.view.dispatch(n.view.state.tr),!0),removeInsertionLoading:t=>({editor:e})=>{const n={...this.storage.insertionPoints};return n[t]&&(delete n[t],this.storage.insertionPoints=n,hu.delete(t),Object.keys(n).length===0&&e.view.dom.classList.remove("has-insertion-loading"),e.view.dispatch(e.view.state.tr)),!0}}},addProseMirrorPlugins(){return[new Ht({key:KB,props:{decorations:t=>{const e=this.storage.insertionPoints,n=[];return Object.entries(e).forEach(([,r])=>{const s=r;s.active&&n.push(Vt.widget(s.position,()=>{const i=hu.get(s.id);if(i)return i;const o=document.createElement("span");o.className="inline-insertion-indicator";const l=document.createElement("span");l.className="inline-insertion-spinner";const d=document.createElement("div");d.className="bounce1";const f=document.createElement("div");f.className="bounce2";const h=document.createElement("div");return l.appendChild(d),l.appendChild(f),l.appendChild(h),o.appendChild(l),hu.set(s.id,o),o},{id:`insertion-${s.id}`}))}),Dt.create(t.doc,n)}}})]}}),GB=["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","horizontalRule","table","taskList","taskItem","image"],Zv=Pt.create({name:"pendingAttributes",addGlobalAttributes(){return[{types:GB,attributes:{pendingStatus:{default:null,parseHTML:t=>t.getAttribute("data-pending-status")||null,renderHTML:t=>t.pendingStatus?{"data-pending-status":t.pendingStatus}:{}},pendingOriginalContent:{default:null,rendered:!1},pendingSelectionFrom:{default:null,rendered:!1},pendingSelectionTo:{default:null,rendered:!1},pendingOriginalFrom:{default:null,rendered:!1},pendingOriginalTo:{default:null,rendered:!1},pendingGroupId:{default:null,rendered:!1},pendingOrphan:{default:null,rendered:!1},pendingStaleBaseline:{default:null,rendered:!1}}}]}}),JB=vn.create({name:"footnoteReference",group:"inline",inline:!0,atom:!0,selectable:!0,draggable:!1,addAttributes(){return{label:{default:"",parseHTML:t=>t.getAttribute("data-label")||"",renderHTML:t=>({"data-label":t.label})}}},parseHTML(){return[{tag:"sup.footnote-ref",getAttrs:t=>{const e=t.getAttribute("data-label");return e?{label:e}:!1}}]},renderHTML({HTMLAttributes:t}){return["sup",zt({class:"footnote-ref"},t)]},addKeyboardShortcuts(){return{"Mod-Shift-f":()=>(t2(this.editor),!0)}}}),YB=vn.create({name:"footnoteSection",group:"block",content:"footnoteDefinition+",defining:!0,isolating:!0,addAttributes(){return{id:{default:null}}},parseHTML(){return[{tag:"section.footnotes"}]},renderHTML({HTMLAttributes:t}){return["section",zt({class:"footnotes"},t),0]}}),XB=vn.create({name:"footnoteDefinition",group:"block",content:"paragraph+",defining:!0,isolating:!0,addAttributes(){return{id:{default:null},label:{default:"",parseHTML:t=>t.getAttribute("data-label")||"",renderHTML:t=>({"data-label":t.label})}}},parseHTML(){return[{tag:"div.footnote-def",getAttrs:t=>{const e=t.getAttribute("data-label");return e?{label:e}:!1}}]},renderHTML({HTMLAttributes:t}){return["div",zt({class:"footnote-def"},t),0]}});function t2(t){const{state:e}=t,{schema:n,doc:r}=e,s=n.nodes.footnoteReference,i=n.nodes.footnoteSection,o=n.nodes.footnoteDefinition,l=n.nodes.paragraph;if(!s||!i||!o||!l)return;const d=new Set;r.descendants(T=>{(T.type.name==="footnoteReference"||T.type.name==="footnoteDefinition")&&T.attrs.label&&d.add(String(T.attrs.label))});let f=1;for(;d.has(String(f));)f++;const h=String(f);let m=-1,g=null;r.forEach((T,j)=>{T.type.name==="footnoteSection"&&(m=j,g=T)});const v=o.create({label:h},l.create()),b=s.create({label:h}),k=e.selection.to,w=e.tr;w.insert(k,b);let E;if(m>=0&&g){const T=b.nodeSize,_=(k<=m?m+T+g.nodeSize:m+g.nodeSize)-1;w.insert(_,v),E=_+2}else{const T=i.create(null,v),j=w.doc.content.size;w.insert(j,T),E=j+3}const C=Math.min(E,w.doc.content.size);w.setSelection(dt.near(w.doc.resolve(C))),w.scrollIntoView(),t.view.dispatch(w),t.view.focus()}function QB({node:t,deleteNode:e}){return c.jsxs(ED,{as:"div",className:"tweet-image-card",draggable:!0,"data-drag-handle":!0,children:[c.jsx("img",{className:"tweet-image-card-img",src:t.attrs.src,alt:t.attrs.alt||"",draggable:!1}),c.jsx("button",{className:"tweet-image-card-remove",onClick:e,title:"Remove image",contentEditable:!1,children:"×"})]})}const ZB=Iv.extend({addNodeView(){return MD(QB)}}),e5=WB(UB),ey=lP.extend({addAttributes(){var t;return{...(t=this.parent)==null?void 0:t.call(this),target:{default:null}}},renderHTML({HTMLAttributes:t}){var r;const{target:e,...n}=t;if((r=n.href)!=null&&r.startsWith("doc:")){const{href:s,...i}=n;return["span",{...i,"data-doc":s.slice(4),class:"doc-link"},0]}return["a",zt(this.options.HTMLAttributes,n),0]}}),t5=[Gv.configure({codeBlock:!1,link:!1,underline:!1}),w6.configure({lowlight:e5}),ey.configure({openOnClick:!1,isAllowedUri:(t,e)=>t.startsWith("doc:")?!0:e.defaultValidate(t),HTMLAttributes:{rel:"noopener noreferrer nofollow"}}),O_,R3,LD,IP,DP,e3,Z4.configure({nested:!0}),Iv,A3,b_.configure({resizable:!1}),y_,v_,g_,Yv,Xv,Qv,Zv,JB,YB,XB,Kd.configure({placeholder:"Start writing..."}),Kv.configure({types:["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","horizontalRule","table","tableRow","tableHeader","tableCell","taskList","taskItem","image","imageLoading","footnoteSection","footnoteDefinition"],attributeName:"id",generateID:()=>crypto.randomUUID().replace(/-/g,"").slice(0,8)})],n5=[Gv.configure({codeBlock:!1,horizontalRule:!0,heading:{levels:[1,2,3]},link:!1,underline:!1}),ey.configure({openOnClick:!1,isAllowedUri:(t,e)=>t.startsWith("doc:")?!0:e.defaultValidate(t),HTMLAttributes:{rel:"noopener noreferrer nofollow"}}),Iv,Yv,Xv,Qv,Zv,Kd.configure({placeholder:"Start writing..."}),Kv.configure({types:["paragraph","heading","bulletList","orderedList","listItem","blockquote","image","imageLoading","horizontalRule"],attributeName:"id",generateID:()=>crypto.randomUUID().replace(/-/g,"").slice(0,8)})],r5=Pt.create({name:"tweetEnterHardBreak",addKeyboardShortcuts(){return{Enter:()=>{const{state:t}=this.editor,{$from:e}=t.selection,n=e.pos,r=n>0?t.doc.resolve(n).nodeBefore:null;if((r==null?void 0:r.type.name)==="hardBreak"){const{tr:s}=t;return s.delete(n-r.nodeSize,n),s.split(s.mapping.map(n)),this.editor.view.dispatch(s),!0}return this.editor.commands.setHardBreak()}}}}),n2=[Gv.configure({codeBlock:!1,horizontalRule:!1,heading:!1,blockquote:!1,bulletList:!1,orderedList:!1,listItem:!1,link:!1,underline:!1}),ey.configure({openOnClick:!1,isAllowedUri:(t,e)=>t.startsWith("doc:")?!0:e.defaultValidate(t),HTMLAttributes:{rel:"noopener noreferrer nofollow"}}),ZB,Yv,Xv,Qv,Zv,r5,Kv.configure({types:["paragraph","image","imageLoading"],attributeName:"id",generateID:()=>crypto.randomUUID().replace(/-/g,"").slice(0,8)})];[...n2,Kd.configure({placeholder:"What is happening?!"})];function Dr({onClick:t,active:e,disabled:n,title:r,children:s}){return c.jsx("button",{className:`floating-toolbar__btn${e?" active":""}${n?" disabled":""}`,onMouseDown:i=>{i.preventDefault(),t()},disabled:n,title:r,children:s})}function nk(){return c.jsx("div",{className:"floating-toolbar__divider"})}function s5({editor:t}){const[e,n]=x.useState(!1),[r,s]=x.useState({top:0,left:0}),[,i]=x.useState(0),o=x.useRef(-1),l=x.useRef(-1),d=x.useRef(!1);return x.useEffect(()=>{const f=t.view.dom,h=()=>{d.current=!0},m=()=>{if(!d.current)return;d.current=!1;const{from:g,to:v}=t.state.selection,b=g!==v&&t.state.selection.node;if(g!==v&&!b){const k=t.isActive("codeBlock"),w=!!document.querySelector(".context-menu");if(!k&&!w){o.current=g,l.current=v;const E=t.view.coordsAtPos(g),C=t.view.coordsAtPos(v,1),T=(E.left+C.right)/2;s({top:E.top,left:T}),n(!0)}}};return f.addEventListener("mousedown",h),document.addEventListener("mouseup",m),()=>{f.removeEventListener("mousedown",h),document.removeEventListener("mouseup",m)}},[t]),x.useEffect(()=>{const f=()=>{d.current=!1,n(!1),o.current=-1,l.current=-1};return t.on("blur",f),()=>{t.off("blur",f)}},[t]),x.useEffect(()=>{const f=()=>{const{from:h,to:m}=t.state.selection,g=h===m,v=t.isActive("codeBlock"),b=!!document.querySelector(".context-menu"),k=t.view.hasFocus(),w=!g&&t.state.selection.node;if(g||w||v||b||!k)n(!1),o.current=-1,l.current=-1;else if(!d.current&&(n(!0),h!==o.current||m!==l.current)){o.current=h,l.current=m;const E=t.view.coordsAtPos(h),C=t.view.coordsAtPos(m,1),T=(E.left+C.right)/2;s({top:E.top,left:T})}i(E=>E+1)};return t.on("transaction",f),()=>{t.off("transaction",f)}},[t]),e?c.jsxs("div",{className:"floating-toolbar",style:{position:"fixed",top:r.top,left:r.left,transform:"translate(-50%, -100%) translateY(-8px)",zIndex:1500},children:[c.jsx(Dr,{onClick:()=>t.chain().focus().toggleBold().run(),active:t.isActive("bold"),title:"Bold (Ctrl+B)",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"})})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleItalic().run(),active:t.isActive("italic"),title:"Italic (Ctrl+I)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"19",x2:"10",y1:"4",y2:"4"}),c.jsx("line",{x1:"14",x2:"5",y1:"20",y2:"20"}),c.jsx("line",{x1:"15",x2:"9",y1:"4",y2:"20"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleUnderline().run(),active:t.isActive("underline"),title:"Underline (Ctrl+U)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M6 4v6a6 6 0 0 0 12 0V4"}),c.jsx("line",{x1:"4",x2:"20",y1:"20",y2:"20"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleStrike().run(),active:t.isActive("strike"),title:"Strikethrough",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M16 4H9a3 3 0 0 0-2.83 4"}),c.jsx("path",{d:"M14 12a4 4 0 0 1 0 8H6"}),c.jsx("line",{x1:"4",x2:"20",y1:"12",y2:"12"})]})}),c.jsx(Dr,{onClick:()=>{const f=t.getAttributes("link").href||"",h=window.prompt("Link URL:",f);h!==null&&(h===""?t.chain().focus().unsetLink().run():t.chain().focus().setLink({href:h}).run())},active:t.isActive("link"),title:"Link (Ctrl+K)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),c.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}),c.jsx(nk,{}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleHeading({level:1}).run(),active:t.isActive("heading",{level:1}),title:"Heading 1",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 12h8"}),c.jsx("path",{d:"M4 18V6"}),c.jsx("path",{d:"M12 18V6"}),c.jsx("path",{d:"m17 12 3-2v8"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleHeading({level:2}).run(),active:t.isActive("heading",{level:2}),title:"Heading 2",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 12h8"}),c.jsx("path",{d:"M4 18V6"}),c.jsx("path",{d:"M12 18V6"}),c.jsx("path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleHeading({level:3}).run(),active:t.isActive("heading",{level:3}),title:"Heading 3",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 12h8"}),c.jsx("path",{d:"M4 18V6"}),c.jsx("path",{d:"M12 18V6"}),c.jsx("path",{d:"M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2"}),c.jsx("path",{d:"M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"})]})}),c.jsx(nk,{}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleBulletList().run(),active:t.isActive("bulletList"),title:"Bullet List",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M3 12h.01"}),c.jsx("path",{d:"M3 18h.01"}),c.jsx("path",{d:"M3 6h.01"}),c.jsx("path",{d:"M8 12h13"}),c.jsx("path",{d:"M8 18h13"}),c.jsx("path",{d:"M8 6h13"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleOrderedList().run(),active:t.isActive("orderedList"),title:"Ordered List",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M11 12h9"}),c.jsx("path",{d:"M11 18h9"}),c.jsx("path",{d:"M11 6h9"}),c.jsx("path",{d:"M4 10V4h1"}),c.jsx("path",{d:"M4 10h2"}),c.jsx("path",{d:"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"})]})}),c.jsx(Dr,{onClick:()=>t.chain().focus().toggleBlockquote().run(),active:t.isActive("blockquote"),title:"Blockquote",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 6H3"}),c.jsx("path",{d:"M21 12H8"}),c.jsx("path",{d:"M21 18H8"}),c.jsx("path",{d:"M3 12v6"})]})}),c.jsx(Dr,{onClick:()=>t2(t),title:"Footnote (Ctrl+Shift+F)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 6h12"}),c.jsx("path",{d:"M4 12h12"}),c.jsx("path",{d:"M4 18h8"}),c.jsx("text",{x:"18",y:"9",fontSize:"9",fontWeight:"bold",stroke:"none",fill:"currentColor",children:"N"})]})})]}):null}const i5=new Jt("pendingDecoration");let r2=null,s2=null;function rk(t,e){r2=t,s2=e??null}let Cd=!1,i2=null,ty=null,o2=null;function ny(){return Cd}function o5(){return ty}function a5(){return o2}function rl(t,e,n,r){Cd=t,i2=t?e??null:null,ty=t?r??null:null,o2=t?n??null:null}function l5(t){switch(t){case"insert":return"pending-insert";case"rewrite":return"pending-rewrite";case"delete":return"pending-delete";default:return""}}function sk(t,e,n){let r=0,s=e+1;for(let i=0;i<t.childCount;i++){const o=t.child(i);if(o.isText){if(r+o.text.length>=n)return s+(n-r);r+=o.text.length,s+=o.nodeSize}else{const l=o.type.name==="hardBreak"?1:o.type.spec.leafText?o.type.spec.leafText(o).length:0;if(l>0&&r+l>=n)return s;r+=l,s+=o.nodeSize}}return n===r?s:null}function ik(t){const e=[];return t.descendants((n,r)=>{var w,E,C,T,j,_,A,O,B;const s=(w=n.attrs)==null?void 0:w.pendingStatus;if(!s)return!0;const i=(E=n.attrs)==null?void 0:E.id,o=(C=n.attrs)==null?void 0:C.pendingGroupId,l=o&&o===s2,f=Cd&&i===i2||o&&Cd&&o===ty,h=f?(T=n.attrs)==null?void 0:T.pendingOriginalFrom:(j=n.attrs)==null?void 0:j.pendingSelectionFrom,m=f?(_=n.attrs)==null?void 0:_.pendingOriginalTo:(A=n.attrs)==null?void 0:A.pendingSelectionTo,g=h!=null&&m!=null,v=f?"pending-original":l5(s),b=[];(O=n.attrs)!=null&&O.pendingOrphan&&b.push("pending-orphan"),(B=n.attrs)!=null&&B.pendingStaleBaseline&&b.push("pending-stale");const k=v+(b.length?" "+b.join(" "):"");if(g&&n.isTextblock&&k){const $=sk(n,r,h),W=sk(n,r,m);$!==null&&W!==null&&$<W&&e.push(Vt.inline($,W,{class:k}))}else k&&(n.isTextblock&&r+1<r+n.nodeSize-1?e.push(Vt.inline(r+1,r+n.nodeSize-1,{class:k})):e.push(Vt.node(r,r+n.nodeSize,{class:k})));if(i&&(i===r2||l)){const $=f?"original":s;e.push(Vt.node(r,r+n.nodeSize,{class:`pending-active pending-active--${$}`}))}return!0}),Dt.create(t,e)}function a2(){return new Ht({key:i5,state:{init(t,e){return ik(e.doc)},apply(t,e,n,r){return t.docChanged||t.getMeta("forceDecorationUpdate")?ik(r.doc):e.map(t.mapping,t.doc)}},props:{decorations(t){return this.getState(t)}}})}function ry(t){const{state:e,dispatch:n}=t,r=e.tr.setMeta("forceDecorationUpdate",!0);n(r)}const c5=new Jt("commentDecoration");let Xo=[];function ok(t){Xo=t}function Ru(){return Xo}function l2(t){return{class:"ow-comment","data-comment-id":t.id}}function ak(t,e,n){const s=e.textContent.indexOf(t.text);if(s===-1)return null;const i=Qo(e,n,s),o=Qo(e,n,s+t.text.length);return i===null||o===null||i>=o?null:Vt.inline(i,o,l2(t))}function u5(t,e){const n=t.nodeIds,r=t.text.split(`
204
204
  `),s=l2(t),i=[];if(r.length===n.length)for(let o=0;o<n.length;o++){const l=r[o];if(!l)continue;const d=e.get(n[o]);if(!d)continue;const h=d.node.textContent.indexOf(l);if(h===-1)continue;const m=Qo(d.node,d.pos,h),g=Qo(d.node,d.pos,h+l.length);m!==null&&g!==null&&m<g&&i.push(Vt.inline(m,g,s))}else{let o=0;for(const l of n){if(o>=r.length)break;const d=e.get(l);if(!d)continue;const f=r[o];if(!f){o++;continue}const m=d.node.textContent.indexOf(f);if(m===-1)continue;const g=Qo(d.node,d.pos,m),v=Qo(d.node,d.pos,m+f.length);g!==null&&v!==null&&g<v&&(i.push(Vt.inline(g,v,s)),o++)}}return i}function lk(t){if(Xo.length===0)return Dt.empty;const e=[],n=new Set,r=new Map;t.descendants((i,o)=>{var l;return i.isTextblock&&((l=i.attrs)!=null&&l.id)&&r.set(i.attrs.id,{node:i,pos:o}),!0});for(const i of Xo)if(i.nodeIds&&i.nodeIds.length>1){const o=u5(i,r);o.length>0&&(n.add(i.id),e.push(...o))}for(const i of Xo){if(n.has(i.id))continue;const o=r.get(i.nodeId);if(!o)continue;const l=ak(i,o.node,o.pos);l&&(n.add(i.id),e.push(l))}const s=Xo.filter(i=>!n.has(i.id));return s.length>0&&t.descendants((i,o)=>{if(!i.isTextblock)return!0;for(const l of s){if(n.has(l.id))continue;const d=ak(l,i,o);d&&(n.add(l.id),e.push(d))}return!0}),Dt.create(t,e)}function Qo(t,e,n){let r=0,s=e+1;for(let i=0;i<t.childCount;i++){const o=t.child(i);if(o.isText){if(r+o.text.length>=n)return s+(n-r);r+=o.text.length,s+=o.nodeSize}else{const l=o.type.spec.leafText?o.type.spec.leafText(o).length:0;if(l>0&&r+l>=n)return s;r+=l,s+=o.nodeSize}}return n===r?s:null}function c2(){return new Ht({key:c5,state:{init(t,e){return lk(e.doc)},apply(t,e,n,r){return t.docChanged||t.getMeta("forceCommentUpdate")?lk(r.doc):e.map(t.mapping,t.doc)}},props:{decorations(t){return this.getState(t)}}})}function ck(t){const{state:e,dispatch:n}=t,r=e.tr.setMeta("forceCommentUpdate",!0);n(r)}const d5=new Jt("backlinkDecoration");let _d=[];function uk(t){_d=Array.isArray(t)?t:[]}function f5(t){const e=new Map;for(const n of t){if(!n.to_node)continue;const r=e.get(n.to_node)??[];r.push(n),e.set(n.to_node,r)}return e}function dk(t){if(_d.length===0)return Dt.empty;const e=f5(_d);if(e.size===0)return Dt.empty;const n=[];return t.descendants((r,s)=>{var l;if(!r.isTextblock)return!0;const i=(l=r.attrs)==null?void 0:l.id;if(!i)return!0;const o=e.get(i);return o&&n.push(Vt.node(s,s+r.nodeSize,{class:"linked-paragraph","data-backlinks-count":String(o.length),"data-backlinks-node":i})),!0}),Dt.create(t,n)}function h5(){return new Ht({key:d5,state:{init(t,e){return dk(e.doc)},apply(t,e,n,r){return t.docChanged||t.getMeta("forceBacklinkUpdate")?dk(r.doc):e.map(t.mapping,t.doc)}},props:{decorations(t){return this.getState(t)}}})}function p5(t){const{state:e,dispatch:n}=t,r=e.tr.setMeta("forceBacklinkUpdate",!0);n(r)}function m5(t){return _d.filter(e=>e.to_node===t)}const sy=new WeakMap;function g5(t,e){sy.set(t,e)}async function u2(t,e){const n=new FormData;n.append("image",t);try{const r=await fetch("/api/upload-image",{method:"POST",body:n});if(!r.ok)return;const{src:s}=await r.json(),i=sy.get(e);if(!i||i.getPreviewImages().length>=4)return;i.addToPreview(s)}catch{}}async function v5(t,e){try{const n=await fetch("/api/download-image",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:t})});if(!n.ok)return;const{src:r}=await n.json(),s=sy.get(e);if(!s||s.getPreviewImages().length>=4)return;s.addToPreview(r)}catch{}}function y5(t){const e=[],n=/<img[^>]+src=["']([^"']+)["']/gi;let r;for(;(r=n.exec(t))!==null;){const s=r[1];(s.startsWith("http://")||s.startsWith("https://"))&&e.push(s)}return e}function d2(t,e){var s,i;const n=(s=e.clipboardData)==null?void 0:s.items;if(!n)return!1;for(const o of n)if(o.type.startsWith("image/")){e.preventDefault();const l=o.getAsFile();return l&&u2(l,t),!0}const r=(i=e.clipboardData)==null?void 0:i.getData("text/html");if(r){const o=y5(r);if(o.length>0){e.preventDefault();for(const l of o)v5(l,t);return!0}}return!1}function f2(t,e){var r;const n=(r=e.dataTransfer)==null?void 0:r.files;if(!(n!=null&&n.length))return!1;for(const s of n)if(s.type.startsWith("image/"))return e.preventDefault(),u2(s,t),!0;return!1}const b5=["<!--StartFragment-->","<span"," style="," class="];function x5(t){return b5.some(e=>t.includes(e))||/<p[^>]*>\s*(<br\s*\/?>)?\s*<\/p>/i.test(t)}function w5(t){var i;if(!x5(t))return t;const e=t.match(/<!--StartFragment-->([\s\S]*?)<!--EndFragment-->/),n=e?e[1]:t,r=new DOMParser().parseFromString(`<div>${n}</div>`,"text/html"),s=r.body.firstChild;if(!s)return n;for(const o of Array.from(s.querySelectorAll("span"))){const l=o.getAttribute("style")||"",d=/font-weight:\s*(bold|[6-9]00)/i.test(l),f=/font-style:\s*italic/i.test(l),h=/text-decoration:[^;]*underline/i.test(l);if(d||f||h){let m=o.innerHTML;d&&(m=`<strong>${m}</strong>`),f&&(m=`<em>${m}</em>`),h&&(m=`<u>${m}</u>`);const g=r.createElement("div");g.innerHTML=m,o.replaceWith(...Array.from(g.childNodes))}else o.replaceWith(...Array.from(o.childNodes))}for(const o of Array.from(s.querySelectorAll("*")))o.removeAttribute("style"),o.removeAttribute("class"),o.removeAttribute("id");for(const o of Array.from(s.querySelectorAll("p"))){const l=(o.textContent||"").replace(/ /g,"").trim(),d=o.children.length===1&&((i=o.firstElementChild)==null?void 0:i.tagName)==="BR";!l&&(o.children.length===0||d)&&o.remove()}return s.innerHTML}const fk=/^[a-f0-9]{8}$/;function h2(t){if(!t.startsWith("doc:"))return null;const e=t.slice(4);let n=e,r=null;const s=e.indexOf("?q=");if(s>=0){n=e.slice(0,s);try{r=decodeURIComponent(e.slice(s+3))}catch{r=e.slice(s+3)}}let i=null;const o=n.indexOf("#");if(o>=0){const d=n.slice(o+1);i=fk.test(d)?d:null,n=n.slice(0,o)}const l=fk.test(n);return{docId:l?n:null,filename:l?null:n,nodeId:i,quote:r}}function _p(t){const e=t.docId||t.filename;if(!e)throw new Error("formatLinkHref: docId or filename required");let n=`doc:${e}`;return t.nodeId&&(n+=`#${t.nodeId}`),t.quote&&(n+=`?q=${encodeURIComponent(t.quote)}`),n}function k5(t){const e=h2(t);return e?e.docId||e.filename:null}function pu({initialContent:t,extensions:e,onUpdate:n,onReady:r,onLinkClick:s}){const i=x.useRef(s);i.current=s;const o=FC({extensions:e||t5,content:t||"<p></p>",onUpdate:({editor:d})=>{ny()||n==null||n(d.getJSON())},editorProps:{attributes:{class:"tiptap"},handlePaste:d2,handleDrop:f2,transformPastedHTML:w5}},[]),l=x.useRef(t);return x.useEffect(()=>{if(!o||!t||l.current===t)return;l.current=t;const d=performance.now();o.commands.setContent(t,{emitUpdate:!1});const f=performance.now(),h=window.__lastSwitch;h&&h.tClick?console.log(`[Editor] setContent t=${f.toFixed(0)} duration=${(f-d).toFixed(1)}ms fromClick=${(f-h.tClick).toFixed(1)}ms fromReceive=${h.tReceive?(f-h.tReceive).toFixed(1):"?"}ms`):console.log(`[Editor] setContent t=${f.toFixed(0)} duration=${(f-d).toFixed(1)}ms (no matching switch)`)},[o,t]),x.useEffect(()=>{o&&console.log(`[Editor] first mount t=${performance.now().toFixed(0)}`)},[o]),x.useEffect(()=>{if(!o)return;const d=o.view.dom,f=h=>{var k;const m=h.target,g=m.closest("span.doc-link[data-doc]");if(g){const w=g.getAttribute("data-doc"),E=h2(`doc:${w}`);if(!E)return;(k=i.current)==null||k.call(i,E);return}const v=m.closest("a[href]");if(!v)return;const b=v.getAttribute("href")||"";/^(https?:|mailto:|tel:)/i.test(b)&&(h.metaKey||h.ctrlKey||h.shiftKey||h.button!==0||(h.preventDefault(),window.open(b,"_blank","noopener,noreferrer")))};return d.addEventListener("click",f,!0),()=>d.removeEventListener("click",f,!0)},[o]),x.useEffect(()=>{if(!o)return;const{state:d}=o.view;if(d.plugins.some(m=>m.key==="pendingDecoration$"))return;const f=a2(),h=d.reconfigure({plugins:[...d.plugins,f]});o.view.updateState(h)},[o]),x.useEffect(()=>{if(!o)return;const{state:d}=o.view;if(d.plugins.some(m=>m.key==="commentDecoration$"))return;const f=c2(),h=d.reconfigure({plugins:[...d.plugins,f]});o.view.updateState(h)},[o]),x.useEffect(()=>{if(!o)return;const{state:d}=o.view;if(d.plugins.some(m=>m.key==="backlinkDecoration$"))return;const f=h5(),h=d.reconfigure({plugins:[...d.plugins,f]});o.view.updateState(h)},[o]),x.useEffect(()=>{o&&(r==null||r(o))},[o,r]),o?c.jsxs(c.Fragment,{children:[c.jsx(Rv,{editor:o}),c.jsx(s5,{editor:o})]}):null}function wn({onClick:t,active:e,disabled:n,title:r,children:s}){return c.jsx("button",{className:`format-toolbar__btn${e?" active":""}${n?" disabled":""}`,onMouseDown:i=>{i.preventDefault(),t()},disabled:n,title:r,children:s})}function Ho(){return c.jsx("div",{className:"format-toolbar__divider"})}async function S5(t,e){const n=new FormData;n.append("image",t);try{const r=await fetch("/api/upload-image",{method:"POST",body:n});if(!r.ok)return;const{src:s}=await r.json();e.chain().focus().setImage({src:s,alt:t.name}).run()}catch{}}function E5({editor:t}){const[,e]=x.useState(0),n=x.useRef(null);x.useEffect(()=>{const s=()=>e(i=>i+1);return t.on("transaction",s),()=>{t.off("transaction",s)}},[t]);const r=s=>{var o;const i=(o=s.target.files)==null?void 0:o[0];i&&S5(i,t),s.target.value=""};return c.jsxs("div",{className:"format-toolbar",children:[c.jsxs("div",{className:"format-toolbar__group",children:[c.jsx(wn,{onClick:()=>t.chain().focus().toggleBold().run(),active:t.isActive("bold"),title:"Bold (Ctrl+B)",children:c.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"})})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleItalic().run(),active:t.isActive("italic"),title:"Italic (Ctrl+I)",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"19",x2:"10",y1:"4",y2:"4"}),c.jsx("line",{x1:"14",x2:"5",y1:"20",y2:"20"}),c.jsx("line",{x1:"15",x2:"9",y1:"4",y2:"20"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleUnderline().run(),active:t.isActive("underline"),title:"Underline (Ctrl+U)",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M6 4v6a6 6 0 0 0 12 0V4"}),c.jsx("line",{x1:"4",x2:"20",y1:"20",y2:"20"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleStrike().run(),active:t.isActive("strike"),title:"Strikethrough",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M16 4H9a3 3 0 0 0-2.83 4"}),c.jsx("path",{d:"M14 12a4 4 0 0 1 0 8H6"}),c.jsx("line",{x1:"4",x2:"20",y1:"12",y2:"12"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleCode().run(),active:t.isActive("code"),title:"Inline Code",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"m16 18 6-6-6-6"}),c.jsx("path",{d:"m8 6-6 6 6 6"})]})})]}),c.jsx(Ho,{}),c.jsxs("div",{className:"format-toolbar__group",children:[c.jsx(wn,{onClick:()=>t.chain().focus().toggleHighlight().run(),active:t.isActive("highlight"),title:"Highlight",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"m9 11-6 6v3h9l3-3"}),c.jsx("path",{d:"m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleSubscript().run(),active:t.isActive("subscript"),title:"Subscript",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"m4 5 8 8"}),c.jsx("path",{d:"m12 5-8 8"}),c.jsx("path",{d:"M20 19h-4c0-1.5.44-2 1.5-2.5S20 15.33 20 14c0-.47-.17-.93-.48-1.29a2.11 2.11 0 0 0-2.62-.44c-.42.24-.74.62-.9 1.07"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleSuperscript().run(),active:t.isActive("superscript"),title:"Superscript",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"m4 19 8-8"}),c.jsx("path",{d:"m12 19-8-8"}),c.jsx("path",{d:"M20 12h-4c0-1.5.44-2 1.5-2.5S20 8.33 20 7c0-.47-.17-.93-.48-1.29a2.11 2.11 0 0 0-2.62-.44c-.42.24-.74.62-.9 1.07"})]})})]}),c.jsx(Ho,{}),c.jsxs("div",{className:"format-toolbar__group",children:[c.jsx(wn,{onClick:()=>t.chain().focus().toggleHeading({level:1}).run(),active:t.isActive("heading",{level:1}),title:"Heading 1",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 12h8"}),c.jsx("path",{d:"M4 18V6"}),c.jsx("path",{d:"M12 18V6"}),c.jsx("path",{d:"m17 12 3-2v8"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleHeading({level:2}).run(),active:t.isActive("heading",{level:2}),title:"Heading 2",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 12h8"}),c.jsx("path",{d:"M4 18V6"}),c.jsx("path",{d:"M12 18V6"}),c.jsx("path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleHeading({level:3}).run(),active:t.isActive("heading",{level:3}),title:"Heading 3",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 12h8"}),c.jsx("path",{d:"M4 18V6"}),c.jsx("path",{d:"M12 18V6"}),c.jsx("path",{d:"M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2"}),c.jsx("path",{d:"M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().setParagraph().run(),active:t.isActive("paragraph")&&!t.isActive("heading"),title:"Paragraph",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M13 4v16"}),c.jsx("path",{d:"M17 4v16"}),c.jsx("path",{d:"M19 4H9.5a4.5 4.5 0 0 0 0 9H13"})]})})]}),c.jsx(Ho,{}),c.jsxs("div",{className:"format-toolbar__group",children:[c.jsx(wn,{onClick:()=>t.chain().focus().toggleBulletList().run(),active:t.isActive("bulletList"),title:"Bullet List",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M3 12h.01"}),c.jsx("path",{d:"M3 18h.01"}),c.jsx("path",{d:"M3 6h.01"}),c.jsx("path",{d:"M8 12h13"}),c.jsx("path",{d:"M8 18h13"}),c.jsx("path",{d:"M8 6h13"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleOrderedList().run(),active:t.isActive("orderedList"),title:"Ordered List",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M11 12h9"}),c.jsx("path",{d:"M11 18h9"}),c.jsx("path",{d:"M11 6h9"}),c.jsx("path",{d:"M4 10V4h1"}),c.jsx("path",{d:"M4 10h2"}),c.jsx("path",{d:"M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleTaskList().run(),active:t.isActive("taskList"),title:"Task List",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"m3 17 2 2 4-4"}),c.jsx("path",{d:"m3 7 2 2 4-4"}),c.jsx("path",{d:"M13 6h8"}),c.jsx("path",{d:"M13 12h8"}),c.jsx("path",{d:"M13 18h8"})]})})]}),c.jsx(Ho,{}),c.jsx("div",{className:"format-toolbar__group",children:c.jsx(wn,{onClick:()=>{const s=t.getAttributes("link").href||"",i=window.prompt("Link URL:",s);i!==null&&(i===""?t.chain().focus().unsetLink().run():t.chain().focus().setLink({href:i}).run())},active:t.isActive("link"),title:"Link (Ctrl+K)",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),c.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})})}),c.jsx(Ho,{}),c.jsxs("div",{className:"format-toolbar__group",children:[c.jsx(wn,{onClick:()=>t.chain().focus().toggleBlockquote().run(),active:t.isActive("blockquote"),title:"Blockquote",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 6H3"}),c.jsx("path",{d:"M21 12H8"}),c.jsx("path",{d:"M21 18H8"}),c.jsx("path",{d:"M3 12v6"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().toggleCodeBlock().run(),active:t.isActive("codeBlock"),title:"Code Block",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),c.jsx("path",{d:"m10 9-3 3 3 3"}),c.jsx("path",{d:"m14 15 3-3-3-3"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().setHorizontalRule().run(),title:"Horizontal Rule",children:c.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M5 12h14"})})})]}),c.jsx(Ho,{}),c.jsxs("div",{className:"format-toolbar__group",children:[c.jsx(wn,{onClick:()=>{var s;return(s=n.current)==null?void 0:s.click()},title:"Insert Image",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),c.jsx("circle",{cx:"9",cy:"9",r:"2"}),c.jsx("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]})}),c.jsx(wn,{onClick:()=>t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),title:"Insert Table",children:c.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),c.jsx("path",{d:"M12 3v18"}),c.jsx("path",{d:"M3 9h18"}),c.jsx("path",{d:"M3 15h18"})]})})]}),c.jsx("input",{ref:n,type:"file",accept:"image/*",className:"format-toolbar__file-input",onChange:r})]})}const p2="ow-right-rail",Jg=280,N5=220,C5=520,m2=x.createContext(null);function _5(){const t={open:!0,activeTab:"activity",width:Jg};try{const e=localStorage.getItem(p2);if(!e)return t;const n=JSON.parse(e);return{open:!!n.open,activeTab:n.activeTab??null,width:g2(typeof n.width=="number"?n.width:Jg)}}catch{return t}}function g2(t){return Number.isFinite(t)?Math.max(N5,Math.min(C5,t)):Jg}function T5({children:t}){const[e,n]=x.useState(()=>_5());x.useEffect(()=>{try{localStorage.setItem(p2,JSON.stringify(e))}catch{}},[e]);const r=x.useCallback(d=>{n(f=>({...f,open:!0,activeTab:d}))},[]),s=x.useCallback(()=>{n(d=>({...d,open:!1}))},[]),i=x.useCallback(()=>{n(d=>({...d,open:!d.open}))},[]),o=x.useCallback(d=>{n(f=>({...f,width:g2(d)}))},[]),l=x.useMemo(()=>({...e,openTab:r,closeRail:s,toggleRail:i,setWidth:o}),[e,r,s,i,o]);return c.jsx(m2.Provider,{value:l,children:t})}function Jd(){const t=x.useContext(m2);if(!t)throw new Error("useRightRail must be used inside <RightRailProvider>");return t}const Sn={strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round"},j5=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M9 12l2 2 4-4",stroke:"currentColor",...Sn}),c.jsx("path",{d:"M21 12c0 4.97-4.03 9-9 9s-9-4.03-9-9 4.03-9 9-9c2.3 0 4.4.86 6 2.27",stroke:"currentColor",...Sn})]}),M5=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",...Sn}),c.jsx("path",{d:"M12 7v5l3 3",stroke:"currentColor",...Sn})]}),A5=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",stroke:"currentColor",...Sn}),c.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",stroke:"currentColor",...Sn})]}),R5=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",stroke:"currentColor",...Sn}),c.jsx("polyline",{points:"7 10 12 15 17 10",stroke:"currentColor",...Sn}),c.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3",stroke:"currentColor",...Sn})]}),O5=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:c.jsx("path",{d:"M3 12h3l3-8 4 16 3-8h5",stroke:"currentColor",...Sn})}),I5=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M12 22v-5",stroke:"currentColor",...Sn}),c.jsx("path",{d:"M9 8V2",stroke:"currentColor",...Sn}),c.jsx("path",{d:"M15 8V2",stroke:"currentColor",...Sn}),c.jsx("path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",stroke:"currentColor",...Sn})]}),L5=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("circle",{cx:"12",cy:"5",r:"3",stroke:"currentColor",...Sn}),c.jsx("circle",{cx:"5",cy:"19",r:"3",stroke:"currentColor",...Sn}),c.jsx("circle",{cx:"19",cy:"19",r:"3",stroke:"currentColor",...Sn}),c.jsx("line",{x1:"12",y1:"8",x2:"5",y2:"16",stroke:"currentColor",...Sn}),c.jsx("line",{x1:"12",y1:"8",x2:"19",y2:"16",stroke:"currentColor",...Sn})]}),D5=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",stroke:"currentColor",...Sn}),c.jsx("circle",{cx:"13.5",cy:"6.5",r:"1",fill:"currentColor",stroke:"none"}),c.jsx("circle",{cx:"17.5",cy:"10.5",r:"1",fill:"currentColor",stroke:"none"}),c.jsx("circle",{cx:"6.5",cy:"12.5",r:"1",fill:"currentColor",stroke:"none"}),c.jsx("circle",{cx:"8.5",cy:"7.5",r:"1",fill:"currentColor",stroke:"none"})]}),v2=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:c.jsx("path",{d:"M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),P5=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M15 3v18",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M9 10l2 2-2 2",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),B5=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M15 3v18",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M10 10l-2 2 2 2",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});function $5({title:t,onTitleChange:e,onToggleSidebar:n,canGoBack:r,canGoForward:s,onGoBack:i,onGoForward:o,editor:l,onToggleToolbar:d,toolbarOpen:f,focusMode:h,onToggleFocusMode:m}){const{open:g,openTab:v,activeTab:b}=Jd(),[k,w]=x.useState(!1),[,E]=x.useState(0),C=x.useRef(null),[T,j]=x.useState(null);x.useEffect(()=>{fetch("/api/update-info").then(B=>B.json()).then(B=>{B.updateAvailable&&j({currentVersion:B.currentVersion,latestVersion:B.updateAvailable})}).catch(()=>{})},[]);const _=x.useCallback(()=>{w(!0),setTimeout(()=>{var B;return(B=C.current)==null?void 0:B.select()},0)},[]),A=x.useCallback(()=>{w(!1)},[]),O=x.useCallback(B=>{B.key==="Enter"&&w(!1),B.key==="Escape"&&w(!1)},[]);return x.useEffect(()=>{if(!l)return;const B=()=>E($=>$+1);return l.on("transaction",B),()=>{l.off("transaction",B)}},[l]),c.jsxs("div",{className:"titlebar",children:[c.jsxs("div",{className:"titlebar-left",children:[n&&c.jsx("button",{className:"titlebar-menu-btn",onClick:n,title:"Open sidebar",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M9 3v18",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M14 10l2 2-2 2",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}),i&&c.jsx("button",{className:"titlebar-nav-btn",onClick:i,disabled:!r,title:"Go back (Alt+Left)",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M10 3L5 8l5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),o&&c.jsx("button",{className:"titlebar-nav-btn",onClick:o,disabled:!s,title:"Go forward (Alt+Right)",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M6 3l5 5-5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),l&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"titlebar-divider"}),c.jsx("button",{className:"titlebar-nav-btn",onClick:()=>l.chain().focus().undo().run(),disabled:!l.can().undo(),title:"Undo (Ctrl+Z)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M3 10h10a5 5 0 0 1 0 10H9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M7 6L3 10l4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}),c.jsx("button",{className:"titlebar-nav-btn",onClick:()=>l.chain().focus().redo().run(),disabled:!l.can().redo(),title:"Redo (Ctrl+Y)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M21 10H11a5 5 0 0 0 0 10h4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M17 6l4 4-4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})})]})]}),c.jsxs("div",{className:"titlebar-center",children:[k?c.jsx("input",{ref:C,className:"titlebar-input",value:t,onChange:B=>e(B.target.value),onBlur:A,onKeyDown:O,autoFocus:!0}):c.jsx("span",{className:"titlebar-title",onDoubleClick:_,children:t}),T&&c.jsxs("span",{className:"titlebar-update-badge",title:`Update available: v${T.currentVersion} → v${T.latestVersion}
205
- Run: npm update -g openwriter`,children:["v",T.latestVersion]})]}),c.jsxs("div",{className:"titlebar-right",children:[!g&&m&&c.jsx("button",{className:`titlebar-nav-btn${h?" titlebar-nav-btn--active":""}`,onClick:m,title:"Focus mode","aria-label":"Focus mode","aria-pressed":h,children:c.jsx(v2,{})}),!g&&d&&c.jsx("button",{className:`titlebar-nav-btn${f?" titlebar-nav-btn--active":""}`,onClick:d,title:"Toggle format toolbar","aria-label":"Toggle format toolbar","aria-pressed":f,children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 20h16"}),c.jsx("path",{d:"m6 16 6-12 6 12"}),c.jsx("path",{d:"M8 12h8"})]})}),!g&&c.jsx("button",{className:"titlebar-nav-btn",onClick:()=>v(b||"activity"),title:"Show right rail","aria-label":"Show right rail",children:c.jsx(B5,{})})]})]})}function Ln(t,e){let n=null;return t.state.doc.descendants((r,s)=>{var i;return((i=r.attrs)==null?void 0:i.id)===e?(n={node:r,pos:s},!1):!0}),n}function Yd(t,e){const n=[];return t.state.doc.descendants((r,s)=>{var i;return((i=r.attrs)==null?void 0:i.pendingGroupId)===e&&n.push({nodeId:r.attrs.id,pos:s,node:r}),!0}),n}function ta(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID().replace(/-/g,"").slice(0,8):Math.random().toString(16).slice(2,10)}function Td(t){return t?Array.isArray(t)?t.map(Td).join(""):t.text?t.text:t.content&&Array.isArray(t.content)?t.content.map(e=>Td(e)).join(""):"":""}const z5=new Set(["paragraph","heading","codeBlock","horizontalRule","table","image"]);function jd(t,e){for(const n of t)n.type&&z5.has(n.type)?n.attrs={...n.attrs,pendingStatus:e}:n.content&&jd(n.content,e)}function Yg(t,e,n,r){const s=Array.isArray(n)?n:[n],i=(r==null?void 0:r.autoAccept)===!0;if(e.nodeId&&!e.afterNodeId&&!e.beforeNodeId){const m=Ln(t,e.nodeId);if(!m)return{success:!1,error:`Node ${e.nodeId} not found`};const g=s.map((v,b)=>{var k;return{...v,attrs:{...v.attrs,id:((k=v.attrs)==null?void 0:k.id)||(b===0?e.nodeId:ta())}}});i||jd(g,"insert");try{return t.chain().deleteRange({from:m.pos,to:m.pos+m.node.nodeSize}).insertContentAt(m.pos,g).run(),{success:!0,nodeId:e.nodeId}}catch(v){return{success:!1,error:`Failed to replace empty node: ${v}`}}}if(!e.afterNodeId&&!e.beforeNodeId)return{success:!1,error:"Insert requires afterNodeId, beforeNodeId, or nodeId"};const o=e.afterNodeId||e.beforeNodeId,l=!!e.afterNodeId,d=Ln(t,o);if(!d)return{success:!1,error:`Anchor node ${o} not found`};if(!i){const m=Td(n),g=l?d.pos+d.node.nodeSize:0,v=l?d.pos+d.node.nodeSize+5e3:d.pos;let b=null;if(t.state.doc.nodesBetween(g,Math.min(v,t.state.doc.content.size),k=>{var w,E;return((w=k.attrs)==null?void 0:w.pendingStatus)==="insert"&&((E=k.attrs)!=null&&E.id)&&(k.textContent||"")===m?(b=k.attrs.id,!1):!0}),b)return{success:!0,nodeId:b}}const f=s.map(m=>{var g;return{...m,attrs:{...m.attrs,id:((g=m.attrs)==null?void 0:g.id)||ta()}}});i||jd(f,"insert");const h=l?d.pos+d.node.nodeSize:d.pos;try{return t.chain().insertContentAt(h,f).run(),{success:!0,nodeId:f[0].attrs.id}}catch(m){return{success:!1,error:`Failed to insert content: ${m}`}}}function iy(t,e,n,r,s){var w,E,C,T,j,_;const i=Ln(t,e);if(!i)return{success:!1,error:`Node ${e} not found`};const{node:o,pos:l}=i,d=Array.isArray(n)?n:[n],f=(s==null?void 0:s.autoAccept)===!0,m=!((w=o.attrs)!=null&&w.pendingOriginalContent)?o.toJSON():o.attrs.pendingOriginalContent,v=((E=d[0])==null?void 0:E.type)==="listItem"&&((_=(j=(T=(C=d[0])==null?void 0:C.content)==null?void 0:T[0])==null?void 0:j.attrs)==null?void 0:_.pendingStatus)!=null?{...d[0],attrs:{...d[0].attrs,id:e}}:{...d[0],attrs:f?{...d[0].attrs,id:e}:{...d[0].attrs,id:e,pendingStatus:"rewrite",pendingOriginalContent:m,...r?{pendingSelectionFrom:r.selectionFrom,pendingSelectionTo:r.selectionTo,pendingOriginalFrom:r.originalFrom,pendingOriginalTo:r.originalTo}:{}}},b=d.slice(1).map(A=>{var O;return{...A,attrs:{...A.attrs,id:((O=A.attrs)==null?void 0:O.id)||ta()}}});f||jd(b,"insert");const k=[v,...b];try{return t.chain().command(({tr:A})=>{const O=k.map(B=>t.state.schema.nodeFromJSON(B));return A.replaceWith(l,l+o.nodeSize,O),!0}).run(),{success:!0,nodeId:e}}catch(A){return{success:!1,error:`Failed to rewrite: ${A}`}}}function F5(t,e,n){if(e.length===0)return{success:!1,error:"Range rewrite requires original IDs"};if(!n||n.length===0)return{success:!1,error:"Range rewrite requires new content (received empty)"};if(n.map(m=>Td(m)).join("").trim().length===0)return{success:!1,error:"Range rewrite content is empty (no text) — aborting"};const s=Ln(t,e[0]),i=Ln(t,e[e.length-1]);if(!s||!i)return{success:!1,error:"Could not find original nodes for range rewrite"};const o=[];for(const m of e){const g=Ln(t,m);g&&o.push(g.node.toJSON())}const l=s.pos,d=i.pos+i.node.nodeSize,f=ta()+ta(),h=n.map((m,g)=>{var v;return{...m,attrs:{...m.attrs,id:((v=m.attrs)==null?void 0:v.id)||ta(),pendingStatus:"rewrite",pendingGroupId:f,...g===0?{pendingOriginalContent:o}:{}}}});try{return t.chain().deleteRange({from:l,to:d}).insertContentAt(l,h).run(),{success:!0,nodeId:h[0].attrs.id}}catch(m){return{success:!1,error:`Failed to apply range rewrite: ${m}`}}}function y2(t,e,n){var l;const r=Ln(t,e);if(!r)return{success:!1,error:`Node ${e} not found`};const{node:s,pos:i}=r,o=(n==null?void 0:n.autoAccept)===!0;if(!o&&((l=s.attrs)==null?void 0:l.pendingStatus)==="delete")return{success:!0,nodeId:e};try{return o?t.chain().deleteRange({from:i,to:i+s.nodeSize}).run():t.chain().command(({tr:d})=>(d.setNodeMarkup(i,void 0,{...s.attrs,pendingStatus:"delete"}),!0)).run(),{success:!0,nodeId:e}}catch(d){return{success:!1,error:`Failed to ${o?"delete":"mark for deletion"}: ${d}`}}}function U5(t,e){const n=e.autoAccept?{autoAccept:!0}:void 0;if(e.operation==="rewrite"&&e.nodeId&&e.content){const r=iy(t,e.nodeId,e.content,null,n);return{success:r.success,error:r.error}}if(e.operation==="insert"&&e.content){let r=null;if(e.nodeId&&!e.afterNodeId?r={nodeId:e.nodeId}:e.afterNodeId&&(r={afterNodeId:e.afterNodeId}),!r)return{success:!1,error:"Insert requires afterNodeId or nodeId"};const s=Yg(t,r,e.content,n);return{success:s.success,error:s.error}}if(e.operation==="delete"&&e.nodeId){const r=y2(t,e.nodeId,n);return{success:r.success,error:r.error}}return{success:!1,error:`Invalid operation: ${e.operation}`}}function Tp(t,e){if(e.length===0)return;if(e.length===1){U5(t,e[0]);return}const n=t.state.schema;t.chain().command(({tr:r})=>{var s;for(const i of e)try{const o=i.autoAccept===!0;if(i.operation==="rewrite"&&i.nodeId&&i.content){const l=Ya(r.doc,i.nodeId);if(!l){console.warn("[openwriter] rewrite skipped — node id not found in editor",{nodeId:i.nodeId});continue}const f=(Array.isArray(i.content)?i.content:[i.content]).map(h=>n.nodeFromJSON(h));r.replaceWith(l.pos,l.pos+l.node.nodeSize,f)}else if(i.operation==="insert"&&i.content){const d=(Array.isArray(i.content)?i.content:[i.content]).map(f=>n.nodeFromJSON(f));if(!o){const f=d.map(h=>h.textContent||"").join("");if(f&&i.afterNodeId){const h=Ya(r.doc,i.afterNodeId);if(h){const m=h.pos+h.node.nodeSize,g=Math.min(m+5e3,r.doc.content.size);let v=!1;if(r.doc.nodesBetween(m,g,b=>{var k;return v?!1:((k=b.attrs)==null?void 0:k.pendingStatus)==="insert"&&(b.textContent||"")===f?(v=!0,!1):!0}),v)continue}}}if(i.nodeId&&!i.afterNodeId){const f=Ya(r.doc,i.nodeId);if(!f){console.warn("[openwriter] insert (replace) skipped — node id not found in editor",{nodeId:i.nodeId});continue}r.replaceWith(f.pos,f.pos+f.node.nodeSize,d)}else if(i.afterNodeId){const f=Ya(r.doc,i.afterNodeId);if(!f){console.warn("[openwriter] insert (after) skipped — anchor id not found in editor",{afterNodeId:i.afterNodeId});continue}const h=f.pos+f.node.nodeSize;r.insert(h,be.fromArray(d))}}else if(i.operation==="delete"&&i.nodeId){const l=Ya(r.doc,i.nodeId);if(!l){console.warn("[openwriter] delete skipped — node id not found in editor",{nodeId:i.nodeId});continue}if(o)r.delete(l.pos,l.pos+l.node.nodeSize);else{if(((s=l.node.attrs)==null?void 0:s.pendingStatus)==="delete")continue;r.setNodeMarkup(l.pos,void 0,{...l.node.attrs,pendingStatus:"delete"})}}}catch{continue}return!0}).run()}function Ya(t,e){let n=null;return t.descendants((r,s)=>{var i;return((i=r.attrs)==null?void 0:i.id)===e?(n={node:r,pos:s},!1):!0}),n}function H5(t,e){if(!e||e.length===0||t.isDestroyed)return;const n=new Map(e.map(r=>[r.oldId,r.newId]));t.chain().command(({tr:r})=>{const s=[];r.doc.descendants((i,o)=>{var d;const l=(d=i.attrs)==null?void 0:d.id;l&&n.has(l)&&s.push({pos:o,attrs:{...i.attrs,id:n.get(l)}})});for(const{pos:i,attrs:o}of s)r.setNodeMarkup(i,void 0,o);return!0}).run()}function W5(t,e,n,r){const s=[];if(r==="delete"){for(const o of n)s.push(y2(t,o));return s}if(r==="insert"){const o=n[n.length-1];return o&&e.length>0&&s.push(Yg(t,{nodeId:o},e)),s}if(n.length>1){const o=F5(t,n,e);return s.push(o),s}const i=iy(t,n[0],e[0]);if(s.push(i),e.length>1){const o=e.slice(1);s.push(Yg(t,{afterNodeId:n[0]},o))}return s}const hk="[[START_SELECTION]]",pk="[[END_SELECTION]]";function q5(t){if(!(t!=null&&t.content)||!Array.isArray(t.content))return 0;let e=0;for(const n of t.content)n.type==="text"&&typeof n.text=="string"?e+=n.text.length:n.type==="hardBreak"&&(e+=1);return e}function mu(t,e,n){if(!(t!=null&&t.content)||!Array.isArray(t.content))return;const r=q5(t);let s=Math.max(0,Math.min(e,r));for(let i=0;i<t.content.length;i++){const o=t.content[i];if(o.type==="text"&&typeof o.text=="string"){if(s<=o.text.length){const l=Math.max(0,Math.min(o.text.length,s));o.text=o.text.slice(0,l)+n+o.text.slice(l);return}s-=o.text.length;continue}if(o.type==="hardBreak"){if(s===0){t.content.splice(i+1,0,{type:"text",text:n});return}s-=1;continue}if(s===0){t.content.splice(i,0,{type:"text",text:n});return}}t.content.push({type:"text",text:n})}function V5(t,e,n){const r=JSON.parse(JSON.stringify(t));return r.length===0?r:r.length===1?(mu(r[0],n,pk),mu(r[0],e,hk),r):(mu(r[0],e,hk),mu(r[r.length-1],n,pk),r)}function K5(t){const e=r=>r.replace(/\[\[(START|END)_SELECTION]]/g,""),n=r=>{r.type==="text"&&typeof r.text=="string"&&(r.text=e(r.text)),r.content&&Array.isArray(r.content)&&r.content.forEach(n)};Array.isArray(t)?t.forEach(n):n(t)}function mk(t,e){return t.docId&&e.includes(t.docId)?!0:e.includes(t.filename)}const G5=[{action:"comment",label:"Comment",shortcut:"M",condition:"has-selection"},{action:"delete",label:"Delete",shortcut:"D"}];function J5({editorRef:t,allEditors:e,documentId:n}){const[r,s]=x.useState(!1),[i,o]=x.useState({x:0,y:0}),[l,d]=x.useState(!1),[f,h]=x.useState(""),[m,g]=x.useState(!1),[v,b]=x.useState(""),[k,w]=x.useState(!1),[E,C]=x.useState([]),[T,j]=x.useState([]),[_,A]=x.useState(!1),[O,B]=x.useState(""),[$,W]=x.useState([]),[J,z]=x.useState(!1),[G,D]=x.useState(""),[U,q]=x.useState(null),[se,V]=x.useState(null),[te,K]=x.useState(null),[M,L]=x.useState(!1),[ee,fe]=x.useState(null),[ge,oe]=x.useState(null),we=x.useRef(null),xe=x.useRef(null),We=x.useRef(null),He=x.useCallback(ne=>{if(e&&e.length>0){for(const he of e)if(he.view.dom.contains(ne))return he}const de=t.current;return de&&de.view.dom.contains(ne)?de:null},[e,t]);x.useLayoutEffect(()=>{const ne=we.current;if(!ne||!r)return;const de=ne.getBoundingClientRect(),he=8;let{x:Ge,y:Pe}=i;Pe+de.height+he>window.innerHeight&&(Pe=i.y-de.height),Ge+de.width+he>window.innerWidth&&(Ge=i.x-de.width),Pe<he&&(Pe=he),Ge<he&&(Ge=he),(Ge!==i.x||Pe!==i.y)&&o({x:Ge,y:Pe})},[r,i]);const Ze=x.useCallback(()=>{fetch("/api/plugins").then(ne=>ne.json()).then(ne=>{const de=[];for(const he of ne.plugins||[]){const Ge=he.displayName||void 0;for(const Pe of he.contextMenuItems||[])de.push({...Pe,pluginDisplayName:Ge})}W(de)}).catch(()=>{})},[]);x.useEffect(()=>{Ze()},[Ze]),x.useEffect(()=>{const ne=()=>Ze();return window.addEventListener("ow-plugins-changed",ne),()=>window.removeEventListener("ow-plugins-changed",ne)},[Ze]),x.useEffect(()=>{const ne=de=>{we.current&&!we.current.contains(de.target)&&(s(!1),g(!1),w(!1),z(!1),D(""),q(null),V(null),fe(null))};return document.addEventListener("mousedown",ne),()=>document.removeEventListener("mousedown",ne)},[]);const Oe=x.useCallback(()=>{const ne=We.current||t.current;return ne?ne.isActive("link"):!1},[t]),Ke=x.useCallback(()=>{const ne=We.current||t.current,de=xe.current;if(!ne||!de)return!1;const{from:he,to:Ge}=de;let Pe=!1;return ne.state.doc.nodesBetween(he,Ge,et=>{var ot;return(ot=et.attrs)!=null&&ot.pendingStatus&&(Pe=!0),!Pe}),Pe},[t]),pt=x.useCallback(()=>{const ne=We.current||t.current,de=xe.current,he=(de==null?void 0:de.from)??0,Ge=(de==null?void 0:de.to)??0,Pe=he!==Ge,et=(()=>{if(!ne)return!1;try{return ne.state.doc.resolve(he).parent.content.size===0}catch{return!1}})(),ot=Ke(),bt=[];for(const Ye of $)Ye.condition==="has-selection"&&!Pe||Ye.condition==="empty-node"&&!et||bt.push({action:Ye.action,label:Ye.label,shortcut:Ye.shortcut,isPlugin:!0,promptForInput:Ye.promptForInput,pluginDisplayName:Ye.pluginDisplayName});for(const Ye of G5)Ye.condition==="has-selection"&&(!Pe||ot)||bt.push(Ye);if(Pe&&bt.push({action:"link",label:"Link to doc",shortcut:"L"}),Oe()&&bt.push({action:"unlink",label:"Unlink"}),te&&te.entries.length>0&&bt.unshift({action:"see-connections",label:`See connections (${te.entries.length})`}),ee){const Ye=ee.title?`Go to "${ee.title}"`:"Go to target";bt.unshift({action:"go-to-target",label:Ye})}return bt},[t,Oe,$,Ke,te,ee]);x.useEffect(()=>{const ne=he=>{var Ye;if(he.button!==2)return;const Ge=He(he.target);if(!Ge)return;We.current=Ge;const{from:Pe,to:et}=Ge.state.selection,ot=[],bt=[];if(Pe!==et&&Ge.state.doc.nodesBetween(Pe,et,it=>{it.isBlock&&it.type.name!=="doc"&&(ot.push(it.toJSON()),it.attrs.id&&bt.push(it.attrs.id))}),ot.length===0){const{$from:it}=Ge.state.selection,gt=it.parent;gt&&gt.type.name!=="doc"&&(ot.push(gt.toJSON()),(Ye=gt.attrs)!=null&&Ye.id&&bt.push(gt.attrs.id))}xe.current={from:Pe,to:et,nodes:ot,nodeIds:bt}},de=he=>{var gt,Nt,Ie,Me,qe,F;if(!He(he.target)||he.shiftKey)return;const Pe=(Nt=(gt=he.target)==null?void 0:gt.closest)==null?void 0:Nt.call(gt,"[data-comment-id]"),et=(Pe==null?void 0:Pe.getAttribute("data-comment-id"))||null,ot=(Me=(Ie=he.target)==null?void 0:Ie.closest)==null?void 0:Me.call(Ie,".linked-paragraph[data-backlinks-node]"),bt=(ot==null?void 0:ot.getAttribute("data-backlinks-node"))||null,Ye=(F=(qe=he.target)==null?void 0:qe.closest)==null?void 0:F.call(qe,"span.doc-link[data-doc]"),it=(Ye==null?void 0:Ye.getAttribute("data-doc"))||null;if(he.preventDefault(),o({x:he.clientX,y:he.clientY}),s(!0),g(!1),w(!1),L(!1),z(!1),D(""),q(null),et){const ce=xe.current;if(!(!!ce&&ce.from!==ce.to)){const P=Ru().find(Z=>Z.id===et);if(P){V({id:P.id,text:P.text,note:P.note}),K(null);return}}}if(V(null),bt){const ce=m5(bt);K(ce.length>0?{nodeId:bt,entries:ce}:null)}else K(null);if(it){const ce=it.indexOf("?"),Ne=ce>=0?it.slice(0,ce):it,[P,Z]=Ne.split("#"),I=P&&/^[a-f0-9]{8}$/.test(P)?P:null,re=Z&&/^[a-f0-9]{8}$/.test(Z)?Z:null;if(I){const ye=E.find(Te=>Te.docId===I);fe({docId:I,nodeId:re,title:(ye==null?void 0:ye.title)||null}),ye||fetch("/api/documents").then(Te=>Te.json()).then(Te=>{if(Array.isArray(Te)){const Se=Te.map(me=>({filename:me.filename,title:me.title,docId:me.docId}));C(Se);const Ee=Se.find(me=>me.docId===I);Ee&&fe(me=>me&&me.docId===I?{...me,title:Ee.title}:me)}}).catch(()=>{})}else fe(null)}else fe(null)};return document.addEventListener("mousedown",ne,!0),document.addEventListener("contextmenu",de),()=>{document.removeEventListener("mousedown",ne,!0),document.removeEventListener("contextmenu",de)}},[He]);const Je=x.useCallback(async(ne,de)=>{var Nt,Ie,Me,qe,F;const he=We.current||t.current;if(!he)return;const Ge=xe.current;if(!Ge||Ge.nodes.length===0){console.warn("[ContextMenu] No captured selection for action:",ne);return}let{nodes:Pe,nodeIds:et}=Ge;const{from:ot,to:bt}=Ge;d(!0),s(!1),g(!1);const Ye=`ctx-${Date.now()}`,it=ne.includes(":")?ne.split(":").slice(1).join(":"):ne,gt=["insert","fill","fill-sentence"].includes(it);if(gt)he.commands.showInsertionLoading(Ye,ot);else{const ce=he.state.doc.resolve(ot),Ne=he.state.doc.resolve(bt),P=ce.sameParent(Ne)&&ot!==bt;he.commands.applyLoadingEffect(Ye,ot,bt,P?"selection":"paragraph")}try{const ce=[],Ne=[],P=new Set(et);let Z=!1;const I=he.state.doc;for(let Ft=0;Ft<I.childCount;Ft++){const xt=I.child(Ft),Pn=(Nt=xt.attrs)==null?void 0:Nt.id;if(Pn&&P.has(Pn))Z=!0;else if(Z){const un=xt.textContent.trim();un&&Ne.push(un)}else{const un=xt.textContent.trim();un&&ce.push(un)}}let re=Pe,ye=!1,Te=0,Se=0;const Ee=ot!==bt?he.state.doc.resolve(ot):null,me=ot!==bt?he.state.doc.resolve(bt):null;if((Ee&&me?Ee.sameParent(me):!1)&&Ee&&Pe.length===1){const Ft=Ee.start(Ee.depth);Te=ot-Ft,Se=bt-Ft;const xt=((Me=(Ie=Pe[0])==null?void 0:Ie.content)==null?void 0:Me.reduce((Pn,un)=>{var yr;return Pn+(((yr=un.text)==null?void 0:yr.length)||(un.type==="hardBreak"?1:0))},0))??0;(Te>0||Se<xt)&&(re=V5(Pe,Te,Se),ye=!0)}const Ct=he.state.doc.textContent,en={nodes:re,action:it,nodeIds:et,contextBefore:ce.slice(-3),contextAfter:Ne.slice(0,3),fullDocument:Ct,documentId:n,debug:!0};ye&&(en.hasSelectionMarkers=!0),de&&(en.instruction=de);const on=await fetch(`${window.location.origin}/api/voice/apply-editor`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(en)});if(!on.ok){const Ft=await on.json().catch(()=>({}));console.error("[ContextMenu] API error:",on.status,Ft);return}const Wt=await on.json();if(Wt.success&&Wt.nodes){let Ft=Wt.nodes;if(Ft.length===1&&Array.isArray(Ft[0])&&(Ft=Ft[0]),K5(Ft),ye&&Ft.length===1&&et.length===1){const xt=_r=>(_r==null?void 0:_r.reduce((Wr,is)=>{var ie;return Wr+(((ie=is.text)==null?void 0:ie.length)||(is.type==="hardBreak"?1:0))},0))??0,Pn=xt((qe=Pe[0])==null?void 0:qe.content),un=xt((F=Ft[0])==null?void 0:F.content),yr={selectionFrom:Te,selectionTo:un-(Pn-Se),originalFrom:Te,originalTo:Se};iy(he,et[0],Ft[0],yr)}else W5(he,Ft,et,it);window.dispatchEvent(new CustomEvent("ow-pending-write-applied")),Wt.debug&&fetch("/api/prompt-debug",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:it,debug:Wt.debug,metadata:Wt.metadata})}).catch(()=>{})}else console.warn("[ContextMenu] Unexpected response:",Wt)}catch(ce){console.error("[ContextMenu] Plugin action failed:",ce)}finally{gt?he.commands.removeInsertionLoading(Ye):he.commands.removeLoadingEffect(Ye),d(!1)}},[t]),pe=x.useCallback(async ne=>{const de=We.current||t.current;if(!de)return;const{$from:he}=de.state.selection,Ge=he.before(he.depth),Pe=he.after(he.depth),et=he.parent.content.size===0;d(!0),s(!1),g(!1),et?de.chain().focus().deleteRange({from:Ge,to:Pe}).insertContentAt(Ge,{type:"imageLoading"}).run():de.chain().focus().insertContentAt(Pe,{type:"imageLoading"}).run();let ot=-1;de.state.doc.descendants((bt,Ye)=>{if(bt.type.name==="imageLoading"&&ot===-1)return ot=Ye,bt.nodeSize,!1});try{const bt=await fetch("/api/image-gen/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:ne})}),Ye=await bt.json().catch(()=>({success:!1,error:`Generation failed (${bt.status})`}));if(Ye.success&&Ye.src){let it=-1,gt=0;if(de.state.doc.descendants((Nt,Ie)=>{if(Nt.type.name==="imageLoading"&&it===-1)return it=Ie,gt=Nt.nodeSize,!1}),it>=0){const{tr:Nt}=de.state;Nt.replaceWith(it,it+gt,de.schema.nodes.image.create({src:Ye.src,alt:ne})),de.view.dispatch(Nt)}}else{console.error("[ContextMenu] Image generation failed:",Ye.error);let it=-1,gt=0;if(de.state.doc.descendants((Nt,Ie)=>{if(Nt.type.name==="imageLoading"&&it===-1)return it=Ie,gt=Nt.nodeSize,!1}),it>=0){const{tr:Nt}=de.state;Nt.delete(it,it+gt),de.view.dispatch(Nt)}}}catch(bt){console.error("[ContextMenu] Image generation failed:",bt);let Ye=-1,it=0;if(de.state.doc.descendants((gt,Nt)=>{if(gt.type.name==="imageLoading"&&Ye===-1)return Ye=Nt,it=gt.nodeSize,!1}),Ye>=0){const{tr:gt}=de.state;gt.delete(Ye,Ye+it),de.view.dispatch(gt)}}finally{d(!1)}},[t]),mt=x.useCallback(ne=>{const{action:de,isPlugin:he,promptForInput:Ge}=ne;if(he&&Ge){b(de),g(!0);return}if(he){if(de.startsWith("img:"))return;Je(de);return}if(de==="comment"){z(!0);return}if(de==="delete"){const Pe=We.current||t.current,et=xe.current;if(Pe&&et&&et.nodeIds.length>0){const{tr:ot}=Pe.state,bt=new Set(et.nodeIds),Ye=[];Pe.state.doc.descendants((it,gt)=>{var Nt;if((Nt=it.attrs)!=null&&Nt.id&&bt.has(it.attrs.id))return Ye.push({from:gt,to:gt+it.nodeSize}),!1});for(const it of Ye.reverse())ot.delete(it.from,it.to);Ye.length>0&&Pe.view.dispatch(ot)}s(!1);return}if(de==="link"){const Pe=We.current||t.current;if(Pe){const et=[];Pe.state.doc.descendants(ot=>{var bt;(bt=ot.marks)==null||bt.forEach(Ye=>{var it,gt;if(Ye.type.name==="link"&&((gt=(it=Ye.attrs)==null?void 0:it.href)!=null&&gt.startsWith("doc:"))){const Nt=k5(Ye.attrs.href);Nt&&!et.includes(Nt)&&et.push(Nt)}})}),j(et)}fetch("/api/documents").then(et=>et.json()).then(et=>{Array.isArray(et)&&C(et.map(ot=>({filename:ot.filename,title:ot.title,docId:ot.docId}))),A(!1),B(""),w(!0)}).catch(()=>{});return}if(de==="unlink"){const Pe=We.current||t.current;Pe&&Pe.chain().focus().unsetLink().run(),s(!1);return}if(de==="see-connections"){fetch("/api/documents").then(Pe=>Pe.json()).then(Pe=>{Array.isArray(Pe)&&C(Pe.map(et=>({filename:et.filename,title:et.title,docId:et.docId})))}).catch(()=>{}),L(!0);return}if(de==="go-to-target"){ee&&window.dispatchEvent(new CustomEvent("ow-navigate-to-link",{detail:{docId:ee.docId,nodeId:ee.nodeId,filename:null,quote:null}})),s(!1),fe(null);return}},[Je,t,ee]),ft=x.useCallback(()=>{f.trim()&&(v.startsWith("img:")?pe(f.trim()):Je(v,f.trim()),h(""),b(""))},[Je,pe,v,f]),at=x.useCallback(()=>{if(!n)return;if(U){fetch("/api/comments",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:n,id:U.id,note:G.trim()})}).then(()=>{s(!1),z(!1),D(""),q(null)}).catch(ot=>{console.error("[ContextMenu] Comment edit failed:",ot)});return}const ne=We.current||t.current,de=xe.current;if(!ne||!de)return;const{from:he,to:Ge,nodeIds:Pe}=de;if(he===Ge||Pe.length===0)return;const et=ne.state.doc.textBetween(he,Ge,`
206
- `);et.trim()&&fetch("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:n,text:et,note:G.trim(),nodeId:Pe[Pe.length-1],nodeIds:Pe})}).then(()=>{s(!1),z(!1),D("")}).catch(ot=>{console.error("[ContextMenu] Comment create failed:",ot)})},[t,n,G,U]),nt=x.useCallback(()=>{se&&(q({id:se.id,text:se.text}),D(se.note),z(!0),V(null))},[se]),ht=x.useCallback(()=>{se&&fetch("/api/comments/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[se.id]})}).then(()=>{s(!1),V(null)}).catch(ne=>{console.error("[ContextMenu] Comment resolve failed:",ne)})},[se]),Fe=x.useCallback(()=>{se&&fetch("/api/comments",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[se.id]})}).then(()=>{s(!1),V(null)}).catch(ne=>{console.error("[ContextMenu] Comment delete failed:",ne)})},[se]),ve=x.useCallback((ne,de)=>{const he=We.current||t.current;if(he){const Ge=ne.docId?_p({docId:ne.docId,nodeId:de==null?void 0:de.nodeId,quote:de==null?void 0:de.quote}):_p({filename:ne.filename});he.chain().focus().setLink({href:Ge}).run()}fetch("/api/auto-tag-link",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetFile:ne.filename})}).catch(()=>{}),s(!1),w(!1),oe(null)},[t]),X=x.useCallback(ne=>{if(!ne.docId){ve(ne);return}oe({docId:ne.docId,filename:ne.filename,title:ne.title,paragraphs:[],loading:!0}),fetch(`/api/documents/by-doc-id/${ne.docId}/paragraphs`).then(de=>de.json()).then(de=>{oe(he=>he&&he.docId===ne.docId?{...he,paragraphs:Array.isArray(de.paragraphs)?de.paragraphs:[],loading:!1}:he)}).catch(()=>{oe(de=>de&&de.docId===ne.docId?{...de,paragraphs:[],loading:!1}:de)})},[ve]),Be=x.useCallback(()=>{const ne=O.trim();if(!ne)return;const de=We.current||t.current;de&&(fetch("/api/create-link-doc",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:ne})}).then(he=>he.json()).then(he=>{if(he.filename){const Ge=_p(he.docId?{docId:he.docId}:{filename:he.filename});de.chain().focus().setLink({href:Ge}).run()}}).catch(()=>{}),s(!1),w(!1),A(!1),B(""))},[t,O]);return r?c.jsx("div",{ref:we,className:"context-menu",style:{left:i.x,top:i.y},children:l?c.jsx("div",{className:"context-menu-loading",children:"Applying..."}):J?c.jsxs("div",{className:"context-menu-comment-editor",children:[(()=>{const ne=(U==null?void 0:U.text)??(()=>{const de=We.current||t.current,he=xe.current;return!de||!he||he.from===he.to?"":de.state.doc.textBetween(he.from,he.to,`
207
- `)})();return ne?c.jsx("div",{className:"context-menu-comment-quote",children:ne}):null})(),c.jsx("textarea",{autoFocus:!0,className:"context-menu-comment-textarea",value:G,onChange:ne=>D(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&(ne.metaKey||ne.ctrlKey)&&(ne.preventDefault(),at()),ne.key==="Escape"&&(s(!1),z(!1),D(""),q(null))},placeholder:"Note for agent (optional)...",rows:4}),c.jsxs("div",{className:"context-menu-comment-actions",children:[c.jsx("span",{className:"context-menu-comment-hint",children:"⌘↵ to save · Esc to cancel"}),c.jsx("button",{onClick:at,children:U?"Save":"Comment"})]})]}):se?c.jsxs(c.Fragment,{children:[c.jsx("button",{className:"context-menu-item",onClick:nt,children:c.jsx("span",{children:"Edit comment"})}),c.jsx("button",{className:"context-menu-item",onClick:ht,children:c.jsx("span",{children:"Resolve comment"})}),c.jsx("button",{className:"context-menu-item",onClick:Fe,children:c.jsx("span",{children:"Delete comment"})})]}):m?c.jsxs("div",{className:"context-menu-custom",children:[c.jsx("input",{autoFocus:!0,value:f,onChange:ne=>h(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&ft(),ne.key==="Escape"&&s(!1)},placeholder:"Custom instruction..."}),c.jsx("button",{onClick:ft,children:"Apply"})]}):ge?c.jsxs("div",{className:"context-menu-link-picker",children:[c.jsxs("div",{className:"context-menu-link-header",children:[c.jsx("button",{className:"context-menu-link-back",onClick:()=>oe(null),title:"Back to doc list",children:"←"}),c.jsxs("span",{children:['Pick paragraph in "',ge.title,'"']})]}),c.jsx("button",{className:"context-menu-item context-menu-new-link",onClick:()=>ve({filename:ge.filename,docId:ge.docId}),children:c.jsx("span",{children:"Link whole doc"})}),c.jsx("div",{className:"context-menu-link-list",children:ge.loading?c.jsx("div",{className:"context-menu-loading",children:"Loading…"}):ge.paragraphs.length===0?c.jsx("div",{className:"context-menu-loading",children:"No paragraphs"}):ge.paragraphs.map(ne=>{const de=ne.preview.replace(/…$/,"").slice(0,50),he=ne.type==="heading"?Math.max(0,(ne.level||1)-1)*12:12;return c.jsx("button",{className:`context-menu-item context-menu-paragraph-row context-menu-paragraph-row--${ne.type}`,style:{paddingLeft:8+he},onClick:()=>ve({filename:ge.filename,docId:ge.docId},{nodeId:ne.nodeId,quote:de}),children:c.jsx("span",{children:ne.preview})},ne.nodeId)})})]}):M&&te?c.jsxs("div",{className:"context-menu-link-picker",children:[c.jsxs("div",{className:"context-menu-link-header",children:["Linked from ",te.entries.length," ",te.entries.length===1?"place":"places"]}),c.jsx("div",{className:"context-menu-link-list",children:te.entries.map((ne,de)=>{const he=E.find(Pe=>Pe.docId===ne.from_doc),Ge=(he==null?void 0:he.title)||ne.from_doc;return c.jsxs("button",{className:"context-menu-item",onClick:()=>{window.dispatchEvent(new CustomEvent("ow-navigate-to-link",{detail:{docId:ne.from_doc,nodeId:ne.from_node,filename:null,quote:null}})),s(!1),L(!1)},children:[c.jsx("span",{children:Ge}),c.jsxs("span",{className:"context-menu-shortcut",children:['"',ne.text,'"']})]},`${ne.from_doc}-${ne.from_node}-${de}`)})})]}):k?c.jsxs("div",{className:"context-menu-link-picker",children:[c.jsx("div",{className:"context-menu-link-header",children:"Link to document"}),_?c.jsxs("div",{className:"context-menu-custom",children:[c.jsx("input",{autoFocus:!0,value:O,onChange:ne=>B(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&Be(),ne.key==="Escape"&&A(!1)},placeholder:"New document title..."}),c.jsx("button",{onClick:Be,children:"Create"})]}):c.jsx("button",{className:"context-menu-item context-menu-new-link",onClick:()=>A(!0),children:c.jsx("span",{children:"+ New link doc"})}),c.jsxs("div",{className:"context-menu-link-list",children:[T.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-section-header",children:"Linked in this doc"}),E.filter(ne=>mk(ne,T)).map(ne=>c.jsxs("div",{className:"context-menu-link-row",children:[c.jsx("button",{className:"context-menu-item context-menu-link-row__main",onClick:()=>ve(ne),children:c.jsx("span",{children:ne.title})}),ne.docId&&c.jsx("button",{className:"context-menu-link-row__drill",title:"Pick a paragraph in this doc",onClick:()=>X(ne),children:"▸"})]},`linked-${ne.filename}`))]}),c.jsx("div",{className:"context-menu-section-header",children:"All documents"}),E.filter(ne=>!mk(ne,T)).map(ne=>c.jsxs("div",{className:"context-menu-link-row",children:[c.jsx("button",{className:"context-menu-item context-menu-link-row__main",onClick:()=>ve(ne),children:c.jsx("span",{children:ne.title})}),ne.docId&&c.jsx("button",{className:"context-menu-link-row__drill",title:"Pick a paragraph in this doc",onClick:()=>X(ne),children:"▸"})]},ne.filename)),E.length===0&&c.jsx("div",{className:"context-menu-loading",children:"No documents"})]})]}):(()=>{const ne=pt();let de;return ne.map((he,Ge)=>{const Pe=he.isPlugin&&he.pluginDisplayName&&he.pluginDisplayName!==de,et=de!==void 0;he.isPlugin?de=he.pluginDisplayName:de=void 0;const ot=!he.isPlugin&&et;return c.jsxs("span",{children:[Pe&&c.jsx("div",{className:"context-menu-section-header",children:he.pluginDisplayName}),ot&&c.jsx("div",{className:"context-menu-divider"}),c.jsxs("button",{className:"context-menu-item",onClick:()=>mt(he),children:[c.jsx("span",{children:he.label}),he.shortcut&&c.jsx("span",{className:"context-menu-shortcut",children:he.shortcut})]})]},he.action)})})()}):null}const Y5=80,jp=8,Wo=8,X5=400;function gk(t){return t.nodeIds&&t.nodeIds.length>0?t.nodeIds:[t.nodeId]}function vk(t,e){const n=new Set(e);return t.every(r=>n.has(r))}function Q5(t,e){const n=e.find(s=>s.id===t);if(!n)return[];const r=gk(n);return e.filter(s=>{if(s.id===n.id)return!0;const i=gk(s);return vk(i,r)||vk(r,i)}).sort((s,i)=>(s.createdAt||"").localeCompare(i.createdAt||""))}function Z5({documentId:t}){const[e,n]=x.useState(null),[r,s]=x.useState({kind:"view"}),[i,o]=x.useState(""),[l,d]=x.useState(0),[f,h]=x.useState({left:0,top:0,placement:"above"}),m=x.useRef(null),g=x.useRef(null),v=x.useRef(null),b=x.useRef(null),k=x.useRef({kind:"view"});x.useEffect(()=>{b.current=e},[e]),x.useEffect(()=>{k.current=r},[r]),x.useEffect(()=>{const G=()=>d(D=>D+1);return window.addEventListener("ow-comments-changed",G),()=>window.removeEventListener("ow-comments-changed",G)},[]);const w=x.useCallback(()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)},[]),E=x.useCallback(()=>{w(),v.current=window.setTimeout(()=>{k.current.kind==="view"&&n(null)},Y5)},[w]),C=x.useCallback(()=>{w(),n(null),s({kind:"view"}),o("")},[w]),T=x.useMemo(()=>e?Q5(e.commentId,Ru()):[],[e,l]);x.useEffect(()=>{e&&T.length===0&&C()},[e,T.length,C]),x.useLayoutEffect(()=>{if(!e)return;const G=m.current;if(!G)return;const D=G.getBoundingClientRect(),{rect:U}=e,q=U.top,se=window.innerHeight-U.bottom,V=q>=D.height+jp||q>=se?"above":"below",te=V==="above"?Math.max(Wo,U.top-D.height-jp):Math.min(window.innerHeight-D.height-Wo,U.bottom+jp);let K=U.left;K+D.width>window.innerWidth-Wo&&(K=window.innerWidth-D.width-Wo),K<Wo&&(K=Wo),h({left:K,top:te,placement:V})},[e,r,T.length,l]),x.useEffect(()=>{const G=se=>{var K,M,L;const V=se.target,te=(K=V==null?void 0:V.closest)==null?void 0:K.call(V,"[data-comment-id]");if(te){const ee=te.getAttribute("data-comment-id");if(!ee)return;if(((M=b.current)==null?void 0:M.commentId)===ee){w();return}w(),s({kind:"view"}),o(""),n({commentId:ee,rect:te.getBoundingClientRect()});return}if((L=m.current)!=null&&L.contains(V)){w();return}b.current&&E()},D=se=>{var te,K;const V=se.relatedTarget;if(V&&((te=m.current)!=null&&te.contains(V))){w();return}V&&((K=V.closest)!=null&&K.call(V,"[data-comment-id]"))||b.current&&E()},U=se=>{if(se.key==="Escape"&&b.current){if(se.preventDefault(),k.current.kind!=="view"){s({kind:"view"}),o("");return}C()}},q=se=>{var V;b.current&&k.current.kind==="view"&&((V=m.current)!=null&&V.contains(se.target)||C())};return document.addEventListener("mouseover",G),document.addEventListener("mouseout",D),document.addEventListener("keydown",U),document.addEventListener("scroll",q,!0),()=>{document.removeEventListener("mouseover",G),document.removeEventListener("mouseout",D),document.removeEventListener("keydown",U),document.removeEventListener("scroll",q,!0),w()}},[w,E,C]),x.useEffect(()=>{var G;r.kind!=="view"&&((G=g.current)==null||G.focus())},[r]);const j=x.useCallback(G=>{const D=Ru().find(U=>U.id===G);D&&(o(D.note||""),s({kind:"edit",commentId:G}))},[]),_=x.useCallback(G=>{o(""),s({kind:"compose",parentCommentId:G})},[]),A=x.useCallback(()=>{s({kind:"view"}),o("")},[]),O=x.useCallback(()=>{r.kind!=="edit"||!t||fetch("/api/comments",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:t,id:r.commentId,note:i.trim()})}).then(()=>{s({kind:"view"}),o("")}).catch(G=>console.error("[CommentPopover] Save failed:",G))},[r,t,i]),B=x.useCallback(()=>{if(r.kind!=="compose"||!t)return;const G=Ru().find(D=>D.id===r.parentCommentId);G&&fetch("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:t,text:G.text,note:i.trim(),nodeId:G.nodeId,nodeIds:G.nodeIds})}).then(()=>{s({kind:"view"}),o("")}).catch(D=>console.error("[CommentPopover] Create failed:",D))},[r,t,i]),$=x.useCallback(G=>{fetch("/api/comments/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[G]})}).catch(D=>console.error("[CommentPopover] Resolve failed:",D))},[]),W=x.useCallback(G=>{fetch("/api/comments",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[G]})}).catch(D=>console.error("[CommentPopover] Delete failed:",D))},[]);if(!e||T.length===0)return null;const J=r.kind!=="view",z=r.kind==="compose"?"Adding a new comment on the same range":null;return c.jsx("div",{ref:m,className:`ow-comment-popover ow-comment-popover-${f.placement}`,style:{left:f.left,top:f.top,maxHeight:X5},onMouseEnter:w,onMouseLeave:E,children:J?c.jsxs(c.Fragment,{children:[z&&c.jsx("div",{className:"ow-comment-popover-empty",children:z}),c.jsx("textarea",{ref:g,className:"ow-comment-popover-textarea",value:i,onChange:G=>o(G.target.value),onKeyDown:G=>{G.key==="Enter"&&(G.metaKey||G.ctrlKey)&&(G.preventDefault(),r.kind==="edit"?O():r.kind==="compose"&&B()),G.key==="Escape"&&(G.preventDefault(),A())},rows:4,placeholder:"Note for agent (optional)..."}),c.jsxs("div",{className:"ow-comment-popover-actions",children:[c.jsx("span",{className:"ow-comment-popover-hint",children:"⌘↵ to save · Esc to cancel"}),c.jsx("button",{className:"ow-icon-btn",onClick:r.kind==="edit"?O:B,title:"Save",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M20 6 9 17l-5-5"})})})]})]}):c.jsx("div",{className:"ow-comment-popover-stack",children:T.map((G,D)=>c.jsxs("div",{className:`ow-comment-popover-card${D>0?" ow-comment-popover-card-divider":""}`,children:[G.note?c.jsx("div",{className:"ow-comment-popover-text",children:G.note}):c.jsx("div",{className:"ow-comment-popover-empty",children:"No note"}),c.jsxs("div",{className:"ow-comment-popover-actions",children:[c.jsx("button",{className:"ow-icon-btn",onClick:()=>j(G.id),title:"Edit comment",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12 20h9"}),c.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})]})}),c.jsx("button",{className:"ow-icon-btn",onClick:()=>_(G.id),title:"Add another comment on this range",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12 5v14"}),c.jsx("path",{d:"M5 12h14"})]})}),c.jsx("button",{className:"ow-icon-btn",onClick:()=>$(G.id),title:"Resolve (mark addressed)",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M20 6 9 17l-5-5"})})}),c.jsx("button",{className:"ow-icon-btn ow-icon-btn-danger",onClick:()=>W(G.id),title:"Delete (remove permanently)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M18 6 6 18"}),c.jsx("path",{d:"m6 6 12 12"})]})})]})]},G.id))})})}function gu(t){return t.type==="doc"?t.file:t.id}function Tl(t,e){for(const n of t)n.type==="doc"?e.add(n.file):n.type==="container"&&Tl(n.items,e)}function b2(t,e,n,r){for(const s of t){if(s.type==="doc"&&s.file===e)return n||r;if(s.type==="container"){const i=s.autoAccept===!0,o=b2(s.items,e,n,r||i);if(o!==null)return o}}return null}function Md(t,e){for(const n of t){const r=n.workspace;if(!r)continue;const s=r.autoAccept===!0;if(b2(r.root,e,s,!1)===!0)return!0}return!1}function ca(t){const e=new Date(t),n=Date.now()-e.getTime();return n<6e4?"just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<6048e5?`${Math.floor(n/864e5)}d ago`:e.toLocaleDateString()}function Ls(t){return/^[A-Z]:[/\\]|^\//.test(t)}function x2(t){const e=t.replace(/\\/g,"/").split("/");return e.length>=2?e[e.length-2]:""}function e8(t){const e=new Date(t),n=new Date,r=new Date(n.getFullYear(),n.getMonth(),n.getDate()),s=new Date(r.getTime()-864e5),i=new Date(e.getFullYear(),e.getMonth(),e.getDate());return i.getTime()===r.getTime()?"Today":i.getTime()===s.getTime()?"Yesterday":n.getTime()-i.getTime()<6048e5?e.toLocaleDateString(void 0,{weekday:"long"}):e.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function t8(t,e){const[n,r]=x.useState([]),[s,i]=x.useState([]),o=x.useRef(null),l=x.useRef(new Set),d=x.useCallback(g=>{l.current.add(g)},[]),f=x.useMemo(()=>{const g=new Set;for(const v of s)v.workspace&&Tl(v.workspace.root,g);return g},[s]),h=x.useCallback(()=>{fetch("/api/documents").then(g=>g.json()).then(g=>{if(!Array.isArray(g))return;const v=l.current;if(v.size>0){const k=new Set(g.map(w=>w.filename));for(const w of[...v])k.has(w)||v.delete(w)}const b=v.size>0?g.filter(k=>!v.has(k.filename)):g;r(b)}).catch(()=>{})},[]),m=x.useCallback(()=>{fetch("/api/workspaces").then(g=>g.json()).then(async g=>{if(!Array.isArray(g))return;const v=await Promise.all(g.map(async b=>{try{const w=await(await fetch(`/api/workspaces/${encodeURIComponent(b.filename)}`)).json();return{...b,workspace:w}}catch{return b}}));i(v)}).catch(()=>{})},[]);return x.useEffect(()=>{h()},[h,t]),x.useEffect(()=>{m()},[m,e]),x.useEffect(()=>{const g=requestAnimationFrame(()=>{var b;const v=(b=o.current)==null?void 0:b.querySelector(".sidebar-item.active");v==null||v.scrollIntoView({block:"nearest",behavior:"instant"})});return()=>cancelAnimationFrame(g)},[n]),{docs:n,setDocs:r,workspaces:s,setWorkspaces:i,assignedFiles:f,fetchDocs:h,fetchWorkspaces:m,scrollRef:o,markPendingDelete:d}}function Xg(t,e){return t.filter(n=>!e(n)).map(n=>n.type==="container"?{...n,items:Xg(n.items,e)}:n)}function w2(t,e,n){return t.map(r=>r.type==="container"&&r.id===e?{...r,name:n}:r.type==="container"?{...r,items:w2(r.items,e,n)}:r)}function n8(t,e,n,r,s,i){const o=x.useCallback(_=>{n(A=>A.filter(O=>O.filename!==_)),i==null||i(_),fetch(`/api/documents/${encodeURIComponent(_)}`,{method:"DELETE"}).catch(()=>t())},[n,t]),l=x.useCallback(_=>{n(A=>A.filter(O=>O.filename!==_)),fetch(`/api/documents/${encodeURIComponent(_)}/archive`,{method:"POST"}).catch(()=>t())},[n,t]),d=x.useCallback(_=>{n(A=>A.filter(O=>O.filename!==_)),fetch(`/api/documents/${encodeURIComponent(_)}/unarchive`,{method:"POST"}).catch(()=>t())},[n,t]),f=x.useCallback((_,A,O)=>{!O.trim()||O.trim()===A||(n(B=>B.map($=>$.filename===_?{...$,title:O.trim()}:$)),fetch(`/api/documents/${encodeURIComponent(_)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:O.trim()})}).catch(()=>t()))},[n,t]),h=x.useCallback(_=>{r(A=>A.filter(O=>O.filename!==_)),fetch(`/api/workspaces/${encodeURIComponent(_)}`,{method:"DELETE"}).catch(()=>e())},[r,e]),m=x.useCallback((_,A)=>{A.trim()&&(r(O=>O.map(B=>B.filename===_?{...B,title:A.trim()}:B)),fetch(`/api/workspaces/${encodeURIComponent(_)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:A.trim()})}).catch(()=>e()))},[r,e]),g=x.useCallback((_,A)=>{r(O=>O.map(B=>B.filename!==_||!B.workspace?B:{...B,docCount:Math.max(0,B.docCount-1),workspace:{...B.workspace,root:Xg(B.workspace.root,$=>$.type==="doc"&&$.file===A)}})),fetch(`/api/workspaces/${encodeURIComponent(_)}/docs/${encodeURIComponent(A)}`,{method:"DELETE"}).catch(()=>e())},[r,e]),v=x.useCallback((_,A,O=!1)=>{r($=>$.map(W=>W.filename!==_||!W.workspace?W:{...W,workspace:{...W.workspace,root:Xg(W.workspace.root,J=>J.type==="container"&&J.id===A)}}));const B=`/api/workspaces/${encodeURIComponent(_)}/containers/${encodeURIComponent(A)}${O?"?cascade=true":""}`;fetch(B,{method:"DELETE"}).then(()=>{O&&t()}).catch(()=>e())},[r,e,t]),b=x.useCallback((_,A,O)=>{O.trim()&&(r(B=>B.map($=>$.filename!==_||!$.workspace?$:{...$,workspace:{...$.workspace,root:w2($.workspace.root,A,O.trim())}})),fetch(`/api/workspaces/${encodeURIComponent(_)}/containers/${encodeURIComponent(A)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O.trim()})}).catch(()=>e()))},[r,e]),k=x.useCallback(()=>{fetch("/api/workspaces",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:"Untitled Workspace"})}).catch(()=>{})},[]),w=x.useCallback((_,A,O)=>{fetch("/api/documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O?{metadata:O}:{})}).then(B=>B.json()).then(B=>{if(B.filename)return fetch(`/api/workspaces/${encodeURIComponent(_)}/docs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:B.filename,title:B.title||"Untitled",containerId:A})})}).catch(()=>{})},[]),E=x.useCallback((_,A)=>{fetch(`/api/workspaces/${encodeURIComponent(_)}/containers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"Untitled",parentContainerId:A})}).catch(()=>{})},[]),C=x.useCallback(_=>{const A=s.find(O=>O.filename===_);return(A==null?void 0:A.tags)??[]},[s]),T=x.useCallback((_,A)=>{const O=A.trim();O&&(n(B=>B.map($=>{if($.filename!==_)return $;const W=$.tags??[];return W.includes(O)?$:{...$,tags:[...W,O]}})),fetch(`/api/doc-tags/${encodeURIComponent(_)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:O})}).catch(()=>{}))},[n]),j=x.useCallback((_,A)=>{n(O=>O.map(B=>{if(B.filename!==_)return B;const $=B.tags??[],W=$.filter(J=>J!==A);return W.length===$.length?B:W.length>0?{...B,tags:W}:{...B,tags:void 0}})),fetch(`/api/doc-tags/${encodeURIComponent(_)}/${encodeURIComponent(A)}`,{method:"DELETE"}).catch(()=>{})},[n]);return{fetchDocs:t,handleDelete:o,handleArchive:l,handleUnarchive:d,handleRename:f,handleCreateWorkspace:k,handleDeleteWorkspace:h,handleCreateInWorkspace:w,handleRemoveFromWorkspace:g,handleCreateContainer:E,handleDeleteContainer:v,handleRenameContainer:b,handleRenameWorkspace:m,getDocTags:C,handleAddTag:T,handleRemoveTag:j}}function k2({docs:t,workspaces:e,assignedFiles:n,scrollRef:r,setCollapsedSections:s}){const[i,o]=x.useState(null),[l,d]=x.useState(null),f=x.useRef(null),h=x.useRef(null),m=x.useRef(null),g=x.useRef(null),v=x.useRef(null),b=5,k=(W,J,z)=>z==="before"?J>0?gu(W[J-1]):null:gu(W[J]),w=x.useCallback((W,J)=>{if(J===null){const D=t.filter(q=>!n.has(q.filename)).map(q=>({type:"doc",file:q.filename,title:q.title})),U=D.findIndex(q=>gu(q)===W);return U>=0?{siblings:D,index:U,containerId:null}:null}const z=e.find(D=>D.filename===J);if(!(z!=null&&z.workspace))return null;const G=(D,U)=>{for(let q=0;q<D.length;q++){if(gu(D[q])===W)return{siblings:D,index:q,containerId:U};if(D[q].type==="container"){const se=G(D[q].items,D[q].id);if(se)return se}}return null};return G(z.workspace.root,null)},[t,n,e]),E=x.useCallback(()=>{o(null),d(null),v.current=null,g.current=null,m.current&&(m.current.remove(),m.current=null),f.current&&(clearTimeout(f.current),f.current=null),h.current&&(cancelAnimationFrame(h.current),h.current=null),document.body.style.userSelect=""},[]),C=x.useCallback((W,J)=>{if(!W||!J)return;if(W.type==="workspace"){const V=J.itemId;if(V===W.filename)return;const te=e.map(L=>L.filename),K=te.indexOf(W.filename);if(K<0)return;te.splice(K,1);let M=te.indexOf(V);if(M<0)return;J.position==="after"&&(M+=1),te.splice(M,0,W.filename),fetch("/api/workspaces/reorder",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:te})}).catch(()=>{});return}const{wsFilename:z,containerId:G,afterId:D}=J,U=W.type==="doc"?W.file:W.id,q=W.sourceWs;if(J.itemId===U)return;if(W.type==="container"){if(z===null&&G===null&&J.itemId!=="__section__"){const V=J.itemId,te=J.position==="after"?V:(()=>{const K=e.findIndex(M=>M.filename===V);return K>0?e[K-1].filename:null})();fetch("/api/workspaces/promote-container",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceWorkspace:q,containerId:U,afterWorkspaceFilename:te})}).catch(()=>{});return}if(q!==z&&z){fetch(`/api/workspaces/${encodeURIComponent(z)}/containers/${encodeURIComponent(U)}/cross-move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceWorkspace:q,targetContainerId:G??null,afterIdentifier:D})}).catch(()=>{});return}if(!z)return;fetch(`/api/workspaces/${encodeURIComponent(z)}/docs/${encodeURIComponent(U)}/move`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetContainerId:G??null,afterFile:D})}).catch(()=>{});return}const se=W.file;if(q===null&&z===null){const V=t.filter(ee=>!n.has(ee.filename)).map(ee=>ee.filename),te=V.indexOf(se);if(te<0)return;V.splice(te,1);let K=D?V.indexOf(D):-1;K>=0?K+=1:K=0,V.splice(K,0,se);const M=[];let L=0;for(const ee of t)n.has(ee.filename)?M.push(ee.filename):M.push(V[L++]);fetch("/api/documents/reorder",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:M})}).catch(()=>{});return}if(q===null&&z!==null){fetch(`/api/workspaces/${encodeURIComponent(z)}/docs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:se,title:se.replace(/\.md$/,""),containerId:G??null,afterFile:D})}).catch(()=>{});return}if(q!==null&&z===null){fetch(`/api/workspaces/${encodeURIComponent(q)}/docs/${encodeURIComponent(se)}`,{method:"DELETE"}).catch(()=>{});return}if(q===z&&z!==null){fetch(`/api/workspaces/${encodeURIComponent(z)}/docs/${encodeURIComponent(se)}/move`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetContainerId:G??null,afterFile:D})}).catch(()=>{});return}q!==null&&z!==null&&fetch(`/api/workspaces/${encodeURIComponent(z)}/docs/${encodeURIComponent(se)}/cross-move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceWorkspace:q,containerId:G??null,afterFile:D,title:se.replace(/\.md$/,"")})}).catch(()=>{})},[e,t,n]),T=x.useCallback((W,J)=>{const z=m.current;z&&(z.style.display="none");const G=document.elementFromPoint(W,J);if(z&&(z.style.display=""),!G)return null;if((i==null?void 0:i.type)==="workspace"||(i==null?void 0:i.type)==="container"){const ee=G.closest("[data-ws-drag]");if(ee){const fe=ee.dataset.wsDrag,ge=ee.getBoundingClientRect(),oe=(J-ge.top)/ge.height;return{itemId:fe,position:oe<.5?"before":"after",wsFilename:null,containerId:null,afterId:null}}if((i==null?void 0:i.type)==="workspace")return null}if((i==null?void 0:i.type)==="doc"){const ee=G.closest("[data-ws-drag]");if(ee)return{itemId:"__section__",position:"inside",wsFilename:ee.dataset.wsDrag,containerId:null,afterId:null}}const D=G.closest("[data-drag-id]");if(!D){const ee=G.closest("[data-drop-ws]");return ee?{itemId:"__section__",position:"inside",wsFilename:ee.dataset.dropWs==="__docs__"?null:ee.dataset.dropWs,containerId:ee.dataset.dropContainer||null,afterId:null}:null}const U=D.dataset.dragId,q=D.dataset.dragType,se=D.dataset.dragWs==="__docs__"?null:D.dataset.dragWs,V=D.getBoundingClientRect(),te=(J-V.top)/V.height;if(q==="container-header"){const ee=U,fe=D.dataset.dragParent||null,ge=w(ee,se);if(!ge)return null;const oe=(i==null?void 0:i.type)==="container"?.33:.25;return te<oe?{itemId:ee,position:"before",wsFilename:se,containerId:fe,afterId:k(ge.siblings,ge.index,"before")}:te>1-oe?{itemId:ee,position:"after",wsFilename:se,containerId:fe,afterId:k(ge.siblings,ge.index,"after")}:{itemId:ee,position:"inside",wsFilename:se,containerId:ee,afterId:null}}const K=D.dataset.dragContainer||null,M=w(U,se);if(!M)return null;const L=te<.5?"before":"after";return{itemId:U,position:L,wsFilename:se,containerId:K,afterId:k(M.siblings,M.index,L)}},[w,i]),j=x.useCallback(W=>{const J=r.current;if(!J)return;const z=J.getBoundingClientRect(),G=80,D=18;let U=0;if(W<z.top+G?U=-D*Math.max(0,1-(W-z.top)/G):W>z.bottom-G&&(U=D*Math.max(0,1-(z.bottom-W)/G)),h.current&&(cancelAnimationFrame(h.current),h.current=null),U!==0){const q=()=>{J.scrollTop+=U,h.current=requestAnimationFrame(q)};h.current=requestAnimationFrame(q)}},[r]),_=x.useCallback((W,J)=>{const z=m.current;z&&(z.style.display="none");const G=document.elementFromPoint(W,J);z&&(z.style.display="");const D=G==null?void 0:G.closest("[data-section-key]");if(!D){f.current&&(clearTimeout(f.current),f.current=null);return}const U=D.dataset.sectionKey;f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{s(q=>{if(!q.has(U))return q;const se=new Set(q);return se.delete(U),se})},500)},[s]);x.useEffect(()=>{if(!i)return;const W=z=>{m.current&&(m.current.style.left=`${z.clientX+12}px`,m.current.style.top=`${z.clientY-8}px`),d(T(z.clientX,z.clientY)),j(z.clientY),_(z.clientX,z.clientY)},J=z=>{C(i,T(z.clientX,z.clientY)),E()};return window.addEventListener("pointermove",W),window.addEventListener("pointerup",J),()=>{window.removeEventListener("pointermove",W),window.removeEventListener("pointerup",J)}},[i,T,C,E,j,_]);const A=x.useCallback((W,J,z)=>{if(W.button!==0||W.target.closest("input, button, .sidebar-tag-remove, .sidebar-tag-add, .sidebar-container-actions, .sidebar-delete-btn, .sidebar-confirm-delete, .sidebar-inline-confirm"))return;g.current={x:W.clientX,y:W.clientY},v.current=J;const D=q=>{if(!g.current||!v.current)return;const se=q.clientX-g.current.x,V=q.clientY-g.current.y;if(Math.abs(se)+Math.abs(V)>=b){document.body.style.userSelect="none",window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",U),o(v.current),v.current=null;const te=document.createElement("div");te.style.cssText="position:fixed;pointer-events:none;z-index:9999;padding:4px 10px;background:var(--bg-surface, white);border:1px solid var(--border, #cbd5e1);border-radius:6px;font-size:12px;box-shadow:0 2px 8px rgba(0,0,0,0.12);max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--ink-dark, #334155);",te.textContent=z,document.body.appendChild(te),m.current=te,te.style.left=`${q.clientX+12}px`,te.style.top=`${q.clientY-8}px`}},U=()=>{window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",U),g.current=null,v.current=null,document.body.style.userSelect=""};window.addEventListener("pointermove",D),window.addEventListener("pointerup",U)},[]);return{draggedItem:i,dropIndicator:l,handlePointerDown:A,dropClass:W=>!l||l.itemId!==W?"":l.position==="before"?"drop-before":l.position==="after"?"drop-after":l.position==="inside"?"drop-inside":"",isDragging:W=>i?i.type==="doc"?i.file===W:i.type==="workspace"?i.filename===W:i.id===W:!1,isContainerDropTarget:W=>!l||!i?!1:l.containerId===W}}const r8=[{key:"document",label:"Document"},{key:"tweet",label:"Tweet"},{key:"article",label:"Article"},{key:"linkedin",label:"LinkedIn"},{key:"newsletter",label:"Newsletter"},{key:"blog",label:"Blog"}];function s8({onPick:t,menuRef:e}){const[n,r]=x.useState(!1),s=x.useRef(null),[i,o]=x.useState({});return x.useLayoutEffect(()=>{if(!n||!s.current||!e.current)return;const l=e.current.getBoundingClientRect(),d=s.current.getBoundingClientRect(),f=8;let h=l.right-4,m=s.current.offsetTop+l.top-4;h+d.width+f>window.innerWidth&&(h=l.left-d.width+4),m+d.height+f>window.innerHeight&&(m=window.innerHeight-d.height-f),m<f&&(m=f),o({position:"fixed",left:h,top:m})},[n,e]),c.jsxs("span",{onMouseLeave:()=>r(!1),children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("button",{className:"context-menu-item context-menu-submenu-trigger",onMouseEnter:()=>r(!0),onClick:()=>r(l=>!l),children:[c.jsx("span",{children:"Create variant"}),c.jsx("span",{className:"context-menu-submenu-arrow",children:"▸"})]}),n&&c.jsx("div",{ref:s,className:"context-menu context-menu-submenu",style:i,children:r8.map(l=>c.jsx("button",{className:"context-menu-item",onClick:()=>t(l.key),children:c.jsx("span",{children:l.label})},l.key))})]})}function i8({items:t,onAction:e,menuRef:n}){const[r,s]=x.useState(null),i=x.useRef(null),o=x.useMemo(()=>{const h=new Map;for(const m of t){const g=m.pluginDisplayName||"_ungrouped",v=h.get(g)||[];v.push(m),h.set(g,v)}return h},[t]),[l,d]=x.useState({});x.useLayoutEffect(()=>{if(!r||!i.current||!n.current)return;const h=n.current.getBoundingClientRect(),m=i.current.getBoundingClientRect(),g=8;let v=h.right-4,b=i.current.offsetTop+h.top-4;v+m.width+g>window.innerWidth&&(v=h.left-m.width+4),b+m.height+g>window.innerHeight&&(b=window.innerHeight-m.height-g),b<g&&(b=g),d({position:"fixed",left:v,top:b})},[r,n]);const f=[];for(const[h,m]of o)if(h!=="_ungrouped"&&m.length>=3)f.push(c.jsxs("span",{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("button",{className:"context-menu-item context-menu-submenu-trigger",onMouseEnter:()=>s(h),onClick:()=>s(r===h?null:h),children:[c.jsx("span",{children:"Transform"}),c.jsx("span",{className:"context-menu-submenu-arrow",children:"▸"})]}),r===h&&c.jsx("div",{ref:i,className:"context-menu context-menu-submenu",style:l,onMouseLeave:()=>s(null),children:m.map(g=>c.jsx("button",{className:"context-menu-item",onClick:()=>e(g),children:c.jsx("span",{children:g.label})},g.action))})]},`sub-${h}`));else{let g=!0;for(const v of m){const b=g&&h!=="_ungrouped";g=!1,f.push(c.jsxs("span",{children:[b&&c.jsx("div",{className:"context-menu-divider"}),b&&c.jsx("div",{className:"context-menu-section-header",children:h}),c.jsx("button",{className:"context-menu-item",onClick:()=>e(v),children:c.jsx("span",{children:v.label})})]},v.action))}}return c.jsx(c.Fragment,{children:f})}function Ad({x:t,y:e,filename:n,title:r,onClose:s,onDuplicate:i,onCreateVariant:o,onRename:l,onArchive:d,onDelete:f,onPluginAction:h,pluginItems:m,onSchedulePost:g,onPostNow:v,isAlreadyPublished:b,onViewAnalytics:k,viewAnalyticsLabel:w,onMarkSent:E,isAlreadySent:C,isApproved:T,onToggleApprove:j,isAutoAccept:_,onToggleAutoAccept:A,sortState:O,sortProposalLabel:B,sortProposalReasoning:$,onRequestSort:W,onCancelSort:J,onAcceptSortProposal:z,onRejectSortProposal:G,folderMode:D,onNewDoc:U,onNewContainer:q,onAcceptAll:se,onRejectAll:V,folderAutoAccept:te,onToggleFolderAutoAccept:K,folderAutoAcceptLabel:M,onRequestSortAll:L,folderDocCount:ee,onDeleteWithDocs:fe,bulkCount:ge,onBulkDelete:oe,onBulkRequestSort:we}){const xe=x.useRef(null),[We,He]=x.useState(!1),[Ze,Oe]=x.useState(!1),[Ke,pt]=x.useState({left:t,top:e});x.useLayoutEffect(()=>{const pe=xe.current;if(!pe)return;const mt=pe.getBoundingClientRect(),ft=8;let at=t,nt=e;e+mt.height+ft>window.innerHeight&&(nt=e-mt.height),t+mt.width+ft>window.innerWidth&&(at=t-mt.width),nt<ft&&(nt=ft),at<ft&&(at=ft),pt({left:at,top:nt})},[t,e]),x.useEffect(()=>{const pe=mt=>{xe.current&&!xe.current.contains(mt.target)&&s()};return document.addEventListener("mousedown",pe),()=>document.removeEventListener("mousedown",pe)},[s]),x.useEffect(()=>{const pe=mt=>{mt.key==="Escape"&&s()};return document.addEventListener("keydown",pe),()=>document.removeEventListener("keydown",pe)},[s]);const Je=x.useCallback(pe=>{h(pe.action,pe),s()},[h,s]);return ge&&ge>1&&oe?c.jsxs("div",{ref:xe,className:"context-menu",style:{left:Ke.left,top:Ke.top},children:[c.jsxs("div",{className:"context-menu-section-header",children:[ge," selected"]}),we&&c.jsx("button",{className:"context-menu-item",onClick:()=>{we(),s()},children:c.jsxs("span",{children:["Request sort (",ge,")"]})}),We?c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsxs("span",{children:["Delete ",ge,"?"]}),c.jsx("button",{onClick:()=>{oe(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>He(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item sidebar-ctx-delete",onClick:()=>He(!0),children:c.jsxs("span",{children:["Delete (",ge,")"]})})]}):D?c.jsxs("div",{ref:xe,className:"context-menu",style:{left:Ke.left,top:Ke.top},children:[c.jsx("button",{className:"context-menu-item",onClick:()=>{l(),s()},children:c.jsx("span",{children:"Rename"})}),U&&c.jsx("button",{className:"context-menu-item",onClick:pe=>{U(pe),s()},children:c.jsx("span",{children:"New Document"})}),q&&c.jsx("button",{className:"context-menu-item",onClick:()=>{q(),s()},children:c.jsx("span",{children:"New Container"})}),(se||V)&&c.jsx("div",{className:"context-menu-divider"}),se&&c.jsx("button",{className:"context-menu-item",onClick:()=>{se(),s()},children:c.jsx("span",{children:"Accept All Changes"})}),V&&c.jsx("button",{className:"context-menu-item",onClick:()=>{V(),s()},children:c.jsx("span",{children:"Reject All Changes"})}),K&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{K(),s()},children:c.jsx("span",{children:te?`Turn off auto-accept${M?" "+M:""}`:`Turn on auto-accept${M?" "+M:""}`})})]}),L&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{L(),s()},children:c.jsx("span",{children:"Request sort all"})})]}),c.jsx("div",{className:"context-menu-divider"}),We?ee&&ee>0&&fe?c.jsxs("div",{className:"sidebar-ctx-folder-delete",onClick:pe=>pe.stopPropagation(),children:[c.jsx("div",{className:"sidebar-ctx-folder-delete-prompt",children:"Delete this folder?"}),c.jsxs("button",{className:"context-menu-item sidebar-ctx-delete-option",onClick:()=>{f(),s()},children:[c.jsx("span",{children:"Folder only"}),c.jsxs("span",{className:"sidebar-ctx-delete-hint",children:[ee," doc",ee===1?"":"s"," → Documents"]})]}),c.jsxs("button",{className:"context-menu-item sidebar-ctx-delete-option sidebar-ctx-delete",onClick:()=>{fe(),s()},children:[c.jsxs("span",{children:["Folder + ",ee," doc",ee===1?"":"s"]}),c.jsx("span",{className:"sidebar-ctx-delete-hint",children:"permanently deletes files"})]}),c.jsx("button",{className:"context-menu-item sidebar-ctx-delete-cancel",onClick:()=>He(!1),children:c.jsx("span",{children:"Cancel"})})]}):c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{children:"Delete?"}),c.jsx("button",{onClick:()=>{f(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>He(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item sidebar-ctx-delete",onClick:()=>He(!0),children:c.jsx("span",{children:"Delete"})})]}):c.jsxs("div",{ref:xe,className:"context-menu",style:{left:Ke.left,top:Ke.top},children:[c.jsx("button",{className:"context-menu-item",onClick:()=>{i(),s()},children:c.jsx("span",{children:"Duplicate"})}),o&&c.jsx(s8,{onPick:pe=>{o(pe),s()},menuRef:xe}),c.jsx("button",{className:"context-menu-item",onClick:()=>{l(),s()},children:c.jsx("span",{children:"Rename"})}),Ze?c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{children:"Archive?"}),c.jsx("button",{onClick:()=>{d(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>Oe(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item",onClick:()=>Oe(!0),children:c.jsx("span",{children:"Archive"})}),We?c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{children:Ls(n)?"Remove?":"Delete?"}),c.jsx("button",{onClick:()=>{f(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>He(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item sidebar-ctx-delete",onClick:()=>He(!0),children:c.jsx("span",{children:Ls(n)?"Remove":"Delete"})}),j&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{j(),s()},children:c.jsx("span",{children:T?"Remove Approval":"Approve"})})]}),A&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{A(),s()},children:c.jsx("span",{children:_?"Turn off auto-accept":"Turn on auto-accept"})})]}),O==="proposal"&&z&&G&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("div",{className:"sidebar-ctx-sort-proposal",onClick:pe=>pe.stopPropagation(),children:[c.jsxs("div",{className:"sidebar-ctx-sort-proposal-label",children:["Sort to ",B]}),$&&c.jsx("div",{className:"sidebar-ctx-sort-proposal-reason",children:$}),c.jsxs("div",{className:"sidebar-ctx-sort-proposal-actions",children:[c.jsx("button",{onClick:()=>{z(),s()},children:"Accept"}),c.jsx("button",{onClick:()=>{G(),s()},children:"Reject"})]})]})]}),O==="pending"&&J&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("div",{className:"sidebar-ctx-sort-pending",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{className:"sidebar-ctx-sort-pending-label",children:"Sort requested"}),c.jsx("button",{onClick:()=>{J(),s()},children:"Cancel"})]})]}),O==="none"&&W&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{W(),s()},children:c.jsx("span",{children:"Request sort"})})]}),g&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{g(),s()},children:c.jsx("span",{children:"Schedule Post"})})]}),v&&c.jsx("button",{className:"context-menu-item",onClick:()=>{v(),s()},children:c.jsx("span",{children:b?"Republish to Blog":"Post to Blog Now"})}),E&&!C&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{E(),s()},children:c.jsx("span",{children:"Mark as Sent"})})]}),k&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{k(),s()},children:c.jsx("span",{children:w||"View Analytics"})})]}),m.length>0&&c.jsx(i8,{items:m,onAction:Je,menuRef:xe})]})}function S2({actionLabel:t,docTitle:e,onConfirm:n,onClose:r}){const[s,i]=x.useState(""),o=x.useRef(null);x.useEffect(()=>{var d;(d=o.current)==null||d.focus()},[]),x.useEffect(()=>{const d=f=>{f.key==="Escape"&&r()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[r]);const l=x.useCallback(()=>{n(s.trim())},[s,n]);return c.jsx("div",{className:"focus-modal-overlay",onClick:r,children:c.jsxs("div",{className:"focus-modal",onClick:d=>d.stopPropagation(),children:[c.jsxs("div",{className:"focus-modal-header",children:[c.jsx("h2",{children:t}),c.jsx("button",{className:"focus-modal-close",onClick:r,children:"×"})]}),c.jsxs("div",{className:"focus-modal-body",children:[c.jsxs("label",{children:['Focus instructions for "',e,'"',c.jsx("textarea",{ref:o,value:s,onChange:d=>i(d.target.value.slice(0,500)),placeholder:"Optional: guide the transformation (e.g. 'focus on the intro section', 'keep it professional')...",onKeyDown:d=>{d.key==="Enter"&&(d.ctrlKey||d.metaKey)&&l()}})]}),c.jsxs("div",{className:"focus-modal-hint",children:[s.length,"/500"]}),c.jsxs("div",{className:"focus-modal-actions",children:[c.jsx("button",{className:"focus-modal-btn secondary",onClick:r,children:"Cancel"}),c.jsx("button",{className:"focus-modal-btn primary",onClick:l,children:"Go"})]})]})]})})}function Mp(t,e){if(!e)return[t];const n=[],r=t.toLowerCase(),s=e.toLowerCase();let i=0;for(;i<t.length;){const o=r.indexOf(s,i);if(o===-1){n.push(t.slice(i));break}o>i&&n.push(t.slice(i,o)),n.push(c.jsx("mark",{children:t.slice(o,o+e.length)},o)),i=o+e.length}return n}function yk({r:t,query:e,onClick:n}){return c.jsxs("div",{className:`sidebar-item search-result-item ${t.isActive?"active":""} ${t.isArchived?"search-result-archived":""}`,onClick:n,children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-item-title-text",children:t.matchType==="title"?Mp(t.title,e):t.title}),t.isArchived&&c.jsx("span",{className:"search-archived-badge",children:"archived"})]}),t.matchType==="tag"&&t.matchedTag&&c.jsxs("div",{className:"search-result-tag",children:["Tag: ",Mp(t.matchedTag,e)]}),t.matchType==="content"&&t.snippet&&c.jsx("div",{className:"search-result-snippet",children:Mp(t.snippet,e)}),c.jsxs("div",{className:"sidebar-item-meta",children:[t.wordCount.toLocaleString()," words · ",ca(t.lastModified)]})]})}function Xd({results:t,query:e,onSwitchDocument:n,actions:r}){if(t.length===0)return c.jsx("div",{className:"sidebar-scroll",children:c.jsxs("div",{className:"search-empty",children:['No results for "',e,'"']})});const s=t.filter(o=>!o.isArchived),i=t.filter(o=>o.isArchived);return c.jsx("div",{className:"sidebar-scroll",children:c.jsxs("div",{className:"search-results",children:[s.map(o=>c.jsx(yk,{r:o,query:e,onClick:()=>n(o.filename)},o.filename)),i.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"search-archived-divider",children:c.jsx("span",{children:"Archived"})}),i.map(o=>c.jsx(yk,{r:o,query:e,onClick:()=>r.handleUnarchive(o.filename)},o.filename))]})]})})}async function Ap(t,e={}){var s,i;const r=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:t,arguments:e})})).json();return(i=(s=r.content)==null?void 0:s[0])!=null&&i.text?JSON.parse(r.content[0].text):r}function Rp(t,e){return e?(t/e*100).toFixed(1)+"%":"0%"}function bk(t){return new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function xk(t,e=50){try{const n=new URL(t),r=n.hostname+n.pathname+n.search;return r.length>e?r.slice(0,e)+"...":r}catch{return t.length>e?t.slice(0,e)+"...":t}}function E2({docId:t,title:e,onClose:n}){const[r,s]=x.useState("loading"),[i,o]=x.useState([]),[l,d]=x.useState(""),[f,h]=x.useState(null),[m,g]=x.useState(null),[v,b]=x.useState("links"),[k,w]=x.useState("all"),[E,C]=x.useState(!1),[T,j]=x.useState(!1),[_,A]=x.useState(""),[O,B]=x.useState(!1),[$,W]=x.useState(null),J=x.useRef(null);x.useEffect(()=>{let oe=!1;return(async()=>{try{const we=await Ap("list_newsletter_issues",{limit:20});if(oe)return;if(!we.issues||we.issues.length===0){s("no-data");return}o(we.issues);const xe=we.issues[0].id;d(xe)}catch(we){oe||(g(we.message),s("error"))}})(),()=>{oe=!0}},[]),x.useEffect(()=>{if(!l)return;let oe=!1;return C(!0),j(!1),W(null),A(""),(async()=>{try{const we=await Ap("get_newsletter_analytics",{issue_id:l});if(oe)return;if(we.error){g(we.error),s("error");return}h(we),s("loaded")}catch(we){oe||(g(we.message),s("error"))}finally{oe||C(!1)}})(),()=>{oe=!0}},[l]),x.useEffect(()=>{const oe=we=>{J.current&&!J.current.contains(we.target)&&n()};return document.addEventListener("mousedown",oe),()=>document.removeEventListener("mousedown",oe)},[n]),x.useEffect(()=>{const oe=we=>{we.key==="Escape"&&n()};return document.addEventListener("keydown",oe),()=>document.removeEventListener("keydown",oe)},[n]);const z=f?a8(f.subscriber_events):[],G=(f==null?void 0:f.issue.recipient_count)??0,D=f?f.stats.delivered||G-f.stats.bounces:0,U=f?new Set(f.subscriber_events.filter(oe=>{var we;return oe.event_type==="click"&&((we=oe.url)==null?void 0:we.includes("/newsletter/unsubscribe/"))}).map(oe=>oe.email)).size:0,q=f?f.stats.unsubscribes||U:0,se=f?f.subscriber_events.filter(oe=>oe.event_type==="dropped").length:0,V=f?Math.max(0,G-f.stats.unique_opens):0,te=f!=null&&f.issue.sent_at?Date.now()-new Date(f.issue.sent_at).getTime():0,K=Math.floor(te/36e5),M=!!(f!=null&&f.issue.resent_at||$),L=oe=>{const we=Math.floor(oe/36e5);return we<1?"just now":we<24?`${we}h ago`:`${Math.floor(we/24)}d ${we%24}h ago`},ee=async()=>{if(!(!_.trim()||O)){B(!0);try{const oe=await Ap("resend_to_unopened",{issue_id:l,subject:_});oe.error?(g(oe.error),s("error")):(W({sent:oe.sent,failed:oe.failed}),j(!1))}catch(oe){g(oe.message),s("error")}finally{B(!1)}}},fe=oe=>{var we;return oe.event_type==="unsubscribe"||oe.event_type==="click"&&!!((we=oe.url)!=null&&we.includes("/newsletter/unsubscribe/"))},ge=f?o8(f.subscriber_events.filter(oe=>k==="all"?!0:k==="unsubscribe"?fe(oe):oe.event_type===k)):[];return c.jsx("div",{className:"newsletter-modal-overlay",children:c.jsxs("div",{className:"na-modal",ref:J,children:[c.jsxs("div",{className:"na-header",children:[c.jsx("h3",{children:"Newsletter Analytics"}),c.jsx("button",{className:"newsletter-modal__close",onClick:n,children:"×"})]}),r==="loading"&&!f&&c.jsx("div",{className:"na-body",children:c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:"Loading analytics..."})]})}),r==="no-data"&&c.jsxs("div",{className:"na-body",children:[c.jsx("div",{className:"newsletter-modal__status",children:c.jsx("span",{children:"No newsletter sends found yet."})}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:n,children:"Done"})})]}),r==="error"&&c.jsxs("div",{className:"na-body",children:[c.jsx("div",{className:"newsletter-modal__error",children:m}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:n,children:"Done"})})]}),r==="loaded"&&f&&c.jsxs("div",{className:"na-body",children:[i.length>1&&c.jsx("select",{className:"newsletter-modal__select na-issue-select",value:l,onChange:oe=>d(oe.target.value),children:i.map(oe=>c.jsxs("option",{value:oe.id,children:[oe.subject," — ",bk(oe.sent_at)]},oe.id))}),E?c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:"Loading..."})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"na-kpi-row",children:[c.jsxs("div",{className:"na-kpi",children:[c.jsx("div",{className:"na-kpi__value",children:D.toLocaleString()}),c.jsx("div",{className:"na-kpi__label",children:"Delivered"}),c.jsxs("div",{className:"na-kpi__sub",children:[G.toLocaleString()," sent"]})]}),c.jsxs("div",{className:"na-kpi",children:[c.jsx("div",{className:"na-kpi__value",children:Rp(f.stats.unique_opens,D)}),c.jsx("div",{className:"na-kpi__label",children:"Open rate"}),c.jsxs("div",{className:"na-kpi__sub",children:[f.stats.unique_opens.toLocaleString()," opens"]})]}),c.jsxs("div",{className:"na-kpi",children:[c.jsx("div",{className:"na-kpi__value",children:Rp(f.stats.unique_clicks,D)}),c.jsx("div",{className:"na-kpi__label",children:"Click rate"}),c.jsxs("div",{className:"na-kpi__sub",children:[f.stats.unique_clicks.toLocaleString()," clicks"]})]})]}),c.jsxs("div",{className:"na-kpi-row na-kpi-row--secondary",children:[c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:f.stats.bounces}),c.jsx("span",{className:"na-kpi__label--sm",children:"Bounces"})]}),c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:q}),c.jsx("span",{className:"na-kpi__label--sm",children:"Unsubs"})]}),c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:se}),c.jsx("span",{className:"na-kpi__label--sm",children:"Dropped"})]}),f.stats.complaints>0&&c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:f.stats.complaints}),c.jsx("span",{className:"na-kpi__label--sm",children:"Spam"})]})]}),V>0&&!M&&c.jsx("div",{className:"na-resend",children:T?c.jsxs("div",{className:"na-resend-panel",children:[c.jsxs("div",{className:"na-resend-label-row",children:[c.jsx("span",{className:"na-resend-label",children:"New subject line"}),c.jsxs("span",{className:"na-resend-meta",children:["sent ",L(te),K<48?" · consider waiting 48h":""]})]}),c.jsx("input",{className:"na-resend-input",type:"text",value:_,onChange:oe=>A(oe.target.value),placeholder:"Try a different angle"}),c.jsxs("div",{className:"na-resend-actions",children:[c.jsx("button",{className:"na-resend-cancel",onClick:()=>j(!1),children:"Cancel"}),c.jsx("button",{className:"na-resend-send",onClick:ee,disabled:O||!_.trim(),children:O?"Sending...":`Send to ${V.toLocaleString()}`})]})]}):c.jsxs("button",{className:"na-resend-toggle",onClick:()=>{j(!0),A(f.issue.subject)},children:["Resend to ",V.toLocaleString()," non-openers ",c.jsx("span",{style:{float:"right"},children:"›"})]})}),M&&c.jsxs("div",{className:"na-resend-done",children:["Resent ",f.issue.resent_at?L(Date.now()-new Date(f.issue.resent_at).getTime()):"just now",$?` — ${$.sent} sent`:"",f.issue.resend_subject?` — "${f.issue.resend_subject}"`:""]}),c.jsxs("div",{className:"na-tabs",children:[c.jsxs("button",{className:`na-tab${v==="links"?" active":""}`,onClick:()=>b("links"),children:["Links (",z.length,")"]}),c.jsxs("button",{className:`na-tab${v==="activity"?" active":""}`,onClick:()=>b("activity"),children:["Activity (",f.subscriber_events.length,")"]})]}),v==="links"&&c.jsx("div",{className:"na-table-wrap",children:z.length===0?c.jsx("div",{className:"na-empty",children:"No link clicks recorded yet."}):c.jsxs("table",{className:"na-table",children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Link"}),c.jsx("th",{children:"Unique"}),c.jsx("th",{children:"Total"}),c.jsx("th",{children:"CTR"})]})}),c.jsx("tbody",{children:z.map(oe=>c.jsxs("tr",{children:[c.jsx("td",{className:"na-table__url",title:oe.url,children:c.jsx("a",{href:oe.url,target:"_blank",rel:"noopener noreferrer",children:xk(oe.url)})}),c.jsx("td",{children:oe.uniqueClicks}),c.jsx("td",{children:oe.totalClicks}),c.jsx("td",{children:Rp(oe.uniqueClicks,D)})]},oe.url))})]})}),v==="activity"&&c.jsxs("div",{className:"na-activity",children:[c.jsx("div",{className:"na-filter-row",children:["all","open","click","bounce","dropped","unsubscribe"].map(oe=>c.jsx("button",{className:`na-filter-btn${k===oe?" active":""}`,onClick:()=>w(oe),children:oe==="all"?"All":oe.charAt(0).toUpperCase()+oe.slice(1)+"s"},oe))}),c.jsxs("div",{className:"na-table-wrap",children:[ge.length===0?c.jsxs("div",{className:"na-empty",children:["No ",k==="all"?"":k+" ","events recorded."]}):c.jsxs("table",{className:"na-table",children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Email"}),c.jsx("th",{children:"Event"}),c.jsx("th",{children:"Detail"}),c.jsx("th",{children:"Time"})]})}),c.jsx("tbody",{children:ge.slice(0,100).map(oe=>c.jsxs("tr",{children:[c.jsx("td",{className:"na-table__email",children:oe.email}),c.jsxs("td",{children:[c.jsx("span",{className:`na-badge na-badge--${oe.event_type}`,children:oe.event_type}),oe.count>1&&c.jsxs("span",{className:"na-count",children:[oe.count,"x"]})]}),c.jsx("td",{className:"na-table__url",children:oe.url?c.jsx("a",{href:oe.url,target:"_blank",rel:"noopener noreferrer",children:xk(oe.url,35)}):"—"}),c.jsx("td",{className:"na-table__time",children:bk(oe.latestTimestamp)})]},oe.key))})]}),ge.length>100&&c.jsxs("div",{className:"na-truncated",children:["Showing 100 of ",ge.length," events"]})]})]})]})]})]})})}function o8(t){const e=new Map;for(const n of t){const r=`${n.email}|${n.event_type}|${n.url||""}`,s=e.get(r);s?(s.count++,n.timestamp>s.latestTimestamp&&(s.latestTimestamp=n.timestamp)):e.set(r,{key:r,email:n.email,event_type:n.event_type,url:n.url,latestTimestamp:n.timestamp,count:1})}return Array.from(e.values()).sort((n,r)=>new Date(r.latestTimestamp).getTime()-new Date(n.latestTimestamp).getTime())}function a8(t){const e=t.filter(r=>r.event_type==="click"&&r.url),n=new Map;for(const r of e){const s=r.url;let i=n.get(s);i||(i={emails:new Set,total:0},n.set(s,i)),i.emails.add(r.email),i.total++}return Array.from(n.entries()).map(([r,{emails:s,total:i}])=>({url:r,uniqueClicks:s.size,totalClicks:i})).sort((r,s)=>s.uniqueClicks-r.uniqueClicks)}function l8(t){return t.tweetContext?"tweet":t.articleContext?"article":t.linkedinContext?"linkedin":t.newsletterContext?"newsletter":t.blogContext?"blog":"tweet"}function Dl({filename:t,title:e,onClose:n}){const[r,s]=x.useState("queue"),[i,o]=x.useState(null),[l,d]=x.useState(null),[f,h]=x.useState(""),[m,g]=x.useState(!1),[v,b]=x.useState(null),[k,w]=x.useState(null);x.useEffect(()=>{fetch(`/api/documents/${encodeURIComponent(t)}/text`).then(T=>{if(!T.ok)throw new Error("Failed to load document");return T.json()}).then(T=>{d(T.text||""),o(l8(T.meta||{}))}).catch(T=>w(T.message))},[t]);const E=async()=>{var T;if(!(!l||!i)){g(!0);try{const j={content:l,content_type:i,mode:r};r==="custom"&&f&&(j.scheduled_at=new Date(f).toISOString());const _=await fetch("/api/scheduler/queue",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(j)}),A=await _.json();if(_.ok){const O=(T=A.item)!=null&&T.scheduled_at?new Date(A.item.scheduled_at).toLocaleString():"now";b({success:!0,message:`Scheduled for ${O}`})}else b({success:!1,message:A.error||"Failed to schedule"})}catch(j){b({success:!1,message:j.message})}finally{g(!1)}}},C=i===null&&!k;return c.jsx("div",{className:"schedule-post-overlay",onClick:n,children:c.jsxs("div",{className:"schedule-post-modal",onClick:T=>T.stopPropagation(),children:[c.jsxs("div",{className:"schedule-post-modal-header",children:[c.jsx("h3",{children:"Schedule Post"}),c.jsx("button",{className:"schedule-post-modal-close",onClick:n,children:"×"})]}),c.jsx("div",{className:"schedule-post-modal-doc",children:e}),k?c.jsxs("div",{className:"schedule-post-modal-result error",children:[k,c.jsx("button",{className:"schedule-post-modal-done",onClick:n,children:"Done"})]}):v?c.jsxs("div",{className:`schedule-post-modal-result ${v.success?"success":"error"}`,children:[v.message,c.jsx("button",{className:"schedule-post-modal-done",onClick:n,children:"Done"})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"schedule-post-modal-field",children:[c.jsx("label",{children:"Content Type"}),c.jsx("div",{className:"schedule-post-modal-type",children:C?"...":i})]}),c.jsxs("div",{className:"schedule-post-modal-field",children:[c.jsx("label",{children:"Mode"}),c.jsxs("div",{className:"schedule-post-modal-modes",children:[c.jsx("button",{className:`schedule-post-mode ${r==="queue"?"active":""}`,onClick:()=>s("queue"),children:"Queue Next"}),c.jsx("button",{className:`schedule-post-mode ${r==="now"?"active":""}`,onClick:()=>s("now"),children:"Post Now"}),c.jsx("button",{className:`schedule-post-mode ${r==="custom"?"active":""}`,onClick:()=>s("custom"),children:"Custom Time"})]})]}),r==="custom"&&c.jsxs("div",{className:"schedule-post-modal-field",children:[c.jsx("label",{children:"Date & Time"}),c.jsx("input",{type:"datetime-local",value:f,onChange:T=>h(T.target.value)})]}),c.jsxs("div",{className:"schedule-post-modal-actions",children:[c.jsx("button",{className:"schedule-post-modal-cancel",onClick:n,children:"Cancel"}),c.jsx("button",{className:"schedule-post-modal-submit",onClick:E,disabled:m||C||r==="custom"&&!f,children:m?"Scheduling...":r==="now"?"Post Now":"Schedule"})]})]})]})})}const wk=[{key:"document",label:"Document"},{key:"tweet",label:"Tweet",metadata:{content_type:"tweet",tweetContext:{mode:"tweet"}}},{key:"reply",label:"Reply",needsUrl:!0,urlPlaceholder:"Paste tweet URL...",metadata:{content_type:"reply",tweetContext:{mode:"reply"}}},{key:"quote",label:"Quote Tweet",needsUrl:!0,urlPlaceholder:"Paste tweet URL...",metadata:{content_type:"quote",tweetContext:{mode:"quote"}}},{key:"article",label:"Article",metadata:{content_type:"article",articleContext:{active:!0}}},{key:"linkedin",label:"LinkedIn",metadata:{content_type:"linkedin",linkedinContext:{active:!0}}},{key:"newsletter",label:"Newsletter",metadata:{content_type:"newsletter",newsletterContext:{active:!0}}},{key:"blog",label:"Blog",metadata:{content_type:"blog",blogContext:{active:!0}}}];function N2({anchorRect:t,onSelect:e,onClose:n}){const r=x.useRef(null),[s,i]=x.useState(null),[o,l]=x.useState(""),d=x.useRef(null),[f,h]=x.useState({left:t.left,top:t.bottom+4});x.useLayoutEffect(()=>{const b=r.current;if(!b)return;const k=b.getBoundingClientRect(),w=8;let E=t.left,C=t.bottom+4;C+k.height+w>window.innerHeight&&(C=t.top-k.height-4),E+k.width+w>window.innerWidth&&(E=t.right-k.width),C<w&&(C=w),E<w&&(E=w),h({left:E,top:C})},[t]),x.useEffect(()=>{const b=k=>{r.current&&!r.current.contains(k.target)&&n()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[n]),x.useEffect(()=>{const b=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[n]),x.useEffect(()=>{s&&setTimeout(()=>{var b;return(b=d.current)==null?void 0:b.focus()},0)},[s]);const m=b=>{if(b.needsUrl){i(b.key),l("");return}e(b.metadata)},g=()=>{if(!s||!o.trim())return;const b=o.trim();if(!b.includes("x.com")&&!b.includes("twitter.com"))return;const k=wk.find(E=>E.key===s);if(!(k!=null&&k.metadata))return;const w=JSON.parse(JSON.stringify(k.metadata));w.tweetContext&&(w.tweetContext.url=b),e(w)},v=o.trim().includes("x.com")||o.trim().includes("twitter.com");return c.jsx("div",{ref:r,className:"create-doc-dropdown",style:{left:f.left,top:f.top},children:wk.map(b=>c.jsxs("div",{children:[c.jsx("button",{className:`create-doc-dropdown-item${s===b.key?" active":""}`,onClick:()=>m(b),children:b.label}),s===b.key&&c.jsxs("div",{className:"create-doc-dropdown-url",children:[c.jsx("input",{ref:d,type:"text",placeholder:b.urlPlaceholder,value:o,onChange:k=>l(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),g()),k.key==="Escape"&&(i(null),l(""))}}),c.jsx("button",{onClick:g,disabled:!v,children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})})]})]},b.key))})}const c8=[{id:"full",label:"Full"},{id:"compact",label:"Compact"},{id:"minimal",label:"Minimal"}];function C2(t,e){for(const n of t){if(n.type==="doc"&&n.file===e)return[];if(n.type==="container"){const r=C2(n.items,e);if(r)return[n.id,...r]}}return null}function u8({docs:t,archivedDocs:e,workspaces:n,assignedFiles:r,pendingDocs:s,onSwitchDocument:i,onCreateDocument:o,actions:l,scrollRef:d,writingTitle:f,writingTarget:h,pendingWriteFilenames:m,searchQuery:g,searchResults:v,onSearchChange:b}){const k=I=>!!m&&m.has(I),[w,E]=x.useState(null),[C,T]=x.useState(""),[j,_]=x.useState(null),[A,O]=x.useState(()=>{try{const I=localStorage.getItem("ow-collapsed-sections");return I?new Set(JSON.parse(I)):new Set}catch{return new Set}}),[B,$]=x.useState(null),[W,J]=x.useState(null),[z,G]=x.useState(""),[D,U]=x.useState(null),[q,se]=x.useState(""),[V,te]=x.useState(null),[K,M]=x.useState(""),[L,ee]=x.useState(null),[fe,ge]=x.useState(null),[oe,we]=x.useState([]),[xe,We]=x.useState(!1),[He,Ze]=x.useState(null),[Oe,Ke]=x.useState(null),[pt,Je]=x.useState(null),[pe,mt]=x.useState(null),[ft,at]=x.useState(null),[nt,ht]=x.useState(NE),Fe=x.useRef(null);x.useEffect(()=>{if(!ft)return;const I=re=>{Fe.current&&!Fe.current.contains(re.target)&&at(null)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[ft]);const ve=I=>{ht(I),gM(I),at(null)},X=I=>{I.preventDefault(),at({x:I.clientX,y:I.clientY})},Be=x.useCallback((I,re)=>{fetch("/api/documents/batch-resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filenames:I,action:re})}).catch(()=>{})},[]),{draggedItem:ne,dropIndicator:de,handlePointerDown:he,dropClass:Ge,isDragging:Pe,isContainerDropTarget:et}=k2({docs:t,workspaces:n,assignedFiles:r,scrollRef:d,setCollapsedSections:O}),ot=x.useCallback(()=>{fetch("/api/plugins").then(I=>I.json()).then(I=>{const re=[];let ye=!1;for(const Te of I.plugins||[]){const Se=Te.displayName||void 0;for(const Ee of Te.sidebarMenuItems||[])re.push({...Ee,pluginDisplayName:Se});Te.name==="@openwriter/plugin-publish"&&Te.enabled&&(ye=!0)}we(re),We(ye)}).catch(()=>{})},[]);x.useEffect(()=>{ot()},[ot]),x.useEffect(()=>{const I=()=>ot();return window.addEventListener("ow-plugins-changed",I),()=>window.removeEventListener("ow-plugins-changed",I)},[ot]);const{variantsByMaster:bt,variantFilenames:Ye}=x.useMemo(()=>{const I=new Map,re=new Set;for(const ye of t)if(ye.masterDocId){const Te=I.get(ye.masterDocId)||[];Te.push(ye),I.set(ye.masterDocId,Te),re.add(ye.filename)}return{variantsByMaster:I,variantFilenames:re}},[t]),it=x.useCallback((I,re)=>{I.preventDefault(),I.stopPropagation(),ee({x:I.clientX,y:I.clientY,filename:re.filename,title:re.title,docId:re.docId,lastSent:re.lastSent,postedUrl:re.postedUrl,isNewsletter:re.isNewsletter})},[]),gt=x.useCallback(I=>{fetch("/api/documents/duplicate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:I})}).catch(()=>{})},[]),Nt=x.useCallback((I,re,ye)=>{fetch("/api/documents/duplicate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:I,masterDocId:re,variantType:ye})}).catch(()=>{})},[]),Ie=x.useCallback((I,re,ye,Te,Se)=>{if(re.promptForFocus&&Se===void 0){Ze({action:I,label:re.label,filename:ye,title:Te});return}fetch("/api/plugins/sidebar-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:I,filename:ye,title:Te,instructions:Se||"",label:re.label})}).catch(()=>{})},[]),Me=I=>{O(re=>{const ye=new Set(re);return ye.has(I)?ye.delete(I):ye.add(I),localStorage.setItem("ow-collapsed-sections",JSON.stringify([...ye])),ye})},qe=t.find(I=>I.isActive),F=x.useRef(n);if(F.current=n,x.useEffect(()=>{var I;if(qe)for(const re of F.current){const ye=C2(((I=re.workspace)==null?void 0:I.root)||[],qe.filename);if(ye){O(Te=>{const Se=[re.filename,...ye.map(me=>`container-${me}`)];if(Se.every(me=>!Te.has(me)))return Te;const Ee=new Set(Te);for(const me of Se)Ee.delete(me);return localStorage.setItem("ow-collapsed-sections",JSON.stringify([...Ee])),Ee});break}}},[qe==null?void 0:qe.filename]),v!==null)return c.jsx(Xd,{results:v,query:g,onSwitchDocument:i,actions:l});const ce=t.filter(I=>!r.has(I.filename)&&!Ye.has(I.filename)),Ne=(I,re,ye,Te,Se,Ee=!1)=>c.jsxs("div",{className:`sidebar-item ${I.isActive?"active":""} ${Pe(I.filename)?"dragging":""} ${Ge(I.filename)}`,"data-drag-id":I.filename,"data-drag-type":"doc","data-drag-ws":re||"__docs__","data-drag-container":ye||"",onPointerDown:me=>he(me,{type:"doc",file:I.filename,sourceWs:re||null},I.title),onClick:()=>!I.isActive&&!ne&&i(I.filename),onDoubleClick:()=>{E(I.filename),T(I.title)},onContextMenu:me=>it(me,I),children:[w===I.filename?c.jsx("input",{className:"sidebar-rename-input",value:C,onChange:me=>T(me.target.value),onBlur:()=>{l.handleRename(I.filename,I.title,C),E(null)},onKeyDown:me=>{me.key==="Enter"&&(l.handleRename(I.filename,I.title,C),E(null)),me.key==="Escape"&&E(null)},autoFocus:!0,onClick:me=>me.stopPropagation()}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-item-title-text",children:I.title}),I.variantType&&c.jsx("span",{className:"files-badge-variant",children:I.variantType}),l.getDocTags(I.filename).includes("✓")&&c.jsx("svg",{className:"sidebar-approved-icon",title:"Approved",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),I.lastSent&&c.jsx("svg",{className:"sidebar-sent-icon",title:"Sent",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),(I.autoAccept===!0||I.autoAccept!==!1&&Ee)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:I.autoAccept===!0?"Auto-accept on":"Auto-accept inherited"}),s.filenames.includes(I.filename)&&c.jsx("span",{className:"sidebar-pending-dot"})]}),Ls(I.filename)&&c.jsx("div",{className:"sidebar-item-context",children:x2(I.filename)}),c.jsxs("div",{className:"sidebar-item-meta",children:[I.wordCount.toLocaleString()," words · ",ca(I.lastModified)]}),c.jsxs("div",{className:"sidebar-tags",children:[l.getDocTags(I.filename).filter(me=>me!=="✓").map(me=>c.jsxs("span",{className:"sidebar-tag",onClick:ke=>ke.stopPropagation(),children:[me,c.jsx("span",{className:"sidebar-tag-remove",onClick:ke=>{ke.stopPropagation(),l.handleRemoveTag(I.filename,me)},children:"×"})]},me)),V===I.filename?c.jsx("input",{className:"sidebar-tag-input",value:K,onChange:me=>M(me.target.value),onBlur:()=>{K.trim()&&l.handleAddTag(I.filename,K),te(null)},onKeyDown:me=>{me.key==="Enter"&&(l.handleAddTag(I.filename,K),te(null),M("")),me.key==="Escape"&&(te(null),M(""))},autoFocus:!0,onClick:me=>me.stopPropagation(),placeholder:"tag..."}):c.jsx("button",{className:"sidebar-tag-add",onClick:me=>{me.stopPropagation(),te(I.filename),M("")},children:"+"})]})]}),j===I.filename?c.jsxs("div",{className:"sidebar-confirm-delete",onClick:me=>me.stopPropagation(),children:[c.jsx("span",{children:Ls(I.filename)?"Remove?":"Delete?"}),c.jsx("button",{onClick:()=>{l.handleDelete(I.filename),_(null)},children:"Yes"}),c.jsx("button",{onClick:()=>_(null),children:"No"})]}):c.jsx("button",{className:"sidebar-delete-btn",onClick:me=>{me.stopPropagation(),_(I.filename)},title:Ls(I.filename)?"Remove document":"Delete document",children:"×"})]},I.filename),P=(I,re,ye,Te,Se,Ee=!1)=>{const me=I.docId?bt.get(I.docId):void 0,ke=f&&(h==null?void 0:h.parentDocId)&&h.parentDocId===I.docId;if(!(me&&me.length>0||ke))return Ne(I,re,ye,Te,Se,Ee);const en=`variants-${I.docId}`,on=!A.has(en);return c.jsxs("div",{className:"sidebar-variant-group",children:[c.jsxs("div",{className:"sidebar-variant-master",onClick:Wt=>{Wt.target.closest(".sidebar-variant-chevron")&&(Wt.stopPropagation(),Me(en))},children:[Ne(I,re,ye,Te,Se,Ee),c.jsx("span",{className:`sidebar-variant-chevron${on?"":" collapsed"}`,children:c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),on&&c.jsxs("div",{className:"sidebar-variant-children",children:[me==null?void 0:me.map((Wt,Ft)=>Ne(Wt,re,ye,Te,Ft,Ee)),ke&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]})]})]},`vg-${I.filename}`)},Z=(I,re,ye,Te,Se,Ee,me=!1)=>{if(I.type==="doc"){const xt=t.find(Pn=>Pn.filename===I.file);return xt?Ye.has(xt.filename)?c.jsx(c.Fragment,{}):P(xt,ye,Te,Se,Ee,me):Ls(I.file)?c.jsx("div",{className:"sidebar-item sidebar-unavailable",children:c.jsxs("div",{className:"sidebar-item-title",children:[I.title||I.file," (unavailable)"]})},I.file):c.jsxs("div",{className:"sidebar-item sidebar-missing",children:[c.jsxs("div",{className:"sidebar-item-title",children:[I.title||I.file," (missing)"]}),c.jsx("button",{className:"sidebar-delete-btn",onClick:()=>l.handleRemoveFromWorkspace(ye,I.file),title:"Remove",children:"×"})]},I.file)}const ke=I,Ct=`container-${ke.id}`,en=A.has(Ct),on=re<=2?`depth-${re}`:"depth-2",Wt=ke.autoAccept===!0,Ft=Wt||me;return c.jsxs("div",{className:`sidebar-container ${on} ${en?"collapsed":""} ${Ge(ke.id)} ${et(ke.id)?"drop-inside":""}`,children:[c.jsxs("div",{className:`sidebar-container-header ${(de==null?void 0:de.itemId)===ke.id&&de.position==="inside"?"drop-inside":""}`,"data-drag-id":ke.id,"data-drag-type":"container-header","data-drag-ws":ye,"data-drag-parent":Te||"","data-section-key":Ct,onPointerDown:xt=>he(xt,{type:"container",id:ke.id,sourceWs:ye},ke.name),onClick:()=>!ne&&Me(Ct),onContextMenu:xt=>{xt.preventDefault(),xt.stopPropagation(),mt({x:xt.clientX,y:xt.clientY,type:"container",wsFilename:ye,containerId:ke.id,title:ke.name,nodes:ke.items,autoAccept:Wt})},children:[c.jsx("span",{className:`sidebar-chevron ${en?"collapsed":""}`,children:"▾"}),W===ke.id?c.jsx("input",{className:"sidebar-rename-input",value:z,onChange:xt=>G(xt.target.value),onBlur:()=>{l.handleRenameContainer(ye,ke.id,z),J(null)},onKeyDown:xt=>{xt.key==="Enter"&&(l.handleRenameContainer(ye,ke.id,z),J(null)),xt.key==="Escape"&&J(null)},autoFocus:!0,onClick:xt=>xt.stopPropagation()}):c.jsx("span",{className:"sidebar-container-name",onDoubleClick:xt=>{xt.stopPropagation(),J(ke.id),G(ke.name)},children:ke.name}),Ft&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:Wt?"Auto-accept on for this container":"Auto-accept inherited from workspace"}),c.jsxs("div",{className:"sidebar-container-actions",children:[c.jsx("button",{className:"sidebar-new-btn",onClick:xt=>{xt.stopPropagation(),Je({anchor:xt.target.getBoundingClientRect(),wsFilename:ye,containerId:ke.id})},title:"New doc",children:"+"}),re<2&&c.jsx("button",{className:"sidebar-new-btn",onClick:xt=>{xt.stopPropagation(),l.handleCreateContainer(ye,ke.id)},title:"New sub-container",children:"☐"}),c.jsx("button",{className:"sidebar-new-btn sidebar-container-delete",onClick:xt=>{xt.stopPropagation(),l.handleDeleteContainer(ye,ke.id)},title:"Delete container",children:"×"})]})]}),!en&&c.jsxs("div",{className:"sidebar-container-list","data-drop-ws":ye,"data-drop-container":ke.id,children:[f&&!(h!=null&&h.parentDocId)&&(h==null?void 0:h.wsFilename)===ye&&h.containerId===ke.id&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ke.items.filter(xt=>xt.type!=="doc"?!0:!(k(xt.file)||f&&(h==null?void 0:h.wsFilename)===ye&&h.containerId===ke.id&&xt.title===f)).map((xt,Pn)=>Z(xt,re+1,ye,ke.id,ke.items,Pn,Ft)),ke.items.length===0&&!f&&c.jsx("div",{className:"sidebar-empty",children:ne?"Drop here":"Empty"})]})]},ke.id)};return c.jsxs("div",{className:"sidebar-scroll",ref:d,children:[c.jsxs("div",{className:`sidebar-section sidebar-docs-section ${A.has("docs")?"docs-collapsed":""}`,children:[c.jsxs("div",{className:"sidebar-section-header","data-section-key":"docs",onClick:()=>Me("docs"),onContextMenu:X,children:[c.jsx("span",{className:`sidebar-chevron ${A.has("docs")?"collapsed":""}`,children:"▾"}),c.jsx("span",{className:"sidebar-label",children:"Documents"}),c.jsx("button",{className:"sidebar-new-btn",onClick:I=>{I.stopPropagation(),Je({anchor:I.target.getBoundingClientRect()})},title:"New document",children:"+"})]}),!A.has("docs")&&c.jsxs("div",{className:"sidebar-section-list","data-drop-ws":"__docs__",children:[f&&!(h!=null&&h.parentDocId)&&(!h||!n.some(I=>I.filename===(h==null?void 0:h.wsFilename)))&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ce.filter(I=>!k(I.filename)&&(!f||I.title!==f)).map((I,re)=>{const ye=ce.map(Te=>({type:"doc",file:Te.filename,title:Te.title}));return P(I,void 0,null,ye,re)}),ce.length===0&&c.jsx("div",{className:"sidebar-empty",children:ne?"Drop here to unassign":"No unassigned documents"})]})]}),n.map(I=>{var Se,Ee,me;const re=((Se=I.workspace)==null?void 0:Se.root)||[],ye=A.has(I.filename),Te=((Ee=I.workspace)==null?void 0:Ee.autoAccept)===!0||I.autoAccept===!0;return c.jsxs("div",{className:`sidebar-section sidebar-workspace-section ${ye?"ws-collapsed":""} ${Pe(I.filename)?"dragging":""} ${(de==null?void 0:de.itemId)===I.filename?de.position==="before"?"drop-before":"drop-after":""}`,children:[c.jsxs("div",{className:"sidebar-section-header","data-section-key":I.filename,"data-ws-drag":I.filename,onPointerDown:ke=>he(ke,{type:"workspace",filename:I.filename},I.title),onClick:()=>!ne&&Me(I.filename),onContextMenu:ke=>{var Ct;ke.preventDefault(),ke.stopPropagation(),mt({x:ke.clientX,y:ke.clientY,type:"workspace",wsFilename:I.filename,title:I.title,nodes:re,autoAccept:((Ct=I.workspace)==null?void 0:Ct.autoAccept)===!0||I.autoAccept===!0})},children:[c.jsx("span",{className:`sidebar-chevron ${ye?"collapsed":""}`,children:"▾"}),D===I.filename?c.jsx("input",{className:"sidebar-rename-input",value:q,onChange:ke=>se(ke.target.value),onBlur:()=>{l.handleRenameWorkspace(I.filename,q),U(null)},onKeyDown:ke=>{ke.key==="Enter"&&(l.handleRenameWorkspace(I.filename,q),U(null)),ke.key==="Escape"&&U(null)},autoFocus:!0,onClick:ke=>ke.stopPropagation()}):c.jsx("span",{className:"sidebar-label sidebar-workspace-label",onDoubleClick:ke=>{ke.stopPropagation(),U(I.filename),se(I.title)},children:I.title}),(((me=I.workspace)==null?void 0:me.autoAccept)===!0||I.autoAccept===!0)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:"Auto-accept on for this workspace"}),c.jsxs("div",{className:"sidebar-workspace-actions",children:[c.jsx("button",{className:"sidebar-new-btn",onClick:ke=>{ke.stopPropagation(),Je({anchor:ke.target.getBoundingClientRect(),wsFilename:I.filename,containerId:null})},title:"New document",children:"+"}),c.jsx("button",{className:"sidebar-new-btn",onClick:ke=>{ke.stopPropagation(),l.handleCreateContainer(I.filename,null)},title:"New container",children:"☐"}),B===I.filename?c.jsxs("span",{className:"sidebar-inline-confirm",onClick:ke=>ke.stopPropagation(),children:[c.jsx("button",{onClick:()=>{l.handleDeleteWorkspace(I.filename),$(null)},children:"Yes"}),c.jsx("button",{onClick:()=>$(null),children:"No"})]}):c.jsx("button",{className:"sidebar-new-btn sidebar-workspace-delete",onClick:ke=>{ke.stopPropagation(),$(I.filename)},title:"Delete workspace",children:"×"})]})]}),!ye&&c.jsxs("div",{className:"sidebar-section-list","data-drop-ws":I.filename,children:[f&&!(h!=null&&h.parentDocId)&&(h==null?void 0:h.wsFilename)===I.filename&&h.containerId===null&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),re.filter(ke=>ke.type!=="doc"?!0:!(k(ke.file)||f&&(h==null?void 0:h.wsFilename)===I.filename&&h.containerId===null&&ke.title===f)).map((ke,Ct)=>Z(ke,0,I.filename,null,re,Ct,Te)),re.length===0&&!f&&c.jsx("div",{className:"sidebar-empty",children:ne?"Drop here to add":"Empty workspace"})]})]},I.filename)}),c.jsx("div",{className:"sidebar-new-workspace",children:c.jsx("button",{onClick:l.handleCreateWorkspace,children:"+ New Workspace"})}),pe&&c.jsx(Ad,{x:pe.x,y:pe.y,filename:pe.wsFilename,title:pe.title,onClose:()=>mt(null),onDuplicate:()=>{},onRename:()=>{pe.type==="workspace"?(U(pe.wsFilename),se(pe.title)):pe.containerId&&(J(pe.containerId),G(pe.title)),mt(null)},onArchive:()=>{},onDelete:()=>{pe.type==="workspace"?l.handleDeleteWorkspace(pe.wsFilename):pe.containerId&&l.handleDeleteContainer(pe.wsFilename,pe.containerId)},onPluginAction:()=>{},pluginItems:[],folderMode:!0,onNewDoc:I=>{Je({anchor:I.target.getBoundingClientRect(),wsFilename:pe.wsFilename,containerId:pe.type==="container"?pe.containerId:null}),mt(null)},onNewContainer:()=>{l.handleCreateContainer(pe.wsFilename,pe.type==="container"?pe.containerId:null),mt(null)},onAcceptAll:()=>{const I=new Set;Tl(pe.nodes,I),I.size&&Be([...I],"accept"),mt(null)},onRejectAll:()=>{const I=new Set;Tl(pe.nodes,I),I.size&&Be([...I],"reject"),mt(null)},folderAutoAccept:pe.autoAccept,folderAutoAcceptLabel:pe.type==="workspace"?"for workspace":"for container",onToggleFolderAutoAccept:()=>{fetch("/api/auto-accept/inherit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wsFile:pe.wsFilename,...pe.type==="container"?{containerId:pe.containerId}:{},enabled:!pe.autoAccept})}).catch(()=>{})}}),L&&c.jsx(Ad,{x:L.x,y:L.y,filename:L.filename,title:L.title,onClose:()=>ee(null),onDuplicate:()=>gt(L.filename),onCreateVariant:L.docId?I=>Nt(L.filename,L.docId,I):void 0,onRename:()=>{E(L.filename),T(L.title)},onArchive:()=>l.handleArchive(L.filename),onDelete:()=>l.handleDelete(L.filename),onPluginAction:(I,re)=>Ie(I,re,L.filename,L.title),pluginItems:oe,onSchedulePost:xe?()=>{Ke({filename:L.filename,title:L.title}),ee(null)}:void 0,onViewAnalytics:L.docId&&L.lastSent&&(L.postedUrl||L.isNewsletter)?()=>{L.isNewsletter?ge({docId:L.docId,title:L.title}):L.postedUrl&&window.open(L.postedUrl,"_blank"),ee(null)}:void 0,viewAnalyticsLabel:L.isNewsletter?"View Analytics":L.postedUrl?"View on X":"View Analytics",isApproved:l.getDocTags(L.filename).includes("✓"),onToggleApprove:()=>{l.getDocTags(L.filename).includes("✓")?l.handleRemoveTag(L.filename,"✓"):(l.handleAddTag(L.filename,"✓"),setTimeout(()=>window.dispatchEvent(new CustomEvent("ow-accept-all")),50))},isAutoAccept:(()=>{var re;const I=(re=t.find(ye=>ye.filename===L.filename))==null?void 0:re.autoAccept;return I===!0?!0:I===!1?!1:Md(n,L.filename)})(),onToggleAutoAccept:()=>{var ye;const I=(ye=t.find(Te=>Te.filename===L.filename))==null?void 0:ye.autoAccept,re=I===!0?!0:I===!1?!1:Md(n,L.filename);fetch("/api/auto-accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:L.filename,enabled:!re})}).then(()=>l.fetchDocs()).catch(()=>{})},isAlreadySent:!!L.lastSent,onMarkSent:()=>{const I=L.filename;l.getDocTags(I).includes("✓")&&l.handleRemoveTag(I,"✓"),i(I),setTimeout(()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({manualPost:{postedAt:new Date().toISOString()}})}).then(()=>l.fetchDocs()).catch(()=>{})},100),ee(null)}}),He&&c.jsx(S2,{actionLabel:He.label,docTitle:He.title,onClose:()=>Ze(null),onConfirm:I=>{const re=oe.find(ye=>ye.action===He.action);re&&Ie(He.action,re,He.filename,He.title,I),Ze(null)}}),fe&&c.jsx(E2,{docId:fe.docId,title:fe.title,onClose:()=>ge(null)}),Oe&&c.jsx(Dl,{filename:Oe.filename,title:Oe.title,onClose:()=>Ke(null)}),pt&&c.jsx(N2,{anchorRect:pt.anchor,onClose:()=>Je(null),onSelect:I=>{Je(null),pt.wsFilename?l.handleCreateInWorkspace(pt.wsFilename,pt.containerId??null,I):I?fetch("/api/documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({metadata:I})}).catch(()=>{}):o()}}),ft&&c.jsx("div",{ref:Fe,className:"sidebar-density-dropdown",style:{position:"fixed",left:ft.x,top:ft.y,zIndex:200},children:c8.map(I=>c.jsx("button",{className:`sidebar-density-option ${nt===I.id?"active":""}`,onClick:()=>ve(I.id),children:I.label},I.id))})]})}function d8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,onCreateDocument:i,actions:o,scrollRef:l,searchQuery:d,searchResults:f}){const[h,m]=x.useState(null);if(f!==null)return c.jsx(Xd,{results:f,query:d,onSwitchDocument:s});const g=[...t].sort((w,E)=>new Date(E.lastModified).getTime()-new Date(w.lastModified).getTime()),v=[];let b="";for(const w of g){const E=e8(w.lastModified);E!==b&&(v.push({label:E,docs:[]}),b=E),v[v.length-1].docs.push(w)}const k=w=>{for(const E of e){if(!E.workspace)continue;const C=T=>{for(const j of T)if(j.type==="doc"&&j.file===w||j.type==="container"&&C(j.items))return!0;return!1};if(C(E.workspace.root))return E.title}return null};return c.jsxs("div",{className:"sidebar-scroll tl-scroll",ref:l,children:[c.jsxs("div",{className:"tl-header",children:[c.jsx("span",{className:"tl-title",children:"Timeline"}),c.jsx("button",{className:"sidebar-new-btn",onClick:i,title:"New document",children:"+"})]}),v.map(w=>c.jsxs("div",{className:"tl-group",children:[c.jsx("div",{className:"tl-date",children:w.label}),w.docs.map(E=>{const C=k(E.filename);return c.jsxs("div",{className:`tl-item ${E.isActive?"active":""}`,onClick:()=>!E.isActive&&s(E.filename),children:[c.jsx("div",{className:"tl-dot"}),c.jsxs("div",{className:"tl-content",children:[c.jsxs("div",{className:"tl-item-title",children:[c.jsx("span",{children:E.title}),r.filenames.includes(E.filename)&&c.jsx("span",{className:"sidebar-pending-dot"})]}),Ls(E.filename)&&c.jsx("div",{className:"tl-item-context",children:x2(E.filename)}),c.jsxs("div",{className:"tl-item-meta",children:[E.wordCount.toLocaleString()," words · ",ca(E.lastModified)]}),C&&c.jsx("div",{className:"tl-badge",children:C})]}),h===E.filename?c.jsxs("div",{className:"sidebar-confirm-delete",onClick:T=>T.stopPropagation(),children:[c.jsx("span",{children:Ls(E.filename)?"Remove?":"Delete?"}),c.jsx("button",{onClick:()=>{o.handleDelete(E.filename),m(null)},children:"Yes"}),c.jsx("button",{onClick:()=>m(null),children:"No"})]}):c.jsx("button",{className:"sidebar-delete-btn",onClick:T=>{T.stopPropagation(),m(E.filename)},title:Ls(E.filename)?"Remove":"Delete",children:"×"})]},E.filename)})]},w.label)),t.length===0&&c.jsx("div",{className:"sidebar-empty",children:"No documents yet"})]})}function f8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,actions:i,scrollRef:o,searchQuery:l,searchResults:d,onSearchChange:f}){const[h,m]=x.useState([]),[g,v]=x.useState(null),[b,k]=x.useState(null),w=x.useRef(null);x.useEffect(()=>{if(!g)return;const M=L=>{w.current&&!w.current.contains(L.target)&&v(null)};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[g]);const E=(M,L)=>{for(const ee of M)if(ee.type==="container"){if(ee.id===L)return ee;const fe=E(ee.items,L);if(fe)return fe}return null},C=M=>{let L=0;for(const ee of M)ee.type==="doc"?L++:ee.type==="container"&&(L+=C(ee.items));return L},T=M=>{const L=[];for(const ee of M)ee.type==="doc"?L.push(ee.file):ee.type==="container"&&L.push(...T(ee.items));return L},j=x.useMemo(()=>{if(h.length===0)return[];const M=h[h.length-1],L=e.find(fe=>fe.filename===M.wsFilename);if(!(L!=null&&L.workspace))return[];if(M.type==="workspace")return L.workspace.root;const ee=E(L.workspace.root,M.key);return ee?ee.items:[]},[h,e]),_=j.filter(M=>M.type==="container"),A=x.useMemo(()=>{const M=j.filter(L=>L.type==="doc").map(L=>L.file);return t.filter(L=>M.includes(L.filename))},[j,t]),O=M=>{const L=T(M.items);return t.filter(ee=>L.includes(ee.filename))},B=M=>{const L=e.find(fe=>fe.filename===M);if(!(L!=null&&L.workspace))return[];const ee=T(L.workspace.root);return t.filter(fe=>ee.includes(fe.filename))},$=x.useMemo(()=>t.filter(M=>!n.has(M.filename)),[t,n]),W=M=>{m(L=>[...L,M]),v(null)},J=()=>{m(M=>M.slice(0,-1)),v(null)},z=(M,L)=>{if(g===M){v(null);return}const fe=L.currentTarget.getBoundingClientRect();k({top:fe.bottom+4,left:fe.left}),v(M)},G=M=>{s(M),v(null)},D=h.length>1?h[h.length-2].title:"All",U=x.useRef(null),q=x.useRef(null),[se,V]=x.useState(null),te=x.useCallback(M=>{const ee=M.currentTarget.getBoundingClientRect();V({top:ee.bottom+4,left:ee.left})},[]);x.useEffect(()=>{if(!d)return;const M=L=>{q.current&&!q.current.contains(L.target)&&U.current&&!U.current.contains(L.target)&&f("")};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[d,f]);const K=()=>{if(!g)return[];if(g==="__unassigned__")return $;if(g==="__level-docs__")return A;const M=e.find(L=>L.filename===g);if(M)return B(M.filename);for(const L of e){if(!L.workspace)continue;const ee=E(L.workspace.root,g);if(ee)return O(ee)}return[]};return c.jsxs("div",{className:"board-scroll",ref:o,children:[c.jsxs("div",{className:"board-search-pill",children:[c.jsxs("svg",{className:"board-search-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"11",cy:"11",r:"8"}),c.jsx("path",{d:"m21 21-4.3-4.3"})]}),c.jsx("input",{ref:U,className:"board-search-input",type:"text",placeholder:"Search...",value:l,onChange:M=>f(M.target.value),onFocus:te}),l&&c.jsx("button",{className:"board-search-clear",onClick:()=>f(""),children:"×"})]}),h.length===0?c.jsx("button",{className:"board-back board-back--static",tabIndex:-1,children:"All"}):c.jsxs("button",{className:"board-back",onClick:J,title:`Back to ${D}`,children:["← ",D]}),h.length===0&&c.jsxs(c.Fragment,{children:[$.length>0&&c.jsxs("button",{className:`board-chip ${g==="__unassigned__"?"open":""}`,onClick:M=>z("__unassigned__",M),children:["Documents ",c.jsx("span",{className:"board-chip-count",children:$.length})]}),e.map(M=>{var ee;const L=(ee=M.workspace)==null?void 0:ee.root.some(fe=>fe.type==="container");return c.jsxs("button",{className:`board-chip ${g===M.filename?"open":""}`,onClick:fe=>L?W({type:"workspace",key:M.filename,title:M.title,wsFilename:M.filename}):z(M.filename,fe),children:[M.title," ",c.jsx("span",{className:"board-chip-count",children:M.docCount}),L&&c.jsx("span",{className:"board-chip-arrow",children:"›"})]},M.filename)}),c.jsx("button",{className:"board-chip board-chip-add",onClick:i.handleCreateWorkspace,title:"New workspace",children:"+"})]}),h.length>0&&c.jsxs(c.Fragment,{children:[A.length>0&&c.jsxs("button",{className:`board-chip board-chip-docs ${g==="__level-docs__"?"open":""}`,onClick:M=>z("__level-docs__",M),children:["Docs ",c.jsx("span",{className:"board-chip-count",children:A.length})]}),_.map(M=>{const L=M.items.some(ee=>ee.type==="container");return c.jsxs("button",{className:`board-chip ${g===M.id?"open":""}`,onClick:ee=>L?W({type:"container",key:M.id,title:M.name,wsFilename:h[h.length-1].wsFilename}):z(M.id,ee),children:[M.name," ",c.jsx("span",{className:"board-chip-count",children:C(M.items)}),L&&c.jsx("span",{className:"board-chip-arrow",children:"›"})]},M.id)})]}),g&&b&&(()=>{const M=K();return c.jsxs("div",{className:"board-dropdown",ref:w,style:{position:"fixed",top:b.top,left:b.left},children:[M.map(L=>c.jsxs("div",{className:`board-dropdown-item ${L.isActive?"active":""}`,onClick:()=>G(L.filename),children:[c.jsxs("span",{className:"board-dropdown-title",children:[L.title,r.filenames.includes(L.filename)&&c.jsx("span",{className:"board-pending-dot"})]}),c.jsxs("span",{className:"board-dropdown-meta",children:[L.wordCount.toLocaleString()," words · ",ca(L.lastModified)]})]},L.filename)),M.length===0&&c.jsx("div",{className:"board-dropdown-empty",children:"No documents"})]})})(),d&&se&&c.jsxs("div",{className:"board-dropdown board-search-dropdown",ref:q,style:{position:"fixed",top:se.top,left:se.left},children:[d.map(M=>c.jsxs("div",{className:`board-dropdown-item ${M.isActive?"active":""}`,onClick:()=>{s(M.filename),f("")},children:[c.jsx("span",{className:"board-dropdown-title",children:M.title}),M.matchType==="tag"&&M.matchedTag&&c.jsxs("span",{className:"board-dropdown-meta",children:["Tag: ",M.matchedTag]}),M.matchType==="content"&&M.snippet&&c.jsx("span",{className:"board-dropdown-meta board-search-snippet",children:M.snippet}),c.jsxs("span",{className:"board-dropdown-meta",children:[M.wordCount.toLocaleString()," words · ",ca(M.lastModified)]})]},M.filename)),d.length===0&&c.jsx("div",{className:"board-dropdown-empty",children:"No results"})]})]})}function h8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,actions:i,scrollRef:o,searchQuery:l,searchResults:d}){const[f,h]=x.useState([]);if(d!==null)return c.jsx(Xd,{results:d,query:l,onSwitchDocument:s});const m=(j,_)=>{for(const A of j)if(A.type==="container"){if(A.id===_)return A;const O=m(A.items,_);if(O)return O}return null},g=j=>{let _=0;for(const A of j)A.type==="doc"?_++:A.type==="container"&&(_+=g(A.items));return _},v=x.useMemo(()=>{if(f.length===0)return[];const j=f[f.length-1],_=e.find(O=>O.filename===j.wsFilename);if(!(_!=null&&_.workspace))return[];if(j.type==="workspace")return _.workspace.root;const A=m(_.workspace.root,j.key);return A?A.items:[]},[f,e]),b=v.filter(j=>j.type==="container"),k=x.useMemo(()=>{if(f.length===0)return t.filter(_=>!n.has(_.filename));const j=v.filter(_=>_.type==="doc").map(_=>_.file);return t.filter(_=>j.includes(_.filename))},[f,v,t,n]),w=j=>h(_=>[..._,j]),E=()=>h(j=>j.slice(0,-1)),C=f.length>1?f[f.length-2].title:"Shelf",T=f.length>0?f[f.length-1].title:"Documents";return c.jsxs("div",{className:"shelf-wrapper",children:[c.jsxs("div",{className:"shelf-spines",ref:o,children:[f.length>0&&c.jsxs("button",{className:"shelf-back",onClick:E,title:`Back to ${C}`,children:[c.jsx("span",{className:"shelf-back-arrow",children:"←"}),c.jsx("span",{className:"shelf-back-label",children:C})]}),f.length===0&&c.jsxs(c.Fragment,{children:[e.map(j=>c.jsxs("div",{className:"shelf-section-spine",onClick:()=>w({type:"workspace",key:j.filename,title:j.title,wsFilename:j.filename}),title:j.title,children:[c.jsx("span",{className:"shelf-section-title",children:j.title}),c.jsx("span",{className:"shelf-section-count",children:j.docCount})]},j.filename)),c.jsx("button",{className:"shelf-add",onClick:i.handleCreateWorkspace,title:"New workspace",children:"+"})]}),f.length>0&&b.map(j=>c.jsxs("div",{className:"shelf-section-spine shelf-section-container",onClick:()=>w({type:"container",key:j.id,title:j.name,wsFilename:f[f.length-1].wsFilename}),title:j.name,children:[c.jsx("span",{className:"shelf-section-title",children:j.name}),c.jsx("span",{className:"shelf-section-count",children:g(j.items)})]},j.id))]}),c.jsxs("div",{className:"shelf-docs",children:[c.jsx("div",{className:"shelf-docs-header",children:T}),c.jsxs("div",{className:"shelf-docs-list",children:[k.map(j=>c.jsxs("div",{className:`shelf-doc-item ${j.isActive?"active":""}`,onClick:()=>s(j.filename),children:[c.jsxs("div",{className:"shelf-doc-title",children:[c.jsx("span",{children:j.title}),r.filenames.includes(j.filename)&&c.jsx("span",{className:"shelf-pending-dot"})]}),c.jsxs("div",{className:"shelf-doc-meta",children:[j.wordCount.toLocaleString()," words · ",ca(j.lastModified)]})]},j.filename)),k.length===0&&c.jsx("div",{className:"shelf-docs-empty",children:"No documents"})]})]})]})}async function kk(t,e={}){var s,i;const r=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:t,arguments:e})})).json();if((i=(s=r==null?void 0:r.content)==null?void 0:s[0])!=null&&i.text)try{return JSON.parse(r.content[0].text)}catch{return r.content[0].text}return r}function _2({filename:t,title:e,isActive:n,onSwitchDocument:r,onClose:s}){const[i,o]=x.useState("loading"),[l,d]=x.useState([]),[f,h]=x.useState(null),[m,g]=x.useState(null),[v,b]=x.useState(null);x.useEffect(()=>{kk("list_blog_sites").then(E=>{if(E.error){g(E.error),o("error");return}const C=E.sites||[];d(C),C.length===0?o("pick"):C.length===1?(h(C[0].id),o("confirm")):o("pick")}).catch(E=>{g((E==null?void 0:E.message)||"Failed to load blog sites"),o("error")})},[]);const k=l.find(E=>E.id===f)||null,w=async()=>{if(k){o("posting"),g(null),n||(r(t),await new Promise(E=>setTimeout(E,350)));try{const E=await kk("post_to_blog",{site_id:k.id});if(E!=null&&E.error){g(E.error),o("error");return}const C=E.commit?`https://github.com/${k.owner}/${k.repo}/commit/${E.commit}`:void 0;b({...E,url:C}),o("done")}catch(E){g((E==null?void 0:E.message)||"Publish failed"),o("error")}}};return c.jsx("div",{className:"post-blog-overlay",onClick:()=>{i!=="posting"&&s()},children:c.jsxs("div",{className:"post-blog-modal",onClick:E=>E.stopPropagation(),children:[c.jsxs("div",{className:"post-blog-modal-header",children:[c.jsx("h3",{children:"Post to Blog"}),c.jsx("button",{className:"post-blog-modal-close",onClick:s,disabled:i==="posting",children:"×"})]}),c.jsx("div",{className:"post-blog-modal-doc",children:e}),i==="loading"&&c.jsx("div",{className:"post-blog-modal-loading",children:"Loading blog sites…"}),i==="pick"&&l.length===0&&c.jsxs("div",{className:"post-blog-modal-empty",children:["No blog sites registered. Add one in ",c.jsx("strong",{children:"Settings → Plugins → GitHub"})," first.",c.jsx("button",{className:"post-blog-modal-done",onClick:s,children:"Close"})]}),i==="pick"&&l.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"post-blog-modal-label",children:"Choose a destination"}),c.jsx("div",{className:"post-blog-modal-sites",children:l.map(E=>c.jsxs("button",{className:`post-blog-modal-site${f===E.id?" post-blog-modal-site--selected":""}`,onClick:()=>{h(E.id),o("confirm")},children:[c.jsx("div",{className:"post-blog-modal-site-label",children:E.label}),c.jsxs("div",{className:"post-blog-modal-site-repo",children:[E.owner,"/",E.repo,"@",E.branch]})]},E.id))})]}),i==="confirm"&&k&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"post-blog-modal-confirm",children:["Publish to ",c.jsxs("strong",{children:[k.owner,"/",k.repo,"@",k.branch]}),"?",c.jsxs("div",{className:"post-blog-modal-target-dir",children:["→ ",k.content_dir]})]}),c.jsxs("div",{className:"post-blog-modal-actions",children:[c.jsx("button",{className:"post-blog-modal-btn post-blog-modal-btn--primary",onClick:w,children:"Publish now"}),l.length>1&&c.jsx("button",{className:"post-blog-modal-btn",onClick:()=>o("pick"),children:"Back"}),c.jsx("button",{className:"post-blog-modal-btn",onClick:s,children:"Cancel"})]})]}),i==="posting"&&c.jsx("div",{className:"post-blog-modal-loading",children:"Publishing…"}),i==="done"&&v&&c.jsxs("div",{className:"post-blog-modal-result post-blog-modal-result--success",children:[c.jsx("div",{children:v.message||"Published"}),v.file&&c.jsx("div",{className:"post-blog-modal-meta",children:v.file}),typeof v.images_committed=="number"&&v.images_committed>0&&c.jsxs("div",{className:"post-blog-modal-meta",children:[v.images_committed," image",v.images_committed===1?"":"s"," committed"]}),c.jsxs("div",{className:"post-blog-modal-actions",children:[v.url&&c.jsx("button",{className:"post-blog-modal-btn post-blog-modal-btn--primary",onClick:()=>window.open(v.url,"_blank"),children:"View commit"}),c.jsx("button",{className:"post-blog-modal-btn",onClick:s,children:"Done"})]})]}),i==="error"&&c.jsxs("div",{className:"post-blog-modal-result post-blog-modal-result--error",children:[c.jsx("div",{children:m||"Publish failed"}),c.jsx("div",{className:"post-blog-modal-actions",children:c.jsx("button",{className:"post-blog-modal-btn",onClick:s,children:"Close"})})]})]})})}const p8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M20 20H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h4l2 2h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2z"}),c.jsx("line",{x1:"9",y1:"14",x2:"15",y2:"14",opacity:"0.5"})]}),m8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("polyline",{points:"14 2 14 8 20 8"}),c.jsx("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),c.jsx("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),g8=()=>c.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),v8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:[c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",opacity:"0.5"}),c.jsx("path",{d:"M7 15l-4-3.5L7 8",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),y8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:[c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",opacity:"0.5"}),c.jsx("path",{d:"M3 8V6.5C3 5.67 3.67 5 4.5 5h2C7.33 5 8 5.67 8 6.5V8c0 2-1.5 3-3 3",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),b8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:[c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",opacity:"0.5"}),c.jsx("rect",{x:"2",y:"16",width:"8",height:"7",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5"}),c.jsx("line",{x1:"4",y1:"18.5",x2:"8",y2:"18.5",stroke:"currentColor",strokeWidth:"1",opacity:"0.7"}),c.jsx("line",{x1:"4",y1:"20.5",x2:"7",y2:"20.5",stroke:"currentColor",strokeWidth:"1",opacity:"0.7"})]}),x8=()=>c.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:c.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 0 1-2.063-2.065 2.064 2.064 0 1 1 2.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"})}),w8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),c.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),k8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("path",{d:"M2 12h20"}),c.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]}),Sk=()=>c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})});function S8({type:t}){switch(t){case"tweet":return c.jsx(g8,{});case"reply":return c.jsx(v8,{});case"quote":return c.jsx(y8,{});case"article":return c.jsx(b8,{});case"linkedin":return c.jsx(x8,{});case"newsletter":return c.jsx(w8,{});case"blog":return c.jsx(k8,{});default:return c.jsx(m8,{})}}function Ou(t){let e=0;for(const n of t)n.type==="doc"?e++:n.type==="container"&&(e+=Ou(n.items));return e}function T2(t,e){for(const n of t){if(n.type==="doc"&&n.file===e)return[];if(n.type==="container"){const r=T2(n.items,e);if(r)return[n.id,...r]}}return null}function Op(t){const e=new Set;return Tl(t,e),[...e]}function j2(t,e,n=0){for(const r of t)if(r.type==="container"){if(r.id===e)return n;const s=j2(r.items,e,n+1);if(s>=0)return s}return-1}function E8(t,e){if(!e)return 12;for(const n of t){if(!n.workspace)continue;const r=j2(n.workspace.root,e);if(r>=0)return 12+(r+1)*16}return 12}function N8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,onCreateDocument:i,actions:o,scrollRef:l,writingTitle:d,writingTarget:f,pendingWriteFilenames:h,searchQuery:m,searchResults:g,onSearchChange:v}){var Ie,Me,qe;const b=F=>!!h&&h.has(F),[k,w]=x.useState(()=>{try{const F=localStorage.getItem("ow-files-collapsed");return F?new Set(JSON.parse(F)):new Set}catch{return new Set}}),{draggedItem:E,dropIndicator:C,handlePointerDown:T,dropClass:j,isDragging:_,isContainerDropTarget:A}=k2({docs:t,workspaces:e,assignedFiles:n,scrollRef:l,setCollapsedSections:w}),O=F=>!C||C.itemId!==F||C.position==="inside"?void 0:{"--drop-indent":`${E8(e,C.containerId)}px`},{variantsByMaster:B,variantFilenames:$}=x.useMemo(()=>{const F=new Map,ce=new Set;for(const Ne of t)if(Ne.masterDocId){const P=F.get(Ne.masterDocId)||[];P.push(Ne),F.set(Ne.masterDocId,P),ce.add(Ne.filename)}return{variantsByMaster:F,variantFilenames:ce}},[t]),[W,J]=x.useState(null),[z,G]=x.useState(null),[D,U]=x.useState(new Set),[q,se]=x.useState(null),[V,te]=x.useState([]),[K,M]=x.useState(!1),[L,ee]=x.useState(null),[fe,ge]=x.useState(null),[oe,we]=x.useState(null),[xe,We]=x.useState(null),[He,Ze]=x.useState(null),[Oe,Ke]=x.useState(null),[pt,Je]=x.useState(new Set);x.useEffect(()=>{Je(new Set)},[r]);const pe=x.useCallback(()=>{fetch("/api/plugins").then(F=>F.json()).then(F=>{const ce=[];let Ne=!1;for(const P of F.plugins||[]){const Z=P.displayName||void 0;for(const I of P.sidebarMenuItems||[])ce.push({...I,pluginDisplayName:Z});P.name==="@openwriter/plugin-publish"&&P.enabled&&(Ne=!0)}te(ce),M(Ne)}).catch(()=>{})},[]);x.useEffect(()=>{pe()},[pe]),x.useEffect(()=>{const F=()=>pe();return window.addEventListener("ow-plugins-changed",F),()=>window.removeEventListener("ow-plugins-changed",F)},[pe]);const mt=x.useCallback((F,ce)=>{if(F.preventDefault(),F.stopPropagation(),D.has(ce.filename)&&D.size>1){G({x:F.clientX,y:F.clientY,filename:ce.filename,title:ce.title,bulkCount:D.size});return}D.size>0&&!D.has(ce.filename)&&U(new Set),G({x:F.clientX,y:F.clientY,filename:ce.filename,title:ce.title,docId:ce.docId,lastSent:ce.lastSent,postedUrl:ce.postedUrl,isNewsletter:ce.isNewsletter,contentType:ce.contentType,sortRequest:ce.sortRequest})},[D]),ft=x.useCallback(F=>{fetch("/api/documents/duplicate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:F})}).catch(()=>{})},[]),at=x.useCallback((F,ce,Ne,P,Z)=>{if(ce.promptForFocus&&Z===void 0){ee({action:F,label:ce.label,filename:Ne,title:P});return}fetch("/api/plugins/sidebar-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:F,filename:Ne,title:P,instructions:Z||"",label:ce.label})}).catch(()=>{})},[]),nt=x.useCallback((F,ce)=>{Je(Ne=>{const P=new Set(Ne);for(const Z of F)P.add(Z);return P}),fetch("/api/documents/batch-resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filenames:F,action:ce})}).catch(()=>{})},[]),ht=F=>{w(ce=>{const Ne=new Set(ce);return Ne.has(F)?Ne.delete(F):Ne.add(F),localStorage.setItem("ow-files-collapsed",JSON.stringify([...Ne])),Ne})},Fe=(F,ce,Ne,P)=>{J({type:F,key:ce,value:Ne,wsFilename:P})},ve=()=>{if(!W)return;const{type:F,key:ce,value:Ne,wsFilename:P}=W;F==="doc"?o.handleRename(ce,"",Ne):F==="workspace"?o.handleRenameWorkspace(ce,Ne):F==="container"&&P&&o.handleRenameContainer(P,ce,Ne),J(null)},X=t.find(F=>F.isActive),Be=x.useRef(e);Be.current=e,x.useEffect(()=>{var F;if(X)for(const ce of Be.current){const Ne=T2(((F=ce.workspace)==null?void 0:F.root)||[],X.filename);if(Ne){w(P=>{const Z=[ce.filename,...Ne.map(re=>`container-${re}`)];if(Z.every(re=>!P.has(re)))return P;const I=new Set(P);for(const re of Z)I.delete(re);return localStorage.setItem("ow-files-collapsed",JSON.stringify([...I])),I});break}}},[X==null?void 0:X.filename]);const ne=x.useMemo(()=>t.filter(F=>!n.has(F.filename)&&!$.has(F.filename)&&!b(F.filename)),[t,n,$,h]),de=x.useMemo(()=>{var P;const F=[],ce=Z=>{F.push(Z.filename);const I=Z.docId?B.get(Z.docId):void 0,re=Z.docId&&!k.has(`variants-${Z.docId}`);if(I&&re)for(const ye of I)F.push(ye.filename)},Ne=Z=>{for(const I of Z)if(I.type==="doc"){const re=t.find(ye=>ye.filename===I.file);re&&!$.has(re.filename)&&ce(re)}else k.has(`container-${I.id}`)||Ne(I.items)};k.has("docs")||ne.forEach(ce);for(const Z of e)k.has(Z.filename)||Ne(((P=Z.workspace)==null?void 0:P.root)||[]);return F},[t,e,ne,$,B,k]),he=x.useCallback(()=>{U(new Set)},[]),Ge=x.useCallback((F,ce)=>{if(E)return;const Ne=F.shiftKey,P=F.ctrlKey||F.metaKey;if(Ne){const I=q||(X==null?void 0:X.filename)||ce,re=de.indexOf(I),ye=de.indexOf(ce);if(re<0||ye<0){U(new Set([ce])),se(ce);return}const[Te,Se]=re<ye?[re,ye]:[ye,re];U(new Set(de.slice(Te,Se+1)));return}if(P){U(I=>{const re=new Set(I);return re.has(ce)?re.delete(ce):re.add(ce),re}),se(ce);return}U(new Set),se(ce);const Z=t.find(I=>I.filename===ce);Z&&!Z.isActive&&s(ce)},[E,q,X==null?void 0:X.filename,de,s,t]);x.useEffect(()=>{if(D.size===0)return;const F=ce=>{ce.key==="Escape"&&he()};return document.addEventListener("keydown",F),()=>document.removeEventListener("keydown",F)},[D.size,he]);const Pe=x.useCallback(()=>{for(const F of D)o.handleDelete(F);U(new Set),se(null)},[D,o]),et=x.useCallback(F=>{F.length!==0&&fetch("/api/documents/sort-request",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filenames:F})}).then(()=>o.fetchDocs()).catch(()=>{})},[o]),ot=x.useCallback(F=>{fetch("/api/documents/sort-reject",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:F})}).then(()=>o.fetchDocs()).catch(()=>{})},[o]),bt=x.useCallback(F=>{fetch("/api/documents/sort-accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:F})}).then(()=>o.fetchDocs()).catch(()=>{})},[o]);if(g!==null)return c.jsx(Xd,{results:g,query:m,onSwitchDocument:s,actions:o});const Ye=F=>c.jsx("input",{className:"sidebar-rename-input",value:W.value,onChange:ce=>J(Ne=>Ne?{...Ne,value:ce.target.value}:null),onBlur:F,onKeyDown:ce=>{ce.key==="Enter"&&F(),ce.key==="Escape"&&J(null)},autoFocus:!0,onClick:ce=>ce.stopPropagation()}),it=(F,ce,Ne,P,Z,I=!1)=>c.jsxs("div",{className:`files-row${F.isActive?" active":""}${D.has(F.filename)?" selected":""} ${_(F.filename)?"dragging":""} ${j(F.filename)}${F.masterDocId?" is-variant":""}`,style:{paddingLeft:ce,...O(F.filename)},"data-drag-id":F.filename,"data-drag-type":"doc","data-drag-ws":Ne||"__docs__","data-drag-container":P||"",onPointerDown:re=>T(re,{type:"doc",file:F.filename,sourceWs:Ne||null},F.title),onClick:re=>Ge(re,F.filename),onDoubleClick:()=>Fe("doc",F.filename,F.title),onContextMenu:re=>mt(re,F),children:[c.jsx("span",{className:"files-row-icon",children:c.jsx(S8,{type:F.contentType})}),(W==null?void 0:W.type)==="doc"&&W.key===F.filename?Ye(ve):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"files-row-label",children:F.title}),F.variantType&&c.jsx("span",{className:"files-badge-variant",children:F.variantType}),(F.autoAccept===!0||F.autoAccept!==!1&&I)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:F.autoAccept===!0?"Auto-accept on":"Auto-accept inherited"}),r.filenames.includes(F.filename)&&!pt.has(F.filename)&&c.jsx("span",{className:"files-badge-pending"}),F.sortRequest&&(F.sortRequest.proposal?c.jsx("span",{className:"files-badge-sort-proposal",title:"Sort proposal ready — right-click to review"}):c.jsx("span",{className:"files-badge-sort-pending",title:"Sort requested"})),o.getDocTags(F.filename).includes("✓")&&c.jsx("span",{className:"files-badge-approved",children:c.jsx(Sk,{})}),F.lastSent&&c.jsx("span",{className:"files-badge-sent",children:c.jsx(Sk,{})}),Z&&c.jsx("span",{className:`files-row-chevron${k.has(`variants-${F.docId}`)?" collapsed":""}`,onClick:re=>{re.stopPropagation(),ht(`variants-${F.docId}`)},children:c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})})]})]},F.filename),gt=(F,ce,Ne,P,Z=!1)=>{const I=F.docId?B.get(F.docId):void 0,re=!!(I&&I.length>0),ye=d&&(f==null?void 0:f.parentDocId)&&f.parentDocId===F.docId,Te=re||ye,Se=!k.has(`variants-${F.docId}`);return Te?c.jsxs("div",{className:"files-variant-group",children:[it(F,ce,Ne,P,re,Z),Se&&(I==null?void 0:I.map(Ee=>it(Ee,ce+16,Ne,P,!1,Z))),ye&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:ce+16},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]})]},`vg-${F.filename}`):it(F,ce,Ne,P,!1,Z)},Nt=(F,ce,Ne,P,Z=!1)=>{const I=12+ce*16;if(F.type==="doc"){const ke=t.find(Ct=>Ct.filename===F.file);return!ke||$.has(ke.filename)?null:gt(ke,I,Ne,P,Z)}const re=F,ye=`container-${re.id}`,Te=k.has(ye),Se=Ou(re.items),Ee=re.autoAccept===!0,me=Ee||Z;return c.jsxs("div",{className:`${j(re.id)} ${A(re.id)?"files-drop-inside":""}`,children:[c.jsxs("div",{className:`files-row is-container ${_(re.id)?"dragging":""} ${j(re.id)}`,style:{paddingLeft:I,...O(re.id)},"data-drag-id":re.id,"data-drag-type":"container-header","data-drag-ws":Ne,"data-drag-parent":P||"","data-section-key":ye,onPointerDown:ke=>T(ke,{type:"container",id:re.id,sourceWs:Ne},re.name),onClick:()=>!E&&ht(ye),onDoubleClick:ke=>{ke.stopPropagation(),Fe("container",re.id,re.name,Ne)},onContextMenu:ke=>{ke.preventDefault(),ke.stopPropagation(),Ke({x:ke.clientX,y:ke.clientY,type:"container",wsFilename:Ne,containerId:re.id,title:re.name,nodes:re.items,autoAccept:Ee})},children:[c.jsx("span",{className:"files-row-icon",children:c.jsx(p8,{})}),(W==null?void 0:W.type)==="container"&&W.key===re.id?Ye(ve):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"files-row-label",children:re.name}),me&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:Ee?"Auto-accept on for this container":"Auto-accept inherited from workspace"}),c.jsx("span",{className:"files-row-count",children:Se})]})]}),c.jsxs("div",{className:`files-children${Te?" collapsed":""}`,"data-drop-ws":Ne,"data-drop-container":re.id,children:[d&&!(f!=null&&f.parentDocId)&&(f==null?void 0:f.wsFilename)===Ne&&f.containerId===re.id&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:12+(ce+1)*16},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),re.items.filter(ke=>ke.type!=="doc"||!b(ke.file)).map(ke=>Nt(ke,ce+1,Ne,re.id,me))]})]},re.id)};return c.jsxs("div",{className:"files-scroll",ref:l,children:[c.jsxs("div",{className:"files-section",children:[c.jsxs("div",{className:"files-row is-section","data-section-key":"docs",onClick:()=>ht("docs"),children:[c.jsx("span",{className:`files-row-chevron leading${k.has("docs")?" collapsed":""}`,children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),c.jsx("span",{className:"files-row-label",children:"Documents"}),c.jsx("button",{className:"files-section-btn",onClick:F=>{F.stopPropagation(),Ze({anchor:F.target.getBoundingClientRect()})},title:"New document",children:"+"})]}),c.jsxs("div",{className:`files-section-list files-children${k.has("docs")?" collapsed":""}`,"data-drop-ws":"__docs__",children:[d&&!(f!=null&&f.parentDocId)&&(!f||!e.some(F=>F.filename===(f==null?void 0:f.wsFilename)))&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:28},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ne.map(F=>gt(F,28))]})]}),e.map(F=>{var I,re,ye;const ce=((I=F.workspace)==null?void 0:I.root)||[],Ne=k.has(F.filename),P=Ou(ce),Z=((re=F.workspace)==null?void 0:re.autoAccept)===!0||F.autoAccept===!0;return c.jsxs("div",{className:`files-section ${_(F.filename)?"dragging":""} ${(C==null?void 0:C.itemId)===F.filename?C.position==="before"?"files-ws-drop-before":"files-ws-drop-after":""}`,children:[c.jsx("div",{className:`files-row is-section${(C==null?void 0:C.itemId)==="__section__"&&C.wsFilename===F.filename&&C.position==="inside"?" files-ws-drop-target":""}`,"data-section-key":F.filename,"data-ws-drag":F.filename,onPointerDown:Te=>T(Te,{type:"workspace",filename:F.filename},F.title),onClick:()=>!E&&ht(F.filename),onDoubleClick:Te=>{Te.stopPropagation(),Fe("workspace",F.filename,F.title)},onContextMenu:Te=>{var Se;Te.preventDefault(),Te.stopPropagation(),Ke({x:Te.clientX,y:Te.clientY,type:"workspace",wsFilename:F.filename,title:F.title,nodes:ce,autoAccept:((Se=F.workspace)==null?void 0:Se.autoAccept)===!0||F.autoAccept===!0})},children:(W==null?void 0:W.type)==="workspace"&&W.key===F.filename?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:`files-row-chevron leading${Ne?" collapsed":""}`,children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),Ye(ve)]}):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:`files-row-chevron leading${Ne?" collapsed":""}`,children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),c.jsx("span",{className:"files-row-label",children:F.title}),(((ye=F.workspace)==null?void 0:ye.autoAccept)===!0||F.autoAccept===!0)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:"Auto-accept on for this workspace"}),c.jsx("span",{className:"files-row-count",children:P}),c.jsxs("div",{className:"files-section-actions",children:[c.jsx("button",{className:"files-section-btn",onClick:Te=>{Te.stopPropagation(),Ze({anchor:Te.target.getBoundingClientRect(),wsFilename:F.filename,containerId:null})},title:"New document",children:"+"}),c.jsx("button",{className:"files-section-btn",onClick:Te=>{Te.stopPropagation(),o.handleCreateContainer(F.filename,null)},title:"New container",children:"☐"})]})]})}),c.jsxs("div",{className:`files-section-list files-children${Ne?" collapsed":""}`,"data-drop-ws":F.filename,children:[d&&!(f!=null&&f.parentDocId)&&(f==null?void 0:f.wsFilename)===F.filename&&f.containerId===null&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:28},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ce.filter(Te=>Te.type!=="doc"||!b(Te.file)).map(Te=>Nt(Te,1,F.filename,null,Z))]})]},F.filename)}),c.jsx("div",{className:"files-new-ws",children:c.jsx("button",{onClick:o.handleCreateWorkspace,children:"+ New Workspace"})}),Oe&&c.jsx(Ad,{x:Oe.x,y:Oe.y,filename:Oe.wsFilename,title:Oe.title,onClose:()=>Ke(null),onDuplicate:()=>{},onRename:()=>{Oe.type==="workspace"?Fe("workspace",Oe.wsFilename,Oe.title):Oe.containerId&&Fe("container",Oe.containerId,Oe.title,Oe.wsFilename),Ke(null)},onArchive:()=>{},onDelete:()=>{Oe.type==="workspace"?o.handleDeleteWorkspace(Oe.wsFilename):Oe.containerId&&o.handleDeleteContainer(Oe.wsFilename,Oe.containerId,!1)},folderDocCount:Oe.type==="container"?Ou(Oe.nodes):0,onDeleteWithDocs:Oe.type==="container"&&Oe.containerId?()=>{o.handleDeleteContainer(Oe.wsFilename,Oe.containerId,!0)}:void 0,onPluginAction:()=>{},pluginItems:[],folderMode:!0,onNewDoc:F=>{Ze({anchor:F.target.getBoundingClientRect(),wsFilename:Oe.wsFilename,containerId:Oe.type==="container"?Oe.containerId:null}),Ke(null)},onNewContainer:()=>{o.handleCreateContainer(Oe.wsFilename,Oe.type==="container"?Oe.containerId:null),Ke(null)},onAcceptAll:()=>{const F=Op(Oe.nodes);F.length&&nt(F,"accept"),Ke(null)},onRejectAll:()=>{const F=Op(Oe.nodes);F.length&&nt(F,"reject"),Ke(null)},folderAutoAccept:Oe.autoAccept,folderAutoAcceptLabel:Oe.type==="workspace"?"for workspace":"for container",onToggleFolderAutoAccept:()=>{fetch("/api/auto-accept/inherit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wsFile:Oe.wsFilename,...Oe.type==="container"?{containerId:Oe.containerId}:{},enabled:!Oe.autoAccept})}).catch(()=>{})},onRequestSortAll:()=>{const F=Op(Oe.nodes);F.length&&et(F)}}),z&&c.jsx(Ad,{x:z.x,y:z.y,filename:z.filename,title:z.title,bulkCount:z.bulkCount,onBulkDelete:Pe,onBulkRequestSort:z.bulkCount?()=>et([...D]):void 0,onClose:()=>G(null),onDuplicate:()=>ft(z.filename),onCreateVariant:z.docId?F=>{fetch("/api/documents/duplicate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:z.filename,masterDocId:z.docId,variantType:F})}).catch(()=>{})}:void 0,onRename:()=>{Fe("doc",z.filename,z.title),G(null)},onArchive:()=>o.handleArchive(z.filename),onDelete:()=>o.handleDelete(z.filename),onPluginAction:(F,ce)=>at(F,ce,z.filename,z.title),pluginItems:V,onSchedulePost:K?()=>{ge({filename:z.filename,title:z.title}),G(null)}:void 0,onPostNow:z.contentType==="blog"?()=>{const F=(X==null?void 0:X.filename)===z.filename;we({filename:z.filename,title:z.title,isActive:F}),G(null)}:void 0,isAlreadyPublished:z.contentType==="blog"&&!!z.postedUrl,onViewAnalytics:z.docId&&z.lastSent&&(z.postedUrl||z.isNewsletter)?()=>{z.isNewsletter?We({docId:z.docId,title:z.title}):z.postedUrl&&window.open(z.postedUrl,"_blank"),G(null)}:void 0,viewAnalyticsLabel:z.isNewsletter?"View Analytics":z.contentType==="blog"&&z.postedUrl?"View Post":z.postedUrl?"View on X":"View Analytics",isApproved:o.getDocTags(z.filename).includes("✓"),onToggleApprove:()=>{o.getDocTags(z.filename).includes("✓")?o.handleRemoveTag(z.filename,"✓"):(o.handleAddTag(z.filename,"✓"),setTimeout(()=>window.dispatchEvent(new CustomEvent("ow-accept-all")),50))},isAutoAccept:(()=>{var ce;const F=(ce=t.find(Ne=>Ne.filename===z.filename))==null?void 0:ce.autoAccept;return F===!0?!0:F===!1?!1:Md(e,z.filename)})(),onToggleAutoAccept:()=>{var Ne;const F=(Ne=t.find(P=>P.filename===z.filename))==null?void 0:Ne.autoAccept,ce=F===!0?!0:F===!1?!1:Md(e,z.filename);fetch("/api/auto-accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:z.filename,enabled:!ce})}).then(()=>o.fetchDocs()).catch(()=>{})},isAlreadySent:!!z.lastSent,onMarkSent:()=>{const F=z.filename;o.getDocTags(F).includes("✓")&&o.handleRemoveTag(F,"✓"),s(F),setTimeout(()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({manualPost:{postedAt:new Date().toISOString()}})}).then(()=>o.fetchDocs()).catch(()=>{})},100),G(null)},sortState:z.bulkCount?void 0:(Ie=z.sortRequest)!=null&&Ie.proposal?"proposal":z.sortRequest?"pending":"none",sortProposalLabel:(()=>{var I;const F=(I=z.sortRequest)==null?void 0:I.proposal;if(!F)return;const ce=e.find(re=>re.filename===F.wsFilename),Ne=(ce==null?void 0:ce.title)||F.wsFilename;if(!F.containerId)return Ne;const P=re=>{for(const ye of re){if(ye.type==="container"&&ye.id===F.containerId)return ye.name;if(ye.type==="container"){const Te=P(ye.items);if(Te)return Te}}return null},Z=ce!=null&&ce.workspace?P(ce.workspace.root):null;return Z?`${Ne} / ${Z}`:Ne})(),sortProposalReasoning:(qe=(Me=z.sortRequest)==null?void 0:Me.proposal)==null?void 0:qe.reasoning,onRequestSort:z.bulkCount?void 0:()=>et([z.filename]),onCancelSort:()=>ot(z.filename),onAcceptSortProposal:()=>bt(z.filename),onRejectSortProposal:()=>ot(z.filename)}),L&&c.jsx(S2,{actionLabel:L.label,docTitle:L.title,onClose:()=>ee(null),onConfirm:F=>{const ce=V.find(Ne=>Ne.action===L.action);ce&&at(L.action,ce,L.filename,L.title,F),ee(null)}}),xe&&c.jsx(E2,{docId:xe.docId,title:xe.title,onClose:()=>We(null)}),fe&&c.jsx(Dl,{filename:fe.filename,title:fe.title,onClose:()=>ge(null)}),oe&&c.jsx(_2,{filename:oe.filename,title:oe.title,isActive:oe.isActive,onSwitchDocument:s,onClose:()=>we(null)}),He&&c.jsx(N2,{anchorRect:He.anchor,onClose:()=>Ze(null),onSelect:F=>{Ze(null),He.wsFilename?o.handleCreateInWorkspace(He.wsFilename,He.containerId??null,F):F?fetch("/api/documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({metadata:F})}).catch(()=>{}):i()}})]})}const C8=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],_8=[{value:"any",label:"Any"},{value:"content_type",label:"Content Type"},{value:"connection",label:"Connection"}],M2=["America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Anchorage","Pacific/Honolulu","America/Phoenix","America/Toronto","America/Vancouver","America/Sao_Paulo","America/Mexico_City","Europe/London","Europe/Paris","Europe/Berlin","Europe/Amsterdam","Europe/Rome","Europe/Madrid","Europe/Moscow","Asia/Tokyo","Asia/Shanghai","Asia/Kolkata","Asia/Dubai","Asia/Singapore","Asia/Seoul","Australia/Sydney","Australia/Melbourne","Pacific/Auckland"];function Ek(t){var e;try{const n=new Date,i=((e=new Intl.DateTimeFormat("en-US",{timeZone:t,timeZoneName:"short"}).formatToParts(n).find(l=>l.type==="timeZoneName"))==null?void 0:e.value)||"";return`${t.split("/").pop().replace(/_/g," ")} (${i})`}catch{return t}}function T8(t){if(t.length>0)return t[0].timezone;try{const e=Intl.DateTimeFormat().resolvedOptions().timeZone;if(M2.includes(e))return e}catch{}return"America/New_York"}function j8({slots:t,onBack:e}){const[n,r]=x.useState(t),[s,i]=x.useState(()=>T8(t)),[o,l]=x.useState(!1),[d,f]=x.useState("09:00"),[h,m]=x.useState(["default"]),[g,v]=x.useState("any"),[b,k]=x.useState(!1),w=x.useRef(null);x.useEffect(()=>{if(!o)return;function _(A){w.current&&!w.current.contains(A.target)&&l(!1)}return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[o]);async function E(_){i(_);const A=[];for(const O of n){const B=await fetch(`/api/scheduler/slots/${O.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({timezone:_})});if(B.ok){const $=await B.json();A.push($.slot)}else A.push(O)}A.length>0&&r(A)}async function C(){const _=await fetch("/api/scheduler/slots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({time:d,days:h.includes("default")?["default"]:h,filter_type:g,timezone:s})});if(_.ok){const A=await _.json();r(O=>[...O,A.slot]),k(!1),f("09:00"),m(["default"]),v("any")}}async function T(_){(await fetch(`/api/scheduler/slots/${_}`,{method:"DELETE"})).ok&&r(O=>O.filter(B=>B.id!==_))}function j(_){m(A=>{if(_==="default")return["default"];const O=A.filter(B=>B!=="default");if(O.includes(_)){const B=O.filter($=>$!==_);return B.length===0?["default"]:B}return[...O,_]})}return c.jsxs("div",{className:"sidebar-schedule",children:[c.jsxs("div",{className:"sidebar-schedule-header",children:[c.jsx("button",{className:"sidebar-schedule-btn",onClick:e,title:"Back",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Slot Settings"}),c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>k(!b),children:b?"Cancel":"+ Add"})]}),c.jsxs("div",{className:"slot-tz",ref:w,children:[c.jsx("label",{className:"slot-tz-label",children:"Timezone"}),c.jsxs("button",{className:"slot-tz-trigger",onClick:()=>l(!o),children:[c.jsx("span",{children:Ek(s)}),c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`slot-tz-chevron ${o?"slot-tz-chevron--open":""}`,children:c.jsx("path",{d:"m6 9 6 6 6-6"})})]}),o&&c.jsx("div",{className:"slot-tz-dropdown",children:M2.map(_=>c.jsx("div",{className:`slot-tz-option ${_===s?"active":""}`,onClick:()=>{E(_),l(!1)},children:Ek(_)},_))})]}),b&&c.jsxs("div",{className:"slot-add-form",children:[c.jsxs("div",{className:"slot-add-row",children:[c.jsx("input",{type:"time",className:"slot-input",value:d,onChange:_=>f(_.target.value)}),c.jsx("select",{className:"slot-input",value:g,onChange:_=>v(_.target.value),children:_8.map(_=>c.jsx("option",{value:_.value,children:_.label},_.value))})]}),c.jsxs("div",{className:"slot-add-days",children:[c.jsx("button",{className:`sidebar-schedule-btn slot-day-btn ${h.includes("default")?"sidebar-schedule-btn--active":""}`,onClick:()=>j("default"),children:"Every day"}),C8.map(_=>c.jsx("button",{className:`sidebar-schedule-btn slot-day-btn ${h.includes(_.toLowerCase())?"sidebar-schedule-btn--active":""}`,onClick:()=>j(_.toLowerCase()),children:_},_))]}),c.jsx("button",{className:"sidebar-schedule-btn sidebar-schedule-btn--active slot-create-btn",onClick:C,children:"Create Slot"})]}),c.jsx("div",{className:"slot-list",children:n.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No slots"}),c.jsx("div",{className:"schedule-empty-desc",children:"Create time slots to define your posting schedule."})]}):n.map(_=>c.jsxs("div",{className:"schedule-item slot-item",children:[c.jsx("div",{className:"schedule-item-time slot-item-time",children:M8(_.time)}),c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:_.days.includes("default")?"Every day":_.days.join(", ")}),c.jsxs("div",{className:"schedule-item-meta",children:[c.jsxs("span",{children:["Filter: ",_.filter_type]}),_.filter_value&&c.jsxs("span",{children:["(",_.filter_value,")"]})]})]}),c.jsx("button",{className:"schedule-item-action schedule-item-action--danger slot-delete-btn",onClick:()=>T(_.id),title:"Delete slot",children:"×"})]},_.id))})]})}function M8(t){const[e,n]=t.split(":").map(Number),r=e>=12?"PM":"AM";return`${e%12||12}:${String(n).padStart(2,"0")} ${r}`}function A8({onBack:t}){const[e,n]=x.useState([]),[r,s]=x.useState([]),[i,o]=x.useState(null),[l,d]=x.useState(!1),[f,h]=x.useState(!0),m=x.useCallback(async()=>{try{const[E,C]=await Promise.all([fetch("/api/scheduler/autoplugs/goals"),fetch("/api/scheduler/autoplugs/tracking")]);if(E.ok){const T=await E.json();n(T.goals||[])}if(C.ok){const T=await C.json();s(T.tracking||[])}}catch{}h(!1)},[]);x.useEffect(()=>{m()},[m]);const g=async E=>{(await fetch(`/api/scheduler/autoplugs/goals/${E.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!E.enabled})})).ok&&n(T=>T.map(j=>j.id===E.id?{...j,enabled:!j.enabled}:j))},v=async E=>{(await fetch(`/api/scheduler/autoplugs/goals/${E}`,{method:"DELETE"})).ok&&(n(T=>T.filter(j=>j.id!==E)),o(null))},b=async E=>{(await fetch(`/api/scheduler/autoplugs/tracking/${E}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({skipped:!0})})).ok&&s(T=>T.map(j=>j.id===E?{...j,skipped:!0}:j))},k=e.reduce((E,C)=>C.rule&&C.enabled?Math.min(E,C.rule.threshold):E,1/0),w=k===1/0?50:k;return c.jsxs("div",{className:"sidebar-schedule",children:[c.jsxs("div",{className:"sidebar-schedule-header",children:[c.jsx("button",{className:"sidebar-schedule-back",onClick:t,title:"Back",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Autoplugs"}),c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>d(!l),children:l?"Cancel":"+ Add"})]}),l&&c.jsx(O8,{onCreated:E=>{n(C=>[...C,E]),d(!1)}}),f?null:c.jsxs(c.Fragment,{children:[e.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No goals"}),c.jsx("div",{className:"schedule-empty-desc",children:"Create a goal to start autoplugging your tweets."})]}):e.map(E=>c.jsxs("div",{children:[c.jsxs("div",{className:"schedule-item",onClick:()=>o(i===E.id?null:E.id),children:[c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:E.name}),c.jsx("div",{className:"schedule-item-meta",children:R8(E).map((C,T)=>c.jsx("span",{children:C},T))})]}),c.jsx("button",{className:`autoplug-toggle ${E.enabled?"autoplug-toggle--on":"autoplug-toggle--off"}`,onClick:C=>{C.stopPropagation(),g(E)},title:E.enabled?"Disable":"Enable"})]}),i===E.id&&c.jsx(I8,{goal:E,onSaved:C=>{n(T=>T.map(j=>j.id===C.id?C:j))},onDeleted:()=>v(E.id),onRefresh:m})]},E.id)),c.jsx("div",{className:"schedule-day-header",children:"Tracking"}),r.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No tracked tweets"}),c.jsx("div",{className:"schedule-empty-desc",children:"Tweets will appear here after posting."})]}):r.map(E=>c.jsxs("div",{className:"schedule-item",children:[c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:E.original_text||`Tweet ${E.tweet_id}`}),c.jsxs("div",{className:"schedule-item-meta",children:[c.jsx("span",{children:L8(E.posted_at)}),c.jsxs("span",{children:[E.likes," likes"]}),c.jsxs("span",{children:[E.retweets," RTs"]}),E.views>0&&c.jsxs("span",{children:[D8(E.views)," views"]})]}),E.triggered?c.jsxs("div",{className:"autoplug-tracking-triggered",children:[c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Autoplugged ",E.goal_name?`→ ${E.goal_name}`:""]}):E.skipped?c.jsx("div",{className:"autoplug-tracking-skipped",children:"Skipped"}):c.jsx("div",{className:"autoplug-tracking-bar",children:c.jsx("div",{className:"autoplug-tracking-bar-fill",style:{width:`${Math.min(100,E.likes/w*100)}%`}})})]}),!E.triggered&&!E.skipped&&c.jsx("button",{className:"autoplug-tracking-skip",onClick:()=>b(E.id),title:"Skip autoplug for this tweet",children:"×"})]},E.id))]})]})}function R8(t){const e=[];return t.rule&&(e.push(`${t.rule.threshold}+ ${t.rule.metric}`),e.push(t.rule.mode.charAt(0).toUpperCase()+t.rule.mode.slice(1)),t.rule.delay_minutes>0&&e.push(`${t.rule.delay_minutes}m delay`)),e.push(`${t.pool_count} msg${t.pool_count!==1?"s":""}`),e}function O8({onCreated:t}){const[e,n]=x.useState(""),[r,s]=x.useState(""),[i,o]=x.useState(""),[l,d]=x.useState("likes"),[f,h]=x.useState(50),[m,g]=x.useState(30),[v,b]=x.useState("static"),[k,w]=x.useState(!1),E=async()=>{if(e.trim()){w(!0);try{const C=await fetch("/api/scheduler/autoplugs/goals",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.trim(),link:r.trim()||null,description:i.trim()||null})});if(!C.ok){w(!1);return}const{goal:T}=await C.json();await fetch("/api/scheduler/autoplugs/rules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({goal_id:T.id,metric:l,threshold:f,delay_minutes:m,mode:v})});const j=await fetch("/api/scheduler/autoplugs/goals");if(j.ok){const A=((await j.json()).goals||[]).find(O=>O.id===T.id);if(A){t(A);return}}t({...T,rule_count:1,pool_count:0,rule:{metric:l,threshold:f,delay_minutes:m,mode:v,id:""}})}finally{w(!1)}}};return c.jsxs("div",{className:"autoplug-editor",children:[c.jsxs("label",{children:["Name",c.jsx("input",{value:e,onChange:C=>n(C.target.value),placeholder:"Newsletter, Course..."})]}),c.jsxs("label",{children:["Link",c.jsx("input",{value:r,onChange:C=>s(C.target.value),placeholder:"https://..."})]}),c.jsxs("label",{children:["Description (context for LLM)",c.jsx("textarea",{value:i,onChange:C=>o(C.target.value),placeholder:"Weekly engineering insights...",rows:2})]}),c.jsxs("div",{className:"autoplug-editor-row",children:[c.jsx("input",{type:"number",value:f,onChange:C=>h(Number(C.target.value)),min:1}),c.jsxs("select",{value:l,onChange:C=>d(C.target.value),children:[c.jsx("option",{value:"likes",children:"likes"}),c.jsx("option",{value:"retweets",children:"retweets"}),c.jsx("option",{value:"views",children:"views"})]}),c.jsx("span",{className:"autoplug-editor-row-label",children:"wait"}),c.jsx("input",{type:"number",value:m,onChange:C=>g(Number(C.target.value)),min:0,className:"autoplug-delay-input"}),c.jsx("span",{className:"autoplug-editor-row-label",children:"min"})]}),c.jsx("div",{className:"autoplug-mode-toggle",children:["static","llm","hybrid"].map(C=>c.jsx("button",{className:v===C?"active":"",onClick:()=>b(C),children:C==="llm"?"LLM":C.charAt(0).toUpperCase()+C.slice(1)},C))}),c.jsx("button",{className:"sidebar-schedule-btn sidebar-schedule-btn--active autoplug-create-btn",onClick:E,disabled:k||!e.trim(),children:k?"Creating...":"Create Goal"})]})}function I8({goal:t,onSaved:e,onDeleted:n,onRefresh:r}){var J,z,G,D;const[s,i]=x.useState(t.name),[o,l]=x.useState(t.link||""),[d,f]=x.useState(t.description||""),[h,m]=x.useState(((J=t.rule)==null?void 0:J.metric)||"likes"),[g,v]=x.useState(((z=t.rule)==null?void 0:z.threshold)||50),[b,k]=x.useState(((G=t.rule)==null?void 0:G.delay_minutes)||30),[w,E]=x.useState(((D=t.rule)==null?void 0:D.mode)||"static"),[C,T]=x.useState([]),[j,_]=x.useState(""),[A,O]=x.useState(!1);x.useEffect(()=>{fetch(`/api/scheduler/autoplugs/goals/${t.id}/pool`).then(U=>U.json()).then(U=>T(U.pool||[])).catch(()=>{})},[t.id]);const B=async()=>{var U;O(!0);try{await fetch(`/api/scheduler/autoplugs/goals/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s,link:o||null,description:d||null})}),(U=t.rule)!=null&&U.id?await fetch(`/api/scheduler/autoplugs/rules/${t.rule.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({metric:h,threshold:g,delay_minutes:b,mode:w})}):await fetch("/api/scheduler/autoplugs/rules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({goal_id:t.id,metric:h,threshold:g,delay_minutes:b,mode:w})}),r()}finally{O(!1)}},$=async()=>{if(!j.trim())return;const U=await fetch(`/api/scheduler/autoplugs/goals/${t.id}/pool`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:j.trim()})});if(U.ok){const q=await U.json();T(se=>[...se,q.message]),_("")}},W=async U=>{(await fetch(`/api/scheduler/autoplugs/pool/${U}`,{method:"DELETE"})).ok&&T(se=>se.filter(V=>V.id!==U))};return c.jsxs("div",{className:"autoplug-editor",children:[c.jsxs("label",{children:["Name",c.jsx("input",{value:s,onChange:U=>i(U.target.value)})]}),c.jsxs("label",{children:["Link",c.jsx("input",{value:o,onChange:U=>l(U.target.value),placeholder:"https://..."})]}),c.jsxs("label",{children:["Description",c.jsx("textarea",{value:d,onChange:U=>f(U.target.value),rows:2})]}),c.jsx("div",{className:"autoplug-editor-section-label",children:"Trigger"}),c.jsxs("div",{className:"autoplug-editor-row",children:[c.jsx("input",{type:"number",value:g,onChange:U=>v(Number(U.target.value)),min:1}),c.jsxs("select",{value:h,onChange:U=>m(U.target.value),children:[c.jsx("option",{value:"likes",children:"likes"}),c.jsx("option",{value:"retweets",children:"retweets"}),c.jsx("option",{value:"views",children:"views"})]}),c.jsx("span",{className:"autoplug-editor-row-label",children:"wait"}),c.jsx("input",{type:"number",value:b,onChange:U=>k(Number(U.target.value)),min:0,className:"autoplug-delay-input"}),c.jsx("span",{className:"autoplug-editor-row-label",children:"min"})]}),c.jsx("div",{className:"autoplug-mode-toggle",children:["static","llm","hybrid"].map(U=>c.jsx("button",{className:w===U?"active":"",onClick:()=>E(U),children:U==="llm"?"LLM":U.charAt(0).toUpperCase()+U.slice(1)},U))}),c.jsxs("div",{className:"autoplug-pool-section",children:[c.jsx("div",{className:"autoplug-editor-section-label",children:"Static Pool"}),C.map(U=>c.jsxs("div",{className:"autoplug-pool-item",children:[c.jsx("span",{children:U.content}),c.jsx("button",{onClick:()=>W(U.id),title:"Remove",children:"×"})]},U.id)),c.jsxs("div",{className:"autoplug-pool-add",children:[c.jsx("input",{value:j,onChange:U=>_(U.target.value),placeholder:"Add message... (use {{link}} for link)",onKeyDown:U=>U.key==="Enter"&&$()}),c.jsx("button",{onClick:$,children:"+"})]})]}),(w==="llm"||w==="hybrid")&&c.jsx("div",{className:"autoplug-llm-hint",children:"LLM mode uses Author's Voice to generate contextual replies referencing the original tweet."}),c.jsxs("div",{className:"autoplug-editor-actions",children:[c.jsx("button",{className:"schedule-item-action",onClick:B,disabled:A,children:A?"Saving...":"Save"}),c.jsx("button",{className:"schedule-item-action schedule-item-action--danger",onClick:n,children:"Delete"})]})]})}function L8(t){const e=Date.now()-new Date(t).getTime(),n=Math.floor(e/6e4);if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function D8(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function P8({onBack:t}){const[e,n]=x.useState([]),[r,s]=x.useState([]),[i,o]=x.useState(!1),[l,d]=x.useState(!1),[f,h]=x.useState(null),[m,g]=x.useState(!0),v=x.useCallback(async()=>{try{const[w,E]=await Promise.all([fetch("/api/scheduler/queue"),fetch("/api/scheduler/slots"),fetch("/api/scheduler/sync",{method:"POST"})]);if(w.ok){const C=await w.json();n(C.items||[])}if(E.ok){const C=await E.json();s(C.slots||[])}}catch{}g(!1)},[]);x.useEffect(()=>{v()},[v]);const b=async w=>{(await fetch(`/api/scheduler/queue/${w}`,{method:"DELETE"})).ok&&(n(C=>C.filter(T=>T.id!==w)),h(null))};if(l)return c.jsx(A8,{onBack:()=>{d(!1),v()}});if(i)return c.jsx(j8,{slots:r,onBack:()=>{o(!1),v()}});const k=B8(r,e);return c.jsxs("div",{className:"sidebar-schedule",children:[c.jsxs("div",{className:"sidebar-schedule-header",children:[c.jsx("button",{className:"sidebar-schedule-back",onClick:t,title:"Back to documents",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Schedule"}),c.jsxs("div",{className:"sidebar-schedule-actions",children:[c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>d(!0),title:"Autoplugs",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}),c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>o(!0),title:"Manage slots",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),c.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]}),m?null:r.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No time slots"}),c.jsx("div",{className:"schedule-empty-desc",children:"Create time slots to define your posting schedule."})]}):k.map(({label:w,entries:E})=>c.jsxs("div",{className:"schedule-day",children:[c.jsx("div",{className:"schedule-day-header",children:w}),E.map((C,T)=>{var j,_,A,O,B;return C.type==="empty"?c.jsxs("div",{className:"schedule-slot-empty",children:[c.jsx("div",{className:"schedule-item-time",children:Ck(C.time)}),c.jsx("div",{className:"schedule-slot-empty-label",children:((j=C.slot)==null?void 0:j.filter_type)==="any"?"Open slot":`${(_=C.slot)==null?void 0:_.filter_type}: ${((A=C.slot)==null?void 0:A.filter_value)||"any"}`})]},`empty-${T}`):c.jsxs("div",{children:[c.jsxs("div",{className:"schedule-item",onClick:()=>h(f===C.item.id?null:C.item.id),children:[c.jsx("div",{className:"schedule-item-time",children:Ck(C.time)}),c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:((O=C.item.content)==null?void 0:O.text)||JSON.stringify(C.item.content)}),c.jsxs("div",{className:"schedule-item-meta",children:[c.jsx("span",{className:`schedule-item-status schedule-item-status--${C.item.status}`}),c.jsx("span",{children:C.item.status}),C.item.connection_name&&c.jsx("span",{children:C.item.connection_name}),C.item.provider&&c.jsx("span",{children:C.item.provider})]})]})]}),f===C.item.id&&c.jsxs("div",{className:"schedule-item-expanded",children:[c.jsx("div",{className:"schedule-item-full-text",children:((B=C.item.content)==null?void 0:B.text)||JSON.stringify(C.item.content,null,2)}),c.jsx("div",{className:"schedule-item-actions",children:c.jsx("button",{className:"schedule-item-action schedule-item-action--danger",onClick:()=>b(C.item.id),children:"Cancel"})})]})]},C.item.id)})]},w))]})}function B8(t,e){const n=new Date,r=[];for(let l=0;l<7;l++){const d=new Date(n);d.setDate(d.getDate()+l),d.setHours(0,0,0,0);let f;l===0?f="Today":l===1?f="Tomorrow":f=d.toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"}),r.push({label:f,date:d})}const s=new Map;for(const l of e){const d=new Date(l.scheduled_at),f=`${d.getFullYear()}-${d.getMonth()}-${d.getDate()}-${d.getHours()}-${d.getMinutes()}`;s.set(f,l)}const i=new Set,o=[];for(const{label:l,date:d}of r){const f=[],h=d.getDay(),g=["sun","mon","tue","wed","thu","fri","sat"][h];for(const v of t){if(!(v.days.includes("default")||v.days.includes(g)))continue;const[k,w]=v.time.split(":").map(Number),E=new Date(d);if(E.setHours(k,w,0,0),Nk(d,n)&&E<n)continue;const C=`${E.getFullYear()}-${E.getMonth()}-${E.getDate()}-${k}-${w}`,T=s.get(C);T?(f.push({type:"filled",time:E,item:T,slot:v}),i.add(T.id)):f.push({type:"empty",time:E,slot:v})}for(const v of e){if(i.has(v.id))continue;const b=new Date(v.scheduled_at);Nk(b,d)&&(f.push({type:"filled",time:b,item:v}),i.add(v.id))}f.sort((v,b)=>v.time.getTime()-b.time.getTime()),f.length>0&&o.push({label:l,entries:f})}return o}function Nk(t,e){return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()}function Ck(t){return t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})}function $8({onBack:t}){const[e,n]=x.useState([]),[r,s]=x.useState(""),[i,o]=x.useState(null),[l,d]=x.useState(!1),f=x.useRef(null),h=x.useCallback(async()=>{try{const w=await fetch("/api/tasks");if(w.ok){const E=await w.json();n(E.tasks||[])}}catch{}},[]);x.useEffect(()=>{h()},[h]);const m=async()=>{const w=r.trim();if(w){s("");try{const E=await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:w})});if(E.ok){const C=await E.json();n(T=>[...T,C.task])}}catch{}}},g=w=>{o(w),fetch(`/api/tasks/${w}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({completed:!0})}).catch(()=>{}),setTimeout(()=>{n(E=>E.filter(C=>C.id!==w)),o(null)},400)},v=async w=>{try{(await fetch(`/api/tasks/${w}`,{method:"DELETE"})).ok&&n(C=>C.filter(T=>T.id!==w))}catch{}},b=()=>{d(!0),setTimeout(()=>{var w;return(w=f.current)==null?void 0:w.focus()},0)},k=e.filter(w=>!w.completed);return c.jsxs("div",{className:"sidebar-tasks",children:[c.jsxs("div",{className:"sidebar-tasks-header",children:[c.jsx("button",{className:"sidebar-tasks-back",onClick:t,title:"Back to documents",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Tasks"}),c.jsx("button",{className:"sidebar-tasks-add-btn",onClick:b,title:"Add task",children:"+"})]}),k.length===0&&!l?c.jsxs("div",{className:"sidebar-tasks-empty",children:[c.jsx("div",{className:"sidebar-tasks-empty-title",children:"No tasks"}),c.jsx("div",{className:"sidebar-tasks-empty-desc",children:"Add tasks to track your checklist."})]}):c.jsx("div",{className:"sidebar-tasks-list",children:k.map(w=>c.jsxs("div",{className:`sidebar-tasks-item${i===w.id?" completing":""}`,children:[c.jsx("input",{type:"checkbox",className:"sidebar-tasks-checkbox",checked:i===w.id,onChange:()=>g(w.id)}),c.jsx("span",{className:`sidebar-tasks-text${i===w.id?" completed":""}`,children:w.text}),c.jsx("button",{className:"sidebar-tasks-delete",onClick:()=>v(w.id),title:"Remove",children:"×"})]},w.id))}),l&&c.jsx("div",{className:"sidebar-tasks-add",children:c.jsx("input",{ref:f,type:"text",placeholder:"New task...",value:r,onChange:w=>s(w.target.value),onKeyDown:w=>{w.key==="Enter"&&m(),w.key==="Escape"&&(d(!1),s(""))},onBlur:()=>{r.trim()||d(!1)}})})]})}function z8({profiles:t,activeProfile:e,trashedProfiles:n,onSwitch:r,onCreate:s,onDelete:i,onRestore:o}){const[l,d]=x.useState(!1),[f,h]=x.useState(!1),[m,g]=x.useState(""),[v,b]=x.useState(null),k=x.useRef(null),w=x.useRef(null);x.useEffect(()=>{if(!l)return;const C=T=>{k.current&&!k.current.contains(T.target)&&(d(!1),h(!1),g(""),b(null))};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[l]),x.useEffect(()=>{f&&w.current&&w.current.focus()},[f]);const E=()=>{const C=m.trim();C&&(s(C),g(""),h(!1))};return c.jsxs("div",{className:"sidebar-profile-wrapper",ref:k,children:[c.jsx("button",{className:"sidebar-collapse-btn",onClick:()=>d(!l),title:`Profile: ${e}`,children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"8",r:"4"}),c.jsx("path",{d:"M5.5 21a8.38 8.38 0 0 1 13 0"})]})}),l&&c.jsxs("div",{className:"sidebar-profile-dropdown",children:[t.map(C=>c.jsxs("div",{className:"sidebar-profile-row",children:[v===C?c.jsxs("div",{className:"sidebar-profile-confirm",children:[c.jsx("span",{children:"Delete?"}),c.jsxs("div",{className:"sidebar-inline-confirm",children:[c.jsx("button",{onClick:()=>{i(C),b(null)},children:"Yes"}),c.jsx("button",{onClick:()=>b(null),children:"No"})]})]}):c.jsx(c.Fragment,{children:c.jsxs("button",{className:`sidebar-profile-option ${C===e?"active":""}`,onClick:()=>{C!==e&&r(C),d(!1)},children:[c.jsx("span",{className:"sidebar-profile-check",children:C===e?"✓":""}),c.jsx("span",{children:C})]})}),C!=="Default"&&C!==e&&v!==C&&c.jsx("button",{className:"sidebar-profile-delete-btn",onClick:T=>{T.stopPropagation(),b(C)},title:"Delete profile",children:"×"})]},C)),n.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"sidebar-profile-divider"}),c.jsx("div",{className:"sidebar-profile-trash-label",children:"Trash"}),n.map(C=>c.jsxs("div",{className:"sidebar-profile-row sidebar-profile-trashed",children:[c.jsx("span",{className:"sidebar-profile-trash-name",children:C}),c.jsx("button",{className:"sidebar-profile-restore-btn",onClick:()=>o(C),children:"Restore"})]},C))]}),c.jsx("div",{className:"sidebar-profile-divider"}),f?c.jsx("div",{className:"sidebar-profile-add-input",children:c.jsx("input",{ref:w,type:"text",value:m,onChange:C=>g(C.target.value),onKeyDown:C=>{C.key==="Enter"&&E(),C.key==="Escape"&&(h(!1),g(""))},placeholder:"Profile name..."})}):c.jsxs("button",{className:"sidebar-profile-option sidebar-profile-add",onClick:()=>h(!0),children:[c.jsx("span",{className:"sidebar-profile-check",children:"+"}),c.jsx("span",{children:"New Profile"})]})]})]})}const _k=200,Tk=600,Ip=260;function jk({open:t,onSwitchDocument:e,onCreateDocument:n,refreshKey:r,docTagsRefreshKey:s,workspacesRefreshKey:i,pendingDocs:o,writingTitle:l,writingTarget:d,pendingWriteFilenames:f,onClose:h}){const{docs:m,setDocs:g,workspaces:v,setWorkspaces:b,assignedFiles:k,fetchDocs:w,fetchWorkspaces:E,scrollRef:C,markPendingDelete:T}=t8(r,i),j=n8(w,E,g,b,m,T),_=Rd(),[A,O]=x.useState(()=>{try{const nt=localStorage.getItem("ow-sidebar-width");if(nt){const ht=parseInt(nt,10);if(!isNaN(ht)&&ht>=_k&&ht<=Tk)return ht}}catch{}return Ip}),B=x.useRef(!1),$=x.useCallback(nt=>{nt.preventDefault(),B.current=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none";const ht=ve=>{if(!B.current)return;const X=Math.min(Tk,Math.max(_k,ve.clientX));O(X)},Fe=()=>{B.current=!1,document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("pointermove",ht),window.removeEventListener("pointerup",Fe);try{localStorage.setItem("ow-sidebar-width",String(W.current))}catch{}};window.addEventListener("pointermove",ht),window.addEventListener("pointerup",Fe)},[]),W=x.useRef(A);W.current=A;const J=x.useCallback(nt=>{g(ht=>ht.map(Fe=>({...Fe,isActive:Fe.filename===nt}))),e(nt)},[g,e]),[z,G]=x.useState(!1),[D,U]=x.useState(!1),[q,se]=x.useState([]),[V,te]=x.useState("Default"),K=x.useCallback(async()=>{try{const nt=await fetch("/api/profiles");if(nt.ok){const ht=await nt.json();se(ht.profiles),te(ht.active)}}catch{}},[]);x.useEffect(()=>{K()},[K]);const M=x.useCallback(async nt=>{try{(await fetch("/api/profiles/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:nt})})).ok&&(te(nt),K())}catch{}},[K]),L=x.useCallback(async nt=>{try{(await fetch("/api/profiles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:nt})})).ok&&K()}catch{}},[K]),[ee,fe]=x.useState([]),ge=x.useCallback(async()=>{try{const nt=await fetch("/api/profiles/trash");if(nt.ok){const ht=await nt.json();fe(ht.profiles)}}catch{}},[]);x.useEffect(()=>{ge()},[ge]);const oe=x.useCallback(async nt=>{try{(await fetch(`/api/profiles/${encodeURIComponent(nt)}`,{method:"DELETE"})).ok&&(K(),ge())}catch{}},[K,ge]),we=x.useCallback(async nt=>{try{(await fetch("/api/profiles/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:nt})})).ok&&(K(),ge())}catch{}},[K,ge]),[xe,We]=x.useState(""),[He,Ze]=x.useState(null),Oe=x.useRef(),Ke=x.useRef(null),pt=x.useCallback(nt=>{if(We(nt),Oe.current&&clearTimeout(Oe.current),!nt.trim()){Ze(null);return}Oe.current=setTimeout(async()=>{try{const ht=await fetch(`/api/documents/search?q=${encodeURIComponent(nt.trim())}&archived=true`);ht.ok&&Ze(await ht.json())}catch{}},250)},[]);x.useEffect(()=>()=>{Oe.current&&clearTimeout(Oe.current)},[]);const Je={docs:m,archivedDocs:[],workspaces:v,assignedFiles:k,pendingDocs:o,writingTitle:l,writingTarget:d,pendingWriteFilenames:f,onSwitchDocument:J,onCreateDocument:n,actions:j,scrollRef:C,searchQuery:xe,searchResults:He,onSearchChange:pt},pe=()=>{switch(_){case"files":return c.jsx(N8,{...Je});case"timeline":return c.jsx(d8,{...Je});case"board":return c.jsx(f8,{...Je});case"shelf":return c.jsx(h8,{...Je});default:return c.jsx(u8,{...Je})}},mt=c.jsxs("div",{className:"sidebar-search",children:[c.jsxs("svg",{className:"sidebar-search-icon",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"10.5",cy:"10.5",r:"7"}),c.jsx("path",{d:"m20 20-4.5-4.5"})]}),c.jsx("input",{ref:Ke,className:"sidebar-search-input",type:"text",placeholder:"Search...",value:xe,onChange:nt=>pt(nt.target.value)}),xe&&c.jsx("button",{className:"sidebar-search-clear",onClick:()=>pt(""),title:"Clear search",children:"×"})]}),ft=t?{width:`${A}px`,minWidth:`${A}px`}:void 0,at=t?c.jsx("div",{className:"sidebar-resize-handle",onPointerDown:$,onDoubleClick:()=>{O(Ip);try{localStorage.setItem("ow-sidebar-width",String(Ip))}catch{}},title:"Drag to resize · double-click to reset"}):null;return _==="board"?c.jsxs("div",{className:`sidebar sidebar-board-mode ${t?"open":""}`,style:ft,children:[pe(),at]}):c.jsxs("div",{className:`sidebar ${t?"open":""}`,style:ft,children:[c.jsxs("div",{className:"sidebar-topbar",children:[c.jsxs("div",{className:"sidebar-logo",children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M17 3a2.83 2.83 0 0 1 4 4L7.5 20.5 2 22l1.5-5.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M15 5l4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),c.jsx("span",{className:"sidebar-logo-text",children:"OpenWriter"})]}),c.jsxs("div",{className:"sidebar-topbar-actions",children:[c.jsx(z8,{profiles:q,activeProfile:V,trashedProfiles:ee,onSwitch:M,onCreate:L,onDelete:oe,onRestore:we}),c.jsx("button",{className:`sidebar-collapse-btn${z?" sidebar-collapse-btn--active":""}`,onClick:()=>{G(!z),U(!1)},title:"Schedule",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),c.jsx("line",{x1:"16",x2:"16",y1:"1",y2:"5"}),c.jsx("line",{x1:"8",x2:"8",y1:"1",y2:"5"}),c.jsx("line",{x1:"3",x2:"21",y1:"9",y2:"9"})]})}),c.jsx("button",{className:`sidebar-collapse-btn${D?" sidebar-collapse-btn--active":""}`,onClick:()=>{U(!D),G(!1)},title:"Tasks",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),c.jsx("path",{d:"m9 12 2 2 4-4"})]})}),h&&c.jsx("button",{className:"sidebar-collapse-btn",onClick:h,title:"Close sidebar",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M9 3v18",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M15 10l-2 2 2 2",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})})]})]}),D?c.jsx($8,{onBack:()=>U(!1)}):z?c.jsx(P8,{onBack:()=>G(!1)}):c.jsxs(c.Fragment,{children:[mt,pe()]}),at]})}function oy(t,e,n){let r=t.resolve(e);for(;r.depth>0;){const s=r.node(r.depth),i=r.before(r.depth),o=i+s.nodeSize;if(s.childCount===1)e=i,n=o,r=t.resolve(e);else break}return{from:e,to:n}}function F8(t,e){const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;return t.chain().command(({tr:i})=>(i.setNodeMarkup(s,void 0,{...r.attrs,pendingStatus:null}),!0)).run(),!0}function U8(t,e){const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;return t.chain().command(({tr:i})=>(i.setNodeMarkup(s,void 0,{...r.attrs,pendingStatus:null,pendingOriginalContent:null,pendingSelectionFrom:null,pendingSelectionTo:null,pendingOriginalFrom:null,pendingOriginalTo:null}),!0)).run(),!0}function H8(t,e){var o;const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;if(((o=r.attrs)==null?void 0:o.pendingStatus)!=="delete")return!0;const i=oy(t.state.doc,s,s+r.nodeSize);return t.chain().deleteRange(i).run(),!0}function W8(t,e){var o;const n=Ln(t,e);if(!n)return!0;const{node:r,pos:s}=n;if(((o=r.attrs)==null?void 0:o.pendingStatus)!=="insert")return!0;const i=oy(t.state.doc,s,s+r.nodeSize);return t.chain().deleteRange(i).run(),!0}function q8(t,e){var o,l;const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;if(((o=r.attrs)==null?void 0:o.pendingStatus)!=="rewrite")return!0;const i=(l=r.attrs)==null?void 0:l.pendingOriginalContent;if(i)t.chain().deleteRange({from:s,to:s+r.nodeSize}).insertContentAt(s,i).run();else{const d=oy(t.state.doc,s,s+r.nodeSize);t.chain().deleteRange(d).run()}return!0}function V8(t,e){var i;const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;return((i=r.attrs)==null?void 0:i.pendingStatus)!=="delete"||t.chain().command(({tr:o})=>(o.setNodeMarkup(s,void 0,{...r.attrs,pendingStatus:null}),!0)).run(),!0}function K8(t,e){const n=Yd(t,e);if(n.length===0)return!1;for(const r of[...n].reverse()){const s=Ln(t,r.nodeId);s&&t.chain().command(({tr:i})=>(i.setNodeMarkup(s.pos,void 0,{...s.node.attrs,pendingStatus:null,pendingOriginalContent:null,pendingGroupId:null,pendingSelectionFrom:null,pendingSelectionTo:null,pendingOriginalFrom:null,pendingOriginalTo:null}),!0)).run()}return!0}function G8(t,e){var l;const n=Yd(t,e);if(n.length===0)return!1;const r=(l=n[0].node.attrs)==null?void 0:l.pendingOriginalContent,s=n[0].pos,i=n[n.length-1],o=i.pos+i.node.nodeSize;try{return r&&Array.isArray(r)&&r.length>0?t.chain().deleteRange({from:s,to:o}).insertContentAt(s,r).run():t.chain().deleteRange({from:s,to:o}).run(),!0}catch{return!1}}function A2(t,e){var i,o;const n=Ln(t,e);if(!n)return!1;const r=(i=n.node.attrs)==null?void 0:i.pendingGroupId;if(r)return K8(t,r);switch((o=n.node.attrs)==null?void 0:o.pendingStatus){case"insert":return F8(t,e);case"rewrite":return U8(t,e);case"delete":return H8(t,e);default:return!1}}function R2(t,e){var i,o;const n=Ln(t,e);if(!n)return!1;const r=(i=n.node.attrs)==null?void 0:i.pendingGroupId;if(r)return G8(t,r);switch((o=n.node.attrs)==null?void 0:o.pendingStatus){case"insert":return W8(t,e);case"rewrite":return q8(t,e);case"delete":return V8(t,e);default:return!1}}function J8(t){const e=O2(t).reverse();for(const n of e)A2(t,n);t.view&&ry(t.view)}function Y8(t){const e=O2(t).reverse();for(const n of e)R2(t,n);t.view&&ry(t.view)}function ay(t){const e=[],n=new Set;return t.state.doc.descendants((r,s)=>{var o,l,d;const i=(o=r.attrs)==null?void 0:o.pendingStatus;if(i&&((l=r.attrs)!=null&&l.id)){const f=(d=r.attrs)==null?void 0:d.pendingGroupId;if(f){if(n.has(f))return!0;n.add(f)}e.push({nodeId:r.attrs.id,pos:s,pendingStatus:i,groupId:f,editor:t})}return!0}),e}function Lp(t){const e=[];for(const n of t)n&&!n.isDestroyed&&e.push(...ay(n));return e}function O2(t){return ay(t).map(e=>e.nodeId)}function X8(t){let e=0,n=0,r=0;for(const s of t)s.pendingStatus==="insert"?e++:s.pendingStatus==="rewrite"?n++:s.pendingStatus==="delete"&&r++;return{insert:e,rewrite:n,delete:r,total:t.length}}function Xa(t,e){if(t.isDestroyed)return;let n=-1;if(t.state.doc.descendants((i,o)=>{var l;return((l=i.attrs)==null?void 0:l.id)===e?(n=o,!1):!0}),n===-1)return;const r=t.view.nodeDOM(n),s=r instanceof HTMLElement?r:r==null?void 0:r.parentElement;if(s){s.scrollIntoView({behavior:"smooth",block:"center"});return}try{const i=t.view.coordsAtPos(n),o=t.view.dom.closest(".editor-container");if(o){const l=o.getBoundingClientRect(),d=i.top-l.top+o.scrollTop-o.clientHeight/2;o.scrollTo({top:d,behavior:"smooth"})}}catch{}}function Q8(t){const[e,n]=x.useState([]),[r,s]=x.useState(0),i=x.useRef(),o=x.useRef(new Set),l=x.useCallback(()=>{const E=t.filter(A=>A&&!A.isDestroyed);if(E.length===0){n([]),o.current=new Set;return}const C=Lp(E);n(C);const T=o.current,j=new Set(C.map(A=>A.nodeId));let _=-1;if(T.size>0){for(let A=0;A<C.length;A++)if(!T.has(C[A].nodeId)){_=A;break}}o.current=j,_>=0?(s(_),Xa(C[_].editor,C[_].nodeId)):C.length===0?s(0):s(A=>Math.min(A,C.length-1))},[t]);x.useEffect(()=>{const E=t.filter(j=>j&&!j.isDestroyed);if(E.length===0)return;const C=()=>{clearTimeout(i.current),i.current=setTimeout(l,50)};for(const j of E)j.on("transaction",C);l();const T=setTimeout(()=>{const j=Lp(E.filter(_=>!_.isDestroyed));j.length>0&&Xa(j[0].editor,j[0].nodeId)},150);return()=>{for(const j of E)j.isDestroyed||j.off("transaction",C);clearTimeout(i.current),clearTimeout(T)}},[t,l]),x.useEffect(()=>{const E=e[r]??null;return rk((E==null?void 0:E.nodeId)??null,(E==null?void 0:E.groupId)??null),E!=null&&E.editor&&!E.editor.isDestroyed&&E.editor.view&&ry(E.editor.view),()=>{rk(null)}},[r,e]);const d=X8(e),f=e[r]??null,h=x.useCallback(()=>{if(e.length===0)return;const E=(r+1)%e.length;s(E),e[E]&&Xa(e[E].editor,e[E].nodeId)},[e,r]),m=x.useCallback(()=>{if(e.length===0)return;const E=(r-1+e.length)%e.length;s(E),e[E]&&Xa(e[E].editor,e[E].nodeId)},[e,r]),g=x.useCallback(()=>{const E=t.filter(j=>j&&!j.isDestroyed),C=Lp(E);if(C.length===0)return;const T=Math.min(r,C.length-1);Xa(C[T].editor,C[T].nodeId)},[t,r]),v=x.useCallback(()=>{f&&(A2(f.editor,f.nodeId),l(),g())},[f,l,g]),b=x.useCallback(()=>{f&&(R2(f.editor,f.nodeId),l(),g())},[f,l,g]),k=x.useCallback(()=>{const E=t.filter(C=>C&&!C.isDestroyed);for(const C of E)J8(C);l()},[t,l]),w=x.useCallback(()=>{const E=t.filter(C=>C&&!C.isDestroyed);for(const C of E)Y8(C);l()},[t,l]);return{pendingNodes:e,counts:d,currentNode:f,currentIndex:r,hasPending:d.total>0,goToNext:h,goToPrevious:m,acceptCurrent:v,rejectCurrent:b,acceptAll:k,rejectAll:w,refresh:l}}const I2="ow-review-scope";function Z8(){try{return localStorage.getItem(I2)==="workspace"?"workspace":"all"}catch{return"all"}}function e$(t){try{localStorage.setItem(I2,t)}catch{}}function L2(t){if(!t)return[];const e=[];for(const n of t)n.type==="doc"&&n.file&&e.push(n.file),n.type==="container"&&n.items&&e.push(...L2(n.items));return e}function D2(t,e){if(!t)return!1;for(const n of t)if(n.type==="doc"&&n.file===e||n.type==="container"&&n.items&&D2(n.items,e))return!0;return!1}const da={strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"},t$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M10 3L5 8l5 5",stroke:"currentColor",...da})}),n$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M6 3l5 5-5 5",stroke:"currentColor",...da})}),r$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 10l5-5 5 5",stroke:"currentColor",...da})}),s$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 6l5 5 5-5",stroke:"currentColor",...da})}),Mk=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 8.5l3.5 3.5L13 5",stroke:"currentColor",...da})}),Ak=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M4 4l8 8M12 4l-8 8",stroke:"currentColor",...da})});function P2(t,e,n){const r=Ln(t,e);if(!r)return!1;const{pos:s,node:i}=r,o={type:n.type||i.type.name,attrs:{...n.attrs||{},id:i.attrs.id,pendingStatus:i.attrs.pendingStatus,pendingOriginalContent:i.attrs.pendingOriginalContent,pendingSelectionFrom:i.attrs.pendingSelectionFrom,pendingSelectionTo:i.attrs.pendingSelectionTo,pendingOriginalFrom:i.attrs.pendingOriginalFrom,pendingOriginalTo:i.attrs.pendingOriginalTo},content:n.content};try{return t.chain().command(({tr:l})=>(l.setMeta("addToHistory",!1),!0)).deleteRange({from:s,to:s+i.nodeSize}).insertContentAt(s,o).run(),!0}catch{return!1}}function B2(t,e,n){const r=Yd(t,e);if(r.length===0)return!1;const s=r[0].pos,i=r[r.length-1].pos+r[r.length-1].node.nodeSize;try{return t.chain().command(({tr:o})=>(o.setMeta("addToHistory",!1),!0)).deleteRange({from:s,to:i}).insertContentAt(s,n).run(),!0}catch{return!1}}function vu(t,e){if(!ny()||!e)return!1;const n=a5();return o5()&&n&&Array.isArray(n)?B2(t,e,n):n&&P2(t,e,n),rl(!1),!0}function i$(t,e){return t.indexOf(e)}function o$({editors:t,pendingDocs:e,currentFilename:n,docId:r,pendingTitle:s,onSwitchDocument:i,sendMessage:o,getDocument:l,docVersionRef:d}){const{counts:f,currentNode:h,currentIndex:m,hasPending:g,goToNext:v,goToPrevious:b,acceptCurrent:k,rejectCurrent:w,acceptAll:E,rejectAll:C}=Q8(t),[T,j]=x.useState(s?"title":"body");x.useEffect(()=>{s&&T!=="title"&&f.total===0?j("title"):!s&&T==="title"&&j("body")},[s,f.total,T]);const _=!!s,A=f.total+(_?1:0),O=T==="title"?0:(_?1:0)+m,[B,$]=x.useState(!1);x.useEffect(()=>{T!=="title"&&$(!1)},[T]),x.useEffect(()=>{const Fe=!!s&&T==="title",ve={docId:r,titleFocused:Fe,titleShowOriginal:Fe&&B};return window.dispatchEvent(new CustomEvent("ow-pending-review-cursor",{detail:ve})),()=>{window.dispatchEvent(new CustomEvent("ow-pending-review-cursor",{detail:{docId:r,titleFocused:!1,titleShowOriginal:!1}}))}},[r,s,T,B]);const W=x.useCallback(()=>{r&&o({type:"accept-pending-title",docId:r})},[r,o]),J=x.useCallback(()=>{r&&o({type:"reject-pending-title",docId:r})},[r,o]),z=x.useRef(null),G=x.useRef(null),[D,U]=x.useState(()=>Z8()),[q,se]=x.useState([]);x.useEffect(()=>{let Fe=!1;async function ve(){try{const ne=await(await fetch("/api/workspaces")).json();if(!Array.isArray(ne))return;const de=await Promise.all(ne.map(async he=>{try{const Pe=await(await fetch(`/api/workspaces/${encodeURIComponent(he.filename)}`)).json();return{...he,workspace:Pe}}catch{return he}}));Fe||se(de)}catch{}}ve();const X=()=>ve();return window.addEventListener("ow-workspaces-changed",X),()=>{Fe=!0,window.removeEventListener("ow-workspaces-changed",X)}},[]);const V=x.useMemo(()=>{var ve;if(q.length===0||!n)return null;const Fe=q.find(X=>{var Be;return D2((Be=X.workspace)==null?void 0:Be.root,n)});return Fe?new Set(L2((ve=Fe.workspace)==null?void 0:ve.root)):null},[q,n]),te=x.useMemo(()=>D==="all"||!V?e.filenames:e.filenames.filter(Fe=>V.has(Fe)),[D,e.filenames,V]),K=x.useCallback(Fe=>{U(Fe),e$(Fe)},[]),M=te.length,L=i$(te,n),ee=(h==null?void 0:h.pendingStatus)==="rewrite",fe=!!(h!=null&&h.groupId),ge=ee,oe=x.useCallback(()=>{var ve,X;const Fe=h==null?void 0:h.editor;if(!(!Fe||!h||h.pendingStatus!=="rewrite"))if(B)G.current&&vu(G.current,z.current),z.current=null,G.current=null,$(!1);else if(fe&&h.groupId){const Be=Yd(Fe,h.groupId);if(Be.length===0)return;const ne=(ve=Be[0].node.attrs)==null?void 0:ve.pendingOriginalContent;if(!ne||!Array.isArray(ne))return;const de=Be.map(Pe=>Pe.node.toJSON()),he=ne.map((Pe,et)=>({...Pe,attrs:{...Pe.attrs||{},pendingStatus:"rewrite",pendingGroupId:h.groupId,...et===0?{pendingOriginalContent:ne}:{}}}));if(rl(!0,h.nodeId,de,h.groupId),!B2(Fe,h.groupId,he)){rl(!1);return}z.current=h.nodeId,G.current=Fe,$(!0)}else{const Be=Ln(Fe,h.nodeId);if(!Be)return;const{node:ne}=Be,de=(X=ne.attrs)==null?void 0:X.pendingOriginalContent;if(!de)return;const he=ne.toJSON();if(rl(!0,h.nodeId,he),!P2(Fe,h.nodeId,de)){rl(!1);return}z.current=h.nodeId,G.current=Fe,$(!0)}},[h,B,fe]);x.useEffect(()=>{if(!B)return;const Fe=z.current,ve=G.current;Fe&&ve&&(h==null?void 0:h.nodeId)!==Fe&&(vu(ve,Fe),z.current=null,G.current=null,$(!1))},[h==null?void 0:h.nodeId,B]),x.useEffect(()=>{if(t.length!==0)return()=>{ny()&&z.current&&G.current&&(vu(G.current,z.current),z.current=null,G.current=null)}},[t]);const we=x.useCallback(Fe=>{if(!n)return;if(!t.some(X=>!X||X.isDestroyed?!1:ay(X).length>0)){const X=l==null?void 0:l();X&&o({type:"doc-update",document:X,filename:n,version:(d==null?void 0:d.current)??0}),o({type:"pending-resolved",filename:n,action:Fe})}},[t,n,o,l,d]),xe=x.useCallback(()=>{G.current&&B&&z.current&&(vu(G.current,z.current),z.current=null,G.current=null,$(!1))},[B]),We=x.useCallback(()=>{if(T==="title"&&s){W(),f.total>0&&j("body");return}xe(),k(),we("accept")},[T,s,W,f.total,xe,k,we]),He=x.useCallback(()=>{if(T==="title"&&s){J(),f.total>0&&j("body");return}xe(),w(),we("reject")},[T,s,J,f.total,xe,w,we]),Ze=x.useCallback(()=>{xe(),s&&W(),E(),we("accept")},[xe,s,W,E,we]);x.useEffect(()=>{const Fe=()=>Ze();return window.addEventListener("ow-accept-all",Fe),()=>window.removeEventListener("ow-accept-all",Fe)},[Ze]);const Oe=x.useCallback(()=>{xe(),s&&J(),C(),we("reject")},[xe,s,J,C,we]),Ke=x.useCallback(()=>{if(!(A<=1)){if(T==="title"){j("body");return}if(_&&m>=f.total-1){v(),j("title");return}v()}},[A,T,_,m,f.total,v]),pt=x.useCallback(()=>{if(!(A<=1)){if(T==="title"){b(),j("body");return}if(_&&m===0){j("title");return}b()}},[A,T,_,m,b]),Je=x.useCallback(()=>{if(M===0||M===1&&L===0)return;const Fe=L<=0?M-1:L-1;i(te[Fe])},[M,L,te,i]),pe=x.useCallback(()=>{if(M===0||M===1&&L===0)return;const Fe=L>=M-1?0:L+1;i(te[Fe])},[M,L,te,i]);x.useEffect(()=>{if(!g&&!s)return;const Fe=ve=>{if(!(ve.target instanceof HTMLInputElement||ve.target instanceof HTMLTextAreaElement)&&!(ve.target instanceof HTMLElement&&ve.target.closest("[contenteditable]")))switch(ve.key){case"j":case"ArrowDown":!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),Ke());break;case"k":case"ArrowUp":!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),pt());break;case"h":case"ArrowLeft":!ve.metaKey&&!ve.ctrlKey&&!ve.altKey&&(ve.preventDefault(),Je());break;case"l":case"ArrowRight":!ve.metaKey&&!ve.ctrlKey&&!ve.altKey&&(ve.preventDefault(),pe());break;case"a":!ve.metaKey&&!ve.ctrlKey&&!ve.shiftKey&&(ve.preventDefault(),We());break;case"r":!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),He());break;case"A":ve.shiftKey&&!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),Ze());break;case"R":ve.shiftKey&&!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),Oe());break;case"o":!ve.metaKey&&!ve.ctrlKey&&!ve.shiftKey&&(ve.preventDefault(),T==="title"?$(X=>!X):oe());break}};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[g,s,Ke,pt,Je,pe,We,He,Ze,Oe,oe]);const mt=L>=0?`${L+1} / ${M}`:`— / ${M}`,ft=e.filenames.length,at=!V,ht=ft>0?c.jsxs("div",{className:"review-tab__section",children:[c.jsx("div",{className:"review-tab__section-label",children:"Scope"}),c.jsxs("div",{className:"review-tab__toggle",children:[c.jsx("button",{type:"button",className:`review-panel__toggle-btn${D==="all"?" review-panel__toggle-btn--active":""}`,onClick:()=>K("all"),title:"Cycle every pending doc in the profile",children:"All"}),c.jsx("button",{type:"button",className:`review-panel__toggle-btn${D==="workspace"?" review-panel__toggle-btn--active":""}`,onClick:()=>!at&&K("workspace"),disabled:at,title:at?"Current doc is not in a workspace":"Only cycle pending docs in this workspace",children:"Workspace"})]})]}):null;return!g&&!s?c.jsxs("div",{className:"review-tab__empty",children:[c.jsx("div",{className:"review-tab__empty-title",children:"All caught up"}),c.jsx("div",{className:"review-tab__empty-note",children:"No pending agent changes. New writes from agents will land here for review."})]}):c.jsxs("div",{className:"review-tab",children:[ht,M>1&&c.jsxs("div",{className:"review-tab__section",children:[c.jsx("div",{className:"review-tab__section-label",children:"Document"}),c.jsxs("div",{className:"review-tab__row",children:[c.jsx("button",{className:"review-panel__btn",onClick:Je,title:"Previous doc (h)",children:c.jsx(t$,{})}),c.jsx("span",{className:"review-panel__counter",children:mt}),c.jsx("button",{className:"review-panel__btn",onClick:pe,title:"Next doc (l)",children:c.jsx(n$,{})})]})]}),c.jsxs("div",{className:"review-tab__section",children:[c.jsx("div",{className:"review-tab__section-label",children:T==="title"?"Title":"Change"}),c.jsxs("div",{className:"review-tab__row",children:[c.jsx("button",{className:"review-panel__btn",onClick:pt,disabled:A<=1,title:"Previous (k)",children:c.jsx(r$,{})}),c.jsxs("span",{className:"review-panel__counter",children:[O+1," / ",A]}),c.jsx("button",{className:"review-panel__btn",onClick:Ke,disabled:A<=1,title:"Next (j)",children:c.jsx(s$,{})})]})]}),c.jsx("div",{className:"review-tab__section",children:c.jsxs("div",{className:"review-tab__toggle",children:[c.jsx("button",{className:`review-panel__toggle-btn${(ge||T==="title")&&!B?" review-panel__toggle-btn--active":""}`,onClick:()=>{T==="title"?B&&$(!1):ge&&B&&oe()},disabled:!ge&&T!=="title",title:"Show modified (o)",children:"Modified"}),c.jsx("button",{className:`review-panel__toggle-btn${(ge||T==="title")&&B?" review-panel__toggle-btn--active":""}`,onClick:()=>{T==="title"?B||$(!0):ge&&!B&&oe()},disabled:!ge&&T!=="title",title:"Show original (o)",children:"Original"})]})}),c.jsxs("div",{className:"review-tab__section review-tab__section--actions",children:[c.jsxs("div",{className:"review-tab__row",children:[c.jsxs("button",{className:"review-panel__accept review-tab__action-btn",onClick:We,title:"Accept (a)",children:[c.jsx(Mk,{}),c.jsx("span",{children:"Accept"})]}),c.jsxs("button",{className:"review-panel__reject review-tab__action-btn",onClick:He,title:"Reject (r)",children:[c.jsx(Ak,{}),c.jsx("span",{children:"Reject"})]})]}),c.jsxs("div",{className:"review-tab__row",children:[c.jsxs("button",{className:"review-panel__accept-all review-tab__action-btn",onClick:Ze,title:"Accept all (Shift+A)",children:[c.jsx(Mk,{}),c.jsx("span",{children:"Accept All"})]}),c.jsxs("button",{className:"review-panel__reject-all review-tab__action-btn",onClick:Oe,title:"Reject all (Shift+R)",children:[c.jsx(Ak,{}),c.jsx("span",{children:"Reject All"})]})]})]})]})}function a$(t){const e=Date.now()-t,n=Math.floor(e/1e3);if(n<60)return"Just now";const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const s=Math.floor(r/60);if(s<24)return`${s}h ago`;const i=Math.floor(s/24);return i<7?`${i}d ago`:new Date(t).toLocaleDateString()}function l$(t){return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function c$({currentFilename:t}){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(!1),l=x.useCallback(()=>{fetch("/api/versions").then(f=>f.json()).then(f=>{n(Array.isArray(f)?f:[]),s(null)}).catch(()=>n([]))},[]);x.useEffect(()=>{l()},[t,l]);const d=x.useCallback(async f=>{if(r!==null){o(!0);try{(await fetch(`/api/versions/${r}/restore`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:f})})).ok&&l()}catch{}o(!1)}},[r,l]);return c.jsxs("div",{className:"versions-tab",children:[c.jsx("div",{className:"versions-tab__list",children:e.length===0?c.jsx("div",{className:"versions-tab__empty",children:"No versions yet. Versions are created automatically when you save."}):e.map(f=>c.jsxs("div",{className:`versions-tab__item${r===f.timestamp?" versions-tab__item--selected":""}`,onClick:()=>s(f.timestamp===r?null:f.timestamp),children:[c.jsx("span",{className:"versions-tab__item-time",children:a$(f.timestamp)}),c.jsxs("span",{className:"versions-tab__item-meta",children:[f.wordCount.toLocaleString()," words · ",l$(f.size)]})]},f.timestamp))}),e.length>0&&c.jsxs("div",{className:"versions-tab__footer",children:[c.jsx("button",{className:"versions-tab__review-btn",disabled:r===null||i,onClick:()=>d("review"),children:"Review"}),c.jsx("button",{className:"versions-tab__restore-btn",disabled:r===null||i,onClick:()=>d("full"),children:"Restore"})]})]})}function u$({docId:t,currentFilename:e,onSwitchDocument:n}){const[r,s]=x.useState(new Map),[i,o]=x.useState([]),[l,d]=x.useState([]),[f,h]=x.useState(!0),[m,g]=x.useState(!1);x.useEffect(()=>{let w=!1;const E=async()=>{try{const j=await(await fetch("/api/documents")).json();if(w)return;const _=new Map;if(Array.isArray(j))for(const A of j)A!=null&&A.docId&&_.set(A.docId,{docId:A.docId,filename:A.filename,title:A.title||A.filename});s(_)}catch{}finally{w||h(!1)}};E();const C=()=>E();return window.addEventListener("ow-documents-changed",C),()=>{w=!0,window.removeEventListener("ow-documents-changed",C)}},[]),x.useEffect(()=>{if(!t){o([]);return}let w=!1;const E=()=>{g(!0),fetch(`/api/backlinks/${t}`).then(T=>T.ok?T.json():[]).then(T=>{w||o(Array.isArray(T)?T:[])}).catch(()=>{w||o([])}).finally(()=>{w||g(!1)})};E();const C=()=>E();return window.addEventListener("ow-metadata-changed",C),()=>{w=!0,window.removeEventListener("ow-metadata-changed",C)}},[t]),x.useEffect(()=>{let w=!1;const E=()=>{fetch("/api/document").then(T=>T.json()).then(T=>{var _;if(w)return;const j=(_=T==null?void 0:T.metadata)==null?void 0:_.references;d(Array.isArray(j)?j:[])}).catch(()=>{w||d([])})};E();const C=()=>E();return window.addEventListener("ow-metadata-changed",C),()=>{w=!0,window.removeEventListener("ow-metadata-changed",C)}},[e,t]);const v=x.useMemo(()=>i.map(w=>{const E=r.get(w.from_doc);return E?{docId:w.from_doc,title:E.title,filename:E.filename,snippet:w.text}:null}).filter(w=>w!==null),[i,r]),b=x.useMemo(()=>l.map(w=>{const E=r.get(w);return E?{docId:w,title:E.title,filename:E.filename}:null}).filter(w=>w!==null),[l,r]);if(!t)return c.jsxs("div",{className:"backlinks-tab__empty",children:[c.jsx("div",{className:"backlinks-tab__empty-title",children:"No document open"}),c.jsx("div",{className:"backlinks-tab__empty-note",children:"Open a doc to see what links to it and what it links out to."})]});const k=f||m;return c.jsxs("div",{className:"backlinks-tab",children:[c.jsxs("div",{className:"backlinks-tab__group",children:[c.jsxs("div",{className:"backlinks-tab__group-label",children:["Inbound ",c.jsx("span",{className:"backlinks-tab__count",children:v.length})]}),k&&v.length===0?c.jsx("div",{className:"backlinks-tab__empty-note backlinks-tab__inline-note",children:"Loading…"}):v.length===0?c.jsx("div",{className:"backlinks-tab__empty-note backlinks-tab__inline-note",children:"No docs link to this one yet."}):v.map(w=>c.jsxs("button",{type:"button",className:"backlinks-tab__entry",onClick:()=>n(w.filename),children:[c.jsx("div",{className:"backlinks-tab__entry-title",children:w.title}),w.snippet&&c.jsx("div",{className:"backlinks-tab__entry-snippet",children:w.snippet})]},w.docId))]}),c.jsxs("div",{className:"backlinks-tab__group",children:[c.jsxs("div",{className:"backlinks-tab__group-label",children:["Outbound ",c.jsx("span",{className:"backlinks-tab__count",children:b.length})]}),b.length===0?c.jsx("div",{className:"backlinks-tab__empty-note backlinks-tab__inline-note",children:"This doc doesn’t reference others yet."}):b.map(w=>c.jsx("button",{type:"button",className:"backlinks-tab__entry",onClick:()=>n(w.filename),children:c.jsx("div",{className:"backlinks-tab__entry-title",children:w.title})},w.docId))]})]})}const d$=[{key:"md",label:"Markdown",desc:"Plain .md file",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("path",{d:"M14 2v6h6"})]})},{key:"html",label:"HTML",desc:"Styled web page",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"16 18 22 12 16 6"}),c.jsx("polyline",{points:"8 6 2 12 8 18"})]})},{key:"docx",label:"Word",desc:"Microsoft Word .docx",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("path",{d:"M14 2v6h6"}),c.jsx("path",{d:"M16 13H8"}),c.jsx("path",{d:"M16 17H8"}),c.jsx("path",{d:"M10 9H8"})]})},{key:"txt",label:"Plain Text",desc:"Unformatted .txt file",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 6.1H3"}),c.jsx("path",{d:"M21 12.1H3"}),c.jsx("path",{d:"M15.1 18H3"})]})},{key:"pdf",label:"PDF",desc:"Print preview for save as PDF",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"6 9 6 2 18 2 18 9"}),c.jsx("path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),c.jsx("rect",{x:"6",y:"14",width:"12",height:"8"})]})}];function f$(t){const e=n=>{if(n==="pdf"){window.open("/api/export?format=pdf","_blank");return}const r=document.createElement("a");r.href=`/api/export?format=${n}`,r.download="",document.body.appendChild(r),r.click(),document.body.removeChild(r)};return c.jsx("div",{className:"exports-tab",children:c.jsx("div",{className:"exports-tab__list",children:d$.map(n=>c.jsxs("button",{type:"button",className:"exports-tab__item",onClick:()=>e(n.key),children:[c.jsx("span",{className:"exports-tab__item-icon",children:n.icon}),c.jsxs("span",{className:"exports-tab__item-text",children:[c.jsx("span",{className:"exports-tab__item-label",children:n.label}),c.jsx("span",{className:"exports-tab__item-desc",children:n.desc})]})]},n.key))})})}const h$=3e4,p$=500;let pi={entries:[],freshKeys:new Set};const Qg=new Set;function $2(t){return`${t.ts}:${t.kind}:${t.headline}`}function m$(){for(const t of Qg)t(pi)}function Zg(t){pi=t,m$()}function g$(t){return Qg.add(t),()=>{Qg.delete(t)}}function v$(){return pi}function y$(t){const e=t.detail;e!=null&&e.entries&&Zg({entries:e.entries,freshKeys:new Set})}function b$(t){const e=t.detail;if(!(e!=null&&e.event))return;const n=e.event,r=$2(n),s={entries:[n,...pi.entries].slice(0,p$),freshKeys:new Set([...pi.freshKeys,r])};Zg(s),window.setTimeout(()=>{if(pi.freshKeys.has(r)){const i=new Set(pi.freshKeys);i.delete(r),Zg({...pi,freshKeys:i})}},h$)}typeof window<"u"&&(window.addEventListener("ow-activity-seed",y$),window.addEventListener("ow-activity-event",b$));function x$(){const[t,e]=x.useState(v$);return x.useEffect(()=>g$(e),[]),t}function w$(){const[t,e]=x.useState(()=>({byDocId:new Map,filenameSet:new Set}));return x.useEffect(()=>{let n=!1;const r=()=>{fetch("/api/documents").then(s=>s.json()).then(s=>{if(n||!Array.isArray(s))return;const i=new Map,o=new Set;for(const l of s)l.filename&&o.add(l.filename),l.docId&&l.filename&&i.set(l.docId,l.filename);e({byDocId:i,filenameSet:o})}).catch(()=>{})};return r(),window.addEventListener("ow-documents-changed",r),()=>{n=!0,window.removeEventListener("ow-documents-changed",r)}},[]),t}function k$(t,e){return t.docId?e.byDocId.get(t.docId)??null:t.filename&&e.filenameSet.has(t.filename)?t.filename:null}function S$(t,e){const n=Math.max(0,e-t),r=Math.floor(n/1e3);if(r<45)return"just now";const s=Math.floor(r/60);if(s<60)return`${s}m ago`;const i=Math.floor(s/60);if(i<24)return`${i}h ago`;const o=Math.floor(i/24);return o<7?`${o}d ago`:new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function E$({onSwitchDocument:t}){const{entries:e,freshKeys:n}=x$(),r=w$(),[s,i]=x.useState(()=>Date.now());x.useEffect(()=>{const l=setInterval(()=>i(Date.now()),3e4);return()=>clearInterval(l)},[]);const o=x.useMemo(()=>N$(e,s),[e,s]);return e.length===0?c.jsxs("div",{className:"activity-tab__empty",children:[c.jsx("div",{className:"activity-tab__empty-title",children:"No activity yet"}),c.jsx("div",{className:"activity-tab__empty-note",children:"Agent actions — writes, enrichment, backlink propagation — will appear here as they happen."})]}):c.jsx("div",{className:"activity-tab",children:o.map(l=>c.jsxs("div",{className:"activity-tab__group",children:[c.jsx("div",{className:"activity-tab__group-label",children:l.label}),l.entries.map(d=>{const f=$2(d),h=n.has(f),m=d.kind==="doc-deleted"?null:k$(d,r),g=m!==null,v=!g,b=v&&d.kind!=="doc-deleted"?"Doc no longer available":void 0,k=()=>{m&&t(m)};return c.jsxs("div",{className:`activity-tab__entry${h?" activity-tab__entry--fresh":""}${g?" activity-tab__entry--clickable":""}${v?" activity-tab__entry--muted":""}`,role:g?"button":void 0,tabIndex:g?0:void 0,title:b,onClick:k,onKeyDown:w=>{g&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),k())},children:[c.jsx("span",{className:`activity-tab__kind-dot activity-tab__kind-dot--${d.kind}`,"aria-hidden":"true"}),c.jsxs("div",{className:"activity-tab__entry-body",children:[c.jsx("div",{className:"activity-tab__headline",children:d.headline}),d.detail&&c.jsx("div",{className:"activity-tab__detail",children:d.detail})]}),c.jsx("div",{className:"activity-tab__ts",title:new Date(d.ts).toLocaleString(),children:S$(d.ts,s)})]},f)})]},l.label))})}function N$(t,e){if(t.length===0)return[];const n=Rk(e),r=n-1440*60*1e3,s=[];let i=null;for(const o of t){const l=Rk(o.ts);let d;l===n?d="Today":l===r?d="Yesterday":d=new Date(o.ts).toLocaleDateString(void 0,{weekday:"long",month:"short",day:"numeric"}),(!i||i.label!==d)&&(i={label:d,entries:[]},s.push(i)),i.entries.push(o)}return s}function Rk(t){const e=new Date(t);return e.setHours(0,0,0,0),e.getTime()}async function yu(t,e={}){var s,i;const r=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:t,arguments:e})})).json();if((i=(s=r==null?void 0:r.content)==null?void 0:s[0])!=null&&i.text)try{return JSON.parse(r.content[0].text)}catch{return r.content[0].text}return r}function C$(){const[t,e]=x.useState([]),[n,r]=x.useState(!0),[s,i]=x.useState("closed"),[o,l]=x.useState(""),[d,f]=x.useState(!1),[h,m]=x.useState(null),[g,v]=x.useState(null),[b,k]=x.useState(null),w=x.useCallback(async()=>{r(!0);try{const _=await yu("list_blog_sites");e((_==null?void 0:_.sites)||[])}finally{r(!1)}},[]);x.useEffect(()=>{w()},[w]);const E=()=>{i("closed"),l(""),m(null),v(null),k(null)},C=async()=>{if(o.trim()){f(!0),m(null);try{const _=await yu("inspect_blog_repo",{repo_url:o.trim()});if(_.error){m(_.error);return}v({..._,label:_.repo,branch:"main",site_url:_.site_url||"",blog_url_pattern:_.blog_url_pattern||"/blog/{slug}/"}),i("review")}catch(_){m((_==null?void 0:_.message)||"Inspection failed")}finally{f(!1)}}},T=async()=>{if(g){i("saving"),k(null);try{const _=await yu("add_blog_site",{label:g.label,owner:g.owner,repo:g.repo,branch:g.branch||"main",content_dir:g.content_dir,image_dir:g.image_dir,image_public_prefix:g.image_public_prefix,framework:g.framework,frontmatter_defaults:g.frontmatter_defaults||{},frontmatter_field_map:g.frontmatter_field_map||{},frontmatter_schema:g.frontmatter_schema||[],site_url:g.site_url||"",blog_url_pattern:g.blog_url_pattern||"/blog/{slug}/"});if(_!=null&&_.error){k(_.error),i("review");return}E(),await w()}catch(_){k((_==null?void 0:_.message)||"Save failed"),i("review")}}},j=async _=>{if(!window.confirm(`Remove "${_.label}" (${_.owner}/${_.repo})?
205
+ Run: npm update -g openwriter`,children:["v",T.latestVersion]})]}),c.jsxs("div",{className:"titlebar-right",children:[!g&&m&&c.jsx("button",{className:`titlebar-nav-btn${h?" titlebar-nav-btn--active":""}`,onClick:m,title:"Focus mode","aria-label":"Focus mode","aria-pressed":h,children:c.jsx(v2,{})}),!g&&d&&c.jsx("button",{className:`titlebar-nav-btn${f?" titlebar-nav-btn--active":""}`,onClick:d,title:"Toggle format toolbar","aria-label":"Toggle format toolbar","aria-pressed":f,children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 20h16"}),c.jsx("path",{d:"m6 16 6-12 6 12"}),c.jsx("path",{d:"M8 12h8"})]})}),!g&&c.jsx("button",{className:"titlebar-nav-btn",onClick:()=>v(b||"activity"),title:"Show right rail","aria-label":"Show right rail",children:c.jsx(B5,{})})]})]})}function Ln(t,e){let n=null;return t.state.doc.descendants((r,s)=>{var i;return((i=r.attrs)==null?void 0:i.id)===e?(n={node:r,pos:s},!1):!0}),n}function Yd(t,e){const n=[];return t.state.doc.descendants((r,s)=>{var i;return((i=r.attrs)==null?void 0:i.pendingGroupId)===e&&n.push({nodeId:r.attrs.id,pos:s,node:r}),!0}),n}function ta(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID().replace(/-/g,"").slice(0,8):Math.random().toString(16).slice(2,10)}function Td(t){return t?Array.isArray(t)?t.map(Td).join(""):t.text?t.text:t.content&&Array.isArray(t.content)?t.content.map(e=>Td(e)).join(""):"":""}const z5=new Set(["paragraph","heading","codeBlock","horizontalRule","table","image"]);function jd(t,e){for(const n of t)n.type&&z5.has(n.type)?n.attrs={...n.attrs,pendingStatus:e}:n.content&&jd(n.content,e)}function Yg(t,e,n,r){const s=Array.isArray(n)?n:[n],i=(r==null?void 0:r.autoAccept)===!0;if(e.nodeId&&!e.afterNodeId&&!e.beforeNodeId){const m=Ln(t,e.nodeId);if(!m)return{success:!1,error:`Node ${e.nodeId} not found`};const g=s.map((v,b)=>{var k;return{...v,attrs:{...v.attrs,id:((k=v.attrs)==null?void 0:k.id)||(b===0?e.nodeId:ta())}}});i||jd(g,"insert");try{return t.chain().deleteRange({from:m.pos,to:m.pos+m.node.nodeSize}).insertContentAt(m.pos,g).run(),{success:!0,nodeId:e.nodeId}}catch(v){return{success:!1,error:`Failed to replace empty node: ${v}`}}}if(!e.afterNodeId&&!e.beforeNodeId)return{success:!1,error:"Insert requires afterNodeId, beforeNodeId, or nodeId"};const o=e.afterNodeId||e.beforeNodeId,l=!!e.afterNodeId,d=Ln(t,o);if(!d)return{success:!1,error:`Anchor node ${o} not found`};if(!i){const m=Td(n),g=l?d.pos+d.node.nodeSize:0,v=l?d.pos+d.node.nodeSize+5e3:d.pos;let b=null;if(t.state.doc.nodesBetween(g,Math.min(v,t.state.doc.content.size),k=>{var w,E;return((w=k.attrs)==null?void 0:w.pendingStatus)==="insert"&&((E=k.attrs)!=null&&E.id)&&(k.textContent||"")===m?(b=k.attrs.id,!1):!0}),b)return{success:!0,nodeId:b}}const f=s.map(m=>{var g;return{...m,attrs:{...m.attrs,id:((g=m.attrs)==null?void 0:g.id)||ta()}}});i||jd(f,"insert");const h=l?d.pos+d.node.nodeSize:d.pos;try{return t.chain().insertContentAt(h,f).run(),{success:!0,nodeId:f[0].attrs.id}}catch(m){return{success:!1,error:`Failed to insert content: ${m}`}}}function iy(t,e,n,r,s){var w,E,C,T,j,_;const i=Ln(t,e);if(!i)return{success:!1,error:`Node ${e} not found`};const{node:o,pos:l}=i,d=Array.isArray(n)?n:[n],f=(s==null?void 0:s.autoAccept)===!0,m=!((w=o.attrs)!=null&&w.pendingOriginalContent)?o.toJSON():o.attrs.pendingOriginalContent,v=((E=d[0])==null?void 0:E.type)==="listItem"&&((_=(j=(T=(C=d[0])==null?void 0:C.content)==null?void 0:T[0])==null?void 0:j.attrs)==null?void 0:_.pendingStatus)!=null?{...d[0],attrs:{...d[0].attrs,id:e}}:{...d[0],attrs:f?{...d[0].attrs,id:e}:{...d[0].attrs,id:e,pendingStatus:"rewrite",pendingOriginalContent:m,...r?{pendingSelectionFrom:r.selectionFrom,pendingSelectionTo:r.selectionTo,pendingOriginalFrom:r.originalFrom,pendingOriginalTo:r.originalTo}:{}}},b=d.slice(1).map(A=>{var O;return{...A,attrs:{...A.attrs,id:((O=A.attrs)==null?void 0:O.id)||ta()}}});f||jd(b,"insert");const k=[v,...b];try{return t.chain().command(({tr:A})=>{const O=k.map(B=>t.state.schema.nodeFromJSON(B));return A.replaceWith(l,l+o.nodeSize,O),!0}).run(),{success:!0,nodeId:e}}catch(A){return{success:!1,error:`Failed to rewrite: ${A}`}}}function F5(t,e,n){if(e.length===0)return{success:!1,error:"Range rewrite requires original IDs"};if(!n||n.length===0)return{success:!1,error:"Range rewrite requires new content (received empty)"};if(n.map(m=>Td(m)).join("").trim().length===0)return{success:!1,error:"Range rewrite content is empty (no text) — aborting"};const s=Ln(t,e[0]),i=Ln(t,e[e.length-1]);if(!s||!i)return{success:!1,error:"Could not find original nodes for range rewrite"};const o=[];for(const m of e){const g=Ln(t,m);g&&o.push(g.node.toJSON())}const l=s.pos,d=i.pos+i.node.nodeSize,f=ta()+ta(),h=n.map((m,g)=>{var v;return{...m,attrs:{...m.attrs,id:((v=m.attrs)==null?void 0:v.id)||ta(),pendingStatus:"rewrite",pendingGroupId:f,...g===0?{pendingOriginalContent:o}:{}}}});try{return t.chain().deleteRange({from:l,to:d}).insertContentAt(l,h).run(),{success:!0,nodeId:h[0].attrs.id}}catch(m){return{success:!1,error:`Failed to apply range rewrite: ${m}`}}}function y2(t,e,n){var l;const r=Ln(t,e);if(!r)return{success:!1,error:`Node ${e} not found`};const{node:s,pos:i}=r,o=(n==null?void 0:n.autoAccept)===!0;if(!o&&((l=s.attrs)==null?void 0:l.pendingStatus)==="delete")return{success:!0,nodeId:e};try{return o?t.chain().deleteRange({from:i,to:i+s.nodeSize}).run():t.chain().command(({tr:d})=>(d.setNodeMarkup(i,void 0,{...s.attrs,pendingStatus:"delete"}),!0)).run(),{success:!0,nodeId:e}}catch(d){return{success:!1,error:`Failed to ${o?"delete":"mark for deletion"}: ${d}`}}}function U5(t,e){const n=e.autoAccept?{autoAccept:!0}:void 0;if(e.operation==="rewrite"&&e.nodeId&&e.content){const r=iy(t,e.nodeId,e.content,null,n);return{success:r.success,error:r.error}}if(e.operation==="insert"&&e.content){let r=null;if(e.nodeId&&!e.afterNodeId?r={nodeId:e.nodeId}:e.afterNodeId&&(r={afterNodeId:e.afterNodeId}),!r)return{success:!1,error:"Insert requires afterNodeId or nodeId"};const s=Yg(t,r,e.content,n);return{success:s.success,error:s.error}}if(e.operation==="delete"&&e.nodeId){const r=y2(t,e.nodeId,n);return{success:r.success,error:r.error}}return{success:!1,error:`Invalid operation: ${e.operation}`}}function Tp(t,e){if(e.length===0)return;if(e.length===1){U5(t,e[0]);return}const n=t.state.schema;t.chain().command(({tr:r})=>{var s;for(const i of e)try{const o=i.autoAccept===!0;if(i.operation==="rewrite"&&i.nodeId&&i.content){const l=Ya(r.doc,i.nodeId);if(!l){console.warn("[openwriter] rewrite skipped — node id not found in editor",{nodeId:i.nodeId});continue}const f=(Array.isArray(i.content)?i.content:[i.content]).map(h=>n.nodeFromJSON(h));r.replaceWith(l.pos,l.pos+l.node.nodeSize,f)}else if(i.operation==="insert"&&i.content){const d=(Array.isArray(i.content)?i.content:[i.content]).map(f=>n.nodeFromJSON(f));if(!o){const f=d.map(h=>h.textContent||"").join("");if(f&&i.afterNodeId){const h=Ya(r.doc,i.afterNodeId);if(h){const m=h.pos+h.node.nodeSize,g=Math.min(m+5e3,r.doc.content.size);let v=!1;if(r.doc.nodesBetween(m,g,b=>{var k;return v?!1:((k=b.attrs)==null?void 0:k.pendingStatus)==="insert"&&(b.textContent||"")===f?(v=!0,!1):!0}),v)continue}}}if(i.nodeId&&!i.afterNodeId){const f=Ya(r.doc,i.nodeId);if(!f){console.warn("[openwriter] insert (replace) skipped — node id not found in editor",{nodeId:i.nodeId});continue}r.replaceWith(f.pos,f.pos+f.node.nodeSize,d)}else if(i.afterNodeId){const f=Ya(r.doc,i.afterNodeId);if(!f){console.warn("[openwriter] insert (after) skipped — anchor id not found in editor",{afterNodeId:i.afterNodeId});continue}const h=f.pos+f.node.nodeSize;r.insert(h,be.fromArray(d))}}else if(i.operation==="delete"&&i.nodeId){const l=Ya(r.doc,i.nodeId);if(!l){console.warn("[openwriter] delete skipped — node id not found in editor",{nodeId:i.nodeId});continue}if(o)r.delete(l.pos,l.pos+l.node.nodeSize);else{if(((s=l.node.attrs)==null?void 0:s.pendingStatus)==="delete")continue;r.setNodeMarkup(l.pos,void 0,{...l.node.attrs,pendingStatus:"delete"})}}}catch{continue}return!0}).run()}function Ya(t,e){let n=null;return t.descendants((r,s)=>{var i;return((i=r.attrs)==null?void 0:i.id)===e?(n={node:r,pos:s},!1):!0}),n}function H5(t,e){if(!e||e.length===0||t.isDestroyed)return;const n=new Map(e.map(r=>[r.oldId,r.newId]));t.chain().command(({tr:r})=>{const s=[];r.doc.descendants((i,o)=>{var d;const l=(d=i.attrs)==null?void 0:d.id;l&&n.has(l)&&s.push({pos:o,attrs:{...i.attrs,id:n.get(l)}})});for(const{pos:i,attrs:o}of s)r.setNodeMarkup(i,void 0,o);return!0}).run()}function W5(t,e,n,r){const s=[];if(r==="delete"){for(const o of n)s.push(y2(t,o));return s}if(r==="insert"){const o=n[n.length-1];return o&&e.length>0&&s.push(Yg(t,{nodeId:o},e)),s}if(n.length>1){const o=F5(t,n,e);return s.push(o),s}const i=iy(t,n[0],e[0]);if(s.push(i),e.length>1){const o=e.slice(1);s.push(Yg(t,{afterNodeId:n[0]},o))}return s}const hk="[[START_SELECTION]]",pk="[[END_SELECTION]]";function q5(t){if(!(t!=null&&t.content)||!Array.isArray(t.content))return 0;let e=0;for(const n of t.content)n.type==="text"&&typeof n.text=="string"?e+=n.text.length:n.type==="hardBreak"&&(e+=1);return e}function mu(t,e,n){if(!(t!=null&&t.content)||!Array.isArray(t.content))return;const r=q5(t);let s=Math.max(0,Math.min(e,r));for(let i=0;i<t.content.length;i++){const o=t.content[i];if(o.type==="text"&&typeof o.text=="string"){if(s<=o.text.length){const l=Math.max(0,Math.min(o.text.length,s));o.text=o.text.slice(0,l)+n+o.text.slice(l);return}s-=o.text.length;continue}if(o.type==="hardBreak"){if(s===0){t.content.splice(i+1,0,{type:"text",text:n});return}s-=1;continue}if(s===0){t.content.splice(i,0,{type:"text",text:n});return}}t.content.push({type:"text",text:n})}function V5(t,e,n){const r=JSON.parse(JSON.stringify(t));return r.length===0?r:r.length===1?(mu(r[0],n,pk),mu(r[0],e,hk),r):(mu(r[0],e,hk),mu(r[r.length-1],n,pk),r)}function K5(t){const e=r=>r.replace(/\[\[(START|END)_SELECTION]]/g,""),n=r=>{r.type==="text"&&typeof r.text=="string"&&(r.text=e(r.text)),r.content&&Array.isArray(r.content)&&r.content.forEach(n)};Array.isArray(t)?t.forEach(n):n(t)}function mk(t,e){return t.docId&&e.includes(t.docId)?!0:e.includes(t.filename)}const G5=[{action:"comment",label:"Comment",shortcut:"M",condition:"has-selection"},{action:"delete",label:"Delete",shortcut:"D"}];function J5({editorRef:t,allEditors:e,documentId:n}){const[r,s]=x.useState(!1),[i,o]=x.useState({x:0,y:0}),[l,d]=x.useState(!1),[f,h]=x.useState(""),[m,g]=x.useState(!1),[v,b]=x.useState(""),[k,w]=x.useState(!1),[E,C]=x.useState([]),[T,j]=x.useState([]),[_,A]=x.useState(!1),[O,B]=x.useState(""),[$,W]=x.useState([]),[J,z]=x.useState(!1),[G,D]=x.useState(""),[U,q]=x.useState(null),[se,V]=x.useState(null),[te,K]=x.useState(null),[M,L]=x.useState(!1),[ee,fe]=x.useState(null),[ge,oe]=x.useState(null),xe=x.useRef(null),we=x.useRef(null),We=x.useRef(null),He=x.useCallback(ne=>{if(e&&e.length>0){for(const he of e)if(he.view.dom.contains(ne))return he}const de=t.current;return de&&de.view.dom.contains(ne)?de:null},[e,t]);x.useLayoutEffect(()=>{const ne=xe.current;if(!ne||!r)return;const de=ne.getBoundingClientRect(),he=8;let{x:Ge,y:Pe}=i;Pe+de.height+he>window.innerHeight&&(Pe=i.y-de.height),Ge+de.width+he>window.innerWidth&&(Ge=i.x-de.width),Pe<he&&(Pe=he),Ge<he&&(Ge=he),(Ge!==i.x||Pe!==i.y)&&o({x:Ge,y:Pe})},[r,i]);const Ze=x.useCallback(()=>{fetch("/api/plugins").then(ne=>ne.json()).then(ne=>{const de=[];for(const he of ne.plugins||[]){const Ge=he.displayName||void 0;for(const Pe of he.contextMenuItems||[])de.push({...Pe,pluginDisplayName:Ge})}W(de)}).catch(()=>{})},[]);x.useEffect(()=>{Ze()},[Ze]),x.useEffect(()=>{const ne=()=>Ze();return window.addEventListener("ow-plugins-changed",ne),()=>window.removeEventListener("ow-plugins-changed",ne)},[Ze]),x.useEffect(()=>{const ne=de=>{xe.current&&!xe.current.contains(de.target)&&(s(!1),g(!1),w(!1),z(!1),D(""),q(null),V(null),fe(null))};return document.addEventListener("mousedown",ne),()=>document.removeEventListener("mousedown",ne)},[]);const Oe=x.useCallback(()=>{const ne=We.current||t.current;return ne?ne.isActive("link"):!1},[t]),Ke=x.useCallback(()=>{const ne=We.current||t.current,de=we.current;if(!ne||!de)return!1;const{from:he,to:Ge}=de;let Pe=!1;return ne.state.doc.nodesBetween(he,Ge,et=>{var ot;return(ot=et.attrs)!=null&&ot.pendingStatus&&(Pe=!0),!Pe}),Pe},[t]),pt=x.useCallback(()=>{const ne=We.current||t.current,de=we.current,he=(de==null?void 0:de.from)??0,Ge=(de==null?void 0:de.to)??0,Pe=he!==Ge,et=(()=>{if(!ne)return!1;try{return ne.state.doc.resolve(he).parent.content.size===0}catch{return!1}})(),ot=Ke(),bt=[];for(const Ye of $)Ye.condition==="has-selection"&&!Pe||Ye.condition==="empty-node"&&!et||bt.push({action:Ye.action,label:Ye.label,shortcut:Ye.shortcut,isPlugin:!0,promptForInput:Ye.promptForInput,pluginDisplayName:Ye.pluginDisplayName});for(const Ye of G5)Ye.condition==="has-selection"&&(!Pe||ot)||bt.push(Ye);if(Pe&&bt.push({action:"link",label:"Link to doc",shortcut:"L"}),Oe()&&bt.push({action:"unlink",label:"Unlink"}),te&&te.entries.length>0&&bt.unshift({action:"see-connections",label:`See connections (${te.entries.length})`}),ee){const Ye=ee.title?`Go to "${ee.title}"`:"Go to target";bt.unshift({action:"go-to-target",label:Ye})}return bt},[t,Oe,$,Ke,te,ee]);x.useEffect(()=>{const ne=he=>{var Ye;if(he.button!==2)return;const Ge=He(he.target);if(!Ge)return;We.current=Ge;const{from:Pe,to:et}=Ge.state.selection,ot=[],bt=[];if(Pe!==et&&Ge.state.doc.nodesBetween(Pe,et,it=>{it.isBlock&&it.type.name!=="doc"&&(ot.push(it.toJSON()),it.attrs.id&&bt.push(it.attrs.id))}),ot.length===0){const{$from:it}=Ge.state.selection,gt=it.parent;gt&&gt.type.name!=="doc"&&(ot.push(gt.toJSON()),(Ye=gt.attrs)!=null&&Ye.id&&bt.push(gt.attrs.id))}we.current={from:Pe,to:et,nodes:ot,nodeIds:bt}},de=he=>{var gt,Nt,Ie,Me,qe,F;if(!He(he.target)||he.shiftKey)return;const Pe=(Nt=(gt=he.target)==null?void 0:gt.closest)==null?void 0:Nt.call(gt,"[data-comment-id]"),et=(Pe==null?void 0:Pe.getAttribute("data-comment-id"))||null,ot=(Me=(Ie=he.target)==null?void 0:Ie.closest)==null?void 0:Me.call(Ie,".linked-paragraph[data-backlinks-node]"),bt=(ot==null?void 0:ot.getAttribute("data-backlinks-node"))||null,Ye=(F=(qe=he.target)==null?void 0:qe.closest)==null?void 0:F.call(qe,"span.doc-link[data-doc]"),it=(Ye==null?void 0:Ye.getAttribute("data-doc"))||null;if(he.preventDefault(),o({x:he.clientX,y:he.clientY}),s(!0),g(!1),w(!1),L(!1),z(!1),D(""),q(null),et){const ce=we.current;if(!(!!ce&&ce.from!==ce.to)){const P=Ru().find(Z=>Z.id===et);if(P){V({id:P.id,text:P.text,note:P.note}),K(null);return}}}if(V(null),bt){const ce=m5(bt);K(ce.length>0?{nodeId:bt,entries:ce}:null)}else K(null);if(it){const ce=it.indexOf("?"),Ne=ce>=0?it.slice(0,ce):it,[P,Z]=Ne.split("#"),I=P&&/^[a-f0-9]{8}$/.test(P)?P:null,re=Z&&/^[a-f0-9]{8}$/.test(Z)?Z:null;if(I){const ye=E.find(Te=>Te.docId===I);fe({docId:I,nodeId:re,title:(ye==null?void 0:ye.title)||null}),ye||fetch("/api/documents").then(Te=>Te.json()).then(Te=>{if(Array.isArray(Te)){const Se=Te.map(me=>({filename:me.filename,title:me.title,docId:me.docId}));C(Se);const Ee=Se.find(me=>me.docId===I);Ee&&fe(me=>me&&me.docId===I?{...me,title:Ee.title}:me)}}).catch(()=>{})}else fe(null)}else fe(null)};return document.addEventListener("mousedown",ne,!0),document.addEventListener("contextmenu",de),()=>{document.removeEventListener("mousedown",ne,!0),document.removeEventListener("contextmenu",de)}},[He]);const Je=x.useCallback(async(ne,de)=>{var Nt,Ie,Me,qe,F;const he=We.current||t.current;if(!he)return;const Ge=we.current;if(!Ge||Ge.nodes.length===0){console.warn("[ContextMenu] No captured selection for action:",ne);return}let{nodes:Pe,nodeIds:et}=Ge;const{from:ot,to:bt}=Ge;d(!0),s(!1),g(!1);const Ye=`ctx-${Date.now()}`,it=ne.includes(":")?ne.split(":").slice(1).join(":"):ne,gt=["insert","fill","fill-sentence"].includes(it);if(gt)he.commands.showInsertionLoading(Ye,ot);else{const ce=he.state.doc.resolve(ot),Ne=he.state.doc.resolve(bt),P=ce.sameParent(Ne)&&ot!==bt;he.commands.applyLoadingEffect(Ye,ot,bt,P?"selection":"paragraph")}try{const ce=[],Ne=[],P=new Set(et);let Z=!1;const I=he.state.doc;for(let Ft=0;Ft<I.childCount;Ft++){const xt=I.child(Ft),Pn=(Nt=xt.attrs)==null?void 0:Nt.id;if(Pn&&P.has(Pn))Z=!0;else if(Z){const un=xt.textContent.trim();un&&Ne.push(un)}else{const un=xt.textContent.trim();un&&ce.push(un)}}let re=Pe,ye=!1,Te=0,Se=0;const Ee=ot!==bt?he.state.doc.resolve(ot):null,me=ot!==bt?he.state.doc.resolve(bt):null;if((Ee&&me?Ee.sameParent(me):!1)&&Ee&&Pe.length===1){const Ft=Ee.start(Ee.depth);Te=ot-Ft,Se=bt-Ft;const xt=((Me=(Ie=Pe[0])==null?void 0:Ie.content)==null?void 0:Me.reduce((Pn,un)=>{var yr;return Pn+(((yr=un.text)==null?void 0:yr.length)||(un.type==="hardBreak"?1:0))},0))??0;(Te>0||Se<xt)&&(re=V5(Pe,Te,Se),ye=!0)}const Ct=he.state.doc.textContent,en={nodes:re,action:it,nodeIds:et,contextBefore:ce.slice(-3),contextAfter:Ne.slice(0,3),fullDocument:Ct,documentId:n,debug:!0};ye&&(en.hasSelectionMarkers=!0),de&&(en.instruction=de);const on=await fetch(`${window.location.origin}/api/voice/apply-editor`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(en)});if(!on.ok){const Ft=await on.json().catch(()=>({}));console.error("[ContextMenu] API error:",on.status,Ft);return}const Wt=await on.json();if(Wt.success&&Wt.nodes){let Ft=Wt.nodes;if(Ft.length===1&&Array.isArray(Ft[0])&&(Ft=Ft[0]),K5(Ft),ye&&Ft.length===1&&et.length===1){const xt=_r=>(_r==null?void 0:_r.reduce((Wr,is)=>{var ie;return Wr+(((ie=is.text)==null?void 0:ie.length)||(is.type==="hardBreak"?1:0))},0))??0,Pn=xt((qe=Pe[0])==null?void 0:qe.content),un=xt((F=Ft[0])==null?void 0:F.content),yr={selectionFrom:Te,selectionTo:un-(Pn-Se),originalFrom:Te,originalTo:Se};iy(he,et[0],Ft[0],yr)}else W5(he,Ft,et,it);window.dispatchEvent(new CustomEvent("ow-pending-write-applied")),Wt.debug&&fetch("/api/prompt-debug",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:it,debug:Wt.debug,metadata:Wt.metadata})}).catch(()=>{})}else console.warn("[ContextMenu] Unexpected response:",Wt)}catch(ce){console.error("[ContextMenu] Plugin action failed:",ce)}finally{gt?he.commands.removeInsertionLoading(Ye):he.commands.removeLoadingEffect(Ye),d(!1)}},[t]),pe=x.useCallback(async ne=>{const de=We.current||t.current;if(!de)return;const{$from:he}=de.state.selection,Ge=he.before(he.depth),Pe=he.after(he.depth),et=he.parent.content.size===0;d(!0),s(!1),g(!1),et?de.chain().focus().deleteRange({from:Ge,to:Pe}).insertContentAt(Ge,{type:"imageLoading"}).run():de.chain().focus().insertContentAt(Pe,{type:"imageLoading"}).run();let ot=-1;de.state.doc.descendants((bt,Ye)=>{if(bt.type.name==="imageLoading"&&ot===-1)return ot=Ye,bt.nodeSize,!1});try{const bt=await fetch("/api/image-gen/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:ne})}),Ye=await bt.json().catch(()=>({success:!1,error:`Generation failed (${bt.status})`}));if(Ye.success&&Ye.src){let it=-1,gt=0;if(de.state.doc.descendants((Nt,Ie)=>{if(Nt.type.name==="imageLoading"&&it===-1)return it=Ie,gt=Nt.nodeSize,!1}),it>=0){const{tr:Nt}=de.state;Nt.replaceWith(it,it+gt,de.schema.nodes.image.create({src:Ye.src,alt:ne})),de.view.dispatch(Nt)}}else{console.error("[ContextMenu] Image generation failed:",Ye.error);let it=-1,gt=0;if(de.state.doc.descendants((Nt,Ie)=>{if(Nt.type.name==="imageLoading"&&it===-1)return it=Ie,gt=Nt.nodeSize,!1}),it>=0){const{tr:Nt}=de.state;Nt.delete(it,it+gt),de.view.dispatch(Nt)}}}catch(bt){console.error("[ContextMenu] Image generation failed:",bt);let Ye=-1,it=0;if(de.state.doc.descendants((gt,Nt)=>{if(gt.type.name==="imageLoading"&&Ye===-1)return Ye=Nt,it=gt.nodeSize,!1}),Ye>=0){const{tr:gt}=de.state;gt.delete(Ye,Ye+it),de.view.dispatch(gt)}}finally{d(!1)}},[t]),mt=x.useCallback(ne=>{const{action:de,isPlugin:he,promptForInput:Ge}=ne;if(he&&Ge){b(de),g(!0);return}if(he){if(de.startsWith("img:"))return;Je(de);return}if(de==="comment"){z(!0);return}if(de==="delete"){const Pe=We.current||t.current,et=we.current;if(Pe&&et&&et.nodeIds.length>0){const{tr:ot}=Pe.state,bt=new Set(et.nodeIds),Ye=[];Pe.state.doc.descendants((it,gt)=>{var Nt;if((Nt=it.attrs)!=null&&Nt.id&&bt.has(it.attrs.id))return Ye.push({from:gt,to:gt+it.nodeSize}),!1});for(const it of Ye.reverse())ot.delete(it.from,it.to);Ye.length>0&&Pe.view.dispatch(ot)}s(!1);return}if(de==="link"){const Pe=We.current||t.current;if(Pe){const et=[];Pe.state.doc.descendants(ot=>{var bt;(bt=ot.marks)==null||bt.forEach(Ye=>{var it,gt;if(Ye.type.name==="link"&&((gt=(it=Ye.attrs)==null?void 0:it.href)!=null&&gt.startsWith("doc:"))){const Nt=k5(Ye.attrs.href);Nt&&!et.includes(Nt)&&et.push(Nt)}})}),j(et)}fetch("/api/documents").then(et=>et.json()).then(et=>{Array.isArray(et)&&C(et.map(ot=>({filename:ot.filename,title:ot.title,docId:ot.docId}))),A(!1),B(""),w(!0)}).catch(()=>{});return}if(de==="unlink"){const Pe=We.current||t.current;Pe&&Pe.chain().focus().unsetLink().run(),s(!1);return}if(de==="see-connections"){fetch("/api/documents").then(Pe=>Pe.json()).then(Pe=>{Array.isArray(Pe)&&C(Pe.map(et=>({filename:et.filename,title:et.title,docId:et.docId})))}).catch(()=>{}),L(!0);return}if(de==="go-to-target"){ee&&window.dispatchEvent(new CustomEvent("ow-navigate-to-link",{detail:{docId:ee.docId,nodeId:ee.nodeId,filename:null,quote:null}})),s(!1),fe(null);return}},[Je,t,ee]),ft=x.useCallback(()=>{f.trim()&&(v.startsWith("img:")?pe(f.trim()):Je(v,f.trim()),h(""),b(""))},[Je,pe,v,f]),at=x.useCallback(()=>{if(!n)return;if(U){fetch("/api/comments",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:n,id:U.id,note:G.trim()})}).then(()=>{s(!1),z(!1),D(""),q(null)}).catch(ot=>{console.error("[ContextMenu] Comment edit failed:",ot)});return}const ne=We.current||t.current,de=we.current;if(!ne||!de)return;const{from:he,to:Ge,nodeIds:Pe}=de;if(he===Ge||Pe.length===0)return;const et=ne.state.doc.textBetween(he,Ge,`
206
+ `);et.trim()&&fetch("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:n,text:et,note:G.trim(),nodeId:Pe[Pe.length-1],nodeIds:Pe})}).then(()=>{s(!1),z(!1),D("")}).catch(ot=>{console.error("[ContextMenu] Comment create failed:",ot)})},[t,n,G,U]),nt=x.useCallback(()=>{se&&(q({id:se.id,text:se.text}),D(se.note),z(!0),V(null))},[se]),ht=x.useCallback(()=>{se&&fetch("/api/comments/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[se.id]})}).then(()=>{s(!1),V(null)}).catch(ne=>{console.error("[ContextMenu] Comment resolve failed:",ne)})},[se]),Fe=x.useCallback(()=>{se&&fetch("/api/comments",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[se.id]})}).then(()=>{s(!1),V(null)}).catch(ne=>{console.error("[ContextMenu] Comment delete failed:",ne)})},[se]),ve=x.useCallback((ne,de)=>{const he=We.current||t.current;if(he){const Ge=ne.docId?_p({docId:ne.docId,nodeId:de==null?void 0:de.nodeId,quote:de==null?void 0:de.quote}):_p({filename:ne.filename});he.chain().focus().setLink({href:Ge}).run()}fetch("/api/auto-tag-link",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetFile:ne.filename})}).catch(()=>{}),s(!1),w(!1),oe(null)},[t]),X=x.useCallback(ne=>{if(!ne.docId){ve(ne);return}oe({docId:ne.docId,filename:ne.filename,title:ne.title,paragraphs:[],loading:!0}),fetch(`/api/documents/by-doc-id/${ne.docId}/paragraphs`).then(de=>de.json()).then(de=>{oe(he=>he&&he.docId===ne.docId?{...he,paragraphs:Array.isArray(de.paragraphs)?de.paragraphs:[],loading:!1}:he)}).catch(()=>{oe(de=>de&&de.docId===ne.docId?{...de,paragraphs:[],loading:!1}:de)})},[ve]),Be=x.useCallback(()=>{const ne=O.trim();if(!ne)return;const de=We.current||t.current;de&&(fetch("/api/create-link-doc",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:ne})}).then(he=>he.json()).then(he=>{if(he.filename){const Ge=_p(he.docId?{docId:he.docId}:{filename:he.filename});de.chain().focus().setLink({href:Ge}).run()}}).catch(()=>{}),s(!1),w(!1),A(!1),B(""))},[t,O]);return r?c.jsx("div",{ref:xe,className:"context-menu",style:{left:i.x,top:i.y},children:l?c.jsx("div",{className:"context-menu-loading",children:"Applying..."}):J?c.jsxs("div",{className:"context-menu-comment-editor",children:[(()=>{const ne=(U==null?void 0:U.text)??(()=>{const de=We.current||t.current,he=we.current;return!de||!he||he.from===he.to?"":de.state.doc.textBetween(he.from,he.to,`
207
+ `)})();return ne?c.jsx("div",{className:"context-menu-comment-quote",children:ne}):null})(),c.jsx("textarea",{autoFocus:!0,className:"context-menu-comment-textarea",value:G,onChange:ne=>D(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&(ne.metaKey||ne.ctrlKey)&&(ne.preventDefault(),at()),ne.key==="Escape"&&(s(!1),z(!1),D(""),q(null))},placeholder:"Note for agent (optional)...",rows:4}),c.jsxs("div",{className:"context-menu-comment-actions",children:[c.jsx("span",{className:"context-menu-comment-hint",children:"⌘↵ to save · Esc to cancel"}),c.jsx("button",{onClick:at,children:U?"Save":"Comment"})]})]}):se?c.jsxs(c.Fragment,{children:[c.jsx("button",{className:"context-menu-item",onClick:nt,children:c.jsx("span",{children:"Edit comment"})}),c.jsx("button",{className:"context-menu-item",onClick:ht,children:c.jsx("span",{children:"Resolve comment"})}),c.jsx("button",{className:"context-menu-item",onClick:Fe,children:c.jsx("span",{children:"Delete comment"})})]}):m?c.jsxs("div",{className:"context-menu-custom",children:[c.jsx("input",{autoFocus:!0,value:f,onChange:ne=>h(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&ft(),ne.key==="Escape"&&s(!1)},placeholder:"Custom instruction..."}),c.jsx("button",{onClick:ft,children:"Apply"})]}):ge?c.jsxs("div",{className:"context-menu-link-picker",children:[c.jsxs("div",{className:"context-menu-link-header",children:[c.jsx("button",{className:"context-menu-link-back",onClick:()=>oe(null),title:"Back to doc list",children:"←"}),c.jsxs("span",{children:['Pick paragraph in "',ge.title,'"']})]}),c.jsx("button",{className:"context-menu-item context-menu-new-link",onClick:()=>ve({filename:ge.filename,docId:ge.docId}),children:c.jsx("span",{children:"Link whole doc"})}),c.jsx("div",{className:"context-menu-link-list",children:ge.loading?c.jsx("div",{className:"context-menu-loading",children:"Loading…"}):ge.paragraphs.length===0?c.jsx("div",{className:"context-menu-loading",children:"No paragraphs"}):ge.paragraphs.map(ne=>{const de=ne.preview.replace(/…$/,"").slice(0,50),he=ne.type==="heading"?Math.max(0,(ne.level||1)-1)*12:12;return c.jsx("button",{className:`context-menu-item context-menu-paragraph-row context-menu-paragraph-row--${ne.type}`,style:{paddingLeft:8+he},onClick:()=>ve({filename:ge.filename,docId:ge.docId},{nodeId:ne.nodeId,quote:de}),children:c.jsx("span",{children:ne.preview})},ne.nodeId)})})]}):M&&te?c.jsxs("div",{className:"context-menu-link-picker",children:[c.jsxs("div",{className:"context-menu-link-header",children:["Linked from ",te.entries.length," ",te.entries.length===1?"place":"places"]}),c.jsx("div",{className:"context-menu-link-list",children:te.entries.map((ne,de)=>{const he=E.find(Pe=>Pe.docId===ne.from_doc),Ge=(he==null?void 0:he.title)||ne.from_doc;return c.jsxs("button",{className:"context-menu-item",onClick:()=>{window.dispatchEvent(new CustomEvent("ow-navigate-to-link",{detail:{docId:ne.from_doc,nodeId:ne.from_node,filename:null,quote:null}})),s(!1),L(!1)},children:[c.jsx("span",{children:Ge}),c.jsxs("span",{className:"context-menu-shortcut",children:['"',ne.text,'"']})]},`${ne.from_doc}-${ne.from_node}-${de}`)})})]}):k?c.jsxs("div",{className:"context-menu-link-picker",children:[c.jsx("div",{className:"context-menu-link-header",children:"Link to document"}),_?c.jsxs("div",{className:"context-menu-custom",children:[c.jsx("input",{autoFocus:!0,value:O,onChange:ne=>B(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&Be(),ne.key==="Escape"&&A(!1)},placeholder:"New document title..."}),c.jsx("button",{onClick:Be,children:"Create"})]}):c.jsx("button",{className:"context-menu-item context-menu-new-link",onClick:()=>A(!0),children:c.jsx("span",{children:"+ New link doc"})}),c.jsxs("div",{className:"context-menu-link-list",children:[T.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-section-header",children:"Linked in this doc"}),E.filter(ne=>mk(ne,T)).map(ne=>c.jsxs("div",{className:"context-menu-link-row",children:[c.jsx("button",{className:"context-menu-item context-menu-link-row__main",onClick:()=>ve(ne),children:c.jsx("span",{children:ne.title})}),ne.docId&&c.jsx("button",{className:"context-menu-link-row__drill",title:"Pick a paragraph in this doc",onClick:()=>X(ne),children:"▸"})]},`linked-${ne.filename}`))]}),c.jsx("div",{className:"context-menu-section-header",children:"All documents"}),E.filter(ne=>!mk(ne,T)).map(ne=>c.jsxs("div",{className:"context-menu-link-row",children:[c.jsx("button",{className:"context-menu-item context-menu-link-row__main",onClick:()=>ve(ne),children:c.jsx("span",{children:ne.title})}),ne.docId&&c.jsx("button",{className:"context-menu-link-row__drill",title:"Pick a paragraph in this doc",onClick:()=>X(ne),children:"▸"})]},ne.filename)),E.length===0&&c.jsx("div",{className:"context-menu-loading",children:"No documents"})]})]}):(()=>{const ne=pt();let de;return ne.map((he,Ge)=>{const Pe=he.isPlugin&&he.pluginDisplayName&&he.pluginDisplayName!==de,et=de!==void 0;he.isPlugin?de=he.pluginDisplayName:de=void 0;const ot=!he.isPlugin&&et;return c.jsxs("span",{children:[Pe&&c.jsx("div",{className:"context-menu-section-header",children:he.pluginDisplayName}),ot&&c.jsx("div",{className:"context-menu-divider"}),c.jsxs("button",{className:"context-menu-item",onClick:()=>mt(he),children:[c.jsx("span",{children:he.label}),he.shortcut&&c.jsx("span",{className:"context-menu-shortcut",children:he.shortcut})]})]},he.action)})})()}):null}const Y5=80,jp=8,Wo=8,X5=400;function gk(t){return t.nodeIds&&t.nodeIds.length>0?t.nodeIds:[t.nodeId]}function vk(t,e){const n=new Set(e);return t.every(r=>n.has(r))}function Q5(t,e){const n=e.find(s=>s.id===t);if(!n)return[];const r=gk(n);return e.filter(s=>{if(s.id===n.id)return!0;const i=gk(s);return vk(i,r)||vk(r,i)}).sort((s,i)=>(s.createdAt||"").localeCompare(i.createdAt||""))}function Z5({documentId:t}){const[e,n]=x.useState(null),[r,s]=x.useState({kind:"view"}),[i,o]=x.useState(""),[l,d]=x.useState(0),[f,h]=x.useState({left:0,top:0,placement:"above"}),m=x.useRef(null),g=x.useRef(null),v=x.useRef(null),b=x.useRef(null),k=x.useRef({kind:"view"});x.useEffect(()=>{b.current=e},[e]),x.useEffect(()=>{k.current=r},[r]),x.useEffect(()=>{const G=()=>d(D=>D+1);return window.addEventListener("ow-comments-changed",G),()=>window.removeEventListener("ow-comments-changed",G)},[]);const w=x.useCallback(()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)},[]),E=x.useCallback(()=>{w(),v.current=window.setTimeout(()=>{k.current.kind==="view"&&n(null)},Y5)},[w]),C=x.useCallback(()=>{w(),n(null),s({kind:"view"}),o("")},[w]),T=x.useMemo(()=>e?Q5(e.commentId,Ru()):[],[e,l]);x.useEffect(()=>{e&&T.length===0&&C()},[e,T.length,C]),x.useLayoutEffect(()=>{if(!e)return;const G=m.current;if(!G)return;const D=G.getBoundingClientRect(),{rect:U}=e,q=U.top,se=window.innerHeight-U.bottom,V=q>=D.height+jp||q>=se?"above":"below",te=V==="above"?Math.max(Wo,U.top-D.height-jp):Math.min(window.innerHeight-D.height-Wo,U.bottom+jp);let K=U.left;K+D.width>window.innerWidth-Wo&&(K=window.innerWidth-D.width-Wo),K<Wo&&(K=Wo),h({left:K,top:te,placement:V})},[e,r,T.length,l]),x.useEffect(()=>{const G=se=>{var K,M,L;const V=se.target,te=(K=V==null?void 0:V.closest)==null?void 0:K.call(V,"[data-comment-id]");if(te){const ee=te.getAttribute("data-comment-id");if(!ee)return;if(((M=b.current)==null?void 0:M.commentId)===ee){w();return}w(),s({kind:"view"}),o(""),n({commentId:ee,rect:te.getBoundingClientRect()});return}if((L=m.current)!=null&&L.contains(V)){w();return}b.current&&E()},D=se=>{var te,K;const V=se.relatedTarget;if(V&&((te=m.current)!=null&&te.contains(V))){w();return}V&&((K=V.closest)!=null&&K.call(V,"[data-comment-id]"))||b.current&&E()},U=se=>{if(se.key==="Escape"&&b.current){if(se.preventDefault(),k.current.kind!=="view"){s({kind:"view"}),o("");return}C()}},q=se=>{var V;b.current&&k.current.kind==="view"&&((V=m.current)!=null&&V.contains(se.target)||C())};return document.addEventListener("mouseover",G),document.addEventListener("mouseout",D),document.addEventListener("keydown",U),document.addEventListener("scroll",q,!0),()=>{document.removeEventListener("mouseover",G),document.removeEventListener("mouseout",D),document.removeEventListener("keydown",U),document.removeEventListener("scroll",q,!0),w()}},[w,E,C]),x.useEffect(()=>{var G;r.kind!=="view"&&((G=g.current)==null||G.focus())},[r]);const j=x.useCallback(G=>{const D=Ru().find(U=>U.id===G);D&&(o(D.note||""),s({kind:"edit",commentId:G}))},[]),_=x.useCallback(G=>{o(""),s({kind:"compose",parentCommentId:G})},[]),A=x.useCallback(()=>{s({kind:"view"}),o("")},[]),O=x.useCallback(()=>{r.kind!=="edit"||!t||fetch("/api/comments",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:t,id:r.commentId,note:i.trim()})}).then(()=>{s({kind:"view"}),o("")}).catch(G=>console.error("[CommentPopover] Save failed:",G))},[r,t,i]),B=x.useCallback(()=>{if(r.kind!=="compose"||!t)return;const G=Ru().find(D=>D.id===r.parentCommentId);G&&fetch("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:t,text:G.text,note:i.trim(),nodeId:G.nodeId,nodeIds:G.nodeIds})}).then(()=>{s({kind:"view"}),o("")}).catch(D=>console.error("[CommentPopover] Create failed:",D))},[r,t,i]),$=x.useCallback(G=>{fetch("/api/comments/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[G]})}).catch(D=>console.error("[CommentPopover] Resolve failed:",D))},[]),W=x.useCallback(G=>{fetch("/api/comments",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[G]})}).catch(D=>console.error("[CommentPopover] Delete failed:",D))},[]);if(!e||T.length===0)return null;const J=r.kind!=="view",z=r.kind==="compose"?"Adding a new comment on the same range":null;return c.jsx("div",{ref:m,className:`ow-comment-popover ow-comment-popover-${f.placement}`,style:{left:f.left,top:f.top,maxHeight:X5},onMouseEnter:w,onMouseLeave:E,children:J?c.jsxs(c.Fragment,{children:[z&&c.jsx("div",{className:"ow-comment-popover-empty",children:z}),c.jsx("textarea",{ref:g,className:"ow-comment-popover-textarea",value:i,onChange:G=>o(G.target.value),onKeyDown:G=>{G.key==="Enter"&&(G.metaKey||G.ctrlKey)&&(G.preventDefault(),r.kind==="edit"?O():r.kind==="compose"&&B()),G.key==="Escape"&&(G.preventDefault(),A())},rows:4,placeholder:"Note for agent (optional)..."}),c.jsxs("div",{className:"ow-comment-popover-actions",children:[c.jsx("span",{className:"ow-comment-popover-hint",children:"⌘↵ to save · Esc to cancel"}),c.jsx("button",{className:"ow-icon-btn",onClick:r.kind==="edit"?O:B,title:"Save",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M20 6 9 17l-5-5"})})})]})]}):c.jsx("div",{className:"ow-comment-popover-stack",children:T.map((G,D)=>c.jsxs("div",{className:`ow-comment-popover-card${D>0?" ow-comment-popover-card-divider":""}`,children:[G.note?c.jsx("div",{className:"ow-comment-popover-text",children:G.note}):c.jsx("div",{className:"ow-comment-popover-empty",children:"No note"}),c.jsxs("div",{className:"ow-comment-popover-actions",children:[c.jsx("button",{className:"ow-icon-btn",onClick:()=>j(G.id),title:"Edit comment",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12 20h9"}),c.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})]})}),c.jsx("button",{className:"ow-icon-btn",onClick:()=>_(G.id),title:"Add another comment on this range",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12 5v14"}),c.jsx("path",{d:"M5 12h14"})]})}),c.jsx("button",{className:"ow-icon-btn",onClick:()=>$(G.id),title:"Resolve (mark addressed)",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M20 6 9 17l-5-5"})})}),c.jsx("button",{className:"ow-icon-btn ow-icon-btn-danger",onClick:()=>W(G.id),title:"Delete (remove permanently)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M18 6 6 18"}),c.jsx("path",{d:"m6 6 12 12"})]})})]})]},G.id))})})}function gu(t){return t.type==="doc"?t.file:t.id}function Tl(t,e){for(const n of t)n.type==="doc"?e.add(n.file):n.type==="container"&&Tl(n.items,e)}function b2(t,e,n,r){for(const s of t){if(s.type==="doc"&&s.file===e)return n||r;if(s.type==="container"){const i=s.autoAccept===!0,o=b2(s.items,e,n,r||i);if(o!==null)return o}}return null}function Md(t,e){for(const n of t){const r=n.workspace;if(!r)continue;const s=r.autoAccept===!0;if(b2(r.root,e,s,!1)===!0)return!0}return!1}function ca(t){const e=new Date(t),n=Date.now()-e.getTime();return n<6e4?"just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<6048e5?`${Math.floor(n/864e5)}d ago`:e.toLocaleDateString()}function Ls(t){return/^[A-Z]:[/\\]|^\//.test(t)}function x2(t){const e=t.replace(/\\/g,"/").split("/");return e.length>=2?e[e.length-2]:""}function e8(t){const e=new Date(t),n=new Date,r=new Date(n.getFullYear(),n.getMonth(),n.getDate()),s=new Date(r.getTime()-864e5),i=new Date(e.getFullYear(),e.getMonth(),e.getDate());return i.getTime()===r.getTime()?"Today":i.getTime()===s.getTime()?"Yesterday":n.getTime()-i.getTime()<6048e5?e.toLocaleDateString(void 0,{weekday:"long"}):e.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function t8(t,e){const[n,r]=x.useState([]),[s,i]=x.useState([]),o=x.useRef(null),l=x.useRef(new Set),d=x.useCallback(g=>{l.current.add(g)},[]),f=x.useMemo(()=>{const g=new Set;for(const v of s)v.workspace&&Tl(v.workspace.root,g);return g},[s]),h=x.useCallback(()=>{fetch("/api/documents").then(g=>g.json()).then(g=>{if(!Array.isArray(g))return;const v=l.current;if(v.size>0){const k=new Set(g.map(w=>w.filename));for(const w of[...v])k.has(w)||v.delete(w)}const b=v.size>0?g.filter(k=>!v.has(k.filename)):g;r(b)}).catch(()=>{})},[]),m=x.useCallback(()=>{fetch("/api/workspaces").then(g=>g.json()).then(async g=>{if(!Array.isArray(g))return;const v=await Promise.all(g.map(async b=>{try{const w=await(await fetch(`/api/workspaces/${encodeURIComponent(b.filename)}`)).json();return{...b,workspace:w}}catch{return b}}));i(v)}).catch(()=>{})},[]);return x.useEffect(()=>{h()},[h,t]),x.useEffect(()=>{m()},[m,e]),x.useEffect(()=>{const g=requestAnimationFrame(()=>{var b;const v=(b=o.current)==null?void 0:b.querySelector(".sidebar-item.active");v==null||v.scrollIntoView({block:"nearest",behavior:"instant"})});return()=>cancelAnimationFrame(g)},[n]),{docs:n,setDocs:r,workspaces:s,setWorkspaces:i,assignedFiles:f,fetchDocs:h,fetchWorkspaces:m,scrollRef:o,markPendingDelete:d}}function Xg(t,e){return t.filter(n=>!e(n)).map(n=>n.type==="container"?{...n,items:Xg(n.items,e)}:n)}function w2(t,e,n){return t.map(r=>r.type==="container"&&r.id===e?{...r,name:n}:r.type==="container"?{...r,items:w2(r.items,e,n)}:r)}function n8(t,e,n,r,s,i){const o=x.useCallback(_=>{n(A=>A.filter(O=>O.filename!==_)),i==null||i(_),fetch(`/api/documents/${encodeURIComponent(_)}`,{method:"DELETE"}).catch(()=>t())},[n,t]),l=x.useCallback(_=>{n(A=>A.filter(O=>O.filename!==_)),fetch(`/api/documents/${encodeURIComponent(_)}/archive`,{method:"POST"}).catch(()=>t())},[n,t]),d=x.useCallback(_=>{n(A=>A.filter(O=>O.filename!==_)),fetch(`/api/documents/${encodeURIComponent(_)}/unarchive`,{method:"POST"}).catch(()=>t())},[n,t]),f=x.useCallback((_,A,O)=>{!O.trim()||O.trim()===A||(n(B=>B.map($=>$.filename===_?{...$,title:O.trim()}:$)),fetch(`/api/documents/${encodeURIComponent(_)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:O.trim()})}).catch(()=>t()))},[n,t]),h=x.useCallback(_=>{r(A=>A.filter(O=>O.filename!==_)),fetch(`/api/workspaces/${encodeURIComponent(_)}`,{method:"DELETE"}).catch(()=>e())},[r,e]),m=x.useCallback((_,A)=>{A.trim()&&(r(O=>O.map(B=>B.filename===_?{...B,title:A.trim()}:B)),fetch(`/api/workspaces/${encodeURIComponent(_)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:A.trim()})}).catch(()=>e()))},[r,e]),g=x.useCallback((_,A)=>{r(O=>O.map(B=>B.filename!==_||!B.workspace?B:{...B,docCount:Math.max(0,B.docCount-1),workspace:{...B.workspace,root:Xg(B.workspace.root,$=>$.type==="doc"&&$.file===A)}})),fetch(`/api/workspaces/${encodeURIComponent(_)}/docs/${encodeURIComponent(A)}`,{method:"DELETE"}).catch(()=>e())},[r,e]),v=x.useCallback((_,A,O=!1)=>{r($=>$.map(W=>W.filename!==_||!W.workspace?W:{...W,workspace:{...W.workspace,root:Xg(W.workspace.root,J=>J.type==="container"&&J.id===A)}}));const B=`/api/workspaces/${encodeURIComponent(_)}/containers/${encodeURIComponent(A)}${O?"?cascade=true":""}`;fetch(B,{method:"DELETE"}).then(()=>{O&&t()}).catch(()=>e())},[r,e,t]),b=x.useCallback((_,A,O)=>{O.trim()&&(r(B=>B.map($=>$.filename!==_||!$.workspace?$:{...$,workspace:{...$.workspace,root:w2($.workspace.root,A,O.trim())}})),fetch(`/api/workspaces/${encodeURIComponent(_)}/containers/${encodeURIComponent(A)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O.trim()})}).catch(()=>e()))},[r,e]),k=x.useCallback(()=>{fetch("/api/workspaces",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:"Untitled Workspace"})}).catch(()=>{})},[]),w=x.useCallback((_,A,O)=>{fetch("/api/documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O?{metadata:O}:{})}).then(B=>B.json()).then(B=>{if(B.filename)return fetch(`/api/workspaces/${encodeURIComponent(_)}/docs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:B.filename,title:B.title||"Untitled",containerId:A})})}).catch(()=>{})},[]),E=x.useCallback((_,A)=>{fetch(`/api/workspaces/${encodeURIComponent(_)}/containers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"Untitled",parentContainerId:A})}).catch(()=>{})},[]),C=x.useCallback(_=>{const A=s.find(O=>O.filename===_);return(A==null?void 0:A.tags)??[]},[s]),T=x.useCallback((_,A)=>{const O=A.trim();O&&(n(B=>B.map($=>{if($.filename!==_)return $;const W=$.tags??[];return W.includes(O)?$:{...$,tags:[...W,O]}})),fetch(`/api/doc-tags/${encodeURIComponent(_)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:O})}).catch(()=>{}))},[n]),j=x.useCallback((_,A)=>{n(O=>O.map(B=>{if(B.filename!==_)return B;const $=B.tags??[],W=$.filter(J=>J!==A);return W.length===$.length?B:W.length>0?{...B,tags:W}:{...B,tags:void 0}})),fetch(`/api/doc-tags/${encodeURIComponent(_)}/${encodeURIComponent(A)}`,{method:"DELETE"}).catch(()=>{})},[n]);return{fetchDocs:t,handleDelete:o,handleArchive:l,handleUnarchive:d,handleRename:f,handleCreateWorkspace:k,handleDeleteWorkspace:h,handleCreateInWorkspace:w,handleRemoveFromWorkspace:g,handleCreateContainer:E,handleDeleteContainer:v,handleRenameContainer:b,handleRenameWorkspace:m,getDocTags:C,handleAddTag:T,handleRemoveTag:j}}function k2({docs:t,workspaces:e,assignedFiles:n,scrollRef:r,setCollapsedSections:s}){const[i,o]=x.useState(null),[l,d]=x.useState(null),f=x.useRef(null),h=x.useRef(null),m=x.useRef(null),g=x.useRef(null),v=x.useRef(null),b=5,k=(W,J,z)=>z==="before"?J>0?gu(W[J-1]):null:gu(W[J]),w=x.useCallback((W,J)=>{if(J===null){const D=t.filter(q=>!n.has(q.filename)).map(q=>({type:"doc",file:q.filename,title:q.title})),U=D.findIndex(q=>gu(q)===W);return U>=0?{siblings:D,index:U,containerId:null}:null}const z=e.find(D=>D.filename===J);if(!(z!=null&&z.workspace))return null;const G=(D,U)=>{for(let q=0;q<D.length;q++){if(gu(D[q])===W)return{siblings:D,index:q,containerId:U};if(D[q].type==="container"){const se=G(D[q].items,D[q].id);if(se)return se}}return null};return G(z.workspace.root,null)},[t,n,e]),E=x.useCallback(()=>{o(null),d(null),v.current=null,g.current=null,m.current&&(m.current.remove(),m.current=null),f.current&&(clearTimeout(f.current),f.current=null),h.current&&(cancelAnimationFrame(h.current),h.current=null),document.body.style.userSelect=""},[]),C=x.useCallback((W,J)=>{if(!W||!J)return;if(W.type==="workspace"){const V=J.itemId;if(V===W.filename)return;const te=e.map(L=>L.filename),K=te.indexOf(W.filename);if(K<0)return;te.splice(K,1);let M=te.indexOf(V);if(M<0)return;J.position==="after"&&(M+=1),te.splice(M,0,W.filename),fetch("/api/workspaces/reorder",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:te})}).catch(()=>{});return}const{wsFilename:z,containerId:G,afterId:D}=J,U=W.type==="doc"?W.file:W.id,q=W.sourceWs;if(J.itemId===U)return;if(W.type==="container"){if(z===null&&G===null&&J.itemId!=="__section__"){const V=J.itemId,te=J.position==="after"?V:(()=>{const K=e.findIndex(M=>M.filename===V);return K>0?e[K-1].filename:null})();fetch("/api/workspaces/promote-container",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceWorkspace:q,containerId:U,afterWorkspaceFilename:te})}).catch(()=>{});return}if(q!==z&&z){fetch(`/api/workspaces/${encodeURIComponent(z)}/containers/${encodeURIComponent(U)}/cross-move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceWorkspace:q,targetContainerId:G??null,afterIdentifier:D})}).catch(()=>{});return}if(!z)return;fetch(`/api/workspaces/${encodeURIComponent(z)}/docs/${encodeURIComponent(U)}/move`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetContainerId:G??null,afterFile:D})}).catch(()=>{});return}const se=W.file;if(q===null&&z===null){const V=t.filter(ee=>!n.has(ee.filename)).map(ee=>ee.filename),te=V.indexOf(se);if(te<0)return;V.splice(te,1);let K=D?V.indexOf(D):-1;K>=0?K+=1:K=0,V.splice(K,0,se);const M=[];let L=0;for(const ee of t)n.has(ee.filename)?M.push(ee.filename):M.push(V[L++]);fetch("/api/documents/reorder",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:M})}).catch(()=>{});return}if(q===null&&z!==null){fetch(`/api/workspaces/${encodeURIComponent(z)}/docs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:se,title:se.replace(/\.md$/,""),containerId:G??null,afterFile:D})}).catch(()=>{});return}if(q!==null&&z===null){fetch(`/api/workspaces/${encodeURIComponent(q)}/docs/${encodeURIComponent(se)}`,{method:"DELETE"}).catch(()=>{});return}if(q===z&&z!==null){fetch(`/api/workspaces/${encodeURIComponent(z)}/docs/${encodeURIComponent(se)}/move`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetContainerId:G??null,afterFile:D})}).catch(()=>{});return}q!==null&&z!==null&&fetch(`/api/workspaces/${encodeURIComponent(z)}/docs/${encodeURIComponent(se)}/cross-move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceWorkspace:q,containerId:G??null,afterFile:D,title:se.replace(/\.md$/,"")})}).catch(()=>{})},[e,t,n]),T=x.useCallback((W,J)=>{const z=m.current;z&&(z.style.display="none");const G=document.elementFromPoint(W,J);if(z&&(z.style.display=""),!G)return null;if((i==null?void 0:i.type)==="workspace"||(i==null?void 0:i.type)==="container"){const ee=G.closest("[data-ws-drag]");if(ee){const fe=ee.dataset.wsDrag,ge=ee.getBoundingClientRect(),oe=(J-ge.top)/ge.height;return{itemId:fe,position:oe<.5?"before":"after",wsFilename:null,containerId:null,afterId:null}}if((i==null?void 0:i.type)==="workspace")return null}if((i==null?void 0:i.type)==="doc"){const ee=G.closest("[data-ws-drag]");if(ee)return{itemId:"__section__",position:"inside",wsFilename:ee.dataset.wsDrag,containerId:null,afterId:null}}const D=G.closest("[data-drag-id]");if(!D){const ee=G.closest("[data-drop-ws]");return ee?{itemId:"__section__",position:"inside",wsFilename:ee.dataset.dropWs==="__docs__"?null:ee.dataset.dropWs,containerId:ee.dataset.dropContainer||null,afterId:null}:null}const U=D.dataset.dragId,q=D.dataset.dragType,se=D.dataset.dragWs==="__docs__"?null:D.dataset.dragWs,V=D.getBoundingClientRect(),te=(J-V.top)/V.height;if(q==="container-header"){const ee=U,fe=D.dataset.dragParent||null,ge=w(ee,se);if(!ge)return null;const oe=(i==null?void 0:i.type)==="container"?.33:.25;return te<oe?{itemId:ee,position:"before",wsFilename:se,containerId:fe,afterId:k(ge.siblings,ge.index,"before")}:te>1-oe?{itemId:ee,position:"after",wsFilename:se,containerId:fe,afterId:k(ge.siblings,ge.index,"after")}:{itemId:ee,position:"inside",wsFilename:se,containerId:ee,afterId:null}}const K=D.dataset.dragContainer||null,M=w(U,se);if(!M)return null;const L=te<.5?"before":"after";return{itemId:U,position:L,wsFilename:se,containerId:K,afterId:k(M.siblings,M.index,L)}},[w,i]),j=x.useCallback(W=>{const J=r.current;if(!J)return;const z=J.getBoundingClientRect(),G=80,D=18;let U=0;if(W<z.top+G?U=-D*Math.max(0,1-(W-z.top)/G):W>z.bottom-G&&(U=D*Math.max(0,1-(z.bottom-W)/G)),h.current&&(cancelAnimationFrame(h.current),h.current=null),U!==0){const q=()=>{J.scrollTop+=U,h.current=requestAnimationFrame(q)};h.current=requestAnimationFrame(q)}},[r]),_=x.useCallback((W,J)=>{const z=m.current;z&&(z.style.display="none");const G=document.elementFromPoint(W,J);z&&(z.style.display="");const D=G==null?void 0:G.closest("[data-section-key]");if(!D){f.current&&(clearTimeout(f.current),f.current=null);return}const U=D.dataset.sectionKey;f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{s(q=>{if(!q.has(U))return q;const se=new Set(q);return se.delete(U),se})},500)},[s]);x.useEffect(()=>{if(!i)return;const W=z=>{m.current&&(m.current.style.left=`${z.clientX+12}px`,m.current.style.top=`${z.clientY-8}px`),d(T(z.clientX,z.clientY)),j(z.clientY),_(z.clientX,z.clientY)},J=z=>{C(i,T(z.clientX,z.clientY)),E()};return window.addEventListener("pointermove",W),window.addEventListener("pointerup",J),()=>{window.removeEventListener("pointermove",W),window.removeEventListener("pointerup",J)}},[i,T,C,E,j,_]);const A=x.useCallback((W,J,z)=>{if(W.button!==0||W.target.closest("input, button, .sidebar-tag-remove, .sidebar-tag-add, .sidebar-container-actions, .sidebar-delete-btn, .sidebar-confirm-delete, .sidebar-inline-confirm"))return;g.current={x:W.clientX,y:W.clientY},v.current=J;const D=q=>{if(!g.current||!v.current)return;const se=q.clientX-g.current.x,V=q.clientY-g.current.y;if(Math.abs(se)+Math.abs(V)>=b){document.body.style.userSelect="none",window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",U),o(v.current),v.current=null;const te=document.createElement("div");te.style.cssText="position:fixed;pointer-events:none;z-index:9999;padding:4px 10px;background:var(--bg-surface, white);border:1px solid var(--border, #cbd5e1);border-radius:6px;font-size:12px;box-shadow:0 2px 8px rgba(0,0,0,0.12);max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--ink-dark, #334155);",te.textContent=z,document.body.appendChild(te),m.current=te,te.style.left=`${q.clientX+12}px`,te.style.top=`${q.clientY-8}px`}},U=()=>{window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",U),g.current=null,v.current=null,document.body.style.userSelect=""};window.addEventListener("pointermove",D),window.addEventListener("pointerup",U)},[]);return{draggedItem:i,dropIndicator:l,handlePointerDown:A,dropClass:W=>!l||l.itemId!==W?"":l.position==="before"?"drop-before":l.position==="after"?"drop-after":l.position==="inside"?"drop-inside":"",isDragging:W=>i?i.type==="doc"?i.file===W:i.type==="workspace"?i.filename===W:i.id===W:!1,isContainerDropTarget:W=>!l||!i?!1:l.containerId===W}}const r8=[{key:"document",label:"Document"},{key:"tweet",label:"Tweet"},{key:"article",label:"Article"},{key:"linkedin",label:"LinkedIn"},{key:"newsletter",label:"Newsletter"},{key:"blog",label:"Blog"}];function s8({onPick:t}){const[e,n]=x.useState(!1),r=x.useRef(null),s=x.useRef(null),[i,o]=x.useState({});return x.useLayoutEffect(()=>{if(!e||!r.current||!s.current)return;const l=s.current.getBoundingClientRect(),d=r.current.getBoundingClientRect(),f=8;let h=l.right-4,m=l.top-4;h+d.width+f>window.innerWidth&&(h=l.left-d.width+4),m+d.height+f>window.innerHeight&&(m=window.innerHeight-d.height-f),m<f&&(m=f),o({position:"fixed",left:h,top:m})},[e]),c.jsxs("span",{onMouseLeave:()=>n(!1),children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("button",{ref:s,className:"context-menu-item context-menu-submenu-trigger",onMouseEnter:()=>n(!0),onClick:()=>n(l=>!l),children:[c.jsx("span",{children:"Create variant"}),c.jsx("span",{className:"context-menu-submenu-arrow",children:"▸"})]}),e&&c.jsx("div",{ref:r,className:"context-menu context-menu-submenu",style:i,children:r8.map(l=>c.jsx("button",{className:"context-menu-item",onClick:()=>t(l.key),children:c.jsx("span",{children:l.label})},l.key))})]})}function i8({items:t,onAction:e}){const[n,r]=x.useState(null),s=x.useRef(null),i=x.useRef({}),o=x.useMemo(()=>{const h=new Map;for(const m of t){const g=m.pluginDisplayName||"_ungrouped",v=h.get(g)||[];v.push(m),h.set(g,v)}return h},[t]),[l,d]=x.useState({});x.useLayoutEffect(()=>{const h=n?i.current[n]:null;if(!n||!s.current||!h)return;const m=h.getBoundingClientRect(),g=s.current.getBoundingClientRect(),v=8;let b=m.right-4,k=m.top-4;b+g.width+v>window.innerWidth&&(b=m.left-g.width+4),k+g.height+v>window.innerHeight&&(k=window.innerHeight-g.height-v),k<v&&(k=v),d({position:"fixed",left:b,top:k})},[n]);const f=[];for(const[h,m]of o)if(h!=="_ungrouped"&&m.length>=3)f.push(c.jsxs("span",{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("button",{ref:g=>{i.current[h]=g},className:"context-menu-item context-menu-submenu-trigger",onMouseEnter:()=>r(h),onClick:()=>r(n===h?null:h),children:[c.jsx("span",{children:"Transform"}),c.jsx("span",{className:"context-menu-submenu-arrow",children:"▸"})]}),n===h&&c.jsx("div",{ref:s,className:"context-menu context-menu-submenu",style:l,onMouseLeave:()=>r(null),children:m.map(g=>c.jsx("button",{className:"context-menu-item",onClick:()=>e(g),children:c.jsx("span",{children:g.label})},g.action))})]},`sub-${h}`));else{let g=!0;for(const v of m){const b=g&&h!=="_ungrouped";g=!1,f.push(c.jsxs("span",{children:[b&&c.jsx("div",{className:"context-menu-divider"}),b&&c.jsx("div",{className:"context-menu-section-header",children:h}),c.jsx("button",{className:"context-menu-item",onClick:()=>e(v),children:c.jsx("span",{children:v.label})})]},v.action))}}return c.jsx(c.Fragment,{children:f})}function Ad({x:t,y:e,filename:n,title:r,onClose:s,onDuplicate:i,onCreateVariant:o,onRename:l,onArchive:d,onDelete:f,onPluginAction:h,pluginItems:m,onSchedulePost:g,onPostNow:v,isAlreadyPublished:b,onViewAnalytics:k,viewAnalyticsLabel:w,onMarkSent:E,isAlreadySent:C,isApproved:T,onToggleApprove:j,isAutoAccept:_,onToggleAutoAccept:A,sortState:O,sortProposalLabel:B,sortProposalReasoning:$,onRequestSort:W,onCancelSort:J,onAcceptSortProposal:z,onRejectSortProposal:G,folderMode:D,onNewDoc:U,onNewContainer:q,onAcceptAll:se,onRejectAll:V,folderAutoAccept:te,onToggleFolderAutoAccept:K,folderAutoAcceptLabel:M,onRequestSortAll:L,folderDocCount:ee,onDeleteWithDocs:fe,bulkCount:ge,onBulkDelete:oe,onBulkRequestSort:xe}){const we=x.useRef(null),[We,He]=x.useState(!1),[Ze,Oe]=x.useState(!1),[Ke,pt]=x.useState({left:t,top:e});x.useLayoutEffect(()=>{const pe=we.current;if(!pe)return;const mt=pe.getBoundingClientRect(),ft=8;let at=t,nt=e;e+mt.height+ft>window.innerHeight&&(nt=e-mt.height),t+mt.width+ft>window.innerWidth&&(at=t-mt.width),nt<ft&&(nt=ft),at<ft&&(at=ft),pt({left:at,top:nt})},[t,e]),x.useEffect(()=>{const pe=mt=>{we.current&&!we.current.contains(mt.target)&&s()};return document.addEventListener("mousedown",pe),()=>document.removeEventListener("mousedown",pe)},[s]),x.useEffect(()=>{const pe=mt=>{mt.key==="Escape"&&s()};return document.addEventListener("keydown",pe),()=>document.removeEventListener("keydown",pe)},[s]);const Je=x.useCallback(pe=>{h(pe.action,pe),s()},[h,s]);return ge&&ge>1&&oe?c.jsxs("div",{ref:we,className:"context-menu",style:{left:Ke.left,top:Ke.top},children:[c.jsxs("div",{className:"context-menu-section-header",children:[ge," selected"]}),xe&&c.jsx("button",{className:"context-menu-item",onClick:()=>{xe(),s()},children:c.jsxs("span",{children:["Request sort (",ge,")"]})}),We?c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsxs("span",{children:["Delete ",ge,"?"]}),c.jsx("button",{onClick:()=>{oe(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>He(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item sidebar-ctx-delete",onClick:()=>He(!0),children:c.jsxs("span",{children:["Delete (",ge,")"]})})]}):D?c.jsxs("div",{ref:we,className:"context-menu",style:{left:Ke.left,top:Ke.top},children:[c.jsx("button",{className:"context-menu-item",onClick:()=>{l(),s()},children:c.jsx("span",{children:"Rename"})}),U&&c.jsx("button",{className:"context-menu-item",onClick:pe=>{U(pe),s()},children:c.jsx("span",{children:"New Document"})}),q&&c.jsx("button",{className:"context-menu-item",onClick:()=>{q(),s()},children:c.jsx("span",{children:"New Container"})}),(se||V)&&c.jsx("div",{className:"context-menu-divider"}),se&&c.jsx("button",{className:"context-menu-item",onClick:()=>{se(),s()},children:c.jsx("span",{children:"Accept All Changes"})}),V&&c.jsx("button",{className:"context-menu-item",onClick:()=>{V(),s()},children:c.jsx("span",{children:"Reject All Changes"})}),K&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{K(),s()},children:c.jsx("span",{children:te?`Turn off auto-accept${M?" "+M:""}`:`Turn on auto-accept${M?" "+M:""}`})})]}),L&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{L(),s()},children:c.jsx("span",{children:"Request sort all"})})]}),c.jsx("div",{className:"context-menu-divider"}),We?ee&&ee>0&&fe?c.jsxs("div",{className:"sidebar-ctx-folder-delete",onClick:pe=>pe.stopPropagation(),children:[c.jsx("div",{className:"sidebar-ctx-folder-delete-prompt",children:"Delete this folder?"}),c.jsxs("button",{className:"context-menu-item sidebar-ctx-delete-option",onClick:()=>{f(),s()},children:[c.jsx("span",{children:"Folder only"}),c.jsxs("span",{className:"sidebar-ctx-delete-hint",children:[ee," doc",ee===1?"":"s"," → Documents"]})]}),c.jsxs("button",{className:"context-menu-item sidebar-ctx-delete-option sidebar-ctx-delete",onClick:()=>{fe(),s()},children:[c.jsxs("span",{children:["Folder + ",ee," doc",ee===1?"":"s"]}),c.jsx("span",{className:"sidebar-ctx-delete-hint",children:"permanently deletes files"})]}),c.jsx("button",{className:"context-menu-item sidebar-ctx-delete-cancel",onClick:()=>He(!1),children:c.jsx("span",{children:"Cancel"})})]}):c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{children:"Delete?"}),c.jsx("button",{onClick:()=>{f(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>He(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item sidebar-ctx-delete",onClick:()=>He(!0),children:c.jsx("span",{children:"Delete"})})]}):c.jsxs("div",{ref:we,className:"context-menu",style:{left:Ke.left,top:Ke.top},children:[c.jsx("button",{className:"context-menu-item",onClick:()=>{i(),s()},children:c.jsx("span",{children:"Duplicate"})}),o&&c.jsx(s8,{onPick:pe=>{o(pe),s()}}),c.jsx("button",{className:"context-menu-item",onClick:()=>{l(),s()},children:c.jsx("span",{children:"Rename"})}),Ze?c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{children:"Archive?"}),c.jsx("button",{onClick:()=>{d(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>Oe(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item",onClick:()=>Oe(!0),children:c.jsx("span",{children:"Archive"})}),We?c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{children:Ls(n)?"Remove?":"Delete?"}),c.jsx("button",{onClick:()=>{f(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>He(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item sidebar-ctx-delete",onClick:()=>He(!0),children:c.jsx("span",{children:Ls(n)?"Remove":"Delete"})}),j&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{j(),s()},children:c.jsx("span",{children:T?"Remove Approval":"Approve"})})]}),A&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{A(),s()},children:c.jsx("span",{children:_?"Turn off auto-accept":"Turn on auto-accept"})})]}),O==="proposal"&&z&&G&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("div",{className:"sidebar-ctx-sort-proposal",onClick:pe=>pe.stopPropagation(),children:[c.jsxs("div",{className:"sidebar-ctx-sort-proposal-label",children:["Sort to ",B]}),$&&c.jsx("div",{className:"sidebar-ctx-sort-proposal-reason",children:$}),c.jsxs("div",{className:"sidebar-ctx-sort-proposal-actions",children:[c.jsx("button",{onClick:()=>{z(),s()},children:"Accept"}),c.jsx("button",{onClick:()=>{G(),s()},children:"Reject"})]})]})]}),O==="pending"&&J&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("div",{className:"sidebar-ctx-sort-pending",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{className:"sidebar-ctx-sort-pending-label",children:"Sort requested"}),c.jsx("button",{onClick:()=>{J(),s()},children:"Cancel"})]})]}),O==="none"&&W&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{W(),s()},children:c.jsx("span",{children:"Request sort"})})]}),g&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{g(),s()},children:c.jsx("span",{children:"Schedule Post"})})]}),v&&c.jsx("button",{className:"context-menu-item",onClick:()=>{v(),s()},children:c.jsx("span",{children:b?"Republish to Blog":"Post to Blog Now"})}),E&&!C&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{E(),s()},children:c.jsx("span",{children:"Mark as Sent"})})]}),k&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{k(),s()},children:c.jsx("span",{children:w||"View Analytics"})})]}),m.length>0&&c.jsx(i8,{items:m,onAction:Je})]})}function S2({actionLabel:t,docTitle:e,onConfirm:n,onClose:r}){const[s,i]=x.useState(""),o=x.useRef(null);x.useEffect(()=>{var d;(d=o.current)==null||d.focus()},[]),x.useEffect(()=>{const d=f=>{f.key==="Escape"&&r()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[r]);const l=x.useCallback(()=>{n(s.trim())},[s,n]);return c.jsx("div",{className:"focus-modal-overlay",onClick:r,children:c.jsxs("div",{className:"focus-modal",onClick:d=>d.stopPropagation(),children:[c.jsxs("div",{className:"focus-modal-header",children:[c.jsx("h2",{children:t}),c.jsx("button",{className:"focus-modal-close",onClick:r,children:"×"})]}),c.jsxs("div",{className:"focus-modal-body",children:[c.jsxs("label",{children:['Focus instructions for "',e,'"',c.jsx("textarea",{ref:o,value:s,onChange:d=>i(d.target.value.slice(0,500)),placeholder:"Optional: guide the transformation (e.g. 'focus on the intro section', 'keep it professional')...",onKeyDown:d=>{d.key==="Enter"&&(d.ctrlKey||d.metaKey)&&l()}})]}),c.jsxs("div",{className:"focus-modal-hint",children:[s.length,"/500"]}),c.jsxs("div",{className:"focus-modal-actions",children:[c.jsx("button",{className:"focus-modal-btn secondary",onClick:r,children:"Cancel"}),c.jsx("button",{className:"focus-modal-btn primary",onClick:l,children:"Go"})]})]})]})})}function Mp(t,e){if(!e)return[t];const n=[],r=t.toLowerCase(),s=e.toLowerCase();let i=0;for(;i<t.length;){const o=r.indexOf(s,i);if(o===-1){n.push(t.slice(i));break}o>i&&n.push(t.slice(i,o)),n.push(c.jsx("mark",{children:t.slice(o,o+e.length)},o)),i=o+e.length}return n}function yk({r:t,query:e,onClick:n}){return c.jsxs("div",{className:`sidebar-item search-result-item ${t.isActive?"active":""} ${t.isArchived?"search-result-archived":""}`,onClick:n,children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-item-title-text",children:t.matchType==="title"?Mp(t.title,e):t.title}),t.isArchived&&c.jsx("span",{className:"search-archived-badge",children:"archived"})]}),t.matchType==="tag"&&t.matchedTag&&c.jsxs("div",{className:"search-result-tag",children:["Tag: ",Mp(t.matchedTag,e)]}),t.matchType==="content"&&t.snippet&&c.jsx("div",{className:"search-result-snippet",children:Mp(t.snippet,e)}),c.jsxs("div",{className:"sidebar-item-meta",children:[t.wordCount.toLocaleString()," words · ",ca(t.lastModified)]})]})}function Xd({results:t,query:e,onSwitchDocument:n,actions:r}){if(t.length===0)return c.jsx("div",{className:"sidebar-scroll",children:c.jsxs("div",{className:"search-empty",children:['No results for "',e,'"']})});const s=t.filter(o=>!o.isArchived),i=t.filter(o=>o.isArchived);return c.jsx("div",{className:"sidebar-scroll",children:c.jsxs("div",{className:"search-results",children:[s.map(o=>c.jsx(yk,{r:o,query:e,onClick:()=>n(o.filename)},o.filename)),i.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"search-archived-divider",children:c.jsx("span",{children:"Archived"})}),i.map(o=>c.jsx(yk,{r:o,query:e,onClick:()=>r.handleUnarchive(o.filename)},o.filename))]})]})})}async function Ap(t,e={}){var s,i;const r=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:t,arguments:e})})).json();return(i=(s=r.content)==null?void 0:s[0])!=null&&i.text?JSON.parse(r.content[0].text):r}function Rp(t,e){return e?(t/e*100).toFixed(1)+"%":"0%"}function bk(t){return new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function xk(t,e=50){try{const n=new URL(t),r=n.hostname+n.pathname+n.search;return r.length>e?r.slice(0,e)+"...":r}catch{return t.length>e?t.slice(0,e)+"...":t}}function E2({docId:t,title:e,onClose:n}){const[r,s]=x.useState("loading"),[i,o]=x.useState([]),[l,d]=x.useState(""),[f,h]=x.useState(null),[m,g]=x.useState(null),[v,b]=x.useState("links"),[k,w]=x.useState("all"),[E,C]=x.useState(!1),[T,j]=x.useState(!1),[_,A]=x.useState(""),[O,B]=x.useState(!1),[$,W]=x.useState(null),J=x.useRef(null);x.useEffect(()=>{let oe=!1;return(async()=>{try{const xe=await Ap("list_newsletter_issues",{limit:20});if(oe)return;if(!xe.issues||xe.issues.length===0){s("no-data");return}o(xe.issues);const we=xe.issues[0].id;d(we)}catch(xe){oe||(g(xe.message),s("error"))}})(),()=>{oe=!0}},[]),x.useEffect(()=>{if(!l)return;let oe=!1;return C(!0),j(!1),W(null),A(""),(async()=>{try{const xe=await Ap("get_newsletter_analytics",{issue_id:l});if(oe)return;if(xe.error){g(xe.error),s("error");return}h(xe),s("loaded")}catch(xe){oe||(g(xe.message),s("error"))}finally{oe||C(!1)}})(),()=>{oe=!0}},[l]),x.useEffect(()=>{const oe=xe=>{J.current&&!J.current.contains(xe.target)&&n()};return document.addEventListener("mousedown",oe),()=>document.removeEventListener("mousedown",oe)},[n]),x.useEffect(()=>{const oe=xe=>{xe.key==="Escape"&&n()};return document.addEventListener("keydown",oe),()=>document.removeEventListener("keydown",oe)},[n]);const z=f?a8(f.subscriber_events):[],G=(f==null?void 0:f.issue.recipient_count)??0,D=f?f.stats.delivered||G-f.stats.bounces:0,U=f?new Set(f.subscriber_events.filter(oe=>{var xe;return oe.event_type==="click"&&((xe=oe.url)==null?void 0:xe.includes("/newsletter/unsubscribe/"))}).map(oe=>oe.email)).size:0,q=f?f.stats.unsubscribes||U:0,se=f?f.subscriber_events.filter(oe=>oe.event_type==="dropped").length:0,V=f?Math.max(0,G-f.stats.unique_opens):0,te=f!=null&&f.issue.sent_at?Date.now()-new Date(f.issue.sent_at).getTime():0,K=Math.floor(te/36e5),M=!!(f!=null&&f.issue.resent_at||$),L=oe=>{const xe=Math.floor(oe/36e5);return xe<1?"just now":xe<24?`${xe}h ago`:`${Math.floor(xe/24)}d ${xe%24}h ago`},ee=async()=>{if(!(!_.trim()||O)){B(!0);try{const oe=await Ap("resend_to_unopened",{issue_id:l,subject:_});oe.error?(g(oe.error),s("error")):(W({sent:oe.sent,failed:oe.failed}),j(!1))}catch(oe){g(oe.message),s("error")}finally{B(!1)}}},fe=oe=>{var xe;return oe.event_type==="unsubscribe"||oe.event_type==="click"&&!!((xe=oe.url)!=null&&xe.includes("/newsletter/unsubscribe/"))},ge=f?o8(f.subscriber_events.filter(oe=>k==="all"?!0:k==="unsubscribe"?fe(oe):oe.event_type===k)):[];return c.jsx("div",{className:"newsletter-modal-overlay",children:c.jsxs("div",{className:"na-modal",ref:J,children:[c.jsxs("div",{className:"na-header",children:[c.jsx("h3",{children:"Newsletter Analytics"}),c.jsx("button",{className:"newsletter-modal__close",onClick:n,children:"×"})]}),r==="loading"&&!f&&c.jsx("div",{className:"na-body",children:c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:"Loading analytics..."})]})}),r==="no-data"&&c.jsxs("div",{className:"na-body",children:[c.jsx("div",{className:"newsletter-modal__status",children:c.jsx("span",{children:"No newsletter sends found yet."})}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:n,children:"Done"})})]}),r==="error"&&c.jsxs("div",{className:"na-body",children:[c.jsx("div",{className:"newsletter-modal__error",children:m}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:n,children:"Done"})})]}),r==="loaded"&&f&&c.jsxs("div",{className:"na-body",children:[i.length>1&&c.jsx("select",{className:"newsletter-modal__select na-issue-select",value:l,onChange:oe=>d(oe.target.value),children:i.map(oe=>c.jsxs("option",{value:oe.id,children:[oe.subject," — ",bk(oe.sent_at)]},oe.id))}),E?c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:"Loading..."})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"na-kpi-row",children:[c.jsxs("div",{className:"na-kpi",children:[c.jsx("div",{className:"na-kpi__value",children:D.toLocaleString()}),c.jsx("div",{className:"na-kpi__label",children:"Delivered"}),c.jsxs("div",{className:"na-kpi__sub",children:[G.toLocaleString()," sent"]})]}),c.jsxs("div",{className:"na-kpi",children:[c.jsx("div",{className:"na-kpi__value",children:Rp(f.stats.unique_opens,D)}),c.jsx("div",{className:"na-kpi__label",children:"Open rate"}),c.jsxs("div",{className:"na-kpi__sub",children:[f.stats.unique_opens.toLocaleString()," opens"]})]}),c.jsxs("div",{className:"na-kpi",children:[c.jsx("div",{className:"na-kpi__value",children:Rp(f.stats.unique_clicks,D)}),c.jsx("div",{className:"na-kpi__label",children:"Click rate"}),c.jsxs("div",{className:"na-kpi__sub",children:[f.stats.unique_clicks.toLocaleString()," clicks"]})]})]}),c.jsxs("div",{className:"na-kpi-row na-kpi-row--secondary",children:[c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:f.stats.bounces}),c.jsx("span",{className:"na-kpi__label--sm",children:"Bounces"})]}),c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:q}),c.jsx("span",{className:"na-kpi__label--sm",children:"Unsubs"})]}),c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:se}),c.jsx("span",{className:"na-kpi__label--sm",children:"Dropped"})]}),f.stats.complaints>0&&c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:f.stats.complaints}),c.jsx("span",{className:"na-kpi__label--sm",children:"Spam"})]})]}),V>0&&!M&&c.jsx("div",{className:"na-resend",children:T?c.jsxs("div",{className:"na-resend-panel",children:[c.jsxs("div",{className:"na-resend-label-row",children:[c.jsx("span",{className:"na-resend-label",children:"New subject line"}),c.jsxs("span",{className:"na-resend-meta",children:["sent ",L(te),K<48?" · consider waiting 48h":""]})]}),c.jsx("input",{className:"na-resend-input",type:"text",value:_,onChange:oe=>A(oe.target.value),placeholder:"Try a different angle"}),c.jsxs("div",{className:"na-resend-actions",children:[c.jsx("button",{className:"na-resend-cancel",onClick:()=>j(!1),children:"Cancel"}),c.jsx("button",{className:"na-resend-send",onClick:ee,disabled:O||!_.trim(),children:O?"Sending...":`Send to ${V.toLocaleString()}`})]})]}):c.jsxs("button",{className:"na-resend-toggle",onClick:()=>{j(!0),A(f.issue.subject)},children:["Resend to ",V.toLocaleString()," non-openers ",c.jsx("span",{style:{float:"right"},children:"›"})]})}),M&&c.jsxs("div",{className:"na-resend-done",children:["Resent ",f.issue.resent_at?L(Date.now()-new Date(f.issue.resent_at).getTime()):"just now",$?` — ${$.sent} sent`:"",f.issue.resend_subject?` — "${f.issue.resend_subject}"`:""]}),c.jsxs("div",{className:"na-tabs",children:[c.jsxs("button",{className:`na-tab${v==="links"?" active":""}`,onClick:()=>b("links"),children:["Links (",z.length,")"]}),c.jsxs("button",{className:`na-tab${v==="activity"?" active":""}`,onClick:()=>b("activity"),children:["Activity (",f.subscriber_events.length,")"]})]}),v==="links"&&c.jsx("div",{className:"na-table-wrap",children:z.length===0?c.jsx("div",{className:"na-empty",children:"No link clicks recorded yet."}):c.jsxs("table",{className:"na-table",children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Link"}),c.jsx("th",{children:"Unique"}),c.jsx("th",{children:"Total"}),c.jsx("th",{children:"CTR"})]})}),c.jsx("tbody",{children:z.map(oe=>c.jsxs("tr",{children:[c.jsx("td",{className:"na-table__url",title:oe.url,children:c.jsx("a",{href:oe.url,target:"_blank",rel:"noopener noreferrer",children:xk(oe.url)})}),c.jsx("td",{children:oe.uniqueClicks}),c.jsx("td",{children:oe.totalClicks}),c.jsx("td",{children:Rp(oe.uniqueClicks,D)})]},oe.url))})]})}),v==="activity"&&c.jsxs("div",{className:"na-activity",children:[c.jsx("div",{className:"na-filter-row",children:["all","open","click","bounce","dropped","unsubscribe"].map(oe=>c.jsx("button",{className:`na-filter-btn${k===oe?" active":""}`,onClick:()=>w(oe),children:oe==="all"?"All":oe.charAt(0).toUpperCase()+oe.slice(1)+"s"},oe))}),c.jsxs("div",{className:"na-table-wrap",children:[ge.length===0?c.jsxs("div",{className:"na-empty",children:["No ",k==="all"?"":k+" ","events recorded."]}):c.jsxs("table",{className:"na-table",children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Email"}),c.jsx("th",{children:"Event"}),c.jsx("th",{children:"Detail"}),c.jsx("th",{children:"Time"})]})}),c.jsx("tbody",{children:ge.slice(0,100).map(oe=>c.jsxs("tr",{children:[c.jsx("td",{className:"na-table__email",children:oe.email}),c.jsxs("td",{children:[c.jsx("span",{className:`na-badge na-badge--${oe.event_type}`,children:oe.event_type}),oe.count>1&&c.jsxs("span",{className:"na-count",children:[oe.count,"x"]})]}),c.jsx("td",{className:"na-table__url",children:oe.url?c.jsx("a",{href:oe.url,target:"_blank",rel:"noopener noreferrer",children:xk(oe.url,35)}):"—"}),c.jsx("td",{className:"na-table__time",children:bk(oe.latestTimestamp)})]},oe.key))})]}),ge.length>100&&c.jsxs("div",{className:"na-truncated",children:["Showing 100 of ",ge.length," events"]})]})]})]})]})]})})}function o8(t){const e=new Map;for(const n of t){const r=`${n.email}|${n.event_type}|${n.url||""}`,s=e.get(r);s?(s.count++,n.timestamp>s.latestTimestamp&&(s.latestTimestamp=n.timestamp)):e.set(r,{key:r,email:n.email,event_type:n.event_type,url:n.url,latestTimestamp:n.timestamp,count:1})}return Array.from(e.values()).sort((n,r)=>new Date(r.latestTimestamp).getTime()-new Date(n.latestTimestamp).getTime())}function a8(t){const e=t.filter(r=>r.event_type==="click"&&r.url),n=new Map;for(const r of e){const s=r.url;let i=n.get(s);i||(i={emails:new Set,total:0},n.set(s,i)),i.emails.add(r.email),i.total++}return Array.from(n.entries()).map(([r,{emails:s,total:i}])=>({url:r,uniqueClicks:s.size,totalClicks:i})).sort((r,s)=>s.uniqueClicks-r.uniqueClicks)}function l8(t){return t.tweetContext?"tweet":t.articleContext?"article":t.linkedinContext?"linkedin":t.newsletterContext?"newsletter":t.blogContext?"blog":"tweet"}function Dl({filename:t,title:e,onClose:n}){const[r,s]=x.useState("queue"),[i,o]=x.useState(null),[l,d]=x.useState(null),[f,h]=x.useState(""),[m,g]=x.useState(!1),[v,b]=x.useState(null),[k,w]=x.useState(null);x.useEffect(()=>{fetch(`/api/documents/${encodeURIComponent(t)}/text`).then(T=>{if(!T.ok)throw new Error("Failed to load document");return T.json()}).then(T=>{d(T.text||""),o(l8(T.meta||{}))}).catch(T=>w(T.message))},[t]);const E=async()=>{var T;if(!(!l||!i)){g(!0);try{const j={content:l,content_type:i,mode:r};r==="custom"&&f&&(j.scheduled_at=new Date(f).toISOString());const _=await fetch("/api/scheduler/queue",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(j)}),A=await _.json();if(_.ok){const O=(T=A.item)!=null&&T.scheduled_at?new Date(A.item.scheduled_at).toLocaleString():"now";b({success:!0,message:`Scheduled for ${O}`})}else b({success:!1,message:A.error||"Failed to schedule"})}catch(j){b({success:!1,message:j.message})}finally{g(!1)}}},C=i===null&&!k;return c.jsx("div",{className:"schedule-post-overlay",onClick:n,children:c.jsxs("div",{className:"schedule-post-modal",onClick:T=>T.stopPropagation(),children:[c.jsxs("div",{className:"schedule-post-modal-header",children:[c.jsx("h3",{children:"Schedule Post"}),c.jsx("button",{className:"schedule-post-modal-close",onClick:n,children:"×"})]}),c.jsx("div",{className:"schedule-post-modal-doc",children:e}),k?c.jsxs("div",{className:"schedule-post-modal-result error",children:[k,c.jsx("button",{className:"schedule-post-modal-done",onClick:n,children:"Done"})]}):v?c.jsxs("div",{className:`schedule-post-modal-result ${v.success?"success":"error"}`,children:[v.message,c.jsx("button",{className:"schedule-post-modal-done",onClick:n,children:"Done"})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"schedule-post-modal-field",children:[c.jsx("label",{children:"Content Type"}),c.jsx("div",{className:"schedule-post-modal-type",children:C?"...":i})]}),c.jsxs("div",{className:"schedule-post-modal-field",children:[c.jsx("label",{children:"Mode"}),c.jsxs("div",{className:"schedule-post-modal-modes",children:[c.jsx("button",{className:`schedule-post-mode ${r==="queue"?"active":""}`,onClick:()=>s("queue"),children:"Queue Next"}),c.jsx("button",{className:`schedule-post-mode ${r==="now"?"active":""}`,onClick:()=>s("now"),children:"Post Now"}),c.jsx("button",{className:`schedule-post-mode ${r==="custom"?"active":""}`,onClick:()=>s("custom"),children:"Custom Time"})]})]}),r==="custom"&&c.jsxs("div",{className:"schedule-post-modal-field",children:[c.jsx("label",{children:"Date & Time"}),c.jsx("input",{type:"datetime-local",value:f,onChange:T=>h(T.target.value)})]}),c.jsxs("div",{className:"schedule-post-modal-actions",children:[c.jsx("button",{className:"schedule-post-modal-cancel",onClick:n,children:"Cancel"}),c.jsx("button",{className:"schedule-post-modal-submit",onClick:E,disabled:m||C||r==="custom"&&!f,children:m?"Scheduling...":r==="now"?"Post Now":"Schedule"})]})]})]})})}const wk=[{key:"document",label:"Document"},{key:"tweet",label:"Tweet",metadata:{content_type:"tweet",tweetContext:{mode:"tweet"}}},{key:"reply",label:"Reply",needsUrl:!0,urlPlaceholder:"Paste tweet URL...",metadata:{content_type:"reply",tweetContext:{mode:"reply"}}},{key:"quote",label:"Quote Tweet",needsUrl:!0,urlPlaceholder:"Paste tweet URL...",metadata:{content_type:"quote",tweetContext:{mode:"quote"}}},{key:"article",label:"Article",metadata:{content_type:"article",articleContext:{active:!0}}},{key:"linkedin",label:"LinkedIn",metadata:{content_type:"linkedin",linkedinContext:{active:!0}}},{key:"newsletter",label:"Newsletter",metadata:{content_type:"newsletter",newsletterContext:{active:!0}}},{key:"blog",label:"Blog",metadata:{content_type:"blog",blogContext:{active:!0}}}];function N2({anchorRect:t,onSelect:e,onClose:n}){const r=x.useRef(null),[s,i]=x.useState(null),[o,l]=x.useState(""),d=x.useRef(null),[f,h]=x.useState({left:t.left,top:t.bottom+4});x.useLayoutEffect(()=>{const b=r.current;if(!b)return;const k=b.getBoundingClientRect(),w=8;let E=t.left,C=t.bottom+4;C+k.height+w>window.innerHeight&&(C=t.top-k.height-4),E+k.width+w>window.innerWidth&&(E=t.right-k.width),C<w&&(C=w),E<w&&(E=w),h({left:E,top:C})},[t]),x.useEffect(()=>{const b=k=>{r.current&&!r.current.contains(k.target)&&n()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[n]),x.useEffect(()=>{const b=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[n]),x.useEffect(()=>{s&&setTimeout(()=>{var b;return(b=d.current)==null?void 0:b.focus()},0)},[s]);const m=b=>{if(b.needsUrl){i(b.key),l("");return}e(b.metadata)},g=()=>{if(!s||!o.trim())return;const b=o.trim();if(!b.includes("x.com")&&!b.includes("twitter.com"))return;const k=wk.find(E=>E.key===s);if(!(k!=null&&k.metadata))return;const w=JSON.parse(JSON.stringify(k.metadata));w.tweetContext&&(w.tweetContext.url=b),e(w)},v=o.trim().includes("x.com")||o.trim().includes("twitter.com");return c.jsx("div",{ref:r,className:"create-doc-dropdown",style:{left:f.left,top:f.top},children:wk.map(b=>c.jsxs("div",{children:[c.jsx("button",{className:`create-doc-dropdown-item${s===b.key?" active":""}`,onClick:()=>m(b),children:b.label}),s===b.key&&c.jsxs("div",{className:"create-doc-dropdown-url",children:[c.jsx("input",{ref:d,type:"text",placeholder:b.urlPlaceholder,value:o,onChange:k=>l(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),g()),k.key==="Escape"&&(i(null),l(""))}}),c.jsx("button",{onClick:g,disabled:!v,children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})})]})]},b.key))})}const c8=[{id:"full",label:"Full"},{id:"compact",label:"Compact"},{id:"minimal",label:"Minimal"}];function C2(t,e){for(const n of t){if(n.type==="doc"&&n.file===e)return[];if(n.type==="container"){const r=C2(n.items,e);if(r)return[n.id,...r]}}return null}function u8({docs:t,archivedDocs:e,workspaces:n,assignedFiles:r,pendingDocs:s,onSwitchDocument:i,onCreateDocument:o,actions:l,scrollRef:d,writingTitle:f,writingTarget:h,pendingWriteFilenames:m,searchQuery:g,searchResults:v,onSearchChange:b}){const k=I=>!!m&&m.has(I),[w,E]=x.useState(null),[C,T]=x.useState(""),[j,_]=x.useState(null),[A,O]=x.useState(()=>{try{const I=localStorage.getItem("ow-collapsed-sections");return I?new Set(JSON.parse(I)):new Set}catch{return new Set}}),[B,$]=x.useState(null),[W,J]=x.useState(null),[z,G]=x.useState(""),[D,U]=x.useState(null),[q,se]=x.useState(""),[V,te]=x.useState(null),[K,M]=x.useState(""),[L,ee]=x.useState(null),[fe,ge]=x.useState(null),[oe,xe]=x.useState([]),[we,We]=x.useState(!1),[He,Ze]=x.useState(null),[Oe,Ke]=x.useState(null),[pt,Je]=x.useState(null),[pe,mt]=x.useState(null),[ft,at]=x.useState(null),[nt,ht]=x.useState(NE),Fe=x.useRef(null);x.useEffect(()=>{if(!ft)return;const I=re=>{Fe.current&&!Fe.current.contains(re.target)&&at(null)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[ft]);const ve=I=>{ht(I),gM(I),at(null)},X=I=>{I.preventDefault(),at({x:I.clientX,y:I.clientY})},Be=x.useCallback((I,re)=>{fetch("/api/documents/batch-resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filenames:I,action:re})}).catch(()=>{})},[]),{draggedItem:ne,dropIndicator:de,handlePointerDown:he,dropClass:Ge,isDragging:Pe,isContainerDropTarget:et}=k2({docs:t,workspaces:n,assignedFiles:r,scrollRef:d,setCollapsedSections:O}),ot=x.useCallback(()=>{fetch("/api/plugins").then(I=>I.json()).then(I=>{const re=[];let ye=!1;for(const Te of I.plugins||[]){const Se=Te.displayName||void 0;for(const Ee of Te.sidebarMenuItems||[])re.push({...Ee,pluginDisplayName:Se});Te.name==="@openwriter/plugin-publish"&&Te.enabled&&(ye=!0)}xe(re),We(ye)}).catch(()=>{})},[]);x.useEffect(()=>{ot()},[ot]),x.useEffect(()=>{const I=()=>ot();return window.addEventListener("ow-plugins-changed",I),()=>window.removeEventListener("ow-plugins-changed",I)},[ot]);const{variantsByMaster:bt,variantFilenames:Ye}=x.useMemo(()=>{const I=new Map,re=new Set;for(const ye of t)if(ye.masterDocId){const Te=I.get(ye.masterDocId)||[];Te.push(ye),I.set(ye.masterDocId,Te),re.add(ye.filename)}return{variantsByMaster:I,variantFilenames:re}},[t]),it=x.useCallback((I,re)=>{I.preventDefault(),I.stopPropagation(),ee({x:I.clientX,y:I.clientY,filename:re.filename,title:re.title,docId:re.docId,lastSent:re.lastSent,postedUrl:re.postedUrl,isNewsletter:re.isNewsletter})},[]),gt=x.useCallback(I=>{fetch("/api/documents/duplicate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:I})}).catch(()=>{})},[]),Nt=x.useCallback((I,re,ye)=>{fetch("/api/documents/variant",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:I,masterDocId:re,variantType:ye})}).catch(()=>{})},[]),Ie=x.useCallback((I,re,ye,Te,Se)=>{if(re.promptForFocus&&Se===void 0){Ze({action:I,label:re.label,filename:ye,title:Te});return}fetch("/api/plugins/sidebar-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:I,filename:ye,title:Te,instructions:Se||"",label:re.label})}).catch(()=>{})},[]),Me=I=>{O(re=>{const ye=new Set(re);return ye.has(I)?ye.delete(I):ye.add(I),localStorage.setItem("ow-collapsed-sections",JSON.stringify([...ye])),ye})},qe=t.find(I=>I.isActive),F=x.useRef(n);if(F.current=n,x.useEffect(()=>{var I;if(qe)for(const re of F.current){const ye=C2(((I=re.workspace)==null?void 0:I.root)||[],qe.filename);if(ye){O(Te=>{const Se=[re.filename,...ye.map(me=>`container-${me}`)];if(Se.every(me=>!Te.has(me)))return Te;const Ee=new Set(Te);for(const me of Se)Ee.delete(me);return localStorage.setItem("ow-collapsed-sections",JSON.stringify([...Ee])),Ee});break}}},[qe==null?void 0:qe.filename]),v!==null)return c.jsx(Xd,{results:v,query:g,onSwitchDocument:i,actions:l});const ce=t.filter(I=>!r.has(I.filename)&&!Ye.has(I.filename)),Ne=(I,re,ye,Te,Se,Ee=!1)=>c.jsxs("div",{className:`sidebar-item ${I.isActive?"active":""} ${Pe(I.filename)?"dragging":""} ${Ge(I.filename)}`,"data-drag-id":I.filename,"data-drag-type":"doc","data-drag-ws":re||"__docs__","data-drag-container":ye||"",onPointerDown:me=>he(me,{type:"doc",file:I.filename,sourceWs:re||null},I.title),onClick:()=>!I.isActive&&!ne&&i(I.filename),onDoubleClick:()=>{E(I.filename),T(I.title)},onContextMenu:me=>it(me,I),children:[w===I.filename?c.jsx("input",{className:"sidebar-rename-input",value:C,onChange:me=>T(me.target.value),onBlur:()=>{l.handleRename(I.filename,I.title,C),E(null)},onKeyDown:me=>{me.key==="Enter"&&(l.handleRename(I.filename,I.title,C),E(null)),me.key==="Escape"&&E(null)},autoFocus:!0,onClick:me=>me.stopPropagation()}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-item-title-text",children:I.title}),I.variantType&&c.jsx("span",{className:"files-badge-variant",children:I.variantType}),l.getDocTags(I.filename).includes("✓")&&c.jsx("svg",{className:"sidebar-approved-icon",title:"Approved",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),I.lastSent&&c.jsx("svg",{className:"sidebar-sent-icon",title:"Sent",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),(I.autoAccept===!0||I.autoAccept!==!1&&Ee)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:I.autoAccept===!0?"Auto-accept on":"Auto-accept inherited"}),s.filenames.includes(I.filename)&&c.jsx("span",{className:"sidebar-pending-dot"})]}),Ls(I.filename)&&c.jsx("div",{className:"sidebar-item-context",children:x2(I.filename)}),c.jsxs("div",{className:"sidebar-item-meta",children:[I.wordCount.toLocaleString()," words · ",ca(I.lastModified)]}),c.jsxs("div",{className:"sidebar-tags",children:[l.getDocTags(I.filename).filter(me=>me!=="✓").map(me=>c.jsxs("span",{className:"sidebar-tag",onClick:ke=>ke.stopPropagation(),children:[me,c.jsx("span",{className:"sidebar-tag-remove",onClick:ke=>{ke.stopPropagation(),l.handleRemoveTag(I.filename,me)},children:"×"})]},me)),V===I.filename?c.jsx("input",{className:"sidebar-tag-input",value:K,onChange:me=>M(me.target.value),onBlur:()=>{K.trim()&&l.handleAddTag(I.filename,K),te(null)},onKeyDown:me=>{me.key==="Enter"&&(l.handleAddTag(I.filename,K),te(null),M("")),me.key==="Escape"&&(te(null),M(""))},autoFocus:!0,onClick:me=>me.stopPropagation(),placeholder:"tag..."}):c.jsx("button",{className:"sidebar-tag-add",onClick:me=>{me.stopPropagation(),te(I.filename),M("")},children:"+"})]})]}),j===I.filename?c.jsxs("div",{className:"sidebar-confirm-delete",onClick:me=>me.stopPropagation(),children:[c.jsx("span",{children:Ls(I.filename)?"Remove?":"Delete?"}),c.jsx("button",{onClick:()=>{l.handleDelete(I.filename),_(null)},children:"Yes"}),c.jsx("button",{onClick:()=>_(null),children:"No"})]}):c.jsx("button",{className:"sidebar-delete-btn",onClick:me=>{me.stopPropagation(),_(I.filename)},title:Ls(I.filename)?"Remove document":"Delete document",children:"×"})]},I.filename),P=(I,re,ye,Te,Se,Ee=!1)=>{const me=I.docId?bt.get(I.docId):void 0,ke=f&&(h==null?void 0:h.parentDocId)&&h.parentDocId===I.docId;if(!(me&&me.length>0||ke))return Ne(I,re,ye,Te,Se,Ee);const en=`variants-${I.docId}`,on=!A.has(en);return c.jsxs("div",{className:"sidebar-variant-group",children:[c.jsxs("div",{className:"sidebar-variant-master",onClick:Wt=>{Wt.target.closest(".sidebar-variant-chevron")&&(Wt.stopPropagation(),Me(en))},children:[Ne(I,re,ye,Te,Se,Ee),c.jsx("span",{className:`sidebar-variant-chevron${on?"":" collapsed"}`,children:c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),on&&c.jsxs("div",{className:"sidebar-variant-children",children:[me==null?void 0:me.map((Wt,Ft)=>Ne(Wt,re,ye,Te,Ft,Ee)),ke&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]})]})]},`vg-${I.filename}`)},Z=(I,re,ye,Te,Se,Ee,me=!1)=>{if(I.type==="doc"){const xt=t.find(Pn=>Pn.filename===I.file);return xt?Ye.has(xt.filename)?c.jsx(c.Fragment,{}):P(xt,ye,Te,Se,Ee,me):Ls(I.file)?c.jsx("div",{className:"sidebar-item sidebar-unavailable",children:c.jsxs("div",{className:"sidebar-item-title",children:[I.title||I.file," (unavailable)"]})},I.file):c.jsxs("div",{className:"sidebar-item sidebar-missing",children:[c.jsxs("div",{className:"sidebar-item-title",children:[I.title||I.file," (missing)"]}),c.jsx("button",{className:"sidebar-delete-btn",onClick:()=>l.handleRemoveFromWorkspace(ye,I.file),title:"Remove",children:"×"})]},I.file)}const ke=I,Ct=`container-${ke.id}`,en=A.has(Ct),on=re<=2?`depth-${re}`:"depth-2",Wt=ke.autoAccept===!0,Ft=Wt||me;return c.jsxs("div",{className:`sidebar-container ${on} ${en?"collapsed":""} ${Ge(ke.id)} ${et(ke.id)?"drop-inside":""}`,children:[c.jsxs("div",{className:`sidebar-container-header ${(de==null?void 0:de.itemId)===ke.id&&de.position==="inside"?"drop-inside":""}`,"data-drag-id":ke.id,"data-drag-type":"container-header","data-drag-ws":ye,"data-drag-parent":Te||"","data-section-key":Ct,onPointerDown:xt=>he(xt,{type:"container",id:ke.id,sourceWs:ye},ke.name),onClick:()=>!ne&&Me(Ct),onContextMenu:xt=>{xt.preventDefault(),xt.stopPropagation(),mt({x:xt.clientX,y:xt.clientY,type:"container",wsFilename:ye,containerId:ke.id,title:ke.name,nodes:ke.items,autoAccept:Wt})},children:[c.jsx("span",{className:`sidebar-chevron ${en?"collapsed":""}`,children:"▾"}),W===ke.id?c.jsx("input",{className:"sidebar-rename-input",value:z,onChange:xt=>G(xt.target.value),onBlur:()=>{l.handleRenameContainer(ye,ke.id,z),J(null)},onKeyDown:xt=>{xt.key==="Enter"&&(l.handleRenameContainer(ye,ke.id,z),J(null)),xt.key==="Escape"&&J(null)},autoFocus:!0,onClick:xt=>xt.stopPropagation()}):c.jsx("span",{className:"sidebar-container-name",onDoubleClick:xt=>{xt.stopPropagation(),J(ke.id),G(ke.name)},children:ke.name}),Ft&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:Wt?"Auto-accept on for this container":"Auto-accept inherited from workspace"}),c.jsxs("div",{className:"sidebar-container-actions",children:[c.jsx("button",{className:"sidebar-new-btn",onClick:xt=>{xt.stopPropagation(),Je({anchor:xt.target.getBoundingClientRect(),wsFilename:ye,containerId:ke.id})},title:"New doc",children:"+"}),re<2&&c.jsx("button",{className:"sidebar-new-btn",onClick:xt=>{xt.stopPropagation(),l.handleCreateContainer(ye,ke.id)},title:"New sub-container",children:"☐"}),c.jsx("button",{className:"sidebar-new-btn sidebar-container-delete",onClick:xt=>{xt.stopPropagation(),l.handleDeleteContainer(ye,ke.id)},title:"Delete container",children:"×"})]})]}),!en&&c.jsxs("div",{className:"sidebar-container-list","data-drop-ws":ye,"data-drop-container":ke.id,children:[f&&!(h!=null&&h.parentDocId)&&(h==null?void 0:h.wsFilename)===ye&&h.containerId===ke.id&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ke.items.filter(xt=>xt.type!=="doc"?!0:!(k(xt.file)||f&&(h==null?void 0:h.wsFilename)===ye&&h.containerId===ke.id&&xt.title===f)).map((xt,Pn)=>Z(xt,re+1,ye,ke.id,ke.items,Pn,Ft)),ke.items.length===0&&!f&&c.jsx("div",{className:"sidebar-empty",children:ne?"Drop here":"Empty"})]})]},ke.id)};return c.jsxs("div",{className:"sidebar-scroll",ref:d,children:[c.jsxs("div",{className:`sidebar-section sidebar-docs-section ${A.has("docs")?"docs-collapsed":""}`,children:[c.jsxs("div",{className:"sidebar-section-header","data-section-key":"docs",onClick:()=>Me("docs"),onContextMenu:X,children:[c.jsx("span",{className:`sidebar-chevron ${A.has("docs")?"collapsed":""}`,children:"▾"}),c.jsx("span",{className:"sidebar-label",children:"Documents"}),c.jsx("button",{className:"sidebar-new-btn",onClick:I=>{I.stopPropagation(),Je({anchor:I.target.getBoundingClientRect()})},title:"New document",children:"+"})]}),!A.has("docs")&&c.jsxs("div",{className:"sidebar-section-list","data-drop-ws":"__docs__",children:[f&&!(h!=null&&h.parentDocId)&&(!h||!n.some(I=>I.filename===(h==null?void 0:h.wsFilename)))&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ce.filter(I=>!k(I.filename)&&(!f||I.title!==f)).map((I,re)=>{const ye=ce.map(Te=>({type:"doc",file:Te.filename,title:Te.title}));return P(I,void 0,null,ye,re)}),ce.length===0&&c.jsx("div",{className:"sidebar-empty",children:ne?"Drop here to unassign":"No unassigned documents"})]})]}),n.map(I=>{var Se,Ee,me;const re=((Se=I.workspace)==null?void 0:Se.root)||[],ye=A.has(I.filename),Te=((Ee=I.workspace)==null?void 0:Ee.autoAccept)===!0||I.autoAccept===!0;return c.jsxs("div",{className:`sidebar-section sidebar-workspace-section ${ye?"ws-collapsed":""} ${Pe(I.filename)?"dragging":""} ${(de==null?void 0:de.itemId)===I.filename?de.position==="before"?"drop-before":"drop-after":""}`,children:[c.jsxs("div",{className:"sidebar-section-header","data-section-key":I.filename,"data-ws-drag":I.filename,onPointerDown:ke=>he(ke,{type:"workspace",filename:I.filename},I.title),onClick:()=>!ne&&Me(I.filename),onContextMenu:ke=>{var Ct;ke.preventDefault(),ke.stopPropagation(),mt({x:ke.clientX,y:ke.clientY,type:"workspace",wsFilename:I.filename,title:I.title,nodes:re,autoAccept:((Ct=I.workspace)==null?void 0:Ct.autoAccept)===!0||I.autoAccept===!0})},children:[c.jsx("span",{className:`sidebar-chevron ${ye?"collapsed":""}`,children:"▾"}),D===I.filename?c.jsx("input",{className:"sidebar-rename-input",value:q,onChange:ke=>se(ke.target.value),onBlur:()=>{l.handleRenameWorkspace(I.filename,q),U(null)},onKeyDown:ke=>{ke.key==="Enter"&&(l.handleRenameWorkspace(I.filename,q),U(null)),ke.key==="Escape"&&U(null)},autoFocus:!0,onClick:ke=>ke.stopPropagation()}):c.jsx("span",{className:"sidebar-label sidebar-workspace-label",onDoubleClick:ke=>{ke.stopPropagation(),U(I.filename),se(I.title)},children:I.title}),(((me=I.workspace)==null?void 0:me.autoAccept)===!0||I.autoAccept===!0)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:"Auto-accept on for this workspace"}),c.jsxs("div",{className:"sidebar-workspace-actions",children:[c.jsx("button",{className:"sidebar-new-btn",onClick:ke=>{ke.stopPropagation(),Je({anchor:ke.target.getBoundingClientRect(),wsFilename:I.filename,containerId:null})},title:"New document",children:"+"}),c.jsx("button",{className:"sidebar-new-btn",onClick:ke=>{ke.stopPropagation(),l.handleCreateContainer(I.filename,null)},title:"New container",children:"☐"}),B===I.filename?c.jsxs("span",{className:"sidebar-inline-confirm",onClick:ke=>ke.stopPropagation(),children:[c.jsx("button",{onClick:()=>{l.handleDeleteWorkspace(I.filename),$(null)},children:"Yes"}),c.jsx("button",{onClick:()=>$(null),children:"No"})]}):c.jsx("button",{className:"sidebar-new-btn sidebar-workspace-delete",onClick:ke=>{ke.stopPropagation(),$(I.filename)},title:"Delete workspace",children:"×"})]})]}),!ye&&c.jsxs("div",{className:"sidebar-section-list","data-drop-ws":I.filename,children:[f&&!(h!=null&&h.parentDocId)&&(h==null?void 0:h.wsFilename)===I.filename&&h.containerId===null&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),re.filter(ke=>ke.type!=="doc"?!0:!(k(ke.file)||f&&(h==null?void 0:h.wsFilename)===I.filename&&h.containerId===null&&ke.title===f)).map((ke,Ct)=>Z(ke,0,I.filename,null,re,Ct,Te)),re.length===0&&!f&&c.jsx("div",{className:"sidebar-empty",children:ne?"Drop here to add":"Empty workspace"})]})]},I.filename)}),c.jsx("div",{className:"sidebar-new-workspace",children:c.jsx("button",{onClick:l.handleCreateWorkspace,children:"+ New Workspace"})}),pe&&c.jsx(Ad,{x:pe.x,y:pe.y,filename:pe.wsFilename,title:pe.title,onClose:()=>mt(null),onDuplicate:()=>{},onRename:()=>{pe.type==="workspace"?(U(pe.wsFilename),se(pe.title)):pe.containerId&&(J(pe.containerId),G(pe.title)),mt(null)},onArchive:()=>{},onDelete:()=>{pe.type==="workspace"?l.handleDeleteWorkspace(pe.wsFilename):pe.containerId&&l.handleDeleteContainer(pe.wsFilename,pe.containerId)},onPluginAction:()=>{},pluginItems:[],folderMode:!0,onNewDoc:I=>{Je({anchor:I.target.getBoundingClientRect(),wsFilename:pe.wsFilename,containerId:pe.type==="container"?pe.containerId:null}),mt(null)},onNewContainer:()=>{l.handleCreateContainer(pe.wsFilename,pe.type==="container"?pe.containerId:null),mt(null)},onAcceptAll:()=>{const I=new Set;Tl(pe.nodes,I),I.size&&Be([...I],"accept"),mt(null)},onRejectAll:()=>{const I=new Set;Tl(pe.nodes,I),I.size&&Be([...I],"reject"),mt(null)},folderAutoAccept:pe.autoAccept,folderAutoAcceptLabel:pe.type==="workspace"?"for workspace":"for container",onToggleFolderAutoAccept:()=>{fetch("/api/auto-accept/inherit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wsFile:pe.wsFilename,...pe.type==="container"?{containerId:pe.containerId}:{},enabled:!pe.autoAccept})}).catch(()=>{})}}),L&&c.jsx(Ad,{x:L.x,y:L.y,filename:L.filename,title:L.title,onClose:()=>ee(null),onDuplicate:()=>gt(L.filename),onCreateVariant:L.docId?I=>Nt(L.filename,L.docId,I):void 0,onRename:()=>{E(L.filename),T(L.title)},onArchive:()=>l.handleArchive(L.filename),onDelete:()=>l.handleDelete(L.filename),onPluginAction:(I,re)=>Ie(I,re,L.filename,L.title),pluginItems:oe,onSchedulePost:we?()=>{Ke({filename:L.filename,title:L.title}),ee(null)}:void 0,onViewAnalytics:L.docId&&L.lastSent&&(L.postedUrl||L.isNewsletter)?()=>{L.isNewsletter?ge({docId:L.docId,title:L.title}):L.postedUrl&&window.open(L.postedUrl,"_blank"),ee(null)}:void 0,viewAnalyticsLabel:L.isNewsletter?"View Analytics":L.postedUrl?"View on X":"View Analytics",isApproved:l.getDocTags(L.filename).includes("✓"),onToggleApprove:()=>{l.getDocTags(L.filename).includes("✓")?l.handleRemoveTag(L.filename,"✓"):(l.handleAddTag(L.filename,"✓"),setTimeout(()=>window.dispatchEvent(new CustomEvent("ow-accept-all")),50))},isAutoAccept:(()=>{var re;const I=(re=t.find(ye=>ye.filename===L.filename))==null?void 0:re.autoAccept;return I===!0?!0:I===!1?!1:Md(n,L.filename)})(),onToggleAutoAccept:()=>{var ye;const I=(ye=t.find(Te=>Te.filename===L.filename))==null?void 0:ye.autoAccept,re=I===!0?!0:I===!1?!1:Md(n,L.filename);fetch("/api/auto-accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:L.filename,enabled:!re})}).then(()=>l.fetchDocs()).catch(()=>{})},isAlreadySent:!!L.lastSent,onMarkSent:()=>{const I=L.filename;l.getDocTags(I).includes("✓")&&l.handleRemoveTag(I,"✓"),i(I),setTimeout(()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({manualPost:{postedAt:new Date().toISOString()}})}).then(()=>l.fetchDocs()).catch(()=>{})},100),ee(null)}}),He&&c.jsx(S2,{actionLabel:He.label,docTitle:He.title,onClose:()=>Ze(null),onConfirm:I=>{const re=oe.find(ye=>ye.action===He.action);re&&Ie(He.action,re,He.filename,He.title,I),Ze(null)}}),fe&&c.jsx(E2,{docId:fe.docId,title:fe.title,onClose:()=>ge(null)}),Oe&&c.jsx(Dl,{filename:Oe.filename,title:Oe.title,onClose:()=>Ke(null)}),pt&&c.jsx(N2,{anchorRect:pt.anchor,onClose:()=>Je(null),onSelect:I=>{Je(null),pt.wsFilename?l.handleCreateInWorkspace(pt.wsFilename,pt.containerId??null,I):I?fetch("/api/documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({metadata:I})}).catch(()=>{}):o()}}),ft&&c.jsx("div",{ref:Fe,className:"sidebar-density-dropdown",style:{position:"fixed",left:ft.x,top:ft.y,zIndex:200},children:c8.map(I=>c.jsx("button",{className:`sidebar-density-option ${nt===I.id?"active":""}`,onClick:()=>ve(I.id),children:I.label},I.id))})]})}function d8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,onCreateDocument:i,actions:o,scrollRef:l,searchQuery:d,searchResults:f}){const[h,m]=x.useState(null);if(f!==null)return c.jsx(Xd,{results:f,query:d,onSwitchDocument:s});const g=[...t].sort((w,E)=>new Date(E.lastModified).getTime()-new Date(w.lastModified).getTime()),v=[];let b="";for(const w of g){const E=e8(w.lastModified);E!==b&&(v.push({label:E,docs:[]}),b=E),v[v.length-1].docs.push(w)}const k=w=>{for(const E of e){if(!E.workspace)continue;const C=T=>{for(const j of T)if(j.type==="doc"&&j.file===w||j.type==="container"&&C(j.items))return!0;return!1};if(C(E.workspace.root))return E.title}return null};return c.jsxs("div",{className:"sidebar-scroll tl-scroll",ref:l,children:[c.jsxs("div",{className:"tl-header",children:[c.jsx("span",{className:"tl-title",children:"Timeline"}),c.jsx("button",{className:"sidebar-new-btn",onClick:i,title:"New document",children:"+"})]}),v.map(w=>c.jsxs("div",{className:"tl-group",children:[c.jsx("div",{className:"tl-date",children:w.label}),w.docs.map(E=>{const C=k(E.filename);return c.jsxs("div",{className:`tl-item ${E.isActive?"active":""}`,onClick:()=>!E.isActive&&s(E.filename),children:[c.jsx("div",{className:"tl-dot"}),c.jsxs("div",{className:"tl-content",children:[c.jsxs("div",{className:"tl-item-title",children:[c.jsx("span",{children:E.title}),r.filenames.includes(E.filename)&&c.jsx("span",{className:"sidebar-pending-dot"})]}),Ls(E.filename)&&c.jsx("div",{className:"tl-item-context",children:x2(E.filename)}),c.jsxs("div",{className:"tl-item-meta",children:[E.wordCount.toLocaleString()," words · ",ca(E.lastModified)]}),C&&c.jsx("div",{className:"tl-badge",children:C})]}),h===E.filename?c.jsxs("div",{className:"sidebar-confirm-delete",onClick:T=>T.stopPropagation(),children:[c.jsx("span",{children:Ls(E.filename)?"Remove?":"Delete?"}),c.jsx("button",{onClick:()=>{o.handleDelete(E.filename),m(null)},children:"Yes"}),c.jsx("button",{onClick:()=>m(null),children:"No"})]}):c.jsx("button",{className:"sidebar-delete-btn",onClick:T=>{T.stopPropagation(),m(E.filename)},title:Ls(E.filename)?"Remove":"Delete",children:"×"})]},E.filename)})]},w.label)),t.length===0&&c.jsx("div",{className:"sidebar-empty",children:"No documents yet"})]})}function f8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,actions:i,scrollRef:o,searchQuery:l,searchResults:d,onSearchChange:f}){const[h,m]=x.useState([]),[g,v]=x.useState(null),[b,k]=x.useState(null),w=x.useRef(null);x.useEffect(()=>{if(!g)return;const M=L=>{w.current&&!w.current.contains(L.target)&&v(null)};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[g]);const E=(M,L)=>{for(const ee of M)if(ee.type==="container"){if(ee.id===L)return ee;const fe=E(ee.items,L);if(fe)return fe}return null},C=M=>{let L=0;for(const ee of M)ee.type==="doc"?L++:ee.type==="container"&&(L+=C(ee.items));return L},T=M=>{const L=[];for(const ee of M)ee.type==="doc"?L.push(ee.file):ee.type==="container"&&L.push(...T(ee.items));return L},j=x.useMemo(()=>{if(h.length===0)return[];const M=h[h.length-1],L=e.find(fe=>fe.filename===M.wsFilename);if(!(L!=null&&L.workspace))return[];if(M.type==="workspace")return L.workspace.root;const ee=E(L.workspace.root,M.key);return ee?ee.items:[]},[h,e]),_=j.filter(M=>M.type==="container"),A=x.useMemo(()=>{const M=j.filter(L=>L.type==="doc").map(L=>L.file);return t.filter(L=>M.includes(L.filename))},[j,t]),O=M=>{const L=T(M.items);return t.filter(ee=>L.includes(ee.filename))},B=M=>{const L=e.find(fe=>fe.filename===M);if(!(L!=null&&L.workspace))return[];const ee=T(L.workspace.root);return t.filter(fe=>ee.includes(fe.filename))},$=x.useMemo(()=>t.filter(M=>!n.has(M.filename)),[t,n]),W=M=>{m(L=>[...L,M]),v(null)},J=()=>{m(M=>M.slice(0,-1)),v(null)},z=(M,L)=>{if(g===M){v(null);return}const fe=L.currentTarget.getBoundingClientRect();k({top:fe.bottom+4,left:fe.left}),v(M)},G=M=>{s(M),v(null)},D=h.length>1?h[h.length-2].title:"All",U=x.useRef(null),q=x.useRef(null),[se,V]=x.useState(null),te=x.useCallback(M=>{const ee=M.currentTarget.getBoundingClientRect();V({top:ee.bottom+4,left:ee.left})},[]);x.useEffect(()=>{if(!d)return;const M=L=>{q.current&&!q.current.contains(L.target)&&U.current&&!U.current.contains(L.target)&&f("")};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[d,f]);const K=()=>{if(!g)return[];if(g==="__unassigned__")return $;if(g==="__level-docs__")return A;const M=e.find(L=>L.filename===g);if(M)return B(M.filename);for(const L of e){if(!L.workspace)continue;const ee=E(L.workspace.root,g);if(ee)return O(ee)}return[]};return c.jsxs("div",{className:"board-scroll",ref:o,children:[c.jsxs("div",{className:"board-search-pill",children:[c.jsxs("svg",{className:"board-search-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"11",cy:"11",r:"8"}),c.jsx("path",{d:"m21 21-4.3-4.3"})]}),c.jsx("input",{ref:U,className:"board-search-input",type:"text",placeholder:"Search...",value:l,onChange:M=>f(M.target.value),onFocus:te}),l&&c.jsx("button",{className:"board-search-clear",onClick:()=>f(""),children:"×"})]}),h.length===0?c.jsx("button",{className:"board-back board-back--static",tabIndex:-1,children:"All"}):c.jsxs("button",{className:"board-back",onClick:J,title:`Back to ${D}`,children:["← ",D]}),h.length===0&&c.jsxs(c.Fragment,{children:[$.length>0&&c.jsxs("button",{className:`board-chip ${g==="__unassigned__"?"open":""}`,onClick:M=>z("__unassigned__",M),children:["Documents ",c.jsx("span",{className:"board-chip-count",children:$.length})]}),e.map(M=>{var ee;const L=(ee=M.workspace)==null?void 0:ee.root.some(fe=>fe.type==="container");return c.jsxs("button",{className:`board-chip ${g===M.filename?"open":""}`,onClick:fe=>L?W({type:"workspace",key:M.filename,title:M.title,wsFilename:M.filename}):z(M.filename,fe),children:[M.title," ",c.jsx("span",{className:"board-chip-count",children:M.docCount}),L&&c.jsx("span",{className:"board-chip-arrow",children:"›"})]},M.filename)}),c.jsx("button",{className:"board-chip board-chip-add",onClick:i.handleCreateWorkspace,title:"New workspace",children:"+"})]}),h.length>0&&c.jsxs(c.Fragment,{children:[A.length>0&&c.jsxs("button",{className:`board-chip board-chip-docs ${g==="__level-docs__"?"open":""}`,onClick:M=>z("__level-docs__",M),children:["Docs ",c.jsx("span",{className:"board-chip-count",children:A.length})]}),_.map(M=>{const L=M.items.some(ee=>ee.type==="container");return c.jsxs("button",{className:`board-chip ${g===M.id?"open":""}`,onClick:ee=>L?W({type:"container",key:M.id,title:M.name,wsFilename:h[h.length-1].wsFilename}):z(M.id,ee),children:[M.name," ",c.jsx("span",{className:"board-chip-count",children:C(M.items)}),L&&c.jsx("span",{className:"board-chip-arrow",children:"›"})]},M.id)})]}),g&&b&&(()=>{const M=K();return c.jsxs("div",{className:"board-dropdown",ref:w,style:{position:"fixed",top:b.top,left:b.left},children:[M.map(L=>c.jsxs("div",{className:`board-dropdown-item ${L.isActive?"active":""}`,onClick:()=>G(L.filename),children:[c.jsxs("span",{className:"board-dropdown-title",children:[L.title,r.filenames.includes(L.filename)&&c.jsx("span",{className:"board-pending-dot"})]}),c.jsxs("span",{className:"board-dropdown-meta",children:[L.wordCount.toLocaleString()," words · ",ca(L.lastModified)]})]},L.filename)),M.length===0&&c.jsx("div",{className:"board-dropdown-empty",children:"No documents"})]})})(),d&&se&&c.jsxs("div",{className:"board-dropdown board-search-dropdown",ref:q,style:{position:"fixed",top:se.top,left:se.left},children:[d.map(M=>c.jsxs("div",{className:`board-dropdown-item ${M.isActive?"active":""}`,onClick:()=>{s(M.filename),f("")},children:[c.jsx("span",{className:"board-dropdown-title",children:M.title}),M.matchType==="tag"&&M.matchedTag&&c.jsxs("span",{className:"board-dropdown-meta",children:["Tag: ",M.matchedTag]}),M.matchType==="content"&&M.snippet&&c.jsx("span",{className:"board-dropdown-meta board-search-snippet",children:M.snippet}),c.jsxs("span",{className:"board-dropdown-meta",children:[M.wordCount.toLocaleString()," words · ",ca(M.lastModified)]})]},M.filename)),d.length===0&&c.jsx("div",{className:"board-dropdown-empty",children:"No results"})]})]})}function h8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,actions:i,scrollRef:o,searchQuery:l,searchResults:d}){const[f,h]=x.useState([]);if(d!==null)return c.jsx(Xd,{results:d,query:l,onSwitchDocument:s});const m=(j,_)=>{for(const A of j)if(A.type==="container"){if(A.id===_)return A;const O=m(A.items,_);if(O)return O}return null},g=j=>{let _=0;for(const A of j)A.type==="doc"?_++:A.type==="container"&&(_+=g(A.items));return _},v=x.useMemo(()=>{if(f.length===0)return[];const j=f[f.length-1],_=e.find(O=>O.filename===j.wsFilename);if(!(_!=null&&_.workspace))return[];if(j.type==="workspace")return _.workspace.root;const A=m(_.workspace.root,j.key);return A?A.items:[]},[f,e]),b=v.filter(j=>j.type==="container"),k=x.useMemo(()=>{if(f.length===0)return t.filter(_=>!n.has(_.filename));const j=v.filter(_=>_.type==="doc").map(_=>_.file);return t.filter(_=>j.includes(_.filename))},[f,v,t,n]),w=j=>h(_=>[..._,j]),E=()=>h(j=>j.slice(0,-1)),C=f.length>1?f[f.length-2].title:"Shelf",T=f.length>0?f[f.length-1].title:"Documents";return c.jsxs("div",{className:"shelf-wrapper",children:[c.jsxs("div",{className:"shelf-spines",ref:o,children:[f.length>0&&c.jsxs("button",{className:"shelf-back",onClick:E,title:`Back to ${C}`,children:[c.jsx("span",{className:"shelf-back-arrow",children:"←"}),c.jsx("span",{className:"shelf-back-label",children:C})]}),f.length===0&&c.jsxs(c.Fragment,{children:[e.map(j=>c.jsxs("div",{className:"shelf-section-spine",onClick:()=>w({type:"workspace",key:j.filename,title:j.title,wsFilename:j.filename}),title:j.title,children:[c.jsx("span",{className:"shelf-section-title",children:j.title}),c.jsx("span",{className:"shelf-section-count",children:j.docCount})]},j.filename)),c.jsx("button",{className:"shelf-add",onClick:i.handleCreateWorkspace,title:"New workspace",children:"+"})]}),f.length>0&&b.map(j=>c.jsxs("div",{className:"shelf-section-spine shelf-section-container",onClick:()=>w({type:"container",key:j.id,title:j.name,wsFilename:f[f.length-1].wsFilename}),title:j.name,children:[c.jsx("span",{className:"shelf-section-title",children:j.name}),c.jsx("span",{className:"shelf-section-count",children:g(j.items)})]},j.id))]}),c.jsxs("div",{className:"shelf-docs",children:[c.jsx("div",{className:"shelf-docs-header",children:T}),c.jsxs("div",{className:"shelf-docs-list",children:[k.map(j=>c.jsxs("div",{className:`shelf-doc-item ${j.isActive?"active":""}`,onClick:()=>s(j.filename),children:[c.jsxs("div",{className:"shelf-doc-title",children:[c.jsx("span",{children:j.title}),r.filenames.includes(j.filename)&&c.jsx("span",{className:"shelf-pending-dot"})]}),c.jsxs("div",{className:"shelf-doc-meta",children:[j.wordCount.toLocaleString()," words · ",ca(j.lastModified)]})]},j.filename)),k.length===0&&c.jsx("div",{className:"shelf-docs-empty",children:"No documents"})]})]})]})}async function kk(t,e={}){var s,i;const r=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:t,arguments:e})})).json();if((i=(s=r==null?void 0:r.content)==null?void 0:s[0])!=null&&i.text)try{return JSON.parse(r.content[0].text)}catch{return r.content[0].text}return r}function _2({filename:t,title:e,isActive:n,onSwitchDocument:r,onClose:s}){const[i,o]=x.useState("loading"),[l,d]=x.useState([]),[f,h]=x.useState(null),[m,g]=x.useState(null),[v,b]=x.useState(null);x.useEffect(()=>{kk("list_blog_sites").then(E=>{if(E.error){g(E.error),o("error");return}const C=E.sites||[];d(C),C.length===0?o("pick"):C.length===1?(h(C[0].id),o("confirm")):o("pick")}).catch(E=>{g((E==null?void 0:E.message)||"Failed to load blog sites"),o("error")})},[]);const k=l.find(E=>E.id===f)||null,w=async()=>{if(k){o("posting"),g(null),n||(r(t),await new Promise(E=>setTimeout(E,350)));try{const E=await kk("post_to_blog",{site_id:k.id});if(E!=null&&E.error){g(E.error),o("error");return}const C=E.commit?`https://github.com/${k.owner}/${k.repo}/commit/${E.commit}`:void 0;b({...E,url:C}),o("done")}catch(E){g((E==null?void 0:E.message)||"Publish failed"),o("error")}}};return c.jsx("div",{className:"post-blog-overlay",onClick:()=>{i!=="posting"&&s()},children:c.jsxs("div",{className:"post-blog-modal",onClick:E=>E.stopPropagation(),children:[c.jsxs("div",{className:"post-blog-modal-header",children:[c.jsx("h3",{children:"Post to Blog"}),c.jsx("button",{className:"post-blog-modal-close",onClick:s,disabled:i==="posting",children:"×"})]}),c.jsx("div",{className:"post-blog-modal-doc",children:e}),i==="loading"&&c.jsx("div",{className:"post-blog-modal-loading",children:"Loading blog sites…"}),i==="pick"&&l.length===0&&c.jsxs("div",{className:"post-blog-modal-empty",children:["No blog sites registered. Add one in ",c.jsx("strong",{children:"Settings → Plugins → GitHub"})," first.",c.jsx("button",{className:"post-blog-modal-done",onClick:s,children:"Close"})]}),i==="pick"&&l.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"post-blog-modal-label",children:"Choose a destination"}),c.jsx("div",{className:"post-blog-modal-sites",children:l.map(E=>c.jsxs("button",{className:`post-blog-modal-site${f===E.id?" post-blog-modal-site--selected":""}`,onClick:()=>{h(E.id),o("confirm")},children:[c.jsx("div",{className:"post-blog-modal-site-label",children:E.label}),c.jsxs("div",{className:"post-blog-modal-site-repo",children:[E.owner,"/",E.repo,"@",E.branch]})]},E.id))})]}),i==="confirm"&&k&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"post-blog-modal-confirm",children:["Publish to ",c.jsxs("strong",{children:[k.owner,"/",k.repo,"@",k.branch]}),"?",c.jsxs("div",{className:"post-blog-modal-target-dir",children:["→ ",k.content_dir]})]}),c.jsxs("div",{className:"post-blog-modal-actions",children:[c.jsx("button",{className:"post-blog-modal-btn post-blog-modal-btn--primary",onClick:w,children:"Publish now"}),l.length>1&&c.jsx("button",{className:"post-blog-modal-btn",onClick:()=>o("pick"),children:"Back"}),c.jsx("button",{className:"post-blog-modal-btn",onClick:s,children:"Cancel"})]})]}),i==="posting"&&c.jsx("div",{className:"post-blog-modal-loading",children:"Publishing…"}),i==="done"&&v&&c.jsxs("div",{className:"post-blog-modal-result post-blog-modal-result--success",children:[c.jsx("div",{children:v.message||"Published"}),v.file&&c.jsx("div",{className:"post-blog-modal-meta",children:v.file}),typeof v.images_committed=="number"&&v.images_committed>0&&c.jsxs("div",{className:"post-blog-modal-meta",children:[v.images_committed," image",v.images_committed===1?"":"s"," committed"]}),c.jsxs("div",{className:"post-blog-modal-actions",children:[v.url&&c.jsx("button",{className:"post-blog-modal-btn post-blog-modal-btn--primary",onClick:()=>window.open(v.url,"_blank"),children:"View commit"}),c.jsx("button",{className:"post-blog-modal-btn",onClick:s,children:"Done"})]})]}),i==="error"&&c.jsxs("div",{className:"post-blog-modal-result post-blog-modal-result--error",children:[c.jsx("div",{children:m||"Publish failed"}),c.jsx("div",{className:"post-blog-modal-actions",children:c.jsx("button",{className:"post-blog-modal-btn",onClick:s,children:"Close"})})]})]})})}const p8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M20 20H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h4l2 2h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2z"}),c.jsx("line",{x1:"9",y1:"14",x2:"15",y2:"14",opacity:"0.5"})]}),m8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("polyline",{points:"14 2 14 8 20 8"}),c.jsx("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),c.jsx("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),g8=()=>c.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),v8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:[c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",opacity:"0.5"}),c.jsx("path",{d:"M7 15l-4-3.5L7 8",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),y8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:[c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",opacity:"0.5"}),c.jsx("path",{d:"M3 8V6.5C3 5.67 3.67 5 4.5 5h2C7.33 5 8 5.67 8 6.5V8c0 2-1.5 3-3 3",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),b8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:[c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",opacity:"0.5"}),c.jsx("rect",{x:"2",y:"16",width:"8",height:"7",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5"}),c.jsx("line",{x1:"4",y1:"18.5",x2:"8",y2:"18.5",stroke:"currentColor",strokeWidth:"1",opacity:"0.7"}),c.jsx("line",{x1:"4",y1:"20.5",x2:"7",y2:"20.5",stroke:"currentColor",strokeWidth:"1",opacity:"0.7"})]}),x8=()=>c.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:c.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 0 1-2.063-2.065 2.064 2.064 0 1 1 2.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"})}),w8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),c.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),k8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("path",{d:"M2 12h20"}),c.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]}),Sk=()=>c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})});function S8({type:t}){switch(t){case"tweet":return c.jsx(g8,{});case"reply":return c.jsx(v8,{});case"quote":return c.jsx(y8,{});case"article":return c.jsx(b8,{});case"linkedin":return c.jsx(x8,{});case"newsletter":return c.jsx(w8,{});case"blog":return c.jsx(k8,{});default:return c.jsx(m8,{})}}function Ou(t){let e=0;for(const n of t)n.type==="doc"?e++:n.type==="container"&&(e+=Ou(n.items));return e}function T2(t,e){for(const n of t){if(n.type==="doc"&&n.file===e)return[];if(n.type==="container"){const r=T2(n.items,e);if(r)return[n.id,...r]}}return null}function Op(t){const e=new Set;return Tl(t,e),[...e]}function j2(t,e,n=0){for(const r of t)if(r.type==="container"){if(r.id===e)return n;const s=j2(r.items,e,n+1);if(s>=0)return s}return-1}function E8(t,e){if(!e)return 12;for(const n of t){if(!n.workspace)continue;const r=j2(n.workspace.root,e);if(r>=0)return 12+(r+1)*16}return 12}function N8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,onCreateDocument:i,actions:o,scrollRef:l,writingTitle:d,writingTarget:f,pendingWriteFilenames:h,searchQuery:m,searchResults:g,onSearchChange:v}){var Ie,Me,qe;const b=F=>!!h&&h.has(F),[k,w]=x.useState(()=>{try{const F=localStorage.getItem("ow-files-collapsed");return F?new Set(JSON.parse(F)):new Set}catch{return new Set}}),{draggedItem:E,dropIndicator:C,handlePointerDown:T,dropClass:j,isDragging:_,isContainerDropTarget:A}=k2({docs:t,workspaces:e,assignedFiles:n,scrollRef:l,setCollapsedSections:w}),O=F=>!C||C.itemId!==F||C.position==="inside"?void 0:{"--drop-indent":`${E8(e,C.containerId)}px`},{variantsByMaster:B,variantFilenames:$}=x.useMemo(()=>{const F=new Map,ce=new Set;for(const Ne of t)if(Ne.masterDocId){const P=F.get(Ne.masterDocId)||[];P.push(Ne),F.set(Ne.masterDocId,P),ce.add(Ne.filename)}return{variantsByMaster:F,variantFilenames:ce}},[t]),[W,J]=x.useState(null),[z,G]=x.useState(null),[D,U]=x.useState(new Set),[q,se]=x.useState(null),[V,te]=x.useState([]),[K,M]=x.useState(!1),[L,ee]=x.useState(null),[fe,ge]=x.useState(null),[oe,xe]=x.useState(null),[we,We]=x.useState(null),[He,Ze]=x.useState(null),[Oe,Ke]=x.useState(null),[pt,Je]=x.useState(new Set);x.useEffect(()=>{Je(new Set)},[r]);const pe=x.useCallback(()=>{fetch("/api/plugins").then(F=>F.json()).then(F=>{const ce=[];let Ne=!1;for(const P of F.plugins||[]){const Z=P.displayName||void 0;for(const I of P.sidebarMenuItems||[])ce.push({...I,pluginDisplayName:Z});P.name==="@openwriter/plugin-publish"&&P.enabled&&(Ne=!0)}te(ce),M(Ne)}).catch(()=>{})},[]);x.useEffect(()=>{pe()},[pe]),x.useEffect(()=>{const F=()=>pe();return window.addEventListener("ow-plugins-changed",F),()=>window.removeEventListener("ow-plugins-changed",F)},[pe]);const mt=x.useCallback((F,ce)=>{if(F.preventDefault(),F.stopPropagation(),D.has(ce.filename)&&D.size>1){G({x:F.clientX,y:F.clientY,filename:ce.filename,title:ce.title,bulkCount:D.size});return}D.size>0&&!D.has(ce.filename)&&U(new Set),G({x:F.clientX,y:F.clientY,filename:ce.filename,title:ce.title,docId:ce.docId,lastSent:ce.lastSent,postedUrl:ce.postedUrl,isNewsletter:ce.isNewsletter,contentType:ce.contentType,sortRequest:ce.sortRequest})},[D]),ft=x.useCallback(F=>{fetch("/api/documents/duplicate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:F})}).catch(()=>{})},[]),at=x.useCallback((F,ce,Ne,P,Z)=>{if(ce.promptForFocus&&Z===void 0){ee({action:F,label:ce.label,filename:Ne,title:P});return}fetch("/api/plugins/sidebar-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:F,filename:Ne,title:P,instructions:Z||"",label:ce.label})}).catch(()=>{})},[]),nt=x.useCallback((F,ce)=>{Je(Ne=>{const P=new Set(Ne);for(const Z of F)P.add(Z);return P}),fetch("/api/documents/batch-resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filenames:F,action:ce})}).catch(()=>{})},[]),ht=F=>{w(ce=>{const Ne=new Set(ce);return Ne.has(F)?Ne.delete(F):Ne.add(F),localStorage.setItem("ow-files-collapsed",JSON.stringify([...Ne])),Ne})},Fe=(F,ce,Ne,P)=>{J({type:F,key:ce,value:Ne,wsFilename:P})},ve=()=>{if(!W)return;const{type:F,key:ce,value:Ne,wsFilename:P}=W;F==="doc"?o.handleRename(ce,"",Ne):F==="workspace"?o.handleRenameWorkspace(ce,Ne):F==="container"&&P&&o.handleRenameContainer(P,ce,Ne),J(null)},X=t.find(F=>F.isActive),Be=x.useRef(e);Be.current=e,x.useEffect(()=>{var F;if(X)for(const ce of Be.current){const Ne=T2(((F=ce.workspace)==null?void 0:F.root)||[],X.filename);if(Ne){w(P=>{const Z=[ce.filename,...Ne.map(re=>`container-${re}`)];if(Z.every(re=>!P.has(re)))return P;const I=new Set(P);for(const re of Z)I.delete(re);return localStorage.setItem("ow-files-collapsed",JSON.stringify([...I])),I});break}}},[X==null?void 0:X.filename]);const ne=x.useMemo(()=>t.filter(F=>!n.has(F.filename)&&!$.has(F.filename)&&!b(F.filename)),[t,n,$,h]),de=x.useMemo(()=>{var P;const F=[],ce=Z=>{F.push(Z.filename);const I=Z.docId?B.get(Z.docId):void 0,re=Z.docId&&!k.has(`variants-${Z.docId}`);if(I&&re)for(const ye of I)F.push(ye.filename)},Ne=Z=>{for(const I of Z)if(I.type==="doc"){const re=t.find(ye=>ye.filename===I.file);re&&!$.has(re.filename)&&ce(re)}else k.has(`container-${I.id}`)||Ne(I.items)};k.has("docs")||ne.forEach(ce);for(const Z of e)k.has(Z.filename)||Ne(((P=Z.workspace)==null?void 0:P.root)||[]);return F},[t,e,ne,$,B,k]),he=x.useCallback(()=>{U(new Set)},[]),Ge=x.useCallback((F,ce)=>{if(E)return;const Ne=F.shiftKey,P=F.ctrlKey||F.metaKey;if(Ne){const I=q||(X==null?void 0:X.filename)||ce,re=de.indexOf(I),ye=de.indexOf(ce);if(re<0||ye<0){U(new Set([ce])),se(ce);return}const[Te,Se]=re<ye?[re,ye]:[ye,re];U(new Set(de.slice(Te,Se+1)));return}if(P){U(I=>{const re=new Set(I);return re.has(ce)?re.delete(ce):re.add(ce),re}),se(ce);return}U(new Set),se(ce);const Z=t.find(I=>I.filename===ce);Z&&!Z.isActive&&s(ce)},[E,q,X==null?void 0:X.filename,de,s,t]);x.useEffect(()=>{if(D.size===0)return;const F=ce=>{ce.key==="Escape"&&he()};return document.addEventListener("keydown",F),()=>document.removeEventListener("keydown",F)},[D.size,he]);const Pe=x.useCallback(()=>{for(const F of D)o.handleDelete(F);U(new Set),se(null)},[D,o]),et=x.useCallback(F=>{F.length!==0&&fetch("/api/documents/sort-request",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filenames:F})}).then(()=>o.fetchDocs()).catch(()=>{})},[o]),ot=x.useCallback(F=>{fetch("/api/documents/sort-reject",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:F})}).then(()=>o.fetchDocs()).catch(()=>{})},[o]),bt=x.useCallback(F=>{fetch("/api/documents/sort-accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:F})}).then(()=>o.fetchDocs()).catch(()=>{})},[o]);if(g!==null)return c.jsx(Xd,{results:g,query:m,onSwitchDocument:s,actions:o});const Ye=F=>c.jsx("input",{className:"sidebar-rename-input",value:W.value,onChange:ce=>J(Ne=>Ne?{...Ne,value:ce.target.value}:null),onBlur:F,onKeyDown:ce=>{ce.key==="Enter"&&F(),ce.key==="Escape"&&J(null)},autoFocus:!0,onClick:ce=>ce.stopPropagation()}),it=(F,ce,Ne,P,Z,I=!1)=>c.jsxs("div",{className:`files-row${F.isActive?" active":""}${D.has(F.filename)?" selected":""} ${_(F.filename)?"dragging":""} ${j(F.filename)}${F.masterDocId?" is-variant":""}`,style:{paddingLeft:ce,...O(F.filename)},"data-drag-id":F.filename,"data-drag-type":"doc","data-drag-ws":Ne||"__docs__","data-drag-container":P||"",onPointerDown:re=>T(re,{type:"doc",file:F.filename,sourceWs:Ne||null},F.title),onClick:re=>Ge(re,F.filename),onDoubleClick:()=>Fe("doc",F.filename,F.title),onContextMenu:re=>mt(re,F),children:[c.jsx("span",{className:"files-row-icon",children:c.jsx(S8,{type:F.contentType})}),(W==null?void 0:W.type)==="doc"&&W.key===F.filename?Ye(ve):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"files-row-label",children:F.title}),F.variantType&&c.jsx("span",{className:"files-badge-variant",children:F.variantType}),(F.autoAccept===!0||F.autoAccept!==!1&&I)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:F.autoAccept===!0?"Auto-accept on":"Auto-accept inherited"}),r.filenames.includes(F.filename)&&!pt.has(F.filename)&&c.jsx("span",{className:"files-badge-pending"}),F.sortRequest&&(F.sortRequest.proposal?c.jsx("span",{className:"files-badge-sort-proposal",title:"Sort proposal ready — right-click to review"}):c.jsx("span",{className:"files-badge-sort-pending",title:"Sort requested"})),o.getDocTags(F.filename).includes("✓")&&c.jsx("span",{className:"files-badge-approved",children:c.jsx(Sk,{})}),F.lastSent&&c.jsx("span",{className:"files-badge-sent",children:c.jsx(Sk,{})}),Z&&c.jsx("span",{className:`files-row-chevron${k.has(`variants-${F.docId}`)?" collapsed":""}`,onClick:re=>{re.stopPropagation(),ht(`variants-${F.docId}`)},children:c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})})]})]},F.filename),gt=(F,ce,Ne,P,Z=!1)=>{const I=F.docId?B.get(F.docId):void 0,re=!!(I&&I.length>0),ye=d&&(f==null?void 0:f.parentDocId)&&f.parentDocId===F.docId,Te=re||ye,Se=!k.has(`variants-${F.docId}`);return Te?c.jsxs("div",{className:"files-variant-group",children:[it(F,ce,Ne,P,re,Z),Se&&(I==null?void 0:I.map(Ee=>it(Ee,ce+16,Ne,P,!1,Z))),ye&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:ce+16},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]})]},`vg-${F.filename}`):it(F,ce,Ne,P,!1,Z)},Nt=(F,ce,Ne,P,Z=!1)=>{const I=12+ce*16;if(F.type==="doc"){const ke=t.find(Ct=>Ct.filename===F.file);return!ke||$.has(ke.filename)?null:gt(ke,I,Ne,P,Z)}const re=F,ye=`container-${re.id}`,Te=k.has(ye),Se=Ou(re.items),Ee=re.autoAccept===!0,me=Ee||Z;return c.jsxs("div",{className:`${j(re.id)} ${A(re.id)?"files-drop-inside":""}`,children:[c.jsxs("div",{className:`files-row is-container ${_(re.id)?"dragging":""} ${j(re.id)}`,style:{paddingLeft:I,...O(re.id)},"data-drag-id":re.id,"data-drag-type":"container-header","data-drag-ws":Ne,"data-drag-parent":P||"","data-section-key":ye,onPointerDown:ke=>T(ke,{type:"container",id:re.id,sourceWs:Ne},re.name),onClick:()=>!E&&ht(ye),onDoubleClick:ke=>{ke.stopPropagation(),Fe("container",re.id,re.name,Ne)},onContextMenu:ke=>{ke.preventDefault(),ke.stopPropagation(),Ke({x:ke.clientX,y:ke.clientY,type:"container",wsFilename:Ne,containerId:re.id,title:re.name,nodes:re.items,autoAccept:Ee})},children:[c.jsx("span",{className:"files-row-icon",children:c.jsx(p8,{})}),(W==null?void 0:W.type)==="container"&&W.key===re.id?Ye(ve):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"files-row-label",children:re.name}),me&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:Ee?"Auto-accept on for this container":"Auto-accept inherited from workspace"}),c.jsx("span",{className:"files-row-count",children:Se})]})]}),c.jsxs("div",{className:`files-children${Te?" collapsed":""}`,"data-drop-ws":Ne,"data-drop-container":re.id,children:[d&&!(f!=null&&f.parentDocId)&&(f==null?void 0:f.wsFilename)===Ne&&f.containerId===re.id&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:12+(ce+1)*16},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),re.items.filter(ke=>ke.type!=="doc"||!b(ke.file)).map(ke=>Nt(ke,ce+1,Ne,re.id,me))]})]},re.id)};return c.jsxs("div",{className:"files-scroll",ref:l,children:[c.jsxs("div",{className:"files-section",children:[c.jsxs("div",{className:"files-row is-section","data-section-key":"docs",onClick:()=>ht("docs"),children:[c.jsx("span",{className:`files-row-chevron leading${k.has("docs")?" collapsed":""}`,children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),c.jsx("span",{className:"files-row-label",children:"Documents"}),c.jsx("button",{className:"files-section-btn",onClick:F=>{F.stopPropagation(),Ze({anchor:F.target.getBoundingClientRect()})},title:"New document",children:"+"})]}),c.jsxs("div",{className:`files-section-list files-children${k.has("docs")?" collapsed":""}`,"data-drop-ws":"__docs__",children:[d&&!(f!=null&&f.parentDocId)&&(!f||!e.some(F=>F.filename===(f==null?void 0:f.wsFilename)))&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:28},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ne.map(F=>gt(F,28))]})]}),e.map(F=>{var I,re,ye;const ce=((I=F.workspace)==null?void 0:I.root)||[],Ne=k.has(F.filename),P=Ou(ce),Z=((re=F.workspace)==null?void 0:re.autoAccept)===!0||F.autoAccept===!0;return c.jsxs("div",{className:`files-section ${_(F.filename)?"dragging":""} ${(C==null?void 0:C.itemId)===F.filename?C.position==="before"?"files-ws-drop-before":"files-ws-drop-after":""}`,children:[c.jsx("div",{className:`files-row is-section${(C==null?void 0:C.itemId)==="__section__"&&C.wsFilename===F.filename&&C.position==="inside"?" files-ws-drop-target":""}`,"data-section-key":F.filename,"data-ws-drag":F.filename,onPointerDown:Te=>T(Te,{type:"workspace",filename:F.filename},F.title),onClick:()=>!E&&ht(F.filename),onDoubleClick:Te=>{Te.stopPropagation(),Fe("workspace",F.filename,F.title)},onContextMenu:Te=>{var Se;Te.preventDefault(),Te.stopPropagation(),Ke({x:Te.clientX,y:Te.clientY,type:"workspace",wsFilename:F.filename,title:F.title,nodes:ce,autoAccept:((Se=F.workspace)==null?void 0:Se.autoAccept)===!0||F.autoAccept===!0})},children:(W==null?void 0:W.type)==="workspace"&&W.key===F.filename?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:`files-row-chevron leading${Ne?" collapsed":""}`,children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),Ye(ve)]}):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:`files-row-chevron leading${Ne?" collapsed":""}`,children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),c.jsx("span",{className:"files-row-label",children:F.title}),(((ye=F.workspace)==null?void 0:ye.autoAccept)===!0||F.autoAccept===!0)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:"Auto-accept on for this workspace"}),c.jsx("span",{className:"files-row-count",children:P}),c.jsxs("div",{className:"files-section-actions",children:[c.jsx("button",{className:"files-section-btn",onClick:Te=>{Te.stopPropagation(),Ze({anchor:Te.target.getBoundingClientRect(),wsFilename:F.filename,containerId:null})},title:"New document",children:"+"}),c.jsx("button",{className:"files-section-btn",onClick:Te=>{Te.stopPropagation(),o.handleCreateContainer(F.filename,null)},title:"New container",children:"☐"})]})]})}),c.jsxs("div",{className:`files-section-list files-children${Ne?" collapsed":""}`,"data-drop-ws":F.filename,children:[d&&!(f!=null&&f.parentDocId)&&(f==null?void 0:f.wsFilename)===F.filename&&f.containerId===null&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:28},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ce.filter(Te=>Te.type!=="doc"||!b(Te.file)).map(Te=>Nt(Te,1,F.filename,null,Z))]})]},F.filename)}),c.jsx("div",{className:"files-new-ws",children:c.jsx("button",{onClick:o.handleCreateWorkspace,children:"+ New Workspace"})}),Oe&&c.jsx(Ad,{x:Oe.x,y:Oe.y,filename:Oe.wsFilename,title:Oe.title,onClose:()=>Ke(null),onDuplicate:()=>{},onRename:()=>{Oe.type==="workspace"?Fe("workspace",Oe.wsFilename,Oe.title):Oe.containerId&&Fe("container",Oe.containerId,Oe.title,Oe.wsFilename),Ke(null)},onArchive:()=>{},onDelete:()=>{Oe.type==="workspace"?o.handleDeleteWorkspace(Oe.wsFilename):Oe.containerId&&o.handleDeleteContainer(Oe.wsFilename,Oe.containerId,!1)},folderDocCount:Oe.type==="container"?Ou(Oe.nodes):0,onDeleteWithDocs:Oe.type==="container"&&Oe.containerId?()=>{o.handleDeleteContainer(Oe.wsFilename,Oe.containerId,!0)}:void 0,onPluginAction:()=>{},pluginItems:[],folderMode:!0,onNewDoc:F=>{Ze({anchor:F.target.getBoundingClientRect(),wsFilename:Oe.wsFilename,containerId:Oe.type==="container"?Oe.containerId:null}),Ke(null)},onNewContainer:()=>{o.handleCreateContainer(Oe.wsFilename,Oe.type==="container"?Oe.containerId:null),Ke(null)},onAcceptAll:()=>{const F=Op(Oe.nodes);F.length&&nt(F,"accept"),Ke(null)},onRejectAll:()=>{const F=Op(Oe.nodes);F.length&&nt(F,"reject"),Ke(null)},folderAutoAccept:Oe.autoAccept,folderAutoAcceptLabel:Oe.type==="workspace"?"for workspace":"for container",onToggleFolderAutoAccept:()=>{fetch("/api/auto-accept/inherit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wsFile:Oe.wsFilename,...Oe.type==="container"?{containerId:Oe.containerId}:{},enabled:!Oe.autoAccept})}).catch(()=>{})},onRequestSortAll:()=>{const F=Op(Oe.nodes);F.length&&et(F)}}),z&&c.jsx(Ad,{x:z.x,y:z.y,filename:z.filename,title:z.title,bulkCount:z.bulkCount,onBulkDelete:Pe,onBulkRequestSort:z.bulkCount?()=>et([...D]):void 0,onClose:()=>G(null),onDuplicate:()=>ft(z.filename),onCreateVariant:z.docId?F=>{fetch("/api/documents/variant",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:z.filename,masterDocId:z.docId,variantType:F})}).catch(()=>{})}:void 0,onRename:()=>{Fe("doc",z.filename,z.title),G(null)},onArchive:()=>o.handleArchive(z.filename),onDelete:()=>o.handleDelete(z.filename),onPluginAction:(F,ce)=>at(F,ce,z.filename,z.title),pluginItems:V,onSchedulePost:K?()=>{ge({filename:z.filename,title:z.title}),G(null)}:void 0,onPostNow:z.contentType==="blog"?()=>{const F=(X==null?void 0:X.filename)===z.filename;xe({filename:z.filename,title:z.title,isActive:F}),G(null)}:void 0,isAlreadyPublished:z.contentType==="blog"&&!!z.postedUrl,onViewAnalytics:z.docId&&z.lastSent&&(z.postedUrl||z.isNewsletter)?()=>{z.isNewsletter?We({docId:z.docId,title:z.title}):z.postedUrl&&window.open(z.postedUrl,"_blank"),G(null)}:void 0,viewAnalyticsLabel:z.isNewsletter?"View Analytics":z.contentType==="blog"&&z.postedUrl?"View Post":z.postedUrl?"View on X":"View Analytics",isApproved:o.getDocTags(z.filename).includes("✓"),onToggleApprove:()=>{o.getDocTags(z.filename).includes("✓")?o.handleRemoveTag(z.filename,"✓"):(o.handleAddTag(z.filename,"✓"),setTimeout(()=>window.dispatchEvent(new CustomEvent("ow-accept-all")),50))},isAutoAccept:(()=>{var ce;const F=(ce=t.find(Ne=>Ne.filename===z.filename))==null?void 0:ce.autoAccept;return F===!0?!0:F===!1?!1:Md(e,z.filename)})(),onToggleAutoAccept:()=>{var Ne;const F=(Ne=t.find(P=>P.filename===z.filename))==null?void 0:Ne.autoAccept,ce=F===!0?!0:F===!1?!1:Md(e,z.filename);fetch("/api/auto-accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:z.filename,enabled:!ce})}).then(()=>o.fetchDocs()).catch(()=>{})},isAlreadySent:!!z.lastSent,onMarkSent:()=>{const F=z.filename;o.getDocTags(F).includes("✓")&&o.handleRemoveTag(F,"✓"),s(F),setTimeout(()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({manualPost:{postedAt:new Date().toISOString()}})}).then(()=>o.fetchDocs()).catch(()=>{})},100),G(null)},sortState:z.bulkCount?void 0:(Ie=z.sortRequest)!=null&&Ie.proposal?"proposal":z.sortRequest?"pending":"none",sortProposalLabel:(()=>{var I;const F=(I=z.sortRequest)==null?void 0:I.proposal;if(!F)return;const ce=e.find(re=>re.filename===F.wsFilename),Ne=(ce==null?void 0:ce.title)||F.wsFilename;if(!F.containerId)return Ne;const P=re=>{for(const ye of re){if(ye.type==="container"&&ye.id===F.containerId)return ye.name;if(ye.type==="container"){const Te=P(ye.items);if(Te)return Te}}return null},Z=ce!=null&&ce.workspace?P(ce.workspace.root):null;return Z?`${Ne} / ${Z}`:Ne})(),sortProposalReasoning:(qe=(Me=z.sortRequest)==null?void 0:Me.proposal)==null?void 0:qe.reasoning,onRequestSort:z.bulkCount?void 0:()=>et([z.filename]),onCancelSort:()=>ot(z.filename),onAcceptSortProposal:()=>bt(z.filename),onRejectSortProposal:()=>ot(z.filename)}),L&&c.jsx(S2,{actionLabel:L.label,docTitle:L.title,onClose:()=>ee(null),onConfirm:F=>{const ce=V.find(Ne=>Ne.action===L.action);ce&&at(L.action,ce,L.filename,L.title,F),ee(null)}}),we&&c.jsx(E2,{docId:we.docId,title:we.title,onClose:()=>We(null)}),fe&&c.jsx(Dl,{filename:fe.filename,title:fe.title,onClose:()=>ge(null)}),oe&&c.jsx(_2,{filename:oe.filename,title:oe.title,isActive:oe.isActive,onSwitchDocument:s,onClose:()=>xe(null)}),He&&c.jsx(N2,{anchorRect:He.anchor,onClose:()=>Ze(null),onSelect:F=>{Ze(null),He.wsFilename?o.handleCreateInWorkspace(He.wsFilename,He.containerId??null,F):F?fetch("/api/documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({metadata:F})}).catch(()=>{}):i()}})]})}const C8=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],_8=[{value:"any",label:"Any"},{value:"content_type",label:"Content Type"},{value:"connection",label:"Connection"}],M2=["America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Anchorage","Pacific/Honolulu","America/Phoenix","America/Toronto","America/Vancouver","America/Sao_Paulo","America/Mexico_City","Europe/London","Europe/Paris","Europe/Berlin","Europe/Amsterdam","Europe/Rome","Europe/Madrid","Europe/Moscow","Asia/Tokyo","Asia/Shanghai","Asia/Kolkata","Asia/Dubai","Asia/Singapore","Asia/Seoul","Australia/Sydney","Australia/Melbourne","Pacific/Auckland"];function Ek(t){var e;try{const n=new Date,i=((e=new Intl.DateTimeFormat("en-US",{timeZone:t,timeZoneName:"short"}).formatToParts(n).find(l=>l.type==="timeZoneName"))==null?void 0:e.value)||"";return`${t.split("/").pop().replace(/_/g," ")} (${i})`}catch{return t}}function T8(t){if(t.length>0)return t[0].timezone;try{const e=Intl.DateTimeFormat().resolvedOptions().timeZone;if(M2.includes(e))return e}catch{}return"America/New_York"}function j8({slots:t,onBack:e}){const[n,r]=x.useState(t),[s,i]=x.useState(()=>T8(t)),[o,l]=x.useState(!1),[d,f]=x.useState("09:00"),[h,m]=x.useState(["default"]),[g,v]=x.useState("any"),[b,k]=x.useState(!1),w=x.useRef(null);x.useEffect(()=>{if(!o)return;function _(A){w.current&&!w.current.contains(A.target)&&l(!1)}return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[o]);async function E(_){i(_);const A=[];for(const O of n){const B=await fetch(`/api/scheduler/slots/${O.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({timezone:_})});if(B.ok){const $=await B.json();A.push($.slot)}else A.push(O)}A.length>0&&r(A)}async function C(){const _=await fetch("/api/scheduler/slots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({time:d,days:h.includes("default")?["default"]:h,filter_type:g,timezone:s})});if(_.ok){const A=await _.json();r(O=>[...O,A.slot]),k(!1),f("09:00"),m(["default"]),v("any")}}async function T(_){(await fetch(`/api/scheduler/slots/${_}`,{method:"DELETE"})).ok&&r(O=>O.filter(B=>B.id!==_))}function j(_){m(A=>{if(_==="default")return["default"];const O=A.filter(B=>B!=="default");if(O.includes(_)){const B=O.filter($=>$!==_);return B.length===0?["default"]:B}return[...O,_]})}return c.jsxs("div",{className:"sidebar-schedule",children:[c.jsxs("div",{className:"sidebar-schedule-header",children:[c.jsx("button",{className:"sidebar-schedule-btn",onClick:e,title:"Back",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Slot Settings"}),c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>k(!b),children:b?"Cancel":"+ Add"})]}),c.jsxs("div",{className:"slot-tz",ref:w,children:[c.jsx("label",{className:"slot-tz-label",children:"Timezone"}),c.jsxs("button",{className:"slot-tz-trigger",onClick:()=>l(!o),children:[c.jsx("span",{children:Ek(s)}),c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`slot-tz-chevron ${o?"slot-tz-chevron--open":""}`,children:c.jsx("path",{d:"m6 9 6 6 6-6"})})]}),o&&c.jsx("div",{className:"slot-tz-dropdown",children:M2.map(_=>c.jsx("div",{className:`slot-tz-option ${_===s?"active":""}`,onClick:()=>{E(_),l(!1)},children:Ek(_)},_))})]}),b&&c.jsxs("div",{className:"slot-add-form",children:[c.jsxs("div",{className:"slot-add-row",children:[c.jsx("input",{type:"time",className:"slot-input",value:d,onChange:_=>f(_.target.value)}),c.jsx("select",{className:"slot-input",value:g,onChange:_=>v(_.target.value),children:_8.map(_=>c.jsx("option",{value:_.value,children:_.label},_.value))})]}),c.jsxs("div",{className:"slot-add-days",children:[c.jsx("button",{className:`sidebar-schedule-btn slot-day-btn ${h.includes("default")?"sidebar-schedule-btn--active":""}`,onClick:()=>j("default"),children:"Every day"}),C8.map(_=>c.jsx("button",{className:`sidebar-schedule-btn slot-day-btn ${h.includes(_.toLowerCase())?"sidebar-schedule-btn--active":""}`,onClick:()=>j(_.toLowerCase()),children:_},_))]}),c.jsx("button",{className:"sidebar-schedule-btn sidebar-schedule-btn--active slot-create-btn",onClick:C,children:"Create Slot"})]}),c.jsx("div",{className:"slot-list",children:n.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No slots"}),c.jsx("div",{className:"schedule-empty-desc",children:"Create time slots to define your posting schedule."})]}):n.map(_=>c.jsxs("div",{className:"schedule-item slot-item",children:[c.jsx("div",{className:"schedule-item-time slot-item-time",children:M8(_.time)}),c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:_.days.includes("default")?"Every day":_.days.join(", ")}),c.jsxs("div",{className:"schedule-item-meta",children:[c.jsxs("span",{children:["Filter: ",_.filter_type]}),_.filter_value&&c.jsxs("span",{children:["(",_.filter_value,")"]})]})]}),c.jsx("button",{className:"schedule-item-action schedule-item-action--danger slot-delete-btn",onClick:()=>T(_.id),title:"Delete slot",children:"×"})]},_.id))})]})}function M8(t){const[e,n]=t.split(":").map(Number),r=e>=12?"PM":"AM";return`${e%12||12}:${String(n).padStart(2,"0")} ${r}`}function A8({onBack:t}){const[e,n]=x.useState([]),[r,s]=x.useState([]),[i,o]=x.useState(null),[l,d]=x.useState(!1),[f,h]=x.useState(!0),m=x.useCallback(async()=>{try{const[E,C]=await Promise.all([fetch("/api/scheduler/autoplugs/goals"),fetch("/api/scheduler/autoplugs/tracking")]);if(E.ok){const T=await E.json();n(T.goals||[])}if(C.ok){const T=await C.json();s(T.tracking||[])}}catch{}h(!1)},[]);x.useEffect(()=>{m()},[m]);const g=async E=>{(await fetch(`/api/scheduler/autoplugs/goals/${E.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!E.enabled})})).ok&&n(T=>T.map(j=>j.id===E.id?{...j,enabled:!j.enabled}:j))},v=async E=>{(await fetch(`/api/scheduler/autoplugs/goals/${E}`,{method:"DELETE"})).ok&&(n(T=>T.filter(j=>j.id!==E)),o(null))},b=async E=>{(await fetch(`/api/scheduler/autoplugs/tracking/${E}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({skipped:!0})})).ok&&s(T=>T.map(j=>j.id===E?{...j,skipped:!0}:j))},k=e.reduce((E,C)=>C.rule&&C.enabled?Math.min(E,C.rule.threshold):E,1/0),w=k===1/0?50:k;return c.jsxs("div",{className:"sidebar-schedule",children:[c.jsxs("div",{className:"sidebar-schedule-header",children:[c.jsx("button",{className:"sidebar-schedule-back",onClick:t,title:"Back",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Autoplugs"}),c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>d(!l),children:l?"Cancel":"+ Add"})]}),l&&c.jsx(O8,{onCreated:E=>{n(C=>[...C,E]),d(!1)}}),f?null:c.jsxs(c.Fragment,{children:[e.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No goals"}),c.jsx("div",{className:"schedule-empty-desc",children:"Create a goal to start autoplugging your tweets."})]}):e.map(E=>c.jsxs("div",{children:[c.jsxs("div",{className:"schedule-item",onClick:()=>o(i===E.id?null:E.id),children:[c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:E.name}),c.jsx("div",{className:"schedule-item-meta",children:R8(E).map((C,T)=>c.jsx("span",{children:C},T))})]}),c.jsx("button",{className:`autoplug-toggle ${E.enabled?"autoplug-toggle--on":"autoplug-toggle--off"}`,onClick:C=>{C.stopPropagation(),g(E)},title:E.enabled?"Disable":"Enable"})]}),i===E.id&&c.jsx(I8,{goal:E,onSaved:C=>{n(T=>T.map(j=>j.id===C.id?C:j))},onDeleted:()=>v(E.id),onRefresh:m})]},E.id)),c.jsx("div",{className:"schedule-day-header",children:"Tracking"}),r.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No tracked tweets"}),c.jsx("div",{className:"schedule-empty-desc",children:"Tweets will appear here after posting."})]}):r.map(E=>c.jsxs("div",{className:"schedule-item",children:[c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:E.original_text||`Tweet ${E.tweet_id}`}),c.jsxs("div",{className:"schedule-item-meta",children:[c.jsx("span",{children:L8(E.posted_at)}),c.jsxs("span",{children:[E.likes," likes"]}),c.jsxs("span",{children:[E.retweets," RTs"]}),E.views>0&&c.jsxs("span",{children:[D8(E.views)," views"]})]}),E.triggered?c.jsxs("div",{className:"autoplug-tracking-triggered",children:[c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Autoplugged ",E.goal_name?`→ ${E.goal_name}`:""]}):E.skipped?c.jsx("div",{className:"autoplug-tracking-skipped",children:"Skipped"}):c.jsx("div",{className:"autoplug-tracking-bar",children:c.jsx("div",{className:"autoplug-tracking-bar-fill",style:{width:`${Math.min(100,E.likes/w*100)}%`}})})]}),!E.triggered&&!E.skipped&&c.jsx("button",{className:"autoplug-tracking-skip",onClick:()=>b(E.id),title:"Skip autoplug for this tweet",children:"×"})]},E.id))]})]})}function R8(t){const e=[];return t.rule&&(e.push(`${t.rule.threshold}+ ${t.rule.metric}`),e.push(t.rule.mode.charAt(0).toUpperCase()+t.rule.mode.slice(1)),t.rule.delay_minutes>0&&e.push(`${t.rule.delay_minutes}m delay`)),e.push(`${t.pool_count} msg${t.pool_count!==1?"s":""}`),e}function O8({onCreated:t}){const[e,n]=x.useState(""),[r,s]=x.useState(""),[i,o]=x.useState(""),[l,d]=x.useState("likes"),[f,h]=x.useState(50),[m,g]=x.useState(30),[v,b]=x.useState("static"),[k,w]=x.useState(!1),E=async()=>{if(e.trim()){w(!0);try{const C=await fetch("/api/scheduler/autoplugs/goals",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.trim(),link:r.trim()||null,description:i.trim()||null})});if(!C.ok){w(!1);return}const{goal:T}=await C.json();await fetch("/api/scheduler/autoplugs/rules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({goal_id:T.id,metric:l,threshold:f,delay_minutes:m,mode:v})});const j=await fetch("/api/scheduler/autoplugs/goals");if(j.ok){const A=((await j.json()).goals||[]).find(O=>O.id===T.id);if(A){t(A);return}}t({...T,rule_count:1,pool_count:0,rule:{metric:l,threshold:f,delay_minutes:m,mode:v,id:""}})}finally{w(!1)}}};return c.jsxs("div",{className:"autoplug-editor",children:[c.jsxs("label",{children:["Name",c.jsx("input",{value:e,onChange:C=>n(C.target.value),placeholder:"Newsletter, Course..."})]}),c.jsxs("label",{children:["Link",c.jsx("input",{value:r,onChange:C=>s(C.target.value),placeholder:"https://..."})]}),c.jsxs("label",{children:["Description (context for LLM)",c.jsx("textarea",{value:i,onChange:C=>o(C.target.value),placeholder:"Weekly engineering insights...",rows:2})]}),c.jsxs("div",{className:"autoplug-editor-row",children:[c.jsx("input",{type:"number",value:f,onChange:C=>h(Number(C.target.value)),min:1}),c.jsxs("select",{value:l,onChange:C=>d(C.target.value),children:[c.jsx("option",{value:"likes",children:"likes"}),c.jsx("option",{value:"retweets",children:"retweets"}),c.jsx("option",{value:"views",children:"views"})]}),c.jsx("span",{className:"autoplug-editor-row-label",children:"wait"}),c.jsx("input",{type:"number",value:m,onChange:C=>g(Number(C.target.value)),min:0,className:"autoplug-delay-input"}),c.jsx("span",{className:"autoplug-editor-row-label",children:"min"})]}),c.jsx("div",{className:"autoplug-mode-toggle",children:["static","llm","hybrid"].map(C=>c.jsx("button",{className:v===C?"active":"",onClick:()=>b(C),children:C==="llm"?"LLM":C.charAt(0).toUpperCase()+C.slice(1)},C))}),c.jsx("button",{className:"sidebar-schedule-btn sidebar-schedule-btn--active autoplug-create-btn",onClick:E,disabled:k||!e.trim(),children:k?"Creating...":"Create Goal"})]})}function I8({goal:t,onSaved:e,onDeleted:n,onRefresh:r}){var J,z,G,D;const[s,i]=x.useState(t.name),[o,l]=x.useState(t.link||""),[d,f]=x.useState(t.description||""),[h,m]=x.useState(((J=t.rule)==null?void 0:J.metric)||"likes"),[g,v]=x.useState(((z=t.rule)==null?void 0:z.threshold)||50),[b,k]=x.useState(((G=t.rule)==null?void 0:G.delay_minutes)||30),[w,E]=x.useState(((D=t.rule)==null?void 0:D.mode)||"static"),[C,T]=x.useState([]),[j,_]=x.useState(""),[A,O]=x.useState(!1);x.useEffect(()=>{fetch(`/api/scheduler/autoplugs/goals/${t.id}/pool`).then(U=>U.json()).then(U=>T(U.pool||[])).catch(()=>{})},[t.id]);const B=async()=>{var U;O(!0);try{await fetch(`/api/scheduler/autoplugs/goals/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s,link:o||null,description:d||null})}),(U=t.rule)!=null&&U.id?await fetch(`/api/scheduler/autoplugs/rules/${t.rule.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({metric:h,threshold:g,delay_minutes:b,mode:w})}):await fetch("/api/scheduler/autoplugs/rules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({goal_id:t.id,metric:h,threshold:g,delay_minutes:b,mode:w})}),r()}finally{O(!1)}},$=async()=>{if(!j.trim())return;const U=await fetch(`/api/scheduler/autoplugs/goals/${t.id}/pool`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:j.trim()})});if(U.ok){const q=await U.json();T(se=>[...se,q.message]),_("")}},W=async U=>{(await fetch(`/api/scheduler/autoplugs/pool/${U}`,{method:"DELETE"})).ok&&T(se=>se.filter(V=>V.id!==U))};return c.jsxs("div",{className:"autoplug-editor",children:[c.jsxs("label",{children:["Name",c.jsx("input",{value:s,onChange:U=>i(U.target.value)})]}),c.jsxs("label",{children:["Link",c.jsx("input",{value:o,onChange:U=>l(U.target.value),placeholder:"https://..."})]}),c.jsxs("label",{children:["Description",c.jsx("textarea",{value:d,onChange:U=>f(U.target.value),rows:2})]}),c.jsx("div",{className:"autoplug-editor-section-label",children:"Trigger"}),c.jsxs("div",{className:"autoplug-editor-row",children:[c.jsx("input",{type:"number",value:g,onChange:U=>v(Number(U.target.value)),min:1}),c.jsxs("select",{value:h,onChange:U=>m(U.target.value),children:[c.jsx("option",{value:"likes",children:"likes"}),c.jsx("option",{value:"retweets",children:"retweets"}),c.jsx("option",{value:"views",children:"views"})]}),c.jsx("span",{className:"autoplug-editor-row-label",children:"wait"}),c.jsx("input",{type:"number",value:b,onChange:U=>k(Number(U.target.value)),min:0,className:"autoplug-delay-input"}),c.jsx("span",{className:"autoplug-editor-row-label",children:"min"})]}),c.jsx("div",{className:"autoplug-mode-toggle",children:["static","llm","hybrid"].map(U=>c.jsx("button",{className:w===U?"active":"",onClick:()=>E(U),children:U==="llm"?"LLM":U.charAt(0).toUpperCase()+U.slice(1)},U))}),c.jsxs("div",{className:"autoplug-pool-section",children:[c.jsx("div",{className:"autoplug-editor-section-label",children:"Static Pool"}),C.map(U=>c.jsxs("div",{className:"autoplug-pool-item",children:[c.jsx("span",{children:U.content}),c.jsx("button",{onClick:()=>W(U.id),title:"Remove",children:"×"})]},U.id)),c.jsxs("div",{className:"autoplug-pool-add",children:[c.jsx("input",{value:j,onChange:U=>_(U.target.value),placeholder:"Add message... (use {{link}} for link)",onKeyDown:U=>U.key==="Enter"&&$()}),c.jsx("button",{onClick:$,children:"+"})]})]}),(w==="llm"||w==="hybrid")&&c.jsx("div",{className:"autoplug-llm-hint",children:"LLM mode uses Author's Voice to generate contextual replies referencing the original tweet."}),c.jsxs("div",{className:"autoplug-editor-actions",children:[c.jsx("button",{className:"schedule-item-action",onClick:B,disabled:A,children:A?"Saving...":"Save"}),c.jsx("button",{className:"schedule-item-action schedule-item-action--danger",onClick:n,children:"Delete"})]})]})}function L8(t){const e=Date.now()-new Date(t).getTime(),n=Math.floor(e/6e4);if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function D8(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function P8({onBack:t}){const[e,n]=x.useState([]),[r,s]=x.useState([]),[i,o]=x.useState(!1),[l,d]=x.useState(!1),[f,h]=x.useState(null),[m,g]=x.useState(!0),v=x.useCallback(async()=>{try{const[w,E]=await Promise.all([fetch("/api/scheduler/queue"),fetch("/api/scheduler/slots"),fetch("/api/scheduler/sync",{method:"POST"})]);if(w.ok){const C=await w.json();n(C.items||[])}if(E.ok){const C=await E.json();s(C.slots||[])}}catch{}g(!1)},[]);x.useEffect(()=>{v()},[v]);const b=async w=>{(await fetch(`/api/scheduler/queue/${w}`,{method:"DELETE"})).ok&&(n(C=>C.filter(T=>T.id!==w)),h(null))};if(l)return c.jsx(A8,{onBack:()=>{d(!1),v()}});if(i)return c.jsx(j8,{slots:r,onBack:()=>{o(!1),v()}});const k=B8(r,e);return c.jsxs("div",{className:"sidebar-schedule",children:[c.jsxs("div",{className:"sidebar-schedule-header",children:[c.jsx("button",{className:"sidebar-schedule-back",onClick:t,title:"Back to documents",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Schedule"}),c.jsxs("div",{className:"sidebar-schedule-actions",children:[c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>d(!0),title:"Autoplugs",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}),c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>o(!0),title:"Manage slots",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),c.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]}),m?null:r.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No time slots"}),c.jsx("div",{className:"schedule-empty-desc",children:"Create time slots to define your posting schedule."})]}):k.map(({label:w,entries:E})=>c.jsxs("div",{className:"schedule-day",children:[c.jsx("div",{className:"schedule-day-header",children:w}),E.map((C,T)=>{var j,_,A,O,B;return C.type==="empty"?c.jsxs("div",{className:"schedule-slot-empty",children:[c.jsx("div",{className:"schedule-item-time",children:Ck(C.time)}),c.jsx("div",{className:"schedule-slot-empty-label",children:((j=C.slot)==null?void 0:j.filter_type)==="any"?"Open slot":`${(_=C.slot)==null?void 0:_.filter_type}: ${((A=C.slot)==null?void 0:A.filter_value)||"any"}`})]},`empty-${T}`):c.jsxs("div",{children:[c.jsxs("div",{className:"schedule-item",onClick:()=>h(f===C.item.id?null:C.item.id),children:[c.jsx("div",{className:"schedule-item-time",children:Ck(C.time)}),c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:((O=C.item.content)==null?void 0:O.text)||JSON.stringify(C.item.content)}),c.jsxs("div",{className:"schedule-item-meta",children:[c.jsx("span",{className:`schedule-item-status schedule-item-status--${C.item.status}`}),c.jsx("span",{children:C.item.status}),C.item.connection_name&&c.jsx("span",{children:C.item.connection_name}),C.item.provider&&c.jsx("span",{children:C.item.provider})]})]})]}),f===C.item.id&&c.jsxs("div",{className:"schedule-item-expanded",children:[c.jsx("div",{className:"schedule-item-full-text",children:((B=C.item.content)==null?void 0:B.text)||JSON.stringify(C.item.content,null,2)}),c.jsx("div",{className:"schedule-item-actions",children:c.jsx("button",{className:"schedule-item-action schedule-item-action--danger",onClick:()=>b(C.item.id),children:"Cancel"})})]})]},C.item.id)})]},w))]})}function B8(t,e){const n=new Date,r=[];for(let l=0;l<7;l++){const d=new Date(n);d.setDate(d.getDate()+l),d.setHours(0,0,0,0);let f;l===0?f="Today":l===1?f="Tomorrow":f=d.toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"}),r.push({label:f,date:d})}const s=new Map;for(const l of e){const d=new Date(l.scheduled_at),f=`${d.getFullYear()}-${d.getMonth()}-${d.getDate()}-${d.getHours()}-${d.getMinutes()}`;s.set(f,l)}const i=new Set,o=[];for(const{label:l,date:d}of r){const f=[],h=d.getDay(),g=["sun","mon","tue","wed","thu","fri","sat"][h];for(const v of t){if(!(v.days.includes("default")||v.days.includes(g)))continue;const[k,w]=v.time.split(":").map(Number),E=new Date(d);if(E.setHours(k,w,0,0),Nk(d,n)&&E<n)continue;const C=`${E.getFullYear()}-${E.getMonth()}-${E.getDate()}-${k}-${w}`,T=s.get(C);T?(f.push({type:"filled",time:E,item:T,slot:v}),i.add(T.id)):f.push({type:"empty",time:E,slot:v})}for(const v of e){if(i.has(v.id))continue;const b=new Date(v.scheduled_at);Nk(b,d)&&(f.push({type:"filled",time:b,item:v}),i.add(v.id))}f.sort((v,b)=>v.time.getTime()-b.time.getTime()),f.length>0&&o.push({label:l,entries:f})}return o}function Nk(t,e){return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()}function Ck(t){return t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})}function $8({onBack:t}){const[e,n]=x.useState([]),[r,s]=x.useState(""),[i,o]=x.useState(null),[l,d]=x.useState(!1),f=x.useRef(null),h=x.useCallback(async()=>{try{const w=await fetch("/api/tasks");if(w.ok){const E=await w.json();n(E.tasks||[])}}catch{}},[]);x.useEffect(()=>{h()},[h]);const m=async()=>{const w=r.trim();if(w){s("");try{const E=await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:w})});if(E.ok){const C=await E.json();n(T=>[...T,C.task])}}catch{}}},g=w=>{o(w),fetch(`/api/tasks/${w}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({completed:!0})}).catch(()=>{}),setTimeout(()=>{n(E=>E.filter(C=>C.id!==w)),o(null)},400)},v=async w=>{try{(await fetch(`/api/tasks/${w}`,{method:"DELETE"})).ok&&n(C=>C.filter(T=>T.id!==w))}catch{}},b=()=>{d(!0),setTimeout(()=>{var w;return(w=f.current)==null?void 0:w.focus()},0)},k=e.filter(w=>!w.completed);return c.jsxs("div",{className:"sidebar-tasks",children:[c.jsxs("div",{className:"sidebar-tasks-header",children:[c.jsx("button",{className:"sidebar-tasks-back",onClick:t,title:"Back to documents",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Tasks"}),c.jsx("button",{className:"sidebar-tasks-add-btn",onClick:b,title:"Add task",children:"+"})]}),k.length===0&&!l?c.jsxs("div",{className:"sidebar-tasks-empty",children:[c.jsx("div",{className:"sidebar-tasks-empty-title",children:"No tasks"}),c.jsx("div",{className:"sidebar-tasks-empty-desc",children:"Add tasks to track your checklist."})]}):c.jsx("div",{className:"sidebar-tasks-list",children:k.map(w=>c.jsxs("div",{className:`sidebar-tasks-item${i===w.id?" completing":""}`,children:[c.jsx("input",{type:"checkbox",className:"sidebar-tasks-checkbox",checked:i===w.id,onChange:()=>g(w.id)}),c.jsx("span",{className:`sidebar-tasks-text${i===w.id?" completed":""}`,children:w.text}),c.jsx("button",{className:"sidebar-tasks-delete",onClick:()=>v(w.id),title:"Remove",children:"×"})]},w.id))}),l&&c.jsx("div",{className:"sidebar-tasks-add",children:c.jsx("input",{ref:f,type:"text",placeholder:"New task...",value:r,onChange:w=>s(w.target.value),onKeyDown:w=>{w.key==="Enter"&&m(),w.key==="Escape"&&(d(!1),s(""))},onBlur:()=>{r.trim()||d(!1)}})})]})}function z8({profiles:t,activeProfile:e,trashedProfiles:n,onSwitch:r,onCreate:s,onDelete:i,onRestore:o}){const[l,d]=x.useState(!1),[f,h]=x.useState(!1),[m,g]=x.useState(""),[v,b]=x.useState(null),k=x.useRef(null),w=x.useRef(null);x.useEffect(()=>{if(!l)return;const C=T=>{k.current&&!k.current.contains(T.target)&&(d(!1),h(!1),g(""),b(null))};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[l]),x.useEffect(()=>{f&&w.current&&w.current.focus()},[f]);const E=()=>{const C=m.trim();C&&(s(C),g(""),h(!1))};return c.jsxs("div",{className:"sidebar-profile-wrapper",ref:k,children:[c.jsx("button",{className:"sidebar-collapse-btn",onClick:()=>d(!l),title:`Profile: ${e}`,children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"8",r:"4"}),c.jsx("path",{d:"M5.5 21a8.38 8.38 0 0 1 13 0"})]})}),l&&c.jsxs("div",{className:"sidebar-profile-dropdown",children:[t.map(C=>c.jsxs("div",{className:"sidebar-profile-row",children:[v===C?c.jsxs("div",{className:"sidebar-profile-confirm",children:[c.jsx("span",{children:"Delete?"}),c.jsxs("div",{className:"sidebar-inline-confirm",children:[c.jsx("button",{onClick:()=>{i(C),b(null)},children:"Yes"}),c.jsx("button",{onClick:()=>b(null),children:"No"})]})]}):c.jsx(c.Fragment,{children:c.jsxs("button",{className:`sidebar-profile-option ${C===e?"active":""}`,onClick:()=>{C!==e&&r(C),d(!1)},children:[c.jsx("span",{className:"sidebar-profile-check",children:C===e?"✓":""}),c.jsx("span",{children:C})]})}),C!=="Default"&&C!==e&&v!==C&&c.jsx("button",{className:"sidebar-profile-delete-btn",onClick:T=>{T.stopPropagation(),b(C)},title:"Delete profile",children:"×"})]},C)),n.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"sidebar-profile-divider"}),c.jsx("div",{className:"sidebar-profile-trash-label",children:"Trash"}),n.map(C=>c.jsxs("div",{className:"sidebar-profile-row sidebar-profile-trashed",children:[c.jsx("span",{className:"sidebar-profile-trash-name",children:C}),c.jsx("button",{className:"sidebar-profile-restore-btn",onClick:()=>o(C),children:"Restore"})]},C))]}),c.jsx("div",{className:"sidebar-profile-divider"}),f?c.jsx("div",{className:"sidebar-profile-add-input",children:c.jsx("input",{ref:w,type:"text",value:m,onChange:C=>g(C.target.value),onKeyDown:C=>{C.key==="Enter"&&E(),C.key==="Escape"&&(h(!1),g(""))},placeholder:"Profile name..."})}):c.jsxs("button",{className:"sidebar-profile-option sidebar-profile-add",onClick:()=>h(!0),children:[c.jsx("span",{className:"sidebar-profile-check",children:"+"}),c.jsx("span",{children:"New Profile"})]})]})]})}const _k=200,Tk=600,Ip=260;function jk({open:t,onSwitchDocument:e,onCreateDocument:n,refreshKey:r,docTagsRefreshKey:s,workspacesRefreshKey:i,pendingDocs:o,writingTitle:l,writingTarget:d,pendingWriteFilenames:f,onClose:h}){const{docs:m,setDocs:g,workspaces:v,setWorkspaces:b,assignedFiles:k,fetchDocs:w,fetchWorkspaces:E,scrollRef:C,markPendingDelete:T}=t8(r,i),j=n8(w,E,g,b,m,T),_=Rd(),[A,O]=x.useState(()=>{try{const nt=localStorage.getItem("ow-sidebar-width");if(nt){const ht=parseInt(nt,10);if(!isNaN(ht)&&ht>=_k&&ht<=Tk)return ht}}catch{}return Ip}),B=x.useRef(!1),$=x.useCallback(nt=>{nt.preventDefault(),B.current=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none";const ht=ve=>{if(!B.current)return;const X=Math.min(Tk,Math.max(_k,ve.clientX));O(X)},Fe=()=>{B.current=!1,document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("pointermove",ht),window.removeEventListener("pointerup",Fe);try{localStorage.setItem("ow-sidebar-width",String(W.current))}catch{}};window.addEventListener("pointermove",ht),window.addEventListener("pointerup",Fe)},[]),W=x.useRef(A);W.current=A;const J=x.useCallback(nt=>{g(ht=>ht.map(Fe=>({...Fe,isActive:Fe.filename===nt}))),e(nt)},[g,e]),[z,G]=x.useState(!1),[D,U]=x.useState(!1),[q,se]=x.useState([]),[V,te]=x.useState("Default"),K=x.useCallback(async()=>{try{const nt=await fetch("/api/profiles");if(nt.ok){const ht=await nt.json();se(ht.profiles),te(ht.active)}}catch{}},[]);x.useEffect(()=>{K()},[K]);const M=x.useCallback(async nt=>{try{(await fetch("/api/profiles/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:nt})})).ok&&(te(nt),K())}catch{}},[K]),L=x.useCallback(async nt=>{try{(await fetch("/api/profiles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:nt})})).ok&&K()}catch{}},[K]),[ee,fe]=x.useState([]),ge=x.useCallback(async()=>{try{const nt=await fetch("/api/profiles/trash");if(nt.ok){const ht=await nt.json();fe(ht.profiles)}}catch{}},[]);x.useEffect(()=>{ge()},[ge]);const oe=x.useCallback(async nt=>{try{(await fetch(`/api/profiles/${encodeURIComponent(nt)}`,{method:"DELETE"})).ok&&(K(),ge())}catch{}},[K,ge]),xe=x.useCallback(async nt=>{try{(await fetch("/api/profiles/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:nt})})).ok&&(K(),ge())}catch{}},[K,ge]),[we,We]=x.useState(""),[He,Ze]=x.useState(null),Oe=x.useRef(),Ke=x.useRef(null),pt=x.useCallback(nt=>{if(We(nt),Oe.current&&clearTimeout(Oe.current),!nt.trim()){Ze(null);return}Oe.current=setTimeout(async()=>{try{const ht=await fetch(`/api/documents/search?q=${encodeURIComponent(nt.trim())}&archived=true`);ht.ok&&Ze(await ht.json())}catch{}},250)},[]);x.useEffect(()=>()=>{Oe.current&&clearTimeout(Oe.current)},[]);const Je={docs:m,archivedDocs:[],workspaces:v,assignedFiles:k,pendingDocs:o,writingTitle:l,writingTarget:d,pendingWriteFilenames:f,onSwitchDocument:J,onCreateDocument:n,actions:j,scrollRef:C,searchQuery:we,searchResults:He,onSearchChange:pt},pe=()=>{switch(_){case"files":return c.jsx(N8,{...Je});case"timeline":return c.jsx(d8,{...Je});case"board":return c.jsx(f8,{...Je});case"shelf":return c.jsx(h8,{...Je});default:return c.jsx(u8,{...Je})}},mt=c.jsxs("div",{className:"sidebar-search",children:[c.jsxs("svg",{className:"sidebar-search-icon",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"10.5",cy:"10.5",r:"7"}),c.jsx("path",{d:"m20 20-4.5-4.5"})]}),c.jsx("input",{ref:Ke,className:"sidebar-search-input",type:"text",placeholder:"Search...",value:we,onChange:nt=>pt(nt.target.value)}),we&&c.jsx("button",{className:"sidebar-search-clear",onClick:()=>pt(""),title:"Clear search",children:"×"})]}),ft=t?{width:`${A}px`,minWidth:`${A}px`}:void 0,at=t?c.jsx("div",{className:"sidebar-resize-handle",onPointerDown:$,onDoubleClick:()=>{O(Ip);try{localStorage.setItem("ow-sidebar-width",String(Ip))}catch{}},title:"Drag to resize · double-click to reset"}):null;return _==="board"?c.jsxs("div",{className:`sidebar sidebar-board-mode ${t?"open":""}`,style:ft,children:[pe(),at]}):c.jsxs("div",{className:`sidebar ${t?"open":""}`,style:ft,children:[c.jsxs("div",{className:"sidebar-topbar",children:[c.jsxs("div",{className:"sidebar-logo",children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M17 3a2.83 2.83 0 0 1 4 4L7.5 20.5 2 22l1.5-5.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M15 5l4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),c.jsx("span",{className:"sidebar-logo-text",children:"OpenWriter"})]}),c.jsxs("div",{className:"sidebar-topbar-actions",children:[c.jsx(z8,{profiles:q,activeProfile:V,trashedProfiles:ee,onSwitch:M,onCreate:L,onDelete:oe,onRestore:xe}),c.jsx("button",{className:`sidebar-collapse-btn${z?" sidebar-collapse-btn--active":""}`,onClick:()=>{G(!z),U(!1)},title:"Schedule",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),c.jsx("line",{x1:"16",x2:"16",y1:"1",y2:"5"}),c.jsx("line",{x1:"8",x2:"8",y1:"1",y2:"5"}),c.jsx("line",{x1:"3",x2:"21",y1:"9",y2:"9"})]})}),c.jsx("button",{className:`sidebar-collapse-btn${D?" sidebar-collapse-btn--active":""}`,onClick:()=>{U(!D),G(!1)},title:"Tasks",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),c.jsx("path",{d:"m9 12 2 2 4-4"})]})}),h&&c.jsx("button",{className:"sidebar-collapse-btn",onClick:h,title:"Close sidebar",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M9 3v18",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M15 10l-2 2 2 2",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})})]})]}),D?c.jsx($8,{onBack:()=>U(!1)}):z?c.jsx(P8,{onBack:()=>G(!1)}):c.jsxs(c.Fragment,{children:[mt,pe()]}),at]})}function oy(t,e,n){let r=t.resolve(e);for(;r.depth>0;){const s=r.node(r.depth),i=r.before(r.depth),o=i+s.nodeSize;if(s.childCount===1)e=i,n=o,r=t.resolve(e);else break}return{from:e,to:n}}function F8(t,e){const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;return t.chain().command(({tr:i})=>(i.setNodeMarkup(s,void 0,{...r.attrs,pendingStatus:null}),!0)).run(),!0}function U8(t,e){const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;return t.chain().command(({tr:i})=>(i.setNodeMarkup(s,void 0,{...r.attrs,pendingStatus:null,pendingOriginalContent:null,pendingSelectionFrom:null,pendingSelectionTo:null,pendingOriginalFrom:null,pendingOriginalTo:null}),!0)).run(),!0}function H8(t,e){var o;const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;if(((o=r.attrs)==null?void 0:o.pendingStatus)!=="delete")return!0;const i=oy(t.state.doc,s,s+r.nodeSize);return t.chain().deleteRange(i).run(),!0}function W8(t,e){var o;const n=Ln(t,e);if(!n)return!0;const{node:r,pos:s}=n;if(((o=r.attrs)==null?void 0:o.pendingStatus)!=="insert")return!0;const i=oy(t.state.doc,s,s+r.nodeSize);return t.chain().deleteRange(i).run(),!0}function q8(t,e){var o,l;const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;if(((o=r.attrs)==null?void 0:o.pendingStatus)!=="rewrite")return!0;const i=(l=r.attrs)==null?void 0:l.pendingOriginalContent;if(i)t.chain().deleteRange({from:s,to:s+r.nodeSize}).insertContentAt(s,i).run();else{const d=oy(t.state.doc,s,s+r.nodeSize);t.chain().deleteRange(d).run()}return!0}function V8(t,e){var i;const n=Ln(t,e);if(!n)return!1;const{node:r,pos:s}=n;return((i=r.attrs)==null?void 0:i.pendingStatus)!=="delete"||t.chain().command(({tr:o})=>(o.setNodeMarkup(s,void 0,{...r.attrs,pendingStatus:null}),!0)).run(),!0}function K8(t,e){const n=Yd(t,e);if(n.length===0)return!1;for(const r of[...n].reverse()){const s=Ln(t,r.nodeId);s&&t.chain().command(({tr:i})=>(i.setNodeMarkup(s.pos,void 0,{...s.node.attrs,pendingStatus:null,pendingOriginalContent:null,pendingGroupId:null,pendingSelectionFrom:null,pendingSelectionTo:null,pendingOriginalFrom:null,pendingOriginalTo:null}),!0)).run()}return!0}function G8(t,e){var l;const n=Yd(t,e);if(n.length===0)return!1;const r=(l=n[0].node.attrs)==null?void 0:l.pendingOriginalContent,s=n[0].pos,i=n[n.length-1],o=i.pos+i.node.nodeSize;try{return r&&Array.isArray(r)&&r.length>0?t.chain().deleteRange({from:s,to:o}).insertContentAt(s,r).run():t.chain().deleteRange({from:s,to:o}).run(),!0}catch{return!1}}function A2(t,e){var i,o;const n=Ln(t,e);if(!n)return!1;const r=(i=n.node.attrs)==null?void 0:i.pendingGroupId;if(r)return K8(t,r);switch((o=n.node.attrs)==null?void 0:o.pendingStatus){case"insert":return F8(t,e);case"rewrite":return U8(t,e);case"delete":return H8(t,e);default:return!1}}function R2(t,e){var i,o;const n=Ln(t,e);if(!n)return!1;const r=(i=n.node.attrs)==null?void 0:i.pendingGroupId;if(r)return G8(t,r);switch((o=n.node.attrs)==null?void 0:o.pendingStatus){case"insert":return W8(t,e);case"rewrite":return q8(t,e);case"delete":return V8(t,e);default:return!1}}function J8(t){const e=O2(t).reverse();for(const n of e)A2(t,n);t.view&&ry(t.view)}function Y8(t){const e=O2(t).reverse();for(const n of e)R2(t,n);t.view&&ry(t.view)}function ay(t){const e=[],n=new Set;return t.state.doc.descendants((r,s)=>{var o,l,d;const i=(o=r.attrs)==null?void 0:o.pendingStatus;if(i&&((l=r.attrs)!=null&&l.id)){const f=(d=r.attrs)==null?void 0:d.pendingGroupId;if(f){if(n.has(f))return!0;n.add(f)}e.push({nodeId:r.attrs.id,pos:s,pendingStatus:i,groupId:f,editor:t})}return!0}),e}function Lp(t){const e=[];for(const n of t)n&&!n.isDestroyed&&e.push(...ay(n));return e}function O2(t){return ay(t).map(e=>e.nodeId)}function X8(t){let e=0,n=0,r=0;for(const s of t)s.pendingStatus==="insert"?e++:s.pendingStatus==="rewrite"?n++:s.pendingStatus==="delete"&&r++;return{insert:e,rewrite:n,delete:r,total:t.length}}function Xa(t,e){if(t.isDestroyed)return;let n=-1;if(t.state.doc.descendants((i,o)=>{var l;return((l=i.attrs)==null?void 0:l.id)===e?(n=o,!1):!0}),n===-1)return;const r=t.view.nodeDOM(n),s=r instanceof HTMLElement?r:r==null?void 0:r.parentElement;if(s){s.scrollIntoView({behavior:"smooth",block:"center"});return}try{const i=t.view.coordsAtPos(n),o=t.view.dom.closest(".editor-container");if(o){const l=o.getBoundingClientRect(),d=i.top-l.top+o.scrollTop-o.clientHeight/2;o.scrollTo({top:d,behavior:"smooth"})}}catch{}}function Q8(t){const[e,n]=x.useState([]),[r,s]=x.useState(0),i=x.useRef(),o=x.useRef(new Set),l=x.useCallback(()=>{const E=t.filter(A=>A&&!A.isDestroyed);if(E.length===0){n([]),o.current=new Set;return}const C=Lp(E);n(C);const T=o.current,j=new Set(C.map(A=>A.nodeId));let _=-1;if(T.size>0){for(let A=0;A<C.length;A++)if(!T.has(C[A].nodeId)){_=A;break}}o.current=j,_>=0?(s(_),Xa(C[_].editor,C[_].nodeId)):C.length===0?s(0):s(A=>Math.min(A,C.length-1))},[t]);x.useEffect(()=>{const E=t.filter(j=>j&&!j.isDestroyed);if(E.length===0)return;const C=()=>{clearTimeout(i.current),i.current=setTimeout(l,50)};for(const j of E)j.on("transaction",C);l();const T=setTimeout(()=>{const j=Lp(E.filter(_=>!_.isDestroyed));j.length>0&&Xa(j[0].editor,j[0].nodeId)},150);return()=>{for(const j of E)j.isDestroyed||j.off("transaction",C);clearTimeout(i.current),clearTimeout(T)}},[t,l]),x.useEffect(()=>{const E=e[r]??null;return rk((E==null?void 0:E.nodeId)??null,(E==null?void 0:E.groupId)??null),E!=null&&E.editor&&!E.editor.isDestroyed&&E.editor.view&&ry(E.editor.view),()=>{rk(null)}},[r,e]);const d=X8(e),f=e[r]??null,h=x.useCallback(()=>{if(e.length===0)return;const E=(r+1)%e.length;s(E),e[E]&&Xa(e[E].editor,e[E].nodeId)},[e,r]),m=x.useCallback(()=>{if(e.length===0)return;const E=(r-1+e.length)%e.length;s(E),e[E]&&Xa(e[E].editor,e[E].nodeId)},[e,r]),g=x.useCallback(()=>{const E=t.filter(j=>j&&!j.isDestroyed),C=Lp(E);if(C.length===0)return;const T=Math.min(r,C.length-1);Xa(C[T].editor,C[T].nodeId)},[t,r]),v=x.useCallback(()=>{f&&(A2(f.editor,f.nodeId),l(),g())},[f,l,g]),b=x.useCallback(()=>{f&&(R2(f.editor,f.nodeId),l(),g())},[f,l,g]),k=x.useCallback(()=>{const E=t.filter(C=>C&&!C.isDestroyed);for(const C of E)J8(C);l()},[t,l]),w=x.useCallback(()=>{const E=t.filter(C=>C&&!C.isDestroyed);for(const C of E)Y8(C);l()},[t,l]);return{pendingNodes:e,counts:d,currentNode:f,currentIndex:r,hasPending:d.total>0,goToNext:h,goToPrevious:m,acceptCurrent:v,rejectCurrent:b,acceptAll:k,rejectAll:w,refresh:l}}const I2="ow-review-scope";function Z8(){try{return localStorage.getItem(I2)==="workspace"?"workspace":"all"}catch{return"all"}}function e$(t){try{localStorage.setItem(I2,t)}catch{}}function L2(t){if(!t)return[];const e=[];for(const n of t)n.type==="doc"&&n.file&&e.push(n.file),n.type==="container"&&n.items&&e.push(...L2(n.items));return e}function D2(t,e){if(!t)return!1;for(const n of t)if(n.type==="doc"&&n.file===e||n.type==="container"&&n.items&&D2(n.items,e))return!0;return!1}const da={strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"},t$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M10 3L5 8l5 5",stroke:"currentColor",...da})}),n$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M6 3l5 5-5 5",stroke:"currentColor",...da})}),r$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 10l5-5 5 5",stroke:"currentColor",...da})}),s$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 6l5 5 5-5",stroke:"currentColor",...da})}),Mk=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 8.5l3.5 3.5L13 5",stroke:"currentColor",...da})}),Ak=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M4 4l8 8M12 4l-8 8",stroke:"currentColor",...da})});function P2(t,e,n){const r=Ln(t,e);if(!r)return!1;const{pos:s,node:i}=r,o={type:n.type||i.type.name,attrs:{...n.attrs||{},id:i.attrs.id,pendingStatus:i.attrs.pendingStatus,pendingOriginalContent:i.attrs.pendingOriginalContent,pendingSelectionFrom:i.attrs.pendingSelectionFrom,pendingSelectionTo:i.attrs.pendingSelectionTo,pendingOriginalFrom:i.attrs.pendingOriginalFrom,pendingOriginalTo:i.attrs.pendingOriginalTo},content:n.content};try{return t.chain().command(({tr:l})=>(l.setMeta("addToHistory",!1),!0)).deleteRange({from:s,to:s+i.nodeSize}).insertContentAt(s,o).run(),!0}catch{return!1}}function B2(t,e,n){const r=Yd(t,e);if(r.length===0)return!1;const s=r[0].pos,i=r[r.length-1].pos+r[r.length-1].node.nodeSize;try{return t.chain().command(({tr:o})=>(o.setMeta("addToHistory",!1),!0)).deleteRange({from:s,to:i}).insertContentAt(s,n).run(),!0}catch{return!1}}function vu(t,e){if(!ny()||!e)return!1;const n=a5();return o5()&&n&&Array.isArray(n)?B2(t,e,n):n&&P2(t,e,n),rl(!1),!0}function i$(t,e){return t.indexOf(e)}function o$({editors:t,pendingDocs:e,currentFilename:n,docId:r,pendingTitle:s,onSwitchDocument:i,sendMessage:o,getDocument:l,docVersionRef:d}){const{counts:f,currentNode:h,currentIndex:m,hasPending:g,goToNext:v,goToPrevious:b,acceptCurrent:k,rejectCurrent:w,acceptAll:E,rejectAll:C}=Q8(t),[T,j]=x.useState(s?"title":"body");x.useEffect(()=>{s&&T!=="title"&&f.total===0?j("title"):!s&&T==="title"&&j("body")},[s,f.total,T]);const _=!!s,A=f.total+(_?1:0),O=T==="title"?0:(_?1:0)+m,[B,$]=x.useState(!1);x.useEffect(()=>{T!=="title"&&$(!1)},[T]),x.useEffect(()=>{const Fe=!!s&&T==="title",ve={docId:r,titleFocused:Fe,titleShowOriginal:Fe&&B};return window.dispatchEvent(new CustomEvent("ow-pending-review-cursor",{detail:ve})),()=>{window.dispatchEvent(new CustomEvent("ow-pending-review-cursor",{detail:{docId:r,titleFocused:!1,titleShowOriginal:!1}}))}},[r,s,T,B]);const W=x.useCallback(()=>{r&&o({type:"accept-pending-title",docId:r})},[r,o]),J=x.useCallback(()=>{r&&o({type:"reject-pending-title",docId:r})},[r,o]),z=x.useRef(null),G=x.useRef(null),[D,U]=x.useState(()=>Z8()),[q,se]=x.useState([]);x.useEffect(()=>{let Fe=!1;async function ve(){try{const ne=await(await fetch("/api/workspaces")).json();if(!Array.isArray(ne))return;const de=await Promise.all(ne.map(async he=>{try{const Pe=await(await fetch(`/api/workspaces/${encodeURIComponent(he.filename)}`)).json();return{...he,workspace:Pe}}catch{return he}}));Fe||se(de)}catch{}}ve();const X=()=>ve();return window.addEventListener("ow-workspaces-changed",X),()=>{Fe=!0,window.removeEventListener("ow-workspaces-changed",X)}},[]);const V=x.useMemo(()=>{var ve;if(q.length===0||!n)return null;const Fe=q.find(X=>{var Be;return D2((Be=X.workspace)==null?void 0:Be.root,n)});return Fe?new Set(L2((ve=Fe.workspace)==null?void 0:ve.root)):null},[q,n]),te=x.useMemo(()=>D==="all"||!V?e.filenames:e.filenames.filter(Fe=>V.has(Fe)),[D,e.filenames,V]),K=x.useCallback(Fe=>{U(Fe),e$(Fe)},[]),M=te.length,L=i$(te,n),ee=(h==null?void 0:h.pendingStatus)==="rewrite",fe=!!(h!=null&&h.groupId),ge=ee,oe=x.useCallback(()=>{var ve,X;const Fe=h==null?void 0:h.editor;if(!(!Fe||!h||h.pendingStatus!=="rewrite"))if(B)G.current&&vu(G.current,z.current),z.current=null,G.current=null,$(!1);else if(fe&&h.groupId){const Be=Yd(Fe,h.groupId);if(Be.length===0)return;const ne=(ve=Be[0].node.attrs)==null?void 0:ve.pendingOriginalContent;if(!ne||!Array.isArray(ne))return;const de=Be.map(Pe=>Pe.node.toJSON()),he=ne.map((Pe,et)=>({...Pe,attrs:{...Pe.attrs||{},pendingStatus:"rewrite",pendingGroupId:h.groupId,...et===0?{pendingOriginalContent:ne}:{}}}));if(rl(!0,h.nodeId,de,h.groupId),!B2(Fe,h.groupId,he)){rl(!1);return}z.current=h.nodeId,G.current=Fe,$(!0)}else{const Be=Ln(Fe,h.nodeId);if(!Be)return;const{node:ne}=Be,de=(X=ne.attrs)==null?void 0:X.pendingOriginalContent;if(!de)return;const he=ne.toJSON();if(rl(!0,h.nodeId,he),!P2(Fe,h.nodeId,de)){rl(!1);return}z.current=h.nodeId,G.current=Fe,$(!0)}},[h,B,fe]);x.useEffect(()=>{if(!B)return;const Fe=z.current,ve=G.current;Fe&&ve&&(h==null?void 0:h.nodeId)!==Fe&&(vu(ve,Fe),z.current=null,G.current=null,$(!1))},[h==null?void 0:h.nodeId,B]),x.useEffect(()=>{if(t.length!==0)return()=>{ny()&&z.current&&G.current&&(vu(G.current,z.current),z.current=null,G.current=null)}},[t]);const xe=x.useCallback(Fe=>{if(!n)return;if(!t.some(X=>!X||X.isDestroyed?!1:ay(X).length>0)){const X=l==null?void 0:l();X&&o({type:"doc-update",document:X,filename:n,version:(d==null?void 0:d.current)??0}),o({type:"pending-resolved",filename:n,action:Fe})}},[t,n,o,l,d]),we=x.useCallback(()=>{G.current&&B&&z.current&&(vu(G.current,z.current),z.current=null,G.current=null,$(!1))},[B]),We=x.useCallback(()=>{if(T==="title"&&s){W(),f.total>0&&j("body");return}we(),k(),xe("accept")},[T,s,W,f.total,we,k,xe]),He=x.useCallback(()=>{if(T==="title"&&s){J(),f.total>0&&j("body");return}we(),w(),xe("reject")},[T,s,J,f.total,we,w,xe]),Ze=x.useCallback(()=>{we(),s&&W(),E(),xe("accept")},[we,s,W,E,xe]);x.useEffect(()=>{const Fe=()=>Ze();return window.addEventListener("ow-accept-all",Fe),()=>window.removeEventListener("ow-accept-all",Fe)},[Ze]);const Oe=x.useCallback(()=>{we(),s&&J(),C(),xe("reject")},[we,s,J,C,xe]),Ke=x.useCallback(()=>{if(!(A<=1)){if(T==="title"){j("body");return}if(_&&m>=f.total-1){v(),j("title");return}v()}},[A,T,_,m,f.total,v]),pt=x.useCallback(()=>{if(!(A<=1)){if(T==="title"){b(),j("body");return}if(_&&m===0){j("title");return}b()}},[A,T,_,m,b]),Je=x.useCallback(()=>{if(M===0||M===1&&L===0)return;const Fe=L<=0?M-1:L-1;i(te[Fe])},[M,L,te,i]),pe=x.useCallback(()=>{if(M===0||M===1&&L===0)return;const Fe=L>=M-1?0:L+1;i(te[Fe])},[M,L,te,i]);x.useEffect(()=>{if(!g&&!s)return;const Fe=ve=>{if(!(ve.target instanceof HTMLInputElement||ve.target instanceof HTMLTextAreaElement)&&!(ve.target instanceof HTMLElement&&ve.target.closest("[contenteditable]")))switch(ve.key){case"j":case"ArrowDown":!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),Ke());break;case"k":case"ArrowUp":!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),pt());break;case"h":case"ArrowLeft":!ve.metaKey&&!ve.ctrlKey&&!ve.altKey&&(ve.preventDefault(),Je());break;case"l":case"ArrowRight":!ve.metaKey&&!ve.ctrlKey&&!ve.altKey&&(ve.preventDefault(),pe());break;case"a":!ve.metaKey&&!ve.ctrlKey&&!ve.shiftKey&&(ve.preventDefault(),We());break;case"r":!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),He());break;case"A":ve.shiftKey&&!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),Ze());break;case"R":ve.shiftKey&&!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),Oe());break;case"o":!ve.metaKey&&!ve.ctrlKey&&!ve.shiftKey&&(ve.preventDefault(),T==="title"?$(X=>!X):oe());break}};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[g,s,Ke,pt,Je,pe,We,He,Ze,Oe,oe]);const mt=L>=0?`${L+1} / ${M}`:`— / ${M}`,ft=e.filenames.length,at=!V,ht=ft>0?c.jsxs("div",{className:"review-tab__section",children:[c.jsx("div",{className:"review-tab__section-label",children:"Scope"}),c.jsxs("div",{className:"review-tab__toggle",children:[c.jsx("button",{type:"button",className:`review-panel__toggle-btn${D==="all"?" review-panel__toggle-btn--active":""}`,onClick:()=>K("all"),title:"Cycle every pending doc in the profile",children:"All"}),c.jsx("button",{type:"button",className:`review-panel__toggle-btn${D==="workspace"?" review-panel__toggle-btn--active":""}`,onClick:()=>!at&&K("workspace"),disabled:at,title:at?"Current doc is not in a workspace":"Only cycle pending docs in this workspace",children:"Workspace"})]})]}):null;return!g&&!s?c.jsxs("div",{className:"review-tab__empty",children:[c.jsx("div",{className:"review-tab__empty-title",children:"All caught up"}),c.jsx("div",{className:"review-tab__empty-note",children:"No pending agent changes. New writes from agents will land here for review."})]}):c.jsxs("div",{className:"review-tab",children:[ht,M>1&&c.jsxs("div",{className:"review-tab__section",children:[c.jsx("div",{className:"review-tab__section-label",children:"Document"}),c.jsxs("div",{className:"review-tab__row",children:[c.jsx("button",{className:"review-panel__btn",onClick:Je,title:"Previous doc (h)",children:c.jsx(t$,{})}),c.jsx("span",{className:"review-panel__counter",children:mt}),c.jsx("button",{className:"review-panel__btn",onClick:pe,title:"Next doc (l)",children:c.jsx(n$,{})})]})]}),c.jsxs("div",{className:"review-tab__section",children:[c.jsx("div",{className:"review-tab__section-label",children:T==="title"?"Title":"Change"}),c.jsxs("div",{className:"review-tab__row",children:[c.jsx("button",{className:"review-panel__btn",onClick:pt,disabled:A<=1,title:"Previous (k)",children:c.jsx(r$,{})}),c.jsxs("span",{className:"review-panel__counter",children:[O+1," / ",A]}),c.jsx("button",{className:"review-panel__btn",onClick:Ke,disabled:A<=1,title:"Next (j)",children:c.jsx(s$,{})})]})]}),c.jsx("div",{className:"review-tab__section",children:c.jsxs("div",{className:"review-tab__toggle",children:[c.jsx("button",{className:`review-panel__toggle-btn${(ge||T==="title")&&!B?" review-panel__toggle-btn--active":""}`,onClick:()=>{T==="title"?B&&$(!1):ge&&B&&oe()},disabled:!ge&&T!=="title",title:"Show modified (o)",children:"Modified"}),c.jsx("button",{className:`review-panel__toggle-btn${(ge||T==="title")&&B?" review-panel__toggle-btn--active":""}`,onClick:()=>{T==="title"?B||$(!0):ge&&!B&&oe()},disabled:!ge&&T!=="title",title:"Show original (o)",children:"Original"})]})}),c.jsxs("div",{className:"review-tab__section review-tab__section--actions",children:[c.jsxs("div",{className:"review-tab__row",children:[c.jsxs("button",{className:"review-panel__accept review-tab__action-btn",onClick:We,title:"Accept (a)",children:[c.jsx(Mk,{}),c.jsx("span",{children:"Accept"})]}),c.jsxs("button",{className:"review-panel__reject review-tab__action-btn",onClick:He,title:"Reject (r)",children:[c.jsx(Ak,{}),c.jsx("span",{children:"Reject"})]})]}),c.jsxs("div",{className:"review-tab__row",children:[c.jsxs("button",{className:"review-panel__accept-all review-tab__action-btn",onClick:Ze,title:"Accept all (Shift+A)",children:[c.jsx(Mk,{}),c.jsx("span",{children:"Accept All"})]}),c.jsxs("button",{className:"review-panel__reject-all review-tab__action-btn",onClick:Oe,title:"Reject all (Shift+R)",children:[c.jsx(Ak,{}),c.jsx("span",{children:"Reject All"})]})]})]})]})}function a$(t){const e=Date.now()-t,n=Math.floor(e/1e3);if(n<60)return"Just now";const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const s=Math.floor(r/60);if(s<24)return`${s}h ago`;const i=Math.floor(s/24);return i<7?`${i}d ago`:new Date(t).toLocaleDateString()}function l$(t){return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function c$({currentFilename:t}){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(!1),l=x.useCallback(()=>{fetch("/api/versions").then(f=>f.json()).then(f=>{n(Array.isArray(f)?f:[]),s(null)}).catch(()=>n([]))},[]);x.useEffect(()=>{l()},[t,l]);const d=x.useCallback(async f=>{if(r!==null){o(!0);try{(await fetch(`/api/versions/${r}/restore`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:f})})).ok&&l()}catch{}o(!1)}},[r,l]);return c.jsxs("div",{className:"versions-tab",children:[c.jsx("div",{className:"versions-tab__list",children:e.length===0?c.jsx("div",{className:"versions-tab__empty",children:"No versions yet. Versions are created automatically when you save."}):e.map(f=>c.jsxs("div",{className:`versions-tab__item${r===f.timestamp?" versions-tab__item--selected":""}`,onClick:()=>s(f.timestamp===r?null:f.timestamp),children:[c.jsx("span",{className:"versions-tab__item-time",children:a$(f.timestamp)}),c.jsxs("span",{className:"versions-tab__item-meta",children:[f.wordCount.toLocaleString()," words · ",l$(f.size)]})]},f.timestamp))}),e.length>0&&c.jsxs("div",{className:"versions-tab__footer",children:[c.jsx("button",{className:"versions-tab__review-btn",disabled:r===null||i,onClick:()=>d("review"),children:"Review"}),c.jsx("button",{className:"versions-tab__restore-btn",disabled:r===null||i,onClick:()=>d("full"),children:"Restore"})]})]})}function u$({docId:t,currentFilename:e,onSwitchDocument:n}){const[r,s]=x.useState(new Map),[i,o]=x.useState([]),[l,d]=x.useState([]),[f,h]=x.useState(!0),[m,g]=x.useState(!1);x.useEffect(()=>{let w=!1;const E=async()=>{try{const j=await(await fetch("/api/documents")).json();if(w)return;const _=new Map;if(Array.isArray(j))for(const A of j)A!=null&&A.docId&&_.set(A.docId,{docId:A.docId,filename:A.filename,title:A.title||A.filename});s(_)}catch{}finally{w||h(!1)}};E();const C=()=>E();return window.addEventListener("ow-documents-changed",C),()=>{w=!0,window.removeEventListener("ow-documents-changed",C)}},[]),x.useEffect(()=>{if(!t){o([]);return}let w=!1;const E=()=>{g(!0),fetch(`/api/backlinks/${t}`).then(T=>T.ok?T.json():[]).then(T=>{w||o(Array.isArray(T)?T:[])}).catch(()=>{w||o([])}).finally(()=>{w||g(!1)})};E();const C=()=>E();return window.addEventListener("ow-metadata-changed",C),()=>{w=!0,window.removeEventListener("ow-metadata-changed",C)}},[t]),x.useEffect(()=>{let w=!1;const E=()=>{fetch("/api/document").then(T=>T.json()).then(T=>{var _;if(w)return;const j=(_=T==null?void 0:T.metadata)==null?void 0:_.references;d(Array.isArray(j)?j:[])}).catch(()=>{w||d([])})};E();const C=()=>E();return window.addEventListener("ow-metadata-changed",C),()=>{w=!0,window.removeEventListener("ow-metadata-changed",C)}},[e,t]);const v=x.useMemo(()=>i.map(w=>{const E=r.get(w.from_doc);return E?{docId:w.from_doc,title:E.title,filename:E.filename,snippet:w.text}:null}).filter(w=>w!==null),[i,r]),b=x.useMemo(()=>l.map(w=>{const E=r.get(w);return E?{docId:w,title:E.title,filename:E.filename}:null}).filter(w=>w!==null),[l,r]);if(!t)return c.jsxs("div",{className:"backlinks-tab__empty",children:[c.jsx("div",{className:"backlinks-tab__empty-title",children:"No document open"}),c.jsx("div",{className:"backlinks-tab__empty-note",children:"Open a doc to see what links to it and what it links out to."})]});const k=f||m;return c.jsxs("div",{className:"backlinks-tab",children:[c.jsxs("div",{className:"backlinks-tab__group",children:[c.jsxs("div",{className:"backlinks-tab__group-label",children:["Inbound ",c.jsx("span",{className:"backlinks-tab__count",children:v.length})]}),k&&v.length===0?c.jsx("div",{className:"backlinks-tab__empty-note backlinks-tab__inline-note",children:"Loading…"}):v.length===0?c.jsx("div",{className:"backlinks-tab__empty-note backlinks-tab__inline-note",children:"No docs link to this one yet."}):v.map(w=>c.jsxs("button",{type:"button",className:"backlinks-tab__entry",onClick:()=>n(w.filename),children:[c.jsx("div",{className:"backlinks-tab__entry-title",children:w.title}),w.snippet&&c.jsx("div",{className:"backlinks-tab__entry-snippet",children:w.snippet})]},w.docId))]}),c.jsxs("div",{className:"backlinks-tab__group",children:[c.jsxs("div",{className:"backlinks-tab__group-label",children:["Outbound ",c.jsx("span",{className:"backlinks-tab__count",children:b.length})]}),b.length===0?c.jsx("div",{className:"backlinks-tab__empty-note backlinks-tab__inline-note",children:"This doc doesn’t reference others yet."}):b.map(w=>c.jsx("button",{type:"button",className:"backlinks-tab__entry",onClick:()=>n(w.filename),children:c.jsx("div",{className:"backlinks-tab__entry-title",children:w.title})},w.docId))]})]})}const d$=[{key:"md",label:"Markdown",desc:"Plain .md file",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("path",{d:"M14 2v6h6"})]})},{key:"html",label:"HTML",desc:"Styled web page",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"16 18 22 12 16 6"}),c.jsx("polyline",{points:"8 6 2 12 8 18"})]})},{key:"docx",label:"Word",desc:"Microsoft Word .docx",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("path",{d:"M14 2v6h6"}),c.jsx("path",{d:"M16 13H8"}),c.jsx("path",{d:"M16 17H8"}),c.jsx("path",{d:"M10 9H8"})]})},{key:"txt",label:"Plain Text",desc:"Unformatted .txt file",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 6.1H3"}),c.jsx("path",{d:"M21 12.1H3"}),c.jsx("path",{d:"M15.1 18H3"})]})},{key:"pdf",label:"PDF",desc:"Print preview for save as PDF",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"6 9 6 2 18 2 18 9"}),c.jsx("path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),c.jsx("rect",{x:"6",y:"14",width:"12",height:"8"})]})}];function f$(t){const e=n=>{if(n==="pdf"){window.open("/api/export?format=pdf","_blank");return}const r=document.createElement("a");r.href=`/api/export?format=${n}`,r.download="",document.body.appendChild(r),r.click(),document.body.removeChild(r)};return c.jsx("div",{className:"exports-tab",children:c.jsx("div",{className:"exports-tab__list",children:d$.map(n=>c.jsxs("button",{type:"button",className:"exports-tab__item",onClick:()=>e(n.key),children:[c.jsx("span",{className:"exports-tab__item-icon",children:n.icon}),c.jsxs("span",{className:"exports-tab__item-text",children:[c.jsx("span",{className:"exports-tab__item-label",children:n.label}),c.jsx("span",{className:"exports-tab__item-desc",children:n.desc})]})]},n.key))})})}const h$=3e4,p$=500;let pi={entries:[],freshKeys:new Set};const Qg=new Set;function $2(t){return`${t.ts}:${t.kind}:${t.headline}`}function m$(){for(const t of Qg)t(pi)}function Zg(t){pi=t,m$()}function g$(t){return Qg.add(t),()=>{Qg.delete(t)}}function v$(){return pi}function y$(t){const e=t.detail;e!=null&&e.entries&&Zg({entries:e.entries,freshKeys:new Set})}function b$(t){const e=t.detail;if(!(e!=null&&e.event))return;const n=e.event,r=$2(n),s={entries:[n,...pi.entries].slice(0,p$),freshKeys:new Set([...pi.freshKeys,r])};Zg(s),window.setTimeout(()=>{if(pi.freshKeys.has(r)){const i=new Set(pi.freshKeys);i.delete(r),Zg({...pi,freshKeys:i})}},h$)}typeof window<"u"&&(window.addEventListener("ow-activity-seed",y$),window.addEventListener("ow-activity-event",b$));function x$(){const[t,e]=x.useState(v$);return x.useEffect(()=>g$(e),[]),t}function w$(){const[t,e]=x.useState(()=>({byDocId:new Map,filenameSet:new Set}));return x.useEffect(()=>{let n=!1;const r=()=>{fetch("/api/documents").then(s=>s.json()).then(s=>{if(n||!Array.isArray(s))return;const i=new Map,o=new Set;for(const l of s)l.filename&&o.add(l.filename),l.docId&&l.filename&&i.set(l.docId,l.filename);e({byDocId:i,filenameSet:o})}).catch(()=>{})};return r(),window.addEventListener("ow-documents-changed",r),()=>{n=!0,window.removeEventListener("ow-documents-changed",r)}},[]),t}function k$(t,e){return t.docId?e.byDocId.get(t.docId)??null:t.filename&&e.filenameSet.has(t.filename)?t.filename:null}function S$(t,e){const n=Math.max(0,e-t),r=Math.floor(n/1e3);if(r<45)return"just now";const s=Math.floor(r/60);if(s<60)return`${s}m ago`;const i=Math.floor(s/60);if(i<24)return`${i}h ago`;const o=Math.floor(i/24);return o<7?`${o}d ago`:new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function E$({onSwitchDocument:t}){const{entries:e,freshKeys:n}=x$(),r=w$(),[s,i]=x.useState(()=>Date.now());x.useEffect(()=>{const l=setInterval(()=>i(Date.now()),3e4);return()=>clearInterval(l)},[]);const o=x.useMemo(()=>N$(e,s),[e,s]);return e.length===0?c.jsxs("div",{className:"activity-tab__empty",children:[c.jsx("div",{className:"activity-tab__empty-title",children:"No activity yet"}),c.jsx("div",{className:"activity-tab__empty-note",children:"Agent actions — writes, enrichment, backlink propagation — will appear here as they happen."})]}):c.jsx("div",{className:"activity-tab",children:o.map(l=>c.jsxs("div",{className:"activity-tab__group",children:[c.jsx("div",{className:"activity-tab__group-label",children:l.label}),l.entries.map(d=>{const f=$2(d),h=n.has(f),m=d.kind==="doc-deleted"?null:k$(d,r),g=m!==null,v=!g,b=v&&d.kind!=="doc-deleted"?"Doc no longer available":void 0,k=()=>{m&&t(m)};return c.jsxs("div",{className:`activity-tab__entry${h?" activity-tab__entry--fresh":""}${g?" activity-tab__entry--clickable":""}${v?" activity-tab__entry--muted":""}`,role:g?"button":void 0,tabIndex:g?0:void 0,title:b,onClick:k,onKeyDown:w=>{g&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),k())},children:[c.jsx("span",{className:`activity-tab__kind-dot activity-tab__kind-dot--${d.kind}`,"aria-hidden":"true"}),c.jsxs("div",{className:"activity-tab__entry-body",children:[c.jsx("div",{className:"activity-tab__headline",children:d.headline}),d.detail&&c.jsx("div",{className:"activity-tab__detail",children:d.detail})]}),c.jsx("div",{className:"activity-tab__ts",title:new Date(d.ts).toLocaleString(),children:S$(d.ts,s)})]},f)})]},l.label))})}function N$(t,e){if(t.length===0)return[];const n=Rk(e),r=n-1440*60*1e3,s=[];let i=null;for(const o of t){const l=Rk(o.ts);let d;l===n?d="Today":l===r?d="Yesterday":d=new Date(o.ts).toLocaleDateString(void 0,{weekday:"long",month:"short",day:"numeric"}),(!i||i.label!==d)&&(i={label:d,entries:[]},s.push(i)),i.entries.push(o)}return s}function Rk(t){const e=new Date(t);return e.setHours(0,0,0,0),e.getTime()}async function yu(t,e={}){var s,i;const r=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:t,arguments:e})})).json();if((i=(s=r==null?void 0:r.content)==null?void 0:s[0])!=null&&i.text)try{return JSON.parse(r.content[0].text)}catch{return r.content[0].text}return r}function C$(){const[t,e]=x.useState([]),[n,r]=x.useState(!0),[s,i]=x.useState("closed"),[o,l]=x.useState(""),[d,f]=x.useState(!1),[h,m]=x.useState(null),[g,v]=x.useState(null),[b,k]=x.useState(null),w=x.useCallback(async()=>{r(!0);try{const _=await yu("list_blog_sites");e((_==null?void 0:_.sites)||[])}finally{r(!1)}},[]);x.useEffect(()=>{w()},[w]);const E=()=>{i("closed"),l(""),m(null),v(null),k(null)},C=async()=>{if(o.trim()){f(!0),m(null);try{const _=await yu("inspect_blog_repo",{repo_url:o.trim()});if(_.error){m(_.error);return}v({..._,label:_.repo,branch:"main",site_url:_.site_url||"",blog_url_pattern:_.blog_url_pattern||"/blog/{slug}/"}),i("review")}catch(_){m((_==null?void 0:_.message)||"Inspection failed")}finally{f(!1)}}},T=async()=>{if(g){i("saving"),k(null);try{const _=await yu("add_blog_site",{label:g.label,owner:g.owner,repo:g.repo,branch:g.branch||"main",content_dir:g.content_dir,image_dir:g.image_dir,image_public_prefix:g.image_public_prefix,framework:g.framework,frontmatter_defaults:g.frontmatter_defaults||{},frontmatter_field_map:g.frontmatter_field_map||{},frontmatter_schema:g.frontmatter_schema||[],site_url:g.site_url||"",blog_url_pattern:g.blog_url_pattern||"/blog/{slug}/"});if(_!=null&&_.error){k(_.error),i("review");return}E(),await w()}catch(_){k((_==null?void 0:_.message)||"Save failed"),i("review")}}},j=async _=>{if(!window.confirm(`Remove "${_.label}" (${_.owner}/${_.repo})?
208
208
 
209
- This only removes the OpenWriter registration. Your GitHub repo is untouched.`))return;const O=await yu("remove_blog_site",{id:_.id});if(O!=null&&O.error){alert(`Remove failed: ${O.error}`);return}await w()};return c.jsxs("div",{className:"github-plugin-settings",children:[c.jsxs("div",{className:"github-plugin-settings__header",children:[c.jsx("span",{className:"github-plugin-settings__title",children:"Blog repos"}),s==="closed"&&c.jsx("button",{className:"github-plugin-settings__add-btn",onClick:()=>i("url"),children:"+ Add"})]}),n?c.jsx("div",{className:"github-plugin-settings__loading",children:"Loading…"}):t.length===0&&s==="closed"?c.jsxs("div",{className:"github-plugin-settings__empty",children:["Connect a GitHub repo to publish blog posts via local git — no PATs, no Workers. Uses your existing ",c.jsx("code",{children:"gh auth login"}),"."]}):c.jsx("div",{className:"github-plugin-settings__list",children:t.map(_=>c.jsxs("div",{className:"github-plugin-settings__site",children:[c.jsxs("div",{className:"github-plugin-settings__site-info",children:[c.jsxs("div",{className:"github-plugin-settings__site-row1",children:[c.jsx("span",{className:"github-plugin-settings__site-label",children:_.label}),c.jsx("span",{className:`github-plugin-settings__site-framework github-plugin-settings__site-framework--${_.framework}`,children:_.framework})]}),c.jsxs("div",{className:"github-plugin-settings__site-repo",children:[_.owner,"/",_.repo,"@",_.branch]}),c.jsxs("div",{className:"github-plugin-settings__site-dirs",children:[c.jsx("span",{title:"content_dir",children:_.content_dir}),c.jsx("span",{className:"github-plugin-settings__site-sep",children:"·"}),c.jsx("span",{title:"image_public_prefix",children:_.image_public_prefix})]})]}),c.jsx("button",{className:"github-plugin-settings__remove-btn",onClick:()=>j(_),title:"Remove",children:"×"})]},_.id))}),s==="url"&&c.jsxs("div",{className:"github-plugin-settings__form",children:[c.jsx("label",{className:"github-plugin-settings__label",children:"GitHub repo"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"owner/repo or https://github.com/owner/repo",value:o,onChange:_=>l(_.target.value),onKeyDown:_=>{_.key==="Enter"&&!d&&C()},autoFocus:!0}),h&&c.jsx("div",{className:"github-plugin-settings__error",children:h}),c.jsxs("div",{className:"github-plugin-settings__form-buttons",children:[c.jsx("button",{className:"github-plugin-settings__btn github-plugin-settings__btn--primary",onClick:C,disabled:d||!o.trim(),children:d?"Inspecting…":"Inspect"}),c.jsx("button",{className:"github-plugin-settings__btn",onClick:E,disabled:d,children:"Cancel"})]})]}),(s==="review"||s==="saving")&&g&&c.jsxs("div",{className:"github-plugin-settings__form",children:[c.jsxs("div",{className:"github-plugin-settings__form-meta",children:[c.jsxs("span",{children:["Detected: ",g.framework]}),c.jsx("span",{children:"·"}),c.jsxs("span",{children:[g.markdown_files_found," posts"]}),c.jsx("span",{children:"·"}),c.jsxs("span",{className:`github-plugin-settings__confidence github-plugin-settings__confidence--${g.confidence}`,children:[g.confidence," confidence"]})]}),c.jsx("label",{className:"github-plugin-settings__label",children:"Label"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.label,onChange:_=>v({...g,label:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Branch"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.branch,onChange:_=>v({...g,branch:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Content directory"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.content_dir,onChange:_=>v({...g,content_dir:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Image directory"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.image_dir,onChange:_=>v({...g,image_dir:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Image public prefix"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.image_public_prefix,onChange:_=>v({...g,image_public_prefix:_.target.value})}),c.jsxs("label",{className:"github-plugin-settings__label",children:["Site URL ",c.jsx("span",{className:"github-plugin-settings__hint",children:"— optional, used for the live link after publish"})]}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"https://example.com",value:g.site_url||"",onChange:_=>v({...g,site_url:_.target.value})}),c.jsxs("label",{className:"github-plugin-settings__label",children:["Blog URL pattern ",c.jsxs("span",{className:"github-plugin-settings__hint",children:["— uses ","{slug}"," placeholder"]})]}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"/blog/{slug}/",value:g.blog_url_pattern||"",onChange:_=>v({...g,blog_url_pattern:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Framework"}),c.jsxs("select",{className:"github-plugin-settings__input",value:g.framework,onChange:_=>v({...g,framework:_.target.value}),children:[c.jsx("option",{value:"astro",children:"Astro"}),c.jsx("option",{value:"next",children:"Next"}),c.jsx("option",{value:"jekyll",children:"Jekyll"}),c.jsx("option",{value:"hugo",children:"Hugo"}),c.jsx("option",{value:"unknown",children:"Unknown"})]}),g.frontmatter_schema.length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsxs("span",{className:"github-plugin-settings__label",children:["Frontmatter keys detected (",g.samples_analyzed," ",g.samples_analyzed===1?"sample":"samples",")"]}),c.jsx("code",{children:g.frontmatter_schema.join(", ")})]}),Object.keys(g.frontmatter_defaults||{}).length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsx("span",{className:"github-plugin-settings__label",children:"Frontmatter defaults (constants applied to every post)"}),c.jsx("code",{children:Object.entries(g.frontmatter_defaults).map(([_,A])=>c.jsxs("div",{children:[_,": ",typeof A=="string"?A:JSON.stringify(A)]},_))})]}),Object.keys(g.frontmatter_field_map||{}).length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsx("span",{className:"github-plugin-settings__label",children:"Field name mapping (openwriter → site)"}),c.jsx("code",{children:Object.entries(g.frontmatter_field_map).map(([_,A])=>c.jsxs("div",{children:[_," → ",A]},_))})]}),b&&c.jsx("div",{className:"github-plugin-settings__error",children:b}),c.jsxs("div",{className:"github-plugin-settings__form-buttons",children:[c.jsx("button",{className:"github-plugin-settings__btn github-plugin-settings__btn--primary",onClick:T,disabled:s==="saving"||!g.label.trim(),children:s==="saving"?"Saving…":"Add site"}),c.jsx("button",{className:"github-plugin-settings__btn",onClick:E,disabled:s==="saving",children:"Cancel"})]})]})]})}const _$={none:"No Plan",free:"No Plan",creator:"Creator — $19/mo",growth:"Growth — $49/mo",publisher:"Publisher — $79/mo"},T$=[{plan:"creator",label:"Creator $19/mo"},{plan:"growth",label:"Growth $49/mo"}];function j$(){var d,f;const[t,e]=x.useState(null),[n,r]=x.useState(!0);x.useEffect(()=>{fetch("/api/billing").then(h=>h.json()).then(h=>e(h)).catch(()=>{}).finally(()=>r(!1))},[]);const s=x.useCallback(async h=>{const m=await fetch("/api/billing/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plan:h})});if(m.ok){const g=await m.json();g.url&&window.open(g.url,"_blank")}},[]),i=x.useCallback(async()=>{const h=await fetch("/api/billing/portal",{method:"POST",headers:{"Content-Type":"application/json"}});if(h.ok){const m=await h.json();m.url&&window.open(m.url,"_blank")}},[]);if(n)return c.jsx("div",{className:"billing-section",children:c.jsx("div",{className:"billing-loading",children:"Loading..."})});if(!(t!=null&&t.authenticated))return null;const o=t.plan||"free",l=T$.filter(h=>{const m=["free","creator","growth","publisher"];return m.indexOf(h.plan)>m.indexOf(o)});return c.jsxs("div",{className:"billing-section",children:[c.jsxs("div",{className:"billing-plan",children:[c.jsx("span",{className:"billing-plan-label",children:"Plan"}),c.jsx("span",{className:`billing-plan-badge billing-plan-badge--${o}`,children:_$[o]||o})]}),((d=t.billing)==null?void 0:d.paymentFailed)&&c.jsx("div",{className:"billing-warning",children:"Payment failed — update card to keep your plan."}),l.length>0&&c.jsx("div",{className:"billing-upgrades",children:l.map(h=>c.jsxs("button",{className:"billing-upgrade-btn",onClick:()=>s(h.plan),children:["Upgrade to ",h.label]},h.plan))}),((f=t.billing)==null?void 0:f.hasPaymentMethod)&&c.jsx("button",{className:"billing-manage-btn",onClick:i,children:"Manage Billing"})]})}function Ok(t){return t.replace(/^@openwriter\/plugin-/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function M$(t){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(new Set),l=x.useCallback(()=>{fetch("/api/available-plugins").then(h=>h.json()).then(h=>n(h.plugins||[])).catch(()=>{})},[]);x.useEffect(()=>{l()},[l]),x.useEffect(()=>{const h=()=>l();return window.addEventListener("ow-plugins-changed",h),()=>window.removeEventListener("ow-plugins-changed",h)},[l]);const d=x.useCallback(async(h,m)=>{s(h);try{(await fetch(m?"/api/plugins/disable":"/api/plugins/enable",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:h})})).ok&&l()}catch{}finally{s(null)}},[l]),f=x.useCallback((h,m,g)=>{fetch("/api/plugins/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:h,config:{[m]:g}})}).catch(()=>{})},[]);return c.jsx("div",{className:"plugins-tab",children:e.length===0?c.jsx("div",{className:"plugin-empty",children:"No plugins found"}):e.map(h=>c.jsxs("div",{className:"plugin-item",children:[c.jsxs("div",{className:"plugin-item-header",children:[c.jsxs("div",{className:"plugin-item-info",children:[c.jsxs("div",{className:"plugin-item-name",children:[Ok(h.name),c.jsxs("span",{className:"plugin-item-version",children:["v",h.version]})]}),h.description&&c.jsx("div",{className:"plugin-item-desc",children:h.description})]}),c.jsxs("label",{className:`plugin-toggle${r===h.name?" loading":""}`,children:[c.jsx("input",{type:"checkbox",checked:h.enabled,disabled:r===h.name,onChange:()=>d(h.name,h.enabled)}),c.jsx("span",{className:"plugin-toggle-track"}),c.jsx("span",{className:"plugin-toggle-thumb"})]})]}),h.enabled&&h.name==="@openwriter/plugin-publish"&&c.jsx(j$,{}),h.enabled&&h.name==="@openwriter/plugin-github"&&c.jsx(C$,{}),h.enabled&&Object.keys(h.configSchema).length>0&&(()=>{const m=Object.entries(h.configSchema).some(([g,v])=>v.required&&!h.config[g]);return c.jsxs("div",{className:"plugin-config-section",children:[m&&c.jsxs("div",{className:"plugin-setup-hint",children:["Ask your agent: “set up ",Ok(h.name),"”"]}),c.jsxs("button",{className:"plugin-config-toggle",onClick:()=>o(g=>{const v=new Set(g);return v.has(h.name)?v.delete(h.name):v.add(h.name),v}),children:[c.jsx("svg",{className:`plugin-config-chevron${i.has(h.name)?" plugin-config-chevron--open":""}`,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Settings"]}),i.has(h.name)&&c.jsx("div",{className:"plugin-config",children:Object.entries(h.configSchema).map(([g,v])=>c.jsxs("div",{className:"plugin-config-field",children:[c.jsx("label",{className:"plugin-config-label",children:v.description||g}),c.jsx("input",{className:"plugin-config-input",type:g.toLowerCase().includes("key")||g.toLowerCase().includes("secret")||g.toLowerCase().includes("token")?"password":"text",defaultValue:h.config[g]||"",placeholder:v.env?`$${v.env}`:"",onBlur:b=>f(h.name,g,b.target.value)})]},g))})]})})()]},h.name))})}function A$({existingConnection:t,onClose:e,onSaved:n}){const[r,s]=x.useState("form"),[i,o]=x.useState(null),[l,d]=x.useState((t==null?void 0:t.domain)||""),[f,h]=x.useState(""),[m,g]=x.useState((t==null?void 0:t.from_name)||""),[v,b]=x.useState(""),[k,w]=x.useState((t==null?void 0:t.id)||""),[E,C]=x.useState({dns_verified:!1,sender_verified:!1}),T=x.useRef(null),j=x.useRef(null);x.useEffect(()=>{const J=z=>{r!=="submitting"&&r!=="verifying"&&j.current&&!j.current.contains(z.target)&&e()};return document.addEventListener("mousedown",J),()=>document.removeEventListener("mousedown",J)},[e,r]),x.useEffect(()=>{const J=z=>{z.key==="Escape"&&r!=="submitting"&&r!=="verifying"&&e()};return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[e,r]),x.useEffect(()=>()=>{T.current&&clearInterval(T.current)},[]);async function _(){var J,z;s("submitting"),o(null);try{const D=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"setup_custom_domain",arguments:{domain:l,from_email:f,from_name:m||void 0,physical_address:v}})})).json(),U=(z=(J=D.content)==null?void 0:J[0])!=null&&z.text?JSON.parse(D.content[0].text):D;if(U.error){o(U.error),s("error");return}const q=U.connectionId||U.connection_id||k;q&&w(q),O(q)}catch(G){o(G.message),s("error")}}async function A(){var J,z;s("submitting"),o(null);try{const D=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"setup_custom_domain",arguments:{domain:l,from_email:f||void 0,from_name:m||void 0,physical_address:v||void 0}})})).json(),U=(z=(J=D.content)==null?void 0:J[0])!=null&&z.text?JSON.parse(D.content[0].text):D;if(U.error){o(U.error),s("error");return}s("done")}catch(G){o(G.message),s("error")}}function O(J){s("verifying"),T.current=setInterval(async()=>{var z,G;try{const U=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"check_domain_status",arguments:{connectionId:J}})})).json(),q=(G=(z=U.content)==null?void 0:z[0])!=null&&G.text?JSON.parse(U.content[0].text):U,se=!!q.dns_verified,V=!!q.sender_verified;C({dns_verified:se,sender_verified:V}),se&&V&&(T.current&&clearInterval(T.current),T.current=null,s("done"))}catch{}},5e3)}function B(){k&&fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"resend_domain_verification",arguments:{connectionId:k}})}).catch(()=>{})}const $=!!t,W=l.trim()&&f.trim()&&v.trim();return c.jsx("div",{className:"newsletter-modal-overlay",children:c.jsxs("div",{className:"newsletter-modal newsletter-modal--setup",ref:j,children:[c.jsxs("div",{className:"newsletter-modal__header",children:[c.jsx("h3",{children:$?"Newsletter Settings":"Set Up Newsletter"}),c.jsx("button",{className:"newsletter-modal__close",onClick:e,children:"×"})]}),c.jsxs("div",{className:"newsletter-modal__body",children:[r==="form"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsx("label",{className:"newsletter-modal__label",children:"Domain"}),c.jsx("input",{className:"newsletter-modal__input",type:"text",placeholder:"yourdomain.com",value:l,onChange:J=>d(J.target.value),disabled:$,autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsx("label",{className:"newsletter-modal__label",children:"From Email"}),c.jsx("input",{className:"newsletter-modal__input",type:"email",placeholder:"newsletter@yourdomain.com",value:f,onChange:J=>h(J.target.value),autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsxs("label",{className:"newsletter-modal__label",children:["From Name ",c.jsx("span",{className:"newsletter-modal__optional",children:"(optional)"})]}),c.jsx("input",{className:"newsletter-modal__input",type:"text",placeholder:"Your Name or Brand",value:m,onChange:J=>g(J.target.value),autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsxs("label",{className:"newsletter-modal__label",children:["Physical Address ",c.jsx("span",{className:"newsletter-modal__required",children:"*"})]}),c.jsx("textarea",{className:"newsletter-modal__input newsletter-modal__textarea",rows:2,placeholder:"123 Main St, City, State 12345",value:v,onChange:J=>b(J.target.value)}),c.jsx("span",{className:"newsletter-modal__hint",children:"Required by CAN-SPAM. Included in email footer."})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:e,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:$?A:_,disabled:!W,children:$?"Save":"Set Up Domain"})]})]}),r==="submitting"&&c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:$?"Saving...":"Setting up domain..."})]}),r==="verifying"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__verify",children:[c.jsx("p",{className:"newsletter-modal__verify-title",children:"Verifying domain setup..."}),c.jsxs("div",{className:"newsletter-modal__verify-checks",children:[c.jsxs("div",{className:`newsletter-modal__verify-item${E.dns_verified?" newsletter-modal__verify-item--done":""}`,children:[E.dns_verified?"✓":c.jsx("span",{className:"newsletter-modal__spinner newsletter-modal__spinner--sm"}),c.jsx("span",{children:"DNS records"})]}),c.jsxs("div",{className:`newsletter-modal__verify-item${E.sender_verified?" newsletter-modal__verify-item--done":""}`,children:[E.sender_verified?"✓":c.jsx("span",{className:"newsletter-modal__spinner newsletter-modal__spinner--sm"}),c.jsx("span",{children:"Sender verification"})]})]}),c.jsx("p",{className:"newsletter-modal__hint",children:"This may take a few minutes. You can close and check back later."})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:B,children:"Resend Verification"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>{n(),e()},children:"Close"})]})]}),r==="done"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__status newsletter-modal__status--success",children:$?"Settings saved!":"Newsletter domain configured!"}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>{n(),e()},children:"Done"})})]}),r==="error"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__error",children:i}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:e,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>s("form"),children:"Try Again"})]})]})]})]})})}const R$={x:[],linkedin:[]};function O$({connectionId:t,provider:e,displayName:n,onClose:r,onSaved:s}){const[i,o]=x.useState("loading"),[l,d]=x.useState({}),[f,h]=x.useState(null),m=x.useRef(null),g=R$[e]||[];x.useEffect(()=>{fetch(`/api/connections/${t}/config`).then(k=>k.json()).then(k=>{d(k.config||{}),o("form")}).catch(k=>{h(k.message),o("error")})},[t]),x.useEffect(()=>{const k=w=>{i!=="saving"&&m.current&&!m.current.contains(w.target)&&r()};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[r,i]),x.useEffect(()=>{const k=w=>{w.key==="Escape"&&i!=="saving"&&r()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[r,i]);async function v(){o("saving"),h(null);try{const k=await fetch(`/api/connections/${t}/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),w=await k.json();if(!k.ok)throw new Error(w.error||"Failed to save");o("saved"),s(),setTimeout(r,800)}catch(k){h(k.message),o("error")}}function b(k){switch(k){case"x":return"X (Twitter)";case"linkedin":return"LinkedIn";default:return k}}return c.jsx("div",{className:"conn-config-overlay",children:c.jsxs("div",{className:"conn-config-modal",ref:m,children:[c.jsxs("div",{className:"conn-config-modal__header",children:[c.jsxs("div",{className:"conn-config-modal__title",children:[b(e)," Settings"]}),c.jsx("div",{className:"conn-config-modal__subtitle",children:n})]}),i==="loading"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("div",{className:"conn-config-spinner"}),c.jsx("span",{children:"Loading configuration..."})]}),(i==="form"||i==="error")&&g.length>0&&c.jsxs("div",{className:"conn-config-modal__body",children:[g.map(k=>c.jsxs("div",{className:"conn-config-field",children:[c.jsxs("label",{className:"conn-config-field__label",children:[k.label,k.readonly&&c.jsx("span",{className:"conn-config-field__badge",children:"read-only"})]}),c.jsx("input",{className:"conn-config-field__input",value:l[k.key]||"",placeholder:k.placeholder,readOnly:k.readonly,onChange:w=>d(E=>({...E,[k.key]:w.target.value}))})]},k.key)),f&&c.jsx("div",{className:"conn-config-modal__error",children:f})]}),(i==="form"||i==="error")&&g.length===0&&c.jsx("div",{className:"conn-config-modal__body conn-config-modal__center",children:c.jsxs("span",{className:"conn-config-modal__empty",children:["No configuration needed for ",b(e),"."]})}),i==="saving"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("div",{className:"conn-config-spinner"}),c.jsx("span",{children:"Saving..."})]}),i==="saved"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"#22c55e",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),c.jsx("span",{children:"Saved"})]}),c.jsxs("div",{className:"conn-config-modal__footer",children:[c.jsx("button",{className:"conn-config-btn conn-config-btn--secondary",onClick:r,children:i==="saved"?"Close":"Cancel"}),g.length>0&&(i==="form"||i==="error")&&c.jsx("button",{className:"conn-config-btn conn-config-btn--primary",onClick:v,children:"Save"})]})]})})}const I$=[{id:"x",label:"X (Twitter)",oauth:!0},{id:"linkedin",label:"LinkedIn",oauth:!0},{id:"newsletter",label:"Newsletter",oauth:!1}];function Dp(t){switch(t){case"x":return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})});case"linkedin":return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"})});case"newsletter":return c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),c.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]});default:return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("circle",{cx:"12",cy:"12",r:"10"})})}}function L$(t){return t==="active"?"connections-status--active":t==="expired"?"connections-status--expired":t==="revoked"?"connections-status--revoked":"connections-status--pending"}function D$(t){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(null),[l,d]=x.useState(null),[f,h]=x.useState(null),[m,g]=x.useState(null),v=x.useRef(null);async function b(){try{const A=await(await fetch("/api/connections")).json();s(A.authenticated!==!1);const O=(A.connections||[]).filter(B=>B&&B.id&&B.provider);return n(O),O}catch{return[]}}x.useEffect(()=>{b()},[]),x.useEffect(()=>()=>{v.current&&clearInterval(v.current)},[]);async function k(_){d(_);try{const A=await fetch(`/api/connections/oauth/${_}/start`,{method:"POST"}),O=await A.json();if(!A.ok||!O.url){d(null);return}window.open(O.url,"_blank","width=600,height=700"),v.current=setInterval(async()=>{try{const $=await(await fetch(`/api/connections/oauth/${_}/status/${O.state}`)).json();if($.status==="completed"){v.current&&clearInterval(v.current),v.current=null,d(null);const W=await b();if(_==="x"){const J=W.find(z=>z.provider==="x"&&z.status==="active");if(J!=null&&J.display_name){const z=J.display_name.replace("@","");localStorage.setItem("ow-x-handle",z),window.dispatchEvent(new StorageEvent("storage",{key:"ow-x-handle",newValue:z}))}}}else $.status==="failed"&&(v.current&&clearInterval(v.current),v.current=null,d(null))}catch{}},2e3)}catch{d(null)}}async function w(_){try{const A=await fetch(`/api/connections/${_}`,{method:"DELETE"});if(!A.ok){const O=await A.json().catch(()=>({error:"Delete failed"}));console.error("[Connections] Delete failed:",O.error)}}catch(A){console.error("[Connections] Delete error:",A)}o(null),await b()}const E=new Map,C=new Map;for(const _ of e){E.has(_.provider)||E.set(_.provider,_);const A=C.get(_.provider)||[];A.push(_),C.set(_.provider,A)}const T=new Set,j=r===!1;return c.jsxs("div",{className:"connections-tab",children:[m&&c.jsx(O$,{connectionId:m.id,provider:m.provider,displayName:m.display_name,onClose:()=>g(null),onSaved:()=>b()}),f&&c.jsx(A$,{existingConnection:f==="edit"?E.get("newsletter"):null,onClose:()=>h(null),onSaved:()=>b()}),j?c.jsxs("div",{className:"connections-dropdown__upsell",children:[c.jsx("p",{children:"Connect your X, LinkedIn, and other accounts to publish directly from OpenWriter."}),c.jsxs("p",{children:["Set up the ",c.jsx("strong",{children:"Publish"})," plugin to get started."]})]}):c.jsx("div",{className:"connections-dropdown__list",children:I$.flatMap(_=>{const A=T.has(_.id),O=C.get(_.id)||[],B=W=>i===W.id?c.jsxs("div",{className:"connections-dropdown__confirm",children:[c.jsxs("span",{children:["Disconnect ",W.display_name||_.label,"?"]}),c.jsxs("div",{className:"connections-dropdown__confirm-btns",children:[c.jsx("button",{onClick:()=>w(W.id),children:"Yes"}),c.jsx("button",{onClick:()=>o(null),children:"No"})]})]},W.id):c.jsxs("div",{className:"connections-dropdown__item",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Dp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:W.display_name||W.domain||_.label}),c.jsxs("div",{className:"connections-dropdown__type",children:[c.jsx("span",{className:`connections-status ${L$(W.status)}`}),"Connected"]})]}),c.jsxs("div",{className:"connections-dropdown__actions",children:[c.jsx("button",{className:"connections-dropdown__action-btn",onClick:()=>{_.id==="newsletter"?h("edit"):g({id:W.id,provider:_.id,display_name:W.display_name||_.label})},title:"Settings",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),c.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),c.jsx("button",{className:"connections-dropdown__action-btn connections-dropdown__action-btn--delete",onClick:()=>o(W.id),title:"Disconnect",children:"×"})]})]},W.id),$=O.map(B);return A?($.push(c.jsx("div",{className:"connections-dropdown__add-row",children:c.jsx("button",{className:"connections-dropdown__add-btn",onClick:()=>k(_.id),disabled:l!==null,children:l===_.id?"Connecting…":`+ Add ${_.label} repo`})},`${_.id}__add`)),$):O.length>0?$:_.oauth?[c.jsxs("div",{className:"connections-dropdown__item connections-dropdown__item--disconnected",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Dp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:_.label}),c.jsx("div",{className:"connections-dropdown__type",children:"Not connected"})]}),c.jsx("button",{className:"connections-dropdown__connect-inline-btn",onClick:()=>k(_.id),disabled:l!==null,children:l===_.id?"Connecting…":"Connect"})]},_.id)]:[c.jsxs("div",{className:"connections-dropdown__item connections-dropdown__item--disconnected",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Dp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:_.label}),c.jsx("div",{className:"connections-dropdown__type",children:"Built-in · Not configured"})]}),c.jsx("button",{className:"connections-dropdown__connect-inline-btn",onClick:()=>h("new"),children:"Configure"})]},_.id)]})})]})}const P$={tree:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M3 3h7v7H3zM14 3h7v4h-7zM14 10h7v4h-7zM3 13h7v8H3z"})}),files:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("polyline",{points:"14 2 14 8 20 8"})]}),timeline:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"22"}),c.jsx("circle",{cx:"12",cy:"6",r:"2"}),c.jsx("circle",{cx:"12",cy:"12",r:"2"}),c.jsx("circle",{cx:"12",cy:"18",r:"2"}),c.jsx("line",{x1:"14",y1:"6",x2:"20",y2:"6"}),c.jsx("line",{x1:"14",y1:"12",x2:"20",y2:"12"}),c.jsx("line",{x1:"14",y1:"18",x2:"20",y2:"18"})]}),board:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"5",height:"18",rx:"1"}),c.jsx("rect",{x:"10",y:"3",width:"5",height:"12",rx:"1"}),c.jsx("rect",{x:"17",y:"3",width:"5",height:"15",rx:"1"})]}),shelf:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 19V5"}),c.jsx("path",{d:"M8 19V7"}),c.jsx("path",{d:"M12 19V4"}),c.jsx("path",{d:"M16 19V8"}),c.jsx("path",{d:"M20 19V6"}),c.jsx("line",{x1:"2",y1:"20",x2:"22",y2:"20"})]})};function B$(t){const[e,n]=x.useState(kE),[r,s]=x.useState(SE),[i,o]=x.useState(Rd),l=EE(),[d,f]=x.useState(CE),[h,m]=x.useState(_E),g=(C=e,T=r,j=i,_=l,A=d,O=h)=>{TE(C,T,j,_,A,O)},v=C=>{n(C),g(C)},b=()=>{const C=r==="light"?"dark":"light";s(C),g(void 0,C)},k=C=>{o(C),g(void 0,void 0,C),window.dispatchEvent(new CustomEvent("ow-sidebar-mode-change",{detail:C}))},w=C=>{f(C),g(void 0,void 0,void 0,void 0,C)},E=C=>{m(C),g(void 0,void 0,void 0,void 0,void 0,C)};return c.jsxs("div",{className:"appearance-tab",children:[c.jsx("div",{className:"appearance-section",children:c.jsxs("div",{className:"appearance-section-header",children:[c.jsx("span",{className:"appearance-section-title",children:"Mode"}),c.jsxs("button",{className:"appearance-mode-btn",onClick:b,title:r==="light"?"Switch to dark":"Switch to light",children:[r==="light"?c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"5"}),c.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),c.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),c.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),c.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),c.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),c.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),c.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),c.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):c.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}),c.jsx("span",{children:r==="light"?"Light":"Dark"})]})]})}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Typography"})}),c.jsx("div",{className:"appearance-typeface-grid",children:yE.map(C=>c.jsx("button",{className:`appearance-style-option ${e===C.id?"active":""}`,onClick:()=>v(C.id),title:C.description,children:C.label},C.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Spacing"})}),c.jsx("div",{className:"appearance-typography-grid",children:wE.map(C=>c.jsx("button",{className:`appearance-style-option ${d===C.id?"active":""}`,onClick:()=>w(C.id),children:C.label},C.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Canvas"})}),c.jsx("div",{className:"appearance-style-grid",children:xE.map(C=>c.jsx("button",{className:`appearance-style-option ${h===C.id?"active":""}`,onClick:()=>E(C.id),children:C.label},C.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Layout"})}),c.jsx("div",{className:"appearance-mode-grid",children:bE.map(C=>c.jsxs("button",{className:`appearance-mode-option ${i===C.id?"active":""}`,onClick:()=>k(C.id),children:[P$[C.icon],c.jsx("span",{children:C.label})]},C.id))})]})]})}const z2=[{id:"review",label:"Review",scope:"doc",icon:c.jsx(j5,{}),Component:o$},{id:"activity",label:"Activity",scope:"workspace",icon:c.jsx(O5,{}),Component:E$},{id:"backlinks",label:"Backlinks",scope:"doc",icon:c.jsx(A5,{}),Component:u$},{id:"exports",label:"Export",scope:"doc",icon:c.jsx(R5,{}),Component:f$},{id:"versions",label:"Versions",scope:"doc",icon:c.jsx(M5,{}),Component:c$},{id:"plugins",label:"Plugins",scope:"settings",icon:c.jsx(I5,{}),Component:M$},{id:"connections",label:"Connections",scope:"settings",icon:c.jsx(L5,{}),Component:D$},{id:"appearance",label:"Appearance",scope:"settings",icon:c.jsx(D5,{}),Component:B$}];function $$(t){return t?z2.find(e=>e.id===t)??null:null}function Ik({pendingDocs:t}){const{open:e,activeTab:n,openTab:r}=Jd(),[s,i]=x.useState(!1),[o,l]=x.useState(!1),d=x.useRef(0);return x.useEffect(()=>{const f=t.filenames.length,h=d.current;d.current=f,h===0&&f>0&&r("review")},[t.filenames.length,r]),x.useEffect(()=>{const f=()=>r("review");return window.addEventListener("ow-pending-write-applied",f),()=>window.removeEventListener("ow-pending-write-applied",f)},[r]),x.useEffect(()=>{const f=()=>{if(!(e&&n==="activity")){i(!0),window.setTimeout(()=>i(!1),500);try{localStorage.getItem("ow-bell-hint-seen")||(l(!0),localStorage.setItem("ow-bell-hint-seen","1"),window.setTimeout(()=>l(!1),6e3))}catch{}}};return window.addEventListener("ow-activity-event",f),()=>window.removeEventListener("ow-activity-event",f)},[e,n]),c.jsx("div",{className:"rail-icon-strip",role:"tablist","aria-label":"Right rail tabs",children:z2.map(f=>{const h=e&&n===f.id,m=f.id==="activity";return c.jsxs("button",{type:"button",role:"tab","aria-selected":h,className:["rail-icon-btn",h?"rail-icon-btn--active":"",`rail-icon-btn--scope-${f.scope}`,m&&s?"rail-icon-btn--pulsing":""].filter(Boolean).join(" "),onClick:()=>r(f.id),title:f.label,"aria-label":f.label,children:[f.icon,m&&o&&c.jsxs("div",{className:"rail-icon-hint",role:"tooltip",children:[c.jsx("span",{children:"Agent activity lives here."}),c.jsx("button",{type:"button",className:"rail-icon-hint-close",onClick:g=>{g.stopPropagation(),l(!1)},"aria-label":"Dismiss",children:"×"})]})]},f.id)})})}function z$(t){const{activeTab:e}=Jd(),n=$$(e);return c.jsx("div",{className:"rail-body",role:"tabpanel",children:n?c.jsx(n.Component,{...t}):null})}const F$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),U$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M9 14l2 2 4-4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),H$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M12 16v-5M9.5 13.5L12 11l2.5 2.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),W$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M14 14l-4 4M10 14l4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});function q$({syncStatus:t,onSync:e}){const[n,r]=x.useState(!1),[s,i]=x.useState([]),[o,l]=x.useState(!1),d=x.useRef(null),f=x.useCallback(()=>{if(n){r(!1);return}r(!0),l(!0),fetch("/api/sync/pending").then(h=>h.json()).then(h=>i(h)).catch(()=>i([])).finally(()=>l(!1))},[n]);return x.useEffect(()=>{t.state!=="pending"&&r(!1)},[t.state]),x.useEffect(()=>{if(!n)return;const h=m=>{d.current&&!d.current.contains(m.target)&&r(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[n]),c.jsxs("div",{className:"sync-btn-group",ref:d,children:[c.jsxs("button",{className:`titlebar-btn sync-btn-state sync-${t.state}`,onClick:e,disabled:t.state==="syncing",title:t.lastSyncTime?`Last synced: ${new Date(t.lastSyncTime).toLocaleString()}`:"Sync to GitHub",children:[t.state==="unconfigured"&&c.jsxs(c.Fragment,{children:[c.jsx(F$,{})," Sync"]}),t.state==="synced"&&c.jsxs(c.Fragment,{children:[c.jsx(U$,{})," Synced"]}),t.state==="pending"&&c.jsxs(c.Fragment,{children:[c.jsx(H$,{})," Sync",t.pendingFiles?` (${t.pendingFiles})`:""]}),t.state==="syncing"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"sync-btn-spinner"})," Syncing..."]}),t.state==="error"&&c.jsxs(c.Fragment,{children:[c.jsx(W$,{})," Retry"]})]}),t.state==="pending"&&t.pendingFiles&&t.pendingFiles>0&&c.jsx("button",{className:"sync-details-btn",onClick:f,title:"View pending changes",children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:c.jsx("path",{d:n?"M3 7.5L6 4.5L9 7.5":"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n&&c.jsxs("div",{className:"sync-pending-dropdown",children:[c.jsx("div",{className:"sync-pending-header",children:"Changes to push"}),o?c.jsx("div",{className:"sync-pending-loading",children:"Loading..."}):s.length===0?c.jsx("div",{className:"sync-pending-loading",children:"No changes"}):c.jsx("div",{className:"sync-pending-list",children:s.map((h,m)=>c.jsxs("div",{className:`sync-pending-item sync-file-${h.status}`,children:[c.jsx("span",{className:"sync-file-badge",children:h.status[0].toUpperCase()}),c.jsx("span",{className:"sync-file-name",children:h.file})]},m))})]})]})}function V$(t){const{syncStatus:e,onSync:n,onToggleToolbar:r,toolbarOpen:s,focusMode:i,onToggleFocusMode:o,...l}=t,{open:d,activeTab:f,width:h,setWidth:m,closeRail:g,openTab:v}=Jd(),b=x.useRef(null),k=x.useRef(null),w=x.useRef(i);x.useEffect(()=>{if(i!==w.current)if(w.current=i,i)k.current={open:d,activeTab:f},d&&g();else{const C=k.current;k.current=null,C!=null&&C.open&&C.activeTab&&v(C.activeTab)}},[i]);const E=x.useCallback(C=>{C.preventDefault();const T=C.clientX,j=h,_=O=>{const B=T-O.clientX;m(j+B)},A=()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",A)},[h,m]);return x.useEffect(()=>{if(!d)return;const C=T=>{T.key==="Escape"&&b.current&&b.current.contains(document.activeElement)&&(T.preventDefault(),g())};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[d,g]),d?c.jsxs("aside",{ref:b,className:"right-rail-column",style:{width:h,minWidth:h},"aria-label":"Right rail",children:[c.jsx("div",{className:"right-rail-resize-handle",onPointerDown:E,"aria-hidden":"true"}),c.jsxs("div",{className:"right-rail-topbar",children:[c.jsxs("div",{className:"right-rail-topbar-actions right-rail-topbar-actions--start",children:[c.jsx("button",{type:"button",className:"right-rail-topbar-btn",onClick:g,title:"Hide rail","aria-label":"Hide rail",children:c.jsx(P5,{})}),c.jsx("button",{type:"button",className:`right-rail-topbar-btn${i?" right-rail-topbar-btn--active":""}`,onClick:o,title:"Focus mode","aria-label":"Focus mode","aria-pressed":i,children:c.jsx(v2,{})}),c.jsx("button",{type:"button",className:`right-rail-topbar-btn${s?" right-rail-topbar-btn--active":""}`,onClick:r,title:"Toggle format toolbar","aria-label":"Toggle format toolbar","aria-pressed":s,children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 20h16"}),c.jsx("path",{d:"m6 16 6-12 6 12"}),c.jsx("path",{d:"M8 12h8"})]})})]}),c.jsx("div",{className:"right-rail-topbar-actions right-rail-topbar-actions--end",children:c.jsx(q$,{syncStatus:e,onSync:n})})]}),c.jsx(Ik,{pendingDocs:l.pendingDocs}),c.jsx(z$,{...l})]}):c.jsx("div",{className:"right-rail-mount-keepalive",style:{display:"none"},children:c.jsx(Ik,{pendingDocs:l.pendingDocs})})}function K$({onClose:t,onSetupComplete:e}){const[n,r]=x.useState("detecting"),[s,i]=x.useState(null),[o,l]=x.useState("gh"),[d,f]=x.useState("openwriter-docs"),[h,m]=x.useState(!0),[g,v]=x.useState(""),[b,k]=x.useState(""),[w,E]=x.useState(""),[C,T]=x.useState("");x.useEffect(()=>{fetch("/api/sync/capabilities").then(_=>_.json()).then(_=>{i(_),_.ghAuthenticated?l("gh"):(_.gitInstalled,l("pat")),r("setup")}).catch(()=>{E("Failed to detect git capabilities"),r("error")})},[]);const j=x.useCallback(async()=>{r("progress"),T(o==="connect"?"Connecting to repository...":"Creating repository and syncing...");try{const _={method:o,repoName:d,isPrivate:h};o==="pat"&&(_.pat=g),o==="connect"&&(_.remoteUrl=b,_.pat=g||void 0);const A=await fetch("/api/sync/setup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)});if(!A.ok){const O=await A.json().catch(()=>({}));throw new Error(O.error||`Setup failed (${A.status})`)}r("done"),e()}catch(_){E(_.message),r("error")}},[o,d,h,g,b,e]);return c.jsx("div",{className:"sync-modal-overlay",onClick:t,children:c.jsxs("div",{className:"sync-modal",onClick:_=>_.stopPropagation(),children:[c.jsxs("div",{className:"sync-modal-header",children:[c.jsx("h2",{children:"Sync to GitHub"}),c.jsx("button",{className:"sync-modal-close",onClick:t,children:"×"})]}),n==="detecting"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-spinner"}),c.jsx("p",{children:"Detecting git configuration..."})]}),n==="setup"&&s&&c.jsxs("div",{className:"sync-modal-body",children:[!s.gitInstalled&&c.jsxs("div",{className:"sync-warning",children:["Git is not installed. Please ",c.jsx("a",{href:"https://git-scm.com/downloads",target:"_blank",rel:"noreferrer",children:"install git"})," first."]}),s.gitInstalled&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"sync-tabs",children:[s.ghAuthenticated&&c.jsx("button",{className:`sync-tab${o==="gh"?" active":""}`,onClick:()=>l("gh"),children:"GitHub CLI"}),c.jsx("button",{className:`sync-tab${o==="pat"?" active":""}`,onClick:()=>l("pat"),children:"Personal Access Token"}),c.jsx("button",{className:`sync-tab${o==="connect"?" active":""}`,onClick:()=>l("connect"),children:"Connect Existing"})]}),o==="gh"&&c.jsxs("div",{className:"sync-form",children:[c.jsxs("label",{children:["Repository name",c.jsx("input",{type:"text",value:d,onChange:_=>f(_.target.value),placeholder:"openwriter-docs"})]}),c.jsxs("label",{className:"sync-checkbox",children:[c.jsx("input",{type:"checkbox",checked:h,onChange:_=>m(_.target.checked)}),"Private repository"]})]}),o==="pat"&&c.jsxs("div",{className:"sync-form",children:[!s.ghAuthenticated&&!s.ghInstalled&&c.jsxs("p",{className:"sync-hint",children:["Create a ",c.jsx("a",{href:"https://github.com/settings/tokens/new?scopes=repo&description=OpenWriter",target:"_blank",rel:"noreferrer",children:"Personal Access Token"})," with ",c.jsx("code",{children:"repo"})," scope."]}),c.jsxs("label",{children:["Personal Access Token",c.jsx("input",{type:"password",value:g,onChange:_=>v(_.target.value),placeholder:"ghp_..."})]}),c.jsxs("label",{children:["Repository name",c.jsx("input",{type:"text",value:d,onChange:_=>f(_.target.value),placeholder:"openwriter-docs"})]}),c.jsxs("label",{className:"sync-checkbox",children:[c.jsx("input",{type:"checkbox",checked:h,onChange:_=>m(_.target.checked)}),"Private repository"]})]}),o==="connect"&&c.jsxs("div",{className:"sync-form",children:[c.jsxs("label",{children:["Remote URL",c.jsx("input",{type:"text",value:b,onChange:_=>k(_.target.value),placeholder:"https://github.com/user/repo.git"})]}),c.jsxs("label",{children:["PAT (optional, for private repos)",c.jsx("input",{type:"password",value:g,onChange:_=>v(_.target.value),placeholder:"ghp_..."})]})]}),c.jsxs("div",{className:"sync-modal-actions",children:[c.jsx("button",{className:"sync-btn secondary",onClick:t,children:"Cancel"}),c.jsx("button",{className:"sync-btn primary",onClick:j,disabled:o==="pat"&&!g||o==="connect"&&!b||o!=="connect"&&!d,children:o==="connect"?"Connect & Sync":"Create & Sync"})]})]})]}),n==="progress"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-spinner"}),c.jsx("p",{children:C})]}),n==="done"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-success-icon",children:"✓"}),c.jsx("p",{children:"Successfully synced to GitHub!"}),c.jsx("div",{className:"sync-modal-actions",children:c.jsx("button",{className:"sync-btn primary",onClick:t,children:"Done"})})]}),n==="error"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-error-msg",children:w}),c.jsxs("div",{className:"sync-modal-actions",children:[c.jsx("button",{className:"sync-btn secondary",onClick:()=>r("setup"),children:"Back"}),c.jsx("button",{className:"sync-btn secondary",onClick:t,children:"Close"})]})]})]})})}function G$({onNodeChanges:t,onAgentStatus:e,onDocumentSwitched:n,onDocumentReloaded:r,onDocumentsChanged:s,onWorkspacesChanged:i,onTitleChanged:o,onPendingDocsChanged:l,onMetadataChanged:d,onSyncStatus:f,onWritingStarted:h,onWritingFinished:m,onIdRewrites:g,onPendingFilenamesChanged:v,getEditorState:b}){const k=x.useRef(null),[w,E]=x.useState(!1),C=x.useRef(0),T=x.useRef(new Set),j=()=>{var M;return(M=se.current)==null?void 0:M.call(se,new Set(T.current))},_=x.useRef(t),A=x.useRef(e),O=x.useRef(n),B=x.useRef(s),$=x.useRef(i),W=x.useRef(o),J=x.useRef(l),z=x.useRef(f),G=x.useRef(d),D=x.useRef(h),U=x.useRef(m),q=x.useRef(g),se=x.useRef(v),V=x.useRef(r),te=x.useRef(b);_.current=t,A.current=e,O.current=n,B.current=s,$.current=i,W.current=o,J.current=l,G.current=d,z.current=f,D.current=h,U.current=m,q.current=g,se.current=v,V.current=r,te.current=b,x.useEffect(()=>{const L=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`;let ee,fe=!1,ge=1e3;function oe(){const xe=new WebSocket(L);k.current=xe,xe.onopen=()=>{E(!0),ge=1e3,fe&&xe.send(JSON.stringify({type:"request-document"})),fe=!0},xe.onmessage=We=>{var He,Ze,Oe,Ke,pt,Je,pe,mt,ft,at,nt,ht,Fe,ve;try{const X=JSON.parse(We.data);if(X.type==="node-changes"&&X.changes&&((He=_.current)==null||He.call(_,X.changes),typeof X.version=="number"&&(C.current=X.version)),X.type==="id-rewrites"&&Array.isArray(X.rewrites)&&((Ze=q.current)==null||Ze.call(q,X.rewrites)),X.type==="agent-status"&&((Oe=A.current)==null||Oe.call(A,!!X.agentConnected)),X.type==="document-switched"&&(C.current=0,(Ke=O.current)==null||Ke.call(O,{document:X.document,title:X.title,filename:X.filename,docId:X.docId,metadata:X.metadata,pendingMetadata:X.pendingMetadata??null}),window.dispatchEvent(new CustomEvent("ow-pending-metadata-changed",{detail:{docId:X.docId,pendingMetadata:X.pendingMetadata??null}}))),X.type==="pending-metadata-changed"&&window.dispatchEvent(new CustomEvent("ow-pending-metadata-changed",{detail:{docId:X.docId,pendingMetadata:X.pendingMetadata??null}})),X.type==="document-reloaded"&&(typeof X.version=="number"&&(C.current=X.version),(pt=V.current)==null||pt.call(V,{document:X.document,title:X.title,filename:X.filename,docId:X.docId,metadata:X.metadata,orphanCount:typeof X.orphanCount=="number"?X.orphanCount:0,staleBaselineCount:typeof X.staleBaselineCount=="number"?X.staleBaselineCount:0})),X.type==="metadata-changed"&&X.metadata&&((Je=G.current)==null||Je.call(G,X.metadata)),X.type==="documents-changed"&&((pe=B.current)==null||pe.call(B)),X.type==="workspaces-changed"&&((mt=$.current)==null||mt.call($)),X.type==="title-changed"&&X.title&&((ft=W.current)==null||ft.call(W,X.title)),X.type==="pending-docs-changed"&&X.pendingDocs&&((at=J.current)==null||at.call(J,X.pendingDocs)),X.type==="sync-status"&&((nt=z.current)==null||nt.call(z,{state:X.state,lastSyncTime:X.lastSyncTime,pendingFiles:X.pendingFiles,error:X.error})),X.type==="writing-started"&&X.title&&(typeof X.key=="string"&&(T.current.add(X.key),j()),(ht=D.current)==null||ht.call(D,X.title,X.target||null)),X.type==="writing-finished"&&(typeof X.key=="string"&&X.key?T.current.delete(X.key):T.current.clear(),j(),(Fe=U.current)==null||Fe.call(U)),X.type==="pending-writes-sync"&&Array.isArray(X.writes)&&(T.current=new Set(X.writes.map(Be=>Be.key).filter(Boolean)),j(),X.writes.length>0)){const Be=X.writes.reduce((ne,de)=>ne.startedAt>de.startedAt?ne:de);Be!=null&&Be.title&&((ve=D.current)==null||ve.call(D,Be.title,Be.target||null))}X.type==="plugins-changed"&&window.dispatchEvent(new CustomEvent("ow-plugins-changed")),X.type==="comments-changed"&&X.filename&&window.dispatchEvent(new CustomEvent("ow-comments-changed",{detail:{filename:X.filename}})),X.type==="documents-changed"&&window.dispatchEvent(new CustomEvent("ow-documents-changed")),X.type==="metadata-changed"&&window.dispatchEvent(new CustomEvent("ow-metadata-changed",{detail:{metadata:X.metadata}})),X.type==="activity-log"&&Array.isArray(X.entries)&&window.dispatchEvent(new CustomEvent("ow-activity-seed",{detail:{entries:X.entries}})),X.type==="activity-event"&&X.event&&window.dispatchEvent(new CustomEvent("ow-activity-event",{detail:{event:X.event}}))}catch{}},xe.onclose=()=>{E(!1),ee=setTimeout(oe,ge),ge=Math.min(ge*1.5,8e3)},xe.onerror=()=>{xe.close()}}oe();function we(){var xe;document.visibilityState==="visible"&&((xe=k.current)==null?void 0:xe.readyState)!==WebSocket.OPEN&&(clearTimeout(ee),ge=1e3,oe())}return document.addEventListener("visibilitychange",we),()=>{clearTimeout(ee),document.removeEventListener("visibilitychange",we),k.current&&(k.current.onclose=null,k.current.close())}},[]);const K=x.useCallback(M=>{var L;((L=k.current)==null?void 0:L.readyState)===WebSocket.OPEN&&k.current.send(JSON.stringify(M))},[]);return{connected:w,sendMessage:K,docVersionRef:C}}function J$(t){const[e,n]=x.useState(null),[r,s]=x.useState(!1),[i,o]=x.useState(null),l=x.useRef(void 0);return x.useEffect(()=>{if(!t){n(null),s(!1),o(null),l.current=void 0;return}t!==l.current&&(l.current=t,s(!0),o(null),fetch(`/api/tweet-embed?url=${encodeURIComponent(t)}`).then(d=>d.ok?d.json():d.json().then(f=>Promise.reject(new Error(f.error||`HTTP ${d.status}`)))).then(d=>{n(d),s(!1)}).catch(d=>{o(d.message),s(!1)}))},[t]),{tweet:e,loading:r,error:i}}function Y$(t){var r;const e=t.view.dom,n=[];for(const s of e.children){const i=(r=s.innerText)==null?void 0:r.trim();i&&n.push(i)}return n.join(`
209
+ This only removes the OpenWriter registration. Your GitHub repo is untouched.`))return;const O=await yu("remove_blog_site",{id:_.id});if(O!=null&&O.error){alert(`Remove failed: ${O.error}`);return}await w()};return c.jsxs("div",{className:"github-plugin-settings",children:[c.jsxs("div",{className:"github-plugin-settings__header",children:[c.jsx("span",{className:"github-plugin-settings__title",children:"Blog repos"}),s==="closed"&&c.jsx("button",{className:"github-plugin-settings__add-btn",onClick:()=>i("url"),children:"+ Add"})]}),n?c.jsx("div",{className:"github-plugin-settings__loading",children:"Loading…"}):t.length===0&&s==="closed"?c.jsxs("div",{className:"github-plugin-settings__empty",children:["Connect a GitHub repo to publish blog posts via local git — no PATs, no Workers. Uses your existing ",c.jsx("code",{children:"gh auth login"}),"."]}):c.jsx("div",{className:"github-plugin-settings__list",children:t.map(_=>c.jsxs("div",{className:"github-plugin-settings__site",children:[c.jsxs("div",{className:"github-plugin-settings__site-info",children:[c.jsxs("div",{className:"github-plugin-settings__site-row1",children:[c.jsx("span",{className:"github-plugin-settings__site-label",children:_.label}),c.jsx("span",{className:`github-plugin-settings__site-framework github-plugin-settings__site-framework--${_.framework}`,children:_.framework})]}),c.jsxs("div",{className:"github-plugin-settings__site-repo",children:[_.owner,"/",_.repo,"@",_.branch]}),c.jsxs("div",{className:"github-plugin-settings__site-dirs",children:[c.jsx("span",{title:"content_dir",children:_.content_dir}),c.jsx("span",{className:"github-plugin-settings__site-sep",children:"·"}),c.jsx("span",{title:"image_public_prefix",children:_.image_public_prefix})]})]}),c.jsx("button",{className:"github-plugin-settings__remove-btn",onClick:()=>j(_),title:"Remove",children:"×"})]},_.id))}),s==="url"&&c.jsxs("div",{className:"github-plugin-settings__form",children:[c.jsx("label",{className:"github-plugin-settings__label",children:"GitHub repo"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"owner/repo or https://github.com/owner/repo",value:o,onChange:_=>l(_.target.value),onKeyDown:_=>{_.key==="Enter"&&!d&&C()},autoFocus:!0}),h&&c.jsx("div",{className:"github-plugin-settings__error",children:h}),c.jsxs("div",{className:"github-plugin-settings__form-buttons",children:[c.jsx("button",{className:"github-plugin-settings__btn github-plugin-settings__btn--primary",onClick:C,disabled:d||!o.trim(),children:d?"Inspecting…":"Inspect"}),c.jsx("button",{className:"github-plugin-settings__btn",onClick:E,disabled:d,children:"Cancel"})]})]}),(s==="review"||s==="saving")&&g&&c.jsxs("div",{className:"github-plugin-settings__form",children:[c.jsxs("div",{className:"github-plugin-settings__form-meta",children:[c.jsxs("span",{children:["Detected: ",g.framework]}),c.jsx("span",{children:"·"}),c.jsxs("span",{children:[g.markdown_files_found," posts"]}),c.jsx("span",{children:"·"}),c.jsxs("span",{className:`github-plugin-settings__confidence github-plugin-settings__confidence--${g.confidence}`,children:[g.confidence," confidence"]})]}),c.jsx("label",{className:"github-plugin-settings__label",children:"Label"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.label,onChange:_=>v({...g,label:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Branch"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.branch,onChange:_=>v({...g,branch:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Content directory"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.content_dir,onChange:_=>v({...g,content_dir:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Image directory"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.image_dir,onChange:_=>v({...g,image_dir:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Image public prefix"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.image_public_prefix,onChange:_=>v({...g,image_public_prefix:_.target.value})}),c.jsxs("label",{className:"github-plugin-settings__label",children:["Site URL ",c.jsx("span",{className:"github-plugin-settings__hint",children:"— optional, used for the live link after publish"})]}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"https://example.com",value:g.site_url||"",onChange:_=>v({...g,site_url:_.target.value})}),c.jsxs("label",{className:"github-plugin-settings__label",children:["Blog URL pattern ",c.jsxs("span",{className:"github-plugin-settings__hint",children:["— uses ","{slug}"," placeholder"]})]}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"/blog/{slug}/",value:g.blog_url_pattern||"",onChange:_=>v({...g,blog_url_pattern:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Framework"}),c.jsxs("select",{className:"github-plugin-settings__input",value:g.framework,onChange:_=>v({...g,framework:_.target.value}),children:[c.jsx("option",{value:"astro",children:"Astro"}),c.jsx("option",{value:"next",children:"Next"}),c.jsx("option",{value:"jekyll",children:"Jekyll"}),c.jsx("option",{value:"hugo",children:"Hugo"}),c.jsx("option",{value:"unknown",children:"Unknown"})]}),g.frontmatter_schema.length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsxs("span",{className:"github-plugin-settings__label",children:["Frontmatter keys detected (",g.samples_analyzed," ",g.samples_analyzed===1?"sample":"samples",")"]}),c.jsx("code",{children:g.frontmatter_schema.join(", ")})]}),Object.keys(g.frontmatter_defaults||{}).length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsx("span",{className:"github-plugin-settings__label",children:"Frontmatter defaults (constants applied to every post)"}),c.jsx("code",{children:Object.entries(g.frontmatter_defaults).map(([_,A])=>c.jsxs("div",{children:[_,": ",typeof A=="string"?A:JSON.stringify(A)]},_))})]}),Object.keys(g.frontmatter_field_map||{}).length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsx("span",{className:"github-plugin-settings__label",children:"Field name mapping (openwriter → site)"}),c.jsx("code",{children:Object.entries(g.frontmatter_field_map).map(([_,A])=>c.jsxs("div",{children:[_," → ",A]},_))})]}),b&&c.jsx("div",{className:"github-plugin-settings__error",children:b}),c.jsxs("div",{className:"github-plugin-settings__form-buttons",children:[c.jsx("button",{className:"github-plugin-settings__btn github-plugin-settings__btn--primary",onClick:T,disabled:s==="saving"||!g.label.trim(),children:s==="saving"?"Saving…":"Add site"}),c.jsx("button",{className:"github-plugin-settings__btn",onClick:E,disabled:s==="saving",children:"Cancel"})]})]})]})}const _$={none:"No Plan",free:"No Plan",creator:"Creator — $19/mo",growth:"Growth — $49/mo",publisher:"Publisher — $79/mo"},T$=[{plan:"creator",label:"Creator $19/mo"},{plan:"growth",label:"Growth $49/mo"}];function j$(){var d,f;const[t,e]=x.useState(null),[n,r]=x.useState(!0);x.useEffect(()=>{fetch("/api/billing").then(h=>h.json()).then(h=>e(h)).catch(()=>{}).finally(()=>r(!1))},[]);const s=x.useCallback(async h=>{const m=await fetch("/api/billing/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plan:h})});if(m.ok){const g=await m.json();g.url&&window.open(g.url,"_blank")}},[]),i=x.useCallback(async()=>{const h=await fetch("/api/billing/portal",{method:"POST",headers:{"Content-Type":"application/json"}});if(h.ok){const m=await h.json();m.url&&window.open(m.url,"_blank")}},[]);if(n)return c.jsx("div",{className:"billing-section",children:c.jsx("div",{className:"billing-loading",children:"Loading..."})});if(!(t!=null&&t.authenticated))return null;const o=t.plan||"free",l=T$.filter(h=>{const m=["free","creator","growth","publisher"];return m.indexOf(h.plan)>m.indexOf(o)});return c.jsxs("div",{className:"billing-section",children:[c.jsxs("div",{className:"billing-plan",children:[c.jsx("span",{className:"billing-plan-label",children:"Plan"}),c.jsx("span",{className:`billing-plan-badge billing-plan-badge--${o}`,children:_$[o]||o})]}),((d=t.billing)==null?void 0:d.paymentFailed)&&c.jsx("div",{className:"billing-warning",children:"Payment failed — update card to keep your plan."}),l.length>0&&c.jsx("div",{className:"billing-upgrades",children:l.map(h=>c.jsxs("button",{className:"billing-upgrade-btn",onClick:()=>s(h.plan),children:["Upgrade to ",h.label]},h.plan))}),((f=t.billing)==null?void 0:f.hasPaymentMethod)&&c.jsx("button",{className:"billing-manage-btn",onClick:i,children:"Manage Billing"})]})}function Ok(t){return t.replace(/^@openwriter\/plugin-/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function M$(t){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(new Set),l=x.useCallback(()=>{fetch("/api/available-plugins").then(h=>h.json()).then(h=>n(h.plugins||[])).catch(()=>{})},[]);x.useEffect(()=>{l()},[l]),x.useEffect(()=>{const h=()=>l();return window.addEventListener("ow-plugins-changed",h),()=>window.removeEventListener("ow-plugins-changed",h)},[l]);const d=x.useCallback(async(h,m)=>{s(h);try{(await fetch(m?"/api/plugins/disable":"/api/plugins/enable",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:h})})).ok&&l()}catch{}finally{s(null)}},[l]),f=x.useCallback((h,m,g)=>{fetch("/api/plugins/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:h,config:{[m]:g}})}).catch(()=>{})},[]);return c.jsx("div",{className:"plugins-tab",children:e.length===0?c.jsx("div",{className:"plugin-empty",children:"No plugins found"}):e.map(h=>c.jsxs("div",{className:"plugin-item",children:[c.jsxs("div",{className:"plugin-item-header",children:[c.jsxs("div",{className:"plugin-item-info",children:[c.jsxs("div",{className:"plugin-item-name",children:[Ok(h.name),c.jsxs("span",{className:"plugin-item-version",children:["v",h.version]})]}),h.description&&c.jsx("div",{className:"plugin-item-desc",children:h.description})]}),c.jsxs("label",{className:`plugin-toggle${r===h.name?" loading":""}`,children:[c.jsx("input",{type:"checkbox",checked:h.enabled,disabled:r===h.name,onChange:()=>d(h.name,h.enabled)}),c.jsx("span",{className:"plugin-toggle-track"}),c.jsx("span",{className:"plugin-toggle-thumb"})]})]}),h.enabled&&h.name==="@openwriter/plugin-publish"&&c.jsx(j$,{}),h.enabled&&h.name==="@openwriter/plugin-github"&&c.jsx(C$,{}),h.enabled&&Object.keys(h.configSchema).length>0&&(()=>{const m=Object.entries(h.configSchema).some(([g,v])=>v.required&&!h.config[g]);return c.jsxs("div",{className:"plugin-config-section",children:[m&&c.jsxs("div",{className:"plugin-setup-hint",children:["Ask your agent: “set up ",Ok(h.name),"”"]}),c.jsxs("button",{className:"plugin-config-toggle",onClick:()=>o(g=>{const v=new Set(g);return v.has(h.name)?v.delete(h.name):v.add(h.name),v}),children:[c.jsx("svg",{className:`plugin-config-chevron${i.has(h.name)?" plugin-config-chevron--open":""}`,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Settings"]}),i.has(h.name)&&c.jsx("div",{className:"plugin-config",children:Object.entries(h.configSchema).map(([g,v])=>c.jsxs("div",{className:"plugin-config-field",children:[c.jsx("label",{className:"plugin-config-label",children:v.description||g}),c.jsx("input",{className:"plugin-config-input",type:g.toLowerCase().includes("key")||g.toLowerCase().includes("secret")||g.toLowerCase().includes("token")?"password":"text",defaultValue:h.config[g]||"",placeholder:v.env?`$${v.env}`:"",onBlur:b=>f(h.name,g,b.target.value)})]},g))})]})})()]},h.name))})}function A$({existingConnection:t,onClose:e,onSaved:n}){const[r,s]=x.useState("form"),[i,o]=x.useState(null),[l,d]=x.useState((t==null?void 0:t.domain)||""),[f,h]=x.useState(""),[m,g]=x.useState((t==null?void 0:t.from_name)||""),[v,b]=x.useState(""),[k,w]=x.useState((t==null?void 0:t.id)||""),[E,C]=x.useState({dns_verified:!1,sender_verified:!1}),T=x.useRef(null),j=x.useRef(null);x.useEffect(()=>{const J=z=>{r!=="submitting"&&r!=="verifying"&&j.current&&!j.current.contains(z.target)&&e()};return document.addEventListener("mousedown",J),()=>document.removeEventListener("mousedown",J)},[e,r]),x.useEffect(()=>{const J=z=>{z.key==="Escape"&&r!=="submitting"&&r!=="verifying"&&e()};return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[e,r]),x.useEffect(()=>()=>{T.current&&clearInterval(T.current)},[]);async function _(){var J,z;s("submitting"),o(null);try{const D=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"setup_custom_domain",arguments:{domain:l,from_email:f,from_name:m||void 0,physical_address:v}})})).json(),U=(z=(J=D.content)==null?void 0:J[0])!=null&&z.text?JSON.parse(D.content[0].text):D;if(U.error){o(U.error),s("error");return}const q=U.connectionId||U.connection_id||k;q&&w(q),O(q)}catch(G){o(G.message),s("error")}}async function A(){var J,z;s("submitting"),o(null);try{const D=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"setup_custom_domain",arguments:{domain:l,from_email:f||void 0,from_name:m||void 0,physical_address:v||void 0}})})).json(),U=(z=(J=D.content)==null?void 0:J[0])!=null&&z.text?JSON.parse(D.content[0].text):D;if(U.error){o(U.error),s("error");return}s("done")}catch(G){o(G.message),s("error")}}function O(J){s("verifying"),T.current=setInterval(async()=>{var z,G;try{const U=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"check_domain_status",arguments:{connectionId:J}})})).json(),q=(G=(z=U.content)==null?void 0:z[0])!=null&&G.text?JSON.parse(U.content[0].text):U,se=!!q.dns_verified,V=!!q.sender_verified;C({dns_verified:se,sender_verified:V}),se&&V&&(T.current&&clearInterval(T.current),T.current=null,s("done"))}catch{}},5e3)}function B(){k&&fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"resend_domain_verification",arguments:{connectionId:k}})}).catch(()=>{})}const $=!!t,W=l.trim()&&f.trim()&&v.trim();return c.jsx("div",{className:"newsletter-modal-overlay",children:c.jsxs("div",{className:"newsletter-modal newsletter-modal--setup",ref:j,children:[c.jsxs("div",{className:"newsletter-modal__header",children:[c.jsx("h3",{children:$?"Newsletter Settings":"Set Up Newsletter"}),c.jsx("button",{className:"newsletter-modal__close",onClick:e,children:"×"})]}),c.jsxs("div",{className:"newsletter-modal__body",children:[r==="form"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsx("label",{className:"newsletter-modal__label",children:"Domain"}),c.jsx("input",{className:"newsletter-modal__input",type:"text",placeholder:"yourdomain.com",value:l,onChange:J=>d(J.target.value),disabled:$,autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsx("label",{className:"newsletter-modal__label",children:"From Email"}),c.jsx("input",{className:"newsletter-modal__input",type:"email",placeholder:"newsletter@yourdomain.com",value:f,onChange:J=>h(J.target.value),autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsxs("label",{className:"newsletter-modal__label",children:["From Name ",c.jsx("span",{className:"newsletter-modal__optional",children:"(optional)"})]}),c.jsx("input",{className:"newsletter-modal__input",type:"text",placeholder:"Your Name or Brand",value:m,onChange:J=>g(J.target.value),autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsxs("label",{className:"newsletter-modal__label",children:["Physical Address ",c.jsx("span",{className:"newsletter-modal__required",children:"*"})]}),c.jsx("textarea",{className:"newsletter-modal__input newsletter-modal__textarea",rows:2,placeholder:"123 Main St, City, State 12345",value:v,onChange:J=>b(J.target.value)}),c.jsx("span",{className:"newsletter-modal__hint",children:"Required by CAN-SPAM. Included in email footer."})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:e,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:$?A:_,disabled:!W,children:$?"Save":"Set Up Domain"})]})]}),r==="submitting"&&c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:$?"Saving...":"Setting up domain..."})]}),r==="verifying"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__verify",children:[c.jsx("p",{className:"newsletter-modal__verify-title",children:"Verifying domain setup..."}),c.jsxs("div",{className:"newsletter-modal__verify-checks",children:[c.jsxs("div",{className:`newsletter-modal__verify-item${E.dns_verified?" newsletter-modal__verify-item--done":""}`,children:[E.dns_verified?"✓":c.jsx("span",{className:"newsletter-modal__spinner newsletter-modal__spinner--sm"}),c.jsx("span",{children:"DNS records"})]}),c.jsxs("div",{className:`newsletter-modal__verify-item${E.sender_verified?" newsletter-modal__verify-item--done":""}`,children:[E.sender_verified?"✓":c.jsx("span",{className:"newsletter-modal__spinner newsletter-modal__spinner--sm"}),c.jsx("span",{children:"Sender verification"})]})]}),c.jsx("p",{className:"newsletter-modal__hint",children:"This may take a few minutes. You can close and check back later."})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:B,children:"Resend Verification"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>{n(),e()},children:"Close"})]})]}),r==="done"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__status newsletter-modal__status--success",children:$?"Settings saved!":"Newsletter domain configured!"}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>{n(),e()},children:"Done"})})]}),r==="error"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__error",children:i}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:e,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>s("form"),children:"Try Again"})]})]})]})]})})}const R$={x:[],linkedin:[]};function O$({connectionId:t,provider:e,displayName:n,onClose:r,onSaved:s}){const[i,o]=x.useState("loading"),[l,d]=x.useState({}),[f,h]=x.useState(null),m=x.useRef(null),g=R$[e]||[];x.useEffect(()=>{fetch(`/api/connections/${t}/config`).then(k=>k.json()).then(k=>{d(k.config||{}),o("form")}).catch(k=>{h(k.message),o("error")})},[t]),x.useEffect(()=>{const k=w=>{i!=="saving"&&m.current&&!m.current.contains(w.target)&&r()};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[r,i]),x.useEffect(()=>{const k=w=>{w.key==="Escape"&&i!=="saving"&&r()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[r,i]);async function v(){o("saving"),h(null);try{const k=await fetch(`/api/connections/${t}/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),w=await k.json();if(!k.ok)throw new Error(w.error||"Failed to save");o("saved"),s(),setTimeout(r,800)}catch(k){h(k.message),o("error")}}function b(k){switch(k){case"x":return"X (Twitter)";case"linkedin":return"LinkedIn";default:return k}}return c.jsx("div",{className:"conn-config-overlay",children:c.jsxs("div",{className:"conn-config-modal",ref:m,children:[c.jsxs("div",{className:"conn-config-modal__header",children:[c.jsxs("div",{className:"conn-config-modal__title",children:[b(e)," Settings"]}),c.jsx("div",{className:"conn-config-modal__subtitle",children:n})]}),i==="loading"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("div",{className:"conn-config-spinner"}),c.jsx("span",{children:"Loading configuration..."})]}),(i==="form"||i==="error")&&g.length>0&&c.jsxs("div",{className:"conn-config-modal__body",children:[g.map(k=>c.jsxs("div",{className:"conn-config-field",children:[c.jsxs("label",{className:"conn-config-field__label",children:[k.label,k.readonly&&c.jsx("span",{className:"conn-config-field__badge",children:"read-only"})]}),c.jsx("input",{className:"conn-config-field__input",value:l[k.key]||"",placeholder:k.placeholder,readOnly:k.readonly,onChange:w=>d(E=>({...E,[k.key]:w.target.value}))})]},k.key)),f&&c.jsx("div",{className:"conn-config-modal__error",children:f})]}),(i==="form"||i==="error")&&g.length===0&&c.jsx("div",{className:"conn-config-modal__body conn-config-modal__center",children:c.jsxs("span",{className:"conn-config-modal__empty",children:["No configuration needed for ",b(e),"."]})}),i==="saving"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("div",{className:"conn-config-spinner"}),c.jsx("span",{children:"Saving..."})]}),i==="saved"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"#22c55e",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),c.jsx("span",{children:"Saved"})]}),c.jsxs("div",{className:"conn-config-modal__footer",children:[c.jsx("button",{className:"conn-config-btn conn-config-btn--secondary",onClick:r,children:i==="saved"?"Close":"Cancel"}),g.length>0&&(i==="form"||i==="error")&&c.jsx("button",{className:"conn-config-btn conn-config-btn--primary",onClick:v,children:"Save"})]})]})})}const I$=[{id:"x",label:"X (Twitter)",oauth:!0},{id:"linkedin",label:"LinkedIn",oauth:!0},{id:"newsletter",label:"Newsletter",oauth:!1}];function Dp(t){switch(t){case"x":return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})});case"linkedin":return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"})});case"newsletter":return c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),c.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]});default:return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("circle",{cx:"12",cy:"12",r:"10"})})}}function L$(t){return t==="active"?"connections-status--active":t==="expired"?"connections-status--expired":t==="revoked"?"connections-status--revoked":"connections-status--pending"}function D$(t){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(null),[l,d]=x.useState(null),[f,h]=x.useState(null),[m,g]=x.useState(null),v=x.useRef(null);async function b(){try{const A=await(await fetch("/api/connections")).json();s(A.authenticated!==!1);const O=(A.connections||[]).filter(B=>B&&B.id&&B.provider);return n(O),O}catch{return[]}}x.useEffect(()=>{b()},[]),x.useEffect(()=>()=>{v.current&&clearInterval(v.current)},[]);async function k(_){d(_);try{const A=await fetch(`/api/connections/oauth/${_}/start`,{method:"POST"}),O=await A.json();if(!A.ok||!O.url){d(null);return}window.open(O.url,"_blank","width=600,height=700"),v.current=setInterval(async()=>{try{const $=await(await fetch(`/api/connections/oauth/${_}/status/${O.state}`)).json();if($.status==="completed"){v.current&&clearInterval(v.current),v.current=null,d(null);const W=await b();if(_==="x"){const J=W.find(z=>z.provider==="x"&&z.status==="active");if(J!=null&&J.display_name){const z=J.display_name.replace("@","");localStorage.setItem("ow-x-handle",z),window.dispatchEvent(new StorageEvent("storage",{key:"ow-x-handle",newValue:z}))}}}else $.status==="failed"&&(v.current&&clearInterval(v.current),v.current=null,d(null))}catch{}},2e3)}catch{d(null)}}async function w(_){try{const A=await fetch(`/api/connections/${_}`,{method:"DELETE"});if(!A.ok){const O=await A.json().catch(()=>({error:"Delete failed"}));console.error("[Connections] Delete failed:",O.error)}}catch(A){console.error("[Connections] Delete error:",A)}o(null),await b()}const E=new Map,C=new Map;for(const _ of e){E.has(_.provider)||E.set(_.provider,_);const A=C.get(_.provider)||[];A.push(_),C.set(_.provider,A)}const T=new Set,j=r===!1;return c.jsxs("div",{className:"connections-tab",children:[m&&c.jsx(O$,{connectionId:m.id,provider:m.provider,displayName:m.display_name,onClose:()=>g(null),onSaved:()=>b()}),f&&c.jsx(A$,{existingConnection:f==="edit"?E.get("newsletter"):null,onClose:()=>h(null),onSaved:()=>b()}),j?c.jsxs("div",{className:"connections-dropdown__upsell",children:[c.jsx("p",{children:"Connect your X, LinkedIn, and other accounts to publish directly from OpenWriter."}),c.jsxs("p",{children:["Set up the ",c.jsx("strong",{children:"Publish"})," plugin to get started."]})]}):c.jsx("div",{className:"connections-dropdown__list",children:I$.flatMap(_=>{const A=T.has(_.id),O=C.get(_.id)||[],B=W=>i===W.id?c.jsxs("div",{className:"connections-dropdown__confirm",children:[c.jsxs("span",{children:["Disconnect ",W.display_name||_.label,"?"]}),c.jsxs("div",{className:"connections-dropdown__confirm-btns",children:[c.jsx("button",{onClick:()=>w(W.id),children:"Yes"}),c.jsx("button",{onClick:()=>o(null),children:"No"})]})]},W.id):c.jsxs("div",{className:"connections-dropdown__item",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Dp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:W.display_name||W.domain||_.label}),c.jsxs("div",{className:"connections-dropdown__type",children:[c.jsx("span",{className:`connections-status ${L$(W.status)}`}),"Connected"]})]}),c.jsxs("div",{className:"connections-dropdown__actions",children:[c.jsx("button",{className:"connections-dropdown__action-btn",onClick:()=>{_.id==="newsletter"?h("edit"):g({id:W.id,provider:_.id,display_name:W.display_name||_.label})},title:"Settings",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),c.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),c.jsx("button",{className:"connections-dropdown__action-btn connections-dropdown__action-btn--delete",onClick:()=>o(W.id),title:"Disconnect",children:"×"})]})]},W.id),$=O.map(B);return A?($.push(c.jsx("div",{className:"connections-dropdown__add-row",children:c.jsx("button",{className:"connections-dropdown__add-btn",onClick:()=>k(_.id),disabled:l!==null,children:l===_.id?"Connecting…":`+ Add ${_.label} repo`})},`${_.id}__add`)),$):O.length>0?$:_.oauth?[c.jsxs("div",{className:"connections-dropdown__item connections-dropdown__item--disconnected",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Dp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:_.label}),c.jsx("div",{className:"connections-dropdown__type",children:"Not connected"})]}),c.jsx("button",{className:"connections-dropdown__connect-inline-btn",onClick:()=>k(_.id),disabled:l!==null,children:l===_.id?"Connecting…":"Connect"})]},_.id)]:[c.jsxs("div",{className:"connections-dropdown__item connections-dropdown__item--disconnected",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Dp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:_.label}),c.jsx("div",{className:"connections-dropdown__type",children:"Built-in · Not configured"})]}),c.jsx("button",{className:"connections-dropdown__connect-inline-btn",onClick:()=>h("new"),children:"Configure"})]},_.id)]})})]})}const P$={tree:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M3 3h7v7H3zM14 3h7v4h-7zM14 10h7v4h-7zM3 13h7v8H3z"})}),files:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("polyline",{points:"14 2 14 8 20 8"})]}),timeline:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"22"}),c.jsx("circle",{cx:"12",cy:"6",r:"2"}),c.jsx("circle",{cx:"12",cy:"12",r:"2"}),c.jsx("circle",{cx:"12",cy:"18",r:"2"}),c.jsx("line",{x1:"14",y1:"6",x2:"20",y2:"6"}),c.jsx("line",{x1:"14",y1:"12",x2:"20",y2:"12"}),c.jsx("line",{x1:"14",y1:"18",x2:"20",y2:"18"})]}),board:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"5",height:"18",rx:"1"}),c.jsx("rect",{x:"10",y:"3",width:"5",height:"12",rx:"1"}),c.jsx("rect",{x:"17",y:"3",width:"5",height:"15",rx:"1"})]}),shelf:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 19V5"}),c.jsx("path",{d:"M8 19V7"}),c.jsx("path",{d:"M12 19V4"}),c.jsx("path",{d:"M16 19V8"}),c.jsx("path",{d:"M20 19V6"}),c.jsx("line",{x1:"2",y1:"20",x2:"22",y2:"20"})]})};function B$(t){const[e,n]=x.useState(kE),[r,s]=x.useState(SE),[i,o]=x.useState(Rd),l=EE(),[d,f]=x.useState(CE),[h,m]=x.useState(_E),g=(C=e,T=r,j=i,_=l,A=d,O=h)=>{TE(C,T,j,_,A,O)},v=C=>{n(C),g(C)},b=()=>{const C=r==="light"?"dark":"light";s(C),g(void 0,C)},k=C=>{o(C),g(void 0,void 0,C),window.dispatchEvent(new CustomEvent("ow-sidebar-mode-change",{detail:C}))},w=C=>{f(C),g(void 0,void 0,void 0,void 0,C)},E=C=>{m(C),g(void 0,void 0,void 0,void 0,void 0,C)};return c.jsxs("div",{className:"appearance-tab",children:[c.jsx("div",{className:"appearance-section",children:c.jsxs("div",{className:"appearance-section-header",children:[c.jsx("span",{className:"appearance-section-title",children:"Mode"}),c.jsxs("button",{className:"appearance-mode-btn",onClick:b,title:r==="light"?"Switch to dark":"Switch to light",children:[r==="light"?c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"5"}),c.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),c.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),c.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),c.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),c.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),c.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),c.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),c.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):c.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}),c.jsx("span",{children:r==="light"?"Light":"Dark"})]})]})}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Typography"})}),c.jsx("div",{className:"appearance-typeface-grid",children:yE.map(C=>c.jsx("button",{className:`appearance-style-option ${e===C.id?"active":""}`,onClick:()=>v(C.id),title:C.description,children:C.label},C.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Spacing"})}),c.jsx("div",{className:"appearance-typography-grid",children:wE.map(C=>c.jsx("button",{className:`appearance-style-option ${d===C.id?"active":""}`,onClick:()=>w(C.id),children:C.label},C.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Canvas"})}),c.jsx("div",{className:"appearance-style-grid",children:xE.map(C=>c.jsx("button",{className:`appearance-style-option ${h===C.id?"active":""}`,onClick:()=>E(C.id),children:C.label},C.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Layout"})}),c.jsx("div",{className:"appearance-mode-grid",children:bE.map(C=>c.jsxs("button",{className:`appearance-mode-option ${i===C.id?"active":""}`,onClick:()=>k(C.id),children:[P$[C.icon],c.jsx("span",{children:C.label})]},C.id))})]})]})}const z2=[{id:"review",label:"Review",scope:"doc",icon:c.jsx(j5,{}),Component:o$},{id:"activity",label:"Activity",scope:"workspace",icon:c.jsx(O5,{}),Component:E$},{id:"backlinks",label:"Backlinks",scope:"doc",icon:c.jsx(A5,{}),Component:u$},{id:"exports",label:"Export",scope:"doc",icon:c.jsx(R5,{}),Component:f$},{id:"versions",label:"Versions",scope:"doc",icon:c.jsx(M5,{}),Component:c$},{id:"plugins",label:"Plugins",scope:"settings",icon:c.jsx(I5,{}),Component:M$},{id:"connections",label:"Connections",scope:"settings",icon:c.jsx(L5,{}),Component:D$},{id:"appearance",label:"Appearance",scope:"settings",icon:c.jsx(D5,{}),Component:B$}];function $$(t){return t?z2.find(e=>e.id===t)??null:null}function Ik({pendingDocs:t}){const{open:e,activeTab:n,openTab:r}=Jd(),[s,i]=x.useState(!1),[o,l]=x.useState(!1),d=x.useRef(0);return x.useEffect(()=>{const f=t.filenames.length,h=d.current;d.current=f,h===0&&f>0&&r("review")},[t.filenames.length,r]),x.useEffect(()=>{const f=()=>r("review");return window.addEventListener("ow-pending-write-applied",f),()=>window.removeEventListener("ow-pending-write-applied",f)},[r]),x.useEffect(()=>{const f=()=>{if(!(e&&n==="activity")){i(!0),window.setTimeout(()=>i(!1),500);try{localStorage.getItem("ow-bell-hint-seen")||(l(!0),localStorage.setItem("ow-bell-hint-seen","1"),window.setTimeout(()=>l(!1),6e3))}catch{}}};return window.addEventListener("ow-activity-event",f),()=>window.removeEventListener("ow-activity-event",f)},[e,n]),c.jsx("div",{className:"rail-icon-strip",role:"tablist","aria-label":"Right rail tabs",children:z2.map(f=>{const h=e&&n===f.id,m=f.id==="activity";return c.jsxs("button",{type:"button",role:"tab","aria-selected":h,className:["rail-icon-btn",h?"rail-icon-btn--active":"",`rail-icon-btn--scope-${f.scope}`,m&&s?"rail-icon-btn--pulsing":""].filter(Boolean).join(" "),onClick:()=>r(f.id),title:f.label,"aria-label":f.label,children:[f.icon,m&&o&&c.jsxs("div",{className:"rail-icon-hint",role:"tooltip",children:[c.jsx("span",{children:"Agent activity lives here."}),c.jsx("button",{type:"button",className:"rail-icon-hint-close",onClick:g=>{g.stopPropagation(),l(!1)},"aria-label":"Dismiss",children:"×"})]})]},f.id)})})}function z$(t){const{activeTab:e}=Jd(),n=$$(e);return c.jsx("div",{className:"rail-body",role:"tabpanel",children:n?c.jsx(n.Component,{...t}):null})}const F$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),U$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M9 14l2 2 4-4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),H$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M12 16v-5M9.5 13.5L12 11l2.5 2.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),W$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M14 14l-4 4M10 14l4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});function q$({syncStatus:t,onSync:e}){const[n,r]=x.useState(!1),[s,i]=x.useState([]),[o,l]=x.useState(!1),d=x.useRef(null),f=x.useCallback(()=>{if(n){r(!1);return}r(!0),l(!0),fetch("/api/sync/pending").then(h=>h.json()).then(h=>i(h)).catch(()=>i([])).finally(()=>l(!1))},[n]);return x.useEffect(()=>{t.state!=="pending"&&r(!1)},[t.state]),x.useEffect(()=>{if(!n)return;const h=m=>{d.current&&!d.current.contains(m.target)&&r(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[n]),c.jsxs("div",{className:"sync-btn-group",ref:d,children:[c.jsxs("button",{className:`titlebar-btn sync-btn-state sync-${t.state}`,onClick:e,disabled:t.state==="syncing",title:t.lastSyncTime?`Last synced: ${new Date(t.lastSyncTime).toLocaleString()}`:"Sync to GitHub",children:[t.state==="unconfigured"&&c.jsxs(c.Fragment,{children:[c.jsx(F$,{})," Sync"]}),t.state==="synced"&&c.jsxs(c.Fragment,{children:[c.jsx(U$,{})," Synced"]}),t.state==="pending"&&c.jsxs(c.Fragment,{children:[c.jsx(H$,{})," Sync",t.pendingFiles?` (${t.pendingFiles})`:""]}),t.state==="syncing"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"sync-btn-spinner"})," Syncing..."]}),t.state==="error"&&c.jsxs(c.Fragment,{children:[c.jsx(W$,{})," Retry"]})]}),t.state==="pending"&&t.pendingFiles&&t.pendingFiles>0&&c.jsx("button",{className:"sync-details-btn",onClick:f,title:"View pending changes",children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:c.jsx("path",{d:n?"M3 7.5L6 4.5L9 7.5":"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n&&c.jsxs("div",{className:"sync-pending-dropdown",children:[c.jsx("div",{className:"sync-pending-header",children:"Changes to push"}),o?c.jsx("div",{className:"sync-pending-loading",children:"Loading..."}):s.length===0?c.jsx("div",{className:"sync-pending-loading",children:"No changes"}):c.jsx("div",{className:"sync-pending-list",children:s.map((h,m)=>c.jsxs("div",{className:`sync-pending-item sync-file-${h.status}`,children:[c.jsx("span",{className:"sync-file-badge",children:h.status[0].toUpperCase()}),c.jsx("span",{className:"sync-file-name",children:h.file})]},m))})]})]})}function V$(t){const{syncStatus:e,onSync:n,onToggleToolbar:r,toolbarOpen:s,focusMode:i,onToggleFocusMode:o,...l}=t,{open:d,activeTab:f,width:h,setWidth:m,closeRail:g,openTab:v}=Jd(),b=x.useRef(null),k=x.useRef(null),w=x.useRef(i);x.useEffect(()=>{if(i!==w.current)if(w.current=i,i)k.current={open:d,activeTab:f},d&&g();else{const C=k.current;k.current=null,C!=null&&C.open&&C.activeTab&&v(C.activeTab)}},[i]);const E=x.useCallback(C=>{C.preventDefault();const T=C.clientX,j=h,_=O=>{const B=T-O.clientX;m(j+B)},A=()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",A)},[h,m]);return x.useEffect(()=>{if(!d)return;const C=T=>{T.key==="Escape"&&b.current&&b.current.contains(document.activeElement)&&(T.preventDefault(),g())};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[d,g]),d?c.jsxs("aside",{ref:b,className:"right-rail-column",style:{width:h,minWidth:h},"aria-label":"Right rail",children:[c.jsx("div",{className:"right-rail-resize-handle",onPointerDown:E,"aria-hidden":"true"}),c.jsxs("div",{className:"right-rail-topbar",children:[c.jsxs("div",{className:"right-rail-topbar-actions right-rail-topbar-actions--start",children:[c.jsx("button",{type:"button",className:"right-rail-topbar-btn",onClick:g,title:"Hide rail","aria-label":"Hide rail",children:c.jsx(P5,{})}),c.jsx("button",{type:"button",className:`right-rail-topbar-btn${i?" right-rail-topbar-btn--active":""}`,onClick:o,title:"Focus mode","aria-label":"Focus mode","aria-pressed":i,children:c.jsx(v2,{})}),c.jsx("button",{type:"button",className:`right-rail-topbar-btn${s?" right-rail-topbar-btn--active":""}`,onClick:r,title:"Toggle format toolbar","aria-label":"Toggle format toolbar","aria-pressed":s,children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 20h16"}),c.jsx("path",{d:"m6 16 6-12 6 12"}),c.jsx("path",{d:"M8 12h8"})]})})]}),c.jsx("div",{className:"right-rail-topbar-actions right-rail-topbar-actions--end",children:c.jsx(q$,{syncStatus:e,onSync:n})})]}),c.jsx(Ik,{pendingDocs:l.pendingDocs}),c.jsx(z$,{...l})]}):c.jsx("div",{className:"right-rail-mount-keepalive",style:{display:"none"},children:c.jsx(Ik,{pendingDocs:l.pendingDocs})})}function K$({onClose:t,onSetupComplete:e}){const[n,r]=x.useState("detecting"),[s,i]=x.useState(null),[o,l]=x.useState("gh"),[d,f]=x.useState("openwriter-docs"),[h,m]=x.useState(!0),[g,v]=x.useState(""),[b,k]=x.useState(""),[w,E]=x.useState(""),[C,T]=x.useState("");x.useEffect(()=>{fetch("/api/sync/capabilities").then(_=>_.json()).then(_=>{i(_),_.ghAuthenticated?l("gh"):(_.gitInstalled,l("pat")),r("setup")}).catch(()=>{E("Failed to detect git capabilities"),r("error")})},[]);const j=x.useCallback(async()=>{r("progress"),T(o==="connect"?"Connecting to repository...":"Creating repository and syncing...");try{const _={method:o,repoName:d,isPrivate:h};o==="pat"&&(_.pat=g),o==="connect"&&(_.remoteUrl=b,_.pat=g||void 0);const A=await fetch("/api/sync/setup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)});if(!A.ok){const O=await A.json().catch(()=>({}));throw new Error(O.error||`Setup failed (${A.status})`)}r("done"),e()}catch(_){E(_.message),r("error")}},[o,d,h,g,b,e]);return c.jsx("div",{className:"sync-modal-overlay",onClick:t,children:c.jsxs("div",{className:"sync-modal",onClick:_=>_.stopPropagation(),children:[c.jsxs("div",{className:"sync-modal-header",children:[c.jsx("h2",{children:"Sync to GitHub"}),c.jsx("button",{className:"sync-modal-close",onClick:t,children:"×"})]}),n==="detecting"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-spinner"}),c.jsx("p",{children:"Detecting git configuration..."})]}),n==="setup"&&s&&c.jsxs("div",{className:"sync-modal-body",children:[!s.gitInstalled&&c.jsxs("div",{className:"sync-warning",children:["Git is not installed. Please ",c.jsx("a",{href:"https://git-scm.com/downloads",target:"_blank",rel:"noreferrer",children:"install git"})," first."]}),s.gitInstalled&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"sync-tabs",children:[s.ghAuthenticated&&c.jsx("button",{className:`sync-tab${o==="gh"?" active":""}`,onClick:()=>l("gh"),children:"GitHub CLI"}),c.jsx("button",{className:`sync-tab${o==="pat"?" active":""}`,onClick:()=>l("pat"),children:"Personal Access Token"}),c.jsx("button",{className:`sync-tab${o==="connect"?" active":""}`,onClick:()=>l("connect"),children:"Connect Existing"})]}),o==="gh"&&c.jsxs("div",{className:"sync-form",children:[c.jsxs("label",{children:["Repository name",c.jsx("input",{type:"text",value:d,onChange:_=>f(_.target.value),placeholder:"openwriter-docs"})]}),c.jsxs("label",{className:"sync-checkbox",children:[c.jsx("input",{type:"checkbox",checked:h,onChange:_=>m(_.target.checked)}),"Private repository"]})]}),o==="pat"&&c.jsxs("div",{className:"sync-form",children:[!s.ghAuthenticated&&!s.ghInstalled&&c.jsxs("p",{className:"sync-hint",children:["Create a ",c.jsx("a",{href:"https://github.com/settings/tokens/new?scopes=repo&description=OpenWriter",target:"_blank",rel:"noreferrer",children:"Personal Access Token"})," with ",c.jsx("code",{children:"repo"})," scope."]}),c.jsxs("label",{children:["Personal Access Token",c.jsx("input",{type:"password",value:g,onChange:_=>v(_.target.value),placeholder:"ghp_..."})]}),c.jsxs("label",{children:["Repository name",c.jsx("input",{type:"text",value:d,onChange:_=>f(_.target.value),placeholder:"openwriter-docs"})]}),c.jsxs("label",{className:"sync-checkbox",children:[c.jsx("input",{type:"checkbox",checked:h,onChange:_=>m(_.target.checked)}),"Private repository"]})]}),o==="connect"&&c.jsxs("div",{className:"sync-form",children:[c.jsxs("label",{children:["Remote URL",c.jsx("input",{type:"text",value:b,onChange:_=>k(_.target.value),placeholder:"https://github.com/user/repo.git"})]}),c.jsxs("label",{children:["PAT (optional, for private repos)",c.jsx("input",{type:"password",value:g,onChange:_=>v(_.target.value),placeholder:"ghp_..."})]})]}),c.jsxs("div",{className:"sync-modal-actions",children:[c.jsx("button",{className:"sync-btn secondary",onClick:t,children:"Cancel"}),c.jsx("button",{className:"sync-btn primary",onClick:j,disabled:o==="pat"&&!g||o==="connect"&&!b||o!=="connect"&&!d,children:o==="connect"?"Connect & Sync":"Create & Sync"})]})]})]}),n==="progress"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-spinner"}),c.jsx("p",{children:C})]}),n==="done"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-success-icon",children:"✓"}),c.jsx("p",{children:"Successfully synced to GitHub!"}),c.jsx("div",{className:"sync-modal-actions",children:c.jsx("button",{className:"sync-btn primary",onClick:t,children:"Done"})})]}),n==="error"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-error-msg",children:w}),c.jsxs("div",{className:"sync-modal-actions",children:[c.jsx("button",{className:"sync-btn secondary",onClick:()=>r("setup"),children:"Back"}),c.jsx("button",{className:"sync-btn secondary",onClick:t,children:"Close"})]})]})]})})}function G$({onNodeChanges:t,onAgentStatus:e,onDocumentSwitched:n,onDocumentReloaded:r,onDocumentsChanged:s,onWorkspacesChanged:i,onTitleChanged:o,onPendingDocsChanged:l,onMetadataChanged:d,onSyncStatus:f,onWritingStarted:h,onWritingFinished:m,onIdRewrites:g,onPendingFilenamesChanged:v,getEditorState:b}){const k=x.useRef(null),[w,E]=x.useState(!1),C=x.useRef(0),T=x.useRef(new Set),j=()=>{var M;return(M=se.current)==null?void 0:M.call(se,new Set(T.current))},_=x.useRef(t),A=x.useRef(e),O=x.useRef(n),B=x.useRef(s),$=x.useRef(i),W=x.useRef(o),J=x.useRef(l),z=x.useRef(f),G=x.useRef(d),D=x.useRef(h),U=x.useRef(m),q=x.useRef(g),se=x.useRef(v),V=x.useRef(r),te=x.useRef(b);_.current=t,A.current=e,O.current=n,B.current=s,$.current=i,W.current=o,J.current=l,G.current=d,z.current=f,D.current=h,U.current=m,q.current=g,se.current=v,V.current=r,te.current=b,x.useEffect(()=>{const L=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`;let ee,fe=!1,ge=1e3;function oe(){const we=new WebSocket(L);k.current=we,we.onopen=()=>{E(!0),ge=1e3,fe&&we.send(JSON.stringify({type:"request-document"})),fe=!0},we.onmessage=We=>{var He,Ze,Oe,Ke,pt,Je,pe,mt,ft,at,nt,ht,Fe,ve;try{const X=JSON.parse(We.data);if(X.type==="node-changes"&&X.changes&&((He=_.current)==null||He.call(_,X.changes),typeof X.version=="number"&&(C.current=X.version)),X.type==="id-rewrites"&&Array.isArray(X.rewrites)&&((Ze=q.current)==null||Ze.call(q,X.rewrites)),X.type==="agent-status"&&((Oe=A.current)==null||Oe.call(A,!!X.agentConnected)),X.type==="document-switched"&&(C.current=0,(Ke=O.current)==null||Ke.call(O,{document:X.document,title:X.title,filename:X.filename,docId:X.docId,metadata:X.metadata,pendingMetadata:X.pendingMetadata??null}),window.dispatchEvent(new CustomEvent("ow-pending-metadata-changed",{detail:{docId:X.docId,pendingMetadata:X.pendingMetadata??null}}))),X.type==="pending-metadata-changed"&&window.dispatchEvent(new CustomEvent("ow-pending-metadata-changed",{detail:{docId:X.docId,pendingMetadata:X.pendingMetadata??null}})),X.type==="document-reloaded"&&(typeof X.version=="number"&&(C.current=X.version),(pt=V.current)==null||pt.call(V,{document:X.document,title:X.title,filename:X.filename,docId:X.docId,metadata:X.metadata,orphanCount:typeof X.orphanCount=="number"?X.orphanCount:0,staleBaselineCount:typeof X.staleBaselineCount=="number"?X.staleBaselineCount:0})),X.type==="metadata-changed"&&X.metadata&&((Je=G.current)==null||Je.call(G,X.metadata)),X.type==="documents-changed"&&((pe=B.current)==null||pe.call(B)),X.type==="workspaces-changed"&&((mt=$.current)==null||mt.call($)),X.type==="title-changed"&&X.title&&((ft=W.current)==null||ft.call(W,X.title)),X.type==="pending-docs-changed"&&X.pendingDocs&&((at=J.current)==null||at.call(J,X.pendingDocs)),X.type==="sync-status"&&((nt=z.current)==null||nt.call(z,{state:X.state,lastSyncTime:X.lastSyncTime,pendingFiles:X.pendingFiles,error:X.error})),X.type==="writing-started"&&X.title&&(typeof X.key=="string"&&(T.current.add(X.key),j()),(ht=D.current)==null||ht.call(D,X.title,X.target||null)),X.type==="writing-finished"&&(typeof X.key=="string"&&X.key?T.current.delete(X.key):T.current.clear(),j(),(Fe=U.current)==null||Fe.call(U)),X.type==="pending-writes-sync"&&Array.isArray(X.writes)&&(T.current=new Set(X.writes.map(Be=>Be.key).filter(Boolean)),j(),X.writes.length>0)){const Be=X.writes.reduce((ne,de)=>ne.startedAt>de.startedAt?ne:de);Be!=null&&Be.title&&((ve=D.current)==null||ve.call(D,Be.title,Be.target||null))}X.type==="plugins-changed"&&window.dispatchEvent(new CustomEvent("ow-plugins-changed")),X.type==="comments-changed"&&X.filename&&window.dispatchEvent(new CustomEvent("ow-comments-changed",{detail:{filename:X.filename}})),X.type==="documents-changed"&&window.dispatchEvent(new CustomEvent("ow-documents-changed")),X.type==="metadata-changed"&&window.dispatchEvent(new CustomEvent("ow-metadata-changed",{detail:{metadata:X.metadata}})),X.type==="activity-log"&&Array.isArray(X.entries)&&window.dispatchEvent(new CustomEvent("ow-activity-seed",{detail:{entries:X.entries}})),X.type==="activity-event"&&X.event&&window.dispatchEvent(new CustomEvent("ow-activity-event",{detail:{event:X.event}}))}catch{}},we.onclose=()=>{E(!1),ee=setTimeout(oe,ge),ge=Math.min(ge*1.5,8e3)},we.onerror=()=>{we.close()}}oe();function xe(){var we;document.visibilityState==="visible"&&((we=k.current)==null?void 0:we.readyState)!==WebSocket.OPEN&&(clearTimeout(ee),ge=1e3,oe())}return document.addEventListener("visibilitychange",xe),()=>{clearTimeout(ee),document.removeEventListener("visibilitychange",xe),k.current&&(k.current.onclose=null,k.current.close())}},[]);const K=x.useCallback(M=>{var L;((L=k.current)==null?void 0:L.readyState)===WebSocket.OPEN&&k.current.send(JSON.stringify(M))},[]);return{connected:w,sendMessage:K,docVersionRef:C}}function J$(t){const[e,n]=x.useState(null),[r,s]=x.useState(!1),[i,o]=x.useState(null),l=x.useRef(void 0);return x.useEffect(()=>{if(!t){n(null),s(!1),o(null),l.current=void 0;return}t!==l.current&&(l.current=t,s(!0),o(null),fetch(`/api/tweet-embed?url=${encodeURIComponent(t)}`).then(d=>d.ok?d.json():d.json().then(f=>Promise.reject(new Error(f.error||`HTTP ${d.status}`)))).then(d=>{n(d),s(!1)}).catch(d=>{o(d.message),s(!1)}))},[t]),{tweet:e,loading:r,error:i}}function Y$(t){var r;const e=t.view.dom,n=[];for(const s of e.children){const i=(r=s.innerText)==null?void 0:r.trim();i&&n.push(i)}return n.join(`
210
210
 
211
- `)}function X$(t){const e=n=>{var r;if(n.type==="image"&&((r=n.attrs)!=null&&r.src))return n.attrs.src;if(n.content)for(const s of n.content){const i=e(s);if(i)return i}return null};return e(t.getJSON())}async function Q$(t){try{const e=await fetch(t);if(!e.ok)return null;const n=await e.blob();return n.type==="image/png"?n:new Promise(r=>{const s=new Image,i=URL.createObjectURL(n);s.onload=()=>{const o=document.createElement("canvas");o.width=s.naturalWidth,o.height=s.naturalHeight,o.getContext("2d").drawImage(s,0,0),o.toBlob(l=>{URL.revokeObjectURL(i),r(l)},"image/png")},s.onerror=()=>{URL.revokeObjectURL(i),r(null)},s.src=i})}catch{return null}}function Z$(t,e){const[n,r]=x.useState("idle"),s=x.useRef();return{copyText:x.useCallback(async()=>{const o=t.current[e];if(!o)return;const l=Y$(o),d=X$(o);if(!(!l&&!d)){try{const f={};if(l&&(f["text/plain"]=new Blob([l],{type:"text/plain"})),d){const h=await Q$(d);h&&(f["image/png"]=h)}Object.keys(f).length>0&&await navigator.clipboard.write([new ClipboardItem(f)])}catch{if(l){const f=document.createElement("textarea");f.value=l,f.style.position="fixed",f.style.opacity="0",document.body.appendChild(f),f.select(),document.execCommand("copy"),document.body.removeChild(f)}}r("copied"),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>r("idle"),2e3)}},[t,e]),copyState:n}}function Pp(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e4?`${(t/1e3).toFixed(0)}K`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toLocaleString()}function ez(t){try{const e=Date.now(),n=new Date(t).getTime(),r=Math.floor((e-n)/1e3);if(r<60)return`${r}s`;const s=Math.floor(r/60);if(s<60)return`${s}m`;const i=Math.floor(s/60);return i<24?`${i}h`:new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric"})}catch{return""}}const tz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M1.751 10c0-4.42 3.584-8 8.005-8h4.366c4.49 0 8.129 3.64 8.129 8.13 0 2.96-1.607 5.68-4.196 7.11l-8.054 4.46v-3.69h-.067c-4.49.1-8.183-3.51-8.183-8.01zm8.005-6c-3.317 0-6.005 2.69-6.005 6 0 3.37 2.77 6.08 6.138 6.01l.351-.01h1.761v2.3l5.087-2.81c1.951-1.08 3.163-3.13 3.163-5.36 0-3.39-2.744-6.13-6.129-6.13H9.756z"})}),nz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M4.5 3.88l4.432 4.14-1.364 1.46L5.5 7.55V16c0 1.1.896 2 2 2H13v2H7.5c-2.209 0-4-1.79-4-4V7.55L1.432 9.48.068 8.02 4.5 3.88zM16.5 6H11V4h5.5c2.209 0 4 1.79 4 4v8.45l2.068-1.93 1.364 1.46-4.432 4.14-4.432-4.14 1.364-1.46 2.068 1.93V8c0-1.1-.896-2-2-2z"})}),rz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M16.697 5.5c-1.222-.06-2.679.51-3.89 2.16l-.805 1.09-.806-1.09C9.984 6.01 8.526 5.44 7.304 5.5c-1.243.07-2.349.78-2.91 1.91-.552 1.12-.633 2.78.479 4.82 1.074 1.97 3.257 4.27 7.129 6.61 3.87-2.34 6.052-4.64 7.126-6.61 1.111-2.04 1.03-3.7.477-4.82-.561-1.13-1.666-1.84-2.908-1.91zm4.187 7.69c-1.351 2.48-4.001 5.12-8.379 7.67l-.503.3-.504-.3c-4.379-2.55-7.029-5.19-8.382-7.67-1.36-2.5-1.41-4.86-.514-6.67.887-1.79 2.647-2.91 4.601-3.01 1.651-.09 3.368.56 4.798 2.01 1.429-1.45 3.146-2.1 4.796-2.01 1.954.1 3.714 1.22 4.601 3.01.896 1.81.846 4.17-.514 6.67z"})}),sz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M4 4.5C4 3.12 5.119 2 6.5 2h11C18.881 2 20 3.12 20 4.5v18.44l-8-5.71-8 5.71V4.5zM6.5 4c-.276 0-.5.22-.5.5v14.56l6-4.29 6 4.29V4.5c0-.28-.224-.5-.5-.5h-11z"})}),iz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M12 2.59l5.7 5.7-1.41 1.42L13 6.41V16h-2V6.41l-3.3 3.3-1.41-1.42L12 2.59zM21 15l-.02 3.51c0 1.38-1.12 2.49-2.5 2.49H5.5C4.11 21 3 19.88 3 18.5V15h2v3.5c0 .28.22.5.5.5h12.98c.28 0 .5-.22.5-.5L19 15h2z"})});function F2({tweet:t,nested:e,url:n}){const r=ez(t.createdAt);return c.jsxs("div",{className:`tweet-embed-card${e?" tweet-embed-nested":""}${n?" tweet-embed-card--clickable":""}`,onClick:n?()=>window.open(n,"_blank","noopener,noreferrer"):void 0,role:n?"link":void 0,children:[c.jsxs("div",{className:"tweet-author-row",children:[t.author.avatarUrl?c.jsx("img",{className:"tweet-avatar",src:t.author.avatarUrl,alt:""}):c.jsx("div",{className:"tweet-avatar tweet-avatar-placeholder"}),c.jsxs("div",{className:"tweet-author-info",children:[c.jsx("span",{className:"tweet-author-name",children:t.author.name}),c.jsxs("span",{className:"tweet-author-handle",children:["@",t.author.username]}),r&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"tweet-author-separator",children:"·"}),c.jsx("span",{className:"tweet-author-timestamp",children:r})]})]})]}),c.jsx("div",{className:"tweet-text",children:t.text}),t.media&&t.media.length>0&&c.jsx("div",{className:"tweet-media","data-count":t.media.length,children:t.media.map((s,i)=>s.type==="photo"?c.jsx("img",{className:"tweet-media-img",src:s.url,alt:"",loading:"lazy"},i):s.type==="video"||s.type==="gif"?c.jsx("div",{className:"tweet-media-video-placeholder",children:c.jsx("span",{children:"Video"})},i):null)}),t.quoteTweet&&c.jsx(F2,{tweet:t.quoteTweet,nested:!0}),!e&&c.jsxs("div",{className:"tweet-actions-row",children:[c.jsxs("span",{className:"tweet-action tweet-action-reply",children:[c.jsx(tz,{}),t.metrics.replies>0&&Pp(t.metrics.replies)]}),c.jsxs("span",{className:"tweet-action tweet-action-retweet",children:[c.jsx(nz,{}),t.metrics.retweets>0&&Pp(t.metrics.retweets)]}),c.jsxs("span",{className:"tweet-action tweet-action-like",children:[c.jsx(rz,{}),t.metrics.likes>0&&Pp(t.metrics.likes)]}),c.jsx("span",{className:"tweet-action tweet-action-bookmark",children:c.jsx(sz,{})}),c.jsx("span",{className:"tweet-action tweet-action-share",children:c.jsx(iz,{})})]})]})}function Lk({tweet:t,url:e}){return c.jsx(F2,{tweet:t,url:e})}function oz({initialContent:t,initialPreviewImages:e,placeholder:n="What is happening?!",onUpdate:r,onReady:s,onFocus:i,onPreviewImagesChange:o}){const[l,d]=x.useState(e||[]),f=x.useRef(e||[]),h=x.useRef(!1),m=x.useRef(s);m.current=s;const g=x.useRef(o);g.current=o;const v=x.useCallback(E=>{var T;const C=E.slice(0,4);f.current=C,d(C),(T=g.current)==null||T.call(g,C)},[]),b=x.useCallback(E=>{if(h.current)return;const C=[],T=[];if(E.state.doc.descendants((O,B)=>{var $;O.type.name==="image"&&(($=O.attrs)!=null&&$.src)&&(C.push(O.attrs.src),T.push({from:B,to:B+O.nodeSize}))}),C.length===0)return;h.current=!0;const{tr:j}=E.state;for(let O=T.length-1;O>=0;O--)j.delete(T[O].from,T[O].to);E.view.dispatch(j);const _=f.current,A=4-_.length;A>0&&v([..._,...C.slice(0,A)]),h.current=!1},[v]),k=FC({extensions:[...n2,Kd.configure({placeholder:n})],content:t||"<p></p>",onCreate:({editor:E})=>{b(E)},onUpdate:({editor:E})=>{b(E),r==null||r(E)},onFocus:()=>{i==null||i()},editorProps:{handlePaste:d2,handleDrop:f2}},[t]);x.useEffect(()=>{k&&g5(k.view,{addToPreview:E=>{const C=f.current;C.length>=4||v([...C,E])},getPreviewImages:()=>f.current})},[k,v]),x.useEffect(()=>{if(!k)return;const{state:E}=k.view;if(E.plugins.some(j=>j.key==="pendingDecoration$"))return;const C=a2(),T=E.reconfigure({plugins:[...E.plugins,C]});k.view.updateState(T)},[k]),x.useEffect(()=>{if(!k)return;const{state:E}=k.view;if(E.plugins.some(j=>j.key==="commentDecoration$"))return;const C=c2(),T=E.reconfigure({plugins:[...E.plugins,C]});k.view.updateState(T)},[k]),x.useEffect(()=>{var E;k&&((E=m.current)==null||E.call(m,k))},[k]);const w=x.useCallback(E=>{v(f.current.filter((C,T)=>T!==E))},[v]);return k?c.jsxs(c.Fragment,{children:[c.jsx(Rv,{editor:k}),l.length>0&&c.jsx("div",{className:"tweet-preview-grid","data-count":l.length,children:l.map((E,C)=>c.jsxs("div",{className:"tweet-image-card",children:[c.jsx("img",{className:"tweet-image-card-img",src:E,alt:"",draggable:!1}),c.jsx("button",{className:"tweet-image-card-remove",onClick:()=>w(C),title:"Remove image",children:"×"})]},E))})]}):null}function az({count:t,softLimit:e=280}){const n=e-t,r=Math.min(t/e,1),s=n<=20,i=s?30:26,o=2,l=(i-o)/2,d=2*Math.PI*l,f=d*(1-r);let h="var(--x-blue, #1d9bf0)";return n<=0?h="var(--x-red, #f4212e)":n<=20&&(h="var(--x-yellow, #ffd400)"),t===0?null:c.jsxs("div",{className:"tweet-char-counter",title:`${t} / ${e}`,style:{width:i,height:i},children:[c.jsxs("svg",{width:i,height:i,viewBox:`0 0 ${i} ${i}`,children:[c.jsx("circle",{cx:i/2,cy:i/2,r:l,fill:"none",stroke:"var(--x-border, #eff3f4)",strokeWidth:o}),c.jsx("circle",{cx:i/2,cy:i/2,r:l,fill:"none",stroke:h,strokeWidth:o,strokeDasharray:d,strokeDashoffset:f,strokeLinecap:"round",transform:`rotate(-90 ${i/2} ${i/2})`,style:{transition:"stroke-dashoffset 0.15s ease, stroke 0.15s ease"}})]}),s&&c.jsx("span",{className:"tweet-char-number",style:{color:h,fontSize:n<-9||n>9?10:11},children:n})]})}const Dk="@openwriter/plugin-x-api",Pk=[{key:"api-key",label:"API Key",env:"X_API_KEY"},{key:"api-secret",label:"API Secret",env:"X_API_SECRET"},{key:"access-token",label:"Access Token",env:"X_ACCESS_TOKEN"},{key:"access-token-secret",label:"Access Token Secret",env:"X_ACCESS_TOKEN_SECRET"}];function lz({onConnected:t,onCancel:e}){const[n,r]=x.useState({"api-key":"","api-secret":"","access-token":"","access-token-secret":""}),[s,i]=x.useState(!1),[o,l]=x.useState(""),d=Pk.every(h=>n[h.key].trim()),f=async()=>{i(!0),l("");try{if(!(await fetch("/api/plugins/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Dk,config:n})})).ok)throw new Error("Failed to save config");const g=await(await fetch("/api/plugins/enable",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Dk})})).json();if(!g.success)throw new Error(g.error||"Failed to enable plugin");const b=await(await fetch("/api/x/status")).json();b.connected?t():l(b.error||"Could not verify X credentials. Check your API keys.")}catch(h){l(h.message||"Connection failed")}finally{i(!1)}};return c.jsxs("div",{className:"x-connect-prompt",children:[c.jsxs("div",{className:"x-connect-header",children:[c.jsx("span",{className:"x-connect-title",children:"Connect your X account to post"}),c.jsx("button",{className:"x-connect-cancel",onClick:e,title:"Cancel",children:c.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18",children:c.jsx("path",{fill:"currentColor",d:"M10.59 12L4.54 5.96l1.42-1.42L12 10.59l6.04-6.05 1.42 1.42L13.41 12l6.05 6.04-1.42 1.42L12 13.41l-6.04 6.05-1.42-1.42L10.59 12z"})})})]}),c.jsx("div",{className:"x-connect-fields",children:Pk.map(h=>c.jsxs("div",{className:"x-connect-field",children:[c.jsx("label",{className:"x-connect-label",children:h.label}),c.jsx("input",{type:"password",className:"x-connect-input",value:n[h.key],onChange:m=>r(g=>({...g,[h.key]:m.target.value})),placeholder:h.env,spellCheck:!1,autoComplete:"off"})]},h.key))}),o&&c.jsx("div",{className:"x-connect-error",children:o}),c.jsxs("div",{className:"x-connect-actions",children:[c.jsx("a",{className:"x-connect-dev-link",href:"https://developer.x.com/en/portal/dashboard",target:"_blank",rel:"noopener noreferrer",children:"Get credentials"}),c.jsx("button",{className:"x-connect-btn",onClick:f,disabled:!d||s,children:s?"Connecting...":"Connect"})]})]})}var Bk={},Bp,$k;function $s(){return $k||($k=1,Bp=function(t){return typeof t=="object"?t!==null:typeof t=="function"}),Bp}var $p,zk;function Cr(){if(zk)return $p;zk=1;var t=$s();return $p=function(e){if(!t(e))throw TypeError(e+" is not an object!");return e},$p}var zp,Fk;function Qd(){return Fk||(Fk=1,zp=function(t){if(t==null)throw TypeError("Can't call method on "+t);return t}),zp}var Fp,Uk;function ji(){if(Uk)return Fp;Uk=1;var t=Qd();return Fp=function(e){return Object(t(e))},Fp}var Up,Hk;function Zd(){if(Hk)return Up;Hk=1;var t=Math.ceil,e=Math.floor;return Up=function(n){return isNaN(n=+n)?0:(n>0?e:t)(n)},Up}var Hp,Wk;function mo(){if(Wk)return Hp;Wk=1;var t=Zd(),e=Math.min;return Hp=function(n){return n>0?e(t(n),9007199254740991):0},Hp}var Wp,qk;function U2(){if(qk)return Wp;qk=1;var t=Zd(),e=Qd();return Wp=function(n){return function(r,s){var i=String(e(r)),o=t(s),l=i.length,d,f;return o<0||o>=l?n?"":void 0:(d=i.charCodeAt(o),d<55296||d>56319||o+1===l||(f=i.charCodeAt(o+1))<56320||f>57343?n?i.charAt(o):d:n?i.slice(o,o+2):(d-55296<<10)+(f-56320)+65536)}},Wp}var qp,Vk;function ly(){if(Vk)return qp;Vk=1;var t=U2()(!0);return qp=function(e,n,r){return n+(r?t(e,n).length:1)},qp}var Vp,Kk;function ef(){if(Kk)return Vp;Kk=1;var t={}.toString;return Vp=function(e){return t.call(e).slice(8,-1)},Vp}var Kp={exports:{}},Gp={exports:{}},Jp={exports:{}},Gk;function fa(){if(Gk)return Jp.exports;Gk=1;var t=Jp.exports={version:"2.6.12"};return typeof __e=="number"&&(__e=t),Jp.exports}var Yp={exports:{}},Jk;function Ur(){if(Jk)return Yp.exports;Jk=1;var t=Yp.exports=typeof window<"u"&&window.Math==Math?window:typeof self<"u"&&self.Math==Math?self:Function("return this")();return typeof __g=="number"&&(__g=t),Yp.exports}var Xp,Yk;function tf(){return Yk||(Yk=1,Xp=!1),Xp}var Xk;function nf(){if(Xk)return Gp.exports;Xk=1;var t=fa(),e=Ur(),n="__core-js_shared__",r=e[n]||(e[n]={});return(Gp.exports=function(s,i){return r[s]||(r[s]=i!==void 0?i:{})})("versions",[]).push({version:t.version,mode:tf()?"pure":"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"}),Gp.exports}var Qp,Qk;function Pl(){if(Qk)return Qp;Qk=1;var t=0,e=Math.random();return Qp=function(n){return"Symbol(".concat(n===void 0?"":n,")_",(++t+e).toString(36))},Qp}var Zk;function Dn(){if(Zk)return Kp.exports;Zk=1;var t=nf()("wks"),e=Pl(),n=Ur().Symbol,r=typeof n=="function",s=Kp.exports=function(i){return t[i]||(t[i]=r&&n[i]||(r?n:e)("Symbol."+i))};return s.store=t,Kp.exports}var Zp,e1;function cy(){if(e1)return Zp;e1=1;var t=ef(),e=Dn()("toStringTag"),n=t((function(){return arguments})())=="Arguments",r=function(s,i){try{return s[i]}catch{}};return Zp=function(s){var i,o,l;return s===void 0?"Undefined":s===null?"Null":typeof(o=r(i=Object(s),e))=="string"?o:n?t(i):(l=t(i))=="Object"&&typeof i.callee=="function"?"Arguments":l},Zp}var em,t1;function uy(){if(t1)return em;t1=1;var t=cy(),e=RegExp.prototype.exec;return em=function(n,r){var s=n.exec;if(typeof s=="function"){var i=s.call(n,r);if(typeof i!="object")throw new TypeError("RegExp exec method returned something other than an Object or null");return i}if(t(n)!=="RegExp")throw new TypeError("RegExp#exec called on incompatible receiver");return e.call(n,r)},em}var n1={},tm,r1;function rf(){if(r1)return tm;r1=1;var t=Cr();return tm=function(){var e=t(this),n="";return e.global&&(n+="g"),e.ignoreCase&&(n+="i"),e.multiline&&(n+="m"),e.unicode&&(n+="u"),e.sticky&&(n+="y"),n},tm}var nm,s1;function dy(){if(s1)return nm;s1=1;var t=rf(),e=RegExp.prototype.exec,n=String.prototype.replace,r=e,s="lastIndex",i=(function(){var d=/a/,f=/b*/g;return e.call(d,"a"),e.call(f,"a"),d[s]!==0||f[s]!==0})(),o=/()??/.exec("")[1]!==void 0,l=i||o;return l&&(r=function(f){var h=this,m,g,v,b;return o&&(g=new RegExp("^"+h.source+"$(?!\\s)",t.call(h))),i&&(m=h[s]),v=e.call(h,f),i&&v&&(h[s]=h.global?v.index+v[0].length:m),o&&v&&v.length>1&&n.call(v[0],g,function(){for(b=1;b<arguments.length-2;b++)arguments[b]===void 0&&(v[b]=void 0)}),v}),nm=r,nm}var rm={},sm,i1;function rs(){return i1||(i1=1,sm=function(t){try{return!!t()}catch{return!0}}),sm}var im,o1;function Hr(){return o1||(o1=1,im=!rs()(function(){return Object.defineProperty({},"a",{get:function(){return 7}}).a!=7})),im}var om,a1;function H2(){if(a1)return om;a1=1;var t=$s(),e=Ur().document,n=t(e)&&t(e.createElement);return om=function(r){return n?e.createElement(r):{}},om}var am,l1;function W2(){return l1||(l1=1,am=!Hr()&&!rs()(function(){return Object.defineProperty(H2()("div"),"a",{get:function(){return 7}}).a!=7})),am}var lm,c1;function fy(){if(c1)return lm;c1=1;var t=$s();return lm=function(e,n){if(!t(e))return e;var r,s;if(n&&typeof(r=e.toString)=="function"&&!t(s=r.call(e))||typeof(r=e.valueOf)=="function"&&!t(s=r.call(e))||!n&&typeof(r=e.toString)=="function"&&!t(s=r.call(e)))return s;throw TypeError("Can't convert object to primitive value")},lm}var u1;function ss(){if(u1)return rm;u1=1;var t=Cr(),e=W2(),n=fy(),r=Object.defineProperty;return rm.f=Hr()?Object.defineProperty:function(i,o,l){if(t(i),o=n(o,!0),t(l),e)try{return r(i,o,l)}catch{}if("get"in l||"set"in l)throw TypeError("Accessors not supported!");return"value"in l&&(i[o]=l.value),i},rm}var cm,d1;function Bl(){return d1||(d1=1,cm=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}}),cm}var um,f1;function Mi(){if(f1)return um;f1=1;var t=ss(),e=Bl();return um=Hr()?function(n,r,s){return t.f(n,r,e(1,s))}:function(n,r,s){return n[r]=s,n},um}var dm={exports:{}},fm,h1;function go(){if(h1)return fm;h1=1;var t={}.hasOwnProperty;return fm=function(e,n){return t.call(e,n)},fm}var hm,p1;function cz(){return p1||(p1=1,hm=nf()("native-function-to-string",Function.toString)),hm}var m1;function zs(){if(m1)return dm.exports;m1=1;var t=Ur(),e=Mi(),n=go(),r=Pl()("src"),s=cz(),i="toString",o=(""+s).split(i);return fa().inspectSource=function(l){return s.call(l)},(dm.exports=function(l,d,f,h){var m=typeof f=="function";m&&(n(f,"name")||e(f,"name",d)),l[d]!==f&&(m&&(n(f,r)||e(f,r,l[d]?""+l[d]:o.join(String(d)))),l===t?l[d]=f:h?l[d]?l[d]=f:e(l,d,f):(delete l[d],e(l,d,f)))})(Function.prototype,i,function(){return typeof this=="function"&&this[r]||s.call(this)}),dm.exports}var pm,g1;function sf(){return g1||(g1=1,pm=function(t){if(typeof t!="function")throw TypeError(t+" is not a function!");return t}),pm}var mm,v1;function of(){if(v1)return mm;v1=1;var t=sf();return mm=function(e,n,r){if(t(e),n===void 0)return e;switch(r){case 1:return function(s){return e.call(n,s)};case 2:return function(s,i){return e.call(n,s,i)};case 3:return function(s,i,o){return e.call(n,s,i,o)}}return function(){return e.apply(n,arguments)}},mm}var gm,y1;function vr(){if(y1)return gm;y1=1;var t=Ur(),e=fa(),n=Mi(),r=zs(),s=of(),i="prototype",o=function(l,d,f){var h=l&o.F,m=l&o.G,g=l&o.S,v=l&o.P,b=l&o.B,k=m?t:g?t[d]||(t[d]={}):(t[d]||{})[i],w=m?e:e[d]||(e[d]={}),E=w[i]||(w[i]={}),C,T,j,_;m&&(f=d);for(C in f)T=!h&&k&&k[C]!==void 0,j=(T?k:f)[C],_=b&&T?s(j,t):v&&typeof j=="function"?s(Function.call,j):j,k&&r(k,C,j,l&o.U),w[C]!=j&&n(w,C,_),v&&E[C]!=j&&(E[C]=j)};return t.core=e,o.F=1,o.G=2,o.S=4,o.P=8,o.B=16,o.W=32,o.U=64,o.R=128,gm=o,gm}var b1;function uz(){if(b1)return n1;b1=1;var t=dy();return vr()({target:"RegExp",proto:!0,forced:t!==/./.exec},{exec:t}),n1}var vm,x1;function hy(){if(x1)return vm;x1=1,uz();var t=zs(),e=Mi(),n=rs(),r=Qd(),s=Dn(),i=dy(),o=s("species"),l=!n(function(){var f=/./;return f.exec=function(){var h=[];return h.groups={a:"7"},h},"".replace(f,"$<a>")!=="7"}),d=(function(){var f=/(?:)/,h=f.exec;f.exec=function(){return h.apply(this,arguments)};var m="ab".split(f);return m.length===2&&m[0]==="a"&&m[1]==="b"})();return vm=function(f,h,m){var g=s(f),v=!n(function(){var T={};return T[g]=function(){return 7},""[f](T)!=7}),b=v?!n(function(){var T=!1,j=/a/;return j.exec=function(){return T=!0,null},f==="split"&&(j.constructor={},j.constructor[o]=function(){return j}),j[g](""),!T}):void 0;if(!v||!b||f==="replace"&&!l||f==="split"&&!d){var k=/./[g],w=m(r,g,""[f],function(j,_,A,O,B){return _.exec===i?v&&!B?{done:!0,value:k.call(_,A,O)}:{done:!0,value:j.call(A,_,O)}:{done:!1}}),E=w[0],C=w[1];t(String.prototype,f,E),e(RegExp.prototype,g,h==2?function(T,j){return C.call(T,this,j)}:function(T){return C.call(T,this)})}},vm}var w1;function dz(){if(w1)return Bk;w1=1;var t=Cr(),e=ji(),n=mo(),r=Zd(),s=ly(),i=uy(),o=Math.max,l=Math.min,d=Math.floor,f=/\$([$&`']|\d\d?|<[^>]*>)/g,h=/\$([$&`']|\d\d?)/g,m=function(g){return g===void 0?g:String(g)};return hy()("replace",2,function(g,v,b,k){return[function(C,T){var j=g(this),_=C==null?void 0:C[v];return _!==void 0?_.call(C,j,T):b.call(String(j),C,T)},function(E,C){var T=k(b,E,this,C);if(T.done)return T.value;var j=t(E),_=String(this),A=typeof C=="function";A||(C=String(C));var O=j.global;if(O){var B=j.unicode;j.lastIndex=0}for(var $=[];;){var W=i(j,_);if(W===null||($.push(W),!O))break;var J=String(W[0]);J===""&&(j.lastIndex=s(_,n(j.lastIndex),B))}for(var z="",G=0,D=0;D<$.length;D++){W=$[D];for(var U=String(W[0]),q=o(l(r(W.index),_.length),0),se=[],V=1;V<W.length;V++)se.push(m(W[V]));var te=W.groups;if(A){var K=[U].concat(se,q,_);te!==void 0&&K.push(te);var M=String(C.apply(void 0,K))}else M=w(U,_,q,se,te,C);q>=G&&(z+=_.slice(G,q)+M,G=q+U.length)}return z+_.slice(G)}];function w(E,C,T,j,_,A){var O=T+E.length,B=j.length,$=h;return _!==void 0&&(_=e(_),$=f),b.call(A,$,function(W,J){var z;switch(J.charAt(0)){case"$":return"$";case"&":return E;case"`":return C.slice(0,T);case"'":return C.slice(O);case"<":z=_[J.slice(1,-1)];break;default:var G=+J;if(G===0)return W;if(G>B){var D=d(G/10);return D===0?W:D<=B?j[D-1]===void 0?J.charAt(1):j[D-1]+J.charAt(1):W}z=j[G-1]}return z===void 0?"":z})}}),Bk}dz();var k1={},ym,S1;function py(){if(S1)return ym;S1=1;var t=ef();return ym=Object("z").propertyIsEnumerable(0)?Object:function(e){return t(e)=="String"?e.split(""):Object(e)},ym}var bm,E1;function vo(){if(E1)return bm;E1=1;var t=py(),e=Qd();return bm=function(n){return t(e(n))},bm}var xm,N1;function fz(){if(N1)return xm;N1=1;var t=Zd(),e=Math.max,n=Math.min;return xm=function(r,s){return r=t(r),r<0?e(r+s,0):n(r,s)},xm}var wm,C1;function q2(){if(C1)return wm;C1=1;var t=vo(),e=mo(),n=fz();return wm=function(r){return function(s,i,o){var l=t(s),d=e(l.length),f=n(o,d),h;if(r&&i!=i){for(;d>f;)if(h=l[f++],h!=h)return!0}else for(;d>f;f++)if((r||f in l)&&l[f]===i)return r||f||0;return!r&&-1}},wm}var km,_1;function $l(){if(_1)return km;_1=1;var t=rs();return km=function(e,n){return!!e&&t(function(){n?e.call(null,function(){},1):e.call(null)})},km}var T1;function hz(){if(T1)return k1;T1=1;var t=vr(),e=q2()(!1),n=[].indexOf,r=!!n&&1/[1].indexOf(1,-0)<0;return t(t.P+t.F*(r||!$l()(n)),"Array",{indexOf:function(i){return r?n.apply(this,arguments)||0:e(this,i,arguments[1])}}),k1}hz();var pz=/[a-z]{1,6}(?:[._][a-z]{1,2})?/i,V2=/\!'#%&'\(\)*\+,\\\-\.\/:;<=>\?@\[\]\^_{|}~\$/,j1={},Sm={},Em={},M1;function my(){return M1||(M1=1,Em.f={}.propertyIsEnumerable),Em}var A1;function gy(){if(A1)return Sm;A1=1;var t=my(),e=Bl(),n=vo(),r=fy(),s=go(),i=W2(),o=Object.getOwnPropertyDescriptor;return Sm.f=Hr()?o:function(d,f){if(d=n(d),f=r(f,!0),i)try{return o(d,f)}catch{}if(s(d,f))return e(!t.f.call(d,f),d[f])},Sm}var Nm,R1;function mz(){if(R1)return Nm;R1=1;var t=$s(),e=Cr(),n=function(r,s){if(e(r),!t(s)&&s!==null)throw TypeError(s+": can't set as prototype!")};return Nm={set:Object.setPrototypeOf||("__proto__"in{}?(function(r,s,i){try{i=of()(Function.call,gy().f(Object.prototype,"__proto__").set,2),i(r,[]),s=!(r instanceof Array)}catch{s=!0}return function(l,d){return n(l,d),s?l.__proto__=d:i(l,d),l}})({},!1):void 0),check:n},Nm}var Cm,O1;function gz(){if(O1)return Cm;O1=1;var t=$s(),e=mz().set;return Cm=function(n,r,s){var i=r.constructor,o;return i!==s&&typeof i=="function"&&(o=i.prototype)!==s.prototype&&t(o)&&e&&e(n,o),n},Cm}var _m={},Tm,I1;function vy(){if(I1)return Tm;I1=1;var t=nf()("keys"),e=Pl();return Tm=function(n){return t[n]||(t[n]=e(n))},Tm}var jm,L1;function K2(){if(L1)return jm;L1=1;var t=go(),e=vo(),n=q2()(!1),r=vy()("IE_PROTO");return jm=function(s,i){var o=e(s),l=0,d=[],f;for(f in o)f!=r&&t(o,f)&&d.push(f);for(;i.length>l;)t(o,f=i[l++])&&(~n(d,f)||d.push(f));return d},jm}var Mm,D1;function yy(){return D1||(D1=1,Mm="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")),Mm}var P1;function af(){if(P1)return _m;P1=1;var t=K2(),e=yy().concat("length","prototype");return _m.f=Object.getOwnPropertyNames||function(r){return t(r,e)},_m}var Am,B1;function G2(){if(B1)return Am;B1=1;var t=$s(),e=ef(),n=Dn()("match");return Am=function(r){var s;return t(r)&&((s=r[n])!==void 0?!!s:e(r)=="RegExp")},Am}var Rm,$1;function vz(){if($1)return Rm;$1=1;var t=Ur(),e=ss(),n=Hr(),r=Dn()("species");return Rm=function(s){var i=t[s];n&&i&&!i[r]&&e.f(i,r,{configurable:!0,get:function(){return this}})},Rm}var z1;function yz(){if(z1)return j1;z1=1;var t=Ur(),e=gz(),n=ss().f,r=af().f,s=G2(),i=rf(),o=t.RegExp,l=o,d=o.prototype,f=/a/g,h=/a/g,m=new o(f)!==f;if(Hr()&&(!m||rs()(function(){return h[Dn()("match")]=!1,o(f)!=f||o(h)==h||o(f,"i")!="/a/i"}))){o=function(w,E){var C=this instanceof o,T=s(w),j=E===void 0;return!C&&T&&w.constructor===o&&j?w:e(m?new l(T&&!j?w.source:w,E):l((T=w instanceof o)?w.source:w,T&&j?i.call(w):E),C?this:d,o)};for(var g=function(k){k in o||n(o,k,{configurable:!0,get:function(){return l[k]},set:function(w){l[k]=w}})},v=r(l),b=0;v.length>b;)g(v[b++]);d.constructor=o,o.prototype=d,zs()(t,"RegExp",o)}return vz()("RegExp"),j1}yz();function Mt(t,e,n){return n=n||"",typeof t!="string"&&(t.global&&n.indexOf("g")<0&&(n+="g"),t.ignoreCase&&n.indexOf("i")<0&&(n+="i"),t.multiline&&n.indexOf("m")<0&&(n+="m"),t=t.source),new RegExp(t.replace(/#\{(\w+)\}/g,function(r,s){var i=e[s]||"";return typeof i!="string"&&(i=i.source),i}),n)}var J2=/\x09-\x0D\x20\x85\xA0\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000/;const Y2=Mt(/[#{spacesGroup}]/,{spacesGroup:J2});Mt("(^|#{spaces})(\\$)(#{cashtag})(?=$|\\s|[#{punct}])",{cashtag:pz,spaces:Y2,punct:V2},"gi");var F1={},U1;function bz(){if(U1)return F1;U1=1;var t=Cr(),e=mo(),n=ly(),r=uy();return hy()("match",1,function(s,i,o,l){return[function(f){var h=s(this),m=f==null?void 0:f[i];return m!==void 0?m.call(f,h):new RegExp(f)[i](String(h))},function(d){var f=l(o,d,this);if(f.done)return f.value;var h=t(d),m=String(this);if(!h.global)return r(h,m);var g=h.unicode;h.lastIndex=0;for(var v=[],b=0,k;(k=r(h,m))!==null;){var w=String(k[0]);v[b]=w,w===""&&(h.lastIndex=n(m,e(h.lastIndex),g)),b++}return b===0?null:v}]}),F1}bz();var X2=/[##]/;Mt(/^(?:#{hashSigns}|:\/\/)/,{hashSigns:X2});var Q2=Mt(RegExp("(?:(?:한국|香港|澳門|新加坡|台灣|台湾|中國|中国|გე|ລາວ|ไทย|ලංකා|ഭാരതം|ಭಾರತ|భారత్|சிங்கப்பூர்|இலங்கை|இந்தியா|ଭାରତ|ભારત|ਭਾਰਤ|ভাৰত|ভারত|বাংলা|भारोत|भारतम्|भारत|ڀارت|پاکستان|موريتانيا|مليسيا|مصر|قطر|فلسطين|عمان|عراق|سورية|سودان|تونس|بھارت|بارت|ایران|امارات|المغرب|السعودية|الجزائر|البحرين|الاردن|հայ|қаз|укр|срб|рф|мон|мкд|ею|бел|бг|ευ|ελ|zw|zm|za|yt|ye|ws|wf|vu|vn|vi|vg|ve|vc|va|uz|uy|us|um|uk|ug|ua|tz|tw|tv|tt|tr|tp|to|tn|tm|tl|tk|tj|th|tg|tf|td|tc|sz|sy|sx|sv|su|st|ss|sr|so|sn|sm|sl|sk|sj|si|sh|sg|se|sd|sc|sb|sa|rw|ru|rs|ro|re|qa|py|pw|pt|ps|pr|pn|pm|pl|pk|ph|pg|pf|pe|pa|om|nz|nu|nr|np|no|nl|ni|ng|nf|ne|nc|na|mz|my|mx|mw|mv|mu|mt|ms|mr|mq|mp|mo|mn|mm|ml|mk|mh|mg|mf|me|md|mc|ma|ly|lv|lu|lt|ls|lr|lk|li|lc|lb|la|kz|ky|kw|kr|kp|kn|km|ki|kh|kg|ke|jp|jo|jm|je|it|is|ir|iq|io|in|im|il|ie|id|hu|ht|hr|hn|hm|hk|gy|gw|gu|gt|gs|gr|gq|gp|gn|gm|gl|gi|gh|gg|gf|ge|gd|gb|ga|fr|fo|fm|fk|fj|fi|eu|et|es|er|eh|eg|ee|ec|dz|do|dm|dk|dj|de|cz|cy|cx|cw|cv|cu|cr|co|cn|cm|cl|ck|ci|ch|cg|cf|cd|cc|ca|bz|by|bw|bv|bt|bs|br|bq|bo|bn|bm|bl|bj|bi|bh|bg|bf|be|bd|bb|ba|az|ax|aw|au|at|as|ar|aq|ao|an|am|al|ai|ag|af|ae|ad|ac)(?=[^0-9a-zA-Z@+-]|$))")),Z2=/\u202A-\u202E\u061C\u200E\u200F\u2066\u2067\u2068\u2069/,by=/\uFFFE\uFEFF\uFFFF/;function xz(t,e){return t.replace(/#\{(\w+)\}/g,function(n,r){return e[r]||""})}var wz=xz("#{punct}#{spacesGroup}#{invalidCharsGroup}#{directionalMarkersGroup}",{punct:V2,spacesGroup:J2,invalidCharsGroup:by,directionalMarkersGroup:Z2}),eT=Mt(/[^#{invalidDomainChars}]/,{invalidDomainChars:wz}),kz=Mt(/(?:(?:#{validDomainChars}(?:-|#{validDomainChars})*)?#{validDomainChars}\.)/,{validDomainChars:eT}),tT=Mt(RegExp("(?:(?:삼성|닷컴|닷넷|香格里拉|餐厅|食品|飞利浦|電訊盈科|集团|通販|购物|谷歌|诺基亚|联通|网络|网站|网店|网址|组织机构|移动|珠宝|点看|游戏|淡马锡|机构|書籍|时尚|新闻|政府|政务|招聘|手表|手机|我爱你|慈善|微博|广东|工行|家電|娱乐|天主教|大拿|大众汽车|在线|嘉里大酒店|嘉里|商标|商店|商城|公益|公司|八卦|健康|信息|佛山|企业|中文网|中信|世界|ポイント|ファッション|セール|ストア|コム|グーグル|クラウド|みんな|คอม|संगठन|नेट|कॉम|همراه|موقع|موبايلي|كوم|كاثوليك|عرب|شبكة|بيتك|بازار|العليان|ارامكو|اتصالات|ابوظبي|קום|сайт|рус|орг|онлайн|москва|ком|католик|дети|zuerich|zone|zippo|zip|zero|zara|zappos|yun|youtube|you|yokohama|yoga|yodobashi|yandex|yamaxun|yahoo|yachts|xyz|xxx|xperia|xin|xihuan|xfinity|xerox|xbox|wtf|wtc|wow|world|works|work|woodside|wolterskluwer|wme|winners|wine|windows|win|williamhill|wiki|wien|whoswho|weir|weibo|wedding|wed|website|weber|webcam|weatherchannel|weather|watches|watch|warman|wanggou|wang|walter|walmart|wales|vuelos|voyage|voto|voting|vote|volvo|volkswagen|vodka|vlaanderen|vivo|viva|vistaprint|vista|vision|visa|virgin|vip|vin|villas|viking|vig|video|viajes|vet|versicherung|vermögensberatung|vermögensberater|verisign|ventures|vegas|vanguard|vana|vacations|ups|uol|uno|university|unicom|uconnect|ubs|ubank|tvs|tushu|tunes|tui|tube|trv|trust|travelersinsurance|travelers|travelchannel|travel|training|trading|trade|toys|toyota|town|tours|total|toshiba|toray|top|tools|tokyo|today|tmall|tkmaxx|tjx|tjmaxx|tirol|tires|tips|tiffany|tienda|tickets|tiaa|theatre|theater|thd|teva|tennis|temasek|telefonica|telecity|tel|technology|tech|team|tdk|tci|taxi|tax|tattoo|tatar|tatamotors|target|taobao|talk|taipei|tab|systems|symantec|sydney|swiss|swiftcover|swatch|suzuki|surgery|surf|support|supply|supplies|sucks|style|study|studio|stream|store|storage|stockholm|stcgroup|stc|statoil|statefarm|statebank|starhub|star|staples|stada|srt|srl|spreadbetting|spot|sport|spiegel|space|soy|sony|song|solutions|solar|sohu|software|softbank|social|soccer|sncf|smile|smart|sling|skype|sky|skin|ski|site|singles|sina|silk|shriram|showtime|show|shouji|shopping|shop|shoes|shiksha|shia|shell|shaw|sharp|shangrila|sfr|sexy|sex|sew|seven|ses|services|sener|select|seek|security|secure|seat|search|scot|scor|scjohnson|science|schwarz|schule|school|scholarships|schmidt|schaeffler|scb|sca|sbs|sbi|saxo|save|sas|sarl|sapo|sap|sanofi|sandvikcoromant|sandvik|samsung|samsclub|salon|sale|sakura|safety|safe|saarland|ryukyu|rwe|run|ruhr|rugby|rsvp|room|rogers|rodeo|rocks|rocher|rmit|rip|rio|ril|rightathome|ricoh|richardli|rich|rexroth|reviews|review|restaurant|rest|republican|report|repair|rentals|rent|ren|reliance|reit|reisen|reise|rehab|redumbrella|redstone|red|recipes|realty|realtor|realestate|read|raid|radio|racing|qvc|quest|quebec|qpon|pwc|pub|prudential|pru|protection|property|properties|promo|progressive|prof|productions|prod|pro|prime|press|praxi|pramerica|post|porn|politie|poker|pohl|pnc|plus|plumbing|playstation|play|place|pizza|pioneer|pink|ping|pin|pid|pictures|pictet|pics|piaget|physio|photos|photography|photo|phone|philips|phd|pharmacy|pfizer|pet|pccw|pay|passagens|party|parts|partners|pars|paris|panerai|panasonic|pamperedchef|page|ovh|ott|otsuka|osaka|origins|orientexpress|organic|org|orange|oracle|open|ooo|onyourside|online|onl|ong|one|omega|ollo|oldnavy|olayangroup|olayan|okinawa|office|off|observer|obi|nyc|ntt|nrw|nra|nowtv|nowruz|now|norton|northwesternmutual|nokia|nissay|nissan|ninja|nikon|nike|nico|nhk|ngo|nfl|nexus|nextdirect|next|news|newholland|new|neustar|network|netflix|netbank|net|nec|nba|navy|natura|nationwide|name|nagoya|nadex|nab|mutuelle|mutual|museum|mtr|mtpc|mtn|msd|movistar|movie|mov|motorcycles|moto|moscow|mortgage|mormon|mopar|montblanc|monster|money|monash|mom|moi|moe|moda|mobily|mobile|mobi|mma|mls|mlb|mitsubishi|mit|mint|mini|mil|microsoft|miami|metlife|merckmsd|meo|menu|men|memorial|meme|melbourne|meet|media|med|mckinsey|mcdonalds|mcd|mba|mattel|maserati|marshalls|marriott|markets|marketing|market|map|mango|management|man|makeup|maison|maif|madrid|macys|luxury|luxe|lupin|lundbeck|ltda|ltd|lplfinancial|lpl|love|lotto|lotte|london|lol|loft|locus|locker|loans|loan|llp|llc|lixil|living|live|lipsy|link|linde|lincoln|limo|limited|lilly|like|lighting|lifestyle|lifeinsurance|life|lidl|liaison|lgbt|lexus|lego|legal|lefrak|leclerc|lease|lds|lawyer|law|latrobe|latino|lat|lasalle|lanxess|landrover|land|lancome|lancia|lancaster|lamer|lamborghini|ladbrokes|lacaixa|kyoto|kuokgroup|kred|krd|kpn|kpmg|kosher|komatsu|koeln|kiwi|kitchen|kindle|kinder|kim|kia|kfh|kerryproperties|kerrylogistics|kerryhotels|kddi|kaufen|juniper|juegos|jprs|jpmorgan|joy|jot|joburg|jobs|jnj|jmp|jll|jlc|jio|jewelry|jetzt|jeep|jcp|jcb|java|jaguar|iwc|iveco|itv|itau|istanbul|ist|ismaili|iselect|irish|ipiranga|investments|intuit|international|intel|int|insure|insurance|institute|ink|ing|info|infiniti|industries|inc|immobilien|immo|imdb|imamat|ikano|iinet|ifm|ieee|icu|ice|icbc|ibm|hyundai|hyatt|hughes|htc|hsbc|how|house|hotmail|hotels|hoteles|hot|hosting|host|hospital|horse|honeywell|honda|homesense|homes|homegoods|homedepot|holiday|holdings|hockey|hkt|hiv|hitachi|hisamitsu|hiphop|hgtv|hermes|here|helsinki|help|healthcare|health|hdfcbank|hdfc|hbo|haus|hangout|hamburg|hair|guru|guitars|guide|guge|gucci|guardian|group|grocery|gripe|green|gratis|graphics|grainger|gov|got|gop|google|goog|goodyear|goodhands|goo|golf|goldpoint|gold|godaddy|gmx|gmo|gmbh|gmail|globo|global|gle|glass|glade|giving|gives|gifts|gift|ggee|george|genting|gent|gea|gdn|gbiz|gay|garden|gap|games|game|gallup|gallo|gallery|gal|fyi|futbol|furniture|fund|fun|fujixerox|fujitsu|ftr|frontier|frontdoor|frogans|frl|fresenius|free|fox|foundation|forum|forsale|forex|ford|football|foodnetwork|food|foo|fly|flsmidth|flowers|florist|flir|flights|flickr|fitness|fit|fishing|fish|firmdale|firestone|fire|financial|finance|final|film|fido|fidelity|fiat|ferrero|ferrari|feedback|fedex|fast|fashion|farmers|farm|fans|fan|family|faith|fairwinds|fail|fage|extraspace|express|exposed|expert|exchange|everbank|events|eus|eurovision|etisalat|esurance|estate|esq|erni|ericsson|equipment|epson|epost|enterprises|engineering|engineer|energy|emerck|email|education|edu|edeka|eco|eat|earth|dvr|dvag|durban|dupont|duns|dunlop|duck|dubai|dtv|drive|download|dot|doosan|domains|doha|dog|dodge|doctor|docs|dnp|diy|dish|discover|discount|directory|direct|digital|diet|diamonds|dhl|dev|design|desi|dentist|dental|democrat|delta|deloitte|dell|delivery|degree|deals|dealer|deal|dds|dclk|day|datsun|dating|date|data|dance|dad|dabur|cyou|cymru|cuisinella|csc|cruises|cruise|crs|crown|cricket|creditunion|creditcard|credit|cpa|courses|coupons|coupon|country|corsica|coop|cool|cookingchannel|cooking|contractors|contact|consulting|construction|condos|comsec|computer|compare|company|community|commbank|comcast|com|cologne|college|coffee|codes|coach|clubmed|club|cloud|clothing|clinique|clinic|click|cleaning|claims|cityeats|city|citic|citi|citadel|cisco|circle|cipriani|church|chrysler|chrome|christmas|chloe|chintai|cheap|chat|chase|charity|channel|chanel|cfd|cfa|cern|ceo|center|ceb|cbs|cbre|cbn|cba|catholic|catering|cat|casino|cash|caseih|case|casa|cartier|cars|careers|career|care|cards|caravan|car|capitalone|capital|capetown|canon|cancerresearch|camp|camera|cam|calvinklein|call|cal|cafe|cab|bzh|buzz|buy|business|builders|build|bugatti|budapest|brussels|brother|broker|broadway|bridgestone|bradesco|box|boutique|bot|boston|bostik|bosch|boots|booking|book|boo|bond|bom|bofa|boehringer|boats|bnpparibas|bnl|bmw|bms|blue|bloomberg|blog|blockbuster|blanco|blackfriday|black|biz|bio|bingo|bing|bike|bid|bible|bharti|bet|bestbuy|best|berlin|bentley|beer|beauty|beats|bcn|bcg|bbva|bbt|bbc|bayern|bauhaus|basketball|baseball|bargains|barefoot|barclays|barclaycard|barcelona|bar|bank|band|bananarepublic|banamex|baidu|baby|azure|axa|aws|avianca|autos|auto|author|auspost|audio|audible|audi|auction|attorney|athleta|associates|asia|asda|arte|art|arpa|army|archi|aramco|arab|aquarelle|apple|app|apartments|aol|anz|anquan|android|analytics|amsterdam|amica|amfam|amex|americanfamily|americanexpress|alstom|alsace|ally|allstate|allfinanz|alipay|alibaba|alfaromeo|akdn|airtel|airforce|airbus|aigo|aig|agency|agakhan|africa|afl|afamilycompany|aetna|aero|aeg|adult|ads|adac|actor|active|aco|accountants|accountant|accenture|academy|abudhabi|abogado|able|abc|abbvie|abbott|abb|abarth|aarp|aaa|onion)(?=[^0-9a-zA-Z@+-]|$))")),nT=/(?:xn--[\-0-9a-z]+)/,Sz=Mt(/(?:(?:#{validDomainChars}(?:[_-]|#{validDomainChars})*)?#{validDomainChars}\.)/,{validDomainChars:eT}),Ez=Mt(/(?:#{validSubdomain}*#{validDomainName}(?:#{validGTLD}|#{validCCTLD}|#{validPunycode}))/,{validDomainName:kz,validSubdomain:Sz,validGTLD:tT,validCCTLD:Q2,validPunycode:nT}),Nz=/[0-9]+/,rT=/\u0400-\u04FF/,lf=/\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u024F\u0253\u0254\u0256\u0257\u0259\u025B\u0263\u0268\u026F\u0272\u0289\u028B\u02BB\u0300-\u036F\u1E00-\u1EFF/,sT=Mt(/[a-z#{cyrillicLettersAndMarks}0-9!\*';:=\+,\.\$\/%#\[\]\-\u2013_~@\|&#{latinAccentChars}]/i,{cyrillicLettersAndMarks:rT,latinAccentChars:lf}),iT=Mt("\\((?:#{validGeneralUrlPathChars}+|(?:#{validGeneralUrlPathChars}*\\(#{validGeneralUrlPathChars}+\\)#{validGeneralUrlPathChars}*))\\)",{validGeneralUrlPathChars:sT},"i"),Cz=Mt(/[\+\-a-z#{cyrillicLettersAndMarks}0-9=_#\/#{latinAccentChars}]|(?:#{validUrlBalancedParens})/i,{cyrillicLettersAndMarks:rT,latinAccentChars:lf,validUrlBalancedParens:iT}),_z=Mt("(?:(?:#{validGeneralUrlPathChars}*(?:#{validUrlBalancedParens}#{validGeneralUrlPathChars}*)*#{validUrlPathEndingChars})|(?:@#{validGeneralUrlPathChars}+/))",{validGeneralUrlPathChars:sT,validUrlBalancedParens:iT,validUrlPathEndingChars:Cz},"i"),Tz=Mt(/(?:[^A-Za-z0-9@@$###{invalidCharsGroup}]|[#{directionalMarkersGroup}]|^)/,{invalidCharsGroup:by,directionalMarkersGroup:Z2}),oT=/[a-z0-9!?\*'@\(\);:&=\+\$\/%#\[\]\-_\.,~|]/i,aT=/[a-z0-9\-_&=#\/]/i,H1=Mt("((#{validUrlPrecedingChars})((https?:\\/\\/)?(#{validDomain})(?::(#{validPortNumber}))?(\\/#{validUrlPath}*)?(\\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?))",{validUrlPrecedingChars:Tz,validDomain:Ez,validPortNumber:Nz,validUrlPath:_z,validUrlQueryChars:oT,validUrlQueryEndingChars:aT},"gi"),jz=/[-_.\/]$/,W1={},Om,q1;function Mz(){if(q1)return Om;q1=1;var t=Cr(),e=sf(),n=Dn()("species");return Om=function(r,s){var i=t(r).constructor,o;return i===void 0||(o=t(i)[n])==null?s:e(o)},Om}var V1;function Az(){if(V1)return W1;V1=1;var t=G2(),e=Cr(),n=Mz(),r=ly(),s=mo(),i=uy(),o=dy(),l=rs(),d=Math.min,f=[].push,h="split",m="length",g="lastIndex",v=4294967295,b=!l(function(){});return hy()("split",2,function(k,w,E,C){var T;return"abbc"[h](/(b)*/)[1]=="c"||"test"[h](/(?:)/,-1)[m]!=4||"ab"[h](/(?:ab)*/)[m]!=2||"."[h](/(.?)(.?)/)[m]!=4||"."[h](/()()/)[m]>1||""[h](/.?/)[m]?T=function(j,_){var A=String(this);if(j===void 0&&_===0)return[];if(!t(j))return E.call(A,j,_);for(var O=[],B=(j.ignoreCase?"i":"")+(j.multiline?"m":"")+(j.unicode?"u":"")+(j.sticky?"y":""),$=0,W=_===void 0?v:_>>>0,J=new RegExp(j.source,B+"g"),z,G,D;(z=o.call(J,A))&&(G=J[g],!(G>$&&(O.push(A.slice($,z.index)),z[m]>1&&z.index<A[m]&&f.apply(O,z.slice(1)),D=z[0][m],$=G,O[m]>=W)));)J[g]===z.index&&J[g]++;return $===A[m]?(D||!J.test(""))&&O.push(""):O.push(A.slice($)),O[m]>W?O.slice(0,W):O}:"0"[h](void 0,0)[m]?T=function(j,_){return j===void 0&&_===0?[]:E.call(this,j,_)}:T=E,[function(_,A){var O=k(this),B=_==null?void 0:_[w];return B!==void 0?B.call(_,O,A):T.call(String(O),_,A)},function(j,_){var A=C(T,j,this,_,T!==E);if(A.done)return A.value;var O=e(j),B=String(this),$=n(O,RegExp),W=O.unicode,J=(O.ignoreCase?"i":"")+(O.multiline?"m":"")+(O.unicode?"u":"")+(b?"y":"g"),z=new $(b?O:"^(?:"+O.source+")",J),G=_===void 0?v:_>>>0;if(G===0)return[];if(B.length===0)return i(z,B)===null?[B]:[];for(var D=0,U=0,q=[];U<B.length;){z.lastIndex=b?U:0;var se=i(z,b?B:B.slice(U)),V;if(se===null||(V=d(s(z.lastIndex+(b?0:U)),B.length))===D)U=r(B,U,W);else{if(q.push(B.slice(D,U)),q.length===G)return q;for(var te=1;te<=se.length-1;te++)if(q.push(se[te]),q.length===G)return q;U=D=V}}return q.push(B.slice(D)),q}]}),W1}Az();var sl={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */var Rz=sl.exports,K1;function Oz(){return K1||(K1=1,(function(t,e){(function(n){var r=e&&!e.nodeType&&e,s=t&&!t.nodeType&&t,i=typeof F0=="object"&&F0;(i.global===i||i.window===i||i.self===i)&&(n=i);var o,l=2147483647,d=36,f=1,h=26,m=38,g=700,v=72,b=128,k="-",w=/^xn--/,E=/[^\x20-\x7E]/,C=/[\x2E\u3002\uFF0E\uFF61]/g,T={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},j=d-f,_=Math.floor,A=String.fromCharCode,O;function B(K){throw new RangeError(T[K])}function $(K,M){for(var L=K.length,ee=[];L--;)ee[L]=M(K[L]);return ee}function W(K,M){var L=K.split("@"),ee="";L.length>1&&(ee=L[0]+"@",K=L[1]),K=K.replace(C,".");var fe=K.split("."),ge=$(fe,M).join(".");return ee+ge}function J(K){for(var M=[],L=0,ee=K.length,fe,ge;L<ee;)fe=K.charCodeAt(L++),fe>=55296&&fe<=56319&&L<ee?(ge=K.charCodeAt(L++),(ge&64512)==56320?M.push(((fe&1023)<<10)+(ge&1023)+65536):(M.push(fe),L--)):M.push(fe);return M}function z(K){return $(K,function(M){var L="";return M>65535&&(M-=65536,L+=A(M>>>10&1023|55296),M=56320|M&1023),L+=A(M),L}).join("")}function G(K){return K-48<10?K-22:K-65<26?K-65:K-97<26?K-97:d}function D(K,M){return K+22+75*(K<26)-((M!=0)<<5)}function U(K,M,L){var ee=0;for(K=L?_(K/g):K>>1,K+=_(K/M);K>j*h>>1;ee+=d)K=_(K/j);return _(ee+(j+1)*K/(K+m))}function q(K){var M=[],L=K.length,ee,fe=0,ge=b,oe=v,we,xe,We,He,Ze,Oe,Ke,pt,Je;for(we=K.lastIndexOf(k),we<0&&(we=0),xe=0;xe<we;++xe)K.charCodeAt(xe)>=128&&B("not-basic"),M.push(K.charCodeAt(xe));for(We=we>0?we+1:0;We<L;){for(He=fe,Ze=1,Oe=d;We>=L&&B("invalid-input"),Ke=G(K.charCodeAt(We++)),(Ke>=d||Ke>_((l-fe)/Ze))&&B("overflow"),fe+=Ke*Ze,pt=Oe<=oe?f:Oe>=oe+h?h:Oe-oe,!(Ke<pt);Oe+=d)Je=d-pt,Ze>_(l/Je)&&B("overflow"),Ze*=Je;ee=M.length+1,oe=U(fe-He,ee,He==0),_(fe/ee)>l-ge&&B("overflow"),ge+=_(fe/ee),fe%=ee,M.splice(fe++,0,ge)}return z(M)}function se(K){var M,L,ee,fe,ge,oe,we,xe,We,He,Ze,Oe=[],Ke,pt,Je,pe;for(K=J(K),Ke=K.length,M=b,L=0,ge=v,oe=0;oe<Ke;++oe)Ze=K[oe],Ze<128&&Oe.push(A(Ze));for(ee=fe=Oe.length,fe&&Oe.push(k);ee<Ke;){for(we=l,oe=0;oe<Ke;++oe)Ze=K[oe],Ze>=M&&Ze<we&&(we=Ze);for(pt=ee+1,we-M>_((l-L)/pt)&&B("overflow"),L+=(we-M)*pt,M=we,oe=0;oe<Ke;++oe)if(Ze=K[oe],Ze<M&&++L>l&&B("overflow"),Ze==M){for(xe=L,We=d;He=We<=ge?f:We>=ge+h?h:We-ge,!(xe<He);We+=d)pe=xe-He,Je=d-He,Oe.push(A(D(He+pe%Je,0))),xe=_(pe/Je);Oe.push(A(D(xe,0))),ge=U(L,pt,ee==fe),L=0,++ee}++L,++M}return Oe.join("")}function V(K){return W(K,function(M){return w.test(M)?q(M.slice(4).toLowerCase()):M})}function te(K){return W(K,function(M){return E.test(M)?"xn--"+se(M):M})}if(o={version:"1.4.1",ucs2:{decode:J,encode:z},decode:q,encode:se,toASCII:te,toUnicode:V},r&&s)if(t.exports==r)s.exports=o;else for(O in o)o.hasOwnProperty(O)&&(r[O]=o[O]);else n.punycode=o})(Rz)})(sl,sl.exports)),sl.exports}var Iz=Oz();const Lz=jl(Iz);var lT=Mt(/(?:(?:[\-a-z0-9#{latinAccentChars}]+)\.)+(?:#{validGTLD}|#{validCCTLD}|#{validPunycode})/gi,{latinAccentChars:lf,validGTLD:tT,validCCTLD:Q2,validPunycode:nT}),Dz=63,Pz="xn--",Bz={toAscii:function(e){if(!(e.substring(0,4)===Pz&&!e.match(lT))){for(var n=e.split("."),r=0;r<n.length;r++){var s=n[r],i=Lz.toASCII(s);if(i.length<1||i.length>Dz)return}return n.join(".")}}},$z=Mt(/^https?:\/\/t\.co\/([a-z0-9]+)(?:\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?/,{validUrlQueryChars:oT,validUrlQueryEndingChars:aT},"i"),zz="https://",Fz={extractUrlsWithoutProtocol:!0},Uz=4096,Hz=40,Wz=function(e){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Fz;if(!e||(n.extractUrlsWithoutProtocol?!e.match(/\./):!e.match(/:/)))return[];for(var r=[],s=function(){var l=RegExp.$2,d=RegExp.$3,f=RegExp.$4,h=RegExp.$5,m=RegExp.$7,g=H1.lastIndex,v=g-d.length;if(!qz(d,f||zz,h))return"continue";if(f){if(d.match($z)){var w=RegExp.$1;if(w&&w.length>Hz)return"continue";d=RegExp.lastMatch,g=v+d.length}r.push({url:d,indices:[v,g]})}else{if(!n.extractUrlsWithoutProtocol||l.match(jz))return"continue";var b=null,k=0;if(h.replace(lT,function(E){var C=h.indexOf(E,k);k=C+E.length,b={url:E,indices:[v+C,v+k]},r.push(b)}),b==null)return"continue";m&&(b.url=d.replace(h,b.url),b.indices[1]=g)}};H1.exec(e);)var i=s();return r},qz=function(e,n,r){var s=e.length,i=Bz.toAscii(r);return!i||!i.length?!1:(s=s+i.length-r.length,n.length+s<=Uz)},G1={},J1;function Vz(){if(J1)return G1;J1=1;var t=vr(),e=sf(),n=ji(),r=rs(),s=[].sort,i=[1,2,3];return t(t.P+t.F*(r(function(){i.sort(void 0)})||!r(function(){i.sort(null)})||!$l()(s)),"Array",{sort:function(l){return l===void 0?s.call(n(this)):s.call(n(this),e(l))}}),G1}Vz();var cT=/\ud800[\udc00-\udc0b\udc0d-\udc26\udc28-\udc3a\udc3c\udc3d\udc3f-\udc4d\udc50-\udc5d\udc80-\udcfa\uddfd\ude80-\ude9c\udea0-\uded0\udee0\udf00-\udf1f\udf30-\udf40\udf42-\udf49\udf50-\udf7a\udf80-\udf9d\udfa0-\udfc3\udfc8-\udfcf]|\ud801[\udc00-\udc9d\udd00-\udd27\udd30-\udd63\ude00-\udf36\udf40-\udf55\udf60-\udf67]|\ud802[\udc00-\udc05\udc08\udc0a-\udc35\udc37\udc38\udc3c\udc3f-\udc55\udc60-\udc76\udc80-\udc9e\udd00-\udd15\udd20-\udd39\udd80-\uddb7\uddbe\uddbf\ude00-\ude03\ude05\ude06\ude0c-\ude13\ude15-\ude17\ude19-\ude33\ude38-\ude3a\ude3f\ude60-\ude7c\ude80-\ude9c\udec0-\udec7\udec9-\udee6\udf00-\udf35\udf40-\udf55\udf60-\udf72\udf80-\udf91]|\ud803[\udc00-\udc48]|\ud804[\udc00-\udc46\udc7f-\udcba\udcd0-\udce8\udd00-\udd34\udd50-\udd73\udd76\udd80-\uddc4\uddda\ude00-\ude11\ude13-\ude37\udeb0-\udeea\udf01-\udf03\udf05-\udf0c\udf0f\udf10\udf13-\udf28\udf2a-\udf30\udf32\udf33\udf35-\udf39\udf3c-\udf44\udf47\udf48\udf4b-\udf4d\udf57\udf5d-\udf63\udf66-\udf6c\udf70-\udf74]|\ud805[\udc80-\udcc5\udcc7\udd80-\uddb5\uddb8-\uddc0\ude00-\ude40\ude44\ude80-\udeb7]|\ud806[\udca0-\udcdf\udcff\udec0-\udef8]|\ud808[\udc00-\udf98]|\ud80c[\udc00-\udfff]|\ud80d[\udc00-\udc2e]|\ud81a[\udc00-\ude38\ude40-\ude5e\uded0-\udeed\udef0-\udef4\udf00-\udf36\udf40-\udf43\udf63-\udf77\udf7d-\udf8f]|\ud81b[\udf00-\udf44\udf50-\udf7e\udf8f-\udf9f]|\ud82c[\udc00\udc01]|\ud82f[\udc00-\udc6a\udc70-\udc7c\udc80-\udc88\udc90-\udc99\udc9d\udc9e]|\ud834[\udd65-\udd69\udd6d-\udd72\udd7b-\udd82\udd85-\udd8b\uddaa-\uddad\ude42-\ude44]|\ud835[\udc00-\udc54\udc56-\udc9c\udc9e\udc9f\udca2\udca5\udca6\udca9-\udcac\udcae-\udcb9\udcbb\udcbd-\udcc3\udcc5-\udd05\udd07-\udd0a\udd0d-\udd14\udd16-\udd1c\udd1e-\udd39\udd3b-\udd3e\udd40-\udd44\udd46\udd4a-\udd50\udd52-\udea5\udea8-\udec0\udec2-\udeda\udedc-\udefa\udefc-\udf14\udf16-\udf34\udf36-\udf4e\udf50-\udf6e\udf70-\udf88\udf8a-\udfa8\udfaa-\udfc2\udfc4-\udfcb]|\ud83a[\udc00-\udcc4\udcd0-\udcd6]|\ud83b[\ude00-\ude03\ude05-\ude1f\ude21\ude22\ude24\ude27\ude29-\ude32\ude34-\ude37\ude39\ude3b\ude42\ude47\ude49\ude4b\ude4d-\ude4f\ude51\ude52\ude54\ude57\ude59\ude5b\ude5d\ude5f\ude61\ude62\ude64\ude67-\ude6a\ude6c-\ude72\ude74-\ude77\ude79-\ude7c\ude7e\ude80-\ude89\ude8b-\ude9b\udea1-\udea3\udea5-\udea9\udeab-\udebb]|\ud840[\udc00-\udfff]|\ud841[\udc00-\udfff]|\ud842[\udc00-\udfff]|\ud843[\udc00-\udfff]|\ud844[\udc00-\udfff]|\ud845[\udc00-\udfff]|\ud846[\udc00-\udfff]|\ud847[\udc00-\udfff]|\ud848[\udc00-\udfff]|\ud849[\udc00-\udfff]|\ud84a[\udc00-\udfff]|\ud84b[\udc00-\udfff]|\ud84c[\udc00-\udfff]|\ud84d[\udc00-\udfff]|\ud84e[\udc00-\udfff]|\ud84f[\udc00-\udfff]|\ud850[\udc00-\udfff]|\ud851[\udc00-\udfff]|\ud852[\udc00-\udfff]|\ud853[\udc00-\udfff]|\ud854[\udc00-\udfff]|\ud855[\udc00-\udfff]|\ud856[\udc00-\udfff]|\ud857[\udc00-\udfff]|\ud858[\udc00-\udfff]|\ud859[\udc00-\udfff]|\ud85a[\udc00-\udfff]|\ud85b[\udc00-\udfff]|\ud85c[\udc00-\udfff]|\ud85d[\udc00-\udfff]|\ud85e[\udc00-\udfff]|\ud85f[\udc00-\udfff]|\ud860[\udc00-\udfff]|\ud861[\udc00-\udfff]|\ud862[\udc00-\udfff]|\ud863[\udc00-\udfff]|\ud864[\udc00-\udfff]|\ud865[\udc00-\udfff]|\ud866[\udc00-\udfff]|\ud867[\udc00-\udfff]|\ud868[\udc00-\udfff]|\ud869[\udc00-\uded6\udf00-\udfff]|\ud86a[\udc00-\udfff]|\ud86b[\udc00-\udfff]|\ud86c[\udc00-\udfff]|\ud86d[\udc00-\udf34\udf40-\udfff]|\ud86e[\udc00-\udc1d]|\ud87e[\udc00-\ude1d]|\udb40[\udd00-\uddef]/,uT=/A-Za-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0300-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u0483-\u052f\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u05d0-\u05ea\u05f0-\u05f2\u0610-\u061a\u0620-\u065f\u066e-\u06d3\u06d5-\u06dc\u06df-\u06e8\u06ea-\u06ef\u06fa-\u06fc\u06ff\u0710-\u074a\u074d-\u07b1\u07ca-\u07f5\u07fa\u0800-\u082d\u0840-\u085b\u08a0-\u08b2\u08e4-\u0963\u0971-\u0983\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bc-\u09c4\u09c7\u09c8\u09cb-\u09ce\u09d7\u09dc\u09dd\u09df-\u09e3\u09f0\u09f1\u0a01-\u0a03\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a59-\u0a5c\u0a5e\u0a70-\u0a75\u0a81-\u0a83\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abc-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ad0\u0ae0-\u0ae3\u0b01-\u0b03\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3c-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5c\u0b5d\u0b5f-\u0b63\u0b71\u0b82\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd0\u0bd7\u0c00-\u0c03\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c58\u0c59\u0c60-\u0c63\u0c81-\u0c83\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbc-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0cde\u0ce0-\u0ce3\u0cf1\u0cf2\u0d01-\u0d03\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d-\u0d44\u0d46-\u0d48\u0d4a-\u0d4e\u0d57\u0d60-\u0d63\u0d7a-\u0d7f\u0d82\u0d83\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e01-\u0e3a\u0e40-\u0e4e\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb9\u0ebb-\u0ebd\u0ec0-\u0ec4\u0ec6\u0ec8-\u0ecd\u0edc-\u0edf\u0f00\u0f18\u0f19\u0f35\u0f37\u0f39\u0f3e-\u0f47\u0f49-\u0f6c\u0f71-\u0f84\u0f86-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u103f\u1050-\u108f\u109a-\u109d\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u135d-\u135f\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16f1-\u16f8\u1700-\u170c\u170e-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176c\u176e-\u1770\u1772\u1773\u1780-\u17d3\u17d7\u17dc\u17dd\u180b-\u180d\u1820-\u1877\u1880-\u18aa\u18b0-\u18f5\u1900-\u191e\u1920-\u192b\u1930-\u193b\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a1b\u1a20-\u1a5e\u1a60-\u1a7c\u1a7f\u1aa7\u1ab0-\u1abe\u1b00-\u1b4b\u1b6b-\u1b73\u1b80-\u1baf\u1bba-\u1bf3\u1c00-\u1c37\u1c4d-\u1c4f\u1c5a-\u1c7d\u1cd0-\u1cd2\u1cd4-\u1cf6\u1cf8\u1cf9\u1d00-\u1df5\u1dfc-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u20d0-\u20f0\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2183\u2184\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d7f-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2de0-\u2dff\u2e2f\u3005\u3006\u302a-\u302f\u3031-\u3035\u303b\u303c\u3041-\u3096\u3099\u309a\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua672\ua674-\ua67d\ua67f-\ua69d\ua69f-\ua6e5\ua6f0\ua6f1\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua7ad\ua7b0\ua7b1\ua7f7-\ua827\ua840-\ua873\ua880-\ua8c4\ua8e0-\ua8f7\ua8fb\ua90a-\ua92d\ua930-\ua953\ua960-\ua97c\ua980-\ua9c0\ua9cf\ua9e0-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa36\uaa40-\uaa4d\uaa60-\uaa76\uaa7a-\uaac2\uaadb-\uaadd\uaae0-\uaaef\uaaf2-\uaaf6\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab5f\uab64\uab65\uabc0-\uabea\uabec\uabed\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf870-\uf87f\uf882\uf884-\uf89f\uf8b8\uf8c1-\uf8d6\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe00-\ufe0f\ufe20-\ufe2d\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc/,dT=/[\uD800-\uDBFF][\uDC00-\uDFFF]/gm,Kz=Mt(/(?:[#{bmpLetterAndMarks}]|(?=#{nonBmpCodePairs})(?:#{astralLetterAndMarks}))/,{bmpLetterAndMarks:uT,nonBmpCodePairs:dT,astralLetterAndMarks:cT}),Gz=/\ud801[\udca0-\udca9]|\ud804[\udc66-\udc6f\udcf0-\udcf9\udd36-\udd3f\uddd0-\uddd9\udef0-\udef9]|\ud805[\udcd0-\udcd9\ude50-\ude59\udec0-\udec9]|\ud806[\udce0-\udce9]|\ud81a[\ude60-\ude69\udf50-\udf59]|\ud835[\udfce-\udfff]/,Jz=/0-9\u0660-\u0669\u06f0-\u06f9\u07c0-\u07c9\u0966-\u096f\u09e6-\u09ef\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be6-\u0bef\u0c66-\u0c6f\u0ce6-\u0cef\u0d66-\u0d6f\u0de6-\u0def\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29\u1040-\u1049\u1090-\u1099\u17e0-\u17e9\u1810-\u1819\u1946-\u194f\u19d0-\u19d9\u1a80-\u1a89\u1a90-\u1a99\u1b50-\u1b59\u1bb0-\u1bb9\u1c40-\u1c49\u1c50-\u1c59\ua620-\ua629\ua8d0-\ua8d9\ua900-\ua909\ua9d0-\ua9d9\ua9f0-\ua9f9\uaa50-\uaa59\uabf0-\uabf9\uff10-\uff19/,Yz=/_\u200c\u200d\ua67e\u05be\u05f3\u05f4\uff5e\u301c\u309b\u309c\u30a0\u30fb\u3003\u0f0b\u0f0c\xb7/,fT=Mt(/(?:[#{bmpLetterAndMarks}#{bmpNumerals}#{hashtagSpecialChars}]|(?=#{nonBmpCodePairs})(?:#{astralLetterAndMarks}|#{astralNumerals}))/,{bmpLetterAndMarks:uT,bmpNumerals:Jz,hashtagSpecialChars:Yz,nonBmpCodePairs:dT,astralLetterAndMarks:cT,astralNumerals:Gz}),Xz=/(?:[^\uD800-\uDFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF])/,Qz=Mt(/(?:^|\uFE0E|\uFE0F|$|(?!#{hashtagAlphaNumeric}|&)#{codePoint})/,{codePoint:Xz,hashtagAlphaNumeric:fT});Mt(/(#{hashtagBoundary})(#{hashSigns})(?!\uFE0F|\u20E3)(#{hashtagAlphaNumeric}*#{hashtagAlpha}#{hashtagAlphaNumeric}*)/gi,{hashtagBoundary:Qz,hashSigns:X2,hashtagAlphaNumeric:fT,hashtagAlpha:Kz});var xy=/[@@]/;Mt(/^(?:#{atSigns}|[#{latinAccentChars}]|:\/\/)/,{atSigns:xy,latinAccentChars:lf});var Zz=/(?:^|[^a-zA-Z0-9_!#$%&*@@]|(?:^|[^a-zA-Z0-9_+~.-])(?:rt|RT|rT|Rt):?)/,eF=Mt("(#{validMentionPrecedingChars})(#{atSigns})([a-zA-Z0-9_]{1,20})(/[a-zA-Z][a-zA-Z0-9_-]{0,24})?",{validMentionPrecedingChars:Zz,atSigns:xy},"g"),Y1={},X1={},Q1;function tF(){return Q1||(Q1=1,Hr()&&/./g.flags!="g"&&ss().f(RegExp.prototype,"flags",{configurable:!0,get:rf()})),X1}var Z1;function nF(){if(Z1)return Y1;Z1=1,tF();var t=Cr(),e=rf(),n=Hr(),r="toString",s=/./[r],i=function(o){zs()(RegExp.prototype,r,o,!0)};return rs()(function(){return s.call({source:"a",flags:"b"})!="/a/b"})?i(function(){var l=t(this);return"/".concat(l.source,"/","flags"in l?l.flags:!n&&l instanceof RegExp?e.call(l):void 0)}):s.name!=r&&i(function(){return s.call(this)}),Y1}nF();var eS={},tS;function rF(){if(tS)return eS;tS=1;var t=Date.prototype,e="Invalid Date",n="toString",r=t[n],s=t.getTime;return new Date(NaN)+""!=e&&zs()(t,n,function(){var o=s.call(this);return o===o?r.call(this):e}),eS}rF();var nS={},rS;function sF(){if(rS)return nS;rS=1;var t=cy(),e={};return e[Dn()("toStringTag")]="z",e+""!="[object z]"&&zs()(Object.prototype,"toString",function(){return"[object "+t(this)+"]"},!0),nS}sF();const sS={defaults:{version:3,maxWeightedTweetLength:280,scale:100,defaultWeight:200,emojiParsingEnabled:!0,transformedURLLength:23,ranges:[{start:0,end:4351,weight:100},{start:8192,end:8205,weight:100},{start:8208,end:8223,weight:100},{start:8242,end:8247,weight:100}]}};Mt(/^(?:#{spaces})*#{atSigns}([a-zA-Z0-9_]{1,20})/,{atSigns:xy,spaces:Y2});var iS={},Im,oS;function wy(){if(oS)return Im;oS=1;var t=ef();return Im=Array.isArray||function(n){return t(n)=="Array"},Im}var aS;function iF(){if(aS)return iS;aS=1;var t=vr();return t(t.S,"Array",{isArray:wy()}),iS}iF();var oF=function(e,n){var r=n.defaultWeight,s=n.ranges,i=r,o=e.charCodeAt(0);if(Array.isArray(s))for(var l=0,d=s.length;l<d;l++){var f=s[l];if(o>=f.start&&o<=f.end){i=f.weight;break}}return i},lS={},Lm,cS;function aF(){if(cS)return Lm;cS=1;var t=sf(),e=ji(),n=py(),r=mo();return Lm=function(s,i,o,l,d){t(i);var f=e(s),h=n(f),m=r(f.length),g=d?m-1:0,v=d?-1:1;if(o<2)for(;;){if(g in h){l=h[g],g+=v;break}if(g+=v,d?g<0:m<=g)throw TypeError("Reduce of empty array with no initial value")}for(;d?g>=0:m>g;g+=v)g in h&&(l=i(l,h[g],g,f));return l},Lm}var uS;function lF(){if(uS)return lS;uS=1;var t=vr(),e=aF();return t(t.P+t.F*!$l()([].reduce,!0),"Array",{reduce:function(r){return e(this,r,arguments.length,arguments[1],!1)}}),lS}lF();var dS={},Dm,fS;function cF(){if(fS)return Dm;fS=1;var t=Dn()("unscopables"),e=Array.prototype;return e[t]==null&&Mi()(e,t,{}),Dm=function(n){e[t][n]=!0},Dm}var Pm,hS;function uF(){return hS||(hS=1,Pm=function(t,e){return{value:e,done:!!t}}),Pm}var Bm,pS;function zl(){return pS||(pS=1,Bm={}),Bm}var $m,mS;function Fl(){if(mS)return $m;mS=1;var t=K2(),e=yy();return $m=Object.keys||function(r){return t(r,e)},$m}var zm,gS;function hT(){if(gS)return zm;gS=1;var t=ss(),e=Cr(),n=Fl();return zm=Hr()?Object.defineProperties:function(s,i){e(s);for(var o=n(i),l=o.length,d=0,f;l>d;)t.f(s,f=o[d++],i[f]);return s},zm}var Fm,vS;function dF(){if(vS)return Fm;vS=1;var t=Ur().document;return Fm=t&&t.documentElement,Fm}var Um,yS;function pT(){if(yS)return Um;yS=1;var t=Cr(),e=hT(),n=yy(),r=vy()("IE_PROTO"),s=function(){},i="prototype",o=function(){var l=H2()("iframe"),d=n.length,f="<",h=">",m;for(l.style.display="none",dF().appendChild(l),l.src="javascript:",m=l.contentWindow.document,m.open(),m.write(f+"script"+h+"document.F=Object"+f+"/script"+h),m.close(),o=m.F;d--;)delete o[i][n[d]];return o()};return Um=Object.create||function(d,f){var h;return d!==null?(s[i]=t(d),h=new s,s[i]=null,h[r]=d):h=o(),f===void 0?h:e(h,f)},Um}var Hm,bS;function ky(){if(bS)return Hm;bS=1;var t=ss().f,e=go(),n=Dn()("toStringTag");return Hm=function(r,s,i){r&&!e(r=i?r:r.prototype,n)&&t(r,n,{configurable:!0,value:s})},Hm}var Wm,xS;function fF(){if(xS)return Wm;xS=1;var t=pT(),e=Bl(),n=ky(),r={};return Mi()(r,Dn()("iterator"),function(){return this}),Wm=function(s,i,o){s.prototype=t(r,{next:e(1,o)}),n(s,i+" Iterator")},Wm}var qm,wS;function hF(){if(wS)return qm;wS=1;var t=go(),e=ji(),n=vy()("IE_PROTO"),r=Object.prototype;return qm=Object.getPrototypeOf||function(s){return s=e(s),t(s,n)?s[n]:typeof s.constructor=="function"&&s instanceof s.constructor?s.constructor.prototype:s instanceof Object?r:null},qm}var Vm,kS;function mT(){if(kS)return Vm;kS=1;var t=tf(),e=vr(),n=zs(),r=Mi(),s=zl(),i=fF(),o=ky(),l=hF(),d=Dn()("iterator"),f=!([].keys&&"next"in[].keys()),h="@@iterator",m="keys",g="values",v=function(){return this};return Vm=function(b,k,w,E,C,T,j){i(w,k,E);var _=function(se){if(!f&&se in $)return $[se];switch(se){case m:return function(){return new w(this,se)};case g:return function(){return new w(this,se)}}return function(){return new w(this,se)}},A=k+" Iterator",O=C==g,B=!1,$=b.prototype,W=$[d]||$[h]||C&&$[C],J=W||_(C),z=C?O?_("entries"):J:void 0,G=k=="Array"&&$.entries||W,D,U,q;if(G&&(q=l(G.call(new b)),q!==Object.prototype&&q.next&&(o(q,A,!0),!t&&typeof q[d]!="function"&&r(q,d,v))),O&&W&&W.name!==g&&(B=!0,J=function(){return W.call(this)}),(!t||j)&&(f||B||!$[d])&&r($,d,J),s[k]=J,s[A]=v,C)if(D={values:O?J:_(g),keys:T?J:_(m),entries:z},j)for(U in D)U in $||n($,U,D[U]);else e(e.P+e.F*(f||B),k,D);return D},Vm}var Km,SS;function gT(){if(SS)return Km;SS=1;var t=cF(),e=uF(),n=zl(),r=vo();return Km=mT()(Array,"Array",function(s,i){this._t=r(s),this._i=0,this._k=i},function(){var s=this._t,i=this._k,o=this._i++;return!s||o>=s.length?(this._t=void 0,e(1)):i=="keys"?e(0,o):i=="values"?e(0,s[o]):e(0,[o,s[o]])},"values"),n.Arguments=n.Array,t("keys"),t("values"),t("entries"),Km}var ES;function pF(){if(ES)return dS;ES=1;for(var t=gT(),e=Fl(),n=zs(),r=Ur(),s=Mi(),i=zl(),o=Dn(),l=o("iterator"),d=o("toStringTag"),f=i.Array,h={CSSRuleList:!0,CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},m=e(h),g=0;g<m.length;g++){var v=m[g],b=h[v],k=r[v],w=k&&k.prototype,E;if(w&&(w[l]||s(w,l,f),w[d]||s(w,d,v),i[v]=f,b))for(E in t)w[E]||n(w,E,t[E],!0)}return dS}pF();gT();var NS={},Gm,CS;function mF(){if(CS)return Gm;CS=1;var t=vr(),e=fa(),n=rs();return Gm=function(r,s){var i=(e.Object||{})[r]||Object[r],o={};o[r]=s(i),t(t.S+t.F*n(function(){i(1)}),"Object",o)},Gm}var _S;function gF(){if(_S)return NS;_S=1;var t=ji(),e=Fl();return mF()("keys",function(){return function(r){return e(t(r))}}),NS}gF();var vF=Mt(/[#{invalidCharsGroup}]/,{invalidCharsGroup:by});function yF(t){return vF.test(t)}var Gi={},bu={},TS;function bF(){return TS||(TS=1,Object.defineProperty(bu,"__esModule",{value:!0}),bu.default=/(?:\ud83d[\udc68\udc69])(?:\ud83c[\udffb-\udfff])?\u200d(?:\u2695\ufe0f|\u2696\ufe0f|\u2708\ufe0f|\ud83c[\udf3e\udf73\udf93\udfa4\udfa8\udfeb\udfed]|\ud83d[\udcbb\udcbc\udd27\udd2c\ude80\ude92]|\ud83e[\uddb0-\uddb3])|(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75]|\u26f9)((?:\ud83c[\udffb-\udfff]|\ufe0f)\u200d[\u2640\u2642]\ufe0f)|(?:\ud83c[\udfc3\udfc4\udfca]|\ud83d[\udc6e\udc71\udc73\udc77\udc81\udc82\udc86\udc87\ude45-\ude47\ude4b\ude4d\ude4e\udea3\udeb4-\udeb6]|\ud83e[\udd26\udd35\udd37-\udd39\udd3d\udd3e\uddb8\uddb9\uddd6-\udddd])(?:\ud83c[\udffb-\udfff])?\u200d[\u2640\u2642]\ufe0f|(?:\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83c\udff3\ufe0f\u200d\ud83c\udf08|\ud83c\udff4\u200d\u2620\ufe0f|\ud83d\udc41\u200d\ud83d\udde8|\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc6f\u200d\u2640\ufe0f|\ud83d\udc6f\u200d\u2642\ufe0f|\ud83e\udd3c\u200d\u2640\ufe0f|\ud83e\udd3c\u200d\u2642\ufe0f|\ud83e\uddde\u200d\u2640\ufe0f|\ud83e\uddde\u200d\u2642\ufe0f|\ud83e\udddf\u200d\u2640\ufe0f|\ud83e\udddf\u200d\u2642\ufe0f)|[#*0-9]\ufe0f?\u20e3|(?:[©®\u2122\u265f]\ufe0f)|(?:\ud83c[\udc04\udd70\udd71\udd7e\udd7f\ude02\ude1a\ude2f\ude37\udf21\udf24-\udf2c\udf36\udf7d\udf96\udf97\udf99-\udf9b\udf9e\udf9f\udfcd\udfce\udfd4-\udfdf\udff3\udff5\udff7]|\ud83d[\udc3f\udc41\udcfd\udd49\udd4a\udd6f\udd70\udd73\udd76-\udd79\udd87\udd8a-\udd8d\udda5\udda8\uddb1\uddb2\uddbc\uddc2-\uddc4\uddd1-\uddd3\udddc-\uddde\udde1\udde3\udde8\uddef\uddf3\uddfa\udecb\udecd-\udecf\udee0-\udee5\udee9\udef0\udef3]|[\u203c\u2049\u2139\u2194-\u2199\u21a9\u21aa\u231a\u231b\u2328\u23cf\u23ed-\u23ef\u23f1\u23f2\u23f8-\u23fa\u24c2\u25aa\u25ab\u25b6\u25c0\u25fb-\u25fe\u2600-\u2604\u260e\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262a\u262e\u262f\u2638-\u263a\u2640\u2642\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267b\u267f\u2692-\u2697\u2699\u269b\u269c\u26a0\u26a1\u26aa\u26ab\u26b0\u26b1\u26bd\u26be\u26c4\u26c5\u26c8\u26cf\u26d1\u26d3\u26d4\u26e9\u26ea\u26f0-\u26f5\u26f8\u26fa\u26fd\u2702\u2708\u2709\u270f\u2712\u2714\u2716\u271d\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u2764\u27a1\u2934\u2935\u2b05-\u2b07\u2b1b\u2b1c\u2b50\u2b55\u3030\u303d\u3297\u3299])(?:\ufe0f|(?!\ufe0e))|(?:(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75\udd90]|[\u261d\u26f7\u26f9\u270c\u270d])(?:\ufe0f|(?!\ufe0e))|(?:\ud83c[\udf85\udfc2-\udfc4\udfc7\udfca]|\ud83d[\udc42\udc43\udc46-\udc50\udc66-\udc69\udc6e\udc70-\udc78\udc7c\udc81-\udc83\udc85-\udc87\udcaa\udd7a\udd95\udd96\ude45-\ude47\ude4b-\ude4f\udea3\udeb4-\udeb6\udec0\udecc]|\ud83e[\udd18-\udd1c\udd1e\udd1f\udd26\udd30-\udd39\udd3d\udd3e\uddb5\uddb6\uddb8\uddb9\uddd1-\udddd]|[\u270a\u270b]))(?:\ud83c[\udffb-\udfff])?|(?:\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc65\udb40\udc6e\udb40\udc67\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc73\udb40\udc63\udb40\udc74\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc77\udb40\udc6c\udb40\udc73\udb40\udc7f|\ud83c\udde6\ud83c[\udde8-\uddec\uddee\uddf1\uddf2\uddf4\uddf6-\uddfa\uddfc\uddfd\uddff]|\ud83c\udde7\ud83c[\udde6\udde7\udde9-\uddef\uddf1-\uddf4\uddf6-\uddf9\uddfb\uddfc\uddfe\uddff]|\ud83c\udde8\ud83c[\udde6\udde8\udde9\uddeb-\uddee\uddf0-\uddf5\uddf7\uddfa-\uddff]|\ud83c\udde9\ud83c[\uddea\uddec\uddef\uddf0\uddf2\uddf4\uddff]|\ud83c\uddea\ud83c[\udde6\udde8\uddea\uddec\udded\uddf7-\uddfa]|\ud83c\uddeb\ud83c[\uddee-\uddf0\uddf2\uddf4\uddf7]|\ud83c\uddec\ud83c[\udde6\udde7\udde9-\uddee\uddf1-\uddf3\uddf5-\uddfa\uddfc\uddfe]|\ud83c\udded\ud83c[\uddf0\uddf2\uddf3\uddf7\uddf9\uddfa]|\ud83c\uddee\ud83c[\udde8-\uddea\uddf1-\uddf4\uddf6-\uddf9]|\ud83c\uddef\ud83c[\uddea\uddf2\uddf4\uddf5]|\ud83c\uddf0\ud83c[\uddea\uddec-\uddee\uddf2\uddf3\uddf5\uddf7\uddfc\uddfe\uddff]|\ud83c\uddf1\ud83c[\udde6-\udde8\uddee\uddf0\uddf7-\uddfb\uddfe]|\ud83c\uddf2\ud83c[\udde6\udde8-\udded\uddf0-\uddff]|\ud83c\uddf3\ud83c[\udde6\udde8\uddea-\uddec\uddee\uddf1\uddf4\uddf5\uddf7\uddfa\uddff]|\ud83c\uddf4\ud83c\uddf2|\ud83c\uddf5\ud83c[\udde6\uddea-\udded\uddf0-\uddf3\uddf7-\uddf9\uddfc\uddfe]|\ud83c\uddf6\ud83c\udde6|\ud83c\uddf7\ud83c[\uddea\uddf4\uddf8\uddfa\uddfc]|\ud83c\uddf8\ud83c[\udde6-\uddea\uddec-\uddf4\uddf7-\uddf9\uddfb\uddfd-\uddff]|\ud83c\uddf9\ud83c[\udde6\udde8\udde9\uddeb-\udded\uddef-\uddf4\uddf7\uddf9\uddfb\uddfc\uddff]|\ud83c\uddfa\ud83c[\udde6\uddec\uddf2\uddf3\uddf8\uddfe\uddff]|\ud83c\uddfb\ud83c[\udde6\udde8\uddea\uddec\uddee\uddf3\uddfa]|\ud83c\uddfc\ud83c[\uddeb\uddf8]|\ud83c\uddfd\ud83c\uddf0|\ud83c\uddfe\ud83c[\uddea\uddf9]|\ud83c\uddff\ud83c[\udde6\uddf2\uddfc]|\ud83c[\udccf\udd8e\udd91-\udd9a\udde6-\uddff\ude01\ude32-\ude36\ude38-\ude3a\ude50\ude51\udf00-\udf20\udf2d-\udf35\udf37-\udf7c\udf7e-\udf84\udf86-\udf93\udfa0-\udfc1\udfc5\udfc6\udfc8\udfc9\udfcf-\udfd3\udfe0-\udff0\udff4\udff8-\udfff]|\ud83d[\udc00-\udc3e\udc40\udc44\udc45\udc51-\udc65\udc6a-\udc6d\udc6f\udc79-\udc7b\udc7d-\udc80\udc84\udc88-\udca9\udcab-\udcfc\udcff-\udd3d\udd4b-\udd4e\udd50-\udd67\udda4\uddfb-\ude44\ude48-\ude4a\ude80-\udea2\udea4-\udeb3\udeb7-\udebf\udec1-\udec5\uded0-\uded2\udeeb\udeec\udef4-\udef9]|\ud83e[\udd10-\udd17\udd1d\udd20-\udd25\udd27-\udd2f\udd3a\udd3c\udd40-\udd45\udd47-\udd70\udd73-\udd76\udd7a\udd7c-\udda2\uddb4\uddb7\uddc0-\uddc2\uddd0\uddde-\uddff]|[\u23e9-\u23ec\u23f0\u23f3\u267e\u26ce\u2705\u2728\u274c\u274e\u2753-\u2755\u2795-\u2797\u27b0\u27bf\ue50a])|\ufe0f/g),bu}var jS;function xF(){if(jS)return Gi;jS=1,Object.defineProperty(Gi,"__esModule",{value:!0}),Gi.TypeName=void 0,Gi.parse=s,Gi.toCodePoints=d;var t=bF(),e=n(t);function n(f){return f&&f.__esModule?f:{default:f}}var r=Gi.TypeName="emoji";function s(f,h){var m=h&&h.assetType?h.assetType:"svg",g=h&&h.buildUrl?h.buildUrl:function(E,C){return C==="png"?"https://twemoji.maxcdn.com/2/72x72/"+E+".png":"https://twemoji.maxcdn.com/2/svg/"+E+".svg"},v=[];for(e.default.lastIndex=0;;){var b=e.default.exec(f);if(!b)break;var k=b[0],w=d(l(k)).join("-");v.push({url:w?g(w,m):"",indices:[b.index,e.default.lastIndex],text:k,type:r})}return v}var i=/\uFE0F/g,o="‍",l=function(h){return h.indexOf(o)<0?h.replace(i,""):h};function d(f){for(var h=[],m=0,g=0,v=0;v<f.length;)m=f.charCodeAt(v++),g?(h.push((65536+(g-55296<<10)+(m-56320)).toString(16)),g=0):m>55296&&m<=56319?g=m:h.push(m.toString(16));return h}return Gi}var wF=xF(),kF=function(){for(var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:sS.defaults,r=Object.keys(n).length?n:sS.defaults,s=r.defaultWeight,i=r.emojiParsingEnabled,o=r.scale,l=r.maxWeightedTweetLength,d=r.transformedURLLength,f=typeof String.prototype.normalize=="function"?e.normalize():e,h=MS(Wz(f)),m=i?MS(wF.parse(f)):[],g=f.length,v=0,b=0,k=!0,w=0;w<g;w++){if(h[w]){var E=h[w],C=E.url;E.indices,v+=d*o,w+=C.length-1}else if(i&&m[w]){var T=m[w],j=T.text;T.indices,v+=s,w+=j.length-1}else w+=SF(f,w)?1:0,v+=oF(f.charAt(w),r);k&&(k=!yF(f.substring(w,w+1))),k&&v<=l*o&&(b=w)}v=v/o,k=k&&v>0&&v<=l;var _=Math.floor(v/l*1e3),A=e.length-f.length;return b+=A,{weightedLength:v,valid:k,permillage:_,validRangeStart:0,validRangeEnd:b,displayRangeStart:0,displayRangeEnd:e.length>0?e.length-1:0}},MS=function(e){return e.reduce(function(n,r){return n[r.indices[0]]=r,n},{})},SF=function(e,n){if(n<e.length-1){var r=e.charCodeAt(n),s=e.charCodeAt(n+1);return 55296<=r&&r<=56319&&56320<=s&&s<=57343}return!1},AS={},RS;function EF(){if(RS)return AS;RS=1;var t=vr();return t(t.S+t.F*!Hr(),"Object",{defineProperty:ss().f}),AS}EF();var OS={},IS;function NF(){if(IS)return OS;IS=1;var t=vr();return t(t.S+t.F*!Hr(),"Object",{defineProperties:hT()}),OS}NF();var LS={},Jm={},DS;function Sy(){return DS||(DS=1,Jm.f=Object.getOwnPropertySymbols),Jm}var Ym,PS;function CF(){if(PS)return Ym;PS=1;var t=af(),e=Sy(),n=Cr(),r=Ur().Reflect;return Ym=r&&r.ownKeys||function(i){var o=t.f(n(i)),l=e.f;return l?o.concat(l(i)):o},Ym}var Xm,BS;function vT(){if(BS)return Xm;BS=1;var t=ss(),e=Bl();return Xm=function(n,r,s){r in n?t.f(n,r,e(0,s)):n[r]=s},Xm}var $S;function _F(){if($S)return LS;$S=1;var t=vr(),e=CF(),n=vo(),r=gy(),s=vT();return t(t.S,"Object",{getOwnPropertyDescriptors:function(o){for(var l=n(o),d=r.f,f=e(l),h={},m=0,g,v;f.length>m;)v=d(l,g=f[m++]),v!==void 0&&s(h,g,v);return h}}),LS}_F();var zS={},Qm,FS;function TF(){if(FS)return Qm;FS=1;var t=$s(),e=wy(),n=Dn()("species");return Qm=function(r){var s;return e(r)&&(s=r.constructor,typeof s=="function"&&(s===Array||e(s.prototype))&&(s=void 0),t(s)&&(s=s[n],s===null&&(s=void 0))),s===void 0?Array:s},Qm}var Zm,US;function jF(){if(US)return Zm;US=1;var t=TF();return Zm=function(e,n){return new(t(e))(n)},Zm}var eg,HS;function yT(){if(HS)return eg;HS=1;var t=of(),e=py(),n=ji(),r=mo(),s=jF();return eg=function(i,o){var l=i==1,d=i==2,f=i==3,h=i==4,m=i==6,g=i==5||m,v=o||s;return function(b,k,w){for(var E=n(b),C=e(E),T=t(k,w,3),j=r(C.length),_=0,A=l?v(b,j):d?v(b,0):void 0,O,B;j>_;_++)if((g||_ in C)&&(O=C[_],B=T(O,_,E),i)){if(l)A[_]=B;else if(B)switch(i){case 3:return!0;case 5:return O;case 6:return _;case 2:A.push(O)}else if(h)return!1}return m?-1:f||h?h:A}},eg}var WS;function MF(){if(WS)return zS;WS=1;var t=vr(),e=yT()(0),n=$l()([].forEach,!0);return t(t.P+t.F*!n,"Array",{forEach:function(s){return e(this,s,arguments[1])}}),zS}MF();var qS={},VS;function AF(){if(VS)return qS;VS=1;var t=vr(),e=yT()(2);return t(t.P+t.F*!$l()([].filter,!0),"Array",{filter:function(r){return e(this,r,arguments[1])}}),qS}AF();var KS={},tg={exports:{}},GS;function RF(){if(GS)return tg.exports;GS=1;var t=Pl()("meta"),e=$s(),n=go(),r=ss().f,s=0,i=Object.isExtensible||function(){return!0},o=!rs()(function(){return i(Object.preventExtensions({}))}),l=function(g){r(g,t,{value:{i:"O"+ ++s,w:{}}})},d=function(g,v){if(!e(g))return typeof g=="symbol"?g:(typeof g=="string"?"S":"P")+g;if(!n(g,t)){if(!i(g))return"F";if(!v)return"E";l(g)}return g[t].i},f=function(g,v){if(!n(g,t)){if(!i(g))return!0;if(!v)return!1;l(g)}return g[t].w},h=function(g){return o&&m.NEED&&i(g)&&!n(g,t)&&l(g),g},m=tg.exports={KEY:t,NEED:!1,fastKey:d,getWeak:f,onFreeze:h};return tg.exports}var ng={},JS;function bT(){return JS||(JS=1,ng.f=Dn()),ng}var rg,YS;function OF(){if(YS)return rg;YS=1;var t=Ur(),e=fa(),n=tf(),r=bT(),s=ss().f;return rg=function(i){var o=e.Symbol||(e.Symbol=n?{}:t.Symbol||{});i.charAt(0)!="_"&&!(i in o)&&s(o,i,{value:r.f(i)})},rg}var sg,XS;function IF(){if(XS)return sg;XS=1;var t=Fl(),e=Sy(),n=my();return sg=function(r){var s=t(r),i=e.f;if(i)for(var o=i(r),l=n.f,d=0,f;o.length>d;)l.call(r,f=o[d++])&&s.push(f);return s},sg}var ig={},QS;function LF(){if(QS)return ig;QS=1;var t=vo(),e=af().f,n={}.toString,r=typeof window=="object"&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],s=function(i){try{return e(i)}catch{return r.slice()}};return ig.f=function(o){return r&&n.call(o)=="[object Window]"?s(o):e(t(o))},ig}var ZS;function DF(){if(ZS)return KS;ZS=1;var t=Ur(),e=go(),n=Hr(),r=vr(),s=zs(),i=RF().KEY,o=rs(),l=nf(),d=ky(),f=Pl(),h=Dn(),m=bT(),g=OF(),v=IF(),b=wy(),k=Cr(),w=$s(),E=ji(),C=vo(),T=fy(),j=Bl(),_=pT(),A=LF(),O=gy(),B=Sy(),$=ss(),W=Fl(),J=O.f,z=$.f,G=A.f,D=t.Symbol,U=t.JSON,q=U&&U.stringify,se="prototype",V=h("_hidden"),te=h("toPrimitive"),K={}.propertyIsEnumerable,M=l("symbol-registry"),L=l("symbols"),ee=l("op-symbols"),fe=Object[se],ge=typeof D=="function"&&!!B.f,oe=t.QObject,we=!oe||!oe[se]||!oe[se].findChild,xe=n&&o(function(){return _(z({},"a",{get:function(){return z(this,"a",{value:7}).a}})).a!=7})?function(ve,X,Be){var ne=J(fe,X);ne&&delete fe[X],z(ve,X,Be),ne&&ve!==fe&&z(fe,X,ne)}:z,We=function(ve){var X=L[ve]=_(D[se]);return X._k=ve,X},He=ge&&typeof D.iterator=="symbol"?function(ve){return typeof ve=="symbol"}:function(ve){return ve instanceof D},Ze=function(X,Be,ne){return X===fe&&Ze(ee,Be,ne),k(X),Be=T(Be,!0),k(ne),e(L,Be)?(ne.enumerable?(e(X,V)&&X[V][Be]&&(X[V][Be]=!1),ne=_(ne,{enumerable:j(0,!1)})):(e(X,V)||z(X,V,j(1,{})),X[V][Be]=!0),xe(X,Be,ne)):z(X,Be,ne)},Oe=function(X,Be){k(X);for(var ne=v(Be=C(Be)),de=0,he=ne.length,Ge;he>de;)Ze(X,Ge=ne[de++],Be[Ge]);return X},Ke=function(X,Be){return Be===void 0?_(X):Oe(_(X),Be)},pt=function(X){var Be=K.call(this,X=T(X,!0));return this===fe&&e(L,X)&&!e(ee,X)?!1:Be||!e(this,X)||!e(L,X)||e(this,V)&&this[V][X]?Be:!0},Je=function(X,Be){if(X=C(X),Be=T(Be,!0),!(X===fe&&e(L,Be)&&!e(ee,Be))){var ne=J(X,Be);return ne&&e(L,Be)&&!(e(X,V)&&X[V][Be])&&(ne.enumerable=!0),ne}},pe=function(X){for(var Be=G(C(X)),ne=[],de=0,he;Be.length>de;)!e(L,he=Be[de++])&&he!=V&&he!=i&&ne.push(he);return ne},mt=function(X){for(var Be=X===fe,ne=G(Be?ee:C(X)),de=[],he=0,Ge;ne.length>he;)e(L,Ge=ne[he++])&&(!Be||e(fe,Ge))&&de.push(L[Ge]);return de};ge||(D=function(){if(this instanceof D)throw TypeError("Symbol is not a constructor!");var X=f(arguments.length>0?arguments[0]:void 0),Be=function(ne){this===fe&&Be.call(ee,ne),e(this,V)&&e(this[V],X)&&(this[V][X]=!1),xe(this,X,j(1,ne))};return n&&we&&xe(fe,X,{configurable:!0,set:Be}),We(X)},s(D[se],"toString",function(){return this._k}),O.f=Je,$.f=Ze,af().f=A.f=pe,my().f=pt,B.f=mt,n&&!tf()&&s(fe,"propertyIsEnumerable",pt,!0),m.f=function(ve){return We(h(ve))}),r(r.G+r.W+r.F*!ge,{Symbol:D});for(var ft="hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),at=0;ft.length>at;)h(ft[at++]);for(var nt=W(h.store),ht=0;nt.length>ht;)g(nt[ht++]);r(r.S+r.F*!ge,"Symbol",{for:function(ve){return e(M,ve+="")?M[ve]:M[ve]=D(ve)},keyFor:function(X){if(!He(X))throw TypeError(X+" is not a symbol!");for(var Be in M)if(M[Be]===X)return Be},useSetter:function(){we=!0},useSimple:function(){we=!1}}),r(r.S+r.F*!ge,"Object",{create:Ke,defineProperty:Ze,defineProperties:Oe,getOwnPropertyDescriptor:Je,getOwnPropertyNames:pe,getOwnPropertySymbols:mt});var Fe=o(function(){B.f(1)});return r(r.S+r.F*Fe,"Object",{getOwnPropertySymbols:function(X){return B.f(E(X))}}),U&&r(r.S+r.F*(!ge||o(function(){var ve=D();return q([ve])!="[null]"||q({a:ve})!="{}"||q(Object(ve))!="{}"})),"JSON",{stringify:function(X){for(var Be=[X],ne=1,de,he;arguments.length>ne;)Be.push(arguments[ne++]);if(he=de=Be[1],!(!w(de)&&X===void 0||He(X)))return b(de)||(de=function(Ge,Pe){if(typeof he=="function"&&(Pe=he.call(this,Ge,Pe)),!He(Pe))return Pe}),Be[1]=de,q.apply(U,Be)}}),D[se][te]||Mi()(D[se],te,D[se].valueOf),d(D,"Symbol"),d(Math,"Math",!0),d(t.JSON,"JSON",!0),KS}DF();Mt(/^#{validMentionOrList}$/,{validMentionOrList:eF});var xT=/[a-z\u0400-\u04FF0-9\-._~]/i,wT=/(?:%[0-9a-f]{2})/i,kT=/[!$&'()*+,;=]/i,ST=Mt("(?:#{validateUrlUnreserved}|#{validateUrlPctEncoded}|#{validateUrlSubDelims}|:)*",{validateUrlUnreserved:xT,validateUrlPctEncoded:wT,validateUrlSubDelims:kT},"i"),PF=/(?:[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?)/i,BF=/(?:[a-z](?:[a-z0-9\-]*[a-z0-9])?)/i,$F=/(?:[a-z0-9](?:[a-z0-9_\-]*[a-z0-9])?)/i,zF=Mt(/(?:(?:#{validateUrlSubDomainSegment}\.)*(?:#{validateUrlDomainSegment}\.)#{validateUrlDomainTld})/i,{validateUrlSubDomainSegment:$F,validateUrlDomainSegment:PF,validateUrlDomainTld:BF}),FF=/(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9]{2})|(?:2[0-4][0-9])|(?:25[0-5]))/i,UF=Mt(/(?:#{validateUrlDecOctet}(?:\.#{validateUrlDecOctet}){3})/i,{validateUrlDecOctet:FF}),HF=/(?:\[[a-f0-9:\.]+\])/i,ET=Mt("(?:#{validateUrlIpv4}|#{validateUrlIpv6})",{validateUrlIpv4:UF,validateUrlIpv6:HF},"i"),WF=Mt("(?:#{validateUrlIp}|#{validateUrlDomain})",{validateUrlIp:ET,validateUrlDomain:zF},"i"),NT=/[0-9]{1,5}/;Mt("(?:(#{validateUrlUserinfo})@)?(#{validateUrlHost})(?::(#{validateUrlPort}))?",{validateUrlUserinfo:ST,validateUrlHost:WF,validateUrlPort:NT},"i");var Ey=Mt("(?:#{validateUrlUnreserved}|#{validateUrlPctEncoded}|#{validateUrlSubDelims}|[:|@])",{validateUrlUnreserved:xT,validateUrlPctEncoded:wT,validateUrlSubDelims:kT},"i");Mt(/(#{validateUrlPchar}|\/|\?)*/i,{validateUrlPchar:Ey});Mt(/(\/#{validateUrlPchar}*)*/i,{validateUrlPchar:Ey});Mt(/(#{validateUrlPchar}|\/|\?)*/i,{validateUrlPchar:Ey});Mt("^(?:([^:/?#]+):\\/\\/)?([^/?#]*)([^?#]*)(?:\\?([^#]*))?(?:#(.*))?$","i");var qF=/(?:(?:[a-z0-9]|[^\u0000-\u007f])(?:(?:[a-z0-9_\-]|[^\u0000-\u007f])*(?:[a-z0-9]|[^\u0000-\u007f]))?)/i,VF=/(?:(?:[a-z0-9]|[^\u0000-\u007f])(?:(?:[a-z0-9\-]|[^\u0000-\u007f])*(?:[a-z0-9]|[^\u0000-\u007f]))?)/i,KF=/(?:(?:[a-z]|[^\u0000-\u007f])(?:(?:[a-z0-9\-]|[^\u0000-\u007f])*(?:[a-z0-9]|[^\u0000-\u007f]))?)/i,GF=Mt(/(?:(?:#{validateUrlUnicodeSubDomainSegment}\.)*(?:#{validateUrlUnicodeDomainSegment}\.)#{validateUrlUnicodeDomainTld})/i,{validateUrlUnicodeSubDomainSegment:qF,validateUrlUnicodeDomainSegment:VF,validateUrlUnicodeDomainTld:KF}),JF=Mt("(?:#{validateUrlIp}|#{validateUrlUnicodeDomain})",{validateUrlIp:ET,validateUrlUnicodeDomain:GF},"i");Mt("(?:(#{validateUrlUserinfo})@)?(#{validateUrlUnicodeHost})(?::(#{validateUrlPort}))?",{validateUrlUserinfo:ST,validateUrlUnicodeHost:JF,validateUrlPort:NT},"i");var eE={},tE;function YF(){if(tE)return eE;tE=1;var t=U2()(!0);return mT()(String,"String",function(e){this._t=String(e),this._i=0},function(){var e=this._t,n=this._i,r;return n>=e.length?{value:void 0,done:!0}:(r=t(e,n),this._i+=r.length,{value:r,done:!1})}),eE}YF();var nE={},og,rE;function XF(){if(rE)return og;rE=1;var t=Cr();return og=function(e,n,r,s){try{return s?n(t(r)[0],r[1]):n(r)}catch(o){var i=e.return;throw i!==void 0&&t(i.call(e)),o}},og}var ag,sE;function QF(){if(sE)return ag;sE=1;var t=zl(),e=Dn()("iterator"),n=Array.prototype;return ag=function(r){return r!==void 0&&(t.Array===r||n[e]===r)},ag}var lg,iE;function ZF(){if(iE)return lg;iE=1;var t=cy(),e=Dn()("iterator"),n=zl();return lg=fa().getIteratorMethod=function(r){if(r!=null)return r[e]||r["@@iterator"]||n[t(r)]},lg}var cg,oE;function eU(){if(oE)return cg;oE=1;var t=Dn()("iterator"),e=!1;try{var n=[7][t]();n.return=function(){e=!0},Array.from(n,function(){throw 2})}catch{}return cg=function(r,s){if(!s&&!e)return!1;var i=!1;try{var o=[7],l=o[t]();l.next=function(){return{done:i=!0}},o[t]=function(){return l},r(o)}catch{}return i},cg}var aE;function tU(){if(aE)return nE;aE=1;var t=of(),e=vr(),n=ji(),r=XF(),s=QF(),i=mo(),o=vT(),l=ZF();return e(e.S+e.F*!eU()(function(d){Array.from(d)}),"Array",{from:function(f){var h=n(f),m=typeof this=="function"?this:Array,g=arguments.length,v=g>1?arguments[1]:void 0,b=v!==void 0,k=0,w=l(h),E,C,T,j;if(b&&(v=t(v,g>2?arguments[2]:void 0,2)),w!=null&&!(m==Array&&s(w)))for(j=w.call(h),C=new m;!(T=j.next()).done;k++)o(C,k,b?r(j,v,[T.value,k],!0):T.value);else for(E=i(h.length),C=new m(E);E>k;k++)o(C,k,b?v(h[k],k):h[k]);return C.length=k,C}}),nE}tU();const nU={parseTweet:kF},{parseTweet:rU}=nU;function lE(t){return rU(t).weightedLength}const cE="ow-x-handle";function sU(){const[t,e]=x.useState(()=>localStorage.getItem(cE)||""),[n,r]=x.useState(!1),[s,i]=x.useState(""),o=x.useRef(null),l=x.useRef(null),d=()=>{const m=s.replace(/^@/,"").trim();m&&(localStorage.setItem(cE,m),e(m)),r(!1)},f=()=>{i(t),r(!0),setTimeout(()=>{var m;return(m=o.current)==null?void 0:m.focus()},0)};x.useEffect(()=>{if(!n)return;const m=g=>{l.current&&!l.current.contains(g.target)&&d()};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[n,s]);const h=t?`https://unavatar.io/twitter/${t}`:"";return c.jsxs("div",{className:"tweet-compose-avatar-wrapper",ref:l,children:[t?c.jsx("img",{className:"tweet-compose-avatar tweet-compose-avatar-img",src:h,alt:`@${t}`,onClick:f,title:`@${t} — click to change`}):c.jsx("div",{className:"tweet-compose-avatar",onClick:f,title:"Set your @handle"}),n&&c.jsx("div",{className:"tweet-handle-popover",children:c.jsx("input",{ref:o,className:"tweet-handle-input",value:s,onChange:m=>i(m.target.value),onKeyDown:m=>{m.key==="Enter"&&d(),m.key==="Escape"&&r(!1)},placeholder:"your_handle",spellCheck:!1})})]})}const iU={tweet:!0,reply:!0,quote:!1};function uE(){return c.jsxs("div",{className:"tweet-skeleton",children:[c.jsxs("div",{className:"tweet-author-row",children:[c.jsx("div",{className:"tweet-avatar tweet-avatar-placeholder tweet-pulse"}),c.jsxs("div",{className:"tweet-author-info",children:[c.jsx("span",{className:"tweet-skeleton-line tweet-pulse",style:{width:120}}),c.jsx("span",{className:"tweet-skeleton-line tweet-pulse",style:{width:80}})]})]}),c.jsx("div",{className:"tweet-skeleton-line tweet-pulse",style:{width:"100%",height:16,marginTop:12}}),c.jsx("div",{className:"tweet-skeleton-line tweet-pulse",style:{width:"75%",height:16,marginTop:8}})]})}function oU(t){var e;if(t)return(e=t.match(/\/status\/(\d+)/))==null?void 0:e[1]}function xu(t){if(!t)return[null];if(typeof t=="string"){const e=t.split(/<hr\s*\/?>/i).map(n=>n.trim()).filter(Boolean);return e.length?e:[null]}if((t==null?void 0:t.type)==="doc"&&Array.isArray(t.content)){const e=[[]];for(const r of t.content)r.type==="horizontalRule"?e.push([]):e[e.length-1].push(r);const n=e.map(r=>r.length?{type:"doc",content:r}:null).filter(Boolean);return n.length?n:[null]}return[t]}function wu(t){var n;if(!t||typeof t=="string"||!t.content)return[];const e=[];for(let r=t.content.length-1;r>=0&&(t.content[r].type==="image"&&((n=t.content[r].attrs)!=null&&n.src));r--)e.unshift(t.content[r].attrs.src);return e}function dE(t,e){if(!t||typeof t=="string"||!t.content||e===0)return t;const n=t.content.slice(0,t.content.length-e);return n.length===0?{type:"doc",content:[{type:"paragraph",content:[]}]}:{...t,content:n}}function ku(t,e){const n=[];let r=0;return t.forEach((s,i)=>{if(!s)return;r>0&&n.push({type:"horizontalRule"});const o=s.getJSON();o.content&&n.push(...o.content);const l=e==null?void 0:e[i];if(l)for(const d of l){const f=crypto.randomUUID().replace(/-/g,"").slice(0,8);n.push({type:"image",attrs:{src:d,id:f}})}r++}),{type:"doc",content:n}}function fE(t,e){const n=[],r=s=>{var i;s.type==="image"&&((i=s.attrs)!=null&&i.src)&&n.push(s.attrs.src),s.content&&s.content.forEach(r)};return r(t.getJSON()),e&&n.push(...e),n.slice(0,4)}function Su(t){fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tweetContext:t}),keepalive:!0}).catch(()=>{})}function aU({tweetContext:t,initialContent:e,onUpdate:n,onEditorReady:r,onEditorsChange:s,onActiveEditorChange:i,filename:o,title:l,autoplug:d}){var Nt;const{tweet:f,loading:h,error:m}=J$(t==null?void 0:t.url),[g,v]=x.useState(()=>xu(e).map(Me=>{const qe=wu(Me);return dE(Me,qe.length)})),[b,k]=x.useState(0),w=x.useRef([]),E=x.useRef(null),C=x.useRef(!0),T=x.useRef(!1),j=x.useRef(g.length),[_,A]=x.useState(()=>g.map(()=>0)),[O,B]=x.useState(0),[$,W]=x.useState(0),J=x.useRef(xu(e).map(Ie=>wu(Ie))),[z,G]=x.useState(()=>xu(e).map(Me=>wu(Me).length)),[D,U]=x.useState(null),[q,se]=x.useState(),[V,te]=x.useState(!1),[K,M]=x.useState("idle"),[L,ee]=x.useState(""),fe=x.useRef(),{copyText:ge,copyState:oe}=Z$(w,O),[we,xe]=x.useState(!1),We=iU[(t==null?void 0:t.mode)??"tweet"],He=!!((Nt=t==null?void 0:t.lastPost)!=null&&Nt.postedAt),[Ze,Oe]=x.useState(!1),[Ke,pt]=x.useState(""),Je=x.useRef(null),pe=x.useRef(null);x.useEffect(()=>{if(!Ze)return;setTimeout(()=>{var Me;return(Me=Je.current)==null?void 0:Me.focus()},0);const Ie=Me=>{pe.current&&!pe.current.contains(Me.target)&&(Oe(!1),pt(""))};return document.addEventListener("mousedown",Ie),()=>document.removeEventListener("mousedown",Ie)},[Ze]);const mt=()=>{var F;const Ie=Ke.trim();if(!(!Ie||Ie.includes("x.com")||Ie.includes("twitter.com")))return;const qe=(F=t==null?void 0:t.lastPost)==null?void 0:F.postedAt;Su({lastPost:{postedAt:qe??new Date().toISOString(),tweetUrl:Ie||void 0}}),Oe(!1),pt("")},ft=()=>{Su({lastPost:null})},at=d!==!1,nt=()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({autoplug:!at}),keepalive:!0}).catch(()=>{})};x.useEffect(()=>{let Ie=!1;return(async()=>{try{const Me=await fetch("/api/x/status");if(Ie)return;if(Me.ok){const qe=await Me.json();U(qe.connected),se(qe.username)}else U(!1)}catch{Ie||U(!1)}})(),()=>{Ie=!0}},[]),x.useEffect(()=>{if(C.current){C.current=!1;return}if(!e||JSON.stringify(e)===E.current)return;const Me=xu(e),qe=Me.map(ce=>wu(ce)),F=Me.map((ce,Ne)=>dE(ce,qe[Ne].length));T.current=!0,j.current=F.length,w.current=[],J.current=qe,v(F),A(F.map(()=>0)),G(qe.map(ce=>ce.length)),k(ce=>ce+1)},[e]);const ht=x.useCallback((Ie,Me)=>{if(w.current[Ie]=Me,A(F=>{const ce=[...F];return ce[Ie]=lE(Me.getText()),ce}),T.current)return;const qe=ku(w.current,J.current);E.current=JSON.stringify(qe),n==null||n(qe)},[n]),Fe=x.useCallback((Ie,Me)=>{if(w.current[Ie]=Me,A(qe=>{const F=[...qe];return F[Ie]=lE(Me.getText()),F}),W(qe=>qe+1),T.current&&w.current.filter(Boolean).length>=j.current){T.current=!1;const F=ku(w.current,J.current);E.current=JSON.stringify(F)}Ie===0&&(r==null||r(Me)),s==null||s(w.current.filter(Boolean))},[r,s]),ve=g.length>1;_.reduce((Ie,Me)=>Ie+Me,0);const X=x.useCallback(()=>{const Ie=O+1;v(Me=>[...Me.slice(0,Ie),"<p></p>",...Me.slice(Ie)]),A(Me=>[...Me.slice(0,Ie),0,...Me.slice(Ie)]),J.current.splice(Ie,0,[]),G(Me=>[...Me.slice(0,Ie),0,...Me.slice(Ie)]),B(Ie)},[O]),Be=x.useCallback(Ie=>{Ie!==0&&(w.current.splice(Ie,1),J.current.splice(Ie,1),v(Me=>Me.filter((qe,F)=>F!==Ie)),A(Me=>Me.filter((qe,F)=>F!==Ie)),G(Me=>Me.filter((qe,F)=>F!==Ie)),setTimeout(()=>{const Me=ku(w.current,J.current);n==null||n(Me),s==null||s(w.current.filter(Boolean))},0))},[n,s]),ne=!!(t!=null&&t.url),de=(t==null?void 0:t.mode)==="reply",he=(()=>{const Me=w.current.filter(Boolean).some(F=>F.getText().trim()||fE(F).length>0),qe=z.some(F=>F>0);return Me||qe})(),Ge=D&&he&&K==="idle",Pe=async()=>{if(!D){te(!0);return}if(Ge){M("uploading"),ee("");try{const Ie=[];for(let qe=0;qe<w.current.length;qe++){const F=w.current[qe];if(!F)continue;const ce=F.getText().trim(),Ne=fE(F,J.current[qe]);if(!ce&&Ne.length===0)continue;const P=[];for(const Z of Ne){const re=await(await fetch("/api/x/upload-media",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({src:Z})})).json();if(!re.success)throw new Error(re.error||"Image upload failed");P.push(re.mediaId)}Ie.push({text:ce,mediaIds:P})}if(Ie.length===0)return;M("posting");const Me=oU(t==null?void 0:t.url);if(Ie.length===1){const qe={};Ie[0].text&&(qe.text=Ie[0].text),Ie[0].mediaIds.length>0&&(qe.mediaIds=Ie[0].mediaIds),(t==null?void 0:t.mode)==="reply"&&Me?qe.replyTo=Me:(t==null?void 0:t.mode)==="quote"&&Me&&(qe.quoteTweetId=Me);const ce=await(await fetch("/api/x/post",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(qe)})).json();ce.success?(Su({lastPost:{postedAt:new Date().toISOString(),tweetUrl:ce.tweetUrl}}),M("success"),fe.current=setTimeout(()=>M("idle"),2500)):(console.error("[TweetCompose] Post error:",ce.error),ee(ce.error||"Post failed"),M("error"),setTimeout(()=>M("idle"),3e3))}else{const F={tweets:Ie.map(P=>({text:P.text,...P.mediaIds.length>0?{mediaIds:P.mediaIds}:{}}))};(t==null?void 0:t.mode)==="reply"&&Me&&(F.replyTo=Me);const Ne=await(await fetch("/api/x/post-thread",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)})).json();Ne.success?(Su({lastPost:{postedAt:new Date().toISOString(),tweetUrl:Ne.threadUrl}}),M("success"),fe.current=setTimeout(()=>M("idle"),2500)):(ee(Ne.error||"Thread post failed"),M("error"),setTimeout(()=>M("idle"),3e3))}}catch(Ie){ee(Ie.message||"Network error"),M("error"),setTimeout(()=>M("idle"),3e3)}}};x.useEffect(()=>()=>{fe.current&&clearTimeout(fe.current)},[]);const et=()=>{U(!0),te(!1),fetch("/api/x/status").then(Ie=>Ie.json()).then(Ie=>{Ie.username&&se(Ie.username)}).catch(()=>{})},ot=K==="uploading"?"Uploading...":K==="posting"?"Posting...":K==="success"?"Posted!":K==="error"?"Failed":ve?O===0?"Post Thread":"Post All":"Post",bt=g.map((Ie,Me)=>Me===0?de?"Post your reply":"What is happening?!":"Add another tweet"),Ye=Ie=>{var Me;return c.jsxs("div",{className:`tweet-compose-footer${Ie?" tweet-compose-footer--inline":""}`,children:[O===0&&((Me=t==null?void 0:t.lastPost)==null?void 0:Me.postedAt)&&c.jsxs("a",{className:"tweet-posted-status",href:t.lastPost.tweetUrl,target:"_blank",rel:"noopener noreferrer",title:t.lastPost.tweetUrl||"Posted to X",children:[c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Posted ",new Date(t.lastPost.postedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})]}),K==="error"&&L&&c.jsx("span",{className:"tweet-post-error",children:L}),ve&&c.jsxs("span",{className:"tweet-thread-counter",children:[O+1,"/",g.length]}),c.jsx(az,{count:_[O]||0}),c.jsx("button",{className:"tweet-thread-add",onClick:X,title:"Add another tweet",children:c.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[c.jsx("line",{x1:"10",y1:"4",x2:"10",y2:"16",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),c.jsx("line",{x1:"4",y1:"10",x2:"16",y2:"10",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}),c.jsx("button",{className:`tweet-copy-btn${oe==="copied"?" tweet-copy-btn--copied":""}`,disabled:!he,onClick:ge,title:"Copy tweet text to clipboard",children:oe==="copied"?c.jsxs(c.Fragment,{children:[c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 8.5L6.5 12L13 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),"Copied!"]}):c.jsxs(c.Fragment,{children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[c.jsx("rect",{x:"5.5",y:"2",width:"8.5",height:"10.5",rx:"1.5",stroke:"currentColor",strokeWidth:"1.5"}),c.jsx("path",{d:"M3.5 5H2.5A1.5 1.5 0 001 6.5V13a1.5 1.5 0 001.5 1.5H9A1.5 1.5 0 0010.5 13v-1",stroke:"currentColor",strokeWidth:"1.5"})]}),"Copy"]})}),O===0&&!We&&(()=>{var ce;const qe=((ce=t==null?void 0:t.lastPost)==null?void 0:ce.tweetUrl)??"",F=()=>{if(He){ft(),Oe(!1),pt("");return}pt(qe),Oe(!0)};return c.jsxs("div",{className:"tweet-mark-sent-wrap",ref:pe,children:[c.jsx("button",{className:`tweet-mark-sent-btn${He?" tweet-mark-sent-btn--done":""}`,onClick:F,title:He?qe?`Posted — click to unmark (${qe})`:"Posted — click to unmark":"Mark as manually posted",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:He?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"8 12 11 15 16 9",stroke:He?"#fff":"currentColor"})]})}),Ze&&(()=>{const Ne=Ke.trim(),P=!Ne||Ne.includes("x.com")||Ne.includes("twitter.com");return c.jsxs("div",{className:"tweet-mark-sent-url",children:[c.jsx("input",{ref:Je,type:"text",placeholder:"Paste posted tweet URL...",value:Ke,onChange:Z=>pt(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"&&(Z.preventDefault(),mt()),Z.key==="Escape"&&(Oe(!1),pt(""))}}),c.jsx("button",{onClick:mt,disabled:!P,title:Ne?"Save URL":"Mark posted without URL",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})})]})})()]})})(),c.jsx("button",{className:`tweet-autoplug-toggle${at?" tweet-autoplug-toggle--on":""}`,onClick:nt,title:at?"Auto-plug ON — engagement autoplugs may reply to this post with your configured promo. Click to opt out.":"Auto-plug OFF — this post is excluded from autoplugs. Click to opt in.",children:at?"Auto-plug on":"Auto-plug off"}),o&&!He&&c.jsx("button",{className:"tweet-schedule-btn",onClick:()=>xe(!0),title:"Schedule post",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"12 6 12 12 16 14"})]})}),We&&c.jsx("button",{className:`tweet-post-btn${Ge||!D&&D!==null?" tweet-post-btn--active":""}${K==="success"?" tweet-post-btn--success":""}${K==="error"?" tweet-post-btn--error":""}`,disabled:D?!Ge:!1,onClick:Pe,title:D?q?`Post as @${q}`:"Post to X":"Connect X to post",children:ot})]})},it=ne&&!de,gt=()=>c.jsx("div",{className:"tweet-thread-editors",children:g.map((Ie,Me)=>c.jsxs("div",{className:`tweet-thread-item${Me===O?" tweet-thread-item--active":" tweet-thread-item--inactive"}`,children:[c.jsxs("div",{className:"tweet-thread-item-left",children:[c.jsx(sU,{}),Me<g.length-1&&c.jsx("div",{className:"tweet-thread-line"})]}),c.jsxs("div",{className:"tweet-thread-item-right",children:[Me>0&&c.jsx("button",{className:"tweet-thread-remove",onClick:()=>Be(Me),title:"Remove this tweet",children:"×"}),c.jsx("div",{className:`tweet-compose-box${Me===0&&!ve?" tweet-compose-box--standalone":""}`,children:c.jsx(oz,{initialContent:Ie,initialPreviewImages:J.current[Me],placeholder:bt[Me],onUpdate:qe=>ht(Me,qe),onReady:qe=>Fe(Me,qe),onFocus:()=>{B(Me);const qe=w.current[Me];qe&&(i==null||i(qe))},onPreviewImagesChange:qe=>{if(J.current[Me]=qe,G(F=>{const ce=[...F];return ce[Me]=qe.length,ce}),!T.current){const F=ku(w.current,J.current);E.current=JSON.stringify(F),n==null||n(F)}}})}),Me===O&&!it&&Ye(Me<g.length-1)]})]},`${b}-${Me}`))});return c.jsxs("div",{className:"tweet-compose-wrapper",children:[ne&&de&&c.jsxs(c.Fragment,{children:[h&&c.jsx("div",{className:"tweet-context-section",children:c.jsx(uE,{})}),m&&c.jsx("div",{className:"tweet-context-section",children:c.jsxs("div",{className:"tweet-embed-error",children:[c.jsx("span",{children:"Could not load tweet"}),c.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"tweet-fallback-link",children:t.url})]})}),f&&c.jsxs("div",{className:"tweet-reply-parent-section",children:[c.jsx("div",{className:"tweet-reply-parent-card",children:c.jsx(Lk,{tweet:f,url:t==null?void 0:t.url})}),c.jsxs("div",{className:"tweet-replying-to",children:["Replying to ",c.jsxs("span",{className:"tweet-reply-handle",children:["@",f.author.username]})]})]}),gt()]}),it&&c.jsxs(c.Fragment,{children:[gt(),c.jsxs("div",{className:"tweet-quote-section",style:{padding:"0 16px 12px"},children:[h&&c.jsx(uE,{}),m&&c.jsxs("div",{className:"tweet-embed-error",children:[c.jsx("span",{children:"Could not load tweet"}),c.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"tweet-fallback-link",children:t.url})]}),f&&c.jsx(Lk,{tweet:f,url:t==null?void 0:t.url})]}),c.jsx("div",{className:"tweet-quote-footer",children:Ye()})]}),!ne&&gt(),V&&c.jsx(lz,{onConnected:et,onCancel:()=>te(!1)}),we&&o&&c.jsx(Dl,{filename:o,title:l||"Untitled",onClose:()=>xe(!1)})]})}function lU(){const[t,e]=x.useState("idle"),n=x.useRef();return{copyAsHtml:x.useCallback(async()=>{const s=document.querySelector(".ProseMirror");if(!s)return;const i=s.cloneNode(!0);i.querySelectorAll(".ProseMirror-widget, [data-widget], .ProseMirror-gapcursor").forEach(h=>h.remove());let o="";const l=document.querySelector(".article-title-input");l!=null&&l.value&&l.value!=="Untitled"&&(o+=`<h1>${l.value}</h1>
211
+ `)}function X$(t){const e=n=>{var r;if(n.type==="image"&&((r=n.attrs)!=null&&r.src))return n.attrs.src;if(n.content)for(const s of n.content){const i=e(s);if(i)return i}return null};return e(t.getJSON())}async function Q$(t){try{const e=await fetch(t);if(!e.ok)return null;const n=await e.blob();return n.type==="image/png"?n:new Promise(r=>{const s=new Image,i=URL.createObjectURL(n);s.onload=()=>{const o=document.createElement("canvas");o.width=s.naturalWidth,o.height=s.naturalHeight,o.getContext("2d").drawImage(s,0,0),o.toBlob(l=>{URL.revokeObjectURL(i),r(l)},"image/png")},s.onerror=()=>{URL.revokeObjectURL(i),r(null)},s.src=i})}catch{return null}}function Z$(t,e){const[n,r]=x.useState("idle"),s=x.useRef();return{copyText:x.useCallback(async()=>{const o=t.current[e];if(!o)return;const l=Y$(o),d=X$(o);if(!(!l&&!d)){try{const f={};if(l&&(f["text/plain"]=new Blob([l],{type:"text/plain"})),d){const h=await Q$(d);h&&(f["image/png"]=h)}Object.keys(f).length>0&&await navigator.clipboard.write([new ClipboardItem(f)])}catch{if(l){const f=document.createElement("textarea");f.value=l,f.style.position="fixed",f.style.opacity="0",document.body.appendChild(f),f.select(),document.execCommand("copy"),document.body.removeChild(f)}}r("copied"),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>r("idle"),2e3)}},[t,e]),copyState:n}}function Pp(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e4?`${(t/1e3).toFixed(0)}K`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toLocaleString()}function ez(t){try{const e=Date.now(),n=new Date(t).getTime(),r=Math.floor((e-n)/1e3);if(r<60)return`${r}s`;const s=Math.floor(r/60);if(s<60)return`${s}m`;const i=Math.floor(s/60);return i<24?`${i}h`:new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric"})}catch{return""}}const tz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M1.751 10c0-4.42 3.584-8 8.005-8h4.366c4.49 0 8.129 3.64 8.129 8.13 0 2.96-1.607 5.68-4.196 7.11l-8.054 4.46v-3.69h-.067c-4.49.1-8.183-3.51-8.183-8.01zm8.005-6c-3.317 0-6.005 2.69-6.005 6 0 3.37 2.77 6.08 6.138 6.01l.351-.01h1.761v2.3l5.087-2.81c1.951-1.08 3.163-3.13 3.163-5.36 0-3.39-2.744-6.13-6.129-6.13H9.756z"})}),nz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M4.5 3.88l4.432 4.14-1.364 1.46L5.5 7.55V16c0 1.1.896 2 2 2H13v2H7.5c-2.209 0-4-1.79-4-4V7.55L1.432 9.48.068 8.02 4.5 3.88zM16.5 6H11V4h5.5c2.209 0 4 1.79 4 4v8.45l2.068-1.93 1.364 1.46-4.432 4.14-4.432-4.14 1.364-1.46 2.068 1.93V8c0-1.1-.896-2-2-2z"})}),rz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M16.697 5.5c-1.222-.06-2.679.51-3.89 2.16l-.805 1.09-.806-1.09C9.984 6.01 8.526 5.44 7.304 5.5c-1.243.07-2.349.78-2.91 1.91-.552 1.12-.633 2.78.479 4.82 1.074 1.97 3.257 4.27 7.129 6.61 3.87-2.34 6.052-4.64 7.126-6.61 1.111-2.04 1.03-3.7.477-4.82-.561-1.13-1.666-1.84-2.908-1.91zm4.187 7.69c-1.351 2.48-4.001 5.12-8.379 7.67l-.503.3-.504-.3c-4.379-2.55-7.029-5.19-8.382-7.67-1.36-2.5-1.41-4.86-.514-6.67.887-1.79 2.647-2.91 4.601-3.01 1.651-.09 3.368.56 4.798 2.01 1.429-1.45 3.146-2.1 4.796-2.01 1.954.1 3.714 1.22 4.601 3.01.896 1.81.846 4.17-.514 6.67z"})}),sz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M4 4.5C4 3.12 5.119 2 6.5 2h11C18.881 2 20 3.12 20 4.5v18.44l-8-5.71-8 5.71V4.5zM6.5 4c-.276 0-.5.22-.5.5v14.56l6-4.29 6 4.29V4.5c0-.28-.224-.5-.5-.5h-11z"})}),iz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M12 2.59l5.7 5.7-1.41 1.42L13 6.41V16h-2V6.41l-3.3 3.3-1.41-1.42L12 2.59zM21 15l-.02 3.51c0 1.38-1.12 2.49-2.5 2.49H5.5C4.11 21 3 19.88 3 18.5V15h2v3.5c0 .28.22.5.5.5h12.98c.28 0 .5-.22.5-.5L19 15h2z"})});function F2({tweet:t,nested:e,url:n}){const r=ez(t.createdAt);return c.jsxs("div",{className:`tweet-embed-card${e?" tweet-embed-nested":""}${n?" tweet-embed-card--clickable":""}`,onClick:n?()=>window.open(n,"_blank","noopener,noreferrer"):void 0,role:n?"link":void 0,children:[c.jsxs("div",{className:"tweet-author-row",children:[t.author.avatarUrl?c.jsx("img",{className:"tweet-avatar",src:t.author.avatarUrl,alt:""}):c.jsx("div",{className:"tweet-avatar tweet-avatar-placeholder"}),c.jsxs("div",{className:"tweet-author-info",children:[c.jsx("span",{className:"tweet-author-name",children:t.author.name}),c.jsxs("span",{className:"tweet-author-handle",children:["@",t.author.username]}),r&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"tweet-author-separator",children:"·"}),c.jsx("span",{className:"tweet-author-timestamp",children:r})]})]})]}),c.jsx("div",{className:"tweet-text",children:t.text}),t.media&&t.media.length>0&&c.jsx("div",{className:"tweet-media","data-count":t.media.length,children:t.media.map((s,i)=>s.type==="photo"?c.jsx("img",{className:"tweet-media-img",src:s.url,alt:"",loading:"lazy"},i):s.type==="video"||s.type==="gif"?c.jsx("div",{className:"tweet-media-video-placeholder",children:c.jsx("span",{children:"Video"})},i):null)}),t.quoteTweet&&c.jsx(F2,{tweet:t.quoteTweet,nested:!0}),!e&&c.jsxs("div",{className:"tweet-actions-row",children:[c.jsxs("span",{className:"tweet-action tweet-action-reply",children:[c.jsx(tz,{}),t.metrics.replies>0&&Pp(t.metrics.replies)]}),c.jsxs("span",{className:"tweet-action tweet-action-retweet",children:[c.jsx(nz,{}),t.metrics.retweets>0&&Pp(t.metrics.retweets)]}),c.jsxs("span",{className:"tweet-action tweet-action-like",children:[c.jsx(rz,{}),t.metrics.likes>0&&Pp(t.metrics.likes)]}),c.jsx("span",{className:"tweet-action tweet-action-bookmark",children:c.jsx(sz,{})}),c.jsx("span",{className:"tweet-action tweet-action-share",children:c.jsx(iz,{})})]})]})}function Lk({tweet:t,url:e}){return c.jsx(F2,{tweet:t,url:e})}function oz({initialContent:t,initialPreviewImages:e,placeholder:n="What is happening?!",onUpdate:r,onReady:s,onFocus:i,onPreviewImagesChange:o}){const[l,d]=x.useState(e||[]),f=x.useRef(e||[]),h=x.useRef(!1),m=x.useRef(s);m.current=s;const g=x.useRef(o);g.current=o;const v=x.useCallback(E=>{var T;const C=E.slice(0,4);f.current=C,d(C),(T=g.current)==null||T.call(g,C)},[]),b=x.useCallback(E=>{if(h.current)return;const C=[],T=[];if(E.state.doc.descendants((O,B)=>{var $;O.type.name==="image"&&(($=O.attrs)!=null&&$.src)&&(C.push(O.attrs.src),T.push({from:B,to:B+O.nodeSize}))}),C.length===0)return;h.current=!0;const{tr:j}=E.state;for(let O=T.length-1;O>=0;O--)j.delete(T[O].from,T[O].to);E.view.dispatch(j);const _=f.current,A=4-_.length;A>0&&v([..._,...C.slice(0,A)]),h.current=!1},[v]),k=FC({extensions:[...n2,Kd.configure({placeholder:n})],content:t||"<p></p>",onCreate:({editor:E})=>{b(E)},onUpdate:({editor:E})=>{b(E),r==null||r(E)},onFocus:()=>{i==null||i()},editorProps:{handlePaste:d2,handleDrop:f2}},[t]);x.useEffect(()=>{k&&g5(k.view,{addToPreview:E=>{const C=f.current;C.length>=4||v([...C,E])},getPreviewImages:()=>f.current})},[k,v]),x.useEffect(()=>{if(!k)return;const{state:E}=k.view;if(E.plugins.some(j=>j.key==="pendingDecoration$"))return;const C=a2(),T=E.reconfigure({plugins:[...E.plugins,C]});k.view.updateState(T)},[k]),x.useEffect(()=>{if(!k)return;const{state:E}=k.view;if(E.plugins.some(j=>j.key==="commentDecoration$"))return;const C=c2(),T=E.reconfigure({plugins:[...E.plugins,C]});k.view.updateState(T)},[k]),x.useEffect(()=>{var E;k&&((E=m.current)==null||E.call(m,k))},[k]);const w=x.useCallback(E=>{v(f.current.filter((C,T)=>T!==E))},[v]);return k?c.jsxs(c.Fragment,{children:[c.jsx(Rv,{editor:k}),l.length>0&&c.jsx("div",{className:"tweet-preview-grid","data-count":l.length,children:l.map((E,C)=>c.jsxs("div",{className:"tweet-image-card",children:[c.jsx("img",{className:"tweet-image-card-img",src:E,alt:"",draggable:!1}),c.jsx("button",{className:"tweet-image-card-remove",onClick:()=>w(C),title:"Remove image",children:"×"})]},E))})]}):null}function az({count:t,softLimit:e=280}){const n=e-t,r=Math.min(t/e,1),s=n<=20,i=s?30:26,o=2,l=(i-o)/2,d=2*Math.PI*l,f=d*(1-r);let h="var(--x-blue, #1d9bf0)";return n<=0?h="var(--x-red, #f4212e)":n<=20&&(h="var(--x-yellow, #ffd400)"),t===0?null:c.jsxs("div",{className:"tweet-char-counter",title:`${t} / ${e}`,style:{width:i,height:i},children:[c.jsxs("svg",{width:i,height:i,viewBox:`0 0 ${i} ${i}`,children:[c.jsx("circle",{cx:i/2,cy:i/2,r:l,fill:"none",stroke:"var(--x-border, #eff3f4)",strokeWidth:o}),c.jsx("circle",{cx:i/2,cy:i/2,r:l,fill:"none",stroke:h,strokeWidth:o,strokeDasharray:d,strokeDashoffset:f,strokeLinecap:"round",transform:`rotate(-90 ${i/2} ${i/2})`,style:{transition:"stroke-dashoffset 0.15s ease, stroke 0.15s ease"}})]}),s&&c.jsx("span",{className:"tweet-char-number",style:{color:h,fontSize:n<-9||n>9?10:11},children:n})]})}const Dk="@openwriter/plugin-x-api",Pk=[{key:"api-key",label:"API Key",env:"X_API_KEY"},{key:"api-secret",label:"API Secret",env:"X_API_SECRET"},{key:"access-token",label:"Access Token",env:"X_ACCESS_TOKEN"},{key:"access-token-secret",label:"Access Token Secret",env:"X_ACCESS_TOKEN_SECRET"}];function lz({onConnected:t,onCancel:e}){const[n,r]=x.useState({"api-key":"","api-secret":"","access-token":"","access-token-secret":""}),[s,i]=x.useState(!1),[o,l]=x.useState(""),d=Pk.every(h=>n[h.key].trim()),f=async()=>{i(!0),l("");try{if(!(await fetch("/api/plugins/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Dk,config:n})})).ok)throw new Error("Failed to save config");const g=await(await fetch("/api/plugins/enable",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:Dk})})).json();if(!g.success)throw new Error(g.error||"Failed to enable plugin");const b=await(await fetch("/api/x/status")).json();b.connected?t():l(b.error||"Could not verify X credentials. Check your API keys.")}catch(h){l(h.message||"Connection failed")}finally{i(!1)}};return c.jsxs("div",{className:"x-connect-prompt",children:[c.jsxs("div",{className:"x-connect-header",children:[c.jsx("span",{className:"x-connect-title",children:"Connect your X account to post"}),c.jsx("button",{className:"x-connect-cancel",onClick:e,title:"Cancel",children:c.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18",children:c.jsx("path",{fill:"currentColor",d:"M10.59 12L4.54 5.96l1.42-1.42L12 10.59l6.04-6.05 1.42 1.42L13.41 12l6.05 6.04-1.42 1.42L12 13.41l-6.04 6.05-1.42-1.42L10.59 12z"})})})]}),c.jsx("div",{className:"x-connect-fields",children:Pk.map(h=>c.jsxs("div",{className:"x-connect-field",children:[c.jsx("label",{className:"x-connect-label",children:h.label}),c.jsx("input",{type:"password",className:"x-connect-input",value:n[h.key],onChange:m=>r(g=>({...g,[h.key]:m.target.value})),placeholder:h.env,spellCheck:!1,autoComplete:"off"})]},h.key))}),o&&c.jsx("div",{className:"x-connect-error",children:o}),c.jsxs("div",{className:"x-connect-actions",children:[c.jsx("a",{className:"x-connect-dev-link",href:"https://developer.x.com/en/portal/dashboard",target:"_blank",rel:"noopener noreferrer",children:"Get credentials"}),c.jsx("button",{className:"x-connect-btn",onClick:f,disabled:!d||s,children:s?"Connecting...":"Connect"})]})]})}var Bk={},Bp,$k;function $s(){return $k||($k=1,Bp=function(t){return typeof t=="object"?t!==null:typeof t=="function"}),Bp}var $p,zk;function Cr(){if(zk)return $p;zk=1;var t=$s();return $p=function(e){if(!t(e))throw TypeError(e+" is not an object!");return e},$p}var zp,Fk;function Qd(){return Fk||(Fk=1,zp=function(t){if(t==null)throw TypeError("Can't call method on "+t);return t}),zp}var Fp,Uk;function ji(){if(Uk)return Fp;Uk=1;var t=Qd();return Fp=function(e){return Object(t(e))},Fp}var Up,Hk;function Zd(){if(Hk)return Up;Hk=1;var t=Math.ceil,e=Math.floor;return Up=function(n){return isNaN(n=+n)?0:(n>0?e:t)(n)},Up}var Hp,Wk;function mo(){if(Wk)return Hp;Wk=1;var t=Zd(),e=Math.min;return Hp=function(n){return n>0?e(t(n),9007199254740991):0},Hp}var Wp,qk;function U2(){if(qk)return Wp;qk=1;var t=Zd(),e=Qd();return Wp=function(n){return function(r,s){var i=String(e(r)),o=t(s),l=i.length,d,f;return o<0||o>=l?n?"":void 0:(d=i.charCodeAt(o),d<55296||d>56319||o+1===l||(f=i.charCodeAt(o+1))<56320||f>57343?n?i.charAt(o):d:n?i.slice(o,o+2):(d-55296<<10)+(f-56320)+65536)}},Wp}var qp,Vk;function ly(){if(Vk)return qp;Vk=1;var t=U2()(!0);return qp=function(e,n,r){return n+(r?t(e,n).length:1)},qp}var Vp,Kk;function ef(){if(Kk)return Vp;Kk=1;var t={}.toString;return Vp=function(e){return t.call(e).slice(8,-1)},Vp}var Kp={exports:{}},Gp={exports:{}},Jp={exports:{}},Gk;function fa(){if(Gk)return Jp.exports;Gk=1;var t=Jp.exports={version:"2.6.12"};return typeof __e=="number"&&(__e=t),Jp.exports}var Yp={exports:{}},Jk;function Ur(){if(Jk)return Yp.exports;Jk=1;var t=Yp.exports=typeof window<"u"&&window.Math==Math?window:typeof self<"u"&&self.Math==Math?self:Function("return this")();return typeof __g=="number"&&(__g=t),Yp.exports}var Xp,Yk;function tf(){return Yk||(Yk=1,Xp=!1),Xp}var Xk;function nf(){if(Xk)return Gp.exports;Xk=1;var t=fa(),e=Ur(),n="__core-js_shared__",r=e[n]||(e[n]={});return(Gp.exports=function(s,i){return r[s]||(r[s]=i!==void 0?i:{})})("versions",[]).push({version:t.version,mode:tf()?"pure":"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"}),Gp.exports}var Qp,Qk;function Pl(){if(Qk)return Qp;Qk=1;var t=0,e=Math.random();return Qp=function(n){return"Symbol(".concat(n===void 0?"":n,")_",(++t+e).toString(36))},Qp}var Zk;function Dn(){if(Zk)return Kp.exports;Zk=1;var t=nf()("wks"),e=Pl(),n=Ur().Symbol,r=typeof n=="function",s=Kp.exports=function(i){return t[i]||(t[i]=r&&n[i]||(r?n:e)("Symbol."+i))};return s.store=t,Kp.exports}var Zp,e1;function cy(){if(e1)return Zp;e1=1;var t=ef(),e=Dn()("toStringTag"),n=t((function(){return arguments})())=="Arguments",r=function(s,i){try{return s[i]}catch{}};return Zp=function(s){var i,o,l;return s===void 0?"Undefined":s===null?"Null":typeof(o=r(i=Object(s),e))=="string"?o:n?t(i):(l=t(i))=="Object"&&typeof i.callee=="function"?"Arguments":l},Zp}var em,t1;function uy(){if(t1)return em;t1=1;var t=cy(),e=RegExp.prototype.exec;return em=function(n,r){var s=n.exec;if(typeof s=="function"){var i=s.call(n,r);if(typeof i!="object")throw new TypeError("RegExp exec method returned something other than an Object or null");return i}if(t(n)!=="RegExp")throw new TypeError("RegExp#exec called on incompatible receiver");return e.call(n,r)},em}var n1={},tm,r1;function rf(){if(r1)return tm;r1=1;var t=Cr();return tm=function(){var e=t(this),n="";return e.global&&(n+="g"),e.ignoreCase&&(n+="i"),e.multiline&&(n+="m"),e.unicode&&(n+="u"),e.sticky&&(n+="y"),n},tm}var nm,s1;function dy(){if(s1)return nm;s1=1;var t=rf(),e=RegExp.prototype.exec,n=String.prototype.replace,r=e,s="lastIndex",i=(function(){var d=/a/,f=/b*/g;return e.call(d,"a"),e.call(f,"a"),d[s]!==0||f[s]!==0})(),o=/()??/.exec("")[1]!==void 0,l=i||o;return l&&(r=function(f){var h=this,m,g,v,b;return o&&(g=new RegExp("^"+h.source+"$(?!\\s)",t.call(h))),i&&(m=h[s]),v=e.call(h,f),i&&v&&(h[s]=h.global?v.index+v[0].length:m),o&&v&&v.length>1&&n.call(v[0],g,function(){for(b=1;b<arguments.length-2;b++)arguments[b]===void 0&&(v[b]=void 0)}),v}),nm=r,nm}var rm={},sm,i1;function rs(){return i1||(i1=1,sm=function(t){try{return!!t()}catch{return!0}}),sm}var im,o1;function Hr(){return o1||(o1=1,im=!rs()(function(){return Object.defineProperty({},"a",{get:function(){return 7}}).a!=7})),im}var om,a1;function H2(){if(a1)return om;a1=1;var t=$s(),e=Ur().document,n=t(e)&&t(e.createElement);return om=function(r){return n?e.createElement(r):{}},om}var am,l1;function W2(){return l1||(l1=1,am=!Hr()&&!rs()(function(){return Object.defineProperty(H2()("div"),"a",{get:function(){return 7}}).a!=7})),am}var lm,c1;function fy(){if(c1)return lm;c1=1;var t=$s();return lm=function(e,n){if(!t(e))return e;var r,s;if(n&&typeof(r=e.toString)=="function"&&!t(s=r.call(e))||typeof(r=e.valueOf)=="function"&&!t(s=r.call(e))||!n&&typeof(r=e.toString)=="function"&&!t(s=r.call(e)))return s;throw TypeError("Can't convert object to primitive value")},lm}var u1;function ss(){if(u1)return rm;u1=1;var t=Cr(),e=W2(),n=fy(),r=Object.defineProperty;return rm.f=Hr()?Object.defineProperty:function(i,o,l){if(t(i),o=n(o,!0),t(l),e)try{return r(i,o,l)}catch{}if("get"in l||"set"in l)throw TypeError("Accessors not supported!");return"value"in l&&(i[o]=l.value),i},rm}var cm,d1;function Bl(){return d1||(d1=1,cm=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}}),cm}var um,f1;function Mi(){if(f1)return um;f1=1;var t=ss(),e=Bl();return um=Hr()?function(n,r,s){return t.f(n,r,e(1,s))}:function(n,r,s){return n[r]=s,n},um}var dm={exports:{}},fm,h1;function go(){if(h1)return fm;h1=1;var t={}.hasOwnProperty;return fm=function(e,n){return t.call(e,n)},fm}var hm,p1;function cz(){return p1||(p1=1,hm=nf()("native-function-to-string",Function.toString)),hm}var m1;function zs(){if(m1)return dm.exports;m1=1;var t=Ur(),e=Mi(),n=go(),r=Pl()("src"),s=cz(),i="toString",o=(""+s).split(i);return fa().inspectSource=function(l){return s.call(l)},(dm.exports=function(l,d,f,h){var m=typeof f=="function";m&&(n(f,"name")||e(f,"name",d)),l[d]!==f&&(m&&(n(f,r)||e(f,r,l[d]?""+l[d]:o.join(String(d)))),l===t?l[d]=f:h?l[d]?l[d]=f:e(l,d,f):(delete l[d],e(l,d,f)))})(Function.prototype,i,function(){return typeof this=="function"&&this[r]||s.call(this)}),dm.exports}var pm,g1;function sf(){return g1||(g1=1,pm=function(t){if(typeof t!="function")throw TypeError(t+" is not a function!");return t}),pm}var mm,v1;function of(){if(v1)return mm;v1=1;var t=sf();return mm=function(e,n,r){if(t(e),n===void 0)return e;switch(r){case 1:return function(s){return e.call(n,s)};case 2:return function(s,i){return e.call(n,s,i)};case 3:return function(s,i,o){return e.call(n,s,i,o)}}return function(){return e.apply(n,arguments)}},mm}var gm,y1;function vr(){if(y1)return gm;y1=1;var t=Ur(),e=fa(),n=Mi(),r=zs(),s=of(),i="prototype",o=function(l,d,f){var h=l&o.F,m=l&o.G,g=l&o.S,v=l&o.P,b=l&o.B,k=m?t:g?t[d]||(t[d]={}):(t[d]||{})[i],w=m?e:e[d]||(e[d]={}),E=w[i]||(w[i]={}),C,T,j,_;m&&(f=d);for(C in f)T=!h&&k&&k[C]!==void 0,j=(T?k:f)[C],_=b&&T?s(j,t):v&&typeof j=="function"?s(Function.call,j):j,k&&r(k,C,j,l&o.U),w[C]!=j&&n(w,C,_),v&&E[C]!=j&&(E[C]=j)};return t.core=e,o.F=1,o.G=2,o.S=4,o.P=8,o.B=16,o.W=32,o.U=64,o.R=128,gm=o,gm}var b1;function uz(){if(b1)return n1;b1=1;var t=dy();return vr()({target:"RegExp",proto:!0,forced:t!==/./.exec},{exec:t}),n1}var vm,x1;function hy(){if(x1)return vm;x1=1,uz();var t=zs(),e=Mi(),n=rs(),r=Qd(),s=Dn(),i=dy(),o=s("species"),l=!n(function(){var f=/./;return f.exec=function(){var h=[];return h.groups={a:"7"},h},"".replace(f,"$<a>")!=="7"}),d=(function(){var f=/(?:)/,h=f.exec;f.exec=function(){return h.apply(this,arguments)};var m="ab".split(f);return m.length===2&&m[0]==="a"&&m[1]==="b"})();return vm=function(f,h,m){var g=s(f),v=!n(function(){var T={};return T[g]=function(){return 7},""[f](T)!=7}),b=v?!n(function(){var T=!1,j=/a/;return j.exec=function(){return T=!0,null},f==="split"&&(j.constructor={},j.constructor[o]=function(){return j}),j[g](""),!T}):void 0;if(!v||!b||f==="replace"&&!l||f==="split"&&!d){var k=/./[g],w=m(r,g,""[f],function(j,_,A,O,B){return _.exec===i?v&&!B?{done:!0,value:k.call(_,A,O)}:{done:!0,value:j.call(A,_,O)}:{done:!1}}),E=w[0],C=w[1];t(String.prototype,f,E),e(RegExp.prototype,g,h==2?function(T,j){return C.call(T,this,j)}:function(T){return C.call(T,this)})}},vm}var w1;function dz(){if(w1)return Bk;w1=1;var t=Cr(),e=ji(),n=mo(),r=Zd(),s=ly(),i=uy(),o=Math.max,l=Math.min,d=Math.floor,f=/\$([$&`']|\d\d?|<[^>]*>)/g,h=/\$([$&`']|\d\d?)/g,m=function(g){return g===void 0?g:String(g)};return hy()("replace",2,function(g,v,b,k){return[function(C,T){var j=g(this),_=C==null?void 0:C[v];return _!==void 0?_.call(C,j,T):b.call(String(j),C,T)},function(E,C){var T=k(b,E,this,C);if(T.done)return T.value;var j=t(E),_=String(this),A=typeof C=="function";A||(C=String(C));var O=j.global;if(O){var B=j.unicode;j.lastIndex=0}for(var $=[];;){var W=i(j,_);if(W===null||($.push(W),!O))break;var J=String(W[0]);J===""&&(j.lastIndex=s(_,n(j.lastIndex),B))}for(var z="",G=0,D=0;D<$.length;D++){W=$[D];for(var U=String(W[0]),q=o(l(r(W.index),_.length),0),se=[],V=1;V<W.length;V++)se.push(m(W[V]));var te=W.groups;if(A){var K=[U].concat(se,q,_);te!==void 0&&K.push(te);var M=String(C.apply(void 0,K))}else M=w(U,_,q,se,te,C);q>=G&&(z+=_.slice(G,q)+M,G=q+U.length)}return z+_.slice(G)}];function w(E,C,T,j,_,A){var O=T+E.length,B=j.length,$=h;return _!==void 0&&(_=e(_),$=f),b.call(A,$,function(W,J){var z;switch(J.charAt(0)){case"$":return"$";case"&":return E;case"`":return C.slice(0,T);case"'":return C.slice(O);case"<":z=_[J.slice(1,-1)];break;default:var G=+J;if(G===0)return W;if(G>B){var D=d(G/10);return D===0?W:D<=B?j[D-1]===void 0?J.charAt(1):j[D-1]+J.charAt(1):W}z=j[G-1]}return z===void 0?"":z})}}),Bk}dz();var k1={},ym,S1;function py(){if(S1)return ym;S1=1;var t=ef();return ym=Object("z").propertyIsEnumerable(0)?Object:function(e){return t(e)=="String"?e.split(""):Object(e)},ym}var bm,E1;function vo(){if(E1)return bm;E1=1;var t=py(),e=Qd();return bm=function(n){return t(e(n))},bm}var xm,N1;function fz(){if(N1)return xm;N1=1;var t=Zd(),e=Math.max,n=Math.min;return xm=function(r,s){return r=t(r),r<0?e(r+s,0):n(r,s)},xm}var wm,C1;function q2(){if(C1)return wm;C1=1;var t=vo(),e=mo(),n=fz();return wm=function(r){return function(s,i,o){var l=t(s),d=e(l.length),f=n(o,d),h;if(r&&i!=i){for(;d>f;)if(h=l[f++],h!=h)return!0}else for(;d>f;f++)if((r||f in l)&&l[f]===i)return r||f||0;return!r&&-1}},wm}var km,_1;function $l(){if(_1)return km;_1=1;var t=rs();return km=function(e,n){return!!e&&t(function(){n?e.call(null,function(){},1):e.call(null)})},km}var T1;function hz(){if(T1)return k1;T1=1;var t=vr(),e=q2()(!1),n=[].indexOf,r=!!n&&1/[1].indexOf(1,-0)<0;return t(t.P+t.F*(r||!$l()(n)),"Array",{indexOf:function(i){return r?n.apply(this,arguments)||0:e(this,i,arguments[1])}}),k1}hz();var pz=/[a-z]{1,6}(?:[._][a-z]{1,2})?/i,V2=/\!'#%&'\(\)*\+,\\\-\.\/:;<=>\?@\[\]\^_{|}~\$/,j1={},Sm={},Em={},M1;function my(){return M1||(M1=1,Em.f={}.propertyIsEnumerable),Em}var A1;function gy(){if(A1)return Sm;A1=1;var t=my(),e=Bl(),n=vo(),r=fy(),s=go(),i=W2(),o=Object.getOwnPropertyDescriptor;return Sm.f=Hr()?o:function(d,f){if(d=n(d),f=r(f,!0),i)try{return o(d,f)}catch{}if(s(d,f))return e(!t.f.call(d,f),d[f])},Sm}var Nm,R1;function mz(){if(R1)return Nm;R1=1;var t=$s(),e=Cr(),n=function(r,s){if(e(r),!t(s)&&s!==null)throw TypeError(s+": can't set as prototype!")};return Nm={set:Object.setPrototypeOf||("__proto__"in{}?(function(r,s,i){try{i=of()(Function.call,gy().f(Object.prototype,"__proto__").set,2),i(r,[]),s=!(r instanceof Array)}catch{s=!0}return function(l,d){return n(l,d),s?l.__proto__=d:i(l,d),l}})({},!1):void 0),check:n},Nm}var Cm,O1;function gz(){if(O1)return Cm;O1=1;var t=$s(),e=mz().set;return Cm=function(n,r,s){var i=r.constructor,o;return i!==s&&typeof i=="function"&&(o=i.prototype)!==s.prototype&&t(o)&&e&&e(n,o),n},Cm}var _m={},Tm,I1;function vy(){if(I1)return Tm;I1=1;var t=nf()("keys"),e=Pl();return Tm=function(n){return t[n]||(t[n]=e(n))},Tm}var jm,L1;function K2(){if(L1)return jm;L1=1;var t=go(),e=vo(),n=q2()(!1),r=vy()("IE_PROTO");return jm=function(s,i){var o=e(s),l=0,d=[],f;for(f in o)f!=r&&t(o,f)&&d.push(f);for(;i.length>l;)t(o,f=i[l++])&&(~n(d,f)||d.push(f));return d},jm}var Mm,D1;function yy(){return D1||(D1=1,Mm="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")),Mm}var P1;function af(){if(P1)return _m;P1=1;var t=K2(),e=yy().concat("length","prototype");return _m.f=Object.getOwnPropertyNames||function(r){return t(r,e)},_m}var Am,B1;function G2(){if(B1)return Am;B1=1;var t=$s(),e=ef(),n=Dn()("match");return Am=function(r){var s;return t(r)&&((s=r[n])!==void 0?!!s:e(r)=="RegExp")},Am}var Rm,$1;function vz(){if($1)return Rm;$1=1;var t=Ur(),e=ss(),n=Hr(),r=Dn()("species");return Rm=function(s){var i=t[s];n&&i&&!i[r]&&e.f(i,r,{configurable:!0,get:function(){return this}})},Rm}var z1;function yz(){if(z1)return j1;z1=1;var t=Ur(),e=gz(),n=ss().f,r=af().f,s=G2(),i=rf(),o=t.RegExp,l=o,d=o.prototype,f=/a/g,h=/a/g,m=new o(f)!==f;if(Hr()&&(!m||rs()(function(){return h[Dn()("match")]=!1,o(f)!=f||o(h)==h||o(f,"i")!="/a/i"}))){o=function(w,E){var C=this instanceof o,T=s(w),j=E===void 0;return!C&&T&&w.constructor===o&&j?w:e(m?new l(T&&!j?w.source:w,E):l((T=w instanceof o)?w.source:w,T&&j?i.call(w):E),C?this:d,o)};for(var g=function(k){k in o||n(o,k,{configurable:!0,get:function(){return l[k]},set:function(w){l[k]=w}})},v=r(l),b=0;v.length>b;)g(v[b++]);d.constructor=o,o.prototype=d,zs()(t,"RegExp",o)}return vz()("RegExp"),j1}yz();function Mt(t,e,n){return n=n||"",typeof t!="string"&&(t.global&&n.indexOf("g")<0&&(n+="g"),t.ignoreCase&&n.indexOf("i")<0&&(n+="i"),t.multiline&&n.indexOf("m")<0&&(n+="m"),t=t.source),new RegExp(t.replace(/#\{(\w+)\}/g,function(r,s){var i=e[s]||"";return typeof i!="string"&&(i=i.source),i}),n)}var J2=/\x09-\x0D\x20\x85\xA0\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000/;const Y2=Mt(/[#{spacesGroup}]/,{spacesGroup:J2});Mt("(^|#{spaces})(\\$)(#{cashtag})(?=$|\\s|[#{punct}])",{cashtag:pz,spaces:Y2,punct:V2},"gi");var F1={},U1;function bz(){if(U1)return F1;U1=1;var t=Cr(),e=mo(),n=ly(),r=uy();return hy()("match",1,function(s,i,o,l){return[function(f){var h=s(this),m=f==null?void 0:f[i];return m!==void 0?m.call(f,h):new RegExp(f)[i](String(h))},function(d){var f=l(o,d,this);if(f.done)return f.value;var h=t(d),m=String(this);if(!h.global)return r(h,m);var g=h.unicode;h.lastIndex=0;for(var v=[],b=0,k;(k=r(h,m))!==null;){var w=String(k[0]);v[b]=w,w===""&&(h.lastIndex=n(m,e(h.lastIndex),g)),b++}return b===0?null:v}]}),F1}bz();var X2=/[##]/;Mt(/^(?:#{hashSigns}|:\/\/)/,{hashSigns:X2});var Q2=Mt(RegExp("(?:(?:한국|香港|澳門|新加坡|台灣|台湾|中國|中国|გე|ລາວ|ไทย|ලංකා|ഭാരതം|ಭಾರತ|భారత్|சிங்கப்பூர்|இலங்கை|இந்தியா|ଭାରତ|ભારત|ਭਾਰਤ|ভাৰত|ভারত|বাংলা|भारोत|भारतम्|भारत|ڀارت|پاکستان|موريتانيا|مليسيا|مصر|قطر|فلسطين|عمان|عراق|سورية|سودان|تونس|بھارت|بارت|ایران|امارات|المغرب|السعودية|الجزائر|البحرين|الاردن|հայ|қаз|укр|срб|рф|мон|мкд|ею|бел|бг|ευ|ελ|zw|zm|za|yt|ye|ws|wf|vu|vn|vi|vg|ve|vc|va|uz|uy|us|um|uk|ug|ua|tz|tw|tv|tt|tr|tp|to|tn|tm|tl|tk|tj|th|tg|tf|td|tc|sz|sy|sx|sv|su|st|ss|sr|so|sn|sm|sl|sk|sj|si|sh|sg|se|sd|sc|sb|sa|rw|ru|rs|ro|re|qa|py|pw|pt|ps|pr|pn|pm|pl|pk|ph|pg|pf|pe|pa|om|nz|nu|nr|np|no|nl|ni|ng|nf|ne|nc|na|mz|my|mx|mw|mv|mu|mt|ms|mr|mq|mp|mo|mn|mm|ml|mk|mh|mg|mf|me|md|mc|ma|ly|lv|lu|lt|ls|lr|lk|li|lc|lb|la|kz|ky|kw|kr|kp|kn|km|ki|kh|kg|ke|jp|jo|jm|je|it|is|ir|iq|io|in|im|il|ie|id|hu|ht|hr|hn|hm|hk|gy|gw|gu|gt|gs|gr|gq|gp|gn|gm|gl|gi|gh|gg|gf|ge|gd|gb|ga|fr|fo|fm|fk|fj|fi|eu|et|es|er|eh|eg|ee|ec|dz|do|dm|dk|dj|de|cz|cy|cx|cw|cv|cu|cr|co|cn|cm|cl|ck|ci|ch|cg|cf|cd|cc|ca|bz|by|bw|bv|bt|bs|br|bq|bo|bn|bm|bl|bj|bi|bh|bg|bf|be|bd|bb|ba|az|ax|aw|au|at|as|ar|aq|ao|an|am|al|ai|ag|af|ae|ad|ac)(?=[^0-9a-zA-Z@+-]|$))")),Z2=/\u202A-\u202E\u061C\u200E\u200F\u2066\u2067\u2068\u2069/,by=/\uFFFE\uFEFF\uFFFF/;function xz(t,e){return t.replace(/#\{(\w+)\}/g,function(n,r){return e[r]||""})}var wz=xz("#{punct}#{spacesGroup}#{invalidCharsGroup}#{directionalMarkersGroup}",{punct:V2,spacesGroup:J2,invalidCharsGroup:by,directionalMarkersGroup:Z2}),eT=Mt(/[^#{invalidDomainChars}]/,{invalidDomainChars:wz}),kz=Mt(/(?:(?:#{validDomainChars}(?:-|#{validDomainChars})*)?#{validDomainChars}\.)/,{validDomainChars:eT}),tT=Mt(RegExp("(?:(?:삼성|닷컴|닷넷|香格里拉|餐厅|食品|飞利浦|電訊盈科|集团|通販|购物|谷歌|诺基亚|联通|网络|网站|网店|网址|组织机构|移动|珠宝|点看|游戏|淡马锡|机构|書籍|时尚|新闻|政府|政务|招聘|手表|手机|我爱你|慈善|微博|广东|工行|家電|娱乐|天主教|大拿|大众汽车|在线|嘉里大酒店|嘉里|商标|商店|商城|公益|公司|八卦|健康|信息|佛山|企业|中文网|中信|世界|ポイント|ファッション|セール|ストア|コム|グーグル|クラウド|みんな|คอม|संगठन|नेट|कॉम|همراه|موقع|موبايلي|كوم|كاثوليك|عرب|شبكة|بيتك|بازار|العليان|ارامكو|اتصالات|ابوظبي|קום|сайт|рус|орг|онлайн|москва|ком|католик|дети|zuerich|zone|zippo|zip|zero|zara|zappos|yun|youtube|you|yokohama|yoga|yodobashi|yandex|yamaxun|yahoo|yachts|xyz|xxx|xperia|xin|xihuan|xfinity|xerox|xbox|wtf|wtc|wow|world|works|work|woodside|wolterskluwer|wme|winners|wine|windows|win|williamhill|wiki|wien|whoswho|weir|weibo|wedding|wed|website|weber|webcam|weatherchannel|weather|watches|watch|warman|wanggou|wang|walter|walmart|wales|vuelos|voyage|voto|voting|vote|volvo|volkswagen|vodka|vlaanderen|vivo|viva|vistaprint|vista|vision|visa|virgin|vip|vin|villas|viking|vig|video|viajes|vet|versicherung|vermögensberatung|vermögensberater|verisign|ventures|vegas|vanguard|vana|vacations|ups|uol|uno|university|unicom|uconnect|ubs|ubank|tvs|tushu|tunes|tui|tube|trv|trust|travelersinsurance|travelers|travelchannel|travel|training|trading|trade|toys|toyota|town|tours|total|toshiba|toray|top|tools|tokyo|today|tmall|tkmaxx|tjx|tjmaxx|tirol|tires|tips|tiffany|tienda|tickets|tiaa|theatre|theater|thd|teva|tennis|temasek|telefonica|telecity|tel|technology|tech|team|tdk|tci|taxi|tax|tattoo|tatar|tatamotors|target|taobao|talk|taipei|tab|systems|symantec|sydney|swiss|swiftcover|swatch|suzuki|surgery|surf|support|supply|supplies|sucks|style|study|studio|stream|store|storage|stockholm|stcgroup|stc|statoil|statefarm|statebank|starhub|star|staples|stada|srt|srl|spreadbetting|spot|sport|spiegel|space|soy|sony|song|solutions|solar|sohu|software|softbank|social|soccer|sncf|smile|smart|sling|skype|sky|skin|ski|site|singles|sina|silk|shriram|showtime|show|shouji|shopping|shop|shoes|shiksha|shia|shell|shaw|sharp|shangrila|sfr|sexy|sex|sew|seven|ses|services|sener|select|seek|security|secure|seat|search|scot|scor|scjohnson|science|schwarz|schule|school|scholarships|schmidt|schaeffler|scb|sca|sbs|sbi|saxo|save|sas|sarl|sapo|sap|sanofi|sandvikcoromant|sandvik|samsung|samsclub|salon|sale|sakura|safety|safe|saarland|ryukyu|rwe|run|ruhr|rugby|rsvp|room|rogers|rodeo|rocks|rocher|rmit|rip|rio|ril|rightathome|ricoh|richardli|rich|rexroth|reviews|review|restaurant|rest|republican|report|repair|rentals|rent|ren|reliance|reit|reisen|reise|rehab|redumbrella|redstone|red|recipes|realty|realtor|realestate|read|raid|radio|racing|qvc|quest|quebec|qpon|pwc|pub|prudential|pru|protection|property|properties|promo|progressive|prof|productions|prod|pro|prime|press|praxi|pramerica|post|porn|politie|poker|pohl|pnc|plus|plumbing|playstation|play|place|pizza|pioneer|pink|ping|pin|pid|pictures|pictet|pics|piaget|physio|photos|photography|photo|phone|philips|phd|pharmacy|pfizer|pet|pccw|pay|passagens|party|parts|partners|pars|paris|panerai|panasonic|pamperedchef|page|ovh|ott|otsuka|osaka|origins|orientexpress|organic|org|orange|oracle|open|ooo|onyourside|online|onl|ong|one|omega|ollo|oldnavy|olayangroup|olayan|okinawa|office|off|observer|obi|nyc|ntt|nrw|nra|nowtv|nowruz|now|norton|northwesternmutual|nokia|nissay|nissan|ninja|nikon|nike|nico|nhk|ngo|nfl|nexus|nextdirect|next|news|newholland|new|neustar|network|netflix|netbank|net|nec|nba|navy|natura|nationwide|name|nagoya|nadex|nab|mutuelle|mutual|museum|mtr|mtpc|mtn|msd|movistar|movie|mov|motorcycles|moto|moscow|mortgage|mormon|mopar|montblanc|monster|money|monash|mom|moi|moe|moda|mobily|mobile|mobi|mma|mls|mlb|mitsubishi|mit|mint|mini|mil|microsoft|miami|metlife|merckmsd|meo|menu|men|memorial|meme|melbourne|meet|media|med|mckinsey|mcdonalds|mcd|mba|mattel|maserati|marshalls|marriott|markets|marketing|market|map|mango|management|man|makeup|maison|maif|madrid|macys|luxury|luxe|lupin|lundbeck|ltda|ltd|lplfinancial|lpl|love|lotto|lotte|london|lol|loft|locus|locker|loans|loan|llp|llc|lixil|living|live|lipsy|link|linde|lincoln|limo|limited|lilly|like|lighting|lifestyle|lifeinsurance|life|lidl|liaison|lgbt|lexus|lego|legal|lefrak|leclerc|lease|lds|lawyer|law|latrobe|latino|lat|lasalle|lanxess|landrover|land|lancome|lancia|lancaster|lamer|lamborghini|ladbrokes|lacaixa|kyoto|kuokgroup|kred|krd|kpn|kpmg|kosher|komatsu|koeln|kiwi|kitchen|kindle|kinder|kim|kia|kfh|kerryproperties|kerrylogistics|kerryhotels|kddi|kaufen|juniper|juegos|jprs|jpmorgan|joy|jot|joburg|jobs|jnj|jmp|jll|jlc|jio|jewelry|jetzt|jeep|jcp|jcb|java|jaguar|iwc|iveco|itv|itau|istanbul|ist|ismaili|iselect|irish|ipiranga|investments|intuit|international|intel|int|insure|insurance|institute|ink|ing|info|infiniti|industries|inc|immobilien|immo|imdb|imamat|ikano|iinet|ifm|ieee|icu|ice|icbc|ibm|hyundai|hyatt|hughes|htc|hsbc|how|house|hotmail|hotels|hoteles|hot|hosting|host|hospital|horse|honeywell|honda|homesense|homes|homegoods|homedepot|holiday|holdings|hockey|hkt|hiv|hitachi|hisamitsu|hiphop|hgtv|hermes|here|helsinki|help|healthcare|health|hdfcbank|hdfc|hbo|haus|hangout|hamburg|hair|guru|guitars|guide|guge|gucci|guardian|group|grocery|gripe|green|gratis|graphics|grainger|gov|got|gop|google|goog|goodyear|goodhands|goo|golf|goldpoint|gold|godaddy|gmx|gmo|gmbh|gmail|globo|global|gle|glass|glade|giving|gives|gifts|gift|ggee|george|genting|gent|gea|gdn|gbiz|gay|garden|gap|games|game|gallup|gallo|gallery|gal|fyi|futbol|furniture|fund|fun|fujixerox|fujitsu|ftr|frontier|frontdoor|frogans|frl|fresenius|free|fox|foundation|forum|forsale|forex|ford|football|foodnetwork|food|foo|fly|flsmidth|flowers|florist|flir|flights|flickr|fitness|fit|fishing|fish|firmdale|firestone|fire|financial|finance|final|film|fido|fidelity|fiat|ferrero|ferrari|feedback|fedex|fast|fashion|farmers|farm|fans|fan|family|faith|fairwinds|fail|fage|extraspace|express|exposed|expert|exchange|everbank|events|eus|eurovision|etisalat|esurance|estate|esq|erni|ericsson|equipment|epson|epost|enterprises|engineering|engineer|energy|emerck|email|education|edu|edeka|eco|eat|earth|dvr|dvag|durban|dupont|duns|dunlop|duck|dubai|dtv|drive|download|dot|doosan|domains|doha|dog|dodge|doctor|docs|dnp|diy|dish|discover|discount|directory|direct|digital|diet|diamonds|dhl|dev|design|desi|dentist|dental|democrat|delta|deloitte|dell|delivery|degree|deals|dealer|deal|dds|dclk|day|datsun|dating|date|data|dance|dad|dabur|cyou|cymru|cuisinella|csc|cruises|cruise|crs|crown|cricket|creditunion|creditcard|credit|cpa|courses|coupons|coupon|country|corsica|coop|cool|cookingchannel|cooking|contractors|contact|consulting|construction|condos|comsec|computer|compare|company|community|commbank|comcast|com|cologne|college|coffee|codes|coach|clubmed|club|cloud|clothing|clinique|clinic|click|cleaning|claims|cityeats|city|citic|citi|citadel|cisco|circle|cipriani|church|chrysler|chrome|christmas|chloe|chintai|cheap|chat|chase|charity|channel|chanel|cfd|cfa|cern|ceo|center|ceb|cbs|cbre|cbn|cba|catholic|catering|cat|casino|cash|caseih|case|casa|cartier|cars|careers|career|care|cards|caravan|car|capitalone|capital|capetown|canon|cancerresearch|camp|camera|cam|calvinklein|call|cal|cafe|cab|bzh|buzz|buy|business|builders|build|bugatti|budapest|brussels|brother|broker|broadway|bridgestone|bradesco|box|boutique|bot|boston|bostik|bosch|boots|booking|book|boo|bond|bom|bofa|boehringer|boats|bnpparibas|bnl|bmw|bms|blue|bloomberg|blog|blockbuster|blanco|blackfriday|black|biz|bio|bingo|bing|bike|bid|bible|bharti|bet|bestbuy|best|berlin|bentley|beer|beauty|beats|bcn|bcg|bbva|bbt|bbc|bayern|bauhaus|basketball|baseball|bargains|barefoot|barclays|barclaycard|barcelona|bar|bank|band|bananarepublic|banamex|baidu|baby|azure|axa|aws|avianca|autos|auto|author|auspost|audio|audible|audi|auction|attorney|athleta|associates|asia|asda|arte|art|arpa|army|archi|aramco|arab|aquarelle|apple|app|apartments|aol|anz|anquan|android|analytics|amsterdam|amica|amfam|amex|americanfamily|americanexpress|alstom|alsace|ally|allstate|allfinanz|alipay|alibaba|alfaromeo|akdn|airtel|airforce|airbus|aigo|aig|agency|agakhan|africa|afl|afamilycompany|aetna|aero|aeg|adult|ads|adac|actor|active|aco|accountants|accountant|accenture|academy|abudhabi|abogado|able|abc|abbvie|abbott|abb|abarth|aarp|aaa|onion)(?=[^0-9a-zA-Z@+-]|$))")),nT=/(?:xn--[\-0-9a-z]+)/,Sz=Mt(/(?:(?:#{validDomainChars}(?:[_-]|#{validDomainChars})*)?#{validDomainChars}\.)/,{validDomainChars:eT}),Ez=Mt(/(?:#{validSubdomain}*#{validDomainName}(?:#{validGTLD}|#{validCCTLD}|#{validPunycode}))/,{validDomainName:kz,validSubdomain:Sz,validGTLD:tT,validCCTLD:Q2,validPunycode:nT}),Nz=/[0-9]+/,rT=/\u0400-\u04FF/,lf=/\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u024F\u0253\u0254\u0256\u0257\u0259\u025B\u0263\u0268\u026F\u0272\u0289\u028B\u02BB\u0300-\u036F\u1E00-\u1EFF/,sT=Mt(/[a-z#{cyrillicLettersAndMarks}0-9!\*';:=\+,\.\$\/%#\[\]\-\u2013_~@\|&#{latinAccentChars}]/i,{cyrillicLettersAndMarks:rT,latinAccentChars:lf}),iT=Mt("\\((?:#{validGeneralUrlPathChars}+|(?:#{validGeneralUrlPathChars}*\\(#{validGeneralUrlPathChars}+\\)#{validGeneralUrlPathChars}*))\\)",{validGeneralUrlPathChars:sT},"i"),Cz=Mt(/[\+\-a-z#{cyrillicLettersAndMarks}0-9=_#\/#{latinAccentChars}]|(?:#{validUrlBalancedParens})/i,{cyrillicLettersAndMarks:rT,latinAccentChars:lf,validUrlBalancedParens:iT}),_z=Mt("(?:(?:#{validGeneralUrlPathChars}*(?:#{validUrlBalancedParens}#{validGeneralUrlPathChars}*)*#{validUrlPathEndingChars})|(?:@#{validGeneralUrlPathChars}+/))",{validGeneralUrlPathChars:sT,validUrlBalancedParens:iT,validUrlPathEndingChars:Cz},"i"),Tz=Mt(/(?:[^A-Za-z0-9@@$###{invalidCharsGroup}]|[#{directionalMarkersGroup}]|^)/,{invalidCharsGroup:by,directionalMarkersGroup:Z2}),oT=/[a-z0-9!?\*'@\(\);:&=\+\$\/%#\[\]\-_\.,~|]/i,aT=/[a-z0-9\-_&=#\/]/i,H1=Mt("((#{validUrlPrecedingChars})((https?:\\/\\/)?(#{validDomain})(?::(#{validPortNumber}))?(\\/#{validUrlPath}*)?(\\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?))",{validUrlPrecedingChars:Tz,validDomain:Ez,validPortNumber:Nz,validUrlPath:_z,validUrlQueryChars:oT,validUrlQueryEndingChars:aT},"gi"),jz=/[-_.\/]$/,W1={},Om,q1;function Mz(){if(q1)return Om;q1=1;var t=Cr(),e=sf(),n=Dn()("species");return Om=function(r,s){var i=t(r).constructor,o;return i===void 0||(o=t(i)[n])==null?s:e(o)},Om}var V1;function Az(){if(V1)return W1;V1=1;var t=G2(),e=Cr(),n=Mz(),r=ly(),s=mo(),i=uy(),o=dy(),l=rs(),d=Math.min,f=[].push,h="split",m="length",g="lastIndex",v=4294967295,b=!l(function(){});return hy()("split",2,function(k,w,E,C){var T;return"abbc"[h](/(b)*/)[1]=="c"||"test"[h](/(?:)/,-1)[m]!=4||"ab"[h](/(?:ab)*/)[m]!=2||"."[h](/(.?)(.?)/)[m]!=4||"."[h](/()()/)[m]>1||""[h](/.?/)[m]?T=function(j,_){var A=String(this);if(j===void 0&&_===0)return[];if(!t(j))return E.call(A,j,_);for(var O=[],B=(j.ignoreCase?"i":"")+(j.multiline?"m":"")+(j.unicode?"u":"")+(j.sticky?"y":""),$=0,W=_===void 0?v:_>>>0,J=new RegExp(j.source,B+"g"),z,G,D;(z=o.call(J,A))&&(G=J[g],!(G>$&&(O.push(A.slice($,z.index)),z[m]>1&&z.index<A[m]&&f.apply(O,z.slice(1)),D=z[0][m],$=G,O[m]>=W)));)J[g]===z.index&&J[g]++;return $===A[m]?(D||!J.test(""))&&O.push(""):O.push(A.slice($)),O[m]>W?O.slice(0,W):O}:"0"[h](void 0,0)[m]?T=function(j,_){return j===void 0&&_===0?[]:E.call(this,j,_)}:T=E,[function(_,A){var O=k(this),B=_==null?void 0:_[w];return B!==void 0?B.call(_,O,A):T.call(String(O),_,A)},function(j,_){var A=C(T,j,this,_,T!==E);if(A.done)return A.value;var O=e(j),B=String(this),$=n(O,RegExp),W=O.unicode,J=(O.ignoreCase?"i":"")+(O.multiline?"m":"")+(O.unicode?"u":"")+(b?"y":"g"),z=new $(b?O:"^(?:"+O.source+")",J),G=_===void 0?v:_>>>0;if(G===0)return[];if(B.length===0)return i(z,B)===null?[B]:[];for(var D=0,U=0,q=[];U<B.length;){z.lastIndex=b?U:0;var se=i(z,b?B:B.slice(U)),V;if(se===null||(V=d(s(z.lastIndex+(b?0:U)),B.length))===D)U=r(B,U,W);else{if(q.push(B.slice(D,U)),q.length===G)return q;for(var te=1;te<=se.length-1;te++)if(q.push(se[te]),q.length===G)return q;U=D=V}}return q.push(B.slice(D)),q}]}),W1}Az();var sl={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */var Rz=sl.exports,K1;function Oz(){return K1||(K1=1,(function(t,e){(function(n){var r=e&&!e.nodeType&&e,s=t&&!t.nodeType&&t,i=typeof F0=="object"&&F0;(i.global===i||i.window===i||i.self===i)&&(n=i);var o,l=2147483647,d=36,f=1,h=26,m=38,g=700,v=72,b=128,k="-",w=/^xn--/,E=/[^\x20-\x7E]/,C=/[\x2E\u3002\uFF0E\uFF61]/g,T={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},j=d-f,_=Math.floor,A=String.fromCharCode,O;function B(K){throw new RangeError(T[K])}function $(K,M){for(var L=K.length,ee=[];L--;)ee[L]=M(K[L]);return ee}function W(K,M){var L=K.split("@"),ee="";L.length>1&&(ee=L[0]+"@",K=L[1]),K=K.replace(C,".");var fe=K.split("."),ge=$(fe,M).join(".");return ee+ge}function J(K){for(var M=[],L=0,ee=K.length,fe,ge;L<ee;)fe=K.charCodeAt(L++),fe>=55296&&fe<=56319&&L<ee?(ge=K.charCodeAt(L++),(ge&64512)==56320?M.push(((fe&1023)<<10)+(ge&1023)+65536):(M.push(fe),L--)):M.push(fe);return M}function z(K){return $(K,function(M){var L="";return M>65535&&(M-=65536,L+=A(M>>>10&1023|55296),M=56320|M&1023),L+=A(M),L}).join("")}function G(K){return K-48<10?K-22:K-65<26?K-65:K-97<26?K-97:d}function D(K,M){return K+22+75*(K<26)-((M!=0)<<5)}function U(K,M,L){var ee=0;for(K=L?_(K/g):K>>1,K+=_(K/M);K>j*h>>1;ee+=d)K=_(K/j);return _(ee+(j+1)*K/(K+m))}function q(K){var M=[],L=K.length,ee,fe=0,ge=b,oe=v,xe,we,We,He,Ze,Oe,Ke,pt,Je;for(xe=K.lastIndexOf(k),xe<0&&(xe=0),we=0;we<xe;++we)K.charCodeAt(we)>=128&&B("not-basic"),M.push(K.charCodeAt(we));for(We=xe>0?xe+1:0;We<L;){for(He=fe,Ze=1,Oe=d;We>=L&&B("invalid-input"),Ke=G(K.charCodeAt(We++)),(Ke>=d||Ke>_((l-fe)/Ze))&&B("overflow"),fe+=Ke*Ze,pt=Oe<=oe?f:Oe>=oe+h?h:Oe-oe,!(Ke<pt);Oe+=d)Je=d-pt,Ze>_(l/Je)&&B("overflow"),Ze*=Je;ee=M.length+1,oe=U(fe-He,ee,He==0),_(fe/ee)>l-ge&&B("overflow"),ge+=_(fe/ee),fe%=ee,M.splice(fe++,0,ge)}return z(M)}function se(K){var M,L,ee,fe,ge,oe,xe,we,We,He,Ze,Oe=[],Ke,pt,Je,pe;for(K=J(K),Ke=K.length,M=b,L=0,ge=v,oe=0;oe<Ke;++oe)Ze=K[oe],Ze<128&&Oe.push(A(Ze));for(ee=fe=Oe.length,fe&&Oe.push(k);ee<Ke;){for(xe=l,oe=0;oe<Ke;++oe)Ze=K[oe],Ze>=M&&Ze<xe&&(xe=Ze);for(pt=ee+1,xe-M>_((l-L)/pt)&&B("overflow"),L+=(xe-M)*pt,M=xe,oe=0;oe<Ke;++oe)if(Ze=K[oe],Ze<M&&++L>l&&B("overflow"),Ze==M){for(we=L,We=d;He=We<=ge?f:We>=ge+h?h:We-ge,!(we<He);We+=d)pe=we-He,Je=d-He,Oe.push(A(D(He+pe%Je,0))),we=_(pe/Je);Oe.push(A(D(we,0))),ge=U(L,pt,ee==fe),L=0,++ee}++L,++M}return Oe.join("")}function V(K){return W(K,function(M){return w.test(M)?q(M.slice(4).toLowerCase()):M})}function te(K){return W(K,function(M){return E.test(M)?"xn--"+se(M):M})}if(o={version:"1.4.1",ucs2:{decode:J,encode:z},decode:q,encode:se,toASCII:te,toUnicode:V},r&&s)if(t.exports==r)s.exports=o;else for(O in o)o.hasOwnProperty(O)&&(r[O]=o[O]);else n.punycode=o})(Rz)})(sl,sl.exports)),sl.exports}var Iz=Oz();const Lz=jl(Iz);var lT=Mt(/(?:(?:[\-a-z0-9#{latinAccentChars}]+)\.)+(?:#{validGTLD}|#{validCCTLD}|#{validPunycode})/gi,{latinAccentChars:lf,validGTLD:tT,validCCTLD:Q2,validPunycode:nT}),Dz=63,Pz="xn--",Bz={toAscii:function(e){if(!(e.substring(0,4)===Pz&&!e.match(lT))){for(var n=e.split("."),r=0;r<n.length;r++){var s=n[r],i=Lz.toASCII(s);if(i.length<1||i.length>Dz)return}return n.join(".")}}},$z=Mt(/^https?:\/\/t\.co\/([a-z0-9]+)(?:\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?/,{validUrlQueryChars:oT,validUrlQueryEndingChars:aT},"i"),zz="https://",Fz={extractUrlsWithoutProtocol:!0},Uz=4096,Hz=40,Wz=function(e){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Fz;if(!e||(n.extractUrlsWithoutProtocol?!e.match(/\./):!e.match(/:/)))return[];for(var r=[],s=function(){var l=RegExp.$2,d=RegExp.$3,f=RegExp.$4,h=RegExp.$5,m=RegExp.$7,g=H1.lastIndex,v=g-d.length;if(!qz(d,f||zz,h))return"continue";if(f){if(d.match($z)){var w=RegExp.$1;if(w&&w.length>Hz)return"continue";d=RegExp.lastMatch,g=v+d.length}r.push({url:d,indices:[v,g]})}else{if(!n.extractUrlsWithoutProtocol||l.match(jz))return"continue";var b=null,k=0;if(h.replace(lT,function(E){var C=h.indexOf(E,k);k=C+E.length,b={url:E,indices:[v+C,v+k]},r.push(b)}),b==null)return"continue";m&&(b.url=d.replace(h,b.url),b.indices[1]=g)}};H1.exec(e);)var i=s();return r},qz=function(e,n,r){var s=e.length,i=Bz.toAscii(r);return!i||!i.length?!1:(s=s+i.length-r.length,n.length+s<=Uz)},G1={},J1;function Vz(){if(J1)return G1;J1=1;var t=vr(),e=sf(),n=ji(),r=rs(),s=[].sort,i=[1,2,3];return t(t.P+t.F*(r(function(){i.sort(void 0)})||!r(function(){i.sort(null)})||!$l()(s)),"Array",{sort:function(l){return l===void 0?s.call(n(this)):s.call(n(this),e(l))}}),G1}Vz();var cT=/\ud800[\udc00-\udc0b\udc0d-\udc26\udc28-\udc3a\udc3c\udc3d\udc3f-\udc4d\udc50-\udc5d\udc80-\udcfa\uddfd\ude80-\ude9c\udea0-\uded0\udee0\udf00-\udf1f\udf30-\udf40\udf42-\udf49\udf50-\udf7a\udf80-\udf9d\udfa0-\udfc3\udfc8-\udfcf]|\ud801[\udc00-\udc9d\udd00-\udd27\udd30-\udd63\ude00-\udf36\udf40-\udf55\udf60-\udf67]|\ud802[\udc00-\udc05\udc08\udc0a-\udc35\udc37\udc38\udc3c\udc3f-\udc55\udc60-\udc76\udc80-\udc9e\udd00-\udd15\udd20-\udd39\udd80-\uddb7\uddbe\uddbf\ude00-\ude03\ude05\ude06\ude0c-\ude13\ude15-\ude17\ude19-\ude33\ude38-\ude3a\ude3f\ude60-\ude7c\ude80-\ude9c\udec0-\udec7\udec9-\udee6\udf00-\udf35\udf40-\udf55\udf60-\udf72\udf80-\udf91]|\ud803[\udc00-\udc48]|\ud804[\udc00-\udc46\udc7f-\udcba\udcd0-\udce8\udd00-\udd34\udd50-\udd73\udd76\udd80-\uddc4\uddda\ude00-\ude11\ude13-\ude37\udeb0-\udeea\udf01-\udf03\udf05-\udf0c\udf0f\udf10\udf13-\udf28\udf2a-\udf30\udf32\udf33\udf35-\udf39\udf3c-\udf44\udf47\udf48\udf4b-\udf4d\udf57\udf5d-\udf63\udf66-\udf6c\udf70-\udf74]|\ud805[\udc80-\udcc5\udcc7\udd80-\uddb5\uddb8-\uddc0\ude00-\ude40\ude44\ude80-\udeb7]|\ud806[\udca0-\udcdf\udcff\udec0-\udef8]|\ud808[\udc00-\udf98]|\ud80c[\udc00-\udfff]|\ud80d[\udc00-\udc2e]|\ud81a[\udc00-\ude38\ude40-\ude5e\uded0-\udeed\udef0-\udef4\udf00-\udf36\udf40-\udf43\udf63-\udf77\udf7d-\udf8f]|\ud81b[\udf00-\udf44\udf50-\udf7e\udf8f-\udf9f]|\ud82c[\udc00\udc01]|\ud82f[\udc00-\udc6a\udc70-\udc7c\udc80-\udc88\udc90-\udc99\udc9d\udc9e]|\ud834[\udd65-\udd69\udd6d-\udd72\udd7b-\udd82\udd85-\udd8b\uddaa-\uddad\ude42-\ude44]|\ud835[\udc00-\udc54\udc56-\udc9c\udc9e\udc9f\udca2\udca5\udca6\udca9-\udcac\udcae-\udcb9\udcbb\udcbd-\udcc3\udcc5-\udd05\udd07-\udd0a\udd0d-\udd14\udd16-\udd1c\udd1e-\udd39\udd3b-\udd3e\udd40-\udd44\udd46\udd4a-\udd50\udd52-\udea5\udea8-\udec0\udec2-\udeda\udedc-\udefa\udefc-\udf14\udf16-\udf34\udf36-\udf4e\udf50-\udf6e\udf70-\udf88\udf8a-\udfa8\udfaa-\udfc2\udfc4-\udfcb]|\ud83a[\udc00-\udcc4\udcd0-\udcd6]|\ud83b[\ude00-\ude03\ude05-\ude1f\ude21\ude22\ude24\ude27\ude29-\ude32\ude34-\ude37\ude39\ude3b\ude42\ude47\ude49\ude4b\ude4d-\ude4f\ude51\ude52\ude54\ude57\ude59\ude5b\ude5d\ude5f\ude61\ude62\ude64\ude67-\ude6a\ude6c-\ude72\ude74-\ude77\ude79-\ude7c\ude7e\ude80-\ude89\ude8b-\ude9b\udea1-\udea3\udea5-\udea9\udeab-\udebb]|\ud840[\udc00-\udfff]|\ud841[\udc00-\udfff]|\ud842[\udc00-\udfff]|\ud843[\udc00-\udfff]|\ud844[\udc00-\udfff]|\ud845[\udc00-\udfff]|\ud846[\udc00-\udfff]|\ud847[\udc00-\udfff]|\ud848[\udc00-\udfff]|\ud849[\udc00-\udfff]|\ud84a[\udc00-\udfff]|\ud84b[\udc00-\udfff]|\ud84c[\udc00-\udfff]|\ud84d[\udc00-\udfff]|\ud84e[\udc00-\udfff]|\ud84f[\udc00-\udfff]|\ud850[\udc00-\udfff]|\ud851[\udc00-\udfff]|\ud852[\udc00-\udfff]|\ud853[\udc00-\udfff]|\ud854[\udc00-\udfff]|\ud855[\udc00-\udfff]|\ud856[\udc00-\udfff]|\ud857[\udc00-\udfff]|\ud858[\udc00-\udfff]|\ud859[\udc00-\udfff]|\ud85a[\udc00-\udfff]|\ud85b[\udc00-\udfff]|\ud85c[\udc00-\udfff]|\ud85d[\udc00-\udfff]|\ud85e[\udc00-\udfff]|\ud85f[\udc00-\udfff]|\ud860[\udc00-\udfff]|\ud861[\udc00-\udfff]|\ud862[\udc00-\udfff]|\ud863[\udc00-\udfff]|\ud864[\udc00-\udfff]|\ud865[\udc00-\udfff]|\ud866[\udc00-\udfff]|\ud867[\udc00-\udfff]|\ud868[\udc00-\udfff]|\ud869[\udc00-\uded6\udf00-\udfff]|\ud86a[\udc00-\udfff]|\ud86b[\udc00-\udfff]|\ud86c[\udc00-\udfff]|\ud86d[\udc00-\udf34\udf40-\udfff]|\ud86e[\udc00-\udc1d]|\ud87e[\udc00-\ude1d]|\udb40[\udd00-\uddef]/,uT=/A-Za-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0300-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u0483-\u052f\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u05d0-\u05ea\u05f0-\u05f2\u0610-\u061a\u0620-\u065f\u066e-\u06d3\u06d5-\u06dc\u06df-\u06e8\u06ea-\u06ef\u06fa-\u06fc\u06ff\u0710-\u074a\u074d-\u07b1\u07ca-\u07f5\u07fa\u0800-\u082d\u0840-\u085b\u08a0-\u08b2\u08e4-\u0963\u0971-\u0983\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bc-\u09c4\u09c7\u09c8\u09cb-\u09ce\u09d7\u09dc\u09dd\u09df-\u09e3\u09f0\u09f1\u0a01-\u0a03\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a59-\u0a5c\u0a5e\u0a70-\u0a75\u0a81-\u0a83\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abc-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ad0\u0ae0-\u0ae3\u0b01-\u0b03\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3c-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5c\u0b5d\u0b5f-\u0b63\u0b71\u0b82\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd0\u0bd7\u0c00-\u0c03\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c58\u0c59\u0c60-\u0c63\u0c81-\u0c83\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbc-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0cde\u0ce0-\u0ce3\u0cf1\u0cf2\u0d01-\u0d03\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d-\u0d44\u0d46-\u0d48\u0d4a-\u0d4e\u0d57\u0d60-\u0d63\u0d7a-\u0d7f\u0d82\u0d83\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e01-\u0e3a\u0e40-\u0e4e\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb9\u0ebb-\u0ebd\u0ec0-\u0ec4\u0ec6\u0ec8-\u0ecd\u0edc-\u0edf\u0f00\u0f18\u0f19\u0f35\u0f37\u0f39\u0f3e-\u0f47\u0f49-\u0f6c\u0f71-\u0f84\u0f86-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u103f\u1050-\u108f\u109a-\u109d\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u135d-\u135f\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16f1-\u16f8\u1700-\u170c\u170e-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176c\u176e-\u1770\u1772\u1773\u1780-\u17d3\u17d7\u17dc\u17dd\u180b-\u180d\u1820-\u1877\u1880-\u18aa\u18b0-\u18f5\u1900-\u191e\u1920-\u192b\u1930-\u193b\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a1b\u1a20-\u1a5e\u1a60-\u1a7c\u1a7f\u1aa7\u1ab0-\u1abe\u1b00-\u1b4b\u1b6b-\u1b73\u1b80-\u1baf\u1bba-\u1bf3\u1c00-\u1c37\u1c4d-\u1c4f\u1c5a-\u1c7d\u1cd0-\u1cd2\u1cd4-\u1cf6\u1cf8\u1cf9\u1d00-\u1df5\u1dfc-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u20d0-\u20f0\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2183\u2184\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d7f-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2de0-\u2dff\u2e2f\u3005\u3006\u302a-\u302f\u3031-\u3035\u303b\u303c\u3041-\u3096\u3099\u309a\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua672\ua674-\ua67d\ua67f-\ua69d\ua69f-\ua6e5\ua6f0\ua6f1\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua7ad\ua7b0\ua7b1\ua7f7-\ua827\ua840-\ua873\ua880-\ua8c4\ua8e0-\ua8f7\ua8fb\ua90a-\ua92d\ua930-\ua953\ua960-\ua97c\ua980-\ua9c0\ua9cf\ua9e0-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa36\uaa40-\uaa4d\uaa60-\uaa76\uaa7a-\uaac2\uaadb-\uaadd\uaae0-\uaaef\uaaf2-\uaaf6\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab5f\uab64\uab65\uabc0-\uabea\uabec\uabed\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf870-\uf87f\uf882\uf884-\uf89f\uf8b8\uf8c1-\uf8d6\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe00-\ufe0f\ufe20-\ufe2d\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc/,dT=/[\uD800-\uDBFF][\uDC00-\uDFFF]/gm,Kz=Mt(/(?:[#{bmpLetterAndMarks}]|(?=#{nonBmpCodePairs})(?:#{astralLetterAndMarks}))/,{bmpLetterAndMarks:uT,nonBmpCodePairs:dT,astralLetterAndMarks:cT}),Gz=/\ud801[\udca0-\udca9]|\ud804[\udc66-\udc6f\udcf0-\udcf9\udd36-\udd3f\uddd0-\uddd9\udef0-\udef9]|\ud805[\udcd0-\udcd9\ude50-\ude59\udec0-\udec9]|\ud806[\udce0-\udce9]|\ud81a[\ude60-\ude69\udf50-\udf59]|\ud835[\udfce-\udfff]/,Jz=/0-9\u0660-\u0669\u06f0-\u06f9\u07c0-\u07c9\u0966-\u096f\u09e6-\u09ef\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be6-\u0bef\u0c66-\u0c6f\u0ce6-\u0cef\u0d66-\u0d6f\u0de6-\u0def\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29\u1040-\u1049\u1090-\u1099\u17e0-\u17e9\u1810-\u1819\u1946-\u194f\u19d0-\u19d9\u1a80-\u1a89\u1a90-\u1a99\u1b50-\u1b59\u1bb0-\u1bb9\u1c40-\u1c49\u1c50-\u1c59\ua620-\ua629\ua8d0-\ua8d9\ua900-\ua909\ua9d0-\ua9d9\ua9f0-\ua9f9\uaa50-\uaa59\uabf0-\uabf9\uff10-\uff19/,Yz=/_\u200c\u200d\ua67e\u05be\u05f3\u05f4\uff5e\u301c\u309b\u309c\u30a0\u30fb\u3003\u0f0b\u0f0c\xb7/,fT=Mt(/(?:[#{bmpLetterAndMarks}#{bmpNumerals}#{hashtagSpecialChars}]|(?=#{nonBmpCodePairs})(?:#{astralLetterAndMarks}|#{astralNumerals}))/,{bmpLetterAndMarks:uT,bmpNumerals:Jz,hashtagSpecialChars:Yz,nonBmpCodePairs:dT,astralLetterAndMarks:cT,astralNumerals:Gz}),Xz=/(?:[^\uD800-\uDFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF])/,Qz=Mt(/(?:^|\uFE0E|\uFE0F|$|(?!#{hashtagAlphaNumeric}|&)#{codePoint})/,{codePoint:Xz,hashtagAlphaNumeric:fT});Mt(/(#{hashtagBoundary})(#{hashSigns})(?!\uFE0F|\u20E3)(#{hashtagAlphaNumeric}*#{hashtagAlpha}#{hashtagAlphaNumeric}*)/gi,{hashtagBoundary:Qz,hashSigns:X2,hashtagAlphaNumeric:fT,hashtagAlpha:Kz});var xy=/[@@]/;Mt(/^(?:#{atSigns}|[#{latinAccentChars}]|:\/\/)/,{atSigns:xy,latinAccentChars:lf});var Zz=/(?:^|[^a-zA-Z0-9_!#$%&*@@]|(?:^|[^a-zA-Z0-9_+~.-])(?:rt|RT|rT|Rt):?)/,eF=Mt("(#{validMentionPrecedingChars})(#{atSigns})([a-zA-Z0-9_]{1,20})(/[a-zA-Z][a-zA-Z0-9_-]{0,24})?",{validMentionPrecedingChars:Zz,atSigns:xy},"g"),Y1={},X1={},Q1;function tF(){return Q1||(Q1=1,Hr()&&/./g.flags!="g"&&ss().f(RegExp.prototype,"flags",{configurable:!0,get:rf()})),X1}var Z1;function nF(){if(Z1)return Y1;Z1=1,tF();var t=Cr(),e=rf(),n=Hr(),r="toString",s=/./[r],i=function(o){zs()(RegExp.prototype,r,o,!0)};return rs()(function(){return s.call({source:"a",flags:"b"})!="/a/b"})?i(function(){var l=t(this);return"/".concat(l.source,"/","flags"in l?l.flags:!n&&l instanceof RegExp?e.call(l):void 0)}):s.name!=r&&i(function(){return s.call(this)}),Y1}nF();var eS={},tS;function rF(){if(tS)return eS;tS=1;var t=Date.prototype,e="Invalid Date",n="toString",r=t[n],s=t.getTime;return new Date(NaN)+""!=e&&zs()(t,n,function(){var o=s.call(this);return o===o?r.call(this):e}),eS}rF();var nS={},rS;function sF(){if(rS)return nS;rS=1;var t=cy(),e={};return e[Dn()("toStringTag")]="z",e+""!="[object z]"&&zs()(Object.prototype,"toString",function(){return"[object "+t(this)+"]"},!0),nS}sF();const sS={defaults:{version:3,maxWeightedTweetLength:280,scale:100,defaultWeight:200,emojiParsingEnabled:!0,transformedURLLength:23,ranges:[{start:0,end:4351,weight:100},{start:8192,end:8205,weight:100},{start:8208,end:8223,weight:100},{start:8242,end:8247,weight:100}]}};Mt(/^(?:#{spaces})*#{atSigns}([a-zA-Z0-9_]{1,20})/,{atSigns:xy,spaces:Y2});var iS={},Im,oS;function wy(){if(oS)return Im;oS=1;var t=ef();return Im=Array.isArray||function(n){return t(n)=="Array"},Im}var aS;function iF(){if(aS)return iS;aS=1;var t=vr();return t(t.S,"Array",{isArray:wy()}),iS}iF();var oF=function(e,n){var r=n.defaultWeight,s=n.ranges,i=r,o=e.charCodeAt(0);if(Array.isArray(s))for(var l=0,d=s.length;l<d;l++){var f=s[l];if(o>=f.start&&o<=f.end){i=f.weight;break}}return i},lS={},Lm,cS;function aF(){if(cS)return Lm;cS=1;var t=sf(),e=ji(),n=py(),r=mo();return Lm=function(s,i,o,l,d){t(i);var f=e(s),h=n(f),m=r(f.length),g=d?m-1:0,v=d?-1:1;if(o<2)for(;;){if(g in h){l=h[g],g+=v;break}if(g+=v,d?g<0:m<=g)throw TypeError("Reduce of empty array with no initial value")}for(;d?g>=0:m>g;g+=v)g in h&&(l=i(l,h[g],g,f));return l},Lm}var uS;function lF(){if(uS)return lS;uS=1;var t=vr(),e=aF();return t(t.P+t.F*!$l()([].reduce,!0),"Array",{reduce:function(r){return e(this,r,arguments.length,arguments[1],!1)}}),lS}lF();var dS={},Dm,fS;function cF(){if(fS)return Dm;fS=1;var t=Dn()("unscopables"),e=Array.prototype;return e[t]==null&&Mi()(e,t,{}),Dm=function(n){e[t][n]=!0},Dm}var Pm,hS;function uF(){return hS||(hS=1,Pm=function(t,e){return{value:e,done:!!t}}),Pm}var Bm,pS;function zl(){return pS||(pS=1,Bm={}),Bm}var $m,mS;function Fl(){if(mS)return $m;mS=1;var t=K2(),e=yy();return $m=Object.keys||function(r){return t(r,e)},$m}var zm,gS;function hT(){if(gS)return zm;gS=1;var t=ss(),e=Cr(),n=Fl();return zm=Hr()?Object.defineProperties:function(s,i){e(s);for(var o=n(i),l=o.length,d=0,f;l>d;)t.f(s,f=o[d++],i[f]);return s},zm}var Fm,vS;function dF(){if(vS)return Fm;vS=1;var t=Ur().document;return Fm=t&&t.documentElement,Fm}var Um,yS;function pT(){if(yS)return Um;yS=1;var t=Cr(),e=hT(),n=yy(),r=vy()("IE_PROTO"),s=function(){},i="prototype",o=function(){var l=H2()("iframe"),d=n.length,f="<",h=">",m;for(l.style.display="none",dF().appendChild(l),l.src="javascript:",m=l.contentWindow.document,m.open(),m.write(f+"script"+h+"document.F=Object"+f+"/script"+h),m.close(),o=m.F;d--;)delete o[i][n[d]];return o()};return Um=Object.create||function(d,f){var h;return d!==null?(s[i]=t(d),h=new s,s[i]=null,h[r]=d):h=o(),f===void 0?h:e(h,f)},Um}var Hm,bS;function ky(){if(bS)return Hm;bS=1;var t=ss().f,e=go(),n=Dn()("toStringTag");return Hm=function(r,s,i){r&&!e(r=i?r:r.prototype,n)&&t(r,n,{configurable:!0,value:s})},Hm}var Wm,xS;function fF(){if(xS)return Wm;xS=1;var t=pT(),e=Bl(),n=ky(),r={};return Mi()(r,Dn()("iterator"),function(){return this}),Wm=function(s,i,o){s.prototype=t(r,{next:e(1,o)}),n(s,i+" Iterator")},Wm}var qm,wS;function hF(){if(wS)return qm;wS=1;var t=go(),e=ji(),n=vy()("IE_PROTO"),r=Object.prototype;return qm=Object.getPrototypeOf||function(s){return s=e(s),t(s,n)?s[n]:typeof s.constructor=="function"&&s instanceof s.constructor?s.constructor.prototype:s instanceof Object?r:null},qm}var Vm,kS;function mT(){if(kS)return Vm;kS=1;var t=tf(),e=vr(),n=zs(),r=Mi(),s=zl(),i=fF(),o=ky(),l=hF(),d=Dn()("iterator"),f=!([].keys&&"next"in[].keys()),h="@@iterator",m="keys",g="values",v=function(){return this};return Vm=function(b,k,w,E,C,T,j){i(w,k,E);var _=function(se){if(!f&&se in $)return $[se];switch(se){case m:return function(){return new w(this,se)};case g:return function(){return new w(this,se)}}return function(){return new w(this,se)}},A=k+" Iterator",O=C==g,B=!1,$=b.prototype,W=$[d]||$[h]||C&&$[C],J=W||_(C),z=C?O?_("entries"):J:void 0,G=k=="Array"&&$.entries||W,D,U,q;if(G&&(q=l(G.call(new b)),q!==Object.prototype&&q.next&&(o(q,A,!0),!t&&typeof q[d]!="function"&&r(q,d,v))),O&&W&&W.name!==g&&(B=!0,J=function(){return W.call(this)}),(!t||j)&&(f||B||!$[d])&&r($,d,J),s[k]=J,s[A]=v,C)if(D={values:O?J:_(g),keys:T?J:_(m),entries:z},j)for(U in D)U in $||n($,U,D[U]);else e(e.P+e.F*(f||B),k,D);return D},Vm}var Km,SS;function gT(){if(SS)return Km;SS=1;var t=cF(),e=uF(),n=zl(),r=vo();return Km=mT()(Array,"Array",function(s,i){this._t=r(s),this._i=0,this._k=i},function(){var s=this._t,i=this._k,o=this._i++;return!s||o>=s.length?(this._t=void 0,e(1)):i=="keys"?e(0,o):i=="values"?e(0,s[o]):e(0,[o,s[o]])},"values"),n.Arguments=n.Array,t("keys"),t("values"),t("entries"),Km}var ES;function pF(){if(ES)return dS;ES=1;for(var t=gT(),e=Fl(),n=zs(),r=Ur(),s=Mi(),i=zl(),o=Dn(),l=o("iterator"),d=o("toStringTag"),f=i.Array,h={CSSRuleList:!0,CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},m=e(h),g=0;g<m.length;g++){var v=m[g],b=h[v],k=r[v],w=k&&k.prototype,E;if(w&&(w[l]||s(w,l,f),w[d]||s(w,d,v),i[v]=f,b))for(E in t)w[E]||n(w,E,t[E],!0)}return dS}pF();gT();var NS={},Gm,CS;function mF(){if(CS)return Gm;CS=1;var t=vr(),e=fa(),n=rs();return Gm=function(r,s){var i=(e.Object||{})[r]||Object[r],o={};o[r]=s(i),t(t.S+t.F*n(function(){i(1)}),"Object",o)},Gm}var _S;function gF(){if(_S)return NS;_S=1;var t=ji(),e=Fl();return mF()("keys",function(){return function(r){return e(t(r))}}),NS}gF();var vF=Mt(/[#{invalidCharsGroup}]/,{invalidCharsGroup:by});function yF(t){return vF.test(t)}var Gi={},bu={},TS;function bF(){return TS||(TS=1,Object.defineProperty(bu,"__esModule",{value:!0}),bu.default=/(?:\ud83d[\udc68\udc69])(?:\ud83c[\udffb-\udfff])?\u200d(?:\u2695\ufe0f|\u2696\ufe0f|\u2708\ufe0f|\ud83c[\udf3e\udf73\udf93\udfa4\udfa8\udfeb\udfed]|\ud83d[\udcbb\udcbc\udd27\udd2c\ude80\ude92]|\ud83e[\uddb0-\uddb3])|(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75]|\u26f9)((?:\ud83c[\udffb-\udfff]|\ufe0f)\u200d[\u2640\u2642]\ufe0f)|(?:\ud83c[\udfc3\udfc4\udfca]|\ud83d[\udc6e\udc71\udc73\udc77\udc81\udc82\udc86\udc87\ude45-\ude47\ude4b\ude4d\ude4e\udea3\udeb4-\udeb6]|\ud83e[\udd26\udd35\udd37-\udd39\udd3d\udd3e\uddb8\uddb9\uddd6-\udddd])(?:\ud83c[\udffb-\udfff])?\u200d[\u2640\u2642]\ufe0f|(?:\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83c\udff3\ufe0f\u200d\ud83c\udf08|\ud83c\udff4\u200d\u2620\ufe0f|\ud83d\udc41\u200d\ud83d\udde8|\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc6f\u200d\u2640\ufe0f|\ud83d\udc6f\u200d\u2642\ufe0f|\ud83e\udd3c\u200d\u2640\ufe0f|\ud83e\udd3c\u200d\u2642\ufe0f|\ud83e\uddde\u200d\u2640\ufe0f|\ud83e\uddde\u200d\u2642\ufe0f|\ud83e\udddf\u200d\u2640\ufe0f|\ud83e\udddf\u200d\u2642\ufe0f)|[#*0-9]\ufe0f?\u20e3|(?:[©®\u2122\u265f]\ufe0f)|(?:\ud83c[\udc04\udd70\udd71\udd7e\udd7f\ude02\ude1a\ude2f\ude37\udf21\udf24-\udf2c\udf36\udf7d\udf96\udf97\udf99-\udf9b\udf9e\udf9f\udfcd\udfce\udfd4-\udfdf\udff3\udff5\udff7]|\ud83d[\udc3f\udc41\udcfd\udd49\udd4a\udd6f\udd70\udd73\udd76-\udd79\udd87\udd8a-\udd8d\udda5\udda8\uddb1\uddb2\uddbc\uddc2-\uddc4\uddd1-\uddd3\udddc-\uddde\udde1\udde3\udde8\uddef\uddf3\uddfa\udecb\udecd-\udecf\udee0-\udee5\udee9\udef0\udef3]|[\u203c\u2049\u2139\u2194-\u2199\u21a9\u21aa\u231a\u231b\u2328\u23cf\u23ed-\u23ef\u23f1\u23f2\u23f8-\u23fa\u24c2\u25aa\u25ab\u25b6\u25c0\u25fb-\u25fe\u2600-\u2604\u260e\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262a\u262e\u262f\u2638-\u263a\u2640\u2642\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267b\u267f\u2692-\u2697\u2699\u269b\u269c\u26a0\u26a1\u26aa\u26ab\u26b0\u26b1\u26bd\u26be\u26c4\u26c5\u26c8\u26cf\u26d1\u26d3\u26d4\u26e9\u26ea\u26f0-\u26f5\u26f8\u26fa\u26fd\u2702\u2708\u2709\u270f\u2712\u2714\u2716\u271d\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u2764\u27a1\u2934\u2935\u2b05-\u2b07\u2b1b\u2b1c\u2b50\u2b55\u3030\u303d\u3297\u3299])(?:\ufe0f|(?!\ufe0e))|(?:(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75\udd90]|[\u261d\u26f7\u26f9\u270c\u270d])(?:\ufe0f|(?!\ufe0e))|(?:\ud83c[\udf85\udfc2-\udfc4\udfc7\udfca]|\ud83d[\udc42\udc43\udc46-\udc50\udc66-\udc69\udc6e\udc70-\udc78\udc7c\udc81-\udc83\udc85-\udc87\udcaa\udd7a\udd95\udd96\ude45-\ude47\ude4b-\ude4f\udea3\udeb4-\udeb6\udec0\udecc]|\ud83e[\udd18-\udd1c\udd1e\udd1f\udd26\udd30-\udd39\udd3d\udd3e\uddb5\uddb6\uddb8\uddb9\uddd1-\udddd]|[\u270a\u270b]))(?:\ud83c[\udffb-\udfff])?|(?:\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc65\udb40\udc6e\udb40\udc67\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc73\udb40\udc63\udb40\udc74\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc77\udb40\udc6c\udb40\udc73\udb40\udc7f|\ud83c\udde6\ud83c[\udde8-\uddec\uddee\uddf1\uddf2\uddf4\uddf6-\uddfa\uddfc\uddfd\uddff]|\ud83c\udde7\ud83c[\udde6\udde7\udde9-\uddef\uddf1-\uddf4\uddf6-\uddf9\uddfb\uddfc\uddfe\uddff]|\ud83c\udde8\ud83c[\udde6\udde8\udde9\uddeb-\uddee\uddf0-\uddf5\uddf7\uddfa-\uddff]|\ud83c\udde9\ud83c[\uddea\uddec\uddef\uddf0\uddf2\uddf4\uddff]|\ud83c\uddea\ud83c[\udde6\udde8\uddea\uddec\udded\uddf7-\uddfa]|\ud83c\uddeb\ud83c[\uddee-\uddf0\uddf2\uddf4\uddf7]|\ud83c\uddec\ud83c[\udde6\udde7\udde9-\uddee\uddf1-\uddf3\uddf5-\uddfa\uddfc\uddfe]|\ud83c\udded\ud83c[\uddf0\uddf2\uddf3\uddf7\uddf9\uddfa]|\ud83c\uddee\ud83c[\udde8-\uddea\uddf1-\uddf4\uddf6-\uddf9]|\ud83c\uddef\ud83c[\uddea\uddf2\uddf4\uddf5]|\ud83c\uddf0\ud83c[\uddea\uddec-\uddee\uddf2\uddf3\uddf5\uddf7\uddfc\uddfe\uddff]|\ud83c\uddf1\ud83c[\udde6-\udde8\uddee\uddf0\uddf7-\uddfb\uddfe]|\ud83c\uddf2\ud83c[\udde6\udde8-\udded\uddf0-\uddff]|\ud83c\uddf3\ud83c[\udde6\udde8\uddea-\uddec\uddee\uddf1\uddf4\uddf5\uddf7\uddfa\uddff]|\ud83c\uddf4\ud83c\uddf2|\ud83c\uddf5\ud83c[\udde6\uddea-\udded\uddf0-\uddf3\uddf7-\uddf9\uddfc\uddfe]|\ud83c\uddf6\ud83c\udde6|\ud83c\uddf7\ud83c[\uddea\uddf4\uddf8\uddfa\uddfc]|\ud83c\uddf8\ud83c[\udde6-\uddea\uddec-\uddf4\uddf7-\uddf9\uddfb\uddfd-\uddff]|\ud83c\uddf9\ud83c[\udde6\udde8\udde9\uddeb-\udded\uddef-\uddf4\uddf7\uddf9\uddfb\uddfc\uddff]|\ud83c\uddfa\ud83c[\udde6\uddec\uddf2\uddf3\uddf8\uddfe\uddff]|\ud83c\uddfb\ud83c[\udde6\udde8\uddea\uddec\uddee\uddf3\uddfa]|\ud83c\uddfc\ud83c[\uddeb\uddf8]|\ud83c\uddfd\ud83c\uddf0|\ud83c\uddfe\ud83c[\uddea\uddf9]|\ud83c\uddff\ud83c[\udde6\uddf2\uddfc]|\ud83c[\udccf\udd8e\udd91-\udd9a\udde6-\uddff\ude01\ude32-\ude36\ude38-\ude3a\ude50\ude51\udf00-\udf20\udf2d-\udf35\udf37-\udf7c\udf7e-\udf84\udf86-\udf93\udfa0-\udfc1\udfc5\udfc6\udfc8\udfc9\udfcf-\udfd3\udfe0-\udff0\udff4\udff8-\udfff]|\ud83d[\udc00-\udc3e\udc40\udc44\udc45\udc51-\udc65\udc6a-\udc6d\udc6f\udc79-\udc7b\udc7d-\udc80\udc84\udc88-\udca9\udcab-\udcfc\udcff-\udd3d\udd4b-\udd4e\udd50-\udd67\udda4\uddfb-\ude44\ude48-\ude4a\ude80-\udea2\udea4-\udeb3\udeb7-\udebf\udec1-\udec5\uded0-\uded2\udeeb\udeec\udef4-\udef9]|\ud83e[\udd10-\udd17\udd1d\udd20-\udd25\udd27-\udd2f\udd3a\udd3c\udd40-\udd45\udd47-\udd70\udd73-\udd76\udd7a\udd7c-\udda2\uddb4\uddb7\uddc0-\uddc2\uddd0\uddde-\uddff]|[\u23e9-\u23ec\u23f0\u23f3\u267e\u26ce\u2705\u2728\u274c\u274e\u2753-\u2755\u2795-\u2797\u27b0\u27bf\ue50a])|\ufe0f/g),bu}var jS;function xF(){if(jS)return Gi;jS=1,Object.defineProperty(Gi,"__esModule",{value:!0}),Gi.TypeName=void 0,Gi.parse=s,Gi.toCodePoints=d;var t=bF(),e=n(t);function n(f){return f&&f.__esModule?f:{default:f}}var r=Gi.TypeName="emoji";function s(f,h){var m=h&&h.assetType?h.assetType:"svg",g=h&&h.buildUrl?h.buildUrl:function(E,C){return C==="png"?"https://twemoji.maxcdn.com/2/72x72/"+E+".png":"https://twemoji.maxcdn.com/2/svg/"+E+".svg"},v=[];for(e.default.lastIndex=0;;){var b=e.default.exec(f);if(!b)break;var k=b[0],w=d(l(k)).join("-");v.push({url:w?g(w,m):"",indices:[b.index,e.default.lastIndex],text:k,type:r})}return v}var i=/\uFE0F/g,o="‍",l=function(h){return h.indexOf(o)<0?h.replace(i,""):h};function d(f){for(var h=[],m=0,g=0,v=0;v<f.length;)m=f.charCodeAt(v++),g?(h.push((65536+(g-55296<<10)+(m-56320)).toString(16)),g=0):m>55296&&m<=56319?g=m:h.push(m.toString(16));return h}return Gi}var wF=xF(),kF=function(){for(var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:sS.defaults,r=Object.keys(n).length?n:sS.defaults,s=r.defaultWeight,i=r.emojiParsingEnabled,o=r.scale,l=r.maxWeightedTweetLength,d=r.transformedURLLength,f=typeof String.prototype.normalize=="function"?e.normalize():e,h=MS(Wz(f)),m=i?MS(wF.parse(f)):[],g=f.length,v=0,b=0,k=!0,w=0;w<g;w++){if(h[w]){var E=h[w],C=E.url;E.indices,v+=d*o,w+=C.length-1}else if(i&&m[w]){var T=m[w],j=T.text;T.indices,v+=s,w+=j.length-1}else w+=SF(f,w)?1:0,v+=oF(f.charAt(w),r);k&&(k=!yF(f.substring(w,w+1))),k&&v<=l*o&&(b=w)}v=v/o,k=k&&v>0&&v<=l;var _=Math.floor(v/l*1e3),A=e.length-f.length;return b+=A,{weightedLength:v,valid:k,permillage:_,validRangeStart:0,validRangeEnd:b,displayRangeStart:0,displayRangeEnd:e.length>0?e.length-1:0}},MS=function(e){return e.reduce(function(n,r){return n[r.indices[0]]=r,n},{})},SF=function(e,n){if(n<e.length-1){var r=e.charCodeAt(n),s=e.charCodeAt(n+1);return 55296<=r&&r<=56319&&56320<=s&&s<=57343}return!1},AS={},RS;function EF(){if(RS)return AS;RS=1;var t=vr();return t(t.S+t.F*!Hr(),"Object",{defineProperty:ss().f}),AS}EF();var OS={},IS;function NF(){if(IS)return OS;IS=1;var t=vr();return t(t.S+t.F*!Hr(),"Object",{defineProperties:hT()}),OS}NF();var LS={},Jm={},DS;function Sy(){return DS||(DS=1,Jm.f=Object.getOwnPropertySymbols),Jm}var Ym,PS;function CF(){if(PS)return Ym;PS=1;var t=af(),e=Sy(),n=Cr(),r=Ur().Reflect;return Ym=r&&r.ownKeys||function(i){var o=t.f(n(i)),l=e.f;return l?o.concat(l(i)):o},Ym}var Xm,BS;function vT(){if(BS)return Xm;BS=1;var t=ss(),e=Bl();return Xm=function(n,r,s){r in n?t.f(n,r,e(0,s)):n[r]=s},Xm}var $S;function _F(){if($S)return LS;$S=1;var t=vr(),e=CF(),n=vo(),r=gy(),s=vT();return t(t.S,"Object",{getOwnPropertyDescriptors:function(o){for(var l=n(o),d=r.f,f=e(l),h={},m=0,g,v;f.length>m;)v=d(l,g=f[m++]),v!==void 0&&s(h,g,v);return h}}),LS}_F();var zS={},Qm,FS;function TF(){if(FS)return Qm;FS=1;var t=$s(),e=wy(),n=Dn()("species");return Qm=function(r){var s;return e(r)&&(s=r.constructor,typeof s=="function"&&(s===Array||e(s.prototype))&&(s=void 0),t(s)&&(s=s[n],s===null&&(s=void 0))),s===void 0?Array:s},Qm}var Zm,US;function jF(){if(US)return Zm;US=1;var t=TF();return Zm=function(e,n){return new(t(e))(n)},Zm}var eg,HS;function yT(){if(HS)return eg;HS=1;var t=of(),e=py(),n=ji(),r=mo(),s=jF();return eg=function(i,o){var l=i==1,d=i==2,f=i==3,h=i==4,m=i==6,g=i==5||m,v=o||s;return function(b,k,w){for(var E=n(b),C=e(E),T=t(k,w,3),j=r(C.length),_=0,A=l?v(b,j):d?v(b,0):void 0,O,B;j>_;_++)if((g||_ in C)&&(O=C[_],B=T(O,_,E),i)){if(l)A[_]=B;else if(B)switch(i){case 3:return!0;case 5:return O;case 6:return _;case 2:A.push(O)}else if(h)return!1}return m?-1:f||h?h:A}},eg}var WS;function MF(){if(WS)return zS;WS=1;var t=vr(),e=yT()(0),n=$l()([].forEach,!0);return t(t.P+t.F*!n,"Array",{forEach:function(s){return e(this,s,arguments[1])}}),zS}MF();var qS={},VS;function AF(){if(VS)return qS;VS=1;var t=vr(),e=yT()(2);return t(t.P+t.F*!$l()([].filter,!0),"Array",{filter:function(r){return e(this,r,arguments[1])}}),qS}AF();var KS={},tg={exports:{}},GS;function RF(){if(GS)return tg.exports;GS=1;var t=Pl()("meta"),e=$s(),n=go(),r=ss().f,s=0,i=Object.isExtensible||function(){return!0},o=!rs()(function(){return i(Object.preventExtensions({}))}),l=function(g){r(g,t,{value:{i:"O"+ ++s,w:{}}})},d=function(g,v){if(!e(g))return typeof g=="symbol"?g:(typeof g=="string"?"S":"P")+g;if(!n(g,t)){if(!i(g))return"F";if(!v)return"E";l(g)}return g[t].i},f=function(g,v){if(!n(g,t)){if(!i(g))return!0;if(!v)return!1;l(g)}return g[t].w},h=function(g){return o&&m.NEED&&i(g)&&!n(g,t)&&l(g),g},m=tg.exports={KEY:t,NEED:!1,fastKey:d,getWeak:f,onFreeze:h};return tg.exports}var ng={},JS;function bT(){return JS||(JS=1,ng.f=Dn()),ng}var rg,YS;function OF(){if(YS)return rg;YS=1;var t=Ur(),e=fa(),n=tf(),r=bT(),s=ss().f;return rg=function(i){var o=e.Symbol||(e.Symbol=n?{}:t.Symbol||{});i.charAt(0)!="_"&&!(i in o)&&s(o,i,{value:r.f(i)})},rg}var sg,XS;function IF(){if(XS)return sg;XS=1;var t=Fl(),e=Sy(),n=my();return sg=function(r){var s=t(r),i=e.f;if(i)for(var o=i(r),l=n.f,d=0,f;o.length>d;)l.call(r,f=o[d++])&&s.push(f);return s},sg}var ig={},QS;function LF(){if(QS)return ig;QS=1;var t=vo(),e=af().f,n={}.toString,r=typeof window=="object"&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],s=function(i){try{return e(i)}catch{return r.slice()}};return ig.f=function(o){return r&&n.call(o)=="[object Window]"?s(o):e(t(o))},ig}var ZS;function DF(){if(ZS)return KS;ZS=1;var t=Ur(),e=go(),n=Hr(),r=vr(),s=zs(),i=RF().KEY,o=rs(),l=nf(),d=ky(),f=Pl(),h=Dn(),m=bT(),g=OF(),v=IF(),b=wy(),k=Cr(),w=$s(),E=ji(),C=vo(),T=fy(),j=Bl(),_=pT(),A=LF(),O=gy(),B=Sy(),$=ss(),W=Fl(),J=O.f,z=$.f,G=A.f,D=t.Symbol,U=t.JSON,q=U&&U.stringify,se="prototype",V=h("_hidden"),te=h("toPrimitive"),K={}.propertyIsEnumerable,M=l("symbol-registry"),L=l("symbols"),ee=l("op-symbols"),fe=Object[se],ge=typeof D=="function"&&!!B.f,oe=t.QObject,xe=!oe||!oe[se]||!oe[se].findChild,we=n&&o(function(){return _(z({},"a",{get:function(){return z(this,"a",{value:7}).a}})).a!=7})?function(ve,X,Be){var ne=J(fe,X);ne&&delete fe[X],z(ve,X,Be),ne&&ve!==fe&&z(fe,X,ne)}:z,We=function(ve){var X=L[ve]=_(D[se]);return X._k=ve,X},He=ge&&typeof D.iterator=="symbol"?function(ve){return typeof ve=="symbol"}:function(ve){return ve instanceof D},Ze=function(X,Be,ne){return X===fe&&Ze(ee,Be,ne),k(X),Be=T(Be,!0),k(ne),e(L,Be)?(ne.enumerable?(e(X,V)&&X[V][Be]&&(X[V][Be]=!1),ne=_(ne,{enumerable:j(0,!1)})):(e(X,V)||z(X,V,j(1,{})),X[V][Be]=!0),we(X,Be,ne)):z(X,Be,ne)},Oe=function(X,Be){k(X);for(var ne=v(Be=C(Be)),de=0,he=ne.length,Ge;he>de;)Ze(X,Ge=ne[de++],Be[Ge]);return X},Ke=function(X,Be){return Be===void 0?_(X):Oe(_(X),Be)},pt=function(X){var Be=K.call(this,X=T(X,!0));return this===fe&&e(L,X)&&!e(ee,X)?!1:Be||!e(this,X)||!e(L,X)||e(this,V)&&this[V][X]?Be:!0},Je=function(X,Be){if(X=C(X),Be=T(Be,!0),!(X===fe&&e(L,Be)&&!e(ee,Be))){var ne=J(X,Be);return ne&&e(L,Be)&&!(e(X,V)&&X[V][Be])&&(ne.enumerable=!0),ne}},pe=function(X){for(var Be=G(C(X)),ne=[],de=0,he;Be.length>de;)!e(L,he=Be[de++])&&he!=V&&he!=i&&ne.push(he);return ne},mt=function(X){for(var Be=X===fe,ne=G(Be?ee:C(X)),de=[],he=0,Ge;ne.length>he;)e(L,Ge=ne[he++])&&(!Be||e(fe,Ge))&&de.push(L[Ge]);return de};ge||(D=function(){if(this instanceof D)throw TypeError("Symbol is not a constructor!");var X=f(arguments.length>0?arguments[0]:void 0),Be=function(ne){this===fe&&Be.call(ee,ne),e(this,V)&&e(this[V],X)&&(this[V][X]=!1),we(this,X,j(1,ne))};return n&&xe&&we(fe,X,{configurable:!0,set:Be}),We(X)},s(D[se],"toString",function(){return this._k}),O.f=Je,$.f=Ze,af().f=A.f=pe,my().f=pt,B.f=mt,n&&!tf()&&s(fe,"propertyIsEnumerable",pt,!0),m.f=function(ve){return We(h(ve))}),r(r.G+r.W+r.F*!ge,{Symbol:D});for(var ft="hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),at=0;ft.length>at;)h(ft[at++]);for(var nt=W(h.store),ht=0;nt.length>ht;)g(nt[ht++]);r(r.S+r.F*!ge,"Symbol",{for:function(ve){return e(M,ve+="")?M[ve]:M[ve]=D(ve)},keyFor:function(X){if(!He(X))throw TypeError(X+" is not a symbol!");for(var Be in M)if(M[Be]===X)return Be},useSetter:function(){xe=!0},useSimple:function(){xe=!1}}),r(r.S+r.F*!ge,"Object",{create:Ke,defineProperty:Ze,defineProperties:Oe,getOwnPropertyDescriptor:Je,getOwnPropertyNames:pe,getOwnPropertySymbols:mt});var Fe=o(function(){B.f(1)});return r(r.S+r.F*Fe,"Object",{getOwnPropertySymbols:function(X){return B.f(E(X))}}),U&&r(r.S+r.F*(!ge||o(function(){var ve=D();return q([ve])!="[null]"||q({a:ve})!="{}"||q(Object(ve))!="{}"})),"JSON",{stringify:function(X){for(var Be=[X],ne=1,de,he;arguments.length>ne;)Be.push(arguments[ne++]);if(he=de=Be[1],!(!w(de)&&X===void 0||He(X)))return b(de)||(de=function(Ge,Pe){if(typeof he=="function"&&(Pe=he.call(this,Ge,Pe)),!He(Pe))return Pe}),Be[1]=de,q.apply(U,Be)}}),D[se][te]||Mi()(D[se],te,D[se].valueOf),d(D,"Symbol"),d(Math,"Math",!0),d(t.JSON,"JSON",!0),KS}DF();Mt(/^#{validMentionOrList}$/,{validMentionOrList:eF});var xT=/[a-z\u0400-\u04FF0-9\-._~]/i,wT=/(?:%[0-9a-f]{2})/i,kT=/[!$&'()*+,;=]/i,ST=Mt("(?:#{validateUrlUnreserved}|#{validateUrlPctEncoded}|#{validateUrlSubDelims}|:)*",{validateUrlUnreserved:xT,validateUrlPctEncoded:wT,validateUrlSubDelims:kT},"i"),PF=/(?:[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?)/i,BF=/(?:[a-z](?:[a-z0-9\-]*[a-z0-9])?)/i,$F=/(?:[a-z0-9](?:[a-z0-9_\-]*[a-z0-9])?)/i,zF=Mt(/(?:(?:#{validateUrlSubDomainSegment}\.)*(?:#{validateUrlDomainSegment}\.)#{validateUrlDomainTld})/i,{validateUrlSubDomainSegment:$F,validateUrlDomainSegment:PF,validateUrlDomainTld:BF}),FF=/(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9]{2})|(?:2[0-4][0-9])|(?:25[0-5]))/i,UF=Mt(/(?:#{validateUrlDecOctet}(?:\.#{validateUrlDecOctet}){3})/i,{validateUrlDecOctet:FF}),HF=/(?:\[[a-f0-9:\.]+\])/i,ET=Mt("(?:#{validateUrlIpv4}|#{validateUrlIpv6})",{validateUrlIpv4:UF,validateUrlIpv6:HF},"i"),WF=Mt("(?:#{validateUrlIp}|#{validateUrlDomain})",{validateUrlIp:ET,validateUrlDomain:zF},"i"),NT=/[0-9]{1,5}/;Mt("(?:(#{validateUrlUserinfo})@)?(#{validateUrlHost})(?::(#{validateUrlPort}))?",{validateUrlUserinfo:ST,validateUrlHost:WF,validateUrlPort:NT},"i");var Ey=Mt("(?:#{validateUrlUnreserved}|#{validateUrlPctEncoded}|#{validateUrlSubDelims}|[:|@])",{validateUrlUnreserved:xT,validateUrlPctEncoded:wT,validateUrlSubDelims:kT},"i");Mt(/(#{validateUrlPchar}|\/|\?)*/i,{validateUrlPchar:Ey});Mt(/(\/#{validateUrlPchar}*)*/i,{validateUrlPchar:Ey});Mt(/(#{validateUrlPchar}|\/|\?)*/i,{validateUrlPchar:Ey});Mt("^(?:([^:/?#]+):\\/\\/)?([^/?#]*)([^?#]*)(?:\\?([^#]*))?(?:#(.*))?$","i");var qF=/(?:(?:[a-z0-9]|[^\u0000-\u007f])(?:(?:[a-z0-9_\-]|[^\u0000-\u007f])*(?:[a-z0-9]|[^\u0000-\u007f]))?)/i,VF=/(?:(?:[a-z0-9]|[^\u0000-\u007f])(?:(?:[a-z0-9\-]|[^\u0000-\u007f])*(?:[a-z0-9]|[^\u0000-\u007f]))?)/i,KF=/(?:(?:[a-z]|[^\u0000-\u007f])(?:(?:[a-z0-9\-]|[^\u0000-\u007f])*(?:[a-z0-9]|[^\u0000-\u007f]))?)/i,GF=Mt(/(?:(?:#{validateUrlUnicodeSubDomainSegment}\.)*(?:#{validateUrlUnicodeDomainSegment}\.)#{validateUrlUnicodeDomainTld})/i,{validateUrlUnicodeSubDomainSegment:qF,validateUrlUnicodeDomainSegment:VF,validateUrlUnicodeDomainTld:KF}),JF=Mt("(?:#{validateUrlIp}|#{validateUrlUnicodeDomain})",{validateUrlIp:ET,validateUrlUnicodeDomain:GF},"i");Mt("(?:(#{validateUrlUserinfo})@)?(#{validateUrlUnicodeHost})(?::(#{validateUrlPort}))?",{validateUrlUserinfo:ST,validateUrlUnicodeHost:JF,validateUrlPort:NT},"i");var eE={},tE;function YF(){if(tE)return eE;tE=1;var t=U2()(!0);return mT()(String,"String",function(e){this._t=String(e),this._i=0},function(){var e=this._t,n=this._i,r;return n>=e.length?{value:void 0,done:!0}:(r=t(e,n),this._i+=r.length,{value:r,done:!1})}),eE}YF();var nE={},og,rE;function XF(){if(rE)return og;rE=1;var t=Cr();return og=function(e,n,r,s){try{return s?n(t(r)[0],r[1]):n(r)}catch(o){var i=e.return;throw i!==void 0&&t(i.call(e)),o}},og}var ag,sE;function QF(){if(sE)return ag;sE=1;var t=zl(),e=Dn()("iterator"),n=Array.prototype;return ag=function(r){return r!==void 0&&(t.Array===r||n[e]===r)},ag}var lg,iE;function ZF(){if(iE)return lg;iE=1;var t=cy(),e=Dn()("iterator"),n=zl();return lg=fa().getIteratorMethod=function(r){if(r!=null)return r[e]||r["@@iterator"]||n[t(r)]},lg}var cg,oE;function eU(){if(oE)return cg;oE=1;var t=Dn()("iterator"),e=!1;try{var n=[7][t]();n.return=function(){e=!0},Array.from(n,function(){throw 2})}catch{}return cg=function(r,s){if(!s&&!e)return!1;var i=!1;try{var o=[7],l=o[t]();l.next=function(){return{done:i=!0}},o[t]=function(){return l},r(o)}catch{}return i},cg}var aE;function tU(){if(aE)return nE;aE=1;var t=of(),e=vr(),n=ji(),r=XF(),s=QF(),i=mo(),o=vT(),l=ZF();return e(e.S+e.F*!eU()(function(d){Array.from(d)}),"Array",{from:function(f){var h=n(f),m=typeof this=="function"?this:Array,g=arguments.length,v=g>1?arguments[1]:void 0,b=v!==void 0,k=0,w=l(h),E,C,T,j;if(b&&(v=t(v,g>2?arguments[2]:void 0,2)),w!=null&&!(m==Array&&s(w)))for(j=w.call(h),C=new m;!(T=j.next()).done;k++)o(C,k,b?r(j,v,[T.value,k],!0):T.value);else for(E=i(h.length),C=new m(E);E>k;k++)o(C,k,b?v(h[k],k):h[k]);return C.length=k,C}}),nE}tU();const nU={parseTweet:kF},{parseTweet:rU}=nU;function lE(t){return rU(t).weightedLength}const cE="ow-x-handle";function sU(){const[t,e]=x.useState(()=>localStorage.getItem(cE)||""),[n,r]=x.useState(!1),[s,i]=x.useState(""),o=x.useRef(null),l=x.useRef(null),d=()=>{const m=s.replace(/^@/,"").trim();m&&(localStorage.setItem(cE,m),e(m)),r(!1)},f=()=>{i(t),r(!0),setTimeout(()=>{var m;return(m=o.current)==null?void 0:m.focus()},0)};x.useEffect(()=>{if(!n)return;const m=g=>{l.current&&!l.current.contains(g.target)&&d()};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[n,s]);const h=t?`https://unavatar.io/twitter/${t}`:"";return c.jsxs("div",{className:"tweet-compose-avatar-wrapper",ref:l,children:[t?c.jsx("img",{className:"tweet-compose-avatar tweet-compose-avatar-img",src:h,alt:`@${t}`,onClick:f,title:`@${t} — click to change`}):c.jsx("div",{className:"tweet-compose-avatar",onClick:f,title:"Set your @handle"}),n&&c.jsx("div",{className:"tweet-handle-popover",children:c.jsx("input",{ref:o,className:"tweet-handle-input",value:s,onChange:m=>i(m.target.value),onKeyDown:m=>{m.key==="Enter"&&d(),m.key==="Escape"&&r(!1)},placeholder:"your_handle",spellCheck:!1})})]})}const iU={tweet:!0,reply:!0,quote:!1};function uE(){return c.jsxs("div",{className:"tweet-skeleton",children:[c.jsxs("div",{className:"tweet-author-row",children:[c.jsx("div",{className:"tweet-avatar tweet-avatar-placeholder tweet-pulse"}),c.jsxs("div",{className:"tweet-author-info",children:[c.jsx("span",{className:"tweet-skeleton-line tweet-pulse",style:{width:120}}),c.jsx("span",{className:"tweet-skeleton-line tweet-pulse",style:{width:80}})]})]}),c.jsx("div",{className:"tweet-skeleton-line tweet-pulse",style:{width:"100%",height:16,marginTop:12}}),c.jsx("div",{className:"tweet-skeleton-line tweet-pulse",style:{width:"75%",height:16,marginTop:8}})]})}function oU(t){var e;if(t)return(e=t.match(/\/status\/(\d+)/))==null?void 0:e[1]}function xu(t){if(!t)return[null];if(typeof t=="string"){const e=t.split(/<hr\s*\/?>/i).map(n=>n.trim()).filter(Boolean);return e.length?e:[null]}if((t==null?void 0:t.type)==="doc"&&Array.isArray(t.content)){const e=[[]];for(const r of t.content)r.type==="horizontalRule"?e.push([]):e[e.length-1].push(r);const n=e.map(r=>r.length?{type:"doc",content:r}:null).filter(Boolean);return n.length?n:[null]}return[t]}function wu(t){var n;if(!t||typeof t=="string"||!t.content)return[];const e=[];for(let r=t.content.length-1;r>=0&&(t.content[r].type==="image"&&((n=t.content[r].attrs)!=null&&n.src));r--)e.unshift(t.content[r].attrs.src);return e}function dE(t,e){if(!t||typeof t=="string"||!t.content||e===0)return t;const n=t.content.slice(0,t.content.length-e);return n.length===0?{type:"doc",content:[{type:"paragraph",content:[]}]}:{...t,content:n}}function ku(t,e){const n=[];let r=0;return t.forEach((s,i)=>{if(!s)return;r>0&&n.push({type:"horizontalRule"});const o=s.getJSON();o.content&&n.push(...o.content);const l=e==null?void 0:e[i];if(l)for(const d of l){const f=crypto.randomUUID().replace(/-/g,"").slice(0,8);n.push({type:"image",attrs:{src:d,id:f}})}r++}),{type:"doc",content:n}}function fE(t,e){const n=[],r=s=>{var i;s.type==="image"&&((i=s.attrs)!=null&&i.src)&&n.push(s.attrs.src),s.content&&s.content.forEach(r)};return r(t.getJSON()),e&&n.push(...e),n.slice(0,4)}function Su(t){fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tweetContext:t}),keepalive:!0}).catch(()=>{})}function aU({tweetContext:t,initialContent:e,onUpdate:n,onEditorReady:r,onEditorsChange:s,onActiveEditorChange:i,filename:o,title:l,autoplug:d}){var Nt;const{tweet:f,loading:h,error:m}=J$(t==null?void 0:t.url),[g,v]=x.useState(()=>xu(e).map(Me=>{const qe=wu(Me);return dE(Me,qe.length)})),[b,k]=x.useState(0),w=x.useRef([]),E=x.useRef(null),C=x.useRef(!0),T=x.useRef(!1),j=x.useRef(g.length),[_,A]=x.useState(()=>g.map(()=>0)),[O,B]=x.useState(0),[$,W]=x.useState(0),J=x.useRef(xu(e).map(Ie=>wu(Ie))),[z,G]=x.useState(()=>xu(e).map(Me=>wu(Me).length)),[D,U]=x.useState(null),[q,se]=x.useState(),[V,te]=x.useState(!1),[K,M]=x.useState("idle"),[L,ee]=x.useState(""),fe=x.useRef(),{copyText:ge,copyState:oe}=Z$(w,O),[xe,we]=x.useState(!1),We=iU[(t==null?void 0:t.mode)??"tweet"],He=!!((Nt=t==null?void 0:t.lastPost)!=null&&Nt.postedAt),[Ze,Oe]=x.useState(!1),[Ke,pt]=x.useState(""),Je=x.useRef(null),pe=x.useRef(null);x.useEffect(()=>{if(!Ze)return;setTimeout(()=>{var Me;return(Me=Je.current)==null?void 0:Me.focus()},0);const Ie=Me=>{pe.current&&!pe.current.contains(Me.target)&&(Oe(!1),pt(""))};return document.addEventListener("mousedown",Ie),()=>document.removeEventListener("mousedown",Ie)},[Ze]);const mt=()=>{var F;const Ie=Ke.trim();if(!(!Ie||Ie.includes("x.com")||Ie.includes("twitter.com")))return;const qe=(F=t==null?void 0:t.lastPost)==null?void 0:F.postedAt;Su({lastPost:{postedAt:qe??new Date().toISOString(),tweetUrl:Ie||void 0}}),Oe(!1),pt("")},ft=()=>{Su({lastPost:null})},at=d!==!1,nt=()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({autoplug:!at}),keepalive:!0}).catch(()=>{})};x.useEffect(()=>{let Ie=!1;return(async()=>{try{const Me=await fetch("/api/x/status");if(Ie)return;if(Me.ok){const qe=await Me.json();U(qe.connected),se(qe.username)}else U(!1)}catch{Ie||U(!1)}})(),()=>{Ie=!0}},[]),x.useEffect(()=>{if(C.current){C.current=!1;return}if(!e||JSON.stringify(e)===E.current)return;const Me=xu(e),qe=Me.map(ce=>wu(ce)),F=Me.map((ce,Ne)=>dE(ce,qe[Ne].length));T.current=!0,j.current=F.length,w.current=[],J.current=qe,v(F),A(F.map(()=>0)),G(qe.map(ce=>ce.length)),k(ce=>ce+1)},[e]);const ht=x.useCallback((Ie,Me)=>{if(w.current[Ie]=Me,A(F=>{const ce=[...F];return ce[Ie]=lE(Me.getText()),ce}),T.current)return;const qe=ku(w.current,J.current);E.current=JSON.stringify(qe),n==null||n(qe)},[n]),Fe=x.useCallback((Ie,Me)=>{if(w.current[Ie]=Me,A(qe=>{const F=[...qe];return F[Ie]=lE(Me.getText()),F}),W(qe=>qe+1),T.current&&w.current.filter(Boolean).length>=j.current){T.current=!1;const F=ku(w.current,J.current);E.current=JSON.stringify(F)}Ie===0&&(r==null||r(Me)),s==null||s(w.current.filter(Boolean))},[r,s]),ve=g.length>1;_.reduce((Ie,Me)=>Ie+Me,0);const X=x.useCallback(()=>{const Ie=O+1;v(Me=>[...Me.slice(0,Ie),"<p></p>",...Me.slice(Ie)]),A(Me=>[...Me.slice(0,Ie),0,...Me.slice(Ie)]),J.current.splice(Ie,0,[]),G(Me=>[...Me.slice(0,Ie),0,...Me.slice(Ie)]),B(Ie)},[O]),Be=x.useCallback(Ie=>{Ie!==0&&(w.current.splice(Ie,1),J.current.splice(Ie,1),v(Me=>Me.filter((qe,F)=>F!==Ie)),A(Me=>Me.filter((qe,F)=>F!==Ie)),G(Me=>Me.filter((qe,F)=>F!==Ie)),setTimeout(()=>{const Me=ku(w.current,J.current);n==null||n(Me),s==null||s(w.current.filter(Boolean))},0))},[n,s]),ne=!!(t!=null&&t.url),de=(t==null?void 0:t.mode)==="reply",he=(()=>{const Me=w.current.filter(Boolean).some(F=>F.getText().trim()||fE(F).length>0),qe=z.some(F=>F>0);return Me||qe})(),Ge=D&&he&&K==="idle",Pe=async()=>{if(!D){te(!0);return}if(Ge){M("uploading"),ee("");try{const Ie=[];for(let qe=0;qe<w.current.length;qe++){const F=w.current[qe];if(!F)continue;const ce=F.getText().trim(),Ne=fE(F,J.current[qe]);if(!ce&&Ne.length===0)continue;const P=[];for(const Z of Ne){const re=await(await fetch("/api/x/upload-media",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({src:Z})})).json();if(!re.success)throw new Error(re.error||"Image upload failed");P.push(re.mediaId)}Ie.push({text:ce,mediaIds:P})}if(Ie.length===0)return;M("posting");const Me=oU(t==null?void 0:t.url);if(Ie.length===1){const qe={};Ie[0].text&&(qe.text=Ie[0].text),Ie[0].mediaIds.length>0&&(qe.mediaIds=Ie[0].mediaIds),(t==null?void 0:t.mode)==="reply"&&Me?qe.replyTo=Me:(t==null?void 0:t.mode)==="quote"&&Me&&(qe.quoteTweetId=Me);const ce=await(await fetch("/api/x/post",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(qe)})).json();ce.success?(Su({lastPost:{postedAt:new Date().toISOString(),tweetUrl:ce.tweetUrl}}),M("success"),fe.current=setTimeout(()=>M("idle"),2500)):(console.error("[TweetCompose] Post error:",ce.error),ee(ce.error||"Post failed"),M("error"),setTimeout(()=>M("idle"),3e3))}else{const F={tweets:Ie.map(P=>({text:P.text,...P.mediaIds.length>0?{mediaIds:P.mediaIds}:{}}))};(t==null?void 0:t.mode)==="reply"&&Me&&(F.replyTo=Me);const Ne=await(await fetch("/api/x/post-thread",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)})).json();Ne.success?(Su({lastPost:{postedAt:new Date().toISOString(),tweetUrl:Ne.threadUrl}}),M("success"),fe.current=setTimeout(()=>M("idle"),2500)):(ee(Ne.error||"Thread post failed"),M("error"),setTimeout(()=>M("idle"),3e3))}}catch(Ie){ee(Ie.message||"Network error"),M("error"),setTimeout(()=>M("idle"),3e3)}}};x.useEffect(()=>()=>{fe.current&&clearTimeout(fe.current)},[]);const et=()=>{U(!0),te(!1),fetch("/api/x/status").then(Ie=>Ie.json()).then(Ie=>{Ie.username&&se(Ie.username)}).catch(()=>{})},ot=K==="uploading"?"Uploading...":K==="posting"?"Posting...":K==="success"?"Posted!":K==="error"?"Failed":ve?O===0?"Post Thread":"Post All":"Post",bt=g.map((Ie,Me)=>Me===0?de?"Post your reply":"What is happening?!":"Add another tweet"),Ye=Ie=>{var Me;return c.jsxs("div",{className:`tweet-compose-footer${Ie?" tweet-compose-footer--inline":""}`,children:[O===0&&((Me=t==null?void 0:t.lastPost)==null?void 0:Me.postedAt)&&c.jsxs("a",{className:"tweet-posted-status",href:t.lastPost.tweetUrl,target:"_blank",rel:"noopener noreferrer",title:t.lastPost.tweetUrl||"Posted to X",children:[c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Posted ",new Date(t.lastPost.postedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})]}),K==="error"&&L&&c.jsx("span",{className:"tweet-post-error",children:L}),ve&&c.jsxs("span",{className:"tweet-thread-counter",children:[O+1,"/",g.length]}),c.jsx(az,{count:_[O]||0}),c.jsx("button",{className:"tweet-thread-add",onClick:X,title:"Add another tweet",children:c.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[c.jsx("line",{x1:"10",y1:"4",x2:"10",y2:"16",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),c.jsx("line",{x1:"4",y1:"10",x2:"16",y2:"10",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}),c.jsx("button",{className:`tweet-copy-btn${oe==="copied"?" tweet-copy-btn--copied":""}`,disabled:!he,onClick:ge,title:"Copy tweet text to clipboard",children:oe==="copied"?c.jsxs(c.Fragment,{children:[c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 8.5L6.5 12L13 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),"Copied!"]}):c.jsxs(c.Fragment,{children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[c.jsx("rect",{x:"5.5",y:"2",width:"8.5",height:"10.5",rx:"1.5",stroke:"currentColor",strokeWidth:"1.5"}),c.jsx("path",{d:"M3.5 5H2.5A1.5 1.5 0 001 6.5V13a1.5 1.5 0 001.5 1.5H9A1.5 1.5 0 0010.5 13v-1",stroke:"currentColor",strokeWidth:"1.5"})]}),"Copy"]})}),O===0&&!We&&(()=>{var ce;const qe=((ce=t==null?void 0:t.lastPost)==null?void 0:ce.tweetUrl)??"",F=()=>{if(He){ft(),Oe(!1),pt("");return}pt(qe),Oe(!0)};return c.jsxs("div",{className:"tweet-mark-sent-wrap",ref:pe,children:[c.jsx("button",{className:`tweet-mark-sent-btn${He?" tweet-mark-sent-btn--done":""}`,onClick:F,title:He?qe?`Posted — click to unmark (${qe})`:"Posted — click to unmark":"Mark as manually posted",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:He?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"8 12 11 15 16 9",stroke:He?"#fff":"currentColor"})]})}),Ze&&(()=>{const Ne=Ke.trim(),P=!Ne||Ne.includes("x.com")||Ne.includes("twitter.com");return c.jsxs("div",{className:"tweet-mark-sent-url",children:[c.jsx("input",{ref:Je,type:"text",placeholder:"Paste posted tweet URL...",value:Ke,onChange:Z=>pt(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"&&(Z.preventDefault(),mt()),Z.key==="Escape"&&(Oe(!1),pt(""))}}),c.jsx("button",{onClick:mt,disabled:!P,title:Ne?"Save URL":"Mark posted without URL",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})})]})})()]})})(),c.jsx("button",{className:`tweet-autoplug-toggle${at?" tweet-autoplug-toggle--on":""}`,onClick:nt,title:at?"Auto-plug ON — engagement autoplugs may reply to this post with your configured promo. Click to opt out.":"Auto-plug OFF — this post is excluded from autoplugs. Click to opt in.",children:at?"Auto-plug on":"Auto-plug off"}),o&&!He&&c.jsx("button",{className:"tweet-schedule-btn",onClick:()=>we(!0),title:"Schedule post",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"12 6 12 12 16 14"})]})}),We&&c.jsx("button",{className:`tweet-post-btn${Ge||!D&&D!==null?" tweet-post-btn--active":""}${K==="success"?" tweet-post-btn--success":""}${K==="error"?" tweet-post-btn--error":""}`,disabled:D?!Ge:!1,onClick:Pe,title:D?q?`Post as @${q}`:"Post to X":"Connect X to post",children:ot})]})},it=ne&&!de,gt=()=>c.jsx("div",{className:"tweet-thread-editors",children:g.map((Ie,Me)=>c.jsxs("div",{className:`tweet-thread-item${Me===O?" tweet-thread-item--active":" tweet-thread-item--inactive"}`,children:[c.jsxs("div",{className:"tweet-thread-item-left",children:[c.jsx(sU,{}),Me<g.length-1&&c.jsx("div",{className:"tweet-thread-line"})]}),c.jsxs("div",{className:"tweet-thread-item-right",children:[Me>0&&c.jsx("button",{className:"tweet-thread-remove",onClick:()=>Be(Me),title:"Remove this tweet",children:"×"}),c.jsx("div",{className:`tweet-compose-box${Me===0&&!ve?" tweet-compose-box--standalone":""}`,children:c.jsx(oz,{initialContent:Ie,initialPreviewImages:J.current[Me],placeholder:bt[Me],onUpdate:qe=>ht(Me,qe),onReady:qe=>Fe(Me,qe),onFocus:()=>{B(Me);const qe=w.current[Me];qe&&(i==null||i(qe))},onPreviewImagesChange:qe=>{if(J.current[Me]=qe,G(F=>{const ce=[...F];return ce[Me]=qe.length,ce}),!T.current){const F=ku(w.current,J.current);E.current=JSON.stringify(F),n==null||n(F)}}})}),Me===O&&!it&&Ye(Me<g.length-1)]})]},`${b}-${Me}`))});return c.jsxs("div",{className:"tweet-compose-wrapper",children:[ne&&de&&c.jsxs(c.Fragment,{children:[h&&c.jsx("div",{className:"tweet-context-section",children:c.jsx(uE,{})}),m&&c.jsx("div",{className:"tweet-context-section",children:c.jsxs("div",{className:"tweet-embed-error",children:[c.jsx("span",{children:"Could not load tweet"}),c.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"tweet-fallback-link",children:t.url})]})}),f&&c.jsxs("div",{className:"tweet-reply-parent-section",children:[c.jsx("div",{className:"tweet-reply-parent-card",children:c.jsx(Lk,{tweet:f,url:t==null?void 0:t.url})}),c.jsxs("div",{className:"tweet-replying-to",children:["Replying to ",c.jsxs("span",{className:"tweet-reply-handle",children:["@",f.author.username]})]})]}),gt()]}),it&&c.jsxs(c.Fragment,{children:[gt(),c.jsxs("div",{className:"tweet-quote-section",style:{padding:"0 16px 12px"},children:[h&&c.jsx(uE,{}),m&&c.jsxs("div",{className:"tweet-embed-error",children:[c.jsx("span",{children:"Could not load tweet"}),c.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"tweet-fallback-link",children:t.url})]}),f&&c.jsx(Lk,{tweet:f,url:t==null?void 0:t.url})]}),c.jsx("div",{className:"tweet-quote-footer",children:Ye()})]}),!ne&&gt(),V&&c.jsx(lz,{onConnected:et,onCancel:()=>te(!1)}),xe&&o&&c.jsx(Dl,{filename:o,title:l||"Untitled",onClose:()=>we(!1)})]})}function lU(){const[t,e]=x.useState("idle"),n=x.useRef();return{copyAsHtml:x.useCallback(async()=>{const s=document.querySelector(".ProseMirror");if(!s)return;const i=s.cloneNode(!0);i.querySelectorAll(".ProseMirror-widget, [data-widget], .ProseMirror-gapcursor").forEach(h=>h.remove());let o="";const l=document.querySelector(".article-title-input");l!=null&&l.value&&l.value!=="Untitled"&&(o+=`<h1>${l.value}</h1>
212
212
  `);const d=o+i.innerHTML,f=cU(i);try{const h=new ClipboardItem({"text/html":new Blob([d],{type:"text/html"}),"text/plain":new Blob([f],{type:"text/plain"})});await navigator.clipboard.write([h])}catch{try{await navigator.clipboard.writeText(f)}catch{const h=document.createElement("textarea");h.value=f,h.style.position="fixed",h.style.opacity="0",document.body.appendChild(h),h.select(),document.execCommand("copy"),document.body.removeChild(h)}}e("copied"),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>e("idle"),2e3)},[]),copyState:t}}function cU(t){var n;const e=[];for(const r of t.children){const s=(n=r.innerText)==null?void 0:n.trim();s&&e.push(s)}return e.join(`
213
213
 
214
- `)}function CT(t,e){const n=x.useRef(null),r=x.useCallback(()=>{const o=n.current;o&&(o.style.height="auto",o.style.height=`${o.scrollHeight}px`)},[]);x.useLayoutEffect(()=>{r()},[t,r]);const s=x.useCallback(o=>{e(o.target.value.replace(/[\r\n]+/g," ")),r()},[e,r]),i=x.useCallback(o=>{var l;o.key==="Enter"&&(o.preventDefault(),(l=n.current)==null||l.blur())},[]);return{ref:n,onChange:s,onKeyDown:i}}const ug="ow-x-handle",hE="ow-x-name",uU=new Set(["Untitled","New Document","Article"]);function dU({src:t,coverImages:e}){const[n,r]=x.useState(t?"display":"empty"),[s,i]=x.useState(t||""),[o,l]=x.useState(e||(t?[t]:[])),[d,f]=x.useState(""),[h,m]=x.useState(""),g=x.useRef(null);x.useEffect(()=>{t?(i(t),r("display")):e&&e.length>0?(i(e[0]),r("display")):(i(""),r("empty"),f(""),m(""))},[t,e]),x.useEffect(()=>{e&&e.length>0?l(e):l(t?[t]:[])},[e]);const v=s?o.indexOf(s):-1,b=o.length,k=b>1,w=x.useCallback($=>{const W=o[$];W&&(i(W),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{coverImage:W,coverImages:o}})}).catch(()=>{}))},[o]),E=x.useCallback(()=>{v>0&&w(v-1)},[v,w]),C=x.useCallback(()=>{v<b-1&&w(v+1)},[v,b,w]),T=x.useCallback(async()=>{if(d.trim()){r("loading"),m("");try{const $=await fetch("/api/image-gen/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:d.trim()})});if(!$.ok){const J=await $.json().catch(()=>null);m((J==null?void 0:J.error)||`Generation failed (${$.status})`),r("prompt");return}const W=await $.json();if(W.success&&W.src){const J=[...o,W.src];l(J),i(W.src),r("display"),f(""),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{coverImage:W.src,coverImages:J}})}).catch(()=>{})}else m(W.error||"Generation failed"),r("prompt")}catch($){m($.message||"Network error"),r("prompt")}}},[d,o]),j=$=>{$.key==="Enter"&&T(),$.key==="Escape"&&(r("empty"),f(""),m(""))},_=()=>{r("prompt"),setTimeout(()=>{var $;return($=g.current)==null?void 0:$.focus()},0)},A=()=>{const $=o.filter(W=>W!==s);if(l($),$.length>0){const W=Math.min(v,$.length-1),J=$[W];i(J),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{coverImage:J,coverImages:$}})}).catch(()=>{})}else i(""),r("empty"),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{coverImage:null,coverImages:null}})}).catch(()=>{})},O=()=>{r("prompt"),setTimeout(()=>{var $;return($=g.current)==null?void 0:$.focus()},0)},B=()=>{const $=document.createElement("a");$.href=s,$.download=`cover-${v+1}.png`,$.click()};return n==="display"&&s?c.jsxs("div",{className:"article-cover article-cover--display",children:[c.jsx("img",{className:"article-cover-img",src:s,alt:"Cover"}),c.jsxs("div",{className:"article-cover-overlay",children:[k&&c.jsx("button",{className:"article-cover-arrow article-cover-arrow--left",onClick:E,disabled:v<=0,children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"15 18 9 12 15 6"})})}),c.jsxs("div",{className:"article-cover-overlay-center",children:[c.jsxs("button",{className:"article-cover-overlay-btn",onClick:O,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"23 4 23 10 17 10"}),c.jsx("polyline",{points:"1 20 1 14 7 14"}),c.jsx("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"})]}),"Regenerate"]}),c.jsxs("button",{className:"article-cover-overlay-btn",onClick:B,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),c.jsx("polyline",{points:"7 10 12 15 17 10"}),c.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),"Save"]}),c.jsxs("button",{className:"article-cover-overlay-btn article-cover-overlay-btn--danger",onClick:A,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),"Remove"]})]}),k&&c.jsx("button",{className:"article-cover-arrow article-cover-arrow--right",onClick:C,disabled:v>=b-1,children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})}),k&&c.jsxs("div",{className:"article-cover-counter",children:[v+1," / ",b]})]})]}):n==="loading"?c.jsxs("div",{className:"article-cover article-cover--loading",children:[c.jsx("div",{className:"article-cover-spinner"}),c.jsx("span",{className:"article-cover-loading-text",children:"Generating cover image..."})]}):n==="prompt"?c.jsxs("div",{className:"article-cover article-cover--prompt",children:[c.jsxs("div",{className:"article-cover-prompt-row",children:[c.jsx("input",{ref:g,className:"article-cover-prompt-input",value:d,onChange:$=>f($.target.value),onKeyDown:j,placeholder:"Describe your cover image...",spellCheck:!1}),c.jsx("button",{className:"article-cover-prompt-btn",onClick:T,disabled:!d.trim(),children:"Generate"}),c.jsx("button",{className:"article-cover-prompt-cancel",onClick:()=>{r(s?"display":"empty"),f(""),m("")},children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),h&&c.jsx("div",{className:"article-cover-error",children:h})]}):c.jsxs("div",{className:"article-cover article-cover--empty",onClick:_,children:[c.jsxs("svg",{className:"article-cover-icon",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),c.jsx("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),c.jsx("polyline",{points:"21 15 16 10 5 21"})]}),c.jsx("span",{className:"article-cover-hint",children:"We recommend an image with a 5:2 aspect ratio for best results."})]})}function fU(){const[t,e]=x.useState(()=>localStorage.getItem(ug)||""),[n,r]=x.useState(()=>localStorage.getItem(hE)||""),[s,i]=x.useState(!1),[o,l]=x.useState(""),d=x.useRef(null),f=x.useRef(null),h=()=>{const b=o.replace(/^@/,"").trim();b&&(localStorage.setItem(ug,b),e(b)),i(!1)},m=()=>{l(t),i(!0),setTimeout(()=>{var b;return(b=d.current)==null?void 0:b.focus()},0)};x.useEffect(()=>{if(!s)return;const b=k=>{f.current&&!f.current.contains(k.target)&&h()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[s,o]),x.useEffect(()=>{const b=()=>{e(localStorage.getItem(ug)||""),r(localStorage.getItem(hE)||"")};return window.addEventListener("storage",b),()=>window.removeEventListener("storage",b)},[]);const g=t?`https://unavatar.io/twitter/${t}`:"",v=n||t||"Set your @handle";return c.jsxs("div",{className:"article-byline",ref:f,children:[c.jsxs("div",{className:"article-byline-row",onClick:m,title:t?`@${t} — click to change`:"Set your @handle",children:[t?c.jsx("img",{className:"article-byline-avatar",src:g,alt:`@${t}`}):c.jsx("div",{className:"article-byline-avatar article-byline-avatar--empty"}),c.jsx("span",{className:"article-byline-name",children:v}),t&&c.jsxs("span",{className:"article-byline-handle",children:["@",t]})]}),s&&c.jsx("div",{className:"article-byline-popover",children:c.jsx("input",{ref:d,className:"article-byline-input",value:o,onChange:b=>l(b.target.value),onKeyDown:b=>{b.key==="Enter"&&h(),b.key==="Escape"&&i(!1)},placeholder:"your_handle",spellCheck:!1})})]})}function hU({children:t,title:e,onTitleChange:n,coverImage:r,coverImages:s,lastPost:i,pendingTitle:o,docId:l,autoplug:d}){const{copyAsHtml:f,copyState:h}=lU(),[m,g]=x.useState(i?"done":"idle"),v=uU.has(e||"")?"":e||"",b=CT(v,D=>n==null?void 0:n(D||"Untitled")),[k,w]=x.useState(!1),[E,C]=x.useState(!1);x.useEffect(()=>{function D(U){const q=U.detail;q&&(l&&q.docId&&q.docId!==l||(w(!!q.titleFocused),C(!!q.titleShowOriginal)))}return window.addEventListener("ow-pending-review-cursor",D),()=>window.removeEventListener("ow-pending-review-cursor",D)},[l]);const[T,j]=x.useState(!1),[_,A]=x.useState(""),O=x.useRef(null),B=x.useRef(null);x.useEffect(()=>{g(i?"done":"idle")},[i]),x.useEffect(()=>{if(!T)return;setTimeout(()=>{var U;return(U=O.current)==null?void 0:U.focus()},0);const D=U=>{B.current&&!B.current.contains(U.target)&&(j(!1),A(""))};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[T]);const $=x.useCallback(()=>{const D=_.trim();if(!(!D||D.includes("x.com")||D.includes("twitter.com")))return;const q=(i==null?void 0:i.postedAt)??new Date().toISOString();fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{lastPost:D?{postedAt:q,tweetUrl:D}:{postedAt:q}}}),keepalive:!0}).catch(()=>{}),g("done"),j(!1),A("")},[_,i==null?void 0:i.postedAt]),W=x.useCallback(()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{lastPost:null}}),keepalive:!0}).catch(()=>{}),g("idle")},[]),J=d!==!1,z=()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({autoplug:!J}),keepalive:!0}).catch(()=>{})},G=x.useCallback(()=>{if(m==="done"){W(),j(!1),A("");return}A((i==null?void 0:i.tweetUrl)??""),j(!0)},[m,i==null?void 0:i.tweetUrl,W]);return c.jsxs("div",{className:"article-compose-wrapper",children:[c.jsx(dU,{src:r,coverImages:s}),c.jsxs("div",{className:"article-compose-content",children:[o?E?c.jsx("div",{className:`article-title-input article-title-input--pending${k?" pending-active pending-active--original":""}`,title:`Showing original title. Toggle back to Modified to see the agent's proposal "${o.to}".`,"aria-label":`Original title ${o.from} (agent proposed ${o.to})`,children:c.jsx("span",{className:"pending-original",children:o.from})}):c.jsx("div",{className:`article-title-input article-title-input--pending${k?" pending-active pending-active--insert":""}`,title:`Agent proposed rename from "${o.from}". Accept or reject in the Review panel.`,"aria-label":`Pending title rename from ${o.from} to ${o.to}`,children:c.jsx("span",{className:"pending-insert",children:o.to})}):c.jsx("textarea",{className:"article-title-input",ref:b.ref,value:v,onChange:b.onChange,onKeyDown:b.onKeyDown,placeholder:"Add a title",rows:1,spellCheck:!1}),c.jsx(fU,{}),c.jsx("div",{className:"article-compose-body",children:t})]}),c.jsxs("div",{className:"article-compose-footer",children:[c.jsxs("div",{className:"article-mark-sent-wrap",ref:B,children:[c.jsx("button",{className:`article-mark-sent-btn${m==="done"?" article-mark-sent-btn--done":""}`,onClick:G,title:m==="done"?i!=null&&i.tweetUrl?`Posted — click to unmark (${i.tweetUrl})`:"Posted — click to unmark":"Mark as manually posted",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:m==="done"?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"8 12 11 15 16 9",stroke:m==="done"?"#fff":"currentColor"})]})}),T&&(()=>{const D=_.trim(),U=!D||D.includes("x.com")||D.includes("twitter.com");return c.jsxs("div",{className:"article-mark-sent-url",children:[c.jsx("input",{ref:O,type:"text",placeholder:"Paste posted tweet URL...",value:_,onChange:q=>A(q.target.value),onKeyDown:q=>{q.key==="Enter"&&(q.preventDefault(),$()),q.key==="Escape"&&(j(!1),A(""))}}),c.jsx("button",{onClick:$,disabled:!U,title:D?"Save URL":"Mark posted without URL",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})})]})})()]}),c.jsx("button",{className:`article-autoplug-toggle${J?" article-autoplug-toggle--on":""}`,onClick:z,title:J?"Auto-plug ON — engagement autoplugs may reply to this post with your configured promo. Click to opt out.":"Auto-plug OFF — this post is excluded from autoplugs. Click to opt in.",children:J?"Auto-plug on":"Auto-plug off"}),m==="done"&&i&&(i.tweetUrl?c.jsxs("a",{className:"article-sent-status",href:i.tweetUrl,target:"_blank",rel:"noopener noreferrer",children:["Posted ",new Date(i.postedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})]}):c.jsxs("span",{className:"article-sent-status",children:["Posted ",new Date(i.postedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})]})),c.jsx("button",{className:`article-copy-btn${h==="copied"?" article-copy-btn--copied":""}`,onClick:f,children:h==="copied"?c.jsxs(c.Fragment,{children:[c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Copied!"]}):c.jsxs(c.Fragment,{children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),c.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),"Copy as HTML"]})})]})]})}const pU={font:"sans",width:"standard",spacing:"comfortable"},pE=new Set(["Untitled","New Document","Blog"]),mU=[];function gU(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80)}function mE(){return new Date().toISOString().split("T")[0]}function yi(t){fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({blogContext:t})}).catch(()=>{})}function vU({src:t,coverImages:e}){const[n,r]=x.useState(t?"display":"empty"),[s,i]=x.useState(t||""),[o,l]=x.useState(e||(t?[t]:[])),[d,f]=x.useState(""),[h,m]=x.useState(""),g=x.useRef(null);x.useEffect(()=>{t?(i(t),r("display")):(i(""),r("empty"),f(""),m(""))},[t]),x.useEffect(()=>{e&&e.length>0?l(e):l(t?[t]:[])},[e]);const v=s?o.indexOf(s):-1,b=o.length,k=b>1,w=x.useCallback($=>{const W=o[$];W&&(i(W),yi({coverImage:W,coverImages:o}))},[o]),E=x.useCallback(()=>{v>0&&w(v-1)},[v,w]),C=x.useCallback(()=>{v<b-1&&w(v+1)},[v,b,w]),T=x.useCallback(async()=>{if(d.trim()){r("loading"),m("");try{const $=await fetch("/api/image-gen/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:d.trim()})});if(!$.ok){const J=await $.json().catch(()=>null);m((J==null?void 0:J.error)||`Generation failed (${$.status})`),r("prompt");return}const W=await $.json();if(W.success&&W.src){const J=[...o,W.src];l(J),i(W.src),r("display"),f(""),yi({coverImage:W.src,coverImages:J})}else m(W.error||"Generation failed"),r("prompt")}catch($){m($.message||"Network error"),r("prompt")}}},[d,o]),j=$=>{$.key==="Enter"&&T(),$.key==="Escape"&&(r("empty"),f(""),m(""))},_=()=>{r("prompt"),setTimeout(()=>{var $;return($=g.current)==null?void 0:$.focus()},0)},A=()=>{const $=o.filter(W=>W!==s);if(l($),$.length>0){const W=Math.min(v,$.length-1),J=$[W];i(J),yi({coverImage:J,coverImages:$})}else i(""),r("empty"),yi({coverImage:void 0,coverImages:void 0})},O=()=>{r("prompt"),setTimeout(()=>{var $;return($=g.current)==null?void 0:$.focus()},0)},B=()=>{const $=document.createElement("a");$.href=s,$.download=`cover-${v+1}.png`,$.click()};return n==="display"&&s?c.jsxs("div",{className:"blog-cover blog-cover--display",children:[c.jsx("img",{className:"blog-cover-img",src:s,alt:"Cover"}),c.jsxs("div",{className:"blog-cover-overlay",children:[k&&c.jsx("button",{className:"blog-cover-arrow blog-cover-arrow--left",onClick:E,disabled:v<=0,children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"15 18 9 12 15 6"})})}),c.jsxs("div",{className:"blog-cover-overlay-center",children:[c.jsxs("button",{className:"blog-cover-btn",onClick:O,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"23 4 23 10 17 10"}),c.jsx("polyline",{points:"1 20 1 14 7 14"}),c.jsx("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"})]}),"Regenerate"]}),c.jsxs("button",{className:"blog-cover-btn",onClick:B,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),c.jsx("polyline",{points:"7 10 12 15 17 10"}),c.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),"Save"]}),c.jsxs("button",{className:"blog-cover-btn blog-cover-btn--danger",onClick:A,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),"Remove"]})]}),k&&c.jsx("button",{className:"blog-cover-arrow blog-cover-arrow--right",onClick:C,disabled:v>=b-1,children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})}),k&&c.jsxs("div",{className:"blog-cover-counter",children:[v+1," / ",b]})]})]}):n==="loading"?c.jsxs("div",{className:"blog-cover blog-cover--loading",children:[c.jsx("div",{className:"blog-cover-spinner"}),c.jsx("span",{className:"blog-cover-loading-text",children:"Generating cover image..."})]}):n==="prompt"?c.jsxs("div",{className:"blog-cover blog-cover--prompt",children:[c.jsxs("div",{className:"blog-cover-prompt-row",children:[c.jsx("input",{ref:g,className:"blog-cover-prompt-input",value:d,onChange:$=>f($.target.value),onKeyDown:j,placeholder:"Describe your cover image...",spellCheck:!1}),c.jsx("button",{className:"blog-cover-prompt-btn",onClick:T,disabled:!d.trim(),children:"Generate"}),c.jsx("button",{className:"blog-cover-prompt-cancel",onClick:()=>{r(s?"display":"empty"),f(""),m("")},children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),h&&c.jsx("div",{className:"blog-cover-error",children:h})]}):c.jsxs("div",{className:"blog-cover blog-cover--empty",onClick:_,children:[c.jsxs("svg",{className:"blog-cover-icon",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),c.jsx("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),c.jsx("polyline",{points:"21 15 16 10 5 21"})]}),c.jsx("span",{className:"blog-cover-hint",children:"Add a featured image"})]})}function yU({tags:t,onChange:e}){const[n,r]=x.useState(""),s=x.useRef(null),i=d=>{const f=d.trim().toLowerCase();f&&!t.includes(f)&&e([...t,f]),r("")},o=d=>e(t.filter(f=>f!==d)),l=d=>{(d.key==="Enter"||d.key===",")&&(d.preventDefault(),i(n)),d.key==="Backspace"&&!n&&t.length>0&&o(t[t.length-1])};return c.jsxs("div",{className:"blog-tags",onClick:()=>{var d;return(d=s.current)==null?void 0:d.focus()},children:[t.map(d=>c.jsxs("span",{className:"blog-tag",children:[d,c.jsx("button",{className:"blog-tag-remove",onClick:f=>{f.stopPropagation(),o(d)},children:c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},d)),c.jsx("input",{ref:s,className:"blog-tag-input",value:n,onChange:d=>r(d.target.value),onKeyDown:l,onBlur:()=>{n.trim()&&i(n)},placeholder:t.length===0?"Add tags...":"",spellCheck:!1})]})}function bU({style:t,onChange:e}){const n=r=>`blog-style-btn${r?" active":""}`;return c.jsxs("div",{className:"blog-style-controls",children:[c.jsxs("div",{className:"blog-style-group",children:[c.jsx("span",{className:"blog-style-label",children:"Font"}),c.jsx("button",{className:n(t.font==="sans"),onClick:()=>e({...t,font:"sans"}),title:"Sans-serif",children:"Aa"}),c.jsx("button",{className:`${n(t.font==="serif")} serif-btn`,onClick:()=>e({...t,font:"serif"}),title:"Serif",children:"Aa"}),c.jsx("button",{className:`${n(t.font==="mono")} mono-btn`,onClick:()=>e({...t,font:"mono"}),title:"Monospace",children:"Aa"})]}),c.jsxs("div",{className:"blog-style-group",children:[c.jsx("span",{className:"blog-style-label",children:"Width"}),c.jsx("button",{className:n(t.width==="narrow"),onClick:()=>e({...t,width:"narrow"}),title:"Narrow (600px)",children:c.jsx("svg",{width:"16",height:"14",viewBox:"0 0 16 14",children:c.jsx("rect",{x:"4",y:"1",width:"8",height:"12",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})})}),c.jsx("button",{className:n(t.width==="standard"),onClick:()=>e({...t,width:"standard"}),title:"Standard (720px)",children:c.jsx("svg",{width:"16",height:"14",viewBox:"0 0 16 14",children:c.jsx("rect",{x:"2",y:"1",width:"12",height:"12",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})})}),c.jsx("button",{className:n(t.width==="wide"),onClick:()=>e({...t,width:"wide"}),title:"Wide (900px)",children:c.jsx("svg",{width:"16",height:"14",viewBox:"0 0 16 14",children:c.jsx("rect",{x:"0.5",y:"1",width:"15",height:"12",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})})})]}),c.jsxs("div",{className:"blog-style-group",children:[c.jsx("span",{className:"blog-style-label",children:"Spacing"}),c.jsx("button",{className:n(t.spacing==="compact"),onClick:()=>e({...t,spacing:"compact"}),title:"Compact",children:c.jsxs("svg",{width:"16",height:"14",viewBox:"0 0 16 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[c.jsx("line",{x1:"1",y1:"3",x2:"15",y2:"3"}),c.jsx("line",{x1:"1",y1:"7",x2:"15",y2:"7"}),c.jsx("line",{x1:"1",y1:"11",x2:"15",y2:"11"})]})}),c.jsx("button",{className:n(t.spacing==="comfortable"),onClick:()=>e({...t,spacing:"comfortable"}),title:"Comfortable",children:c.jsxs("svg",{width:"16",height:"14",viewBox:"0 0 16 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[c.jsx("line",{x1:"1",y1:"2",x2:"15",y2:"2"}),c.jsx("line",{x1:"1",y1:"7",x2:"15",y2:"7"}),c.jsx("line",{x1:"1",y1:"12",x2:"15",y2:"12"})]})})]})]})}function xU({children:t,title:e,onTitleChange:n,blogContext:r,filename:s}){var V;const i=r||{},o=!!(r!=null&&r.active),l=pE.has(e||"")?"":e||"",d=CT(l,te=>n==null?void 0:n(te||"Untitled")),[f,h]=x.useState(i.description||""),[m,g]=x.useState(i.date||mE()),[v,b]=x.useState(i.author||""),[k,w]=x.useState(i.slug||""),[E,C]=x.useState(!!i.slug),[T,j]=x.useState(!1),[_,A]=x.useState(!1),[O,B]=x.useState(!1),[$,W]=x.useState(!1),J=i.tags||mU,z=i.draft??!1,G=x.useMemo(()=>({...pU,...i.style}),[i.style]);x.useEffect(()=>{h(i.description||""),g(i.date||mE()),b(i.author||""),w(i.slug||""),C(!!i.slug)},[s]),x.useEffect(()=>{fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"list_blog_sites",arguments:{}})}).then(te=>te.json()).then(te=>{var M,L;const K=(L=(M=te==null?void 0:te.content)==null?void 0:M[0])!=null&&L.text?JSON.parse(te.content[0].text):te;B(Array.isArray(K==null?void 0:K.sites)&&K.sites.length>0)}).catch(()=>{})},[]),x.useEffect(()=>{!E&&e&&!pE.has(e)&&w(gU(e))},[e,E]);const D=x.useCallback(()=>{o&&yi({description:f,date:m,author:v,slug:k})},[o,f,m,v,k]),U=f.length,q=U>160,se=["blog-compose-wrapper",`blog--font-${G.font}`,`blog--width-${G.width}`,`blog--spacing-${G.spacing}`].join(" ");return c.jsxs("div",{className:se,children:[c.jsx(vU,{src:i.coverImage,coverImages:i.coverImages}),c.jsxs("div",{className:"blog-compose-content",children:[((V=i.lastPublish)==null?void 0:V.publishedAt)&&c.jsxs("a",{className:"blog-published-status",href:i.lastPublish.url,target:"_blank",rel:"noopener noreferrer",title:i.lastPublish.url||`Published to ${i.lastPublish.repo||"GitHub"}`,children:[c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Published ",new Date(i.lastPublish.publishedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"}),i.lastPublish.repo?` to ${i.lastPublish.repo.split("/").pop()}`:""]}),c.jsx("textarea",{className:"blog-title-input",ref:d.ref,value:l,onChange:d.onChange,onKeyDown:d.onKeyDown,placeholder:"Post title",rows:1,spellCheck:!1}),c.jsxs("div",{className:"blog-description-wrap",children:[c.jsx("textarea",{className:`blog-description-input${q?" over-limit":""}`,value:f,onChange:te=>h(te.target.value),onBlur:D,placeholder:"Write a short description for SEO and social previews...",rows:2,spellCheck:!1}),c.jsxs("span",{className:`blog-description-count${q?" over-limit":""}`,children:[U,"/160"]})]}),c.jsxs("div",{className:"blog-meta-toggle",onClick:()=>A(te=>!te),children:[c.jsx("svg",{className:`blog-meta-chevron${_?" open":""}`,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})}),c.jsx("span",{children:"Metadata"}),z&&c.jsx("span",{className:"blog-draft-badge",children:"Draft"})]}),_&&c.jsxs("div",{className:"blog-meta-fields",children:[c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Date"}),c.jsx("input",{type:"date",className:"blog-meta-input",value:m,onChange:te=>g(te.target.value),onBlur:D})]}),c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Author"}),c.jsx("input",{type:"text",className:"blog-meta-input",value:v,onChange:te=>b(te.target.value),onBlur:D,placeholder:"Author name",spellCheck:!1})]}),c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Slug"}),c.jsx("input",{type:"text",className:"blog-meta-input",value:k,onChange:te=>{C(!0),w(te.target.value)},onBlur:D,placeholder:"auto-generated-from-title",spellCheck:!1})]}),c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Tags"}),c.jsx(yU,{tags:J,onChange:te=>{o&&yi({tags:te})}})]}),c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Draft"}),c.jsx("button",{className:`blog-draft-toggle${z?" active":""}`,onClick:()=>{o&&yi({draft:!z})},children:c.jsx("div",{className:"blog-draft-toggle-knob"})})]})]}),c.jsx("div",{className:"blog-compose-body",children:t})]}),c.jsxs("div",{className:"blog-compose-footer",children:[c.jsx(bU,{style:G,onChange:te=>{o&&yi({style:te})}}),s&&c.jsxs("div",{className:"blog-footer-actions",children:[O&&c.jsxs("button",{className:"blog-footer-btn blog-footer-btn--primary",onClick:()=>W(!0),children:[c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"})}),"Publish"]}),c.jsxs("button",{className:"blog-footer-btn",onClick:()=>j(!0),children:[c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"12 6 12 12 16 14"})]}),"Schedule"]})]})]}),T&&s&&c.jsx(Dl,{filename:s,title:e||"Untitled",onClose:()=>j(!1)}),$&&s&&c.jsx(_2,{filename:s,title:e||"Untitled",isActive:!0,onSwitchDocument:()=>{},onClose:()=>W(!1)})]})}function wU({connectionId:t,subject:e,filename:n,onBeforeSend:r,onClose:s}){const[i,o]=x.useState("confirm"),[l,d]=x.useState("html"),[f,h]=x.useState(""),[m,g]=x.useState(null),[v,b]=x.useState(null),[k,w]=x.useState(0),[E,C]=x.useState(null),[T,j]=x.useState(null),[_,A]=x.useState("all"),[O,B]=x.useState([]),[$,W]=x.useState(""),J=x.useRef(null),z=O.find(q=>q.id===$),G=_==="exclude_issue"&&z&&T!=null?Math.max(0,T-z.recipient_count):T;x.useEffect(()=>{fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"list_subscribers",arguments:{limit:1}})}).then(q=>q.json()).then(q=>{var V,te;const se=(te=(V=q.content)==null?void 0:V[0])!=null&&te.text?JSON.parse(q.content[0].text):q;se.count!=null&&j(se.count)}).catch(()=>{}),fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"list_newsletter_issues",arguments:{limit:10}})}).then(q=>q.json()).then(q=>{var V,te;const se=(te=(V=q.content)==null?void 0:V[0])!=null&&te.text?JSON.parse(q.content[0].text):q;se.issues&&B(se.issues)}).catch(()=>{})},[]);const D=()=>i==="sent"?{sentCount:k,issueId:E,sentAt:new Date().toISOString()}:void 0;x.useEffect(()=>{const q=se=>{i!=="sending"&&i!=="testing"&&J.current&&!J.current.contains(se.target)&&s(D())};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[s,i,k,E]),x.useEffect(()=>{const q=se=>{se.key==="Escape"&&i!=="sending"&&i!=="testing"&&s(D())};return document.addEventListener("keydown",q),()=>document.removeEventListener("keydown",q)},[s,i,k,E]);async function U(q){var se,V;o(q?"testing":"sending"),b(null);try{r&&await r();const te={subject:e,connectionId:t,format:l};q&&(te.test_email=q),!q&&_==="exclude_issue"&&$&&(te.exclude_issue_id=$);const M=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"send_newsletter",arguments:te})})).json(),L=(V=(se=M.content)==null?void 0:se[0])!=null&&V.text?JSON.parse(M.content[0].text):M;if(L.error){b(L.error),o("error");return}if(L.test){g(L.sent_to),o("confirm");return}const ee=L.sent||0,fe=L.issueId||null,ge=new Date().toISOString();w(ee),C(fe),o("sent"),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({newsletterContext:{lastSend:{sentCount:ee,sentAt:ge,issueId:fe||void 0}}})}).catch(()=>{})}catch(te){b(te.message),o("error")}}return c.jsx("div",{className:"newsletter-modal-overlay",children:c.jsxs("div",{className:"newsletter-modal",ref:J,children:[c.jsxs("div",{className:"newsletter-modal__header",children:[c.jsx("h3",{children:"Send Newsletter"}),c.jsx("button",{className:"newsletter-modal__close",onClick:()=>s(D()),children:"×"})]}),c.jsxs("div",{className:"newsletter-modal__body",children:[i==="confirm"&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{className:"newsletter-modal__confirm-text",style:G==null?{visibility:"hidden"}:void 0,children:['Send "',c.jsx("strong",{children:e}),'" to ',G!=null?G.toLocaleString():0," subscriber",G!==1?"s":"","?"]}),c.jsxs("div",{className:"newsletter-modal__audience",children:[c.jsx("label",{className:"newsletter-modal__label",children:"Audience"}),c.jsxs("select",{className:"newsletter-modal__select",value:_,onChange:q=>{const se=q.target.value;A(se),se==="all"&&W("")},children:[c.jsx("option",{value:"all",children:"All subscribers"}),O.length>0&&c.jsx("option",{value:"exclude_issue",children:"Exclude who received..."})]}),_==="exclude_issue"&&c.jsxs("select",{className:"newsletter-modal__select",value:$,onChange:q=>W(q.target.value),children:[c.jsx("option",{value:"",children:"Select a past issue"}),O.map(q=>c.jsxs("option",{value:q.id,children:[q.subject," (",q.recipient_count," sent)"]},q.id))]})]}),c.jsxs("div",{className:"newsletter-modal__format-toggle",children:[c.jsx("button",{className:`newsletter-modal__format-btn${l==="html"?" active":""}`,onClick:()=>d("html"),children:"HTML"}),c.jsx("button",{className:`newsletter-modal__format-btn${l==="plaintext"?" active":""}`,onClick:()=>d("plaintext"),children:"Plaintext"})]}),c.jsxs("div",{className:"newsletter-modal__test-section",children:[c.jsxs("div",{className:"newsletter-modal__test-row",children:[c.jsx("input",{type:"email",className:"newsletter-modal__test-input",placeholder:"Test email address",value:f,onChange:q=>h(q.target.value),onKeyDown:q=>{q.key==="Enter"&&f.trim()&&U(f.trim())}}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--test",disabled:!f.trim(),onClick:()=>U(f.trim()),children:"Send Test"})]}),m&&c.jsxs("p",{className:"newsletter-modal__test-success",children:["Test sent to ",m]})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:s,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",disabled:_==="exclude_issue"&&!$,onClick:()=>U(),children:"Send Now"})]})]}),(i==="sending"||i==="testing")&&c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:i==="testing"?"Sending test...":"Sending..."})]}),i==="sent"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__status newsletter-modal__status--success",children:["Sent to ",k," subscriber",k!==1?"s":"","!"]}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>s({sentCount:k,issueId:E,sentAt:new Date().toISOString()}),children:"Done"})})]}),i==="error"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__error",children:v}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:s,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>U(),children:"Retry"})]})]})]})]})})}function gE(t){fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({newsletterContext:t})}).catch(()=>{})}function kU({children:t,newsletterContext:e,filename:n,title:r,onTitleChange:s,onBeforeSend:i}){var D;const o=e||{},[l,d]=x.useState(o.subject||""),[f,h]=x.useState(o.previewText||""),[m,g]=x.useState([]),[v,b]=x.useState(null),[k,w]=x.useState(!1),[E,C]=x.useState((D=o.lastSend)!=null&&D.sentAt?{sentCount:o.lastSend.sentCount,issueId:o.lastSend.issueId||null,sentAt:o.lastSend.sentAt}:null),T=x.useRef(null),j=x.useRef(n),_=x.useRef(o.subject||""),A=x.useRef(o.previewText||"");x.useEffect(()=>{var U;if(j.current!==n)d(o.subject||""),h(o.previewText||""),_.current=o.subject||"",A.current=o.previewText||"",j.current=n;else{const q=o.subject||"",se=o.previewText||"";q!==_.current&&(d(q),_.current=q),se!==A.current&&(h(se),A.current=se)}C((U=o.lastSend)!=null&&U.sentAt?{sentCount:o.lastSend.sentCount,issueId:o.lastSend.issueId||null,sentAt:o.lastSend.sentAt}:null)},[e,n]),x.useEffect(()=>{fetch("/api/connections").then(U=>U.json()).then(U=>{const q=(U.connections||[]).filter(se=>se.provider==="newsletter"&&se.status==="active");g(q)}).catch(()=>{})},[]);const O=!!(e!=null&&e.active),B=x.useRef();x.useEffect(()=>{if(B.current&&clearTimeout(B.current),!(!s||!l.trim()))return B.current=setTimeout(async()=>{const U=r,q=!U||U==="Untitled",se=T.current!==null&&U===T.current;if(q||se){try{await fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({newsletterContext:{subject:l}})})}catch{}s(l.trim()),T.current=l.trim()}},500),()=>{B.current&&clearTimeout(B.current)}},[l,r,s]);const $=x.useCallback(()=>{O&&(_.current=l,A.current=f,gE({subject:l,previewText:f}))},[O,l,f]),W=f.length,J=W>=90,z=W>150,G=()=>{m.length===1&&b(m[0].id),m.length>1&&b(m[0].id)};return c.jsxs("div",{className:"nl-compose-wrapper",children:[E&&c.jsxs("div",{className:"nl-sent-status",children:[c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Sent ",new Date(E.sentAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})," to ",E.sentCount," subscriber",E.sentCount!==1?"s":""]}),c.jsxs("div",{className:"nl-compose-content",children:[c.jsx("input",{className:"nl-subject-input",type:"text",value:l,onChange:U=>d(U.target.value),onBlur:$,placeholder:"Subject line (defaults to title if empty)",autoComplete:"off","data-lpignore":"true","data-1p-ignore":!0,spellCheck:!1}),c.jsxs("div",{className:"nl-preview-wrap",children:[c.jsx("textarea",{className:`nl-preview-input${z?" over-limit":""}`,value:f,onChange:U=>h(U.target.value),onBlur:$,placeholder:"Preview text shown in inbox before opening...",rows:2,spellCheck:!1}),c.jsxs("span",{className:`nl-preview-count${z?" over-limit":J?" full":""}`,children:[W,"/90"]})]}),c.jsx("div",{className:"nl-compose-body",children:t})]}),n&&c.jsxs("div",{className:"nl-compose-footer",children:[m.length>0&&c.jsxs("button",{className:"nl-footer-btn nl-footer-btn--primary",onClick:G,children:[c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),c.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]}),"Send"]}),c.jsxs("button",{className:"nl-footer-btn",onClick:()=>w(!0),children:[c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"12 6 12 12 16 14"})]}),"Schedule"]})]}),v&&n&&c.jsx(wU,{connectionId:v,subject:l||r||"Untitled",filename:n,onBeforeSend:i,onClose:U=>{b(null),U&&(C(U),gE({lastSend:{sentCount:U.sentCount,sentAt:U.sentAt,issueId:U.issueId||void 0}}))}}),k&&n&&c.jsx(Dl,{filename:n,title:r||"Untitled",onClose:()=>w(!1)})]})}function Eu(t){return t!=null&&typeof t=="object"&&Object.keys(t).length>0}function SU(t){const e=typeof(t==null?void 0:t.content_type)=="string"&&t.content_type||typeof(t==null?void 0:t.contentType)=="string"&&t.contentType||"";return e||(Eu(t==null?void 0:t.blogContext)?"blog":t!=null&&t.newsletterContext&&(t.newsletterContext.active===!0||Eu(t.newsletterContext))?"newsletter":Eu(t==null?void 0:t.articleContext)?"article":t!=null&&t.tweetContext?t.tweetContext.mode||"tweet":Eu(t==null?void 0:t.linkedinContext)?"linkedin":"document")}function EU(){var _r,Wr,is;const t=x.useRef(null),e=x.useRef([]),[n,r]=x.useState(null),[s,i]=x.useState(null),[o,l]=x.useState([]),[d,f]=x.useState("Untitled"),[h,m]=x.useState(null),[g,v]=x.useState(void 0),[b,k]=x.useState(0),[w,E]=x.useState(!0),[C,T]=x.useState(0),[j,_]=x.useState(0),[A,O]=x.useState(0),[B,$]=x.useState({filenames:[],counts:{}}),[W,J]=x.useState({state:"unconfigured"}),[z,G]=x.useState(!1),[D,U]=x.useState({}),[q,se]=x.useState(()=>localStorage.getItem("ow-toolbar")!=="hidden"),[V,te]=x.useState(!1),K=x.useRef(null),[M,L]=x.useState(null),[ee,fe]=x.useState(null),[ge,oe]=x.useState(new Set),we=x.useRef(0),xe=x.useRef(null),We=1500,He=x.useCallback((ie,je)=>{xe.current&&(clearTimeout(xe.current),xe.current=null),we.current=Date.now(),L(ie),fe(je)},[]),Ze=x.useCallback(()=>{if(xe.current)return;const ie=Date.now()-we.current,je=We-ie;je<=0?(L(null),fe(null)):xe.current=setTimeout(()=>{xe.current=null,L(null),fe(null)},je)},[]),[,Oe]=x.useState(0),[Ke,pt]=x.useState(null),Je=x.useRef(null),pe=x.useRef(null),mt=x.useRef(null),ft=x.useRef([]),at=x.useRef(-1),nt=x.useRef(null),ht=x.useRef(!1),Fe=x.useRef(""),[ve,X]=x.useState(""),[Be,ne]=x.useState(!1),[de,he]=x.useState(!1);function Ge(){const ie=document.querySelector(".editor-container");return(ie==null?void 0:ie.scrollTop)||0}function Pe(){if(at.current<0)return;const ie=ft.current[at.current];ie&&(ie.scrollTop=Ge())}const et=SU(D),ot=et==="article",bt=et==="blog",Ye=et==="newsletter",it=et==="tweet"||et==="reply"||et==="quote";x.useEffect(()=>(ot?document.documentElement.setAttribute("data-view","article"):bt?document.documentElement.setAttribute("data-view","blog"):Ye?document.documentElement.setAttribute("data-view","newsletter"):it?document.documentElement.setAttribute("data-view","tweet"):document.documentElement.removeAttribute("data-view"),()=>document.documentElement.removeAttribute("data-view")),[it,ot,bt,Ye]),x.useEffect(()=>{const ie=()=>Oe(je=>je+1);return window.addEventListener("ow-sidebar-mode-change",ie),()=>window.removeEventListener("ow-sidebar-mode-change",ie)},[]),x.useEffect(()=>{fetch("/api/document",{cache:"no-store"}).then(ie=>ie.json()).then(ie=>{ie.document&&(v(ie.document),pe.current=ie.document),ie.title&&f(ie.title),ie.metadata&&U(ie.metadata)}).catch(()=>{v(void 0)}),fetch("/api/pending-docs").then(ie=>ie.json()).then(ie=>$(ie)).catch(()=>{}),fetch("/api/sync/status").then(ie=>ie.json()).then(ie=>J(ie)).catch(()=>{})},[]);const gt=x.useCallback(ie=>{t.current=ie,r(ie),i(null),e.current=[ie],l([ie])},[]),Nt=x.useRef([]),Ie=x.useCallback(ie=>{if(e.current=ie,l(ie),Nt.current.length>0&&ie.length>0){const je=Nt.current;Nt.current=[];for(const ze of ie)ze.isDestroyed||Tp(ze,je)}},[]),Me=x.useCallback(ie=>{var tr,qr;const je=performance.now(),ze=window.__lastSwitch;ze&&ze.filename===ie.filename?(ze.tReceive=je,console.log(`[Switch] RECEIVE filename=${ie.filename} sendToReceive=${(je-ze.tSend).toFixed(1)}ms (server round-trip)`)):console.log(`[Switch] RECEIVE filename=${ie.filename} (no matching CLICK — agent or initial-load switch)`),Je.current&&(clearTimeout(Je.current),Je.current=null);const _t=Fe.current==="",Rt=ie.filename===Fe.current;Fe.current=ie.filename,pe.current=ie.document,mt.current=JSON.stringify(ie.document),X(ie.filename),v(ie.document),f(ie.title),U(ie.metadata||{}),m(((tr=ie.pendingMetadata)==null?void 0:tr.title)??null),!Rt&&!_t&&((qr=ie.metadata)!=null&&qr.tweetContext)&&k(Kt=>Kt+1),ze&&ze.filename===ie.filename&&requestAnimationFrame(()=>{const Kt=performance.now();ze.tCommit=Kt,console.log(`[Switch] COMMIT filename=${ie.filename} receiveToCommit=${(Kt-je).toFixed(1)}ms totalClickToPaint=${(Kt-ze.tClick).toFixed(1)}ms`)});const It=nt.current??"push";if(nt.current=null,ft.current.length===0?(ft.current=[{filename:ie.filename,scrollTop:0}],at.current=0):It==="back"?at.current=Math.max(0,at.current-1):It==="forward"?at.current=Math.min(ft.current.length-1,at.current+1):Rt||(ft.current=ft.current.slice(0,at.current+1),ft.current.push({filename:ie.filename,scrollTop:0}),at.current=ft.current.length-1),!ht.current){const Kt=`#${encodeURIComponent(ie.filename)}`,Vn={ow:{filename:ie.filename,navIndex:at.current}};ft.current.length===1||Rt?window.history.replaceState(Vn,"",Kt):window.history.pushState(Vn,"",Kt)}if(ht.current=!1,It==="back"||It==="forward"){const Kt=ft.current[at.current];Kt&&setTimeout(()=>{const Vn=document.querySelector(".editor-container");Vn&&(Vn.scrollTop=Kt.scrollTop)},50)}ne(at.current>0),he(at.current<ft.current.length-1)},[]),qe=x.useCallback(ie=>{Je.current&&(clearTimeout(Je.current),Je.current=null),pe.current=ie.document,mt.current=JSON.stringify(ie.document),v(ie.document),f(ie.title),U(ie.metadata||{}),pt(je=>je?{filename:ie.filename,orphanCount:je.orphanCount+ie.orphanCount,staleBaselineCount:je.staleBaselineCount+ie.staleBaselineCount,reloadCount:je.reloadCount+1}:{filename:ie.filename,orphanCount:ie.orphanCount,staleBaselineCount:ie.staleBaselineCount,reloadCount:1})},[]),F=x.useCallback(()=>{T(ie=>ie+1),_(ie=>ie+1)},[]),ce=x.useCallback(()=>{O(ie=>ie+1)},[]),Ne=x.useCallback(ie=>{$(ie)},[]),{connected:P,sendMessage:Z,docVersionRef:I}=G$({onNodeChanges:ie=>{const je=e.current;if(je.length<=1){const ze=t.current;if(!ze)return;Tp(ze,ie)}else{if(je.some(_t=>_t.isDestroyed)){Nt.current.push(...ie);return}for(const _t of je)Tp(_t,ie)}},onDocumentSwitched:Me,onDocumentReloaded:qe,onDocumentsChanged:F,onWorkspacesChanged:ce,onPendingDocsChanged:Ne,onMetadataChanged:ie=>U(ie),onWritingStarted:(ie,je)=>He(ie,je),onWritingFinished:()=>Ze(),onIdRewrites:ie=>{const je=e.current,ze=je.length>0?je:t.current?[t.current]:[];for(const Rt of ze)Rt.isDestroyed||H5(Rt,ie);const _t=pe.current;if(_t&&Array.isArray(ie)&&ie.length>0){const Rt=new Map(ie.map(tr=>[tr.oldId,tr.newId])),It=tr=>{var qr;if(Array.isArray(tr))for(const Kt of tr){const Vn=(qr=Kt==null?void 0:Kt.attrs)==null?void 0:qr.id;Vn&&Rt.has(Vn)&&(Kt.attrs={...Kt.attrs,id:Rt.get(Vn)}),Kt!=null&&Kt.content&&It(Kt.content)}};It(_t.content||[])}},onPendingFilenamesChanged:ie=>oe(ie),onSyncStatus:ie=>J(ie),onTitleChanged:ie=>f(ie),getEditorState:()=>{var je;const ie=pe.current||((je=t.current)==null?void 0:je.getJSON());return ie?{document:ie}:null}}),re=x.useCallback(()=>{var ze;Je.current&&(clearTimeout(Je.current),Je.current=null);const ie=pe.current||((ze=t.current)==null?void 0:ze.getJSON());if(!ie)return;const je=JSON.stringify(ie);je!==mt.current&&(Z({type:"doc-update",document:ie,filename:Fe.current,version:I.current}),mt.current=je)},[Z,I]),ye=x.useCallback(async()=>{var je;const ie=pe.current||((je=t.current)==null?void 0:je.getJSON());ie&&await fetch("/api/documents/sync-content",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({document:ie,filename:Fe.current})})},[]);x.useEffect(()=>{const ie=()=>{var Rt;Je.current&&(clearTimeout(Je.current),Je.current=null);const ze=pe.current||((Rt=t.current)==null?void 0:Rt.getJSON());if(!ze)return;const _t=JSON.stringify({type:"flush",document:ze});navigator.sendBeacon("/api/flush",new Blob([_t],{type:"application/json"}))},je=()=>{document.visibilityState==="hidden"&&ie()};return window.addEventListener("beforeunload",ie),document.addEventListener("visibilitychange",je),()=>{window.removeEventListener("beforeunload",ie),document.removeEventListener("visibilitychange",je)}},[]);const Te=x.useCallback(()=>{re(),Z({type:"create-document"})},[re,Z]),Se=x.useCallback(ie=>{if(ie===Fe.current)return;const je=performance.now();window.__lastSwitch={filename:ie,tClick:je,tSend:0,tReceive:0,tCommit:0},console.log(`[Switch] CLICK filename=${ie} t=${je.toFixed(0)}`),Pe(),nt.current="push",re(),Z({type:"switch-document",filename:ie});const ze=performance.now();window.__lastSwitch.tSend=ze,console.log(`[Switch] SEND filename=${ie} clickToSend=${(ze-je).toFixed(1)}ms`)},[re,Z]),Ee=x.useRef(null),me=x.useCallback(async ie=>{let je=null;if(ie.docId)try{const ze=await fetch("/api/documents").then(_t=>_t.json());if(Array.isArray(ze)){const _t=ze.find(Rt=>Rt.docId===ie.docId);_t&&(je=_t.filename)}}catch{}if(!je&&ie.filename&&(je=ie.filename),!je){console.warn("[link] could not resolve doc: target",ie);return}ie.nodeId||ie.quote?Ee.current={nodeId:ie.nodeId||void 0,quote:ie.quote||void 0}:Ee.current={toTop:!0},Se(je)},[Se]);x.useEffect(()=>{const ie=je=>{const ze=je.detail;ze&&me(ze)};return window.addEventListener("ow-navigate-to-link",ie),()=>window.removeEventListener("ow-navigate-to-link",ie)},[me]);const ke=x.useRef(!1);x.useEffect(()=>{if(ke.current)return;ke.current=!0;const ie=window.location.pathname.match(/^\/d\/([a-f0-9]{8})\/?$/);if(!ie)return;const je=ie[1],ze=window.location.hash.match(/^#node=([a-f0-9]{8})$/),_t=ze?ze[1]:null;me({docId:je,filename:null,nodeId:_t,quote:null})},[me]),x.useEffect(()=>{if(!n||!Ee.current)return;const ie=Ee.current;Ee.current=null,setTimeout(()=>{if(ie.toTop){const _t=document.querySelector(".editor-container");_t&&(_t.scrollTop=0);return}let je=null;if(ie.nodeId&&n.state.doc.descendants((_t,Rt)=>{var It;return je!==null?!1:((It=_t.attrs)==null?void 0:It.id)===ie.nodeId?(je=Rt+1,!1):!0}),je===null&&ie.quote){const _t=ie.quote;n.state.doc.descendants((Rt,It)=>{if(je!==null)return!1;if(Rt.isTextblock){const tr=Rt.textContent.indexOf(_t);if(tr>=0)return je=It+1+tr,!1}return!0})}if(je===null)return;n.chain().focus().setTextSelection({from:je,to:je}).scrollIntoView().run();const ze=n.view.nodeDOM(je-1);ze!=null&&ze.classList&&(ze.classList.add("scroll-target-flash"),setTimeout(()=>ze.classList.remove("scroll-target-flash"),1200))},100)},[n,ve]);const Ct=x.useCallback(()=>{at.current<=0||window.history.back()},[]),en=x.useCallback(()=>{at.current>=ft.current.length-1||window.history.forward()},[]);x.useEffect(()=>{const ie=je=>{const ze=je.state&&je.state.ow;ze!=null&&ze.filename&&ze.filename!==Fe.current&&(Pe(),nt.current=ze.navIndex<at.current?"back":"forward",ht.current=!0,re(),Z({type:"switch-document",filename:ze.filename}))};return window.addEventListener("popstate",ie),()=>window.removeEventListener("popstate",ie)},[re,Z]);const on=x.useCallback(()=>{const ie=Fe.current,je=t.current;if(!ie||!je)return;const ze=()=>{const _t=e.current;if(_t.length>1)for(const Rt of _t)Rt!=null&&Rt.view&&ck(Rt.view);else je!=null&&je.view&&ck(je.view)};fetch(`/api/comments/${encodeURIComponent(ie)}`).then(_t=>_t.json()).then(_t=>{ok(_t.comments||[]),ze()}).catch(()=>{ok([]),ze()})},[]);x.useEffect(()=>{on()},[ve,n,on]),x.useEffect(()=>{const ie=je=>{const ze=je.detail;(ze==null?void 0:ze.filename)===Fe.current&&on()};return window.addEventListener("ow-comments-changed",ie),()=>window.removeEventListener("ow-comments-changed",ie)},[on]),x.useEffect(()=>{function ie(je){var Rt;const ze=je.detail;if(!ze)return;const _t=D==null?void 0:D.docId;_t&&ze.docId&&ze.docId!==_t||m(((Rt=ze.pendingMetadata)==null?void 0:Rt.title)??null)}return window.addEventListener("ow-pending-metadata-changed",ie),()=>window.removeEventListener("ow-pending-metadata-changed",ie)},[D==null?void 0:D.docId]),x.useEffect(()=>{const ie=D==null?void 0:D.docId;if(!ie){uk([]);return}let je=!1;return fetch(`/api/backlinks/${ie}`).then(ze=>ze.ok?ze.json():[]).then(ze=>{if(je)return;uk(Array.isArray(ze)?ze:[]);const _t=e.current.length>0?e.current:n?[n]:[];for(const Rt of _t)Rt!=null&&Rt.view&&p5(Rt.view)}).catch(()=>{}),()=>{je=!0}},[D,n]),x.useEffect(()=>{const ie=je=>{je.altKey&&je.key==="ArrowLeft"&&(je.preventDefault(),Ct()),je.altKey&&je.key==="ArrowRight"&&(je.preventDefault(),en())};return window.addEventListener("keydown",ie),()=>window.removeEventListener("keydown",ie)},[Ct,en]);const Wt=x.useCallback(ie=>{pe.current=ie,Je.current&&clearTimeout(Je.current),Je.current=setTimeout(()=>{const je=pe.current||ie,ze=JSON.stringify(je);ze!==mt.current&&(Z({type:"doc-update",document:je,filename:Fe.current,version:I.current}),mt.current=ze)},1e3)},[Z,I]),Ft=x.useCallback(ie=>{f(ie),Z({type:"title-update",title:ie})},[Z]),xt=x.useCallback(()=>{se(ie=>(localStorage.setItem("ow-toolbar",ie?"hidden":"visible"),!ie))},[]),Pn=x.useCallback(()=>{te(ie=>{if(!ie)return K.current={sidebarOpen:w,showToolbar:q},E(!1),se(!1),!0;const je=K.current;return je&&(E(je.sidebarOpen),se(je.showToolbar),K.current=null),!1})},[w,q]),un=x.useCallback(()=>{if(W.state==="unconfigured"){G(!0);return}re(),Z({type:"save"}),fetch("/api/sync/push",{method:"POST"}).catch(()=>{})},[W.state,re,Z]),yr=Rd()==="board";return c.jsx(T5,{children:c.jsxs("div",{className:"app",children:[!yr&&c.jsx(jk,{open:w,onSwitchDocument:Se,onCreateDocument:Te,refreshKey:C,docTagsRefreshKey:j,workspacesRefreshKey:A,pendingDocs:B,writingTitle:M,writingTarget:ee,pendingWriteFilenames:ge,onClose:()=>E(!1)}),c.jsxs("div",{className:"app-main",children:[c.jsx($5,{title:d,onTitleChange:Ft,onToggleSidebar:!yr&&!w?()=>E(!0):void 0,canGoBack:Be,canGoForward:de,onGoBack:Ct,onGoForward:en,editor:n,onToggleToolbar:xt,toolbarOpen:q,focusMode:V,onToggleFocusMode:Pn}),q&&n&&c.jsx(E5,{editor:s||n}),yr&&c.jsx(jk,{open:!0,onSwitchDocument:Se,onCreateDocument:Te,refreshKey:C,docTagsRefreshKey:j,workspacesRefreshKey:A,pendingDocs:B,writingTitle:M,writingTarget:ee,pendingWriteFilenames:ge}),!P&&c.jsxs("div",{className:"connection-banner",children:[c.jsx("div",{className:"connection-banner-spinner"}),c.jsx("span",{children:"Reconnecting to server..."})]}),(D==null?void 0:D.autoAccept)===!0&&c.jsxs("div",{className:"editor-auto-accept-banner",title:"Agent edits skip the review step. Right-click the doc in the sidebar to turn off.",children:[c.jsx("span",{className:"editor-auto-accept-dot"}),"Auto-accept on — agent edits skip review"]}),Ke&&c.jsxs("div",{className:"editor-reload-banner",role:"status","aria-live":"polite",children:[c.jsx("span",{className:"editor-reload-dot","aria-hidden":"true"}),c.jsx("span",{children:Ke.reloadCount>1?`Document reloaded from disk ${Ke.reloadCount}× since you last looked`:"Document reloaded from disk (external write detected)"}),(Ke.orphanCount>0||Ke.staleBaselineCount>0)&&c.jsxs("span",{className:"editor-reload-detail",children:[Ke.orphanCount>0&&c.jsxs("span",{className:"editor-reload-tag editor-reload-tag--orphan",children:[Ke.orphanCount," orphan",Ke.orphanCount===1?"":"s"]}),Ke.staleBaselineCount>0&&c.jsxs("span",{className:"editor-reload-tag editor-reload-tag--stale",children:[Ke.staleBaselineCount," stale-baseline"]})]}),c.jsx("button",{type:"button",className:"editor-reload-dismiss",onClick:()=>pt(null),"aria-label":"Dismiss reload notification",children:"×"})]}),c.jsx("div",{className:"editor-container",children:ot?c.jsx(hU,{title:d,onTitleChange:Ft,coverImage:(_r=D==null?void 0:D.articleContext)==null?void 0:_r.coverImage,coverImages:(Wr=D==null?void 0:D.articleContext)==null?void 0:Wr.coverImages,lastPost:(is=D==null?void 0:D.articleContext)==null?void 0:is.lastPost,pendingTitle:h,docId:(D==null?void 0:D.docId)||void 0,autoplug:D==null?void 0:D.autoplug,children:c.jsx(pu,{initialContent:g,extensions:n5,onUpdate:Wt,onReady:gt,onLinkClick:me})}):bt?c.jsx(xU,{title:d,onTitleChange:Ft,blogContext:D==null?void 0:D.blogContext,filename:ve,children:c.jsx(pu,{initialContent:g,onUpdate:Wt,onReady:gt,onLinkClick:me})}):Ye?c.jsx(kU,{newsletterContext:D==null?void 0:D.newsletterContext,filename:ve,title:d,onTitleChange:Ft,onBeforeSend:ye,children:c.jsx(pu,{initialContent:g,onUpdate:Wt,onReady:gt,onLinkClick:me})}):it&&(D!=null&&D.tweetContext)?c.jsx(aU,{tweetContext:D.tweetContext,initialContent:g,onUpdate:Wt,onEditorReady:gt,onEditorsChange:Ie,onActiveEditorChange:i,filename:ve,title:d,autoplug:D==null?void 0:D.autoplug},b):c.jsx(pu,{initialContent:g,onUpdate:Wt,onReady:gt,onLinkClick:me})})]}),c.jsx(V$,{editors:o,pendingDocs:B,currentFilename:ve,docId:(D==null?void 0:D.docId)||null,pendingTitle:h,onSwitchDocument:Se,sendMessage:Z,getDocument:()=>pe.current,docVersionRef:I,syncStatus:W,onSync:un,onToggleToolbar:xt,toolbarOpen:q,focusMode:V,onToggleFocusMode:Pn}),c.jsx(J5,{editorRef:t,allEditors:o,documentId:ve}),c.jsx(Z5,{documentId:ve}),z&&c.jsx(K$,{onClose:()=>G(!1),onSetupComplete:()=>{fetch("/api/sync/status").then(ie=>ie.json()).then(J).catch(()=>{})}})]})})}vM();fM.createRoot(document.getElementById("root")).render(c.jsx(ki.StrictMode,{children:c.jsx(EU,{})}));
214
+ `)}function CT(t,e){const n=x.useRef(null),r=x.useCallback(()=>{const o=n.current;o&&(o.style.height="auto",o.style.height=`${o.scrollHeight}px`)},[]);x.useLayoutEffect(()=>{r()},[t,r]);const s=x.useCallback(o=>{e(o.target.value.replace(/[\r\n]+/g," ")),r()},[e,r]),i=x.useCallback(o=>{var l;o.key==="Enter"&&(o.preventDefault(),(l=n.current)==null||l.blur())},[]);return{ref:n,onChange:s,onKeyDown:i}}const ug="ow-x-handle",hE="ow-x-name",uU=new Set(["Untitled","New Document","Article"]);function dU({src:t,coverImages:e}){const[n,r]=x.useState(t?"display":"empty"),[s,i]=x.useState(t||""),[o,l]=x.useState(e||(t?[t]:[])),[d,f]=x.useState(""),[h,m]=x.useState(""),g=x.useRef(null);x.useEffect(()=>{t?(i(t),r("display")):e&&e.length>0?(i(e[0]),r("display")):(i(""),r("empty"),f(""),m(""))},[t,e]),x.useEffect(()=>{e&&e.length>0?l(e):l(t?[t]:[])},[e]);const v=s?o.indexOf(s):-1,b=o.length,k=b>1,w=x.useCallback($=>{const W=o[$];W&&(i(W),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{coverImage:W,coverImages:o}})}).catch(()=>{}))},[o]),E=x.useCallback(()=>{v>0&&w(v-1)},[v,w]),C=x.useCallback(()=>{v<b-1&&w(v+1)},[v,b,w]),T=x.useCallback(async()=>{if(d.trim()){r("loading"),m("");try{const $=await fetch("/api/image-gen/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:d.trim()})});if(!$.ok){const J=await $.json().catch(()=>null);m((J==null?void 0:J.error)||`Generation failed (${$.status})`),r("prompt");return}const W=await $.json();if(W.success&&W.src){const J=[...o,W.src];l(J),i(W.src),r("display"),f(""),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{coverImage:W.src,coverImages:J}})}).catch(()=>{})}else m(W.error||"Generation failed"),r("prompt")}catch($){m($.message||"Network error"),r("prompt")}}},[d,o]),j=$=>{$.key==="Enter"&&T(),$.key==="Escape"&&(r("empty"),f(""),m(""))},_=()=>{r("prompt"),setTimeout(()=>{var $;return($=g.current)==null?void 0:$.focus()},0)},A=()=>{const $=o.filter(W=>W!==s);if(l($),$.length>0){const W=Math.min(v,$.length-1),J=$[W];i(J),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{coverImage:J,coverImages:$}})}).catch(()=>{})}else i(""),r("empty"),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{coverImage:null,coverImages:null}})}).catch(()=>{})},O=()=>{r("prompt"),setTimeout(()=>{var $;return($=g.current)==null?void 0:$.focus()},0)},B=()=>{const $=document.createElement("a");$.href=s,$.download=`cover-${v+1}.png`,$.click()};return n==="display"&&s?c.jsxs("div",{className:"article-cover article-cover--display",children:[c.jsx("img",{className:"article-cover-img",src:s,alt:"Cover"}),c.jsxs("div",{className:"article-cover-overlay",children:[k&&c.jsx("button",{className:"article-cover-arrow article-cover-arrow--left",onClick:E,disabled:v<=0,children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"15 18 9 12 15 6"})})}),c.jsxs("div",{className:"article-cover-overlay-center",children:[c.jsxs("button",{className:"article-cover-overlay-btn",onClick:O,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"23 4 23 10 17 10"}),c.jsx("polyline",{points:"1 20 1 14 7 14"}),c.jsx("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"})]}),"Regenerate"]}),c.jsxs("button",{className:"article-cover-overlay-btn",onClick:B,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),c.jsx("polyline",{points:"7 10 12 15 17 10"}),c.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),"Save"]}),c.jsxs("button",{className:"article-cover-overlay-btn article-cover-overlay-btn--danger",onClick:A,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),"Remove"]})]}),k&&c.jsx("button",{className:"article-cover-arrow article-cover-arrow--right",onClick:C,disabled:v>=b-1,children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})}),k&&c.jsxs("div",{className:"article-cover-counter",children:[v+1," / ",b]})]})]}):n==="loading"?c.jsxs("div",{className:"article-cover article-cover--loading",children:[c.jsx("div",{className:"article-cover-spinner"}),c.jsx("span",{className:"article-cover-loading-text",children:"Generating cover image..."})]}):n==="prompt"?c.jsxs("div",{className:"article-cover article-cover--prompt",children:[c.jsxs("div",{className:"article-cover-prompt-row",children:[c.jsx("input",{ref:g,className:"article-cover-prompt-input",value:d,onChange:$=>f($.target.value),onKeyDown:j,placeholder:"Describe your cover image...",spellCheck:!1}),c.jsx("button",{className:"article-cover-prompt-btn",onClick:T,disabled:!d.trim(),children:"Generate"}),c.jsx("button",{className:"article-cover-prompt-cancel",onClick:()=>{r(s?"display":"empty"),f(""),m("")},children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),h&&c.jsx("div",{className:"article-cover-error",children:h})]}):c.jsxs("div",{className:"article-cover article-cover--empty",onClick:_,children:[c.jsxs("svg",{className:"article-cover-icon",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),c.jsx("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),c.jsx("polyline",{points:"21 15 16 10 5 21"})]}),c.jsx("span",{className:"article-cover-hint",children:"We recommend an image with a 5:2 aspect ratio for best results."})]})}function fU(){const[t,e]=x.useState(()=>localStorage.getItem(ug)||""),[n,r]=x.useState(()=>localStorage.getItem(hE)||""),[s,i]=x.useState(!1),[o,l]=x.useState(""),d=x.useRef(null),f=x.useRef(null),h=()=>{const b=o.replace(/^@/,"").trim();b&&(localStorage.setItem(ug,b),e(b)),i(!1)},m=()=>{l(t),i(!0),setTimeout(()=>{var b;return(b=d.current)==null?void 0:b.focus()},0)};x.useEffect(()=>{if(!s)return;const b=k=>{f.current&&!f.current.contains(k.target)&&h()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[s,o]),x.useEffect(()=>{const b=()=>{e(localStorage.getItem(ug)||""),r(localStorage.getItem(hE)||"")};return window.addEventListener("storage",b),()=>window.removeEventListener("storage",b)},[]);const g=t?`https://unavatar.io/twitter/${t}`:"",v=n||t||"Set your @handle";return c.jsxs("div",{className:"article-byline",ref:f,children:[c.jsxs("div",{className:"article-byline-row",onClick:m,title:t?`@${t} — click to change`:"Set your @handle",children:[t?c.jsx("img",{className:"article-byline-avatar",src:g,alt:`@${t}`}):c.jsx("div",{className:"article-byline-avatar article-byline-avatar--empty"}),c.jsx("span",{className:"article-byline-name",children:v}),t&&c.jsxs("span",{className:"article-byline-handle",children:["@",t]})]}),s&&c.jsx("div",{className:"article-byline-popover",children:c.jsx("input",{ref:d,className:"article-byline-input",value:o,onChange:b=>l(b.target.value),onKeyDown:b=>{b.key==="Enter"&&h(),b.key==="Escape"&&i(!1)},placeholder:"your_handle",spellCheck:!1})})]})}function hU({children:t,title:e,onTitleChange:n,coverImage:r,coverImages:s,lastPost:i,pendingTitle:o,docId:l,autoplug:d}){const{copyAsHtml:f,copyState:h}=lU(),[m,g]=x.useState(i?"done":"idle"),v=uU.has(e||"")?"":e||"",b=CT(v,D=>n==null?void 0:n(D||"Untitled")),[k,w]=x.useState(!1),[E,C]=x.useState(!1);x.useEffect(()=>{function D(U){const q=U.detail;q&&(l&&q.docId&&q.docId!==l||(w(!!q.titleFocused),C(!!q.titleShowOriginal)))}return window.addEventListener("ow-pending-review-cursor",D),()=>window.removeEventListener("ow-pending-review-cursor",D)},[l]);const[T,j]=x.useState(!1),[_,A]=x.useState(""),O=x.useRef(null),B=x.useRef(null);x.useEffect(()=>{g(i?"done":"idle")},[i]),x.useEffect(()=>{if(!T)return;setTimeout(()=>{var U;return(U=O.current)==null?void 0:U.focus()},0);const D=U=>{B.current&&!B.current.contains(U.target)&&(j(!1),A(""))};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[T]);const $=x.useCallback(()=>{const D=_.trim();if(!(!D||D.includes("x.com")||D.includes("twitter.com")))return;const q=(i==null?void 0:i.postedAt)??new Date().toISOString();fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{lastPost:D?{postedAt:q,tweetUrl:D}:{postedAt:q}}}),keepalive:!0}).catch(()=>{}),g("done"),j(!1),A("")},[_,i==null?void 0:i.postedAt]),W=x.useCallback(()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({articleContext:{lastPost:null}}),keepalive:!0}).catch(()=>{}),g("idle")},[]),J=d!==!1,z=()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({autoplug:!J}),keepalive:!0}).catch(()=>{})},G=x.useCallback(()=>{if(m==="done"){W(),j(!1),A("");return}A((i==null?void 0:i.tweetUrl)??""),j(!0)},[m,i==null?void 0:i.tweetUrl,W]);return c.jsxs("div",{className:"article-compose-wrapper",children:[c.jsx(dU,{src:r,coverImages:s}),c.jsxs("div",{className:"article-compose-content",children:[o?E?c.jsx("div",{className:`article-title-input article-title-input--pending${k?" pending-active pending-active--original":""}`,title:`Showing original title. Toggle back to Modified to see the agent's proposal "${o.to}".`,"aria-label":`Original title ${o.from} (agent proposed ${o.to})`,children:c.jsx("span",{className:"pending-original",children:o.from})}):c.jsx("div",{className:`article-title-input article-title-input--pending${k?" pending-active pending-active--insert":""}`,title:`Agent proposed rename from "${o.from}". Accept or reject in the Review panel.`,"aria-label":`Pending title rename from ${o.from} to ${o.to}`,children:c.jsx("span",{className:"pending-insert",children:o.to})}):c.jsx("textarea",{className:"article-title-input",ref:b.ref,value:v,onChange:b.onChange,onKeyDown:b.onKeyDown,placeholder:"Add a title",rows:1,spellCheck:!1}),c.jsx(fU,{}),c.jsx("div",{className:"article-compose-body",children:t})]}),c.jsxs("div",{className:"article-compose-footer",children:[c.jsxs("div",{className:"article-mark-sent-wrap",ref:B,children:[c.jsx("button",{className:`article-mark-sent-btn${m==="done"?" article-mark-sent-btn--done":""}`,onClick:G,title:m==="done"?i!=null&&i.tweetUrl?`Posted — click to unmark (${i.tweetUrl})`:"Posted — click to unmark":"Mark as manually posted",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:m==="done"?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"8 12 11 15 16 9",stroke:m==="done"?"#fff":"currentColor"})]})}),T&&(()=>{const D=_.trim(),U=!D||D.includes("x.com")||D.includes("twitter.com");return c.jsxs("div",{className:"article-mark-sent-url",children:[c.jsx("input",{ref:O,type:"text",placeholder:"Paste posted tweet URL...",value:_,onChange:q=>A(q.target.value),onKeyDown:q=>{q.key==="Enter"&&(q.preventDefault(),$()),q.key==="Escape"&&(j(!1),A(""))}}),c.jsx("button",{onClick:$,disabled:!U,title:D?"Save URL":"Mark posted without URL",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})})]})})()]}),c.jsx("button",{className:`article-autoplug-toggle${J?" article-autoplug-toggle--on":""}`,onClick:z,title:J?"Auto-plug ON — engagement autoplugs may reply to this post with your configured promo. Click to opt out.":"Auto-plug OFF — this post is excluded from autoplugs. Click to opt in.",children:J?"Auto-plug on":"Auto-plug off"}),m==="done"&&i&&(i.tweetUrl?c.jsxs("a",{className:"article-sent-status",href:i.tweetUrl,target:"_blank",rel:"noopener noreferrer",children:["Posted ",new Date(i.postedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})]}):c.jsxs("span",{className:"article-sent-status",children:["Posted ",new Date(i.postedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})]})),c.jsx("button",{className:`article-copy-btn${h==="copied"?" article-copy-btn--copied":""}`,onClick:f,children:h==="copied"?c.jsxs(c.Fragment,{children:[c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Copied!"]}):c.jsxs(c.Fragment,{children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),c.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),"Copy as HTML"]})})]})]})}const pU={font:"sans",width:"standard",spacing:"comfortable"},pE=new Set(["Untitled","New Document","Blog"]),mU=[];function gU(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80)}function mE(){return new Date().toISOString().split("T")[0]}function yi(t){fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({blogContext:t})}).catch(()=>{})}function vU({src:t,coverImages:e}){const[n,r]=x.useState(t?"display":"empty"),[s,i]=x.useState(t||""),[o,l]=x.useState(e||(t?[t]:[])),[d,f]=x.useState(""),[h,m]=x.useState(""),g=x.useRef(null);x.useEffect(()=>{t?(i(t),r("display")):(i(""),r("empty"),f(""),m(""))},[t]),x.useEffect(()=>{e&&e.length>0?l(e):l(t?[t]:[])},[e]);const v=s?o.indexOf(s):-1,b=o.length,k=b>1,w=x.useCallback($=>{const W=o[$];W&&(i(W),yi({coverImage:W,coverImages:o}))},[o]),E=x.useCallback(()=>{v>0&&w(v-1)},[v,w]),C=x.useCallback(()=>{v<b-1&&w(v+1)},[v,b,w]),T=x.useCallback(async()=>{if(d.trim()){r("loading"),m("");try{const $=await fetch("/api/image-gen/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:d.trim()})});if(!$.ok){const J=await $.json().catch(()=>null);m((J==null?void 0:J.error)||`Generation failed (${$.status})`),r("prompt");return}const W=await $.json();if(W.success&&W.src){const J=[...o,W.src];l(J),i(W.src),r("display"),f(""),yi({coverImage:W.src,coverImages:J})}else m(W.error||"Generation failed"),r("prompt")}catch($){m($.message||"Network error"),r("prompt")}}},[d,o]),j=$=>{$.key==="Enter"&&T(),$.key==="Escape"&&(r("empty"),f(""),m(""))},_=()=>{r("prompt"),setTimeout(()=>{var $;return($=g.current)==null?void 0:$.focus()},0)},A=()=>{const $=o.filter(W=>W!==s);if(l($),$.length>0){const W=Math.min(v,$.length-1),J=$[W];i(J),yi({coverImage:J,coverImages:$})}else i(""),r("empty"),yi({coverImage:void 0,coverImages:void 0})},O=()=>{r("prompt"),setTimeout(()=>{var $;return($=g.current)==null?void 0:$.focus()},0)},B=()=>{const $=document.createElement("a");$.href=s,$.download=`cover-${v+1}.png`,$.click()};return n==="display"&&s?c.jsxs("div",{className:"blog-cover blog-cover--display",children:[c.jsx("img",{className:"blog-cover-img",src:s,alt:"Cover"}),c.jsxs("div",{className:"blog-cover-overlay",children:[k&&c.jsx("button",{className:"blog-cover-arrow blog-cover-arrow--left",onClick:E,disabled:v<=0,children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"15 18 9 12 15 6"})})}),c.jsxs("div",{className:"blog-cover-overlay-center",children:[c.jsxs("button",{className:"blog-cover-btn",onClick:O,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"23 4 23 10 17 10"}),c.jsx("polyline",{points:"1 20 1 14 7 14"}),c.jsx("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15"})]}),"Regenerate"]}),c.jsxs("button",{className:"blog-cover-btn",onClick:B,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),c.jsx("polyline",{points:"7 10 12 15 17 10"}),c.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),"Save"]}),c.jsxs("button",{className:"blog-cover-btn blog-cover-btn--danger",onClick:A,children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),"Remove"]})]}),k&&c.jsx("button",{className:"blog-cover-arrow blog-cover-arrow--right",onClick:C,disabled:v>=b-1,children:c.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})}),k&&c.jsxs("div",{className:"blog-cover-counter",children:[v+1," / ",b]})]})]}):n==="loading"?c.jsxs("div",{className:"blog-cover blog-cover--loading",children:[c.jsx("div",{className:"blog-cover-spinner"}),c.jsx("span",{className:"blog-cover-loading-text",children:"Generating cover image..."})]}):n==="prompt"?c.jsxs("div",{className:"blog-cover blog-cover--prompt",children:[c.jsxs("div",{className:"blog-cover-prompt-row",children:[c.jsx("input",{ref:g,className:"blog-cover-prompt-input",value:d,onChange:$=>f($.target.value),onKeyDown:j,placeholder:"Describe your cover image...",spellCheck:!1}),c.jsx("button",{className:"blog-cover-prompt-btn",onClick:T,disabled:!d.trim(),children:"Generate"}),c.jsx("button",{className:"blog-cover-prompt-cancel",onClick:()=>{r(s?"display":"empty"),f(""),m("")},children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),h&&c.jsx("div",{className:"blog-cover-error",children:h})]}):c.jsxs("div",{className:"blog-cover blog-cover--empty",onClick:_,children:[c.jsxs("svg",{className:"blog-cover-icon",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),c.jsx("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),c.jsx("polyline",{points:"21 15 16 10 5 21"})]}),c.jsx("span",{className:"blog-cover-hint",children:"Add a featured image"})]})}function yU({tags:t,onChange:e}){const[n,r]=x.useState(""),s=x.useRef(null),i=d=>{const f=d.trim().toLowerCase();f&&!t.includes(f)&&e([...t,f]),r("")},o=d=>e(t.filter(f=>f!==d)),l=d=>{(d.key==="Enter"||d.key===",")&&(d.preventDefault(),i(n)),d.key==="Backspace"&&!n&&t.length>0&&o(t[t.length-1])};return c.jsxs("div",{className:"blog-tags",onClick:()=>{var d;return(d=s.current)==null?void 0:d.focus()},children:[t.map(d=>c.jsxs("span",{className:"blog-tag",children:[d,c.jsx("button",{className:"blog-tag-remove",onClick:f=>{f.stopPropagation(),o(d)},children:c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},d)),c.jsx("input",{ref:s,className:"blog-tag-input",value:n,onChange:d=>r(d.target.value),onKeyDown:l,onBlur:()=>{n.trim()&&i(n)},placeholder:t.length===0?"Add tags...":"",spellCheck:!1})]})}function bU({style:t,onChange:e}){const n=r=>`blog-style-btn${r?" active":""}`;return c.jsxs("div",{className:"blog-style-controls",children:[c.jsxs("div",{className:"blog-style-group",children:[c.jsx("span",{className:"blog-style-label",children:"Font"}),c.jsx("button",{className:n(t.font==="sans"),onClick:()=>e({...t,font:"sans"}),title:"Sans-serif",children:"Aa"}),c.jsx("button",{className:`${n(t.font==="serif")} serif-btn`,onClick:()=>e({...t,font:"serif"}),title:"Serif",children:"Aa"}),c.jsx("button",{className:`${n(t.font==="mono")} mono-btn`,onClick:()=>e({...t,font:"mono"}),title:"Monospace",children:"Aa"})]}),c.jsxs("div",{className:"blog-style-group",children:[c.jsx("span",{className:"blog-style-label",children:"Width"}),c.jsx("button",{className:n(t.width==="narrow"),onClick:()=>e({...t,width:"narrow"}),title:"Narrow (600px)",children:c.jsx("svg",{width:"16",height:"14",viewBox:"0 0 16 14",children:c.jsx("rect",{x:"4",y:"1",width:"8",height:"12",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})})}),c.jsx("button",{className:n(t.width==="standard"),onClick:()=>e({...t,width:"standard"}),title:"Standard (720px)",children:c.jsx("svg",{width:"16",height:"14",viewBox:"0 0 16 14",children:c.jsx("rect",{x:"2",y:"1",width:"12",height:"12",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})})}),c.jsx("button",{className:n(t.width==="wide"),onClick:()=>e({...t,width:"wide"}),title:"Wide (900px)",children:c.jsx("svg",{width:"16",height:"14",viewBox:"0 0 16 14",children:c.jsx("rect",{x:"0.5",y:"1",width:"15",height:"12",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})})})]}),c.jsxs("div",{className:"blog-style-group",children:[c.jsx("span",{className:"blog-style-label",children:"Spacing"}),c.jsx("button",{className:n(t.spacing==="compact"),onClick:()=>e({...t,spacing:"compact"}),title:"Compact",children:c.jsxs("svg",{width:"16",height:"14",viewBox:"0 0 16 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[c.jsx("line",{x1:"1",y1:"3",x2:"15",y2:"3"}),c.jsx("line",{x1:"1",y1:"7",x2:"15",y2:"7"}),c.jsx("line",{x1:"1",y1:"11",x2:"15",y2:"11"})]})}),c.jsx("button",{className:n(t.spacing==="comfortable"),onClick:()=>e({...t,spacing:"comfortable"}),title:"Comfortable",children:c.jsxs("svg",{width:"16",height:"14",viewBox:"0 0 16 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[c.jsx("line",{x1:"1",y1:"2",x2:"15",y2:"2"}),c.jsx("line",{x1:"1",y1:"7",x2:"15",y2:"7"}),c.jsx("line",{x1:"1",y1:"12",x2:"15",y2:"12"})]})})]})]})}function xU({children:t,title:e,onTitleChange:n,blogContext:r,filename:s}){var V;const i=r||{},o=!!(r!=null&&r.active),l=pE.has(e||"")?"":e||"",d=CT(l,te=>n==null?void 0:n(te||"Untitled")),[f,h]=x.useState(i.description||""),[m,g]=x.useState(i.date||mE()),[v,b]=x.useState(i.author||""),[k,w]=x.useState(i.slug||""),[E,C]=x.useState(!!i.slug),[T,j]=x.useState(!1),[_,A]=x.useState(!1),[O,B]=x.useState(!1),[$,W]=x.useState(!1),J=i.tags||mU,z=i.draft??!1,G=x.useMemo(()=>({...pU,...i.style}),[i.style]);x.useEffect(()=>{h(i.description||""),g(i.date||mE()),b(i.author||""),w(i.slug||""),C(!!i.slug)},[s]),x.useEffect(()=>{fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"list_blog_sites",arguments:{}})}).then(te=>te.json()).then(te=>{var M,L;const K=(L=(M=te==null?void 0:te.content)==null?void 0:M[0])!=null&&L.text?JSON.parse(te.content[0].text):te;B(Array.isArray(K==null?void 0:K.sites)&&K.sites.length>0)}).catch(()=>{})},[]),x.useEffect(()=>{!E&&e&&!pE.has(e)&&w(gU(e))},[e,E]);const D=x.useCallback(()=>{o&&yi({description:f,date:m,author:v,slug:k})},[o,f,m,v,k]),U=f.length,q=U>160,se=["blog-compose-wrapper",`blog--font-${G.font}`,`blog--width-${G.width}`,`blog--spacing-${G.spacing}`].join(" ");return c.jsxs("div",{className:se,children:[c.jsx(vU,{src:i.coverImage,coverImages:i.coverImages}),c.jsxs("div",{className:"blog-compose-content",children:[((V=i.lastPublish)==null?void 0:V.publishedAt)&&c.jsxs("a",{className:"blog-published-status",href:i.lastPublish.url,target:"_blank",rel:"noopener noreferrer",title:i.lastPublish.url||`Published to ${i.lastPublish.repo||"GitHub"}`,children:[c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Published ",new Date(i.lastPublish.publishedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"}),i.lastPublish.repo?` to ${i.lastPublish.repo.split("/").pop()}`:""]}),c.jsx("textarea",{className:"blog-title-input",ref:d.ref,value:l,onChange:d.onChange,onKeyDown:d.onKeyDown,placeholder:"Post title",rows:1,spellCheck:!1}),c.jsxs("div",{className:"blog-description-wrap",children:[c.jsx("textarea",{className:`blog-description-input${q?" over-limit":""}`,value:f,onChange:te=>h(te.target.value),onBlur:D,placeholder:"Write a short description for SEO and social previews...",rows:2,spellCheck:!1}),c.jsxs("span",{className:`blog-description-count${q?" over-limit":""}`,children:[U,"/160"]})]}),c.jsxs("div",{className:"blog-meta-toggle",onClick:()=>A(te=>!te),children:[c.jsx("svg",{className:`blog-meta-chevron${_?" open":""}`,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})}),c.jsx("span",{children:"Metadata"}),z&&c.jsx("span",{className:"blog-draft-badge",children:"Draft"})]}),_&&c.jsxs("div",{className:"blog-meta-fields",children:[c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Date"}),c.jsx("input",{type:"date",className:"blog-meta-input",value:m,onChange:te=>g(te.target.value),onBlur:D})]}),c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Author"}),c.jsx("input",{type:"text",className:"blog-meta-input",value:v,onChange:te=>b(te.target.value),onBlur:D,placeholder:"Author name",spellCheck:!1})]}),c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Slug"}),c.jsx("input",{type:"text",className:"blog-meta-input",value:k,onChange:te=>{C(!0),w(te.target.value)},onBlur:D,placeholder:"auto-generated-from-title",spellCheck:!1})]}),c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Tags"}),c.jsx(yU,{tags:J,onChange:te=>{o&&yi({tags:te})}})]}),c.jsxs("div",{className:"blog-meta-row",children:[c.jsx("label",{className:"blog-meta-label",children:"Draft"}),c.jsx("button",{className:`blog-draft-toggle${z?" active":""}`,onClick:()=>{o&&yi({draft:!z})},children:c.jsx("div",{className:"blog-draft-toggle-knob"})})]})]}),c.jsx("div",{className:"blog-compose-body",children:t})]}),c.jsxs("div",{className:"blog-compose-footer",children:[c.jsx(bU,{style:G,onChange:te=>{o&&yi({style:te})}}),s&&c.jsxs("div",{className:"blog-footer-actions",children:[O&&c.jsxs("button",{className:"blog-footer-btn blog-footer-btn--primary",onClick:()=>W(!0),children:[c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"})}),"Publish"]}),c.jsxs("button",{className:"blog-footer-btn",onClick:()=>j(!0),children:[c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"12 6 12 12 16 14"})]}),"Schedule"]})]})]}),T&&s&&c.jsx(Dl,{filename:s,title:e||"Untitled",onClose:()=>j(!1)}),$&&s&&c.jsx(_2,{filename:s,title:e||"Untitled",isActive:!0,onSwitchDocument:()=>{},onClose:()=>W(!1)})]})}function wU({connectionId:t,subject:e,filename:n,onBeforeSend:r,onClose:s}){const[i,o]=x.useState("confirm"),[l,d]=x.useState("html"),[f,h]=x.useState(""),[m,g]=x.useState(null),[v,b]=x.useState(null),[k,w]=x.useState(0),[E,C]=x.useState(null),[T,j]=x.useState(null),[_,A]=x.useState("all"),[O,B]=x.useState([]),[$,W]=x.useState(""),J=x.useRef(null),z=O.find(q=>q.id===$),G=_==="exclude_issue"&&z&&T!=null?Math.max(0,T-z.recipient_count):T;x.useEffect(()=>{fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"list_subscribers",arguments:{limit:1}})}).then(q=>q.json()).then(q=>{var V,te;const se=(te=(V=q.content)==null?void 0:V[0])!=null&&te.text?JSON.parse(q.content[0].text):q;se.count!=null&&j(se.count)}).catch(()=>{}),fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"list_newsletter_issues",arguments:{limit:10}})}).then(q=>q.json()).then(q=>{var V,te;const se=(te=(V=q.content)==null?void 0:V[0])!=null&&te.text?JSON.parse(q.content[0].text):q;se.issues&&B(se.issues)}).catch(()=>{})},[]);const D=()=>i==="sent"?{sentCount:k,issueId:E,sentAt:new Date().toISOString()}:void 0;x.useEffect(()=>{const q=se=>{i!=="sending"&&i!=="testing"&&J.current&&!J.current.contains(se.target)&&s(D())};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[s,i,k,E]),x.useEffect(()=>{const q=se=>{se.key==="Escape"&&i!=="sending"&&i!=="testing"&&s(D())};return document.addEventListener("keydown",q),()=>document.removeEventListener("keydown",q)},[s,i,k,E]);async function U(q){var se,V;o(q?"testing":"sending"),b(null);try{r&&await r();const te={subject:e,connectionId:t,format:l};q&&(te.test_email=q),!q&&_==="exclude_issue"&&$&&(te.exclude_issue_id=$);const M=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"send_newsletter",arguments:te})})).json(),L=(V=(se=M.content)==null?void 0:se[0])!=null&&V.text?JSON.parse(M.content[0].text):M;if(L.error){b(L.error),o("error");return}if(L.test){g(L.sent_to),o("confirm");return}const ee=L.sent||0,fe=L.issueId||null,ge=new Date().toISOString();w(ee),C(fe),o("sent"),fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({newsletterContext:{lastSend:{sentCount:ee,sentAt:ge,issueId:fe||void 0}}})}).catch(()=>{})}catch(te){b(te.message),o("error")}}return c.jsx("div",{className:"newsletter-modal-overlay",children:c.jsxs("div",{className:"newsletter-modal",ref:J,children:[c.jsxs("div",{className:"newsletter-modal__header",children:[c.jsx("h3",{children:"Send Newsletter"}),c.jsx("button",{className:"newsletter-modal__close",onClick:()=>s(D()),children:"×"})]}),c.jsxs("div",{className:"newsletter-modal__body",children:[i==="confirm"&&c.jsxs(c.Fragment,{children:[c.jsxs("p",{className:"newsletter-modal__confirm-text",style:G==null?{visibility:"hidden"}:void 0,children:['Send "',c.jsx("strong",{children:e}),'" to ',G!=null?G.toLocaleString():0," subscriber",G!==1?"s":"","?"]}),c.jsxs("div",{className:"newsletter-modal__audience",children:[c.jsx("label",{className:"newsletter-modal__label",children:"Audience"}),c.jsxs("select",{className:"newsletter-modal__select",value:_,onChange:q=>{const se=q.target.value;A(se),se==="all"&&W("")},children:[c.jsx("option",{value:"all",children:"All subscribers"}),O.length>0&&c.jsx("option",{value:"exclude_issue",children:"Exclude who received..."})]}),_==="exclude_issue"&&c.jsxs("select",{className:"newsletter-modal__select",value:$,onChange:q=>W(q.target.value),children:[c.jsx("option",{value:"",children:"Select a past issue"}),O.map(q=>c.jsxs("option",{value:q.id,children:[q.subject," (",q.recipient_count," sent)"]},q.id))]})]}),c.jsxs("div",{className:"newsletter-modal__format-toggle",children:[c.jsx("button",{className:`newsletter-modal__format-btn${l==="html"?" active":""}`,onClick:()=>d("html"),children:"HTML"}),c.jsx("button",{className:`newsletter-modal__format-btn${l==="plaintext"?" active":""}`,onClick:()=>d("plaintext"),children:"Plaintext"})]}),c.jsxs("div",{className:"newsletter-modal__test-section",children:[c.jsxs("div",{className:"newsletter-modal__test-row",children:[c.jsx("input",{type:"email",className:"newsletter-modal__test-input",placeholder:"Test email address",value:f,onChange:q=>h(q.target.value),onKeyDown:q=>{q.key==="Enter"&&f.trim()&&U(f.trim())}}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--test",disabled:!f.trim(),onClick:()=>U(f.trim()),children:"Send Test"})]}),m&&c.jsxs("p",{className:"newsletter-modal__test-success",children:["Test sent to ",m]})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:s,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",disabled:_==="exclude_issue"&&!$,onClick:()=>U(),children:"Send Now"})]})]}),(i==="sending"||i==="testing")&&c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:i==="testing"?"Sending test...":"Sending..."})]}),i==="sent"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__status newsletter-modal__status--success",children:["Sent to ",k," subscriber",k!==1?"s":"","!"]}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>s({sentCount:k,issueId:E,sentAt:new Date().toISOString()}),children:"Done"})})]}),i==="error"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__error",children:v}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:s,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>U(),children:"Retry"})]})]})]})]})})}function gE(t){fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({newsletterContext:t})}).catch(()=>{})}function kU({children:t,newsletterContext:e,filename:n,title:r,onTitleChange:s,onBeforeSend:i}){var D;const o=e||{},[l,d]=x.useState(o.subject||""),[f,h]=x.useState(o.previewText||""),[m,g]=x.useState([]),[v,b]=x.useState(null),[k,w]=x.useState(!1),[E,C]=x.useState((D=o.lastSend)!=null&&D.sentAt?{sentCount:o.lastSend.sentCount,issueId:o.lastSend.issueId||null,sentAt:o.lastSend.sentAt}:null),T=x.useRef(null),j=x.useRef(n),_=x.useRef(o.subject||""),A=x.useRef(o.previewText||"");x.useEffect(()=>{var U;if(j.current!==n)d(o.subject||""),h(o.previewText||""),_.current=o.subject||"",A.current=o.previewText||"",j.current=n;else{const q=o.subject||"",se=o.previewText||"";q!==_.current&&(d(q),_.current=q),se!==A.current&&(h(se),A.current=se)}C((U=o.lastSend)!=null&&U.sentAt?{sentCount:o.lastSend.sentCount,issueId:o.lastSend.issueId||null,sentAt:o.lastSend.sentAt}:null)},[e,n]),x.useEffect(()=>{fetch("/api/connections").then(U=>U.json()).then(U=>{const q=(U.connections||[]).filter(se=>se.provider==="newsletter"&&se.status==="active");g(q)}).catch(()=>{})},[]);const O=!!(e!=null&&e.active),B=x.useRef();x.useEffect(()=>{if(B.current&&clearTimeout(B.current),!(!s||!l.trim()))return B.current=setTimeout(async()=>{const U=r,q=!U||U==="Untitled",se=T.current!==null&&U===T.current;if(q||se){try{await fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({newsletterContext:{subject:l}})})}catch{}s(l.trim()),T.current=l.trim()}},500),()=>{B.current&&clearTimeout(B.current)}},[l,r,s]);const $=x.useCallback(()=>{O&&(_.current=l,A.current=f,gE({subject:l,previewText:f}))},[O,l,f]),W=f.length,J=W>=90,z=W>150,G=()=>{m.length===1&&b(m[0].id),m.length>1&&b(m[0].id)};return c.jsxs("div",{className:"nl-compose-wrapper",children:[E&&c.jsxs("div",{className:"nl-sent-status",children:[c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Sent ",new Date(E.sentAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})," to ",E.sentCount," subscriber",E.sentCount!==1?"s":""]}),c.jsxs("div",{className:"nl-compose-content",children:[c.jsx("input",{className:"nl-subject-input",type:"text",value:l,onChange:U=>d(U.target.value),onBlur:$,placeholder:"Subject line (defaults to title if empty)",autoComplete:"off","data-lpignore":"true","data-1p-ignore":!0,spellCheck:!1}),c.jsxs("div",{className:"nl-preview-wrap",children:[c.jsx("textarea",{className:`nl-preview-input${z?" over-limit":""}`,value:f,onChange:U=>h(U.target.value),onBlur:$,placeholder:"Preview text shown in inbox before opening...",rows:2,spellCheck:!1}),c.jsxs("span",{className:`nl-preview-count${z?" over-limit":J?" full":""}`,children:[W,"/90"]})]}),c.jsx("div",{className:"nl-compose-body",children:t})]}),n&&c.jsxs("div",{className:"nl-compose-footer",children:[m.length>0&&c.jsxs("button",{className:"nl-footer-btn nl-footer-btn--primary",onClick:G,children:[c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),c.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]}),"Send"]}),c.jsxs("button",{className:"nl-footer-btn",onClick:()=>w(!0),children:[c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"12 6 12 12 16 14"})]}),"Schedule"]})]}),v&&n&&c.jsx(wU,{connectionId:v,subject:l||r||"Untitled",filename:n,onBeforeSend:i,onClose:U=>{b(null),U&&(C(U),gE({lastSend:{sentCount:U.sentCount,sentAt:U.sentAt,issueId:U.issueId||void 0}}))}}),k&&n&&c.jsx(Dl,{filename:n,title:r||"Untitled",onClose:()=>w(!1)})]})}function Eu(t){return t!=null&&typeof t=="object"&&Object.keys(t).length>0}function SU(t){const e=typeof(t==null?void 0:t.content_type)=="string"&&t.content_type||typeof(t==null?void 0:t.contentType)=="string"&&t.contentType||"";return e||(Eu(t==null?void 0:t.blogContext)?"blog":t!=null&&t.newsletterContext&&(t.newsletterContext.active===!0||Eu(t.newsletterContext))?"newsletter":Eu(t==null?void 0:t.articleContext)?"article":t!=null&&t.tweetContext?t.tweetContext.mode||"tweet":Eu(t==null?void 0:t.linkedinContext)?"linkedin":"document")}function EU(){var _r,Wr,is;const t=x.useRef(null),e=x.useRef([]),[n,r]=x.useState(null),[s,i]=x.useState(null),[o,l]=x.useState([]),[d,f]=x.useState("Untitled"),[h,m]=x.useState(null),[g,v]=x.useState(void 0),[b,k]=x.useState(0),[w,E]=x.useState(!0),[C,T]=x.useState(0),[j,_]=x.useState(0),[A,O]=x.useState(0),[B,$]=x.useState({filenames:[],counts:{}}),[W,J]=x.useState({state:"unconfigured"}),[z,G]=x.useState(!1),[D,U]=x.useState({}),[q,se]=x.useState(()=>localStorage.getItem("ow-toolbar")!=="hidden"),[V,te]=x.useState(!1),K=x.useRef(null),[M,L]=x.useState(null),[ee,fe]=x.useState(null),[ge,oe]=x.useState(new Set),xe=x.useRef(0),we=x.useRef(null),We=1500,He=x.useCallback((ie,je)=>{we.current&&(clearTimeout(we.current),we.current=null),xe.current=Date.now(),L(ie),fe(je)},[]),Ze=x.useCallback(()=>{if(we.current)return;const ie=Date.now()-xe.current,je=We-ie;je<=0?(L(null),fe(null)):we.current=setTimeout(()=>{we.current=null,L(null),fe(null)},je)},[]),[,Oe]=x.useState(0),[Ke,pt]=x.useState(null),Je=x.useRef(null),pe=x.useRef(null),mt=x.useRef(null),ft=x.useRef([]),at=x.useRef(-1),nt=x.useRef(null),ht=x.useRef(!1),Fe=x.useRef(""),[ve,X]=x.useState(""),[Be,ne]=x.useState(!1),[de,he]=x.useState(!1);function Ge(){const ie=document.querySelector(".editor-container");return(ie==null?void 0:ie.scrollTop)||0}function Pe(){if(at.current<0)return;const ie=ft.current[at.current];ie&&(ie.scrollTop=Ge())}const et=SU(D),ot=et==="article",bt=et==="blog",Ye=et==="newsletter",it=et==="tweet"||et==="reply"||et==="quote";x.useEffect(()=>(ot?document.documentElement.setAttribute("data-view","article"):bt?document.documentElement.setAttribute("data-view","blog"):Ye?document.documentElement.setAttribute("data-view","newsletter"):it?document.documentElement.setAttribute("data-view","tweet"):document.documentElement.removeAttribute("data-view"),()=>document.documentElement.removeAttribute("data-view")),[it,ot,bt,Ye]),x.useEffect(()=>{const ie=()=>Oe(je=>je+1);return window.addEventListener("ow-sidebar-mode-change",ie),()=>window.removeEventListener("ow-sidebar-mode-change",ie)},[]),x.useEffect(()=>{fetch("/api/document",{cache:"no-store"}).then(ie=>ie.json()).then(ie=>{ie.document&&(v(ie.document),pe.current=ie.document),ie.title&&f(ie.title),ie.metadata&&U(ie.metadata)}).catch(()=>{v(void 0)}),fetch("/api/pending-docs").then(ie=>ie.json()).then(ie=>$(ie)).catch(()=>{}),fetch("/api/sync/status").then(ie=>ie.json()).then(ie=>J(ie)).catch(()=>{})},[]);const gt=x.useCallback(ie=>{t.current=ie,r(ie),i(null),e.current=[ie],l([ie])},[]),Nt=x.useRef([]),Ie=x.useCallback(ie=>{if(e.current=ie,l(ie),Nt.current.length>0&&ie.length>0){const je=Nt.current;Nt.current=[];for(const ze of ie)ze.isDestroyed||Tp(ze,je)}},[]),Me=x.useCallback(ie=>{var tr,qr;const je=performance.now(),ze=window.__lastSwitch;ze&&ze.filename===ie.filename?(ze.tReceive=je,console.log(`[Switch] RECEIVE filename=${ie.filename} sendToReceive=${(je-ze.tSend).toFixed(1)}ms (server round-trip)`)):console.log(`[Switch] RECEIVE filename=${ie.filename} (no matching CLICK — agent or initial-load switch)`),Je.current&&(clearTimeout(Je.current),Je.current=null);const _t=Fe.current==="",Rt=ie.filename===Fe.current;Fe.current=ie.filename,pe.current=ie.document,mt.current=JSON.stringify(ie.document),X(ie.filename),v(ie.document),f(ie.title),U(ie.metadata||{}),m(((tr=ie.pendingMetadata)==null?void 0:tr.title)??null),!Rt&&!_t&&((qr=ie.metadata)!=null&&qr.tweetContext)&&k(Kt=>Kt+1),ze&&ze.filename===ie.filename&&requestAnimationFrame(()=>{const Kt=performance.now();ze.tCommit=Kt,console.log(`[Switch] COMMIT filename=${ie.filename} receiveToCommit=${(Kt-je).toFixed(1)}ms totalClickToPaint=${(Kt-ze.tClick).toFixed(1)}ms`)});const It=nt.current??"push";if(nt.current=null,ft.current.length===0?(ft.current=[{filename:ie.filename,scrollTop:0}],at.current=0):It==="back"?at.current=Math.max(0,at.current-1):It==="forward"?at.current=Math.min(ft.current.length-1,at.current+1):Rt||(ft.current=ft.current.slice(0,at.current+1),ft.current.push({filename:ie.filename,scrollTop:0}),at.current=ft.current.length-1),!ht.current){const Kt=`#${encodeURIComponent(ie.filename)}`,Vn={ow:{filename:ie.filename,navIndex:at.current}};ft.current.length===1||Rt?window.history.replaceState(Vn,"",Kt):window.history.pushState(Vn,"",Kt)}if(ht.current=!1,It==="back"||It==="forward"){const Kt=ft.current[at.current];Kt&&setTimeout(()=>{const Vn=document.querySelector(".editor-container");Vn&&(Vn.scrollTop=Kt.scrollTop)},50)}ne(at.current>0),he(at.current<ft.current.length-1)},[]),qe=x.useCallback(ie=>{Je.current&&(clearTimeout(Je.current),Je.current=null),pe.current=ie.document,mt.current=JSON.stringify(ie.document),v(ie.document),f(ie.title),U(ie.metadata||{}),pt(je=>je?{filename:ie.filename,orphanCount:je.orphanCount+ie.orphanCount,staleBaselineCount:je.staleBaselineCount+ie.staleBaselineCount,reloadCount:je.reloadCount+1}:{filename:ie.filename,orphanCount:ie.orphanCount,staleBaselineCount:ie.staleBaselineCount,reloadCount:1})},[]),F=x.useCallback(()=>{T(ie=>ie+1),_(ie=>ie+1)},[]),ce=x.useCallback(()=>{O(ie=>ie+1)},[]),Ne=x.useCallback(ie=>{$(ie)},[]),{connected:P,sendMessage:Z,docVersionRef:I}=G$({onNodeChanges:ie=>{const je=e.current;if(je.length<=1){const ze=t.current;if(!ze)return;Tp(ze,ie)}else{if(je.some(_t=>_t.isDestroyed)){Nt.current.push(...ie);return}for(const _t of je)Tp(_t,ie)}},onDocumentSwitched:Me,onDocumentReloaded:qe,onDocumentsChanged:F,onWorkspacesChanged:ce,onPendingDocsChanged:Ne,onMetadataChanged:ie=>U(ie),onWritingStarted:(ie,je)=>He(ie,je),onWritingFinished:()=>Ze(),onIdRewrites:ie=>{const je=e.current,ze=je.length>0?je:t.current?[t.current]:[];for(const Rt of ze)Rt.isDestroyed||H5(Rt,ie);const _t=pe.current;if(_t&&Array.isArray(ie)&&ie.length>0){const Rt=new Map(ie.map(tr=>[tr.oldId,tr.newId])),It=tr=>{var qr;if(Array.isArray(tr))for(const Kt of tr){const Vn=(qr=Kt==null?void 0:Kt.attrs)==null?void 0:qr.id;Vn&&Rt.has(Vn)&&(Kt.attrs={...Kt.attrs,id:Rt.get(Vn)}),Kt!=null&&Kt.content&&It(Kt.content)}};It(_t.content||[])}},onPendingFilenamesChanged:ie=>oe(ie),onSyncStatus:ie=>J(ie),onTitleChanged:ie=>f(ie),getEditorState:()=>{var je;const ie=pe.current||((je=t.current)==null?void 0:je.getJSON());return ie?{document:ie}:null}}),re=x.useCallback(()=>{var ze;Je.current&&(clearTimeout(Je.current),Je.current=null);const ie=pe.current||((ze=t.current)==null?void 0:ze.getJSON());if(!ie)return;const je=JSON.stringify(ie);je!==mt.current&&(Z({type:"doc-update",document:ie,filename:Fe.current,version:I.current}),mt.current=je)},[Z,I]),ye=x.useCallback(async()=>{var je;const ie=pe.current||((je=t.current)==null?void 0:je.getJSON());ie&&await fetch("/api/documents/sync-content",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({document:ie,filename:Fe.current})})},[]);x.useEffect(()=>{const ie=()=>{var Rt;Je.current&&(clearTimeout(Je.current),Je.current=null);const ze=pe.current||((Rt=t.current)==null?void 0:Rt.getJSON());if(!ze)return;const _t=JSON.stringify({type:"flush",document:ze});navigator.sendBeacon("/api/flush",new Blob([_t],{type:"application/json"}))},je=()=>{document.visibilityState==="hidden"&&ie()};return window.addEventListener("beforeunload",ie),document.addEventListener("visibilitychange",je),()=>{window.removeEventListener("beforeunload",ie),document.removeEventListener("visibilitychange",je)}},[]);const Te=x.useCallback(()=>{re(),Z({type:"create-document"})},[re,Z]),Se=x.useCallback(ie=>{if(ie===Fe.current)return;const je=performance.now();window.__lastSwitch={filename:ie,tClick:je,tSend:0,tReceive:0,tCommit:0},console.log(`[Switch] CLICK filename=${ie} t=${je.toFixed(0)}`),Pe(),nt.current="push",re(),Z({type:"switch-document",filename:ie});const ze=performance.now();window.__lastSwitch.tSend=ze,console.log(`[Switch] SEND filename=${ie} clickToSend=${(ze-je).toFixed(1)}ms`)},[re,Z]),Ee=x.useRef(null),me=x.useCallback(async ie=>{let je=null;if(ie.docId)try{const ze=await fetch("/api/documents").then(_t=>_t.json());if(Array.isArray(ze)){const _t=ze.find(Rt=>Rt.docId===ie.docId);_t&&(je=_t.filename)}}catch{}if(!je&&ie.filename&&(je=ie.filename),!je){console.warn("[link] could not resolve doc: target",ie);return}ie.nodeId||ie.quote?Ee.current={nodeId:ie.nodeId||void 0,quote:ie.quote||void 0}:Ee.current={toTop:!0},Se(je)},[Se]);x.useEffect(()=>{const ie=je=>{const ze=je.detail;ze&&me(ze)};return window.addEventListener("ow-navigate-to-link",ie),()=>window.removeEventListener("ow-navigate-to-link",ie)},[me]);const ke=x.useRef(!1);x.useEffect(()=>{if(ke.current)return;ke.current=!0;const ie=window.location.pathname.match(/^\/d\/([a-f0-9]{8})\/?$/);if(!ie)return;const je=ie[1],ze=window.location.hash.match(/^#node=([a-f0-9]{8})$/),_t=ze?ze[1]:null;me({docId:je,filename:null,nodeId:_t,quote:null})},[me]),x.useEffect(()=>{if(!n||!Ee.current)return;const ie=Ee.current;Ee.current=null,setTimeout(()=>{if(ie.toTop){const _t=document.querySelector(".editor-container");_t&&(_t.scrollTop=0);return}let je=null;if(ie.nodeId&&n.state.doc.descendants((_t,Rt)=>{var It;return je!==null?!1:((It=_t.attrs)==null?void 0:It.id)===ie.nodeId?(je=Rt+1,!1):!0}),je===null&&ie.quote){const _t=ie.quote;n.state.doc.descendants((Rt,It)=>{if(je!==null)return!1;if(Rt.isTextblock){const tr=Rt.textContent.indexOf(_t);if(tr>=0)return je=It+1+tr,!1}return!0})}if(je===null)return;n.chain().focus().setTextSelection({from:je,to:je}).scrollIntoView().run();const ze=n.view.nodeDOM(je-1);ze!=null&&ze.classList&&(ze.classList.add("scroll-target-flash"),setTimeout(()=>ze.classList.remove("scroll-target-flash"),1200))},100)},[n,ve]);const Ct=x.useCallback(()=>{at.current<=0||window.history.back()},[]),en=x.useCallback(()=>{at.current>=ft.current.length-1||window.history.forward()},[]);x.useEffect(()=>{const ie=je=>{const ze=je.state&&je.state.ow;ze!=null&&ze.filename&&ze.filename!==Fe.current&&(Pe(),nt.current=ze.navIndex<at.current?"back":"forward",ht.current=!0,re(),Z({type:"switch-document",filename:ze.filename}))};return window.addEventListener("popstate",ie),()=>window.removeEventListener("popstate",ie)},[re,Z]);const on=x.useCallback(()=>{const ie=Fe.current,je=t.current;if(!ie||!je)return;const ze=()=>{const _t=e.current;if(_t.length>1)for(const Rt of _t)Rt!=null&&Rt.view&&ck(Rt.view);else je!=null&&je.view&&ck(je.view)};fetch(`/api/comments/${encodeURIComponent(ie)}`).then(_t=>_t.json()).then(_t=>{ok(_t.comments||[]),ze()}).catch(()=>{ok([]),ze()})},[]);x.useEffect(()=>{on()},[ve,n,on]),x.useEffect(()=>{const ie=je=>{const ze=je.detail;(ze==null?void 0:ze.filename)===Fe.current&&on()};return window.addEventListener("ow-comments-changed",ie),()=>window.removeEventListener("ow-comments-changed",ie)},[on]),x.useEffect(()=>{function ie(je){var Rt;const ze=je.detail;if(!ze)return;const _t=D==null?void 0:D.docId;_t&&ze.docId&&ze.docId!==_t||m(((Rt=ze.pendingMetadata)==null?void 0:Rt.title)??null)}return window.addEventListener("ow-pending-metadata-changed",ie),()=>window.removeEventListener("ow-pending-metadata-changed",ie)},[D==null?void 0:D.docId]),x.useEffect(()=>{const ie=D==null?void 0:D.docId;if(!ie){uk([]);return}let je=!1;return fetch(`/api/backlinks/${ie}`).then(ze=>ze.ok?ze.json():[]).then(ze=>{if(je)return;uk(Array.isArray(ze)?ze:[]);const _t=e.current.length>0?e.current:n?[n]:[];for(const Rt of _t)Rt!=null&&Rt.view&&p5(Rt.view)}).catch(()=>{}),()=>{je=!0}},[D,n]),x.useEffect(()=>{const ie=je=>{je.altKey&&je.key==="ArrowLeft"&&(je.preventDefault(),Ct()),je.altKey&&je.key==="ArrowRight"&&(je.preventDefault(),en())};return window.addEventListener("keydown",ie),()=>window.removeEventListener("keydown",ie)},[Ct,en]);const Wt=x.useCallback(ie=>{pe.current=ie,Je.current&&clearTimeout(Je.current),Je.current=setTimeout(()=>{const je=pe.current||ie,ze=JSON.stringify(je);ze!==mt.current&&(Z({type:"doc-update",document:je,filename:Fe.current,version:I.current}),mt.current=ze)},1e3)},[Z,I]),Ft=x.useCallback(ie=>{f(ie),Z({type:"title-update",title:ie})},[Z]),xt=x.useCallback(()=>{se(ie=>(localStorage.setItem("ow-toolbar",ie?"hidden":"visible"),!ie))},[]),Pn=x.useCallback(()=>{te(ie=>{if(!ie)return K.current={sidebarOpen:w,showToolbar:q},E(!1),se(!1),!0;const je=K.current;return je&&(E(je.sidebarOpen),se(je.showToolbar),K.current=null),!1})},[w,q]),un=x.useCallback(()=>{if(W.state==="unconfigured"){G(!0);return}re(),Z({type:"save"}),fetch("/api/sync/push",{method:"POST"}).catch(()=>{})},[W.state,re,Z]),yr=Rd()==="board";return c.jsx(T5,{children:c.jsxs("div",{className:"app",children:[!yr&&c.jsx(jk,{open:w,onSwitchDocument:Se,onCreateDocument:Te,refreshKey:C,docTagsRefreshKey:j,workspacesRefreshKey:A,pendingDocs:B,writingTitle:M,writingTarget:ee,pendingWriteFilenames:ge,onClose:()=>E(!1)}),c.jsxs("div",{className:"app-main",children:[c.jsx($5,{title:d,onTitleChange:Ft,onToggleSidebar:!yr&&!w?()=>E(!0):void 0,canGoBack:Be,canGoForward:de,onGoBack:Ct,onGoForward:en,editor:n,onToggleToolbar:xt,toolbarOpen:q,focusMode:V,onToggleFocusMode:Pn}),q&&n&&c.jsx(E5,{editor:s||n}),yr&&c.jsx(jk,{open:!0,onSwitchDocument:Se,onCreateDocument:Te,refreshKey:C,docTagsRefreshKey:j,workspacesRefreshKey:A,pendingDocs:B,writingTitle:M,writingTarget:ee,pendingWriteFilenames:ge}),!P&&c.jsxs("div",{className:"connection-banner",children:[c.jsx("div",{className:"connection-banner-spinner"}),c.jsx("span",{children:"Reconnecting to server..."})]}),(D==null?void 0:D.autoAccept)===!0&&c.jsxs("div",{className:"editor-auto-accept-banner",title:"Agent edits skip the review step. Right-click the doc in the sidebar to turn off.",children:[c.jsx("span",{className:"editor-auto-accept-dot"}),"Auto-accept on — agent edits skip review"]}),Ke&&c.jsxs("div",{className:"editor-reload-banner",role:"status","aria-live":"polite",children:[c.jsx("span",{className:"editor-reload-dot","aria-hidden":"true"}),c.jsx("span",{children:Ke.reloadCount>1?`Document reloaded from disk ${Ke.reloadCount}× since you last looked`:"Document reloaded from disk (external write detected)"}),(Ke.orphanCount>0||Ke.staleBaselineCount>0)&&c.jsxs("span",{className:"editor-reload-detail",children:[Ke.orphanCount>0&&c.jsxs("span",{className:"editor-reload-tag editor-reload-tag--orphan",children:[Ke.orphanCount," orphan",Ke.orphanCount===1?"":"s"]}),Ke.staleBaselineCount>0&&c.jsxs("span",{className:"editor-reload-tag editor-reload-tag--stale",children:[Ke.staleBaselineCount," stale-baseline"]})]}),c.jsx("button",{type:"button",className:"editor-reload-dismiss",onClick:()=>pt(null),"aria-label":"Dismiss reload notification",children:"×"})]}),c.jsx("div",{className:"editor-container",children:ot?c.jsx(hU,{title:d,onTitleChange:Ft,coverImage:(_r=D==null?void 0:D.articleContext)==null?void 0:_r.coverImage,coverImages:(Wr=D==null?void 0:D.articleContext)==null?void 0:Wr.coverImages,lastPost:(is=D==null?void 0:D.articleContext)==null?void 0:is.lastPost,pendingTitle:h,docId:(D==null?void 0:D.docId)||void 0,autoplug:D==null?void 0:D.autoplug,children:c.jsx(pu,{initialContent:g,extensions:n5,onUpdate:Wt,onReady:gt,onLinkClick:me})}):bt?c.jsx(xU,{title:d,onTitleChange:Ft,blogContext:D==null?void 0:D.blogContext,filename:ve,children:c.jsx(pu,{initialContent:g,onUpdate:Wt,onReady:gt,onLinkClick:me})}):Ye?c.jsx(kU,{newsletterContext:D==null?void 0:D.newsletterContext,filename:ve,title:d,onTitleChange:Ft,onBeforeSend:ye,children:c.jsx(pu,{initialContent:g,onUpdate:Wt,onReady:gt,onLinkClick:me})}):it&&(D!=null&&D.tweetContext)?c.jsx(aU,{tweetContext:D.tweetContext,initialContent:g,onUpdate:Wt,onEditorReady:gt,onEditorsChange:Ie,onActiveEditorChange:i,filename:ve,title:d,autoplug:D==null?void 0:D.autoplug},b):c.jsx(pu,{initialContent:g,onUpdate:Wt,onReady:gt,onLinkClick:me})})]}),c.jsx(V$,{editors:o,pendingDocs:B,currentFilename:ve,docId:(D==null?void 0:D.docId)||null,pendingTitle:h,onSwitchDocument:Se,sendMessage:Z,getDocument:()=>pe.current,docVersionRef:I,syncStatus:W,onSync:un,onToggleToolbar:xt,toolbarOpen:q,focusMode:V,onToggleFocusMode:Pn}),c.jsx(J5,{editorRef:t,allEditors:o,documentId:ve}),c.jsx(Z5,{documentId:ve}),z&&c.jsx(K$,{onClose:()=>G(!1),onSetupComplete:()=>{fetch("/api/sync/status").then(ie=>ie.json()).then(J).catch(()=>{})}})]})})}vM();fM.createRoot(document.getElementById("root")).render(c.jsx(ki.StrictMode,{children:c.jsx(EU,{})}));