/* global $ */
import Ember from 'ember';

export default Ember.Component.extend({
  session: Ember.inject.service(),
  tagName: 'li',
  classNames: ['b-order-group'],

  isManager: Ember.computed(function() {
    return this.get('session.account.id') !== this.get('order.manager.id');
  }),

  canDelete: Ember.computed('order.active', function() {
    const currentAccountId = this.get('session.account.id');
    const order = this.get('order');

    if (order.get('active')) {
      return (currentAccountId === this.get('order.manager.id'));
    } else {
      return false;
    }
  }),

  allPaid: Ember.computed('portions.@each.paid', function() {
    return this.get('portions').isEvery('paid', true);
  }),

  click: (e) => {
    const target = $(e.target);

    if (target.hasClass('checkbox__text') || target.hasClass('checkbox__control')) {
      e.stopPropagation();
      return;
    }

    const elem = (e.target === this) ? target : target.parents('.b-order-group');

    if (!elem.length) {
      return;
    }

    elem.find('.b-order-group__summary').slideToggle(100);
  },

  actions: {
    removeAll() {
      const order = this.get('order');
      this.get('portions').forEach((portion) => {
        order.removePortion(portion);
        portion.set('deleted', true);
        portion.save();
      });
      order.save();
    },

    toggleAll() {
      const value = this.get('allPaid');
      this.get('portions').forEach((portion) => {
        if (portion.get('paid') === value) {
          portion.set('paid', !value);
          portion.updateOrderMoney();
          portion.save();
        }
      });
    }
  }
});

@@ -541,25 +541,76 @@
 d'))
-;
+ %7C%7C
 %0A    
-%7D else %7B%0A  
+         (currentAccountId === this.get('owner.id'));%0A    %7D%0A
     
@@ -623,22 +623,16 @@
  false;%0A
-    %7D%0A
   %7D),%0A%0A 

Allow delete portion for portion’s author as well