import React from 'react'; import { useEditor } from '@craftjs/core'; import { labelStyle, inputStyle, sectionGap } from './shared'; import { AssetPicker } from '../../../ui/AssetPicker'; interface Feature { title?: string; description?: string; icon?: string; image?: string; imageAlt?: string; buttonText?: string; buttonUrl?: string; } /** * Dedicated per-feature editor for the FeaturesGrid guided panel. Unlike the * generic array editor (which only shows fields already present on the item), * this always exposes icon / image (upload or URL) / button controls, so it * works on template-created features that lack those keys. An image renders in * place of the icon whenever `image` is set. */ export const FeaturesEditor: React.FC<{ selectedId: string; features: unknown }> = ({ selectedId, features }) => { const { actions } = useEditor(); const list: Feature[] = Array.isArray(features) ? (features as Feature[]) : []; const mutate = (fn: (arr: Feature[]) => Feature[]) => actions.setProp(selectedId, (p: any) => { p.features = fn([...(p.features || [])]); }); const update = (i: number, field: keyof Feature, value: string) => mutate((arr) => { arr[i] = { ...arr[i], [field]: value }; return arr; }); const add = () => mutate((arr) => [...arr, { title: 'New Feature', description: 'Describe this feature.', icon: '🔧', image: '', imageAlt: '', buttonText: '', buttonUrl: '' }]); const remove = (i: number) => mutate((arr) => { arr.splice(i, 1); return arr; }); return (