import { ref } from 'vue' import { defineStore } from 'pinia' type ModalContentType = { title?: string; guardMessage?: string; content?: string; contentHTML?: string; acceptText?: string; cancelText?: string; dangerous?: boolean; } export const useModalStore = defineStore('modal', () => { const modalContent = ref({ title: 'title', guardMessage: 'guardMessage', content: '', contentHTML: '', acceptText: 'acceptText', cancelText: 'cancelText', dangerous: false, }); const isOpened = ref(false); const onAcceptFunction: any = ref(()=>{}); const onCancelFunction: any = ref(()=>{}); function togleModal() { isOpened.value = !isOpened.value; } function setOnAcceptFunction(func: Function) { onAcceptFunction.value = func; } function setOnCancelFunction(func: Function) { onCancelFunction.value = func; } function setModalContent(content: ModalContentType) { modalContent.value = { title: content.title || '', guardMessage: content.guardMessage || '', content: content.content || '', contentHTML: content.contentHTML || '', acceptText: content.acceptText || 'acceptText', cancelText: content.cancelText || 'cancelText', dangerous: content.dangerous ?? false, }; } function resetmodalState() { isOpened.value = false; modalContent.value = { title: 'title', guardMessage: 'guardMessage', content: 'content', contentHTML: '', acceptText: 'acceptText', cancelText: 'cancelText', dangerous: false, }; setOnAcceptFunction(()=>{}); } return {isOpened, setModalContent,onCancelFunction, togleModal,modalContent, setOnAcceptFunction, onAcceptFunction,resetmodalState,setOnCancelFunction} })