/**
 * @license
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 */

CLASS({
  package: 'com.google.nbuEDU',
  name: 'Invite',

  requires: [
    'foam.u2.Element',
    'com.google.nbuEDU.ClientSignup'
  ],

  properties: [
    {
      name: 'id'
    },
    [ 'name', 'unused' ],
    {
      name: 'signupSid',
      help: 'Add an envelope with this sid to complete signup.',
      defaultValue: 'nbuEDUSignup'
    },
    {
      model_: 'StringProperty',
      name: 'titleText',
      defaultValue: 'StudyBuddy: Help with School'
    },
    {
      model_: 'StringProperty',
      name: 'description',
      defaultValue: '<p>You are invited to join the StudyBuddy community.</p><p>Tap this card to get help with school.</p>'
    },
    ['resetInviteTitle', 'StudyBuddy'],
    ['resetInviteText', '<p>Welcome! You have already enrolled.</p> <p>Tap this card to see your profile.</p>'],
    ['complete', false]
  ],

  methods: [
    function inviteComplete() {
      this.titleText = this.resetInviteTitle;
      this.description = this.resetInviteText;
      this.complete = true;
    },

    // TODO(markdittmer): We should use model-for-model or similar here.
    function toDetailE(X) {
      var self = this;
      var Y = (X || self.Y);
      return self.Element.create(null, Y).add(
        function() { //return ( self.complete ) ?
          var nY = ( self.complete ) ? Y.sub({controllerMode: 'ro'}) : Y
          //self.toCitationE(Y).add("TODO: show control panel stuff here") :
          return self.ClientSignup.create({ sid: self.signupSid }, nY).toDetailE(nY);
        }.on$(self.complete)
      );
    },
    function toCitationE(X) {
      var Y = X || this.Y;
      return this.Element.create(null, Y)
        .start().style({ 'display': 'flex', 'flex-direction': 'column', margin: '16px' })
            .start().add(this.description$).cls('md-subhead').end()
        .end()
    }
  ]
});

@@ -438,16 +438,43 @@
 '%0A  %5D,%0A%0A
+  imports: %5B 'dynamic' %5D,%0A%0A
   proper
@@ -1553,24 +1553,37 @@
 dd(%0A        
+self.dynamic(
 function() %7B
@@ -1861,13 +1861,10 @@
    %7D
-.on$(
+, 
 self
@@ -1872,16 +1872,17 @@
 complete
+$
 )%0A      

Update nbuEDU to X.dynamic.