import { computed, onMounted } from "vue";
import { useProjectInfoStore } from "@/stores/projectInfo";

/**
 * 列表页通用逻辑：项目信息缓存清理/筛选 + 新增按钮权限
 * @param {string|number} projectLzType - 项目流转类型（来自 defineProps）
 * @param {Function} getDataFn - 获取列表数据的函数，接收 params 对象
 * @returns {{ showAddBtn: import('vue').ComputedRef<boolean> }}
 */
export function useProjectList(projectLzType, getDataFn) {
  const store = useProjectInfoStore();

  const showAddBtn = computed(() => !projectLzType || projectLzType == 9);

  onMounted(() => {
    if (!window.location.href.includes("xmdakDetaill")) {
      store.clearProjectInfo();
      getDataFn();
    } else {
      getDataFn({
        projectId: store.getProjectInfo.projectId,
      });
    }
  });

  return { showAddBtn };
}
