import { Component, OnInit } from '@angular/core';
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';

interface EquirmentModel {
  id: number;
  name: string;
  desc: string;
  type: string;
  pic: string;
}
interface RoomModel{
  rid : number;
  rname : string;
  rdesc : string;
  rpic : string;
}

@Component({
  selector: 'app-equipment',
  templateUrl: './equipment.component.html',
  styleUrls: ['./equipment.component.scss']
})
export class EquipmentComponent implements OnInit {
  page = 1;
  pageSize = 10;

  closeResult = '';

  listEquirment: EquirmentModel[] = [
    {
      id: 1,
      name: "จอคอมพิวเตอร์",
      desc: "หน้าจอขนาด 22 นิ้ว",
      type: "it",
      pic: "assets/img/mo1.jpg"
    },
    {
      id: 2,
      name: "เมาส์",
      desc: "...",
      type: "it",
      pic: "assets/img/mou.jpg"
    },
    {
      id: 3,
      name: "โน๊ตบุ๊ค",
      desc: "หน้าจอขนาด 20 นิ้ว",
      type: "it",
      pic: "assets/img/notebook.jpg"
    },
    {
      id: 4,
      name: "คีย์บอร์ด",
      desc: "...",
      type: "it",
      pic: "assets/img/keyboard.png"
    }
  ]
  
  listRoomModel: RoomModel[] = [
    {
      rid: 1,
      rname: "ห้องเดียว",
      rdesc: "จำนวนคน 25 คน",
      rpic: "assets/img/room.jpg"
    },
    {
      rid: 2,
      rname: "ห้องคู่",
      rdesc: "จำนวนคน 50 คน",
      rpic: "assets/img/room.jpg"
    },
    {
      rid: 3,
      rname: "ห้องรวม",
      rdesc: "จำนวนคน 100 คน",
      rpic: "assets/img/room.jpg"
    },
    {
      rid: 4,
      rname: "รถ",
      rdesc: "รถบริษัท",
      rpic: "assets/img/car.jpg"
    },
  ]
  collectionSize = this.listEquirment.length;

  constructor(private modalService: NgbModal) { }

  ngOnInit(): void {
  }

  open(content) {
    this.modalService.open(content, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

  private getDismissReason(reason: any): string {
    if (reason === ModalDismissReasons.ESC) {
      return 'by pressing ESC';
    } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
      return 'by clicking on a backdrop';
    } else {
      return `with: ${reason}`;
    }
  }
  refreshCountries() {
    this.listEquirment = this.listEquirment
      .map((item, i) => ({ id: i + 1, ...item }))
      .slice((this.page - 1) * this.pageSize, (this.page - 1) * this.pageSize + this.pageSize);
  }
}