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 { bindingMode, computedFrom } from "aurelia-binding";
import { bindable } from "aurelia-templating";
import { Container } from "aurelia-framework";
import { UIInternal } from "../../../utils/ui-internal";
import { DisposableViewModelBase } from '../../../vm/disposable-view-model-base';
export var CommonColumn = (function (_super) {
    __extends(CommonColumn, _super);
    function CommonColumn(element, parser, viewCompiler, viewResources, bindingEngine) {
        var _this = _super.call(this) || this;
        _this.element = element;
        _this.parser = parser;
        _this.viewCompiler = viewCompiler;
        _this.viewResources = viewResources;
        _this.bindingEngine = bindingEngine;
        _this.label = "";
        _this.classes = '';
        _this.order = 'auto';
        _this.sortable = false;
        _this.hideOnLarge = false;
        _this.hideOnSmall = false;
        _this.noHeaderOnLarge = false;
        _this.noHeaderOnSmall = false;
        _this.sortable = element.hasAttribute("sortable");
        _this.isRowClickIgnore = element.hasAttribute("row-click-ignore");
        _this.hideOnLarge = element.hasAttribute("hide-on-large");
        _this.hideOnSmall = element.hasAttribute("hide-on-small");
        _this.noHeaderOnLarge = element.hasAttribute("no-header") || element.hasAttribute("no-header-on-large");
        _this.noHeaderOnSmall = element.hasAttribute("no-header") || element.hasAttribute("no-header-on-small");
        var uiColumnHeader = element.querySelector("ui-column-header");
        if (_this.templateHeader == null && uiColumnHeader != null) {
            _this.templateHeader = document.createElement("template");
            _this.templateHeader.innerHTML = uiColumnHeader.innerHTML;
        }
        if (_this.templateCell == null) {
            _this.templateCell = document.createElement("template");
            _this.templateCell.title = element.outerText.trim();
            if (element.children.length > 0) {
                Array.from(element.children).filter(function (x) { return x.localName != "ui-column-header"; }).forEach(function (c) {
                    _this.templateCell.innerHTML += c.outerHTML;
                });
            }
            else {
                _this.templateCell.innerHTML = element.innerHTML;
            }
        }
        return _this;
    }
    Object.defineProperty(CommonColumn.prototype, "isVisible", {
        get: function () {
            var _a;
            return (_a = this.colVisible) !== null && _a !== void 0 ? _a : true;
        },
        enumerable: false,
        configurable: true
    });
    CommonColumn.prototype.colVisibleChanged = function () {
        UIInternal.broadcast(UIInternal.EVT_UI_TABLE_REFRESH + "_".concat(this.tableAuTargetId));
    };
    CommonColumn.prototype.cellIsVisible = function (record) {
        if (this.cellVisible != null) {
            if (typeof (this.cellVisible) == "boolean") {
                return this.cellVisible;
            }
            if (typeof (this.cellVisible) == "string") {
                return this.getResultExpression(this.cellVisible, record);
            }
        }
        return true;
    };
    CommonColumn.prototype.getCss = function (record) {
        if (this.css != null) {
            if (typeof (this.css) == "object") {
                return this.css;
            }
            if (typeof (this.css) == "string") {
                return this.getResultExpression(this.css, record);
            }
        }
        return {};
    };
    CommonColumn.prototype.compileCell = function () {
        var tpl = this.templateCell.outerHTML;
        this.view = this.internalCompileTemplate(tpl);
    };
    CommonColumn.prototype.getResultExpression = function (expressionText, record) {
        if (expressionText != null && record != null) {
            var expression = this.parser.parse(expressionText);
            var scope = {
                bindingContext: { record: record },
                overrideContext: null
            };
            return expression.evaluate(scope);
        }
    };
    CommonColumn.prototype.internalCompileTemplate = function (tpl) {
        var childContainer = Container.instance.createChild();
        var viewFactory = this.viewCompiler
            .compile(tpl, this.viewResources);
        var view = viewFactory.create(childContainer);
        return view;
    };
    __decorate([
        bindable({ defaultBindingMode: bindingMode.toView }),
        __metadata("design:type", String)
    ], CommonColumn.prototype, "headerAlign", void 0);
    __decorate([
        bindable({ defaultBindingMode: bindingMode.toView }),
        __metadata("design:type", String)
    ], CommonColumn.prototype, "label", void 0);
    __decorate([
        bindable({ defaultBindingMode: bindingMode.toView }),
        __metadata("design:type", String)
    ], CommonColumn.prototype, "title", void 0);
    __decorate([
        bindable({ defaultBindingMode: bindingMode.toView }),
        __metadata("design:type", String)
    ], CommonColumn.prototype, "dataId", void 0);
    __decorate([
        bindable({ defaultBindingMode: bindingMode.toView }),
        __metadata("design:type", String)
    ], CommonColumn.prototype, "cellAlign", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Object)
    ], CommonColumn.prototype, "css", void 0);
    __decorate([
        bindable,
        __metadata("design:type", String)
    ], CommonColumn.prototype, "classes", void 0);
    __decorate([
        bindable,
        __metadata("design:type", String)
    ], CommonColumn.prototype, "cellVisible", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Boolean)
    ], CommonColumn.prototype, "colVisible", void 0);
    __decorate([
        bindable,
        __metadata("design:type", Object)
    ], CommonColumn.prototype, "order", void 0);
    __decorate([
        bindable({ defaultBindingMode: bindingMode.toView }),
        __metadata("design:type", String)
    ], CommonColumn.prototype, "validatePropertyName", void 0);
    __decorate([
        computedFrom('colVisible'),
        __metadata("design:type", Boolean),
        __metadata("design:paramtypes", [])
    ], CommonColumn.prototype, "isVisible", null);
    return CommonColumn;
}(DisposableViewModelBase));

//# sourceMappingURL=common-column.js.map
