import { ChangeDetectionStrategy, Component, EventEmitter, Output } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "@vendure/admin-ui/core";
import * as i3 from "@angular/common";
import * as i4 from "@ngx-translate/core";
export class TestAddressFormComponent {
    constructor(formBuilder, dataService, localStorageService) {
        this.formBuilder = formBuilder;
        this.dataService = dataService;
        this.localStorageService = localStorageService;
        this.addressChange = new EventEmitter();
    }
    ngOnInit() {
        this.availableCountries$ = this.dataService.settings
            .getAvailableCountries()
            .mapSingle(result => result.countries.items);
        const storedValue = this.localStorageService.getForCurrentLocation('shippingTestAddress');
        const initialValue = storedValue
            ? storedValue
            : {
                city: '',
                countryCode: '',
                postalCode: '',
                province: '',
            };
        this.addressChange.emit(initialValue);
        this.form = this.formBuilder.group(initialValue);
        this.subscription = this.form.valueChanges.subscribe(value => {
            this.localStorageService.setForCurrentLocation('shippingTestAddress', value);
            this.addressChange.emit(value);
        });
    }
    ngOnDestroy() {
        if (this.subscription) {
            this.subscription.unsubscribe();
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: TestAddressFormComponent, deps: [{ token: i1.UntypedFormBuilder }, { token: i2.DataService }, { token: i2.LocalStorageService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.2", type: TestAddressFormComponent, selector: "vdr-test-address-form", outputs: { addressChange: "addressChange" }, ngImport: i0, template: "<div class=\"card\">\n    <div class=\"card-header\">\n        {{ 'settings.test-address' | translate }}\n    </div>\n    <div class=\"card-block\">\n        <form [formGroup]=\"form\" class=\"form-grid\">\n            <vdr-form-field [label]=\"'customer.city' | translate\">\n                <input formControlName=\"city\" type=\"text\"  />\n            </vdr-form-field>\n            <vdr-form-field [label]=\"'customer.province' | translate\">\n                <input formControlName=\"province\" type=\"text\"  />\n            </vdr-form-field>\n            <vdr-form-field [label]=\"'customer.postal-code' | translate\">\n                <input formControlName=\"postalCode\" type=\"text\"  />\n            </vdr-form-field>\n            <vdr-form-field [label]=\"'customer.country' | translate\">\n                <select name=\"countryCode\" formControlName=\"countryCode\" >\n                    <option *ngFor=\"let country of availableCountries$ | async\" [value]=\"country.code\">\n                        {{ country.name }}\n                    </option>\n                </select>\n            </vdr-form-field>\n        </form>\n    </div>\n</div>\n", styles: [":host{display:block}clr-input-container{margin-bottom:12px}\n"], dependencies: [{ kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgSelectOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i1.ɵNgSelectMultipleOption, selector: "option", inputs: ["ngValue", "value"] }, { kind: "directive", type: i1.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: i1.SelectControlValueAccessor, selector: "select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]", inputs: ["compareWith"] }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: i2.FormFieldComponent, selector: "vdr-form-field", inputs: ["label", "for", "tooltip", "errors", "readOnlyToggle"] }, { kind: "directive", type: i2.FormFieldControlDirective, selector: "input, textarea, select" }, { kind: "pipe", type: i3.AsyncPipe, name: "async" }, { kind: "pipe", type: i4.TranslatePipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.2", ngImport: i0, type: TestAddressFormComponent, decorators: [{
            type: Component,
            args: [{ selector: 'vdr-test-address-form', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div class=\"card\">\n    <div class=\"card-header\">\n        {{ 'settings.test-address' | translate }}\n    </div>\n    <div class=\"card-block\">\n        <form [formGroup]=\"form\" class=\"form-grid\">\n            <vdr-form-field [label]=\"'customer.city' | translate\">\n                <input formControlName=\"city\" type=\"text\"  />\n            </vdr-form-field>\n            <vdr-form-field [label]=\"'customer.province' | translate\">\n                <input formControlName=\"province\" type=\"text\"  />\n            </vdr-form-field>\n            <vdr-form-field [label]=\"'customer.postal-code' | translate\">\n                <input formControlName=\"postalCode\" type=\"text\"  />\n            </vdr-form-field>\n            <vdr-form-field [label]=\"'customer.country' | translate\">\n                <select name=\"countryCode\" formControlName=\"countryCode\" >\n                    <option *ngFor=\"let country of availableCountries$ | async\" [value]=\"country.code\">\n                        {{ country.name }}\n                    </option>\n                </select>\n            </vdr-form-field>\n        </form>\n    </div>\n</div>\n", styles: [":host{display:block}clr-input-container{margin-bottom:12px}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.UntypedFormBuilder }, { type: i2.DataService }, { type: i2.LocalStorageService }]; }, propDecorators: { addressChange: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 