<commit_before>(function () {
  'use strict'
  window.GOVUK = window.GOVUK || {}

  var adminEditionWorkflowConfirmUnpublish = {
    init: function (params) {
      this.unpublishReasonIds = params.unpublish_reason_ids

      this.revealCorrectForm()
      this.hideExplanationIfRedirecting()
      this.revealNewWithdrawalFields()

      $("input[name='unpublishing_reason_id']").change(this.revealCorrectForm)
      $('#unpublishing_redirect').change(this.hideExplanationIfRedirecting)
      $("input[name='previous_withdrawal_id']").change(this.revealNewWithdrawalFields)
    },

    revealCorrectForm: function () {
      var selectedReasonId = $("input[name='unpublishing_reason_id']:checked").val() - 0
      switch (selectedReasonId) {
        case adminEditionWorkflowConfirmUnpublish.unpublishReasonIds.Withdrawn:
          $('#js-withdraw-form').show()
          $('#js-published-in-error-form').hide()
          $('#js-consolidated-form').hide()
          break
        case adminEditionWorkflowConfirmUnpublish.unpublishReasonIds.PublishedInError:
          $('#js-withdraw-form').hide()
          $('#js-published-in-error-form').show()
          $('#js-consolidated-form').hide()
          break
        case adminEditionWorkflowConfirmUnpublish.unpublishReasonIds.Consolidated:
          $('#js-withdraw-form').hide()
          $('#js-published-in-error-form').hide()
          $('#js-consolidated-form').show()
          break
      }
    },

    hideExplanationIfRedirecting: function () {
      if ($('#unpublishing_redirect').prop('checked')) {
        $('#published_in_error_explanation').val('').closest('fieldset').hide()
      } else {
        $('#published_in_error_explanation').closest('fieldset').show()
      }
    },

    revealNewWithdrawalFields: function () {
      var withdrawalRadios = $("input[name='previous_withdrawal_id']")
      if (withdrawalRadios.length > 0) {
        var selected = withdrawalRadios.filter(':checked').val()
        $('#new-withdrawal').toggle(selected === 'new')
      }<commit_msg>Add GA tracking to unpublish/withdraw journey<commit_after>(function () {
  'use strict'
  window.GOVUK = window.GOVUK || {}

  var adminEditionWorkflowConfirmUnpublish = {
    init: function (params) {
      this.unpublishReasonIds = params.unpublish_reason_ids

      this.revealCorrectForm()
      this.hideExplanationIfRedirecting()
      this.revealNewWithdrawalFields()

      $("input[name='unpublishing_reason_id']").change(this.revealCorrectForm)
      $('#unpublishing_redirect').change(this.hideExplanationIfRedirecting)
      $("input[name='previous_withdrawal_id']").change(this.revealNewWithdrawalFields)
      $('main form').on('submit', this.trackFormSubmission)
    },

    revealCorrectForm: function () {
      var selectedReasonId = $("input[name='unpublishing_reason_id']:checked").val() - 0
      switch (selectedReasonId) {
        case adminEditionWorkflowConfirmUnpublish.unpublishReasonIds.Withdrawn:
          $('#js-withdraw-form').show()
          $('#js-published-in-error-form').hide()
          $('#js-consolidated-form').hide()
          break
        case adminEditionWorkflowConfirmUnpublish.unpublishReasonIds.PublishedInError:
          $('#js-withdraw-form').hide()
          $('#js-published-in-error-form').show()
          $('#js-consolidated-form').hide()
          break
        case adminEditionWorkflowConfirmUnpublish.unpublishReasonIds.Consolidated:
          $('#js-withdraw-form').hide()
          $('#js-published-in-error-form').hide()
          $('#js-consolidated-form').show()
          break
      }
    },

    hideExplanationIfRedirecting: function () {
      if ($('#unpublishing_redirect').prop('checked')) {
        $('#published_in_error_explanation').val('').closest('fieldset').hide()
      } else {
        $('#published_in_error_explanation').closest('fieldset').show()
      }
    },

    revealNewWithdrawalFields: function () {
      var withdrawalRadios = $("input[name='previous_withdrawal_id']")
      if (withdrawalRadios.length > 0) {
        var selected = withdrawalRadios.filter(':checked').val()
        $('#new-withdrawal').toggle(selected === 'new')
      }
    },

    trackFormSubmission: function () {
      var unpublishType = $("input[name='unpublishing_reason_id']:checked").parent().text().trim()
      GOVUKAdmin.trackEvent('WithdrawUnpublishSelection', 'WithdrawUnpublish-selection', { label: unpublishType })

      var withdrawalDate = $('input[name=previous_withdrawal_id]:checked').parent().find('strong').text().trim()
      if (withdrawalDate) {
        GOVUKAdmin.trackEvent('WithdrawUnpublishSelection', 'Withdraw-selection', { label: withdrawalDate })
      }
{'fraction_non_alphanumeric': 0.154468085106383, 'fraction_numerical': 0.000851063829787234, 'mean_word_length': 3.4771428571428573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '680573', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1374, 'n_words': 154}