<script setup lang="ts">
import { PageSearch, usePageSearch } from "/@/components/PageSearch";
import { PageModal, usePageModal } from "/@/components/PageModal";
import { PageContent } from "/@/components/PageContent";
import searchFormConfig from "./config/search.config";
import contentConfig from "./config/content.config";
import modalConfig from "./config/modal.config";
import { onMounted, ref } from "vue";
import { useUserStoreHook } from "/@/store/modules/user";
import PagePower from "/@/components/PagePower/PagePower.vue";
import ProcessList from "./components/process-list.vue";

defineOptions({
  name: "invoiceheader"
});

const currentProcess = ref<Record<string, any>>({});

const { pageContentRef, handleResetClick, handleSearchClick } = usePageSearch();

const {
  pageModalRef,
  handleUpdateData,
  handleCreateData,
  handlePreviewData,
  handleConfrim,
  defaultInfo
} = usePageModal({ pageContentRef });

function handleProcessChange(process) {
  currentProcess.value = process;
  //重新请求
}

onMounted(
  () =>
    (contentConfig.powers =
      useUserStoreHook().getMenuActions("setActionProcess"))
);
</script>

<template>
  <div class="main role bg-white">
    <PagePower :is-show="contentConfig.powers.some(i => i === '001')">
      <div w-full flex>
        <div class="min-w-240px h-[calc(100vh-90px)] process-list__content">
          <ProcessList
            :current-process="currentProcess"
            @change-btn-click="handleProcessChange"
          />
        </div>

        <div flex-1>
          <PageSearch
            :form-config="searchFormConfig"
            @search-btn-click="handleSearchClick"
            @reset-btn-click="handleResetClick"
          />
          <PageContent
            ref="pageContentRef"
            :content-config="contentConfig"
            @create-btn-click="handleCreateData"
            @update-btn-click="handleUpdateData"
            @preview-btn-click="handlePreviewData"
          />
        </div>
      </div>
    </PagePower>
    <PageModal
      ref="pageModalRef"
      :modal-config="modalConfig"
      :default-info="defaultInfo"
      @confirm-btn-click="handleConfrim"
    />
  </div>
</template>

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

.processs-list__content {
  border-right: 1px solid #dfe6ec;
}
</style>
