/*
 * Copyright (C) 2022 StApps
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

import {Component, Input} from '@angular/core';
import {PAIADocument} from '../../../types';
import {SCArticle, SCBook, SCPeriodical} from '@openstapps/core';
import {LibraryAccountService} from '../../library-account.service';

@Component({
  selector: 'stapps-paia-item',
  templateUrl: './paiaitem.component.html',
  styleUrls: ['./paiaitem.component.scss'],
})
export class PAIAItemComponent {
  book?: SCBook | SCPeriodical | SCArticle;

  private _item: PAIADocument;

  additionalPropertiesToShow: (keyof PAIADocument)[] = [
    'about',
    'endtime',
    'label',
  ];

  @Input()
  set item(item: PAIADocument) {
    this._item = item;
    this.libraryAccountService
      .getDocumentFromHDS(item.edition as string)
      .then(book => {
        this.book = book;
      });
  }

  get item() {
    return this._item;
  }

  @Input()
  pageName: string;

  constructor(private readonly libraryAccountService: LibraryAccountService) {}
}
