// 处理 区分处理管乐迷 管乐团的数据

// import { queryTree_gym } from "@/api/cloudPractice.api"
import { URL_TEACH_GYM, URL_TEACH_GYT, URL_TEACH_KLX } from "@/config"
import { getToken } from "@/libs/auth"

// import { httpAjaxErrMsg, httpAjax } from "@/plugin/httpAjax"
// import { CODE_ERR_CANCELED } from "@/libs/auth"
// import { ElMessage } from "element-plus"

import userStore from "@/store/modules/user"
import { ref } from "vue"

/**
 * 搜索数据
 */
export const useFunction = () => {
   const userStoreHook = userStore()
   const loading = ref(false)

   /** 跳转云教练 */
   const isPracticeShow = ref(false)
   const practiceUrl = ref("")
   function goToCloud(musicId: string, partIndex = 0) {
      //  GYM,GYT,KLX 区分   云教练
      const urlObj = {
         GYT: `${URL_TEACH_GYT}?id=${musicId}&modelType=practice&modeType=json&part-index=${partIndex}&Authorization=${getToken()}&isYjt=1&&isHideBack=false`,
         GYM: `${URL_TEACH_GYM}#/detail/${musicId}?Authorization=${getToken()}&platform=web&part-index=${partIndex}&liveConfig=1&isYjt=1`,
         KLX: `${URL_TEACH_KLX}?Authorization=${getToken()}&id=${musicId}&limitModel=practice&part-index=${partIndex}&isYjt=1&client=teacher`
      }
      isPracticeShow.value = true
      practiceUrl.value = urlObj[userStoreHook.roles!]
      //window.open(urlObj[userStoreHook.roles!], "_blank")
   }
   function handlePracticeClose() {
      isPracticeShow.value = false
      practiceUrl.value = ""
   }
   return { loading, goToCloud, isPracticeShow, practiceUrl, handlePracticeClose }
}

// function chunkArray(array: any[], size: number) {
//    const result = []
//    for (let i = 0; i < array.length; i += size) {
//       result.push(array.slice(i, i + size))
//    }
//    return result
// }
