<script setup lang="ts">
import contentConfig from "./config/content.config";
import searchConfig from "./config/search.config";
import modalConfig from "./config/modal.config";
import { usePageSearch, usePageModal, type PageHooks } from "/@/hooks/page";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
import { ElMessage } from "element-plus";
import { httpListAll } from "/@/api/reportForm/personnelReportRecord";
import { ref, onMounted } from "vue";
import dayjs from "dayjs";

const PageName = "personnelReportRecord";
const refModalConfig = ref(modalConfig);
const list = ref([]);

async function get_list() {
  const arr = [];
  const { code, data } = await httpListAll({});

  if (code === 0) {
    data.forEach(si => {
      const model = {
        value: si.id,
        label: si.name,
        disabled: String(si.status) == "0"
      };
      arr.push(model);
    });
  }
  list.value = arr;
  refModalConfig.value.formItems[0].options = list.value;
}

const pageSearchHook = function () {
  return usePageSearch(undefined, undefined, searchConfig);
};

const pageModalHook = function (pageContentRef) {
  return usePageModal({
    pageContentRef,
    confirmCallback: ({ create_timer }) => {
      const start = dayjs(create_timer).format("YYYY-MM-DD");
      const end = dayjs(start).endOf("month").format("YYYY-MM-DD");
      return { start, end };
    }
  });
};

const hooks: PageHooks = { pageSearchHook, pageModalHook };
onMounted(() => get_list());
</script>

<template>
  <PageAuth :pageName="PageName">
    <PageContainer
      :hooks="hooks"
      :content-config="contentConfig"
      :search-config="searchConfig"
      :modal-config="refModalConfig"
    >
      <template #content_action="{ status, down_url }">
        <el-link
          :href="down_url"
          v-if="String(status) === '2'"
          target="_blank"
          :underline="false"
        >
          <ElButton
            link
            size="small"
            type="primary"
            :icon="useRenderIcon('download-line')"
          />
        </el-link>
      </template>
    </PageContainer>
  </PageAuth>
</template>
