import Ember from 'ember';

var Checkbox = Ember.Object.extend({
  isSelected: Ember.computed('value', 'selection', function (_, checked) {
    if (arguments.length > 1) {
      var selected = this.get('selection').contains(this.get('value'));

      if (checked && !selected) {
        this.get('selection').addObject(this.get('value'));
      } else if (!checked && selected) {
        this.get('selection').removeObject(this.get('value'));
      }
    }

    return this.get('selection').contains(this.get('value'));
  })
});

export default Ember.Component.extend({
  classNames: ['multiselect-checkboxes'],

  tagName: 'ul',

  options: Ember.A(),

  selection: Ember.A(),

  labelProperty: null,

  valueProperty: null,

  disabled: false,

  checkboxes: Ember.computed('options', 'labelProperty', 'valueProperty', 'selection', function () {
    var labelProperty = this.get('labelProperty');
    var valueProperty = this.get('valueProperty');
    var selection = this.get('selection');

    var checkboxes = this.get('options').map((option) => {
      var label, value;

      if (labelProperty) {
        if (typeof option.get === 'function') {
          label = option.get(labelProperty);
        } else {
          label = option[labelProperty];
        }
      } else {
        label = String(option);
      }

      if (valueProperty) {
        if (typeof option.get === 'function') {
          value = option.get(valueProperty);
        } else {
          value = option[valueProperty];
        }
      } else {
        value = option;
      }

      return Checkbox.create({
        label: label,
        value: value,
        selection: selection
      });
    });

    return Ember.A(checkboxes);
  })
});

@@ -113,60 +113,111 @@
 n', 
-function (_, checked) %7B%0A    if (arguments.length %3E 1
+%7B%0A    get() %7B%0A      return this.get('selection').contains(this.get('value'));%0A    %7D,%0A    set(_, checked
 ) %7B%0A
@@ -495,23 +495,19 @@
       %7D%0A
+%0A
   
-  %7D%0A%0A
     retu
@@ -513,58 +513,22 @@
 urn 
-this.get('selection').contains(this.get('value'));
+checked;%0A    %7D
 %0A  %7D

update to new computed syntax