/*
 * Copyright (C) 2018-2021 StApps
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */
import {Component} from '@angular/core';
import {SearchPageComponent} from './search-page.component';

/**
 * Presents a list of places for eating/drinking
 */
@Component({
  templateUrl: 'search-page.html',
})
export class FoodDataListComponent extends SearchPageComponent {
  /**
   * Sets the forced filter to present only places for eating/drinking
   */
  initialize() {
    this.showDefaultData = true;

    if (this.positionService.position) {
      this.sortQuery = [
        {
          type: 'distance',
          order: 'asc',
          arguments: {
            field: 'geo.point.coordinates',
            position: [
              this.positionService.position.longitude,
              this.positionService.position.latitude,
            ],
          },
        },
      ];
    }

    this.sortQuery = [
      {
        arguments: {field: 'name'},
        order: 'asc',
        type: 'ducet',
      },
    ];

    this.forcedFilter = {
      arguments: {
        filters: [
          {
            arguments: {
              field: 'categories',
              value: 'canteen',
            },
            type: 'value',
          },
          {
            arguments: {
              field: 'categories',
              value: 'student canteen',
            },
            type: 'value',
          },
          {
            arguments: {
              field: 'categories',
              value: 'cafe',
            },
            type: 'value',
          },
          {
            arguments: {
              field: 'categories',
              value: 'restaurant',
            },
            type: 'value',
          },
        ],
        operation: 'or',
      },
      type: 'boolean',
    };
  }
}
