import { Component, Injectable, Input } from "@angular/core";
import { ChildComponent } from "../Child/child.component";
import { Hotel } from "./hotel";
import { CurrencyPipe, NgFor, NgIf } from "@angular/common";
import { FormsModule } from "@angular/forms";
import { StarRatingComponent } from "../star-rating/star-rating.component";
import { HttpClient } from "@angular/common/http";
import { RouterLink } from "@angular/router";

@Component({
  selector: 'app-hotel-item',
  standalone: true,
  templateUrl: './HotelItem.component.html',
  imports: [ChildComponent, CurrencyPipe, FormsModule, StarRatingComponent, NgIf, RouterLink, NgFor],
})
export class HotelItem {

  @Input() public hotel!: Hotel;
  public selectedLanguage?: string;

  @Input() public isDetail: boolean = false;

  public languageChange(lang: string) {
    this.selectedLanguage = lang;
    console.log(this.selectedLanguage);
  }

  public getCurrencyCode(langCode: string | undefined): string {
    if (!langCode) return '';

    for (let language of this.langs) {
      if (language.code === langCode) {
        return language.currency;
      }
    }
    return '';
  }

  public langs = [
    {
      "lang": "en",
      "code": "en-US",
      "currency": "USD"
    },
    {
      "lang": "cn",
      "code": "cn-CN",
      "currency": "CNY"
    },
    {
      "lang": "de",
      "code": "de-DE",
      "currency": "EUR"
    }
  ];
}
