<script setup lang="ts">
import { shallowReactive, ref } from "vue"
import contentConfig from "./config/content.config";
import searchConfig from "./config/search.config";
import { usePageSearch, type PageHooks, type PageEvents } from "/@/hooks/page";
import { useRouter } from "vue-router"

import { ElMessage } from "element-plus"
import UpperModal from "./upperModal.vue"


import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
const PageName = "supplier";

const router = useRouter()
const upper = shallowReactive({ visible: false, code: '' })
const contentRef = ref<any>(null)

const hooks: PageHooks = {
  pageSearchHook: () => usePageSearch(undefined, undefined, searchConfig),
};

const events: PageEvents = {
  content: { 
    create: () => router.push('/supplierSettings/supplierDetail?type=create'),
    update: ({ code, status }) => {
      if(String(status) !== '0'){
        ElMessage.warning('禁用后才能修改!')
        return
      }

      router.push('/supplierSettings/supplierDetail?id=' + code + '&type=update')
    },
    preview: ({ code }) => router.push('/supplierSettings/supplierDetail?id=' + code + '&type=preview'),
  }
}

function onUpper(code: string){
  upper.code = code
  upper.visible = true
}

</script>

<template>
  <PageAuth :pageName="PageName">
    <PageContainer
      :hooks="hooks"
      :events="events"
      :search-config="searchConfig"
      :content-config="contentConfig"
      :get-content-ref="ref => contentRef = ref"
    >
      <template #content_action="{ is_upgrade, code }">
        <ElTooltip placement="top" content="升级" v-if="String(is_upgrade) === '0'">
          <ElButton
            @click="onUpper(code)"
            style="transform:rotate(-90deg)" 
            :icon="useRenderIcon('unExpand')" 
            type="primary" 
            link 
          />
        </ElTooltip>
      </template>
    </PageContainer>

    <UpperModal 
      @refresh="() => contentRef?.onSearch()" 
      v-model:visible="upper.visible" 
      :code="upper.code" 
    />
  </PageAuth>
</template>
