import { defineStore } from 'pinia' import type {SmartBlock} from "@models/smartblock/smartblock.ts"; import type {SmartBlockCriteria} from "@models/smartblock/smartblockCriteria.ts"; import type {SmartBlockContent} from "@models/smartblock/smartblockContent.ts"; export const useSmartBlockStore = defineStore('smartblock', { state: () => ({ currentSmartBlock: {} as SmartBlock, }), actions: { async loadSmartBlock(smartblockData: SmartBlock) { this.currentSmartBlock = { ...smartblockData } this.currentSmartBlockCriteria = smartblockData.criteria }, resetShowDays() { this.currentSmartBlock.showDays = { ...this.baseShowDays }; }, saveSmartBlock() { // Implement API call to save this.currentSmartBlock }, updateField(payload: { key: string; value: any }) { this.currentSmartBlock[payload.key] = payload.value }, updateSmartBlockCriteriaField(payload: { key: string; value: any }) { console.log(payload) const index = this.currentSmartBlock.criteria.findIndex(el => { return el.criteria === payload.value.criteria && el.criteriagroup === payload.value.criteriagroup }) if (index === -1) { this.currentSmartBlock.criteria.push(payload.value) } else { this.currentSmartBlock.criteria[index] = payload.value; } }, updateSmartBlockContentField(payload: { key: string; value: any }) { this.currentSmartBlock.currentSmartBlockContent[payload.key] = payload.value; }, } })