import { ref } from 'vue';
import { store } from '@/store';
import { useAsRouter } from './useAsRouter'
import dayjs, { Dayjs } from 'dayjs';
import 'dayjs/locale/zh-cn';
dayjs.locale('zh-cn');
import { message } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal } from 'ant-design-vue';

interface CommonInterface {
	model ?: CommonType.ModelType,
	page ?: CommonType.PageType
	search ?: CommonType.SearchType
	table ?: CommonType.TableType
	delParam ?: CommonType.DeleteType,

}

export const useCommon = () => {
	const { routerTo, routerCur, routerArrayCur } = useAsRouter();
	let commomParams = ref<CommonInterface>({
		model: {
			title: '',
			okText: '提交',
			resetText: '重置',
			cancelText: '取消',
		},

		page: {
			current: 1,
			pageSize: 1,
			total: 10,
			pageSizeOptions: ['10', '20', '30', '40'],
			hideOnSinglePage: false,
			showSizeChanger: true
		},

		search: {
			page: 1,
			pagesize: 10,
			sort: 'id',
			sortby: 'desc',
			keyword: ''
		},

		table: {
			data: [],
			columns: [],
		},

		delParam: {
			id: 0
		},



		// // MENU
		// openSubMenu: [],
		// menuList: [],

	})

	let openAddModel = ref<Boolean>(store.state.openAddModel);
	let openOtherModel_1 = ref<Boolean>(store.state.openOtherModel_1);
	let openSearchModel = ref<Boolean>(store.state.openSearchModel); // 搜索

	// 点击菜单获取路由
	const onMenu = (path) => {
		routerTo(path);
	};

	// Modal
	const hideModal = () => {
		store.commit('getOpenModel', {
			openAddModel: false
		})
	}

	// 打开添加/编辑对话框
	const showModal = () => {
		store.commit('getOpenModel', {
			openAddModel: true
		})
	};

	const showOtherModal1 = () => {
		store.commit('getOpenMoreModel', {
			openOtherModel_1: true
		})
	};

	const hideOtherModal1 = () => {
		store.commit('getOpenMoreModel', {
			openOtherModel_1: false
		})
	}

	// 打开搜索
	const showSearch = () => {
		store.commit('getSearchModel', {
			openSearchModel: true
		})
	};

	const hideSearch = () => {
		store.commit('getSearchModel', {
			openSearchModel: false
		})
	}

	// 富文本全局
	let richOption = ref<Object>({
		debug: 'info',
		modules: {
			toolbar: [
				[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
				['bold', 'italic', 'underline', 'strike'],
				[{ 'list': 'ordered' }, { 'list': 'bullet' }],
				[{ 'indent': '-1' }, { 'indent': '+1' }],
				[{ 'size': ['small', false, 'large', 'huge'] }],
				[{ 'header': [1, 2, 3, 4, 5, 6, false] }, { 'align': [] }],
				// 添加字体选择器，确保包含黑体和仿宋_GB2312
				[{ 'font': ['黑体', '仿宋_GB2312', 'Arial', /* 其他字体 */] }]                                       // remove formatting button
			]
		},
		placeholder: '请输入文字'
	});

	// 禁止使用日期
	const disabledDate = (val : Dayjs) => {
		return val && val < dayjs().endOf('day');
	};
	
	const disabledDateFront = (val : Dayjs) => {
		return val && val > dayjs().endOf('day');
	};

	// 照片前缀
	// const imageprefix : string = 'https://admin1.jcjob.cn/img/'
	const imageprefix : string = 'https://rcsc-test.jcjob.cn/img/'


	return {
		store,
		commomParams,
		openAddModel,
		onMenu,
		hideModal,
		showModal,
		openOtherModel_1,
		showOtherModal1,
		hideOtherModal1,
		dayjs,
		richOption,
		message,
		ExclamationCircleOutlined,
		Modal,
		disabledDate,
		disabledDateFront,
		imageprefix,
		openSearchModel,
		showSearch,
		hideSearch
	}
}