import { Component, OnInit, Input } from '@angular/core';
import { InputValue } from './input-value';

@Component({
  selector: 'number-range',
  templateUrl: './number-range.component.html',
  styleUrls: ['./number-range.component.scss']
})
export class NumberRangeComponent implements OnInit {

  @Input() public input: InputValue;
  @Input() public min: number = Number.MIN_SAFE_INTEGER;
  @Input() public max: number = Number.MAX_SAFE_INTEGER;
  @Input() public step = 1;

  @Input() public title: string;
  public minLength: number;
  public maxLength: number;


  @Input() public value: number;
  constructor() { }

  ngOnInit() {
    if (this.input) {
      const lMin = this.min.toString().length;
      const lMax = this.max.toString().length;
      this.minLength = Math.min(lMin, lMax);
      this.maxLength = Math.max(lMin, lMax);
    }
  }


    public onChange() {
    if (this.input) {
        this.input.value = this.input.value >= this.max ? this.max : this.input.value;
        this.input.value = this.input.value <= this.min ? this.min : this.input.value;
     }
  }

}
