/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { observer } from 'mobx-react-lite';
import { PurePropertyMappingEditor } from './PurePropertyMappingEditor.js';
import { getElementIcon } from '../../../ElementIconUtils.js';
import {
type MappingElement,
MappingEditorState,
} from '../../../../stores/editor/editor-state/element-editor-state/mapping/MappingEditorState.js';
import type {
InstanceSetImplementationState,
PropertyMappingState,
} from '../../../../stores/editor/editor-state/element-editor-state/mapping/MappingElementState.js';
import {
PurePropertyMappingState,
PureInstanceSetImplementationState,
} from '../../../../stores/editor/editor-state/element-editor-state/mapping/PureInstanceSetImplementationState.js';
import {
clsx,
ArrowCircleRightIcon,
TimesCircleIcon,
TimesIcon,
AsteriskIcon,
} from '@finos/legend-art';
import { guaranteeType } from '@finos/legend-shared';
import {
type FlatDataPropertyMappingState,
FlatDataInstanceSetImplementationState,
} from '../../../../stores/editor/editor-state/element-editor-state/mapping/FlatDataInstanceSetImplementationState.js';
import { FlatDataPropertyMappingEditor } from './FlatDataPropertyMappingEditor.js';
import { RelationalPropertyMappingEditor } from './relational/RelationalPropertyMappingEditor.js';
import type {
RelationalPropertyMappingState,
RootRelationalInstanceSetImplementationState,
} from '../../../../stores/editor/editor-state/element-editor-state/mapping/relational/RelationalInstanceSetImplementationState.js';
import { useEditorStore } from '../../EditorStoreProvider.js';
import {
type Property,
type PropertyMapping,
type Type,
getRootSetImplementation,
Class,
SetImplementation,
PrimitiveType,
PureInstanceSetImplementation,
EmbeddedFlatDataPropertyMapping,
OperationSetImplementation,
FlatDataInstanceSetImplementation,
RootRelationalInstanceSetImplementation,
MULTIPLICITY_INFINITE,
type Multiplicity,
RelationFunctionInstanceSetImplementation,
} from '@finos/legend-graph';
import { useApplicationStore } from '@finos/legend-application';
import {
instanceSetImplementation_deletePropertyMapping,
setImpl_nominateRoot,
setImplementation_setRoot,
} from '../../../../stores/graph-modifier/DSL_Mapping_GraphModifierHelper.js';
import {
CLASS_PROPERTY_TYPE,
getClassPropertyType,
} from '../../../../stores/editor/utils/ModelClassifierUtils.js';
import type { DSL_Mapping_LegendStudioApplicationPlugin_Extension } from '../../../../stores/extensions/DSL_Mapping_LegendStudioApplicationPlugin_Extension.js';
import { Fragment } from 'react';
import { RelationFunctionPropertyMappingEditor } from './RelationFunctionPropertyMappingEditor.js';
import type {
RelationFunctionInstanceSetImplementationState,
RelationFunctionPropertyMappingState,
} from '../../../../stores/editor/editor-state/element-editor-state/mapping/RelationFunctionInstanceSetImplementationState.js';
const MultiplicityBadge: React.FC<{
multiplicity: Multiplicity;
}> = (props) => {
const { multiplicity } = props;
const isRequired = multiplicity.lowerBound && multiplicity.lowerBound > 0;
const tooltipText = `${isRequired ? '[required]' : '[optional]'}${
isRequired ? ` minimum: ${multiplicity.lowerBound}` : ''
} maximum: ${multiplicity.upperBound ?? MULTIPLICITY_INFINITE}`;
return (