import { defineStore } from "pinia" import clonedeep from "clone-deep" import { generateUUID } from "~/lib/utils.js" const defaultBlockNames = { text: "Your name", date: "Date", url: "Link", phone_number: "Phone Number", number: "Number", rating: "Rating", scale: "Scale", slider: "Slider", email: "Email", checkbox: "Checkbox", select: "Select", multi_select: "Multi Select", files: "Files", signature: "Signature", "nf-text": "Text Block", "nf-page-break": "Page Break", "nf-divider": "Divider", "nf-image": "Image", "nf-code": "Code Block", } export const useWorkingFormStore = defineStore("working_form", { state: () => ({ content: null, // Field being edited selectedFieldIndex: null, showEditFieldSidebar: null, showAddFieldSidebar: null, blockForm: null, draggingNewBlock: false, }), actions: { set(form) { this.content = form }, setProperties(properties) { this.content.properties = [...properties] }, openSettingsForField(index) { // If field is passed, compute index if (typeof index === "object") { index = this.content.properties.findIndex( (prop) => prop.id === index.id, ) } this.selectedFieldIndex = index this.showEditFieldSidebar = true this.showAddFieldSidebar = false }, closeEditFieldSidebar() { this.selectedFieldIndex = null this.showEditFieldSidebar = false this.showAddFieldSidebar = false }, openAddFieldSidebar(index) { // If field is passed, compute index if (index !== null && typeof index === "object") { index = this.content.properties.findIndex( (prop) => prop.id === index.id, ) } this.selectedFieldIndex = index this.showAddFieldSidebar = true this.showEditFieldSidebar = false }, closeAddFieldSidebar() { this.selectedFieldIndex = null this.showAddFieldSidebar = false this.showEditFieldSidebar = false }, reset() { this.content = null this.selectedFieldIndex = null this.showEditFieldSidebar = null this.showAddFieldSidebar = null }, resetBlockForm() { this.blockForm = useForm({ type: null, name: null, }) }, prefillDefault(data) { if (data.type === "nf-text") { data.content = "
This is a text block.
" } else if (data.type === "nf-page-break") { data.next_btn_text = "Next" data.previous_btn_text = "Previous" } else if (data.type === "nf-code") { data.content = '