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