1import{r as a,s as v,j as e,bl as B,bm as D,bn as $,bo as L,a4 as q,b0 as z,b3 as E,b5 as T,bM as F,B as j,v as u}from"./index-Buc_AyvT.js";const V=({open:l,onOpenChange:n,documentIds:o,tenantId:b,onSaved:N})=>{const[c,S]=a.useState(""),[y,k]=a.useState([]),[r,x]=a.useState(null),[m,f]=a.useState(!1),[w,h]=a.useState(!1);a.useEffect(()=>{l&&C()},[l]);const C=async()=>{h(!0);const{data:s}=await v.from("physical_boxes").select("id, box_code, description, status").eq("tenant_id",b).eq("status","arquivada").order("created_at",{ascending:!1}).limit(200);k(s||[]),h(!1)},g=y.filter(s=>{if(!c)return!0;const t=c.toLowerCase();return s.box_code.toLowerCase().includes(t)||(s.description||"").toLowerCase().includes(t)}),_=async()=>{if(!r||o.length===0)return;f(!0);let s=0,t=0,i=0;for(const d of o){const{error:p}=await v.from("box_documents").insert({box_id:r,document_id:d});p?p.code==="23505"?t++:i++:s++}if(i>0)u.error(`${i} erro(s) ao vincular documentos`);else if(s>0){const d=t>0?` (${t} já vinculado(s))`:"";u.success(`${s} documento(s) vinculado(s) ao acervo fÃsico!${d}`)}else t>0&&u.info("Todos os documentos já estavam vinculados a este acervo.");f(!1),x(null),n(!1),N()};return e.jsx(B,{open:l,onOpenChange:n,children:e.jsxs(D,{className:"max-w-lg",children:[e.jsx($,{children:e.jsxs(L,{children:["Vincular ",o.length>1?`${o.length} documentos`:"documento"," a Acervo FÃsico"]})}),e.jsxs("div",{className:"relative",children:[e.jsx(q,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx(z,{placeholder:"Buscar acervo...",value:c,onChange:s=>S(s.target.value),className:"pl-9"})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:w?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"Carregando..."}):g.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"Nenhum acervo encontrado."}):g.map(s=>{const t=r===s.id;return e.jsxs("button",{onClick:()=>x(t?null:s.id),className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?"bg-primary/10 ring-1 ring-primary/30":"hover:bg-muted/50"}`,children:[t?e.jsx(E,{size:16,className:"text-primary shrink-0"}):e.jsx(T,{size:16,className:"text-muted-foreground shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-sm font-medium",children:s.box_code}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.description})]})]},s.id)})}),e.jsxs(F,{children:[e.jsx(j,{variant:"outline",onClick:()=>n(!1),children:"Cancelar"}),e.jsx(j,{onClick:_,disabled:m||!r,children:m?"Salvando...":"Vincular"})]})]})})};export{V 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.