import { Component, ChangeDetectionStrategy, Input } from '@angular/core';
import { TextDTO } from '@generated/swagger/cat-search-api';
import { ArticleDetailsTextLinkComponent } from './article-details-text-link.component';

import { LineTypePipe } from './line-type.pipe';
import { ReiheRoutePipe } from './reihe-route.pipe';

@Component({
  selector: 'page-article-details-text',
  templateUrl: 'article-details-text.component.html',
  styleUrls: ['article-details-text.component.css'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'page-article-details-text' },
  imports: [
    ArticleDetailsTextLinkComponent,
    LineTypePipe,
    ReiheRoutePipe
],
})
export class ArticleDetailsTextComponent {
  @Input()
  text: TextDTO;

  get lines() {
    return this.text?.value?.split('\n');
  }

  constructor() {}

  getReihen(line: string): string[] {
    let splittedReihen = line?.split(';');
    return splittedReihen?.map((reihe, index) => {
      if (splittedReihen?.length !== index + 1) {
        return reihe + ';';
      }
      return reihe;
    });
  }
}
