import { useState } from 'react'; import { Tooltip, TextInput, UnstyledButton, rem, type TextInputProps, } from '@mantine/core'; export interface BilingualValue { en: string; am: string; } interface BilingualInputProps extends Omit { value: BilingualValue; onChange: (value: BilingualValue) => void; placeholder?: string | BilingualValue; } function resolvePlaceholder(placeholder: string | BilingualValue | undefined, lang: 'en' | 'am'): string { if (!placeholder) { return lang === 'en' ? 'Enter in English' : 'በአማርኛ ያስገቡ'; } if (typeof placeholder === 'string') { return placeholder; } return placeholder[lang]; } export function BilingualInput({ label, value, onChange, required, placeholder, ...rest }: BilingualInputProps) { const [lang, setLang] = useState<'en' | 'am'>('en'); const otherLang = lang === 'en' ? 'am' : 'en'; const otherLangName = otherLang === 'en' ? 'English' : 'Amharic'; const otherIsEmpty = !value[otherLang]?.trim(); const toggle = () => setLang((l) => (l === 'en' ? 'am' : 'en')); return ( onChange({ ...value, [lang]: e.currentTarget.value })} rightSection={ {lang === 'en' ? 'EN' : 'AM'} {otherIsEmpty && ( )} } styles={{ input: { paddingRight: rem(46), }, }} {...rest} /> ); }