<commit_before>import Ember from 'ember';

const {
  Component,
  isEmpty,
  isNone,
  observer
 } = Ember;
const DEFAULT_TIME_FORMAT = 'hh-i';

/**
 * @public
 *
 * @param disabled - (boolean) Disable the timepicker
 * @param placeholder - (string) The text to display in the input when nothing is selected
 * @param options - (object) Options available via the pick-a-date API
 * @param date - (Date) The inital date to display
 * @param on-selected - (function) Called when a time is selected and passed the new date as the first argument.
 * @param nulls-date - (boolean) If true, will set the date to null when the clear button is pressed.
 *                               If false, will set the time part to 0 only when the clear button is pressed, the date part is unaffected.
 */
export default Component.extend({
  tagName: 'input',
  attributeBindings: ['placeholder', 'disabled', 'type'],
  disabled: null,
  type: 'text',
  placeholder: "Select a time",
  picker: null,
  date: null,
  classNames: ['ember-pick-a-time'],

  didInsertElement() {
    const options = this.attrs.options || {};
    options.onClose = options.onClose || this.onClose;
    options.onSet = () => {
      this.onSelected();
    };
    this.$().pickatime(options);
    this.set('picker', this.$().pickatime('picker'));
  },

  didRender() {
    this.updateInputText();
    this.toggleInputDisabled();
  },

  updateInputText() {
    const date = this.get('date');
    const options = this.attrs.options || {};
    const format = options.format || DEFAULT_TIME_FORMAT;
    const picker = this.get('picker');

    if (!picker.get('open')) {
      picker.set('select', date, {
        format: format,
        muted: true
      });
    }
  },

  toggleInputDisabled: function() {
    if(this.get('disabled')) {
      this.get('picker').stop();
      this.$().prop('disabled', true); // pick-a-date is doing funny things with the disabled attribute
    } else {
      this.get('picker').start();
      this.$().prop('disabled', false);
    }
  },

  dateChanged: observer('date', function() {
    this.updateInputText()
  }),

  optionsChanged: observer('options', function() {
    let options = this.attrs.options;<commit_msg>don't use attrs as it's not updated before computed props are fired<commit_after>import Ember from 'ember';

const {
  Component,
  isEmpty,
  isNone,
  observer
 } = Ember;
const DEFAULT_TIME_FORMAT = 'hh-i';

/**
 * @public
 *
 * @param disabled - (boolean) Disable the timepicker
 * @param placeholder - (string) The text to display in the input when nothing is selected
 * @param options - (object) Options available via the pick-a-date API
 * @param date - (Date) The inital date to display
 * @param on-selected - (function) Called when a time is selected and passed the new date as the first argument.
 * @param nulls-date - (boolean) If true, will set the date to null when the clear button is pressed.
 *                               If false, will set the time part to 0 only when the clear button is pressed, the date part is unaffected.
 */
export default Component.extend({
  tagName: 'input',
  attributeBindings: ['placeholder', 'disabled', 'type'],
  disabled: null,
  type: 'text',
  placeholder: "Select a time",
  picker: null,
  date: null,
  classNames: ['ember-pick-a-time'],

  didInsertElement() {
    const options = this.attrs.options || {};
    options.onClose = options.onClose || this.onClose;
    options.onSet = () => {
      this.onSelected();
    };
    this.$().pickatime(options);
    this.set('picker', this.$().pickatime('picker'));
  },

  didRender() {
    this.updateInputText();
    this.toggleInputDisabled();
  },

  updateInputText() {
    const date = this.get('date');
    const options = this.attrs.options || {};
    const format = options.format || DEFAULT_TIME_FORMAT;
    const picker = this.get('picker');

    if (!picker.get('open')) {
      picker.set('select', date, {
        format: format,
        muted: true
      });
    }
  },

  toggleInputDisabled: function() {
    if(this.get('disabled')) {
      this.get('picker').stop();
      this.$().prop('disabled', true); // pick-a-date is doing funny things with the disabled attribute
    } else {
      this.get('picker').start();
      this.$().prop('disabled', false);
    }
  },

  dateChanged: observer('date', function() {
    this.updateInputText()
  }),

  optionsChanged: observer('options', function() {
    let options = this.get('options');
{'fraction_non_alphanumeric': 0.14471035562513979, 'fraction_numerical': 0.00044732721986132855, 'mean_word_length': 3.091491308325709, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4868266', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1291, 'n_words': 402}