"use strict";
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 });
const core_1 = require("@angular/core");
const store_1 = require("@ngrx/store");
require("rxjs/add/operator/filter");
require("../util/takeUntilDestroyed");
const code_1 = require("../redux/code");
const project_1 = require("../redux/project");
/**
 * The code component displays the code editor for participants/control state/
 */
let CodeNavComponent = class CodeNavComponent {
    constructor(store, project, cdRef) {
        this.store = store;
        this.project = project;
        this.cdRef = cdRef;
        /**
         * Element role (button for accessibility)
         */
        this.role = 'button';
        /**
         * Whether the nav item is active.
         */
        this.isActive = false;
    }
    ngOnInit() {
        this.store
            .select('code')
            .takeUntilDestroyed(this)
            .subscribe(code => {
            this.isActive = code.state === code_1.CodeState[this.value];
            this.cdRef.markForCheck();
            this.cdRef.detectChanges();
        });
    }
    ngOnDestroy() {
        /* noop */
    }
    onClick() {
        this.project.setCodeState(this.isActive ? code_1.CodeState.Closed : code_1.CodeState[this.value]);
    }
};
__decorate([
    core_1.Input('value'),
    __metadata("design:type", Object)
], CodeNavComponent.prototype, "value", void 0);
__decorate([
    core_1.Input('icon'),
    __metadata("design:type", String)
], CodeNavComponent.prototype, "icon", void 0);
__decorate([
    core_1.HostBinding('attr.role'),
    __metadata("design:type", Object)
], CodeNavComponent.prototype, "role", void 0);
__decorate([
    core_1.HostListener('click'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], CodeNavComponent.prototype, "onClick", null);
CodeNavComponent = __decorate([
    core_1.Component({
        selector: 'editor-code-nav',
        templateUrl: './code-nav.component.html',
        styleUrls: ['./code-nav.component.scss'],
        changeDetection: core_1.ChangeDetectionStrategy.OnPush,
    }),
    __metadata("design:paramtypes", [store_1.Store,
        project_1.ProjectService,
        core_1.ChangeDetectorRef])
], CodeNavComponent);
exports.CodeNavComponent = CodeNavComponent;
