import Ember from 'ember';
import Base from '../mixins/base';
import DataAttributes from '../mixins/data-attributes';
import Item from './ui-dropdown-item';

export default Ember.Select.extend(Base, DataAttributes, {
  classNames: ['ui', 'dropdown'],
  module: 'dropdown',
  tagName: 'div',
  defaultTemplate: null,

  optionView: Item,

  groupedView: null,
  groupedContent: null,

  initialize: function() {
    var value = this.get('value');
    if (typeof value !== "undefined" && value !== null) {
      this.execute('set selected', value);
    }
  }.on('didInsertElement'),

  onChange: function(value, text, $element) {
    if (value === undefined) {
      // The initial set selected doesn't have an value. This is potentially a problem
      // within the main Semantic library
      //
      // https://github.com/Semantic-Org/Semantic-UI/blob/master/src/definitions/modules/dropdown.js#L85
      value = $element.data('value');
    }
    return this.set('value', value);
  },

  onUpdate: function() {
    return Ember.run.scheduleOnce('afterRender', this, this.set_value);
  }.observes('value'),

  set_value: function() {
    var dropdownValue, inputValue, _ref;
    inputValue = (_ref = this.get('value')) != null ? _ref.toString() : void 0;
    dropdownValue = this.execute("get value");
    if (inputValue == null) {
      return this.execute("restore defaults");
    } else if (inputValue !== dropdownValue) {
      return this.execute("set selected", this.get('value'));
    }
  }
});

@@ -1022,66 +1022,592 @@
 urn 
-Ember.run.scheduleOnce('afterRender', this, this.set_value
+this.$()%5Bthis.get(%22module%22)%5D(this.settings(this.get(%22module%22)));%0A  %7D.observes('value'),%0A%0A  onContentChange: function() %7B%0A    // Wait for the afterRender portion of the Run Loop to complete after%0A    // after a content change. Once that happens, re-initialize the%0A    // Semantic component the same way as Semantic.BaseMixin%0A    //%0A    // Without this, Dropdown Items will not be clickable if the content%0A    // is set after the initial render.%0A    Ember.run.schedule('afterRender', this, function() %7B%0A      return this.$()%5Bthis.get(%22module%22)%5D(this.settings(this.get(%22module%22)));%0A    %7D
 );%0A 
@@ -1615,29 +1615,31 @@
 %7D.observes('
-value
+content
 '),%0A%0A  set_v

Fix issue with Semantic UI Dropdown Items not being clickable after being set in Promise