import * as i0 from '@angular/core';
import { Component, ChangeDetectionStrategy, Optional, Inject, Input, NgModule } from '@angular/core';
import * as i2 from '@aztrix/components/avatar';
import { AvatarType, AvatarModule } from '@aztrix/components/avatar';
import * as i4 from '@aztrix/helpers';
import { displayName, isOrganisation, avatarUrl, getPropertyTuple, typeFilter, HelperPipesModule } from '@aztrix/helpers';
import { PropertyType, ProfileContext } from '@aztrix/models';
import { BASE_URL } from '@aztrix/sdk';
import { ReplaySubject } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i3 from '@aztrix/icons';
import { IconsModule } from '@aztrix/icons';

class ProfileCellComponent {
    constructor(baseUrl) {
        this.baseUrl = baseUrl;
        this.profile$ = new ReplaySubject(1);
        this.propertiesToShow = [PropertyType.REGION, PropertyType.PHONE, PropertyType.EMAIL];
        this.displayName = displayName;
        // eslint-disable-next-line @typescript-eslint/naming-convention
        this.AvatarType = AvatarType;
        // eslint-disable-next-line @typescript-eslint/naming-convention
        this.PropertyType = PropertyType;
        this.location$ = this.profile$.pipe(map((profile) => this._getProperty(profile, PropertyType.REGION) ||
            this._getProperty(profile, PropertyType.ADDRESS)), shareReplay(1));
        this.phone$ = this.profile$.pipe(map((profile) => this._getProperty(profile, PropertyType.PHONE) ||
            this._getProperty(profile, PropertyType.MOBILE_PHONE)));
        this.email$ = this.profile$.pipe(map((profile) => this._getProperty(profile, PropertyType.EMAIL)), shareReplay(1));
        this.legalid$ = this.profile$.pipe(map((profile) => isOrganisation(profile) ? this._getProperty(profile, PropertyType.LEGAL_ID) : null), shareReplay(1));
    }
    ngOnInit() {
        if (this.profile.profileContext === ProfileContext.ORGANISATION) {
            this.propertiesToShow.splice(1, 0, PropertyType.LEGAL_ID);
        }
        this.source = avatarUrl(this.profile);
    }
    ngOnChanges(changes) {
        if (changes.profile && this.profile) {
            this.profile$.next(this.profile);
        }
    }
    _getProperty(profile, propertyType) {
        const propertyTuple = getPropertyTuple(profile.propertyContexts, typeFilter(propertyType));
        return propertyTuple?.property ?? null;
    }
}
ProfileCellComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ProfileCellComponent, deps: [{ token: BASE_URL, optional: true }], target: i0.ɵɵFactoryTarget.Component });
ProfileCellComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.5", type: ProfileCellComponent, selector: "ax-profile-cell", inputs: { profile: "profile" }, usesOnChanges: true, ngImport: i0, template: "<a class=\"profile\" [attr.href]=\"baseUrl + '/profile/' + profile?.id\" target=\"_blank\">\n  <ax-avatar class=\"avatar\" [source]=\"source\"></ax-avatar>\n  <div class=\"properties-wrapper\">\n    <div class=\"name\">{{ profile | displayName }}</div>\n    <div class=\"properties\">\n      <div class=\"property\" *ngIf=\"propertiesToShow.includes(PropertyType.REGION)\">\n        <ng-container *ngIf=\"location$ | async | propertyHasValue\">\n          <ax-icon class=\"icon\" name=\"map-marker\"></ax-icon>\n          <span>{{ location$ | async | regionDisplay }}</span>\n        </ng-container>\n      </div>\n\n      <div class=\"property\" *ngIf=\"propertiesToShow.includes(PropertyType.LEGAL_ID)\">\n        <ng-container *ngIf=\"legalid$ | async | propertyHasValue\">\n          <ax-icon class=\"icon\" name=\"office-building\"></ax-icon>\n          <span>{{ legalid$ | async | propertyDisplayValue }}</span>\n        </ng-container>\n      </div>\n\n      <div class=\"property\" *ngIf=\"propertiesToShow.includes(PropertyType.PHONE)\">\n        <ng-container *ngIf=\"phone$ | async | propertyHasValue\">\n          <ax-icon\n            class=\"icon\"\n            [name]=\"(phone$ | async).type === PropertyType.PHONE ? 'phone' : 'cellphone'\"\n          ></ax-icon>\n          <span>{{ phone$ | async | propertyDisplayValue }}</span>\n        </ng-container>\n      </div>\n\n      <div class=\"property\" *ngIf=\"propertiesToShow.includes(PropertyType.EMAIL)\">\n        <ng-container *ngIf=\"email$ | async | propertyHasValue\">\n          <ax-icon class=\"icon\" name=\"email\"></ax-icon>\n          <span>{{ email$ | async | propertyDisplayValue }}</span>\n        </ng-container>\n      </div>\n    </div>\n  </div>\n</a>\n", styles: [".profile{display:grid;grid-column-gap:1rem;grid-template-columns:max-content auto;align-items:center;height:60px;padding:0 1rem;background-color:#fff}.profile,.profile:visited,.profile:hover{color:var(--primary-color-500)}.profile:active,.profile:focus{color:var(--primary-color-500)}.profile:hover{background-color:#f8f8f8}.avatar{width:40px;height:40px}.name{color:var(--font-color, #363f48)}.properties-wrapper{display:flex;flex-direction:column}.properties{display:grid;grid-template-columns:repeat(auto-fit,100%);height:15px;overflow-y:hidden;margin-top:4px}@media only screen and (min-width: 600px){.properties{grid-template-columns:repeat(auto-fill,minmax(auto,220px))}}.property{display:block;color:#7a8692;font-size:.75rem;font-weight:400;line-height:1;height:15px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%}.property .icon{margin-right:4px;vertical-align:middle;width:12px;height:12px}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.AvatarComponent, selector: "ax-avatar", inputs: ["source", "type", "icon", "iconColor", "badge", "badgeColor", "border", "round", "rounded", "published"] }, { kind: "component", type: i3.IconComponent, selector: "ax-icon", inputs: ["name", "inline"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }, { kind: "pipe", type: i4.PropertyDisplayValuePipe, name: "propertyDisplayValue" }, { kind: "pipe", type: i4.PropertyHasValuePipe, name: "propertyHasValue" }, { kind: "pipe", type: i4.RegionDisplayPipe, name: "regionDisplay" }, { kind: "pipe", type: i4.DisplayNamePipe, name: "displayName" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ProfileCellComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-profile-cell', changeDetection: ChangeDetectionStrategy.OnPush, template: "<a class=\"profile\" [attr.href]=\"baseUrl + '/profile/' + profile?.id\" target=\"_blank\">\n  <ax-avatar class=\"avatar\" [source]=\"source\"></ax-avatar>\n  <div class=\"properties-wrapper\">\n    <div class=\"name\">{{ profile | displayName }}</div>\n    <div class=\"properties\">\n      <div class=\"property\" *ngIf=\"propertiesToShow.includes(PropertyType.REGION)\">\n        <ng-container *ngIf=\"location$ | async | propertyHasValue\">\n          <ax-icon class=\"icon\" name=\"map-marker\"></ax-icon>\n          <span>{{ location$ | async | regionDisplay }}</span>\n        </ng-container>\n      </div>\n\n      <div class=\"property\" *ngIf=\"propertiesToShow.includes(PropertyType.LEGAL_ID)\">\n        <ng-container *ngIf=\"legalid$ | async | propertyHasValue\">\n          <ax-icon class=\"icon\" name=\"office-building\"></ax-icon>\n          <span>{{ legalid$ | async | propertyDisplayValue }}</span>\n        </ng-container>\n      </div>\n\n      <div class=\"property\" *ngIf=\"propertiesToShow.includes(PropertyType.PHONE)\">\n        <ng-container *ngIf=\"phone$ | async | propertyHasValue\">\n          <ax-icon\n            class=\"icon\"\n            [name]=\"(phone$ | async).type === PropertyType.PHONE ? 'phone' : 'cellphone'\"\n          ></ax-icon>\n          <span>{{ phone$ | async | propertyDisplayValue }}</span>\n        </ng-container>\n      </div>\n\n      <div class=\"property\" *ngIf=\"propertiesToShow.includes(PropertyType.EMAIL)\">\n        <ng-container *ngIf=\"email$ | async | propertyHasValue\">\n          <ax-icon class=\"icon\" name=\"email\"></ax-icon>\n          <span>{{ email$ | async | propertyDisplayValue }}</span>\n        </ng-container>\n      </div>\n    </div>\n  </div>\n</a>\n", styles: [".profile{display:grid;grid-column-gap:1rem;grid-template-columns:max-content auto;align-items:center;height:60px;padding:0 1rem;background-color:#fff}.profile,.profile:visited,.profile:hover{color:var(--primary-color-500)}.profile:active,.profile:focus{color:var(--primary-color-500)}.profile:hover{background-color:#f8f8f8}.avatar{width:40px;height:40px}.name{color:var(--font-color, #363f48)}.properties-wrapper{display:flex;flex-direction:column}.properties{display:grid;grid-template-columns:repeat(auto-fit,100%);height:15px;overflow-y:hidden;margin-top:4px}@media only screen and (min-width: 600px){.properties{grid-template-columns:repeat(auto-fill,minmax(auto,220px))}}.property{display:block;color:#7a8692;font-size:.75rem;font-weight:400;line-height:1;height:15px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%}.property .icon{margin-right:4px;vertical-align:middle;width:12px;height:12px}\n"] }]
        }], ctorParameters: function () { return [{ type: undefined, decorators: [{
                    type: Optional
                }, {
                    type: Inject,
                    args: [BASE_URL]
                }] }]; }, propDecorators: { profile: [{
                type: Input
            }] } });

class ProfileCellModule {
}
ProfileCellModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ProfileCellModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
ProfileCellModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.5", ngImport: i0, type: ProfileCellModule, declarations: [ProfileCellComponent], imports: [CommonModule, AvatarModule, IconsModule, HelperPipesModule], exports: [ProfileCellComponent] });
ProfileCellModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ProfileCellModule, imports: [CommonModule, AvatarModule, IconsModule, HelperPipesModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ProfileCellModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [ProfileCellComponent],
                    imports: [CommonModule, AvatarModule, IconsModule, HelperPipesModule],
                    exports: [ProfileCellComponent],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { ProfileCellComponent, ProfileCellModule };
//# sourceMappingURL=aztrix-components-profile-cell.mjs.map
//# sourceMappingURL=aztrix-components-profile-cell.mjs.map
