/**
 * DevExtreme (esm/renovation/ui/common/icon.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 _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
var _excluded = ["position", "source"];
import {
    createVNode,
    createFragment
} from "inferno";
import {
    Fragment
} from "inferno";
import {
    BaseInfernoComponent
} from "@devextreme/vdom";
import {
    getImageSourceType
} from "../../../core/utils/icon";
import {
    combineClasses
} from "../../utils/combine_classes";
export var viewFunction = _ref => {
    var {
        iconClassName: iconClassName,
        props: {
            source: source
        },
        sourceType: sourceType
    } = _ref;
    return createFragment(["dxIcon" === sourceType && createVNode(1, "i", iconClassName), "fontIcon" === sourceType && createVNode(1, "i", iconClassName), "image" === sourceType && createVNode(1, "img", iconClassName, null, 1, {
        alt: "",
        src: source
    }), "svg" === sourceType && createVNode(1, "i", iconClassName, source, 0)], 0)
};
export var IconProps = {
    position: "left",
    source: ""
};
export class Icon extends BaseInfernoComponent {
    constructor(props) {
        super(props);
        this.state = {}
    }
    get sourceType() {
        return getImageSourceType(this.props.source)
    }
    get cssClass() {
        return "left" !== this.props.position ? "dx-icon-right" : ""
    }
    get iconClassName() {
        var generalClasses = {
            "dx-icon": true,
            [this.cssClass]: !!this.cssClass
        };
        var {
            source: source
        } = this.props;
        if ("dxIcon" === this.sourceType) {
            return combineClasses(_extends({}, generalClasses, {
                ["dx-icon-".concat(source)]: true
            }))
        }
        if ("fontIcon" === this.sourceType) {
            return combineClasses(_extends({}, generalClasses, {
                [String(source)]: !!source
            }))
        }
        if ("image" === this.sourceType) {
            return combineClasses(generalClasses)
        }
        if ("svg" === this.sourceType) {
            return combineClasses(_extends({}, generalClasses, {
                "dx-svg-icon": true
            }))
        }
        return ""
    }
    get restAttributes() {
        var _this$props = this.props,
            restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
        return restProps
    }
    render() {
        var props = this.props;
        return viewFunction({
            props: _extends({}, props),
            sourceType: this.sourceType,
            cssClass: this.cssClass,
            iconClassName: this.iconClassName,
            restAttributes: this.restAttributes
        })
    }
}
Icon.defaultProps = _extends({}, IconProps);
