
import {BindingEngine, inject} from 'aurelia-framework';
import {EventAggregator} from 'aurelia-event-aggregator';
import {DialogService} from 'aurelia-dialog';
import {Confirm} from './confirm';
//import {HttpClient} from 'aurelia-fetch-client';
//import 'fetch';
import {Storage} from './helpers/storage';
import {BaseConfig} from './helpers/baseconfig';
import {Clone} from './helpers/clone';
import $ from 'jquery';


//@inject(HttpClient, Storage, Swag, ObserverLocator, BaseConfig)
@inject(BindingEngine, BaseConfig, Clone, EventAggregator, DialogService)

export class Welcome {

    //constructor(http, storage) {
    constructor(bindingEngine, config, clone, eventAggregator, dialogService) {

        //this.swag = swag;
        this.clone = clone;
        this.eventAggregator = eventAggregator;
        this.dialogService = dialogService;

        //this.storage.set("test", "rippo");

        this.swagEnabled = true;
        this.noSwagOrAttendeesLeft = false;

        this.eventAggregator.subscribe('change.swag.button.state', (state) => {
            if (!this.noSwagOrAttendeesLeft)
                this.swagEnabled = state
        });
        //this.eventAggregator.subscribe('change.put.back.button.state', (state) => this.putBackEnabled = state);
        //this.eventAggregator.subscribe('count.unwon.swag.is', (count) => this.swagEnabled = (count > 0));
        
        this.eventAggregator.subscribe('no.winners.or.swag.left', (state) => {
            this.noSwagOrAttendeesLeft = state;
            this.swagEnabled = !state;
        });
        

        // http.configure(config => {
        //   config
        //     .useStandardConfiguration()
        //     .withBaseUrl('http://localhost:6648/');
        // });
        
    }



    activate() {
        // return this.http.fetch('home/memberlist')
        //   .then(response => response.json())
        //   .then(users => this.attendeeList = users);
    }

    reset() {
        this.dialogService.open({ viewModel: Confirm, model: 'Are you sure you want to reset?' }).then(response => {
            if (!response.wasCancelled) {
                self.location.href = "/";
            }
        });
    }
    
    //Selects random winner
    random() {
        this.eventAggregator.publish("swag.clicked");
    }


};
@@ -1,17 +1,16 @@
-%0A
 import %7BBindingE
@@ -189,18 +189,16 @@
 nfirm';%0A
-//
 import %7B
@@ -242,26 +242,8 @@
 t';%0A
-//import 'fetch';%0A
 impo
@@ -395,18 +395,16 @@
 ery';%0A%0A%0A
-//
 @inject(
@@ -419,60 +419,8 @@
 nt, 
-Storage, Swag, ObserverLocator, BaseConfig)%0A@inject(
 Bind
@@ -510,18 +510,16 @@
  %7B%0A%0A    
-//
 construc
@@ -532,35 +532,8 @@
 tp, 
-storage) %7B%0A    constructor(
 bind
@@ -1048,238 +1048,8 @@
 %7D);%0A
-        //this.eventAggregator.subscribe('change.put.back.button.state', (state) =%3E this.putBackEnabled = state);%0A        //this.eventAggregator.subscribe('count.unwon.swag.is', (count) =%3E this.swagEnabled = (count %3E 0));%0A        
 %0A   
@@ -1223,24 +1223,16 @@
     %7D);%0A
-        
 %0A%0A      
@@ -1232,19 +1232,16 @@
 %0A       
- //
  http.co
@@ -1268,18 +1268,17 @@
         
-//
+ 
    confi
@@ -1283,26 +1283,27 @@
 fig%0A        
-//
+   
      .useSta
@@ -1331,18 +1331,19 @@
         
+   
-//
      .wi
@@ -1364,34 +1364,39 @@
 p://
-localhost:6648
+meetup.wildesoft.net
 /')
-;
 %0A       
  // 
@@ -1395,24 +1395,22 @@
     
- //
  %7D);%0A
+%0A
         
 %0A   
@@ -1405,24 +1405,41 @@
         
+this.http = http;
 %0A    %7D%0A%0A
 %0A%0A    ac
@@ -1430,18 +1430,16 @@
 %0A    %7D%0A%0A
-%0A%0A
     acti
@@ -1447,26 +1447,24 @@
 ate() %7B%0A
+%0A
        
- //
  return 
@@ -1484,23 +1484,21 @@
 ch('
-home/memberlist
+api/attendees
 ')%0A 
@@ -1496,34 +1496,33 @@
 ndees')%0A        
-//
+ 
    .then(respons
@@ -1551,18 +1551,17 @@
         
-//
+ 
    .then
@@ -1574,34 +1574,27 @@
  =%3E 
-this.attendeeList = 
+console.log(
 users)
+)
 ;%0A  

Test pulling back attendees from my meetup api