import classnames from 'classnames';
import React from 'react';
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
import Chip from '@mui/material/Chip';
import { DeltaTypes } from '../../../types';
import { SEGMENT_ACTIVITY_LOG_ATTRIBUTES, SegmentActivityLogAttributes } from '../../../../../constants/segmantation';
import { Field } from '../../../Field';
import { SegmentQueryDeltaValue } from './SegmentQueryDeltaValue';
import { SegmentRefreshScheduleDeltaValue } from './SegmentRefreshScheduleDeltaValue';
import styles from './SegmentDeltaField.module.css';
export var SegmentDeltaField = function (_a) {
    var _b, _c;
    var delta = _a.delta;
    var newValue = (_b = delta.newValue) === null || _b === void 0 ? void 0 : _b.value;
    var oldValue = (_c = delta.oldValue) === null || _c === void 0 ? void 0 : _c.value;
    var value = oldValue || newValue;
    var deltaLabel = DeltaTypes[delta.type];
    var attribute = SEGMENT_ACTIVITY_LOG_ATTRIBUTES[delta.attributeType];
    var renderValue = function (value) {
        if (!value)
            return null;
        if (delta.attributeType === SegmentActivityLogAttributes.rule) {
            return typeof value === 'string' ? React.createElement(SegmentQueryDeltaValue, { value: value }) : null;
        }
        if (delta.attributeType === SegmentActivityLogAttributes.schedule) {
            return React.createElement(SegmentRefreshScheduleDeltaValue, { value: value });
        }
        if (delta.attributeType === SegmentActivityLogAttributes.sharing) {
            return React.createElement("p", { className: styles.firstLetterCapitalized }, String(value));
        }
        return React.createElement(React.Fragment, null, String(value));
    };
    return attribute ? (React.createElement(Field, { fieldName: attribute, "data-reltio-id": "segment-delta-field" },
        value && renderValue(value),
        newValue && oldValue && (React.createElement(React.Fragment, null,
            React.createElement(ArrowForwardIcon, { className: styles.arrow }),
            renderValue(newValue))),
        deltaLabel && (React.createElement(Chip, { variant: "outlined", label: deltaLabel, className: classnames(styles.chip, styles[deltaLabel]) })))) : null;
};
