/**
 * DevExtreme (renovation/ui/grids/data_grid_next/widgets/data_cell.js)
 * Version: 22.1.3 (build 22180-0310)
 * Build date: Wed Jun 29 2022
 *
 * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.viewFunction = exports.DataCellProps = exports.DataCell = void 0;
var _inferno = require("inferno");
var _inferno2 = require("@devextreme/runtime/inferno");
var _combine_classes = require("../../../../utils/combine_classes");
var _classes = _interopRequireDefault(require("../classes"));
var _excluded = ["cellContainerTemplate", "cellTemplate", "column", "columnIndex", "countColumn", "row"];

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}

function _objectWithoutProperties(source, excluded) {
    if (null == source) {
        return {}
    }
    var target = _objectWithoutPropertiesLoose(source, excluded);
    var key, i;
    if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
        for (i = 0; i < sourceSymbolKeys.length; i++) {
            key = sourceSymbolKeys[i];
            if (excluded.indexOf(key) >= 0) {
                continue
            }
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) {
                continue
            }
            target[key] = source[key]
        }
    }
    return target
}

function _objectWithoutPropertiesLoose(source, excluded) {
    if (null == source) {
        return {}
    }
    var target = {};
    var sourceKeys = Object.keys(source);
    var key, i;
    for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) {
            continue
        }
        target[key] = source[key]
    }
    return target
}

function _defineProperty(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        })
    } else {
        obj[key] = value
    }
    return obj
}

function _defineProperties(target, props) {
    for (var i = 0; i < props.length; i++) {
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) {
            descriptor.writable = true
        }
        Object.defineProperty(target, descriptor.key, descriptor)
    }
}

function _createClass(Constructor, protoProps, staticProps) {
    if (protoProps) {
        _defineProperties(Constructor.prototype, protoProps)
    }
    if (staticProps) {
        _defineProperties(Constructor, staticProps)
    }
    Object.defineProperty(Constructor, "prototype", {
        writable: false
    });
    return Constructor
}

function _inheritsLoose(subClass, superClass) {
    subClass.prototype = Object.create(superClass.prototype);
    subClass.prototype.constructor = subClass;
    _setPrototypeOf(subClass, superClass)
}

function _setPrototypeOf(o, p) {
    _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
        o.__proto__ = p;
        return o
    };
    return _setPrototypeOf(o, p)
}

function _extends() {
    _extends = Object.assign ? Object.assign.bind() : function(target) {
        for (var i = 1; i < arguments.length; i++) {
            var source = arguments[i];
            for (var key in source) {
                if (Object.prototype.hasOwnProperty.call(source, key)) {
                    target[key] = source[key]
                }
            }
        }
        return target
    };
    return _extends.apply(this, arguments)
}
var viewFunction = function(viewModel) {
    var cellText = viewModel.cellText,
        classes = viewModel.classes;
    var _viewModel$props = viewModel.props,
        CellContainerTemplate = _viewModel$props.cellContainerTemplate,
        CellTemplate = _viewModel$props.cellTemplate,
        row = _viewModel$props.row;
    var cellContentTemplate = viewModel.props.cellTemplate ? CellTemplate({
        data: row.data
    }) : cellText;
    return !viewModel.props.cellContainerTemplate ? (0, _inferno.createVNode)(1, "td", classes, cellContentTemplate, 0, {
        "aria-selected": "false",
        role: "gridcell"
    }) : CellContainerTemplate({
        data: row.data
    })
};
exports.viewFunction = viewFunction;
var DataCellProps = {
    row: Object.freeze({
        data: {},
        rowType: "data"
    }),
    columnIndex: 0,
    countColumn: 0,
    column: Object.freeze({})
};
exports.DataCellProps = DataCellProps;
var getTemplate = function(TemplateProp) {
    return TemplateProp && (TemplateProp.defaultProps ? function(props) {
        return (0, _inferno.normalizeProps)((0, _inferno.createComponentVNode)(2, TemplateProp, _extends({}, props)))
    } : TemplateProp)
};
var DataCell = function(_BaseInfernoComponent) {
    _inheritsLoose(DataCell, _BaseInfernoComponent);

    function DataCell(props) {
        var _this;
        _this = _BaseInfernoComponent.call(this, props) || this;
        _this.state = {};
        return _this
    }
    var _proto = DataCell.prototype;
    _proto.render = function() {
        var props = this.props;
        return viewFunction({
            props: _extends({}, props, {
                cellTemplate: getTemplate(props.cellTemplate),
                cellContainerTemplate: getTemplate(props.cellContainerTemplate)
            }),
            cellText: this.cellText,
            classes: this.classes,
            restAttributes: this.restAttributes
        })
    };
    _createClass(DataCell, [{
        key: "cellText",
        get: function() {
            var dataField = this.props.column.dataField;
            var value = dataField && this.props.row.data[dataField];
            return void 0 !== value ? String(value) : ""
        }
    }, {
        key: "classes",
        get: function() {
            var _classesMap;
            var _this$props = this.props,
                columnIndex = _this$props.columnIndex,
                countColumn = _this$props.countColumn;
            var classesMap = (_classesMap = {}, _defineProperty(_classesMap, _classes.default.firstChild, 0 === columnIndex), _defineProperty(_classesMap, _classes.default.lastChild, columnIndex === countColumn - 1), _classesMap);
            return (0, _combine_classes.combineClasses)(classesMap)
        }
    }, {
        key: "restAttributes",
        get: function() {
            var _this$props2 = this.props,
                restProps = (_this$props2.cellContainerTemplate, _this$props2.cellTemplate, _this$props2.column, _this$props2.columnIndex, _this$props2.countColumn, _this$props2.row, _objectWithoutProperties(_this$props2, _excluded));
            return restProps
        }
    }]);
    return DataCell
}(_inferno2.BaseInfernoComponent);
exports.DataCell = DataCell;
DataCell.defaultProps = DataCellProps;
