<commit_before>class VmProductForm extends FormWorkflow

  createUpgradeForm: ->
    (KD.getSingleton 'paymentController').createUpgradeForm 'vm'

  checkUsageLimits: (pack, callback) ->
    { subscription } = @collectedData
    subscription.checkUsage pack, (err, usage) ->
      
    console.log 'we need to check the usage limits for this plan', plan

  createPackChoiceForm: -> new PackChoiceForm
    title     : 'Choose your VM'
    itemClass : VmProductView

  setState: (state) ->
    @showForm state

  setCurrentSubscriptions: (subscriptions) ->
    @currentSubscriptions = subscriptions
    switch subscriptions.length
      when 0
        @setState 'upgrade'
      when 1
        [subscription] = subscriptions
        @collectData { subscription }
        @emit 'PackOfferingRequested', subscription
      else
        @setState 'choice'

  setContents: (packs) ->
    @setState 'pack choice'
    (@getForm 'pack choice').setContents packs

  viewAppended: -> @prepareProductForm()

  prepareProductForm: ->

    @requireData ['plan', 'subscription', 'pack']

    upgradeForm = @createUpgradeForm()
    upgradeForm.on 'PlanSelected', (plan) =>
      @collectData { plan }
    @addForm 'upgrade', upgradeForm

    packChoiceForm = @createPackChoiceForm()
    packChoiceForm.on 'PackSelected', (pack) =>
      @checkUsageLimits pack, (err, usage) ->
        debugger
      # @collectData { pack }

    @addForm 'pack choice', packChoiceForm<commit_msg>payment: proceed through the workflow if quota is sufficient...<commit_after>class VmProductForm extends FormWorkflow

  createUpgradeForm: ->
    (KD.getSingleton 'paymentController').createUpgradeForm 'vm'

  checkUsageLimits: (pack, callback) ->
    { subscription } = @collectedData
    subscription.checkUsage pack, (err, usage) =>
      if err
        @clearData 'subscription'
        @setState 'upgrade'
      else
        @collectData { pack }

  createPackChoiceForm: -> new PackChoiceForm
    title     : 'Choose your VM'
    itemClass : VmProductView

  setState: (state) ->
    @showForm state

  setCurrentSubscriptions: (subscriptions) ->
    @currentSubscriptions = subscriptions
    switch subscriptions.length
      when 0
        @setState 'upgrade'
      when 1
        [subscription] = subscriptions
        @collectData { subscription }
        @emit 'PackOfferingRequested', subscription
      else
        @setState 'choice'

  setContents: (packs) ->
    @setState 'pack choice'
    (@getForm 'pack choice').setContents packs

  viewAppended: -> @prepareProductForm()

  prepareProductForm: ->

    @requireData ['subscription', 'pack']

    upgradeForm = @createUpgradeForm()
    upgradeForm.on 'PlanSelected', (plan) =>
      @collectData { plan }

    @addForm 'upgrade', upgradeForm

    packChoiceForm = @createPackChoiceForm()
    packChoiceForm.on 'PackSelected', (pack) =>
      @checkUsageLimits pack, (err, usage) ->
        debugger
      # @collectData { pack }

    @addForm 'pack choice', packChoiceForm
{'fraction_non_alphanumeric': 0.10319573901464714, 'fraction_numerical': 0.0013315579227696406, 'mean_word_length': 3.1391184573002753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5399365', 'n_tokens_mistral': 862, 'n_tokens_neox': 833, 'n_words': 215}