<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 { PageContent } from "/@/components/PageContent";
import ResetPwd from "/@/components/ResetPwd";
import resetPwdConfig from "./config/resetPwd.config";
import { usePermission } from "/@/hooks/usePermission";
import EditModel from "./components/edit-dialog.vue";
const modelRef = ref<InstanceType<typeof EditModel>>(null);
const pageName = "user";
const { pageContentRef, handleResetClick, handleSearchClick } = usePageSearch(
  undefined,
  undefined,
  searchConfig
);
//新建/编辑/查看
function handleAddChangeCheck(item: any, id: string, type: string) {
  modelRef.value.show(item, id, type);
}
const resetPwdRef = ref<InstanceType<typeof ResetPwd>>(null);
const { permissions } = usePermission(pageName);
</script>

<template>
  <PageAuth :pageName="pageName">
    <PageSearch
      :form-config="searchConfig"
      @search-btn-click="handleSearchClick"
      @reset-btn-click="handleResetClick"
    />
    <PageContent
      ref="pageContentRef"
      :powers="permissions"
      :content-config="contentConfig"
      @preview-btn-click="row => handleAddChangeCheck(row, row.id, 'view')"
      @update-btn-click="row => handleAddChangeCheck(row, row.id, 'edit')"
      @change-pwd-btn-click="({ id }) => resetPwdRef.show(id)"
    />
    <EditModel ref="modelRef" @reload="pageContentRef.onSearch()" />
    <ResetPwd ref="resetPwdRef" :modalConfig="resetPwdConfig" />
  </PageAuth>
</template>
