import get from 'lodash/get';
import { fetchAnalysisEndpoint } from 'services/analysis';

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

import { shouldQueryPrecomputedTables } from 'components/widgets/utils/helpers';

import getWidgetProps from './selectors';

export default {
  widget: 'treeCoverGainSimple',
  title: 'Tree cover gain in {location}',
  categories: ['summary', 'forest-change'],
  types: ['geostore', 'wdpa', 'use'],
  admins: ['adm0', 'adm1'],
  metaKey: 'widget_tree_cover_gain',
  settingsConfig: [
    {
      key: 'extentYear',
      label: 'extent year',
      type: 'switch'
    },
    {
      key: 'threshold',
      label: 'canopy density',
      type: 'mini-select',
      metaKey: 'widget_canopy_density'
    }
  ],
  pendingKeys: ['threshold', 'extentYear'],
  refetchKeys: ['threshold', 'extentYear'],
  datasets: [
    {
      dataset: 'fdc8dc1b-2728-4a79-b23f-b09485052b8d',
      layers: [
        '6f6798e6-39ec-4163-979e-182a74ca65ee',
        'c5d1e010-383a-4713-9aaa-44f728c0571c'
      ],
      boundary: true
    },
    // gain
    {
      dataset: '70e2549c-d722-44a6-a8d7-4a385d78565e',
      layers: ['3b22a574-2507-4b4a-a247-80057c1a1ad4']
    }
  ],
  visible: ['dashboard', 'analysis'],
  sortOrder: {
    summary: 3,
    forestChange: 7
  },
  settings: {
    threshold: 30,
    extentYear: 2000
  },
  chartType: 'listLegend',
  colors: 'gain',
  sentence:
    'From 2001 to 2012, {location} gained {gain} of tree cover equal to {gainPercent} is its total extent.',
  getData: params => {
    if (shouldQueryPrecomputedTables(params)) {
      return getGain(params).then(response => {
        const { data } = (response && response.data) || {};
        console.log('data', data[0])
        const gain = data[0].gain || 0; //get(data, 'data[0].treecover_gain_2000-2012__ha');
        const extent = data[0].extent || 0; //get(data, 'data[0].treecover_extent_2000__ha');

        return {
          gain,
          extent
        };
      });
    }

    return fetchAnalysisEndpoint({
      ...params,
      name: 'umd',
      params,
      slug: 'umd-loss-gain',
      version: 'v1',
      aggregate: false
    }).then(response => {
      const { data } = (response && response.data) || {};
      const gain = data && data.attributes.gain;
      const extent =
        data &&
        data.attributes[`treeExtent${params.extentYear === 2010 ? 2010 : ''}`];

      return {
        gain,
        extent
      };
    });
  },
  getWidgetProps
};

@@ -1,34 +1,4 @@
-import get from 'lodash/get';%0A
 impo
@@ -1667,45 +1667,8 @@
 %7B%7D;%0A
-        console.log('data', data%5B0%5D)%0A
     
@@ -1688,78 +1688,38 @@
 n = 
+(
 data%5B0%5D
-.gain %7C%7C 0; //get(data, 'data%5B0%5D.treecover_gain_2000-2012__ha')
+ && data%5B0%5D.gain) %7C%7C 0
 ;%0A  
@@ -1743,77 +1743,40 @@
 t = 
+(
 data%5B0%5D
-.extent %7C%7C 0; //get(data, 'data%5B0%5D.treecover_extent_2000__ha')
+ && data%5B0%5D.extent) %7C%7C 0
 ;%0A%0A 

Remove comments