'use client'; import React, {ChangeEvent} from 'react'; import {LocationProps, Element, SubElement} from '@/hooks/settings/useLocations'; import InputField from '@/components/form/InputField'; import TextInput from '@/components/form/TextInput'; import TexteAreaInput from '@/components/form/TexteAreaInput'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faMapPin, faPlus} from '@fortawesome/free-solid-svg-icons'; import {useTranslations} from 'next-intl'; interface LocationEditorEditProps { section: LocationProps; newElementNames: { [key: string]: string }; newSubElementNames: { [key: string]: string }; onAddElement: (sectionId: string) => Promise; onAddSubElement: (sectionId: string, elementIndex: number) => Promise; onRemoveElement: (sectionId: string, elementIndex: number) => Promise; onRemoveSubElement: (sectionId: string, elementIndex: number, subElementIndex: number) => Promise; onUpdateElement: (sectionId: string, elementIndex: number, field: keyof Element, value: string) => void; onUpdateSubElement: (sectionId: string, elementIndex: number, subElementIndex: number, field: keyof SubElement, value: string) => void; onNewElementNameChange: (sectionId: string, name: string) => void; onNewSubElementNameChange: (elementIndex: number, name: string) => void; } /** * LocationEditorEdit - Version sidebar édition * Layout linéaire simple, champs empilés verticalement * PAS de CollapsableArea, PAS de grids */ export default function LocationEditorEdit({ section, newElementNames, newSubElementNames, onAddElement, onAddSubElement, onRemoveElement, onRemoveSubElement, onUpdateElement, onUpdateSubElement, onNewElementNameChange, onNewSubElementNameChange, }: LocationEditorEditProps): React.JSX.Element { const t = useTranslations(); return (

{section.name}

{/* Éléments existants */} {section.elements.map(function (element: Element, elementIndex: number): React.JSX.Element { return (
{t('locationComponent.element')}
): void { onUpdateElement(section.id, elementIndex, 'name', e.target.value); }} placeholder={t('locationComponent.elementNamePlaceholder')} /> } removeButtonCallBack={function (): Promise { return onRemoveElement(section.id, elementIndex); }} />
): void { onUpdateElement(section.id, elementIndex, 'description', e.target.value); }} placeholder={t('locationComponent.elementDescriptionPlaceholder')} />
{/* Sous-éléments */} {element.subElements.length > 0 && (
{element.subElements.map(function (subElement: SubElement, subElementIndex: number): React.JSX.Element { return (
): void { onUpdateSubElement(section.id, elementIndex, subElementIndex, 'name', e.target.value); }} placeholder={t('locationComponent.subElementNamePlaceholder')} /> } removeButtonCallBack={function (): Promise { return onRemoveSubElement(section.id, elementIndex, subElementIndex); }} />
); })}
)} {/* Ajouter sous-élément */}
): void { onNewSubElementNameChange(elementIndex, e.target.value); }} placeholder={t('locationComponent.newSubElementPlaceholder')} /> } actionIcon={faPlus} actionLabel={t('locationComponent.addSubElement')} addButtonCallBack={function (): Promise { return onAddSubElement(section.id, elementIndex); }} />
); })} {/* Ajouter élément */} ): void { onNewElementNameChange(section.id, e.target.value); }} placeholder={t('locationComponent.newElementPlaceholder')} /> } actionIcon={faPlus} addButtonCallBack={function (): Promise { return onAddElement(section.id); }} />
); }