1import{r as a,o as L,j as e,a0 as E,L as D,M as G,X as J}from"./index-CzU4y74h.js";import{S as z}from"./search-QhF1Kp5l.js";import{S as H}from"./save-DkNbzCVD.js";const Q=["city","village","town","incorporated_place","census_designated_place","unincorporated_community"];function U(){const[g,b]=a.useState([]),[j,w]=a.useState(!0),[o,q]=a.useState(""),[d,F]=a.useState(""),[x,R]=a.useState(""),[u,A]=a.useState(!1),[h,I]=a.useState(!1),[X,M]=a.useState(0),[P,T]=a.useState(!0),[r,m]=a.useState(null),[s,p]=a.useState({counties:"",aliases:"",requires_disambiguation:!1,active:!0}),f=50,k=a.useCallback(()=>{const t={active:!0};return d&&(t.state_abbr=d),x&&(t.place_type=x),h&&(t.requires_disambiguation=!0),t},[d,x,h]),N=a.useCallback(async(t=!1)=>{w(!0);try{const l=k();let i=await L.entities.LocationReference.filter(l,"canonical_name",f+1)||[];if(u&&(i=i.filter(n=>(n.counties||[]).length>1)),o){const n=o.toLowerCase();i=i.filter(y=>{var C,S,_;return((C=y.canonical_name)==null?void 0:C.toLowerCase().includes(n))||((S=y.counties)==null?void 0:S.some(v=>v.toLowerCase().includes(n)))||((_=y.aliases)==null?void 0:_.some(v=>v.toLowerCase().includes(n)))})}t?(b(i.slice(0,f)),M(0)):b(n=>[...n,...i.slice(0,f)]),T(i.length>f)}catch(l){console.error("Failed to load LocationReference records:",l)}w(!1)},[k,o,u]);a.useEffect(()=>{N(!0)},[d,x,u,h]),a.useEffect(()=>{N(!0)},[o]);const B=t=>{m(t),p({counties:(t.counties||[]).join(", "),aliases:(t.aliases||[]).join(", "),requires_disambiguation:t.requires_disambiguation||!1,active:t.active!==!1})},O=async()=>{if(r)try{await L.entities.LocationReference.update(r.id,{counties:s.counties.split(",").map(t=>t.trim()).filter(Boolean),aliases:s.aliases.split(",").map(t=>t.trim()).filter(Boolean),requires_disambiguation:s.requires_disambiguation,active:s.active}),b(t=>t.map(l=>l.id===r.id?{...l,...s,counties:s.counties.split(",").map(c=>c.trim()).filter(Boolean),aliases:s.aliases.split(",").map(c=>c.trim()).filter(Boolean)}:l)),m(null)}catch(t){console.error("Failed to update record:",t),alert("Failed to update: "+t.message)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h1",{className:"font-heading text-2xl font-bold text-slate-900",children:"Location Reference Database"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Geographic source of truth for article resolution â Illinois & Indiana pilot"})]})}),e.jsxs("div",{className:"flex flex-wrap gap-3 items-end",children:[e.jsxs("div",{className:"flex-1 min-w-[200px]",children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:"Search"}),e.jsxs("div",{className:"relative",children:[e.jsx(z,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx("input",{type:"text",value:o,onChange:t=>q(t.target.value),placeholder:"City, county, or alias...",className:"w-full pl-8 pr-3 py-1.5 text-sm border rounded-md bg-white"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider block",children:"State"}),e.jsxs("select",{value:d,onChange:t=>F(t.target.value),className:"border rounded-md px-2 py-1.5 text-sm bg-white",children:[e.jsx("option",{value:"",children:"All"}),e.jsx("option",{value:"IL",children:"Illinois"}),e.jsx("option",{value:"IN",children:"Indiana"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider block",children:"Type"}),e.jsxs("select",{value:x,onChange:t=>R(t.target.value),className:"border rounded-md px-2 py-1.5 text-sm bg-white",children:[e.jsx("option",{value:"",children:"All"}),Q.map(t=>e.jsx("option",{value:t,children:t},t))]})]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:t=>A(t.target.checked)}),"Multi-county"]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:h,onChange:t=>I(t.target.checked)}),e.jsx(E,{className:"w-3.5 h-3.5 text-amber-500"}),"Needs disambiguation"]})]}),e.jsxs("div",{className:"border rounded-lg overflow-hidden bg-white",children:[e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-3 py-2 font-semibold text-muted-foreground",children:"City"}),e.jsx("th",{className:"text-left px-3 py-2 font-semibold text-muted-foreground",children:"State"}),e.jsx("th",{className:"text-left px-3 py-2 font-semibold text-muted-foreground",children:"Type"}),e.jsx("th",{className:"text-left px-3 py-2 font-semibold text-muted-foreground",children:"County(ies)"}),e.jsx("th",{className:"text-left px-3 py-2 font-semibold text-muted-foreground",children:"Aliases"}),e.jsx("th",{className:"text-left px-3 py-2 font-semibold text-muted-foreground",children:"Flags"}),e.jsx("th",{className:"text-right px-3 py-2"})]})}),e.jsxs("tbody",{className:"divide-y",children:[g.map(t=>e.jsxs("tr",{className:"hover:bg-slate-50",children:[e.jsx("td",{className:"px-3 py-2 font-medium",children:t.canonical_name}),e.jsx("td",{className:"px-3 py-2",children:t.state_abbr}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground",children:t.place_type}),e.jsx("td",{className:"px-3 py-2",children:(t.counties||[]).map((l,c)=>e.jsx("span",{className:`inline-block px-1.5 py-0.5 rounded text-xs mr-1 ${(t.counties||[]).length>1?"bg-amber-100 text-amber-800":"bg-slate-100 text-slate-700"}`,children:l},c))}),e.jsx("td",{className:"px-3 py-2 text-xs text-muted-foreground",children:(t.aliases||[]).join(", ")||"â"}),e.jsx("td",{className:"px-3 py-2",children:t.requires_disambiguation&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-amber-600",children:[e.jsx(E,{className:"w-3 h-3"})," Disambig"]})}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsx("button",{onClick:()=>B(t),className:"text-xs text-blue-600 hover:underline",children:"Edit"})})]},t.id)),g.length===0&&!j&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-3 py-8 text-center text-muted-foreground",children:"No records foun
1d"})})]})]}),j&&e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(D,{className:"w-5 h-5 animate-spin text-slate-400"})}),P&&!j&&g.length>0&&e.jsx("div",{className:"p-3 text-center border-t",children:e.jsx("button",{onClick:()=>N(!1),className:"text-sm text-blue-600 hover:underline",children:"Load more"})})]}),r&&e.jsx("div",{className:"fixed inset-0 bg-black/40 flex items-center justify-center z-50 p-4",onClick:()=>m(null),children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full p-5 space-y-4",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h2",{className:"font-heading font-bold text-lg flex items-center gap-2",children:[e.jsx(G,{className:"w-5 h-5"})," ",r.canonical_name,", ",r.state_abbr]}),e.jsx("button",{onClick:()=>m(null),children:e.jsx(J,{className:"w-5 h-5 text-muted-foreground"})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider block mb-1",children:"Counties (comma-separated)"}),e.jsx("input",{value:s.counties,onChange:t=>p({...s,counties:t.target.value}),className:"w-full border rounded px-2 py-1.5 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider block mb-1",children:"Aliases (comma-separated)"}),e.jsx("input",{value:s.aliases,onChange:t=>p({...s,aliases:t.target.value}),className:"w-full border rounded px-2 py-1.5 text-sm",placeholder:"e.g. St John, Saint John"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:s.requires_disambiguation,onChange:t=>p({...s,requires_disambiguation:t.target.checked})}),"Requires disambiguation (ambiguous place name)"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:s.active,onChange:t=>p({...s,active:t.target.checked})}),"Active"]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:()=>m(null),className:"px-3 py-1.5 text-sm border rounded hover:bg-slate-50",children:"Cancel"}),e.jsxs("button",{onClick:O,className:"px-3 py-1.5 text-sm bg-emerald-600 text-white rounded hover:bg-emerald-700 flex items-center gap-1",children:[e.jsx(H,{className:"w-3.5 h-3.5"})," Save"]})]})]})})]})}export{U 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.