/**
 * DevExtreme (cjs/__internal/filter_builder/m_between.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.getConfig = getConfig;
var _renderer = _interopRequireDefault(require("../../core/renderer"));
var _extend = require("../../core/utils/extend");

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}
const FILTER_BUILDER_RANGE_CLASS = "dx-filterbuilder-range";
const FILTER_BUILDER_RANGE_START_CLASS = "".concat("dx-filterbuilder-range", "-start");
const FILTER_BUILDER_RANGE_END_CLASS = "".concat("dx-filterbuilder-range", "-end");
const FILTER_BUILDER_RANGE_SEPARATOR_CLASS = "".concat("dx-filterbuilder-range", "-separator");
const SEPARATOR = "\u2013";

function editorTemplate(conditionInfo, container) {
    const $editorStart = (0, _renderer.default)("<div>").addClass(FILTER_BUILDER_RANGE_START_CLASS);
    const $editorEnd = (0, _renderer.default)("<div>").addClass(FILTER_BUILDER_RANGE_END_CLASS);
    let values = conditionInfo.value || [];
    const getStartValue = function(values) {
        return values && values.length > 0 ? values[0] : null
    };
    const getEndValue = function(values) {
        return values && 2 === values.length ? values[1] : null
    };
    container.append($editorStart);
    container.append((0, _renderer.default)("<span>").addClass(FILTER_BUILDER_RANGE_SEPARATOR_CLASS).text("\u2013"));
    container.append($editorEnd);
    container.addClass("dx-filterbuilder-range");
    this._editorFactory.createEditor.call(this, $editorStart, (0, _extend.extend)({}, conditionInfo.field, conditionInfo, {
        value: getStartValue(values),
        parentType: "filterBuilder",
        setValue(value) {
            values = [value, getEndValue(values)];
            conditionInfo.setValue(values)
        }
    }));
    this._editorFactory.createEditor.call(this, $editorEnd, (0, _extend.extend)({}, conditionInfo.field, conditionInfo, {
        value: getEndValue(values),
        parentType: "filterBuilder",
        setValue(value) {
            values = [getStartValue(values), value];
            conditionInfo.setValue(values)
        }
    }))
}

function getConfig(caption, context) {
    return {
        name: "between",
        caption: caption,
        icon: "range",
        valueSeparator: "\u2013",
        dataTypes: ["number", "date", "datetime"],
        editorTemplate: editorTemplate.bind(context),
        notForLookup: true
    }
}
