PageSourceSearch

https://cdecad.com/assets/JailPage-BngvXLAA.js

js cdecad.com collected 2026-10-08 16:07:25 UTC 49,887 bytes, 1 lines download raw bytes

1import{r as c,j as e}from"./vendor-react-TXDxJ4pL.js";import{m as Le,j as Me,a3 as He,a2 as ce,aH as Oe}from"./vendor-icons--IBbgi4o.js";import{H as re,i6 as Je,i7 as Ue,J as Ke,c6 as n,i8 as Ve,i9 as qe,ia as Qe,ib as Ye,ic as Ge,id as Ze,ie as Xe,ig as et,ih as tt,ii as nt,ij as st,F as it,c7 as at,ik as rt}from"./index-DSQ6kcyn.js";import{u as lt,C as ot}from"./CadHeader-Cjh972dt.js";import{N as z,F as P,j as de,B as k,M as ye,q as V,g as fe,I as Ie,P as _,a as Re,o as je,f as Q,s as be,K as dt,b as X,E as me,C as ct}from"./kit-B0PIX36h.js";import{u as ht}from"./useSocketLink-eSQAEOSE.js";import{u as ut}from"./usePollWhileDown-BvQmKLC2.js";import{E as pt,r as ve,e as mt,m as H,p as xt,i as gt,h as xe,d as he,j as ze,c as ft,a as O,f as we,t as Ae,g as yt,k as oe,l as jt,n as bt,J as vt,o as ke}from"./JailBookSheet-B7lTbD5x.js";import{u as _e,j as wt}from"./useUploads-DIR33u1G.js";import{m as Ee}from"./mugshotSrc-BxHC8MR4.js";import{L as kt}from"./LicenseImageModal-DMNzZetY.js";import{P as St}from"./PrintLayer-D1DGjwWk.js";import{C as Se}from"./CivilianAutofill-BzuUuGeS.js";import{v as Ct,U as Ce}from"./uploadRefs-D6AeyZEr.js";import{l as $t}from"./smartcopMedia-2cC3Z7M5.js";import{a as Tt}from"./vendor-router-BfSjmGu8.js";import"./vendor-i18n-ZeuoPmU-.js";import"./vendor-axios-BCn5QfZZ.js";import"./vendor-toastify-zImE3QEX.js";import"./vendor-CYhC9tBg.js";import"./vendor-socket-Kk_l3rvZ.js";import"./vendor-helmet-COw7OOqs.js";import"./brandTheme-D_FUAiDP.js";import"./departmentConfig-D0qdBJcF.js";import"./Sheet-DFymStGV.js";import"./sheetGesture-BrdUEoTX.js";import"./dispatch43Board-BAdlKzuX.js";import"./dispatchStatuses-D-P2hyu9.js";import"./attachStatus-DCFith6Q.js";import"./cadPalette-De09FqSH.js";const Nt=3e4,Bt=3e4;function Lt(t){const[s,g]=c.useState(null),[y,u]=c.useState(pt),[m,i]=c.useState({loading:!0,error:"",refusal:null}),[S,x]=c.useState(()=>new Date),[b,v]=c.useState(null),f=c.useRef(0),{linkUp:C}=ht(re),j=c.useCallback(async()=>{if(!t)return;const r=++f.current;try{const h=await Je(t);if(r!==f.current)return;if(g(h),!h?.canRead){i({loading:!1,error:"",refusal:{code:h?.code||"JAIL_READ_REFUSED",message:h?.message||""}});return}const a=await Ue(t);if(r!==f.current)return;const w=a?.now?new Date(a.now):new Date;x(w),u(ve({intake:a?.intake||[],inCustody:a?.inCustody||[],due:a?.due||[],released:a?.released||[]},w)),i({loading:!1,error:"",refusal:null})}catch(h){if(r!==f.current)return;const a=mt(h);i({loading:!1,refusal:a,error:a?"":H(h,"The roster did not load. Try again in a moment.")})}},[t]);c.useEffect(()=>{j()},[j]),c.useEffect(()=>{const r=setInterval(()=>{const h=new Date;x(h),u(a=>ve(a,h))},Bt);return()=>clearInterval(r)},[]),c.useEffect(()=>{const r=()=>{document.visibilityState!=="hidden"&&j()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",r),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",r)}},[j]),c.useEffect(()=>{if(!re||!t)return;const r=Ke(re,t),h=a=>{a?.communityId&&String(a.communityId)!==String(t)||(v({...a,at:Date.now()}),j())};return re.on("jail-updated",h),()=>{re.off("jail-updated",h),r()}},[t,j]),ut(C,{enabled:!!t&&!!s?.canRead,intervalMs:Nt,poll:j});const $=c.useCallback(r=>{if(!r)return;const h=new Date;x(h),u(a=>xt(a,r,h))},[]);return{access:s,roster:y,now:S,changed:b,...m,reload:j,applyBooking:$}}function ue({value:t,name:s,size:g=44}){const y=_e(),u=Ee(t,y),[m,i]=c.useState(""),S={width:g,height:Math.round(g*1.2),minWidth:g,borderRadius:g>60?n.r.control:n.r.chip,background:n.press,color:n.sub,display:"inline-flex",alignItems:"center",justifyContent:"center",overflow:"hidden",flex:"none"};return!u||m===u?e.jsx("span",{role:"img","aria-label":s?`No photo on file for ${s}`:"No photo on file","data-photo":"none",style:{...S,fontWeight:700,fontSize:g*.36},children:e.jsx("span",{"aria-hidden":"true",children:gt(s)})}):e.jsx("span",{style:S,"data-photo":"shown",children:e.jsx("img",{src:u,alt:s?`Photo of ${s}`:"Photo on file",onError:()=>i(u),loading:"lazy",style:{width:"100%",height:"100%",objectFit:"cover"}})})}const It=t=>t.free>0?`${t.free} of ${t.beds} free`:"full";function We({communityId:t,booking:s,facilities:g,onSaved:y,actionLabel:u="Assign this cell"}){const m=s.housing||{},[i,S]=c.useState({facilityId:m.facilityId||g[0]?._id||"",unitId:m.unitId||"",cellId:""}),[x,b]=c.useState(!1),[v,f]=c.useState(""),[C,j]=c.useState(null),$=g.find(a=>a._id===i.facilityId)||null,r=$?.units.find(a=>a._id===i.unitId)||null;if(c.useEffect(()=>{$&&!r&&$.units[0]&&S(a=>({...a,unitId:$.units[0]._id,cellId:""}))},[$,r]),!g.length)return e.jsx(z,{tone:"warn",children:"There is no jail layout yet. Add a facility under Layout, with its units and cells, then house people in it."});const h=async(a=!1)=>{b(!0),f("");try{const w=await Ve(t,s._id,{...i,overrideSeparation:a});j(null),y(w)}catch(w){const d=w?.response?.data||{};d.code==="JAIL_KEEP_SEPARATE"?j(d.message):f(H(w,"The cell was not assigned. Try again."))}finally{b(!1)}};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:n.sp(3)},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(150px, 100%), 1fr))",gap:n.sp(3)},children:[e.jsx(P,{label:"Facility",children:e.jsx(de,{value:i.facilityId,onChange:a=>S({facilityId:a.target.value,unitId:"",cellId:""}),children:g.map(a=>e.jsx("option",{value:a._id,children:a.name},a._id))})}),e.jsx(P,{label:"Housing unit",children:e.jsx(de,{value:i.unitId,onChange:a=>S(w=>({...w,unitId:a.target.value,cellId:""})),children:($?.units||[]).map(a=>e.jsx("option",{value:a._id,children:`${a.name} (${a.free} free)`},a._id))})}),e.jsx(P,{label:"Cell",children:e.jsxs(de,{value:i.cellId,onChange:a=>S(w=>({...w,cellId:a.target.value})),children:[e.jsx("option",{value:"",children:"Pick a cell"}),(r?.cells||[]).map(a=>e.jsx("option",{value:a._id,disabled:a.free===0&&a._id!==m.cellId,children:`${a.name}, ${It(a)}`},a._id))]})})]}),v&&e.jsx(z,{tone:"danger",children:v}),C&&e.jsx(z,{tone:"warn",action:e.jsx(k,{size:"sm",onClick:()=>h(!0),disabled:x,children:"House together anyway"}),children:C}),e.jsx("div",{children:e.jsx(k,{onClick:()=>h(!1),disabled:x||!i.cellId,children:x?"Assigning…":u})})]})}const Rt=["minimum","medium","maximum"],zt=["identity","warrants","property","mugshot","classification","housing"],pe={i
1dentity:"Identity",warrants:"Warrant check",property:"Property",mugshot:"Mugshot",classification:"Classification",housing:"Housing"},Z={housed:"Housed","cell-move":"Moved cell",court:"Out to court",medical:"Out to medical",returned:"Returned","transfer-out":"Transferred out"};function De(t){const s=t?.intake||{};return{identity:!!t?.civilianId,warrants:!!s.warrantsCheckedAt,property:!!s.propertySealedAt,mugshot:!!(s.mugshotAt||t?.mugshotRef),classification:!!s.classification?.level,housing:!!t?.housing?.cellId}}function At(t){const s=De(t);return zt.filter(g=>!s[g])}function _t(t,s={}){return t?.status!=="in-custody"?t?.status==="intake"?"This person has not finished intake. Complete intake, or void the booking with a supervisor.":"This booking is already closed.":t.away?.type?`They are out (${Z[t.away.type].toLowerCase()}). Log their return before releasing them.`:(t.intake?.property?.items||[]).length&&s.propertyReturned!==!0?"Check off the property returned to them before releasing.":s.identityConfirmed!==!0?"Confirm the person in front of you matches the photo and date of birth on the booking.":null}const $e={minimum:"Minimum",medium:"Medium",maximum:"Maximum"},Et=t=>[t?.firstName,t?.lastName].filter(Boolean).join(" ");function te({n:t,step:s,done:g,children:y,summary:u}){return e.jsxs("section",{"aria-label":pe[s],"data-step":s,style:{border:`1px solid ${n.border}`,borderRadius:n.r.control,padding:n.sp(3),display:"flex",flexDirection:"column",gap:n.sp(2)},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:n.sp(2),justifyContent:"space-between",flexWrap:"wrap"},children:[e.jsx("h4",{style:{margin:0,fontSize:14.5,fontWeight:650},children:`${t}. ${pe[s]}`}),g?e.jsx(_,{tone:"good",children:"Done"}):e.jsx(_,{children:"To do"})]}),u&&e.jsx("div",{style:{fontSize:13.5,color:n.sub,lineHeight:1.5,overflowWrap:"anywhere"},children:u}),y]})}function Wt({communityId:t,booking:s,civilian:g,facilities:y,dark:u,onSaved:m}){const i=De(s),S=At(s),x=s.intake,[b,v]=c.useState(""),[f,C]=c.useState({step:"",message:""}),[j,$]=c.useState(()=>x.property.items.length?x.property.items:[]),[r,h]=c.useState(""),[a,w]=c.useState(x.property.bagNumber&&x.property.bagNumber!=="none"?x.property.bagNumber:""),[d,I]=c.useState(x.classification.level||"minimum"),[F,q]=c.useState(x.classification.keepSeparate||[]),[N,l]=c.useState(""),[E,J]=c.useState(""),{upload:Y}=wt(t),D=async(p,R)=>{v(p),C({step:"",message:""});try{m(await qe(t,s._id,p,R))}catch(A){C({step:p,message:H(A,"That step was not saved. Try again.")})}finally{v("")}},G=async p=>{const R=p.target.files?.[0];if(p.target.value="",!R)return;const A=Ct(R,Ce.civilianMugshot);if(A){C({step:"mugshot",message:A});return}v("mugshot");try{const M=await Y(R,Ce.civilianMugshot);await D("mugshot",{ref:M})}catch(M){C({step:"mugshot",message:H(M,M?.message||"The photo did not upload. Try again.")}),v("")}},B=async()=>{v("complete"),C({step:"",message:""});try{m(await Qe(t,s._id))}catch(p){C({step:"complete",message:H(p,"Intake was not completed. Try again.")})}finally{v("")}},W=p=>f.step===p?e.jsx(z,{tone:"danger",children:f.message}):null,ie=()=>{const p=r.trim();p&&($(R=>[...R,{description:p,quantity:1}]),h(""))};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:n.sp(3)},children:[e.jsxs("p",{style:{margin:0,color:n.sub,fontSize:14,lineHeight:1.5},children:[s.autoBooked?"Opened automatically when the arrest report was filed. ":"","The sentence starts when intake is complete, not before."]}),e.jsxs(te,{n:1,step:"identity",done:i.identity,summary:i.identity?`Linked to the civilian record of ${s.subjectName}.`:`The arrest named ${s.subjectName||"someone"} without a civilian record. Find them in records.`,children:[!i.identity&&e.jsx(P,{label:"Civilian record",children:e.jsx(Se,{value:E,onChange:J,communityId:t,dark:u,ariaLabel:"Civilian record",placeholder:"Search records by name",onSelect:p=>D("identity",{civilianId:String(p._id||p.id)})})}),W("identity")]}),e.jsxs(te,{n:2,step:"warrants",done:i.warrants,summary:i.warrants?`Checked by ${x.warrantsCheckedByName}. ${x.warrants.length?"":"No warrants found."}`:"Look up warrants for this person: those the arrest cleared and any still outstanding.",children:[x.warrants.length>0&&e.jsx("ul",{style:{margin:0,paddingLeft:n.sp(5),fontSize:13.5,lineHeight:1.6},children:x.warrants.map(p=>e.jsxs("li",{children:[e.jsx(ye,{style:{color:n.text},children:p.caseNumber})," ",p.state,p.charges?.length?`: ${p.charges.join(", ")}`:""]},p.reportId))}),e.jsx("div",{children:e.jsx(k,{size:"sm",onClick:()=>D("warrants",{}),disabled:!!b||!i.identity,children:i.warrants?"Check again":"Run the warrant check"})}),W("warrants")]}),e.jsxs(te,{n:3,step:"property",done:i.property,summary:i.property?x.property.items.length?`${x.property.items.length} items sealed in bag ${x.property.bagNumber} by ${x.propertySealedByName}.`:"Nothing taken from them.":"List what was taken from them, seal it in a bag and write down the bag number.",children:[e.jsx("ul",{"aria-label":"Property",style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:n.sp(1)},children:j.map((p,R)=>e.jsxs("li",{style:{display:"flex",alignItems:"center",gap:n.sp(2),fontSize:14},children:[e.jsxs("span",{style:{flex:1,minWidth:0,overflowWrap:"anywhere"},children:[p.quantity>1?`${p.quantity} x `:"",p.description]}),e.jsx(k,{size:"sm",onClick:()=>$(A=>A.filter((M,ge)=>ge!==R)),children:"Remove"})]},`${p.description}-${R}`))}),e.jsxs("div",{style:{display:"flex",gap:n.sp(2),flexWrap:"wrap"},children:[e.jsx("div",{style:{flex:"1 1 180px"},children:e.jsx(V,{"aria-label":"Item",value:r,placeholder:"Wallet, phone, keys",onChange:p=>h(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),ie())}})}),e.jsx(k,{onClick:ie,disabled:!r.trim(),children:"Add item"})]}),e.jsx(P,{label:"Sealed bag number",hint:j.length?"The number printed on the bag the items went into.":"Leave empty when nothing was taken.",children:e.jsx(V,{value:a,onChange:p=>w(p.target.value),placeholder:"BAG-0031"})}),e.jsx("div",{children:e.jsx(k,{size:"sm",onClick:()=>D("property",{items:j,bagNumber:a}),disabled:!!b,children:j.length?"Seal the bag":"Nothing taken"})}),W("property")]}),e.jsxs(te,{n:4,step:"mugshot",done:i.mugshot,summary:i.mugshot?"Photo taken for this booking.":"Take a booking photo, or use the one on their record.",children:[e.jsxs("div",{style:{display:"flex",gap:n.sp(3),alignItems:"center",flexWrap:"wrap"},children:[e.jsx(ue,{value:s.mugshotRef||g?.mugshotUrl,name:s.subjectName,size:64}),e.jsxs("div",{style:{display:"flex",gap:n.sp(2),flexWrap:"wrap"},children:[g?.mugshotUrl&&e.jsx(k,{size:"sm",onClick:()=>D("mugshot",{useRecordPhoto:!0}),disabled:!!b,children:"Use the photo on record"}),e.jsxs("label",{className:"adm-btn",style:{display:"inline-flex",alignItems:"center",gap:n.sp(2),fontSize:13,fontWeight:600,padding:`${n.sp(1.5)}px ${n.sp(3)}px`,borderRadius:999,border:`1px solid ${n.border}`,background:n.field,cursor:"pointer"},children:[b==="mugshot"?"Uploading…":"Upload a new photo",e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp",onChange:G,style:{display:"none"},disabled:!!b})]})]})]}),W("mugshot")]}),e.jsxs(te,{n:5,step:"classification",done:i.classification,summary:i.
1classification?`${$e[x.classification.level]} security${x.classification.keepSeparate.length?`, kept apart from ${x.classification.keepSeparate.map(p=>p.name).join(", ")}`:""}.`:"Set the security level, and anyone they must be kept apart from.",children:[e.jsx(fe,{ariaLabel:"Security level",value:d,onChange:I,options:Rt.map(p=>({value:p,label:$e[p]})),wrap:!0}),e.jsx(P,{label:"Keep separate from",hint:"Picked from records. Housing warns before putting them in the same unit.",children:e.jsx(Se,{value:N,onChange:l,communityId:t,dark:u,ariaLabel:"Keep separate from",placeholder:"Search records by name",onSelect:p=>{const R=String(p._id||p.id);q(A=>A.some(M=>M.civilianId===R)?A:[...A,{civilianId:R,name:Et(p),reason:""}]),l("")}})}),F.length>0&&e.jsx("ul",{"aria-label":"Kept separate",style:{margin:0,padding:0,listStyle:"none",display:"flex",gap:n.sp(2),flexWrap:"wrap"},children:F.map(p=>e.jsxs("li",{style:{display:"inline-flex",alignItems:"center",gap:n.sp(1),background:n.press,borderRadius:n.r.chip,padding:`2px ${n.sp(1)}px 2px ${n.sp(2)}px`,fontSize:13},children:[p.name,e.jsx(Ie,{size:24,label:`Remove ${p.name}`,icon:e.jsx(Le,{"aria-hidden":"true"}),style:{border:"none",background:"transparent"},onClick:()=>q(R=>R.filter(A=>A.civilianId!==p.civilianId))})]},p.civilianId))}),e.jsx("div",{children:e.jsx(k,{size:"sm",onClick:()=>D("classification",{level:d,keepSeparate:F}),disabled:!!b,children:"Save classification"})}),W("classification")]}),e.jsx(te,{n:6,step:"housing",done:i.housing,summary:i.housing?`Housed in ${xe(s.housing)}.`:"Pick a cell with a free bed.",children:e.jsx(We,{communityId:t,booking:s,facilities:y,onSaved:m,actionLabel:i.housing?"Move to this cell":"Assign this cell"})}),W("complete"),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:n.sp(3),flexWrap:"wrap"},children:[e.jsx(k,{kind:"primary",icon:e.jsx(Me,{"aria-hidden":"true"}),onClick:B,disabled:S.length>0||!!b,children:b==="complete"?"Completing…":"Complete intake"}),S.length>0&&e.jsx("span",{style:{fontSize:13,color:n.sub},children:`Left to do: ${S.map(p=>pe[p].toLowerCase()).join(", ")}.`})]})]})}const Dt={minimum:"Minimum",medium:"Medium",maximum:"Maximum"},ne=t=>t?new Date(t).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"}):"",Pt=t=>t?new Date(t).toLocaleDateString(void 0,{timeZone:"UTC",dateStyle:"medium"}):"",se="#111",Pe="1px solid #999",U={textAlign:"left",padding:"4px 6px",borderBottom:Pe,fontSize:11,textTransform:"uppercase",letterSpacing:"0.04em",color:"#444"},K={padding:"4px 6px",borderBottom:"1px solid #ddd",fontSize:12,verticalAlign:"top"};function L({label:t,value:s}){return e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"130px 1fr",gap:8,fontSize:12,padding:"2px 0"},children:[e.jsx("span",{style:{color:"#555"},children:t}),e.jsx("span",{style:{color:se,overflowWrap:"anywhere"},children:s||"-"})]})}function le({title:t,children:s}){return e.jsxs("section",{style:{marginTop:14},children:[e.jsx("h2",{style:{margin:"0 0 6px",fontSize:13,textTransform:"uppercase",letterSpacing:"0.06em",borderBottom:`2px solid ${se}`,paddingBottom:3},children:t}),s]})}function Ft({booking:t,civilian:s,communityName:g}){const y=_e(),u=Ee(t.mugshotRef||s?.mugshotUrl||"",y),m=t.intake;return e.jsxs("article",{"data-face-sheet":!0,style:{fontFamily:"Helvetica, Arial, sans-serif",color:se,background:"#fff",width:"100%",maxWidth:760,margin:"0 auto"},children:[e.jsxs("header",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-end",borderBottom:`3px solid ${se}`,paddingBottom:6},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:"0.08em",color:"#444"},children:g||"Booking record"}),e.jsx("h1",{style:{margin:0,fontSize:22},children:"Booking face sheet"})]}),e.jsxs("div",{style:{textAlign:"right",fontSize:12},children:[e.jsx("div",{style:{fontFamily:"ui-monospace, Menlo, monospace",fontSize:16,fontWeight:700},children:t.bookingNumber}),e.jsxs("div",{children:["Printed ",ne(new Date().toISOString())]})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"120px 1fr 1fr",gap:14,marginTop:12},children:[e.jsx("div",{style:{width:120,height:150,border:Pe,display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",fontSize:11,color:"#666"},children:u?e.jsx("img",{src:u,alt:`Photo of ${t.subjectName}`,style:{width:"100%",height:"100%",objectFit:"cover"}}):"No photo"}),e.jsxs("div",{children:[e.jsx(L,{label:"Name",value:t.subjectName}
1),e.jsx(L,{label:"Date of birth",value:Pt(t.subjectDob)}),e.jsx(L,{label:"Status",value:{intake:"In intake","in-custody":"In custody",released:"Released",transferred:"Transferred out"}[t.status]}),e.jsx(L,{label:"Classification",value:m.classification.level?`${Dt[m.classification.level]} security`:""}),e.jsx(L,{label:"Keep separate",value:(m.classification.keepSeparate||[]).map(i=>i.name).join(", ")})]}),e.jsxs("div",{children:[e.jsx(L,{label:"Booked",value:ne(t.bookedAt)}),e.jsx(L,{label:"Booked by",value:t.bookedByName}),e.jsx(L,{label:"Arrest report",value:t.arrestCaseNumber}),e.jsx(L,{label:"Housing",value:xe(t.housing)}),e.jsx(L,{label:"Sentence",value:he(t.sentenceMinutes)}),e.jsx(L,{label:"Release due",value:ne(t.releaseDueAt)})]})]}),e.jsx(le,{title:"Charges",children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:U,children:"Code"}),e.jsx("th",{style:U,children:"Charge"}),e.jsx("th",{style:U,children:"Severity"}),e.jsx("th",{style:{...U,textAlign:"right"},children:"Jail time"})]})}),e.jsx("tbody",{children:t.charges.map((i,S)=>e.jsxs("tr",{children:[e.jsx("td",{style:K,children:i.code}),e.jsx("td",{style:K,children:i.description}),e.jsx("td",{style:K,children:i.severity}),e.jsx("td",{style:{...K,textAlign:"right"},children:ze(i.minutes)})]},`${i.code}-${S}`))})]})}),e.jsx(le,{title:"Warrant check",children:m.warrantsCheckedAt?m.warrants.length?m.warrants.map(i=>e.jsx(L,{label:i.caseNumber,value:`${i.state}${i.charges?.length?`: ${i.charges.join(", ")}`:""}`},i.reportId)):e.jsx(L,{label:"Result",value:`No warrants found, checked ${ne(m.warrantsCheckedAt)} by ${m.warrantsCheckedByName}`}):e.jsx(L,{label:"Result",value:"Not checked"})}),e.jsxs(le,{title:"Property",children:[e.jsx(L,{label:"Bag number",value:m.property.bagNumber==="none"?"No property taken":m.property.bagNumber}),m.property.items.map((i,S)=>e.jsx(L,{label:`Item ${S+1}`,value:`${i.quantity>1?`${i.quantity} x `:""}${i.description}`},S)),t.status==="released"&&e.jsx(L,{label:"Returned",value:t.releasePropertyReturned?`Signed off at release by ${t.releasedByName}`:""})]}),e.jsx(le,{title:"Movements",children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:U,children:"When"}),e.jsx("th",{style:U,children:"Movement"}),e.jsx("th",{style:U,children:"From"}),e.jsx("th",{style:U,children:"To"}),e.jsx("th",{style:U,children:"By"})]})}),e.jsx("tbody",{children:t.movements.map((i,S)=>e.jsxs("tr",{children:[e.jsx("td",{style:K,children:ne(i.at)}),e.jsx("td",{style:K,children:Z[i.type]||i.type}),e.jsx("td",{style:K,children:i.from}),e.jsx("td",{style:K,children:i.to}),e.jsx("td",{style:K,children:i.byName})]},i._id||S))})]})}),(t.status==="released"||t.status==="transferred")&&e.jsxs(le,{title:"Release",children:[e.jsx(L,{label:"Released",value:ne(t.releasedAt)}),e.jsx(L,{label:"By",value:t.releasedByName}),e.jsx(L,{label:"Note",value:t.releaseNote}),e.jsx(L,{label:"Identity",value:t.releaseIdentityConfirmed?"Confirmed against the booking photo and date of birth":""})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:24,marginTop:28,fontSize:11,color:"#444"},children:[e.jsx("div",{style:{borderTop:`1px solid ${se}`,paddingTop:4},children:"Booking officer"}),e.jsx("div",{style:{borderTop:`1px solid ${se}`,paddingTop:4},children:"Person booked"})]})]})}const Mt={opened:"Intake opened",intake:"Intake step",booked:"Booked into custody",released:"Released",edited:"Notes edited",moved:"Moved",transferred:"Transferred out"},Ht={minimum:"Minimum",medium:"Medium",maximum:"Maximum"},Te=t=>{if(!t)return"";const s=new Date(t);return Number.isNaN(s.getTime())?"":s.toLocaleDateString(void 0,{timeZone:"UTC"})},Ot=(t,s)=>s==="released"?e.jsx(_,{children:t.status==="transferred"?"Transferred out":"Released"}):s==="intake"?e.jsx(_,{tone:"accent",children:"In intake"}):s==="due"?e.jsx(_,{tone:"warn",children:"Due for release"}):e.jsx(_,{tone:"accent",children:"In custody"});function Jt({communityId:t,bookingId:s,canWrite:g,facilities:y=[],dark:u=!0,communityName:m="",onClose:i,onChanged:S,refreshKey:x=0}){const[b,v]=c.useState({booking:null,civilian:null,loading:!0,error:""}),[f,C]=c.useState("view"),[j,$]=c.useState({notes:"",note:"",to:"",propertyReturned:!1,identityConfirmed:!1,returned:{}}),[r,h]=c.useState(!1),[a,w]=c.useState(""),[d,I]=c.useState(null),[F,q]=c.useState(!1),N=new Date;c.useEffect(()=>{let o=!0;return Ye(t,s).then(T=>{o&&v({booking:T.booking,civilian:T.civilian,loading:!1,error:""})}).catch(T=>{o&&v(ee=>
1({...ee,loading:!1,error:H(T,"That booking did not load. Try again.")}))}),()=>{o=!1}},[t,s,x]),c.useEffect(()=>{if(!F)return;const o=setTimeout(()=>{window.print(),q(!1)},50);return()=>clearTimeout(o)},[F]);const l=b.booking,E=l?ft(l,N):null,J=l?.status==="in-custody",Y=g&&J,D=l?.intake?.property?.items||[],G=o=>{v(T=>({...T,booking:o})),C("view"),w(""),S?.(o)},B=async(o,T)=>{h(!0),w("");try{G(await o())}catch(ee){const ae=ee?.response?.data?.booking;ae&&v(Fe=>({...Fe,booking:ae})),w(H(ee,T))}finally{h(!1)}},W=()=>{$(o=>({...o,note:E==="due"?"Sentence served":"",propertyReturned:!1,identityConfirmed:!1,returned:{}})),w(""),C("release")},ie=D.every((o,T)=>j.returned[T]),p=()=>{const o=yt(j.note)||_t(l,{propertyReturned:ie,identityConfirmed:j.identityConfirmed});if(o){w(o);return}B(()=>Ge(t,l._id,{note:j.note.trim(),propertyReturned:ie,identityConfirmed:j.identityConfirmed}),"The release was not saved. Try again.")},R=o=>B(()=>Ze(t,l._id,{type:o,note:j.note.trim(),to:j.to.trim()}),"That movement was not saved. Try again.");let A=e.jsx(k,{onClick:i,children:"Close"});Y&&f==="view"?A=e.jsxs(e.Fragment,{children:[e.jsx(k,{onClick:()=>{$(o=>({...o,note:"",to:""})),C("move")},children:"Log a movement"}),e.jsx(k,{onClick:()=>{$(o=>({...o,notes:l.notes||""})),C("edit")},children:"Edit notes"}),e.jsx(k,{kind:"primary",onClick:W,children:"Release"})]}):Y&&f==="edit"?A=e.jsxs(e.Fragment,{children:[e.jsx(k,{onClick:()=>C("view"),children:"Cancel"}),e.jsx(k,{kind:"primary",disabled:r,onClick:()=>B(()=>Xe(t,l._id,{notes:j.notes}),"That change was not saved. Try again."),children:r?"Saving…":"Save"})]}):Y&&(f==="release"||f==="move"||f==="cell")&&(A=e.jsxs(e.Fragment,{children:[e.jsx(k,{onClick:()=>C("view"),children:"Cancel"}),f==="release"&&e.jsx(k,{kind:"primary",onClick:p,disabled:r,children:r?"Releasing…":"Release now"})]}));const M=l?.subjectName||"Unknown person",ge=$t(b.civilian);return e.jsxs(Re,{title:l?`Booking ${l.bookingNumber}`:"Booking",onClose:i,footer:A,width:720,children:[b.loading&&e.jsx("div",{role:"status",style:{color:n.sub,fontSize:14},children:"Loading the booking…"}),b.error&&e.jsx(z,{tone:"danger",children:b.error}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",gap:n.sp(4),alignItems:"flex-start",flexWrap:"wrap"},children:[e.jsx(ue,{value:l.mugshotRef||b.civilian?.mugshotUrl,name:M,size:88}),e.jsxs("div",{style:{minWidth:0,flex:"1 1 180px"},children:[e.jsx("div",{style:{fontSize:20,fontWeight:700,letterSpacing:"-0.02em",overflowWrap:"anywhere"},children:M}),l.subjectDob&&e.jsxs("div",{style:{fontSize:13.5,color:n.sub,marginTop:2},children:["Born ",Te(l.subjectDob)]}),e.jsxs("div",{style:{display:"flex",gap:n.sp(2),flexWrap:"wrap",marginTop:n.sp(2)},children:[Ot(l,E),l.intake.classification.level&&e.jsx(_,{children:`${Ht[l.intake.classification.level]} security`}),l.away&&e.jsx(_,{tone:"warn",children:Z[l.away.type]}),l.releasedEarly&&e.jsx(_,{children:"Released early"})]}),e.jsxs("div",{style:{display:"flex",gap:n.sp(2),flexWrap:"wrap",marginTop:n.sp(3)},children:[ge.map(o=>e.jsx(k,{size:"sm",onClick:()=>I(o),children:o.label},o.type)),e.jsx(k,{size:"sm",icon:e.jsx(He,{"aria-hidden":"true"}),onClick:()=>q(!0),children:"Print face sheet"})]})]})]}),E==="due"&&f==="view"&&e.jsxs(z,{tone:"warn",children:["Their sentence was served at ",O(l.releaseDueAt,N),". Nobody is released automatically",g?", so release them here when they are out of the cell.":". A corrections officer releases them."]}),a&&e.jsx(z,{tone:"danger",children:a}),l.status==="intake"&&(g?e.jsx(Wt,{communityId:t,booking:l,civilian:b.civilian,facilities:y,dark:u,onSaved:G},l._id):e.jsx(z,{children:"Intake is in progress. A corrections officer finishes it and the sentence starts then."})),f==="edit"&&e.jsx(P,{label:"Notes",hint:"Seen by everyone who can read this booking.",children:e.jsx(je,{rows:3,value:j.notes,onChange:o=>$(T=>({...T,notes:o.target.value}))})}),f==="move"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:n.sp(3)},children:[e.jsx(P,{label:"Note",hint:"Optional. Kept on the movement log.",children:e.jsx(V,{value:j.note,onChange:o=>$(T=>({...T,note:o.target.value})),placeholder:"Arraignment, courtroom 2"})}),e.jsx("div",{style:{display:"flex",gap:n.sp(2),flexWrap:"wrap"},children:l.away?e.jsx(k,{onClick:()=>R("returned"),disabled:r,children:"Returned to the facility"}):e.jsxs(e.Fragment,{children:[e.jsx(k,{onClick:()=>R("court"),disabled:r,children:"Out to court"}),e.jsx(k,{onClick:()=>R("medical"),disabled:r,children:"Out to medical"}),e.jsx(k,{onClick:()=>C("cell"),disabled:r,children:"Move cell"})]})}),e.jsx(P,{label:"Transfer out to",hint:"Ends custody here: they leave for another agency.",children:e.jsxs("div",{style:{display:"flex",gap:n.sp(2),flexWrap:"wrap"},children:[e.jsx("div",{style:{flex:"1 1 180px"},children:e.jsx(V,{"aria-label":"Transfer destination",value:j.to,onChange:o=>$(T=>({...T,to:o.target.value})),placeholder:"State prison"})}),e.jsx(k,{kind:"danger",onClick:()=>R("transfer-out"),disabled:r||!j.to.trim(),children:"Transfer out"})]})})]}),f==="cell"&&e.jsx(We,{communityId:t,booking:l,facilities:y,onSaved:G,actionLabel:"Move to this cell"}),f==="release"&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:n.sp(3)},children:[we(l,N)>0&&e.jsxs(z,{tone:"warn",children:[he(we(l,N))," of the sentence is left. Releasing now is recorded as an early release."]}),e.jsxs("div",{children:[e.jsx(Q,{children:D.length?`Property in bag ${l.intake.property.bagNumber}`:"Property"}),D.length?e.jsx("div",{role:"group","aria-label":"Property returned",style:{display:"flex",flexDirection:"column",gap:n.sp(1)},children:D.map((o,T)=>e.jsx(be,{checked:!!j.returned[T],label:`${o.quantity>1?`${o.quantity} x `:""}${o.description} handed back`,onChange:ee=>$(ae=>({...ae,returned:{...ae.returned,[T]:ee}}))},T))}):e.jsx("p",{style:{margin:0,fontSize:13.5,color:n.sub},children:"Nothing was taken at intake."})]}),e.jsxs("div",{children:[e.jsx(Q,{children:"Identity"}),e.jsxs("div",{style:{display:"flex",gap:n.sp(3),alignItems:"center",flexWrap:"wrap"},children:[e.jsx(ue,{value:l.mugshotRef||b.civilian?.mugshotUrl,name:M,size:56}),e.jsx(be,{checked:j.identityConfirmed,label:`The person in front of me is ${M}, born ${Te(l.subjectDob)||"as on the record"}`,onChange:o=>$(T=>({...T,identityConfirmed:o}))})]})]}),e.jsx(P,{label:"Release note",hint:"Why they are going, for example bail posted or a court order. Kept on the booking and in the audit log.",children:e.jsx(je,{rows:2,value:j.note,onChange:o=>$(T=>({...T,note:o.target.value}))})})]}),e.jsxs("div",{children:[e.jsx(Q,{children:"Custody"}),e.jsx(dt,{items:[l.status==="intake"?["Intake opened",O(l.openedAt,N)]:["Booked",[O(l.bookedAt,N),l.bookedByName&&`by ${l.bookedByName}
1`].filter(Boolean).join(" ")],["Sentence",he(l.sentenceMinutes)],l.releaseDueAt?["Release due",O(l.releaseDueAt,N)]:["Release due","Set when intake is complete"],J?["Time left",Ae(l,N)]:null,["Housing",xe(l.housing)],l.away?["Out of the facility",`${Z[l.away.type]} since ${O(l.away.since,N)}`]:null,E==="released"?["Released",[O(l.releasedAt,N),l.releasedByName&&`by ${l.releasedByName}`].filter(Boolean).join(" ")]:null,E==="released"?["Release note",l.releaseNote]:null,["Arrest report",l.arrestCaseNumber,{mono:!0}],["Property bag",l.intake.property.bagNumber==="none"?"No property":l.intake.property.bagNumber],["Notes",l.notes]]})]}),e.jsxs("div",{children:[e.jsx(Q,{children:"Charges"}),e.jsx("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:n.sp(2)},children:l.charges.map((o,T)=>e.jsxs("li",{style:{display:"flex",justifyContent:"space-between",gap:n.sp(3),fontSize:14},children:[e.jsxs("span",{style:{minWidth:0,overflowWrap:"anywhere"},children:[e.jsx(ye,{children:o.code})," ",o.description]}),e.jsx("span",{style:{whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums",color:n.sub},children:ze(o.minutes)})]},`${o.code}-${T}`))})]}),l.movements.length>0&&e.jsxs("div",{children:[e.jsx(Q,{children:"Movements"}),e.jsx("ol",{"aria-label":"Movement log",style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:n.sp(2)},children:l.movements.map((o,T)=>e.jsxs("li",{style:{fontSize:13.5,lineHeight:1.45},children:[e.jsx("span",{style:{fontWeight:600},children:Z[o.type]||o.type}),(o.from||o.to)&&e.jsx("span",{style:{color:n.sub},children:` ${[o.from,o.to].filter(Boolean).join(" to ")}`}),o.note&&e.jsx("span",{style:{display:"block",overflowWrap:"anywhere"},children:o.note}),e.jsx("span",{style:{display:"block",fontSize:12.5,color:n.subtle},children:[o.byName,O(o.at,N)].filter(Boolean).join(" · ")})]},o._id||T))})]}),e.jsxs("div",{children:[e.jsx(Q,{children:"History"}),e.jsx("ol",{"aria-label":"Booking history",style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:n.sp(2)},children:l.log.map((o,T)=>e.jsxs("li",{style:{fontSize:13.5,lineHeight:1.45},children:[e.jsx("span",{style:{fontWeight:600},children:Mt[o.action]||o.action}),o.note&&e.jsx("span",{style:{display:"block",color:n.text,overflowWrap:"anywhere"},children:o.note}),e.jsx("span",{style:{display:"block",fontSize:12.5,color:n.subtle},children:[o.byName,O(o.at,N)].filter(Boolean).join(" · ")})]},o._id||T))})]}),e.jsx(St,{page:"A4 portrait",margin:"12mm",children:e.jsx(Ft,{booking:l,civilian:b.civilian,communityName:m})})]}),d&&b.civilian&&e.jsx(kt,{civilianId:b.civilian._id,licenseType:d.type,licenseLabel:d.label,license:d.license,civilian:b.civilian,onClose:()=>I(null)})]})}const Ut={minimum:"Min",medium:"Med",maximum:"Max"},Ne=t=>({name:`Block ${String.fromCharCode(65+t)}`,cells:[{name:`${String.fromCharCode(65+t)}-1`,beds:2}]});function Kt({cell:t,onOpen:s}){const g=t.over?n.danger:t.free===0?n.warn:n.good;return e.jsxs("div",{"data-cell":t.name,style:{border:`1px solid ${n.border}`,borderTop:`3px solid ${g}`,borderRadius:n.r.control,background:n.card,padding:n.sp(2),minWidth:0,display:"flex",flexDirection:"column",gap:n.sp(1)},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:n.sp(1),alignItems:"baseline"},children:[e.jsx("span",{style:{fontWeight:650,fontSize:14},children:t.name}),e.jsx("span",{style:{fontSize:12,color:t.over?n.dangerText:n.sub},children:t.over?`${t.people.length} in ${t.beds} beds`:t.free===0?"Full":`${t.free} of ${t.beds} free`})]}),t.people.length===0&&e.jsx("span",{style:{fontSize:12.5,color:n.subtle},children:"Empty"}),t.people.map(y=>e.jsxs("button",{type:"button",className:"adm-btn",onClick:()=>s?.(y.bookingId),style:{textAlign:"left",background:"transparent",border:"none",padding:0,color:n.text,cursor:s?"pointer":"default",fontFamily:"inherit",fontSize:13,display:"flex",gap:n.sp(1),flexWrap:"wrap",alignItems:"center"},children:[e.jsx("span",{style:{overflowWrap:"anywhere"},children:y.name}),y.level&&e.jsx("span",{style:{fontSize:11,color:n.sub},children:Ut[y.level]}),y.status==="intake"&&e.jsx("span",{style:{fontSize:11,color:n.sub},children:"intake"}),y.away&&e.jsx("span",{style:{fontSize:11,color:n.warnText},children:Z[y.away]})]},y.bookingId))]})}function Vt({communityId:t,facility:s,onClose:g,onSaved:y,onRemoved:u}){const[m,i]=c.useState(()=>s?{_id:s._id,name:s.name,units:s.units.map(r=>({_id:r._id,name:r.name,cells:r.cells.map(h=>({_id:h._id,name:h.name,beds:h.beds}))}))}:{name:"",units:[Ne(0)]}),[S,x]=c.useState(!1),[b,v]=c.useState(""),f=(r,h)=>i(a=>({...a,units:a.units.map((w,d)=>d===r?{...w,...h}:w)})),C=(r,h,a)=>f(r,{cells:m.units[r].cells.map((w,d)=>d===h?{...w,...a}:w)}),j=async()=>{x(!0),v("");try{y(await tt(t,{...m,units:m.units.map(r=>({...r,cells:r.cells.map(h=>({...h,beds:Number(h.beds)}))}))}))}catch(r){v(H(r,"The layout was not saved. Try again."))}finally{x(!1)}},$=async()=>{x(!0),v("");try{await et(t,s._id),u(s._id)}catch(r){v(H(r,"The facility was not removed. Try again."))}finally{x(!1)}};return e.jsxs(Re,{title:s?`Edit ${s.name}`:"Add a facility",onClose:g,width:720,footer:e.jsxs(e.Fragment,{children:[s&&e.jsx(k,{kind:"danger",onClick:$,disabled:S,children:"Remove facility"}),e.jsx(k,{onClick:g,children:"Cancel"}),e.jsx(k,{kind:"primary",onClick:j,disabled:S,children:S?"Saving…":"Save layout"})]}),children:[e.jsx("p",{style:{margin:0,color:n.sub,fontSize:14,lineHeight:1.5},children:"Housing units hold cells; each cell has a number of beds. A cell with people in it cannot be removed or given fewer beds than people."}),b&&e.jsx(z,{tone:"danger",children:b}),e.jsx(P,{label:"Facility name",children:e.jsx(V,{value:m.name,onChange:r=>i(h=>({...h,name:r.target.value})),placeholder:"County jail"})}),m.units.map((r,h)=>e.jsxs("section",{"aria-label":`Unit ${r.name||h+1}`,style:{border:`1px solid ${n.border}`,borderRadius:n.r.control,padding:n.sp(3),display:"flex",flexDirection:"column",gap:n.sp(2)},children:[e.jsxs("div",{style:{display:"flex",gap:n.sp(2),alignItems:"flex-end",flexWrap:"wrap"},children:[e.jsx(P,{label:"Housing unit",style:{flex:"1 1 180px"},children:e.jsx(V,{value:r.name,onChange:a=>f(h,{name:a.target.value})})}),e.jsx(k,{size:"sm",onClick:()=>i(a=>({...a,units:a.units.filter((w,d)=>d!==h)})),children:"Remove unit"})]}),r.cells.map((a,w)=>e.jsxs("div",{style:{display:"flex",gap:n.sp(2),alignItems:"center",flexWrap:"wrap"},children:[e.jsx("div",{style:{flex:"1 1 120px"},children:e.jsx(V,{"aria-label":`Cell name in ${r.name}`,value:a.name,onChange:d=>C(h,w,{name:d.target.value})})}),e.jsx("div",{style:{width:96},children:e.jsx(V,{"aria-label":`Beds in ${a.name||"cell"}`,type:"number",min:1,max:50,value:a.beds,onChange:d=>C(h,w,{beds:d.target.value})})}),e.jsx("span",{style:{fontSize:12.5,color:n.sub},children:"beds"}),e.jsx(Ie,{label:`Remove ${a.name||"cell"}`,size:32,icon:e.jsx(Le,{"aria-hidden":"true"}),onClick:()=>f(h,{cells:r.cells.filter((d,I)=>I!==w)})})]},a._id||`c-${w}`)),e.jsx("div",{children:e.jsx(k,{size:"sm",icon:e.jsx(ce,{"aria-hidden":"true"}),onClick:()=>f(h,{cells:[...r.cells,{name:`${(r.name.match(/\b(\w)\w*$/)||[])[1]||"C"}-${r.cells.length+1}`,beds:2}]}),children:"Add cell"})})]},r._id||`new-${h}`)),e.jsx("div",{children:e.jsx(k,{icon:e.jsx(ce,{"aria-hidden":"true"}),onClick:()=>i(r=>({...r,units:[...r.units,Ne(r.units.length)]})),children:"Add housing unit"})})]})}function qt({communityId:t,facilities:s,canWrite:g,loading:y,error:u,onChanged:m,onOpenBooking:i}){const[S,x]=c.useState(null),b=v=>{x(null),m?.(v)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:n.sp(3),flexWrap:"wrap",marginBottom:n.sp(3)},children:[e.jsx("p",{style:{margin:0,color:n.sub,fontSize:14,lineHeight:1.5,flex:"1 1 260px"},children:"Every cell, who is in it and the free beds. Housing refuses a full cell, and warns before putt
1ing keep-separate people in one unit."}),g&&e.jsx(k,{icon:e.jsx(ce,{"aria-hidden":"true"}),onClick:()=>x("new"),children:"Add a facility"})]}),u&&e.jsx(z,{tone:"danger",children:u}),y&&e.jsx("div",{role:"status",style:{color:n.sub,fontSize:14},children:"Loading the layouts…"}),!y&&!s.length&&e.jsx(X,{children:e.jsx(me,{title:"No jail layout yet",body:g?"Add a facility with its housing units and cells. Intake houses people in it.":"A corrections officer adds the facility layout."})}),s.map(v=>e.jsxs(X,{style:{marginBottom:n.sp(4)},children:[e.jsx(Q,{action:g&&e.jsx(k,{size:"sm",onClick:()=>x(v),children:"Edit layout"}),children:v.name}),e.jsx("div",{style:{fontSize:13,color:n.sub,marginBottom:n.sp(3)},children:`${oe(v.units.reduce((f,C)=>f+C.held,0),"person","people")} housed, ${oe(v.units.reduce((f,C)=>f+C.free,0),"bed")} free`}),v.units.map(f=>e.jsxs("div",{style:{marginBottom:n.sp(3)},children:[e.jsxs("div",{style:{display:"flex",gap:n.sp(2),alignItems:"center",marginBottom:n.sp(2),flexWrap:"wrap"},children:[e.jsx("span",{style:{fontWeight:650,fontSize:14},children:f.name}),e.jsx(_,{tone:f.free===0?"warn":"neutral",children:`${f.held} of ${f.beds} beds taken`})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(150px, 100%), 1fr))",gap:n.sp(2)},children:f.cells.map(C=>e.jsx(Kt,{cell:C,onOpen:i},C._id))})]},f._id))]},v._id)),S&&e.jsx(Vt,{communityId:t,facility:S==="new"?null:S,onClose:()=>x(null),onSaved:b,onRemoved:()=>b(null)})]})}function Qt({communityId:t,facilities:s,canWrite:g,refreshKey:y=0}){const[u,m]=c.useState(s[0]?._id||""),[i,S]=c.useState(null),[x,b]=c.useState({}),[v,f]=c.useState(!1),[C,j]=c.useState(""),[$,r]=c.useState(null),h=c.useCallback(async()=>{if(u)try{S(await nt(t,u))}catch(d){j(H(d,"The count sheet did not load. Try again."))}},[t,u]);if(c.useEffect(()=>{h()},[h,y]),c.useEffect(()=>{!u&&s[0]&&m(s[0]._id)},[s,u]),!s.length)return e.jsx(X,{children:e.jsx(me,{title:"Nothing to count yet",body:"Counts run per housing unit. Add a facility under Layout first."})});const a=async()=>{f(!0),j("");try{const d=await st(t,u,x);r(d),b({}),await h()}catch(d){j(H(d,"The count was not saved. Try again."))}finally{f(!1)}},w=new Date;return e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{margin:`0 0 ${n.sp(3)}px`,color:n.sub,fontSize:14,lineHeight:1.5},children:"Count every unit and enter what you see. Expected numbers come from the bookings: people housed in the unit, less anyone out at court or medical."}),s.length>1&&e.jsx(P,{label:"Facility",style:{maxWidth:320,marginBottom:n.sp(3)},children:e.jsx(de,{value:u,onChange:d=>{m(d.target.value),r(null)},children:s.map(d=>e.jsx("option",{value:d._id,children:d.name},d._id))})}),C&&e.jsx(z,{tone:"danger",children:C}),$&&e.jsx(z,{tone:$.clear?"good":"warn",onDismiss:()=>r(null),children:$.clear?"Count clear: every unit matches.":`Count does not match in ${$.units.filter(d=>!d.matches).map(d=>`${d.name} (expected ${d.expected}, counted ${d.counted})`).join(", ")}.`}),e.jsx(X,{padding:0,style:{overflow:"hidden",marginBottom:n.sp(4)},children:(i?.sheet||[]).map(d=>e.jsxs("div",{"data-count-unit":d.name,style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) auto",gap:n.sp(3),alignItems:"center",padding:`${n.sp(3)}px ${n.sp(4)}px`,borderBottom:`1px solid ${n.hair}`},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontWeight:650,fontSize:15},children:d.name}),e.jsxs("div",{style:{fontSize:13,color:n.sub,marginTop:2},children:[`Expected ${d.expected}`,d.out?`, ${d.out} out`:""]}),d.people.filter(I=>I.away).map(I=>e.jsx("div",{style:{fontSize:12.5,color:n.sub},children:`${I.name}: ${Z[I.away].toLowerCase()}`},I.bookingNumber))]}),g?e.jsx("div",{style:{width:96},children:e.jsx(V,{type:"number",min:0,"aria-label":`Counted in ${d.name}`,value:x[d.unitId]??"",onChange:I=>b(F=>({...F,[d.unitId]:I.target.value===""?"":Number(I.target.value)}))})}):e.jsx(_,{children:`${d.expected} expected`})]},d.unitId))}),g&&e.jsx(k,{kind:"primary",onClick:a,disabled:v||!i,children:v?"Recording…":"Record count"}),(i?.recent||[]).length>0&&e.jsxs("div",{style:{marginTop:n.sp(5)},children:[e.jsx(Q,{children:"Recent counts"}),e.jsx("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:n.sp(2)},children:i.recent.map(d=>e.jsxs("li",{style:{fontSize:13.5,display:"flex",gap:n.sp(2),flexWrap:"wrap",alignItems:"center"},children:[e.jsx(_,{tone:d.clear?"good":"warn",children:d.clear?"Clear":"Did n
1ot match"}),e.jsx("span",{children:`${O(d.at,w)} by ${d.byName}`}),e.jsxs("span",{style:{color:n.sub},children:[oe(d.units.reduce((I,F)=>I+(F.counted||0),0),"person","people")," counted"]})]},d._id))})]})]})}const Yt=t=>(typeof t=="string"?t:t?._id)||"",Gt=[{value:"roster",label:"Roster"},{value:"layout",label:"Layout"},{value:"count",label:"Count"}];function Zt({dark:t,children:s}){return e.jsxs("div",{className:"adm-root",style:{...at(t),minHeight:"100vh",background:n.bg,color:n.text,fontFamily:n.font,colorScheme:n.colorScheme},children:[e.jsx("style",{children:ct}),e.jsx(ot,{}),e.jsx("main",{id:"jail-main",tabIndex:-1,style:{maxWidth:1080,margin:"0 auto",boxSizing:"border-box",padding:`${n.sp(6)}px ${n.sp(4)}px calc(${n.sp(24)}px + env(safe-area-inset-bottom, 0px))`},children:s})]})}function Xt({refusal:t,onBack:s}){const g=t.code==="FEATURE_OFF";return e.jsxs(X,{padding:n.sp(6),style:{maxWidth:620},children:[e.jsx("h1",{style:{margin:0,fontSize:"clamp(21px, 5.2vw, 26px)",letterSpacing:"-0.02em"},children:g?"The jail is turned off":"Custody records aren't open to you"}),e.jsx("p",{style:{margin:`${n.sp(2)}px 0 ${n.sp(5)}px`,color:n.sub,fontSize:15,lineHeight:1.55},children:t.message}),e.jsx(k,{onClick:s,icon:e.jsx(Oe,{"aria-hidden":"true"}),children:"Back to your dashboard"})]})}function en({booking:t,now:s,onOpen:g}){const y=t.bucket,u=xe(t.housing);let m;if(y==="released")m=e.jsxs(e.Fragment,{children:[e.jsx(_,{children:t.status==="transferred"?"Transferred":"Released"}),e.jsx("span",{style:{fontSize:12.5,color:n.sub},children:O(t.releasedAt,s)})]});else if(y==="intake"){const i=t.intakeMissing||[];m=e.jsxs(e.Fragment,{children:[e.jsx(_,{tone:"accent",children:i.length?`${i.length} ${i.length===1?"step":"steps"} left`:"Ready to complete"}),e.jsx("span",{style:{fontSize:12.5,color:n.sub},children:i.length?`Next: ${pe[i[0]].toLowerCase()}`:"Intake"})]})}else m=e.jsxs(e.Fragment,{children:[e.jsx(_,{tone:y==="due"?"warn":"accent",children:Ae(t,s)}),e.jsx("span",{style:{fontSize:12.5,color:n.sub},children:t.away?"Out of the facility":`${y==="due"?"Served at":"Out at"} ${O(t.releaseDueAt,s)}`})]});return e.jsxs("button",{type:"button",className:"adm-btn adm-row-click",onClick:()=>g(t),"data-booking":t.bookingNumber,style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",gap:n.sp(3),alignItems:"center",width:"100%",textAlign:"left",background:n.card,color:n.text,border:"none",borderBottom:`1px solid ${n.hair}`,padding:`${n.sp(3)}px ${n.sp(4)}px`,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(ue,{value:t.mugshotRef,name:t.subjectName}),e.jsxs("span",{style:{minWidth:0},children:[e.jsx("span",{style:{display:"block",fontSize:15,fontWeight:600,overflowWrap:"anywhere"},children:t.subjectName||"Unknown person"}),e.jsxs("span",{style:{display:"block",fontSize:12.5,color:n.sub,marginTop:2,overflowWrap:"anywhere"},children:[e.jsx(ye,{children:t.bookingNumber}),u?` · ${u}`:"",ke(t.charges)?` · ${ke(t.charges)}`:""]})]}),e.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:n.sp(1),textAlign:"right"},children:m})]})}const Be={intake:{title:"Nobody is waiting on intake",body:"A booking opens here when an arrest is booked. Intake takes property, the mugshot, classification and a bed before the sentence starts."},inCustody:{title:"Nobody is in custody",body:"People show up here once intake is complete, with the time left on their sentence."},due:{title:"Nobody is due for release",body:"When a sentence is served the person moves here. Nobody is released until a corrections officer does it."},released:{title:"No releases yet",body:"The most recent releases and transfers out show up here, with who did it and why."}};function tn(t,s,g){const[y,u]=c.useState({facilities:[],loading:!0,error:""}),m=c.useCallback(async()=>{if(!(!t||!s))try{u({facilities:await rt(t),loading:!1,error:""})}catch(i){u(S=>({...S,loading:!1,error:H(i,"The layouts did not load. Try again.")}))}},[t,s]);return c.useEffect(()=>{m()},[m,g]),{...y,reload:m}}function nn({communityId:t,communityName:s,dark:g,navigate:y}){const u=Lt(t),{access:m,roster:i,now:S,loading:x,error:b,refusal:v}=u,[f,C]=c.useState("roster"),[j,$]=c.useState(null),[r,h]=c.useState(!1),[a,w]=c.useState(null),[d,I]=c.useState(null),[F,q]=c.useState(0),N=m?.canWrite===!0,l=tn(t,!!m?.canRead,`${F}:${u.changed?.at||0}`);if(c.useEffect(()=>{j===null&&!x&&!v&&$(jt(i))},[j,x,v,i]),v)return e.jsx(Xt,{refusal:v,onBack:()=>y("/home")});const E=j||"inCustody",J=i[E]||[],Y=u.changed&&String(u.changed.bookingId)===String(a)?u.changed.at:0,D=B=>{h(!1),u.applyBooking(B),I(`${B.subjectName} is in intake as ${B.bookingNumber}. Finish the steps to book them into custody.`),$("intake"),C("roster"),w(B._id)},G=B=>{u.applyBooking(B),q(W=>W+1)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-start",justifyContent:"space-between",gap:n.sp(3),marginBottom:n.sp(4)},children:[e.jsxs("div",{style:{minWidth:0,flex:"1 1 260px"},children:[e.jsx("h1",{style:{margin:0,fontSize:"clamp(21px, 5.2vw, 26px)",letterSpacing:"-0.02em",lineHeight:1.2},children:"Jail"}),e.jsx("p",{style:{margin:`${n.sp(1)}px 0 0`,color:n.sub,fontSize:14,lineHeight:1.5},children:"Who is in custody and until when. A served sentence moves the person to Due for release; a corrections officer releases them by hand."})]}),N&&e.jsx(k,{kind:"primary",icon:e.jsx(ce,{"aria-hidden":"true"}),onClick:()=>h(!0),children:"Book from an arrest"})]}),m&&!N&&e.jsxs(z,{children:["You can read custody records. ",m.message]}),m?.autoBook&&N&&e.jsx(z,{children:"Automatic booking is on: an arrest report filed with a person on it opens their intake here by itself."}),d&&e.jsx(z,{tone:"good",onDismiss:()=>I(null),children:d}),e.jsx("div",{style:{marginBottom:n.sp(4)},children:e.jsx(fe,{ariaLabel:"Jail view",value:f,options:Gt,onChange:C})}),f==="roster"&&e.jsxs(e.Fragment,{children:[!x&&i.due.length>0&&E!=="due"&&e.jsxs(z,{tone:"warn",action:e.jsx(k,{size:"sm",onClick:()=>$("due"),children:"Show"}),children:[oe(i.due.length,"person","people")," ",i.due.length===1?"has":"have"," served their sentence and ",i.due.length===1?"is":"are"," waiting to be released."]}),e.jsx("div",{style:{marginBottom:n.sp(3)},children:e.jsx(fe,{ariaLabel:"Which list",value:E,options:bt(i),onChange:$,wrap:!0})}),b&&e.jsx(z,{tone:"danger",action:e.jsx(k,{size:"sm",onClick:u.reload,children:"Try again"}),children:b}),e.jsxs(X,{padding:0,style:{overflow:"hidden"},children:[x&&e.jsx("div",{role:"status",style:{padding:n.sp(5),color:n.sub,fontSize:14},children:"Loading the roster…"}),!x&&J.length===0&&!b&&e.jsx(me,{title:Be[E].title,body:Be[E].body}),!x&&J.map(B=>e.jsx(en,{booking:B,now:S,onOpen:W=>w(W._id)},B._id))]}),!x&&E==="inCustody"&&J.length>0&&e.jsxs("p",{style:{margin:`${n.sp(3)}px 0 0`,color:n.subtle,fontSize:12.5},children:[oe(J.length,"person","people")," in custody, with ",he(J.reduce((B,W)=>B+(W.minutesLeft||0),0))," left to serve between them."]})]}),f==="layout"&&e.jsx(qt,{communityId:t,facilities:l.facilities,canWrite:N,loading:l.loading,error:l.error,onChanged:()=>q(B=>B+1),onOpenBooking:B=>w(B)}),f==="count"&&e.jsx(Qt,{communityId:t,facilities:l.facilities,canWrite:N,refreshKey:u.changed?.at||0}),r&&e.jsx(vt,{communityId:t,onClose:()=>
1h(!1),onBooked:D}),a&&e.jsx(Jt,{communityId:t,bookingId:a,canWrite:N,refreshKey:Y,facilities:l.facilities,dark:g,communityName:s,onClose:()=>w(null),onChanged:G})]})}function An(){const t=Tt(),{activeCommunity:s}=it(),[g]=lt(),y=g!=="light",u=Yt(s);return e.jsx(Zt,{dark:y,children:u?e.jsx(nn,{communityId:u,communityName:s?.name||"",dark:y,navigate:t}):e.jsx(X,{children:e.jsx(me,{title:"Pick a community first",body:"Custody records belong to a community. Choose one, then come back here."})})})}export{An 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.