"use strict";
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    }
    return function (d, b) {
        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);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var _ = require("lodash");
var angular_1 = require("@jsonforms/angular");
var store_1 = require("@angular-redux/store");
var core_2 = require("@jsonforms/core");
var master_detail_service_1 = require("./master-detail.service");
var keywords = ['#', 'properties', 'items'];
exports.removeSchemaKeywords = function (path) {
    return path.split('/').filter(function (s) { return !_.some(keywords, function (key) { return key === s; }); }).join('.');
};
var MasterListComponent = /** @class */ (function (_super) {
    __extends(MasterListComponent, _super);
    function MasterListComponent(ngRedux, masterDetailService) {
        var _this = _super.call(this, ngRedux) || this;
        _this.masterDetailService = masterDetailService;
        _this.selectedItem = _this.masterDetailService.getSelectedItem();
        return _this;
    }
    MasterListComponent.prototype.mapAdditionalProps = function (props) {
        var data = props.data, schema = props.schema, uischema = props.uischema;
        var controlElement = uischema;
        var instancePath = core_2.toDataPath(controlElement.scope + "/items");
        var resolvedSchema = core_2.resolveSchema(schema, controlElement.scope + "/items");
        var detailUISchema = controlElement.options.detail ||
            core_2.Generate.uiSchema(resolvedSchema, 'VerticalLayout');
        var masterItems = data.map(function (d, index) {
            var labelRefInstancePath = exports.removeSchemaKeywords(controlElement.options.labelRef);
            var masterItem = {
                label: _.get(d, labelRefInstancePath),
                data: d,
                path: instancePath + "." + index,
                schema: resolvedSchema,
                uischema: detailUISchema
            };
            return masterItem;
        });
        if (this.masterItems === undefined ||
            this.masterItems.length !== masterItems.length) {
            this.masterItems = masterItems;
        }
    };
    MasterListComponent.prototype.onSelect = function (item) {
        this.selectedItem = item;
        this.masterDetailService.setSelectedItem(item);
    };
    MasterListComponent = __decorate([
        core_1.Component({
            selector: 'jsonforms-list-with-detail-master',
            template: "\n    <mat-sidenav-container class=\"container\" [fxHide]=\"hidden\">\n        <mat-sidenav mode=\"side\" opened>\n          <mat-nav-list>\n            <mat-list-item\n                *ngFor=\"let item of masterItems\"\n                [class.selected]=\"item === selectedItem\"\n                (click)=\"onSelect(item)\"\n            >\n                <a matLine>{{item.label}}</a>\n            </mat-list-item>\n          </mat-nav-list>\n        </mat-sidenav>\n        <mat-sidenav-content class=\"content\">\n          <jsonforms-detail [item]=\"selectedItem\"></jsonforms-detail>\n        </mat-sidenav-content>\n    </mat-sidenav-container>",
            styles: ["\n      .container {\n        height: 100vh;\n      }\n      .content {\n        padding: 15px;\n      }\n    "]
        }),
        __metadata("design:paramtypes", [store_1.NgRedux,
            master_detail_service_1.MasterDetailService])
    ], MasterListComponent);
    return MasterListComponent;
}(angular_1.JsonFormsControl));
exports.MasterListComponent = MasterListComponent;
exports.masterDetailTester = core_2.rankWith(4, core_2.uiTypeIs('ListWithDetail'));
//# sourceMappingURL=master.js.map