import * as tslib_1 from "tslib";
import { Component, Input, Output, EventEmitter, ViewEncapsulation, ChangeDetectionStrategy, forwardRef, ChangeDetectorRef } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { TransferService } from './transfer.service';
/*
 * Provider Expression that allows component to register as a ControlValueAccessor.
 * This allows it to support [(ngModel)].
 * @docs-private
 */
var TRANSFER_VALUE_ACCESSOR = {
    provide: NG_VALUE_ACCESSOR,
    useExisting: forwardRef(function () { return TransferComponent; }),
    multi: true
};
var TransferComponent = /** @class */ (function () {
    function TransferComponent(_cd, service) {
        var _this = this;
        this._cd = _cd;
        this.service = service;
        /** search event */
        this.searchValue = new EventEmitter();
        /** tree node expand event */
        this.onExpandNode = new EventEmitter();
        /** tree node all trans event */
        this.onTransAll = new EventEmitter();
        /** tree add extend data event */
        this.onExtendData = new EventEmitter();
        /**
         * Whether the transfer is disabled
         * @default false
         */
        this.disabled = false;
        /**
         * Whether the transfer is can all-trans
         * @default false
         */
        this.allSelectLink = true;
        /**
         * Whether the transfer is can all-delete
         * @default false
         */
        this.allDeleteLink = true;
        /**
         * Whether the transfer candidate is have search
         * @default false
         */
        this.candidateSearch = true;
        /**
         * Whether the transfer selected is have search
         * @default false
         */
        this.selectedSearch = true;
        /**
         * candidate list title
         */
        this.candidateTitle = '备选列表';
        /**
         * selected list title
         */
        this.selectedTitle = '已选列表';
        /**
         * add extend data link config
         */
        this.addLink = {
            text: '',
            flag: false
        };
        /**
         * all options count
         * @docs-private
         */
        this.candidateCount = 0;
        /**
         * all selected options count
         * @docs-private
         */
        this.selectedCount = 0;
        this.subscription = this.service.getMsg().subscribe(function (msg) {
            if (typeof msg.candidateCount === 'number') {
                _this.candidateCount = msg.candidateCount;
            }
            if (typeof msg.selectedCount === 'number') {
                _this.selectedCount = msg.selectedCount;
            }
            _this._cd.markForCheck();
        });
    }
    TransferComponent.prototype.ngOnDestroy = function () {
        this.subscription.unsubscribe();
    };
    /**
     * clear search results
     * @docs-private
     */
    TransferComponent.prototype.clearSearch = function (event, mode) {
        this.searchByKeyWord(event, mode);
    };
    /**
     * fitler candidate or selected list by key word
     * @docs-private
     */
    TransferComponent.prototype.searchByKeyWord = function (event, mode) {
        // 向组件外部暴露搜索事件
        this.searchValue.emit({
            event: event,
            mode: mode
        });
    };
    /**
     * tree node expand event
     * @docs-private
     */
    TransferComponent.prototype.expandNode = function (event) {
        this.onExpandNode.emit(event);
    };
    /**
     * trans all options to Selected or not
     * @docs-private
     */
    TransferComponent.prototype.transAll = function (mode, chkVal) {
        this.onTransAll.emit({
            mode: mode,
            chkVal: chkVal
        });
    };
    /**
     * extend data
     * @docs-private
     */
    TransferComponent.prototype.extendData = function () {
        this.onExtendData.emit();
    };
    tslib_1.__decorate([
        Output(),
        tslib_1.__metadata("design:type", EventEmitter)
    ], TransferComponent.prototype, "searchValue", void 0);
    tslib_1.__decorate([
        Output(),
        tslib_1.__metadata("design:type", EventEmitter)
    ], TransferComponent.prototype, "onExpandNode", void 0);
    tslib_1.__decorate([
        Output(),
        tslib_1.__metadata("design:type", EventEmitter)
    ], TransferComponent.prototype, "onTransAll", void 0);
    tslib_1.__decorate([
        Output(),
        tslib_1.__metadata("design:type", EventEmitter)
    ], TransferComponent.prototype, "onExtendData", void 0);
    tslib_1.__decorate([
        Input(),
        tslib_1.__metadata("design:type", Boolean)
    ], TransferComponent.prototype, "disabled", void 0);
    tslib_1.__decorate([
        Input(),
        tslib_1.__metadata("design:type", Boolean)
    ], TransferComponent.prototype, "allSelectLink", void 0);
    tslib_1.__decorate([
        Input(),
        tslib_1.__metadata("design:type", Boolean)
    ], TransferComponent.prototype, "allDeleteLink", void 0);
    tslib_1.__decorate([
        Input(),
        tslib_1.__metadata("design:type", Boolean)
    ], TransferComponent.prototype, "candidateSearch", void 0);
    tslib_1.__decorate([
        Input(),
        tslib_1.__metadata("design:type", Boolean)
    ], TransferComponent.prototype, "selectedSearch", void 0);
    tslib_1.__decorate([
        Input(),
        tslib_1.__metadata("design:type", String)
    ], TransferComponent.prototype, "candidateTitle", void 0);
    tslib_1.__decorate([
        Input(),
        tslib_1.__metadata("design:type", String)
    ], TransferComponent.prototype, "selectedTitle", void 0);
    tslib_1.__decorate([
        Input(),
        tslib_1.__metadata("design:type", Object)
    ], TransferComponent.prototype, "addLink", void 0);
    TransferComponent = tslib_1.__decorate([
        Component({
            selector: 'nb-transfer',
            template: "<div class=\"nb-transfer-candidate\"><div class=\"nb-transfer-title\"><span>{{ candidateTitle }}({{ candidateCount }})</span> <a *ngIf=\"allSelectLink\" nb-button theme=\"transparent\" [disabled]=\"disabled\" [class.nb-transfer-title-link]=\"disabled\" (click)=\"transAll('selected', true)\">全部添加</a></div><nb-search-box *ngIf=\"candidateSearch\" placeholder=\"\" size=\"small\" [disabled]=\"disabled\" (onClear)=\"clearSearch($event, 'candidate')\" (onSearch)=\"searchByKeyWord($event, 'candidate')\"></nb-search-box><div class=\"nb-transfer-tree-wrap\" [class.nb-transfer-tree-have-add-link-wrap]=\"addLink && addLink.flag\" [class.nb-transfer-tree-no-search-wrap]=\"!candidateSearch\"><ng-content select=\"nb-transfer-candidate\"></ng-content></div><a *ngIf=\"addLink && addLink.flag\" nb-button theme=\"transparent\" [disabled]=\"disabled\" [class.nb-transfer-title-link]=\"disabled\" class=\"nb-transfer-add-link\" (click)=\"extendData()\">{{ addLink.text }}</a></div><div class=\"nb-transfer-selected\"><div class=\"nb-transfer-title\"><span>{{ selectedTitle }}({{ selectedCount }}/{{ candidateCount }})</span> <a *ngIf=\"allDeleteLink\" nb-button theme=\"transparent\" [disabled]=\"disabled\" [class.nb-transfer-title-link]=\"disabled\" (click)=\"transAll('candidate', false)\">全部删除</a></div><nb-search-box *ngIf=\"selectedSearch\" placeholder=\"\" size=\"small\" [disabled]=\"disabled\" (onClear)=\"clearSearch($event, 'selected')\" (onSearch)=\"searchByKeyWord($event, 'selected')\"></nb-search-box><div class=\"nb-transfer-tree-wrap\" [class.nb-transfer-tree-have-add-link-wrap]=\"addLink && addLink.flag\" [class.nb-transfer-tree-no-search-wrap]=\"!selectedSearch\"><ng-content select=\"nb-transfer-selected\"></ng-content></div><a *ngIf=\"addLink && addLink.flag\" nb-button theme=\"transparent\" [disabled]=\"disabled\" class=\"nb-transfer-add-link\"></a></div>",
            encapsulation: ViewEncapsulation.None,
            changeDetection: ChangeDetectionStrategy.OnPush,
            preserveWhitespaces: false,
            providers: [TRANSFER_VALUE_ACCESSOR],
            host: {
                'class': 'nb-widget nb-transfer'
            },
            exportAs: 'nbTransfer'
        }),
        tslib_1.__metadata("design:paramtypes", [ChangeDetectorRef,
            TransferService])
    ], TransferComponent);
    return TransferComponent;
}());
export { TransferComponent };
//# sourceMappingURL=transfer.js.map