import { Component, OnInit, ChangeDetectionStrategy, Output, EventEmitter } from '@angular/core';
import { Router } from '@angular/router';
import { createQueryStringFromObject } from 'src/app/shared/util/func';

@Component({
  selector: 'app-search',
  templateUrl: './search.component.html',
  styleUrls: ['./search.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SearchComponent implements OnInit {
  @Output() search = new EventEmitter()
  query = {
    login_name: null,
    display_name: null
  }
  constructor(
    private router: Router
  ) { }

  ngOnInit(): void {
  }

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

  clear(){
    this.query = {
      login_name: null,
      display_name: null
    }
    const query = createQueryStringFromObject(this.query)
    this.search.emit(query)
  }

  add(){
    this.router.navigate(['create-user/add'])
  }

}
