import { EventEmitter, Component, ChangeDetectionStrategy, ChangeDetectorRef, Inject, Optional, ViewChild, Input, Output, ContentChild, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatIconModule } from '@angular/material/icon';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatSelect, MatSelectModule } from '@angular/material/select';
import { FORM_CONFIG, SdLabelDefDirective, SdCommonModule } from '@sd-angular/core/common';
import { SdSelect, SdSelectModule } from '@sd-angular/core/select';
import { SdTranslateModule } from '@sd-angular/core/translate';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';

class SdSelectEditor extends SdSelect {
    constructor(cdRef, formConfiguration) {
        super(cdRef, formConfiguration);
        this.cdRef = cdRef;
        this.formConfiguration = formConfiguration;
        this.addable = true;
        this.editable = true;
        this.deletable = true;
        this.sdAdd = new EventEmitter();
        this.sdEdit = new EventEmitter();
        this.sdDelete = new EventEmitter();
        this.onAdd = ($event) => {
            var _a;
            $event.stopPropagation();
            $event === null || $event === void 0 ? void 0 : $event.preventDefault();
            (_a = this.matSelect) === null || _a === void 0 ? void 0 : _a.close();
            this.sdAdd.emit();
        };
        this.onEdit = ($event, item) => {
            var _a;
            $event.stopPropagation();
            $event === null || $event === void 0 ? void 0 : $event.preventDefault();
            (_a = this.matSelect) === null || _a === void 0 ? void 0 : _a.close();
            this.sdEdit.emit(item);
        };
        this.onDelete = ($event, item) => {
            var _a;
            $event.stopPropagation();
            $event === null || $event === void 0 ? void 0 : $event.preventDefault();
            (_a = this.matSelect) === null || _a === void 0 ? void 0 : _a.close();
            this.sdDelete.emit(item);
        };
    }
}
SdSelectEditor.decorators = [
    { type: Component, args: [{
                selector: "sd-select-editor",
                template: "<label *ngIf=\"!appearance && label && !sdLabelDef?.templateRef\" class=\"d-block mb-0 T14M\">{{label}} <span class=\"text-danger mb-2\"\r\n  *ngIf=\"isRequired\">*</span></label>\r\n<ng-container *ngIf=\"sdLabelDef?.templateRef\" matSuffix>\r\n  <ng-container *ngTemplateOutlet=\"sdLabelDef.templateRef\">\r\n  </ng-container>\r\n</ng-container>\r\n<div class=\"d-flex align-items-center\" [class.sd-view]=\"sdView?.templateRef\" [class.c-focused]=\"isFocused\"\r\n[class.c-disabled]=\"formControl.disabled\" (click)=\"onClick()\">\r\n<ng-container *ngIf=\"sdView?.templateRef && !isFocused; else default\">\r\n  <ng-container\r\n    *ngTemplateOutlet=\"sdView.templateRef;context: { value: formControl.value, selectedItems: selectedItems | async }\">\r\n  </ng-container>\r\n</ng-container>\r\n<ng-template #default>\r\n  <mat-form-field class=\"sd-md\" [ngClass]=\"{'sd-sm': size === 'sm', 'no-padding-wrapper': disableErrorMessage}\"\r\n    [appearance]=\"appearance || 'outline'\">\r\n    <mat-label *ngIf=\"appearance && label\">{{label}}</mat-label>\r\n    <mat-select #select [formControl]=\"formControl\" [placeholder]=\"placeholder || (appearance ? label : '')\" multiple\r\n      (selectionChange)=\"onSelectionChange($event)\" disableOptionCentering=\"true\" panelClass=\"sd-select-panel\"\r\n      [ngClass]=\"{'sd-selected': !isRequired && (multiple ? formControl?.value?.length : formControl?.value != null)}\"\r\n      [required]=\"isRequired\" (openedChange)=\"onOpenChange($event)\" [attr.data-qclabel]=\"label\"\r\n      [attr.data-qcid]=\"qcId\" *ngIf=\"multiple\">\r\n      <mat-select-trigger>\r\n        {{display | async }}\r\n      </mat-select-trigger>\r\n      <mat-option *ngIf=\"filtered\" class=\"sd-filtered-input\" (keyup.Space)=\"$event.stopPropagation()\" disabled=\"true\">\r\n        <mat-form-field class=\"sd-md\" appearance=\"outline\">\r\n          <mat-icon matPrefix>search</mat-icon>\r\n          <input #input placeholder=\"{{'Search' | sdTranslate}}\" matInput autocomplete=\"off\"\r\n            (keydown)=\"$event.stopPropagation()\" (keyup)=\"searchTerm$.next($event.target.value)\">\r\n        </mat-form-field>\r\n      </mat-option>\r\n      <ng-container *ngIf=\"multiple && selectAll\">\r\n        <mat-checkbox class=\"mat-option\" [(ngModel)]=\"allSelected\" [ngModelOptions]=\"{standalone: true}\"\r\n          (change)=\"onSelectAll()\">\r\n          T\u1EA5t c\u1EA3</mat-checkbox>\r\n      </ng-container>\r\n      <ng-container *ngIf=\"valueField && displayField\">\r\n        <mat-option *ngFor=\"let item of filteredItems | async; trackBy: trackByKey\" [value]=\"item[valueField]\">\r\n          <div matTooltipPosition=\"above\" [matTooltip]=\"item[displayField]\" class=\"d-flex justify-content-between\">\r\n            <ng-container *ngIf=\"selectDisplayDef?.templateRef\">\r\n              <ng-container *ngTemplateOutlet=\"selectDisplayDef.templateRef;context:{item: item}\">\r\n              </ng-container>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"!selectDisplayDef?.templateRef\">\r\n              {{ item[displayField] }}\r\n            </ng-container>\r\n            <div>\r\n              <mat-icon *ngIf=\"editable && sdEdit?.observers?.length\" class=\"mr-1 c-fa-icon\" (click)=\"onEdit($event, item)\">\r\n                edit</mat-icon>\r\n              <mat-icon *ngIf=\"deletable && sdDelete?.observers?.length\" class=\"mr-0 c-fa-icon\" (click)=\"onDelete($event, item)\">\r\n                delete</mat-icon>\r\n            </div>\r\n          </div>\r\n        </mat-option>\r\n      </ng-container>\r\n      <ng-container *ngIf=\"!valueField && !displayField\">\r\n        <mat-option *ngFor=\"let item of filteredItems | async; trackBy: trackByKey\" [value]=\"item\">\r\n          <div matTooltipPosition=\"above\" [matTooltip]=\"item\" class=\"d-flex justify-content-between\">\r\n            <ng-container *ngIf=\"selectDisplayDef?.templateRef\">\r\n              <ng-container *ngTemplateOutlet=\"selectDisplayDef.templateRef;context:{item: item}\">\r\n              </ng-container>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"!selectDisplayDef?.templateRef\">\r\n              {{ item }}\r\n            </ng-container>\r\n            <div>\r\n              <mat-icon *ngIf=\"editable && sdEdit?.observers?.length\" class=\"mr-1 c-fa-icon\" (click)=\"onEdit($event, item)\">\r\n                edit</mat-icon>\r\n              <mat-icon *ngIf=\"deletable && sdDelete?.observers?.length\" class=\"mr-0 c-fa-icon\" (click)=\"onDelete($event, item)\">\r\n                delete</mat-icon>\r\n            </div>\r\n          </div>\r\n        </mat-option>\r\n      </ng-container>\r\n      <mat-option class=\"sd__option--add\" *ngIf=\"addable && sdAdd?.observers?.length\" (keyup.Space)=\"$event.stopPropagation()\" disabled=\"true\">\r\n        <div (click)=\"onAdd($event)\">\r\n          <mat-icon class=\"mr-1\">add</mat-icon>\r\n          {{'New item' | sdTranslate}}\r\n        </div>\r\n      </mat-option>\r\n    </mat-select>\r\n    <mat-select #select [formControl]=\"formControl\" [placeholder]=\"placeholder || (appearance ? label : '')\"\r\n      (selectionChange)=\"onSelectionChange($event)\" disableOptionCentering=\"true\" panelClass=\"sd-select-panel\"\r\n      [ngClass]=\"{'sd-selected': !isRequired && formControl?.value != null}\" [required]=\"isRequired\"\r\n      (openedChange)=\"onOpenChange($event)\" [attr.data-qclabel]=\"label\" [attr.data-qcid]=\"qcId\" *ngIf=\"!multiple\">\r\n      <mat-select-trigger>\r\n        {{display | async }}\r\n      </mat-select-trigger>\r\n      <mat-option *ngIf=\"filtered\" class=\"sd-filtered-input\" (keyup.Space)=\"$event.stopPropagation()\" disabled=\"true\">\r\n        <mat-form-field class=\"sd-md\" appearance=\"outline\">\r\n          <mat-icon matPrefix>search</mat-icon>\r\n          <input #input placeholder=\"{{'Search' | sdTranslate}}\" matInput autocomplete=\"off\"\r\n            (keydown)=\"$event.stopPropagation()\" (keyup)=\"searchTerm$.next($event.target.value)\">\r\n        </mat-form-field>\r\n      </mat-option>\r\n      <ng-container *ngIf=\"valueField && displayField\">\r\n        <mat-option *ngFor=\"let item of filteredItems | async; trackBy: trackByKey\" [value]=\"item[valueField]\">\r\n          <div matTooltipPosition=\"above\" [matTooltip]=\"item[displayField]\" class=\"d-flex justify-content-between\">\r\n            <ng-container *ngIf=\"selectDisplayDef?.templateRef\">\r\n              <ng-container *ngTemplateOutlet=\"selectDisplayDef.templateRef;context:{item: item}\">\r\n              </ng-container>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"!selectDisplayDef?.templateRef\">\r\n              {{ item[displayField] }}\r\n            </ng-container>\r\n            <div>\r\n              <mat-icon *ngIf=\"editable && sdEdit?.observers?.length\" class=\"mr-1 c-fa-icon\" (click)=\"onEdit($event, item)\">\r\n                edit</mat-icon>\r\n              <mat-icon *ngIf=\"deletable && sdDelete?.observers?.length\" class=\"mr-0 c-fa-icon\" (click)=\"onDelete($event, item)\">\r\n                delete</mat-icon>\r\n            </div>\r\n          </div>\r\n        </mat-option>\r\n      </ng-container>\r\n      <ng-container *ngIf=\"!valueField && !displayField\">\r\n        <mat-option *ngFor=\"let item of filteredItems | async; trackBy: trackByKey\" [value]=\"item\">\r\n          <div matTooltipPosition=\"above\" [matTooltip]=\"item\" class=\"d-flex justify-content-between\">\r\n            <ng-container *ngIf=\"selectDisplayDef?.templateRef\">\r\n              <ng-container *ngTemplateOutlet=\"selectDisplayDef.templateRef;context:{item: item}\">\r\n              </ng-container>\r\n            </ng-container>\r\n            <ng-container *ngIf=\"!selectDisplayDef?.templateRef\">\r\n              {{ item }}\r\n            </ng-container>\r\n            <div>\r\n              <mat-icon *ngIf=\"editable && sdEdit?.observers?.length\" class=\"mr-1 c-fa-icon\" (click)=\"onEdit($event, item)\">\r\n                edit</mat-icon>\r\n              <mat-icon *ngIf=\"deletable && sdDelete?.observers?.length\" class=\"mr-0 c-fa-icon\" (click)=\"onDelete($event, item)\">\r\n                delete</mat-icon>\r\n            </div>\r\n          </div>\r\n        </mat-option>\r\n      </ng-container>\r\n      <mat-option class=\"sd__option--add\" *ngIf=\"addable && sdAdd?.observers?.length\" (keyup.Space)=\"$event.stopPropagation()\" disabled=\"true\">\r\n        <div (click)=\"onAdd($event)\">\r\n          <mat-icon class=\"mr-1\">add</mat-icon>\r\n          {{'New item' | sdTranslate}}\r\n        </div>\r\n      </mat-option>\r\n    </mat-select>\r\n    <mat-icon\r\n      *ngIf=\"(multiple ? formControl?.value?.length : formControl?.value != null) && !isRequired && !formControl.disabled\"\r\n      class=\"pointer sd-suffix-icon\" (click)=\"clear($event)\" matSuffix>cancel\r\n    </mat-icon>\r\n    <mat-error *ngIf=\"formControl.errors?.required && !disableErrorMessage\">\r\n      {{'This field is required' | sdTranslate}}\r\n    </mat-error>\r\n    <mat-error *ngIf=\"formControl?.errors?.customValidator && !disableErrorMessage\">\r\n      {{formControl?.errors?.customValidator}}\r\n    </mat-error>\r\n  </mat-form-field>\r\n</ng-template>\r\n</div>",
                changeDetection: ChangeDetectionStrategy.OnPush,
                styles: [":host{display:block;padding-top:5px}:host ::ng-deep .mat-form-field.mat-form-field-appearance-outline .mat-select-arrow-wrapper{transform:none}:host ::ng-deep .sd-selected .mat-select-arrow{border:none}:host ::ng-deep .mat-form-field.no-padding-wrapper .mat-form-field-wrapper{padding-bottom:0}:host ::ng-deep .mat-form-field.mat-form-field-appearance-outline.mat-form-field-disabled .mat-form-field-outline{background:#f6f6f6;color:#e9e9e9}:host ::ng-deep .mat-form-field mat-select.mat-select-disabled .mat-select-value{color:#4d4d4d!important}:host ::ng-deep .mat-form-field .mat-placeholder-required{color:#f82c13}.sd-view:not(.c-focused):not(.c-disabled):hover{background-color:#ebecf0}::ng-deep .sd-select-panel .mat-option.sd-filtered-input{background-color:#fff;position:-webkit-sticky;position:sticky;top:0;z-index:10}::ng-deep .sd-select-panel .mat-option.sd-filtered-input .mat-form-field.mat-form-field-appearance-outline{width:100%}::ng-deep .sd-select-panel .mat-option.sd-filtered-input mat-pseudo-checkbox{display:none}::ng-deep .mat-select-panel .mat-option.sd-filtered-input{height:auto}::ng-deep .sd-select-panel .mat-option.sd-filtered-input input{color:#000}::ng-deep .sd-select-panel .mat-option.sd-filtered-input .mat-form-field-prefix .mat-icon{margin-right:0}::ng-deep .sd-select-panel .mat-option.sd-filtered-input .mat-form-field.mat-form-field-appearance-outline .mat-form-field-wrapper{padding:10px 0}::ng-deep .sd-select-panel .mat-option.sd-filtered-input .mat-form-field.mat-form-field-appearance-outline .mat-form-field-wrapper .mat-form-field-outline{background-color:rgba(0,0,0,.04)}.sd__option--add{background-color:#fff;bottom:0;color:rgba(0,0,0,.87);cursor:pointer;position:-webkit-sticky;position:sticky;z-index:10}.sd__option--add ::ng-deep mat-pseudo-checkbox{display:none}"]
            },] }
];
SdSelectEditor.ctorParameters = () => [
    { type: ChangeDetectorRef },
    { type: undefined, decorators: [{ type: Inject, args: [FORM_CONFIG,] }, { type: Optional }] }
];
SdSelectEditor.propDecorators = {
    matSelect: [{ type: ViewChild, args: [MatSelect,] }],
    addable: [{ type: Input }],
    editable: [{ type: Input }],
    deletable: [{ type: Input }],
    sdAdd: [{ type: Output }],
    sdEdit: [{ type: Output }],
    sdDelete: [{ type: Output }],
    sdLabelDef: [{ type: ContentChild, args: [SdLabelDefDirective,] }]
};

class SdSelectEditorModule {
}
SdSelectEditorModule.decorators = [
    { type: NgModule, args: [{
                imports: [
                    CommonModule,
                    FormsModule,
                    ReactiveFormsModule,
                    MatInputModule,
                    MatTooltipModule,
                    MatFormFieldModule,
                    MatIconModule,
                    MatSelectModule,
                    SdTranslateModule,
                    MatCheckboxModule,
                    MatProgressSpinnerModule,
                    SdCommonModule,
                    SdSelectModule
                ],
                declarations: [
                    SdSelectEditor
                ],
                exports: [
                    SdSelectEditor
                ],
                providers: []
            },] }
];

/*
 * Public API Surface of superdev-angular-core
 */

/**
 * Generated bundle index. Do not edit.
 */

export { SdSelectEditor, SdSelectEditorModule };
//# sourceMappingURL=sd-angular-core-select-editor.js.map
