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