<script setup lang="ts">
import { ref } from "vue";
import { usePermission } from "/@/hooks";
import { PageSearch, usePageSearch } from "/@/components/PageSearch";
import { PageContent } from "/@/components/PageContent";
import searchFormConfig from "./config/search.config";
import contentConfig from "./config/content.config";
import GroupModal from "./components/group-modal.vue";

defineOptions({
  name: "userGroup"
});

const groupModalRef = ref<InstanceType<typeof GroupModal>>(null);
const { pageContentRef, handleResetClick, handleSearchClick } = usePageSearch();

const { permission, contentConfigRef } = usePermission({
  pageName: "userGroup",
  contentConfig,
  callback: powers => (contentConfig.powers = powers)
});
</script>

<template>
  <div class="main role">
    <PagePower :is-show="permission.list">
      <div w-full>
        <PageSearch
          :form-config="searchFormConfig"
          @search-btn-click="handleSearchClick"
          @reset-btn-click="handleResetClick"
        />
        <PageContent
          ref="pageContentRef"
          :content-config="contentConfigRef"
          @create-btn-click="() => groupModalRef.onDisplay()"
          @update-btn-click="({ id }) => groupModalRef.onDisplay(id)"
          @preview-btn-click="({ id }) => groupModalRef.onDisplay(id, true)"
        />
      </div>
    </PagePower>

    <GroupModal ref="groupModalRef" @reload="() => handleResetClick()" />
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
</style>
