var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { autoinject, bindable, customAttribute, TaskQueue } from "aurelia-framework";
import { UIInternal } from "../utils/ui-internal";
var BaseAttribute = (function () {
    function BaseAttribute(element) {
        this.element = element;
        this.prefix = "";
        this.value = "default";
        this.oldValue = "default";
        this.singular = false;
    }
    BaseAttribute.prototype.bind = function () {
        this.toggleClass();
    };
    BaseAttribute.prototype.valueChanged = function () {
        this.toggleClass();
    };
    BaseAttribute.prototype.toggleClass = function () {
        var _this = this;
        var el = this.element;
        var vm = getViewModel(this.element);
        if (vm && vm.vmElement) {
            el = vm.vmElement;
        }
        if (el.classList) {
            if (this.oldValue && !this.singular) {
                this.oldValue.split(" ").forEach(function (p) { return el.classList.remove("".concat(_this.prefix, "--").concat(p.trim())); });
            }
            else {
                el.classList.remove("".concat(this.prefix));
            }
            this.oldValue = this.value;
            if (this.value && !this.singular) {
                this.value.split(" ").forEach(function (p) { return el.classList.add("".concat(_this.prefix, "--").concat(p.trim())); });
            }
            else if (!isFalse(this.value)) {
                el.classList.add("".concat(this.prefix));
            }
        }
    };
    BaseAttribute = __decorate([
        autoinject(),
        __metadata("design:paramtypes", [Element])
    ], BaseAttribute);
    return BaseAttribute;
}());
export var UITheme = (function (_super) {
    __extends(UITheme, _super);
    function UITheme() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-theme";
        return _this;
    }
    UITheme = __decorate([
        autoinject(),
        customAttribute("ui-theme")
    ], UITheme);
    return UITheme;
}(BaseAttribute));
export var UIBg = (function (_super) {
    __extends(UIBg, _super);
    function UIBg() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-bg";
        return _this;
    }
    UIBg = __decorate([
        autoinject(),
        customAttribute("ui-bg")
    ], UIBg);
    return UIBg;
}(BaseAttribute));
export var UIColor = (function (_super) {
    __extends(UIColor, _super);
    function UIColor() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-color";
        return _this;
    }
    UIColor = __decorate([
        autoinject(),
        customAttribute("ui-color")
    ], UIColor);
    return UIColor;
}(BaseAttribute));
export var UIHover = (function (_super) {
    __extends(UIHover, _super);
    function UIHover() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-hover";
        return _this;
    }
    UIHover = __decorate([
        autoinject(),
        customAttribute("ui-hover")
    ], UIHover);
    return UIHover;
}(BaseAttribute));
export var UIShadow = (function (_super) {
    __extends(UIShadow, _super);
    function UIShadow() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-shadow";
        return _this;
    }
    UIShadow = __decorate([
        autoinject(),
        customAttribute("ui-shadow")
    ], UIShadow);
    return UIShadow;
}(BaseAttribute));
export var UIPadding = (function (_super) {
    __extends(UIPadding, _super);
    function UIPadding() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-padding";
        return _this;
    }
    UIPadding = __decorate([
        autoinject(),
        customAttribute("ui-padding")
    ], UIPadding);
    return UIPadding;
}(BaseAttribute));
export var UIMargin = (function (_super) {
    __extends(UIMargin, _super);
    function UIMargin() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-margin";
        return _this;
    }
    UIMargin = __decorate([
        autoinject(),
        customAttribute("ui-margin")
    ], UIMargin);
    return UIMargin;
}(BaseAttribute));
export var UIBorder = (function (_super) {
    __extends(UIBorder, _super);
    function UIBorder() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-border";
        return _this;
    }
    UIBorder = __decorate([
        autoinject(),
        customAttribute("ui-border")
    ], UIBorder);
    return UIBorder;
}(BaseAttribute));
export var UIFont = (function (_super) {
    __extends(UIFont, _super);
    function UIFont() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-font";
        return _this;
    }
    UIFont = __decorate([
        autoinject(),
        customAttribute("ui-font")
    ], UIFont);
    return UIFont;
}(BaseAttribute));
export var UIWeight = (function (_super) {
    __extends(UIWeight, _super);
    function UIWeight() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-weight";
        return _this;
    }
    UIWeight = __decorate([
        autoinject(),
        customAttribute("ui-weight")
    ], UIWeight);
    return UIWeight;
}(BaseAttribute));
export var UIText = (function (_super) {
    __extends(UIText, _super);
    function UIText() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-text";
        return _this;
    }
    UIText = __decorate([
        autoinject(),
        customAttribute("ui-text")
    ], UIText);
    return UIText;
}(BaseAttribute));
export var UIAlign = (function (_super) {
    __extends(UIAlign, _super);
    function UIAlign() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-align";
        return _this;
    }
    UIAlign = __decorate([
        autoinject(),
        customAttribute("ui-align")
    ], UIAlign);
    return UIAlign;
}(BaseAttribute));
export var UIGutter = (function (_super) {
    __extends(UIGutter, _super);
    function UIGutter() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-gutter";
        return _this;
    }
    UIGutter = __decorate([
        autoinject(),
        customAttribute("ui-gutter")
    ], UIGutter);
    return UIGutter;
}(BaseAttribute));
export var UIHide = (function (_super) {
    __extends(UIHide, _super);
    function UIHide() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-hide";
        return _this;
    }
    UIHide = __decorate([
        autoinject(),
        customAttribute("ui-hide")
    ], UIHide);
    return UIHide;
}(BaseAttribute));
export var UIShow = (function (_super) {
    __extends(UIShow, _super);
    function UIShow() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-show";
        return _this;
    }
    UIShow = __decorate([
        autoinject(),
        customAttribute("ui-show")
    ], UIShow);
    return UIShow;
}(BaseAttribute));
export var UIClip = (function (_super) {
    __extends(UIClip, _super);
    function UIClip() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-clip";
        _this.singular = true;
        return _this;
    }
    UIClip.prototype.bind = function () {
        _super.prototype.bind.call(this);
        this.valueChanged();
    };
    UIClip.prototype.valueChanged = function () {
        this.element.style.cssText = "--line-clamp: ".concat(this.value, ";");
    };
    UIClip = __decorate([
        autoinject(),
        customAttribute("ui-clip")
    ], UIClip);
    return UIClip;
}(BaseAttribute));
export var UILine = (function (_super) {
    __extends(UILine, _super);
    function UILine() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-line";
        _this.singular = true;
        return _this;
    }
    UILine.prototype.bind = function () {
        _super.prototype.bind.call(this);
        this.valueChanged();
    };
    UILine.prototype.valueChanged = function () {
        this.element.style.cssText = "line-height: ".concat(this.value, ";");
    };
    UILine = __decorate([
        autoinject(),
        customAttribute("ui-line")
    ], UILine);
    return UILine;
}(BaseAttribute));
export var UIPaper = (function (_super) {
    __extends(UIPaper, _super);
    function UIPaper() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-paper";
        _this.singular = true;
        return _this;
    }
    UIPaper = __decorate([
        autoinject(),
        customAttribute("ui-paper")
    ], UIPaper);
    return UIPaper;
}(BaseAttribute));
export var UILink = (function (_super) {
    __extends(UILink, _super);
    function UILink() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-link";
        _this.singular = true;
        return _this;
    }
    UILink = __decorate([
        autoinject(),
        customAttribute("ui-link")
    ], UILink);
    return UILink;
}(BaseAttribute));
export var UIScroll = (function (_super) {
    __extends(UIScroll, _super);
    function UIScroll() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.prefix = "ui-scroll";
        return _this;
    }
    UIScroll = __decorate([
        autoinject(),
        customAttribute("ui-scroll")
    ], UIScroll);
    return UIScroll;
}(BaseAttribute));
export var OnAttached = (function () {
    function OnAttached(taskQueue, element) {
        this.taskQueue = taskQueue;
        this.element = element;
    }
    OnAttached.prototype.attached = function () {
        var _this = this;
        this.taskQueue.queueTask(function () {
            if (_this.event != null) {
                UIInternal.broadcast(_this.event, _this.element);
            }
            if (_this.handler != null) {
                _this.handler({ element: _this.element });
            }
        });
    };
    __decorate([
        bindable({ primaryProperty: true }),
        __metadata("design:type", String)
    ], OnAttached.prototype, "event", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Function)
    ], OnAttached.prototype, "handler", void 0);
    OnAttached = __decorate([
        autoinject(),
        customAttribute("on-attached"),
        __metadata("design:paramtypes", [TaskQueue, Element])
    ], OnAttached);
    return OnAttached;
}());

//# sourceMappingURL=ui-helpers.js.map
