import { fetchMODISHistorical } from 'services/analysis-cached';

import {
  POLITICAL_BOUNDARIES_DATASET,
  FIRES_VIIRS_DATASET
} from 'data/layers-datasets';
import {
  DISPUTED_POLITICAL_BOUNDARIES,
  POLITICAL_BOUNDARIES,
  FIRES_ALERTS_VIIRS
} from 'data/layers';

import getWidgetProps from './selectors';

export default {
  widget: 'firesAlertsHistoricalDaily',
  title: 'Fire Alerts Count in {location}',
  large: true,
  refetchKeys: [
    'startDate',
    'endDate'
  ],
  settingsConfig: [
    {
      key: 'forestType',
      label: 'Forest Type',
      type: 'select',
      placeholder: 'All tree cover',
      clearable: true
    },
    {
      key: 'landCategory',
      label: 'Land Category',
      type: 'select',
      placeholder: 'All categories',
      clearable: true,
      border: true
    },
    {
      key: 'dataset',
      label: 'fires dataset',
      type: 'select'
    },
    {
      key: 'years',
      label: 'years',
      endKey: 'endYear',
      startKey: 'startYear',
      type: 'range-select',
      options: Array.from({ length: 20 }, (a, n) => n + 2001) // range 2001-2020
        .map(y => ({ label: `${y}`, value: y })),
      border: true
    },
    {
      key: 'confidence',
      label: 'Confidence level',
      type: 'select',
      clearable: false,
      border: true
    }
  ],
  visible: ['analysis'],
  types: ['country'],
  admins: ['adm0', 'adm1', 'adm2'],
  chartType: 'composedChart',
  dataType: 'fires',
  colors: 'fires',
  metaKey: 'widget_fire_historical_location',
  settings: {
    startDate: '2019-10-01',
    endDate: '2020-01-24',
    dataset: 'viirs'
  },
  datasets: [
    {
      dataset: POLITICAL_BOUNDARIES_DATASET,
      layers: [DISPUTED_POLITICAL_BOUNDARIES, POLITICAL_BOUNDARIES],
      boundary: true
    },
    // fires
    {
      dataset: FIRES_VIIRS_DATASET,
      layers: [FIRES_ALERTS_VIIRS]
    }
  ],
  sentence:
    'Between {start_date} and {end_date} {location} experienced a total of {total_alerts} {dataset} fire alerts.',
  whitelists: {
    adm0: [
      'AFG',
      'AGO',
      'ALB',
      'AND',
      'ANT',
      'ARE',
      'ARG',
      'ARM',
      'AUS',
      'AUT',
      'AZE',
      'BDI',
      'BEL',
      'BEN',
      'BFA',
      'BGD',
      'BGR',
      'BHR',
      'BHS',
      'BIH',
      'BLM',
      'BLR',
      'BLZ',
      'BOL',
      'BRA',
      'BRB',
      'BRN',
      'BTN',
      'BWA',
      'CAF',
      'CAN',
      'CHE',
      'CHL',
      'CHN',
      'CIV',
      'CMR',
      'COD',
      'COG',
      'COL',
      'COM',
      'CPV',
      'CRI',
      'CUB',
      'CYP',
      'CZE',
      'DEU',
      'DJI',
      'DMA',
      'DNK',
      'DOM',
      'DZA',
      'ECU',
      'EGY',
      'ERI',
      'ESP',
      'EST',
      'ETH',
      'FIN',
      'FJI',
      'FLK',
      'FRA',
      'FSM',
      'GAB',
      'GBR',
      'GEO',
      'GHA',
      'GIB',
      'GIN',
      'GLP',
      'GMB',
      'GNB',
      'GNQ',
      'GRC',
      'GRL',
      'GTM',
      'GUF',
      'GUM',
      'GUY',
      'HND',
      'HRV',
      'HTI',
      'HUN',
      'IDN',
      'IND',
      'IRL',
      'IRN',
      'IRQ',
      'ISR',
      'ITA',
      'JAM',
      'JOR',
      'JPN',
      'KAZ',
      'KEN',
      'KGZ',
      'KHM',
      'KIR',
      'KNA',
      'KOR',
      'KWT',
      'LAO',
      'LBN',
      'LBR',
      'LBY',
      'LCA',
      'LIE',
      'LKA',
      'LSO',
      'LTU',
      'LUX',
      'LVA',
      'MAR',
      'MCO',
      'MDA',
      'MDG',
      'MDV',
      'MEX',
      'MHL',
      'MKD',
      'MLI',
      'MLT',
      'MMR',
      'MNE',
      'MNG',
      'MNP',
      'MOZ',
      'MRT',
      'MSR',
      'MTQ',
      'MUS',
      'MWI',
      'MYS',
      'NAM',
      'NCL',
      'NER',
      'NGA',
      'NIC',
      'NLD',
      'NOR',
      'NPL',
      'NZL',
      'OMN',
      'PAK',
      'PAN',
      'PCN',
      'PER',
      'PHL',
      'PNG',
      'POL',
      'PRI',
      'PRK',
      'PRT',
      'PRY',
      'PSE',
      'PYF',
      'QAT',
      'REU',
      'ROU',
      'RUS',
      'RWA',
      'SAU',
      'SDN',
      'SEN',
      'SGP',
      'SLB',
      'SLE',
      'SLV',
      'SOM',
      'SRB',
      'SSD',
      'STP',
      'SUR',
      'SVK',
      'SVN',
      'SWE',
      'SWZ',
      'SYR',
      'TCD',
      'TGO',
      'THA',
      'TJK',
      'TKL',
      'TKM',
      'TLS',
      'TON',
      'TTO',
      'TUN',
      'TUR',
      'TUV',
      'TZA',
      'UGA',
      'UKR',
      'URY',
      'USA',
      'UZB',
      'VAT',
      'VEN',
      'VIR',
      'VNM',
      'VUT',
      'WSM',
      'YEM',
      'ZAF',
      'ZMB',
      'ZWE'
    ]
  },
  getData: params => fetchMODISHistorical({ ...params, frequency: 'daily' }).then(alerts => {
    const { data } = alerts.data;
    return data;
  }),
  getDataURL: params => [fetchMODISHistorical({ ...params, frequency: 'daily', download: true })],
  getWidgetProps
};

@@ -517,809 +517,68 @@
 y: '
-forestType',%0A      label: 'Forest Type',%0A      type: 'select',%0A      placeholder: 'All tree cover',%0A      clearable: true%0A    %7D,%0A    %7B%0A      key: 'landCategory',%0A      label: 'Land Category',%0A      type: 'select',%0A      placeholder: 'All categories',%0A      clearable: true,%0A      border: true%0A    %7D,%0A    %7B%0A      key: 'dataset',%0A      label: 'fires dataset',%0A      type: 'select'%0A    %7D,%0A    %7B%0A      key: 'years',%0A      label: 'years',%0A      endKey: 'endYear',%0A      startKey: 'startYear',%0A      type: 'range-select',%0A      options: Array.from(%7B length: 20 %7D, (a, n) =%3E n + 2001) // range 2001-2020%0A        .map(y =%3E (%7B label: %60$%7By%7D%60, value: y %7D)),%0A      border: true%0A    %7D,%0A    %7B%0A      key: 'confidence',%0A      label: 'Confidence level',%0A      type: 'select',%0A      clearable: false,%0A      border: true
+dataset',%0A      label: 'fires dataset',%0A      type: 'select'
 %0A   
@@ -802,64 +802,8 @@
 : %7B%0A
-    startDate: '2019-10-01',%0A    endDate: '2020-01-24',%0A
     

tidy config for new widget