import Conductor from 'conductor';
import TestConsumer from 'app/consumers/test';

/* Uncomment/add required javascript files */
Conductor.require('/vendor/jquery.js');
Conductor.require('/vendor/handlebars.js');
Conductor.require('/vendor/ember-latest.js');
//Conductor.require('/vendor/resolver.js'); // if you are using Ember

/* css files */
Conductor.requireCSS('/css/glazier_card.css');
Conductor.requireCSS('card.css');

var card = Conductor.card({
  /* uncomment or add needed services here */
  consumers: {
    //'fullXhr': Conductor.Oasis.Consumer,
    //'paneUserStorage': Conductor.Oasis.Consumer,
    //'authenticatedGithubApi': Conductor.Oasis.Consumer,
    //'unauthenticatedGithubApi': Conductor.Oasis.Consumer,
    'test': TestConsumer

  },
  defaultContentDiv: "<div id=\"card\"></div>",
  bootstrapDiv: "<div id=\"card\">Hello New Card!! (remove me from /card.js)</div>",
  render: function (intent, dimensions) {

    document.body.innerHTML = this.bootstrapDiv;   //this.defaultContentDiv
    /*
      After verifying card bootstrapped, replace this.bootstrapDiv with
      this.defaultContentDiv and you can delete the bootstrapDiv property
import Conductor from 'conductor';
import AuthenticatedStackoverflowApiConsumer from 'app/consumers/authenticated_stackoverflow_api';
var RSVP = Conductor.Oasis.RSVP;

Conductor.require('/vendor/jquery.js');
Conductor.requireCSS('card.css');

var card = Conductor.card({
  consumers: {
    'oauth': Conductor.Oasis.Consumer.extend({
      getAccessTokenPromise: function(){
        var now = +new Date();
        var accessToken = card.data.paneTypeUserEntries.stackOverflowAccessToken;
        var expiresAt = card.data.paneTypeUserEntries.stackOverflowAccessTokenExpiresAt;
        if (accessToken && expiresAt && expiresAt > now) {
          return RSVP.resolve(accessToken);
        }

        var url = 'https://stackexchange.com/oauth/dialog';
        return this.request('authorize', {
          authorizeUrl: url
        }).then(function(data) {
          var accessToken = data.access_token;
          var expires = data.expires; // seconds
          var expiresMs = expires * 1000;
          var expiresAt = now + expiresMs;

          var paneTypeUserStorage = card.consumers.paneTypeUserStorage;

          paneTypeUserStorage.request(
            'setItem', 'stackOverflowAccessToken', accessToken