import { Component, Input, ViewEncapsulation } from '@angular/core';
import { IOnlineBoardRoutePageUrlParams } from '@online-board/services/url/types';
import { ISearchHistoryItem } from '@shared/services/history/search-history.service';
import { IUrlTimeRange } from '@typings/common/url';

@Component({
    selector: 'online-board-route-history-item',
    templateUrl: './online-board-route-history-item.component.html',
    encapsulation: ViewEncapsulation.None,
})
export class OnlineBoardRouteHistoryItemComponent {
    @Input() item: ISearchHistoryItem;

    get params() {
        return this.item.params as IOnlineBoardRoutePageUrlParams;
    }

    get arrival() {
        return this.params.arrival;
    }

    get departure() {
        return this.params.departure;
    }

    get date() {
        return this.params.date;
    }

    get timeRange(): IUrlTimeRange {
        const { timeTo, timeFrom } = this.params;
        return timeFrom && timeTo
            ? {
                  timeFrom,
                  timeTo,
              }
            : undefined;
    }
}
