import { ref } from 'vue'

/**
 * 页面级加载状态管理
 * @param initialLoading 初始 loading 状态，默认 false
 */
export function usePageLoading(initialLoading = false) {
  const loading = ref(initialLoading)

  const startLoading = () => {
    loading.value = true
  }

  const stopLoading = () => {
    loading.value = false
  }

  return {
    loading,
    startLoading,
    stopLoading,
  }
}

/**
 * 按钮级别加载状态管理
 */
export function useButtonLoading() {
  const buttonLoading = ref(false)

  const startButtonLoading = () => {
    buttonLoading.value = true
  }

  const stopButtonLoading = () => {
    buttonLoading.value = false
  }

  return {
    buttonLoading,
    startButtonLoading,
    stopButtonLoading,
  }
}