import { memo } from '@wordpress/element'; import type { MouseEvent } from 'react'; import FieldWrapper from './FieldWrapper'; import ButtonInput from '../Inputs/ButtonInput'; import Icon from '../../utils/Icon'; import useOnboardingStore from '../../store/useOnboardingStore'; import useAlertStore from '../../store/useAlertStore'; interface StatusSection { title: string; content: string; content_html?: string; } interface StatusAction { type: 'button' | 'link'; label: string; onClick?: string; groupId?: string; href?: string; target?: string; rel?: string; } interface StatusFieldConfig { id: string; label?: string; context?: any; context_html?: string; container_class?: string; title_class?: string; content_class?: string; actions_class?: string; sections?: StatusSection[]; actions?: StatusAction[]; [key: string]: any; } interface StatusProps { field: StatusFieldConfig; value?: any; onChange?: (value: any) => void; } const Status = ({ field }: StatusProps) => { const { settings, setValue, getValue } = useOnboardingStore(); const { setAlertState, getAlertState } = useAlertStore(); const { container_class = 'max-w-sm bg-gray-100 rounded-2xl p-6 text-gray-800', title_class = 'text-lg font-semibold mb-1', content_class = 'text-base mb-2', actions_class = 'flex items-center gap-4 !text-[#C4511C] font-semibold', sections = [], actions = [], } = field; /** * Resolve placeholders [[field_id]] using Zustand getValue. */ const resolvePlaceholders = (text: string): string => { if (!text || typeof text !== 'string') { return text; } return text.replace(/\[\[([a-zA-Z0-9_\-]+)\]\]/g, (_match, fieldId) => String(getValue(fieldId))); }; const renderSection = (section: StatusSection, index: number) => { const resolvedContent = section.content_html ? resolvePlaceholders(section.content_html) : resolvePlaceholders(section.content); return (
{resolvedContent}
)}