import { __awaiter } from "tslib";
import { Component, Input, ChangeDetectorRef, EventEmitter, ChangeDetectionStrategy, Output } from '@angular/core';
export class SdGridDesktopColumnEdit {
    constructor(ref) {
        this.ref = ref;
        this.sdChange = new EventEmitter();
        this.onEditorChange = (column, item, value) => {
            var _a, _b;
            if (column.type !== 'children') {
                (_b = (_a = column.editor) === null || _a === void 0 ? void 0 : _a.change) === null || _b === void 0 ? void 0 : _b.call(_a, item, value);
                this.ref.detectChanges();
                this.sdChange.emit();
            }
        };
        this.onAutocompleteChange = (item) => {
            var _a, _b;
            if (this.column.type === 'string' || this.column.type === 'values') {
                (_b = (_a = this.column.editor) === null || _a === void 0 ? void 0 : _a.change) === null || _b === void 0 ? void 0 : _b.call(_a, this.item, this.item[this.column.field], item);
                this.ref.detectChanges();
                this.sdChange.emit();
            }
        };
        this.onSelectionChange = (params) => {
            var _a, _b;
            if (this.column.type === 'string' || this.column.type === 'values') {
                (_b = (_a = this.column.editor) === null || _a === void 0 ? void 0 : _a.change) === null || _b === void 0 ? void 0 : _b.call(_a, this.item, params === null || params === void 0 ? void 0 : params.value, (params === null || params === void 0 ? void 0 : params.item) || (params === null || params === void 0 ? void 0 : params.items));
                this.ref.detectChanges();
                this.sdChange.emit();
            }
        };
        this.dynamicItems = (value) => __awaiter(this, void 0, void 0, function* () {
            if ('editor' in this.column && 'item' in this.column.editor) {
                const items = this.column.editor.item.items || [];
                if (Array.isArray(items)) {
                    return items;
                }
                const results = items(this.item, value);
                if (results instanceof Promise) {
                    return yield results;
                }
                return results;
            }
            else {
                return [];
            }
        });
    }
}
SdGridDesktopColumnEdit.decorators = [
    { type: Component, args: [{
                selector: 'sd-grid-desktop-column-edit',
                template: "<ng-container *ngIf=\"column && item\">\r\n  <div *ngIf=\"column.type === 'string'\">\r\n    <div *ngIf=\"column.editor?.item;else elseUseInput\">\r\n      <sd-select *ngIf=\"!column.editor?.autocomplete\" size=\"sm\" [(model)]=\"item[column.field]\"\r\n        [items]=\"item[column.editor?.item?.dependOnField] | sdDynamicItems:dynamicItems\"\r\n        [valueField]=\"column.editor.item.value\" [displayField]=\"column.editor.item.display\"\r\n        (sdSelection)=\"onSelectionChange($event)\" [placeholder]=\"column.title\">\r\n      </sd-select>\r\n      <sd-autocomplete *ngIf=\"column.editor?.autocomplete\" size=\"sm\" [(model)]=\"item[column.field]\"\r\n        [items]=\"item[column.editor?.item?.dependOnField] | sdDynamicItems:dynamicItems\"\r\n        [valueField]=\"column.editor.item.value\" [displayField]=\"column.editor.item.display\"\r\n        (sdChange)=\"onAutocompleteChange($event)\" [placeholder]=\"column.title\">\r\n      </sd-autocomplete>\r\n    </div>\r\n    <ng-template #elseUseInput>\r\n      <sd-input size=\"sm\" *ngIf=\"column.editor?.click\" [(model)]=\"item[column.field]\"\r\n        (keyupEnter)=\"column.editor?.keyupEnter && column.editor?.keyupEnter(item)\"\r\n        (sdChange)=\"onEditorChange(column,item,item[column.field])\" (sdClick)=\"column.editor.click(item)\"></sd-input>\r\n      <sd-input size=\"sm\" *ngIf=\"!column.editor?.click\" [(model)]=\"item[column.field]\"\r\n        (keyupEnter)=\"column.editor?.keyupEnter && column.editor?.keyupEnter(item)\"\r\n        (sdChange)=\"onEditorChange(column,item,item[column.field])\"></sd-input>\r\n    </ng-template>\r\n  </div>\r\n  <div *ngIf=\"column.type === 'color'\">\r\n    <sd-input size=\"sm\" type=\"color\" [(model)]=\"item[column.field]\"\r\n      (sdChange)=\"onEditorChange(column,item,item[column.field])\">\r\n    </sd-input>\r\n  </div>\r\n  <div *ngIf=\"column.type === 'number'\">\r\n    <sd-input-currency size=\"sm\" [(model)]=\"item[column.field]\"\r\n      (keyupEnter)=\"column.editor?.keyupEnter && column.editor?.keyupEnter(item)\"\r\n      (sdChange)=\"onEditorChange(column,item,item[column.field])\"></sd-input-currency>\r\n  </div>\r\n  <div *ngIf=\"column.type === 'date'\">\r\n    <sd-date-time size=\"sm\" [(model)]=\"item[column.field]\" type=\"date\"></sd-date-time>\r\n  </div>\r\n  <div class=\"text-center\" *ngIf=\"column.type === 'datetime'\">\r\n    <sd-date-time size=\"sm\" [(model)]=\"item[column.field]\" type=\"datetime\"></sd-date-time>\r\n  </div>\r\n  <div class=\"text-center\" *ngIf=\"column.type === 'time'\">\r\n    <sd-time [(model)]=\"item[column.field]\"></sd-time>\r\n    <!-- <sd-grid-date-picker-control [(model)]=\"item[column.field]\" type=\"time\"></sd-grid-date-picker-control> -->\r\n  </div>\r\n  <div class=\"align-middle text-center\" *ngIf=\"column.type === 'bool'\">\r\n    <sd-switch [(model)]=\"item[column.field]\" (sdChange)=\"onEditorChange(column,item,item[column.field])\">\r\n    </sd-switch>\r\n  </div>\r\n  <div *ngIf=\"column.type === 'values'\">\r\n    <div *ngIf=\"column.editor?.item;else elseUseValues\">\r\n      <sd-select *ngIf=\"!column.editor?.autocomplete\" size=\"sm\" [(model)]=\"item[column.field]\"\r\n        [items]=\"item[column.editor?.item?.dependOnField] | sdDynamicItems:dynamicItems\"\r\n        [valueField]=\"column.editor.item.value\" [displayField]=\"column.editor.item.display\"\r\n        (sdSelection)=\"onSelectionChange($event)\" [placeholder]=\"column.title\">\r\n      </sd-select>\r\n      <sd-autocomplete *ngIf=\"column.editor?.autocomplete\" size=\"sm\" [(model)]=\"item[column.field]\"\r\n        [items]=\"item[column.editor?.item?.dependOnField] | sdDynamicItems:dynamicItems\"\r\n        [valueField]=\"column.editor.item.value\" [displayField]=\"column.editor.item.display\"\r\n        (sdChange)=\"onAutocompleteChange($event)\" [placeholder]=\"column.title\">\r\n      </sd-autocomplete>\r\n    </div>\r\n    <ng-template #elseUseValues>\r\n      <sd-select *ngIf=\"!column.editor?.autocomplete\" size=\"sm\" [(model)]=\"item[column.field]\" [items]=\"column.values\" valueField=\"value\" displayField=\"text\"\r\n        (sdSelection)=\"onSelectionChange($event)\" [placeholder]=\"column.title\">\r\n      </sd-select>\r\n      <sd-autocomplete *ngIf=\"column.editor?.autocomplete\" size=\"sm\" [(model)]=\"item[column.field]\" [items]=\"column.values\" valueField=\"value\" displayField=\"text\"\r\n      (sdChange)=\"onAutocompleteChange($event)\" [placeholder]=\"column.title\">\r\n      </sd-autocomplete>\r\n    </ng-template>\r\n  </div>\r\n  <div *ngIf=\"column.type === 'radio'\">\r\n    <section class=\"mt-5 ml-5\">\r\n      <mat-radio-group class=\"d-flex\" [(ngModel)]=\"item[column.field]\"\r\n        (change)=\"column.editor?.change && column.editor?.change(item)\">\r\n        <mat-radio-button *ngIf=\"!column.editor?.required\" color=\"warn\" class=\"mr-5\" value=\"\">\r\n          {{'Please select' | sdTranslate}}\r\n        </mat-radio-button>\r\n        <mat-radio-button color=\"primary\" class=\"mr-5\" *ngFor=\"let data of column.values\"\r\n          [value]=\"data[column.valueField]\">\r\n          {{data[column.displayField]}}\r\n        </mat-radio-button>\r\n      </mat-radio-group>\r\n    </section>\r\n  </div>\r\n  <div class=\"align-middle text-center\" *ngIf=\"column.type === 'image'\">\r\n    <img [src]=\"item[column.field]\" [width]=\"column.display?.width\" [height]=\"column.display?.height\"\r\n      style=\"margin: 5px 0\" (click)=\"column.click && column.click(item[column.field], item)\">\r\n  </div>\r\n</ng-container>",
                changeDetection: ChangeDetectionStrategy.OnPush,
                styles: [".c-input-xs{font-size:13px!important;height:28px!important;line-height:1.5!important;padding:3px!important}"]
            },] }
];
SdGridDesktopColumnEdit.ctorParameters = () => [
    { type: ChangeDetectorRef }
];
SdGridDesktopColumnEdit.propDecorators = {
    column: [{ type: Input }],
    item: [{ type: Input }],
    sdChange: [{ type: Output }]
};
//# sourceMappingURL=data:application/json;base64, 