/**
 * This file is part of the MedSafe application which is commercial software created by MedVision360 B.V.
 * The source code is proprietary and confidential.
 *
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 *
 * Copyright (c) by MedVision360 B.V. All rights reserved.
 *
 * For the application name: io.medrecord.medsafe
 */
import { __decorate, __param } from "tslib";
import { Component, EventEmitter, HostBinding, Input, Optional, Output, Self } from '@angular/core';
import { NgControl } from '@angular/forms';
import { IconType } from '../../../../models';
let SelectComponent = class SelectComponent {
    constructor(ngControl) {
        this.ngControl = ngControl;
        this.selectedItem = null;
        this.items = [];
        this.multiple = false;
        this.maxSelectedItems = false;
        this.addTag = false;
        this.formControlStyles = true;
        this.asBricks = false;
        this.joined = false;
        this.small = false;
        this.unselectable = true;
        this.searchable = false;
        this.selectChange = new EventEmitter();
        this.selectKeyUp = new EventEmitter();
        this.showCustomValue = false;
        this.hint = '';
        this.openStatus = false;
        this.iconType = IconType;
        this.disabledP = false;
        this.onChange = () => { };
        this.onTouched = () => { };
        if (ngControl) {
            ngControl.valueAccessor = this;
        }
    }
    set disabled(value) {
        this.disabledP = value;
    }
    get disabled() {
        return this.disabledP;
    }
    get closeOnSelect() {
        return !this.multiple;
    }
    get hideSelected() {
        return this.multiple;
    }
    selectSearch(term, item) {
        return item;
    }
    selectKeyUpHandle(query) {
        this.selectKeyUp.emit(query.target.value);
    }
    selectChangeHandle(selectedItem) {
        this.selectChange.emit(selectedItem);
        if (this.multiple) {
            this.onChange(selectedItem.map(item => item.value));
            return;
        }
        this.onChange(selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value);
    }
    selectOpen() {
        this.openStatus = true;
    }
    selectClose() {
        this.openStatus = false;
    }
    selectBrick(item) {
        var _a;
        if (this.unselectable && ((_a = this.selectedItem) === null || _a === void 0 ? void 0 : _a.value) === item.value) {
            this.selectChange.emit(null);
            this.selectedItem = null;
            this.onChange(null);
            return;
        }
        this.selectChange.emit(item);
        this.selectedItem = item;
        this.onChange(item.value);
    }
    // ControlValueAccessor implementations
    writeValue(value) {
        setTimeout(() => {
            var _a;
            const foundItem = (_a = this.items) === null || _a === void 0 ? void 0 : _a.find(item => item.value === value);
            if (foundItem) {
                this.selectedItem = foundItem;
            }
        });
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(disabled) {
        this.disabled = disabled;
    }
};
SelectComponent.ctorParameters = () => [
    { type: NgControl, decorators: [{ type: Self }, { type: Optional }] }
];
__decorate([
    Input()
], SelectComponent.prototype, "disabled", null);
__decorate([
    Input()
], SelectComponent.prototype, "selectedItem", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "items", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "multiple", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "maxSelectedItems", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "addTag", void 0);
__decorate([
    HostBinding('class.form-control-styles'), Input()
], SelectComponent.prototype, "formControlStyles", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "width", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "height", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "asBricks", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "joined", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "small", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "unselectable", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "searchable", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "label", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "labelDescription", void 0);
__decorate([
    Output()
], SelectComponent.prototype, "selectChange", void 0);
__decorate([
    Output()
], SelectComponent.prototype, "selectKeyUp", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "showCustomValue", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "customValueLabel", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "searchNotFoundLabel", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "description", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "inputId", void 0);
__decorate([
    Input()
], SelectComponent.prototype, "hint", void 0);
SelectComponent = __decorate([
    Component({
        selector: 'app-select',
        template: "<app-label [label]=\"label\"\n           [labelDescription]=\"labelDescription\"\n           [hint]=\"hint\"\n           [fieldId]=\"inputId\"></app-label>\n\n<div class=\"bricks-wrap\"\n     *ngIf=\"asBricks\">\n  <div class=\"brick\"\n       [class.brick_active]=\"selectedItem && item.value === selectedItem.value\"\n       [class.brick_joined]=\"joined\"\n       [class.brick_small]=\"small\"\n       (click)=\"selectBrick(item)\"\n       *ngFor=\"let item of items\">{{item.label}}</div>\n</div>\n\n<div *ngIf=\"!asBricks\"\n     class=\"select-holder\"\n     [style.max-width.px]=\"width\"\n     [style.width.px]=\"width\">\n  <ng-select [class.multiple-select]=\"multiple\"\n             [disabled]=\"disabled\"\n             [items]=\"items\"\n             bindLabel=\"label\"\n             [clearable]=\"unselectable\"\n             [searchable]=\"searchable\"\n             [(ngModel)]=\"selectedItem\"\n             [multiple]=\"multiple\"\n             [closeOnSelect]=\"closeOnSelect\"\n             [hideSelected]=\"hideSelected\"\n             [addTag]=\"addTag\"\n             [style.max-height.px]=\"height\"\n             [style.height.px]=\"height\"\n             (open)=\"selectOpen()\"\n             (close)=\"selectClose()\"\n             (blur)=\"onTouched()\"\n             [searchFn]=\"selectSearch\"\n             (change)=\"selectChangeHandle($event)\"\n             (keyup)=\"selectKeyUpHandle($event)\"></ng-select>\n\n  <div class=\"open-status-icon-wrap\">\n    <app-icon\n              [icon]=\"openStatus && !multiple ? iconType.chevronUp : iconType.chevronDown\"\n              [type]=\"openStatus && !multiple ? 'light' : 'primary'\"></app-icon>\n  </div>\n</div>\n\n<app-input-errors\n                  *ngIf=\"ngControl\"\n                  [errors]=\"ngControl.errors\"\n                  [touched]=\"ngControl.touched\"></app-input-errors>\n",
        styles: ["/*!\n * This file is part of the MedSafe application which is commercial software created by MedVision360 B.V.\n *  The source code is proprietary and confidential.\n *\n *  Unauthorized copying of this file, via any medium is strictly prohibited.\n *\n *  Copyright (c) by MedVision360 B.V. All rights reserved.\n *\n *  For the application name: io.medrecord.medsafe\n */:host{user-drag:none;user-select:none;-moz-user-select:none;-webkit-user-drag:none;-webkit-user-select:none;-ms-user-select:none;display:block;position:relative}:host label{font-size:14px;display:inline-block;line-height:1;margin-bottom:10px;font-weight:500}:host label span{font-weight:400}:host.form-control-styles{margin-bottom:24px}.select-holder{position:relative}.select-holder .description{position:absolute;top:50%;transform:translate(0,-50%);margin-left:20px;left:100%;white-space:nowrap}.select-holder::ng-deep .ng-select-container{height:100%}.open-status-icon-wrap{pointer-events:none;position:absolute;top:50%;transform:translate(0,-50%);right:10px;z-index:9999;display:flex;align-items:center;justify-content:center}.label-wrapper{display:flex}.label-wrapper label{font-size:14px;font-weight:600;display:inline-block;line-height:1;margin-bottom:10px;margin-right:5px}.label-wrapper app-hint{margin-left:5px;margin-right:10px}.label-wrapper .label-desc{font-weight:400}.bricks-wrap{display:flex}.bricks-wrap .description{-ms-grid-row-align:center;align-self:center;margin-left:10px;white-space:nowrap}.brick{box-sizing:border-box;border:2px solid var(--mystic-color);border-radius:5px;cursor:pointer;margin-right:8px;color:var(--primary-color);padding:7px 20px;font-size:13px}.brick_active{color:var(--white-color);border-color:var(--primary-color);background:var(--primary-color)}.brick_joined{margin-right:0;border-radius:0}.brick_joined:first-child{border-top-left-radius:5px;border-bottom-left-radius:5px}.brick_joined:last-child{border-top-right-radius:5px;border-bottom-right-radius:5px}.brick_small{padding:5px 11px;font-size:11px}.label-hint{display:inline-block;margin-left:4px;vertical-align:middle}::ng-deep .ng-select .ng-select-container{border-color:var(--athens-darken-color);background-color:var(--athens-darken-color)}::ng-deep .ng-select .ng-select-container:hover{border-color:var(--athens-darken-hover-color);background-color:var(--athens-darken-hover-color)}::ng-deep .ng-select .ng-select-container:focus{border-color:var(--geyser-color);background-color:var(--geyser-color)}::ng-deep .ng-select.ng-select-focused .ng-select-container,::ng-deep .ng-select.ng-select-opened .ng-select-container{background-color:var(--primary-color)!important;border-color:var(--primary-color)}::ng-deep .ng-select.ng-select-focused:not(.ng-select-opened)>.ng-select-container{background-color:var(--athens-color)!important;border-color:var(--white-color)}::ng-deep .ng-select.multiple-select.ng-select-multiple.ng-select-opened .ng-select-container{border-color:var(--primary-color)}::ng-deep .ng-select.multiple-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value .ng-value-label{color:var(--cape-cod-color)}::ng-deep .ng-select.multiple-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value .ng-value-icon{color:var(--primary-color)}::ng-deep .ng-select.multiple-select.ng-select-multiple .ng-select-container .ng-value-container .ng-value .ng-value-icon:hover{background-color:var(--primary-color);color:var(--white-color)}::ng-deep .ng-select .ng-dropdown-panel{box-shadow:0 2px 2px rgba(133,145,170,.25)}::ng-deep .ng-select .ng-dropdown-panel .ng-dropdown-panel-items::-webkit-scrollbar-track{box-shadow:none}::ng-deep .ng-select .ng-dropdown-panel .ng-dropdown-panel-items::-webkit-scrollbar{max-height:150px;min-height:6px;width:6px!important}::ng-deep .ng-select .ng-dropdown-panel .ng-dropdown-panel-items::-webkit-scrollbar-thumb{background:rgba(147,146,146,.5);border-radius:3.5px}::ng-deep .ng-select .ng-dropdown-panel .ng-dropdown-panel-items .ng-option{color:var(--boulder-color)!important}::ng-deep .ng-select .ng-dropdown-panel .ng-dropdown-panel-items .ng-option.ng-option-selected{background-color:var(--mystic-color);color:var(--primary-color)!important}::ng-deep .ng-select .ng-dropdown-panel .ng-dropdown-panel-items .ng-option.ng-option-marked{background-color:var(--athens-color)}::ng-deep .ng-select .ng-dropdown-panel .ng-dropdown-panel-items .ng-option:hover{background-color:var(--mystic-hover-color)}::ng-deep .ng-select .ng-dropdown-panel .ng-dropdown-panel-items .ng-option:focus{background-color:var(--mystic-pressed-color)}::ng-deep .ng-select.ng-select-opened>.ng-select-container{background:var(--primary-color);color:var(--white-color)!important}::ng-deep .ng-select.ng-select-opened>.ng-select-container .ng-input input{color:var(--white-color)}::ng-deep .ng-select.ng-select-opened>.ng-select-container:hover{background:var(--primary-hover-color);color:var(--white-hover-color)!important}"]
    }),
    __param(0, Self()), __param(0, Optional())
], SelectComponent);
export { SelectComponent };
//# sourceMappingURL=data:application/json;base64, 