import { Component, HostBinding, Input, ViewChild, } from '@angular/core';
import { hasEqualValue, hasValue, unique } from '@aztrix/helpers';
import { PropertyType } from '@aztrix/models';
import { combineLatest, ReplaySubject, Subscription } from 'rxjs';
import { startWith } from 'rxjs/operators';
import { AbstractPropertyEdit } from '../abstract-property-edit';
import { EditAutocompletionComponent } from '../autocompletion/edit-autocompletion/edit-autocompletion.component';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "../opening-hours-edit/opening-hours-edit.component";
import * as i3 from "../date-property-edit/date-property-edit.component";
import * as i4 from "../category-edit/category-edit.component";
import * as i5 from "../address-edit/address-edit.component";
import * as i6 from "../country-edit/country-edit.component";
import * as i7 from "../default-edit/default-edit.component";
import * as i8 from "../gender-edit/gender-edit.component";
import * as i9 from "../file-edit/file-edit.component";
import * as i10 from "../image-edit/image-edit.component";
import * as i11 from "../social-edit/social-edit.component";
import * as i12 from "../legalid-edit/legalid-edit.component";
import * as i13 from "../avatar-property-edit/avatar-property-edit.component";
import * as i14 from "../name-edit/name-edit.component";
import * as i15 from "../organisation-type-edit/organisation-type-edit.component";
import * as i16 from "../autocompletion/edit-autocompletion/edit-autocompletion.component";
import * as i17 from "../document-edit/document-edit.component";
import * as i18 from "@aztrix/helpers";
export class PropertyEditComponent extends AbstractPropertyEdit {
    constructor() {
        super(...arguments);
        this.isIndividual = false;
        this.isProposalSubscribeForm = false;
        this.formSubscription = new Subscription();
        this.autocompleteComponent$ = new ReplaySubject(1);
        this.autocompleteProperties$ = new ReplaySubject(1);
    }
    get showIconClass() {
        return this.showIcon;
    }
    ngOnChanges(changes) {
        if (changes.autocompleteProperties && this.autocompleteProperties) {
            this.autocompleteProperties$.next(this.autocompleteProperties);
        }
        if (changes.form && this.form) {
            this.formSubscription.unsubscribe();
            this.formSubscription = combineLatest([
                this.autocompleteProperties$,
                this.form.valueChanges.pipe(startWith(this.form.value)),
                this.autocompleteComponent$,
            ]).subscribe(([autocompleteProperties, property, autocompleteComponent]) => {
                if (autocompleteProperties && property && autocompleteComponent) {
                    autocompleteProperties = this._removeDuplicateAutoCompleteValues(autocompleteProperties);
                    autocompleteComponent.autocomplete(autocompleteProperties.filter((p) => {
                        if (p.type === PropertyType.LEGAL_ID) {
                            return !hasEqualValue(p.properties?.find((pr) => pr.type === PropertyType.COMPANY_NUMBER), property.properties.find((pr) => pr.type === PropertyType.COMPANY_NUMBER));
                        }
                        else {
                            return !hasEqualValue(p, property);
                        }
                    }));
                }
            });
        }
    }
    _removeDuplicateAutoCompleteValues(properties) {
        const uniqueProperties = [];
        for (const prop of properties) {
            if (prop && hasValue(prop) && !uniqueProperties.find((p) => hasEqualValue(p, prop))) {
                uniqueProperties.push(prop);
            }
        }
        return unique(uniqueProperties);
    }
    ngAfterViewInit() {
        this.autocompleteComponent$.next(this.autocompleteComponent);
    }
    ngOnDestroy() {
        super.ngOnDestroy();
        this.formSubscription.unsubscribe();
    }
    get property() {
        return this.form?.getRawValue();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: PropertyEditComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: PropertyEditComponent, selector: "ax-property-edit", inputs: { isIndividual: "isIndividual", isProposalSubscribeForm: "isProposalSubscribeForm" }, host: { properties: { "class.showIcon": "this.showIconClass" } }, viewQueries: [{ propertyName: "autocompleteComponent", first: true, predicate: EditAutocompletionComponent, descendants: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "<ng-container [ngSwitch]=\"true\">\n  <ax-address-edit\n    *ngSwitchCase=\"property | propertyIsAddressRelated\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [autocompleteProperties]=\"autocompleteProperties\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-address-edit>\n  <ax-gender-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.GENDER\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n  ></ax-gender-edit>\n  <ax-social-edit\n    *ngSwitchCase=\"property | propertyIsSocialRelated\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [required]=\"required\"\n    [matAutocomplete]=\"auto.matAutocomplete\"\n    [autocompleteAttr]=\"autocompleteAttr\"\n    [autocompleteProperties]=\"autocompleteProperties\"\n    [autocomplete]=\"autocomplete\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-social-edit>\n  <ax-legalid-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.LEGAL_ID\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [matAutocomplete]=\"auto.matAutocomplete\"\n    [autocompleteAttr]=\"autocompleteAttr\"\n    [autocompleteProperties]=\"autocompleteProperties\"\n    [autocomplete]=\"autocomplete\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-legalid-edit>\n  <ax-date-property-edit\n    *ngSwitchCase=\"property | propertyIsDateRelated\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-date-property-edit>\n  <ax-avatar-property-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.AVATAR\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [hint]=\"hint\"\n    [isIndividual]=\"isIndividual\"\n    [readonly]=\"readonly\"\n  ></ax-avatar-property-edit>\n  <ax-opening-hours-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.OPENING_HOURS\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [isProposalSubscribeForm]=\"isProposalSubscribeForm\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n  ></ax-opening-hours-edit>\n  <ax-file-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.FILE\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-file-edit>\n  <ax-document-edit\n    *ngSwitchCase=\"property | propertyIsDocumentRelated\"\n    [form]=\"form\"\n    [showIcon]=\"showIcon\"\n    [required]=\"required\"\n    [readonly]=\"readonly\"\n  ></ax-document-edit>\n  <ax-image-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.IMAGE\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-image-edit>\n  <ax-category-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.CATEGORY\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-category-edit>\n  <ax-organisation-type-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.ORGANISATION_TYPE\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n  ></ax-organisation-type-edit>\n  <ax-name-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.NAME\"\n    [form]=\"form.get('properties')\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [readonly]=\"readonly\"\n  ></ax-name-edit>\n  <ax-country-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.COUNTRY\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n  ></ax-country-edit>\n  <ax-default-edit\n    *ngSwitchDefault\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [matAutocomplete]=\"auto.matAutocomplete\"\n    [autocompleteAttr]=\"autocompleteAttr\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [autocompleteProperties]=\"autocompleteProperties\"\n    [prefix]=\"prefix\"\n    [postfix]=\"postfix\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n    [icon]=\"icon\"\n  ></ax-default-edit>\n</ng-container>\n\n<ax-edit-autocompletion #auto [disabled]=\"!autocomplete\"></ax-edit-autocompletion>\n", dependencies: [{ kind: "directive", type: i1.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i1.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i1.NgSwitchDefault, selector: "[ngSwitchDefault]" }, { kind: "component", type: i2.OpeningHoursEditComponent, selector: "ax-opening-hours-edit", inputs: ["isProposalSubscribeForm"] }, { kind: "component", type: i3.DatePropertyEditComponent, selector: "ax-date-property-edit", inputs: ["minDate", "maxDate"] }, { kind: "component", type: i4.CategoryEditComponent, selector: "ax-category-edit" }, { kind: "component", type: i5.AddressEditComponent, selector: "ax-address-edit" }, { kind: "component", type: i6.CountryEditComponent, selector: "ax-country-edit", inputs: ["countryCodes"], outputs: ["countryUpdated"] }, { kind: "component", type: i7.DefaultEditComponent, selector: "ax-default-edit", inputs: ["placeholder", "matAutocomplete"], outputs: ["focused"] }, { kind: "component", type: i8.GenderEditComponent, selector: "ax-gender-edit" }, { kind: "component", type: i9.FileEditComponent, selector: "ax-file-edit", inputs: ["acceptTypes", "maxFileSize", "uploadLink", "preview", "previewUrl", "demo"] }, { kind: "component", type: i10.ImageEditComponent, selector: "ax-image-edit", inputs: ["acceptTypes", "maxFileSize", "uploadLink", "demo", "preview", "previewUrl"] }, { kind: "component", type: i11.SocialEditComponent, selector: "ax-social-edit", inputs: ["matAutocomplete"] }, { kind: "component", type: i12.LegalIdEditComponent, selector: "ax-legalid-edit", inputs: ["matAutocomplete"] }, { kind: "component", type: i13.AvatarPropertyEditComponent, selector: "ax-avatar-property-edit", inputs: ["isIndividual"] }, { kind: "component", type: i14.NameEditComponent, selector: "ax-name-edit", inputs: ["form", "name", "autofocus", "customLabel", "required", "expanded", "hint", "readonly"] }, { kind: "component", type: i15.OrganisationTypeEditComponent, selector: "ax-organisation-type-edit" }, { kind: "component", type: i16.EditAutocompletionComponent, selector: "ax-edit-autocompletion" }, { kind: "component", type: i17.DocumentEditComponent, selector: "ax-document-edit" }, { kind: "pipe", type: i18.IsOfTypePipe, name: "isOfType" }, { kind: "pipe", type: i18.PropertyIsAddressRelatedPipe, name: "propertyIsAddressRelated" }, { kind: "pipe", type: i18.PropertyIsDocumentRelatedPipe, name: "propertyIsDocumentRelated" }, { kind: "pipe", type: i18.PropertyIsSocialRelatedPipe, name: "propertyIsSocialRelated" }, { kind: "pipe", type: i18.PropertyIsDateRelatedPipe, name: "propertyIsDateRelated" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: PropertyEditComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-property-edit', template: "<ng-container [ngSwitch]=\"true\">\n  <ax-address-edit\n    *ngSwitchCase=\"property | propertyIsAddressRelated\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [autocompleteProperties]=\"autocompleteProperties\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-address-edit>\n  <ax-gender-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.GENDER\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n  ></ax-gender-edit>\n  <ax-social-edit\n    *ngSwitchCase=\"property | propertyIsSocialRelated\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [required]=\"required\"\n    [matAutocomplete]=\"auto.matAutocomplete\"\n    [autocompleteAttr]=\"autocompleteAttr\"\n    [autocompleteProperties]=\"autocompleteProperties\"\n    [autocomplete]=\"autocomplete\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-social-edit>\n  <ax-legalid-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.LEGAL_ID\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [matAutocomplete]=\"auto.matAutocomplete\"\n    [autocompleteAttr]=\"autocompleteAttr\"\n    [autocompleteProperties]=\"autocompleteProperties\"\n    [autocomplete]=\"autocomplete\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-legalid-edit>\n  <ax-date-property-edit\n    *ngSwitchCase=\"property | propertyIsDateRelated\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [readonly]=\"readonly\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-date-property-edit>\n  <ax-avatar-property-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.AVATAR\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [hint]=\"hint\"\n    [isIndividual]=\"isIndividual\"\n    [readonly]=\"readonly\"\n  ></ax-avatar-property-edit>\n  <ax-opening-hours-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.OPENING_HOURS\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [isProposalSubscribeForm]=\"isProposalSubscribeForm\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n  ></ax-opening-hours-edit>\n  <ax-file-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.FILE\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-file-edit>\n  <ax-document-edit\n    *ngSwitchCase=\"property | propertyIsDocumentRelated\"\n    [form]=\"form\"\n    [showIcon]=\"showIcon\"\n    [required]=\"required\"\n    [readonly]=\"readonly\"\n  ></ax-document-edit>\n  <ax-image-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.IMAGE\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-image-edit>\n  <ax-category-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.CATEGORY\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n    [subscriptSizing]=\"subscriptSizing\"\n  ></ax-category-edit>\n  <ax-organisation-type-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.ORGANISATION_TYPE\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n  ></ax-organisation-type-edit>\n  <ax-name-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.NAME\"\n    [form]=\"form.get('properties')\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [readonly]=\"readonly\"\n  ></ax-name-edit>\n  <ax-country-edit\n    *ngSwitchCase=\"property | isOfType: PropertyType.COUNTRY\"\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [showIcon]=\"showIcon\"\n    [readonly]=\"readonly\"\n  ></ax-country-edit>\n  <ax-default-edit\n    *ngSwitchDefault\n    [form]=\"form\"\n    [name]=\"name\"\n    [hint]=\"hint\"\n    [autofocus]=\"autofocus\"\n    [customLabel]=\"customLabel\"\n    [required]=\"required\"\n    [matAutocomplete]=\"auto.matAutocomplete\"\n    [autocompleteAttr]=\"autocompleteAttr\"\n    [showIcon]=\"showIcon\"\n    [showErrors]=\"showErrors\"\n    [autocompleteProperties]=\"autocompleteProperties\"\n    [prefix]=\"prefix\"\n    [postfix]=\"postfix\"\n    [readonly]=\"readonly\"\n    [enableValidation]=\"enableValidation\"\n    [icon]=\"icon\"\n  ></ax-default-edit>\n</ng-container>\n\n<ax-edit-autocompletion #auto [disabled]=\"!autocomplete\"></ax-edit-autocompletion>\n" }]
        }], propDecorators: { isIndividual: [{
                type: Input
            }], showIconClass: [{
                type: HostBinding,
                args: ['class.showIcon']
            }], autocompleteComponent: [{
                type: ViewChild,
                args: [EditAutocompletionComponent]
            }], isProposalSubscribeForm: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 