import{T as b}from"./index-6ac9882e-1725962701482.js";import{d as k,u as R,e as T,q as E,f as l,N as F,g as N,x as A,F as x,j as S,aC as J,E as L,w as z,D as V,aO as q,r as D,A as M}from"./index-8151123c-1725962701482.js";import{a as U,b as X}from"./api-f2ab1cd4-1725962701482.js";import{T as $}from"./index-b03328a0-1725962701482.js";import{u as G}from"./catchData-4810754f-1725962701482.js";const H="_container_1hf18_1",K="_tools_1hf18_8",Q="_tagWrap_1hf18_26",Y="_tags_1hf18_30",Z="_firstButton_1hf18_33",j="_content_1hf18_58",ee="_loadingContent_1hf18_68",te="_itemWrap_1hf18_71",ae="_itemWrapBox_1hf18_76",ne="_item_1hf18_71",le="_cover_1hf18_91",ie="_itemImg_1hf18_108",ce="_itemBg_1hf18_138",se="_itemName_1hf18_163",re="_popSelect1_1hf18_171",de="_textBtn_1hf18_181",oe="_iconArrow_1hf18_181",ue="_textBtnActive_1hf18_193",c={container:H,tools:K,tagWrap:Q,tags:Y,firstButton:Z,content:j,loadingContent:ee,itemWrap:te,itemWrapBox:ae,item:ne,cover:le,itemImg:ie,itemBg:ce,itemName:se,popSelect1:re,textBtn:de,iconArrow:oe,textBtnActive:ue};function B(g){return typeof g=="function"||Object.prototype.toString.call(g)==="[object Object]"&&!V(g)}const O=k({name:"ChildNodeSearch",props:{activeRow:{type:Object,default:()=>({})},list:{type:Array,default:()=>[]},loading:{type:Boolean,default:!1}},emits:["selectChildTag"],setup(g,{emit:_}){const{activeRow:r}=q(g),u=D({});M(()=>g.activeRow,()=>{r.value=g.activeRow,I()});const I=()=>{r.value.activeIndex?(r.value.children||[]).forEach(e=>{if(e.id===r.value.activeIndex){let d,m="";e.children&&(d=[{columnName:e.children[0].columnName,name:"全部",id:""},...e.children],m=e.children[0].columnName,u.value={...e,columnName:m,activeIndex:e.activeIndex,children:d})}}):u.value={}};return E(()=>{I()}),()=>{var s;return l(x,null,[((s=r.value)==null?void 0:s.id)&&l(x,null,[l(N,{label:r.value.columnName+"",class:c.tags},{default:()=>[l(A,{size:[12,8]},{default:()=>{var e;return[(e=r.value)==null?void 0:e.children.map(d=>l(x,null,[l(S,{round:!0,secondary:(r.value.activeIndex||"")!=d.id,type:(r.value.activeIndex||"")==d.id?"primary":"default",onClick:()=>{if(g.loading)return;r.value.activeIndex=d.id;let m,v="";d.children?(m=[{columnName:d.children[0].columnName,name:"全部",id:""},...d.children],v=d.children[0].columnName,u.value={...d,columnName:v,activeIndex:"",children:m}):u.value={},_("selectChildTag",r.value.activeIndex)}},{default:()=>[d.name]})]))]}})]}),l(O,{activeRow:u.value,onSelectChildTag:e=>{_("selectChildTag",e||r.value.activeIndex)}},null)])])}}}),ve=k({name:"XiaokuAi",setup(){const g=G(),_=R(),r=localStorage.getItem("xiaoku-ai-search"),u=r?JSON.parse(r):{},I=u.childSelectId||u.tagActiveId,s=T({musicTagIds:I?[I]:[],enable:!0,instrumentId:u.instrumentId||null,keyword:"",page:1,rows:9999}),e=T({tags:[],tagChildren:[],tagActiveId:u.tagActiveId||"",tagActive:{},tagIndex:u.instrumentId||0,list:[],loading:!1,selectParents:{},childSelectId:u.childSelectId||null}),d=(n,i,t=[])=>{for(const o of i){if(o.children&&o.children.length>0){const a=d(n,o.children,[...t,o.id]);if(a.includes(n))return a}if(o.id===n)return[...t,n]}return t},m=(n,i)=>{for(const t of i){if(n.includes(t.id)&&t.children&&t.children.length>0){let o;t.children.forEach(a=>{n.includes(a.id)&&(o=a.id)}),t.activeIndex=o}t.children&&t.children.length>0&&m(n,t.children)}},v=n=>{for(const i of n)i.children&&i.children.length>0,i.activeIndex="",i.children&&i.children.length>0&&v(i.children)},P=n=>{if(e.loading)return;e.tagActiveId=n.id,e.childSelectId=null,v(e.tags);let i,t="";n.children?(i=[{columnName:n.children[0].columnName,name:"全部",id:""},...n.children],t=n.children[0].columnName,e.selectParents={...n,columnName:t,activeIndex:"",children:i}):e.selectParents={},localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:s.instrumentId,childSelectId:e.childSelectId})),h()},W=async()=>{const n=await U();if(Array.isArray(n==null?void 0:n.data)&&n.data.length){const i=n.data||[];if(e.tags=[{columnName:i[0].columnName,name:"全部",id:""},...i],!e.tagActiveId)e.tagActiveId=e.tags[0].id;else{let t=d(u.childSelectId,e.tags);const o=t.findIndex(a=>a===u.childSelectId);t=t.slice(0,o+1),m(t,e.tags),e.tags.forEach(a=>{if(a.id===e.tagActiveId){let p,y="";if(a.children){p=[{columnName:a.children[0].columnName,name:"全部",id:""},...a.children],y=a.children[0].columnName;let C;a.children.forEach(w=>{t.includes(w.id)&&(C=w.id)}),e.selectParents={...a,columnName:y,activeIndex:C||"",children:p}}else e.selectParents={}}})}}},h=async()=>{var n;e.loading=!0;try{const i=e.childSelectId||e.tagActiveId,t=await X({...s,musicTagIds:[i]});Array.isArray((n=t==null?void 0:t.data)==null?void 0:n.rows)&&(e.list=t.data.rows)}catch(i){}e.loading=!1};E(async()=>{e.loading=!0;try{if(await W(),await h(),await g.getSubjects(),localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:s.instrumentId,childSelectId:e.childSelectId,musicTagIds:s.musicTagIds})),s.instrumentId){let n=[];g.getSubjectInstruments.forEach(i=>{Array.isArray(i.instruments)&&i.instruments.forEach(t=>{s.instrumentId===t.value&&(n=i.instruments||[])})}),n.length>0&&f(n)}}catch(n){}e.loading=!1});const f=n=>{const i={};return n==null||n.forEach(t=>{t.id===e.tagIndex&&(i.selected=!0,i.name=t.name)}),i};return()=>{let n,i;return l("div",{class:c.container},[l("div",{class:c.tools},[l("div",{class:c.tagWrap},[l(F,{labelAlign:"left",labelPlacement:"left"},{default:()=>{var t,o;return[l(N,{label:((o=(t=e.tags)==null?void 0:t[0])==null?void 0:o.columnName)||"",class:c.tags},{default:()=>[l(A,{size:[12,8]},B(n=e.tags.map(a=>l(x,null,[l(S,{round:!0,secondary:e.tagActiveId!==a.id,type:e.tagActiveId===a.id?"primary":"default",onClick:()=>P(a)},{default:()=>[a.name]})])))?n:{default:()=>[n]})]}),l(O,{activeRow:e.selectParents,loading:e.loading,onSelectChildTag:a=>{e.childSelectId=a,localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:s.instrumentId,childSelectId:e.childSelectId,musicTagIds:s.musicTagIds})),h()}},null),l(N,{label:"乐器",class:c.tags},{default:()=>[l(A,{size:[12,8]},B(i=g.getSubjectInstruments.map(a=>a.instruments&&a.instruments.length>1?l(J,{options:a.instruments,trigger:"hover",value:e.tagIndex,"onUpdate:value":[p=>e.tagIndex=p,()=>{s.instrumentId=e.tagIndex,localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:e.tagIndex,musicTagIds:s.musicTagIds})),h()}],scrollable:!0,key:a.value,class:[c.popSelect1]},{default:()=>[l(S,{round:!0,textColor:f(a.instruments).selected?"#fff":"#000",color:f(a.instruments).selected?"#198CFE":"rgba(46, 51, 56, .05)",type:f(a.instruments).selected?"primary":"default",class:[c.textBtn,f(a.instruments).selected&&c.textBtnActive]},{default:()=>[f(a.instruments).name||a.name,l("i",{class:c.iconArrow},null)]})]}):l(S,{round:!0,textColor:e.tagIndex===(a.value||0)?"#fff":"#000",color:e.tagIndex===(a.value||0)?"#198CFE":"rgba(46, 51, 56, .05)",type:e.tagIndex===(a.value||0)?"primary":"default",onClick:()=>{e.tagIndex=a.value||0,s.instrumentId=a.value,localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:a.value,musicTagIds:s.musicTagIds})),h()}},{default:()=>[a.name]})))?i:{default:()=>[i]})]})]}})]),l(b,{round:!0,onSearch:t=>{s.keyword=t,h()}},null)]),l(L,{show:e.loading},{default:()=>[l("div",{class:[c.content,e.loading?c.loadingContent:""]},[e.list.length>0?e.list.map((t,o)=>l("div",{class:c.itemWrap},[l("div",{class:c.itemWrapBox},[l("div",{class:c.item,key:"item-".concat(o),onClick:()=>{sessionStorage.setItem("musicSubjectList",JSON.stringify(t.subjects)),_.push({path:"/xiaoku-music",query:{id:t.id,name:t.name}})}},[l("div",{class:c.cover},[l("div",{class:c.itemImg},[l("div",{class:c.itemBg},null),l(z,{objectFit:"cover",src:t.coverImg,lazy:!0,previewDisabled:!0,onLoad:a=>{a.target.dataset.loaded="true"}},null)])]),l("div",{class:c.itemName},[t.name])])])])):"",!e.loading&&e.list.length<=0&&l($,null,null)])]})])}}});export{ve as default};