import{a as S,j as n,F as B}from"./index-b983ad9b.js";/* empty css                *//* empty css              *//* empty css              *//* empty css              */import{r as f}from"./react-b0e0d18a.js";import{B as E,R as b}from"./Room-7ae51b0a.js";import{s as g}from"./Select.module-b0cb8f14.js";import{R as N,a as m,N as A,S as v}from"./antd-8ca2e36c.js";import{g as M}from"./KB-757eebe4.js";let x=[];function K({level:h,onChange:i}){const[u,p]=f.useState();f.useEffect(()=>{let e=!0;return(async()=>e&&await y({}))(),()=>{e=!1}},[]);const y=async e=>{try{const t=await E.findAll({pp:-1,...e})||[],s=[];t.forEach(r=>{var a;const d=r.area_id,o=`area/${d}`;let c=s.find($=>$.value==o&&$.title!="");c||(c={title:r.path,value:o,children:[]},s.push(c)),c&&((a=c.children)==null||a.push({title:r.name,value:`building/${r.id}/${d}`,children:h=="room"?[{title:"加载房间",value:`building/${r.id}/children`}]:[]}))}),p(s)}catch{}},w=async(e,t)=>{try{const{items:s}=await b.findByBuilding(e,{pp:-1})||[];s.forEach(a=>{a.title=`${a.code}${a.name?`（${a.name}）`:""}`,a.value=`room/${a.id}`});let r=JSON.parse(JSON.stringify(u)),d=r.find(a=>a.value==`area/${t}`),o=r.findIndex(a=>a.value==`area/${t}`),c=d.children.findIndex(a=>a.value==`building/${e}/${t}`);r[o].children[c].children=s,p(r)}catch{}},l=async e=>{let t=e.filter(o=>!x.includes(`${o}`)),s=`${t[0]}`.split("/")[0],r=Number(`${t[0]}`.split("/")[1]),d=Number(`${t[0]}`.split("/")[2]);s&&s=="building"&&await w(r,d),x=e};return S(N,{gutter:[8,8],children:[n(m,{span:6,className:g.selectLabel,children:"地理位置"}),n(m,{span:18,children:n(A,{allowClear:!0,showSearch:!0,style:{width:"100%"},placeholder:"请选择地理位置",dropdownStyle:{maxHeight:500,overflow:"auto"},treeData:u,onTreeExpand:l,defaultOpen:!1,onSelect:e=>{i&&i({type:e.split("/")[0],id:e.split("/")[1]})},onChange:e=>{e?i&&i({type:e.split("/")[0],id:e.split("/")[1]}):i&&i({type:"all",id:"0"})},filterTreeNode:(e,t)=>!!(t&&t.title&&t.title.includes(e))})})]})}const{Option:L}=v;function _({layout:{label:h,value:i},onChange:u}){const[p,y]=f.useState([]);f.useEffect(()=>{let l=!0;return(async()=>{try{l&&await w()}catch{}})(),()=>{l=!1}},[]);const w=async()=>{try{const l=await M();let e=[];for(let t in l)e.push({...l[t],key:t});y(e)}catch{}};return n(B,{children:S(N,{gutter:[8,8],children:[n(m,{span:h,className:g.selectLabel,children:"环境指标"}),n(m,{span:i,children:n(v,{style:{width:"100%"},placeholder:"请选择环境指标",allowClear:!0,onChange:l=>{u&&u(l)},children:p.map(l=>n(L,{value:l.key,children:l.title},l.key))})})]})})}export{K as L,_ as M};
