/* eslint-disable prefer-template */
import {component} from 'flightjs';
import $ from 'jquery';
import queryString from 'query-string';

export default component(function lookback() {
  this.onChange = function() {
    if (this.$node.val() === 'custom') {
      $('#custom-lookback').show();
    } else {
      $('#custom-lookback').hide();
    }
  };

  this.render = function() {
    const selectedLookback = queryString.parse(window.location.search).lookback;
    this.$node.find('option').each((i, option) => {
      const $option = $(option);
      if ($option.val() === selectedLookback) {
        $option.prop('selected', true);
      }
    });
  };

  this.after('initialize', function() {
    this.render();

    this.on('change', this.onChange);
  });
});

@@ -185,24 +185,35 @@
 %0A  this.
-onChange
+refreshCustomFields
  = funct
@@ -721,16 +721,48 @@
 ender();
+%0A    this.refreshCustomFields();
 %0A%0A    th
@@ -786,16 +786,27 @@
 his.
-onChange
+refreshCustomFields
 );%0A 

refresh extra custom date fields on page load (#1929)