<script setup lang="ts">
import { ref } from "vue";
import { PageSearch, usePageSearch } from "/@/components/PageSearch";
import { PageContent } from "/@/components/PageContent";
import contentConfig from "./config/content.config";
import { usePermission } from "/@/hooks/usePermission";
import searchConfig from "./config/search.config";
import EditModel from "./components/edit-dialog.vue";
const { pageContentRef, handleResetClick, handleSearchClick } = usePageSearch(
  undefined,
  undefined,
  searchConfig
);
const modelRef = ref<InstanceType<typeof EditModel>>(null);
const pageName = "updates";
const { hasPermissionWithCode, permissions } = usePermission(pageName);
function handleAddChangeCheck(item: any, id: string, type: string) {
  modelRef.value.show(item, id, type);
}
</script>

<template>
  <PageAuth :pageName="pageName">
    <PageSearch
      :form-config="searchConfig"
      @search-btn-click="handleSearchClick"
      @reset-btn-click="handleResetClick"
    >
      <template #action>
        <el-button
          type="primary"
          @click="handleAddChangeCheck({}, '', 'create')"
          v-if="hasPermissionWithCode('002')"
        >
          新增
        </el-button>
      </template>
    </PageSearch>
    <PageContent
      ref="pageContentRef"
      :content-config="contentConfig"
      :powers="permissions"
      @preview-btn-click="row => handleAddChangeCheck(row, row.id, 'view')"
      @update-btn-click="row => handleAddChangeCheck(row, row.id, 'edit')"
    />

    <EditModel ref="modelRef" @reload="pageContentRef.onSearch()" />
  </PageAuth>
</template>
