import { Component, Input } from '@angular/core';

import { Criterion, ConeSearch } from '../../store/model';
import { getCriterionStr, getHost as host } from '../../../shared/utils';
import { Dataset } from 'src/app/metamodel/model';

@Component({
    selector: 'app-result-download',
    templateUrl: 'download.component.html',
    styleUrls: ['download.component.css']
})
export class DownloadSectionComponent {
    @Input() datasetName: string;
    @Input() datasetList: Dataset[];
    @Input() dataLength: number;
    @Input() criteriaList: Criterion[];
    @Input() coneSearch: ConeSearch;
    @Input() outputList: number[];

    getDataset(): Dataset {
        return this.datasetList.find(dataset => dataset.name === this.datasetName);
    }

    getUrl(format: string): string {
        let query: string = host() + '/search/' + this.datasetName + '?a=' + this.outputList.join(';');
        if (this.criteriaList.length > 0) {
            query += '&c=' + this.criteriaList.map(criterion => getCriterionStr(criterion)).join(';');
        }
        if (this.coneSearch !== null) {
            query += '&cs=' + this.coneSearch.ra + ':' + this.coneSearch.dec + ':' + this.coneSearch.radius;
        }
        query += '&f=' + format
        return query;
    }
}