import { A11yModule } from '@angular/cdk/a11y';
import { Dialog, DIALOG_DATA, DialogModule, DialogRef } from '@angular/cdk/dialog';
import { DragDropModule } from '@angular/cdk/drag-drop';
import { CommonModule } from '@angular/common';
import { Component, HostBinding, inject } from '@angular/core';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { ButtonGroupDirective } from '@metad/ocap-angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { EMPTY, switchMap } from 'rxjs';
import * as i0 from "@angular/core";
import * as i1 from "@angular/cdk/a11y";
import * as i2 from "@angular/forms";
import * as i3 from "@angular/cdk/drag-drop";
import * as i4 from "@angular/material/button";
import * as i5 from "@angular/material/form-field";
import * as i6 from "@angular/material/input";
import * as i7 from "@ngx-translate/core";
export class CdkConfirmUniqueComponent {
    constructor() {
        this.isDialogContainer = true;
        this.data = inject(DIALOG_DATA);
        this._dialogRef = inject((DialogRef));
        this.value = new FormControl(null);
        this.validators = this.data?.validators;
    }
    get invalid() {
        return this.value.invalid;
    }
    get error() {
        return this.value.errors?.['error'];
    }
    ngOnInit() {
        this.value.setAsyncValidators(this.validators?.map((validator) => async (control) => await validator(control.value)));
        this.reset();
    }
    reset() {
        this.value.setValue(this.data?.value);
        this.title = this.data?.title;
    }
    onCancel() {
        this._dialogRef.close();
    }
    onApply() {
        this._dialogRef.close(this.value.value);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: CdkConfirmUniqueComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.3.12", type: CdkConfirmUniqueComponent, isStandalone: true, selector: "cdk-confirm-unique", host: { properties: { "class.ngm-dialog-container": "this.isDialogContainer" }, classAttribute: "cdk-dialog-card" }, ngImport: i0, template: "<header cdkDrag cdkDragRootElement=\".cdk-overlay-pane\" cdkDragHandle class=\"pb-2 cursor-move\">\n  <h4 class=\"text-xl pointer-events-none\">\n    {{ title || ('COMPONENTS.CONFIRM.INPUT_UNIQUE_VALUE' | translate: {Default: 'Input Unique Value'}) }}\n  </h4>\n</header>\n\n<div class=\"mat-typography py-4\" cdkTrapFocus [cdkTrapFocusAutoCapture]=\"true\">\n  <form (ngSubmit)=\"onApply()\">\n    <mat-form-field appearance=\"fill\" class=\"w-full\">\n      <mat-label>{{ 'COMPONENTS.CONFIRM.NAME' | translate: {Default: 'Name'} }}</mat-label>\n      <input cdkFocusInitial matInput name=\"value\" [formControl]=\"value\" />\n      @if (invalid) {\n        <mat-error>\n          {{error || 'Error'}}\n        </mat-error>\n      }\n    </mat-form-field>\n  </form>\n</div>\n\n<div class=\"w-full flex justify-between items-center\">\n  <button mat-button (click)=\"reset()\">\n    {{ 'COMPONENTS.COMMON.RESET' | translate: {Default: 'Reset'} }}\n  </button>\n\n  <div ngmButtonGroup class=\"ml-8\">\n    <button mat-flat-button (click)=\"onCancel()\">\n      {{ 'COMPONENTS.COMMON.CANCEL' | translate: {Default: 'Cancel'} }}\n    </button>\n    <button mat-raised-button color=\"accent\"\n      [disabled]=\"invalid\"\n      cdkFocusInitial\n      (click)=\"onApply()\"\n    >\n      {{ 'COMPONENTS.COMMON.APPLY' | translate: {Default: 'Apply'} }}\n    </button>\n  </div>\n</div>\n", styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: A11yModule }, { kind: "directive", type: i1.CdkTrapFocus, selector: "[cdkTrapFocus]", inputs: ["cdkTrapFocus", "cdkTrapFocusAutoCapture"], exportAs: ["cdkTrapFocus"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i2.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i2.NgForm, selector: "form:not([ngNoForm]):not([formGroup]),ng-form,[ngForm]", inputs: ["ngFormOptions"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "ngmodule", type: DragDropModule }, { kind: "directive", type: i3.CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { kind: "directive", type: i3.CdkDragHandle, selector: "[cdkDragHandle]", inputs: ["cdkDragHandleDisabled"] }, { kind: "ngmodule", type: DialogModule }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i4.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", exportAs: ["matButton"] }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "component", type: i5.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i5.MatLabel, selector: "mat-label" }, { kind: "directive", type: i5.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "ngmodule", type: MatInputModule }, { kind: "directive", type: i6.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "ngmodule", type: TranslateModule }, { kind: "pipe", type: i7.TranslatePipe, name: "translate" }, { kind: "directive", type: ButtonGroupDirective, selector: "[ngmButtonGroup]" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: CdkConfirmUniqueComponent, decorators: [{
            type: Component,
            args: [{ standalone: true, imports: [
                        CommonModule,
                        A11yModule,
                        FormsModule,
                        ReactiveFormsModule,
                        DragDropModule,
                        DialogModule,
                        MatButtonModule,
                        MatFormFieldModule,
                        MatInputModule,
                        TranslateModule,
                        ButtonGroupDirective
                    ], selector: 'cdk-confirm-unique', host: {
                        'class': 'cdk-dialog-card'
                    }, template: "<header cdkDrag cdkDragRootElement=\".cdk-overlay-pane\" cdkDragHandle class=\"pb-2 cursor-move\">\n  <h4 class=\"text-xl pointer-events-none\">\n    {{ title || ('COMPONENTS.CONFIRM.INPUT_UNIQUE_VALUE' | translate: {Default: 'Input Unique Value'}) }}\n  </h4>\n</header>\n\n<div class=\"mat-typography py-4\" cdkTrapFocus [cdkTrapFocusAutoCapture]=\"true\">\n  <form (ngSubmit)=\"onApply()\">\n    <mat-form-field appearance=\"fill\" class=\"w-full\">\n      <mat-label>{{ 'COMPONENTS.CONFIRM.NAME' | translate: {Default: 'Name'} }}</mat-label>\n      <input cdkFocusInitial matInput name=\"value\" [formControl]=\"value\" />\n      @if (invalid) {\n        <mat-error>\n          {{error || 'Error'}}\n        </mat-error>\n      }\n    </mat-form-field>\n  </form>\n</div>\n\n<div class=\"w-full flex justify-between items-center\">\n  <button mat-button (click)=\"reset()\">\n    {{ 'COMPONENTS.COMMON.RESET' | translate: {Default: 'Reset'} }}\n  </button>\n\n  <div ngmButtonGroup class=\"ml-8\">\n    <button mat-flat-button (click)=\"onCancel()\">\n      {{ 'COMPONENTS.COMMON.CANCEL' | translate: {Default: 'Cancel'} }}\n    </button>\n    <button mat-raised-button color=\"accent\"\n      [disabled]=\"invalid\"\n      cdkFocusInitial\n      (click)=\"onApply()\"\n    >\n      {{ 'COMPONENTS.COMMON.APPLY' | translate: {Default: 'Apply'} }}\n    </button>\n  </div>\n</div>\n" }]
        }], propDecorators: { isDialogContainer: [{
                type: HostBinding,
                args: ['class.ngm-dialog-container']
            }] } });
export function injectConfirmUnique() {
    const dialog = inject(Dialog);
    return (info, execution) => {
        return dialog.open(CdkConfirmUniqueComponent, {
            data: info
        }).closed.pipe(switchMap((value) => value ? execution(value) : EMPTY));
    };
}
//# sourceMappingURL=data:application/json;base64, 