| import {
|
| getAdvisorPanelById,
|
| getPersonaById,
|
| saveAdvisorPanelFromForm,
|
| savePersonaFromForm,
|
| } from './creations'
|
| import { loadAdvisorDraft, loadPersonaDraft, saveAdvisorDraft, savePersonaDraft } from './drafts'
|
| import { normalizeAdvisorPanelRecord, type AdvisorFormState } from './advisorPanelFormModel'
|
| import { normalizePersonaFormRecord, PERSONA_FORM_KEYS } from './personaFormModel'
|
|
|
|
|
| export function syncAdvisorDraftToCreations(): string | null {
|
| const d = loadAdvisorDraft()
|
| const panelName = typeof d.panelName === 'string' ? d.panelName.trim() : ''
|
| const appTitle = typeof d.appTitle === 'string' ? d.appTitle.trim() : ''
|
| if (!panelName && !appTitle) return null
|
|
|
| const savedId = typeof d._editingId === 'string' && d._editingId ? d._editingId : null
|
| const existingId = savedId && getAdvisorPanelById(savedId) ? savedId : null
|
| const form = normalizeAdvisorPanelRecord(d) as AdvisorFormState
|
| const id = saveAdvisorPanelFromForm(form, existingId)
|
|
|
| if (d._editingId !== id) {
|
| saveAdvisorDraft({ ...d, _editingId: id })
|
| }
|
| return id
|
| }
|
|
|
|
|
| export function syncPersonaDraftToCreations(): string | null {
|
| const d = loadPersonaDraft()
|
| const name = typeof d.advisorPersonaName === 'string' ? d.advisorPersonaName.trim() : ''
|
| if (!name) return null
|
|
|
| const savedId = typeof d._editingId === 'string' && d._editingId ? d._editingId : null
|
| const existingId = savedId && getPersonaById(savedId) ? savedId : null
|
| const normalized = normalizePersonaFormRecord(d)
|
| const data: Record<string, string> = {}
|
| for (const k of PERSONA_FORM_KEYS) {
|
| data[k] = normalized[k]
|
| }
|
| const id = savePersonaFromForm(data, existingId)
|
|
|
| if (d._editingId !== id) {
|
| savePersonaDraft({ ...d, _editingId: id })
|
| }
|
| return id
|
| }
|
|
|