PHP-Course/exam/dist/assets/index-SI5snNZz.js
2024-07-30 21:20:51 +02:00

10 lines
68 KiB
JavaScript

import{j as e,P as I,B as D,G as j,D as me,L as q,T as A,E as Wt,a as N,b as dt,c as U,C as Z,S as z,A as Ge,M as Qe,d as G,e as ht,f as mt,g as pt,u as se,h as ee,i as X,k as $,l as ft,m as oe,n as ae,o as Gt,p as rt,I as de,q as Qt,r as te,s as ne,t as Kt,v as Jt,w as Ke,x as Yt,y as Je,z as Ye,F as gt,H as xt,J as yt,K as Vt,N as Xt,O as Zt,Q as en,R as tn,U as nn,V as Re,W as rn,X as sn}from"./mui-BnAUJOoN.js";import{u as Ve,a as ie,b as on,c as J,L as W,d as an,O as cn,e as Q,f as ce,g as ln,h as un,q as Ue,i as Ce,j as De,r as Oe,k as dn,R as hn,Q as mn,l as pn}from"./tanstack-DpDh5IPY.js";import{d as fn,r as w,g as Xe,b as ve}from"./react-C9_qfvjK.js";import{c as gn}from"./zustand-DKxXQGKw.js";import{i as ye,B as xn,a as yn,b as vn,u as L,t as S,T as jn}from"./i18n-Be01V9yD.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))o(r);new MutationObserver(r=>{for(const a of r)if(a.type==="childList")for(const u of a.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&o(u)}).observe(document,{childList:!0,subtree:!0});function s(r){const a={};return r.integrity&&(a.integrity=r.integrity),r.referrerPolicy&&(a.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?a.credentials="include":r.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function o(r){if(r.ep)return;r.ep=!0;const a=s(r);fetch(r.href,a)}})();var He={},st=fn;He.createRoot=st.createRoot,He.hydrateRoot=st.hydrateRoot;var k=(n=>(n.NOT_FOUND="NotFound",n.UNAUTHORIZED="Unauthorized",n.NOT_ALLOWED="NotAllowed",n.FAILED_UPDATE="FailedUpdate",n.MISSING_FIELD="MissingField",n.DUPLICATE="Duplicate",n))(k||{});const fe=15,Tn=3;var be={BASE_URL:"/phpCourse/exam/dist",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const $e=new Map,we=n=>{const t=$e.get(n);return t?Object.fromEntries(Object.entries(t.stores).map(([s,o])=>[s,o.getState()])):{}},Cn=(n,t,s)=>{if(n===void 0)return{type:"untracked",connection:t.connect(s)};const o=$e.get(s.name);if(o)return{type:"tracked",store:n,...o};const r={connection:t.connect(s),stores:{}};return $e.set(s.name,r),{type:"tracked",store:n,...r}},Sn=(n,t={})=>(s,o,r)=>{const{enabled:a,anonymousActionType:u,store:d,...h}=t;let m;try{m=(a??(be?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!m)return(be?"production":void 0)!=="production"&&a&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),n(s,o,r);const{connection:l,...i}=Cn(d,m,h);let c=!0;r.setState=(f,y,x)=>{const v=s(f,y);if(!c)return v;const P=x===void 0?{type:u||"anonymous"}:typeof x=="string"?{type:x}:x;return d===void 0?(l==null||l.send(P,o()),v):(l==null||l.send({...P,type:`${d}/${P.type}`},{...we(h.name),[d]:r.getState()}),v)};const p=(...f)=>{const y=c;c=!1,s(...f),c=y},g=n(r.setState,o,r);if(i.type==="untracked"?l==null||l.init(g):(i.stores[i.store]=r,l==null||l.init(Object.fromEntries(Object.entries(i.stores).map(([f,y])=>[f,f===i.store?g:y.getState()])))),r.dispatchFromDevtools&&typeof r.dispatch=="function"){let f=!1;const y=r.dispatch;r.dispatch=(...x)=>{(be?"production":void 0)!=="production"&&x[0].type==="__setState"&&!f&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),f=!0),y(...x)}}return l.subscribe(f=>{var y;switch(f.type){case"ACTION":if(typeof f.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Me(f.payload,x=>{if(x.type==="__setState"){if(d===void 0){p(x.state);return}Object.keys(x.state).length!==1&&console.error(`
[zustand devtools middleware] Unsupported __setState action format.
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
`);const v=x.state[d];if(v==null)return;JSON.stringify(r.getState())!==JSON.stringify(v)&&p(v);return}r.dispatchFromDevtools&&typeof r.dispatch=="function"&&r.dispatch(x)});case"DISPATCH":switch(f.payload.type){case"RESET":return p(g),d===void 0?l==null?void 0:l.init(r.getState()):l==null?void 0:l.init(we(h.name));case"COMMIT":if(d===void 0){l==null||l.init(r.getState());return}return l==null?void 0:l.init(we(h.name));case"ROLLBACK":return Me(f.state,x=>{if(d===void 0){p(x),l==null||l.init(r.getState());return}p(x[d]),l==null||l.init(we(h.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return Me(f.state,x=>{if(d===void 0){p(x);return}JSON.stringify(r.getState())!==JSON.stringify(x[d])&&p(x[d])});case"IMPORT_STATE":{const{nextLiftedState:x}=f.payload,v=(y=x.computedStates.slice(-1)[0])==null?void 0:y.state;if(!v)return;p(d===void 0?v:v[d]),l==null||l.send(null,x);return}case"PAUSE_RECORDING":return c=!c}return}}),g},wn=Sn,Me=(n,t)=>{let s;try{s=JSON.parse(n)}catch(o){console.error("[zustand devtools middleware] Could not parse the received json",o)}s!==void 0&&t(s)};function bn(n,t){let s;try{s=n()}catch{return}return{getItem:r=>{var a;const u=h=>h===null?null:JSON.parse(h,void 0),d=(a=s.getItem(r))!=null?a:null;return d instanceof Promise?d.then(u):u(d)},setItem:(r,a)=>s.setItem(r,JSON.stringify(a,void 0)),removeItem:r=>s.removeItem(r)}}const je=n=>t=>{try{const s=n(t);return s instanceof Promise?s:{then(o){return je(o)(s)},catch(o){return this}}}catch(s){return{then(o){return this},catch(o){return je(o)(s)}}}},En=(n,t)=>(s,o,r)=>{let a={getStorage:()=>localStorage,serialize:JSON.stringify,deserialize:JSON.parse,partialize:y=>y,version:0,merge:(y,x)=>({...x,...y}),...t},u=!1;const d=new Set,h=new Set;let m;try{m=a.getStorage()}catch{}if(!m)return n((...y)=>{console.warn(`[zustand persist middleware] Unable to update item '${a.name}', the given storage is currently unavailable.`),s(...y)},o,r);const l=je(a.serialize),i=()=>{const y=a.partialize({...o()});let x;const v=l({state:y,version:a.version}).then(P=>m.setItem(a.name,P)).catch(P=>{x=P});if(x)throw x;return v},c=r.setState;r.setState=(y,x)=>{c(y,x),i()};const p=n((...y)=>{s(...y),i()},o,r);let g;const f=()=>{var y;if(!m)return;u=!1,d.forEach(v=>v(o()));const x=((y=a.onRehydrateStorage)==null?void 0:y.call(a,o()))||void 0;return je(m.getItem.bind(m))(a.name).then(v=>{if(v)return a.deserialize(v)}).then(v=>{if(v)if(typeof v.version=="number"&&v.version!==a.version){if(a.migrate)return a.migrate(v.state,v.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return v.state}).then(v=>{var P;return g=a.merge(v,(P=o())!=null?P:p),s(g,!0),i()}).then(()=>{x==null||x(g,void 0),u=!0,h.forEach(v=>v(g))}).catch(v=>{x==null||x(void 0,v)})};return r.persist={setOptions:y=>{a={...a,...y},y.getStorage&&(m=y.getStorage())},clearStorage:()=>{m==null||m.removeItem(a.name)},getOptions:()=>a,rehydrate:()=>f(),hasHydrated:()=>u,onHydrate:y=>(d.add(y),()=>{d.delete(y)}),onFinishHydration:y=>(h.add(y),()=>{h.delete(y)})},f(),g||p},An=(n,t)=>(s,o,r)=>{let a={storage:bn(()=>localStorage),partialize:f=>f,version:0,merge:(f,y)=>({...y,...f}),...t},u=!1;const d=new Set,h=new Set;let m=a.storage;if(!m)return n((...f)=>{console.warn(`[zustand persist middleware] Unable to update item '${a.name}', the given storage is currently unavailable.`),s(...f)},o,r);const l=()=>{const f=a.partialize({...o()});return m.setItem(a.name,{state:f,version:a.version})},i=r.setState;r.setState=(f,y)=>{i(f,y),l()};const c=n((...f)=>{s(...f),l()},o,r);r.getInitialState=()=>c;let p;const g=()=>{var f,y;if(!m)return;u=!1,d.forEach(v=>{var P;return v((P=o())!=null?P:c)});const x=((y=a.onRehydrateStorage)==null?void 0:y.call(a,(f=o())!=null?f:c))||void 0;return je(m.getItem.bind(m))(a.name).then(v=>{if(v)if(typeof v.version=="number"&&v.version!==a.version){if(a.migrate)return a.migrate(v.state,v.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return v.state}).then(v=>{var P;return p=a.merge(v,(P=o())!=null?P:c),s(p,!0),l()}).then(()=>{x==null||x(p,void 0),p=o(),u=!0,h.forEach(v=>v(p))}).catch(v=>{x==null||x(void 0,v)})};return r.persist={setOptions:f=>{a={...a,...f},f.storage&&(m=f.storage)},clearStorage:()=>{m==null||m.removeItem(a.name)},getOptions:()=>a,rehydrate:()=>g(),hasHydrated:()=>u,onHydrate:f=>(d.add(f),()=>{d.delete(f)}),onFinishHydration:f=>(h.add(f),()=>{h.delete(f)})},a.skipHydration||g(),p||c},Pn=(n,t)=>"getStorage"in t||"serialize"in t||"deserialize"in t?((be?"production":void 0)!=="production"&&console.warn("[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Use `storage` option instead."),En(n,t)):An(n,t),On=Pn,ke=gn()(wn(On(n=>({theme:void 0,currentSession:[void 0,void 0],setTheme:t=>n(()=>({theme:t})),setCurrentSession:t=>n(()=>({currentSession:t}))}),{name:"guestbook-storage"}))),V="https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/",vt=w.createContext({hasAuth:!1,currentSession:[void 0,void 0]}),_=()=>{const{hasAuth:n,authenticatedUser:t,currentSession:s,logIn:o,logOut:r,posts:a,newPost:u,updatePost:d,deletePost:h,users:m,user:l,createUser:i,confirmUser:c,updateUser:p,updateUserImage:g,updateUserPermissions:f,deleteUser:y,userPosts:x}=w.useContext(vt);if(o&&r&&a&&u&&d&&h&&m&&l&&i&&c&&p&&g&&f&&y&&x)return{hasAuth:n,authenticatedUser:t,currentSession:s,logIn:o,logOut:r,posts:a,newPost:u,updatePost:d,deletePost:h,users:m,user:l,createUser:i,confirmUser:c,updateUser:p,updateUserImage:g,updateUserPermissions:f,deleteUser:y,userPosts:x};throw new Error("Couldn't find context. Is your component inside an ApiProvider?")},In=({children:n})=>{const[t,s]=w.useState(!1),[o,r]=w.useState(),[a,u]=ke(T=>[T.currentSession,T.setCurrentSession]),d=w.useRef();w.useEffect(()=>{a[0]&&!d.current&&(d.current=a[0],nt())},[a]);const h=async(T,b)=>{const{user:E,token:O,refreshToken:zt}=await(await et("login",{email:T,password:b})).json();r(E),u([O,zt]),s(!0),d.current=O},m=async()=>{try{return d.current?await(await H(()=>_e("logout"))).json():!0}catch{return!1}finally{r(void 0),u([void 0,void 0]),s(!1),d.current=void 0}},l=async T=>{const b=`posts?p=${T??0}&l=${fe}`;return t?await(await H(()=>Se(b))).json():await(await qt(b)).json()},i=async T=>await(await H(()=>_e(`posts?l=${fe}`,T))).json(),c=async(T,b)=>await(await H(()=>Le(`posts/${b}`,T))).json(),p=async T=>await(await H(()=>tt(`posts/${T}?l=${fe}`))).json(),g=async T=>{const b=`users?p=${T??0}&l=${fe}`;return await(await H(()=>Se(b))).json()},f=async T=>await(await H(()=>Se(`users/${T??(o==null?void 0:o.id)}`))).json(),y=async T=>await(await et("register",T)).json(),x=async T=>await(await Bt("register",{code:T})).json(),v=async(T,b)=>{const E=await(await H(()=>Le(`users/${b??"self"}`,T))).json();return r(E),E},P=async(T,b)=>{const E=new FormData;T.image&&E.append("image",T.image),!T.image&&T.predefined&&E.append("predefined",T.predefined);const O=await(await H(()=>$t(`users/${b??"self"}/image`,E))).json();return r(O),O},le=async(T,b)=>await(await H(()=>Le(`users/${b}/permissions`,T))).json(),Nt=async T=>await(await H(()=>Se(`users/${T}/posts?l=${Tn}&s=desc`))).json(),Ht=async T=>await(await H(()=>tt(`users/${T}?l=${fe}`))).json(),et=async(T,b,E)=>{const O=await fetch(`${V}${T}`,{mode:"cors",method:"post",headers:E,body:JSON.stringify(b)});if(O.ok)return O;throw await O.json()},_e=async(T,b,E)=>{const O=await fetch(`${V}${T}`,{mode:"cors",method:"post",headers:{token:d.current??"",...E},body:JSON.stringify(b)});if(O.ok)return O;throw await O.json()},$t=async(T,b,E)=>{const O=await fetch(`${V}${T}`,{mode:"cors",method:"post",headers:{token:d.current??"",...E},body:b});if(O.ok)return O;throw await O.json()},qt=async(T,b)=>{const E=await fetch(`${V}${T}`,{mode:"cors",method:"get",headers:b});if(E.ok)return E;throw await E.json()},Se=async(T,b)=>{const E=await fetch(`${V}${T}`,{mode:"cors",method:"get",headers:{token:d.current??"",...b}});if(E.ok)return E;throw await E.json()},tt=async(T,b)=>{const E=await fetch(`${V}${T}`,{mode:"cors",method:"delete",headers:{token:d.current??"",...b}});if(E.ok)return E;throw await E.json()},Bt=async(T,b,E)=>{const O=await fetch(`${V}${T}`,{mode:"cors",method:"patch",headers:E,body:JSON.stringify(b)});if(O.ok)return O;throw await O.json()},Le=async(T,b,E)=>{const O=await fetch(`${V}${T}`,{mode:"cors",method:"patch",headers:{token:d.current??"",...E},body:JSON.stringify(b)});if(O.ok)return O;throw await O.json()},H=async T=>{try{return console.log("[REAUTH] fetching"),await T()}catch(b){if(console.log("[REAUTH] failed once",b),b.code!==k.UNAUTHORIZED)throw b;try{return console.log("[REAUTH] failed due to authentication, try refreshing session"),await nt(),console.log("[REAUTH] refreshed, fetching again"),await T()}catch(E){throw console.log("[REAUTH] terminating session",E),r(void 0),s(!1),u([void 0,void 0]),d.current=void 0,E}}},nt=async()=>{const{user:T,token:b,refreshToken:E}=await(await _e("refresh",{refreshToken:a[1]??"INVALID DEFAULT"})).json();r(T),u([b,E]),s(!0),d.current=b};return e.jsx(vt.Provider,{value:{hasAuth:t,authenticatedUser:o,currentSession:a,logIn:h,logOut:m,posts:l,newPost:i,updatePost:c,deletePost:p,users:g,user:f,createUser:y,confirmUser:x,updateUser:v,updateUserImage:P,updateUserPermissions:le,deleteUser:Ht,userPosts:Nt},children:n})};ye.use(xn).use(yn).use(vn).init({fallbackLng:"en",debug:!1,interpolation:{escapeValue:!1},backend:{loadPath:"/phpCourse/exam/dist/locales/{{lng}}/{{ns}}.json"}});function Rn(n){return n&&typeof n=="object"&&"default"in n?n.default:n}var jt=w,Un=Rn(jt);function ot(n,t,s){return t in n?Object.defineProperty(n,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):n[t]=s,n}function Dn(n,t){n.prototype=Object.create(t.prototype),n.prototype.constructor=n,n.__proto__=t}var kn=!!(typeof window<"u"&&window.document&&window.document.createElement);function Fn(n,t,s){if(typeof n!="function")throw new Error("Expected reducePropsToState to be a function.");if(typeof t!="function")throw new Error("Expected handleStateChangeOnClient to be a function.");if(typeof s<"u"&&typeof s!="function")throw new Error("Expected mapStateOnServer to either be undefined or a function.");function o(r){return r.displayName||r.name||"Component"}return function(a){if(typeof a!="function")throw new Error("Expected WrappedComponent to be a React component.");var u=[],d;function h(){d=n(u.map(function(l){return l.props})),m.canUseDOM?t(d):s&&(d=s(d))}var m=function(l){Dn(i,l);function i(){return l.apply(this,arguments)||this}i.peek=function(){return d},i.rewind=function(){if(i.canUseDOM)throw new Error("You may only call rewind() on the server. Call peek() to read the current state.");var g=d;return d=void 0,u=[],g};var c=i.prototype;return c.UNSAFE_componentWillMount=function(){u.push(this),h()},c.componentDidUpdate=function(){h()},c.componentWillUnmount=function(){var g=u.indexOf(this);u.splice(g,1),h()},c.render=function(){return Un.createElement(a,this.props)},i}(jt.PureComponent);return ot(m,"displayName","SideEffect("+o(a)+")"),ot(m,"canUseDOM",kn),m}}var _n=Fn;const Ln=Xe(_n);var Mn=typeof Element<"u",Nn=typeof Map=="function",Hn=typeof Set=="function",$n=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function Ee(n,t){if(n===t)return!0;if(n&&t&&typeof n=="object"&&typeof t=="object"){if(n.constructor!==t.constructor)return!1;var s,o,r;if(Array.isArray(n)){if(s=n.length,s!=t.length)return!1;for(o=s;o--!==0;)if(!Ee(n[o],t[o]))return!1;return!0}var a;if(Nn&&n instanceof Map&&t instanceof Map){if(n.size!==t.size)return!1;for(a=n.entries();!(o=a.next()).done;)if(!t.has(o.value[0]))return!1;for(a=n.entries();!(o=a.next()).done;)if(!Ee(o.value[1],t.get(o.value[0])))return!1;return!0}if(Hn&&n instanceof Set&&t instanceof Set){if(n.size!==t.size)return!1;for(a=n.entries();!(o=a.next()).done;)if(!t.has(o.value[0]))return!1;return!0}if($n&&ArrayBuffer.isView(n)&&ArrayBuffer.isView(t)){if(s=n.length,s!=t.length)return!1;for(o=s;o--!==0;)if(n[o]!==t[o])return!1;return!0}if(n.constructor===RegExp)return n.source===t.source&&n.flags===t.flags;if(n.valueOf!==Object.prototype.valueOf&&typeof n.valueOf=="function"&&typeof t.valueOf=="function")return n.valueOf()===t.valueOf();if(n.toString!==Object.prototype.toString&&typeof n.toString=="function"&&typeof t.toString=="function")return n.toString()===t.toString();if(r=Object.keys(n),s=r.length,s!==Object.keys(t).length)return!1;for(o=s;o--!==0;)if(!Object.prototype.hasOwnProperty.call(t,r[o]))return!1;if(Mn&&n instanceof Element)return!1;for(o=s;o--!==0;)if(!((r[o]==="_owner"||r[o]==="__v"||r[o]==="__o")&&n.$$typeof)&&!Ee(n[r[o]],t[r[o]]))return!1;return!0}return n!==n&&t!==t}var qn=function(t,s){try{return Ee(t,s)}catch(o){if((o.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw o}};const Bn=Xe(qn);/*
object-assign
(c) Sindre Sorhus
@license MIT
*/var at=Object.getOwnPropertySymbols,zn=Object.prototype.hasOwnProperty,Wn=Object.prototype.propertyIsEnumerable;function Gn(n){if(n==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(n)}function Qn(){try{if(!Object.assign)return!1;var n=new String("abc");if(n[5]="de",Object.getOwnPropertyNames(n)[0]==="5")return!1;for(var t={},s=0;s<10;s++)t["_"+String.fromCharCode(s)]=s;var o=Object.getOwnPropertyNames(t).map(function(a){return t[a]});if(o.join("")!=="0123456789")return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(a){r[a]=a}),Object.keys(Object.assign({},r)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}var Kn=Qn()?Object.assign:function(n,t){for(var s,o=Gn(n),r,a=1;a<arguments.length;a++){s=Object(arguments[a]);for(var u in s)zn.call(s,u)&&(o[u]=s[u]);if(at){r=at(s);for(var d=0;d<r.length;d++)Wn.call(s,r[d])&&(o[r[d]]=s[r[d]])}}return o};const Jn=Xe(Kn);var re={BODY:"bodyAttributes",HTML:"htmlAttributes",TITLE:"titleAttributes"},C={BASE:"base",BODY:"body",HEAD:"head",HTML:"html",LINK:"link",META:"meta",NOSCRIPT:"noscript",SCRIPT:"script",STYLE:"style",TITLE:"title"};Object.keys(C).map(function(n){return C[n]});var R={CHARSET:"charset",CSS_TEXT:"cssText",HREF:"href",HTTPEQUIV:"http-equiv",INNER_HTML:"innerHTML",ITEM_PROP:"itemprop",NAME:"name",PROPERTY:"property",REL:"rel",SRC:"src",TARGET:"target"},Ie={accesskey:"accessKey",charset:"charSet",class:"className",contenteditable:"contentEditable",contextmenu:"contextMenu","http-equiv":"httpEquiv",itemprop:"itemProp",tabindex:"tabIndex"},Te={DEFAULT_TITLE:"defaultTitle",DEFER:"defer",ENCODE_SPECIAL_CHARACTERS:"encodeSpecialCharacters",ON_CHANGE_CLIENT_STATE:"onChangeClientState",TITLE_TEMPLATE:"titleTemplate"},Yn=Object.keys(Ie).reduce(function(n,t){return n[Ie[t]]=t,n},{}),Vn=[C.NOSCRIPT,C.SCRIPT,C.STYLE],B="data-react-helmet",Xn=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},Zn=function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")},er=function(){function n(t,s){for(var o=0;o<s.length;o++){var r=s[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(t,s,o){return s&&n(t.prototype,s),o&&n(t,o),t}}(),M=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var o in s)Object.prototype.hasOwnProperty.call(s,o)&&(n[o]=s[o])}return n},tr=function(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof t);n.prototype=Object.create(t&&t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(n,t):n.__proto__=t)},it=function(n,t){var s={};for(var o in n)t.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(n,o)&&(s[o]=n[o]);return s},nr=function(n,t){if(!n)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t&&(typeof t=="object"||typeof t=="function")?t:n},qe=function(t){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0;return s===!1?String(t):String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;")},rr=function(t){var s=he(t,C.TITLE),o=he(t,Te.TITLE_TEMPLATE);if(o&&s)return o.replace(/%s/g,function(){return Array.isArray(s)?s.join(""):s});var r=he(t,Te.DEFAULT_TITLE);return s||r||void 0},sr=function(t){return he(t,Te.ON_CHANGE_CLIENT_STATE)||function(){}},Ne=function(t,s){return s.filter(function(o){return typeof o[t]<"u"}).map(function(o){return o[t]}).reduce(function(o,r){return M({},o,r)},{})},or=function(t,s){return s.filter(function(o){return typeof o[C.BASE]<"u"}).map(function(o){return o[C.BASE]}).reverse().reduce(function(o,r){if(!o.length)for(var a=Object.keys(r),u=0;u<a.length;u++){var d=a[u],h=d.toLowerCase();if(t.indexOf(h)!==-1&&r[h])return o.concat(r)}return o},[])},ge=function(t,s,o){var r={};return o.filter(function(a){return Array.isArray(a[t])?!0:(typeof a[t]<"u"&&lr("Helmet: "+t+' should be of type "Array". Instead found type "'+Xn(a[t])+'"'),!1)}).map(function(a){return a[t]}).reverse().reduce(function(a,u){var d={};u.filter(function(c){for(var p=void 0,g=Object.keys(c),f=0;f<g.length;f++){var y=g[f],x=y.toLowerCase();s.indexOf(x)!==-1&&!(p===R.REL&&c[p].toLowerCase()==="canonical")&&!(x===R.REL&&c[x].toLowerCase()==="stylesheet")&&(p=x),s.indexOf(y)!==-1&&(y===R.INNER_HTML||y===R.CSS_TEXT||y===R.ITEM_PROP)&&(p=y)}if(!p||!c[p])return!1;var v=c[p].toLowerCase();return r[p]||(r[p]={}),d[p]||(d[p]={}),r[p][v]?!1:(d[p][v]=!0,!0)}).reverse().forEach(function(c){return a.push(c)});for(var h=Object.keys(d),m=0;m<h.length;m++){var l=h[m],i=Jn({},r[l],d[l]);r[l]=i}return a},[]).reverse()},he=function(t,s){for(var o=t.length-1;o>=0;o--){var r=t[o];if(r.hasOwnProperty(s))return r[s]}return null},ar=function(t){return{baseTag:or([R.HREF,R.TARGET],t),bodyAttributes:Ne(re.BODY,t),defer:he(t,Te.DEFER),encode:he(t,Te.ENCODE_SPECIAL_CHARACTERS),htmlAttributes:Ne(re.HTML,t),linkTags:ge(C.LINK,[R.REL,R.HREF],t),metaTags:ge(C.META,[R.NAME,R.CHARSET,R.HTTPEQUIV,R.PROPERTY,R.ITEM_PROP],t),noscriptTags:ge(C.NOSCRIPT,[R.INNER_HTML],t),onChangeClientState:sr(t),scriptTags:ge(C.SCRIPT,[R.SRC,R.INNER_HTML],t),styleTags:ge(C.STYLE,[R.CSS_TEXT],t),title:rr(t),titleAttributes:Ne(re.TITLE,t)}},Be=function(){var n=Date.now();return function(t){var s=Date.now();s-n>16?(n=s,t(s)):setTimeout(function(){Be(t)},0)}}(),ct=function(t){return clearTimeout(t)},ir=typeof window<"u"?window.requestAnimationFrame&&window.requestAnimationFrame.bind(window)||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||Be:global.requestAnimationFrame||Be,cr=typeof window<"u"?window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||ct:global.cancelAnimationFrame||ct,lr=function(t){return console&&typeof console.warn=="function"&&console.warn(t)},xe=null,ur=function(t){xe&&cr(xe),t.defer?xe=ir(function(){lt(t,function(){xe=null})}):(lt(t),xe=null)},lt=function(t,s){var o=t.baseTag,r=t.bodyAttributes,a=t.htmlAttributes,u=t.linkTags,d=t.metaTags,h=t.noscriptTags,m=t.onChangeClientState,l=t.scriptTags,i=t.styleTags,c=t.title,p=t.titleAttributes;ze(C.BODY,r),ze(C.HTML,a),dr(c,p);var g={baseTag:ue(C.BASE,o),linkTags:ue(C.LINK,u),metaTags:ue(C.META,d),noscriptTags:ue(C.NOSCRIPT,h),scriptTags:ue(C.SCRIPT,l),styleTags:ue(C.STYLE,i)},f={},y={};Object.keys(g).forEach(function(x){var v=g[x],P=v.newTags,le=v.oldTags;P.length&&(f[x]=P),le.length&&(y[x]=g[x].oldTags)}),s&&s(),m(t,f,y)},Tt=function(t){return Array.isArray(t)?t.join(""):t},dr=function(t,s){typeof t<"u"&&document.title!==t&&(document.title=Tt(t)),ze(C.TITLE,s)},ze=function(t,s){var o=document.getElementsByTagName(t)[0];if(o){for(var r=o.getAttribute(B),a=r?r.split(","):[],u=[].concat(a),d=Object.keys(s),h=0;h<d.length;h++){var m=d[h],l=s[m]||"";o.getAttribute(m)!==l&&o.setAttribute(m,l),a.indexOf(m)===-1&&a.push(m);var i=u.indexOf(m);i!==-1&&u.splice(i,1)}for(var c=u.length-1;c>=0;c--)o.removeAttribute(u[c]);a.length===u.length?o.removeAttribute(B):o.getAttribute(B)!==d.join(",")&&o.setAttribute(B,d.join(","))}},ue=function(t,s){var o=document.head||document.querySelector(C.HEAD),r=o.querySelectorAll(t+"["+B+"]"),a=Array.prototype.slice.call(r),u=[],d=void 0;return s&&s.length&&s.forEach(function(h){var m=document.createElement(t);for(var l in h)if(h.hasOwnProperty(l))if(l===R.INNER_HTML)m.innerHTML=h.innerHTML;else if(l===R.CSS_TEXT)m.styleSheet?m.styleSheet.cssText=h.cssText:m.appendChild(document.createTextNode(h.cssText));else{var i=typeof h[l]>"u"?"":h[l];m.setAttribute(l,i)}m.setAttribute(B,"true"),a.some(function(c,p){return d=p,m.isEqualNode(c)})?a.splice(d,1):u.push(m)}),a.forEach(function(h){return h.parentNode.removeChild(h)}),u.forEach(function(h){return o.appendChild(h)}),{oldTags:a,newTags:u}},Ct=function(t){return Object.keys(t).reduce(function(s,o){var r=typeof t[o]<"u"?o+'="'+t[o]+'"':""+o;return s?s+" "+r:r},"")},hr=function(t,s,o,r){var a=Ct(o),u=Tt(s);return a?"<"+t+" "+B+'="true" '+a+">"+qe(u,r)+"</"+t+">":"<"+t+" "+B+'="true">'+qe(u,r)+"</"+t+">"},mr=function(t,s,o){return s.reduce(function(r,a){var u=Object.keys(a).filter(function(m){return!(m===R.INNER_HTML||m===R.CSS_TEXT)}).reduce(function(m,l){var i=typeof a[l]>"u"?l:l+'="'+qe(a[l],o)+'"';return m?m+" "+i:i},""),d=a.innerHTML||a.cssText||"",h=Vn.indexOf(t)===-1;return r+"<"+t+" "+B+'="true" '+u+(h?"/>":">"+d+"</"+t+">")},"")},St=function(t){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Object.keys(t).reduce(function(o,r){return o[Ie[r]||r]=t[r],o},s)},pr=function(t){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Object.keys(t).reduce(function(o,r){return o[Yn[r]||r]=t[r],o},s)},fr=function(t,s,o){var r,a=(r={key:s},r[B]=!0,r),u=St(o,a);return[ve.createElement(C.TITLE,u,s)]},gr=function(t,s){return s.map(function(o,r){var a,u=(a={key:r},a[B]=!0,a);return Object.keys(o).forEach(function(d){var h=Ie[d]||d;if(h===R.INNER_HTML||h===R.CSS_TEXT){var m=o.innerHTML||o.cssText;u.dangerouslySetInnerHTML={__html:m}}else u[h]=o[d]}),ve.createElement(t,u)})},K=function(t,s,o){switch(t){case C.TITLE:return{toComponent:function(){return fr(t,s.title,s.titleAttributes)},toString:function(){return hr(t,s.title,s.titleAttributes,o)}};case re.BODY:case re.HTML:return{toComponent:function(){return St(s)},toString:function(){return Ct(s)}};default:return{toComponent:function(){return gr(t,s)},toString:function(){return mr(t,s,o)}}}},wt=function(t){var s=t.baseTag,o=t.bodyAttributes,r=t.encode,a=t.htmlAttributes,u=t.linkTags,d=t.metaTags,h=t.noscriptTags,m=t.scriptTags,l=t.styleTags,i=t.title,c=i===void 0?"":i,p=t.titleAttributes;return{base:K(C.BASE,s,r),bodyAttributes:K(re.BODY,o,r),htmlAttributes:K(re.HTML,a,r),link:K(C.LINK,u,r),meta:K(C.META,d,r),noscript:K(C.NOSCRIPT,h,r),script:K(C.SCRIPT,m,r),style:K(C.STYLE,l,r),title:K(C.TITLE,{title:c,titleAttributes:p},r)}},xr=function(t){var s,o;return o=s=function(r){tr(a,r);function a(){return Zn(this,a),nr(this,r.apply(this,arguments))}return a.prototype.shouldComponentUpdate=function(d){return!Bn(this.props,d)},a.prototype.mapNestedChildrenToProps=function(d,h){if(!h)return null;switch(d.type){case C.SCRIPT:case C.NOSCRIPT:return{innerHTML:h};case C.STYLE:return{cssText:h}}throw new Error("<"+d.type+" /> elements are self-closing and can not contain children. Refer to our API for more information.")},a.prototype.flattenArrayTypeChildren=function(d){var h,m=d.child,l=d.arrayTypeChildren,i=d.newChildProps,c=d.nestedChildren;return M({},l,(h={},h[m.type]=[].concat(l[m.type]||[],[M({},i,this.mapNestedChildrenToProps(m,c))]),h))},a.prototype.mapObjectTypeChildren=function(d){var h,m,l=d.child,i=d.newProps,c=d.newChildProps,p=d.nestedChildren;switch(l.type){case C.TITLE:return M({},i,(h={},h[l.type]=p,h.titleAttributes=M({},c),h));case C.BODY:return M({},i,{bodyAttributes:M({},c)});case C.HTML:return M({},i,{htmlAttributes:M({},c)})}return M({},i,(m={},m[l.type]=M({},c),m))},a.prototype.mapArrayTypeChildrenToProps=function(d,h){var m=M({},h);return Object.keys(d).forEach(function(l){var i;m=M({},m,(i={},i[l]=d[l],i))}),m},a.prototype.warnOnInvalidChildren=function(d,h){return!0},a.prototype.mapChildrenToProps=function(d,h){var m=this,l={};return ve.Children.forEach(d,function(i){if(!(!i||!i.props)){var c=i.props,p=c.children,g=it(c,["children"]),f=pr(g);switch(m.warnOnInvalidChildren(i,p),i.type){case C.LINK:case C.META:case C.NOSCRIPT:case C.SCRIPT:case C.STYLE:l=m.flattenArrayTypeChildren({child:i,arrayTypeChildren:l,newChildProps:f,nestedChildren:p});break;default:h=m.mapObjectTypeChildren({child:i,newProps:h,newChildProps:f,nestedChildren:p});break}}}),h=this.mapArrayTypeChildrenToProps(l,h),h},a.prototype.render=function(){var d=this.props,h=d.children,m=it(d,["children"]),l=M({},m);return h&&(l=this.mapChildrenToProps(h,l)),ve.createElement(t,l)},er(a,null,[{key:"canUseDOM",set:function(d){t.canUseDOM=d}}]),a}(ve.Component),s.propTypes={base:I.object,bodyAttributes:I.object,children:I.oneOfType([I.arrayOf(I.node),I.node]),defaultTitle:I.string,defer:I.bool,encodeSpecialCharacters:I.bool,htmlAttributes:I.object,link:I.arrayOf(I.object),meta:I.arrayOf(I.object),noscript:I.arrayOf(I.object),onChangeClientState:I.func,script:I.arrayOf(I.object),style:I.arrayOf(I.object),title:I.string,titleAttributes:I.object,titleTemplate:I.string},s.defaultProps={defer:!0,encodeSpecialCharacters:!0},s.peek=t.peek,s.rewind=function(){var r=t.rewind();return r||(r=wt({baseTag:[],bodyAttributes:{},encodeSpecialCharacters:!0,htmlAttributes:{},linkTags:[],metaTags:[],noscriptTags:[],scriptTags:[],styleTags:[],title:"",titleAttributes:{}})),r},o},yr=function(){return null},vr=Ln(ar,ur,wt)(yr),We=xr(vr);We.renderStatic=We.rewind;const bt=()=>{const{t:n}=L();return e.jsx(D,{sx:{marginTop:2,display:"flex",justifyContent:"center"},children:e.jsx(D,{sx:{maxWidth:"800px",flexGrow:1},children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:12,sx:{height:"50px"}}),e.jsx(j,{item:!0,xs:12,children:e.jsx(me,{})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(q,{href:"https://www.flaticon.com/free-icons/guests-book",title:"guests book icons",children:e.jsx(A,{variant:"caption",children:n("Favicon")})})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsxs(A,{variant:"caption",children:["© 2024 Kilian Kurt Hofmann | Build ","3.0.0"]})})]})})})},Ze=({children:n})=>e.jsxs(e.Fragment,{children:[e.jsx(D,{sx:{flexGrow:1}}),e.jsx(D,{sx:{display:"flex",justifyContent:"center"},children:e.jsx(D,{sx:{maxWidth:"800px",flexGrow:1},children:n})}),e.jsx(D,{sx:{flexGrow:1}}),e.jsx(bt,{})]});var F=(n=>(n.INDEX="/",n.PROFILE="/profile",n.CONFIRM="/confirm",n.USERS="/users",n))(F||{});const jr=({error:n})=>{const{t}=L(),s=Ve(),o=ie(),r=on(),a=J();return w.useEffect(()=>{console.log(r),r.reset()},[r]),e.jsx(Ze,{children:e.jsxs(j,{container:!0,spacing:2,sx:{marginTop:0},children:[e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(Wt,{sx:{fontSize:"200px"}})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(A,{variant:"h4",sx:{textAlign:"center"},children:t("code"in n&&n.code===k.UNAUTHORIZED?"Session expired":"General error")})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(q,{variant:"h6",sx:{cursor:"pointer"},onClick:()=>{a.clear(),s.invalidate(),o({to:F.INDEX})},children:t("Back to main")})})]})})},Tr=()=>{const{t:n}=L();return e.jsx(Ze,{children:e.jsxs(j,{container:!0,spacing:2,sx:{marginTop:0},children:[e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(A,{variant:"404",children:"404"})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(A,{variant:"h4",sx:{textAlign:"center"},children:n("Page not found")})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(q,{component:W,to:"/",variant:"h6",underline:"none",children:n("Back to main")})})]})})},Cr=()=>e.jsxs(D,{sx:{minHeight:"100vh",display:"flex",flexDirection:"column"},children:[e.jsx(cn,{}),!1]}),pe=an()({component:Cr}),Y=({error:n,context:t,color:s="error.main"})=>{const{t:o}=L();if(!n)return null;if(n.code)switch(n.code){case k.NOT_FOUND:return e.jsx(A,{color:s,children:o(n.code,{context:`${n.entity}:${t}`})});case k.NOT_ALLOWED:case k.UNAUTHORIZED:return e.jsx(A,{color:s,children:o(n.code,{context:t})});case k.FAILED_UPDATE:return n.fields.map((r,a)=>e.jsx(A,{color:s,children:o(n.code,{context:`${n.reasons[a]}:${r}:${t}`})},`error_${r}`));case k.MISSING_FIELD:return n.fields.map(r=>e.jsx(A,{color:s,children:o(n.code,{context:`${r}:${t}`})},`error_${r}`));case k.DUPLICATE:return e.jsx(A,{color:s,children:o(n.code,{context:`${n.entity}:${t}`})})}return e.jsx(A,{color:s,children:o((n==null?void 0:n.message)??"Unknown",{context:t})})},Sr=()=>{const[n,t]=w.useState(),[s,o]=w.useState(0),{t:r}=L(),a=J(),u=ie(),d=_(),h=Q({mutationFn:({data:l})=>d.newPost(l)}),m=ce({defaultValues:{content:""},onSubmit:async({value:l})=>{try{h.mutate({data:l},{onSuccess:async i=>{m.reset(),o(0),await a.invalidateQueries({queryKey:["posts"]}),u({to:"/",search:{page:i.pages-1}})},onError:t})}catch(i){t(i)}}});return e.jsx("form",{onSubmit:l=>{l.preventDefault(),l.stopPropagation(),m.handleSubmit()},onKeyDown:l=>{l.key==="Tab"&&l.stopPropagation()},noValidate:!0,children:e.jsxs(D,{sx:{display:"grid",gap:2,padding:1},children:[e.jsx(m.Field,{name:"content",validators:{onChange:({value:l})=>l?void 0:r("Content required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:l})=>!l&&r("Content required")},children:l=>e.jsxs(e.Fragment,{children:[e.jsx(N,{variant:"outlined",multiline:!0,minRows:3,name:l.name,value:l.state.value,onBlur:l.handleBlur,onChange:i=>{i.target.value.length<=250&&(o(i.target.value.length),l.handleChange(i.target.value))},size:"small",label:r("Comment"),required:!0,error:l.state.meta.isTouched&&l.state.meta.errors.length>0,helperText:l.state.meta.isTouched?l.state.meta.errors.join(","):"",autoComplete:"off",fullWidth:!0}),e.jsx(dt,{variant:"determinate",value:s/250*100,color:s===250?"error":s>=200?"warning":"primary"})]})}),e.jsx(m.Subscribe,{selector:l=>[l.canSubmit,l.isSubmitting],children:([l])=>e.jsx(e.Fragment,{children:e.jsx(U,{type:"submit",disabled:!l||h.isPending,variant:"contained",endIcon:h.isPending&&e.jsx(Z,{color:"inherit",size:"20px"}),children:r("Post comment")})})}),e.jsx(z,{open:h.isError,autoHideDuration:2e3,onClose:()=>{h.reset()},TransitionProps:{onExited:()=>t(void 0)},children:e.jsx(Ge,{severity:"error",variant:"filled",sx:{width:"100%"},children:n&&e.jsx(Y,{error:n,context:"newPost",color:"white"})})})]})})},wr="/phpCourse/exam/dist/assets/guests-book-TdSsJC37.png",br=({anchorEl:n,handleClose:t})=>e.jsxs(Qe,{anchorEl:n,anchorOrigin:{vertical:"bottom",horizontal:"right"},keepMounted:!0,transformOrigin:{vertical:"top",horizontal:"right"},open:!!n,onClose:t,sx:{"& .MuiMenu-paper":{minWidth:"240px"}},children:[e.jsx(G,{selected:ye.language==="en",onClick:()=>{ye.changeLanguage("en"),t()},children:"English"},"de"),e.jsx(G,{selected:ye.language==="de",onClick:()=>{ye.changeLanguage("de"),t()},children:"Deutsch"},"en")]}),Er=({anchorEl:n,handleClose:t})=>{const[s,o]=ke(a=>[a.theme,a.setTheme]),{t:r}=L();return e.jsxs(Qe,{anchorEl:n,anchorOrigin:{vertical:"bottom",horizontal:"right"},keepMounted:!0,transformOrigin:{vertical:"top",horizontal:"right"},open:!!n,onClose:t,sx:{"& .MuiMenu-paper":{minWidth:"240px"}},children:[e.jsx(G,{selected:s==="dark",onClick:()=>{o("dark")},children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:2,children:e.jsx(ht,{})}),e.jsx(j,{item:!0,xs:10,children:e.jsx(A,{children:r("Dark")})})]})},"dark"),e.jsx(G,{selected:s==="light",onClick:()=>{o("light")},children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:2,children:e.jsx(mt,{})}),e.jsx(j,{item:!0,xs:10,children:e.jsx(A,{children:r("Light")})})]})},"light"),e.jsx(G,{selected:!s,onClick:()=>{o(void 0)},children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:2,children:e.jsx(pt,{})}),e.jsx(j,{item:!0,xs:10,children:e.jsx(A,{children:r("System")})})]})},"system")]})},Ar=({open:n,onClose:t})=>{const[s,o]=w.useState(),{t:r}=L(),a=se(),u=ee(a.breakpoints.only("xs"),{noSsr:!0}),d=_(),h=Q({mutationFn:({data:i})=>d.createUser(i)}),m=ce({defaultValues:{username:"",email:"",password:"",passwordConfirm:""},onSubmit:async({value:i})=>{try{h.mutate({data:{username:i.username,email:i.email,password:i.password}},{onSuccess:()=>o(void 0),onError:o})}catch(c){o(c)}}}),l=()=>{m.reset(),o(void 0),t()};return h.isSuccess?e.jsxs(X,{open:n,onClose:l,fullWidth:!0,fullScreen:u,children:[e.jsx($,{children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(ft,{color:"action",sx:{fontSize:"200px"}})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(A,{variant:"h5",children:r("Confirm header")})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(A,{children:r("Confirm mail")})})]})}),e.jsx(oe,{children:e.jsx(U,{onClick:l,children:r("Close")})})]}):e.jsxs(X,{open:n,onClose:l,fullWidth:!0,fullScreen:u,PaperProps:{component:"form",encType:"multipart/form-data",onSubmit:i=>{i.preventDefault(),i.stopPropagation(),m.handleSubmit()},onKeyDown:i=>{i.key==="Tab"&&i.stopPropagation()},noValidate:!0},children:[e.jsx(ae,{children:r("Register")}),e.jsx($,{children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:12,children:e.jsx(m.Field,{name:"username",validators:{onChange:({value:i})=>i?void 0:r("Username required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:i})=>!i&&r("Username required")},children:i=>e.jsx(e.Fragment,{children:e.jsx(N,{variant:"outlined",name:i.name,value:i.state.value,onBlur:i.handleBlur,onChange:c=>i.handleChange(c.target.value),size:"small",label:r("Username"),required:!0,error:i.state.meta.isTouched&&i.state.meta.errors.length>0,helperText:i.state.meta.isTouched?i.state.meta.errors.join(","):"",autoComplete:"new-username",fullWidth:!0,margin:"dense"})})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(m.Field,{name:"email",validators:{onChange:({value:i})=>i?void 0:r("Email required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:i})=>!i&&r("Email required")},children:i=>e.jsx(e.Fragment,{children:e.jsx(N,{variant:"outlined",name:i.name,value:i.state.value,onBlur:i.handleBlur,onChange:c=>i.handleChange(c.target.value),size:"small",label:r("Email"),required:!0,error:i.state.meta.isTouched&&i.state.meta.errors.length>0,helperText:i.state.meta.isTouched?i.state.meta.errors.join(","):"",type:"email",autoComplete:"new-email",inputMode:"email",fullWidth:!0})})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(m.Field,{name:"password",validators:{onChange:({value:i})=>i?void 0:r("Password required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:i})=>!i&&r("Password required")},children:i=>e.jsx(e.Fragment,{children:e.jsx(N,{variant:"outlined",name:i.name,value:i.state.value,onBlur:i.handleBlur,onChange:c=>i.handleChange(c.target.value),size:"small",label:r("Password"),required:!0,error:i.state.meta.isTouched&&i.state.meta.errors.length>0,helperText:i.state.meta.isTouched?i.state.meta.errors.join(","):"",type:"password",autoComplete:"new-password",fullWidth:!0})})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(m.Field,{name:"passwordConfirm",validators:{onChangeListenTo:["password"],onChange:({value:i,fieldApi:c})=>i?i!==c.form.getFieldValue("password")?r("Password match"):void 0:r("Password required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:i,fieldApi:c})=>i?i!==c.form.getFieldValue("password")?r("Password match"):void 0:r("Password required")},children:i=>e.jsx(e.Fragment,{children:e.jsx(N,{variant:"outlined",name:i.name,value:i.state.value,onBlur:i.handleBlur,onChange:c=>i.handleChange(c.target.value),size:"small",label:r("Password confirm"),required:!0,error:i.state.meta.isTouched&&i.state.meta.errors.length>0,helperText:i.state.meta.isTouched?i.state.meta.errors.join(","):"",type:"password",autoComplete:"new-password",fullWidth:!0})})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(m.Subscribe,{selector:i=>[i.canSubmit,i.isSubmitting],children:([i])=>e.jsx(e.Fragment,{children:e.jsx(U,{type:"submit",disabled:!i||h.isPending,variant:"contained",endIcon:h.isPending&&e.jsx(Z,{color:"inherit",size:"20px"}),children:r("Register")})})})}),e.jsx(j,{item:!0,xs:12,children:s&&e.jsx(Y,{error:s,context:"register"})})]})})]})},Pr=()=>{const[n,t]=w.useState(),{t:s}=L(),o=Ve(),r=_(),a=ce({defaultValues:{email:"",password:""},onSubmit:async({value:u})=>{try{await r.logIn(u.email,u.password),o.invalidate()}catch(d){t(d)}}});return e.jsx("form",{onSubmit:u=>{u.preventDefault(),u.stopPropagation(),a.handleSubmit()},onKeyDown:u=>{u.key==="Tab"&&u.stopPropagation()},noValidate:!0,children:e.jsxs(D,{sx:{display:"grid",gap:2,padding:1},children:[e.jsx(a.Field,{name:"email",validators:{onChange:({value:u})=>u?void 0:s("Email required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:u})=>!u&&s("Email required")},children:u=>e.jsx(e.Fragment,{children:e.jsx(N,{variant:"outlined",name:u.name,value:u.state.value,onBlur:u.handleBlur,onChange:d=>u.handleChange(d.target.value),size:"small",label:s("Email"),required:!0,error:u.state.meta.isTouched&&u.state.meta.errors.length>0,helperText:u.state.meta.isTouched?u.state.meta.errors.join(","):"",type:"email",autoComplete:"email",inputMode:"email",fullWidth:!0})})}),e.jsx(a.Field,{name:"password",validators:{onChange:({value:u})=>u?void 0:s("Password required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:u})=>!u&&s("Password required")},children:u=>e.jsx(e.Fragment,{children:e.jsx(N,{variant:"outlined",name:u.name,value:u.state.value,onBlur:u.handleBlur,onChange:d=>u.handleChange(d.target.value),size:"small",label:s("Password"),required:!0,error:u.state.meta.isTouched&&u.state.meta.errors.length>0,helperText:u.state.meta.isTouched?u.state.meta.errors.join(","):"",type:"password",autoComplete:"current-password",fullWidth:!0})})}),e.jsx(a.Subscribe,{selector:u=>[u.canSubmit,u.isSubmitting],children:([u])=>e.jsx(e.Fragment,{children:e.jsx(U,{type:"submit",disabled:!u,variant:"contained",children:s("Log in")})})}),n&&e.jsx(Y,{error:n,context:"login"})]})})},Or=({anchorEl:n,handleClose:t})=>{const[s,o]=w.useState(!1),r=ie(),a=Ve(),u=ln({from:"/profile/",strict:!0,shouldThrow:!1}),d=_(),h=()=>{o(!1),t()};return e.jsx(Qe,{anchorEl:n,anchorOrigin:{vertical:"bottom",horizontal:"right"},keepMounted:!0,transformOrigin:{vertical:"top",horizontal:"right"},open:!!n,onClose:h,sx:{"& .MuiMenu-paper":{minWidth:"240px"}},children:d.authenticatedUser?[e.jsx(G,{selected:!!u,onClick:()=>{r({to:F.PROFILE}),h()},children:S("Profile")},"profile"),e.jsx(G,{onClick:async()=>{await d.logOut(),a.invalidate(),r({to:F.INDEX})},children:S("Log out")},"logout"),d.authenticatedUser.isAdmin&&[e.jsx(me,{children:e.jsx(A,{variant:"caption",children:S("Admin")})}),e.jsx(G,{onClick:()=>r({to:F.USERS}),children:S("Manage users")},"users")]]:s?e.jsx(Ar,{open:s,onClose:()=>o(!1)}):e.jsxs(D,{children:[e.jsx(Pr,{}),e.jsx(D,{sx:{padding:1},children:e.jsxs(jn,{i18nKey:"Register prompt",children:[e.jsx(A,{component:"span"}),e.jsx(q,{sx:{cursor:"pointer"},variant:"body1",color:"secondary.main",onClick:()=>{o(!0),t()}}),e.jsx(A,{component:"span"})]})})]})})},Ir=({children:n})=>{const t=Jt({disableHysteresis:!0,threshold:0});return w.cloneElement(n,{elevation:t?4:0})},Rr=()=>{const[n,t]=w.useState(null),[s,o]=w.useState(null),[r,a]=w.useState(null),{t:u}=L(),d=un({select:i=>i.status==="pending"}),h=_(),[m]=ke(i=>[i.theme,i.setTheme]),l=()=>{t(null),o(null),a(null)};return e.jsx(Ir,{children:e.jsxs(e.Fragment,{children:[e.jsx(Gt,{children:e.jsxs(rt,{children:[e.jsxs(D,{sx:{flexGrow:1,alignItems:"center",display:"flex",gap:1},children:[e.jsxs(q,{component:W,to:"/",color:"white",variant:"h6",underline:"none",sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx("img",{src:wr,width:"24px",height:"24px",alt:u("GuestBook")})," ",u("GuestBook")]}),d&&e.jsx(Z,{size:16,thickness:10,sx:{color:"white"}})]}),e.jsxs(D,{sx:{display:"flex",gap:1},children:[e.jsx(de,{size:"large",onClick:i=>o(i.currentTarget),children:e.jsx(Qt,{sx:{color:"white"}})}),e.jsxs(de,{size:"large",onClick:i=>a(i.currentTarget),children:[m==="dark"&&e.jsx(ht,{}),m==="light"&&e.jsx(mt,{sx:{color:"white"}}),!m&&e.jsx(pt,{sx:{color:"white"}})]}),h.authenticatedUser?e.jsx(de,{onClick:i=>t(i.currentTarget),sx:{p:0},children:e.jsx(te,{alt:h.authenticatedUser.username,src:`${h.authenticatedUser.image}`,children:e.jsx(ne,{})})}):e.jsx(de,{size:"large",onClick:i=>t(i.currentTarget),color:"inherit",children:e.jsx(Kt,{})})]}),e.jsx(br,{anchorEl:s,handleClose:l}),e.jsx(Or,{anchorEl:n,handleClose:l}),e.jsx(Er,{anchorEl:r,handleClose:l})]})}),e.jsx(rt,{})]})})},Fe=({children:n})=>e.jsxs(e.Fragment,{children:[e.jsx(Rr,{}),e.jsx(D,{sx:{display:"flex",justifyContent:"center"},children:e.jsx(D,{sx:{maxWidth:"800px",flexGrow:1},children:n})}),e.jsx(D,{sx:{flexGrow:1}}),e.jsx(bt,{})]}),Et=n=>new Date(n.date).toLocaleString(navigator.languages[0]??"de-DE",{timeZone:n.timezone,day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",hour12:!1,minute:"2-digit"}),Ur=({post:n,open:t,onClose:s})=>{const[o,r]=w.useState(),[a,u]=w.useState(n.content.length),d=se(),h=ee(d.breakpoints.only("xs"),{noSsr:!0}),m=J(),l=_(),i=Q({mutationFn:({data:g,id:f})=>l.updatePost(g,f)}),c=ce({defaultValues:{content:n.content.replaceAll("<br />","")},onSubmit:async({value:g})=>{try{i.mutate({data:g,id:n.id},{onSuccess:()=>{p(),m.invalidateQueries({queryKey:["posts"]})},onError:r})}catch(f){r(f)}}}),p=()=>{c.reset(),r(void 0),s()};return w.useEffect(()=>{l.hasAuth||p()},[l.hasAuth]),e.jsxs(X,{open:t,onClose:p,fullWidth:!0,fullScreen:h,PaperProps:{component:"form",onSubmit:g=>{g.preventDefault(),g.stopPropagation(),c.handleSubmit()},onKeyDown:g=>{g.key==="Tab"&&g.stopPropagation()},noValidate:!0},children:[e.jsx(ae,{children:S("Edit post")}),e.jsx($,{children:e.jsx(c.Field,{name:"content",validators:{onChange:({value:g})=>g?void 0:S("Content required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:g})=>!g&&S("Content required")},children:g=>e.jsxs(e.Fragment,{children:[e.jsx(N,{variant:"outlined",multiline:!0,minRows:3,name:g.name,value:g.state.value,onBlur:g.handleBlur,onChange:f=>{f.target.value.length<=250&&(u(f.target.value.length),g.handleChange(f.target.value))},size:"small",label:S("Comment"),required:!0,error:g.state.meta.isTouched&&g.state.meta.errors.length>0,helperText:g.state.meta.isTouched?g.state.meta.errors.join(","):"",autoComplete:"off",margin:"dense",fullWidth:!0}),e.jsx(dt,{variant:"determinate",value:a/250*100,color:a===250?"error":a>=200?"warning":"primary"})]})})}),e.jsx(oe,{children:e.jsx(c.Subscribe,{selector:g=>[g.canSubmit,g.isSubmitting],children:([g])=>e.jsxs(e.Fragment,{children:[e.jsx(U,{variant:"outlined",onClick:()=>{p()},children:S("Cancel")}),e.jsx(U,{type:"submit",disabled:!g||i.isPending,autoFocus:!0,variant:"contained",endIcon:i.isPending&&e.jsx(Z,{color:"inherit",size:"20px"}),children:S("Save")})]})})}),o&&e.jsx($,{children:e.jsx(Y,{error:o,context:"postUpdate"})})]})},At=({page:n=0,post:t,disableActions:s})=>{var g,f,y,x,v;const[o,r]=w.useState(!1),[a,u]=w.useState(!1),[d,h]=w.useState(),{t:m}=L(),l=J(),i=ie(),c=_(),p=Q({mutationFn:P=>c.deletePost(P)});return e.jsxs(Ke,{children:[e.jsx(Yt,{avatar:!s&&"id"in t.user?t.user.id!==((g=c.authenticatedUser)==null?void 0:g.id)?e.jsx(q,{component:W,to:"/profile/$id",params:{id:t.user.id},children:e.jsx(te,{alt:t.user.username,src:`${t.user.image}`,children:e.jsx(ne,{})})}):e.jsx(q,{component:W,to:"/profile",children:e.jsx(te,{alt:t.user.username,src:`${t.user.image}`,children:e.jsx(ne,{})})}):e.jsx(te,{alt:t.user.username,src:`${t.user.image}`,children:e.jsx(ne,{})}),title:!s&&"id"in t.user?t.user.id!==((f=c.authenticatedUser)==null?void 0:f.id)?e.jsx(q,{component:W,to:"/profile/$id",params:{id:t.user.id},children:t.user.username}):e.jsx(q,{component:W,to:"/profile",children:t.user.username}):t.user.username,subheader:Et(t.postedAt)}),e.jsx(Je,{children:e.jsx(A,{children:e.jsx("span",{dangerouslySetInnerHTML:{__html:t.content}})})}),e.jsxs(Ye,{children:[!s&&(((y=c.authenticatedUser)==null?void 0:y.isAdmin)||"id"in t.user&&t.user.id===((x=c.authenticatedUser)==null?void 0:x.id))&&e.jsxs(e.Fragment,{children:[e.jsx(U,{size:"small",onClick:()=>u(!0),children:m("Edit")}),e.jsx(Ur,{post:t,open:a,onClose:()=>u(!1)})]}),!s&&((v=c.authenticatedUser)==null?void 0:v.isAdmin)&&e.jsxs(e.Fragment,{children:[e.jsx(U,{size:"small",color:"error",onClick:()=>r(!0),children:m("Delete")}),e.jsxs(X,{open:o,onClose:()=>r(!1),children:[e.jsx(ae,{children:m("Confirm post delete title")}),e.jsx($,{children:e.jsx(gt,{children:m("Confirm post delete body",{name:t.user.username})})}),e.jsxs(oe,{children:[e.jsx(U,{onClick:()=>r(!1),autoFocus:!0,variant:"contained",children:m("No")}),e.jsx(U,{variant:"outlined",color:"error",onClick:()=>{p.mutate(t.id,{onSuccess:async P=>{await l.invalidateQueries({queryKey:["posts"]}),n>=P.pages&&i({to:"/",search:{page:P.pages-1}})},onError:h}),r(!1)},children:m("Yes")})]})]})]})]}),e.jsx(z,{open:p.isError,autoHideDuration:2e3,onClose:()=>{p.reset()},TransitionProps:{onExited:()=>h(void 0)},children:e.jsx(Ge,{severity:"error",variant:"filled",sx:{width:"100%"},children:d&&e.jsx(Y,{error:d,context:"deletePost",color:"white"})})}),e.jsx(z,{open:p.isPending,message:m("Deleting")})]})},Pt=(n,t)=>Ue({queryKey:["posts",{page:t??0,hasAuth:n.hasAuth}],queryFn:async()=>await n.posts(t)}),Dr=()=>{const n=_(),{page:t}=Ot.useSearch(),{data:s,isFetching:o}=De(Pt(n,t)),{t:r}=L(),a=ie(),u=se(),d=ee(u.breakpoints.not("xs"),{noSsr:!0});return w.useEffect(()=>{(t??0)>=s.pages&&a({to:F.INDEX,search:{page:s.pages-1}})},[t]),e.jsxs(Fe,{children:[e.jsx(z,{open:o,message:r("Updating")}),e.jsxs(j,{container:!0,spacing:2,sx:{marginTop:0},children:[s.data.map(h=>e.jsx(j,{item:!0,xs:12,children:e.jsx(At,{page:t,post:h})},h.id)),e.jsx(j,{item:!0,xs:12,children:e.jsx(me,{variant:"middle"})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(xt,{page:(t??0)+1,count:s.pages,siblingCount:d?1:0,color:"primary",renderItem:h=>e.jsx(yt,{...h,component:W,to:"/",search:{page:(h.page??0)>0?(h.page??1)-1:void 0},onClick:m=>h.onClick(m)})})}),n.hasAuth?e.jsx(j,{item:!0,xs:12,children:e.jsx(Sr,{})}):e.jsxs(j,{item:!0,xs:12,children:[e.jsx(A,{variant:"h5",children:r("Leave comment header")}),e.jsx(A,{children:r("Leave comment action")})]})]})]})},Ot=Ce(F.INDEX)({loaderDeps:({search:{page:n}})=>({page:n}),loader:({context:{queryClient:n,Api:t},deps:{page:s}})=>n.ensureQueryData(Pt(t,s)),validateSearch:n=>({page:(n==null?void 0:n.page)!==void 0?Number((n==null?void 0:n.page)??0):void 0}),component:Dr}),It=(n,t)=>Ue({queryKey:["users",{page:t??0}],queryFn:async()=>await n.users(t),retry:(s,o)=>"code"in o&&o.code!==k.UNAUTHORIZED?s<3:!1}),kr=()=>{const[n,t]=w.useState(!1),[s,o]=w.useState(),r=_(),{page:a}=Rt.useSearch(),{data:u,isFetching:d,failureReason:h,error:m}=De(It(r,a)),{t:l}=L(),i=ie(),c=J(),p=se(),g=ee(p.breakpoints.not("xs"),{noSsr:!0});if(h&&"code"in h&&h.code===k.UNAUTHORIZED)throw h;if(m&&"code"in m&&m.code===k.UNAUTHORIZED)throw m;const f=Q({mutationFn:x=>r.deleteUser(x)}),y=Q({mutationFn:({data:x,id:v})=>r.updateUserPermissions(x,v)});return w.useEffect(()=>{(a??0)>=u.pages&&i({to:F.USERS,search:{page:u.pages-1}})},[a]),e.jsxs(Fe,{children:[e.jsx(z,{open:d,message:l("Updating")}),e.jsxs(j,{container:!0,spacing:2,sx:{marginTop:0},children:[u.data.map(x=>{var v,P;return e.jsx(j,{item:!0,xs:12,children:e.jsxs(Ke,{children:[e.jsxs(Je,{children:[x.id!==((v=r.authenticatedUser)==null?void 0:v.id)?e.jsx(q,{component:W,to:"/profile/$id",params:{id:x.id},children:x.username}):e.jsx(A,{children:x.username}),e.jsx(A,{children:x.email})]}),x.id!==((P=r.authenticatedUser)==null?void 0:P.id)&&e.jsxs(e.Fragment,{children:[e.jsxs(Ye,{children:[e.jsx(U,{size:"small",color:"error",onClick:()=>t(!0),children:l("Delete")}),e.jsx(U,{size:"small",onClick:()=>{y.mutate({data:{isAdmin:!x.isAdmin},id:x.id},{onSuccess:async()=>{await c.invalidateQueries({queryKey:["users"]})},onError:o})},children:l(x.isAdmin?"Demote Admin":"Make Admin")}),e.jsxs(X,{open:n,onClose:()=>t(!1),children:[e.jsx(ae,{children:l("Confirm user delete title")}),e.jsx($,{children:e.jsx(gt,{children:l("Confirm user delete body",{name:x.username})})}),e.jsxs(oe,{children:[e.jsx(U,{onClick:()=>t(!1),autoFocus:!0,variant:"contained",children:l("No")}),e.jsx(U,{variant:"outlined",color:"error",onClick:()=>{f.mutate(x.id,{onSuccess:async le=>{await c.invalidateQueries({queryKey:["users"]}),(a??0)>=le.pages&&i({to:F.PROFILE,search:{page:le.pages-1}})},onError:o}),t(!1)},children:l("Yes")})]})]})]}),e.jsx(z,{open:f.isError||y.isError,autoHideDuration:2e3,onClose:()=>{f.reset(),y.reset()},TransitionProps:{onExited:()=>o(void 0)},children:e.jsx(Ge,{severity:"error",variant:"filled",sx:{width:"100%"},children:m&&e.jsx(Y,{error:s,context:"delete|PermissionsUser",color:"white"})})}),e.jsx(z,{open:f.isPending,message:l("Deleting")}),e.jsx(z,{open:y.isPending,message:l("Updating")})]})]})},x.id)}),e.jsx(j,{item:!0,xs:12,children:e.jsx(me,{variant:"middle"})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(xt,{page:(a??0)+1,count:u.pages,siblingCount:g?1:0,color:"primary",renderItem:x=>e.jsx(yt,{...x,component:W,to:"/",search:{page:(x.page??0)>0?(x.page??1)-1:void 0},onClick:v=>x.onClick(v)})})})]})]})},Rt=Ce(`${F.USERS}/`)({loaderDeps:({search:{page:n}})=>({page:n}),loader:({context:{queryClient:n,Api:t},deps:{page:s}})=>n.ensureQueryData(It(t,s)),validateSearch:n=>({page:(n==null?void 0:n.page)!==void 0?Number((n==null?void 0:n.page)??0):void 0}),beforeLoad:({context:{Api:n}})=>{var t;if(!n.hasAuth&&!n.currentSession[0]||!((t=n.authenticatedUser)!=null&&t.isAdmin))throw Oe({to:F.INDEX})},component:kr}),Fr=({user:n,open:t,onClose:s})=>{const[o,r]=w.useState(),a=se(),u=ee(a.breakpoints.only("xs"),{noSsr:!0}),d=J(),h=_(),m=Q({mutationFn:({data:c,id:p})=>h.updateUser(c,p)}),l=ce({defaultValues:{username:n.username,email:n.email},onSubmit:async({value:c})=>{var p;try{m.mutate({data:c,id:((p=h.authenticatedUser)==null?void 0:p.id)===n.id?void 0:n.id},{onSuccess:()=>{var f;i();const g=((f=h.authenticatedUser)==null?void 0:f.id)===n.id?["profile"]:["profile",{id:n.id}];d.invalidateQueries({queryKey:g})},onError:r})}catch(g){r(g)}}}),i=()=>{l.reset(),r(void 0),s()};return w.useEffect(()=>{h.hasAuth||i()},[h.hasAuth]),e.jsxs(X,{open:t,onClose:i,fullWidth:!0,fullScreen:u,PaperProps:{component:"form",onSubmit:c=>{c.preventDefault(),c.stopPropagation(),l.handleSubmit()},onKeyDown:c=>{c.key==="Tab"&&c.stopPropagation()},noValidate:!0},children:[e.jsx(ae,{children:S("Edit data")}),e.jsx($,{children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:12,children:e.jsx(l.Field,{name:"username",validators:{onChange:({value:c})=>c?void 0:S("Username required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:c})=>!c&&S("Username required")},children:c=>e.jsx(e.Fragment,{children:e.jsx(N,{name:c.name,value:c.state.value,onBlur:c.handleBlur,onChange:p=>c.handleChange(p.target.value),size:"small",label:S("Username"),required:!0,margin:"dense",autoComplete:"new-username",fullWidth:!0,error:c.state.meta.isTouched&&c.state.meta.errors.length>0,helperText:c.state.meta.isTouched?c.state.meta.errors.join(","):""})})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(l.Field,{name:"email",validators:{onChange:({value:c})=>c?void 0:S("Email required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:c})=>!c&&S("Email required")},children:c=>e.jsx(e.Fragment,{children:e.jsx(N,{name:c.name,value:c.state.value,onBlur:c.handleBlur,onChange:p=>c.handleChange(p.target.value),size:"small",label:S("Email"),required:!0,margin:"dense",autoComplete:"new-email",fullWidth:!0,error:c.state.meta.isTouched&&c.state.meta.errors.length>0,helperText:c.state.meta.isTouched?c.state.meta.errors.join(","):""})})})})]})}),e.jsx(oe,{children:e.jsx(l.Subscribe,{selector:c=>[c.canSubmit,c.isSubmitting],children:([c])=>e.jsxs(e.Fragment,{children:[e.jsx(U,{variant:"outlined",onClick:()=>{i()},children:S("Cancel")}),e.jsx(U,{type:"submit",disabled:!c||m.isPending,autoFocus:!0,variant:"contained",endIcon:m.isPending&&e.jsx(Z,{color:"inherit",size:"20px"}),children:S("Save")})]})})}),o&&e.jsx($,{children:e.jsx(Y,{error:o,context:"userUpdate"})})]})},_r=({user:n,open:t,onClose:s})=>{const[o,r]=w.useState(),a=se(),u=ee(a.breakpoints.only("xs"),{noSsr:!0}),d=J(),h=_(),m=Q({mutationFn:({data:p,id:g})=>h.updateUserImage(p,g)}),l=ce({onSubmit:async({value:p})=>{var g;try{m.mutate({data:p,id:((g=h.authenticatedUser)==null?void 0:g.id)===n.id?void 0:n.id},{onSuccess:()=>{var y;c();const f=((y=h.authenticatedUser)==null?void 0:y.id)===n.id?["profile"]:["profile",{id:n.id}];d.invalidateQueries({queryKey:f})},onError:r})}catch(f){r(f)}}}),i=l.useStore(p=>({image:p.values.image,predefined:p.values.predefined})),c=()=>{l.reset(),r(void 0),s()};return w.useEffect(()=>{h.hasAuth||c()},[h.hasAuth]),e.jsxs(X,{open:t,onClose:c,fullWidth:!0,fullScreen:u,PaperProps:{component:"form",encType:"multipart/form-data",onSubmit:p=>{p.preventDefault(),p.stopPropagation(),l.handleSubmit()},onKeyDown:p=>{p.key==="Tab"&&p.stopPropagation()},noValidate:!0},children:[e.jsx(ae,{children:S("Edit image")}),e.jsx($,{sx:{gap:2},children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(te,{alt:n.username,src:i.image?URL.createObjectURL(i.image):i.predefined?`storage/profilbilder/default/${i.predefined}.svg`:`${n.image}`,sx:{width:"100px",height:"100px"},children:e.jsx(ne,{sx:{width:"60px",height:"60px"}})})}),e.jsx(j,{item:!0,xs:12,children:e.jsxs(D,{sx:{display:"flex",gap:2},children:[e.jsx(U,{component:"label",role:void 0,variant:"contained",tabIndex:-1,startIcon:e.jsx(Vt,{}),fullWidth:!0,children:e.jsx(l.Field,{name:"image",children:p=>{var g;return e.jsxs(e.Fragment,{children:[e.jsx(D,{sx:{textOverflow:"ellipsis",textWrap:"nowrap",overflow:"hidden"},children:p.state.value?S("Upload named",{name:(g=p.state.value)==null?void 0:g.name}):S("Upload image")}),e.jsx(N,{name:p.name,onBlur:p.handleBlur,value:p.state.value?void 0:"",onChange:f=>p.handleChange(f.target.files[0]),size:"small",type:"file",required:!0,sx:{display:"none"},autoComplete:"off"})]})}})}),e.jsx(de,{color:"error",onClick:()=>l.setFieldValue("image",void 0),children:e.jsx(Xt,{})})]})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(me,{variant:"middle",children:e.jsx(A,{sx:{opacity:.36},children:S("or")})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(l.Field,{name:"predefined",children:p=>e.jsxs(Zt,{fullWidth:!0,children:[e.jsx(en,{size:"small",children:S("Predefined")}),e.jsxs(tn,{name:p.name,value:p.state.value??"",onBlur:p.handleBlur,onChange:g=>p.handleChange(g.target.value),size:"small",label:S("Predefined"),autoComplete:"off",fullWidth:!0,children:[e.jsx(G,{value:"",selected:!0,children:"Keine Auswahl"}),[...Array(10).keys()].map(g=>e.jsx(G,{value:`avatar-${g+1}`,children:S("Avatar",{name:g+1})},`avatar-${g+1}`))]})]})})})]})}),e.jsx(oe,{children:e.jsx(l.Subscribe,{selector:p=>[p.canSubmit,p.isSubmitting],children:([p])=>e.jsxs(e.Fragment,{children:[e.jsx(U,{variant:"outlined",onClick:()=>{c()},children:S("Cancel")}),e.jsx(U,{type:"submit",disabled:!p||m.isPending,autoFocus:!0,variant:"contained",endIcon:m.isPending&&e.jsx(Z,{color:"inherit",size:"20px"}),children:S("Save")})]})})}),o&&e.jsx($,{children:e.jsx(Y,{error:o,context:"userUpdate"})})]})},Lr=({user:n,open:t,onClose:s})=>{const[o,r]=w.useState(),a=se(),u=ee(a.breakpoints.only("xs"),{noSsr:!0}),d=J(),h=_(),m=Q({mutationFn:({data:c,id:p})=>h.updateUser(c,p)}),l=ce({defaultValues:{password:"",passwordConfirm:""},onSubmit:async({value:c})=>{var p;try{m.mutate({data:{password:c.password},id:((p=h.authenticatedUser)==null?void 0:p.id)===n.id?void 0:n.id},{onSuccess:()=>{var f;i();const g=((f=h.authenticatedUser)==null?void 0:f.id)===n.id?["profile"]:["profile",{id:n.id}];d.invalidateQueries({queryKey:g})},onError:r})}catch(g){r(g)}}}),i=()=>{l.reset(),r(void 0),s()};return w.useEffect(()=>{h.hasAuth||i()},[h.hasAuth]),e.jsxs(X,{open:t,onClose:i,fullWidth:!0,fullScreen:u,PaperProps:{component:"form",onSubmit:c=>{c.preventDefault(),c.stopPropagation(),l.handleSubmit()},onKeyDown:c=>{c.key==="Tab"&&c.stopPropagation()},noValidate:!0},children:[e.jsx(ae,{children:S("Edit data")}),e.jsx($,{children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:12,children:e.jsx(l.Field,{name:"password",validators:{onChange:({value:c})=>c?void 0:S("Password required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:c})=>!c&&S("Password required")},children:c=>e.jsx(e.Fragment,{children:e.jsx(N,{variant:"outlined",name:c.name,value:c.state.value,onBlur:c.handleBlur,onChange:p=>c.handleChange(p.target.value),size:"small",label:S("Password"),required:!0,error:c.state.meta.isTouched&&c.state.meta.errors.length>0,helperText:c.state.meta.isTouched?c.state.meta.errors.join(","):"",type:"password",autoComplete:"new-password",fullWidth:!0})})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(l.Field,{name:"passwordConfirm",validators:{onChangeListenTo:["password"],onChange:({value:c,fieldApi:p})=>c?c!==p.form.getFieldValue("password")?S("Password match"):void 0:S("Password required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:c,fieldApi:p})=>c?c!==p.form.getFieldValue("password")?S("Password match"):void 0:S("Password required")},children:c=>e.jsx(e.Fragment,{children:e.jsx(N,{variant:"outlined",name:c.name,value:c.state.value,onBlur:c.handleBlur,onChange:p=>c.handleChange(p.target.value),size:"small",label:S("Password confirm"),required:!0,error:c.state.meta.isTouched&&c.state.meta.errors.length>0,helperText:c.state.meta.isTouched?c.state.meta.errors.join(","):"",type:"password",autoComplete:"new-password",fullWidth:!0})})})})]})}),e.jsx(oe,{children:e.jsx(l.Subscribe,{selector:c=>[c.canSubmit,c.isSubmitting],children:([c])=>e.jsxs(e.Fragment,{children:[e.jsx(U,{variant:"outlined",onClick:()=>{i()},children:S("Cancel")}),e.jsx(U,{type:"submit",disabled:!c||m.isPending,autoFocus:!0,variant:"contained",endIcon:m.isPending&&e.jsx(Z,{color:"inherit",size:"20px"}),children:S("Save")})]})})}),o&&e.jsx($,{children:e.jsx(Y,{error:o,context:"userUpdate"})})]})},Ut=({user:n,posts:t,canEdit:s})=>{const[o,r]=w.useState(!1),[a,u]=w.useState(!1),[d,h]=w.useState(!1),{t:m}=L();return e.jsxs(j,{container:!0,sx:{justifyContent:"center",marginTop:0},spacing:2,children:[e.jsx(j,{item:!0,children:e.jsxs(Ke,{children:[e.jsx(Je,{children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,sx:{display:"flex",flexGrow:1,justifyContent:"center"},children:s?e.jsx(de,{onClick:()=>u(!0),children:e.jsx(te,{alt:n.username,src:`${n.image}`,sx:{width:"100px",height:"100px"},children:e.jsx(ne,{sx:{width:"60px",height:"60px"}})})}):e.jsx(te,{alt:n.username,src:`${n.image}`,sx:{width:"100px",height:"100px"},children:e.jsx(ne,{sx:{width:"60px",height:"60px"}})})}),e.jsx(j,{item:!0,sx:{display:"flex",alignItems:"center"},children:e.jsxs(D,{sx:{display:"grid",gridTemplateColumns:"120px 1fr",columnGap:1},children:[e.jsxs(A,{fontWeight:"bold",children:[m("Username"),":"]}),e.jsx(A,{children:n.username}),e.jsxs(A,{fontWeight:"bold",children:[m("Email"),":"]}),e.jsx(A,{children:n.email}),e.jsxs(A,{fontWeight:"bold",children:[m("Member since"),":"]}),e.jsx(A,{children:Et(n.memberSince)}),e.jsxs(A,{fontWeight:"bold",children:[m("Post count"),":"]}),e.jsx(A,{children:n.postCount})]})})]})}),e.jsx(Ye,{children:s&&e.jsxs(e.Fragment,{children:[e.jsx(U,{size:"small",onClick:()=>r(!0),children:m("Edit")}),e.jsx(U,{size:"small",color:"secondary",onClick:()=>h(!0),children:m("Change password")}),e.jsx(Fr,{user:n,open:o,onClose:()=>r(!1)}),e.jsx(_r,{user:n,open:a,onClose:()=>u(!1)}),e.jsx(Lr,{user:n,open:d,onClose:()=>h(!1)})]})})]})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(me,{variant:"middle",children:e.jsx(A,{sx:{opacity:.36},children:m("Recent posts")})})}),t.map(l=>e.jsx(j,{item:!0,xs:12,children:e.jsx(At,{post:l,disableActions:!0})},`post_${l.id}`))]})},Dt=n=>{var t;return Ue({queryKey:["profile",{id:(t=n.authenticatedUser)==null?void 0:t.id}],queryFn:async()=>{var s;return{user:await n.user(),posts:await n.userPosts(((s=n.authenticatedUser)==null?void 0:s.id)??0)}},retry:(s,o)=>"code"in o&&o.code!==k.UNAUTHORIZED?s<3:!1})},kt=(n,t)=>Ue({queryKey:["profile",{id:t}],queryFn:async()=>({user:await n.user(t),posts:await n.userPosts(t)}),retry:(s,o)=>"code"in o&&o.code!==k.UNAUTHORIZED?s<3:!1}),Mr=()=>{const n=_(),{data:{user:t,posts:s},isFetching:o,error:r,failureReason:a}=De(Dt(n));if(a&&"code"in a&&a.code===k.UNAUTHORIZED)throw a;if(r&&"code"in r&&r.code===k.UNAUTHORIZED)throw r;return e.jsxs(Fe,{children:[e.jsx(z,{open:o,message:S("Updating")}),e.jsx(Ut,{user:t,posts:s.data,canEdit:!0})]})},Nr=Ce(`${F.PROFILE}/`)({loader:({context:{queryClient:n,Api:t}})=>{t.authenticatedUser&&n.ensureQueryData(Dt(t))},beforeLoad:({context:{Api:n}})=>{if(!n.hasAuth&&!n.currentSession[0])throw Oe({to:F.INDEX})},component:Mr}),Hr=()=>{const n=_(),{code:t}=Ft.useSearch(),{t:s}=L(),o=ie(),r=Q({mutationFn:({code:a})=>n.confirmUser(a)});return w.useEffect(()=>{t&&setTimeout(()=>r.mutate({code:t}),1e3)},[]),w.useEffect(()=>{t||o({to:"/"})},[t]),e.jsx(Ze,{children:e.jsxs(j,{container:!0,spacing:2,sx:{marginTop:0},children:[e.jsxs(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:[r.isSuccess&&e.jsx(ft,{color:"action",sx:{fontSize:"200px"}}),r.isError&&e.jsx(nn,{color:"action",sx:{fontSize:"200px"}}),(r.isPending||r.isIdle)&&e.jsx(Z,{size:200})]}),e.jsxs(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:[r.isSuccess&&e.jsx(A,{variant:"h5",children:s("Confirm success header")}),r.isError&&e.jsx(A,{variant:"h5",color:"error",children:s("Confirm error header")}),(r.isPending||r.isIdle)&&e.jsx(A,{variant:"h5",children:s("Confirm pending header")})]}),!r.isPending&&!r.isIdle&&e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(q,{component:W,to:"/",variant:"h6",underline:"none",children:s("Back to main")})})]})})},Ft=Ce(`${F.CONFIRM}/`)({validateSearch:n=>({code:(n==null?void 0:n.code)!==void 0?n==null?void 0:n.code:void 0}),component:Hr}),$r=()=>{var d;const n=_(),{id:t}=_t.useParams(),{data:{user:s,posts:o},isFetching:r,error:a,failureReason:u}=De(kt(n,t));if(u&&"code"in u&&u.code===k.UNAUTHORIZED)throw u;if(a&&"code"in a&&a.code===k.UNAUTHORIZED)throw a;return e.jsxs(Fe,{children:[e.jsx(z,{open:r,message:S("Updating")}),e.jsx(Ut,{user:s,posts:o.data,canEdit:(d=n.authenticatedUser)==null?void 0:d.isAdmin})]})},_t=Ce(`${F.PROFILE}/$id`)({params:{parse:({id:n})=>({id:parseInt(n)}),stringify:({id:n})=>({id:n.toString()})},loader:({context:{queryClient:n,Api:t},params:{id:s}})=>{n.ensureQueryData(kt(t,s))},beforeLoad:({params:{id:n},context:{Api:t}})=>{var s;if(!t.hasAuth&&!t.currentSession[0])throw Oe({to:F.INDEX});if(n===((s=t.authenticatedUser)==null?void 0:s.id))throw Oe({to:F.PROFILE})},component:$r}),qr=Ot.update({path:"/",getParentRoute:()=>pe}),Br=Rt.update({path:"/users/",getParentRoute:()=>pe}),zr=Nr.update({path:"/profile/",getParentRoute:()=>pe}),Wr=Ft.update({path:"/confirm/",getParentRoute:()=>pe}),Gr=_t.update({path:"/profile/$id",getParentRoute:()=>pe}),Qr=pe.addChildren({IndexRoute:qr,ProfileIdRoute:Gr,ConfirmIndexRoute:Wr,ProfileIndexRoute:zr,UsersIndexRoute:Br}),Kr=dn({routeTree:Qr,context:{queryClient:void 0,Api:void 0},defaultPreload:"intent",defaultPreloadStaleTime:0,basepath:"/phpCourse/exam",defaultNotFoundComponent:Tr,defaultErrorComponent:jr}),Jr=()=>{const n=_(),t=J();return e.jsx(hn,{router:Kr,context:{queryClient:t,Api:n}})},Lt=n=>({404:{fontSize:"6rem",[n.breakpoints.up("sm")]:{fontSize:"12rem"},[n.breakpoints.up("md")]:{fontSize:"18rem"}}}),Mt={styleOverrides:{root:{backgroundColor:void 0,color:"text.primary"}}};let Ae=Re({palette:{mode:"dark",primary:{main:"#b8e1ff"},secondary:{main:"#f990ca"},warning:{main:"#f9bf90"},error:{main:"#ffada7"},info:{main:"#2ea8ff"},success:{main:"#caf990"},background:{default:"#0f1115",paper:"#0d1019"}}});Ae=Re(Ae,{typography:{...Lt(Ae)},components:{...Mt}});const Yr=Ae;let Pe=Re({palette:{mode:"light",primary:{main:"#000b29"},secondary:{main:"#9d002a"},error:{main:"#d10000"},warning:{main:"#ff9800"},info:{main:"#2196f3"},success:{main:"#4caf50"},background:{default:"#fafafa",paper:"#ffffff"}}});Pe=Re(Pe,{typography:{...Lt(Pe)},components:{...Mt}});const Vr=Pe,Xr=()=>{const n=ee("(prefers-color-scheme: dark)"),t=ke(r=>r.theme),{t:s}=L(),o=w.useMemo(()=>t==="dark"||n?Yr:Vr,[t,n]);return e.jsxs(rn,{theme:o,children:[e.jsx(We,{children:e.jsx("title",{children:s("GuestBook")})}),e.jsx(sn,{}),e.jsx(Jr,{})]})},Zr=new mn,ut=document.getElementById("root");ut.innerHTML||He.createRoot(ut).render(e.jsx(w.StrictMode,{children:e.jsxs(pn,{client:Zr,children:[e.jsx(In,{children:e.jsx(Xr,{})}),!1]})}));