"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SegmentDeltaField = void 0;
var classnames_1 = __importDefault(require("classnames"));
var react_1 = __importDefault(require("react"));
var ArrowForward_1 = __importDefault(require("@mui/icons-material/ArrowForward"));
var Chip_1 = __importDefault(require("@mui/material/Chip"));
var types_1 = require("../../../types");
var segmantation_1 = require("../../../../../constants/segmantation");
var Field_1 = require("../../../Field");
var SegmentQueryDeltaValue_1 = require("./SegmentQueryDeltaValue");
var SegmentRefreshScheduleDeltaValue_1 = require("./SegmentRefreshScheduleDeltaValue");
var SegmentDeltaField_module_css_1 = __importDefault(require("./SegmentDeltaField.module.css"));
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 = types_1.DeltaTypes[delta.type];
    var attribute = segmantation_1.SEGMENT_ACTIVITY_LOG_ATTRIBUTES[delta.attributeType];
    var renderValue = function (value) {
        if (!value)
            return null;
        if (delta.attributeType === segmantation_1.SegmentActivityLogAttributes.rule) {
            return typeof value === 'string' ? react_1.default.createElement(SegmentQueryDeltaValue_1.SegmentQueryDeltaValue, { value: value }) : null;
        }
        if (delta.attributeType === segmantation_1.SegmentActivityLogAttributes.schedule) {
            return react_1.default.createElement(SegmentRefreshScheduleDeltaValue_1.SegmentRefreshScheduleDeltaValue, { value: value });
        }
        if (delta.attributeType === segmantation_1.SegmentActivityLogAttributes.sharing) {
            return react_1.default.createElement("p", { className: SegmentDeltaField_module_css_1.default.firstLetterCapitalized }, String(value));
        }
        return react_1.default.createElement(react_1.default.Fragment, null, String(value));
    };
    return attribute ? (react_1.default.createElement(Field_1.Field, { fieldName: attribute, "data-reltio-id": "segment-delta-field" },
        value && renderValue(value),
        newValue && oldValue && (react_1.default.createElement(react_1.default.Fragment, null,
            react_1.default.createElement(ArrowForward_1.default, { className: SegmentDeltaField_module_css_1.default.arrow }),
            renderValue(newValue))),
        deltaLabel && (react_1.default.createElement(Chip_1.default, { variant: "outlined", label: deltaLabel, className: (0, classnames_1.default)(SegmentDeltaField_module_css_1.default.chip, SegmentDeltaField_module_css_1.default[deltaLabel]) })))) : null;
};
exports.SegmentDeltaField = SegmentDeltaField;
