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