/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ "./assets/js/utility.js":
/*!******************************!*\
  !*** ./assets/js/utility.js ***!
  \******************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "getFaqIndex": () => (/* binding */ getFaqIndex),
/* harmony export */   "checkEditorContent": () => (/* binding */ checkEditorContent),
/* harmony export */   "checkEmptyContent": () => (/* binding */ checkEmptyContent)
/* harmony export */ });
/* eslint-disable no-undef */
// Return FAQ index number from question or answer ID.
const getFaqIndex = (faqItemId, separator = '_') => {
  const faqIdPart = faqItemId.split(separator);
  const faqIndex = faqIdPart[faqIdPart.length - 1]; //("getFaqIndex: ", faqItemId, faqIndex);

  return faqIndex;
};
const checkEditorContent = faqIndex => {
  //console.log('CHK INDEX:', faqIndex);
  // Generate element ID's.
  const questionId = 'question_edit_' + faqIndex;
  const answerId = 'answer_edit_' + faqIndex;
  let qContent, aContent; // console.log(
  // 	'CHECK EDITOR TINYMCE',
  // 	Boolean(tinyMCE.editors[questionId])
  // );
  // console.log(
  // 	'CHECK EDITOR TEXTAREA',
  // 	document.querySelector(`#${questionId}`).textContent
  // );
  // Check if question/answer editor content is empty or just contains whitespace.
  // If TinyMCE not instantiated then use textarea value.

  qContent = Boolean(tinyMCE.editors[questionId]) ? tinyMCE.editors[questionId].getContent() : document.querySelector(`#${questionId}`).textContent;
  qContent = qContent.replace(/(<([^>]+)>)/gi, '').replace(/\s/g, '');
  aContent = Boolean(tinyMCE.editors[answerId]) ? tinyMCE.editors[answerId].getContent() : document.querySelector(`#${answerId}`).textContent;
  aContent = aContent.replace(/(<([^>]+)>)/gi, '').replace(/\s/g, ''); // console.log('>>> Q:', qContent.trim(), qContent.trim().length);
  // console.log('>>> A:', aContent.trim(), aContent.trim().length);

  return [!qContent.trim(), !aContent.trim()];
};
const checkEmptyContent = (qContent, aContent) => {
  // Generate element ID's.
  //const questionId = 'question_edit_' + faqIndex;
  //const answerId = 'answer_edit_' + faqIndex;
  //let qContent, aContent;
  // console.log(
  // 	'CHECK EDITOR TINYMCE',
  // 	Boolean(tinyMCE.editors[questionId])
  // );
  // console.log(
  // 	'CHECK EDITOR TEXTAREA',
  // 	document.querySelector(`#${questionId}`).textContent
  // );
  // Check if question/answer editor content is empty or just contains whitespace.
  // If TinyMCE not instantiated then use textarea value.
  //qContent = Boolean(tinyMCE.editors[questionId]) ? tinyMCE.editors[questionId].getContent() : document.querySelector(`#${questionId}`).textContent;
  qContent = qContent.replace(/(<([^>]+)>)/gi, '').replace(/\s/g, ''); //aContent = Boolean(tinyMCE.editors[answerId]) ? tinyMCE.editors[answerId].getContent() : document.querySelector(`#${answerId}`).textContent;

  aContent = aContent.replace(/(<([^>]+)>)/gi, '').replace(/\s/g, '');
  const empty = !qContent.trim() || !aContent.trim() ? true : false; // console.log('>>> Q:', qContent.trim(), qContent.trim().length);
  // console.log('>>> A:', aContent.trim(), aContent.trim().length);

  return empty;
};

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/define property getters */
/******/ 	(() => {
/******/ 		// define getter functions for harmony exports
/******/ 		__webpack_require__.d = (exports, definition) => {
/******/ 			for(var key in definition) {
/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	(() => {
/******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/make namespace object */
/******/ 	(() => {
/******/ 		// define __esModule on exports
/******/ 		__webpack_require__.r = (exports) => {
/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 			}
/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
/******/ 		};
/******/ 	})();
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
/*!********************************!*\
  !*** ./assets/js/cpt-admin.js ***!
  \********************************/
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _utility__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utility */ "./assets/js/utility.js");

/* eslint-disable @wordpress/no-global-event-listener */

/* eslint-disable no-undef */

/* JavaScript for the FAQ editor screen only. */

jQuery(document).ready(function ($) {
  // -----------------------------------------
  // INITIALIZE VARIABLES
  // -----------------------------------------
  window.wpgo_flexible_faqs__cpt_edit_dirty = false; // set to true if any faq item has been edited / created

  window.faqIdCounter = 1;
  const thumbnailId = $('.post-type-wpgo_faq').find('#_thumbnail_id').val(); // get initial feature image id on page load, -1 if image is not assigned
  // -----------------------------------------
  // FAQ FUNCTION DEFINITIONS
  // -----------------------------------------
  // Define FAQ item template.

  window.faqAdminTemplate = function faqAdminTemplate(question, answer, id, isNew, index = -1) {
    let headToggle; // Remove markup from the question preview text displayed in collapsed view.

    if (question.length !== 0) {
      headToggle = question.replace(/(<p[^>]+?>|<p>|<\/p>)/gim, '');
    } else {
      headToggle = '';
    }

    const emptyFAQ = wp.hooks.applyFilters('empty-faq-item-class', {
      class: '',
      title: ''
    }, question, answer, isNew);
    const {
      disableFaqItem,
      classForDisabledItem
    } = wp.hooks.applyFilters('disable-faq-item', {
      disableFaqItem: '',
      classForDisabledItem: ''
    }, index, window.faqIdCounter);
    const editIconClass = isNew ? 'dashicons-arrow-up-alt2' : 'dashicons-edit';
    const editIconTitle = isNew ? 'Close FAQ editor' : 'Edit FAQ item';
    let contentFaq = `<div class="postbox closed faq-form-box visual-mode-only${classForDisabledItem}"><h2 id="question_edit_${id}-heading" class="outer-heading"${emptyFAQ.title}><span class="dashicons dashicons-menu drag-handle drag-icon${emptyFAQ.class}"></span><span class="question-text">${headToggle}</span><span class="pull-right"><span title="${editIconTitle}" class="toggle-button dashicons ${editIconClass}"></span><span title="Remove FAQ item" class="dashicons dashicons-no remove-faq"></span></span>${disableFaqItem}</h2>`;
    contentFaq += `<div class="inside"><div class="question-container"><h2 class="faq-heading question">Question</h2><textarea id="question_edit_${window.faqIdCounter}" class="full-width question-input" name="wpgo_faq_cpt_questions[]" placeholder="Ask me a question!">${question}</textarea></div>`;
    contentFaq += `<div class="answer-container"><h2 class="faq-heading answer">Answer</h2><textarea id="answer_edit_${window.faqIdCounter}" class="full-width answer-input" name="wpgo_faq_cpt_answers[]" placeholder="Add you\'re answer here&hellip;">${answer}</textarea></div><div class="close-faq"><a href="#" class="button faq-done-btn">Close this FAQ item</a></div></div></div>`;
    return contentFaq;
  }; // Add TinyMCE editor instance.


  window.addTinymce = function (id, addMedia) {
    //console.log('addTinyMCE', id);
    if (typeof tinyMCE === 'object' && typeof tinyMCE.execCommand === 'function') {
      wp.editor.initialize(id, {
        tinymce: {
          selector: 'textarea',
          wpautop: false,
          content_style: 'body { font-size: 15px; }',

          setup(ed) {
            // Resize the Q/A editor container height when Q or A editor (height) has been resized by the user.
            ed.on('ResizeEditor', function (e) {
              const el = $('#' + this.id);
              const containerEl = el.closest('.inside.expanded');
              const qContainerHeight = containerEl.find('.question-container').height();
              const aContainerHeight = containerEl.find('.answer-container').height();
              const closeButtonHeight = containerEl.find('.close-faq').height();
              const offSet = 34; //const edHeight = el.parent().height();
              //const edContainerHeight = el.parent().parent().height();

              el.parent().parent().height(qContainerHeight + aContainerHeight + closeButtonHeight + offSet);
            });
            ed.on('focusout', function (e) {
              //e.target.triggerSave();
              const ed_id = ed.id; // Use the checkbox index

              const chkIndex = $('#' + this.id).closest('.inside').siblings('.outer-heading').find('.disable-faq-item input').attr('value'); //console.log('ED ID: ', ed_id);
              //console.log('CHK INDEX: ', chkIndex);

              wp.hooks.doAction('q-a-editor-blur', ed_id, ed, chkIndex);
            });
            ed.on('change', function (e) {//tinymce.get(id).save();
              //tinymce.activeEditor.triggerSave();
              //tinyMCE.triggerSave('998877');
              //ed.save();
              // tinymce.triggerSave();
            });
            ed.on('keyup', function (e) {
              //ed.save();
              // Update question heading content in realtime as the user types.
              if (id.includes('question')) {
                //console.log("Inside question editor: ", '#' + id + '-heading', $('#question_edit' + id + '-heading .question-text'));
                // find associated heading element
                $('#' + id + '-heading .question-text').html(e.target.innerHTML.replace(/(<p[^>]+?>|<p>|<\/p>)/gim, ''));
              }

              if (id.includes('answer')) {//.log("Inside answer editor: ", id);
              }

              if (e.keyCode == 27) {
                // escape key
                //console.log("ESCAPE KEY PRESSED: ", $(this));
                //console.log("ID: ", id.split(/[_]+/).pop());
                const qId = id.split(/[_]+/).pop();
                $('#question_edit_' + qId + '-heading').closest('.faq-form-box').toggleClass('closed opened').find('.inside').toggleClass('expanded').prev().children('.dashicons-menu').toggleClass('drag-handle'); //.toggleClass('drag-handle', toggleCallback);

                const toggleBtn = $('#question_edit_' + qId + '-heading').closest('.faq-form-box').find('.toggle-button'); // Toggle edit icon title.

                toggleEditIconTitle(toggleBtn);
              } // make sure basic html works. i.e. bold, italic etc.
              //console.log("Key up", $(this), id.includes("question"), id, e);


              window.wpgo_flexible_faqs__cpt_edit_dirty = true; // prompt to save changes before leaving page
            });
          }

        },
        quicktags: false,
        //true,
        mediaButtons: addMedia
      }); //console.log("EDDIE", tinyMCE);
      // get tinymce instance of wp default editor
      //var ed = tinyMCE.getInstanceById(id);
      // add a callback to tinyMCE.onKeyUp event
      //tinyMCE.onKeyUp = function (one) {
      // format: text will strip html tags
      //console.log('UPP'); //ed.getContent({ format: 'text' })).length;
      //$(this).closest('.faq-form-box').find('.outer-heading > .question-text').html(currentText);
      //};
    }
  }; // Note: we're also giving focus to the Q editor when closing the FAQ item but it doesn't really matter here
  // as long as nothing else is affected.


  function expandFaq(e) {
    e.preventDefault(); //console.log('expandFaq');
    // Get the current Questions postbox

    const postbox = e.target.closest('.faq-form-box'); // Control will enter this when the toggle icon is clicked for the first time after page load.
    // wpgo_mce_initialized will remain undefined until TinyMCE has been initialized.

    if (undefined == postbox.wpgo_mce_initialized) {
      initializeEditors(postbox);
    }

    const toggleBtn = $(this).closest('.faq-form-box').find('.toggle-button');
    $(this).closest('.faq-form-box').toggleClass('closed opened').find('.inside').toggleClass('expanded').removeAttr('style').prev().children('.dashicons-menu').toggleClass('drag-handle'); //.toggleClass('drag-handle', toggleCallback);
    // Toggle edit icon title (displayed on hover).

    toggleEditIconTitle(toggleBtn);
    $(this).closest('.faq-form-box').find('.outer-heading').each(function () {
      const tmpID = $(this).attr('id');
      tinyMCE.get($(this).attr('id').replace('-heading', '')).focus();
    }); // Collapse inactive FAQ items.

    const editorId = $(postbox).find('h2').attr('ID');
    wp.hooks.doAction('collapse_inactive_faq_items', editorId);
  }

  function initializeEditors(postbox) {
    // $(postbox)
    // 	.closest('.faq-form-box')
    // 	.find('.question-text')
    // 	.append('<span class="question-spinner spinner"></span>');
    addTinymce(postbox.querySelector('.question-input').getAttribute('id'), false);
    addTinymce(postbox.querySelector('.answer-input').getAttribute('id'), true);
    postbox.wpgo_mce_initialized = true; // $(postbox).closest('.faq-form-box').find('.question-spinner').remove();
  } // function toggleCallback() {
  // 	// Trigger change on bulkAction "select" element to update "Apply" button's status.
  // 	$('#wpgo-faq-cpt #wpgo-faq-bulk-actions').trigger('change');
  // }


  function toggleEditIconTitle(toggleBtn) {
    if (toggleBtn.closest('.faq-form-box').find('.inside').hasClass('expanded')) {
      toggleBtn.removeClass('dashicons-edit').addClass('dashicons-arrow-up-alt2');
      toggleBtn.attr('title', 'Close FAQ editor');
    } else {
      toggleBtn.removeClass('dashicons-arrow-up-alt2').addClass('dashicons-edit');
      toggleBtn.attr('title', 'Edit FAQ item');
    }
  } // -----------------------------------------
  // ACTIONS ON PAGE LOAD
  // -----------------------------------------
  // Remove the spinner inside the FAQ meta box.
  // eslint-disable-next-line no-undef


  if (wpgo_faq.faq_questions.length >= 0) {
    $('.wpgo-spinner').remove();
  } // Prevent FAQ metabox container from being dragged so we can safely add the TinyMCE editor.


  document.querySelector('#wpgo-faq-cpt h2').classList.remove('hndle', 'ui-sortable-handle'); // Make the FAQ items sortable.

  const sortableObj = {
    axis: 'y',
    placeholder: 'placeholder-view',
    containment: 'parent',
    handle: '.drag-handle',
    cursor: 'move',

    update(e, ui) {
      const cmdRemove = parseInt(tinymce.majorVersion) >= 4 ? 'mceRemoveEditor' : 'mceRemoveControl';
      const cmdAdd = parseInt(tinymce.majorVersion) >= 4 ? 'mceAddEditor' : 'mceAddControl';
      const currentFAQItem = $(this).data('ui-sortable').currentItem[0];
      const currentQuestion = $(currentFAQItem).find('.inside .question-input');
      const currentAnswer = $(currentFAQItem).find('.inside .answer-input');
      const currentQuestionId = currentQuestion[0].id;
      const currentAnswerId = currentAnswer[0].id; // If tinyMCE editor is not present, it will just throw an error so initialize it first.

      const postbox = $(`#${currentQuestionId}`).closest('.faq-form-box').get(0);

      if (undefined == postbox.wpgo_mce_initialized) {
        addTinymce(currentQuestionId, false);
        addTinymce(currentAnswerId, true);
        postbox.wpgo_mce_initialized = true;
      }

      const edQ = tinyMCE.get(currentQuestionId);
      const edA = tinyMCE.get(currentAnswerId);
      const contentQ = edQ.getContent();
      const contentA = edA.getContent(); // Disable the 'Question' editor.

      tinymce.execCommand(cmdRemove, false, currentQuestionId); // Immediately re-enable the 'Question' editor

      tinymce.execCommand(cmdAdd, false, currentQuestionId); // Replace the content with what it was to correct paragraphs

      edQ.setContent(contentQ); // If 'Text' editor mode enabled need to force click on the 'Text' tab to make the UI work properly

      if (edQ.isHidden()) {
        $('#' + currentQuestionId + '-html').click();
      } // Disable the 'Answer' editor.


      tinymce.execCommand(cmdRemove, false, currentAnswerId); // Immediately re-enable the 'Answer' editor.

      tinymce.execCommand(cmdAdd, false, currentAnswerId); // Replace the content with what it was to correct paragraphs.

      edA.setContent(contentA); // If 'Text' editor mode enabled need to force click on the 'Text' tab to make the UI work properly.
      // @todo Don't need this anymore?

      if (edA.isHidden()) {
        $('#' + currentAnswerId + '-html').click();
      }

      wp.hooks.doAction('reindex-disable-chk'); // Trigger dirty mode when sort order changed.

      window.wpgo_flexible_faqs__cpt_edit_dirty = true;
    },

    change(event, ui) {},

    stop(event, ui) {// Fire action hook when FAQ items sort order changed.
      //wp.hooks.doAction('reindex-disable-chk');
    } // start: function( e, ui ){
    // 	ui.placeholder.height(ui.item.height());
    // }


  };
  $('#output-faq').sortable(sortableObj); // Render FAQ items on page load.

  $(wpgo_faq.faq_questions).each(function (index, value) {
    const faqContent = faqAdminTemplate(value, wpgo_faq.faq_answers[index], window.faqIdCounter, false, index);
    $('#output-faq').append(faqContent); //addTinymce("question_edit_" + window.faqIdCounter, false);
    //addTinymce("answer_edit_" + window.faqIdCounter, true);

    wp.hooks.doAction('ffaq_initialize_empty_faqs', window.faqIdCounter);

    if (index === wpgo_faq.faq_questions.length - 1) {
      wp.hooks.doAction('ffaq_initialize_stats', window.faqIdCounter);
    }

    window.faqIdCounter++; // Increment counter to next id number.
  }); // Initialize the first TinyMCE editor on page load. This fixes a visual glitch when adding the first FAQ item just after page load.

  if (wpgo_faq.faq_questions == 0) {
    $('#output-faq').append(`<div id="wpgo_initialize_tinyMCE" style="display: none;"><textarea id="wpgo_empty_tinyMCE"></textarea></div>`);
    wp.editor.initialize('wpgo_empty_tinyMCE', {
      tinymce: {
        wpautop: false,
        content_style: 'body { font-size: 15px; }',

        setup(ed) {
          // console.log(ed)
          setTimeout(() => {
            $('#wpgo_initialize_tinyMCE').get(0).remove();
          }, 500);
        }

      },
      quicktags: false,
      mediaButtons: true
    });
  } else {
    addTinymce('question_edit_1', false);
    addTinymce('answer_edit_1', true);
    const postbox = $('#question_edit_1').get(0).closest('.faq-form-box');
    postbox.wpgo_mce_initialized = true;
  } // -----------------------------------------
  // EVENT LISTENERS
  // -----------------------------------------
  // Detects when the window is about to be unloaded so we can cancel if necessary.


  window.addEventListener('beforeunload', function (e) {
    const newThumbnailId = $('.post-type-wpgo_faq').find('#_thumbnail_id').val(); // Get feature image id before leaving page.
    // If new image id is not equal to old image id, set error flag to true.

    if (thumbnailId != newThumbnailId) {
      window.wpgo_flexible_faqs__cpt_edit_dirty = true;
    } // Restrict user from leaving the page before saving the changes.


    if (window.wpgo_flexible_faqs__cpt_edit_dirty) {
      // 'save-post' is the id for saving as draft
      // Skip alert if user clicks on Publish or Save draft button.
      if (document.activeElement.id === 'publish' || document.activeElement.id === 'save-post') {
        return; // Ignore prompt when saving changes.
      }

      e.returnValue = 'o/';
    }
  }); // Add FAQ item when the 'Add New FAQ' button clicked.

  $(document.body).on('click', '.add-faq', function (e) {
    e.preventDefault();
    const faqContent = faqAdminTemplate('', '', window.faqIdCounter, true);
    const currentFaqIndex = window.faqIdCounter; // Hide no faqs message when the add new FAQ button is clicked.

    $('#output-faq .add-faq-msg').addClass('display-none');

    if ($(this).next('.add-sample-faq').length > 0) {
      $(this).next('.add-sample-faq').addClass('display-none');
    }

    wp.hooks.doAction('showOrHideSampleBtn', 0); // Collapse inactive FAQ items.

    const postbox = e.target.closest('.faq-form-box');
    const editorId = $(postbox).find('h2').attr('ID');
    wp.hooks.doAction('collapse_inactive_faq_items', editorId); // Add new FAQ editor and do further processing.

    $('#output-faq').append(faqContent);
    $('#output-faq > div').last().toggleClass('closed opened').find('.inside').toggleClass('expanded').prev().children('.dashicons-menu').toggleClass('drag-handle') //.toggleClass('drag-handle', toggleCallback)
    .closest('.faq-form-box').find('.inside').find('.question-input').focus();
    addTinymce('question_edit_' + window.faqIdCounter, false);
    addTinymce('answer_edit_' + window.faqIdCounter, true);
    window.faqIdCounter++; // increment counter to next id number
    // Set focus for the current FAQ item

    if ($('#question_edit_' + currentFaqIndex).length > 0) {
      tinyMCE.get('question_edit_' + currentFaqIndex).on('init', function () {
        // Set the focus.
        this.focus();
      });
    }

    $('.qa-count').val($('.faq-form-box').length);
    wp.hooks.doAction('ffaq_update_total_enabled_faqs', currentFaqIndex);
  }); // Add sample FAQs when button clicked.

  $(document.body).on('click', '.add-sample-faq', function (e) {
    e.preventDefault();
    $('.add-faq-msg').addClass('display-none');
    $(this).addClass('display-none');
    const faqs = wpgo_faq.sample_faqs[0].faqs;
    faqs.forEach(function (record) {
      const question = record.question;
      const answer = record.answer;
      const faqContent = faqAdminTemplate(question, answer, window.faqIdCounter, false);
      $('#output-faq').append(faqContent);
      window.faqIdCounter++; // Increment counter to next ID number.
    });
    $('.qa-count').val($('.faq-form-box').length);
    window.wpgo_flexible_faqs__cpt_edit_dirty = true; //Enable dirty mode
  }); // Remove an FAQ item on click event.

  $(document.body).on('click', '.remove-faq', function (e) {
    // alert('in main :' + $(this).prop('class'));
    const questionId = $(this).closest('.faq-form-box').find('.inside .question-container textarea').attr('id');
    const answerId = $(this).closest('.faq-form-box').find('.inside .answer-container textarea').attr('id');
    const faqIndex = (0,_utility__WEBPACK_IMPORTED_MODULE_0__.getFaqIndex)(questionId); //console.log("INDEX", $(this), faqIndex, questionId, answerId);
    // Check Q/A editors for empty content.

    const [qContent, aContent] = (0,_utility__WEBPACK_IMPORTED_MODULE_0__.checkEditorContent)(faqIndex); // @todo the two blocks of code in the conditional are pretty similar so we can optimize these.
    // If question or answer content empty.

    if (qContent && aContent) {
      // Remove question and answer TinyMCE instances.
      let cmd = 'mceRemoveControl';

      if (parseInt(tinymce.majorVersion) >= 4) {
        cmd = 'mceRemoveEditor';
      }

      tinymce.execCommand(cmd, false, questionId);
      tinymce.execCommand(cmd, false, answerId);
      $(this).closest('.faq-form-box').remove(); // Update counts when an FAQ item is deleted.

      wp.hooks.doAction('ffaq_update_faqs_count_on_delete', questionId, $(this));
    } else {
      // eslint-disable-next-line no-alert
      const result = confirm("Are you sure you want to remove this FAQ? This action can't be undone once the post is updated.");

      if (result == true) {
        // Remove question and answer TinyMCE instances.
        let cmd = 'mceRemoveControl';

        if (parseInt(tinymce.majorVersion) >= 4) {
          cmd = 'mceRemoveEditor';
        }

        tinymce.execCommand(cmd, false, questionId);
        tinymce.execCommand(cmd, false, answerId);
        $(this).closest('.faq-form-box').remove(); // Update faq counts when a faq item is deleted.

        wp.hooks.doAction('ffaq_update_faqs_count_on_delete', questionId, $(this));
      } else {
        // Don't proceed with any actions related to deleting the FAQ item.
        return;
      }
    }

    $('.qa-count').val($('.faq-form-box').length);

    if ($('.faq-form-box').length == 0) {
      $('#output-faq .add-faq-msg').removeClass('display-none'); // Display no FAQs message if last item removed.

      if ($('.add-sample-faq').length > 0) {
        $('.add-sample-faq').removeClass('display-none');
      }

      wp.hooks.doAction('showOrHideSampleBtn', 1);
      window.faqIdCounter = 1; // Reset counter.
    } else {
      // If we haven't removed the last FAQ item (i.e. there are some remaining) then reindex.
      //console.log("ZERO #1", parseInt($('.faq-form-box').length) + 1, window.faqIdCounter);
      wp.hooks.doAction('reindex-disable-chk'); //console.log("ZERO #2", parseInt($('.faq-form-box').length) + 1, window.faqIdCounter);
      // @todo This should work in theory to make sure the new FAQ item we're adding has the correct ID but in practice there is a bug where TinyMCE editor instances are sometimes not instantiated properly.
      //window.faqIdCounter = parseInt($('.faq-form-box').length) + 1; // Reset counter.
    }

    e.preventDefault();
  }); // Toggle individual FAQ on double click / click events.
  // Need to add the click events at the document level to capture newly added FAQ items too.

  $(document.body).on('dblclick', '.question-text', expandFaq);
  $(document.body).on('dblclick', '.drag-icon', expandFaq);
  $(document.body).on('click', '.toggle-button', expandFaq);
  $(document.body).on('click', '.faq-done-btn', expandFaq); // Copy the text to user clipboard when the 'copy' is clicked.

  $('.wpgo-faq-shortcode-copy').on('click', function (e) {
    window.navigator.clipboard.writeText(this.previousElementSibling.value); // Write shortcode to clipboard.

    this.src = this.src.replace('copy.svg', 'copied.svg'); // Change 'copy' icon to 'copied'.
  }); // Add or remove buttons from TinyMCE editor toolbar.

  $(document).on('tinymce-editor-setup', function (event, editor) {
    //console.log('TOOLBAR: ', editor.settings.toolbar1);
    const upgradeBtn = {
      classes: 'faq-upgrade',
      icon: 'info',
      tooltip: 'View more formatting options',

      //classes: 'faq-insert-media',
      //tooltip: 'Insert item from Media Library',
      //icon: 'image',
      onclick() {
        // eslint-disable-next-line no-alert
        alert('Upgrade today for access to additional editor buttons such as:\r\n\r\n1. Insert Images\r\n2. Insert Video\r\n3. Bulleted Lists\r\n4. Text Alignment\r\n5. Strikethrough'); //$('.mce-faq-insert-media > button').addClass("button insert-media add_media");
      }

    };

    if (editor.id.includes('question')) {
      editor.settings.toolbar1 = wp.hooks.applyFilters('question-editor-buttons', 'q_upgrade_to_pro');
      editor.addButton('q_upgrade_to_pro', upgradeBtn);
    } else if (editor.id.includes('answer')) {
      editor.settings.toolbar1 = wp.hooks.applyFilters('answer-editor-buttons', 'bold, italic, link, a_upgrade_to_pro');
      editor.addButton('a_upgrade_to_pro', upgradeBtn);
      wp.hooks.doAction('answer-custom-buttons', editor);
    } //console.log('tinymce-editor-setup: ', editor, editor.settings.toolbar1);

  });
});
})();

/******/ })()
;
//# sourceMappingURL=cpt-admin-compiled.js.map