import { Component, Input } from '@angular/core';
import { finalize, first } from 'rxjs/operators';
import { marked } from 'marked';
import * as i0 from "@angular/core";
import * as i1 from "@angular/cdk/clipboard";
import * as i2 from "@seniorsistemas/angular-components/toast";
import * as i3 from "@ngx-translate/core";
import * as i4 from "@angular/common";
import * as i5 from "@seniorsistemas/angular-components/badge";
import * as i6 from "./components/ia-insight-card-loader/ia-insight-card-loader.component";
export class IAInsightCardComponent {
    clipboard;
    toastService;
    translateService;
    insight;
    open = false;
    isLoading = false;
    content;
    likeSelected = false;
    dislikeSelected = false;
    constructor(clipboard, toastService, translateService) {
        this.clipboard = clipboard;
        this.toastService = toastService;
        this.translateService = translateService;
    }
    toggle() {
        const newOpenState = !this.open;
        this.open = newOpenState;
        if (newOpenState === true && this.insight.onOpenSidebar) {
            this.insight.onOpenSidebar();
        }
        else if (newOpenState === false && this.insight.onCloseSideBar) {
            this.insight.onCloseSideBar();
        }
        if (newOpenState === true) {
            this._requestInsight();
        }
    }
    onLikeSelected() {
        if (this.likeSelected) {
            this.likeSelected = false;
        }
        else {
            this.likeSelected = true;
            this.dislikeSelected = false;
            this.insight.onLikeSelected?.();
        }
    }
    onDislikeSelected() {
        if (this.dislikeSelected) {
            this.dislikeSelected = false;
        }
        else {
            this.dislikeSelected = true;
            this.likeSelected = false;
            this.insight.onDislikeSelected?.();
        }
    }
    copyContent() {
        if (!this.content)
            return;
        this.insight.onCopy?.(this.content);
        if (this.clipboard.copy(this.content)) {
            this.toastService.show({
                severity: 'info',
                title: this.translateService.instant('platform.angular_components.copied_to_clipboard'),
            });
        }
    }
    reloadContent() {
        this._requestInsight();
    }
    _requestInsight() {
        this.isLoading = true;
        this.insight.request$
            .pipe(first(), finalize(() => (this.isLoading = false)))
            .subscribe(async (content) => {
            this.content = await marked(content);
            if (this.insight.onContentLoaded) {
                this.insight.onContentLoaded();
            }
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: IAInsightCardComponent, deps: [{ token: i1.Clipboard }, { token: i2.ToastService }, { token: i3.TranslateService }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: IAInsightCardComponent, selector: "s-ia-insight-card", inputs: { insight: "insight" }, ngImport: i0, template: "<div\n    class=\"ia-insight-card\"\n    [ngClass]=\"{ 'ia-insight-card--close': !open }\"\n>\n    <div\n        class=\"header\"\n        (click)=\"toggle()\"\n    >\n        <s-badge\n            text=\"Insight\"\n            iconClass=\"fal fa-lightbulb\"\n        ></s-badge>\n        <span class=\"insight-title\">{{ insight.title }}</span>\n        <span class=\"toggle-icon\">\n            <i\n                class=\"fas\"\n                [ngClass]=\"{\n                    'fa-angle-down': !open,\n                    'fa-angle-up': open,\n                }\"\n            >\n            </i>\n        </span>\n    </div>\n    <div class=\"content\">\n        <ng-container *ngIf=\"isLoading; then loadingBlock; else contentBlock\"></ng-container>\n        <ng-template #loadingBlock>\n            <s-ia-insight-card-loader></s-ia-insight-card-loader>\n        </ng-template>\n        <ng-template #contentBlock>\n            <ng-container *ngIf=\"content; then successBlock; else errorBlock\"></ng-container>\n\n            <ng-template #successBlock>\n                <span\n                    class=\"text\"\n                    [innerHTML]=\"content\"\n                ></span>\n                <span class=\"insight-footer\">{{ \"platform.angular_components.insight_footer\" | translate }}</span>\n\n            </ng-template>\n            <ng-template #errorBlock>\n                <span class=\"text text--error\">{{\n                    'platform.angular_components.error_loading_insight_alt' | translate\n                }}</span>\n            </ng-template>\n\n            <div class=\"options\">\n                <button\n                    [disabled]=\"!content\"\n                    (click)=\"copyContent()\"\n                    class=\"option\"\n                >\n                    <i class=\"fal fa-copy\"></i>\n                </button>\n                <button\n                    (click)=\"reloadContent()\"\n                    class=\"option\"\n                >\n                    <i class=\"fal fa-redo\"></i>\n                </button>\n                <button\n                    *ngIf=\"insight.onLikeSelected\"\n                    [disabled]=\"!content\"\n                    (click)=\"onLikeSelected()\"\n                    class=\"option\"\n                >\n                    <i\n                        [ngClass]=\"{\n                            fal: !likeSelected,\n                            fas: likeSelected,\n                            'fa-thumbs-up': true,\n                        }\"\n                    >\n                    </i>\n                </button>\n                <button\n                    *ngIf=\"insight.onDislikeSelected\"\n                    [disabled]=\"!content\"\n                    (click)=\"onDislikeSelected()\"\n                    class=\"option\"\n                >\n                    <i\n                        [ngClass]=\"{\n                            fal: !dislikeSelected,\n                            fas: dislikeSelected,\n                            'fa-thumbs-down': true,\n                        }\"\n                    ></i>\n                </button>\n            </div>\n        </ng-template>\n    </div>\n</div>\n", styles: [".ia-insight-card{background-color:#fff;border:1px solid #9ecad4;border-radius:4px;cursor:pointer;display:flex;flex-direction:column;overflow:hidden}.ia-insight-card .header{align-items:center;background-color:#f1f7f8;border-bottom:1px solid #9ecad4;display:flex;gap:8px;min-height:60px;padding:8px 16px;-webkit-user-select:none;user-select:none}.ia-insight-card .header .insight-title{color:#428bca;flex-grow:1;font-family:Open Sans,sans-serif;font-size:14px;line-height:150%}.ia-insight-card .header .toggle-icon{color:#888b99;font-size:20px}.ia-insight-card .content{align-items:center;justify-content:space-between;cursor:auto;display:flex;flex-direction:column;gap:16px;min-height:160px;padding:24px}.ia-insight-card .content .text{color:#212533;font-family:Open Sans,sans-serif;font-size:14px;width:100%}.ia-insight-card .content .text--error{text-align:center}.ia-insight-card .content .insight-footer{color:#888b99;font-family:Open Sans,sans-serif;font-size:12px;text-align:center}.ia-insight-card .content .options{display:flex;gap:8px}.ia-insight-card .content .options .option{background-color:transparent;border:none;color:#428bca;cursor:pointer;font-size:12px}.ia-insight-card .content .options .option:disabled{color:#c1c1cc;cursor:auto}.ia-insight-card--close{border-color:#dedce5}.ia-insight-card--close .header{background-color:#fbfafc;border:none;border-color:#dedce5}.ia-insight-card--close .header .insight-title{color:#888b99}.ia-insight-card--close .content{display:none}\n"], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i5.BadgeComponent, selector: "s-badge", inputs: ["type", "color", "title", "text", "selectable", "iconClass", "iconPosition", "infoSign", "enableTruncateText"], outputs: ["selected"] }, { kind: "component", type: i6.IAInsightCardLoaderComponent, selector: "s-ia-insight-card-loader" }, { kind: "pipe", type: i3.TranslatePipe, name: "translate" }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: IAInsightCardComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-ia-insight-card', template: "<div\n    class=\"ia-insight-card\"\n    [ngClass]=\"{ 'ia-insight-card--close': !open }\"\n>\n    <div\n        class=\"header\"\n        (click)=\"toggle()\"\n    >\n        <s-badge\n            text=\"Insight\"\n            iconClass=\"fal fa-lightbulb\"\n        ></s-badge>\n        <span class=\"insight-title\">{{ insight.title }}</span>\n        <span class=\"toggle-icon\">\n            <i\n                class=\"fas\"\n                [ngClass]=\"{\n                    'fa-angle-down': !open,\n                    'fa-angle-up': open,\n                }\"\n            >\n            </i>\n        </span>\n    </div>\n    <div class=\"content\">\n        <ng-container *ngIf=\"isLoading; then loadingBlock; else contentBlock\"></ng-container>\n        <ng-template #loadingBlock>\n            <s-ia-insight-card-loader></s-ia-insight-card-loader>\n        </ng-template>\n        <ng-template #contentBlock>\n            <ng-container *ngIf=\"content; then successBlock; else errorBlock\"></ng-container>\n\n            <ng-template #successBlock>\n                <span\n                    class=\"text\"\n                    [innerHTML]=\"content\"\n                ></span>\n                <span class=\"insight-footer\">{{ \"platform.angular_components.insight_footer\" | translate }}</span>\n\n            </ng-template>\n            <ng-template #errorBlock>\n                <span class=\"text text--error\">{{\n                    'platform.angular_components.error_loading_insight_alt' | translate\n                }}</span>\n            </ng-template>\n\n            <div class=\"options\">\n                <button\n                    [disabled]=\"!content\"\n                    (click)=\"copyContent()\"\n                    class=\"option\"\n                >\n                    <i class=\"fal fa-copy\"></i>\n                </button>\n                <button\n                    (click)=\"reloadContent()\"\n                    class=\"option\"\n                >\n                    <i class=\"fal fa-redo\"></i>\n                </button>\n                <button\n                    *ngIf=\"insight.onLikeSelected\"\n                    [disabled]=\"!content\"\n                    (click)=\"onLikeSelected()\"\n                    class=\"option\"\n                >\n                    <i\n                        [ngClass]=\"{\n                            fal: !likeSelected,\n                            fas: likeSelected,\n                            'fa-thumbs-up': true,\n                        }\"\n                    >\n                    </i>\n                </button>\n                <button\n                    *ngIf=\"insight.onDislikeSelected\"\n                    [disabled]=\"!content\"\n                    (click)=\"onDislikeSelected()\"\n                    class=\"option\"\n                >\n                    <i\n                        [ngClass]=\"{\n                            fal: !dislikeSelected,\n                            fas: dislikeSelected,\n                            'fa-thumbs-down': true,\n                        }\"\n                    ></i>\n                </button>\n            </div>\n        </ng-template>\n    </div>\n</div>\n", styles: [".ia-insight-card{background-color:#fff;border:1px solid #9ecad4;border-radius:4px;cursor:pointer;display:flex;flex-direction:column;overflow:hidden}.ia-insight-card .header{align-items:center;background-color:#f1f7f8;border-bottom:1px solid #9ecad4;display:flex;gap:8px;min-height:60px;padding:8px 16px;-webkit-user-select:none;user-select:none}.ia-insight-card .header .insight-title{color:#428bca;flex-grow:1;font-family:Open Sans,sans-serif;font-size:14px;line-height:150%}.ia-insight-card .header .toggle-icon{color:#888b99;font-size:20px}.ia-insight-card .content{align-items:center;justify-content:space-between;cursor:auto;display:flex;flex-direction:column;gap:16px;min-height:160px;padding:24px}.ia-insight-card .content .text{color:#212533;font-family:Open Sans,sans-serif;font-size:14px;width:100%}.ia-insight-card .content .text--error{text-align:center}.ia-insight-card .content .insight-footer{color:#888b99;font-family:Open Sans,sans-serif;font-size:12px;text-align:center}.ia-insight-card .content .options{display:flex;gap:8px}.ia-insight-card .content .options .option{background-color:transparent;border:none;color:#428bca;cursor:pointer;font-size:12px}.ia-insight-card .content .options .option:disabled{color:#c1c1cc;cursor:auto}.ia-insight-card--close{border-color:#dedce5}.ia-insight-card--close .header{background-color:#fbfafc;border:none;border-color:#dedce5}.ia-insight-card--close .header .insight-title{color:#888b99}.ia-insight-card--close .content{display:none}\n"] }]
        }], ctorParameters: () => [{ type: i1.Clipboard }, { type: i2.ToastService }, { type: i3.TranslateService }], propDecorators: { insight: [{
                type: Input,
                args: [{ required: true }]
            }] } });
//# sourceMappingURL=data:application/json;base64, 