/**
 * DevExtreme (esm/ui/scheduler/expressionUtils.js)
 * Version: 21.2.0 (build 21200-0321)
 * Build date: Mon Jul 19 2021
 *
 * Copyright (c) 2012 - 2021 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import {
    isDefined
} from "../../core/utils/type";
import {
    getAppointmentDataProvider,
    getModel
} from "./instanceFactory";
export var ExpressionUtils = {
    getField: (key, field, obj) => {
        var dataAccessors = getAppointmentDataProvider(key).getDataAccessors();
        if (isDefined(dataAccessors.getter[field])) {
            return dataAccessors.getter[field](obj)
        }
    },
    setField: (key, field, obj, value) => {
        var {
            dataAccessors: dataAccessors
        } = getAppointmentDataProvider(key);
        var model = getModel(key);
        if (!isDefined(dataAccessors.setter[field])) {
            return
        }
        var fieldExpression = model["".concat(field, "Expr")];
        var splitExprStr = fieldExpression.split(".");
        var rootField = splitExprStr[0];
        if (void 0 === obj[rootField] && splitExprStr.length > 1) {
            var emptyChain = function(arr) {
                var result = {};
                var tmp = result;
                var arrLength = arr.length - 1;
                for (var i = 1; i < arrLength; i++) {
                    tmp = tmp[arr[i]] = {}
                }
                return result
            }(splitExprStr);
            obj[rootField] = emptyChain
        }
        dataAccessors.setter[field](obj, value);
        return obj
    }
};
