import {Component, OnInit, ChangeDetectionStrategy, Output, EventEmitter} from '@angular/core';
import {createQueryStringFromObject} from '../../../../../../shared/util/func';
import {BranchService} from '../../../../../../core/service/settings/branch.service';

@Component({
    selector: 'app-testing-field-search',
    templateUrl: './testing-field-search.component.html',
    styleUrls: ['./testing-field-search.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class TestingFieldSearchComponent implements OnInit {
    branchMock = [];

    provinceMock = [{id: 1, name: 'จังหวัด 1 '}, {id: 2, name: 'จังหวัด 2 '}];
    @Output() add = new EventEmitter();
    @Output() search = new EventEmitter();
    query = {
        testing_field_name_th : null,
        branch_uid : null
    };
    constructor(
        private branchSV: BranchService,
    ) { }

    ngOnInit(): void {
        this.branchSV.getAll().subscribe(
            result => this.branchMock = result,
        );
    }

    onAdd(){
        this.add.emit();
    }

    onSearch(){
        let query = createQueryStringFromObject(this.query);
        this.search.emit(query);
    }

    clear(){
        this.query = {
            testing_field_name_th : null,
            branch_uid : null
        };
    }

    setBranch(id){
        this.query.branch_uid = id;
    }

}
