import { computed, ref } from 'vue'
import { useAppStore } from '@/stores/app'

export function useLockFn(fn: (...args: any[]) => Promise<any>) {
    const isLock = ref(false)
    const lockFn = async (...args: any[]) => {
        if (isLock.value) return
        isLock.value = true
        try {
            const res = await fn(...args)
            isLock.value = false
            return res
        } catch (e) {
            isLock.value = false
            throw e
        }
    }
    return {
        isLock,
        lockFn
    }
}
export function useToggle() {
    const show = ref(false)
    const handleToggle = () => {
        show.value = !show.value
    }
    return {
        show,
        handleToggle
    }
}

export function useTabs() {
    const appStore = useAppStore()
    const tabsColor = computed(() => appStore.tabsColor)
    return {
        tabsColor
    }
}
