(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";

(function ($) {
  $(document).ready(function () {

    const Toast = Swal.mixin({
        toast: true,
        position: "top-end",
        showConfirmButton: false,
        timer: 3000,
        timerProgressBar: true,
        customClass: {
            container: 'top-40'
        },
        didOpen: (toast) => {
          toast.onmouseenter = Swal.stopTimer;
          toast.onmouseleave = Swal.resumeTimer;
        }
    });

    function formatLabelPath(parts) {
        return parts.filter(Boolean).map(function (s) {
            return String(s).trim();
        }).filter(Boolean).join(' → ');
    }

    function triggerSwalEmptyRequired(arg1, firstLabel, tab) {
        // Supports both old signature (fieldId, firstLabel, tab)
        // and new signature (object { id, tab, group, repeater, label, parent })
        var path = '';
        var p;
        if (typeof arg1 === 'object' && arg1 !== null) {
            p = arg1;
            // Include parent (repeater parent field label) when present
            path = formatLabelPath([p.tab, p.group, p.parent, p.repeater, p.label]);
        } else {
            // Fallback to old behavior
            if (firstLabel) {
                path = formatLabelPath([tab, firstLabel]);
            }
        }

        // Wider dialog for repeater breadcrumb to avoid wrapping
        var isRepeaterContext = (typeof p !== 'undefined') && (!!p.parent || !!p.repeater);

        Swal.fire({
            icon: 'warning',
            title: 'Empty Required Field',
            html: path ? 'Check: <b>' + path + '</b>' : '',
            width: isRepeaterContext ? '50em' : undefined,
            customClass: {
                confirmButton: 'btn text-bg-primary'
            },
            didOpen: (popup) => {
                if (isRepeaterContext) {
                    var htmlC = popup.querySelector('.swal2-html-container');
                    if (htmlC) {
                        htmlC.style.whiteSpace = 'nowrap';
                    }
                }
            }
        });
    }

    // === DeweBox/Nuxy required/visibility helpers (global) ===
    function isBoxChildVisible($box, includeHidden) {
        if (includeHidden === true) return true; // scan *all* tabs/sections
        return $box.is(':visible');
      }

    function readFieldValue($input) {
        const id  = $input.attr('id');
        const tag = $input.prop('tagName');
        const type= ($input.attr('type') || '').toLowerCase();

        // TinyMCE
        if (tag === 'TEXTAREA' && typeof window.tinymce !== 'undefined') {
            const ed = tinymce.get(id);
            if (ed) return ed.getContent();
        }
        // CodeMirror via WP code editor (textarea sibling with .CodeMirror)
        if (tag === 'TEXTAREA' && window.wp && wp.codeEditor) {
            const cmWrap = $input.next('.CodeMirror');
            if (cmWrap.length && cmWrap[0].CodeMirror) {
                return cmWrap[0].CodeMirror.getValue();
            }
        }
        if (type === 'checkbox' || type === 'radio') {
            const name = $input.attr('name');
            return !!$(`[name="${name}"]:checked`).length;
        }
        return $.trim($input.val() || '');
    }

    function isRequiredEmpty($input) {
        if (!$input.is('[required]')) return false;
        const tag  = $input.prop('tagName');
        const type = ($input.attr('type') || '').toLowerCase();
        if (type === 'checkbox' || type === 'radio') {
            const name = $input.attr('name');
            return !$(`[name="${name}"]:checked`).length;
        }
        const v = readFieldValue($input);
        return v === '' || v === null || typeof v === 'undefined';
    }

    function collectInvalidFields(includeHidden) {
        const invalid = [];
        // Ensure TinyMCE mirrors content back to textarea before reading values
        if (window.tinymce) tinymce.triggerSave();

        $('.wpcfto-box-child').each(function () {
            const $boxChild = $(this);
            const fieldId   = $boxChild.attr('data-field');
            const $tab      = $boxChild.closest('.wpcfto-tab');
            const tabId     = $tab.attr('id');
            const tabTitle  = $(`[data-section=${tabId}]`).text();

            if (!isBoxChildVisible($boxChild, includeHidden)) return;

            // Try to find nearest group title before this field
            const groupLabel = ($boxChild.prevAll('.wpcfto_group_started:first')
                                .find('.wpcfto-field-aside__label span:first-child').text() || '').trim();

            if ($boxChild.hasClass('repeater')) {
                // Repeater parent label (the field label for the repeater itself)
                const parentLabel = ($boxChild.find('.wpcfto-field-aside__label span:first-child').first().text() || '').trim();

                // Determine if this repeater is required.
                // We prefer presence of the hidden proxy input (rendered only when required).
                // Fallback: a data attribute marker if used by templates.
                const isRequiredRepeater = (
                    $boxChild.find('.wpcfto-required-proxy').length > 0 ||
                    $boxChild.is('[data-required="true"]')
                );

                // Parent-level empty check: only flag when the repeater itself is required
                const hasRows = $boxChild.find('.wpcfto-repeater-single').length > 0;
                if (isRequiredRepeater && !hasRows) {
                    invalid.push({
                        id: fieldId,
                        tab: tabTitle,
                        group: groupLabel,
                        parent: parentLabel
                    });
                }

                // Child-level checks: scan only inputs that explicitly declare [required]
                $boxChild.find('.wpcfto-repeater-single').each(function (idx) {
                    const $item = $(this);

                    // Repeater item label heuristics (prefer the Vue-rendered title)
                    const titleEl = $item.find('.wpcfto_group_title').first();
                    let repeaterLabel = (titleEl.text() || '').toString().trim();

                    if (!repeaterLabel) {
                        repeaterLabel = (
                            $item.find('[data-repeater-label]').val() ||
                            $item.find('[name*="[label]"]').val() ||
                            $item.find('[name*="[title]"]').val() ||
                            $item.find('[name*="[name]"]').val() ||
                            $item.find('.wpcfto-repeater-title, .wpcfto-repeater-item-label').first().text() ||
                            ''
                        ).toString().trim();
                    }
                    if (!repeaterLabel) repeaterLabel = `Item #${idx+1}`;

                    // Only required child fields should be considered invalid when empty
                    $item.find('input, textarea, select').filter('[required]').each(function () {
                        const $f = $(this);
                        if (isRequiredEmpty($f)) {
                            const emptyLabel = $f.closest('.wpcfto_generic_field')
                                                 .find('.wpcfto-field-aside__label span:first-child').text() || fieldId;
                            invalid.push({
                                id: fieldId,
                                tab: tabTitle,
                                group: groupLabel,
                                parent: parentLabel,
                                repeater: repeaterLabel,
                                label: emptyLabel
                            });
                        }
                    });
                });
                return;
            }

            $boxChild.find('input, textarea, select').filter('[required]').each(function () {
                const $f = $(this);
                if (isRequiredEmpty($f)) {
                    const fieldLabel = $(`[data-field=${fieldId}] label > span:first-child`).text() || fieldId;
                    invalid.push({
                        id: fieldId,
                        tab: tabTitle,
                        group: groupLabel,
                        repeater: null,
                        label: fieldLabel
                    });
                }
            });
        });

        return invalid;
    }

    function firstInvalidField(includeHidden) {
        const inv = collectInvalidFields(includeHidden);
        return inv.length ? inv[0] : null;
    }

    function focusFirstInvalid(invalid) {
        if (!invalid) return;
        const $targetTab = $(`[data-field=${invalid.id}]`).closest('.wpcfto-tab');
        const tabId = $targetTab.attr('id');
        if (tabId) {
            // try Vue's changeTab if available
            if (typeof vm !== 'undefined' && vm.changeTab) {
                vm.changeTab(tabId);
            } else {
                $('#' + tabId).addClass('active').siblings('.wpcfto-tab').removeClass('active');
                $(`[data-section="${tabId}"]`).closest('.wpcfto-nav').addClass('active').siblings('.wpcfto-nav').removeClass('active');
            }
            $('html, body').animate({ scrollTop: $(`[data-field=${invalid.id}]`).offset().top - 120 }, 'fast');
        }
    }

    $('[data-vue]').each(function () {
      var $this = $(this);
      var data_var = $this.attr('data-vue');
      var data_source = $this.attr('data-source');
      Vue.mixin(window.validationMixin); 
      new Vue({
        el: $(this)[0],
        data: function data() {
          return {
            loading: false,
            data: '',
            settings_alert: {
              status: false,
              success: true
            },
            invalidFields: new Set(),
          };
        },
        created() {
            // Listen for validation updates from fields
            this.$on('field-validation', ({ fieldId, isValid }) => {
              if (isValid) {
                this.invalidFields.delete(fieldId);
              } else {
                this.invalidFields.add(fieldId);
              }
            });
        },
        mounted: function mounted() {
            this.getSettings();
            this.clearEmptyGroups();

            // Intercept Classic Editor Publish/Save buttons
            const vm = this;
            vm.$nextTick(() => {
                $(document).off('click.deweboxPublish').on('click.deweboxPublish', '#publish, #save-post', function(e) {
                    const invalidField = firstInvalidField(true);
                    if (invalidField) {
                        e.preventDefault();
                        if (typeof window.Swal === 'function') {
                            triggerSwalEmptyRequired(invalidField);
                        } else {
                            alert('Please fill all required fields before saving.' + (invalidField.label ? '\nFirst missing: ' + invalidField.label : ''));
                        }
                        focusFirstInvalid(invalidField);
                        return false;
                    }
                });
            });

            // Gutenberg: lock publish when invalid and show SweetAlert on attempt
            if (window.wp && wp.data && wp.data.select('core/editor')) {
                const { subscribe, dispatch } = wp.data;
                const LOCK_KEY = 'wpcfto-required-lock';

                const applyLock = () => {
                    const invalid = firstInvalidField(true);
                    if (invalid) {
                        dispatch('core/editor').lockPostSaving(LOCK_KEY);
                    } else {
                        dispatch('core/editor').unlockPostSaving(LOCK_KEY);
                    }
                };
                applyLock();
                subscribe(applyLock);

                $(document).off('click.deweboxGutenberg').on('click.deweboxGutenberg', '.editor-post-publish-button, .editor-post-publish-panel__toggle', function(e){
                    const invalid = firstInvalidField(true);
                    if (invalid) {
                        e.preventDefault();
                        triggerSwalEmptyRequired(invalid);
                        focusFirstInvalid(invalid);
                        return false;
                    }
                });
            }
        },
        methods: {
            validateAllFields: function validateAllFields() {
                const invalid = firstInvalidField(true);
                return invalid ? invalid : null;
            },
            getFieldLabelById(fieldId) {
                let label = '';
                var parent = $('#'+fieldId).closest('.wpcfto-box-child');
                var dataField = parent.attr('data-field');
                var labelText = $('[data-field='+dataField+'] label span:first-child').text();
                label = labelText;
                return label || fieldId;
            },
            initSubmenu: function initSubmenu() {
                Vue.nextTick().then(function () {
                (function ($) {
                    /*Hide all fields in submenu*/
                    var submenu_tab_fields = $('.wpcfto-tab.has-submenu-items [data-field], .wpcfto-tab.has-submenu-items .wpcfto_group_started');
                        submenu_tab_fields.css({
                        display: 'none'
                    });
                    var $sub_menu = $('.wpcfto-submenus .active');
                    var sub_menu_section = $sub_menu.attr('data-submenu');
                    var $submenu_section = $('.' + sub_menu_section);
                    $submenu_section.removeAttr('style');
                    submenu_tab_fields.parents('.wpcfto_group_started').css({
                        display: 'none'
                    });
                    $submenu_section.parents('.wpcfto_group_started').removeAttr('style');
                })(jQuery);
                });
            },
            changeTabFromAnchor: function changeTabFromAnchor() {
                var _this = this;

                var hash = window.location.hash;
                var hashParts = hash.split('#');

                if (typeof hashParts[1] !== 'undefined') {
                Vue.nextTick(function () {
                    _this.changeTab(hashParts[1]);
                });
                }
            },
            changeTab: function changeTab(tab) {
                var $tab = $('#' + tab);
                $tab.closest('.stm_metaboxes_grid__inner').find('.wpcfto-tab').removeClass('active');
                $tab.addClass('active');
                var $section = $('div[data-section="' + tab + '"]');
                $tab.closest('.wpcfto-settings').find('.wpcfto-nav').removeClass('active');
                $tab.closest('.stm_metaboxes_grid__inner').find('.wpcfto-nav').removeClass('active');
                $section.closest('.wpcfto-nav').addClass('active');
                history.pushState(null, null, '#' + tab);
                /*if has submenu*/

                if ($section.closest('.wpcfto-nav').hasClass('has-submenu')) {
                var $submenu = $section.closest('.wpcfto-nav').find('.wpcfto-submenus [data-submenu]').eq(0);
                var urlParams = new URLSearchParams(window.location.search);
                var submenuParam = urlParams.get('submenu');

                if (submenuParam) {
                    var navSubmenu = $section.closest('.wpcfto-nav').find(".wpcfto-submenus [data-submenu=".concat(tab, "_").concat(submenuParam, "]"));
                    $submenu = navSubmenu !== undefined && navSubmenu.length > 0 ? navSubmenu : $submenu;
                }

                this.changeSubMenu($submenu.attr('data-submenu'));
                }
                /*Scroll top*/


                $("html, body").animate({
                scrollTop: $tab.closest('.stm_metaboxes_grid__inner').offset().top - 100
                }, "fast");
            },
            changeSubMenu: function changeSubMenu(sub_menu) {
                var $submenu = $('[data-submenu="' + sub_menu + '"]');
                $('[data-submenu]').removeClass('active');
                $submenu.addClass('active');
                this.initSubmenu();
            },
            getSettings: function getSettings() {
                var _this = this;

                _this.loading = true;
                this.$http.get(stm_wpcfto_ajaxurl + '?action=stm_wpcfto_get_settings&source=' + data_source + '&name=' + data_var + '&nonce=' + wpcfto_global_settings['nonce']).then(function (r) {
                _this.$set(_this, 'data', r.body);

                _this.loading = false;
                this.changeTabFromAnchor();
                this.initSubmenu();
                });
            },
            saveSettings: function saveSettings(id) {
                // Ensure editors sync back to DOM before validation/post
                if (window.tinymce) tinymce.triggerSave();

                const invalidField = firstInvalidField(true);
                if (invalidField) {
                    if (typeof window.Swal === 'function') {
                        triggerSwalEmptyRequired(invalidField);
                    } else {
                        alert('Please fill all required fields before saving.' + (invalidField.label ? '\nFirst missing: ' + invalidField.label : ''));
                    }
                    focusFirstInvalid(invalidField);
                    return;
                }
                
                var vm = this;
                vm.loading = true;
                  // Proceed with existing saveSettings logic
                this.$http.post(stm_wpcfto_ajaxurl + '?action=wpcfto_save_settings&nonce=' + stm_wpcfto_nonces['wpcfto_save_settings'] + '&name=' + id, JSON.stringify(vm.data)).then(function (response) {
                    vm.loading = false;
                    vm.settings_alert = {
                        success: response.status === 200,
                        status: true
                    };
                    setTimeout(function () {
                        vm.settings_alert.status = false;
                    }, 1500);
                    // location.reload();
                    if(response.status == 200 && response.ok)
                    if (typeof window.Swal === 'function') {
                        Toast.fire({
                            icon: "success",
                            title: 'Successfully save any changes'
                        });
                    } else {
                        alert('Successfully save any changes');
                    }
                });
            },
            initOpen: function initOpen(field) {
                if (typeof field.opened === 'undefined') {
                this.$set(field, 'opened', !!field.value);
                }
            },
            openField: function openField(field) {
                var opened = !field.opened;
                this.$set(field, 'opened', opened);

                if (!field.opened) {
                this.$set(field, 'value', '');
                }
            },
            enableAddon: function enableAddon($event, option) {
                var _this = this;

                Vue.nextTick(function () {
                (function ($) {
                    var currentItem = $($event.target);
                    currentItem.addClass('loading');
                    var url = stm_wpcfto_ajaxurl + '?action=stm_lms_enable_addon&addon=' + option;

                    _this.$http.get(url).then(function (response) {
                    currentItem.removeClass('loading');
                    var $container = $('.stm_lms_addon_group_settings_' + option);
                    $container.each(function () {
                        var $this = $(this);
                        $this.removeClass('is_pro is_pro_in_addon');
                        $this.find('.field_overlay').remove();
                        $this.find('.pro-notice').remove();
                    });
                    });
                })(jQuery);
                });
            },
            clearEmptyGroups: function clearEmptyGroups() {
                Vue.nextTick().then(function () {
                (function ($) {
                    $('.wpcfto_group_started').each(function () {
                    var $group = $(this);
                    var $childs = $group.find('.wpcfto-box-child');

                    if (!$childs.length) {
                        $group.addClass('no-childs-visible');
                    } else {
                        $group.removeClass('no-childs-visible');
                    }
                    });
                })(jQuery);
                });
            },
            addRepeaterRow() {
                const invalid = firstInvalidField(true);
                if (invalid) {
                    if (typeof window.Swal === 'function') {
                        Toast.fire({
                            icon: "warning",
                            title: 'Please fill all required fields before adding a new row.'
                        });
                    } else {
                        alert('Please fill all required fields before adding a new row.');
                    }
                    focusFirstInvalid(invalid);
                    return;
                }
                // TODO: your existing logic to actually add a repeater row goes here
            }
        },
        watch: {
          data: {
            deep: true,
            handler: function handler() {
              var _this = this;

              setTimeout(function () {
                _this.clearEmptyGroups();

                _this.initSubmenu();
              }, 100);
            }
          }
        }
      });
    });
  });
})(jQuery);
//# sourceMappingURL=data:application/json;charset=utf-8;base64, 
},{}]},{},[1])