import { ref, onMounted, onUnmounted } from 'vue';
import { getProtocol } from "@/api/modules/user";

export const useProtocol = (protocolKey: string) => {
  const readTime = ref(7);
  const text = ref(null);

  const startReading = () => {
    getProtocol(protocolKey).then(res => {
      text.value = res.content;
      const interval = setInterval(() => {
        readTime.value--;
        if (readTime.value === 0) {
          clearInterval(interval);
        }
      }, 1000);
    });
  };

  return {
    readTime,
    text,
    startReading
  };
};