<template>
	<el-card shadow="never" class="list-card">
		<Table
            ref="cueWordTemplateTable"
            :tableParams="tableParams"
            :btnRole="roleBtn"
            :right-btn="[]"
            @handleAdd="handleAdd('add')"
            @handleEdit="handleAdd('edit', $event)"
        >
		</Table>
	</el-card>

	<addCueWordTemplate ref="addCueWordTemplateRef" @refresh="handleQuery" />
</template>

<script setup name="MessageTemplate" lang="ts">
import { listCueWordTemplate, delCueWord } from '@/api/system/messageTemplate';
import { MessageTemplateVO, MessageTemplateQuery } from '@/api/system/messageTemplate/types';
import auth from '@/plugins/auth'
import Table from '@/components/Table/index.vue'
import { tableTypes } from '@/components/Table/types'
import addCueWordTemplate from './add.vue'

const roleBtn = ref([
    { type: 'add', hasPermi: 'system:cueWordTemplate:add', },
    { type: 'edit', hasPermi:  'system:cueWordTemplate:edit', },
    { type: 'remove', hasPermi:'system:cueWordTemplate:remove', }
])

const tableParams = reactive<tableTypes<MessageTemplateQuery, MessageTemplateVO>>({
	tableColumn: [
		{ show: true, label: '模板名称', prop: 'templateName' },
		{ show: true, label: '模板编码', prop: 'templateCode' },
        { show: true, label: '操作', width: 150, prop: 'operation', render: ({ column }) => { return [] } }
	],
	keyId: 'id',
	queryParams: {},
	listFn: listCueWordTemplate,
    delFn: delCueWord
})

// const handleData = (type: string, column: MessageTemplateVO) => {
// 	let enabled = false
// 	let templateData = null
// 	if(column.detailEntities && column.detailEntities.length > 0) {
// 		templateData = column.detailEntities.find(item => item.templateDetailType == type)
// 		enabled = templateData?.enabled
// 	}
// 	return [
// 		h(ElSwitch, {
// 			modelValue: enabled,
// 			disabled: !templateData,
// 			style: { 'margin-right': '5px' },
// 			onChange: async(v) => {
// 				await changeEnable(templateData.id, v)
// 				ElMessage.success((v ? '启用' : '禁用') + '成功')
// 				templateData.enabled = v
// 			} 
// 		}),
// 		h(ElButton, { link: true, type: 'primary', onClick: () => { handleAdd(type, column) } }, '编辑内容')
// 	]
// }

const cueWordTemplateTable = ref()
/** 搜索按钮操作 */
const handleQuery = () => {
	cueWordTemplateTable.value.getData()
}

const addCueWordTemplateRef = ref()
const handleAdd = (type: string, data?: MessageTemplateVO) => {
	addCueWordTemplateRef.value.open(type, data)
}
</script>
