import{n as e,s as t,t as n}from"./jsx-runtime-Bzw2jH9X.js";import{ct as r}from"./services-Ddh4dHvP.js";import{t as i}from"./createLucideIcon-BkIMvJln.js";import{t as a}from"./x-CkbzgTHo.js";import{B as o,lt as s}from"./index-DkcBoy_T.js";var c={name:`circle-minus`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]],aliases:[`minus-circle`]};c.node;var l=i(c),u=t(e(),1),d=n();function f({selectedOrgs:e,onSelectedOrgsChange:t,enableExclude:n=!1,excludedOrgs:i=[],onExcludedOrgsChange:c}){let[f,p]=(0,u.useState)(!1),[m,h]=(0,u.useState)(``),[g,_]=(0,u.useState)(``),[v,y]=(0,u.useState)(1),[b,x]=(0,u.useState)([]),[S,C]=(0,u.useState)(0),w=(0,u.useRef)(null),T=(0,u.useCallback)(()=>p(!1),[]);o(w,f,T);let E=e.map(e=>e.id),D=n?i.map(e=>e.id):[],O=e.map(e=>e.name).join(`,`),k=n?i.map(e=>e.name).join(`,`):``,A=e.length>0||n&&i.length>0,j=v<=1,M=S===0||v>=S;(0,u.useEffect)(()=>{f&&(async()=>{try{let e=await r({page:v,limit:15,order:`DESC`,sort:`chartCount`,q:g||void 0});x(e.data),C(e.meta.pageCount??0)}catch(e){console.error(e),x([]),C(0)}})()},[f,v,g]);let N=()=>{y(1),_(m.trim())},P=()=>{j||y(e=>e-1)},F=()=>{M||y(e=>e+1)},I=n=>{t(E.includes(n.id)?e.filter(e=>e.id!==n.id):[...e,n])},L=(e,t)=>{n&&c&&(e.stopPropagation(),c(D.includes(t.id)?i.filter(e=>e.id!==t.id):[...i,t]))};return(0,d.jsxs)(`div`,{ref:w,className:`relative w-full`,children:[(0,d.jsxs)(`div`,{className:`group/trigger w-full bg-slate-50 border border-slate-100 rounded-xl px-3 py-2 text-xs cursor-pointer flex justify-between items-start gap-2`,onClick:()=>p(!f),children:[(0,d.jsx)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-0.5`,children:A?n?(0,d.jsxs)(d.Fragment,{children:[O&&(0,d.jsxs)(`span`,{className:`text-slate-700 wrap-break-word leading-relaxed`,children:[`选择:`,O]}),k&&(0,d.jsxs)(`span`,{className:`text-slate-700 wrap-break-word leading-relaxed`,children:[`排除:`,k]})]}):(0,d.jsx)(`span`,{className:`text-slate-700 wrap-break-word leading-relaxed`,children:O}):(0,d.jsx)(`span`,{className:`text-slate-500`,children:`请选择机构`})}),(0,d.jsxs)(`div`,{className:`relative mt-0.5 flex h-3.5 w-3.5 shrink-0 items-center justify-center`,children:[A&&(0,d.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t([]),n&&c&&c([])},"aria-label":`清空`,className:`absolute inset-0 hidden items-center justify-center rounded-full text-slate-400 transition-colors hover:bg-slate-200 hover:text-slate-600 cursor-pointer group-hover/trigger:flex`,children:(0,d.jsx)(a,{size:12,strokeWidth:2.25})}),(0,d.jsx)(s,{size:14,className:`transition-[opacity,transform] ${f?`rotate-90 opacity-100`:`opacity-0 group-hover/trigger:opacity-100`} ${A?`group-hover/trigger:hidden`:``}`})]})]}),f&&(0,d.jsxs)(`div`,{className:`absolute top-full left-0 mt-2 w-120 bg-white border border-slate-200 rounded-xl shadow-xl p-4 z-50`,children:[(0,d.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,d.jsx)(`input`,{type:`text`,placeholder:`请输入机构关键字`,className:`flex-1 border border-slate-200 rounded px-3 py-1.5 text-xs outline-none focus:ring-1 focus:ring-blue-500`,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>e.key===`Enter`&&N()}),(0,d.jsx)(`button`,{type:`button`,className:`bg-blue-600 text-white px-4 py-1.5 rounded text-xs font-bold cursor-pointer`,onClick:N,children:`搜索`}),(0,d.jsx)(`button`,{type:`button`,disabled:j,className:`border border-slate-200 px-3 py-1.5 rounded text-xs cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed`,onClick:P,children:`上一页`}),(0,d.jsx)(`button`,{type:`button`,disabled:M,className:`border border-slate-200 px-3 py-1.5 rounded text-xs cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed`,onClick:F,children:`下一页`})]}),b.length===0?(0,d.jsx)(`div`,{className:`py-8 text-center text-xs text-slate-400`,children:`暂未找到相关机构`}):(0,d.jsx)(`div`,{className:`grid grid-cols-3 gap-x-4 gap-y-3`,children:b.map(e=>{let t=E.includes(e.id),r=n&&D.includes(e.id);return(0,d.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,d.jsxs)(`label`,{className:`flex items-center gap-2 ${r?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,d.jsx)(`input`,{type:`checkbox`,className:`rounded border-slate-300`,checked:t,disabled:r,onChange:()=>I(e)}),(0,d.jsx)(`span`,{className:`text-slate-700`,children:e.name})]}),(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(`span`,{className:`text-slate-400`,children:e.reportCount}),n&&(0,d.jsxs)(`div`,{className:`relative group/exclude`,children:[(0,d.jsx)(`button`,{type:`button`,className:`flex items-center justify-center cursor-pointer`,onClick:t=>L(t,e),children:(0,d.jsx)(l,{size:12,className:r?`text-orange-500 fill-orange-50`:`text-slate-300 hover:text-slate-500`})}),(0,d.jsxs)(`div`,{className:`absolute right-0 top-full mt-2 opacity-0 group-hover/exclude:opacity-100 invisible group-hover/exclude:visible transition-all duration-150 z-60 pointer-events-none whitespace-nowrap bg-white border border-orange-100 text-slate-700 px-3 py-1.5 rounded-xl shadow-lg shadow-orange-100/40 text-[10px] font-medium leading-none`,children:[(0,d.jsx)(`div`,{className:`absolute -top-1 right-2 w-2 h-2 bg-white border-t border-l border-orange-100 transform rotate-45`}),r?`取消排除`:`排除该机构`]})]})]})]},e.id)})})]})]})}export{f as t};