"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var vdom_1 = require("@dojo/framework/core/vdom");
var theme_1 = require("../middleware/theme");
var css = require("../theme/default/chip.m.css");
var index_1 = require("../icon/index");
var util_1 = require("../common/util");
var factory = vdom_1.create({ theme: theme_1.default })
    .properties()
    .children();
exports.default = factory(function Chip(_a) {
    var properties = _a.properties, children = _a.children, theme = _a.middleware.theme;
    var _b = properties(), onClose = _b.onClose, onClick = _b.onClick, disabled = _b.disabled, checked = _b.checked, themeProp = _b.theme, variant = _b.variant, _c = _b.classes, classes = _c === void 0 ? {} : _c;
    var themedCss = theme.classes(css);
    var _d = tslib_1.__read(children(), 1), _e = _d[0], icon = _e.icon, label = _e.label, closeIcon = _e.closeIcon;
    var clickable = !disabled && onClick;
    return (vdom_1.tsx("div", { key: "root", classes: [
            theme.variant(),
            themedCss.root,
            disabled && themedCss.disabled,
            clickable && themedCss.clickable
        ], role: clickable ? 'button' : undefined, onclick: function () {
            if (clickable && onClick) {
                onClick();
            }
        }, tabIndex: clickable ? 0 : undefined, onkeydown: function (event) {
            if (clickable &&
                onClick &&
                (event.which === util_1.Keys.Enter || event.which === util_1.Keys.Space)) {
                event.preventDefault();
                onClick();
            }
        } },
        icon && vdom_1.tsx("span", { classes: themedCss.iconWrapper }, icon(checked)),
        vdom_1.tsx("span", { classes: themedCss.label }, label),
        onClose && (vdom_1.tsx("span", { key: "closeButton", classes: themedCss.closeIconWrapper, tabIndex: 0, role: "button", onclick: function (event) {
                event.stopPropagation();
                onClose();
            }, onkeydown: function (event) {
                if (event.which === util_1.Keys.Enter || event.which === util_1.Keys.Space) {
                    event.stopPropagation();
                    event.preventDefault();
                    onClose();
                }
            } }, closeIcon || (vdom_1.tsx(index_1.default, { type: "closeIcon", classes: tslib_1.__assign({}, classes, { '@dojo/widgets/icon': tslib_1.__assign({}, classes['@dojo/widgets/icon'], { icon: [themedCss.icon] }) }), theme: themeProp, variant: variant }))))));
});

/*# sourceMappingURL=index.js.map*/