<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 addModel from "./cpns/addModel.vue";
import { usePermission } from "/@/hooks/usePermission";
const actionModalRef = ref<InstanceType<typeof addModel>>(null);
const pageName = "setTheme";
const { pageContentRef, handleResetClick, handleSearchClick } = usePageSearch(
  undefined,
  undefined,
  searchConfig
);
const { hasPermissionWithCode, permissions } = usePermission(pageName);
function handleAddChangeCheck(type: string, id: string) {
  actionModalRef.value.onShow("主题设置", type, id);
}
</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"
      :powers="permissions"
      :content-config="contentConfig"
      @preview-btn-click="({ id }) => handleAddChangeCheck('preview', id)"
      @update-btn-click="({ id }) => handleAddChangeCheck('update', id)"
    />
    <addModel ref="actionModalRef" @reload="pageContentRef.onSearch()" />
  </PageAuth>
</template>
