"use client"; import { type CSSProperties } from "react"; import { Entity } from "@/api/entities"; import { Feature } from "@/lib/useEditorState"; import { EntityTypeGroupId, EntityTypeOption, findEntityTypeOption, groupEntityTypeOptions, } from "@/lib/entityTypeOptions"; type EntityFormState = { name: string; slug: string; type_id: string; }; type GeometryMetaFormState = { time_start: string; time_end: string; binding: string; }; type Props = { selectedFeature: Feature | null; selectedFeatureEntitySummary: string; selectedFeatureBindingSummary: string; entities: Entity[]; selectedGeometryEntityIds: string[]; onEntityIdsChange: (values: string[]) => void; entitySearchQuery: string; onEntitySearchQueryChange: (value: string) => void; entitySearchResults: Entity[]; selectedSearchEntityId: string | null; onSelectSearchEntityId: (value: string | null) => void; onAddSelectedSearchEntity: () => void; isEntitySearchLoading: boolean; entityForm: EntityFormState; onEntityFormChange: (key: keyof EntityFormState, value: string) => void; entityTypeOptions: EntityTypeOption[]; geometryMetaForm: GeometryMetaFormState; onGeometryMetaFormChange: (key: keyof GeometryMetaFormState, value: string) => void; isEntitySubmitting: boolean; onCreateEntityAndAttach: () => void; onApplyEntitiesForSelectedGeometry: () => void; changeCount: number; entityFormStatus: string | null; }; export default function SelectedGeometryPanel({ selectedFeature, selectedFeatureEntitySummary, selectedFeatureBindingSummary, entities, selectedGeometryEntityIds, onEntityIdsChange, entitySearchQuery, onEntitySearchQueryChange, entitySearchResults, selectedSearchEntityId, onSelectSearchEntityId, onAddSelectedSearchEntity, isEntitySearchLoading, entityForm, onEntityFormChange, entityTypeOptions, geometryMetaForm, onGeometryMetaFormChange, isEntitySubmitting, onCreateEntityAndAttach, onApplyEntitiesForSelectedGeometry, changeCount, entityFormStatus, }: Props) { const groupedEntityTypeOptions = groupEntityTypeOptions(entityTypeOptions); const allowedGroupIds = selectedFeature ? getAllowedGroupIdsForGeometry(selectedFeature.geometry.type) : []; const visibleGroupedEntityTypeOptions = groupedEntityTypeOptions.filter((group) => allowedGroupIds.includes(group.id) ); const selectedTypeOption = findEntityTypeOption(entityForm.type_id); const hasCurrentTypeOption = entityTypeOptions.some((option) => option.value === entityForm.type_id); const geometryBucket = selectedFeature ? toGeometryBucket(selectedFeature.geometry.type) : null; const selectedTypeBucket = selectedTypeOption ? toTypeBucket(selectedTypeOption) : null; const isGeometryCompatible = geometryBucket && selectedTypeBucket ? geometryBucket === selectedTypeBucket : true; return (