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 { bindable, computedFrom, containerless, processContent, TaskQueue } from "aurelia-framework";
import { UIInternal } from "../../../utils/ui-internal";
import { UITableAction } from "./ui-table-action";
export var HeaderCell = (function () {
    function HeaderCell(element, taskQueue) {
        this.element = element;
        this.taskQueue = taskQueue;
        this.applyColspan = false;
    }
    HeaderCell.prototype.bind = function (bindingContext, overrideContext) {
        var _this = this;
        this.overrideContext = overrideContext;
        UIInternal.subscribe(UIInternal.EVT_CHANGE_LANGUAGE, function () {
            _this.setTitle();
        });
    };
    HeaderCell.prototype.fireSortEvent = function () {
        if (this.column.sortable && this.column.dataId != null) {
            this.element.dispatchEvent(UIInternal.createEvent("sort"));
        }
    };
    HeaderCell.prototype.attached = function () {
        var _this = this;
        this.taskQueue.queueMicroTask(function () {
            _this.compileHeader(_this.el);
        });
    };
    Object.defineProperty(HeaderCell.prototype, "title", {
        get: function () {
            return this._title;
        },
        enumerable: false,
        configurable: true
    });
    HeaderCell.prototype.setTitle = function () {
        var _a, _b, _c, _d, _e;
        this._title = ((_a = this.column) === null || _a === void 0 ? void 0 : _a.title) ? this.column.title : (_e = (_d = (_c = (_b = this.view) === null || _b === void 0 ? void 0 : _b.firstChild) === null || _c === void 0 ? void 0 : _c.textContent) === null || _d === void 0 ? void 0 : _d.trim()) !== null && _e !== void 0 ? _e : '';
    };
    HeaderCell.prototype.compileHeader = function (el) {
        if (el && this.column != null && this.overrideContext != null) {
            var tpl = this.column.templateHeader
                ? this.column.templateHeader.outerHTML
                : "<template><span innerhtml.bind=\"column.label\"></span></template>";
            if (this.overrideContext.parentOverrideContext != null) {
                if (this.overrideContext.parentOverrideContext.parentOverrideContext != null) {
                    this.view = UIInternal.compileTemplate(tpl, this, this.overrideContext.parentOverrideContext.parentOverrideContext.__parentOverrideContext);
                }
                else {
                    this.view = UIInternal.compileTemplate(tpl, this, this.overrideContext.parentOverrideContext.__parentOverrideContext);
                }
                this.view.appendNodesTo(el);
                this.view.attached();
                this.setTitle();
            }
        }
        return true;
    };
    HeaderCell.prototype.isActionColumn = function () {
        return this.column instanceof UITableAction || this.column.type == "action";
    };
    __decorate([
        bindable(),
        __metadata("design:type", Object)
    ], HeaderCell.prototype, "column", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", Boolean)
    ], HeaderCell.prototype, "applyColspan", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], HeaderCell.prototype, "sortBy", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], HeaderCell.prototype, "sortOrder", void 0);
    __decorate([
        computedFrom("_title"),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [])
    ], HeaderCell.prototype, "title", null);
    HeaderCell = __decorate([
        containerless(),
        processContent(function (compiler, resources, node, instruction) {
            instruction.inheritBindingContext = true;
            return true;
        }),
        __metadata("design:paramtypes", [Element, TaskQueue])
    ], HeaderCell);
    return HeaderCell;
}());

//# sourceMappingURL=header-cell.js.map
