import { BaseElement } from '../../types/elements';
import { useCanvasSettings } from '../../contexts/CanvasSettingsContext';
import { NumericPropertyInput } from '../ui/NumericPropertyInput';
interface ExtendedElement extends BaseElement {
src?: string;
objectFit?: string;
padding?: number;
}
interface ImagePropertiesProps {
element: ExtendedElement;
onChange: (elementId: string, property: string, value: unknown) => void;
activeTab: { [key: string]: 'fonctionnalites' | 'personnalisation' | 'positionnement' };
setActiveTab: (tabs: { [key: string]: 'fonctionnalites' | 'personnalisation' | 'positionnement' }) => void;
}
export function ImageProperties({ element, onChange, activeTab, setActiveTab }: ImagePropertiesProps) {
const canvasSettings = useCanvasSettings();
const imageCurrentTab = activeTab[element.id] || 'fonctionnalites';
const setImageCurrentTab = (tab: 'fonctionnalites' | 'personnalisation' | 'positionnement') => {
setActiveTab({ ...activeTab, [element.id]: tab });
};
const openMediaLibrary = () => {
if (window.wp?.media && typeof window.wp.media === 'function') {
const media = window.wp.media({
title: 'Sélectionner une image',
button: {
text: 'Utiliser cette image'
},
multiple: false
});
(media as any).on('select', () => {
const attachment = (media as any).state().get('selection').first().toJSON();
onChange(element.id, 'src', attachment.url);
});
(media as any).open();
} else {
alert('Bibliothèque de médias WordPress non disponible. Veuillez saisir l\'URL manuellement.');
}
};
return (
<>
{/* Système d'onglets pour Image */}
{/* Onglet Fonctionnalités */}
{imageCurrentTab === 'fonctionnalites' && (
<>
{element.src && (
)}
>
)}
{/* Onglet Personnalisation */}
{imageCurrentTab === 'personnalisation' && (
<>
>
)}
{/* Onglet Positionnement */}
{imageCurrentTab === 'positionnement' && (
<>
onChange(element.id, 'x', value)}
/>
onChange(element.id, 'y', value)}
/>
onChange(element.id, 'width', value)}
/>
onChange(element.id, 'height', value)}
/>
{canvasSettings?.selectionRotationEnabled && (
onChange(element.id, 'rotation', value)}
/>
)}
onChange(element.id, 'padding', value)}
/>
onChange(element.id, 'opacity', parseFloat(e.target.value))}
style={{ width: '100%' }}
/>
>
)}
>
);
}