import{T as A}from"./index-d0ad6070-1706882452509.js";import{d as S,u as C,e as p,p as b,f as e,w as u,F as m,j as I,k as N,A as j,v as k}from"./index-f5a86b16-1706882452509.js";import{a as x,b as B}from"./api-743c4898-1706882452509.js";import{T as w}from"./index-dcd64cc7-1706882452509.js";import{u as W}from"./catchData-557c9c01-1706882452509.js";const J="_container_h670f_1",O="_tools_h670f_8",z="_tagWrap_h670f_26",F="_tags_h670f_30",L="_firstButton_h670f_33",E="_content_h670f_48",V="_loadingContent_h670f_58",q="_itemWrap_h670f_61",D="_itemWrapBox_h670f_66",M="_item_h670f_61",P="_cover_h670f_81",R="_itemImg_h670f_98",X="_itemBg_h670f_128",$="_itemName_h670f_153",n={container:J,tools:O,tagWrap:z,tags:F,firstButton:L,content:E,loadingContent:V,itemWrap:q,itemWrapBox:D,item:M,cover:P,itemImg:R,itemBg:X,itemName:$},Y=S({name:"XiaokuAi",setup(){const f=W(),v=C(),h=localStorage.getItem("xiaoku-ai-search"),l=h?JSON.parse(h):{},c=p({musicTagIds:l.musicTagIds?l.musicTagIds:[],enable:!0,subjectId:l.subjectId||null,keyword:"",page:1,rows:9999}),a=p({tags:[],tagChildren:[],tagActiveId:l.tagActiveId||"",tagActive:{},list:[],loading:!1}),_=async()=>{const t=await x();if(Array.isArray(t==null?void 0:t.data)&&t.data.length){a.tags=t.data||[];const i=a.tags.findIndex(s=>s.id==a.tagActiveId);if(i>-1){a.tagActiveId=t.data[i].id;const s=[];g(t.data[i].children,s),a.tagChildren=s}else{a.tagActiveId=t.data[0].id;const s=[];g(t.data[0].children,s),a.tagChildren=s}}},d=async()=>{var t;a.loading=!0;try{const i=await B({...c,musicTagIds:[a.tagActiveId,...c.musicTagIds].filter(Boolean)});Array.isArray((t=i==null?void 0:i.data)==null?void 0:t.rows)&&(a.list=i.data.rows)}catch(i){}a.loading=!1},g=(t,i)=>{if(!(t!=null&&t.length))return;const s={columnName:t[0].columnName,list:[]},o=[];for(let r=0;r<t.length;r++)s.list.push({name:t[r].name,id:t[r].id,activeIndex:-1}),t[r].children&&o.push(...t[r].children);i.push(s),o.length&&g(o,i)};b(async()=>{a.loading=!0;try{await _(),await d(),await f.getSubjects(),localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:a.tagActiveId,subjectId:c.subjectId,musicTagIds:c.musicTagIds}))}catch(t){}a.loading=!1});const T=(t,i)=>{a.tagActiveId=t.id,c.musicTagIds=[],localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:t.id,subjectId:c.subjectId,musicTagIds:c.musicTagIds}));const s=[];g(a.tags[i].children,s),a.tagChildren=s,d()},y=(t,i)=>{const s=a.tagChildren[t].list[a.tagChildren[t].activeIndex],o=a.tagChildren[t].list[i];s&&s.id!==o.id&&(c.musicTagIds=c.musicTagIds.filter(r=>r!==s.id)),c.musicTagIds.includes(o.id)?(c.musicTagIds=c.musicTagIds.filter(r=>r!==o.id),a.tagChildren[t].activeIndex=-1):(c.musicTagIds.push(o.id),a.tagChildren[t].activeIndex=i),localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:a.tagActiveId,subjectId:c.subjectId,musicTagIds:c.musicTagIds})),d()};return()=>e("div",{class:n.container},[e("div",{class:n.tools},[e("div",{class:n.tagWrap},[e("div",{class:n.tags},[e(u,{size:[20,12]},{default:()=>{var t,i;return[e("span",{class:n.firstButton},[(i=(t=a.tags)==null?void 0:t[0])==null?void 0:i.columnName]),a.tags.map((s,o)=>e(m,null,[e(I,{round:!0,secondary:a.tagActiveId!==s.id,type:a.tagActiveId===s.id?"primary":"default",onClick:()=>T(s,o)},{default:()=>[s.name]})]))]}})]),a.tagChildren.map((t,i)=>e("div",{class:n.tags},[e(u,{size:[20,12]},{default:()=>[e("span",{class:n.firstButton},[t.columnName]),t.list.map((s,o)=>e(m,null,[e(I,{round:!0,secondary:t.activeIndex!==o,type:t.activeIndex===o?"primary":"default",onClick:()=>y(i,o)},{default:()=>[s.name]})]))]})])),e("div",{class:n.tags},[e(u,{size:[20,12]},{default:()=>[e("span",{class:n.firstButton},[N("声部")]),f.getSubjectAllList.map(t=>e(m,null,[e(I,{round:!0,secondary:t.id!==c.subjectId,type:t.id===c.subjectId?"primary":"default",onClick:()=>{c.subjectId=t.id,localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:a.tagActiveId,subjectId:t.id,musicTagIds:c.musicTagIds})),d()}},{default:()=>[t.name]})]))]})])]),e(A,{round:!0,onSearch:t=>{c.keyword=t,d()}},null)]),e(j,{show:a.loading},{default:()=>[e("div",{class:[n.content,a.loading?n.loadingContent:""]},[a.list.length>0?a.list.map((t,i)=>e("div",{class:n.itemWrap},[e("div",{class:n.itemWrapBox},[e("div",{class:n.item,key:"item-".concat(i),onClick:()=>{sessionStorage.setItem("musicSubjectList",JSON.stringify(t.subjects)),v.push({path:"/xiaoku-music",query:{id:t.id,name:t.name}})}},[e("div",{class:n.cover},[e("div",{class:n.itemImg},[e("div",{class:n.itemBg},null),e(k,{objectFit:"cover",src:t.coverImg,lazy:!0,previewDisabled:!0,onLoad:s=>{s.target.dataset.loaded="true"}},null)])]),e("div",{class:n.itemName},[t.name])])])])):"",!a.loading&&a.list.length<=0&&e(w,null,null)])]})])}});export{Y as default};
