import { usePagging } from "@/hook/pagging";
import { SceneType, getScenePagging } from "@/store/scene";
import { getCaseFusionImgList, getFilepageList } from "@/store/case";

import { computed, reactive, watch, watchEffect } from "vue";

export const useScenePaggingParams = (type) => {
  const pagging = usePagging({
    get: type?getCaseFusionImgList:getFilepageList,
    paramsTemlate: {
      sceneName: "",
      modelTitle: "",
      title: "",
      dictId: "",
      snCode: "",
      type: '1',
    },
  });

  const isSwmx = computed(() => pagging.state.query.type === SceneType.SWMX);
  const keyword = computed({
    get: () => pagging.state.query.title,
    set: (val: string) => {
      pagging.state.query.title = val;
    },
  });

  let oldSnCode = pagging.state.query.snCode;
  watchEffect(() => {
    if (isSwmx.value) {
      oldSnCode = pagging.state.query.snCode;
      pagging.state.query.snCode = "";
    } else {
      pagging.state.query.snCode = oldSnCode;
    }
  });

  watch(
    () => pagging.state.query.type,
    () => {
      pagging.state.pag.currentPage = 1;
    }
  );

  const queryResetRaw = pagging.queryReset;
  pagging.queryReset = () => {
    const type = pagging.state.query.type;
    queryResetRaw();
    pagging.state.query.type = type;
  };

  return reactive({ pagging, keyword, isSwmx });
};
export type ScenePagging = ReturnType<typeof useScenePaggingParams>["pagging"];
