import{T as y}from"./index-7b4b803c-1694073636386.js";import{d as A,u as S,e as v,n as C,f as e,x as u,F as m,j as I,k as b,B as N,v as k}from"./index-b1b92161-1694073636386.js";import{a as x,b as B}from"./api-7c2239ab-1694073636386.js";import{T as q}from"./index-abb28f9d-1694073636386.js";import{u as w}from"./catchData-634fd794-1694073636386.js";const W="_container_17qfj_1",J="_tools_17qfj_8",O="_tagWrap_17qfj_26",z="_tags_17qfj_30",F="_firstButton_17qfj_33",L="_content_17qfj_48",E="_loadingContent_17qfj_58",V="_itemWrap_17qfj_61",D="_itemWrapBox_17qfj_66",M="_item_17qfj_61",P="_cover_17qfj_81",R="_itemImg_17qfj_98",X="_itemBg_17qfj_128",$="_itemName_17qfj_153",n={container:W,tools:J,tagWrap:O,tags:z,firstButton:F,content:L,loadingContent:E,itemWrap:V,itemWrapBox:D,item:M,cover:P,itemImg:R,itemBg:X,itemName:$},Y=A({name:"XiaokuAi",setup(){const f=w(),h=S(),p=localStorage.getItem("xiaoku-ai-search"),l=p?JSON.parse(p):{},c=v({musicTagIds:l.musicTagIds?l.musicTagIds:[],enable:!0,subjectId:l.subjectId||null,keyword:"",page:1,rows:9999}),a=v({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)};C(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 j=(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()},T=(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:()=>j(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:()=>T(i,o)},{default:()=>[s.name]})]))]})])),e("div",{class:n.tags},[e(u,{size:[20,12]},{default:()=>[e("span",{class:n.firstButton},[b("声部")]),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(y,{round:!0,onSearch:t=>{c.keyword=t,d()}},null)]),e(N,{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)),h.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(q,null,null)])]})])}});export{Y as default};
