1import{j as e}from"./vendor-query-skQMsM6X.js";import{r as o}from"./vendor-react-DyYvSSk1.js";import{am as q,an as H,ao as U,ap as W,I as X,r as Y,v as J,x as K,y as Q,z as O,ab as Z,p as C,c as S}from"./index-BGwtrXIa.js";import{D as ee,a as se,b as ae,d as te,e as re,f as oe,c as _}from"./dropdown-menu-BXFyvXcT.js";import{g as ne,b as le,a as ie}from"./AtlasViewerModal-B6RFesUJ.js";import{Y as ce,bD as I,bC as G,ae as me,q as A,c2 as de,a as ue,X as xe,bL as pe}from"./vendor-ui-CCmu0bzQ.js";import{u as V,i as he}from"./useFeatureGate-DpZInRhK.js";import{P as M}from"./FeatureGate-C9l9WqLx.js";import"./vendor-supabase-BfoV2C50.js";import"./useRadiologyCatalog-DrZCG4PO.js";import"./useUserSessionData-DFvafMsG.js";import"./upgradeBridge-DxSiXl64.js";import"./PlansSelectionSheet-BBT11Dv3.js";import"./edgeFunctionClient-4dcAKx2Z.js";import"./errorTranslations-lTGRyFpS.js";import"./sessionTelemetry-X-Vnv8Qs.js";import"./useTrialStatus-DygoaPw9.js";import"./TrialCTAButton-BubHGtQk.js";import"./useAICredits-DMlHQu4c.js";import"./PromotionalNotice-B-9Mie38.js";function ge({open:m,onOpenChange:D,entries:r,categoryId:y,onSelectEntry:d}){const[u,f]=o.useState(""),[c,j]=o.useState("all"),w=o.useMemo(()=>{const a=new Set;return r.forEach(t=>{t.subcategoria&&a.add(t.subcategoria)}),Array.from(a).sort()},[r]),x=o.useMemo(()=>r.filter(a=>{var N,p;const t=u.toLowerCase(),l=!t||a.termo.toLowerCase().includes(t)||((N=a.termo_en)==null?void 0:N.toLowerCase().includes(t))||((p=a.tags)==null?void 0:p.some(L=>L.toLowerCase().includes(t)))||a.definicao.toLowerCase().includes(t),v=c==="all"||a.subcategoria===c;return l&&v}),[r,u,c]);return e.jsx(q,{open:m,onOpenChange:D,children:e.jsxs(H,{className:"w-[min(96vw,1400px)] sm:max-w-[min(96vw,1400px)] max-h-[88dvh]",children:[e.jsx(U,{children:e.jsx(W,{children:ne(y)})}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 sm:gap-3 mb-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(X,{placeholder:"Buscar termo...",value:u,onChange:a=>f(a.target.value),className:"pl-10"})]}),w.length>0&&e.jsxs(Y,{value:c,onValueChange:j,children:[e.jsx(J,{className:"w-full sm:w-[200px]",children:e.jsx(K,{placeholder:"Subcategoria"})}),e.jsxs(Q,{children:[e.jsx(O,{value:"all",children:"Todas"}),w.map(a=>e.jsx(O,{value:a,children:a},a))]})]})]}),e.jsx("div",{className:"max-h-[64vh] sm:max-h-[68vh] overflow-y-auto",children:x.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(I,{className:"h-12 w-12 mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"Nenhum termo encontrado"})]}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3 pr-1",children:x.map(a=>{var t,l;return e.jsxs("button",{onClick:()=>d(a),className:"group text-left border border-border rounded-lg overflow-hidden hover:border-primary/50 hover:shadow-md transition-all bg-card",children:[(t=a.imagem_urls)!=null&&t[0]||a.imagem_url?e.jsx("div",{className:"aspect-[4/3] bg-muted overflow-hidden",children:e.jsx("img",{src:((l=a.imagem_urls)==null?void 0:l[0])||a.imagem_url,alt:a.termo,className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300",loading:"lazy"})}):e.jsx("div",{className:"aspect-[4/3] bg-muted flex items-center justify-center",children:e.jsx(I,{className:"h-8 w-8 text-muted-foreground/30"})}),e.jsxs("div",{className:"p-2.5",children:[e.jsx("p",{className:"text-sm font-medium line-clamp-2 group-hover:text-primary transition-colors",children:a.termo}),a.termo_en&&e.jsx("p",{className:"text-xs text-muted-foreground italic mt-0.5 line-clamp-1",children:a.termo_en}),a.subcategoria&&e.jsx(Z,{variant:"outline",className:"text-[10px] mt-1.5",children:a.subcategoria})]})]},a.id)})})}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[x.length," de ",r.length," termos"]})]})})}function Ve({editor:m}
1){const[D,r]=o.useState(!1),[y,d]=o.useState(!1),[u,f]=o.useState(!1),[c,j]=o.useState(null),[w,x]=o.useState(""),[a,t]=o.useState([]),{categories:l,isLoading:v,error:N}=le(),{hasAccess:p,openPlansSheet:L}=V("feature_atlas"),{limit:F}=V("max_atlas"),k=F??0,$=o.useMemo(()=>{const s=new Map;let i=0;return l.forEach(n=>{n.entries.forEach(g=>{s.set(g.id,i++)})}),s},[l]);if(!m)return null;const h=s=>{const i=$.get(s.id)??0;return!he(i,k)},b=()=>{r(!1),L()},T=s=>{if(h(s)){b();return}j(s),d(!0),r(!1)},B=async s=>{if(h(s)){b();return}try{await navigator.clipboard.writeText(`${s.termo}: ${s.definicao}`),S.success("Definição copiada!")}catch{S.error("Erro ao copiar")}},P=s=>{if(h(s)){b();return}if(!s.descricao_laudo){S.warning(`"${s.termo}" ainda não tem descrição para laudo cadastrada.`);return}const i=`<p>${s.descricao_laudo}</p>`;m.chain().focus().insertContent(i).run(),S.success(`"${s.termo}" inserido no laudo`),r(!1)},z=(s,i)=>{if(!p||k<=0){b();return}x(s),t(i),f(!0),r(!1)},R=s=>{j(s),d(!0)};if(!v&&!N&&l.length===0)return null;const E=!p||k<=0;return e.jsxs(e.Fragment,{children:[e.jsxs(ee,{open:D,onOpenChange:r,children:[e.jsx(se,{asChild:!0,children:e.jsxs(C,{variant:"ghost",size:"sm",className:"gap-2 text-foreground hover:text-foreground",children:[e.jsx(G,{size:16}),e.jsx("span",{className:"text-sm hidden xl:inline",children:"Atlas"}),e.jsx(me,{size:14})]})}),e.jsx(ae,{className:"w-80 bg-popover border-border z-[100]",children:v?e.jsx("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:"Carregando..."}):l.map(s=>{const i=s.entries.every(n=>h(n));return e.jsxs(te,{children:[e.jsxs(re,{className:"cursor-pointer",children:[e.jsx(G,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:s.name}),i&&e.jsx(M,{className:"ml-2"}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:s.entries.length})]}),e.jsxs(oe,{className:"w-[420px] max-h-[400px] overflow-y-auto bg-popover border-border z-[101]",children:[e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 hover:bg-accent rounded-sm transition-colors cursor-pointer ${E?"text-muted-foreground":"text-primary"}`,onClick:()=>z(s.id,s.entries),children:[E?e.jsx(A,{className:"h-4 w-4"}):e.jsx(de,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Ver Galeria Completa"}),E&&e.jsx(M,{className:"ml-auto"})]}),e.jsx(_,{}),s.entries.slice(0,15).map(n=>{const g=h(n);return e.jsxs("div",{className:`group flex items-center justify-between px-2 py-1.5 hover:bg-accent rounded-sm transition-colors ${g?"opacity-60":""}`,children:[e.jsxs("span",{className:"text-sm line-clamp-1 flex-1 mr-2 flex items-center gap-2",children:[n.termo,g&&e.jsx(M,{})]}),g?e.jsx(A,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}):e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>T(n),title:"Visualizar",children:e.jsx(ue,{className:"h-4 w-4 text-muted-foreground hover:text-blue-400 transition-colors"})}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>B(n),title:"Copiar",children:e.jsx(xe,{className:"h-4 w-4 text-muted-foreground hover:text-blue-400 transition-colors"})}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>P(n),title:"Inserir no editor",children:e.jsx(pe,{className:"h-4 w-4 text-muted-foreground hover:text-green-400 transition-colors"})})]})]},n.id)}),s.entries.length>15&&e.jsxs(e.Fragment,{children:[e.jsx(_,{}),e.jsxs("div",{className:"px-2 py-1.5 text-xs text-muted-foreground text-center cursor-pointer hover:text-primary",onClick:()=>z(s.id,s.entries),children:["+",s.entries.length-15," termos â Ver galeria completa"]})]})]})]},s.id)})})]}),e.jsx(ie,{open:y,onOpenChange:d,entry:c,editor:m}),e.jsx(ge,{open:u,onOpenChange:f,entries:a,categoryId:w,onSelectEntry:R})]})}export{Ve as AtlasDropdown};
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.