import { useTranslation } from "react-i18next"; import { PropertyAttributeName } from "~/application/enums/entities/PropertyAttributeName"; import InputCheckboxWithDescription from "~/components/ui/input/InputCheckboxWithDescription"; import InputNumber from "~/components/ui/input/InputNumber"; import InputSelector from "~/components/ui/input/InputSelector"; import InputText from "~/components/ui/input/InputText"; import PropertyAttributeHelper from "~/utils/helpers/PropertyAttributeHelper"; interface Props { name: PropertyAttributeName; title: string; value: string | undefined; setValue: React.Dispatch>; className?: string; } export default function PropertyAttribute({ name, title, value, setValue, className }: Props) { const { t } = useTranslation(); function isNumber() { return [ PropertyAttributeName.Min, PropertyAttributeName.Max, PropertyAttributeName.MaxSize, PropertyAttributeName.Rows, PropertyAttributeName.Columns, ].includes(name); } function isBoolean() { return [PropertyAttributeName.Uppercase, PropertyAttributeName.Lowercase, PropertyAttributeName.Password].includes(name); } function isSelector() { return PropertyAttributeHelper.getPropertyAttributeOptions(name, t).length > 0; } function getPlaceholder() { if (name === PropertyAttributeName.Step) { return "0.01"; } return ""; } function getDescription() { if (name === PropertyAttributeName.Uppercase) { return t("models.entity.propertyAttributes.descriptions.uppercase"); } else if (name === PropertyAttributeName.Lowercase) { return t("models.entity.propertyAttributes.descriptions.lowercase"); } return ""; } return ( <> {isNumber() ? ( setValue(e?.toString())} max={name === PropertyAttributeName.Columns ? 12 : undefined} hint={ <> {value && ( )} } /> ) : isBoolean() ? ( setValue(e ? (Boolean(e) === true ? "true" : "false") : "false")} /> ) : isSelector() ? ( setValue(e?.toString())} options={PropertyAttributeHelper.getPropertyAttributeOptions(name, t)} hint={ <> {value && ( )} } > ) : ( setValue(e.toString())} placeholder={getPlaceholder()} hint={ <> {value && ( )} } /> )} ); }