<script setup lang="ts">
import { shallowRef, ref } from "vue";
import searchConfig from "./config/search.config";
import contentConfig from "./config/content.config";

import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
import { PageContentInstance } from "/@/components/PageContent";
import { usePageSearch, type PageHooks } from "/@/hooks/page";

import { isBeyondTime } from "../../_utils/isBeyondTime";
import { httpRequsetExport } from "/@/utils/export";

const loading = shallowRef(false);
const pageContentRef = ref<PageContentInstance | null>(null);

const hooks: PageHooks = {
  pageSearchHook: () => usePageSearch(undefined, undefined, searchConfig)
};

const callback = {
  onSuccess: () => (loading.value = false),
  onStart: () => (loading.value = true),
  onFail: () => (loading.value = false)
};

async function handleExportAllReport() {
  const params = pageContentRef.value.getBasicParams() || {};
  const { start_date, end_date } = params;

  const beyondTime = isBeyondTime({
    start: start_date,
    end: end_date,
    len: 30
  });

  if (beyondTime) return;

  await httpRequsetExport({
    fileType: "aplication/zip",
    name: "延时发货单.zip",
    isPurchase: true,
    url: "seoonae",
    ...callback,
    params
  });
}
</script>

<template>
  <PageContainer
    :hooks="hooks"
    :getContentRef="ref => (pageContentRef = ref)"
    :content-config="contentConfig"
    :search-config="searchConfig"
  >
    <template #content_header>
      <el-button
        @click="handleExportAllReport"
        size="small"
        :icon="useRenderIcon('arrow-up-line')"
        type="primary"
        >导出</el-button
      >
    </template>
  </PageContainer>
</template>
