 
   getAggregatedData: -> @aggregatedData
 
-  createPaymentMethodChoiceForm:->
+  createChoiceForm:->
     form = new KDFormViewWithFields
       callback              : (formData) =>
         @addAggregateData formData

          callback          : =>
            @setState 'billing entry'

  createPaymentMethodEntryForm: ->

    form = new BillingForm

    paymentController = KD.getSingleton 'paymentController'
    paymentController.observePaymentSave form, (err, { accountCode }) =>
      @addAggregateData { accountCode }
      @setState 'confirm'

    form

  hideAllForms: ->
    @vmTypeForm.hide()
    @paymentMethodChoiceForm.hide()
    @paymentMethodEntryForm.hide()
    @confirmForm.hide()

  setState: (state) ->
    @hideAllForms()
    switch state
      when 'vm type'          then @vmTypeForm.show()
      when 'billing choice'   then @paymentMethodChoiceForm.show()
      when 'billing entry'    then @paymentMethodEntryForm.show()
      when 'confirm'
        @confirmForm.setData @getAggregatedData()
        @confirmForm.show()


          @setState 'billing entry'

        when 1 then do ([method] = methods) =>

          paymentField.addSubView new BillingMethodView {}, method

          @choiceForm.addCustomData 'accountCode', method.accountCode

        else

          paymentField.addSubView new KDSelectBox
            defaultValue  : preferredAccountCode ? methods[0].accountCode
            name          : 'accountCode'
            selectOptions : methods.map (method) ->
              title       : KD.utils.getPaymentMethodTitle method
