6 lines
43 KiB
JavaScript
6 lines
43 KiB
JavaScript
import{j as e,B as k,G as j,D as ue,T as w,E as at,L,a as R,b as Ue,c as A,C as z,S as J,A as Oe,M as Ce,d as M,e as Re,f as $e,g as Le,u as ne,h as X,i as G,k as _,l as Me,m as re,n as se,o as it,p as Ae,I as W,q as ct,r as K,P as Q,s as lt,t as ut,v as _e,w as dt,x as Ne,y as qe,z as ht,F as mt,H as xt,J as pt,K as gt,N as jt,O as ft,Q as yt,R as vt,U as de,V as Ct,W as St}from"./mui-4z7lf7t1.js";import{u as Se,a as Z,b as wt,L as q,c as bt,O as Tt,d as V,e as B,f as Y,g as Pt,h as Et,q as we,i as he,j as be,r as fe,k as It,R as kt,Q as At,l as Dt}from"./tanstack-Do102PZ-.js";import{c as Ft,r as T}from"./react-C_FdcE2X.js";import{c as Ut}from"./zustand-DAXCIHlT.js";import{i as ee,B as Ot,a as Rt,b as $t,u as U,t as P,T as Lt}from"./i18n-W-kxdzA-.js";(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))i(n);new MutationObserver(n=>{for(const o of n)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&i(c)}).observe(document,{childList:!0,subtree:!0});function s(n){const o={};return n.integrity&&(o.integrity=n.integrity),n.referrerPolicy&&(o.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?o.credentials="include":n.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function i(n){if(n.ep)return;n.ep=!0;const o=s(n);fetch(n.href,o)}})();var ye={},De=Ft;ye.createRoot=De.createRoot,ye.hydrateRoot=De.hydrateRoot;const ge=15,Mt=3;var ie={BASE_URL:"/phpCourse/exam/dist",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const ve=new Map,ae=t=>{const r=ve.get(t);return r?Object.fromEntries(Object.entries(r.stores).map(([s,i])=>[s,i.getState()])):{}},_t=(t,r,s)=>{if(t===void 0)return{type:"untracked",connection:r.connect(s)};const i=ve.get(s.name);if(i)return{type:"tracked",store:t,...i};const n={connection:r.connect(s),stores:{}};return ve.set(s.name,n),{type:"tracked",store:t,...n}},Nt=(t,r={})=>(s,i,n)=>{const{enabled:o,anonymousActionType:c,store:d,...p}=r;let g;try{g=(o??(ie?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(ie?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(s,i,n);const{connection:l,...a}=_t(d,g,p);let u=!0;n.setState=(m,y,C)=>{const f=s(m,y);if(!u)return f;const I=C===void 0?{type:c||"anonymous"}:typeof C=="string"?{type:C}:C;return d===void 0?(l==null||l.send(I,i()),f):(l==null||l.send({...I,type:`${d}/${I.type}`},{...ae(p.name),[d]:n.getState()}),f)};const h=(...m)=>{const y=u;u=!1,s(...m),u=y},x=t(n.setState,i,n);if(a.type==="untracked"?l==null||l.init(x):(a.stores[a.store]=n,l==null||l.init(Object.fromEntries(Object.entries(a.stores).map(([m,y])=>[m,m===a.store?x:y.getState()])))),n.dispatchFromDevtools&&typeof n.dispatch=="function"){let m=!1;const y=n.dispatch;n.dispatch=(...C)=>{(ie?"production":void 0)!=="production"&&C[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),y(...C)}}return l.subscribe(m=>{var y;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return je(m.payload,C=>{if(C.type==="__setState"){if(d===void 0){h(C.state);return}Object.keys(C.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 f=C.state[d];if(f==null)return;JSON.stringify(n.getState())!==JSON.stringify(f)&&h(f);return}n.dispatchFromDevtools&&typeof n.dispatch=="function"&&n.dispatch(C)});case"DISPATCH":switch(m.payload.type){case"RESET":return h(x),d===void 0?l==null?void 0:l.init(n.getState()):l==null?void 0:l.init(ae(p.name));case"COMMIT":if(d===void 0){l==null||l.init(n.getState());return}return l==null?void 0:l.init(ae(p.name));case"ROLLBACK":return je(m.state,C=>{if(d===void 0){h(C),l==null||l.init(n.getState());return}h(C[d]),l==null||l.init(ae(p.name))});case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return je(m.state,C=>{if(d===void 0){h(C);return}JSON.stringify(n.getState())!==JSON.stringify(C[d])&&h(C[d])});case"IMPORT_STATE":{const{nextLiftedState:C}=m.payload,f=(y=C.computedStates.slice(-1)[0])==null?void 0:y.state;if(!f)return;h(d===void 0?f:f[d]),l==null||l.send(null,C);return}case"PAUSE_RECORDING":return u=!u}return}}),x},qt=Nt,je=(t,r)=>{let s;try{s=JSON.parse(t)}catch(i){console.error("[zustand devtools middleware] Could not parse the received json",i)}s!==void 0&&r(s)};function zt(t,r){let s;try{s=t()}catch{return}return{getItem:n=>{var o;const c=p=>p===null?null:JSON.parse(p,void 0),d=(o=s.getItem(n))!=null?o:null;return d instanceof Promise?d.then(c):c(d)},setItem:(n,o)=>s.setItem(n,JSON.stringify(o,void 0)),removeItem:n=>s.removeItem(n)}}const te=t=>r=>{try{const s=t(r);return s instanceof Promise?s:{then(i){return te(i)(s)},catch(i){return this}}}catch(s){return{then(i){return this},catch(i){return te(i)(s)}}}},Bt=(t,r)=>(s,i,n)=>{let o={getStorage:()=>localStorage,serialize:JSON.stringify,deserialize:JSON.parse,partialize:y=>y,version:0,merge:(y,C)=>({...C,...y}),...r},c=!1;const d=new Set,p=new Set;let g;try{g=o.getStorage()}catch{}if(!g)return t((...y)=>{console.warn(`[zustand persist middleware] Unable to update item '${o.name}', the given storage is currently unavailable.`),s(...y)},i,n);const l=te(o.serialize),a=()=>{const y=o.partialize({...i()});let C;const f=l({state:y,version:o.version}).then(I=>g.setItem(o.name,I)).catch(I=>{C=I});if(C)throw C;return f},u=n.setState;n.setState=(y,C)=>{u(y,C),a()};const h=t((...y)=>{s(...y),a()},i,n);let x;const m=()=>{var y;if(!g)return;c=!1,d.forEach(f=>f(i()));const C=((y=o.onRehydrateStorage)==null?void 0:y.call(o,i()))||void 0;return te(g.getItem.bind(g))(o.name).then(f=>{if(f)return o.deserialize(f)}).then(f=>{if(f)if(typeof f.version=="number"&&f.version!==o.version){if(o.migrate)return o.migrate(f.state,f.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return f.state}).then(f=>{var I;return x=o.merge(f,(I=i())!=null?I:h),s(x,!0),a()}).then(()=>{C==null||C(x,void 0),c=!0,p.forEach(f=>f(x))}).catch(f=>{C==null||C(void 0,f)})};return n.persist={setOptions:y=>{o={...o,...y},y.getStorage&&(g=y.getStorage())},clearStorage:()=>{g==null||g.removeItem(o.name)},getOptions:()=>o,rehydrate:()=>m(),hasHydrated:()=>c,onHydrate:y=>(d.add(y),()=>{d.delete(y)}),onFinishHydration:y=>(p.add(y),()=>{p.delete(y)})},m(),x||h},Ht=(t,r)=>(s,i,n)=>{let o={storage:zt(()=>localStorage),partialize:m=>m,version:0,merge:(m,y)=>({...y,...m}),...r},c=!1;const d=new Set,p=new Set;let g=o.storage;if(!g)return t((...m)=>{console.warn(`[zustand persist middleware] Unable to update item '${o.name}', the given storage is currently unavailable.`),s(...m)},i,n);const l=()=>{const m=o.partialize({...i()});return g.setItem(o.name,{state:m,version:o.version})},a=n.setState;n.setState=(m,y)=>{a(m,y),l()};const u=t((...m)=>{s(...m),l()},i,n);n.getInitialState=()=>u;let h;const x=()=>{var m,y;if(!g)return;c=!1,d.forEach(f=>{var I;return f((I=i())!=null?I:u)});const C=((y=o.onRehydrateStorage)==null?void 0:y.call(o,(m=i())!=null?m:u))||void 0;return te(g.getItem.bind(g))(o.name).then(f=>{if(f)if(typeof f.version=="number"&&f.version!==o.version){if(o.migrate)return o.migrate(f.state,f.version);console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return f.state}).then(f=>{var I;return h=o.merge(f,(I=i())!=null?I:u),s(h,!0),l()}).then(()=>{C==null||C(h,void 0),h=i(),c=!0,p.forEach(f=>f(h))}).catch(f=>{C==null||C(void 0,f)})};return n.persist={setOptions:m=>{o={...o,...m},m.storage&&(g=m.storage)},clearStorage:()=>{g==null||g.removeItem(o.name)},getOptions:()=>o,rehydrate:()=>x(),hasHydrated:()=>c,onHydrate:m=>(d.add(m),()=>{d.delete(m)}),onFinishHydration:m=>(p.add(m),()=>{p.delete(m)})},o.skipHydration||x(),h||u},Wt=(t,r)=>"getStorage"in r||"serialize"in r||"deserialize"in r?((ie?"production":void 0)!=="production"&&console.warn("[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Use `storage` option instead."),Bt(t,r)):Ht(t,r),Kt=Wt,me=Ut()(qt(Kt(t=>({theme:void 0,currentSession:[void 0,void 0],setTheme:r=>t(()=>({theme:r})),setCurrentSession:r=>t(()=>({currentSession:r}))}),{name:"guestbook-storage"}))),N="https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/",ze=T.createContext({hasAuth:!1,currentSession:[void 0,void 0]}),D=()=>{const{hasAuth:t,authenticatedUser:r,currentSession:s,logIn:i,logOut:n,posts:o,newPost:c,updatePost:d,deletePost:p,user:g,createUser:l,confirmUser:a,updateUser:u,updateUserImage:h,userPosts:x}=T.useContext(ze);if(i&&n&&o&&c&&d&&p&&g&&l&&a&&u&&h&&x)return{hasAuth:t,authenticatedUser:r,currentSession:s,logIn:i,logOut:n,posts:o,newPost:c,updatePost:d,deletePost:p,user:g,createUser:l,confirmUser:a,updateUser:u,updateUserImage:h,userPosts:x};throw new Error("Couldn't find context. Is your component inside an ApiProvider?")},Qt=({children:t})=>{const[r,s]=T.useState(!1),[i,n]=T.useState(),[o,c]=me(v=>[v.currentSession,v.setCurrentSession]),d=T.useRef();T.useEffect(()=>{o[0]&&!d.current&&(d.current=o[0],ke())},[o]);const p=async(v,S)=>{const{user:b,token:E,refreshToken:ot}=await(await Ee("login",{email:v,password:S})).json();n(b),c([E,ot]),s(!0),d.current=E},g=async()=>{try{return d.current?await(await $(()=>xe("logout"))).json():!0}catch{return!1}finally{n(void 0),c([void 0,void 0]),s(!1),d.current=void 0}},l=async v=>{const S=`posts?p=${v??0}&l=${ge}`;return r?await(await $(()=>pe(S))).json():await(await nt(S)).json()},a=async v=>await(await $(()=>xe(`posts?l=${ge}`,v))).json(),u=async(v,S)=>await(await $(()=>Ie(`posts/${S}`,v))).json(),h=async v=>await(await $(()=>rt(`posts/${v}?l=${ge}`))).json(),x=async v=>await(await $(()=>pe(`users/${v??(i==null?void 0:i.id)}`))).json(),m=async v=>await(await Ee("register",v)).json(),y=async v=>await(await st("register",{code:v})).json(),C=async(v,S)=>{const b=await(await $(()=>Ie(`users/${S??"self"}`,v))).json();return n(b),b},f=async(v,S)=>{const b=new FormData;v.image&&b.append("image",v.image),!v.image&&v.predefined&&b.append("predefined",v.predefined);const E=await(await $(()=>tt(`users/${S??"self"}/image`,b))).json();return n(E),E},I=async v=>await(await $(()=>pe(`users/${v}/posts?l=${Mt}&s=desc`))).json(),Ee=async(v,S,b)=>{const E=await fetch(`${N}${v}`,{mode:"cors",method:"post",headers:b,body:JSON.stringify(S)});if(E.ok)return E;throw await E.json()},xe=async(v,S,b)=>{const E=await fetch(`${N}${v}`,{mode:"cors",method:"post",headers:{token:d.current??"",...b},body:JSON.stringify(S)});if(E.ok)return E;throw await E.json()},tt=async(v,S,b)=>{const E=await fetch(`${N}${v}`,{mode:"cors",method:"post",headers:{token:d.current??"",...b},body:S});if(E.ok)return E;throw await E.json()},nt=async(v,S)=>{const b=await fetch(`${N}${v}`,{mode:"cors",method:"get",headers:S});if(b.ok)return b;throw await b.json()},pe=async(v,S)=>{const b=await fetch(`${N}${v}`,{mode:"cors",method:"get",headers:{token:d.current??"",...S}});if(b.ok)return b;throw await b.json()},rt=async(v,S)=>{const b=await fetch(`${N}${v}`,{mode:"cors",method:"delete",headers:{token:d.current??"",...S}});if(b.ok)return b;throw await b.json()},st=async(v,S,b)=>{const E=await fetch(`${N}${v}`,{mode:"cors",method:"patch",headers:b,body:JSON.stringify(S)});if(E.ok)return E;throw await E.json()},Ie=async(v,S,b)=>{const E=await fetch(`${N}${v}`,{mode:"cors",method:"patch",headers:{token:d.current??"",...b},body:JSON.stringify(S)});if(E.ok)return E;throw await E.json()},$=async v=>{try{return console.log("[REAUTH] fetching"),await v()}catch{try{return console.log("[REAUTH] fail, refreshing"),await ke(),console.log("[REAUTH] refreshed, fetching again"),await v()}catch(S){throw console.log("[REAUTH] terminating session",S),n(void 0),s(!1),c([void 0,void 0]),d.current=void 0,S}}},ke=async()=>{const{user:v,token:S,refreshToken:b}=await(await xe("refresh",{refreshToken:o[1]??"INVALID DEFAULT"})).json();n(v),c([S,b]),s(!0),d.current=S};return e.jsx(ze.Provider,{value:{hasAuth:r,authenticatedUser:i,currentSession:o,logIn:p,logOut:g,posts:l,newPost:a,updatePost:u,deletePost:h,user:x,createUser:m,confirmUser:y,updateUser:C,updateUserImage:f,userPosts:I},children:t})};ee.use(Ot).use(Rt).use($t).init({fallbackLng:"en",debug:!1,interpolation:{escapeValue:!1},backend:{loadPath:"/phpCourse/exam/dist/locales/{{lng}}/{{ns}}.json"}});const Be=()=>e.jsx(k,{sx:{marginTop:2,display:"flex",justifyContent:"center"},children:e.jsx(k,{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(ue,{})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(w,{variant:"caption",children:"© 2024 Kilian Kurt Hofmann"})})]})})}),Te=({children:t})=>e.jsxs(e.Fragment,{children:[e.jsx(k,{sx:{flexGrow:1}}),e.jsx(k,{sx:{display:"flex",justifyContent:"center"},children:e.jsx(k,{sx:{maxWidth:"800px",flexGrow:1},children:t})}),e.jsx(k,{sx:{flexGrow:1}}),e.jsx(Be,{})]});var O=(t=>(t.INDEX="/",t.PROFILE="/profile",t.CONFIRM="/confirm",t))(O||{}),F=(t=>(t.NOT_FOUND="NotFound",t.UNAUTHORIZED="Unauthorized",t.NOT_ALLOWED="NotAllowed",t.FAILED_UPDATE="FailedUpdate",t.MISSING_FIELD="MissingField",t.DUPLICATE="Duplicate",t))(F||{});const Jt=({error:t})=>{const{t:r}=U(),s=Se(),i=Z(),n=wt();return T.useEffect(()=>{console.log(n.isReset()),n.reset()},[n]),e.jsx(Te,{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(at,{sx:{fontSize:"200px"}})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(w,{variant:"h4",sx:{textAlign:"center"},children:r("code"in t&&t.code===F.UNAUTHORIZED?"Session expired":"General error")})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(L,{variant:"h6",underline:"none",onClick:()=>{console.log("CLICK AS WELL"),s.invalidate(),i({to:O.INDEX})},children:r("Back to main")})})]})})},Gt=()=>{const{t}=U();return e.jsx(Te,{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(w,{variant:"404",children:"404"})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(w,{variant:"h4",sx:{textAlign:"center"},children:t("Page not found")})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(L,{component:q,to:"/",variant:"h6",underline:"none",children:t("Back to main")})})]})})},Xt=()=>e.jsxs(k,{sx:{minHeight:"100vh",display:"flex",flexDirection:"column"},children:[e.jsx(Tt,{}),!1]}),oe=bt()({component:Xt,notFoundComponent:Gt,errorComponent:Jt}),H=({error:t,context:r,color:s="error.main"})=>{const{t:i}=U();if(!t)return null;if(t.code)switch(t.code){case F.NOT_FOUND:return e.jsx(w,{color:s,children:i(t.code,{context:`${t.entity}:${r}`})});case F.NOT_ALLOWED:case F.UNAUTHORIZED:return e.jsx(w,{color:s,children:i(t.code,{context:r})});case F.FAILED_UPDATE:return t.fields.map((n,o)=>e.jsx(w,{color:s,children:i(t.code,{context:`${t.reasons[o]}:${n}:${r}`})},`error_${n}`));case F.MISSING_FIELD:return t.fields.map(n=>e.jsx(w,{color:s,children:i(t.code,{context:`${n}:${r}`})},`error_${n}`));case F.DUPLICATE:return e.jsx(w,{color:s,children:i(t.code,{context:`${t.entity}:${r}`})})}return e.jsx(w,{color:s,children:i((t==null?void 0:t.message)??"Unknown",{context:r})})},Zt=()=>{const[t,r]=T.useState(),[s,i]=T.useState(0),{t:n}=U(),o=V(),c=Z(),d=D(),p=B({mutationFn:({data:l})=>d.newPost(l)}),g=Y({defaultValues:{content:""},onSubmit:async({value:l})=>{try{p.mutate({data:l},{onSuccess:async a=>{g.reset(),i(0),await o.invalidateQueries({queryKey:["posts"]}),c({to:"/",search:{page:a.pages-1}})},onError:r})}catch(a){r(a)}}});return e.jsx("form",{onSubmit:l=>{l.preventDefault(),l.stopPropagation(),g.handleSubmit()},onKeyDown:l=>{l.key==="Tab"&&l.stopPropagation()},noValidate:!0,children:e.jsxs(k,{sx:{display:"grid",gap:2,padding:1},children:[e.jsx(g.Field,{name:"content",validators:{onChange:({value:l})=>l?void 0:n("Content required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:l})=>!l&&n("Content required")},children:l=>e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"outlined",multiline:!0,minRows:3,name:l.name,value:l.state.value,onBlur:l.handleBlur,onChange:a=>{a.target.value.length<=250&&(i(a.target.value.length),l.handleChange(a.target.value))},size:"small",label:n("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(Ue,{variant:"determinate",value:s/250*100,color:s===250?"error":s>=200?"warning":"primary"})]})}),e.jsx(g.Subscribe,{selector:l=>[l.canSubmit,l.isSubmitting],children:([l])=>e.jsx(e.Fragment,{children:e.jsx(A,{type:"submit",disabled:!l||p.isPending,variant:"contained",endIcon:p.isPending&&e.jsx(z,{color:"inherit",size:"20px"}),children:n("Post comment")})})}),e.jsx(J,{open:p.isError,autoHideDuration:2e3,onClose:()=>{p.reset()},TransitionProps:{onExited:()=>r(void 0)},children:e.jsx(Oe,{severity:"error",variant:"filled",sx:{width:"100%"},children:t&&e.jsx(H,{error:t,context:"newPost",color:"white"})})})]})})},Vt=({anchorEl:t,handleClose:r})=>e.jsxs(Ce,{anchorEl:t,anchorOrigin:{vertical:"bottom",horizontal:"right"},keepMounted:!0,transformOrigin:{vertical:"top",horizontal:"right"},open:!!t,onClose:r,sx:{"& .MuiMenu-paper":{minWidth:"240px"}},children:[e.jsx(M,{selected:ee.language==="en",onClick:()=>{ee.changeLanguage("en"),r()},children:"English"},"de"),e.jsx(M,{selected:ee.language==="de",onClick:()=>{ee.changeLanguage("de"),r()},children:"Deutsch"},"en")]}),Yt=({anchorEl:t,handleClose:r})=>{const[s,i]=me(o=>[o.theme,o.setTheme]),{t:n}=U();return e.jsxs(Ce,{anchorEl:t,anchorOrigin:{vertical:"bottom",horizontal:"right"},keepMounted:!0,transformOrigin:{vertical:"top",horizontal:"right"},open:!!t,onClose:r,sx:{"& .MuiMenu-paper":{minWidth:"240px"}},children:[e.jsx(M,{selected:s==="dark",onClick:()=>{i("dark")},children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:2,children:e.jsx(Re,{})}),e.jsx(j,{item:!0,xs:10,children:e.jsx(w,{children:n("Dark")})})]})},"dark"),e.jsx(M,{selected:s==="light",onClick:()=>{i("light")},children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:2,children:e.jsx($e,{})}),e.jsx(j,{item:!0,xs:10,children:e.jsx(w,{children:n("Light")})})]})},"light"),e.jsx(M,{selected:!s,onClick:()=>{i(void 0)},children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:2,children:e.jsx(Le,{})}),e.jsx(j,{item:!0,xs:10,children:e.jsx(w,{children:n("System")})})]})},"system")]})},en=({open:t,onClose:r})=>{const[s,i]=T.useState(),{t:n}=U(),o=ne(),c=X(o.breakpoints.only("xs"),{noSsr:!0}),d=D(),p=B({mutationFn:({data:a})=>d.createUser(a)}),g=Y({defaultValues:{username:"",email:"",password:""},onSubmit:async({value:a})=>{try{p.mutate({data:a},{onSuccess:()=>i(void 0),onError:i})}catch(u){i(u)}}}),l=()=>{g.reset(),i(void 0),r()};return p.isSuccess?e.jsxs(G,{open:t,onClose:l,fullWidth:!0,fullScreen:c,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(Me,{color:"action",sx:{fontSize:"200px"}})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(w,{variant:"h5",children:n("Confirm header")})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(w,{children:n("Confirm mail")})})]})}),e.jsx(re,{children:e.jsx(A,{onClick:l,children:n("Close")})})]}):e.jsxs(G,{open:t,onClose:l,fullWidth:!0,fullScreen:c,PaperProps:{component:"form",encType:"multipart/form-data",onSubmit:a=>{a.preventDefault(),a.stopPropagation(),g.handleSubmit()},onKeyDown:a=>{a.key==="Tab"&&a.stopPropagation()},noValidate:!0},children:[e.jsx(se,{children:n("Register")}),e.jsx(_,{sx:{gap:2},children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,xs:12,children:e.jsx(g.Field,{name:"username",validators:{onChange:({value:a})=>a?void 0:n("Username required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:a})=>!a&&n("Username required")},children:a=>e.jsx(e.Fragment,{children:e.jsx(R,{variant:"outlined",name:a.name,value:a.state.value,onBlur:a.handleBlur,onChange:u=>a.handleChange(u.target.value),size:"small",label:n("Username"),required:!0,error:a.state.meta.isTouched&&a.state.meta.errors.length>0,helperText:a.state.meta.isTouched?a.state.meta.errors.join(","):"",autoComplete:"new-username",fullWidth:!0,margin:"dense"})})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(g.Field,{name:"email",validators:{onChange:({value:a})=>a?void 0:n("Email required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:a})=>!a&&n("Email required")},children:a=>e.jsx(e.Fragment,{children:e.jsx(R,{variant:"outlined",name:a.name,value:a.state.value,onBlur:a.handleBlur,onChange:u=>a.handleChange(u.target.value),size:"small",label:n("Email"),required:!0,error:a.state.meta.isTouched&&a.state.meta.errors.length>0,helperText:a.state.meta.isTouched?a.state.meta.errors.join(","):"",type:"email",autoComplete:"new-email",inputMode:"email",fullWidth:!0})})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(g.Field,{name:"password",validators:{onChange:({value:a})=>a?void 0:n("Password required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:a})=>!a&&n("Password required")},children:a=>e.jsx(e.Fragment,{children:e.jsx(R,{variant:"outlined",name:a.name,value:a.state.value,onBlur:a.handleBlur,onChange:u=>a.handleChange(u.target.value),size:"small",label:n("Password"),required:!0,error:a.state.meta.isTouched&&a.state.meta.errors.length>0,helperText:a.state.meta.isTouched?a.state.meta.errors.join(","):"",type:"password",autoComplete:"new-password",fullWidth:!0})})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(g.Subscribe,{selector:a=>[a.canSubmit,a.isSubmitting],children:([a])=>e.jsx(e.Fragment,{children:e.jsx(A,{type:"submit",disabled:!a||p.isPending,variant:"contained",endIcon:p.isPending&&e.jsx(z,{color:"inherit",size:"20px"}),children:n("Register")})})})}),e.jsx(j,{item:!0,xs:12,children:s&&e.jsx(H,{error:s,context:"register"})})]})})]})},tn=()=>{const[t,r]=T.useState(),{t:s}=U(),i=Se(),n=D(),o=Y({defaultValues:{email:"",password:""},onSubmit:async({value:c})=>{try{await n.logIn(c.email,c.password),i.invalidate()}catch(d){r(d)}}});return e.jsx("form",{onSubmit:c=>{c.preventDefault(),c.stopPropagation(),o.handleSubmit()},onKeyDown:c=>{c.key==="Tab"&&c.stopPropagation()},noValidate:!0,children:e.jsxs(k,{sx:{display:"grid",gap:2,padding:1},children:[e.jsx(o.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(R,{variant:"outlined",name:c.name,value:c.state.value,onBlur:c.handleBlur,onChange:d=>c.handleChange(d.target.value),size:"small",label:s("Email"),required:!0,error:c.state.meta.isTouched&&c.state.meta.errors.length>0,helperText:c.state.meta.isTouched?c.state.meta.errors.join(","):"",type:"email",autoComplete:"email",inputMode:"email",fullWidth:!0})})}),e.jsx(o.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(R,{variant:"outlined",name:c.name,value:c.state.value,onBlur:c.handleBlur,onChange:d=>c.handleChange(d.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:"current-password",fullWidth:!0})})}),e.jsx(o.Subscribe,{selector:c=>[c.canSubmit,c.isSubmitting],children:([c])=>e.jsx(e.Fragment,{children:e.jsx(A,{type:"submit",disabled:!c,variant:"contained",children:s("Log in")})})}),t&&e.jsx(H,{error:t,context:"login"})]})})},nn=({anchorEl:t,handleClose:r})=>{const[s,i]=T.useState(!1),n=Z(),o=Se(),c=Pt({from:"/profile/",strict:!0,shouldThrow:!1}),d=D(),p=()=>{i(!1),r()};return e.jsx(Ce,{anchorEl:t,anchorOrigin:{vertical:"bottom",horizontal:"right"},keepMounted:!0,transformOrigin:{vertical:"top",horizontal:"right"},open:!!t,onClose:p,sx:{"& .MuiMenu-paper":{minWidth:"240px"}},children:d.authenticatedUser?[e.jsx(M,{selected:!!c,onClick:()=>{n({to:O.PROFILE}),p()},children:P("Profile")},"profile"),e.jsx(M,{onClick:async()=>{await d.logOut(),o.invalidate(),n({to:O.INDEX})},children:P("Log out")},"logout")]:s?e.jsx(en,{open:s,onClose:()=>i(!1)}):e.jsxs(k,{children:[e.jsx(tn,{}),e.jsx(k,{sx:{padding:1},children:e.jsxs(Lt,{i18nKey:"Register prompt",children:[e.jsx(w,{component:"span"}),e.jsx(L,{sx:{cursor:"pointer"},variant:"body1",underline:"hover",color:"secondary.main",onClick:()=>{i(!0),r()}}),e.jsx(w,{component:"span"})]})})]})})},rn=({children:t})=>{const r=ut({disableHysteresis:!0,threshold:0});return T.cloneElement(t,{elevation:r?4:0})},sn=()=>{const[t,r]=T.useState(null),[s,i]=T.useState(null),[n,o]=T.useState(null),{t:c}=U(),d=Et({select:a=>a.status==="pending"}),p=D(),[g]=me(a=>[a.theme,a.setTheme]),l=()=>{r(null),i(null),o(null)};return e.jsx(rn,{children:e.jsxs(e.Fragment,{children:[e.jsx(it,{children:e.jsxs(Ae,{children:[e.jsxs(k,{sx:{flexGrow:1,alignItems:"center",display:"flex",gap:1},children:[e.jsx(L,{component:q,to:"/",color:"white",variant:"h6",underline:"none",children:c("GuestBook")}),d&&e.jsx(z,{size:16,thickness:10,sx:{color:"white"}})]}),e.jsxs(k,{sx:{display:"flex",gap:1},children:[e.jsx(W,{size:"large",onClick:a=>i(a.currentTarget),children:e.jsx(ct,{sx:{color:"white"}})}),e.jsxs(W,{size:"large",onClick:a=>o(a.currentTarget),children:[g==="dark"&&e.jsx(Re,{}),g==="light"&&e.jsx($e,{sx:{color:"white"}}),!g&&e.jsx(Le,{sx:{color:"white"}})]}),p.authenticatedUser?e.jsx(W,{onClick:a=>r(a.currentTarget),sx:{p:0},children:e.jsx(K,{alt:p.authenticatedUser.username,src:`${p.authenticatedUser.image}`,children:e.jsx(Q,{})})}):e.jsx(W,{size:"large",onClick:a=>r(a.currentTarget),color:"inherit",children:e.jsx(lt,{})})]}),e.jsx(Vt,{anchorEl:s,handleClose:l}),e.jsx(nn,{anchorEl:t,handleClose:l}),e.jsx(Yt,{anchorEl:n,handleClose:l})]})}),e.jsx(Ae,{})]})})},Pe=({children:t})=>e.jsxs(e.Fragment,{children:[e.jsx(sn,{}),e.jsx(k,{sx:{display:"flex",justifyContent:"center"},children:e.jsx(k,{sx:{maxWidth:"800px",flexGrow:1},children:t})}),e.jsx(k,{sx:{flexGrow:1}}),e.jsx(Be,{})]}),He=t=>new Date(t.date).toLocaleString(navigator.languages[0]??"de-DE",{timeZone:t.timezone,day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",hour12:!1,minute:"2-digit"}),on=({post:t,open:r,onClose:s})=>{const[i,n]=T.useState(),[o,c]=T.useState(t.content.length),d=ne(),p=X(d.breakpoints.only("xs"),{noSsr:!0}),g=V(),l=D(),a=B({mutationFn:({data:x,id:m})=>l.updatePost(x,m)}),u=Y({defaultValues:{content:t.content.replaceAll("<br />","")},onSubmit:async({value:x})=>{try{a.mutate({data:x,id:t.id},{onSuccess:()=>{h(),g.invalidateQueries({queryKey:["posts"]})},onError:n})}catch(m){n(m)}}}),h=()=>{u.reset(),n(void 0),s()};return e.jsxs(G,{open:r,onClose:h,fullWidth:!0,fullScreen:p,PaperProps:{component:"form",onSubmit:x=>{x.preventDefault(),x.stopPropagation(),u.handleSubmit()},onKeyDown:x=>{x.key==="Tab"&&x.stopPropagation()},noValidate:!0},children:[e.jsx(se,{children:P("Edit post")}),e.jsx(_,{children:e.jsx(u.Field,{name:"content",validators:{onChange:({value:x})=>x?void 0:P("Content required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:x})=>!x&&P("Content required")},children:x=>e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"outlined",multiline:!0,minRows:3,name:x.name,value:x.state.value,onBlur:x.handleBlur,onChange:m=>{m.target.value.length<=250&&(c(m.target.value.length),x.handleChange(m.target.value))},size:"small",label:P("Comment"),required:!0,error:x.state.meta.isTouched&&x.state.meta.errors.length>0,helperText:x.state.meta.isTouched?x.state.meta.errors.join(","):"",autoComplete:"off",margin:"dense",fullWidth:!0}),e.jsx(Ue,{variant:"determinate",value:o/250*100,color:o===250?"error":o>=200?"warning":"primary"})]})})}),e.jsx(re,{children:e.jsx(u.Subscribe,{selector:x=>[x.canSubmit,x.isSubmitting],children:([x])=>e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"outlined",onClick:()=>{h()},children:P("Cancel")}),e.jsx(A,{type:"submit",disabled:!x||a.isPending,autoFocus:!0,variant:"contained",endIcon:a.isPending&&e.jsx(z,{color:"inherit",size:"20px"}),children:P("Save")})]})})}),i&&e.jsx(_,{children:e.jsx(H,{error:i,context:"postUpdate"})})]})},We=({page:t=0,post:r,disableActions:s})=>{var x,m,y,C,f;const[i,n]=T.useState(!1),[o,c]=T.useState(!1),[d,p]=T.useState(),{t:g}=U(),l=V(),a=Z(),u=D(),h=B({mutationFn:I=>u.deletePost(I)});return e.jsxs(_e,{children:[e.jsx(dt,{avatar:!s&&"id"in r.user?r.user.id!==((x=u.authenticatedUser)==null?void 0:x.id)?e.jsx(L,{component:q,to:"/profile/$id",params:{id:r.user.id},children:e.jsx(K,{alt:r.user.username,src:`${r.user.image}`,children:e.jsx(Q,{})})}):e.jsx(L,{component:q,to:"/profile",children:e.jsx(K,{alt:r.user.username,src:`${r.user.image}`,children:e.jsx(Q,{})})}):e.jsx(K,{alt:r.user.username,src:`${r.user.image}`,children:e.jsx(Q,{})}),title:!s&&"id"in r.user?r.user.id!==((m=u.authenticatedUser)==null?void 0:m.id)?e.jsx(L,{component:q,to:"/profile/$id",params:{id:r.user.id},children:r.user.username}):e.jsx(L,{component:q,to:"/profile",children:r.user.username}):r.user.username,subheader:He(r.postedAt)}),e.jsx(Ne,{children:e.jsx(w,{children:e.jsx("span",{dangerouslySetInnerHTML:{__html:r.content}})})}),e.jsxs(qe,{children:[!s&&(((y=u.authenticatedUser)==null?void 0:y.isAdmin)||"id"in r.user&&r.user.id===((C=u.authenticatedUser)==null?void 0:C.id))&&e.jsxs(e.Fragment,{children:[e.jsx(A,{size:"small",onClick:()=>c(!0),children:g("Edit")}),e.jsx(on,{post:r,open:o,onClose:()=>c(!1)})]}),!s&&((f=u.authenticatedUser)==null?void 0:f.isAdmin)&&e.jsxs(e.Fragment,{children:[e.jsx(A,{size:"small",color:"error",onClick:()=>n(!0),children:g("Delete")}),e.jsxs(G,{open:i,onClose:()=>n(!1),children:[e.jsx(se,{children:g("Confirm post delete title")}),e.jsx(_,{children:e.jsx(ht,{children:g("Confirm post delete body",{name:r.user.username})})}),e.jsxs(re,{children:[e.jsx(A,{onClick:()=>n(!1),autoFocus:!0,variant:"contained",children:g("No")}),e.jsx(A,{variant:"outlined",color:"error",onClick:()=>{h.mutate(r.id,{onSuccess:async I=>{await l.invalidateQueries({queryKey:["posts"]}),t>=I.pages&&a({to:"/",search:{page:I.pages-1}})},onError:p}),n(!1)},children:g("Yes")})]})]})]})]}),e.jsx(J,{open:h.isError,autoHideDuration:2e3,onClose:()=>{h.reset()},TransitionProps:{onExited:()=>p(void 0)},children:e.jsx(Oe,{severity:"error",variant:"filled",sx:{width:"100%"},children:d&&e.jsx(H,{error:d,context:"deletePost",color:"white"})})}),e.jsx(J,{open:h.isPending,message:g("Deleting")})]})},Ke=(t,r)=>we({queryKey:["posts",{page:r??0,hasAuth:t.hasAuth}],queryFn:async()=>await t.posts(r)}),an=()=>{const t=D(),{page:r}=Qe.useSearch(),{data:s,isFetching:i}=be(Ke(t,r)),{t:n}=U(),o=Z(),c=ne(),d=X(c.breakpoints.not("xs"),{noSsr:!0});return T.useEffect(()=>{(r??0)>=s.pages&&o({to:"/",search:{page:s.pages-1}})},[r]),e.jsxs(Pe,{children:[e.jsx(J,{open:i,message:n("Updating")}),e.jsxs(j,{container:!0,spacing:2,sx:{marginTop:0},children:[s.data.map(p=>e.jsx(j,{item:!0,xs:12,children:e.jsx(We,{page:r,post:p})},p.id)),e.jsx(j,{item:!0,xs:12,children:e.jsx(ue,{variant:"middle"})}),e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(mt,{page:(r??0)+1,count:s.pages,siblingCount:d?1:0,color:"primary",renderItem:p=>e.jsx(xt,{...p,component:q,to:"/",search:{page:(p.page??0)>0?(p.page??1)-1:void 0},onClick:g=>p.onClick(g)})})}),t.hasAuth?e.jsx(j,{item:!0,xs:12,children:e.jsx(Zt,{})}):e.jsxs(j,{item:!0,xs:12,children:[e.jsx(w,{variant:"h5",children:n("Leave comment header")}),e.jsx(w,{children:n("Leave comment action")})]})]})]})},Qe=he(O.INDEX)({loaderDeps:({search:{page:t}})=>({page:t}),loader:({context:{queryClient:t,Api:r},deps:{page:s}})=>t.ensureQueryData(Ke(r,s)),validateSearch:t=>({page:(t==null?void 0:t.page)!==void 0?Number((t==null?void 0:t.page)??0):void 0}),component:an}),cn=({user:t,open:r,onClose:s})=>{const[i,n]=T.useState(),o=ne(),c=X(o.breakpoints.only("xs"),{noSsr:!0}),d=V(),p=D(),g=B({mutationFn:({data:u,id:h})=>p.updateUser(u,h)}),l=Y({defaultValues:{username:t.username,email:t.email},onSubmit:async({value:u})=>{var h;try{g.mutate({data:u,id:((h=p.authenticatedUser)==null?void 0:h.id)===t.id?void 0:t.id},{onSuccess:()=>{var m;a();const x=((m=p.authenticatedUser)==null?void 0:m.id)===t.id?["profile"]:["profile",{id:t.id}];d.invalidateQueries({queryKey:x})},onError:n})}catch(x){n(x)}}}),a=()=>{l.reset(),n(void 0),s()};return e.jsxs(G,{open:r,onClose:a,fullWidth:!0,fullScreen:c,PaperProps:{component:"form",onSubmit:u=>{u.preventDefault(),u.stopPropagation(),l.handleSubmit()},onKeyDown:u=>{u.key==="Tab"&&u.stopPropagation()},noValidate:!0},children:[e.jsx(se,{children:P("Edit data")}),e.jsxs(_,{children:[e.jsx(l.Field,{name:"username",validators:{onChange:({value:u})=>u?void 0:P("Username required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:u})=>!u&&P("Username required")},children:u=>e.jsx(e.Fragment,{children:e.jsx(R,{name:u.name,value:u.state.value,onBlur:u.handleBlur,onChange:h=>u.handleChange(h.target.value),size:"small",label:P("Username"),required:!0,margin:"dense",autoComplete:"new-username",fullWidth:!0,error:u.state.meta.isTouched&&u.state.meta.errors.length>0,helperText:u.state.meta.isTouched?u.state.meta.errors.join(","):""})})}),e.jsx(l.Field,{name:"email",validators:{onChange:({value:u})=>u?void 0:P("Email required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:u})=>!u&&P("Email required")},children:u=>e.jsx(e.Fragment,{children:e.jsx(R,{name:u.name,value:u.state.value,onBlur:u.handleBlur,onChange:h=>u.handleChange(h.target.value),size:"small",label:P("Email"),required:!0,margin:"dense",autoComplete:"new-email",fullWidth:!0,error:u.state.meta.isTouched&&u.state.meta.errors.length>0,helperText:u.state.meta.isTouched?u.state.meta.errors.join(","):""})})})]}),e.jsx(re,{children:e.jsx(l.Subscribe,{selector:u=>[u.canSubmit,u.isSubmitting],children:([u])=>e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"outlined",onClick:()=>{a()},children:P("Cancel")}),e.jsx(A,{type:"submit",disabled:!u||g.isPending,autoFocus:!0,variant:"contained",endIcon:g.isPending&&e.jsx(z,{color:"inherit",size:"20px"}),children:P("Save")})]})})}),i&&e.jsx(_,{children:e.jsx(H,{error:i,context:"userUpdate"})})]})},ln=({user:t,open:r,onClose:s})=>{const[i,n]=T.useState(),o=ne(),c=X(o.breakpoints.only("xs"),{noSsr:!0}),d=V(),p=D(),g=B({mutationFn:({data:h,id:x})=>p.updateUserImage(h,x)}),l=Y({onSubmit:async({value:h})=>{var x;try{g.mutate({data:h,id:((x=p.authenticatedUser)==null?void 0:x.id)===t.id?void 0:t.id},{onSuccess:()=>{var y;u();const m=((y=p.authenticatedUser)==null?void 0:y.id)===t.id?["profile"]:["profile",{id:t.id}];d.invalidateQueries({queryKey:m})},onError:n})}catch(m){n(m)}}}),a=l.useStore(h=>({image:h.values.image,predefined:h.values.predefined})),u=()=>{l.reset(),n(void 0),s()};return e.jsxs(G,{open:r,onClose:u,fullWidth:!0,fullScreen:c,PaperProps:{component:"form",encType:"multipart/form-data",onSubmit:h=>{h.preventDefault(),h.stopPropagation(),l.handleSubmit()},onKeyDown:h=>{h.key==="Tab"&&h.stopPropagation()},noValidate:!0},children:[e.jsx(se,{children:P("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(K,{alt:t.username,src:a.image?URL.createObjectURL(a.image):a.predefined?`storage/profilbilder/default/${a.predefined}.svg`:`${t.image}`,sx:{width:"100px",height:"100px"},children:e.jsx(Q,{sx:{width:"60px",height:"60px"}})})}),e.jsx(j,{item:!0,xs:12,children:e.jsxs(k,{sx:{display:"flex",gap:2},children:[e.jsx(A,{component:"label",role:void 0,variant:"contained",tabIndex:-1,startIcon:e.jsx(pt,{}),fullWidth:!0,children:e.jsx(l.Field,{name:"image",children:h=>{var x;return e.jsxs(e.Fragment,{children:[e.jsx(k,{sx:{textOverflow:"ellipsis",textWrap:"nowrap",overflow:"hidden"},children:h.state.value?P("Upload named",{name:(x=h.state.value)==null?void 0:x.name}):P("Upload image")}),e.jsx(R,{name:h.name,onBlur:h.handleBlur,value:h.state.value?void 0:"",onChange:m=>h.handleChange(m.target.files[0]),size:"small",type:"file",required:!0,sx:{display:"none"},autoComplete:"off"})]})}})}),e.jsx(W,{color:"error",onClick:()=>l.setFieldValue("image",void 0),children:e.jsx(gt,{})})]})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(ue,{variant:"middle",children:e.jsx(w,{sx:{opacity:.36},children:P("or")})})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(l.Field,{name:"predefined",children:h=>e.jsxs(jt,{fullWidth:!0,children:[e.jsx(ft,{size:"small",children:P("Predefined")}),e.jsxs(yt,{name:h.name,value:h.state.value??"",onBlur:h.handleBlur,onChange:x=>h.handleChange(x.target.value),size:"small",label:P("Predefined"),autoComplete:"off",fullWidth:!0,children:[e.jsx(M,{value:"",selected:!0,children:"Keine Auswahl"}),[...Array(10).keys()].map(x=>e.jsx(M,{value:`avatar-${x+1}`,children:P("Avatar",{name:x+1})},`avatar-${x+1}`))]})]})})})]})}),e.jsx(re,{children:e.jsx(l.Subscribe,{selector:h=>[h.canSubmit,h.isSubmitting],children:([h])=>e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"outlined",onClick:()=>{u()},children:P("Cancel")}),e.jsx(A,{type:"submit",disabled:!h||g.isPending,autoFocus:!0,variant:"contained",endIcon:g.isPending&&e.jsx(z,{color:"inherit",size:"20px"}),children:P("Save")})]})})}),i&&e.jsx(_,{children:e.jsx(H,{error:i,context:"userUpdate"})})]})},Je=({user:t,posts:r,canEdit:s})=>{const[i,n]=T.useState(!1),[o,c]=T.useState(!1),{t:d}=U();return e.jsxs(j,{container:!0,sx:{justifyContent:"center",marginTop:0},spacing:2,children:[e.jsx(j,{item:!0,children:e.jsxs(_e,{children:[e.jsx(Ne,{children:e.jsxs(j,{container:!0,spacing:2,children:[e.jsx(j,{item:!0,sx:{display:"flex",flexGrow:1,justifyContent:"center"},children:e.jsx(W,{onClick:()=>c(!0),children:e.jsx(K,{alt:t.username,src:`${t.image}`,sx:{width:"100px",height:"100px"},children:e.jsx(Q,{sx:{width:"60px",height:"60px"}})})})}),e.jsx(j,{item:!0,sx:{display:"flex",alignItems:"center"},children:e.jsxs(k,{sx:{display:"grid",gridTemplateColumns:"120px 1fr",columnGap:1},children:[e.jsxs(w,{fontWeight:"bold",children:[d("Username"),":"]}),e.jsx(w,{children:t.username}),e.jsxs(w,{fontWeight:"bold",children:[d("Email"),":"]}),e.jsx(w,{children:t.email}),e.jsxs(w,{fontWeight:"bold",children:[d("Member since"),":"]}),e.jsx(w,{children:He(t.memberSince)}),e.jsxs(w,{fontWeight:"bold",children:[d("Post count"),":"]}),e.jsx(w,{children:t.postCount})]})})]})}),e.jsx(qe,{children:s&&e.jsxs(e.Fragment,{children:[e.jsx(A,{size:"small",onClick:()=>n(!0),children:d("Edit")}),e.jsx(cn,{user:t,open:i,onClose:()=>n(!1)}),e.jsx(ln,{user:t,open:o,onClose:()=>c(!1)})]})})]})}),e.jsx(j,{item:!0,xs:12,children:e.jsx(ue,{variant:"middle",children:e.jsx(w,{sx:{opacity:.36},children:d("Recent posts")})})}),r.map(p=>e.jsx(j,{item:!0,xs:12,children:e.jsx(We,{post:p,disableActions:!0})},`post_${p.id}`))]})},Ge=t=>{var r;return we({queryKey:["profile",{id:(r=t.authenticatedUser)==null?void 0:r.id}],queryFn:async()=>{var s;return{user:await t.user(),posts:await t.userPosts(((s=t.authenticatedUser)==null?void 0:s.id)??0)}}})},Xe=(t,r)=>we({queryKey:["profile",{id:r}],queryFn:async()=>({user:await t.user(r),posts:await t.userPosts(r)})}),un=()=>{const t=D(),{data:{user:r,posts:s},isFetching:i,error:n,failureReason:o}=be(Ge(t));if(o&&"code"in o&&o.code===F.UNAUTHORIZED)throw o;if(n&&"code"in n&&n.code===F.UNAUTHORIZED)throw n;return e.jsxs(Pe,{children:[e.jsx(J,{open:i,message:P("Updating")}),e.jsx(Je,{user:r,posts:s.data,canEdit:!0})]})},dn=he(`${O.PROFILE}/`)({loader:({context:{queryClient:t,Api:r}})=>{t.ensureQueryData(Ge(r))},beforeLoad:({context:{Api:t}})=>{if(!t.hasAuth)throw fe({to:O.INDEX})},component:un}),hn=()=>{const t=D(),{code:r}=Ze.useSearch(),{t:s}=U(),i=Z(),n=B({mutationFn:({code:o})=>t.confirmUser(o)});return T.useEffect(()=>{r&&setTimeout(()=>n.mutate({code:r}),1e3)},[]),T.useEffect(()=>{r||i({to:"/"})},[r]),e.jsx(Te,{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:[n.isSuccess&&e.jsx(Me,{color:"action",sx:{fontSize:"200px"}}),n.isError&&e.jsx(vt,{color:"action",sx:{fontSize:"200px"}}),(n.isPending||n.isIdle)&&e.jsx(z,{size:200})]}),e.jsxs(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:[n.isSuccess&&e.jsx(w,{variant:"h5",children:s("Confirm success header")}),n.isError&&e.jsx(w,{variant:"h5",color:"error",children:s("Confirm error header")}),(n.isPending||n.isIdle)&&e.jsx(w,{variant:"h5",children:s("Confirm pending header")})]}),!n.isPending&&!n.isIdle&&e.jsx(j,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(L,{component:q,to:"/",variant:"h6",underline:"none",children:s("Back to main")})})]})})},Ze=he(`${O.CONFIRM}/`)({validateSearch:t=>({code:(t==null?void 0:t.code)!==void 0?t==null?void 0:t.code:void 0}),component:hn}),mn=()=>{var d;const t=D(),{id:r}=Ve.useParams(),{data:{user:s,posts:i},isFetching:n,error:o,failureReason:c}=be(Xe(t,r));if(c&&"code"in c&&c.code===F.UNAUTHORIZED)throw c;if(o&&"code"in o&&o.code===F.UNAUTHORIZED)throw o;return e.jsxs(Pe,{children:[e.jsx(J,{open:n,message:P("Updating")}),e.jsx(Je,{user:s,posts:i.data,canEdit:(d=t.authenticatedUser)==null?void 0:d.isAdmin})]})},Ve=he(`${O.PROFILE}/$id`)({params:{parse:({id:t})=>({id:parseInt(t)}),stringify:({id:t})=>({id:t.toString()})},loader:({context:{queryClient:t,Api:r},params:{id:s}})=>{t.ensureQueryData(Xe(r,s))},beforeLoad:({params:{id:t},context:{Api:r}})=>{var s;if(!r.hasAuth)throw fe({to:O.INDEX});if(t===((s=r.authenticatedUser)==null?void 0:s.id))throw fe({to:O.PROFILE})},component:mn}),xn=Qe.update({path:"/",getParentRoute:()=>oe}),pn=dn.update({path:"/profile/",getParentRoute:()=>oe}),gn=Ze.update({path:"/confirm/",getParentRoute:()=>oe}),jn=Ve.update({path:"/profile/$id",getParentRoute:()=>oe}),fn=oe.addChildren({IndexRoute:xn,ProfileIdRoute:jn,ConfirmIndexRoute:gn,ProfileIndexRoute:pn}),yn=It({routeTree:fn,context:{queryClient:void 0,Api:void 0},defaultPreload:"intent",defaultPreloadStaleTime:0,basepath:"/phpCourse/exam"}),vn=()=>{const t=D(),r=V();return e.jsx(kt,{router:yn,context:{queryClient:r,Api:t}})},Ye=t=>({404:{fontSize:"6rem",[t.breakpoints.up("sm")]:{fontSize:"12rem"},[t.breakpoints.up("md")]:{fontSize:"18rem"}}}),et={styleOverrides:{root:{backgroundColor:void 0,color:"text.primary"}}};let ce=de({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"}}});ce=de(ce,{typography:{...Ye(ce)},components:{...et}});const Cn=ce;let le=de({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"}}});le=de(le,{typography:{...Ye(le)},components:{...et}});const Sn=le,wn=()=>{const t=X("(prefers-color-scheme: dark)"),r=me(i=>i.theme),s=T.useMemo(()=>r==="dark"||t?Cn:Sn,[r,t]);return e.jsxs(Ct,{theme:s,children:[e.jsx(St,{}),e.jsx(vn,{})]})},bn=new At,Fe=document.getElementById("root");Fe.innerHTML||ye.createRoot(Fe).render(e.jsx(T.StrictMode,{children:e.jsxs(Dt,{client:bn,children:[e.jsx(Qt,{children:e.jsx(wn,{})}),!1]})}));
|