"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DateIntervalSelector = void 0;
var react_1 = __importDefault(require("react"));
var ramda_1 = require("ramda");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var TextField_1 = __importDefault(require("@mui/material/TextField"));
var utils_1 = require("@mui/material/utils");
var events_1 = require("../helpers/events");
var SimpleDropDownSelector_1 = require("../SimpleDropDownSelector");
var styles_1 = require("./styles");
var periods = ['minutes', 'hours', 'days', 'weeks', 'months', 'years'];
var DateIntervalSelector = function (_a) {
    var _b = _a.interval, value = _b[0], unit = _b[1], onChange = _a.onChange, onFocus = _a.onFocus;
    var styles = (0, styles_1.useStyles)();
    var getIntervalFromValue = function (newValue) { return [newValue, unit]; };
    var getIntervalFromUnit = function (_a) {
        var newUnit = _a.value;
        return [value, newUnit];
    };
    var onNumberChange = (0, ramda_1.pipe)(events_1.getValue, parseInt, getIntervalFromValue, onChange);
    var onUnitChange = (0, ramda_1.pipe)(getIntervalFromUnit, onChange);
    return (react_1.default.createElement("div", { "data-reltio-id": "date-interval-selector", className: styles.root },
        react_1.default.createElement(TextField_1.default, { variant: "standard", type: "number", value: value || '', onChange: onNumberChange, inputProps: { min: 1, onFocus: onFocus }, InputProps: { classes: { root: styles.input } }, className: styles.inputNumber }),
        react_1.default.createElement(SimpleDropDownSelector_1.SimpleDropDownSelector, { label: '', placeholder: (0, utils_1.capitalize)(unit), className: styles.inputUnit, value: { value: unit, label: (0, utils_1.capitalize)((0, mdm_sdk_1.getIntervalUnitLabel)(unit)) }, options: periods.map(function (value) { return ({
                value: value,
                label: (0, utils_1.capitalize)((0, mdm_sdk_1.getIntervalUnitLabel)(value))
            }); }), onChange: onUnitChange, TextFieldProps: {
                inputProps: { onFocus: onFocus },
                InputProps: { classes: { root: styles.input } }
            } })));
};
exports.DateIntervalSelector = DateIntervalSelector;
