import { ref } from 'vue';
import useWebsocket from '@/hooks/setting/useWebsocket.ts';

export const useWorkshopTop = () => {
  const workshopList = ref<Array<string>>([]);
  const { start } = useWebsocket(handleWorkshopData);
  const openTopWs = () => {
    const msg = JSON.stringify({
      biz_type: 'workshop_score_ranking',
    });
    start({ msg });
  };

  function handleWorkshopData(data: string) {
    const res = JSON.parse(data).data;
    workshopList.value = res['workshopList'];
    console.log('workshopList', workshopList.value);
  }

  return {
    openTopWs,
    workshopList,
  };
};

export default useWorkshopTop;
