import { EntityDetailView } from '@/components/views/entity-detail-view';
import type { EntityIdentity } from '@/components/views/entity-detail-view';
import type {
    CatalogEngineDetailProps,
    CatalogTrimDetailProps,
} from '@/types/catalog';

type EntityDetailProps = CatalogEngineDetailProps | CatalogTrimDetailProps;

export default function EntityShow(props: EntityDetailProps) {
    const {
        entity_type,
        entity,
        context,
        features = [],
        data_values = [],
        feature_disclaimers = [],
    } = props;

    const identity: EntityIdentity = {
        name: entity.name,
        key: 'engine_key' in entity ? entity.engine_key : entity.trim_key,
        status: entity.status,
        description: entity.description,
        // Only engines carry name_de/name_fr/name_it (IA §6); trims have no
        // localized name — the language switch has no effect there.
        localizedNames:
            'engine_key' in entity
                ? {
                      name_de: entity.name_de,
                      name_fr: entity.name_fr,
                      name_it: entity.name_it,
                  }
                : undefined,
        links: {
            model: context.model,
            bodyType: context.body_type,
        },
    };

    return (
        <EntityDetailView
            entityType={entity_type}
            identity={identity}
            payloadSupported
            features={features}
            dataValues={data_values}
            featureDisclaimers={feature_disclaimers}
        />
    );
}
