import { Component } from '@angular/core';
import { ReplaySubject } from 'rxjs';
import { mergeMap, shareReplay, startWith } from 'rxjs/operators';
import { ValueEdit } from '../../value-edit';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/material/legacy-form-field";
import * as i3 from "@aztrix/icons";
import * as i4 from "@angular/material/legacy-slide-toggle";
import * as i5 from "@aztrix/components/property-published-button";
import * as i6 from "@aztrix/helpers";
export class BooleanEditComponent extends ValueEdit {
    constructor() {
        super(...arguments);
        this.checked = false;
        this._form$ = new ReplaySubject(1);
        this._formValueChanges$ = this._form$.pipe(mergeMap((form) => form.valueChanges.pipe(startWith(form.value))), shareReplay(1));
    }
    ngOnInit() {
        this._subscriptions.add(this._formValueChanges$.subscribe((value) => {
            this.checked = value === 'true';
        }));
    }
    ngOnChanges(changes) {
        super.ngOnChanges(changes);
        if (changes.form && this.form) {
            this._form$.next(this.form);
        }
    }
    changed(event) {
        this.form.setValue(event.checked ? 'true' : 'false');
    }
}
BooleanEditComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: BooleanEditComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
BooleanEditComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.5", type: BooleanEditComponent, selector: "ax-boolean-edit", usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "<ax-icon *ngIf=\"icon\" class=\"icon type-icon\" [name]=\"icon\"></ax-icon>\n\n<mat-slide-toggle\n  color=\"primary\"\n  [name]=\"getName()\"\n  [checked]=\"checked\"\n  (change)=\"changed($event)\"\n  [disabled]=\"form?.disabled\"\n>\n  {{ label | translate }}\n</mat-slide-toggle>\n<mat-hint\n  [ngClass]=\"{collapsed}\"\n  (click)=\"collapsed = !collapsed\"\n  class=\"hint collapsible\"\n  align=\"end\"\n  #hintElement\n>\n  <div><ax-icon *ngIf=\"isOverflowing()\" class=\"icon\" name=\"chevron-down\"></ax-icon></div>\n  <span [ngClass]=\"{overflowing: isOverflowing()}\">{{ hint }}</span>\n</mat-hint>\n<mat-error *ngIf=\"errorsTemplate\">\n  <ng-template [ngTemplateOutlet]=\"errorsTemplate\"></ng-template>\n</mat-error>\n<ax-property-published-button *ngIf=\"published\"></ax-property-published-button>\n", styles: [":host{display:block;position:relative}.hint{grid-column:1/3;font-size:75%;padding:0 1em}\n", ":host .type-icon{display:none}:host.showIcon{display:grid;grid-template-columns:38px 1fr}:host.showIcon .type-icon{display:inline}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i2.MatLegacyError, selector: "mat-error", inputs: ["id"] }, { kind: "directive", type: i2.MatLegacyHint, selector: "mat-hint", inputs: ["align", "id"] }, { kind: "component", type: i3.IconComponent, selector: "ax-icon", inputs: ["name", "inline"] }, { kind: "component", type: i4.MatLegacySlideToggle, selector: "mat-slide-toggle", inputs: ["disabled", "disableRipple", "color", "tabIndex"], exportAs: ["matSlideToggle"] }, { kind: "component", type: i5.PropertyPublishedButtonComponent, selector: "ax-property-published-button" }, { kind: "pipe", type: i6.TranslatePipe, name: "translate" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: BooleanEditComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-boolean-edit', template: "<ax-icon *ngIf=\"icon\" class=\"icon type-icon\" [name]=\"icon\"></ax-icon>\n\n<mat-slide-toggle\n  color=\"primary\"\n  [name]=\"getName()\"\n  [checked]=\"checked\"\n  (change)=\"changed($event)\"\n  [disabled]=\"form?.disabled\"\n>\n  {{ label | translate }}\n</mat-slide-toggle>\n<mat-hint\n  [ngClass]=\"{collapsed}\"\n  (click)=\"collapsed = !collapsed\"\n  class=\"hint collapsible\"\n  align=\"end\"\n  #hintElement\n>\n  <div><ax-icon *ngIf=\"isOverflowing()\" class=\"icon\" name=\"chevron-down\"></ax-icon></div>\n  <span [ngClass]=\"{overflowing: isOverflowing()}\">{{ hint }}</span>\n</mat-hint>\n<mat-error *ngIf=\"errorsTemplate\">\n  <ng-template [ngTemplateOutlet]=\"errorsTemplate\"></ng-template>\n</mat-error>\n<ax-property-published-button *ngIf=\"published\"></ax-property-published-button>\n", styles: [":host{display:block;position:relative}.hint{grid-column:1/3;font-size:75%;padding:0 1em}\n", ":host .type-icon{display:none}:host.showIcon{display:grid;grid-template-columns:38px 1fr}:host.showIcon .type-icon{display:inline}\n"] }]
        }] });
//# sourceMappingURL=data:application/json;base64, 