import request from "~/request/request"

export const practiceList = ref([])

let isCalled = false;
export function requestPracticeList(d: any = {}) {
  if (isCalled) {
    return;
  }
  isCalled = true;

  return request({
    url: '/ybk/hdd/index',
    data: {
      limit: 1000,
      hdd_type: 2,
      ...d,
    }
  }).then((res) => {
    if (res.code === '1') {
      practiceList.value = res.data.page_data
      return res.data.page_data
    }
    return []
  }).catch((error) => {
    console.error(error)
    return []
  })
}

export const practiceDialogVisible = ref(false)
export const practiceDialogList = ref([])

export function handleClickPractice(hdd_content: any) {
  practiceDialogList.value = JSON.parse(hdd_content)
  console.log('practiceDialogList.value : ', practiceDialogList.value)
  practiceDialogVisible.value = true
}

export function sendPractice() {
  // TODO: 发送练习 ws
}
