import { Component } from '@angular/core';
import { ICellRendererAngularComp } from 'ag-grid-angular';
import {StringHelper} from '../../helpers/string-helper';

@Component({
  selector: 'app-journal-detail-cell-renderer',
  template: `
    <div class="full-width-panel">
      <div *ngIf="detailsContent" class="full-width-details" style="white-space: normal" [innerHTML]="detailsContent"></div>
    </div>`
})
export class JournalDetailCellRendererComponent implements ICellRendererAngularComp {

  params: any;
  masterGridApi: any;
  masterRowIndex: any;
  detailsContent: String;

  // called on init
  agInit(params: any): void {
    this.params = params;
    this.refreshContent(this.params);

    this.masterGridApi = params.api;
    this.masterRowIndex = params.rowIndex;
  }

  // called when the cell is refreshed
  refresh(params: any): boolean {
    this.params = params;
    this.refreshContent(this.params);
    return false;
  }

  refreshContent(params) {
    this.detailsContent = null;
    this.detailsContent = params.data.changeCaption.replaceAll('\r\n', '<br>');
  }
}
