import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { isNullOrUndefined } from '@bixi/core/utils';
import { ITimeCol } from '../table.type';
import { ColBase } from './col.base';

@Component({
  selector: 'bixi-table-col-time',
  host: { '[class.bixi-table-col-time]': 'true' },
  template: `
    <bixi-time [time]="value" [format]="col.format || 'YYYY/MM/DD HH:mm'"
               [relative]="col.relative" [radio]="col.radio || 1" [timeout]="col.timeout || 24* 60"
               [duration]="col.duration || 1">
    </bixi-time>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class BixiTableColTimeComponent extends ColBase {
  _col: ITimeCol;
  @Input()
  get col(): ITimeCol {
    return this._col;
  }

  set col(options: ITimeCol) {
    this._col = options;
    this._col.relative = isNullOrUndefined(options.relative) ? true : options.relative;
  }
}


