import { __decorate } from "tslib";
import { Component, Input } from '@angular/core';
import { FaqsForms } from '../../functions/faqs.forms';
import { FaqsDialogs } from '../../functions/faqs.dialogs';
import { Confirmable } from '../../../smz-dialogs/decorators/confirmable.decorator';
import * as i0 from "@angular/core";
import * as i1 from "../../services/faqs-manager.service";
import * as i2 from "../../../smz-dialogs/services/smz-dialogs.service";
import * as i3 from "@angular/common";
import * as i4 from "../../../smz-messages/components/icon-message/icon-message.component";
import * as i5 from "../../../smz-forms/features/form-group/form-group.component";
import * as i6 from "primeng/button";
import * as i7 from "primeng/accordion";
import * as i8 from "primeng/inputtext";
import * as i9 from "@angular/forms";
import * as i10 from "../../../rbk-utils/auth/guards/can-access.pipe";
import * as i11 from "../../pipes/search-faqs.pipe";
import * as i12 from "../../pipes/highlight.pipe";
import * as i13 from "../../pipes/safe-html.pipe";
export class FaqsContentComponent {
    constructor(manager, cdf, dialogs) {
        this.manager = manager;
        this.cdf = cdf;
        this.dialogs = dialogs;
        this.hasUnsavedForm = false;
        this.keywords = '';
    }
    ngOnInit() {
        this.setupForm();
    }
    setupForm() {
        this.formConfig = {
            formId: 'faqs-content-form',
            behaviors: { flattenResponse: true, avoidFocusOnLoad: true },
            groups: [
                FaqsForms.getFaqsFormGroup()
            ],
        };
        this.hasUnsavedForm = false;
        this.cdf.markForCheck();
    }
    create(formComponent) {
        const data = formComponent.viewdata.form.value;
        const creation = {
            tag: this.manager.currentTag,
            question: data.question,
            answer: data.answer
        };
        formComponent.clearFormValues();
        this.manager.create(creation);
    }
    update(item) {
        this.dialogs.open(FaqsDialogs.getDialog(item, (response) => {
            const update = {
                id: item.id,
                tag: this.manager.currentTag,
                question: response.question,
                answer: response.answer
            };
            this.manager.update(update);
        }));
    }
    delete(data) {
        this.manager.delete(data.id);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: FaqsContentComponent, deps: [{ token: i1.FaqsManagerService }, { token: i0.ChangeDetectorRef }, { token: i2.SmzDialogsService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.5", type: FaqsContentComponent, selector: "smz-faqs-content", inputs: { items: "items" }, ngImport: i0, template: "<div class=\"grid\">\r\n\r\n    <div class=\"col-12\">\r\n        <h3>{{ manager.config.placeholders.searchTitle }}</h3>\r\n        <div class=\"p-inputgroup\">\r\n            <span class=\"p-inputgroup-addon\"><i class=\"fa-solid fa-magnifying-glass\"></i></span>\r\n            <input type=\"text\" [(ngModel)]=\"keywords\" pInputText [placeholder]=\"manager.config.placeholders.searchPlaceholder\">\r\n            <button pButton [disabled]=\"keywords === ''\" (click)=\"keywords = ''\" type=\"button\" icon=\"fa-solid fa-xmark\" class=\"p-button-warn\"></button>\r\n        </div>\r\n    </div>\r\n\r\n    <div class=\"col-12\">\r\n        <ng-container *ngIf=\"(items | searchFaqs : keywords) as filtered\">\r\n            <ng-container *ngIf=\"filtered.length > 0; else emptyTemplate\">\r\n                <h3>{{ manager.config.placeholders.contentTitle }}</h3>\r\n                <p-accordion>\r\n                    <ng-container *ngFor=\"let item of filtered\">\r\n                        <p-accordionTab [header]=\"item.question\" [selected]=\"item.metadata?.selected\">\r\n                            <div *ngIf=\"manager.config.creationClaim | rbkCanAccess\" class=\"faqs__actions\">\r\n                                <a class=\"clickable hvr-icon-push mr-2\" (click)=\"update(item)\"><i class=\"far fa-edit hvr-icon\"></i></a>\r\n                                <a class=\"clickable hvr-icon-push\" (click)=\"delete(item)\"><i class=\"far fa-trash-alt hvr-icon\"></i></a>\r\n                            </div>\r\n                            <div class=\"faqs__answer\" [innerHTML]=\"(item.answer | highlight : keywords) | safeHtml\"></div>\r\n                         </p-accordionTab>\r\n                    </ng-container>\r\n                </p-accordion>\r\n            </ng-container>\r\n        </ng-container>\r\n    </div>\r\n\r\n    <div class=\"col-12\">\r\n        <ng-container *ngIf=\"(manager.config.creationClaim | rbkCanAccess) && formConfig != null\">\r\n            <h3>{{ manager.config.placeholders.creationTitle }}</h3>\r\n            <smz-form-group #creationComponent [config]=\"formConfig\"></smz-form-group>\r\n            <button pButton type=\"button\" class=\"p-button p-button-ghost\" label=\"ENVIAR\" [disabled]=\"!creationComponent.isValid\" (click)=\"create(creationComponent)\"></button>\r\n        </ng-container>\r\n    </div>\r\n</div>\r\n\r\n\r\n<ng-template #emptyTemplate>\r\n    <smz-icon-message\r\n        [message]=\"manager.config.placeholders.emptyMessage\"\r\n        [comment]=\"(manager.config.creationClaim | rbkCanAccess) ?\r\n        manager.config.placeholders.creationMessage :\r\n            (keywords === '') ?\r\n            manager.config.placeholders.supportMessage :\r\n            manager.config.placeholders.noSearchResultsMessage\"\r\n            >\r\n    </smz-icon-message>\r\n</ng-template>", styles: [".faqs__answer{white-space:pre-wrap}.faqs__actions{width:100%;text-align:right;padding:0 0 10px}.p-input-icon-left,.p-input-icon-right{position:relative}.ui-float-icon{position:absolute;top:50%;margin-top:-.5rem;left:.5rem;color:#6c757d}.p-input-icon-left>.ui-inputtext{padding-left:2rem;border-left-width:1px}\n"], dependencies: [{ kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i4.SmzIconMessageComponent, selector: "smz-icon-message", inputs: ["icon", "message", "comment"] }, { kind: "component", type: i5.FormGroupComponent, selector: "smz-form-group", inputs: ["config"], outputs: ["statusChanges", "changed", "onChange", "submit"] }, { kind: "directive", type: i6.ButtonDirective, selector: "[pButton]", inputs: ["iconPos", "loadingIcon", "label", "icon", "loading", "severity", "raised", "rounded", "text", "outlined", "size", "plain"] }, { kind: "component", type: i7.Accordion, selector: "p-accordion", inputs: ["multiple", "style", "styleClass", "expandIcon", "collapseIcon", "activeIndex", "selectOnFocus", "headerAriaLevel"], outputs: ["onClose", "onOpen", "activeIndexChange"] }, { kind: "component", type: i7.AccordionTab, selector: "p-accordionTab", inputs: ["id", "header", "headerStyle", "tabStyle", "contentStyle", "tabStyleClass", "headerStyleClass", "contentStyleClass", "disabled", "cache", "transitionOptions", "iconPos", "selected", "headerAriaLevel"], outputs: ["selectedChange"] }, { kind: "directive", type: i8.InputText, selector: "[pInputText]" }, { kind: "directive", type: i9.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: i9.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i9.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "pipe", type: i10.RbkCanAccessPipe, name: "rbkCanAccess" }, { kind: "pipe", type: i11.SearchFaqsPipe, name: "searchFaqs" }, { kind: "pipe", type: i12.HighlightSearch, name: "highlight" }, { kind: "pipe", type: i13.SafeHtmlPipe, name: "safeHtml" }] }); }
}
__decorate([
    Confirmable('Confirma a criação desta pergunta/resposta ?', 'Aviso')
], FaqsContentComponent.prototype, "create", null);
__decorate([
    Confirmable('Deseja realmente excluir esta pergunta/resposta ?', 'Exclusão', true)
], FaqsContentComponent.prototype, "delete", null);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.5", ngImport: i0, type: FaqsContentComponent, decorators: [{
            type: Component,
            args: [{ selector: 'smz-faqs-content', template: "<div class=\"grid\">\r\n\r\n    <div class=\"col-12\">\r\n        <h3>{{ manager.config.placeholders.searchTitle }}</h3>\r\n        <div class=\"p-inputgroup\">\r\n            <span class=\"p-inputgroup-addon\"><i class=\"fa-solid fa-magnifying-glass\"></i></span>\r\n            <input type=\"text\" [(ngModel)]=\"keywords\" pInputText [placeholder]=\"manager.config.placeholders.searchPlaceholder\">\r\n            <button pButton [disabled]=\"keywords === ''\" (click)=\"keywords = ''\" type=\"button\" icon=\"fa-solid fa-xmark\" class=\"p-button-warn\"></button>\r\n        </div>\r\n    </div>\r\n\r\n    <div class=\"col-12\">\r\n        <ng-container *ngIf=\"(items | searchFaqs : keywords) as filtered\">\r\n            <ng-container *ngIf=\"filtered.length > 0; else emptyTemplate\">\r\n                <h3>{{ manager.config.placeholders.contentTitle }}</h3>\r\n                <p-accordion>\r\n                    <ng-container *ngFor=\"let item of filtered\">\r\n                        <p-accordionTab [header]=\"item.question\" [selected]=\"item.metadata?.selected\">\r\n                            <div *ngIf=\"manager.config.creationClaim | rbkCanAccess\" class=\"faqs__actions\">\r\n                                <a class=\"clickable hvr-icon-push mr-2\" (click)=\"update(item)\"><i class=\"far fa-edit hvr-icon\"></i></a>\r\n                                <a class=\"clickable hvr-icon-push\" (click)=\"delete(item)\"><i class=\"far fa-trash-alt hvr-icon\"></i></a>\r\n                            </div>\r\n                            <div class=\"faqs__answer\" [innerHTML]=\"(item.answer | highlight : keywords) | safeHtml\"></div>\r\n                         </p-accordionTab>\r\n                    </ng-container>\r\n                </p-accordion>\r\n            </ng-container>\r\n        </ng-container>\r\n    </div>\r\n\r\n    <div class=\"col-12\">\r\n        <ng-container *ngIf=\"(manager.config.creationClaim | rbkCanAccess) && formConfig != null\">\r\n            <h3>{{ manager.config.placeholders.creationTitle }}</h3>\r\n            <smz-form-group #creationComponent [config]=\"formConfig\"></smz-form-group>\r\n            <button pButton type=\"button\" class=\"p-button p-button-ghost\" label=\"ENVIAR\" [disabled]=\"!creationComponent.isValid\" (click)=\"create(creationComponent)\"></button>\r\n        </ng-container>\r\n    </div>\r\n</div>\r\n\r\n\r\n<ng-template #emptyTemplate>\r\n    <smz-icon-message\r\n        [message]=\"manager.config.placeholders.emptyMessage\"\r\n        [comment]=\"(manager.config.creationClaim | rbkCanAccess) ?\r\n        manager.config.placeholders.creationMessage :\r\n            (keywords === '') ?\r\n            manager.config.placeholders.supportMessage :\r\n            manager.config.placeholders.noSearchResultsMessage\"\r\n            >\r\n    </smz-icon-message>\r\n</ng-template>", styles: [".faqs__answer{white-space:pre-wrap}.faqs__actions{width:100%;text-align:right;padding:0 0 10px}.p-input-icon-left,.p-input-icon-right{position:relative}.ui-float-icon{position:absolute;top:50%;margin-top:-.5rem;left:.5rem;color:#6c757d}.p-input-icon-left>.ui-inputtext{padding-left:2rem;border-left-width:1px}\n"] }]
        }], ctorParameters: () => [{ type: i1.FaqsManagerService }, { type: i0.ChangeDetectorRef }, { type: i2.SmzDialogsService }], propDecorators: { items: [{
                type: Input
            }], create: [], delete: [] } });
//# sourceMappingURL=data:application/json;base64, 