﻿import { Component } from '@angular/core';
import { Router } from '@angular/router';

import { BoardCategoryService, ErrorHandlerService, ModalService } from '../services/index';
import { Board, BoardCategory } from '../models/index';
import { HomeComponent } from '../components/home/home.component';

@Component({
    selector: 'board-category-form',
    templateUrl: './board-category-form.component.html'
})
export class BoardCategoryFormComponent {
    public boardCategory = new BoardCategory();

    loading = false;

    constructor(
        private boardCategoryService: BoardCategoryService,
        private errorHandlerService: ErrorHandlerService,
        private homeComponent: HomeComponent,
        private modalService: ModalService,
        private router: Router) {
    }

    public openModal(id: string) {
        this.modalService.open(id);
    }

    public closeModal(id: string) {
        this.modalService.close(id);

        this.boardCategory.name = "";
    }

    public sa
 {
        this.loading = true;

        this.boardCategoryService.create(this.homeComponent.selectedBoard, this.boardCategory)
            .subscribe(
            data => {
                this.loading = false;
                let boardCategory = data as BoardCategory;
                this.homeComponent.selectedBoard.boardCategories.push(boardCategory); //Let home know there is a new board category
                this.boardCategory.name = "";
            },
            error => {
                this.loading = false;
                this.errorHandlerService.handleError(error);
            });
    }
}
veNewBoardCategory()