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

import ChooseModal from "./component/choose-modal.vue"

const PageName = "managerSetting";

const visible = ref(false)
const contentRef = ref(null)

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


const type = ref('')

const updateData = ref({
  uid: '',
  inv_fee: '',
  day_time: '',
  return_inv_fee: '',
  cost_fee: '',
  return_cost_fee: ''
})

const events: PageEvents = {
  content: {
    create: () => {
      type.value = 'create'
      visible.value = true

      updateData.value = {
        uid: '',
        day_time: '',
        cost_fee: '',
        inv_fee: '',
        return_inv_fee: '',
        return_cost_fee: ''
      }
    },
    update: (row) => {
      type.value = 'update'
      visible.value = true
      
      updateData.value = {
        id: row.id,
        uid: row.uid,
        inv_fee: row.inv_fee,
        day_time: row.day_time,
        cost_fee: row.cost_fee,
        return_inv_fee: row.return_inv_fee,
        return_cost_fee: row.return_cost_fee
      }
    }
  }
};
</script>

<template>
  <PageAuth :pageName="PageName">
    <PageContainer :hooks="hooks" :events="events" :contentConfig="contentConfig" :search-config="searchConfig" :get-content-ref="ref => contentRef = ref" />
    <ChooseModal v-model:visible="visible" :data="updateData" @refresh="contentRef.onSearch()" :type="type" />
  </PageAuth>
</template>
