<script setup lang="ts">
import { ref } from "vue";
import { PageSearch, usePageSearch } from "/@/components/PageSearch";
import searchConfig from "./config/search.config";
import contentConfig from "./config/content.config";
import PageAuth from "/@/components/PageAuth";
import { PageModal, usePageModal } from "/@/components/PageModal";
import modalConfig from "./config/modal.config";
import { PageContent } from "/@/components/PageContent";
import type { PageContentInstance } from "/@/components/PageContent";
import { useResponseHandle } from "/@/hooks/useAsync";
import { httpDetail } from "/@/api/parameter/video";
const pageContentRef = ref<PageContentInstance | null>(null);

const {
  pageModalRef,
  handleUpdateData,
  handleCreateData,
  handlePreviewData,
  handleConfrim,
  defaultInfo
} = usePageModal({
  pageContentRef
});
const { handleResetClick, handleSearchClick } = usePageSearch();
const responseHandle = useResponseHandle();
async function handleDetailData(row, type) {
  const { id } = row;
  //
  const { code, data, message } = await httpDetail({ id: id });

  responseHandle({
    code,
    message,
    handler: () => {
      if (type === "preview") {
        handlePreviewData(data);
      }
      if (type === "update") {
        handleUpdateData(data);
      }
    }
  });
}
</script>

<template>
  <!-- <PageAuth :pageName="pageName"> -->
  <PageSearch
    :form-config="searchConfig"
    @search-btn-click="handleSearchClick"
    @reset-btn-click="handleResetClick"
  />
  <PageContent
    ref="pageContentRef"
    :content-config="contentConfig"
    @create-btn-click="handleCreateData"
    @preview-btn-click="row => handleDetailData(row, 'preview')"
    @update-btn-click="row => handleDetailData(row, 'update')"
  />
  <PageModal
    ref="pageModalRef"
    :modal-config="modalConfig"
    :default-info="defaultInfo"
    @confirm-btn-click="handleConfrim"
  />
  <!-- </PageAuth> -->
</template>
