import * as i0 from '@angular/core';
import { Component, Optional, Inject, Input, NgModule } from '@angular/core';
import * as i1 from '@aztrix/helpers';
import { displayName, avatarUrl, HelperPipesModule } from '@aztrix/helpers';
import { BASE_URL } from '@aztrix/sdk';
import { ReplaySubject } from 'rxjs';
import { filter, map, distinctUntilChanged, mergeMap } from 'rxjs/operators';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i3 from '@aztrix/components/chip';
import { ChipModule } from '@aztrix/components/chip';
import { RouterModule } from '@angular/router';
import { ImageSourceModule } from '@aztrix/components/image-source';
import { IconsModule } from '@aztrix/icons';

class ProposalHeaderComponent {
    constructor(_http, baseUrl) {
        this._http = _http;
        this.baseUrl = baseUrl;
        this.displayName = displayName;
        this.avatarUrl = avatarUrl;
        this.useRouterLink = window.location.origin.includes(this.baseUrl);
        this._proposal$ = new ReplaySubject(1);
        this._ownerId$ = this._proposal$.pipe(filter((proposal) => !!(proposal === null || proposal === void 0 ? void 0 : proposal.id)), map((proposal) => {
            return proposal.ownerId;
        }), distinctUntilChanged());
        this.owner$ = this._ownerId$.pipe(mergeMap((ownerId) => {
            return this.getProfile(ownerId);
        }));
    }
    ngOnChanges(changes) {
        if (this.proposal && changes.proposal) {
            this._proposal$.next(this.proposal);
        }
    }
    getProfile(profileId) {
        return this._http.get(`${this.baseUrl || ''}/r/profiles/${profileId}`);
    }
}
ProposalHeaderComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ProposalHeaderComponent, deps: [{ token: i1.HttpClientService }, { token: BASE_URL, optional: true }], target: i0.ɵɵFactoryTarget.Component });
ProposalHeaderComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.5", type: ProposalHeaderComponent, selector: "ax-proposal-header", inputs: { proposal: "proposal", language: "language" }, usesOnChanges: true, ngImport: i0, template: "<div class=\"header\">\n  <div></div>\n  <h2 class=\"name proposal\">{{ language?.name }}</h2>\n  <ng-content></ng-content>\n</div>\n\n<p axChip color=\"warning\" *ngIf=\"proposal?.retentionDuration\" class=\"retention-duration\">\n  {{ 'proposal.retentionDuration.value' | translate: {days: proposal.retentionDuration} }}\n</p>\n\n<p class=\"description\">{{ language?.description }}</p>\n", styles: [":host{position:relative}:host,.proposal{display:flex;flex-direction:column}.header{display:grid;grid-template-columns:34px 1fr 34px}.proposal{color:var(--font-color, #2b323a);align-items:center;text-align:center}.name{font-size:1.5rem;margin:1rem 0 .5rem}.description{padding:1rem;margin:0}.retention-duration{font-size:13px;margin:0 auto}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.ChipDirective, selector: "[axChip]", inputs: ["color"] }, { kind: "pipe", type: i1.TranslatePipe, name: "translate" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: ProposalHeaderComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-proposal-header', template: "<div class=\"header\">\n  <div></div>\n  <h2 class=\"name proposal\">{{ language?.name }}</h2>\n  <ng-content></ng-content>\n</div>\n\n<p axChip color=\"warning\" *ngIf=\"proposal?.retentionDuration\" class=\"retention-duration\">\n  {{ 'proposal.retentionDuration.value' | translate: {days: proposal.retentionDuration} }}\n</p>\n\n<p class=\"description\">{{ language?.description }}</p>\n", styles: [":host{position:relative}:host,.proposal{display:flex;flex-direction:column}.header{display:grid;grid-template-columns:34px 1fr 34px}.proposal{color:var(--font-color, #2b323a);align-items:center;text-align:center}.name{font-size:1.5rem;margin:1rem 0 .5rem}.description{padding:1rem;margin:0}.retention-duration{font-size:13px;margin:0 auto}\n"] }]
        }], ctorParameters: function () {
        return [{ type: i1.HttpClientService }, { type: undefined, decorators: [{
                        type: Optional
                    }, {
                        type: Inject,
                        args: [BASE_URL]
                    }] }];
    }, propDecorators: { proposal: [{
                type: Input
            }], language: [{
                type: Input
            }] } });

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

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

export { ProposalHeaderComponent, ProposalHeaderModule };
//# sourceMappingURL=aztrix-components-proposal-header.mjs.map
//# sourceMappingURL=aztrix-components-proposal-header.mjs.map
