import { inject, watch, type Ref } from 'vue';
import { tableLoadingKey } from '@kt/unity-table-layout';
export const useSyncLoadingStataus = (attrs: Record<string, any>) => {
  const tableLoading = inject<Ref<boolean>>(tableLoadingKey);
  watch(
    () => attrs.loading,
    val => {
      // 兼容直接传递 loading 的场景，而不是 :loading="true/false"，一般不会有这个问题
      if (val === '') val = true;
      tableLoading && (tableLoading.value = val as any);
    },
    { immediate: true }
  );
};
