PageSourceSearch

https://tresda.institute/assets/AdminTRAAssessment-gwXc_WOE.js

js tresda.institute collected 2026-10-02 01:58:27 UTC 37,911 bytes, 2 lines download raw bytes

1import{b as A,j as e,m as f,r as u,u as R,a as C,n as L,k as S,ae as K,_ as U,a3 as Q,e as P,l as V,W,x as O}from"./index-u0HMC9Vb.js";const $={SORA:"#7F8FA6",AERO:"#D6B46A",ONYX:"#C06A6A",NOVA:"#8FA77A"};function B(){const{data:r=[]}=A({queryKey:["admin-all-assessments"],queryFn:()=>f.entities.TRAAssessment.list("-created_date",500)}),i=r.filter(d=>d.status==="completed"),l=r.filter(d=>d.status!=="completed"),h=r.length,b=h>0?Math.round(i.length/h*100):0,v={},m={High:0,Medium:0,Low:0};for(const d of i)d.primary_tra&&(v[d.primary_tra]=(v[d.primary_tra]||0)+1),d.confidence_level&&(m[d.confidence_level]=(m[d.confidence_level]||0)+1);const o=({label:d,value:p,sub:y})=>e.jsxs("div",{className:"border border-border p-5",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground mb-2",children:d}),e.jsx("p",{className:"text-3xl font-display text-foreground",children:p}),y&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:y})]});return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(o,{label:"Total Assessments",value:h}),e.jsx(o,{label:"Completed",value:i.length,sub:`${b}% completion rate`}),e.jsx(o,{label:"In Progress",value:l.length}),e.jsx(o,{label:"Completion Rate",value:`${b}%`})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"border border-border p-5",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground mb-5",children:"Primary TRA Distribution"}),e.jsx("div",{className:"space-y-3",children:["SORA","AERO","ONYX","NOVA"].map(d=>{const p=v[d]||0,y=i.length>0?p/i.length*100:0;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 text-[9px] font-meta text-muted-foreground",children:d}),e.jsx("div",{className:"flex-1 h-1 bg-border overflow-hidden",children:e.jsx("div",{className:"h-full transition-all",style:{width:`${y}%`,backgroundColor:$[d]}})}),e.jsx("div",{className:"w-10 text-[9px] font-meta text-muted-foreground text-right",children:p})]},d)})})]}),e.jsxs("div",{className:"border border-border p-5",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground mb-5",children:"Confidence Distribution"}),e.jsx("div",{className:"space-y-3",children:["High","Medium","Low"].map(d=>{const p=m[d]||0,y=i.length>0?p/i.length*100:0;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 text-[9px] font-meta text-muted-foreground",children:d}),e.jsx("div",{className:"flex-1 h-1 bg-border overflow-hidden",children:e.jsx("div",{className:"h-full bg-foreground transition-all",style:{width:`${y}%`}})}),e.jsx("div",{className:"w-10 text-[9px] font-meta text-muted-foreground text-right",children:p})]},d)})})]})]})]})}const Y=["Perceptual Lens","Design Behaviour","Time Orientation","Translation Under Constraint","Tension Detection","Spatial Read","Written Calibration"],X=["single_choice","five_point_scale","image_selection","short_paragraph"],M=["SORA","AERO","ONYX","NOVA"],I={question_text:"",section_name:"Perceptual Lens",question_type:"single_choice",order:1,is_required:!0,is_archived:!1,options:[{id:"opt_a",text:"",tra_mapping:"SORA"},{id:"opt_b",text:"",tra_mapping:"AERO"},{id:"opt_c",text:"",tra_mapping:"ONYX"},{id:"opt_d",text:"",tra_mapping:"NOVA"}],scale_target_tra:"SORA",image_set_id:""};function H(){var j;const[r,i]=u.useState(null),[l,h]=u.useState(null),[b,v]=u.useState(null),[m,o]=u.useState(!1),d=R(),{data:p=[],isLoading:y}=A({queryKey:["admin-tra-questions"],queryFn:()=>f.entities.TRAQuestion.list("order",100)}),{data:c=[]}=A({queryKey:["tra-image-sets-admin"],queryFn:()=>f.entities.TRAImageSet.list("-created_date",50)}),w=C({mutationFn:t=>l?f.entities.TRAQuestion.update(l,t):f.entities.TRAQuestion.create(t),onSuccess:()=>{d.invalidateQueries({queryKey:["admin-tra-questions"]}),i(null),h(null)}}),s=C({mutationFn:t=>f.entities.TRAQuestion.update(t,{is_archived:!0}),onSuccess:()=>d.invalidateQueries({queryKey:["admin-tra-questions"]})}),a=t=>{var n;i({...I,...t,options:(n=t.options)!=null&&n.length?t.options:I.options}),h(t.id)},g=()=>{i({...I,order:p.length+1}),h(null)},_=(t,n,x)=>{const N=[...r.options];N[t]={...N[t],[n]:x},i(T=>({...T,options:N}))},k=m?p:p.filter(t=>!t.is_archived);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsx("button",{onClick:()=>o(t=>
1!t),className:"text-[9px] font-meta uppercase tracking-widest text-muted-foreground hover:text-foreground transition-colors border border-border px-3 py-1.5",children:m?"Hide archived":"Show archived"})}),e.jsxs("button",{onClick:g,className:"flex items-center gap-1.5 text-[9px] font-meta uppercase tracking-widest px-4 py-2 bg-foreground text-background hover:opacity-80 transition-opacity",children:[e.jsx(L,{className:"w-3 h-3",strokeWidth:1.5})," New Question"]})]}),r&&e.jsxs("div",{className:"border border-foreground/30 p-6 space-y-5 bg-card",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-widest text-muted-foreground",children:l?"Edit Question":"New Question"}),e.jsx("textarea",{value:r.question_text,onChange:t=>i(n=>({...n,question_text:t.target.value})),placeholder:"Question text...",rows:3,className:"w-full text-sm bg-transparent border border-border p-3 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground/40 resize-none"}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{children:"Section"}),e.jsx("select",{value:r.section_name,onChange:t=>i(n=>({...n,section_name:t.target.value})),className:"w-full text-xs bg-background border border-border px-2 py-2 text-foreground focus:outline-none mt-1",children:Y.map(t=>e.jsx("option",{value:t,children:t},t))})]}),e.jsxs("div",{children:[e.jsx("label",{children:"Type"}
1),e.jsx("select",{value:r.question_type,onChange:t=>i(n=>({...n,question_type:t.target.value})),className:"w-full text-xs bg-background border border-border px-2 py-2 text-foreground focus:outline-none mt-1",children:X.map(t=>e.jsx("option",{value:t,children:t},t))})]}),e.jsxs("div",{children:[e.jsx("label",{children:"Order"}),e.jsx("input",{type:"number",value:r.order,onChange:t=>i(n=>({...n,order:+t.target.value})),className:"w-full text-xs bg-background border border-border px-2 py-2 text-foreground focus:outline-none mt-1"})]}),e.jsx("div",{className:"flex items-end pb-2 gap-2",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.is_required,onChange:t=>i(n=>({...n,is_required:t.target.checked}))}),e.jsx("span",{className:"text-[9px] font-meta uppercase tracking-widest text-muted-foreground",children:"Required"})]})})]}),r.question_type==="single_choice"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-widest text-muted-foreground",children:"Options (A→SORA, B→AERO, C→ONYX, D→NOVA)"}),(j=r.options)==null?void 0:j.map((t,n)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[9px] font-meta text-muted-foreground w-4",children:["A","B","C","D"][n]}),e.jsx("input",{value:t.text,onChange:x=>_(n,"text",x.target.value),placeholder:`Option ${["A","B","C","D"][n]}...`,className:"flex-1 text-xs bg-transparent border border-border px-3 py-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground
1/40"}),e.jsx("select",{value:t.tra_mapping,onChange:x=>_(n,"tra_mapping",x.target.value),className:"text-xs bg-background border border-border px-2 py-2 text-foreground focus:outline-none w-20",children:M.map(x=>e.jsx("option",{value:x,children:x},x))})]},n))]}),r.question_type==="five_point_scale"&&e.jsxs("div",{children:[e.jsx("label",{children:"Scale maps to TRA"}),e.jsx("select",{value:r.scale_target_tra||"SORA",onChange:t=>i(n=>({...n,scale_target_tra:t.target.value})),className:"w-full text-xs bg-background border border-border px-2 py-2 text-foreground focus:outline-none mt-1",children:M.map(t=>e.jsx("option",{value:t,children:t},t))})]}),r.question_type==="image_selection"&&e.jsxs("div",{children:[e.jsx("label",{children:"Image Set"}),e.jsxs("select",{value:r.image_set_id||"",onChange:t=>i(n=>({...n,image_set_id:t.target.value})),className:"w-full text-xs bg-background border border-border px-2 py-2 text-foreground focus:outline-none mt-1",children:[e.jsx("option",{value:"",children:"— None —"}),c.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>w.mutate(r),disabled:w.isPending||!r.question_text,className:"px-5 py-2 bg-foreground text-background text-[10px] font-meta uppercase tracking-widest hover:opacity-80 disabled:opacity-40",children:w.isPending?e.jsx(S,{className:"w-3 h-3 animate-spin"}):l?"Update":"Create"}),e.jsx("button",{onClick:()=>{i(null),h(null)},className:"px-5 py-2 border border-border text-[10px] font-meta uppercase tracking-widest text-muted-foreground hover:text-foreground",children:"Cancel"})]})]}),y?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(S,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"space-y-1",children:k.map(t=>{var n;return e.jsxs("div",{className:`border ${t.is_archived?"border-border opacity-50":"border-border"} bg-card`,children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-muted/30",onClick:()=>v(b===t.id?null:t.id),children:[e.jsx("span",{className:"text-[9px] font-meta text-muted-foreground w-5",children:t.order}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-foreground truncate",children:t.question_text}),e.jsxs("p",{className:"text-[9px] font-meta text-muted-foreground mt-0.5",children:[t.section_name," · ",t.question_type]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:x=>{x.stopPropagation(),a(t)},className:"p-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(K,{className:"w-3 h-3",strokeWidth:1.5})}),!t.is_archived&&e.jsx("button",{onClick:x=>{x.stopPropagation(),s.mutate(t.id)},className:"p-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(U,{className:"w-3 h-3",strokeWidth:1.5})}),b===t.id?e.jsx(Q,{className:"w-3 h-3 text-muted-foreground"}):e.jsx(P,{className:"w-3 h-3 text-muted-foreground"})]})]}),b===t.id&&((n=t.options)==null?void 0:n.length)>0&&e.jsx("div",{className:"px-4 pb-4 border-t border-border bg-muted/20",children:e.jsx("div",{className:"pt-3 space-y-1",children:t.options.map((x,N)=>e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("span",{className:"text-muted-foreground font-meta w-4",children:["A","B","C","D"][N]}),e.jsx("span",{className:"flex-1 text-foreground",children:x.text}),e.jsx("span",{className:"text-[9px] font-meta uppercase text-muted-foreground",children:x.tra_mapping})]},N))})})]},t.id)})})]})}const D={"Perceptual Lens":1.5,"Design Behaviour":1.5,"Time Orientation":1,"Translation Under Constraint":1.5,"Tension Detection":2,"Spatial Read":2,"Written Calibration":0};function z(){const[r,i]=u.useState(D),[l,h]=u.useState({high_min_separation:3,medium_min_separation:1.5,consistency_floor:.5}),[b,v]=u.useState(null),m=R(),{data:o=[],isLoading:d}=A({queryKey:["tra-scoring-configs"],queryFn:()=>f.entities.TRAScoringConfig.filter({is_active:!0})});u.useEffect(()=>{if(o.length>0){const c=o[0];v(c.id),i({...D,...c.section_weights||{}}),h({high_min_separation:3,medium_min_separation:1.5,consistency_floor:.5,...c.c
1onfidence_thresholds||{}})}},[o]);const p=C({mutationFn:c=>b?f.entities.TRAScoringConfig.update(b,c):f.entities.TRAScoringConfig.create({...c,name:"V1 Config",is_active:!0}),onSuccess:()=>m.invalidateQueries({queryKey:["tra-scoring-configs"]})}),y=()=>{p.mutate({section_weights:r,confidence_thresholds:l})};return d?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(S,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-8 max-w-2xl",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground mb-4",children:"Section Weights"}),e.jsx("div",{className:"space-y-3",children:Object.entries(r).map(([c,w])=>e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-xs text-foreground",children:c}),c==="Written Calibration"&&e.jsx("p",{className:"text-[9px] text-muted-foreground mt-0.5",children:"Calibration support only — not included in primary score"})]}),e.jsx("input",{type:"number",step:"0.5",min:"0",max:"5",value:w,onChange:s=>i(a=>({...a,[c]:parseFloat(s.target.value)||0})),className:"w-20 text-xs bg-background border border-border px-2 py-2 text-foreground text-center focus:outline-none focus:border-foreground
1/40"})]},c))})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground mb-4",children:"Confidence Thresholds"}),e.jsx("div",{className:"space-y-3",children:[{key:"high_min_separation",label:"High — minimum score separation"},{key:"medium_min_separation",label:"Medium — minimum score separation"},{key:"consistency_floor",label:"Consistency floor (0–1)"}].map(({key:c,label:w})=>e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"text-xs text-foreground",children:w})}),e.jsx("input",{type:"number",step:"0.5",min:"0",value:l[c]||0,onChange:s=>h(a=>({...a,[c]:parseFloat(s.target.value)||0})),className:"w-20 text-xs bg-background border border-border px-2 py-2 text-foreground text-center focus:outline-none focus:border-foreground/40"})]},c))})]}),e.jsxs("button",{onClick:y,disabled:p.isPending,className:"flex items-center gap-2 px-6 py-2.5 bg-foreground text-background text-[10px] font-meta uppercase tracking-widest hover:opacity-80 disabled:opacity-40 transition-opacity",children:[p.isPending&&e.jsx(S,{className:"w-3 h-3 animate-spin"}),"Save Configuration"]})]})}const G=["SORA","AERO","ONYX","NOVA"];function J(){const[r,i]=u.useState(!1),[l,h]=u.useState(""),[b,v]=u.useState(""),[m,o]=u.useState([]),[d,p]=u.useState(!1),y=u.useRef(null),c=R(),{data:w=[]}=A({queryKey:["tra-image-sets-admin"],queryFn:()=>f.entities.TRAImageSet.list("-created_date",50)}),{data:s=[]}=A({queryKey:["tra-images-admin"],queryFn:()=>f.entities.TRAImage.list("-created_date",200)}),a=C({mutationFn:()=>f.entities.TRAImageSet.create({name:l.trim(),image_ids:m,is_active:!0,admin_notes:b.trim()||void 0}),onSuccess:()=>{c.invalidateQueries({queryKey:["tra-image-sets-admin"]}),i(!1),h(""),v(""),o([])}}),g=C({mutationFn:({id:t,is_active:n})=>f.entities.TRAImageSet.update(t,{is_active:n}),onSuccess:()=>c.invalidateQueries({queryKey:["tra-image-sets-admin"]})}),_=async t=>{const n=Array.from(t.target.files);if(n.length){p(!0);for(const x of n){const{file_url:N}=await f.integrations.Core.UploadFile({file:x});await f.entities.TRAImage.create({file_url:N,intended_tra_bucket:"SORA",admin_notes:""})}c.invalidateQueries({queryKey:["tra-images-admin"]}),p(!1),t.target.value=""}},k=async(t,n)=>{await f.entities.TRAImage.update(t.id,{intended_tra_bucket:n}),c.invalidateQueries({queryKey:["tra-images-admin"]})},j=t=>{o(n=>n.includes(t)?n.filter(x=>x!==t):n.length<4?[...n,t]:n)};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground mb-4",children:"Image Library"}),e.jsxs("button",{onClick:()=>{var t;return(t=y.current)==null?void 0:t.click()},disabled:d,className:"flex items-center gap-2 text-[9px] font-meta uppercase tracking-widest text-muted-foreground border border-border px-4 py-2.5 hover:text-foreground hover:border-foreground
1/40 transition-all",children:[d?e.jsx(S,{className:"w-3 h-3 animate-spin"}):e.jsx(V,{className:"w-3 h-3",strokeWidth:1.5}),"Upload Images"]}),e.jsx("input",{ref:y,type:"file",multiple:!0,accept:"image/*",className:"hidden",onChange:_}),s.length>0&&e.jsx("div",{className:"mt-4 grid grid-cols-3 lg:grid-cols-5 gap-3",children:s.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:`relative aspect-square border-2 overflow-hidden ${m.includes(t.id)?"border-foreground":"border-border"}`,children:[e.jsx("img",{src:t.file_url,alt:"",className:"w-full h-full object-cover"}),e.jsx("button",{onClick:()=>j(t.id),className:`absolute inset-0 flex items-center justify-center transition-opacity ${m.includes(t.id)?"bg-foreground/20":"opacity-0 hover:opacity-100 bg-black/20"}`,children:m.includes(t.id)&&e.jsxs("span",{className:"text-[9px] font-meta text-white bg-foreground px-1.5 py-0.5",children:["#",m.indexOf(t.id)+1]})})]}),e.jsx("select",{value:t.intended_tra_bucket||"SORA",onChange:n=>k(t,n.target.value),className:"w-full text-[9px] font-meta bg-background border border-border px-1 py-1 text-foreground focus:outline-none",children:G.map(n=>e.jsx("option",{value:n,children:n},n))})]},t.id))})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground",children:"Image Sets"}),!r&&e.jsxs("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 text-[9px] font-meta uppercase tracking-widest text-muted-foreground border border-dashed border-border px-3 py-1.5 hover:text-foreground hover:border-foreground
1/40 transition-all",children:[e.jsx(L,{className:"w-3 h-3",strokeWidth:1.5})," New Set"]})]}),r&&e.jsxs("div",{className:"border border-foreground/30 p-5 space-y-4 mb-4",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-widest text-muted-foreground",children:"New Image Set — Select exactly 4 images above"}),e.jsx("input",{value:l,onChange:t=>h(t.target.value),placeholder:"Set name (e.g. Q20 Resolved Spaces)",className:"w-full text-xs bg-transparent border border-border px-3 py-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground/40"}),e.jsx("textarea",{value:b,onChange:t=>v(t.target.value),placeholder:"Admin notes (optional)",rows:2,className:"w-full text-xs bg-transparent border border-border px-3 py-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground/40 resize-none"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"text-[9px] font-meta text-muted-foreground",children:[m.length,"/4 selected"]})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>a.mutate(),disabled:!l.trim()||m.length!==4||a.isPending,className:"px-5 py-2 bg-foreground text-background text-[10px] font-meta uppercase tracking-widest hover:opacity-80 disabled:opacity-40",children:a.isPending?e.jsx(S,{className:"w-3 h-3 animate-spin"}):"Create Set"}),e.jsx("button",{onClick:()=>{i(!1),o([])},className:"px-5 py-2 border border-border text-[10px] font-meta uppercase tracking-widest text-muted-foreground hover:text-foreground",children:"Cancel"})]})]}),e.jsx("div",{className:"space-y-3",children:w.map(t=>{const n=(t.image_ids||[]).map(x=>s.find(N=>N.id===x)).filter(Boolean);return e.jsxs("div",{className:"border border-border p-4",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-foreground",children:t.name}),t.admin_notes&&e.jsx("p",{className:"text-[9px] text-muted-foreground mt-0.5",children:t.admin_notes})]}),e.jsx("button",{onClick:()=>g.mutate({id:t.id,is_active:!t.is_active}),className:`text-[9px] font-meta uppercase tracking-widest px-2.5 py-1 border transition-all ${t.is_active?"border-foreground text-foreground":"border-border text-muted-foreground"}`,children:t.is_active?"Active":"Inactive"})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[n.map((x,N)=>e.jsxs("div",{className:"relative aspect-square border border-border overflow-hidden",children:[e.jsx("img",{src:x.file_url,alt:"",className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute bottom-1 left-1",children:e.jsxs("span",{className:"text-[8px] font-meta bg-background/80 text-foreground px-1",children:[["I","II","III","IV"][N]," · ",x.intended_tra_bucket]})})]},x.id)),n.length<4&&Array.from({length:4-n.length}).map((x,N)=>e.jsx("div",{className:"aspect-square border border-dashed border-border bg-muted/30 flex items-center justify-center",children:e.jsx("span",{className:"text-[9px] font-meta text-muted-foreground",children:"Missing"})},N))]})]},t.id)})})]})]})}const Z={SORA:"#7F8FA6",AERO:"#D6B46A",ONYX:"#C06A6A",NOVA:"#8FA77A"};function ee(){const[r,i]=u.useState(""),[l,h]=u.useState("all"),[b,v]=u.useState("all"),[m,o]=u.useState(null),{data:d=[],isLoading:p}=A({queryKey:["admin-results-explorer"],queryFn:()=>f.entities.TRAAssessment.filter({status:"completed"},"-completion_date",200)}),{data:y=[]}=A({queryKey:["admin-tra-questions"],queryFn:()=>f.entities.TRAQuestion.list("order",100)}),c=d.filter(s=>{var a,g;if(l!=="all"&&s.primary_tra!==l||b!=="all"&&s.confidence_level!==b)return!1;if(r){const _=r.toLowerCase();if(!((a=s.user_id)!=null&&a.toLowerCase().includes(_))&&!((g=s.primary_tra)!=null&&g.toLowerCase().includes(_)))return!1}return!0}),w=()=>{const a=[["User ID","Primary TRA","Secondary TRA","Confidence","Completed","SORA Score","AERO Score","ONYX Score","NOVA Score"],...c.map(j=>{var t,n,x,N,T,q,F,E;return[j.user_id,j.primary_tra||"",j.secondary_tra||"",j.confidence_level||"",j.completion_date?O(new Date(j.completion_date),"yyyy-MM-dd"):"",((n=(t=j.total_weighted_scores)==null?void 0:t.SORA)==null?void 0:n.toFixed(2))||"0",((N=(x=j.total_weighted_scores)==null?void 0:x.AERO)==null?void 0:N.toFixed(2))||"0",((q=(T=j.total_weighted_scores)==null?void 0:T.ONYX)==null?void 0:q.toFixed(2))||"0",((E=(F=j.total_weighted_scores)==null?void 0:F.NOVA)==null?void 0:E.toFixed(2))||"0"]})].map(j=>j.join(",")).join(`
2`),g=new Blob([a],{type:"text/csv"}),_=URL.createObjectURL(g),k=document.createElement("a");k.href=_,k.download=`tra-results-${O(new Date,"yyyy-MM-dd")}.csv`,k.click(),URL.revokeObjectURL(_)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-48",children:[e.jsx(W,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground",strokeWidth:1.5}),e.jsx("input",{value:r,onChange:s=>i(s.target.value),placeholder:"Search by user ID or TRA...",className:"w-full text-xs bg-background border border-border pl-8 pr-3 py-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground
2/40"})]}),e.jsxs("select",{value:l,onChange:s=>h(s.target.value),className:"text-xs bg-background border border-border px-3 py-2 text-foreground focus:outline-none",children:[e.jsx("option",{value:"all",children:"All TRAs"}),["SORA","AERO","ONYX","NOVA"].map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsxs("select",{value:b,onChange:s=>v(s.target.value),className:"text-xs bg-background border border-border px-3 py-2 text-foreground focus:outline-none",children:[e.jsx("option",{value:"all",children:"All Confidence"}),["High","Medium","Low"].map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsx("button",{onClick:w,className:"text-[9px] font-meta uppercase tracking-widest text-muted-foreground border border-border px-3 py-2 hover:text-foreground hover:border-foreground/40 transition-all",children:"Export CSV"})]}),e.jsxs("p",{className:"text-[9px] font-meta text-muted-foreground",children:[c.length," results"]}),p?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(S,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"space-y-1",children:c.map(s=>e.jsxs("div",{className:"border border-border bg-card",children:[e.jsxs("div",{className:"flex items-center gap-4 px-4 py-3 cursor-pointer hover:bg-muted/30",onClick:()=>o(m===s.id?null:s.id),children:[e.jsx("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:Z[s.primary_tra]||"#999"}}),e.jsxs("div",{className:"flex-1 min-w-0 grid grid-cols-2 lg:grid-cols-4 gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground",children:"Primary"}),e.jsx("p",{className:"text-xs text-foreground font-display",children:s.primary_tra||"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground",children:"Secondary"}),e.jsx("p",{className:"text-xs text-foreground",children:s.secondary_tra||"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground",children:"Confidence"}),e.jsx("p",{className:"text-xs text-foreground",children:s.confidence_level||"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground",children:"Completed"}),e.jsx("p",{className:"text-xs text-foreground",children:s.completion_date?O(new Date(s.completion_date),"dd MMM yyyy"):"—"})]})]}),m===s.id?e.jsx(Q,{className:"w-3 h-3 text-muted-foreground"}):e.jsx(P,{className:"w-3 h-3 text-muted-foreground"})]}),m===s.id&&e.jsxs("div",{className:"px-4 pb-5 border-t border-border bg-muted/20 space-y-5 pt-4",children:[s.total_weighted_scores&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-widest text-muted-foreground mb-3",children:"Total Weighted Scores"}),e.jsx("div",{className:"grid grid-cols-4 gap-3",children:Object.entries(s.total_weighted_scores).map(([a,g])=>e.jsxs("div",{className:"text-center border border-border p-2",children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground",children:a}),e.jsx("p",{className:"text-sm font-display text-foreground mt-0.5",children:g.toFixed(2)})]},a))})]}),s.identity_summary&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-widest text-muted-foreground mb-2",children:"Identity Summary"}),e.jsx("p",{className:"text-xs text-foreground leading-relaxed",children:s.identity_summary})]}),s.all_answers_snapshot&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-widest text-muted-foreground mb-3",children:"Written Calibration"}),y.filter(a=>a.question_type==="short_paragraph").map(a=>{const g=s.all_answers_snapshot[a.id];return g!=null&&g.text_response?e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground mb-1",children:a.question_text}),e.jsx("p",{className:"text-xs text-foreground leading-relaxed border-l-2 border-border pl-3",children:g.text_response})]},a.id):null})]})]})]},s.id))})]})}function te(){const[r,i]=u.useState(""),l=R(),{data:h=[],isLoading:b}=A({queryKey:["admin-retake-assessments"],queryFn:()=>f.entities.TRAAssessment.filter({status:"completed"},"-completion_date",200)}),v=C({mutationFn:({id:o,data:d})=>f.entities.TRAAssessment.update(o,d),onSuccess:()=>
2l.invalidateQueries({queryKey:["admin-retake-assessments"]})}),m=h.filter(o=>{var d;return!r||((d=o.user_id)==null?void 0:d.toLowerCase().includes(r.toLowerCase()))});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"relative max-w-md",children:[e.jsx(W,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground",strokeWidth:1.5}),e.jsx("input",{value:r,onChange:o=>i(o.target.value),placeholder:"Search by user ID...",className:"w-full text-xs bg-background border border-border pl-8 pr-3 py-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground/40"})]}),b?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(S,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-1",children:[m.map(o=>e.jsx("div",{className:"border border-border bg-card px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-start gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0 space-y-1",children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground",children:"User ID"}),e.jsx("p",{className:"text-xs text-foreground font-mono truncate",children:o.user_id}),e.jsxs("div",{className:"flex items-center gap-4 mt-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground",children:"Result"}),e.jsxs("p",{className:"text-xs text-foreground",children:[o.primary_tra," · ",o.secondary_tra]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground",children:"Completed"}),e.jsx("p",{className:"text-xs text-foreground",children:o.completion_date?O(new Date(o.completion_date),"dd MMM yyyy"):"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta text-muted-foreground",children:"Official"}),e.jsx("p",{className:"text-xs text-foreground",children:o.is_official?"Yes":"No"})]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>v.mutate({id:o.id,data:{retake_allowed:!o.retake_allowed}}),className:`text-[9px] font-meta uppercase tracking-widest px-3 py-1.5 border transition-all ${o.retake_allowed?"border-foreground bg-foreground text-background":"border-border text-muted-foreground hover:border-foreground
2/40 hover:text-foreground"}`,children:o.retake_allowed?"Retake Allowed":"Allow Retake"}),e.jsx("button",{onClick:()=>v.mutate({id:o.id,data:{is_official:!o.is_official}}),className:`text-[9px] font-meta uppercase tracking-widest px-3 py-1.5 border transition-all ${o.is_official?"border-foreground bg-foreground text-background":"border-border text-muted-foreground hover:border-foreground/40 hover:text-foreground"}`,children:o.is_official?"Official":"Mark Official"})]})]})},o.id)),m.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-12",children:"No completed assessments found."})]})]})}const se=["Perceptual Lens","Design Behaviour","Time Orientation","Translation Under Constraint","Tension Detection","Spatial Read","Written Calibration"];function re(){const[r,i]=u.useState(null),[l,h]=u.useState(null),[b,v]=u.useState({}),[m,o]=u.useState({}),d=R(),{data:p=[],isLoading:y}=A({queryKey:["tra-copy-configs"],queryFn:()=>f.entities.TRACopyConfig.filter({is_active:!0})});u.useEffect(()=>{if(p.length>0){const a=p[0];h(a.id),i({entry_screen_title:a.entry_screen_title||"",entry_screen_body:a.entry_screen_body||"",entry_screen_supporting_text:a.entry_screen_supporting_text||"",entry_screen_cta:a.entry_screen_cta||"",result_screen_headline:a.result_screen_headline||"",course_001_cta_url:a.course_001_cta_url||""}),v(a.section_intros||{}),o(a.explanatory_texts||{})}},[p]);const c=C({mutationFn:a=>l?f.entities.TRACopyConfig.update(l,a):f.entities.TRACopyConfig.create({...a,name:"V1 Copy",is_active:!0}),onSuccess:()=>d.invalidateQueries({queryKey:["tra-copy-configs"]})}),w=()=>{r&&c.mutate({...r,section_intros:b,explanatory_texts:m})};if(y)return e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(S,{className:"w-4 h-4 animate-spin text-muted-foreground"})});if(!r)return e.jsx("div",{className:"py-12 text-xs text-muted-foreground",children:"Run seedTRAQuestions to initialise copy configuration."});const s=({label:a,field:g,multiline:_=!1})=>e.jsxs("div",{children:[e.jsx("label",{children:a}),_?e.jsx("textarea",{value:r[g]||"",onChange:k=>i(j=>({...j,[g]:k.target.value})),rows:4,className:"w-full mt-1 text-xs bg-transparent border border-border px-3 py-2.5 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground
2/40 resize-none"}):e.jsx("input",{value:r[g]||"",onChange:k=>i(j=>({...j,[g]:k.target.value})),className:"w-full mt-1 text-xs bg-transparent border border-border px-3 py-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground/40"})]});return e.jsxs("div",{className:"space-y-8 max-w-2xl",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground",children:"Entry Screen"}),e.jsx(s,{label:"Title",field:"entry_screen_title"}),e.jsx(s,{label:"Body",field:"entry_screen_body",multiline:!0}),e.jsx(s,{label:"Supporting text",field:"entry_screen_supporting_text"}),e.jsx(s,{label:"CTA button text",field:"entry_screen_cta"}),e.jsx(s,{label:"'Begin with 001' button URL (external link)",field:"course_001_cta_url"})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground",children:"Result Screen"}),e.jsx(s,{label:"Headline",field:"result_screen_headline"})]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground",children:"Section Introductions"}),se.map(a=>e.jsxs("div",{children:[e.jsx("label",{children:a}),e.jsx("textarea",{value:b[a]||"",onChange:g=>v(_=>({..._,[a]:g.target.value})),rows:2,className:"w-full mt-1 text-xs bg-transparent border border-border px-3 py-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground
2/40 resize-none"})]},a))]}),e.jsx("div",{className:"h-px bg-border"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground",children:"Explanatory Texts"}),[{key:"retake_locked",label:"Retake locked message"},{key:"confidence_high",label:"High confidence explanation"},{key:"confidence_medium",label:"Medium confidence explanation"},{key:"confidence_low",label:"Low confidence explanation"}].map(({key:a,label:g})=>e.jsxs("div",{children:[e.jsx("label",{children:g}),e.jsx("textarea",{value:m[a]||"",onChange:_=>o(k=>({...k,[a]:_.target.value})),rows:2,className:"w-full mt-1 text-xs bg-transparent border border-border px-3 py-2 text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-foreground/40 resize-none"})]},a))]}),e.jsxs("button",{onClick:w,disabled:c.isPending,className:"flex items-center gap-2 px-6 py-2.5 bg-foreground text-background text-[10px] font-meta uppercase tracking-widest hover:opacity-80 disabled:opacity-40 transition-opacity",children:[c.isPending&&e.jsx(S,{className:"w-3 h-3 animate-spin"}),"Save Copy"]})]})}function ne(){const[r,i]=u.useState(!1),[l,h]=u.useState(null),b=async()=>{i(!0),h(null);const v=await f.functions.invoke("seedTRAQuestions",{});h(v.data),i(!1)};return e.jsx("div",{className:"space-y-6 max-w-xl",children:e.jsxs("div",{className:"border border-border p-5",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground mb-3",children:"Seed Diagnostic Questions"}),e.jsxs("p",{className:"text-xs text-muted-foreground leading-relaxed mb-5",children:["This will replace all existing TRA questions with the 27-question V1 diagnostic specification. It will also create default scoring and copy configurations if none exist.",e.jsx("br",{}),e.jsx("br",{}),e.jsx("strong",{className:"text-foreground",children:"Warning:"})," Existing questions will be deleted. Existing responses and assessments will remain unaffected."]}),e.jsxs("button",{onClick:b,disabled:r,className:"flex items-center gap-2 px-6 py-2.5 bg-foreground text-background text-[10px] font-meta uppercase tracking-widest hover:opacity-80 disabled:opacity-40 transition-opacity",children:[r&&e.jsx(S,{className:"w-3 h-3 animate-spin"}),r?"Seeding...":"Seed V1 Questions"]}),l&&e.jsx("p",{className:"text-xs text-muted-foreground mt-4",children:l.success?`✓ Seeded ${l.questions_created} questions.`:`Error: ${l.error}`})]})})}const ae=[{id:"overview",label:"Overview"},{id:"questions",label:"Questions"},{id:"scoring",label:"Scoring"},{id:"images",label:"Image Sets"},{id:"results",label:"Results"},{id:"retakes",label:"Retakes"},{id:"copy",label:"Copy"},{id:"seed",label:"Setup"}];function ie(){const[r,i]=u.useState("overview");return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("div",{className:"border-b border-border bg-background sticky top-0 z-20",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-6 lg:px-10",children:[e.jsxs("div",{className:"py-5 border-b border-border",children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.3em] text-muted-foreground mb-1",children:"Admin · TRA System"}),e.jsx("h1",{className:"text-xl font-display uppercase tracking-tight text-foreground",children:"TRA Identity Diagnostic"})]}),e.jsx("div",{className:"flex items-center gap-0 overflow-x-auto",style:{scrollbarWidth:"none"},children:ae.map(l=>e.jsx("button",{onClick:()=>i(l.id),className:`px-4 py-3.5 text-[9px] font-meta uppercase tracking-widest border-b-2 transition-all whitespace-nowrap ${r===l.id?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,children:l.label},l.id))})]})}),e.jsxs("div",{className:"max-w-7xl mx-auto px-6 lg:px-10 py-8",children:[r==="overview"&&e.jsx(B,{}),r==="questions"&&e.jsx(H,{}),r==="scoring"&&e.jsx(z,{}),r==="images"&&e.jsx(J,{}),r==="results"&&e.jsx(ee,{}),r==="retakes"&&e.jsx(te,{}),r==="copy"&&e.jsx(re,{}),r==="seed"&&e.jsx(ne,{})]})]})}export{ie as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.