import { getGuidance, setGuidance } from '../../custom-plugins/guide-page/api';
import { ref } from 'vue';

export default function useDragGuidance() {
  // 引导页
  const guidanceShow = ref(false);
  let guideInfoData: Record<string, any> = {};
  getGuidanceShow();
  async function getGuidanceShow() {
    try {
      const res = await getGuidance({ guideTag: 'guideInfo' });
      if (res.code === 200) {
        if (res.data) {
          const guideInfo = JSON.parse(res.data?.guideValue) || null;
          if (guideInfo) {
            guideInfoData = guideInfo;
            guidanceShow.value = !guideInfo.teacherDrag;
          }
        } else {
          guidanceShow.value = true;
        }
      }
    } catch (e) {
      console.log(e);
    }
  }
  function setGuidanceShow() {
    try {
      setGuidance({
        guideTag: 'guideInfo',
        guideValue: JSON.stringify(
          Object.assign(guideInfoData, { teacherDrag: true })
        )
      });
      guidanceShow.value = false;
    } catch (e) {
      console.log(e);
    }
  }
  return {
    guidanceShow,
    setGuidanceShow
  };
}
