import { Component, Input } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "../../pipes/trust-html/trust-html.pipe";
function ReadMoreComponent_a_2_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "a", 2);
    i0.ɵɵlistener("click", function ReadMoreComponent_a_2_Template_a_click_0_listener() { i0.ɵɵrestoreView(_r3); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.readMore(false)); });
    i0.ɵɵtext(1, "...read more");
    i0.ɵɵelementEnd();
} }
function ReadMoreComponent_a_3_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "a", 2);
    i0.ɵɵlistener("click", function ReadMoreComponent_a_3_Template_a_click_0_listener() { i0.ɵɵrestoreView(_r5); const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.readMore(true)); });
    i0.ɵɵtext(1, "...read less");
    i0.ɵɵelementEnd();
} }
export class ReadMoreComponent {
    constructor() {
        this.isCollapsed = true;
        this.text = '';
        this.hideAfter = 150;
        this.hideReadMore = false;
    }
    ngOnInit() {
        console.log('ngOnInit');
        this.readMore(true);
    }
    readMore(more) {
        if (this.text?.length <= this.hideAfter) {
            this.hideReadMore = true;
        }
        if (this.text?.length > this.hideAfter && more) {
            this.value = this.text.substring(0, this.hideAfter);
            this.isCollapsed = false;
        }
        else {
            this.value = this.text;
            this.isCollapsed = true;
        }
    }
    static { this.ɵfac = function ReadMoreComponent_Factory(t) { return new (t || ReadMoreComponent)(); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ReadMoreComponent, selectors: [["app-read-more"]], inputs: { isCollapsed: "isCollapsed", text: "text", hideAfter: "hideAfter" }, decls: 4, vars: 5, consts: [[3, "innerHtml"], ["class", "link", 3, "click", 4, "ngIf"], [1, "link", 3, "click"]], template: function ReadMoreComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelement(0, "span", 0);
            i0.ɵɵpipe(1, "trustHtml");
            i0.ɵɵtemplate(2, ReadMoreComponent_a_2_Template, 2, 0, "a", 1)(3, ReadMoreComponent_a_3_Template, 2, 0, "a", 1);
        } if (rf & 2) {
            i0.ɵɵproperty("innerHtml", i0.ɵɵpipeBind1(1, 3, ctx.value), i0.ɵɵsanitizeHtml);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngIf", !ctx.isCollapsed && !ctx.hideReadMore);
            i0.ɵɵadvance(1);
            i0.ɵɵproperty("ngIf", ctx.isCollapsed && !ctx.hideReadMore);
        } }, dependencies: [i1.NgIf, i2.TrustHtmlPipe], styles: ["div.collapsed[_ngcontent-%COMP%]{height:250px;overflow:hidden}"] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ReadMoreComponent, [{
        type: Component,
        args: [{ selector: 'app-read-more', template: `
    <span [innerHtml]="value | trustHtml">
    </span>
    <a (click)="readMore(false)" class="link" *ngIf="!isCollapsed && !hideReadMore">...read more</a>
    <a (click)="readMore(true)" class="link" *ngIf="isCollapsed && !hideReadMore">...read less</a>
`, styles: ["div.collapsed{height:250px;overflow:hidden}\n"] }]
    }], () => [], { isCollapsed: [{
            type: Input
        }], text: [{
            type: Input
        }], hideAfter: [{
            type: Input
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ReadMoreComponent, { className: "ReadMoreComponent", filePath: "lib\\components\\read-more\\read-more.component.ts", lineNumber: 13 }); })();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVhZC1tb3JlLmNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3Byb2plY3RzL25neC1yZXVzYS1hcHAtbGliL3NyYy9saWIvY29tcG9uZW50cy9yZWFk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