PHP-Course/exam/dist/assets/index-CG0WySTu.js
2024-07-27 16:42:03 +02:00

2 lines
20 KiB
JavaScript

import{j as e,M as ne,a as O,T as p,B as E,b as F,c as f,A as ye,d as J,L as k,C as L,I as Q,e as fe,f as T,P as I,g as Ce,u as ve,h as se,i as re,k as ae,D as K,l as _,m as $,n as H,o as oe,p as be,q as ie,r as le,s as we,S as q,t as Pe,G as y,v as ce,w as Se,x as Ae}from"./mui-v3E5hT34.js";import{u as G,a as R,b as Ee,c as Fe,d as ke,L as S,e as De,O as Te,f as Ie,r as U,g as B,h as N,q as V,i as X,j as Z,Q as $e,k as qe,l as Me,R as Oe,m as Ue}from"./tanstack-yMrSYl0u.js";import{c as Le,r as j}from"./react-DXd9vB-a.js";import{i as D,B as Re,a as Be,b as Ne,u as w,t as m}from"./i18n-DJgSTqOl.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))o(s);new MutationObserver(s=>{for(const c of s)if(c.type==="childList")for(const r of c.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&o(r)}).observe(document,{childList:!0,subtree:!0});function a(s){const c={};return s.integrity&&(c.integrity=s.integrity),s.referrerPolicy&&(c.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?c.credentials="include":s.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function o(s){if(s.ep)return;s.ep=!0;const c=a(s);fetch(s.href,c)}})();var W={},Y=Le;W.createRoot=Y.createRoot,W.hydrateRoot=Y.hydrateRoot;const ze=15,P="https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/";let ee;class Qe{constructor(){if(this.hasAuth=()=>this.token!==void 0,this.isAdmin=()=>{var n;return this.hasAuth()&&((n=this.self)==null?void 0:n.isAdmin)},this.getAuthenticatedUser=()=>this.self,this.getCurrentSession=()=>[this.token,this.refreshToken],this.logIn=async(n,a)=>{const{user:o,token:s}=await(await this.post("login",{email:n,password:a})).json();this.self=o,this.token=s},this.logOut=async()=>{try{return await(await this.postAuth("logout")).json()}catch{return!1}finally{this.self=void 0,this.token=void 0}},this.posts=async n=>{const a=`posts?p=${n??0}&l=${ze}`;return this.token?await(await this.getAuth(a)).json():await(await this.get(a)).json()},this.deletePost=async n=>await(await this.delete(`posts/${n}`)).json(),this.user=async n=>{var a;return await(await this.getAuth(`users/${n??((a=this.self)==null?void 0:a.id)}`)).json()},this.updateUser=async(n,a)=>await(await this.patch(`users/${a??"self"}`,n)).json(),this.newPost=async n=>await(await this.postAuth("posts",n)).json(),this.updatePost=async(n,a)=>await(await this.patch(`posts/${a}`,n)).json(),this.post=async(n,a,o)=>{const s=await fetch(`${P}${n}`,{mode:"cors",method:"post",headers:o,body:JSON.stringify(a)});if(s.ok)return s;throw await s.json()},this.postAuth=async(n,a,o)=>{const s=await fetch(`${P}${n}`,{mode:"cors",method:"post",headers:{token:this.token??"",...o},body:JSON.stringify(a)});if(s.ok)return s;throw await s.json()},this.get=async(n,a)=>{const o=await fetch(`${P}${n}`,{mode:"cors",method:"get",headers:a});if(o.ok)return o;throw await o.json()},this.getAuth=async(n,a)=>{const o=await fetch(`${P}${n}`,{mode:"cors",method:"get",headers:{token:this.token??"",...a}});if(o.ok)return o;throw await o.json()},this.delete=async(n,a)=>{const o=await fetch(`${P}${n}`,{mode:"cors",method:"delete",headers:{token:this.token??"",...a}});if(o.ok)return o;throw await o.json()},this.patch=async(n,a,o)=>{const s=await fetch(`${P}${n}`,{mode:"cors",method:"patch",headers:{token:this.token??"",...o},body:JSON.stringify(a)});if(s.ok)return s;throw await s.json()},ee)throw new Error("New instance cannot be created!!");ee=this}}const d=new Qe;var A=(t=>(t.NOT_FOUND="NotFound",t.UNAUTHORIZED="Unauthorized",t.FAILED_UPDATE="FailedUpdate",t.MISSING_FIELD="MissingField",t))(A||{});D.use(Re).use(Be).use(Ne).init({fallbackLng:"en",debug:!1,interpolation:{escapeValue:!1},backend:{loadPath:"/phpCourse/exam/dist/locales/{{lng}}/{{ns}}.json"}});const We=({anchorEl:t,handleClose:n})=>e.jsxs(ne,{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(O,{selected:D.language==="en",onClick:()=>{D.changeLanguage("en"),n()},children:"English"},"de"),e.jsx(O,{selected:D.language==="de",onClick:()=>{D.changeLanguage("de"),n()},children:"Deutsch"},"en")]});var v=(t=>(t.INDEX="/",t.PROFILE="/profile",t))(v||{});const M=({error:t,context:n,color:a="error.main"})=>{const{t:o}=w();if(console.log(t,n),!t)return null;if(t.code)switch(t.code){case A.NOT_FOUND:return e.jsx(p,{color:a,children:o(t.code,{context:`${t.entity}:${n}`})});case A.UNAUTHORIZED:return e.jsx(p,{color:a,children:o(t.code,{context:n})});case A.FAILED_UPDATE:return t.fields.map((s,c)=>e.jsx(p,{color:a,children:o(t.code,{context:`${t.reasons[c]}:${s}:${n}`})},`error_${s}`));case A.MISSING_FIELD:return t.fields.map(s=>e.jsx(p,{color:a,children:o(t.code,{context:`${s}:${n}`})},`error_${s}`))}return e.jsx(p,{color:a,children:o((t==null?void 0:t.message)??"Unknown",{context:n})})},Ke=({handleClose:t})=>{const[n,a]=j.useState(),{t:o}=w(),s=G(),c=R({defaultValues:{email:"",password:""},onSubmit:async({value:r})=>{try{await d.logIn(r.email,r.password),s.invalidate(),t()}catch(h){a(h)}}});return e.jsx("form",{onSubmit:r=>{r.preventDefault(),r.stopPropagation(),c.handleSubmit()},onKeyDown:r=>{r.key==="Tab"&&r.stopPropagation()},noValidate:!0,children:e.jsxs(E,{sx:{display:"grid",gap:2,padding:1},children:[e.jsx(c.Field,{name:"email",validators:{onChange:({value:r})=>r?void 0:o("Email required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:r})=>!r&&o("Email required")},children:r=>e.jsx(e.Fragment,{children:e.jsx(F,{variant:"outlined",name:r.name,value:r.state.value,onBlur:r.handleBlur,onChange:h=>r.handleChange(h.target.value),size:"small",label:o("Email"),required:!0,error:r.state.meta.isTouched&&r.state.meta.errors.length>0,helperText:r.state.meta.isTouched?r.state.meta.errors.join(","):"",type:"email",autoComplete:"username",inputMode:"email",fullWidth:!0})})}),e.jsx(c.Field,{name:"password",validators:{onChange:({value:r})=>r?void 0:o("Password required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:r})=>!r&&o("Password required")},children:r=>e.jsx(e.Fragment,{children:e.jsx(F,{variant:"outlined",name:r.name,value:r.state.value,onBlur:r.handleBlur,onChange:h=>r.handleChange(h.target.value),size:"small",label:o("Password"),required:!0,error:r.state.meta.isTouched&&r.state.meta.errors.length>0,helperText:r.state.meta.isTouched?r.state.meta.errors.join(","):"",type:"password",autoComplete:"password",fullWidth:!0})})}),e.jsx(c.Subscribe,{selector:r=>[r.canSubmit,r.isSubmitting],children:([r])=>e.jsx(e.Fragment,{children:e.jsx(f,{type:"submit",disabled:!r,variant:"contained",children:o("Log in")})})}),n&&e.jsx(M,{error:n,context:"login"})]})})},_e=({anchorEl:t,handleClose:n})=>{const a=Ee(),o=G(),s=Fe({from:"/profile/",strict:!0,shouldThrow:!1}),c=d.getAuthenticatedUser();return e.jsx(ne,{anchorEl:t,anchorOrigin:{vertical:"bottom",horizontal:"right"},keepMounted:!0,transformOrigin:{vertical:"top",horizontal:"right"},open:!!t,onClose:n,sx:{"& .MuiMenu-paper":{minWidth:"240px"}},children:c?[e.jsx(O,{selected:!!s,onClick:()=>{a({to:v.PROFILE}),n()},children:m("Profile")},"profile"),e.jsx(O,{onClick:async()=>{await d.logOut(),o.invalidate(),n()},children:m("Log out")},"logout")]:e.jsx(Ke,{handleClose:n})})},He=({children:t})=>{const n=ve({disableHysteresis:!0,threshold:0});return j.cloneElement(t,{elevation:n?4:0})},Ge=()=>{const[t,n]=j.useState(null),[a,o]=j.useState(null),{t:s}=w(),c=ke({select:l=>l.status==="pending"}),r=d.getAuthenticatedUser(),h=()=>{o(null),n(null)};return e.jsx(He,{children:e.jsxs(e.Fragment,{children:[e.jsx(ye,{children:e.jsxs(J,{children:[e.jsxs(E,{sx:{flexGrow:1,alignItems:"center",display:"flex",gap:1},children:[e.jsx(k,{component:S,to:"/",color:"#FFF",variant:"h6",underline:"none",children:s("GuestBook")}),c&&e.jsx(L,{size:16,thickness:10,sx:{color:"white"}})]}),e.jsx(Q,{size:"large",onClick:l=>o(l.currentTarget),children:e.jsx(fe,{sx:{color:"white"}})}),r?e.jsx(Q,{onClick:l=>n(l.currentTarget),sx:{p:0},children:e.jsx(T,{alt:r.username,src:`storage/${r.image}`,children:e.jsx(I,{})})}):e.jsx(Q,{size:"large",onClick:l=>n(l.currentTarget),color:"inherit",children:e.jsx(Ce,{})}),e.jsx(We,{anchorEl:a,handleClose:h}),e.jsx(_e,{anchorEl:t,handleClose:h})]})}),e.jsx(J,{})]})})},Ve=()=>e.jsxs(e.Fragment,{children:[e.jsx(Ge,{}),e.jsx(E,{sx:{display:"flex",justifyContent:"center"},children:e.jsx(E,{sx:{maxWidth:"800px",flexGrow:1},children:e.jsx(Te,{})})}),!1]}),Xe=({error:t})=>{const n=G(),a=Ie();return j.useEffect(()=>{a.reset()},[a]),"code"in t&&t.code===A.UNAUTHORIZED&&(d.logOut(),U({to:v.INDEX})),e.jsxs("div",{children:[t.message,e.jsx("button",{onClick:()=>{n.invalidate()},children:"retry"})]})},z=De()({component:Ve,errorComponent:Xe}),Ze=()=>{const[t,n]=j.useState(),[a,o]=j.useState(0),{t:s}=w(),c=B(),r=N({mutationFn:({data:l})=>d.newPost(l)}),h=R({defaultValues:{content:""},onSubmit:async({value:l})=>{try{r.mutate({data:l},{onSuccess:()=>{c.invalidateQueries({queryKey:["posts"]})},onError:n})}catch(g){n(g)}}});return e.jsx("form",{onSubmit:l=>{l.preventDefault(),l.stopPropagation(),h.handleSubmit()},onKeyDown:l=>{l.key==="Tab"&&l.stopPropagation()},noValidate:!0,children:e.jsxs(E,{sx:{display:"grid",gap:2,padding:1},children:[e.jsx(h.Field,{name:"content",validators:{onChange:({value:l})=>l?void 0:s("Content required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:l})=>!l&&s("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:g=>{g.target.value.length<=250&&(o(g.target.value.length),l.handleChange(g.target.value))},size:"small",label:s("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(se,{variant:"determinate",value:a/250*100,color:a===250?"error":a>=200?"warning":"primary"})]})}),e.jsx(h.Subscribe,{selector:l=>[l.canSubmit,l.isSubmitting],children:([l])=>e.jsx(e.Fragment,{children:e.jsx(f,{type:"submit",disabled:!l||r.isPending,variant:"contained",endIcon:r.isPending&&e.jsx(L,{color:"inherit",size:"20px"}),children:s("Post comment")})})}),t&&e.jsx(M,{error:t,context:"newPost"})]})})},ue=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"}),Je=({post:t,open:n,onClose:a})=>{const[o,s]=j.useState(),[c,r]=j.useState(t.content.length),h=N({mutationFn:({data:u,id:C})=>d.updatePost(u,C)}),l=R({defaultValues:{content:t.content.replaceAll("<br />","")},onSubmit:async({value:u})=>{try{h.mutate({data:u,id:t.id},{onSuccess:()=>{x(),i.invalidateQueries({queryKey:["posts"]})},onError:s})}catch(C){s(C)}}}),g=re(),b=ae(g.breakpoints.only("xs"),{noSsr:!0}),i=B(),x=()=>{l.reset(),s(void 0),a()};return e.jsxs(K,{open:n,onClose:x,fullWidth:!0,fullScreen:b,PaperProps:{component:"form",onSubmit:u=>{u.preventDefault(),u.stopPropagation(),l.handleSubmit()},onKeyDown:u=>{u.key==="Tab"&&u.stopPropagation()},noValidate:!0},children:[e.jsx(_,{children:m("Edit post")}),e.jsx($,{children:e.jsx(l.Field,{name:"content",validators:{onChange:({value:u})=>u?void 0:m("Content required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:u})=>!u&&m("Content required")},children:u=>e.jsxs(e.Fragment,{children:[e.jsx(F,{variant:"outlined",multiline:!0,minRows:3,name:u.name,value:u.state.value,onBlur:u.handleBlur,onChange:C=>{C.target.value.length<=250&&(r(C.target.value.length),u.handleChange(C.target.value))},size:"small",label:m("Comment"),required:!0,error:u.state.meta.isTouched&&u.state.meta.errors.length>0,helperText:u.state.meta.isTouched?u.state.meta.errors.join(","):"",autoComplete:"off",margin:"dense",fullWidth:!0}),e.jsx(se,{variant:"determinate",value:c/250*100,color:c===250?"error":c>=200?"warning":"primary"})]})})}),e.jsx(H,{children:e.jsx(l.Subscribe,{selector:u=>[u.canSubmit,u.isSubmitting],children:([u])=>e.jsxs(e.Fragment,{children:[e.jsx(f,{variant:"outlined",onClick:()=>{x()},children:m("Cancel")}),e.jsx(f,{type:"submit",disabled:!u||h.isPending,autoFocus:!0,variant:"contained",endIcon:h.isPending&&e.jsx(L,{color:"inherit",size:"20px"}),children:m("Save")})]})})}),o&&e.jsx($,{children:e.jsx(M,{error:o,context:"postUpdate"})})]})},Ye=({post:t})=>{var b,i,x;const[n,a]=j.useState(!1),[o,s]=j.useState(!1),[c,r]=j.useState(),h=N({mutationFn:u=>d.deletePost(u)}),l=B(),{t:g}=w();return e.jsxs(oe,{children:[e.jsx(be,{avatar:"id"in t.user?t.user.id!==((b=d.getAuthenticatedUser())==null?void 0:b.id)?e.jsx(k,{component:S,to:"/profile/$id",params:{id:t.user.id},children:e.jsx(T,{alt:t.user.username,src:`storage/${t.user.image}`,children:e.jsx(I,{})})}):e.jsx(k,{component:S,to:"/profile",children:e.jsx(T,{alt:t.user.username,src:`storage/${t.user.image}`,children:e.jsx(I,{})})}):e.jsx(T,{alt:t.user.username,src:`storage/${t.user.image}`,children:e.jsx(I,{})}),title:"id"in t.user?t.user.id!==((i=d.getAuthenticatedUser())==null?void 0:i.id)?e.jsx(k,{component:S,to:"/profile/$id",params:{id:t.user.id},children:t.user.username}):e.jsx(k,{component:S,to:"/profile",children:t.user.username}):t.user.username,subheader:ue(t.postedAt)}),e.jsx(ie,{children:e.jsx(p,{children:e.jsx("span",{dangerouslySetInnerHTML:{__html:t.content}})})}),e.jsxs(le,{children:[(d.isAdmin()||"id"in t.user&&t.user.id===((x=d.getAuthenticatedUser())==null?void 0:x.id))&&e.jsxs(e.Fragment,{children:[e.jsx(f,{size:"small",onClick:()=>s(!0),children:g("Edit")}),e.jsx(Je,{post:t,open:o,onClose:()=>s(!1)})]}),d.isAdmin()&&e.jsxs(e.Fragment,{children:[e.jsx(f,{size:"small",color:"error",onClick:()=>a(!0),children:g("Delete")}),e.jsxs(K,{open:n,onClose:()=>a(!1),children:[e.jsx(_,{children:g("Confirm post delete title")}),e.jsx($,{children:e.jsx(we,{children:g("Confirm post delete body",{name:t.user.username})})}),e.jsxs(H,{children:[e.jsx(f,{onClick:()=>a(!1),autoFocus:!0,variant:"contained",children:g("No")}),e.jsx(f,{variant:"outlined",color:"error",onClick:()=>{h.mutate(t.id,{onSuccess:()=>{l.invalidateQueries({queryKey:["posts"]})},onError:r}),a(!1)},children:g("Yes")})]})]})]})]}),e.jsx(q,{open:h.isError,autoHideDuration:2e3,onClose:()=>{h.reset()},TransitionProps:{onExited:()=>r(void 0)},children:e.jsx(Pe,{severity:"error",variant:"filled",sx:{width:"100%"},children:c&&e.jsx(M,{error:c,context:"delete",color:"white"})})}),e.jsx(q,{open:h.isPending,message:g("Deleting")})]})},de=t=>V({queryKey:["posts",{page:t??0,hasAuth:d.hasAuth()}],queryFn:()=>d.posts(t)}),et=()=>{const{page:t}=he.useSearch(),{data:n,isFetching:a}=Z(de(t)),{t:o}=w();return e.jsxs(e.Fragment,{children:[e.jsx(q,{open:a,message:o("Updating")}),e.jsxs(y,{container:!0,spacing:2,children:[n.data.map(s=>e.jsx(y,{item:!0,xs:12,children:e.jsx(Ye,{post:s})},s.id)),e.jsx(y,{item:!0,xs:12,children:e.jsx(ce,{variant:"middle"})}),d.hasAuth()&&e.jsx(y,{item:!0,xs:12,children:e.jsx(Ze,{})}),e.jsx(y,{item:!0,xs:12,sx:{display:"flex",justifyContent:"center"},children:e.jsx(Se,{page:(t??0)+1,count:n.pages,color:"primary",renderItem:s=>e.jsx(Ae,{...s,component:S,to:"/",search:{page:(s.page??0)>0?(s.page??1)-1:void 0},onClick:c=>s.onClick(c)})})})]})]})},he=X(v.INDEX)({loaderDeps:({search:{page:t}})=>({page:t}),loader:({context:{queryClient:t},deps:{page:n}})=>t.ensureQueryData(de(n)),validateSearch:t=>({page:(t==null?void 0:t.page)!==void 0?Number((t==null?void 0:t.page)??0):void 0}),component:et}),tt=({user:t,open:n,onClose:a})=>{const[o,s]=j.useState(),c=N({mutationFn:({data:i,id:x})=>d.updateUser(i,x)}),r=R({defaultValues:{username:t.username,email:t.email},onSubmit:async({value:i})=>{var x;try{c.mutate({data:i,id:((x=d.getAuthenticatedUser())==null?void 0:x.id)===t.id?void 0:t.id},{onSuccess:()=>{var C;b();const u=((C=d.getAuthenticatedUser())==null?void 0:C.id)===t.id?["profile"]:["profile",{id:t.id}];g.invalidateQueries({queryKey:u})},onError:s})}catch(u){s(u)}}}),h=re(),l=ae(h.breakpoints.only("xs"),{noSsr:!0}),g=B(),b=()=>{r.reset(),s(void 0),a()};return e.jsxs(K,{open:n,onClose:b,fullWidth:!0,fullScreen:l,PaperProps:{component:"form",onSubmit:i=>{i.preventDefault(),i.stopPropagation(),r.handleSubmit()},onKeyDown:i=>{i.key==="Tab"&&i.stopPropagation()},noValidate:!0},children:[e.jsx(_,{children:m("Edit data")}),e.jsxs($,{children:[e.jsx(r.Field,{name:"username",validators:{onChange:({value:i})=>i?void 0:m("Username required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:i})=>!i&&m("Username required")},children:i=>e.jsx(e.Fragment,{children:e.jsx(F,{name:i.name,value:i.state.value,onBlur:i.handleBlur,onChange:x=>i.handleChange(x.target.value),size:"small",label:m("Username"),required:!0,margin:"dense",autoComplete:"new-username",fullWidth:!0,error:i.state.meta.isTouched&&i.state.meta.errors.length>0,helperText:i.state.meta.isTouched?i.state.meta.errors.join(","):""})})}),e.jsx(r.Field,{name:"email",validators:{onChange:({value:i})=>i?void 0:m("Email required"),onChangeAsyncDebounceMs:250,onChangeAsync:async({value:i})=>!i&&m("Email required")},children:i=>e.jsx(e.Fragment,{children:e.jsx(F,{name:i.name,value:i.state.value,onBlur:i.handleBlur,onChange:x=>i.handleChange(x.target.value),size:"small",label:m("Email"),required:!0,margin:"dense",autoComplete:"new-username",fullWidth:!0,error:i.state.meta.isTouched&&i.state.meta.errors.length>0,helperText:i.state.meta.isTouched?i.state.meta.errors.join(","):""})})})]}),e.jsx(H,{children:e.jsx(r.Subscribe,{selector:i=>[i.canSubmit,i.isSubmitting],children:([i])=>e.jsxs(e.Fragment,{children:[e.jsx(f,{variant:"outlined",onClick:()=>{b()},children:m("Cancel")}),e.jsx(f,{type:"submit",disabled:!i||c.isPending,autoFocus:!0,variant:"contained",endIcon:c.isPending&&e.jsx(L,{color:"inherit",size:"20px"}),children:m("Save")})]})})}),o&&e.jsx($,{children:e.jsx(M,{error:o,context:"userUpdate"})})]})},me=({user:t,canEdit:n})=>{const[a,o]=j.useState(!1),{t:s}=w();return e.jsxs(y,{container:!0,sx:{justifyContent:"center"},spacing:2,children:[e.jsx(y,{item:!0,children:e.jsxs(oe,{children:[e.jsx(ie,{children:e.jsxs(y,{container:!0,spacing:2,children:[e.jsx(y,{item:!0,sx:{display:"flex",flexGrow:1,justifyContent:"center"},children:e.jsx(T,{alt:t.username,src:`storage/${t.image}`,sx:{width:"100px",height:"100px"},children:e.jsx(I,{sx:{width:"60px",height:"60px"}})})}),e.jsx(y,{item:!0,sx:{display:"flex",alignItems:"center"},children:e.jsxs(E,{sx:{display:"grid",gridTemplateColumns:"120px 1fr",columnGap:1},children:[e.jsxs(p,{fontWeight:"bold",children:[s("Username"),":"]}),e.jsx(p,{children:t.username}),e.jsxs(p,{fontWeight:"bold",children:[s("Email"),":"]}),e.jsx(p,{children:t.email}),e.jsxs(p,{fontWeight:"bold",children:[s("Member since"),":"]}),e.jsx(p,{children:ue(t.memberSince)}),e.jsxs(p,{fontWeight:"bold",children:[s("Post count"),":"]}),e.jsx(p,{children:t.postCount})]})})]})}),e.jsx(le,{children:n&&e.jsx(f,{size:"small",onClick:()=>o(!0),children:s("Edit")})}),e.jsx(tt,{user:t,open:a,onClose:()=>o(!1)})]})}),e.jsx(y,{item:!0,xs:12,children:e.jsx(ce,{variant:"middle",children:e.jsx(p,{sx:{opacity:.36},children:s("Recent posts")})})})]})},ge=V({queryKey:["profile"],queryFn:()=>d.user()}),xe=t=>V({queryKey:["profile",{id:t}],queryFn:()=>d.user(t)}),nt=()=>{const{data:t,isFetching:n}=Z(ge);return e.jsxs(e.Fragment,{children:[e.jsx(q,{open:n,message:m("Updating")}),e.jsx(me,{user:t,canEdit:!0})]})},st=X(`${v.PROFILE}/`)({loader:({context:{queryClient:t}})=>t.ensureQueryData(ge),beforeLoad:()=>{if(!d.hasAuth())throw U({to:v.INDEX})},component:nt}),rt=()=>{const{id:t}=pe.useParams(),{data:n,isFetching:a}=Z(xe(t));return e.jsxs(e.Fragment,{children:[e.jsx(q,{open:a,message:m("Updating")}),e.jsx(me,{user:n,canEdit:d.isAdmin()})]})},pe=X(`${v.PROFILE}/$id`)({params:{parse:({id:t})=>({id:parseInt(t)}),stringify:({id:t})=>({id:t.toString()})},loader:({context:{queryClient:t},params:{id:n}})=>t.ensureQueryData(xe(n)),beforeLoad:({params:{id:t}})=>{var n;if(!d.hasAuth())throw U({to:v.INDEX});if(t===((n=d.getAuthenticatedUser())==null?void 0:n.id))throw U({to:v.PROFILE})},component:rt}),at=he.update({path:"/",getParentRoute:()=>z}),ot=st.update({path:"/profile/",getParentRoute:()=>z}),it=pe.update({path:"/profile/$id",getParentRoute:()=>z}),lt=z.addChildren({IndexRoute:at,ProfileIdRoute:it,ProfileIndexRoute:ot}),je=new $e,ct=qe({routeTree:lt,context:{queryClient:je},defaultPreload:"intent",defaultPreloadStaleTime:0,basepath:"/phpCourse/exam"}),te=document.getElementById("root");te.innerHTML||W.createRoot(te).render(e.jsx(j.StrictMode,{children:e.jsxs(Me,{client:je,children:[e.jsx(Oe,{router:ct}),e.jsx(Ue,{initialIsOpen:!1})]})}));