import type { FC } from 'react' import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' import type { NodeProps } from 'reactflow' import { NodeSourceHandle } from '../_base/components/node-handle' import { isEmptyRelatedOperator } from './utils' import type { Condition, IfElseNodeType } from './types' import ConditionValue from './components/condition-value' import ConditionFilesListValue from './components/condition-files-list-value' const i18nPrefix = 'workflow.nodes.ifElse' const IfElseNode: FC> = (props) => { const { data } = props const { t } = useTranslation() const { cases } = data const casesLength = cases.length const checkIsConditionSet = useCallback((condition: Condition) => { if (!condition.variable_selector || condition.variable_selector.length === 0) return false if (condition.sub_variable_condition) { const isSet = condition.sub_variable_condition.conditions.every((c) => { if (!c.comparison_operator) return false if (isEmptyRelatedOperator(c.comparison_operator!)) return true return !!c.value }) return isSet } else { if (isEmptyRelatedOperator(condition.comparison_operator!)) return true return !!condition.value } }, []) const conditionNotSet = (
{t(`${i18nPrefix}.conditionNotSetup`)}
) return (
{ cases.map((caseItem, index) => (
{casesLength > 1 && `CASE ${index + 1}`}
{index === 0 ? 'IF' : 'ELIF'}
{caseItem.conditions.map((condition, i) => (
{ checkIsConditionSet(condition) ? ( (!isEmptyRelatedOperator(condition.comparison_operator!) && condition.sub_variable_condition) ? ( ) : ( ) ) : conditionNotSet} {i !== caseItem.conditions.length - 1 && (
{t(`${i18nPrefix}.${caseItem.logical_operator}`)}
)}
))}
)) }
ELSE
) } export default React.memo(IfElseNode)