<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 modalConfig from "./config/modal.config";
import { PageModal, usePageModal } from "/@/components/PageModal";
import { PageContent } from "/@/components/PageContent";
import { httpDetail } from "/@/api/interest/account";
import type { PageContentInstance } from "/@/components/PageContent";
import { useResponseHandle } from "/@/hooks/useAsync";
const pageContentRef = ref<PageContentInstance | null>(null);
import resetPassword from "/@/components/resetPassword.vue";
const pageName = "account";
const {
  pageModalRef,
  handleUpdateData,
  handleCreateData,
  handlePreviewData,
  handleConfrim,
  defaultInfo
} = usePageModal({
  pageContentRef
});
const { handleResetClick, handleSearchClick } = usePageSearch();
const responseHandle = useResponseHandle();
const passwordModelId = ref("");
const passwordModel = ref(false);
async function handleDetailData(row, type) {
  const { id } = row;
  const { code, data, message } = await httpDetail({ id: id });
  responseHandle({
    code,
    message,
    handler: () => {
      data.card_id = data.card_id.toString();
      console.log(data);
      if (type === "preview") {
        handlePreviewData(data);
      }
      if (type === "update") {
        handleUpdateData(data);
      }
    }
  });
}

function handleChangePwdData(id) {
  passwordModelId.value = id;
  passwordModel.value = true;
}
</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')"
    @change-pwd-btn-click="({ id }) => handleChangePwdData(id)"
  />
  <PageModal
    ref="pageModalRef"
    :modal-config="modalConfig"
    :default-info="defaultInfo"
    @confirm-btn-click="handleConfrim"
  />
  <reset-password
    :itemId="passwordModelId"
    :show-model="passwordModel"
    @refresh="passwordModel = false"
    @cancel="passwordModel = false"
  />
  <!-- </PageAuth> -->
</template>
