import{n as e,t}from"./VRow-ZHldweuW.js";import{Cr as n,Er as r,I as i,Or as a,Q as o,Sr as s,Tr as c,Ur as l,Vr as u,Z as d,Zr as f,br as p,di as m,gr as h,hi as g,ii as _,jr as v,mi as y,qr as b,xr as x,y as S,yr as C}from"./index-BKLG6eUi.js";import{t as w}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{_ as T,t as E}from"./VTextField-Bs8XQAKI.js";import{t as D}from"./VCheckbox-B4C4ndfy.js";import{o as O}from"./labels-C-A2d08W.js";import{t as k}from"./useServerCategories-BZJuBcZm.js";var A={class:`server-category-picker`},j={class:`d-flex align-center flex-wrap ga-2 mb-2`},M={key:0,class:`text-center text-medium-emphasis py-4`},N={class:`d-flex align-center px-1 mb-1`},P={class:`text-caption text-medium-emphasis ml-1`},F={class:`d-flex align-center ga-2`},I={class:`text-body-2 font-weight-medium text-truncate`},L={class:`text-caption text-medium-emphasis text-truncate`},R=w(a({__name:`ServerCategoryPicker`,props:v({servers:{},loading:{type:Boolean,default:!1},maxHeight:{default:`280px`}},{modelValue:{default:()=>[]},modelModifiers:{}}),emits:[`update:modelValue`],setup(a){let v=b(a,`modelValue`),w=a,R=_(``),z=C(()=>new Set(v.value)),B=C(()=>{let e=R.value.trim().toLowerCase();return e?w.servers.filter(t=>t.name.toLowerCase().includes(e)||(t.domain||``).toLowerCase().includes(e)||(t.category||``).toLowerCase().includes(e)):w.servers}),V=C(()=>{let e={};for(let t of B.value){let n=t.category?.trim()||`uncategorized`;e[n]||(e[n]=[]),e[n].push(t)}return Object.entries(e).map(([e,t])=>({category:e,label:k(e),servers:[...t].sort((e,t)=>e.name.localeCompare(t.name,`zh`))})).sort((e,t)=>e.category===`uncategorized`?1:t.category===`uncategorized`?-1:e.label.localeCompare(t.label,`zh`))}),H=C(()=>{let e=B.value;return e.length>0&&e.every(e=>z.value.has(e.id))});function U(e){return e.servers.filter(e=>z.value.has(e.id)).length}function W(e){let t=V.value.find(t=>t.category===e);return!t||t.servers.length===0?!1:t.servers.every(e=>z.value.has(e.id))}function G(e){v.value=[...e]}function K(e){let t=new Set(v.value);t.has(e)?t.delete(e):t.add(e),G(t)}function q(e){let t=V.value.find(t=>t.category===e);if(!t)return;let n=new Set(v.value),r=t.servers.every(e=>n.has(e.id));for(let e of t.servers)r?n.delete(e.id):n.add(e.id);G(n)}function J(){let e=B.value,t=new Set(v.value),n=e.length>0&&e.every(e=>t.has(e.id));for(let r of e)n?t.delete(r.id):t.add(r.id);G(t)}return(_,b)=>(u(),n(`div`,A,[p(`div`,j,[r(D,{"model-value":H.value,label:`全选`,density:`compact`,"hide-details":``,"onUpdate:modelValue":J},null,8,[`model-value`]),r(E,{modelValue:R.value,"onUpdate:modelValue":b[0]||=e=>R.value=e,"prepend-inner-icon":`mdi-magnify`,label:`搜索服务器`,density:`compact`,"hide-details":``,variant:`outlined`,rounded:``,style:{"max-width":`220px`},clearable:``},null,8,[`modelValue`]),v.value.length>0?(u(),x(S,{key:0,size:`small`,color:`primary`,variant:`tonal`,label:``},{default:f(()=>[c(` 已选 `+g(v.value.length)+` 台 `,1)]),_:1})):s(``,!0),a.loading?(u(),x(d,{key:1,indeterminate:``,size:`18`,width:`2`})):s(``,!0)]),p(`div`,{class:`picker-scroll`,style:y({maxHeight:a.maxHeight})},[!a.loading&&V.value.length===0?(u(),n(`div`,M,` 暂无服务器 `)):s(``,!0),(u(!0),n(h,null,l(V.value,a=>(u(),n(`div`,{key:a.category,class:`mb-3`},[p(`div`,N,[r(i,{size:`x-small`,variant:`text`,color:W(a.category)?`primary`:`default`,onClick:e=>q(a.category)},{default:f(()=>[r(o,{size:`16`,class:`mr-1`},{default:f(()=>[c(g(W(a.category)?`mdi-checkbox-marked`:`mdi-checkbox-blank-outline`),1)]),_:2},1024),c(` `+g(a.label),1)]),_:2},1032,[`color`,`onClick`]),p(`span`,P,` (`+g(U(a))+`/`+g(a.servers.length)+`) `,1)]),r(t,{dense:``},{default:f(()=>[(u(!0),n(h,null,l(a.servers,t=>(u(),x(e,{key:t.id,cols:`12`,sm:`6`},{default:f(()=>[r(T,{color:z.value.has(t.id)?`primary`:void 0,variant:z.value.has(t.id)?`tonal`:`outlined`,rounded:`lg`,class:`pa-2 cursor-pointer`,onClick:e=>K(t.id)},{default:f(()=>[p(`div`,F,[r(o,{color:m(O)(t.is_online),size:`10`},{default:f(()=>[...b[1]||=[c(`mdi-circle`,-1)]]),_:1},8,[`color`]),p(`span`,I,g(t.name),1)]),p(`div`,L,g(t.domain),1)]),_:2},1032,[`color`,`variant`,`onClick`])]),_:2},1024))),128))]),_:2},1024)]))),128))],4)]))}}),[[`__scopeId`,`data-v-4d1df917`]]);export{R as t};