/*
 * Copyright (C) 2023 Robert Bosch GmbH Copyright (C) 2023 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { Component } from '@angular/core';
import { BciCorePicklistIntl } from '@bci-web-core/core';

import { fruits } from '../bci-core-picklist-demo-model';
import { PicklistIntlDemo } from './picklist-intl-demo';

/** This demo shows how to translate the picklist. */
@Component({
  selector: 'bci-internationalization',
  templateUrl: './internationalization.component.html',
  styleUrls: ['./internationalization.component.scss'],
  providers: [{ provide: BciCorePicklistIntl, useClass: PicklistIntlDemo }],
})
export class InternationalizationComponent {
  /** Whether the picklist's labels have already been translated. */
  translated = false;

  fruitNamesList = fruits.map((fruit) => fruit.name);

  constructor(private picklistIntl: BciCorePicklistIntl) {}

  /** Update translations button click handler. */
  onClick(): void {
    this.translated == true ? (<PicklistIntlDemo>this.picklistIntl).englishIntl(): (<PicklistIntlDemo>this.picklistIntl).germanIntl();
    this.translated = !this.translated;
  }
}
