import React, { useMemo } from 'react';
import { convertScheduleApiFormatToTextChunks } from '@reltio/mdm-sdk';
import styles from './SegmentDeltaField.module.css';
var addSpace = function (s, withSpace) {
    if (withSpace === void 0) { withSpace = true; }
    return (withSpace ? s + ' ' : s);
};
export var SegmentRefreshScheduleDeltaValue = function (_a) {
    var value = _a.value;
    var scheduleTextChunks = convertScheduleApiFormatToTextChunks(value);
    var scheduleString = useMemo(function () {
        var chunkStrings = scheduleTextChunks
            .filter(function (chunk) { return chunk.activeLabel; })
            .map(function (_a) {
            var activeLabel = _a.activeLabel, inactiveLabel = _a.inactiveLabel, _b = _a.hasEndingSpace, hasEndingSpace = _b === void 0 ? true : _b;
            var out = [];
            if (inactiveLabel)
                out.push(addSpace(inactiveLabel));
            var active = activeLabel.trim();
            if (active)
                out.push(addSpace(active, hasEndingSpace));
            return out.join('');
        });
        return chunkStrings.join('').trimEnd();
    }, [scheduleTextChunks]);
    return React.createElement("p", { className: styles.firstLetterCapitalized }, scheduleString);
};
