PageSourceSearch

https://sweepwidget.com/js/build_edit_widget_live.js?v=596476738823

js sweepwidget.com collected 2026-10-02 02:25:37 UTC 285,777 bytes, 7,671 lines download raw bytes

1$(function () {
2  var website_url = window.location.origin;
3  var pathname = window.location.pathname;
4  var payment_platform = $("#payment_platform").val();
5
6  var pathname_exp = pathname.split("/");
7  var get_one = pathname_exp[1];
8  var get_two = pathname_exp[2];
9  var get_three = pathname_exp[3];
10
11  var entry_method_id = $("input[name=entry_methods_previous_entry_id]").val();
12
13  var website_plan = parseInt($("#user_website_plan").val());
14  var trial_demo = 0;
15
16  function toggleOverlay2(show) {
17    var el = document.getElementById("overlay");
18    if (show) {
19      el.classList.remove("hidden");
20      el.classList.add("flex");
21    } else {
22      el.classList.add("hidden");
23      el.classList.remove("flex");
24    }
25  }
26
27  // If on 'update-widget' page
28  if (
29    pathname.indexOf("update-widget") !== -1 ||
30    pathname.indexOf("update-photo-contest") !== -1
31  ) {
32    is_update_widget = true;
33  } else {
34    is_update_widget = false;
35  }
36
37  // Free plan
38  if (plan_level("free", "equal", website_plan, payment_platform) == true) {
39    var pro_button_classes = "entry_method_add_disallow_pro";
40    var disabled_pro = 'disabled="disabled"';
41    var disabled_pro_text =
42      '&nbsp;<b class="available_in_pro_plan_text paid_plan_tip">&nbsp;&bull; Pro</b>&nbsp;';
43  } else {
44    var pro_button_classes = "";
45    var disabled_pro = "";
46    var disabled_pro_text = "";
47  }
48
49  function widget_builder_example(id, entry_method_class, if_sortable) {
50    var level = $(
51      "input[name=entry_level_" + entry_method_class + "_" + id + "]"
52    ).val();
53
54    if (level == 1) {
55      // Text input or crypto entry method
56      if (
57        entry_method_class == "text_input" ||
58        entry_method_class.indexOf("crypto_wallet") >= 0
59      ) {
60        // Crypto entry method
61        if (entry_method_class.indexOf("crypto_wallet") >= 0) {
62          var entry_title = $(
63            "#entry_title_" + entry_method_class + "_" + id
64          ).val();
65        }
66        // text_input
67        else {
68          var entry_title = "Custom Title";
69        }
70
71        $("#sw_login_sortable").append(
72          '<div id="sw_row_' +
73          id +
74          '" class="sw_row_1">' +
75          '<div class="sw_input_holder_simple"><div id="sw_' +
76          entry_method_class +
77          "_header_" +
78          id +
79          '" class="sw_input_header_3">' +
80          entry_title +
81          "</div></div>" +
82          '<input maxlength="255" class="sw_text_input" type="text" name="sw_login_name" />' +
83          "</div>"
84        );
85      } else if (entry_method_class == "select") {
86        $("#sw_login_sortable").append(
87          '<div id="sw_row_' +
88          id +
89          '" class="sw_row_1">' +
90          '<div class="sw_input_holder_simple"><div id="sw_' +
91          entry_method_class +
92          "_header_" +
93          id +
94          '" class="sw_input_header_3">Dropdown menu</div></div>' +
95          '<select name="sw_select_' +
96          id +
97          '" id="sw_select_' +
98          id +
99          '" class="sw_select_full_white">' +
100          '<option value="">Choose</option>' +
101          "</select>" +
102          "</div>"
103        );
104
105        $(
106          "input[name=select_options_" + entry_method_class + "_" + id + "]"
107        ).keyup(function () {
108          $("#sw_select_" + id).html("");
109          var val = $(this).val();
110          var input_options_split = val.split(",");
111          $.each(input_options_split, function (key, value) {
112            $("#sw_select_" + id).append(
113              $("<option></option>").attr("value", value).text(value)
114            );
115          });
116        });
117
118        if (if_sortable == 1) {
119          var val =
120            $(
121              "input[name=select_options_" + entry_method_class + "_" + id + "]"
122            ).val() || "";
123
124          if (val !== "") {
125            var input_options_split = val.split(",");
126            $("#sw_select_" + id).html("");
127            $.each(input_options_split, function (key, value) {
128              $("#sw_select_" + id).append(
129                $("<option></option>").attr("value", value).text(value)
130              );
131            });
132          }
133        }
134      } else if (entry_method_class == "radio") {
135        $("#sw_login_sortable").append(
136          '<div id="sw_row_' +
137          id +
138          '" class="sw_row_2">
138' +
139          '<div class="sw_input_holder_simple"><div id="sw_' +
140          entry_method_class +
141          "_header_" +
142          id +
143          '" class="sw_input_header_3">Radio buttons</div></div>' +
144          '<div class="sw_row_2 text-left">' +
145          '<div id="sw_row_2_r_' +
146          id +
147          '">' +
148          '<label class="cursor-pointer">' +
149          '<input name="sw_row_radio_' +
150          id +
151          '" type="radio" class="sw-radio" />' +
152          "<span>Value 1 </span>" +
153          "</label> &nbsp;&nbsp;&nbsp;" +
154          '<label class="cursor-pointer">' +
155          '<input name="sw_row_radio_' +
156          id +
157          '" type="radio" class="sw-radio" />' +
158          "<span>Value 2 </span>" +
159          "</label>" +
160          "</div>" +
161          "</div>" +
162          "</div>"
163        );
164
165        $(
166          "input[name=radio_options_" + entry_method_class + "_" + id + "]"
167        ).keyup(function () {
168          $("#sw_row_2_r_" + id).html("");
169          var val = $(this).val();
170          var input_options_split = val.split(",");
171          $.each(input_options_split, function (key, value) {
172            $("#sw_row_2_r_" + id).append(
173              '<label class="cursor-pointer">' +
174              '<input name="sw_row_radio_' +
175              id +
176              '" type="radio" class="sw-radio" /> ' +
177              "<span>" +
178              value +
179              "<span>" +
180              "</label> &nbsp;&nbsp;&nbsp;"
181            );
182          });
183        });
184
185        if (if_sortable == 1) {
186          var val = $(
187            "input[name=radio_options_" + entry_method_class + "_" + id + "]"
188          ).val();
189
190          if (val !== "") {
191            $("#sw_row_2_r_" + id).html("");
192
193            var input_options_split = val.split(",");
194
195            $.each(input_options_split, function (key, value) {
196              $("#sw_row_2_r_" + id).append(
197                '<div class="sw_input_radio_holder">' +
198                '<label class="cursor-pointer">' +
199                '<input name="sw_row_radio_' +
200                id +
201                '" type="radio" class="sw-radio" /> ' +
202                "<span>" +
203                value +
204                "</span>" +
205                " </label> &nbsp;&nbsp;&nbsp;" +
206                "</div>"
207              );
208            });
209          }
210        }
211      } else if (entry_method_class == "checkbox") {
212        $("#sw_login_sortable").append(
213          '<div id="sw_row_' +
214          id +
215          '" class="sw_row_2 text-left">' +
216          '<div class="sw_row_2 flex items-center">' +
217          '<label for="sw_checkbox_' +
218          id +
219          '" class="cursor-pointer flex items-center">' +
220          '<input type="checkbox" class="sw-checkbox" name="sw_checkbox_' +
221          id +
222          '" id="sw_checkbox_' +
223          id +
224          '" checked />' +
225          '<span id="sw_' + entry_method_class + '_header_' + id + '">' +
226          "Checkbox" +
227          "</span>" +
228          "</label>" +
229          "</div>" +
230          "</div>"
231        );
232      } else if (entry_method_class == "checkboxes") {
233        $("#sw_login_sortable").append(
234          '<div id="sw_row_' +
235          id +
236          '" class="sw_row_2">' +
237          '<div class="sw_input_holder_simple"><div id="sw_' +
238          entry_method_class +
239          "_header_" +
240          id +
241          '" class="sw_input_header_3">Checkboxes (Multi-Choice)</div></div>' +
242          '<div class="sw_row_2 text-left">' +
243          '<div id="sw_row_2_cb_' +
244          id +
245          '">' +
246          '<label class="cursor-pointer flex items-center">' +
247          '<input name="sw_row_checkboxes_' +
248          id +
249          '[]" type="checkbox" class="sw-checkbox" />' +
250          "<span>Value 1 </span>" +
251          "</label> &nbsp;&nbsp;&nbsp;" +
252          '<label class="cursor-pointer flex items-center">' +
253          '<input name="sw_row_checkboxes_' +
254          id +
255          '[]" type="checkbox" class="sw-checkbox" />' +
256          "<span>Value 2 </span>" +
257          "</label>" +
258          "</div>" +
259          "</div>" +
260          "</div>"
261        );
262
263        $(
264          "input[name=checkboxes_options_" + entry_method_class + "_" + id + "]"
265        ).keyup(function () {
266          $("#sw_row_2_cb_" + id).html("");
267          var val = $(this).val();
268          var input_options_split = val.split(",");
269          $.each(input_options_split, function (key, value) {
270            $("#sw_row_2_cb_" + id).append(
271              '<label class="cursor-pointer flex items-center">' +
272              '<input name="sw_row_checkboxes_' +
273              id +
274              '[]" type="checkbox" class="sw-checkbox" /> ' +
275              "<span>" +
276              value +
277              "<span>" +
278              "</label> &nbsp;&nbsp;&nbsp;"
279            );
280          });
281        });
282
283        if (if_sortable == 1) {
284          var val = $(
285            "input[name=checkboxes_options_" + entry_method_class + "_" + id + "]"
286          ).val();
287
288          if (val !== "") {
289            $("#sw_row_2_cb_" + id).html("");
290
291            var input_options_split = val.split(",");
292
293            $.each(input_options_split, function (key, value) {
294              $("#sw_row_2_cb_" + id).append(
295                '<div class="sw_input_checkbox_holder">' +
296                '<label class="cursor-pointer flex items-center">' +
297                '<input name="sw_row_checkboxes_' +
298                id +
299                '[]" type="checkbox" class="sw-checkbox" /> ' +
300                "<span>" +
301                value +
302                "</span>" +
303                " </label> &nbsp;&nbsp;&nbsp;" +
304                "</div>"
305              );
306            });
307          }
308        }
309      } else if (entry_method_class == "textarea") {
310        $("#sw_login_sortable").append(
311          '<div id="sw_input_row_' +
312          id +
313          '">' +
314          '<div class="sw_entry_row_input_inner">' +
315          '<div class="sw_input_header_left">' +
316          '<div id="sw_' +
317          entry_method_class +
318          "_header_" +
319          id +
320          '" class="sw_input_header_3">' +
321          "Textarea" +
322          "</div>" +
323          '<div id="sw_' +
324          entry_method_class +
325          "_sub_header_" +
326          id +
327          '" class="sw_row_2 mb-[-10px] pb-0" style="font-style:normal;">' +
328          "</div>" +
329          "</div>" +
330          '<div class="sw_entry_row_input_inner">' +
331          '<div class="w-full float-left">' +
332          '<textarea name="sw_textarea_' +
333          id +
334          '" id="sw_textarea_' +
335          id +
336          '" class="sw_textarea relative my-4" data-gramm="false" disabled style="text-align:left; cursor:not-allowed;">' +
337          "<div>" +
338          "</textarea>" +
339          "</div>" +
340          "</div>" +
341          "</div>"
342        );
343
344        // set the default header instructions text
345        var additional_instructions =
346          $(
347            "textarea[name=additional_instructions_" +
348            entry_method_class +
349            "_" +
350            id +
351            "]"
352          ).val() || "Additional instructions";
353        $("#sw_" + entry_method_class + "_sub_header_" + id).html(
354          additional_instructions
355        );
356
357        $(
358          "textarea[name=additional_instructions_" +
359          entry_method_class +
360          "_" +
361          id +
362          "]"
363        )
364          .keyup(function () {
365            var val = $(this).val();
366            $("#sw_" + entry_method_class + "_sub_header_" + id).html(val);
367          })
368          .blur(function () {
369            var val = $(this).val() || "Additional instructions";
370            $("#sw_" + entry_method_class + "_sub_header_" + id).html(
371              "* " + val
372            );
373          });
374      } else if (entry_method_class == "secret_code") {
375        $("#sw_login_sortable").append(
376          '<div id="sw_row_' +
377          id +
378          '" class="sw_row_1">' +
379          '<div class="sw_input_holder_simple"><div id="sw_' +
380          entry_method_class +
381          "_header_" +
382          id +
383          '" class="sw_input_header_3">Secret Code</div></div>' +
384          '<input maxlength="255" class="sw_text_input" type="text" name="sw_login_name" />' +
385          "</div>"
386        );
387
388        // E-Signature
389      } else if (entry_method_class == "e_signature") {
390        $("#sw_login_sortable").append(
391          '<div id="sw_row_' +
392          id +
393          '" class="sw_row_1">' +
394          '<div class="sw_input_holder_simple"><div id="sw_' +
395          entry_method_class +
396          "_header_" +
397          id +
398          '" class="sw_input_header_3">Leave Your Signature</div></div>' +
399          '<div class="e_signature_wrapper_parent">' +
400          '<div id="e_signature_wrapper_' +
401          id +
402          '" class="e_sig_wrapper"></div>' +
403          '<div id="e_signature_tools_' +
404          id +
405          '"></div>' +
406          '<div id="e_signature_scrollgrabber_' +
407          id +
408          '"></div>' +
409          "</div>" +
410          "</div>"
411        );
412
413        $(function () {
414          (function ($) {
415            var topics = {};
416            $.publish = function (topic, args) {
417              if (topics[topic]) {
418                var currentTopic = topics[topic],
419                  args = args || {};
420
421                for (var i = 0, j = currentTopic.length; i < j; i++) {
422                  currentTopic[i].call($, args);
423                }
424              }
425            };
426
427            $.subscribe = function (topic, callback) {
428              if (!topics[topic]) {
429                topics[topic] = [];
430              }
431              topics[topic].push(callback);
432              return {
433                topic: topic,
434                callback: callback,
435              };
436            };
437
438            $.unsubscribe = function (handle) {
439              var topic = handle.topic;
440              if (topics[topic]) {
441                var currentTopic = topics[topic];
442
443                for (var i = 0, j = currentTopic.length; i < j; i++) {
444                  if (currentTopic[i] === handle.callback) {
445                    currentTopic.splice(i, 1);
446                  }
447                }
448              }
449            };
450          })(jQuery);
451
452          // This is the part where jSignature is initialized.
453          var $sigdiv = $("#e_signature_wrapper_" + id).jSignature({
454            UndoButton: false,
455          });
456
457          // All the code below is just code driving the demo.
458          var $tools = $("#e_signature_tools_" + id),
459            $extraarea = $("#displayarea"),
460            pubsubprefix = "jSignature.demo.";
461
462          $(
463            '<input type="button" class="e_signature_reset_button" value="Reset">'
464          )
465            .on("click", function (e) {
466              $sigdiv.jSignature("reset");
467            })
468            .appendTo($tools);
469
470          if (Modernizr.touch) {
471            $("#e_signature_scrollgrabber_" + id).height(
472              $("#content").height()
473            );
474          }
475        });
476
477        // Password Field
478      } else if (entry_method_class == "password_field") {
479        $("#sw_login_sortable").append(
480          '<div id="sw_row_' +
481          id +
482          '" class="sw_row_1">' +
483          '<div class="sw_input_holder_simple"><div id="sw_' +
484          entry_method_class +
485          "_header_" +
486          id +
487          '" class="sw_input_header_3">Password</div></div>' +
488          '<input maxlength="255" class="sw_text_input" type="password" name="sw_login_password" />' +
489          "</div>"
490        );
491      }
492
493      // set the default header title text
494      var custom_title =
495        $(
496          "input[name=entry_title_" + entry_method_class + "_" + id + "]"
497        ).val() || "Custom Title";
498      $("#sw_" + entry_method_class + "_header_" + id).html(custom_title);
499
500      $("input[name=entry_title_" + entry_method_class + "_" + id + "]")
501        .keyup(function () {
502          var val = $(this).val();
503          $("#sw_" + entry_method_class + "_header_" + id).html(val);
504        })
505        .blur(function () {
506          var val = $(this).val() || "Custom Title";
507          $("#sw_" + entry_method_class + "_header_" + id).html(val);
508        });
509    }
510  }
511
512  function widget_builder_reorder_example(entry_methods_container) {
513    $("#sw_login_sortable").html("");
514
515    if (
516      entry_methods_container !== "" &&
517      typeof entry_methods_container !== "undefined"
518    ) {
519      if (entry_methods_container.indexOf(",") != -1) {
520        var input_options_split = entry_methods_container.split(",");
521
522        $.each(input_options_split, function (key, value) {
523          var value_exp = value.split("-");
524          var entry_method_class = value_exp[0];
525          var id = value_exp[1];
526
527          var level = $(
528            "input[name=entry_level_" + entry_method_class + "_" + id + "]"
529          ).val();
530
531          if (level == 1) {
532            widget_builder_example(id, entry_method_class, 1);
533          }
534        });
535      }
536    }
537  }
538
539  // How to build click
540  $("#how_to_build").on("click", function () {
541    $("#how_to_build_select_holder").toggle();
542  });
543
544  $(document).on("change", 'select[name="how_to_build_select"]', function () {
545    var user_id = getCookieValue("user_login");
546    var competition_url = $(this).val();
547
548    var website_id = $(".user_sites_select").val().split("|")[0]; // current selected website
549    var website_plan = parseInt($("#user_website_plan").val());
550    var trial_demo = 0;
551    var open_entry_methods = false;
552
553    if (competition_url != "") {
554      // Copy giveaway
555      copy_giveaway_js(
556        user_id,
557        competition_url,
558        website_id,
559        website_plan,
560        trial_demo,
561        open_entry_methods,
562        "",
563        ""
564      );
565      $("#how_to_build_select_holder").hide();
566      $('select[name="how_to_build_select"]').val("");
567
568      // formSelect removed - native selects
569    }
570  });
571
572  // Click on entry_group_exit
573  $(document.body).on("click", ".entry_group_exit", function () {
574    // Get id of .entry_group_hide
575    var entry_group_id = $(this).attr("data-entry_group_id");
576
577    // Hide .entry_group_hide id
578    $("#" + entry_group_id).hide();
579  });
580
581  // --- Picker modal utilities ---
582  window.openPickerModal = function (id) {
583    var $modal = $('#' + id);
584    // Move to body so fixed positioning works regardless of parent containers
585    if (!$modal.parent().is('body')) {
586      $modal.appendTo('body');
587    }
588    $modal.removeClass('hidden');
589    $('body').css('overflow', 'hidden');
590  };
591
592  window.closePickerModal = function (id) {
593    $('#' + id).addClass('hidden');
594    $('body').css('overflow', '');
595    // Close any open sub-groups inside
596    $('#' + id + ' .entry_group_hide').slideUp(150);
597    // Clear search field
598    var $search = $('#' + id + ' #entry_method_search');
599    if ($search.length) {
600      $search.val('');
601      $('#' + id + ' .em-search-item').show();
602    }
603  };
604
605  // Entry method search filter
606  $(document.body).on('input', '#entry_method_search', function () {
607    var query = $(this).val().toLowerCase().trim();
608    var $panel = $(this).closest('.sw-picker-panel');
609    var $items = $panel.find('.em-search-item');
610    if (!query) {
611      $items.show();
612      return;
613    }
614    // Close any open group panels when searching
615    $panel.find('.entry_group_hide').slideUp(150);
616    $items.each(function () {
617      var label = $(this).attr('data-search-label') || '';
618      var match = label.indexOf(query) !== -1;
619      $(this).toggle(match);
620      // If this is a group button, also hide its associated panel when hidden
621      var groupId = $(this).attr('data-entry_group');
622      if (groupId) {
623        if (!match) {
624          $('#' + groupId).hide();
625        }
626      }
627    });
628  });
629
630  // Open modal on trigger button click
631  $(document.body).on("click", ".sw-picker-modal-trigger", function (e) {
632    e.preventDefault();
633    var modalId = $(this).attr("data-modal");
634    if (modalId) openPickerModal(modalId);
635  });
636
637  // Close modal on X button click
638  $(document.body).on("click", ".sw-picker-close", function () {
639    var modalId = $(this).attr("data-modal");
640    if (modalId) closePickerModal(modalId);
641  });
642
643  // Close modal on click outside the panel (backdrop or scroll container area)
644  $(document.body).on("click", ".sw-picker-modal", function (e) {
645    if ($(e.target).closest('.sw-picker-panel').length) return;
646    closePickerModal($(this).attr('id'));
647  });
648
649  // Close modal on ESC key
650  $(document).on("keydown", function (e) {
651    if (e.key === "Escape") {
652      $(".sw-picker-modal:not(.hidden)").each(function () {
653        closePickerModal($(this).attr("id"));
654      });
655    }
656  });
657
658  // Click on entry group sub-button (inside modal: inline expand; outside: absolute position)
659  $(document.body).on("click", ".entry_group_button", function () {
660    var entry_group = $(this).attr("data-entry_group");
661    var level = $(this).attr("data-level");
662
663    // Inside a modal: use inline slideToggle for sub-groups
664    if ($(this).closest('.sw-picker-modal').length) {
665      $(".entry_group_hide:not(#" + entry_group + ")").slideUp(150);
666      $("#" + entry_group).slideToggle(200);
667      return;
668    }
669
670    // Outside modal: original absolute positioning behavior
671    if (level == 1) {
672      var entry_group_width = $("#entry_methods_inner_width_level_1").width();
673    } else if (level == 2) {
674      var entry_group_width = $("#entry_methods_inner_width_level_2").width();
675    }
676
677    var button_pos = $(this).position();
678    var top = button_pos.top - 35;
679
680    if (level == "1") {
681      $("#" + entry_group)
682        .toggle()
683        .css("top", top + "px")
684        .css("width", "100%");
685    } else if (level == "2") {
686      $("#" + entry_group)
687        .toggle()
688        .css("top", top + "px")
689        .css("width", entry_group_width + "px");
690    }
691
692    $(".entry_group_hide:not(#" + entry_group + ")").hide();
693  });
694
695  // Shopify / WooCommerce upgrade modal for free plan users
696  function openShopUpgradeModal(provider) {
697    var $icon = $("#shop_upgrade_icon");
698    var $title = $("#shop_upgrade_title");
699    var $desc = $("#shop_upgrade_desc");
700
701    if (provider === "shopify") {
702      $icon
703        .html('<i class="fa-brands fa-shopify"></i>')
704        .css("background", "#96bf48");
705      $title.text("Shopify Purchases");
706      $desc.text(
707        "Automatically reward your customers with giveaway entries for every dollar they spend in your Shopify store. Orders are tracked in real-time via the Shopify API to ensure only verified purchases count."
708      );
709    } else {
710      $icon
711        .html(
712          '<img src="https://sweepwidgetmain.fra1.cdn.digitaloceanspaces.com/images/social-icons/woo-commerce-icon.png" class="h-5" style="display:inline;float:none;" />'
713        )
714        .css("background", "#96588a");
715      $title.text("WooCommerce Purchases");
716      $desc.text(
717        "Automatically reward your customers with giveaway entries for every dollar they spend in your WooCommerce store. Orders are tracked in real-time via the WooCommerce API to ensure only verified purchases count."
718      );
719    }
720
721    openPickerModal("shop_upgrade_modal");
722  }
723
724  // Intercept clicks on locked Shopify/WooCommerce buttons and their wrappers
725  // Shopify standalone button ID: entries_for_purchase_add (wrapper: entries_for_purchase_add_wrapper)
726  // WooCommerce standalone button ID: woocommerce_purchases_add (wrapper: woocommerce_purchases_add_wrapper)
727  $(document.body).on(
728    "click",
729    "#entries_for_purchase_add_wrapper, #woocommerce_purchases_add_wrapper, #entries_for_purchase_add, #woocommerce_purchases_add",
730    function (e) {
731      // Only intercept when these are locked (have disallow class or are inside a wrapper)
732      var $btn = $(this).is("button") ? $(this) : $(this).find("button").first();
733      if ($btn.length && $btn.hasClass("entry_method_add_disallow_pro")) {
734        e.stopPropagation();
735        e.preventDefault();
736        var id = $(this).attr("id") || "";
737        var provider = id.indexOf("woocommerce") !== -1 ? "woocommerce" : "shopify";
738        openShopUpgradeModal(provider);
739      }
740    }
741  );
742
743  // Shop upgrade modal: monthly/annual toggle
744  var _shopBillingCycle = "monthly";
745
746  $(document.body).on("click", "#shop_toggle_monthly", function () {
747    _shopBillingCycle = "monthly";
748    $(this)
749      .removeClass("bg-transparent text-gray-500")
750      .addClass("bg-white shadow-sm text-gray-900");
751    $("#shop_toggle_annual")
752      .removeClass("bg-white shadow-sm text-gray-900")
753      .addClass("bg-transparent text-gray-500");
754    $(".shop-price").each(function () {
755      var p = $(this).attr("data-monthly");
756      $(this).html(
757        "$" +
758        p +
759        '<span class="shop-price-suffix text-xs font-normal text-gray-400">/mo</span>'
760      );
761    });
762  });
763
764  $(document.body).on("click", "#shop_toggle_annual", function () {
765    _shopBillingCycle = "annual";
766    $(this)
767      .removeClass("bg-transparent text-gray-500")
768      .addClass("bg-white shadow-sm text-gray-900");
769    $("#shop_toggle_monthly")
770      .removeClass("bg-white shadow-sm text-gray-900")
771      .addClass("bg-transparent text-gray-500");
772    $(".shop-price").each(function () {
773      var p = $(this).attr("data-annual");
774      $(this).html(
775        "$" +
776        p +
777        '<span class="shop-price-suffix text-xs font-normal text-gray-400">/yr</span>'
778      );
779    });
780  });
781
782  // Shop upgrade plan button click -> open payment section and auto-click the correct plan button
783  $(document.body).on("click", ".shop-upgrade-btn", function () {
784    var plan = $(this).attr("data-plan"); // pro, business, premium, enterprise
785    var planCapitalized =
786      plan.charAt(0).toUpperCase() + plan.slice(1);
787    closePickerModal("shop_upgrade_modal");
788
789    // Highlight the selected plan card
790    $(".pricing-card").removeClass("pricing-highlight");
791    var planIndex = { pro: 1, business: 2, premium: 3, enterprise: 4 };
792    $(".pricing_" + (planIndex[plan] || 1)).addClass("pricing-highlight");
793
794    // Set the billing cycle toggle on the main pricing section to match
795    if (_shopBillingCycle === "annual") {
796      if (!$("#plan_billing_cycle_option").is(":checked")) {
797        $("#plan_billing_cycle_option").trigger('click');
798      }
799    } else {
800      if ($("#plan_billing_cycle_option").is(":checked")) {
801        $("#plan_billing_cycle_option").trigger('click');
802      }
803    }
804
805    // Show the feature message
806    $("#pricing_payment_feature_wrapper")
807      .show()
808      .html(
809        'This feature is included in the <span class="text-primary">' +
810        planCapitalized +
811        "</span> plan."
812      );
813
814    // Open the pricing modal
815    payment_plan_popup();
816  });
817
818  // Add entry method
819  $(document.body).on("click", ".entry_method_add", function () {
820    var type = $(this).attr("id");
821    var div_class = $(this).attr("class");
822    var user_id = getCookie("user_login");
823
824    // Hide all .entry_group_hide and close any open picker modals
825    $(".entry_group_hide, .entry_group_hide_entry_methods").hide();
826    $(".sw-picker-modal:not(.hidden)").each(function () {
827      closePickerModal($(this).attr("id"));
828    });
829
830    // If not entry method, stop function
831    if (!type) {
832      return;
833    }
834
835    // type contains "_add"
836    if (type.indexOf("_add") != -1) {
837      // Minimize all existing entry methods on click of a new one, and expand the new one
838      type_short = type.replace("_add", "");
839      var prizes_container_next_id = parseInt(
840        $("#prizes_container_next_id").val()
841      );
842      $("#prizes_container_next_id").val(prizes_container_next_id + 1);
843      var prizes_container_current_id = prizes_container_next_id - 1;
844
845      $(".entry_method_body_inner").hide();
846      $(".handle").css("border-radius", "10px").attr("data-toggle", "collapse");
847      $("#" + type_short + "-" + prizes_container_current_id + "-inner").show();
848      $("#" + type_short + "-" + prizes_container_current_id + "-handle")
849        .css("border-radius", "10px 10px 0 0")
850        .attr("data-toggle", "expand");
851    }
852
853    var entry_method_class = type;
854
855    // Remove _add from id, and that returns the entry_method_class
856    entry_method_class = entry_method_class.replace("_add_1", "");
857    entry_method_class = entry_method_class.replace("_add_2", "");
858    entry_method_class = entry_method_class.replace("_add", "");
859
860    // Strip shop provider suffix (button ID includes it to avoid duplicates)
861    entry_method_class = entry_method_class.replace("_shopify", "");
862    entry_method_class = entry_method_class.replace("_woocommerce", "");
863    var level = $(this).attr("data-level");
864
865    // id is an alias of entry_method_id
866    var entry_method_id = $(
867      "input[name=entry_methods_previous_entry_id]"
868    ).val();
869    var id = ++entry_method_id;
870
871    $("input[name=entry_methods_previous_entry_id]").val(id);
872
873    // Entry method int
874    var entry_method_int = $(this).attr("data-entry_method_int");
875
876    // Update next entry_method_id value in hidden field
877    $("input[name=entry_methods_previous_entry_id]").val(id);
878
879    var website_plan = parseInt($("#user_website_plan").val());
880    var trial_demo = 0;
881    var legacy_business = parseInt($("#user_legacy_business").val());
882
883    // If viral share entry method
884    if (type == "refer_friends_add") {
885      var entry_methods_container = $("#entry_methods_container").val();
886      if (entry_methods_container !== "") {
887        // Only allow 1 refer-a-friend entry method per giveaway.
888        if (entry_methods_container.indexOf("refer_friends") != -1) {
889          Swal.fire({
890            title: "Oops...",
891            text: 'You\'re only allowed 1 "Refer-A-Friend" entry method per giveaway.',
892            icon: "error",
893            confirmButtonText: "OK",
894          });
895          return;
896        }
897      }
898    }
899
900    // If E-Signature
901    if (type == "e_signature_add") {
902      var entry_methods_container = $("#entry_methods_container").val();
903      if (entry_methods_container !== "") {
904        // Only allow 1 refer-a-friend entry method per giveaway.
905        if (entry_methods_container.indexOf("e_signature") != -1) {
906          Swal.fire({
907            title: "Oops...",
908            text: 'You\'re only allowed 1 "E-Signature" entry method per giveaway.',
909            icon: "error",
910            confirmButtonText: "OK",
911          });
912          return;
913        }
914      }
915    }
916
917    // This class hides entry method translation fields
918    var entry_method_field_pro = "entry_method_field_pro hidden";
919
920    // Set language to English
921    var language = "en";
922    var entry_method_add_disallow_pro = " entry_method_add_disallow_pro";
923    var entry_method_add_disallow_business =
924      " entry_method_add_disallow_business";
925    var entry_method_add_disallow_premium =
926      " entry_method_add_disallow_premium";
927    var icon_color_disallow = " icon_color_disallow";
928    var require_verification_fields_wrapper_class = "";
929
930    var pro_plan_text =
931      '&nbsp;<b class="available_in_pro_plan_text paid_plan_tip">&bull; Pro</b>';
932    var checkbox_pro_enable_disable = ' disabled="1"';
933    var checkbox_pro_enable_disable_class =
934      " checkbox_pro_enable_disable_class";
935    var input_field_pro_enable_disable = ' readonly="readonly"';
936
937    var business_plan_text =
938      '&nbsp;<b class="available_in_business_plan_text paid_plan_tip">&bull; Business plan</b>';
939    var checkbox_business_enable_disable = ' disabled="1"';
940    var checkbox_business_enable_disable_class =
941      " checkbox_business_enable_disable_class";
942    var input_field_business_enable_disable = ' readonly="readonly"';
943    var business_button_classes = "entry_method_add_disallow_business";
944    var disabled_business = 'disabled="disabled"';
945
946    var premium_plan_text =
947      '&nbsp;<b class="available_in_premium_plan_text paid_plan_tip">&bull; Premium</b>';
948    var checkbox_premium_enable_disable = ' disabled="1"';
949    var checkbox_premium_enable_disable_class =
950      " checkbox_premium_enable_disable_class";
951    var input_field_premium_enable_disable = ' readonly="readonly"';
952    var premium_button_classes = "entry_method_add_disallow_premium";
953    var disabled_premium = 'disabled="disabled"';
954
955    var enterprise_plan_text =
956      '&nbsp;<b class="available_in_enterprise_plan_text paid_plan_tip">&bull; enterprise</b>';
957    var checkbox_enterprise_enable_disable = ' disabled="1"';
958    var checkbox_enterprise_enable_disable_class =
959      " checkbox_enterprise_enable_disable_class";
960    var input_field_enterprise_enable_disable = ' readonly="readonly"';
961    var enterprise_button_classes = "entry_method_add_disallow_enterprise";
962    var disabled_enterprise = 'disabled="disabled"';
963
964    var masked_viral_share_links_message =
965      '<div class="w-full mt-[15px] mb-5 float-left">' +
966      '<div class="input_holder_full mb-0">' +
967      'Auto-add masked whitelabeled viral sharing links with the <b class="available_in_pro_plan_text paid_plan_tip">* (Premium plan)</b>' +
968      "</div>" +
969      "</div>" +
970      '<div class="w-full mb-0 float-left">' +
971      '<div class="input_holder_full mb-0">' +
972      'Refer users to the embedded giveaway on your website instead of the hosted landing page (if you\'re embedding the giveaway) with the <b class="available_in_pro_plan_text paid_plan_tip">* (Premium plan)</b>' +
973      "</div>" +
974      "</div>";
975
976    var enterprise_plan_text =
977      '&nbsp;<b class="available_in_enterprise_plan_text paid_plan_tip">&bull; enterprise</b>';
978    var checkbox_enterprise_enable_disable = ' disabled="1"';
979    var checkbox_enterprise_enable_disable_class =
980      " checkbox_enterprise_enable_disable_class";
981    var input_field_enterprise_enable_disable = ' readonly="readonly"';
982
983    // Pro+
984    if (
985      plan_level("pro", "equal_or_more", website_plan, payment_platform) == true
986    ) {
987      // Show entry method translation fields
988      entry_method_field_pro = "";
989
990      // Currently set language
991      language = $("#language_add").val();
992
993      pro_plan_text = "";
994      pro_plan_text_long = "";
995      entry_method_add_disallow_pro = "";
996      checkbox_pro_enable_disable = "";
997      checkbox_pro_enable_disable_class = "";
998      input_field_pro_enable_disable = "";
999      icon_color_disallow = "";
1000      require_verification_fields_wrapper_class = "!block";
1001      disabled_pro_text = "";
1002      disabled_pro = "";
1003
1004      // Business+
1005      if (
1006        plan_level(
1007          "business",
1008          "equal_or_more",
1009          website_plan,
1010          payment_platform
1011        ) == true
1012      ) {
1013        business_plan_text = "";
1014        checkbox_business_enable_disable = "";
1015        checkbox_business_enable_disable_class = "";
1016        input_field_business_enable_disable = "";
1017        business_button_classes = "";
1018        disabled_business = "";
1019      }
1020
1021      // Premium+
1022      if (
1023        plan_level(
1024          "premium",
1025          "equal_or_more",
1026          website_plan,
1027          payment_platform
1028        ) == true
1029      ) {
1030        premium_plan_text = "";
1031        checkbox_premium_enable_disable = "";
1032        checkbox_premium_enable_disable_class = "";
1033        input_field_premium_enable_disable = "";
1034        masked_viral_share_links_message = "";
1035        premium_button_classes = "";
1036        disabled_premium = "";
1037      }
1038
1039      // Enterprise plan+
1040      if (
1041        plan_level(
1042          "enterprise",
1043          "equal_or_more",
1044          website_plan,
1045          payment_platform
1046        ) == true
1047      ) {
1048        enterprise_plan_text = "";
1049        checkbox_enterprise_enable_disable = "";
1050        checkbox_enterprise_enable_disable_class = "";
1051        input_field_enterprise_enable_disable = "";
1052        enterprise_button_classes = "";
1053        disabled_enterprise = "";
1054      }
1055    }
1056
1057    // Create word version of level i.e. 1 = one, 2 = two
1058
1059    if (level) {
1060      // check for current level
1061      expand_minimize_checkbox_show_hide(level, "add");
1062    }
1063
1064    // Entry methods count
1065    var entry_methods_count = entry_methods_count_func();
1066
1067    // Append entry_method_int to #repeatable_actions_container
1068    var repeatable_actions_container = $("#repeatable_actions_container").val();
1069
1070    var repeatable_actions_count = occurrences(
1071      repeatable_actions_container,
1072      entry_method_class
1073    );
1074
1075    var repeatable_actions_limit = repeatable_actions_limit_func(
1076      website_plan,
1077      trial_demo,
1078      legacy_business,
1079      "",
1080      "",
1081      "count",
1082      user_id,
1083      payment_platform
1084    );
1085
1086    // If Free plan and entry_methods_count > 5
1087    if (
1088      plan_level("free", "equal", website_plan, payment_platform) == true &&
1089      entry_methods_count > 5
1090    ) {
1091      Swal.fire({
1092        title: "Oops...",
1093        text: "You've reached your limit of 5 entry methods. You can upgrade to a Pro plan for 40 entry methods.",
1094        icon: "error",
1095        confirmButtonText: "OK",
1096      });
1097
1098      // If Pro plan and entry_methods_count > 40
1099    } else if (
1100      plan_level("pro", "equal", website_plan, payment_platform) == true &&
1101      entry_methods_count > plan_entry_limit(2, payment_platform)
1102    ) {
1103      Swal.fire({
1104        title: "Oops...",
1105        text:
1106          "You've reached your limit of " +
1107          plan_entry_limit(2, payment_platform) +
1108          " entry methods. You can upgrade to a Business plan for " +
1109          plan_entry_limit(5, payment_platform) +
1110          " entry methods, Premium plan for " +
1111          plan_entry_limit(8, payment_platform) +
1112          " entry methods, or the Enterprise plan for " +
1113          plan_entry_limit(11, payment_platform) +
1114          " entry methods.",
1115        icon: "error",
1116        confirmButtonText: "OK",
1117      });
1118
1119      // If Business plan and entry_methods_count > 60
1120    } else if (
1121      plan_level("business", "equal", website_plan, payment_platform) == true &&
1122      entry_methods_count > plan_entry_limit(5, payment_platform)
1123    ) {
1124      Swal.fire({
1125        title: "Oops...",
1126        text:
1127          "You've reached your limit of " +
1128          plan_entry_limit(5, payment_platform) +
1129          " entry methods. You can upgrade to a Premium plan for " +
1130          plan_entry_limit(8, payment_platform) +
1131          " entry methods or the Enterprise plan for " +
1132          plan_entry_limit(11, payment_platform) +
1133          " entry methods.",
1134        icon: "error",
1135        confirmButtonText: "OK",
1136      });
1137
1138      // If Premium plan and entry_methods_count > 80
1139    } else if (
1140      plan_level("premium", "equal", website_plan, payment_platform) == true &&
1141      entry_methods_count > plan_entry_limit(8, payment_platform)
1142    ) {
1143      Swal.fire({
1144        title: "Oops...",
1145        text:
1146          "You've reached your limit of " +
1147          plan_entry_limit(8, payment_platform) +
1148          " entry methods. You can upgrade to an Enterprise plan for " +
1149          plan_entry_limit(11, payment_platform) +
1150          " entry methods.",
1151        icon: "error",
1152        confirmButtonText: "OK",
1153      });
1154
1155      // If Enterprise plan and entry_methods_count > 125
1156    } else if (
1157      plan_level("enterprise", "equal", website_plan, payment_platform) ==
1158      true &&
1159      entry_methods_count > plan_entry_limit(11, payment_platform)
1160    ) {
1161      Swal.fire({
1162        title: "Oops...",
1163        text:
1164          "You've reached your limit of " +
1165          plan_entry_limit(11, payment_platform) +
1166          " entry methods.",
1167        icon: "error",
1168        confirmButtonText: "OK",
1169      });
1170
1171      // Don't allow... max repeatable actions
1172    } else if (repeatable_actions_count >= repeatable_actions_limit) {
1173      var entry_method_handle = entry_method_fetch_values(
1174        entry_method_class,
1175        "entry_method_handle",
1176        "",
1177        "",
1178        "",
1179        "",
1180        ""
1181      );
1182      var entry_method_docs_link = entry_method_fetch_values(
1183        entry_method_class,
1184        "entry_method_docs_link",
1185        "",
1186        "",
1187        "",
1188        "",
1189        ""
1190      );
1191
1192      // This function returns a message for max allowed repeatable actions
1193      var repeatable_limit_display = repeatable_actions_limit_func(
1194        website_plan,
1195        trial_demo,
1196        legacy_business,
1197        repeatable_actions_limit,
1198        entry_method_handle,
1199        "message",
1200        user_id,
1201        payment_platform
1202      );
1203
1204      Swal.fire({
1205        title: "Oops...",
1206        text: repeatable_limit_display,
1207        icon: "error",
1208        confirmButtonText: "OK",
1209      });
1210
1211      // Continue... repeatable action is allowed
1212    } else {
1213      // Get this from hidden fields from an ajax on when the language is changed. Or, if it's already set on update / reload
1214      var translate_endcoded = $("#language_translations").val();
1215
1216      if (translate_endcoded !== "") {
1217        // Decode translate from hidden value
1218        var translate_decoded = JSON.parse(
1219          decodeURIComponent(translate_endcoded)
1220        );
1221
1222        // I have to save translate like this becuase json object is saved within "translate"
1223        var translate = translate_decoded["translate"];
1224      }
1225
1226      $("#repeatable_actions_container").val(
1227        repeatable_actions_container + "," + entry_method_class
1228      );
1229
1230      // Batch-fetch all entry method field values in one call
1231      var em = entry_method_fetch_all(entry_method_class, language, translate);
1232
1233      // Static fields
1234      var entry_method_handle = em.entry_method_handle;
1235      var entry_method_docs_link = em.entry_method_docs_link;
1236      var entry_method_handle_hint = em.entry_method_handle_hint;
1237      var entry_title = em.entry_title;
1238      var entry_title_header = em.entry_title_header;
1239      var entry_title_placeholder = em.entry_title_placeholder;
1240      var entry_title_value = em.entry_title_value;
1241      var entry_link = em.entry_link;
1242      var entry_link_header = em.entry_link_header;
1243      var entry_link_placeholder = em.entry_link_placeholder;
1244      var entry_link_validation = em.entry_link_validation;
1245      var entry_link_validation_error = em.entry_link_validation_error;
1246      var entry_amount = em.entry_amount;
1247      var entry_amount_header = em.entry_amount_header;
1248      var entry_amount_placeholder = em.entry_amount_placeholder;
1249      var entry_textarea = em.entry_textarea;
1250      var entry_textarea_header = em.entry_textarea_header;
1251      var entry_textarea_placeholder = em.entry_textarea
1251_placeholder;
1252      var entry_textarea_value = em.entry_textarea_value;
1253      var entry_textarea_note = em.entry_textarea_note;
1254      var entry_textarea_max_length = em.entry_textarea_max_length;
1255      var input_header_placeholder = em.input_header_placeholder;
1256      var additional_instructions = em.additional_instructions;
1257      var additional_instructions_placeholder = em.additional_instructions_placeholder;
1258      var additional_instructions_value = em.additional_instructions_value;
1259      var additional_instructions_header = em.additional_instructions_header;
1260      var additional_instructions_note = em.additional_instructions_note;
1261      var additional_instructions_max_length = em.additional_instructions_max_length;
1262      var daily = em.daily;
1263      var timer = em.timer;
1264      var social_optional_engagement = em.social_optional_engagement;
1265      var social_optional_engagement_header = em.social_optional_engagement_header;
1266      var require_verification = em.require_verification;
1267      var require_verification_header = em.require_verification_header;
1268      var require_verification_checked_by_default = em.require_verification_checked_by_default;
1269      var required = em.required;
1270      var custom_icon = em.custom_icon;
1271      var input_type = em.input_type;
1272      var entry_attachment = em.entry_attachment;
1273      var entry_attachment_header = em.entry_attachment_header;
1274      var entry_attachment_hint = em.entry_attachment_hint;
1275      var entry_attachment_value = em.entry_attachment_value;
1276      var entry_attachment_validation = em.entry_attachment_validation;
1277      var entry_attachment_validation_error = em.entry_attachment_validation_error;
1278      var email_integration = em.email_integration;
1279      var upload_a_file = em.upload_a_file;
1280      var upload_a_file_ext = em.upload_a_file_ext;
1281      var viral_share = em.viral_share;
1282      var make_a_purchase = em.make_a_purchase;
1283      var viral_share_options = em.viral_share_options;
1284      var color = em.color;
1285      var background_color = em.background_color;
1286      var font_awesome_icon = em.font_awesome_icon;
1287      var api_auth = em.api_auth;
1288      var api_auth_required = em.api_auth_required;
1289
1290      // Translated fields
1291      var input_header_value = em.input_header_value;
1292      var link_button_text_value = em.link_button_text_value;
1293      var verify_header_value = em.verify_header_value;
1294      var verify_button_text_value = em.verify_button_text_value;
1295
1296      // Strip html and trim
1297      input_header_value = stripHtml(input_header_value).trim();
1298      link_button_text_value = stripHtml(link_button_text_value).trim();
1299      verify_header_value = stripHtml(verify_header_value).trim();
1300      verify_button_text_value = stripHtml(verify_button_text_value).trim();
1301
1302      var daily_checked_value = 0;
1303      var timer_checked_value = 0;
1304      var daily_checked = "";
1305      var timer_checked = 0;
1306      var required_checked_value = 0;
1307      var required_checked = "";
1308      var custom_icon_checked_value = 0;
1309      var custom_icon_checked = "";
1310      var social_optional_engagement_value = 0;
1311      var more_options_checkbox_checked = "";
1312      var social_optional_engagement_checked = "";
1313      var social_optional_engagement_disabled = "";
1314      var require_verification_value = 0;
1315      var require_verification_disabled = "";
1316
1317      if (level == 1) {
1318        var daily = 0;
1319        var entry_amount = 0;
1320        var required = 1;
1321        var required_checked_value = 1;
1322        var required_checked = ' checked="checked"';
1323      }
1324
1325      // if get_two container "photo-contest"
1326      if (get_two.indexOf("photo-contest") != -1) {
1327        var entry_amount = 0;
1328      }
1329
1330      /*
1331        if (daily >= 1 && daily_checked_value >= 1 ) { // confirm if it should be ">= 1" or just "== 1" ?
1332          daily_checked = ' checked="checked"';
1333        }
1334        */
1335
1336      // Initially set each var to empty
1337      var entry_method_handle_display = "";
1338      var entry_amount_display = "";
1339      var entry_title_display = "";
1340      var entry_link_display = "";
1341      var entry_textarea_display = "";
1342      var entry_attachment_display = "";
1343      var email_integration_display = "";
1344      var viral_share_display = "";
1345      var upload_a_file_ext_options_display = "";
1346      var daily_display = "";
1347      var timer_display = "";
1348      var required_display = "";
1349      var tracking_options_display = "";
1350      var tracking_options_display_hidden_wrapper = "";
1351      var telegram_public_private_display = "";
1352      var custom_icon_display = "";
1353      var more_options_display = "";
1354      var more_options_hide = "default";
1355      var entries_for_purchase_send_email_checkbox_display = "";
1356      var entries_for_purchase_advanced_options_display = "";
1357      var auto_enter_people_who_made_purchase_checkbox_display = "";
1358      var social_optional_engagement_display = "";
1359      var require_verification_display = "";
1360      var input_type_display = "";
1361      var input_header_display = "";
1362      var link_button_text_display = "";
1363      var verify_header_display = "";
1364      var verify_button_text_display = "";
1365      var additional_instructions_display = "";
1366      var upload_a_file_ext_display = "";
1367      var custom_radio_options_display = "";
1368      var custom_radio_options_display_question = "";
1369      var api_auth_display = "";
1370      var entries_for_purchase_platform_options_display = "";
1371      var entries_for_purchase_info_display = "";
1372
1373      var add_font_style_bold = "";
1374      var add_font_style_italic = "";
1375      var add_font_style_underline = "";
1376      var add_font_style_link = "";
1377      var add_font_style_phone = "";
1378      var add_font_style_copy_paste = "";
1379
1380      if (require_verification_checked_by_default == 1) {
1381        var require_verification_checked_display = ' checked="checked"';
1382      } else {
1383        var require_verification_checked_display = "";
1384      }
1385
1386      // If entry method is NOT twitter_tweet, create the wysiwyg buttons
1387      if (
1388        entry_method_class !== "twitter_tweet" &&
1389        entry_method_class !== "x_post"
1390      ) {
1391        var add_font_style_bold =
1392          '<div title="Bold" class="sw_add_font_style_icon" data-entry_method_class="' +
1393          entry_method_class +
1394          '" data-entry_method_id="' +
1395          id +
1396          '" data-additional_instructions="' +
1397          additional_instructions +
1398          '" data-entry_textarea="' +
1399          entry_textarea +
1400          '" data-font_style="b">' +
1401          '<i class="fas fa-bold"></i>' +
1402          "</div>";
1403
1404        var add_font_style_italic =
1405          '<div title="Italic" class="sw_add_font_style_icon" data-entry_method_class="' +
1406          entry_method_class +
1407          '" data-entry_method_id="' +
1408          id +
1409          '" data-additional_instructions="' +
1410          additional_instructions +
1411          '" data-entry_textarea="' +
1412          entry_textarea +
1413          '" data-font_style="i">' +
1414          '<i class="fas fa-italic"></i>' +
1415          "</div>";
1416
1417        var add_font_style_underline =
1418          '<div title="Underline" class="sw_add_font_style_icon" data-entry_method_class="' +
1419          entry_method_class +
1420          '" data-entry_method_id="' +
1421          id +
1422          '" data-additional_instructions="' +
1423          additional_instructions +
1424          '" data-entry_textarea="' +
1425          entry_textarea +
1426          '" data-font_style="u">' +
1427          '<i class="fas fa-underline"></i>' +
1428          "</div>";
1429
1430        var add_font_style_link =
1431          '<div title="Link" class="sw_add_font_style_icon_2" data-entry_method_class="' +
1432          entry_method_class +
1433          '" data-entry_method_id="' +
1434          id +
1435          '" data-additional_instructions="' +
1436          additional_instructions +
1437          '" data-entry_textarea="' +
1438          entry_textarea +
1439          '" data-link_type="link">' +
1440          '<i class="fas fa-link"></i>' +
1441          "</div>";
1442
1443        if (
1444          plan_level("pro", "equal_or_more", website_plan, payment_platform) ==
1445          true
1446        ) {
1447          var add_font_style_phone =
1448            '<div title="Phone Number" class="sw_add_font_style_icon_2" data-entry_method_class="' +
1449            entry_method_class +
1450            '" data-entry_method_id="' +
1451            id +
1452            '" data-additional_instructions="' +
1453            additional_instructions +
1454            '" data-entry_textarea="' +
1455            entry_textarea +
1456            '" data-link_type="phone">' +
1457            '<i class="fas fa-phone"></i>' +
1458            "</div>";
1459
1460          var add_font_style_copy_paste =
1461            '<div title="Copy & Paste" class="sw_add_font_style_icon_2" data-entry_method_class="' +
1462            entry_method_class +
1463            '" data-entry_method_id="' +
1464            id +
1465            '" data-additional_instructions="' +
1466            additional_instructions +
1467            '" data-entry_textarea="' +
1468            entry_textarea +
1469            '" data-link_type="copy_paste">' +
1470            '<i class="fas fa-clipboard"></i>' +
1471            "</div>";
1472        }
1473      }
1474
1475      // Append field if it's used by entry method
1476
1477      var entry_level_display =
1478        '<input type="hidden" name="entry_level_' +
1479        entry_method_class +
1480        "_" +
1481        id +
1482        '" value="' +
1483        level +
1484        '" />';
1485
1486      if (entry_method_handle) {
1487        var entry_method_handle_header = "Entry Label";
1488        var entry_method_handle_placeholder = entry_method_handle;
1489        var entry_method_handle_value = entry_method_handle;
1490
1491        // hide "Title" entry input for level1 additional entry methods.
1492        var style_css = "";
1493        if (level == 1) {
1494          style_css = ' style="display:none;"';
1495        }
1496
1497        var entry_method_handle_wrapper_class =
1498          get_two.indexOf("photo-contest") != -1
1499            ? "input_holder_full"
1500            : "input_holder_1";
1501
1502        var entry_method_handle_display =
1503          '<div class="' +
1504          entry_method_handle_wrapper_class +
1505          '"' +
1506          style_css +
1507          ">" +
1508          '<div id="entry_method_handle_header_' +
1509          entry_method_class +
1510          "_" +
1511          id +
1512          '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
1513          entry_method_handle_header +
1514          "</div>" +
1515          '<input type="text" autocomplete="off" name="entry_method_handle_' +
1516          entry_method_class +
1517          "_" +
1518          id +
1519          '" class="entry_input" placeholder="' +
1520          entry_method_handle_placeholder +
1521          '" value= "' +
1522          entry_method_handle_value +
1523          '" maxlength="255" data-entry_method_class="' +
1524          entry_method_class +
1525          '" data-entry_method_id="' +
1526          id +
1527          '" />' +
1528          "</div>";
1529      }
1530
1531      // Entry title
1532      if (entry_title == 1) {
1533        var style = "";
1534
1535        var entry_title_wrapper_class = (entry_method_class === "upload_a_file" && get_two.indexOf("photo-contest") != -1) ? "input_holder_full" : "input_holder_1";
1536
1537        var entry_title_display =
1538          '<div class="' + entry_title_wrapper_class + '"' +
1539          style +
1540          ">" +
1541          '<div id="entry_title_header_' +
1542          entry_method_class +
1543          "_" +
1544          id +
1545          '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
1546          entry_title_header +
1547          "</div>" +
1548          '<input type="text" autocomplete="off" name="entry_title_' +
1549          entry_method_class +
1550          "_" +
1551          id +
1552          '" class="entry_input" placeholder="' +
1553          entry_title_placeholder +
1554          '" value="' +
1555          entry_title_value +
1556          '" maxlength="255" />' +
1557          "</div>";
1558      }
1559
1560      // Entry link
1561      if (entry_link == 1) {
1562        if (entry_method_class == "secret_code") {
1563          // textarea
1564          var entry_link_input =
1565            '<div class="w-full float-left">' +
1566            '<textarea autocomplete="off" name="entry_link_' +
1567            entry_method_class +
1568            "_" +
1569            id +
1570            '" class="sw-textarea entry_link relative my-4" placeholder="' +
1571            entry_link_placeholder +
1572            '" maxlength="1000000" entry_method_text="' +
1573            entry_method_class +
1574            '" data-gramm="false"></textarea>' +
1575            "</div>";
1576        } else {
1577          // text
1578          var entry_link_input =
1579            '<input type="text" autocomplete="off" name="entry_link_' +
1580            entry_method_class +
1581            "_" +
1582            id +
1583            '" class="entry_input entry_link" placeholder="' +
1584            entry_link_placeholder +
1585            '" maxlength="255" entry_method_text="' +
1586            entry_method_class +
1587            '" />';
1588        }
1589        var entry_link_display =
1590          '<div class="input_holder_1">' +
1591          '<div id="entry_link_header_' +
1592          entry_method_class +
1593          "_" +
1594          id +
1595          '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
1596          entry_link_header +
1597          '<span class="validation_error" style="color: red; display: none;">&nbsp;' +
1598          entry_link_validation_error +
1599          "</span>" +
1600          "</div>" +
1601          entry_link_input +
1602          "</div>";
1603      }
1604
1605      // Textarea
1606      if (entry_textarea == 1) {
1607        var user_id = getCookie("user_login");
1608
1609        // Twitter Tweet FIRST create
1610        if (
1611          entry_method_class == "twitter_tweet" ||
1612          entry_method_class == "x_post"
1613        ) {
1614          var tweet_or_post =
1615            entry_method_class == "twitter_tweet" ? "Tweet" : "Post";
1616          var twitter_tweet_num = 1;
1617          var header_id =
1618            "entry_textarea_header_" +
1619            entry_method_class +
1620            "_" +
1621            id +
1622            "-" +
1623            twitter_tweet_num;
1624          var header_class = "entry_group_handle ui-sortable-handle flex items-center justify-between";
1625          var textarea_name =
1626            "entry_textarea_" +
1627            entry_method_class +
1628            "_" +
1629            id +
1630            "-" +
1631            twitter_tweet_num;
1632          var data_attributes =
1633            'data-entry_method_class="' +
1634            entry_method_class +
1635            '" data-entry_method_id="' +
1636            id +
1637            '" data-entry_group_id="' +
1638            twitter_tweet_num +
1639            '"';
1640          var entry_textarea_header =
1641            tweet_or_post + " (" + twitter_tweet_num + ")";
1642          var textarea_class = "entry_textarea_tweet";
1643
1644          var entry_textarea_display =
1645            '<div class="input_holder_full mt-[10px]">' +
1646            '<div class="w-full mt-[10px] mb-[5px] float-left">Duplicate ' +
1647            tweet_or_post +
1648            "s will be removed</div>" +
1649            '<div id="textarea_' +
1650            entry_method_class +
1651            "_wrapper-" +
1652            id +
1653            '">' +
1654            '<div id="entry_group-' +
1655            id +
1656            '" class="ui-sortable">' +
1657            '<div id="' +
1658            twitter_tweet_num +
1659            '" class="entry_group_each" ' +
1660            data_attributes +
1661            ">" +
1662            '<div id="entry_textarea_header_' +
1663            header_id +
1664            '" class="' +
1665            header_class +
1666            '">' +
1667            '<div class="entry_group_handle_text">' +
1668            entry_textarea_header +
1669            "</div>" +
1670            '<div class="entry_group_handle_delete flex items-center justify-center w-6 h-6 rounded hover:bg-black/10 transition-colors cursor-pointer text-gray-400 hover:text-gray-600" title="Remove">' +
1671            '<i class="fas fa-times text-xs"></i>' +
1672            "</div>" +
1673            "</div>" +
1674            '<div class="w-full float-left">' +
1675            '<textarea id="' +
1676            textarea_name +
1677            '" name="' +
1678            textarea_name +
1679            '" class="' +
1680            textarea_class +
1681            ' sw-textarea" placeholder="' +
1682            entry_textarea_placeholder +
1683            '" maxlength="' +
1684            entry_textarea_max_length +
1685            '" data-gramm="false">' +
1686            "</textarea>" +
1687            '<span class="sw_entry_textarea_note">' +
1688            entry_textarea_note +
1689            "</span>" +
1690            "</div>" +
1691            "</div>" +
1692            "</div>" +
1693            "</div>" +
1694            '<input type="hidden" name="' +
1695            entry_method_class +
1696            "_" +
1697            id +
1698            '-num" value="' +
1699            twitter_tweet_num +
1700            '" />' +
1701            '<input type="hidden" name="' +
1702            entry_method_class +
1703            "_" +
1704            id +
1705            '-num-list" value="' +
1706            twitter_tweet_num +
1707            '" />' +
1708            '<div class="w-full float-left clear-both mt-2"><button type="button" class="' +
1709            entry_method_class +
1710            '_append inline-flex items-center gap-1.5 py-2 px-4 text-[13px] font-medium text-[#4a3aff] bg-white border border-gray-200 rounded-lg cursor-pointer outline-none transition-all duration-200 hover:border-[#4a3aff]/40 hover:bg-[#4a3aff]/[0.04]" id="' +
1711            entry_method_class +
1712            "_append-" +
1713            id +
1714            '" data-entry_method_class="' +
1715            entry_method_class +
1716            '" data-entry_method_id="' +
1717            id +
1718            '" data-entry_group_id="' +
1719            twitter_tweet_num +
1720            '">+ Add Another ' +
1721            tweet_or_post +
1722            "</button></div>";
1723
1724          // Textarea for everything other than Twitter tweet
1725        } else {
1726          var entry_textarea_display =
1727            '<div class="input_holder_full">' +
1728            '<div id="entry_textarea_header_' +
1729            entry_method_class +
1730            "_" +
1731            id +
1732            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
1733            entry_textarea_header +
1734            "</div>" +
1735            '<div class="w-full float-left">' +
1736            '<textarea name="entry_textarea_' +
1737            entry_method_class +
1738            "_" +
1739            id +
1740            '" class="sw-textarea" placeholder="' +
1741            entry_textarea_placeholder +
1742            '" maxlength="' +
1743            entry_textarea_max_length +
1744            '" data-gramm="false">' +
1745            entry_textarea_value +
1746            "</textarea>" +
1747            "</div>" +
1748            '<div class="sw_add_font_style_icons_set_holder">' +
1749            add_font_style_bold +
1750            add_font_style_italic +
1751            add_font_style_underline +
1752            add_font_style_link +
1753            add_font_style_phone +
1754            add_font_style_copy_paste +
1755            "</div>" +
1756            '<span class="sw_entry_textarea_note">' +
1757            entry_textarea_note +
1758            "</span>" +
1759            "</div>";
1760        }
1761      }
1762
1763      // Entry amount
1764      if (entry_amount == 1) {
1765        if (entry_method_class == "entries_for_purchase" || entry_method_class == "woocommerce_purchases") {
1766          // Purchase methods: inline "Earn X entries for every $Y spent"
1767          var entry_amount_display =
1768            '<div class="w-full float-left mt-5 mb-2">' +
1769            '<div class="w-full mb-[5px] text-[15px] font-semibold text-[#374151]">Entry Rate</div>' +
1770            '<div class="flex items-center gap-2 text-[15px] text-[#374151] global-entry-rate-row" id="global_entry_rate_row_' + entry_method_class + '_' + entry_method_id + '">' +
1771            '<span>Earn</span>' +
1772            '<input type="number" name="entry_amount_' + entry_method_class + '_' + entry_method_id + '" class="w-[70px] px-2 py-1.5 border border-[#ccc] rounded text-sm text-center bg-white entry_input_pro" value="1" min="1" max="1000" step="1" />' +
1773            '<span>entries for every</span>' +
1774            '<div class="flex items-center gap-0.5">' +
1775            '<span class="text-[#555]">$</span>' +
1776            '<input type="number" name="dollars_per_entry_' + entry_method_class + '_' + entry_method_id + '" class="w-[70px] px-2 py-1.5 border border-[#ccc] rounded text-sm text-center bg-white dollars-per-entry-input" value="1" min="1" max="10000" step="1" data-entry_method_class="' + entry_method_class + '" data-entry_method_id="' + entry_method_id + '" />' +
1777            '</div>' +
1778            '<span>spent</span>' +
1779            '</div></div>';
1780        } else {
1781          var entry_amount_display =
1782            '<div class="input_holder_1">' +
1783            '<div id="entry_amount_header_' +
1784            entry_method_class +
1785            "_" +
1786            id +
1787            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
1788            entry_amount_header +
1789            "</div>" +
1790            '<input type="number" name="entry_amount_' +
1791            entry_method_class +
1792            "_" +
1793            id +
1794            '" class="entry_input entry_input_pro" placeholder="' +
1795            entry_amount_placeholder +
1796            '" value="1" min="1" max="999" step="1" />' +
1797            "</div>";
1798        }
1799      }
1800
1801      // Entry attachment
1802      if (entry_attachment == 1) {
1803        var attachment_file_path =
1804          "https://sweepwidget.fra1.digitaloceanspaces.com/images/root/image3.png";
1805
1806        var entry_attachment_display =
1807          '<div id="entry_attachment_holder_' +
1808          entry_method_class +
1809          "_" +
1810          entry_method_id +
1811          '" class="w-full float-left">' +
1812          '<div class="input_holder_1">' +
1813          '<div id="entry_attachment_header_' +
1814          entry_method_class +
1815          "_" +
1816          entry_method_id +
1817          '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
1818          entry_attachment_header +
1819          "</div>" +
1820          '<div class="sw_entry_hint">' +
1821          entry_attachment_hint +
1822          "</div>" +
1823          '<label class="fileUpload">' +
1824          '<input type="file" name="entry_attachment_' +
1825          entry_method_class +
1826          "_" +
1827          entry_method_id +
1828          '" id="entry_attachment_' +
1829          entry_method_class +
1830          "_" +
1831          entry_method_id +
1832          '" class="entry_attachment_file upload" onchange="entry_attachment_file_upload(this, \'' +
1833          entry_method_class +
1834          "', '" +
1835          entry_method_id +
1836          "')\" />" +
1837          '<span class="attachment_image entry_attachment_value_' +
1838          entry_method_class +
1839          "_" +
1840          entry_method_id +
1841          '">' +
1842          entry_attachment_value +
1843          "</span>" +
1844          "</label>" +
1845          "</div>" +
1846          '<div class="input_holder_1">' +
1847          '<div class="w-full mt-5 mb-[5px] text-[15px] float-left">Preview</div>' +
1848          '<div class="m-0">' +
1849          '<img class="entry_attachment_preview" src="' +
1850          attachment_file_path +
1851          '" width="100px" height="65px"; />' +
1852          '<input type="hidden" name="entry_attachment_preview_hidden_' +
1853          entry_method_class +
1854          "_" +
1855          entry_method_id +
1856          '" class="entry_attachment_preview_hidden" value="" />' +
1857          "</div>" +
1858          "</div>" +
1859          "</div>";
1860      }
1861
1862      // Email integration i.e. Mailchimp, ActiveCampaign, Aweber, etc.
1863      if (email_integration == 1) {
1864        var email_integration_display = buildEmailIntegrationDisplay(entry_method_class, id, website_url);
1865      }
1866
1867      // Upload a file ext
1868      if (upload_a_file == 1 && entry_method_class == "upload_a_file") {
1869        var upload_a_file_ext_options_display = "";
1870
1871        // Loop through all file types categories
1872        for (var category in upload_a_file_ext) {
1873          if (upload_a_file_ext.hasOwnProperty(category)) {
1874            // Add category header
1875            upload_a_file_ext_options_display +=
1876              '<div class="font-bold mt-5 w-full mb-[15px] float-left">' +
1877              category +
1878              ":</div>";
1879
1880            // Loop through options in the category
1881            var options = upload_a_file_ext[category];
1882            for (var i = 0; i < options.length; i++) {
1883              var option = options[i];
1884              var checked = option.checked ? ' checked="checked"' : "";
1885
1886              upload_a_file_ext_options_display +=
1887                '<label class="upload_a_file_checkbox_label mr-[25px] mb-[10px] cursor-pointer inline-block float-left">' + // Ensure block display and pointer cursor for better clickability
1888                '<input type="checkbox" class="sw-checkbox" name="upload_a_file_ext_' +
1889                entry_method_class +
1890                "_" +
1891                entry_method_id +
1892                '[]" value="' +
1893                option.ext +
1894                '" ' +
1895                checked +
1896                " />" + // Add 'sw-checkbox' for custom styling
1897                '<span>' +
1898                option.ext +
1899                "</span>" + // Use margin for spacing between checkbox and label text
1900                "</label>";
1901            }
1902          }
1903        }
1904
1905        upload_a_file_ext_display =
1906          '<div class="w-full mb-0 float-left">' +
1907          '<div class="input_holder_5 mb-0">' +
1908          '<div id="upload_a_file_ext_header_' +
1909          entry_method_class +
1910          "_" +
1911          entry_method_id +
1912          '" class="input_header_2 text-[15px]">' +
1913          "&nbsp;Allowed file types:" +
1914          "</div>" +
1915          "</div>" +
1916          "</div>" +
1917          '<div id="upload_a_file_ext_checkbox_options_holder_' +
1918          entry_method_id +
1919          '" class="input_holder_full">' +
1920          upload_a_file_ext_options_display +
1921          "</div>" +
1922          '<div class="input_holder_full mt-[20px]">' +
1923          "Maximum upload size is 100mb." +
1924          "</div>";
1925      }
1926
1927      // Viral share
1928      if (viral_share == 1) {
1929        var viral_share_options_display = "";
1930        var viral_share_award_bonus_entries_amount_show_hide = "display:none;";
1931        var if_viral_share_award_bonus_entries_checked_value = 0;
1932        var if_viral_share_award_bonus_entries_checked = "";
1933        var viral_share_max_allowed_referrals_amount_show_hide =
1934          "display:none;";
1935        var if_viral_share_max_allowed_referrals_checked_value = 0;
1936        var if_viral_share_max_allowed_referrals_checked = "";
1937        var only_give_credit_after_friend_earns_entries_checked_value = 0;
1938        var only_give_credit_after_friend_earns_entries_checked = "";
1939        var only_give_credit_after_friend_earns_entries_show_hide =
1940          "display:none;";
1941
1942        for (var i = 0; i < viral_share_options.length; i++) {
1943          var option = viral_share_options[i];
1944
1945          var checked = "";
1946
1947          if (option.checked) {
1948            checked = ' checked="checked"';
1949          }
1950
1951          viral_share_options_display +=
1952            '<label class="mr-[25px] mb-[10px] cursor-pointer inline-block float-left">' +
1953            '<input type="checkbox" class="sw-checkbox ' +
1954            option.name +
1955            '" name="viral_share_' +
1956            entry_method_class +
1957            "_" +
1958            entry_method_id +
1959            '[]" id="viral_share_' +
1960            option.name +
1961            "_" +
1962            entry_method_class +
1963            "_" +
1964            entry_method_id +
1965            '" value="' +
1966            option.name +
1967            '" ' +
1968            checked +
1969            ' title="' +
1970            option.label +
1971            '" onclick="entry_viral_share_selection(this.name,this.id,this.title)" />' +
1972            '<span class="viral_share_options_holder_each_text">' +
1973            option.label +
1974            "</span>" +
1975            "</label>";
1976        }
1977
1978        var referral_links_url =
1979          // Referral links landing on specific URL header
1980          '<div class="full_width_no_margin">' +
1981          '<div class="w-full float-left">' +
1982          '<label class="cursor-pointer flex items-center ' + premium_button_classes + '">' +
1983          '<input type="checkbox" name="if_viral_share_referral_url_' +
1984          entry_method_class +
1985          "_" +
1986          entry_method_id +
1987          '" id="if_viral_share_referral_url_' +
1988          entry_method_class +
1989          "_" +
1990          entry_method_id +
1991          '" class="sw-checkbox entry_checkbox entry_checkbox_if_viral_share_referral_url entry_checkbox_premium" data-entry_method_class="' +
1992          entry_method_class +
1993          '" data-entry_method_id="' +
1994          entry_method_id +
1995          '" value="" ' +
1996          disabled_premium +
1997          " />" +
1998          '<span id="if_viral_share_referral_url_header_' +
1999          entry_method_class +
2000          "_" +
2001          entry_method_id +
2002          '" class="input_header_2 text-[15px]">' +
2003          "Have referral links land on a specific URL (for embedded giveaways only)?" +
2004          premium_plan_text +
2005          "</span>" +
2006          "</label>" +
2007          "</div>" +
2008          '<div id="viral_share_referral_url_holder_' +
2009          entry_method_class +
2010          "_" +
2011          entry_method_id +
2012          '" class="w-full float-left mt-2 mb-2" style="display: none;">' +
2013          '<div class="viral_share_referral_url_holder">' +
2014          '<div class="w-full mb-[7px] text-[15px] text-[#444] float-left">' +
2015          "Landing page URL" +
2016          "</div>" +
2017          '<div class="w-full float-left">' +
2018          '<input class="text_input_white" name="custom_viral_share_referral_url_' +
2019          entry_method_class +
2020          "_" +
2021          entry_method_id +
2022          '" value="" placeholder="https://" />' +
2023          "</div>" +
2024          "</div>" +
2025          "</div>" +
2026          "</div>";
2027
2028        viral_share_display =
2029          // Viral share display option header
2030          '<div class="w-full float-left mt-4 mb-1">' +
2031          '<div id="viral_share_header_' +
2032          entry_method_class +
2033          "_" +
2034          entry_method_id +
2035          '" class="input_header_2 text-[15px]">' +
2036          "Display options: " +
2037          '<a target="_blank" class="tooltip_question_mark text-[#aaa] no-u
2037nderline" href="' +
2038          website_url +
2039          '/docs/viral-sharing-refer-a-friend#display-options"><i class="fas fa-question-circle"></i></a>' +
2040          "</div>" +
2041          "</div>" +
2042          // Viral share display radio buttons
2043          '<div id="viral_share_checkbox_options_holder_' +
2044          entry_method_id +
2045          '" class="w-full float-left mb-2">' +
2046          '<div class="w-full float-left">' +
2047          '<label class="cursor-pointer">' +
2048          '<input type="radio" name="widget_display_' +
2049          entry_method_class +
2050          "_" +
2051          entry_method_id +
2052          '" value="2" class="sw-radio" /> ' +
2053          '<span class="ml-1">Featured at top (more exposure)</span>' +
2054          "</label>" +
2055          "</div>" +
2056          '<div class="w-full float-left">' +
2057          '<label class="cursor-pointer">' +
2058          '<input type="radio" name="widget_display_' +
2059          entry_method_class +
2060          "_" +
2061          entry_method_id +
2062          '" value="1" checked="checked" class="sw-radio" /> ' +
2063          '<span class="ml-1">Below with additional entry methods</span>' +
2064          "</label>" +
2065          "</div>" +
2066          "</div>" +
2067          // Viral share sharing options header
2068          '<div class="w-full float-left mt-2 mb-2">' +
2069          '<div class="input_header_2 text-[15px]">' +
2070          "Allow sharing on:" +
2071          "</div>" +
2072          "</div>" +
2073          // Viral share sharing options checkboxes
2074          '<div id="viral_share_checkbox_options_holder_' +
2075          entry_method_id +
2076          '" class="w-full float-left mb-2">' +
2077          viral_share_options_display +
2078          "</div>" +
2079          // Viral share max allowed referrals
2080          '<div class="full_width_no_margin">' +
2081          '<div class="w-full float-left">' +
2082          '<label class="cursor-pointer flex items-center">' +
2083          '<input type="checkbox" class="sw-checkbox entry_checkbox entry_checkbox_if_viral_share_max_allowed_referrals entry_checkbox_business" name="if_viral_share_max_allowed_referrals_' +
2084          entry_method_class +
2085          "_" +
2086          id +
2087          '" id="if_viral_share_max_allowed_referrals_' +
2088          entry_method_class +
2089          "_" +
2090          id +
2091          '" data-entry_method_class="' +
2092          entry_method_class +
2093          '" data-entry_method_id="' +
2094          entry_method_id +
2095          '" value="' +
2096          if_viral_share_max_allowed_referrals_checked_value +
2097          '" ' +
2098          if_viral_share_max_allowed_referrals_checked +
2099          " " +
2100          disabled_business +
2101          " />" +
2102          '<span class="input_header_2 text-[15px]">Limit how many friends each user is allowed to refer?' +
2103          business_plan_text +
2104          "</span>" +
2105          "</label>" +
2106          "</div>" +
2107          '<div id="viral_share_max_allowed_referrals_amount_holder_' +
2108          entry_method_class +
2109          "_" +
2110          id +
2111          '" class="w-full float-left mt-2 mb-2" style="' +
2112          viral_share_max_allowed_referrals_amount_show_hide +
2113          '">' +
2114          '<div class="viral_share_max_allowed_referrals_amount_holder">' +
2115          '<div class="w-full mb-[7px] text-[15px] text-[#444] float-left">' +
2116          "Max allowed?" +
2117          "</div>" +
2118          '<div class="float-left">' +
2119          '<input class="text_input_white" min="1" max="999" step="1" name="viral_share_max_allowed_referrals_amount_' +
2120          entry_method_class +
2121          "_" +
2122          id +
2123          '" value="10" />' +
2124          "</div>" +
2125          '<div class="mt-[11px] ml-[13px] text-[14px] float-left">' +
2126          "Friends" +
2127          "</div>" +
2128          "</div>" +
2129          "</div>" +
2130          "</div>" +
2131          referral_links_url +
2132          // Masked viral share links message
2133          masked_viral_share_links_message;
2134
2135        // Only give credit after friend earns X amount of entries
2136        viral_share_display += '<div class="full_width_no_margin">';
2137        viral_share_display += '<div class="w-full float-left">';
2138        viral_share_display +=
2139          '<div id="only_give_credit_after_friend_earns_entries_header_' +
2140          entry_method_class +
2141          "_" +
2142          entry_method_id +
2143          '" class="input_header_2 text-[15px] !block text-[13px] text-[#6b7280] mt-2 mb-1">';
2144        viral_share_display +=
2145          "Only give credit after the friend earns X amount of entries. " +
2146          business_plan_text;
2147        viral_share_display += "</div>";
2148        viral_share_display += "</div>";
2149
2150        viral_share_display +=
2151          '<div id="friend_required_entry_amount_holder_' +
2152          entry_method_class +
2153          "_" +
2154          entry_method_id +
2155          '" class="w-full float-left mb-1">';
2156
2157        viral_share_display +=
2158          '<div class="friend_required_entry_amount_holder">';
2159
2160        viral_share_display +=
2161          '<div class="w-full mb-[7px] text-[15px] text-[#444] float-left">';
2162        viral_share_display += "Friend must earn:";
2163        viral_share_display += "</div>";
2164
2165        viral_share_display += '<div class="float-left">';
2166        viral_share_display +=
2167          '<input class="text_input_white" min="1" max="999" step="1" name="friend_required_entry_amount_' +
2168          entry_method_class +
2169          "_" +
2170          entry_method_id +
2171          '" value="1" />';
2172        viral_share_display += "</div>";
2173
2174        viral_share_display +=
2175          '<div class="mt-[11px] ml-[13px] text-[14px] float-left">';
2176        viral_share_display += "Entries";
2177        viral_share_display += "</div>";
2178
2179        viral_share_display += "</div>"; // close .friend_required_entry_amount_holder
2180        viral_share_display += "</div>"; // close #friend_required_entry_amount_holder
2181        viral_share_display += "</div>"; // close .full_width_no_margin
2182      }
2183
2184      // Daily select drop down
2185      if (daily == 1) {
2186        if (
2187          entry_method_class == "twitter_tweet" ||
2188          entry_method_class == "x_post"
2189        ) {
2190          // Only allow once every 24 hours for twitter_tweet
2191
2192          var daily_select_options =
2193            '<option value="25" selected="25">1 per day (midnight)</option>' +
2194            '<option value="24">1 every 24 hours</option>' +
2195            '<option value="12">1 every 12 hours</option>' +
2196            '<option value="8">1 every 8 hours</option>';
2197
2198          var daily_note = "";
2199
2200          // Show daily checkbox for Twitter
2201          var daily_checkbox_show_hide = 'style="display:block;"';
2202
2203          // Show daily select for Twitter
2204          var daily_select_show_hide = 'style="display:block;"';
2205        } else {
2206          var daily_select_options =
2207            '<option value="25" selected="25">1 per day (midnight)</option>' +
2208            '<option value="unlimited">Unlimited</option>' +
2209            '<option value="1">1 hour</option>' +
2210            '<option value="2">2 hours</option>' +
2211            '<option value="3">3 hours</option>' +
2212            '<option value="4">4 hours</option>' +
2213            '<option value="5">5 hours</option>' +
2214            '<option value="6">6 hours</option>' +
2215            '<option value="7">7 hours</option>' +
2216            '<option value="8">8 hours</option>' +
2217            '<option value="9">9 hours</option>' +
2218            '<option value="10">10 hours</option>' +
2219            '<option value="11">11 hours</option>' +
2220            '<option value="12">12 hours</option>' +
2221            '<option value="13">13 hours</option>' +
2222            '<option value="14">14 hours</option>' +
2223            '<option value="15">15 hours</option>' +
2224            '<option value="16">16 hours</option>' +
2225            '<option value="17">17 hours</option>' +
2226            '<option value="18">18 hours</option>' +
2227            '<option value="19">19 hours</option>' +
2228            '<option value="20">20 hours</option>' +
2229            '<option value="21">21 hours</option>' +
2230            '<option value="22">22 hours</option>' +
2231            '<option value="23">23 hours</option>' +
2232            '<option value="24">24 hours</option>';
2233
2234          var daily_note = "";
2235
2236          var daily_checkbox_show_hide = "";
2237          var daily_select_show_hide = "";
2238        }
2239
2240        var daily_display =
2241          '<div class="w-full float-left" ' +
2242          daily_checkbox_show_hide +
2243          ">" +
2244          '<label class="cursor-pointer flex items-center">' +
2245          '<input type="checkbox" class="sw-checkbox entry_checkbox entry_checkbox_daily" name="daily_' +
2246          entry_method_class +
2247          "_" +
2248          id +
2249          '" id="daily_' +
2250          entry_method_class +
2251          "_" +
2252          id +
2253          '" data-entry_method_class="' +
2254          entry_method_class +
2255          '" data-entry_method_id="' +
2256          entry_method_id +
2257          '" value="' +
2258          daily_checked_value +
2259          '" ' +
2260          daily_checked +
2261          " />" +
2262          '<span class="input_header_2 text-[15px]">Daily entry <a target="_blank" class="tooltip_question_mark text-[#aaa] no-u
2262nderline" href="' +
2263          website_url +
2264          '/docs/add-daily-entries"><i class="fas fa-question-circle"></i></a></span>' +
2265          "</label>" +
2266          daily_note +
2267          '<div id="daily_select_holder_' +
2268          entry_method_class +
2269          "_" +
2270          id +
2271          '" class="w-full float-left" style="display:none;">' +
2272          '<div class="daily_select_holder" ' +
2273          daily_select_show_hide +
2274          ">" +
2275          '<div class="daily_select_holder_header">' +
2276          (entry_method_class == "twitter_tweet" ||
2277            entry_method_class == "x_post"
2278            ? "Select # of tweets allowed per day (if there's more than 1)"
2279            : "Allow 1 entry per...") +
2280          "</div>" +
2281          '<select name="daily_select_' +
2282          entry_method_class +
2283          "_" +
2284          id +
2285          '" id="daily_select_' +
2286          entry_method_class +
2287          "_" +
2288          id +
2289          '" class="daily_select">' +
2290          daily_select_options +
2291          "</select>" +
2292          "</div>" +
2293          "</div>" +
2294          "</div>";
2295      }
2296
2297      // Timer input drop down.
2298      if (timer == 1) {
2299        var timer_display =
2300          '<div class="w-full float-left">' +
2301          '<label class="cursor-pointer flex items-center">' +
2302          '<input type="checkbox" class="sw-checkbox entry_checkbox entry_checkbox_timer ' +
2303          entry_method_add_disallow_pro +
2304          " " +
2305          checkbox_pro_enable_disable_class +
2306          '" name="timer_' +
2307          entry_method_class +
2308          "_" +
2309          id +
2310          '" id="timer_' +
2311          entry_method_class +
2312          "_" +
2313          id +
2314          '" data-entry_method_class="' +
2315          entry_method_class +
2316          '" data-entry_method_id="' +
2317          entry_method_id +
2318          '" value="' +
2319          timer_checked_value +
2320          '" ' +
2321          timer_checked +
2322          " " +
2323          checkbox_pro_enable_disable +
2324          " />" +
2325          '<span class="input_header_2 text-[15px]">Timer' +
2326          ' <a target="_blank" class="tooltip_question_mark text-[#aaa] no-underline" href="' +
2327          website_url +
2328          '/docs/add-a-timer-before-user-is-allowed-to-confirm-entry"><i class="fas fa-question-circle"></i></a>' +
2329          pro_plan_text +
2330          "</span>" +
2331          "</label>" +
2332          '<div id="timer_select_holder_' +
2333          entry_method_class +
2334          "_" +
2335          id +
2336          '" class="w-full float-left" style="display:none;">' +
2337          '<div class="timer_select_holder">' +
2338          '<div class="timer_select_holder_header">' +
2339          "Timer will begin after user clicks on any link in the entry instructions. Or, if there's no link, the timer will begin when the entry method is opened." +
2340          "</div>" +
2341          '<div class="w-full mb-[5px] float-left">' +
2342          '<div class="mt-[15px] mr-[10px] float-left">Minutes:</div>' +
2343          '<input type="number" name="timer_input_minutes_' +
2344          entry_method_class +
2345          "_" +
2346          id +
2347          '" id="timer_input_minutes_' +
2348          entry_method_class +
2349          "_" +
2350          id +
2351          '" value="0" class="text_input_white w-[80px] float-left">' +
2352          '<div class="mt-[15px] mr-[10px] ml-[30px] float-left">Seconds:</div>' +
2353          '<input type="number" name="timer_input_seconds_' +
2354          entry_method_class +
2355          "_" +
2356          id +
2357          '" id="timer_input_seconds_' +
2358          entry_method_class +
2359          "_" +
2360          id +
2361          '" value="30" class="text_input_white w-[80px] float-left">' +
2362          "</div>" +
2363          "</div> " +
2364          "</div>" +
2365          "</div>";
2366      }
2367
2368      // Required
2369      if (required == 1) {
2370        if (
2371          entry_method_class == "twitter_tweet" ||
2372          entry_method_class == "x_post"
2373        ) {
2374          var entry_instructions =
2375            '<div class="w-full mt-[20px] leading-[21px] float-left" style="border-top:1px solid #eee;">' +
2376            '<div class="w-full mt-[20px] mb-[10px] font-bold float-left">' +
2377            "Instructions for multiple tweets:" +
2378            "</div>" +
2379            '<div class="w-full m-0 font-light float-left">' +
2380            "Create a series of tweets that users can tweet. Each time a user comes back to post an additional tweet, it will be the next tweet in the series." +
2381            "</div>" +
2382            "</div>";
2383        } else {
2384          var entry_instructions = "";
2385        }
2386
2387        var required_display =
2388          '<div class="w-full float-left">' +
2389          '<label class="cursor-pointer flex items-center">' +
2390          '<input type="checkbox" name="required_' +
2391          entry_method_class +
2392          "_" +
2393          id +
2394          '" id="required_' +
2395          entry_method_class +
2396          "_" +
2397          id +
2398          '" class="sw-checkbox entry_checkbox entry_checkbox_required" value="1" data-entry_method_class="' +
2399          entry_method_class +
2400          '" data-entry_method_id="' +
2401          id +
2402          '" ' +
2403          required_checked +
2404          " />" +
2405          '<span class="input_header_2 text-[15px]">Mandatory <a target="_blank" class="tooltip_question_mark text-[#aaa] no-u
2405nderline" href="' +
2406          website_url +
2407          '/docs/add-locked-entry-methods"><i class="fas fa-question-circle"></i></a></span>' +
2408          "</label>" +
2409          entry_instructions +
2410          "</div>";
2411      }
2412
2413      // Telegram - tracking options
2414      if (entry_method_class.indexOf("telegram") >= 0) {
2415        var tracking_options_display =
2416          '<div class="w-full mt-[15px] float-left">' +
2417          '<span class="input_header_3">How do you want to validate entries?' +
2418          "&nbsp;" +
2419          premium_plan_text +
2420          '&nbsp;<a target="_blank" class="tooltipped" data-position="top" data-tooltip="Learn more about Telegram API integration" href="' +
2421          website_url +
2422          '/docs/telegram-api-integration-authenticate-entries">' +
2423          '<i class="fas fa-question-circle"></i>' +
2424          "</a>" +
2425          "</span>" +
2426          '<div class="flex flex-wrap items-center gap-x-5 gap-y-2 mt-[10px] mb-5">' +
2427          '<label class="flex items-center cursor-pointer ' +
2428          entry_method_add_disallow_premium +
2429          '" data-plan="3">' +
2430          '<input class="sw-radio" type="radio" name="tracking_options_radio_options_' +
2431          entry_method_class +
2432          "_" +
2433          id +
2434          '" value="1" checked="checked" onclick="tracking_options_radio_options_display_value(this.value, ' +
2435          id +
2436          ')" ' +
2437          checkbox_premium_enable_disable +
2438          " />" +
2439          "<span>Manual validation</span>" +
2440          "</label>" +
2441          '<label class="flex items-center cursor-pointer ' +
2442          entry_method_add_disallow_premium +
2443          '" data-plan="3">' +
2444          '<input class="sw-radio" type="radio" name="tracking_options_radio_options_' +
2445          entry_method_class +
2446          "_" +
2447          id +
2448          '" value="2" onclick="tracking_options_radio_options_display_value(this.value, ' +
2449          id +
2450          ')" ' +
2451          checkbox_premium_enable_disable +
2452          "/>" +
2453          "<span>API validated entries</span>" +
2454          '&nbsp;&nbsp;<a target="_blank" class="tooltipped" data-position="top" data-tooltip="Learn more about Telegram API integration" href="https://sweepwidget.com/docs/telegram-api-integration-authenticate-entries"><i class="fas fa-question-circle" aria-hidden="true"></i></a>' +
2455          "</label>" +
2456          "</div>" +
2457          "</div>";
2458
2459        if (entry_method_class == "telegram_join_channel") {
2460          var telegram_public_private_display =
2461            '<div class="w-full mb-[0] float-left">' +
2462            '<div id="tracking_options_radio_options_' +
2463            id +
2464            '" class="input_header_3">' +
2465            "Public or private channel?" +
2466            "</div>" +
2467            '<div class="flex flex-wrap items-center gap-x-5 gap-y-2 mt-[5px] mb-5">' +
2468            '<label class="cursor-pointer flex items-center">' +
2469            '<input type="radio" class="sw-radio" name="public_or_private_radio_options_' +
2470            entry_method_class +
2471            "_" +
2472            id +
2473            '" value="1" checked="checked" />' +
2474            " <span>Public</span>" +
2475            "</label>" +
2476            '<label class="cursor-pointer flex items-center">' +
2477            '<input type="radio" class="sw-radio" name="public_or_private_radio_options_' +
2478            entry_method_class +
2479            "_" +
2480            id +
2481            '" value="2" />' +
2482            " <span>Private</span>" +
2483            "</label>" +
2484            "</div>" +
2485            "</div>";
2486        }
2487
2488        // Hidden fields for TG API token
2489        var tracking_options_display_hidden_wrapper =
2490          '<div id="tracking_options_radio_options_holder_' +
2491          id +
2492          '" class="full_width_hidden_2">' +
2493          telegram_public_private_display +
2494          '<div class="mb-[30px] text-[15px]">' +
2495          '<div id="tracking_options_radio_options_header_' +
2496          entry_method_class +
2497          "_" +
2498          id +
2499          '" class="w-full mt-0 mb-[5px] text-[15px] float-left">' +
2500          "Your Telegram bot API token" +
2501          "</div>" +
2502          '<input type="text" autocomplete="off" name="api_key_' +
2503          id +
2504          '" class="entry_input_2" maxlength="500" />' +
2505          '<div class="w-full mt-[5px] mb-[10px] text-red-500 font-bold float-left">IMPORTANT: Make this BOT an admin of your channel/group. Otherwise, the API check will not work.</
2505div>' +
2506          '<div class="w-full mb-[25px] font-bold float-left"><a target="_blank" href="' +
2507          website_url +
2508          '/docs/telegram-api-integration-authenticate-entries">Follow these instructions to build your own Telegram bot &nbsp;<i class="fa-solid fa-arrow-up-right-from-square"></i></a></div>' +
2509          "</div>" +
2510          "</div>";
2511      }
2512
2513      // Shared purchase advanced options builder (used by both Shopify and WooCommerce)
2514      function buildPurchaseAdvancedOptions(cls, id) {
2515        return '<div class="w-full float-left mt-3 mb-2 purchase-config-wrapper" id="purchase_config_wrapper_' + cls + '_' + id + '" data-entry_method_class="' + cls + '" data-entry_method_id="' + id + '">' +
2516          '<div class="flex items-center gap-5 mb-3 mt-1">' +
2517          '<span class="text-[13px] font-semibold text-[#374151]">Entry rate mode:</span>' +
2518          '<label class="cursor-pointer flex items-center gap-1.5">' +
2519          '<input type="radio" name="entry_mode_' + cls + '_' + id + '" class="sw-radio entry-mode-radio" value="global" checked data-entry_method_class="' + cls + '" data-entry_method_id="' + id + '" />' +
2520          '<span class="text-sm text-[#374151]">Global</span></label>' +
2521          '<label class="cursor-pointer flex items-center gap-1.5">' +
2522          '<input type="radio" name="entry_mode_' + cls + '_' + id + '" class="sw-radio entry-mode-radio" value="per_product" data-entry_method_class="' + cls + '" data-entry_method_id="' + id + '" />' +
2523          '<span class="text-sm text-[#374151]">Per-product</span></label>' +
2524          '</div>' +
2525          '<input type="hidden" name="entry_mode_value_' + cls + '_' + id + '" class="entry-mode-value-input" value="global" />' +
2526          '<input type="hidden" name="per_product_rates_json_' + cls + '_' + id + '" class="per-product-rates-json-input" value="{}" />' +
2527          '<div class="mt-4 mb-2">' +
2528          '<div class="cursor-pointer flex items-center gap-1 text-[14px] font-semibold text-[#374151] advanced-options-toggle" data-entry_method_class="' + cls + '" data-entry_method_id="' + id + '">' +
2529          '<span>Set min/max purchase amount</span>' +
2530          '<i class="fas fa-chevron-down text-[11px] ml-1 advanced-options-chevron transition-transform duration-200"></i>' +
2531          '</div></div>' +
2532          '<div class="advanced-purchase-options p-4 bg-[#f9fafb] border border-[#e5e7eb] rounded-lg mb-3" id="advanced_purchase_options_' + cls + '_' + id + '" style="display:none;">' +
2533          '<div class="mb-4"><div class="text-[13px] font-semibold text-[#374151] mb-1">Minimum purchase amount</div>' +
2534          '<div class="flex items-center gap-1"><span class="text-sm text-[#555]">$</span>' +
2535          '<input type="number" name="min_spend_' + cls + '_' + id + '" class="w-[100px] px-2 py-1.5 border border-[#ccc] rounded text-sm bg-white" value="0" min="0" step="0.01" /></div>' +
2536          '<div class="text-[12px] text-[#9ca3af] mt-1">Customers must spend at least this amount to earn entries. Leave at $0 for no minimum.</div></div>' +
2537          '<div><div class="text-[13px] font-semibold text-[#374151] mb-1">Maximum entries per user from purchases</div>' +
2538          '<input type="number" name="entry_cap_' + cls + '_' + id + '" class="w-[100px] px-2 py-1.5 border border-[#ccc] rounded text-sm bg-white" value="0" min="0" step="1" />' +
2539          '<div class="text-[12px] text-[#9ca3af] mt-1">Cap the total entries a single user can earn. 0 = no cap.</div></div></div>' +
2540          '<input type="hidden" name="filter_mode_value_' + cls + '_' + id + '" class="filter-mode-value-input" value="products" />' +
2541          '<input type="hidden" name="collection_ids_json_' + cls + '_' + id + '" class="collection-ids-json-input" value="[]" />' +
2542          '</div>';
2543      }
2544
2545      // Shopify purchase entries
2546      if (entry_method_class == "entries_for_purchase") {
2547
2548        var entries_for_purchase_send_email_checkbox_display =
2549          '<div class="w-full float-left">' +
2550          '<label class="cursor-pointer flex items-center" data-plan="2">' +
2551          '<input type="checkbox" name="successful_purchase_send_email_' + entry_method_class + '_' + entry_method_id + '" class="sw-checkbox entry_checkbox more_options_checkbox entry_checkbox_pro" checked />' +
2552          '<span id="successful_purchase_send_email_header_' + entry_method_class + '"class="input_header_2 text-[15px]">Email users when they get credited entries for a purchase?</span>' +
2553          "</label></div>";
2554
2555        var auto_enter_people_who_made_purchase_checkbox_display =
2556          '<div class="w-full float-left">' +
2557          '<label class="cursor-pointer flex items-center" data-plan="2">' +
2558          '<input type="checkbox" name="auto_enter_people_who_made_purchase_' + entry_method_class + '_' + entry_method_id + '" class="sw-checkbox entry_checkbox more_options_checkbox entry_checkbox_pro auto_enter_people_who_made_purchase_checkbox" data-shop_platform="shopify" />' +
2559          '<span id="auto_enter_people_who_made_purchase_header_' + entry_method_class + '" class="input_header_2 text-[15px]">Automatically enter all people who made a purchase?</span>' +
2560          "</label></div>";
2561
2562        var entries_for_purchase_platform_options_display =
2563          '<textarea name="products_json_' + entry_method_class + '_' + entry_method_id + '" style="display: none;"></textarea>' +
2564          '<input type="hidden" name="selected_product_ids_' + entry_method_class + '_' + entry_method_id + '" value="" />' +
2565          '<input type="hidden" name="shop_platform_' + entry_method_class + '_' + entry_method_id + '" value="shopify" />' +
2566          '<div class="w-full">' +
2567          '<div class="w-full mt-4 mb-1 text-[15px] font-bold">Instructions for Shopify:</div>' +
2568          '<div class="w-full p-5 bg-[#f6f6f6] rounded-[10px] shadow-md mb-6 mt-2 text-[15px] box-border">' +
2569          '<p>Install the SweepWidget app from the <a target="_blank" rel="nofollow" href="https://apps.shopify.com/sweepwidget" class="font-bold underline">Shopify App Store</a>. Users will automatically earn entries for purchases made while the giveaway is live.</p>' +
2570          "</div>" +
2571          '<div class="text-[12px] text-[#9ca3af] -mt-3 mb-4"><strong class="text-[#888]">Order limits:</strong> Pro 100 &middot; Business 1,000 &middot; Premium 5,000 &middot; Enterprise Unlimited</div>' +
2572          '<div class="w-full my-5 text-center">' +
2573          '<div class="w-full mb-5 text-center">Select which products you want to reward entries for</div>' +
2574          '<button type="button" class="sw-btn sw-btn-primary connect_store_connect_button" id="connect_store_' + entry_method_class + '_' + entry_method_id + '" data-entry_method_id="' + entry_method_id + '" data-entry_method_class="' + entry_method_class + '" data-shop_platform="shopify">Connect Shopify Store</button>' +
2575          "</div>" +
2576          '<div id="track_all_products_' + entry_method_class + '_' + entry_method_id + '" class="w-full mt-5 text-center" style="display: none;">' +
2577          '<label class="cursor-pointer"><input type="checkbox" name="track_all_products_' + entry_method_class + '_' + entry_method_id + '" class="sw-checkbox track-all-products-checkbox" data-entry_method_class="' + entry_method_class + '" data-entry_method_id="' + entry_method_id + '" /><span>Track all current and future products</span></label>' +
2578          "</div>" +
2579          '<div class="product-filter-section w-full mt-4"><div id="products_dropdown_shopify_' + entry_method_class + '_' + entry_method_id + '"></div></div>' +
2580          "</div>";
2581
2582        entries_for_purchase_advanced_options_display = buildPurchaseAdvancedOptions(entry_method_class, entry_method_id);
2583      }
2584
2585      // WooCommerce purchase entries
2586      if (entry_method_class == "woocommerce_purchases") {
2587
2588        var entries_for_purchase_send_email_checkbox_display =
2589          '<div class="w-full float-left">' +
2590          '<label class="cursor-pointer flex items-center" data-plan="2">' +
2591          '<input type="checkbox" name="successful_purchase_send_email_' + entry_method_class + '_' + entry_method_id + '" class="sw-checkbox entry_checkbox more_options_checkbox entry_checkbox_pro" checked />' +
2592          '<span id="successful_purchase_send_email_header_' + entry_method_class + '"class="input_header_2 text-[15px]">Email users when they get credited entries for a purchase?</span>' +
2593          "</label></div>";
2594
2595        var auto_enter_people_who_made_purchase_checkbox_display =
2596          '<div class="w-full float-left">' +
2597          '<label class="cursor-pointer flex items-center" data-plan="2">' +
2598          '<input type="checkbox" name="auto_enter_people_who_made_purchase_' + entry_method_class + '_' + entry_method_id + '" class="sw-checkbox entry_checkbox more_options_checkbox entry_checkbox_pro auto_enter_people_who_made_purchase_checkbox" data-shop_platform="woocommerce" />' +
2599          '<span id="auto_enter_people_who_made_purchase_header_' + entry_method_class + '" class="input_header_2 text-[15px]">Automatically enter all people who made a purchase?</span>' +
2600          "</label></div>";
2601
2602        var entries_for_purchase_platform_options_display =
2603          '<textarea name="products_json_' + entry_method_class + '_' + entry_method_id + '" style="display: none;"></textarea>' +
2604          '<input type="hidden" name="selected_product_ids_' + entry_method_class + '_' + entry_method_id + '" value="" />' +
2605          '<input type="hidden" name="shop_platform_' + entry_method_class + '_' + entry_method_id + '" value="woocommerce" />' +
2606          '<div class="w-full">' +
2607          '<div class="w-full mt-4 mb-1 text-[15px] font-bold">Instructions for WooCommerce:</div>' +
2608          '<div class="w-full p-5 bg-[#f6f6f6] rounded-[10px] shadow-md mb-6 mt-2 text-[15px] box-border">' +
2609          '<p>Enter your WooCommerce API credentials below to connect your store. Users will automatically earn entries for purchases made while the giveaway is live. <a target="_blank" rel="nofollow" href="https://woocommerce.com/document/woocommerce-rest-api/" class="font-bold underline">How to find my API key?</a></p>' +
2610          '<div class="w-full"><div class="w-full mt-5 mb-1 text-[15px]">WordPress site URL<br /><em>* Include subfolder if WordPress is installed in one</em></div>' +
2611          '<input type="text" autocomplete="off" name="store_url_' + entry_method_class + '_' + entry_method_id + '" class="entry_input" maxlength="500" value="https://" placeholder="https://sweepwidget.com/store" /></div>' +
2612          '<div class="w-full"><div class="w-full mt-5 mb-1 text-[15px]">WooCommerce Consumer Key</div>' +
2613          '<input type="text" autocomplete="off" name="consumer_key_' + entry_method_class + '_' + entry_method_id + '" class="entry_input" maxlength="500" /></div>' +
2614          '<div class="w-full"><div class="w-full mt-5 mb-1 text-[15px]">WooCommerce Consumer Secret</div>' +
2615          '<input type="text" autocomplete="off" name="consumer_secret_' + entry_method_class + '_' + entry_method_id + '" class="entry_input" maxlength="500" /></div>' +
2616          "</div>" +
2617          '<div class="text-[12px] text-[#9ca3af] -mt-3 mb-4"><strong class="text-[#888]">Order limits:</strong> Pro 100 &middot; Business 1,000 &middot; Premium 5,000 &middot; Enterprise Unlimited</div>' +
2618          '<div class="w-full my-5 text-center">' +
2619          '<div class="w-full mb-5 text-center">Select which products you want to reward entries for</div>' +
2620          '<button type="button" class="sw-btn sw-btn-primary connect_store_connect_button" id="connect_store_' + entry_method_class + '_' + entry_method_id + '" data-entry_method_id="' + entry_method_id + '" data-entry_method_class="' + entry_method_class + '" data-shop_platform="woocommerce">Connect WooCommerce Store</button>' +
2621          "</div>" +
2622          '<div id="track_all_products_' + entry_method_class + '_' + entry_method_id + '" class="w-full mt-5 text-center" style="display: none;">' +
2623          '<label class="cursor-pointer"><input type="checkbox" name="track_all_products_' + entry_method_class + '_' + entry_method_id + '" class="sw-checkbox track-all-products-checkbox" data-entry_method_class="' + entry_method_class + '" data-entry_method_id="' + entry_method_id + '" /><span>Track all current and future products</span></label>' +
2624          "</div>" +
2625          '<div class="product-filter-section w-full mt-4"><div id="products_dropdown_woocommerce_' + entry_method_class + '_' + entry_method_id + '"></div></div>' +
2626          "</div>";
2627
2628        entries_for_purchase_advanced_options_display = buildPurchaseAdvancedOptions(entry_method_class, entry_method_id);
2629      }
2630
2631      // Custom icon
2632      if (custom_icon == 1 && level == 2) {
2633        custom_icons_array = window.FA_ICONS.solid;
2634        custom_icons_array_brands = window.FA_ICONS.brands;
2635
2636        var custom_icons_all = "";
2637
2638        // LOOP through each active entry method to check for errors
2639        for (i = 0; i < custom_icons_array_brands.length; i++) {
2640          custom_icons_all +=
2641            '<i class="fab fa-' +
2642            custom_icons_array_brands[i] +
2643            '" data-filter="' +
2644            custom_icons_array_brands[i].replace("-", " ") +
2645            '"></i>';
2646        }
2647
2648        for (i = 0; i < custom_icons_array.length; i++) {
2649          custom_icons_all +=
2650            '<i class="fas fa-' +
2651            custom_icons_array[i] +
2652            '" data-filter="' +
2653            custom_icons_array[i].replace("-", " ") +
2654            '"></i>';
2655        }
2656
2657        var font_awesome_icon_class =
2658          extract_font_awesome_class_name(font_awesome_icon);
2659
2660        var custom_icon_display =
2661          '<div class="w-full mb-5">' +
2662          '<div id="required_header_' +
2663          entry_method_class +
2664          "_" +
2665          id +
2666          '" class="float-left input_header_2 text-[15px] mb-2 mt-4">' +
2667          "&nbsp;Change icon (2,000+)&nbsp; " +
2668          '<a target="_blank" class="tooltip_question_mark text-[#aaa] no-underline" href="' +
2669          website_url +
2670          '/docs/add-a-custom-icon-to-an-entry-method"><i class="fas fa-question-circle"></i></a>' +
2671          "&nbsp; " +
2672          business_plan_text +
2673          "</div>" +
2674          '<div id="custom_icons_wrapper_' +
2675          entry_method_class +
2676          "_" +
2677          id +
2678          '" class="custom_icons_wrapper">' +
2679          '<div class="custom_icons_wrapper_search_wrapper">' +
2680          '<input id="custom_icons_wrapper_search_' +
2681          entry_method_class +
2682          "_" +
2683          id +
2684          '" class="custom_icons_wrapper_search text_input_white" data-entry_method_class="' +
2685          entry_method_class +
2686          '" data-entry_method_id="' +
2687          id +
2688          '" placeholder="Search for an icon..." />' +
2689          "</div>" +
2690          '<div id="custom_icons_wrapper_inner_' +
2691          entry_method_class +
2692          "_" +
2693          id +
2694          '" class="custom_icons_wrapper_inner" data-entry_method_class="' +
2695          entry_method_class +
2696          '" data-entry_method_id="' +
2697          id +
2698          '">' +
2699          custom_icons_all +
2700          "</div>" +
2701          "</div>" +
2702          '<input type="hidden" name="custom_icon_' +
2703          entry_method_class +
2704          "_" +
2705          id +
2706          '" value="' +
2707          font_awesome_icon_class +
2708          '" />' +
2709          "</div>";
2710      }
2711
2712      // Require Verification
2713      if (require_verification == 1) {
2714        var require_verification_display =
2715          '<div class="w-full float-left ' +
2716          require_verification_fields_wrapper_class +
2717          ' hidden">' +
2718          '<label class="cursor-pointer flex items-center">' +
2719          '<input type="checkbox" name="require_verification_' +
2720          entry_method_class +
2721          "_" +
2722          id +
2723          '" class="sw-checkbox entry_checkbox require_verification_checkbox" ' +
2724          require_verification_checked_display +
2725          " />" +
2726          '<span class="input_header_2 text-[15px]">' +
2727          require_verification_header +
2728          "</span>" +
2729          "</label>" +
2730          "</div>";
2731      }
2732
2733      // API validated entries checkbox
2734      if (api_auth == 1) {
2735        var api_auth_checked = "";
2736        var api_auth_disabled = "";
2737
2738        if (api_auth_required == 1) {
2739          api_auth_checked = ' checked="checked"';
2740          api_auth_disabled = ' disabled="1"';
2741        } else {
2742          api_auth_checked = ' checked="checked"';
2743        }
2744
2745        api_auth_display =
2746          '<div class="w-full float-left">' +
2747          '<label class="cursor-pointer flex items-center">' +
2748          '<input type="checkbox" name="api_auth_' +
2749          entry_method_class +
2750          "_" +
2751          id +
2752          '" class="sw-checkbox entry_checkbox" data-entry_method_class="' +
2753          entry_method_class +
2754          '" data-entry_method_id="' +
2755          id +
2756          '"' +
2757          api_auth_checked +
2758          api_auth_disabled +
2759          " />" +
2760          '<span class="input_header_2 text-[15px]">' +
2761          "API validated entries" +
2762          ' <a target="_blank" class="tooltip_question_mark text-[#aaa] no-u
2762nderline" href="' +
2763          website_url +
2764          '/docs/api-validated-entries"><i class="fas fa-question-circle"></i></a>' +
2765          "</span>" +
2766          "</label>" +
2767          "</div>";
2768      }
2769
2770      // More options (show additional form fields)
2771      var more_options_display =
2772        '<div class="w-full float-left">' +
2773        '<label class="cursor-pointer flex items-center ' +
2774        pro_button_classes +
2775        '" data-plan="2">' +
2776        '<input type="checkbox" name="more_options_' +
2777        entry_method_class +
2778        "_" +
2779        id +
2780        '" class="sw-checkbox entry_checkbox more_options_checkbox" data-plan="2" data-id="' +
2781        id +
2782        '" ' +
2783        checkbox_pro_enable_disable +
2784        ' data-entry_method_class="' +
2785        entry_method_class +
2786        '" ' +
2787        more_options_checkbox_checked +
2788        " />" +
2789        '<span class="input_header_2 text-[15px]">' +
2790        "View button labels &amp; verification settings" +
2791        ' <a target="_blank" class="tooltip_question_mark text-[#aaa] no-underline" href="' +
2792        website_url +
2793        '/docs/view-advanced-entry-method-customizations"><i class="fas fa-question-circle"></i></a>' +
2794        disabled_pro_text +
2795        "</span>" +
2796        "</label>" +
2797        "</div>";
2798
2799      // Social Optional Engagement
2800      if (social_optional_engagement == 1) {
2801        var social_optional_engagement_display =
2802          '<div class="w-full float-left">' +
2803          '<label class="' +
2804          entry_method_add_disallow_pro +
2805          ' cursor-pointer flex items-center" data-plan="2">' +
2806          '<input type="checkbox" name="social_optional_engagement_' +
2807          entry_method_class +
2808          "_" +
2809          id +
2810          '" id="social_optional_engagement_' +
2811          entry_method_class +
2812          "_" +
2813          id +
2814          '" class="sw-checkbox entry_checkbox social_optional_engagement_checkbox entry_checkbox_pro" ' +
2815          social_optional_engagement_checked +
2816          " " +
2817          checkbox_pro_enable_disable +
2818          " />" +
2819          '<span class="input_header_2 text-[15px]">' +
2820          social_optional_engagement_header +
2821          pro_plan_text +
2822          "</span>" +
2823          "</label>" +
2824          "</div>";
2825      }
2826
2827      // Input field
2828      if (input_type == 1) {
2829        var checked_by_default_header = "Checked by default?";
2830
2831        var checkbox_required_display =
2832          '<span class="input_example_2">' +
2833          "The user will be required to check a checkbox agreeing to this." +
2834          "</span>";
2835
2836        if (entry_method_class == "secret_code") {
2837          var checked_by_default_header = "Must be Correct";
2838
2839          var checkbox_required_display = "";
2840        }
2841
2842        if (
2843          entry_method_class == "checkbox" ||
2844          entry_method_class == "secret_code"
2845        ) {
2846          var checked_by_default_checked =
2847            entry_method_class == "secret_code" ? ' checked="checked"' : "";
2848
2849          var input_type_display =
2850            '<div class="w-full float-left">' +
2851            '<label class="cursor-pointer flex items-center">' +
2852            '<input type="checkbox" name="checked_by_default_' +
2853            entry_method_class +
2854            "_" +
2855            id +
2856            '" class="sw-checkbox entry_checkbox"' +
2857            checked_by_default_checked +
2858            " />" +
2859            '<span class="input_header_2 text-[15px]">' +
2860            checked_by_default_header +
2861            "</span>" +
2862            checkbox_required_display +
2863            "</label>" +
2864            "</div>";
2865
2866          if (level == 2 && entry_method_class == "secret_code") {
2867            input_type_display +=
2868              '<div class="w-full float-left">' +
2869              '<label class="cursor-pointer flex items-center">' +
2870              '<input type="checkbox" name="disallow_duplicate_secret_codes_' +
2871              entry_method_class +
2872              "_" +
2873              id +
2874              '" class="sw-checkbox entry_checkbox" />' +
2875              '<span class="input_header_2 text-[15px]">' +
2876              "Prohibit duplicate secret codes" +
2877              "</span>" +
2878              "</label>" +
2879              "</div>";
2880          }
2881        } else if (entry_method_class == "radio") {
2882          var input_type_display =
2883            '<div class="input_holder_1">' +
2884            '<div id="radio_options_header_' +
2885            entry_method_class +
2886            "_" +
2887            id +
2888            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
2889            "Options" +
2890            "</div>" +
2891            '<input type="text" autocomplete="off" name="radio_options_' +
2892            entry_method_class +
2893            "_" +
2894            id +
2895            '" class="entry_input" placeholder="Springfield, Bismarck, Tallahassee" maxlength="500" />' +
2896            '<span class="input_example">' +
2897            "Separate each option with a comma e.g. Springfield, Bismarck, Tallahassee" +
2898            "</span>" +
2899            "</div>" +
2900            '<div class="input_holder_1">' +
2901            '<div id="radio_required_header_' +
2902            entry_method_class +
2903            "_" +
2904            id +
2905            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
2906            "Required Selection (* Optional)<br />" +
2907            "</div>" +
2908            '<input type="text" autocomplete="off" name="radio_required_' +
2909            entry_method_class +
2910            "_" +
2911            id +
2912            '" class="entry_input" maxlength="500" placeholder="Bismarck" />' +
2913            '<span class="input_example">' +
2914            "Must match an option e.g. Bismarck" +
2915            "</span>" +
2916            "</div>";
2917        } else if (entry_method_class == "select") {
2918          var input_type_display =
2919            '<div class="input_holder_1">' +
2920            '<div id="select_header_' +
2921            entry_method_class +
2922            "_" +
2923            id +
2924            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
2925            "Options" +
2926            "</div>" +
2927            '<input type="text" autocomplete="off" name="select_options_' +
2928            entry_method_class +
2929            "_" +
2930            id +
2931            '" class="entry_input" placeholder="Springfield, Bismarck, Tallahassee" maxlength="4000" />' +
2932            '<span class="input_example">' +
2933            "Separate each option with a comma e.g. Springfield, Bismarck, Tallahassee" +
2934            "</span>" +
2935            "</div>" +
2936            '<div class="input_holder_1">' +
2937            '<div id="select_required_header_' +
2938            entry_method_class +
2939            "_" +
2940            id +
2941            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
2942            "Required Selection (* Optional)<br />" +
2943            "</div>" +
2944            '<input type="text" autocomplete="off" name="select_required_' +
2945            entry_method_class +
2946            "_" +
2947            id +
2948            '" class="entry_input" maxlength="500" placeholder="Bismarck" />' +
2949            '<span class="input_example">' +
2950            "Must match an option e.g. Bismarck" +
2951            "</span>" +
2952            "</div>";
2953        } else if (entry_method_class == "checkboxes") {
2954          var input_type_display =
2955            '<div class="input_holder_1">' +
2956            '<div id="checkboxes_options_header_' +
2957            entry_method_class +
2958            "_" +
2959            id +
2960            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
2961            "Options" +
2962            "</div>" +
2963            '<input type="text" autocomplete="off" name="checkboxes_options_' +
2964            entry_method_class +
2965            "_" +
2966            id +
2967            '" class="entry_input" placeholder="Rock, Pop, Jazz, Classical" maxlength="1000" />' +
2968            '<span class="input_example">' +
2969            "Separate each option with a comma e.g. Rock, Pop, Jazz, Classical" +
2970            "</span>" +
2971            "</div>";
2972        } else if (entry_method_class == "textarea") {
2973        } else if (entry_method_class == "app_download") {
2974          var input_type_display =
2975            '<div class="input_holder_1">' +
2976            '<div id="header_' +
2977            entry_method_class +
2978            "_1_" +
2979            id +
2980            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
2981            "Apple App Store URL" +
2982            "</div>" +
2983            '<input type="text" autocomplete="off" name="' +
2984            entry_method_class +
2985            "_1_" +
2986            id +
2987            '" class="entry_input" placeholder="https://itunes.apple.com/us/app/pokemon-go" maxlength="1000" />' +
2988            "</div>" +
2989            '<div class="input_holder_1">' +
2990            '<div id="header_' +
2991            entry_method_class +
2992            "_2_" +
2993            id +
2994            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
2995            "Google Play Store URL<br />" +
2996            "</div>" +
2997            '<input type="text" autocomplete="off" name="' +
2998            entry_method_class +
2999            "_2_" +
3000            id +
3001            '" class="entry_input" maxlength="1000" placeholder="https://play.google.com/store/apps/details?id=com.nianticlabs.pokemongo" />' +
3002            "</div>";
3003
3004          // Password field - validation requirements
3005        } else if (entry_method_class == "password_field") {
3006          var input_type_display =
3007            '<div class="w-full float-left mt-3">' +
3008            '<div class="w-full mb-[5px] text-[15px] float-left font-medium">' +
3009            "Password Requirements" +
3010            "</div>" +
3011            '<div class="input_holder_1 mb-2">' +
3012            '<div class="w-full mb-[5px] text-[14px] float-left">' +
3013            "Minimum Length" +
3014            "</div>" +
3015            '<input type="number" autocomplete="off" name="pw_min_length_' +
3016            entry_method_class +
3017            "_" +
3018            id +
3019            '" class="entry_input" placeholder="e.g. 8" min="1" max="255" style="max-width:120px;" />' +
3020            "</div>" +
3021            '<div class="w-full float-left">' +
3022            '<label class="cursor-pointer flex items-center mb-1">' +
3023            '<input type="checkbox" name="pw_require_uppercase_' +
3024            entry_method_class +
3025            "_" +
3026            id +
3027            '" class="sw-checkbox entry_checkbox" />' +
3028            '<span class="input_header_2 text-[14px]">' +
3029            "Require uppercase letter (A-Z)" +
3030            "</span>" +
3031            "</label>" +
3032            "</div>" +
3033            '<div class="w-full float-left">' +
3034            '<label class="cursor-pointer flex items-center mb-1">' +
3035            '<input type="checkbox" name="pw_require_lowercase_' +
3036            entry_method_class +
3037            "_" +
3038            id +
3039            '" class="sw-checkbox entry_checkbox" />' +
3040            '<span class="input_header_2 text-[14px]">' +
3041            "Require lowercase letter (a-z)" +
3042            "</span>" +
3043            "</label>" +
3044            "</div>" +
3045            '<div class="w-full float-left">' +
3046            '<label class="cursor-pointer flex items-center mb-1">' +
3047            '<input type="checkbox" name="pw_require_number_' +
3048            entry_method_class +
3049            "_" +
3050            id +
3051            '" class="sw-checkbox entry_checkbox" />' +
3052            '<span class="input_header_2 text-[14px]">' +
3053            "Require number (0-9)" +
3054            "</span>" +
3055            "</label>" +
3056            "</div>" +
3057            '<div class="w-full float-left">' +
3058            '<label class="cursor-pointer flex items-center mb-1">' +
3059            '<input type="checkbox" name="pw_require_special_' +
3060            entry_method_class +
3061            "_" +
3062            id +
3063            '" class="sw-checkbox entry_checkbox" />' +
3064            '<span class="input_header_2 text-[14px]">' +
3065            "Require special character (!@#$%^&*)" +
3066            "</span>" +
3067            "</label>" +
3068            "</div>" +
3069            "</div>";
3070
3071          // Crypto wallet address
3072        } else if (entry_method_class.includes("crypto_wallet")) {
3073          var input_type_display =
3074            '<div class="w-full float-left">' +
3075            '<label class="cursor-pointer flex items-center">' +
3076            '<input type="checkbox" name="allow_duplicate_wallet_addresses_' +
3077            entry_method_class +
3078            "_" +
3079            id +
3080            '" class="sw-checkbox entry_checkbox" />' +
3081            '<span class="input_header_2 text-[15px]">
3081Allow duplicate wallet addresses?</span>' +
3082            "</label>" +
3083            "</div>";
3084        }
3085      }
3086
3087      // Input header value
3088      // Write input_header_value if it has a default value from entry_method_fetch_values();
3089      if (
3090        input_header_value !== "" &&
3091        typeof input_header_value !== "undefined"
3092      ) {
3093        // twitter_hashtags
3094        if (entry_method_class == "twitter_hashtags") {
3095          var input_header_display =
3096            '<div class="input_holder_full ' +
3097            entry_method_field_pro +
3098            '">' +
3099            '<div id="twitter_hashtags_' +
3100            entry_method_class +
3101            "_" +
3102            id +
3103            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3104            "Hashtags" +
3105            "</div>" +
3106            '<input name="twitter_hashtags_value_' +
3107            entry_method_class +
3108            "_" +
3109            id +
3110            '" class="entry_input" placeholder="contests, giveaways, sweepwidget" maxlength="1000" />' +
3111            '<div class="sw_entry_method_handle_hint">' +
3112            'Write down each hashtag the user must use separated by a comma "," e.g. contests, giveaways, sweepwidget' +
3113            "</div>" +
3114            "</div>" +
3115            '<div class="input_holder_full mt-[20px] ' +
3116            entry_method_field_pro +
3117            '">' +
3118            '<label class="cursor-pointer">' +
3119            '<input type="radio" class="sw-radio" name="twitter_hashtags_one_or_all_' +
3120            entry_method_class +
3121            "_" +
3122            id +
3123            '" value="1" checked />' +
3124            "<span>&nbsp;Require All Hashtags &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" +
3125            "</label>" +
3126            '<label class="cursor-pointer">' +
3127            '<input type="radio" class="sw-radio" name="twitter_hashtags_one_or_all_' +
3128            entry_method_class +
3129            "_" +
3130            id +
3131            '" value="2" />' +
3132            "<span>&nbsp;Require Any Hashtag</span>" +
3133            "</label>" +
3134            "</div>" +
3135            '<div class="input_holder_full ' +
3136            entry_method_field_pro +
3137            '">' +
3138            '<div id="twitter_hashtags_default_text_' +
3139            entry_method_class +
3140            "_" +
3141            id +
3142            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3143            "Default tweet text (* optional)" +
3144            "</div>" +
3145            '<input name="twitter_hashtags_default_text_value_' +
3146            entry_method_class +
3147            "_" +
3148            id +
3149            '" class="entry_input" placeholder="@SweepWidget is an awesome tool for running #contests and #giveaways!" maxlength="280" />' +
3150            "</div>";
3151        }
3152        // twitter_select_media
3153        else if (entry_method_class == "twitter_select_media") {
3154          var input_header_display =
3155            '<div class="input_holder_full ' +
3156            entry_method_field_pro +
3157            '">' +
3158            '<div id="twitter_select_media_' +
3159            entry_method_class +
3160            "_" +
3161            id +
3162            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3163            "Hashtags (* Optional)" +
3164            "</div>" +
3165            '<input name="twitter_select_media_value_' +
3166            entry_method_class +
3167            "_" +
3168            id +
3169            '" class="entry_input" placeholder="contests, giveaways, sweepwidget" maxlength="1000" />' +
3170            '<div class="sw_entry_method_handle_hint">' +
3171            'Write down each hashtag the user must use separated by a comma "," e.g. contests, giveaways, sweepwidget' +
3172            "</div>" +
3173            '<div class="verification_radio_buttons mt-[20px]">' +
3174            '<label class="cursor-pointer">' +
3175            '<input type="radio" class="sw-radio" name="twitter_select_media_hashtags_one_or_all_' +
3176            entry_method_class +
3177            "_" +
3178            id +
3179            '" value="1" checked />' +
3180            "<span>&nbsp;Require All Hashtags</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
3181            "</label>" +
3182            '<label class="cursor-pointer">' +
3183            '<input type="radio" class="sw-radio" name="twitter_select_media_hashtags_one_or_all_' +
3184            entry_method_class +
3185            "_" +
3186            id +
3187            '" value="2" />' +
3188            "<span>&nbsp;Require Any Hashtag</span>" +
3189            "</label>" +
3190            "</div>" +
3191            "</div>";
3192        }
3193        // facebook_select_media
3194        else if (entry_method_class == "facebook_select_media") {
3195          var input_header_display =
3196            '<div class="input_holder_full ' +
3197            entry_method_field_pro +
3198            '">' +
3199            '<div id="facebook_select_media_' +
3200            entry_method_class +
3201            "_" +
3202            id +
3203            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3204            "Hashtags (* Optional)" +
3205            "</div>" +
3206            '<input name="facebook_select_media_value_' +
3207            entry_method_class +
3208            "_" +
3209            id +
3210            '" class="entry_input" placeholder="contests, giveaways, sweepwidget" maxlength="1000" />' +
3211            '<div class="sw_entry_method_handle_hint">' +
3212            'Write down each hashtag the user must use separated by a comma "," e.g. contests, giveaways, sweepwidget' +
3213            "</div>" +
3214            '<div class="verification_radio_buttons mt-[20px]">' +
3215            '<label class="cursor-pointer">' +
3216            '<input type="radio" class="sw-radio" name="facebook_select_media_hashtags_one_or_all_' +
3217            entry_method_class +
3218            "_" +
3219            id +
3220            '" value="1" checked />' +
3221            "<span>&nbsp;Require All Hashtags</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
3222            "</label>" +
3223            '<label class="cursor-pointer">' +
3224            '<input type="radio" class="sw-radio" name="facebook_select_media_hashtags_one_or_all_' +
3225            entry_method_class +
3226            "_" +
3227            id +
3228            '" value="2" />' +
3229            "<span>&nbsp;Require Any Hashtag</span>" +
3230            "</label>" +
3231            "</div>" +
3232            "</div>";
3233        }
3234        // instagram_select_media
3235        else if (entry_method_class == "instagram_select_media") {
3236          var input_header_display =
3237            '<div class="input_holder_full ' +
3238            entry_method_field_pro +
3239            '">' +
3240            '<div id="instagram_select_media_' +
3241            entry_method_class +
3242            "_" +
3243            id +
3244            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3245            "Hashtags (* Optional)" +
3246            "</div>" +
3247            '<input name="instagram_select_media_value_' +
3248            entry_method_class +
3249            "_" +
3250            id +
3251            '" class="entry_input" placeholder="contests, giveaways, sweepwidget" maxlength="1000" />' +
3252            '<div class="sw_entry_method_handle_hint">' +
3253            'Write down each hashtag the user must use separated by a comma "," e.g. contests, giveaways, sweepwidget' +
3254            "</div>" +
3255            '<div class="verification_radio_buttons mt-[20px]">' +
3256            '<label class="cursor-pointer">' +
3257            '<input type="radio" class="sw-radio" name="instagram_select_media_hashtags_one_or_all_' +
3258            entry_method_class +
3259            "_" +
3260            id +
3261            '" value="1" checked />' +
3262            "<span>&nbsp;Require All Hashtags</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
3263            "</label>" +
3264            '<label class="cursor-pointer">' +
3265            '<input type="radio" class="sw-radio" name="instagram_select_media_hashtags_one_or_all_' +
3266            entry_method_class +
3267            "_" +
3268            id +
3269            '" value="2" />' +
3270            "<span>&nbsp;Require Any Hashtag</span>" +
3271            "</label>" +
3272            "</div>" +
3273            "</div>";
3274        }
3275        // pinterest_select_pin
3276        else if (entry_method_class == "pinterest_select_pin") {
3277          var input_header_display =
3278            '<div class="input_holder_full ' +
3279            entry_method_field_pro +
3280            '">' +
3281            '<div id="pinterest_select_pin_' +
3282            entry_method_class +
3283            "_" +
3284            id +
3285            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3286            "Hashtags (* Optional)" +
3287            "</div>" +
3288            '<input name="pinterest_select_pin_value_' +
3289            entry_method_class +
3290            "_" +
3291            id +
3292            '" class="entry_input" placeholder="contests, giveaways, sweepwidget" maxlength="1000" />' +
3293            '<div class="sw_entry_method_handle_hint">' +
3294            'Write down each hashtag the user must use separated by a comma "," e.g. contests, giveaways, sweepwidget' +
3295            "</div>" +
3296            '<div class="verification_radio_buttons mt-[20px]">' +
3297            '<label class="cursor-pointer">' +
3298            '<input type="radio" class="sw-radio" name="pinterest_select_pin_hashtags_one_or_all_' +
3299            entry_method_class +
3300            "_" +
3301            id +
3302            '" value="1" checked />' +
3303            "<span>&nbsp;Require All Hashtags</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
3304            "</label>" +
3305            '<label class="cursor-pointer">' +
3306            '<input type="radio" class="sw-radio" name="pinterest_select_pin_hashtags_one_or_all_' +
3307            entry_method_class +
3308            "_" +
3309            id +
3310            '" value="2" />' +
3311            "<span>&nbsp;Require Any Hashtag</span>" +
3312            "</label>" +
3313            "</div>" +
3314            "</div>";
3315        }
3316        // pinterest_select_board
3317        else if (entry_method_class == "pinterest_select_board") {
3318          var input_header_display =
3319            '<div class="input_holder_full ' +
3320            entry_method_field_pro +
3321            '">' +
3322            '<div id="pinterest_select_board_' +
3323            entry_method_class +
3324            "_" +
3325            id +
3326            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3327            "Hashtags (* Optional)" +
3328            "</div>" +
3329            '<input name="pinterest_select_board_value_' +
3330            entry_method_class +
3331            "_" +
3332            id +
3333            '" class="entry_input" placeholder="contests, giveaways, sweepwidget" maxlength="1000" />' +
3334            '<div class="sw_entry_method_handle_hint">' +
3335            'Write down each hashtag the user must use separated by a comma "," e.g. contests, giveaways, sweepwidget' +
3336            "</div>" +
3337            '<div class="verification_radio_buttons mt-[20px]">' +
3338            '<label class="cursor-pointer">' +
3339            '<input type="radio" class="sw-radio" name="pinterest_select_board_hashtags_one_or_all_' +
3340            entry_method_class +
3341            "_" +
3342            id +
3343            '" value="1" checked />' +
3344            "<span>&nbsp;Require All Hashtags</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
3345            "</label>" +
3346            '<label class="cursor-pointer">' +
3347            '<input type="radio" class="sw-radio" name="pinterest_select_board_hashtags_one_or_all_' +
3348            entry_method_class +
3349            "_" +
3350            id +
3351            '" value="2" />' +
3352            "<span>&nbsp;Require Any Hashtag</span>" +
3353            "</label>" +
3354            "</div>" +
3355            "</div>";
3356        }
3357        // Everything else
3358        else {
3359          var input_header_display =
3360            '<div class="input_holder_1 ' +
3361            entry_method_field_pro +
3362            '">' +
3363            '<div id="input_header_' +
3364            entry_method_class +
3365            "_" +
3366            id +
3367            '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3368            "Instructions" +
3369            "</div>" +
3370            '<div class="w-full float-left">' +
3371            '<textarea name="input_header_value_' +
3372            entry_method_class +
3373            "_" +
3374            id +
3375            '" class="sw-textarea" maxlength="1000">' +
3376            input_header_value +
3377            "</textarea>" +
3378            "</div>" +
3379            "</div>";
3380        }
3381      }
3382
3383      // Link button text
3384      // Write link_button_text_value if it has a default value from entry_method_fetch_values();
3385      if (
3386        link_button_text_value !== "" &&
3387        typeof link_button_text_value !== "undefined"
3388      ) {
3389        var link_button_text_display =
3390          '<div class="input_holder_1 ' +
3391          entry_method_field_pro +
3392          '">' +
3393          '<div id="link_button_text_header_' +
3394          entry_method_class +
3395          "_" +
3396          id +
3397          '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3398          "Entry Link Text" +
3399          "</div>" +
3400          '<input name="link_button_text_value_' +
3401          entry_method_class +
3402          "_" +
3403          id +
3404          '" value="' +
3405          link_button_text_value +
3406          '" class="entry_input" maxlength="255" />' +
3407          '<div class="sw_entry_method_handle_hint">' +
3408          "This is the entry link text that the user must click to enter" +
3409          "</div>" +
3410          "</div>";
3411      }
3412
3413      // Verify header
3414      // Write verify_header_value if it has a default value from entry_method_fetch_values();
3415      if (
3416        verify_header_value !== "" &&
3417        typeof verify_header_value !== "undefined"
3418      ) {
3419        var verify_header_display =
3420          '<div class="input_holder_1">' +
3421          '<div id="verify_header_' +
3422          entry_method_class +
3423          "_" +
3424          id +
3425          '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3426          "Verification Question" +
3427          "</div>" +
3428          '<input name="verify_header_value_' +
3429          entry_method_class +
3430          "_" +
3431          id +
3432          '" value="' +
3433          verify_header_value +
3434          '" class="entry_input" maxlength="255" />' +
3435          '<div class="sw_entry_method_handle_hint">' +
3436          "This is the verification question the user must complete" +
3437          "</div>" +
3438          "</div>";
3439      }
3440
3441      // Verify button text
3442      // Write verify_button_text_value if it has a default value from entry_method_fetch_values();
3443      if (
3444        verify_button_text_value !== "" &&
3445        typeof verify_button_text_value !== "undefined"
3446      ) {
3447        var verify_button_text_display =
3448          '<div class="input_holder_1">' +
3449          '<div id="verify_button_text_header_' +
3450          entry_method_class +
3451          "_" +
3452          id +
3453          '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3454          "Confirmation Link Text" +
3455          "</div>" +
3456          '<input name="verify_button_text_value_' +
3457          entry_method_class +
3458          "_" +
3459          id +
3460          '" value="' +
3461          verify_button_text_value +
3462          '" class="entry_input" maxlength="2500" />' +
3463          '<div class="sw_entry_method_handle_hint">' +
3464          "i.e. Confirm, Submit, Subscribe, etc." +
3465          "</div>" +
3466          "</div>";
3467      }
3468
3469      if (additional_instructions == 1) {
3470        var additional_instructions_wrapper_class =
3471          get_two.indexOf("photo-contest") != -1
3472            ? "input_holder_full"
3473            : "input_holder_1";
3474
3475        var additional_instructions_display =
3476          '<div class="' +
3477          additional_instructions_wrapper_class +
3478          ' mb-[20px]">' +
3479          '<div id="additional_instructions_header_' +
3480          entry_method_class +
3481          "_" +
3482          id +
3483          '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3484          additional_instructions_header +
3485          "</div>" +
3486          '<div class="w-full float-left">' +
3487          '<textarea name="additional_instructions_' +
3488          entry_method_class +
3489          "_" +
3490          id +
3491          '" class="sw-textarea" placeholder="' +
3492          additional_instructions_placeholder +
3493          '" maxlength="' +
3494          additional_instructions_max_length +
3495          '" data-gramm="false">' +
3496          additional_instructions_value +
3497          "</textarea>" +
3498          "</div>" +
3499          '<div class="sw_add_font_style_icons_set_holder">' +
3500          add_font_style_bold +
3501          add_font_style_italic +
3502          add_font_style_underline +
3503          add_font_style_link +
3504          add_font_style_phone +
3505     
3505     add_font_style_copy_paste +
3506          "</div>" +
3507          '<span class="sw_additional_instructions_note">' +
3508          additional_instructions_note +
3509          "</span>" +
3510          "</div>";
3511      }
3512
3513      if (entry_method_class == "custom") {
3514        var custom_radio_options_display =
3515          '<div class="input_holder_full_margin">' +
3516          '<div id="custom_radio_options_' +
3517          id +
3518          '" class="input_header_3 mt-4 mb-2">' +
3519          "How will you verify they did it?&nbsp;&nbsp;" +
3520          '<a target="_blank" class="tooltip_question_mark text-[#aaa] no-underline" href="' +
3521          website_url +
3522          '/docs/create-your-own-entry-method#custom-verification-question"><i class="fas fa-question-circle"></i></a>' +
3523          "</div>" +
3524          '<div class="verification_radio_buttons">' +
3525          '<label class="cursor-pointer">' +
3526          '<input type="radio" class="sw-radio" name="custom_radio_options_' +
3527          entry_method_class +
3528          "_" +
3529          id +
3530          '" value="1" checked="checked" onclick="custom_radio_options_display_value(this.value, ' +
3531          id +
3532          ')" />' +
3533          " <span>&nbsp;No Verification</span>" +
3534          "</label>" +
3535          "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
3536          '<label class="cursor-pointer">' +
3537          '<input type="radio" class="sw-radio" name="custom_radio_options_' +
3538          entry_method_class +
3539          "_" +
3540          id +
3541          '" value="2" onclick="custom_radio_options_display_value(this.value, ' +
3542          id +
3543          ')" />' +
3544          " <span>&nbsp;Ask a question</span>" +
3545          "</label>" +
3546          "</div>" +
3547          "</div>";
3548
3549        // Create hidden field. Ask the user a question to confirm they did the Create Your Own Entry method.
3550        var custom_radio_options_display_question =
3551          '<div id="custom_radio_options_holder_' +
3552          entry_method_class +
3553          "_" +
3554          id +
3555          '" class="full_width_hidden_2">' +
3556          '<div id="custom_radio_options_header_' +
3557          entry_method_class +
3558          "_" +
3559          id +
3560          '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
3561          "Question" +
3562          "</div>" +
3563          '<input type="text" autocomplete="off" name="custom_radio_options_question_' +
3564          entry_method_class +
3565          "_" +
3566          id +
3567          '" class="entry_input_2" maxlength="500" />' +
3568          "</div>";
3569      }
3570
3571      // Main id so I know which entry method is which
3572      var id_display = entry_method_class + "-" + id;
3573      var class_display = entry_method_class + "-" + id + "-" + level;
3574
3575      if (level == 2) {
3576        var icon_display =
3577          '<div class="input_holder_full">' +
3578          '<div class="text-[13px] font-semibold text-[#374151] mb-2 mt-4">' +
3579          "Icon color " +
3580          '<a target="_blank" class="ml-2 opacity-80 hover:opacity-100 tooltip_question_mark text-[#aaa] no-underline" href="' +
3581          website_url +
3582          '/docs/custom-entry-icon-colors"><i class="fas fa-question-circle"></i></a> ' +
3583          pro_plan_text +
3584          "</div>" +
3585          '<label class="sw-icon-color-row" for="icon_color_' + id + '">' +
3586          '<input type="hidden" name="icon_color_output_' +
3587          entry_method_class +
3588          "_" +
3589          id +
3590          '" value="' +
3591          background_color +
3592          '" />' +
3593          '<div id="icon_color_icon_' +
3594          entry_method_class +
3595          "_" +
3596          id +
3597          '" class="entry_icon_path_display" style="color:' +
3598          color +
3599          "; background:" +
3600          background_color +
3601          ';">' +
3602          font_awesome_icon +
3603          "</div>" +
3604          '<span class="sw-color-picker-label">Click to change</span>' +
3605          '<input type="color" id="icon_color_' +
3606          id +
3607          '" class="sw-color-picker icon_color" value="' +
3608          (background_color.indexOf("#") === 0 ? background_color : "#" + background_color) +
3609          '" data-entry_method_id="' +
3610          id +
3611          '" data-entry_method_class="' +
3612          entry_method_class +
3613          '" data-background_color="' +
3614          background_color +
3615          '" />' +
3616          "</label>" +
3617          '<div data-level="2"id="' +
3618          entry_method_class +
3619          "_" +
3620          id +
3621          '_icon_color_add" ' +
3622          'class="icon_color_picker' +
3623          entry_method_add_disallow_pro +
3624          icon_color_disallow +
3625          '" ' +
3626          'data-entry-method="' +
3627          entry_method_class +
3628          "_" +
3629          id +
3630          '_icon_color_add"></div>' +
3631          "</div>";
3632      } else {
3633        var icon_display = "";
3634      }
3635
3636      var entry_method_docs_link = entry_method_fetch_values(
3637        entry_method_class,
3638        "entry_method_docs_link",
3639        "",
3640        "",
3641        "",
3642        "",
3643        ""
3644      );
3645
3646      // Entry level 2
3647      if (level == "2") {
3648        // Required actions until unlock
3649        var required_actions_until_unlock_display =
3650          '<div class="w-full float-left">' +
3651          '<label class="' +
3652          pro_button_classes +
3653          ' cursor-pointer flex items-center">' +
3654          '<input type="checkbox" name="required_actions_until_unlock_checkbox_' +
3655          entry_method_class +
3656          "_" +
3657          id +
3658          '" class="sw-checkbox entry_checkbox entry_checkbox_pro required_actions_until_unlock_checkbox" data-entry_method_class="' +
3659          entry_method_class +
3660          '" data-entry_method_id="' +
3661          id +
3662          '" ' +
3663          disabled_pro +
3664          " />" +
3665          '<span class="input_header_2 text-[15px]">' +
3666          "Unlock after # of entries" +
3667          ' <a target="_blank" class="tooltip_question_mark text-[#aaa] no-u
3667nderline" href="' +
3668          website_url +
3669          '/docs/require-certain-amount-of-entries-to-unlock-entry-method"><i class="fas fa-question-circle"></i></a>' +
3670          disabled_pro_text +
3671          "</span>" +
3672          "</label>" +
3673          '<div id="required_actions_until_unlock_amount_wrapper_' +
3674          entry_method_class +
3675          "_" +
3676          id +
3677          '" class="hidden mt-2">' + // Additional inputs container
3678          '<input type="number" name="required_actions_until_unlock_' +
3679          entry_method_class +
3680          "_" +
3681          id +
3682          '" class="entry_input entry_input_pro validate w-[80px] p-[9px]" placeholder="1" value="1" min="1" max="999999" step="1">&nbsp; entries' + // Number input for action count
3683          "</div>" +
3684          "</div>";
3685      }
3686      // Entry level 1
3687      else {
3688        var required_actions_until_unlock_display = "";
3689        var more_options_display = "";
3690      }
3691
3692      if (
3693        link_button_text_display == "" &&
3694        verify_header_display == "" &&
3695        verify_button_text_display == ""
3696      ) {
3697        more_options_hide = "none";
3698      }
3699
3700      // *** Output the entry method
3701
3702      // Formatted entry method - NO input fields
3703      if (input_type == 0) {
3704        if (entry_method_handle == "Do A Task") {
3705          var entry_method_handle = "Create Your Own Entry";
3706        }
3707
3708        var entry_method_append =
3709          '<div id="' +
3710          id_display +
3711          '" class="entry_method_each ' +
3712          class_display +
3713          " entry_method_" +
3714          entry_method_class +
3715          '" data-level="' +
3716          level +
3717          '">' +
3718          '<div style="color:' +
3719          color +
3720          "; background: " +
3721          background_color +
3722          '" id="' +
3723          id_display +
3724          '-handle" class="handle" data-toggle="expand"><span class="entry_method_drag_icon"><i class="fa-solid fa-bars"></i></span> ' +
3725          '<span id="entry_method_handle_display_' +
3726          entry_method_class +
3727          "_" +
3728          id +
3729          '">' +
3730          entry_method_handle +
3731          "</span>" +
3732          '<a href="' +
3733          entry_method_docs_link +
3734          '" target="_blank" class="ml-2 opacity-80 hover:opacity-100"><i class="fas fa-question-circle text-white"></i></a>' +
3735          "</div>" +
3736          '<div class="delete" data-entry_method_int="' +
3737          entry_method_int +
3738          '">' +
3739          "Remove" +
3740          "</div>" +
3741          '<div id="' +
3742          id_display +
3743          '-inner" class="entry_method_body_inner">' +
3744          '<div class="entry_method_each_body">' +
3745          (entry_method_class === 'entries_for_purchase' || entry_method_class === 'woocommerce_purchases' ? '<div class="purchase-platform-options">' : '') +
3746          entries_for_purchase_platform_options_display +
3747          (entry_method_class === 'entries_for_purchase' || entry_method_class === 'woocommerce_purchases' ? '</div>' : '') +
3748          '<div class="entry_method_each_body_show_hide" id="entry_method_each_body_show_hide_top_' +
3749          entry_method_class +
3750          "_" +
3751          id +
3752          '">' +
3753          entry_method_handle_display +
3754          entry_amount_display +
3755          entries_for_purchase_advanced_options_display +
3756          entry_title_display +
3757          entry_link_display +
3758          input_header_display +
3759          entry_textarea_display +
3760          additional_instructions_display +
3761          viral_share_display +
3762          upload_a_file_ext_display +
3763          input_type_display +
3764          entry_attachment_display +
3765          custom_radio_options_display +
3766          custom_radio_options_display_question +
3767          entry_level_display +
3768          "</div>" +
3769          '<div class="entry_method_each_body_show_hide" id="entry_method_each_body_show_hide_bottom_' +
3770          entry_method_class +
3771          "_" +
3772          id +
3773          '">' +
3774          '<div class="w-full float-left mt-2">' +
3775          '<div class="full_width_no_margin">' +
3776          email_integration_display +
3777          "</div>" +
3778          '<div class="full_width_no_margin">' +
3779          require_verification_display +
3780          "</div>" +
3781          '<div class="full_width_no_margin">' +
3782          entries_for_purchase_send_email_checkbox_display +
3783          "</div>" +
3784          '<div class="full_width_no_margin">' +
3785          auto_enter_people_who_made_purchase_checkbox_display +
3786          "</div>" +
3787          '<div class="full_width_no_margin" style="display: ' +
3788          more_options_hide +
3789          ';">' +
3790          more_options_display +
3791          '<div class="full_width_margin_2 hidden" id="verify_wrapper_' +
3792          entry_method_class +
3793          "-" +
3794          id +
3795          '">' +
3796          link_button_text_display +
3797          verify_header_display +
3798          verify_button_text_display +
3799          "</div>" +
3800          "</div>" +
3801          '<div class="full_width_no_margin">' +
3802          social_optional_engagement_display +
3803          "</div>" +
3804          '<div class="full_width_no_margin">' +
3805          tracking_options_display +
3806          tracking_options_display_hidden_wrapper +
3807          "</div>" +
3808          '<div class="full_width_no_margin">' +
3809          api_auth_display +
3810          "</div>" +
3811          '<div class="full_width_no_margin">' +
3812          daily_display +
3813          "</div>" +
3814          '<div class="full_width_no_margin">' +
3815          timer_display +
3816          "</div>" +
3817          '<div class="full_width_no_margin">' +
3818          required_display +
3819          "</div>" +
3820          '<div class="full_width_no_margin">' +
3821          required_actions_until_unlock_display +
3822          "</div>" +
3823          icon_display +
3824          '<div class="full_width_no_margin">' +
3825          custom_icon_display +
3826          "</div>" +
3827          "</div>" +
3828          "</div>" +
3829          entries_for_purchase_info_display +
3830          '<div id="error_box_' +
3831          entry_method_class +
3832          "_" +
3833          id +
3834          '" class="entry_method_error_box"></div>' +
3835          "</div>" +
3836          "</div>" +
3837          "</div>";
3838
3839        // Formatted entry method - WITH input fields
3840      } else if (input_type == 1) {
3841        if (entry_method_handle == "Do A Task") {
3842          var entry_method_handle = "Create Your Own Entry";
3843        }
3844
3845        var entry_method_append =
3846          '<div id="' +
3847          id_display +
3848          '" class="entry_method_each ' +
3849          class_display +
3850          " entry_method_" +
3851          entry_method_class +
3852          '" data-level="' +
3853          level +
3854          '">' +
3855          '<div style="color:' +
3856          color +
3857          "; background: " +
3858          background_color +
3859          '" id="' +
3860          id_display +
3861          '-handle" class="handle" data-toggle="expand"><span class="entry_method_drag_icon"><i class="fa-solid fa-bars"></i></span> ' +
3862          '<span id="entry_method_handle_display_' +
3863          entry_method_class +
3864          "_" +
3865          id +
3866          '">' +
3867          entry_method_handle +
3868          "</span>" +
3869          '<a href="' +
3870          entry_method_docs_link +
3871          '" target="_blank" class="ml-2 opacity-80 hover:opacity-100"><i class="fas fa-question-circle text-white"></i></a>' +
3872          "</div>" +
3873          '<div class="delete" data-entry_method_int="' +
3874          entry_method_int +
3875          '">' +
3876          "Remove" +
3877          "</div>" +
3878          '<div id="' +
3879          id_display +
3880          '-inner" class="entry_method_body_inner">' +
3881          '<div class="entry_method_each_body">' +
3882          entry_method_handle_display +
3883          entry_amount_display +
3884          entries_for_purchase_advanced_options_display +
3885          entry_title_display +
3886          entry_link_display +
3887          input_header_display +
3888          entry_textarea_display +
3889          additional_instructions_display +
3890          viral_share_display +
3891          input_type_display +
3892          entry_attachment_display +
3893          entry_level_display +
3894          '<div class="full_width_no_margin mt-4">' +
3895          require_verification_display +
3896          "</div>" +
3897          '<div class="full_width_no_margin">' +
3898          entries_for_purchase_send_email_checkbox_display +
3899          "</div>" +
3900          '<div class="full_width_no_margin">' +
3901          auto_enter_people_who_made_purchase_checkbox_display +
3902          "</div>" +
3903          '<div class="full_width_no_margin">' +
3904          more_options_display +
3905          '<div class="full_width_margin_2" id="verify_wrapper_' +
3906          entry_method_class +
3907          "-" +
3908          id +
3909          '" class="hidden">' +
3910          link_button_text_display +
3911          verify_header_display +
3912          verify_button_text_display +
3913          "</div>" +
3914          "</div>" +
3915          '<div class="full_width_no_margin">' +
3916          social_optional_engagement_display +
3917          "</div>" +
3918          '<div class="full_width_no_margin">' +
3919          tracking_options_display +
3920          tracking_options_display_hidden_wrapper +
3921          "</div>" +
3922          '<div class="full_width_no_margin">' +
3923          api_auth_display +
3924          "</div>" +
3925          '<div class="full_width_no_margin">' +
3926          daily_display +
3927          "</div>" +
3928          '<div class="full_width_no_margin">' +
3929          timer_display +
3930          "</div>" +
3931          '<div class="full_width_no_margin">' +
3932          required_display +
3933          "</div>" +
3934          '<div class="full_width_no_margin">' +
3935          required_actions_until_unlock_display +
3936          "</div>" +
3937          icon_display +
3938          '<div class="full_width_no_margin">' +
3939          custom_icon_display +
3940          "</div>" +
3941          "</div>" +
3942          '<div id="error_box_' +
3943          entry_method_class +
3944          "_" +
3945          id +
3946          '" class="entry_method_error_box"></div>' +
3947          "</div>" +
3948          "</div>";
3949      }
3950
3951      // Format the order
3952      var entry_methods_container = $(
3953        'input[name="entry_methods_container"]'
3954      ).val();
3955      var entry_methods_container_append =
3956        entry_methods_container + "," + id_display;
3957      var entry_methods_container_append =
3958        entry_methods_container_append.replace(/^,|,$/g, "");
3959
3960      $('input[name="entry_methods_container"]').val(
3961        entry_methods_container_append
3962      );
3963
3964      // Format the order l1
3965      if (level == 1) {
3966        var entry_methods_container_l1 = $(
3967          'input[name="entry_methods_container_l1"]'
3968        ).val();
3969        var entry_methods_container_l1_append =
3970          entry_methods_container_l1 + "," + id_display;
3971        var entry_methods_container_l1_append =
3972          entry_methods_container_l1_append.replace(/^,|,$/g, "");
3973
3974        $('input[name="entry_methods_container_l1"]').val(
3975          entry_methods_container_l1_append
3976        );
3977      }
3978
3979      // Format the order l2
3980      if (level == 2) {
3981        var entry_methods_container_l2 = $(
3982          'input[name="entry_methods_container_l2"]'
3983        ).val();
3984        var entry_methods_container_l2_append =
3985          entry_methods_container_l2 + "," + id_display;
3986        var entry_methods_container_l2_append =
3987          entry_methods_container_l2_append.replace(/^,|,$/g, "");
3988
3989        $('input[name="entry_methods_container_l2"]').val(
3990          entry_methods_container_l2_append
3991        );
3992      }
3993
3994      // Append entry method
3995
3996      // Viral share entry method
3997      // if(is_viral_share == true) {
3998
3999      // 	$('#sortable_refer_friends').append(entry_method_append);
4000
4001      // }
4002
4003      // Level 1
4004      if (level == 1) {
4005        $("#sortable_one").append(entry_method_append);
4006
4007        // Append entries to widget example for level one entires
4008        widget_builder_example(id, entry_method_class, 0);
4009
4010        // Initialize sortable if for tweet
4011        if (
4012          entry_method_class == "twitter_tweet" ||
4013          entry_method_class == "x_post"
4014        ) {
4015          sortable_entry_group(id);
4016        }
4017
4018        // Level 2 (additional entry methods)
4019      } else if (level == 2) {
4020        $("#sortable_two").append(entry_method_append);
4021
4022        // Initialize sortable if for tweet
4023        if (
4024          entry_method_class == "twitter_tweet" ||
4025          entry_method_class == "x_post"
4026        ) {
4027          sortable_entry_group(id);
4028        }
4029      }
4030
4031      // Initialize icon color picker
4032      if (level == 2) {
4033        // Init color picker for each entry method
4034        preview_icon_color(id, entry_method_class, background_color);
4035
4036        // Initilize - show payment popup when click on color icon
4037        $("#" + entry_method_class + "_" + id + "_icon_color_add").on(
4038          "click",
4039          function () {
4040            payment_plan_popup();
4041          }
4042        );
4043      }
4044
4045      // For new purchase entry methods, hide config until store is connected
4046      if (entry_method_class === 'entries_for_purchase' || entry_method_class === 'woocommerce_purchases') {
4047        hideShopifyConfig(entry_method_class, id);
4048      }
4049
4050      if (level == 1 || level == 2) {
4051        $("html, body").animate(
4052          {
4053            scrollTop: $("#" + id_display).offset().top - 78,
4054          },
4055          500
4056        );
4057      }
4058
4059      // Form helpers removed - native selects
4060      updateAddButtonLabels();
4061    }
4062  });
4063
4064  // ========== SHOPIFY: Hide config until store is connected ==========
4065
4066  function hideShopifyConfig(cls, id) {
4067    var $inner = $('#' + cls + '-' + id + '-inner');
4068    // Hide everything inside entry_method_each_body except purchase-platform-options
4069    $inner.find('.entry_method_each_body').children().not('.purchase-platform-options').hide();
4070    // Hide all sibling sections (options section, etc.) except the body and error box
4071    $inner.children().not('.entry_method_each_body').not('.entry_method_error_box').hide();
4072  }
4073
4074  // On page load, hide purchase config for entry methods that don't have products loaded yet
4075  $(function () {
4076    $('.entry_method_entries_for_purchase, .entry_method_woocommerce_purchases').each(function () {
4077      var fullId = $(this).attr('id'); // e.g. "entries_for_purchase-123"
4078      var parts = fullId.split('-');
4079      var cls = parts[0]; // "entries_for_purchase" or "woocommerce_purchases"
4080      var id = parts[1];
4081      // Check if products are loaded (hidden textarea has base64 content)
4082      var productsJson = $('textarea[name=products_json_' + cls + '_' + id + ']').val();
4083      if (!productsJson || productsJson.trim() === '') {
4084        hideShopifyConfig(cls, id);
4085      }
4086    });
4087  });
4088
4089  // AWeber | Constant Contact - Authentication
4090  $(document.body).on(
4091    "click",
4092    ".connect_account, .connect_account_again",
4093    function (e) {
4094      var button_text = $(this).val();
4095
4096      $(this).val("Connecting...").prop("disabled", true).css("opacity", "0.7");
4097
4098      var id = $(this).attr("data-id");
4099      var email_provider_text = $(this).attr("data-email-provider-text").trim();
4100
4101      // https://sweepwidget.com/oauth/aweber_auth.php?delete_cookies=true
4102      var api_url = website_url + "/oauth/" + email_provider_text + "_auth.php";
4103      if (
4104        $(this).attr("name").trim() ==
4105        email_provider_text + "_connect_account_again_" + id
4106      ) {
4107        // force connect button
4108        api_url += "?delete_cookies=true";
4109      }
4110
4111      var _this = this;
4112      PopupWindow(
4113        api_url,
4114        function (json) {
4115          if (json && json.success) {
4116            $(
4117              "#email_integration_" +
4118              email_provider_text +
4119              "_input_fields_" +
4120              id
4121            ).show();
4122
4123            // auto-fill fields.
4124            $(
4125              'input[name="' +
4126              email_provider_text +
4127              "_access_token_" +
4128              id +
4129              '"]'
4130            )
4131              .val(json.data.access_token)
4132              .prop("readonly", true);
4133
4134            if (email_provider_text == "aweber") {
4135              $(
4136                'input[name="' +
4137                email_provider_text +
4138                "_access_token_secret_" +
4139                id +
4140                '"]'
4141              )
4142                .val(json.data.access_token_secret)
4143                .prop("readonly", true);
4144            }
4145
4146            if (
4147              email_provider_text == "hubspot" ||
4148              email_provider_text == "constant_contact"
4149            ) {
4150              $(
4151                'input[name="' +
4152                email_provider_text +
4153                "_refresh_token_" +
4154                id +
4155                '"]'
4156              )
4157                .val(json.data.refresh_token)
4158                .prop("readonly", true);
4159              $(
4160                'input[name="' +
4161                email_provider_text +
4162                "_expires_in_" +
4163                id +
4164                '"]'
4165              )
4166                .val(json.data.expires_in)
4167                .prop("readonly", true);
4168            }
4169
4170            $(_this).val("Account Connected").prop("readonly", true);
4171
4172            $(
4173              "#" + email_provider_text + "_connect_again_button_holder" + id
4174            ).css("display", "inline-block"); // show
4175
4176            // Auto fetch the lists.
4177            $(
4178              "input[name=" +
4179              email_provider_text +
4180              "_list_id_search_" +
4181              id +
4182              "]"
4183            ).trigger('click');
4184          } else {
4185            $(_this)
4186              .val(button_text)
4187              .prop("disabled", false)
4188              .css("opacity", "0.9");
4189          }
4190        },
4191        200
4192      );
4193    }
4194  );
4195
4196  // Email integration handles
4197  $(document.body).on("click", ".email_list_submit", function () {
4198    var id = $(this).attr("data-id");
4199
4200    var email_provider_text = $(this).attr("data-email-provider-text").trim();
4201
4202    var body_data = {
4203      email_provider_text: email_provider_text,
4204    };
4205
4206    var email_errors = 0;
4207
4208    // Build body_data from provider config
4209    var provider = window.EMAIL_PROVIDERS_MAP[email_provider_text];
4210    if (provider && provider.fetchDataFields) {
4211      for (var f = 0; f < provider.fetchDataFields.length; f++) {
4212        var field = provider.fetchDataFields[f];
4213        body_data[field] = $("input[name=" + email_provider_text + "_" + field + "_" + id + "]").val();
4214        if (body_data[field] == "") {
4215          email_errors = 1;
4216        }
4217      }
4218    }
4219
4220    // Empty fields
4221    if (email_errors == 1) {
4222      Swal.fire({
4223        icon: "error",
4224        title: "Oops...",
4225        text: "Please fill out all fields.",
4226        confirmButtonText: "OK",
4227      });
4228    }
4229    // Continue
4230    else {
4231      var button_text = $(this).val();
4232
4233      $(this).val("Fetching...");
4234
4235      $(this)
4236        .prop("disabled", true)
4237        .css("background", "#ccc")
4238        .css("border", "1px solid #ccc");
4239
4240      var _this = this;
4241
4242      $.ajax({
4243        url: website_url + "/a/email_integration.php",
4244        data: body_data,
4245        type: "POST",
4246
4247        success: function (data) {
4248          if (data) {
4249            $(
4250              "select[name=" + email_provider_text + "_list_id_" + id + "]"
4251            ).html(data);
4252          }
4253
4254          // $('input[name=' + email_provider_text + '_list_id_search_' + id + ']')
4255          $(_this)
4256            .val(button_text)
4257            .prop("disabled", false)
4258            .css("background", "#4a3aff")
4259            .css("border", "1px solid #4a3aff");
4260
4261          // formSelect removed
4262        },
4263
4264        error: function (err) {
4265          $(_this)
4266            .val(button_text)
4267            .prop("disabled", false)
4268            .css("background", "#4a3aff")
4269            .css("border", "1px solid #4a3aff");
4270        },
4271      });
4272    }
4273  });
4274
4275  // Get translated default text when the language is changed
4276  $(document.body).on("change", "#language_add", function () {
4277    var language = $(this).val();
4278
4279    $.ajax({
4280      url: website_url + "/a/get_translate.php",
4281      data: { language: language },
4282      type: "POST",
4283      xhrFields: true,
4284      dataType: "text",
4285      success: function (data) {
4286        if (data) {
4287          var arr = JSON.parse(data);
4288
4289          // Get json response for translate
4290          var translate = arr.translate;
4291
4292          // Encode it into hidden value on build_edit_widget.inc.php
4293          $("#language_translations").val(
4294            encodeURIComponent(JSON.stringify({ translate: translate }))
4295          );
4296        }
4297      },
4298    });
4299  });
4300
4301  function expand_minimize_checkbox_show_hide(
4302    level_word,
4303    when_entry_action,
4304    toggle_mode
4305  ) {
4306    level_word = level_word || "one";
4307    when_entry_action = when_entry_action || "add";
4308    toggle_mode = toggle_mode || "";
4309
4310    // If on update-widget page
4311    if (pathname.indexOf("update-widget") != -1) {
4312      // header id for update-widget
4313      var expand_minimize_header_id =
4314        "minimize_all_level_" + level_word + "_header";
4315
4316      // checkbox id for update-widget
4317      var expand_minimize_checkbox_id = "minimize_all_level_" + level_word;
4318    } else {
4319      // If on build-widget page
4320
4321      // header id for build-widget
4322      var expand_minimize_header_id =
4323        "minimize_all_level_" + level_word + "_header_copy";
4324
4325      // checkbox id for build-widget
4326      var expand_minimize_checkbox_id =
4327        "minimize_all_level_" + level_word + "_copy";
4328    }
4329
4330    var expand_minimize_checkbox_text = "";
4331
4332    // Remove an entry
4333    if (when_entry_action == "remove") {
4334      // All current level entries removed
4335      if ($("#sortable_" + level_word + " > .entry_method_each").length == 0) {
4336        // Hide expand / minimize checkbox when an entry method is removed
4337        $("#" + expand_minimize_header_id).hide();
4338
4339        // Uncheck expand / minimize checkbox for current level
4340        $("#" + expand_minimize_checkbox_id).prop("checked", false);
4341
4342        expand_minimize_checkbox_text = "Expand1";
4343      }
4344
4345      // Added new entry
4346    } else if (when_entry_action == "add") {
4347      // Show expand / minimize checkbox when an entry method is removed
4348      $("#" + expand_minimize_header_id).show();
4349
4350      // Check expand / minimize checkbox for current level
4351      $("#" + expand_minimize_checkbox_id).prop("checked", true);
4352
4353      expand_minimize_checkbox_text = "Minimize";
4354
4355      // Toggle
4356    } else if (when_entry_action == "toggle" && toggle_mode != "") {
4357      var total_count = $("#sortable_" + level_word + " > .handle").length;
4358      var toggle_mode_count = $(
4359        "#sortable_" +
4360        level_word +
4361        ' > .handle[data-toggle="' +
4362        toggle_mode +
4363        '"]'
4364      ).length;
4365
4366      // All are toggled (expanded / collapsed)
4367      if (total_count == toggle_mode_count) {
4368        // show expand / minimize checkbox when an entry method is toggled
4369        $("#" + expand_minimize_header_id).show();
4370
4371        // Expanded
4372        if (toggle_mode == "expand") {
4373          // check expand / minimize checkbox for current level
4374          $("#" + expand_minimize_checkbox_id).prop("checked", true);
4375
4376          expand_minimize_checkbox_text = "Minimize Entry Methods";
4377
4378          // Collapsed
4379        } else if (toggle_mode == "collapse") {
4380          // uncheck expand / minimize checkbox for current level
4381          $("#" + expand_minimize_checkbox_id).prop("checked", false);
4382
4383          expand_minimize_checkbox_text = "Expand Entry Methods";
4384        }
4385      }
4386    }
4387
4388    // Toggle text to this.
4389    if (expand_minimize_checkbox_text) {
4390      $("#minimize_all_level_" + level_word + "_text").html(
4391        expand_minimize_checkbox_text
4392      );
4393    }
4394  }
4395
4396  // Delete entry method
4397  $(document.body).on("click", ".delete", function () {
4398    var id = $(this).parent().attr("id");
4399
4400    var id_exp = id.split("-");
4401    var entry_method_class = id_exp[0];
4402    var entry_id = id_exp[1];
4403
4404    var level = parseInt($(this).parent().attr("data-level").trim(), 10);
4405
4406    var entry_methods_container = $(
4407      'input[name="entry_methods_container"]'
4408    ).val();
4409    var entry_methods_container_updated = entry_methods_container.replace(
4410      id,
4411      ""
4412    );
4413    var entry_methods_container_updated =
4414      entry_methods_container_updated.replace(",,", ",");
4415    var entry_methods_container_updated =
4416      entry_methods_container_updated.replace(/^,|,$/g, "");
4417    $('input[name="entry_methods_container"]').val(
4418      entry_methods_container_updated
4419    );
4420
4421    // Level 1 entry methods
4422    if (level == 1) {
4423      var entry_methods_container_l1 = $(
4424        'input[name="entry_methods_container_l1"]'
4425      ).val();
4426      var entry_methods_container_l1_updated =
4427        entry_methods_container_l1.replace(id, "");
4428      var entry_methods_container_l1_updated =
4429        entry_methods_container_l1_updated.replace(",,", ",");
4430      var entry_methods_container_l1_updated =
4431        entry_methods_container_l1_updated.replace(/^,|,$/g, "");
4432      $('input[name="entry_methods_container_l1"]').val(
4433        entry_methods_container_l1_updated
4434      );
4435    }
4436
4437    // Level 2 entry methods
4438    if (level == 2) {
4439      var entry_methods_container_l2 = $(
4440        'input[name="entry_methods_container_l2"]'
4441      ).val();
4442      var entry_methods_container_l2_updated =
4443        entry_methods_container_l2.replace(id, "");
4444      var entry_methods_container_l2_updated =
4445        entry_methods_container_l2_updated.replace(",,", ",");
4446      var entry_methods_container_l2_updated =
4447        entry_methods_container_l2_updated.replace(/^,|,$/g, "");
4448      $('input[name="entry_methods_container_l2"]').val(
4449        entry_methods_container_l2_updated
4450      );
4451    }
4452
4453    var repeatable_actions_container = $(
4454      'input[name="repeatable_actions_container"]'
4455    ).val();
4456    var repeatable_actions_container_updated =
4457      repeatable_actions_container.replace(entry_method_class, "");
4458    var repeatable_actions_container_updated =
4459      repeatable_actions_container_updated.replace(",,", ",");
4460    var repeatable_actions_container_updated =
4461      repeatable_actions_container_updated.replace(/^,|,$/g, "");
4462    $('input[name="repeatable_actions_container"]').val(
4463      repeatable_actions_container_updated
4464    );
4465
4466    // Remove Edit Box
4467    $(this).parent().remove();
4468
4469    // Update "Add a/Another" button text
4470    updateAddButtonLabels();
4471
4472    // Hide all .entry_group_hide,
4473    $(".entry_group_hide").hide();
4474
4475    // Remove Widget Example field
4476    $("#sw_row_" + entry_id + ", #sw_input_row_" + entry_id)
4477      .html("")
4478      .css("min-height", "0px")
4479      .css("margin", "0px 0px 0px 0px")
4480      .css("padding", "0px 0px 0px 0px");
4481
4482    var level_word = "";
4483    if (level == 1) {
4484      level_word = "one";
4485    } else if (level == 2) {
4486      level_word = "two";
4487    }
4488
4489    if (level_word) {
4490      // check for current level
4491
4492      expand_minimize_checkbox_show_hide(level_word, "remove");
4493    }
4494
4495    // If refer_friends
4496    if (entry_method_class == "refer_friends") {
4497      // Show add viral share entry_method button
4498      $("#refer_friends_add_wrapper").show();
4499    }
4500  });
4501
4502  // Delete entry group i.e. tweet
4503  $(document.body).on("click", ".entry_group_handle_delete", function () {
4504    // ID containing all tweets
4505    var wrapper_id = $(this).parent().parent().parent().attr("id");
4506
4507    // Tweet wrapper id
4508    var twitter_tweet_num = $(this).parent().parent().attr("id");
4509
4510    var entry_method_class = $(this)
4511      .parent()
4512      .parent()
4513      .attr("data-entry_method_class");
4514    var entry_method_id = $(this)
4515      .parent()
4516      .parent()
4517      .attr("data-entry_method_id");
4518
4519    // Remove tweet
4520    $("#" + wrapper_id + " #" + twitter_tweet_num).remove();
4521
4522    // Get order
4523    var order = $("#" + wrapper_id)
4524      .sortable("toArray")
4525      .toString();
4526
4527    // Sanitize extra commas
4528    var order = order
4529      .replace(/[, ]+/g, ",")
4530      .trim()
4531      .replace(/(^,)|(,$)/g, "");
4532
4533    // Write / update new order
4534    $(
4535      "input[name=" + entry_method_class + "_" + entry_method_id + "-num-list]"
4536    ).val(order);
4537  });
4538
4539  // Function to handle keyup event
4540  function onEditorKeyup2(event) {
4541    // Check if the id is 'textarea_description'
4542    if ($(this).attr("id") === "textarea_description") {
4543      var ed = tinymce.get("textarea_description");
4544      var value = ed ? ed.getContent() : "";
4545      $("#demo_description").html(value);
4546    }
4547  }
4548
4549  // Twitter Tweet APPEND - append extra tweets
4550  $(document.body).on(
4551    "click",
4552    ".twitter_tweet_append, .x_post_append",
4553    function () {
4554      var entry_method_class = $(this).attr("data-entry_method_class");
4555      var entry_method_id = $(this).attr("data-entry_method_id");
4556      var entry_group_id = $(this).attr("data-entry_group_id");
4557      var tweet_or_post =
4558        entry_method_class == "twitter_tweet" ? "Tweet" : "Post";
4559
4560      var id = $(this).parent().parent().parent().attr("id");
4561
4562      // Get previous tweet num
4563      var twitter_tweet_num = $(
4564        "input[name=" + entry_method_class + "_" + entry_method_id + "-num]"
4565      ).val();
4566
4567      // Add +1 so it's the current tweet num
4568      twitter_tweet_num++;
4569
4570      var header_id =
4571        "entry_textarea_header_" +
4572        entry_method_class +
4573        "_" +
4574        entry_method_id +
4575        "-" +
4576        twitter_tweet_num;
4577      var textarea_name =
4578        "entry_textarea_" +
4579        entry_method_class +
4580        "_" +
4581        entry_method_id +
4582        "-" +
4583        twitter_tweet_num;
4584      var data_attributes =
4585        'data-entry_method_class="' +
4586        entry_method_class +
4587        '" data-entry_method_id="' +
4588        entry_method_id +
4589        '" data-entry_group_id="' +
4590        twitter_tweet_num +
4591        '"';
4592      var entry_textarea_max_length = 280;
4593
4594      var entry_textarea_display =
4595        '<div id="' +
4596        twitter_tweet_num +
4597        '" class="entry_group_each" ' +
4598        data_attributes +
4599        ">" +
4600        '<div id="entry_textarea_header_' +
4601        header_id +
4602        '" class="entry_group_handle ui-sortable-handle flex items-center justify-between">' +
4603        '<div class="entry_group_handle_text">' +
4604        tweet_or_post +
4605        " Text (" +
4606        twitter_tweet_num +
4607        ")</div>" +
4608        '<div class="entry_group_handle_delete flex items-center justify-center w-6 h-6 rounded hover:bg-black/10 transition-colors cursor-pointer text-gray-400 hover:text-gray-600" title="Remove">' +
4609        '<i class="fas fa-times text-xs"></i>' +
4610        "</div>" +
4611        "</div>" +
4612        '<div class="w-full float-left">' +
4613        '<textarea id="' +
4614        textarea_name +
4615        '" name="' +
4616        textarea_name +
4617        '" class="sw-textarea" placeholder="280 characters max." maxlength="280" data-gramm="false"></textarea>' +
4618        "</div>" +
4619        "</div>";
4620
4621      // Append the new tweet/post
4622      $("#entry_group-" + entry_method_id).append(entry_textarea_display);
4623
4624      // Destroy and reinitialize sortable to pick up the new item
4625      if ($("#entry_group-" + entry_method_id).hasClass("ui-sortable")) {
4626        $("#entry_group-" + entry_method_id).sortable("destroy");
4627      }
4628      sortable_entry_group(entry_method_id);
4629
4630      $(
4631        "input[name=" + entry_method_class + "_" + entry_method_id + "-num]"
4632      ).val(twitter_tweet_num);
4633      $(
4634        "input[name=" +
4635        entry_method_class +
4636        "_" +
4637        entry_method_id +
4638        "-num-list]"
4639      ).val(
4640        $(
4641          "input[name=" +
4642          entry_method_class +
4643          "_" +
4644          entry_method_id +
4645          "-num-list]"
4646        ).val() +
4647        "," +
4648        twitter_tweet_num
4649      );
4650
4651      // Tweet/post textareas are plain textareas (no TinyMCE)
4652    }
4653  );
4654
4655  // *** Save as Draft
4656  $("#widget_save_draft").on("click", function (e) {
4657    e.preventDefault();
4658
4659    // Set is_draft to 1
4660    document.getElementById("is_draft").value = "1";
4661
4662    // Only validate title for drafts
4663    var title = $('input[name="title"]').val();
4664
4665    if (title == "") {
4666      Swal.fire({
4667        title: "Title Required",
4668        text: "Please enter a giveaway title to save as a draft.",
4669        icon: "error",
4670        confirmButtonText: "OK",
4671      });
4672      return false;
4673    }
4674
4675    // Show saving state
4676    $(this).html('Saving Draft <svg class="inline-block w-4 h-4 ml-1 -mt-0.5 animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path></svg>');
4677    toggleOverlay2(true);
4678
4679    // Add hidden widget_submit so PHP handler recognizes the form submission
4680    var hiddenSubmit = document.createElement("input");
4681    hiddenSubmit.type = "hidden";
4682    hiddenSubmit.name = "widget_submit";
4683    hiddenSubmit.value = "1";
4684    document.getElementById("widget_form").appendChild(hiddenSubmit);
4685
4686    // Submit form directly, bypassing full validation
4687    document.getElementById("widget_form").submit();
4688  });
4689
4690  // *** Form Submit
4691  $("#widget_submit_2").on("click", function (e) {
4692    $("#is_draft").val(0);
4693    var title = $('input[name="title"]').val();
4694    var age_limit = $('input[name="age_limit"]').val();
4695    var age_limit_min_or_max = $('select[name="age_limit_min_or_max"]').val();
4696    var start_date = $('input[name="start_date"]').val();
4697    // var start_time = $('input[name="start_time"]').val();
4698    var end_date = $('input[name="end_date"]').val();
4699    // var end_time = $('input[name="end_time"]').val();
4700    var start_end_date_display = $(
4701      'input[name="start_end_date_display"]'
4702    ).val();
4703    var time_zone = $('select[name="time_zone"]').val();
4704    var countries_allowed = $('textarea[name="countries_allowed"]').val();
4705    var _descEd = tinymce.get("textarea_description");
4706    var description = _descEd ? _descEd.getContent() : $('textarea[name="description"]').val();
4707    var _rulesEd = tinymce.get("textarea_rules");
4708    var textarea_rules = _rulesEd ? _rulesEd.getContent() : $('textarea[name="rules"]').val();
4709    var telegram_bot_error = 0;
4710
4711    if ($('input[name="allowed_world_wide"]').is(":checked")) {
4712      var allowed_world_wide = 1;
4713    } else {
4714      var allowed_world_wide = 0;
4715    }
4716
4717    //var number_of_winners = $('input[name="number_of_winners"]').val();
4718    //var winner_selection_method = $('select[name="winner_selection_method"]').val();
4719    var prize_image = $("#prize_image").val();
4720
4721    // Check for errors in main fields (non-entry methods)
4722
4723    if_empty_field("input", title, "", "title", "title_header", 1);
4724    if_empty_field("input", age_limit, "", "age_limit", "age_limit_header", 1);
4725    if_empty_field(
4726      "select",
4727      age_limit_min_or_max,
4728      "",
4729      "age_limit_min_or_max",
4730      "age_limit_min_or_max_header",
4731      1
4732    );
4733    // if_empty_field(
4734    //   "input",
4735    //   start_date,
4736    //   "",
4737    //   "start_date",
4738    //   "start_date_header",
4739    //   1
4740    // );
4741    // if_empty_field("input", end_date, "", "end_date", "end_date_header", 1);
4742    // if_empty_field("select", time_zone, "", "time_zone", "time_zone_header", 1);
4743
4744    if (allowed_world_wide == 0) {
4745      if_empty_field(
4746        "textarea",
4747        countries_allowed,
4748        "",
4749        "countries_allowed",
4750        "countries_allowed_header",
4751        1
4752      );
4753    }
4754
4755    $("#entry_methods_two_errors").val(0);
4756
4757    // Clear all previous error states
4758    $(".entry_method_each").removeClass("sw-entry-error");
4759    $(".sw-field-error").removeClass("sw-field-error");
4760    $(".sw-label-error").removeClass("sw-label-error");
4761    $(".tox-tinymce.sw-field-error").removeClass("sw-field-error");
4762
4763    // Track which tab has errors: level 1 = Login Fields (tab 3), level 2 = Entry Methods (tab 2)
4764    var login_fields_has_errors = 0;
4765    var entry_methods_tab_has_errors = 0;
4766
4767    // Ignore these entry methods. Note: user_details was what was causing the script to show an error when all fields were filled.
4768    var ignore_entry_method_array = ["user_details"];
4769
4770    var entry_methods_container = $(
4771      'input[name="entry_methods_container"]'
4772    ).val();
4773    var array = entry_methods_container.split(",");
4774
4775    // LOOP through each active entry method to check for errors
4776    $.each(array, function (i) {
4777      var entry_method_full = array[i];
4778      var entry_method_class = entry_method_full.substring(
4779        0,
4780        entry_method_full.indexOf("-")
4781      );
4782      var id = entry_method_full.substr(entry_method_full.indexOf("-") + 1);
4783      var level = $(
4784        "input[name=entry_level_" + entry_method_class + "_" + id + "]"
4785      ).val();
4786
4787      // If entry method iteration is not ignored
4788      if (ignore_entry_method_array.indexOf(entry_method_class) == -1) {
4789        // Batch-fetch all entry method field values for validation
4790        var em = entry_method_fetch_all(entry_method_class, "", "");
4791
4792        // Static fields
4793        var entry_method_handle = em.entry_method_handle;
4794        var entry_method_docs_link = em.entry_method_docs_link;
4795        var entry_title = em.entry_title;
4796        var entry_link = em.entry_link;
4797        var entry_amount = em.entry_amount;
4798        var entry_textarea = em.entry_textarea;
4799        var additional_instructions = em.additional_instructions;
4800        var daily = em.daily;
4801        var timer = em.timer;
4802        var required = em.required;
4803        var custom_icon = em.custom_icon;
4804        var input_type = em.input_type;
4805        var entry_attachment = em.entry_attachment;
4806        var entry_attachment_validation = em.entry_attachment_validation;
4807        var entry_attachment_validation_error = em.entry_attachment_validation_error;
4808        var viral_share = em.viral_share;
4809        var make_a_purchase = em.make_a_purchase;
4810        var email_integration = em.email_integration;
4811
4812        // Error fields
4813        var entry_title_error_val = em.entry_title_error_val;
4814        var entry_link_error_val = em.entry_link_error_val;
4815        var entry_amount_error_val = em.entry_amount_error_val;
4816        var entry_textarea_error_val = em.entry_textarea_error_val;
4817        var entry_match_errors_val = em.entry_match_error_val;
4818        var input_error_1_val = em.input_error_1_val;
4819        var input_error_2_val = em.input_error_2_val;
4820        var email_integration_error = em.email_integration_error_val;
4821
4822        // Field not in batch - fetch individually
4823        var entry_additional_instructions_default_value =
4824          entry_method_fetch_values(
4825            entry_method_class,
4826            "entry_additional_instructions_default_value",
4827            "",
4828            "",
4829            "",
4830            "",
4831            ""
4832          );
4833        //var unlock_rewards_entry_methods_l2_required_error = 0;
4834
4835        if (level == 1) {
4836          var entry_amount = 0;
4837        }
4838
4839        // Check if entry_title is empty
4840        if (entry_method_handle) {
4841          var input_value = $(
4842            'input[name="entry_method_handle_' +
4843            entry_method_class +
4844            "_" +
4845            id +
4846            '"]'
4847          ).val();
4848          var input_name =
4849            "entry_method_handle_" + entry_method_class + "_" + id;
4850          var header_id =
4851            "entry_method_handle_header_" + entry_method_class + "_" + id;
4852          var entry_method_handle_errors = if_empty_field(
4853            "input",
4854            input_value,
4855            "",
4856            input_name,
4857            header_id,
4858            2
4859          );
4860        }
4861
4862        // Check if entry_title is empty
4863        if (entry_title == 1) {
4864          var input_value = $(
4865            'input[name="entry_title_' + entry_method_class + "_" + id + '"]'
4866          ).val();
4867          var input_name = "entry_title_" + entry_method_class + "_" + id;
4868          var header_id = "entry_title_header_" + entry_method_class + "_" + id;
4869          var entry_title_errors = if_empty_field(
4870            "input",
4871            input_value,
4872            "",
4873            input_name,
4874            header_id,
4875            2
4876          );
4877        }
4878
4879        // Check if entry_link is empty
4880        if (entry_link == 1) {
4881          if (entry_method_class == "secret_code") {
4882            var input_or_textarea = "textarea";
4883          } else {
4884            var input_or_textarea = "input";
4885          }
4886          var input_selector =
4887            input_or_textarea +
4888            '[name="entry_link_' +
4889            entry_method_class +
4890            "_" +
4891            id +
4892            '"]';
4893          var input_value = $(input_selector).val();
4894          var input_name = "entry_link_" + entry_method_class + "_" + id;
4895          var header_id = "entry_link_header_" + entry_method_class + "_" + id;
4896          var entry_link_errors = if_empty_field(
4897            "input",
4898            input_value,
4899            "",
4900            input_name,
4901            header_id,
4902            2
4903          );
4904
4905          var entry_link_array = [
4906            "facebook_page_visit|facebook",
4907            "facebook_page_like|facebook",
4908            "facebook_group_join|facebook",
4909            "facebook_post_comment|facebook",
4910            "facebook_post_like|facebook",
4911            "pinterest_repin_pin|pinterest",
4912            "youtube_channel_subscribe|youtube",
4913            "instagram_visit_profile|instagram",
4914            "instagram_view_post|instagram",
4915            "soundcloud_follow|soundcloud",
4916            "etsy_follow|etsy",
4917            "ebay_follow|ebay",
4918            "youtube_comment|youtube",
4919          ];
4920
4921          if ($.inArray(entry_method_class, entry_link_array) !== -1) {
4922            // TODO: verify
4923
4924            var string_contains_substring = string_contains_substring(
4925              entry_method_class,
4926              entry_link_array
4927            );
4928          }
4929
4930          var entry_link_validation = em.entry_link_validation;
4931          var entry_link_validation_error = em.entry_link_validation_error;
4932
4933          if (entry_link_validation) {
4934            if (!entry_link_validation.test(value)) {
4935              // is invalid
4936              $(input_selector).css("border-color", "red");
4937              $(input_selector)
4938                .parent(".input_holder_1")
4939                .find(".validation_error")
4940                .show();
4941
4942              $("#error_box_" + entry_method_class + "_" + id).append(
4943                "<li>" + entry_link_validation_error + "</li>"
4944              );
4945              Swal.fire({
4946                icon: "error",
4947                title: "Oops...",
4948                text:
4949                  'Error in "' +
4950                  entry_method_handle +
4951                  '" entry - ' +
4952                  entry_link_validation_error,
4953                confirmButtonText: "OK",
4954              });
4955            } else {
4956              $(input_selector).css("border-color", "#e0e0e0");
4957              $(input_selector)
4958                .parent(".input_holder_1")
4959                .find(".validation_error")
4960                .hide();
4961            }
4962          }
4963        }
4964
4965        if (pathname.indexOf("build-") != -1) {
4966          // If Telegram private channel - check if bot was created in the last 24 hours. If not, give an error.
4967          if (entry_method_class.indexOf("telegram") != -1) {
4968            // telegram_bot_error = 1;
4969            // entry_match_errors_val = 'You need to create a NEW bot to add to your private channel. The bot must have been created within the last 24 hours. Then, you can add that bot to your channel.';
4970
4971            var user_id = getCookieValue("user_login");
4972            var website_id = $(".user_sites_select").val().split("|")[0]; // current selected website
4973
4974            $.ajax({
4975              url: website_url + "/a/telegram_private_bot_check.php",
4976              type: "GET",
4977              dataType: "json",
4978              data: {
4979                user_id: user_id,
4980                website_id: website_id,
4981              },
4982              success: function (arr) { },
4983            });
4984          }
4985        }
4986
4987        // Check if entry_textarea is empty
4988        if (entry_textarea == 1) {
4989          if (
4990            entry_method_class == "twitter_tweet" ||
4991            entry_method_class == "x_post"
4992          ) {
4993            var twitter_tweet_num_list = $(
4994              "input[name=" + entry_method_class + "_" + id + "-num-list]"
4995            ).val();
4996            var twitter_tweet_num_list = twitter_tweet_num_list.replace(
4997              /^,|,$/g,
4998              ""
4999            );
5000
5001            var tweet_num_arr = twitter_tweet_num_list.split(",");
5002
5003            for (var i = 0; i < tweet_num_arr.length; i++) {
5004              var input_value = $(
5005                "textarea[name=entry_textarea_" +
5006                entry_method_class +
5007                "_" +
5008                id +
5009                "-" +
5010                tweet_num_arr[i] +
5011                "]"
5012              ).val();
5013              var input_name =
5014                "entry_textarea_" +
5015                entry_method_class +
5016                "_" +
5017                id +
5018                "-" +
5019                tweet_num_arr[i];
5020              var header_id =
5021                "entry_textarea_header_" +
5022                entry_method_class +
5023                "_" +
5024                id +
5025                "-" +
5026                tweet_num_arr[i];
5027              var entry_textarea_errors = if_empty_field(
5028                "textarea",
5029                input_value,
5030                "",
5031                input_name,
5032                header_id,
5033                2
5034              );
5035            }
5036          } else {
5037            var input_value = $(
5038              'textarea[name="entry_textarea_' +
5039              entry_method_class +
5040              "_" +
5041              id +
5042              '"]'
5043            ).val();
5044            var input_name = "entry_textarea_" + entry_method_class + "_" + id;
5045            var header_id =
5046              "entry_textarea_header_" + entry_method_class + "_" + id;
5047            var entry_textarea_errors = if_empty_field(
5048              "textarea",
5049              input_value,
5050              "",
5051              input_name,
5052              header_id,
5053              2
5054            );
5055          }
5056        }
5057
5058        // Check if file upload is correct
5059        if (entry_attachment == 1) {
5060          var input_value = $(
5061            'input[name="entry_attachment_' +
5062            entry_method_class +
5063            "_" +
5064            id +
5065            '"]'
5066          ).val();
5067          var input_name = "entry_attachment_" + entry_method_class + "_" + id;
5068          // var header_id = 'entry_attachment_header_' + entry_method_class + '_' + id;
5069          // var entry_attachment_errors = entry_attachment_validation.test();
5070        }
5071
5072        // Check if entry_amount is empty (Only check if level == 2) and not photo contest
5073        if (entry_amount == 1 && get_two.indexOf("photo-contest") == -1) {
5074          var input_value = $(
5075            'input[name="entry_amount_' + entry_method_class + "_" + id + '"]'
5076          ).val();
5077          var input_name = "entry_amount_" + entry_method_class + "_" + id;
5078          var header_id =
5079            "entry_amount_header_" + entry_method_class + "_" + id;
5080          var entry_amount_errors = if_empty_field(
5081            "input",
5082            input_value,
5083            "",
5084            input_name,
5085            header_id,
5086            2
5087          );
5088
5089          if (input_value > 1000000) {
5090            var entry_amount_errors = 1;
5091            $("#entry_methods_two_errors").val(1);
5092          }
5093        }
5094
5095        // Question fields (error check)
5096
5097        // Check additional input fields (radio, checkbox, select, input_field)
5098
5099        var input_type_errors = 0; // Set input errors 0 initially; it will be updated to 1 if one of the values are empty
5100
5101        if (input_type == 1) {
5102          // Checkbox
5103          if (entry_method_class == "checkbox") {
5104            // Radio
5105          } else if (entry_method_class == "radio") {
5106            var input_value_options = $(
5107              "input[name=radio_options_" + entry_method_class + "_" + id + "]"
5108            ).val();
5109            var input_name = "radio_options_" + entry_method_class + "_" + id;
5110            var header_id =
5111              "radio_options_header_" + entry_method_class + "_" + id;
5112            var input_type_errors = if_empty_field(
5113              "input",
5114              input_value_options,
5115              "",
5116              input_name,
5117              header_id,
5118              2
5119            );
5120
5121            var input_value_required = $(
5122              "input[name=radio_required_" + entry_method_class + "_" + id + "]"
5123            ).val();
5124            var input_name_required =
5125              "radio_required_" + entry_method_class + "_" + id;
5126            var header_id_required =
5127              "radio_required_header_" + entry_method_class + "_" + id;
5128
5129            // If Dropdown has a required selection, check to see it matches one of the optinos
5130            var entry_match_errors = if_empty_field(
5131              "input",
5132              input_value_options,
5133              input_value_required,
5134              input_name_required,
5135              header_id,
5136              3
5137            );
5138
5139            // Select
5140          } else if (entry_method_class == "select") {
5141            var input_value_options = $(
5142              "input[name=select_options_" + entry_method_class + "_" + id + "]"
5143            ).val();
5144            var input_name = "select_options_" + entry_method_class + "_" + id;
5145            var header_id = "select_header_" + entry_method_class + "_" + id;
5146            var input_type_errors = if_empty_field(
5147              "input",
5148              input_value_options,
5149              "",
5150              input_name,
5151              header_id,
5152              2
5153            );
5154
5155            var input_value_required = $(
5156              "input[name=select_required_" +
5157              entry_method_class +
5158              "_" +
5159              id +
5160              "]"
5161            ).val();
5162            var input_name_required =
5163              "select_required_" + entry_method_class + "_" + id;
5164            var header_id_required =
5165              "select_required_header_" + entry_method_class + "_" + id;
5166
5167            var input_value_options_required =
5168              input_value_options + "|" + input_value_required;
5169
5170            // If Dropdown has a required selection, check to see it matches one of the optinos
5171            var entry_match_errors = if_empty_field(
5172              "input",
5173              input_value_options,
5174              input_value_required,
5175              input_name_required,
5176              header_id,
5177              3
5178            );
5179
5180            // Input Text
5181          } else if (entry_method_class == "text_input") {
5182            var input_value = $(
5183              "input[name=entry_title_" + entry_method_class + "_" + id + "]"
5184            ).val();
5185            var input_name = "entry_title_" + entry_method_class + "_" + id;
5186            var header_id = "text_header_" + entry_method_class + "_" + id;
5187            var input_type_errors = if_empty_field(
5188              "input",
5189              input_value,
5190              "",
5191              input_name,
5192              header_id,
5193              2
5194            );
5195
5196            // Textarea
5197          } else if (entry_method_class == "textarea") {
5198          }
5199        }
5200
5201        // *** Check email integration errors
5202        else if (email_integration == 1) {
5203          var email_integration_checkbox = $(
5204            'input[name="email_integration_checkbox_' +
5205            entry_method_class +
5206            "_" +
5207            id +
5208            '"]'
5209          ).is(":checked");
5210
5211          // Check if the email integration checkbox is checked
5212          if (email_integration_checkbox == true) {
5213            var email_integration_checkbox = 1;
5214          } else {
5215            var email_integration_checkbox = 0;
5216          }
5217
5218          // Email integration is checked
5219          if (email_integration_checkbox == 1) {
5220            // Validate selected email integration method
5221            input_type_errors = validateEmailIntegration(entry_method_class, id);
5222          }
5223        }
5224
5225        // *** Check Refer A Friend errors
5226        else if (viral_share == 1) {
5227          var viral_share_checked = $(
5228            'input[name="viral_share_' +
5229            entry_method_class +
5230            "_" +
5231            id +
5232            '"]:checked'
5233          );
5234
5235          // Check if the Refer A Friend checkboxes is checked
5236          if (viral_share_checked && viral_share_checked.length > 0) {
5237            input_type_errors = 1;
5238          }
5239        }
5240
5241        var user_id = getCookieValue("user_login");
5242
5243        document
5244          .querySelector("form")
5245          .addEventListener("submit", async function (e) {
5246            // Get the current value of the hidden field dynamically
5247            var amoeAdded = $("#amoeAdded").val();
5248
5249            if (
5250              (entry_method_class == "make_a_purchase" ||
5251                entry_method_class == "entries_for_purchase" ||
5252                entry_method_class == "woocommerce_purchases") &&
5253              user_id !== "3zw91c678e24384088a1f5xkl5"
5254            ) {
5255              // Check if refer_friends exists
5256              if (entry_methods_container.indexOf("refer_friends") == -1) {
5257                // Check localStorage for prior AMOE acknowledgment for this contest
5258                var amoeStorageKey = get_three ? "amoeAcknowledged_" + get_three : "";
5259                if (amoeStorageKey && localStorage.getItem(amoeStorageKey) === "1") {
5260                  amoeAdded = "1";
5261                  $("#amoeAdded").val(1);
5262                }
5263
5264                if (amoeAdded !== "1") {
5265                  // Prevent page from submitting
5266                  e.preventDefault();
5267
5268                  // Show Swal.fire alert with two options
5269                  var result = await Swal.fire({
5270                    title: "AMOE Required",
5271                    html: '<p style="margin-bottom:10px;">Purchase-based giveaways are <strong>legally required</strong> to include an <strong>AMOE (alternative method of entry)</strong> so that participants can enter without making a purchase.</p><p style="margin-bottom:10px;">We recommend adding <strong>Refer-A-Friend</strong> as your AMOE. Click below to auto-add it.</p><p style="margin-bottom:10px;">If you have already provided your own AMOE in your official rules (e.g., mail-in entry, free online form, etc.), you may skip this step. <strong>You are responsible for ensuring your giveaway complies with all applicable laws.</strong></p><p><a target="_blank" href="https://sweepwidget.com/docs/what-is-alternative-method-of-en" class="font-bold underline">Read more about AMOE here</a>.</p>',
5272                    icon: "warning",
5273                    confirmButtonText: "Add Refer-A-Friend (Recommended)",
5274                    showCancelButton: true,
5275                    cancelButtonText: "I already have an AMOE",
5276                    reverseButtons: true,
5277                  });
5278
5279                  if (result.isConfirmed) {
5280                    // Add Refer-A-Friend entry method
5281                    $("#refer_friends_add").trigger('click');
5282                  } else if (result.dismiss === Swal.DismissReason.cancel) {
5283                    // User confirmed they have their own AMOE - save to localStorage for this contest
5284                    if (amoeStorageKey) {
5285                      localStorage.setItem(amoeStorageKey, "1");
5286                    }
5287                  }
5288
5289                  // Scroll to the top of the page
5290                  $("html, body").animate(
5291                    {
5292                      scrollTop: 0,
5293                    },
5294                    1
5295                  );
5296
5297                  // Set the flag so the popup doesn't show again
5298                  $("#amoeAdded").val(1);
5299
5300                  // Submit the form programmatically
5301                  $("#widget_submit_2").trigger('click');
5302                } else {
5303                  // Allow the form to submit after AMOE has been added
5304                  return;
5305                }
5306              }
5307            }
5308          });
5309
5310        // Check for errors
5311        var $entryCard = $("#" + entry_method_class + "-" + id).closest(".entry_method_each");
5312        var $errorBox = $("#error_box_" + entry_method_class + "_" + id);
5313        var hasErrors =
5314          entry_title_errors == 1 ||
5315          entry_link_errors == 1 ||
5316          entry_textarea_errors == 1 ||
5317          entry_amount_errors == 1 ||
5318          input_type_errors == 1 ||
5319          entry_match_errors == 1 ||
5320          telegram_bot_error == 1;
5321
5322        if (hasErrors) {
5323          $entryCard.addClass("sw-entry-error");
5324          $errorBox.show().html("<ul></ul>");
5325          $("#" + entry_method_class + "-" + id + "-inner").show();
5326
5327          // Track which tab has the error
5328          if (level == 1) {
5329            login_fields_has_errors = 1;
5330          } else {
5331            entry_methods_tab_has_errors = 1;
5332          }
5333
5334          var $errorList = $errorBox.find("ul");
5335
5336          if (entry_title_errors == 1) {
5337            $errorList.append("<li>" + entry_title_error_val + "</li>");
5338          }
5339
5340          if (entry_link_errors == 1) {
5341            $errorList.append("<li>" + entry_link_error_val + "</li>");
5342          }
5343
5344          if (entry_textarea_errors == 1) {
5345            $errorList.append("<li>" + entry_textarea_error_val + "</li>");
5346          }
5347
5348          if (entry_amount_errors == 1) {
5349            $errorList.append("<li>" + entry_amount_error_val + "</li>");
5350          }
5351
5352          if (entry_match_errors == 1) {
5353            $errorList.append("<li>" + entry_match_errors_val + "</li>");
5354          }
5355
5356          if (telegram_bot_error == 1) {
5357            $errorList.append("<li>" + entry_match_errors_val + "</li>");
5358          }
5359
5360          if (input_type_errors == 1) {
5361            if (entry_method_class == "checkbox") {
5362              // Checkbox - no message
5363            } else if (entry_method_class == "radio") {
5364              $errorList.append("<li>" + input_error_1_val + "</li>");
5365            } else if (entry_method_class == "select") {
5366              $errorList.append("<li>" + input_error_1_val + "</li>");
5367            } else if (entry_method_class == "textarea") {
5368              // Textarea - no message
5369            } else if (entry_method_class == "email_subscribe") {
5370              $errorList.append("<li>" + email_integration_error + "</li>");
5371            } else if (entry_method_class == "refer_friends") {
5372              $errorList.append(
5373                "<li>At least one sharing checkbox should be checked.</li>"
5374              );
5375            }
5376          }
5377        } else {
5378          $entryCard.removeClass("sw-entry-error");
5379          $errorBox.hide().html("");
5380        }
5381      }
5382    });
5383
5384    // If leaderboard is checked
5385    if ($("input[name=if_leaderboard]").is(":checked")) {
5386      // entry_methods_container_l2 value
5387      var entry_methods_container_l2 = $(
5388        "#input[name=entry_methods_container_l2]"
5389      ).val();
5390
5391      // If there's not viral chare entry method
5392      // if (entry_methods_container.indexOf("refer_friends") == -1) {
5393
5394      // 	var leaderboard_viral_share_required_error = 1;
5395
5396      // }
5397    }
5398
5399    // Unlock rewards is checked
5400    if ($("input[name=if_unlock_rewards]").is(":checked")) {
5401      // Entry methods l2 count
5402      var entry_methods_count_l2 = entry_methods_count_l2_func();
5403
5404      // If if_unlock_rewards is checked, and 0 entry methods
5405      if (entry_methods_count_l2 == 0) {
5406        //var unlock_rewards_entry_methods_l2_required_error = 1;
5407      }
5408    }
5409
5410    // If there's any errors with the entry_method fields
5411    var entry_method_errors = $("#entry_methods_two_errors").val();
5412
5413    var website_id = $(".user_sites_select").val().split("|")[0]; // current selected website
5414
5415    if (
5416      title !== "" &&
5417      age_limit_min_or_max !== "" &&
5418      start_date !== "" &&
5419      // && start_time !== ''
5420      end_date !== "" &&
5421      // && end_time !== ''
5422      // && start_end_date_display !== ''
5423      time_zone !== "" &&
5424      //&& description !== ''
5425      (countries_allowed !== "" || allowed_world_wide == 1) &&
5426      entry_method_errors == 0 &&
5427      telegram_bot_error == 0
5428      //&& unlock_rewards_entry_methods_l2_required_error !== 1
5429      //&& leaderboard_viral_share_required_error !== 1
5430    ) {
5431      // Get value of if_leaderboard, if_unlock_rewards, entry_methods_container
5432      var if_leaderboard = $("input[name=if_leaderboard]:checked").val();
5433      var if_unlock_rewards = $("input[name=if_unlock_rewards]:checked").val();
5434      var entry_methods_container = $("#entry_methods_container").val();
5435
5436      // If leaderboard or unlock rewards is checked and there's no viral entry method, tell the user it must be enabled, and automatically enable it. Also, prevent submit until user does this.
5437      // if(	if_leaderboard == 'on'
5438      // 	&& entry_methods_container.indexOf("refer_friends") == -1) {
5439
5440      // 	// Auto-click #refer_friends_add
5441      // 	$('#refer_friends_add').trigger('click');
5442
5443      // }
5444
5445      // All validation passed!
5446      $("#widget_submit_2").html('Saving <svg class="inline-block w-4 h-4 ml-1 -mt-0.5 animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"></path></svg>');
5447
5448      // Show loading icon
5449      toggleOverlay2(true); // Show overlay
5450    } else {
5451      var errors = "";
5452
5453      if (title == "") {
5454        errors += "<li>Giveaway title</li>";
5455      }
5456
5457      if (age_limit == "") {
5458        errors += "<li>Age limit</li>";
5459      }
5460
5461      if (age_limit_min_or_max == "") {
5462        errors += "<li>Age limit min / max</li>";
5463      }
5464
5465      if (start_date == "") {
5466        errors += "<li>Start date</li>";
5467      }
5468
5469      if (end_date == "") {
5470        errors += "<li>End date</li>";
5471      }
5472
5473      // if(start_time == '') {
5474      // 	errors += '<li>Start time</li>';
5475      // }
5476
5477      // if(end_time == '') {
5478      // 	errors += '<li>End time</li>';
5479      // }
5480
5481      // if(start_end_date_display == '') {
5482      // 	errors += '<li>Start/end date</li>';
5483      // }
5484
5485      if (time_zone == "") {
5486        errors += "<li>Timezone</li>";
5487      }
5488
5489      if (description == "") {
5490        //errors += '<li>Giveaway description</li>';
5491      }
5492
5493      if (countries_allowed == "" && allowed_world_wide == 0) {
5494        errors += "<li>Select a country users can enter in</li>";
5495      }
5496
5497      if (telegram_bot_error == 1) {
5498        errors +=
5499          "<li>You need to create a NEW bot to add to your private channel. The bot must have been created within the last 24 hours. Then, you can add that bot to your channel.</li>";
5500      }
5501
5502      // Check if user is on a mid-contest upgrade plan
5503      var upgrade_plan_mid_contest = $("#upgrade_plan_mid_contest").val();
5504
5505      // Ignore if user is on a mid-contest upgrade plan
5506      if (upgrade_plan_mid_contest == 1) {
5507        return;
5508      }
5509
5510      // Entry methods / login fields error
5511      if (entry_method_errors > 0) {
5512        // Show the correct error message and navigate to the correct tab
5513        if (login_fields_has_errors && !entry_methods_tab_has_errors) {
5514          Swal.fire({
5515            title: "Fill In Your Login Fields",
5516            text: "Please fill in the required information for your login fields. You can also add or delete any login fields.",
5517            icon: "error",
5518            confirmButtonText: "OK",
5519          });
5520          var targetTabId = "#prize-info-link-3";
5521        } else if (entry_methods_tab_has_errors && !login_fields_has_errors) {
5522          Swal.fire({
5523            title: "Fill In Your Entry Methods",
5524            text: "Please fill in the required information for your entry methods. You can also add or delete any entry methods.",
5525            icon: "error",
5526            confirmButtonText: "OK",
5527          });
5528          var targetTabId = "#prize-info-link-2";
5529        } else {
5530          Swal.fire({
5531            title: "Fill In Your Entry Methods & Login Fields",
5532            text: "Please fill in the required information for your entry methods and login fields.",
5533            icon: "error",
5534            confirmButtonText: "OK",
5535          });
5536          var targetTabId = "#prize-info-link-2";
5537        }
5538
5539        // Go to the correct tab
5540        $(".vertical-nav-inner li").removeClass("active");
5541        $(".vertical-nav-inner li a").each(function () {
5542          var target = $(this).attr("href");
5543          $(target).hide();
5544        });
5545
5546        $(targetTabId).parent("li").addClass("active");
5547        var targetContent = $(targetTabId).attr("href");
5548        $(targetContent).show();
5549
5550        // Scroll to the top of the page
5551        $("html, body").animate(
5552          {
5553            scrollTop: 0,
5554          },
5555          1
5556        );
5557
5558        e.preventDefault();
5559        return false;
5560      }
5561
5562      // Other errors
5563      else {
5564        Swal.fire({
5565          title: "Please fix the following fields",
5566          html: '<ul style="list-style:none;padding:0;margin:8px auto 0;display:inline-block;text-align:left;color:#6b7280;font-size:15px;line-height:1.8;">' + errors.replace(/<li>/g, '<li style="padding:0;">') + '</ul>',
5567          icon: "error",
5568          confirmButtonText: "OK",
5569        });
5570
5571        // Go to the "Basic Info" tab
5572        // Deactivate all tabs and hide all content
5573        $(".vertical-nav-inner li").removeClass("active");
5574        $(".vertical-nav-inner li a").each(function () {
5575          var target = $(this).attr("href");
5576          $(target).hide();
5577        });
5578
5579        // Activate the specified tab and show its content
5580        $("#prize-info-link-1").parent("li").addClass("active");
5581        var targetContent = $("#prize-info-link-1").attr("href");
5582        $(targetContent).show();
5583
5584        // Scroll to the top of the page
5585        $("html, body").animate(
5586          {
5587            scrollTop: 0,
5588          },
5589          1
5590        );
5591
5592        // Prevent page from submitting
5593        e.preventDefault();
5594        return false;
5595      }
5596    }
5597    return true;
5598  });
5599
5600  // Add font style i.e. bold, italic, underline
5601  function wrapText(tag, textarea_name) {
5602    var textArea = $(textarea_name),
5603      len = textArea.val().length,
5604      start = textArea[0].selectionStart,
5605      end = textArea[0].selectionEnd,
5606      selectedText = textArea.val().substring(start, end),
5607      replacement = "[" + tag + "]" + selectedText + "[/" + tag + "]";
5608
5609    textArea.val(
5610      textArea.val().substring(0, start) +
5611      replacement +
5612      textArea.val().substring(end, len)
5613    );
5614
5615    $(textarea_name).keyup();
5616  }
5617
5618  // Add Link
5619  function wrapLink(link, textarea_name) {
5620    var textArea = $(textarea_name),
5621      len = textArea.val().length,
5622      start = textArea[0].selectionStart,
5623      end = textArea[0].selectionEnd,
5624      selectedText = textArea.val().substring(start, end);
5625
5626    textArea.val(
5627      textArea.val().substring(0, start) +
5628      link +
5629      textArea.val().substring(end, len)
5630    );
5631
5632    $(textarea_name).keyup();
5633  }
5634
5635  // Add font style i.e. bold, italic, underline for entries additional and textarea fields
5636  $(document).on("click", ".sw_add_font_style_icon", function () {
5637    var entry_method_class = $(this).attr("data-entry_method_class");
5638    var entry_method_id = $(this).attr("data-entry_method_id");
5639    var additional_instructions = $(this).attr("data-additional_instructions");
5640    var entry_textarea = $(this).attr("data-entry_textarea");
5641    var font_style = $(this).attr("data-font_style");
5642
5643    if (entry_textarea == 1) {
5644      var entry_method_prepend = "entry_textarea";
5645    } else if (additional_instructions == 1) {
5646      var entry_method_prepend = "additional_instructions";
5647    } else {
5648      var entry_method_prepend = "entry_textarea";
5649    }
5650
5651    var textarea_name =
5652      "textarea[name=" +
5653      entry_method_prepend +
5654      "_" +
5655      entry_method_class +
5656      "_" +
5657      entry_method_id +
5658      "]";
5659
5660    wrapText(font_style, textarea_name);
5661  });
5662
5663  // Add font style i.e. bold, italic, underline for main description & rules
5664  $(document).on("click", ".sw_add_font_style_icon_reg", function () {
5665    var desc_or_rules = $(this).attr("data-desc_or_rules");
5666    var font_style = $(this).attr("data-font_style");
5667
5668    if (desc_or_rules == "desc") {
5669      var textarea_name = "#textarea_description";
5670    } else if (desc_or_rules == "rules") {
5671      var textarea_name = "#textarea_rules";
5672    }
5673
5674    wrapText(font_style, textarea_name);
5675  });
5676
5677  // Add link for entries additional and textarea fields
5678  $(document).on("click", ".sw_add_font_style_icon_2", function () {
5679    var entry_method_class = $(this).attr("data-entry_method_class");
5680    var entry_method_id = $(this).attr("data-entry_method_id");
5681    var entry_textarea = $(this).attr("data-entry_textarea");
5682    var additional_instructions = $(this).attr("data-additional_instructions");
5683    var link_type = $(this).attr("data-link_type");
5684
5685    var random_num = Math.floor(Math.random() * (99999 - 1 + 1)) + 1;
5686    var entry_method_id_rand = entry_method_id + "_" + random_num;
5687
5688    if (entry_textarea == 1) {
5689      var entry_method_prepend = "entry_textarea";
5690    } else if (additional_instructions == 1) {
5691      var entry_method_prepend = "additional_instructions";
5692    } else {
5693      var entry_method_prepend = "entry_textarea";
5694    }
5695
5696    var textarea_name =
5697      "textarea[name=" +
5698      entry_method_prepend +
5699      "_" +
5700      entry_method_class +
5701      "_" +
5702      entry_method_id +
5703      "]";
5704
5705    var textArea = $(textarea_name),
5706      len = textArea.val().length,
5707      start = textArea[0].selectionStart,
5708      end = textArea[0].selectionEnd,
5709      selectedText = textArea.val().substring(start, end);
5710
5711    if (link_type == "link") {
5712      var text_one = "Add a Link";
5713      var modal_icon = '<i class="fas fa-link"></i>';
5714      var error_one = "Please fill in both fields";
5715
5716      var link_input_one =
5717        '<div class="mb-4">' +
5718        '<label class="block text-[13px] font-medium text-gray-600 mb-1.5">Text to display</label>' +
5719        '<input type="text" id="sw_' +
5720        entry_method_class +
5721        "_add_link_name_" +
5722        entry_method_id_rand +
5723        '" class="w-full px-3 py-2.5 text-[14px] text-gray-700 bg-white border border-gray-200 rounded-lg outline-none transition-all duration-200" value="' +
5724        selectedText +
5725        '" />' +
5726        "</div>";
5727
5728      var link_input_two =
5729        '<div class="mb-4">' +
5730        '<label class="block text-[13px] font-medium text-gray-600 mb-1.5">Link URL</label>' +
5731        '<input type="text" id="sw_' +
5732        entry_method_class +
5733        "_add_link_url_" +
5734        entry_method_id_rand +
5735        '" class="w-full px-3 py-2.5 text-[14px] text-gray-700 bg-white border border-gray-200 rounded-lg outline-none transition-all duration-200" placeholder="https://" value="" />' +
5736        "</div>" +
5737        '<div class="mt-2">' +
5738        '<label class="cursor-pointer">' +
5739        '<input type="checkbox" name="sw_' +
5740        entry_method_class +
5741        "_add_link_button_" +
5742        entry_method_id_rand +
5743        '" class="sw-checkbox" />' +
5744        '<span class="text-[14px] text-gray-600">Make this a button?</span>' +
5745        "</label>" +
5746        "</div>";
5747    } else if (link_type == "phone") {
5748      var text_one = "Add a Phone Number";
5749      var modal_icon = '<i class="fas fa-phone"></i>';
5750      var error_one = "Please fill in phone number";
5751
5752      var link_input_one =
5753        '<div class="mb-4">' +
5754        '<label class="block text-[13px] font-medium text-gray-600 mb-1.5">Phone Number</label>' +
5755        '<input type="text" id="sw_' +
5756        entry_method_class +
5757        "_add_link_name_" +
5758        entry_method_id_rand +
5759        '" class="w-full px-3 py-2.5 text-[14px] text-gray-700 bg-white border border-gray-200 rounded-lg outline-none transition-all duration-200" value="' +
5760        selectedText +
5761        '" placeholder="(312) 947-1845" />' +
5762        "</div>" +
5763        '<div class="flex items-center gap-5">' +
5764        '<label class="flex items-center gap-2 cursor-pointer text-[14px] text-gray-600">' +
5765        '<input type="radio" class="sw-radio" name="sw_' +
5766        entry_method_class +
5767        "_add_link_tel_or_sms_" +
5768        entry_method_id_rand +
5769        '" value="tel" checked="1" />' +
5770        "<span>Call</span>" +
5771        "</label>" +
5772        '<label class="flex items-center gap-2 cursor-pointer text-[14px] text-gray-600">' +
5773        '<input type="radio" class="sw-radio" name="sw_' +
5774        entry_method_class +
5775        "_add_link_tel_or_sms_" +
5776        entry_method_id_rand +
5777        '" value="sms" />' +
5778        "<span>Text</span>" +
5779        "</label>" +
5780        "</div>";
5781
5782      var link_input_two = "";
5783    } else if (link_type == "copy_paste") {
5784      var text_one = "Copy Text";
5785      var modal_icon = '<i class="fas fa-copy"></i>';
5786      var error_one = "Please fill in copy/paste text.";
5787
5788      var link_input_one =
5789        '<div class="mb-4">' +
5790        '<label class="block text-[13px] font-medium text-gray-600 mb-1.5">Text user must copy/paste</label>' +
5791        '<input type="text" id="sw_' +
5792        entry_method_class +
5793        "_add_copy_paste_" +
5794        entry_method_id_rand +
5795        '" class="w-full px-3 py-2.5 text-[14px] text-gray-700 bg-white border border-gray-200 rounded-lg outline-none transition-all duration-200" value="' +
5796        selectedText +
5797        '" placeholder="Copy this text..." />' +
5798        "</div>";
5799
5800      var link_input_two = "";
5801    }
5802
5803    $("body").append(
5804      '<div id="sw_' +
5805      entry_method_class +
5806      "_add_link_modal_" +
5807      entry_method_id_rand +
5808      '" class="sw-modal-backdrop fixed inset-0 z-[1000000] flex items-center justify-center bg-black/40">' +
5809      '<div class="bg-white rounded-xl shadow-2xl w-[400px] max-w-[90vw] overflow-hidden">' +
5810      '<div class="flex items-center justify-between px-5 py-4 border-b border-gray-100">' +
5811      '<div class="flex items-center gap-2.5 text-[16px] font-semibold text-gray-800">' +
5812      '<span class="text-primary text-[14px]">' + modal_icon + '</span>' +
5813      text_one +
5814      "</div>" +
5815      '<div id="sw_' +
5816      entry_method_class +
5817      "_add_link_modal_close_" +
5818      entry_method_id_rand +
5819      '" class="text-gray-400 hover:text-gray-600 cursor-pointer text-[18px] leading-none transition-colors duration-150">' +
5820      '<i class="fas fa-times"></i>' +
5821      "</div>" +
5822      "</div>" +
5823      '<div class="px-5 py-5">' +
5824      link_input_one +
5825      link_input_two +
5826      "</div>" +
5827      '<div class="flex items-center justify-end gap-2.5 px-5 py-3.5 border-t border-gray-100 bg-gray-50/60">' +
5828      '<input type="button" value="Cancel" id="sw_' +
5829      entry_method_class +
5830      "_add_link_modal_cancel_" +
5831      entry_method_id_rand +
5832      '" class="py-2 px-4 text-[14px] font-medium text-gray-500 bg-white border border-gray-200 rounded-lg cursor-pointer outline-none transition-all duration-200 hover:bg-gray-50" />' +
5833      '<input type="button" value="Insert" id="sw_' +
5834      entry_method_class +
5835      "_add_link_ok_" +
5836      entry_method_id_rand +
5837      '" class="py-2 px-4 text-[14px] font-medium text-white bg-primary border border-primary rounded-lg cursor-pointer outline-none transition-all duration-200 hover:opacity-90" />' +
5838      "</div>" +
5839      "</div>" +
5840      "</div>"
5841    );
5842
5843    $(document).on(
5844      "click",
5845      "#sw_" +
5846      entry_method_class +
5847      "_add_link_modal_close_" +
5848      entry_method_id_rand +
5849      ", #sw_" +
5850      entry_method_class +
5851      "_add_link_modal_cancel_" +
5852      entry_method_id_rand,
5853      function () {
5854        $(
5855          "#sw_" +
5856          entry_method_class +
5857          "_add_link_modal_" +
5858          entry_method_id_rand
5859        ).hide();
5860      }
5861    );
5862
5863    $(document).on(
5864      "click",
5865      "#sw_" + entry_method_class + "_add_link_ok_" + entry_method_id_rand,
5866      function () {
5867        var link_name = $(
5868          "#sw_" + entry_method_class + "_add_link_name_" + entry_method_id_rand
5869        ).val();
5870
5871        // Get second input for link (phone only uses one)
5872        if (link_type == "link") {
5873          var link_url = $(
5874            "#sw_" +
5875            entry_method_class +
5876            "_add_link_url_" +
5877            entry_method_id_rand
5878          ).val();
5879          var link_url = link_url.replace(/ /g, "");
5880
5881          var add_link_button = $(
5882            "input:checkbox[name=sw_" +
5883            entry_method_class +
5884            "_add_link_button_" +
5885            entry_method_id_rand +
5886            "]:checked"
5887          ).val();
5888        } else if (link_type == "copy_paste") {
5889          var link_name = $(
5890            "#sw_" +
5891            entry_method_class +
5892            "_add_copy_paste_" +
5893            entry_method_id_rand
5894          ).val();
5895
5896          var copy_paste_text = $(
5897            "#sw_" +
5898            entry_method_class +
5899            "_add_copy_paste_" +
5900            entry_method_id_rand
5901          ).val();
5902
5903          // Remove whitespace on phone number
5904        } else if (link_type == "phone") {
5905          var link_name = link_name.replace(/ /g, "");
5906          var tel_or_sms = $(
5907            "input:radio[name=sw_" +
5908            entry_method_class +
5909            "_add_link_tel_or_sms_" +
5910            entry_method_id_rand +
5911            "]:checked"
5912          ).val();
5913        }
5914
5915        // Both link and phone have link_name, only link has link_url
5916        if (link_name == "" || (link_type == "link" && link_url == "")) {
5917          Swal.fire({
5918            title: "Oops...",
5919            text: error_one,
5920            icon: "error",
5921            confirmButtonText: "OK",
5922          });
5923
5924          // Link - check for http:// https://
5925        } else if (
5926          link_type == "link" &&
5927          link_url.indexOf("http://") == -1 &&
5928          link_url.indexOf("https://") == -1
5929        ) {
5930          Swal.fire({
5931            title: "Oops...",
5932            text: error_one,
5933            icon: 'Link URL must contain start with "http://" or "https://"',
5934            confirmButtonText: "OK",
5935          });
5936        } else {
5937          if (link_type == "link") {
5938            if (add_link_button == "on") {
5939              var value = "[[~" + link_name + "~]]((" + link_url + "))";
5940            } else {
5941              var value = "[[" + link_name + "]]((" + link_url + "))";
5942            }
5943          } else if (link_type == "phone") {
5944            var value =
5945              "[[" + link_name + "]]((" + tel_or_sms + ":" + link_name + "))";
5946          } else if (link_type == "copy_paste") {
5947            var value = "{{" + copy_paste_text + "}}";
5948          }
5949
5950          var textarea_name =
5951            "textarea[name=" +
5952            entry_method_prepend +
5953            "_" +
5954            entry_method_class +
5955            "_" +
5956            entry_method_id +
5957            "]";
5958
5959          wrapLink(value, textarea_name);
5960
5961          $(
5962            "#sw_" +
5963            entry_method_class +
5964            "_add_link_modal_" +
5965            entry_method_id_rand
5966          ).hide();
5967        }
5968      }
5969    );
5970
5971    // Close modal when clicking the backdrop (outside the modal panel)
5972    var backdropId = "sw_" + entry_method_class + "_add_link_modal_" + entry_method_id_rand;
5973    document.getElementById(backdropId).addEventListener("click", function (e) {
5974      if (e.target === this) {
5975        $(this).hide();
5976      }
5977    });
5978  });
5979
5980  // Toggle entry method on click
5981  $(document.body).on("click", ".handle", function () {
5982    if (!$(this).parent().find(".entry_method_body_inner").is(":visible")) {
5983      // do this only before open/expand so as initially it will be hidden.
5984      $(this).parent().find(".entry_textarea").keyup(); // make sure to auto-adjust textarea box height for content inside on each entry toggle.
5985    }
5986
5987    var parent_id = $(this).parent().attr("id");
5988    var body_id = parent_id + "-inner";
5989
5990    $("#" + body_id).slideToggle(200);
5991
5992    // make toggling..
5993    var data_toggle = $(this).attr("data-toggle"); // expand / collapse
5994    var switch_toggle = "";
5995
5996    if (data_toggle == "expand") {
5997      switch_toggle = "collapse";
5998      $(this).css("border-radius", "10px");
5999    } else if (data_toggle) {
6000      switch_toggle = "expand";
6001      $(this).css("border-radius", "10px 10px 0px 0px");
6002    }
6003    $(this).attr("data-toggle", switch_toggle); // toggle
6004
6005    expand_minimize_checkbox_show_hide(
6006      $(this).parent().attr("data-toggle"),
6007      "toggle",
6008      switch_toggle
6009    );
6010  });
6011
6012  // Toggle on click / Required
6013  $(document.body).on(
6014    "click",
6015    'input[type="checkbox"].entry_checkbox_required',
6016    function () {
6017      // Remove the code that changes the value - checkboxes should always have value="1"
6018      // The checked state is what matters, not the value attribute
6019    }
6020  );
6021
6022  // Toggle on click / custom icon
6023  $(document.body).on(
6024    "click",
6025    'input[type="checkbox"].entry_checkbox_custom_icon',
6026    function () {
6027      var entry_method_id = $(this).attr("data-entry_method_id");
6028      var entry_method_class = $(this).attr("data-entry_method_class");
6029
6030      if ($(this).is(":checked")) {
6031        $(
6032          "#custom_icons_wrapper_" + entry_method_class + "_" + entry_method_id
6033        ).show();
6034      } else {
6035        $(
6036          "#custom_icons_wrapper_" + entry_meth
6036od_class + "_" + entry_method_id
6037        ).hide();
6038      }
6039    }
6040  );
6041
6042  // Filter custom icon search
6043  $(document.body).on("keyup", ".custom_icons_wrapper_search", function () {
6044    var entry_method_id = $(this).attr("data-entry_method_id");
6045    var entry_method_class = $(this).attr("data-entry_method_class");
6046
6047    var val = $(this).val().toLowerCase();
6048    var $wrapper = $(
6049      "#custom_icons_wrapper_inner_" +
6050      entry_method_class +
6051      "_" +
6052      entry_method_id
6053    );
6054
6055    // Hide icon grid when search is empty
6056    if (val === "") {
6057      $wrapper.hide();
6058      return;
6059    }
6060
6061    $wrapper.show();
6062
6063    $wrapper
6064      .find(".fas, .far, .fal, .fad, .fab")
6065      .filter(function () {
6066        return $(this).data("filter").toLowerCase().indexOf(val) > -1;
6067      })
6068      .show()
6069      .end()
6070      .filter(":visible")
6071      .filter(function () {
6072        return $(this).data("filter").toLowerCase().indexOf(val) === -1;
6073      })
6074      .hide();
6075  });
6076
6077  // Custom icons click on icon
6078  $(document.body).on("click", ".custom_icons_wrapper_inner i", function () {
6079    var website_plan = parseInt($("#user_website_plan").val());
6080
6081    if (
6082      plan_level("pro", "equal_or_less", website_plan, payment_platform) == true
6083    ) {
6084      Swal.fire({
6085        title: "Oops...",
6086        text: "Please upgrade to the business or or higher for custom icons.",
6087        icon: "error",
6088        confirmButtonText: "OK",
6089      });
6090    } else {
6091      var icon_class = $(this).attr("class");
6092      var entry_method_id = $(this).parent().attr("data-entry_method_id");
6093      var entry_method_class = $(this).parent().attr("data-entry_method_class");
6094
6095      $("#icon_color_icon_" + entry_method_class + "_" + entry_method_id)
6096        .hide()
6097        .html('<i class="' + icon_class + '"></i>')
6098        .fadeIn(300);
6099
6100      $(
6101        "input[name=custom_icon_" +
6102        entry_method_class +
6103        "_" +
6104        entry_method_id +
6105        "]"
6106      ).val(icon_class);
6107    }
6108  });
6109
6110  // Toggle on click / Daily
6111  $(document.body).on("click", ".entry_checkbox_daily", function () {
6112    var daily_checked_value = 0;
6113    var entry_method_full_name = $(this).attr("name");
6114    var entry_method_class = $(this).attr("data-entry_method_class");
6115    var entry_method_id = $(this).attr("data-entry_method_id");
6116
6117    if ($("input[name=" + entry_method_full_name + "]").is(":checked")) {
6118      daily_checked_value = 1;
6119      $(
6120        "#daily_select_holder_" + entry_method_class + "_" + entry_method_id
6121      ).slideDown(200); // checked
6122    } else {
6123      daily_checked_value = 0;
6124      $(
6125        "#daily_select_holder_" + entry_method_class + "_" + entry_method_id
6126      ).slideUp(200); // unchecked
6127    }
6128
6129    $(this).val(daily_checked_value);
6130  });
6131
6132  // Toggle on click / timer
6133  $(document.body).on("click", ".entry_checkbox_timer", function () {
6134    var timer_checked_value = 0;
6135    var entry_method_full_name = $(this).attr("name");
6136    var entry_method_class = $(this).attr("data-entry_method_class");
6137    var entry_method_id = $(this).attr("data-entry_method_id");
6138
6139    // Timer minutes value
6140    var timer_input_minutes = $(
6141      "#timer_input_minutes_" + entry_method_class + "_" + entry_method_id
6142    ).val();
6143
6144    // Timer seconds value
6145    var timer_input_seconds = $(
6146      "#timer_input_seconds_" + entry_method_class + "_" + entry_method_id
6147    ).val();
6148
6149    // If bother minutes and seconds are empty or set to 0, make it 30 seconds (so they don't click timer and have it set to 0)
6150    if (
6151      (timer_input_minutes == "" || timer_input_minutes == 0) &&
6152      (timer_input_seconds == "" || timer_input_seconds == 0)
6153    ) {
6154      $(
6155        "#timer_input_seconds_" + entry_method_class + "_" + entry_method_id
6156      ).val("30");
6157    }
6158
6159    if ($("input[name=" + entry_method_full_name + "]").is(":checked")) {
6160      timer_checked_value = 1;
6161      $(
6162        "#timer_select_holder_" + entry_method_class + "_" + entry_method_id
6163      ).slideDown(200); // checked
6164    } else {
6165      timer_checked_value = 0;
6166      $(
6167        "#timer_select_holder_" + entry_method_class + "_" + entry_method_id
6168      ).slideUp(200); // unchecked
6169    }
6170
6171    $(this).val(timer_checked_value);
6172  });
6173
6174  // Entry Link validation
6175  $(document.body).on("focusout", "input.entry_link", function (e) {
6176    var entry_link_validation = entry_method_fetch_values(
6177      $(this).attr("entry_method_text"),
6178      "entry_link_validation",
6179      "",
6180      "",
6181      "",
6182      "",
6183      ""
6184    );
6185    if (entry_link_validation) {
6186      if (!entry_link_validation.test($(this).val())) {
6187        $(this).css("border-color", "red");
6188        $(this).parent(".input_holder_1").find(".validation_error").show();
6189      } else {
6190        $(this).css("border-color", "#e0e0e0");
6191        $(this).parent(".input_holder_1").find(".validation_error").hide();
6192      }
6193    }
6194  });
6195
6196  // Unlock rewards sortable - update container value when dragged
6197  $("#unlock_rewards_wrapper").sortable({
6198    update: function (event, ui) {
6199      var unlock_rewards_value = $("#unlock_rewards_wrapper")
6200        .sortable("toArray")
6201        .toString();
6202      unlock_rewards_container = unlock_rewards_value
6203        .replace(/[, ]+/g, ",")
6204        .trim()
6205        .replace(/(^,)|(,$)/g, "");
6206
6207      // Remove all occurences of "unlock_rewards-"
6208      unlock_rewards_container = unlock_rewards_container.replace(
6209        /unlock_rewards-/g,
6210        ""
6211      );
6212
6213      // Set updated value in unlock_rewards_container
6214      $('input[name="unlock_rewards_container"]').val(unlock_rewards_container);
6215
6216      // // Re-initialize each tinyMCE editor when re-orders (for some reason it disables the text editor on re-order, this fixes it)
6217      // $.each(unlock_rewards_container.split(","), function (key, value) {
6218      //   tinymce.remove(
6219      //     "textarea#unlock_rewards_prize_email_body-" +
6220      //       value +
6221      //       ", textarea#unlock_rewards_coupon_email_body-" +
6222      //       value +
6223      //       ", textarea#unlock_rewards_coupon_directions-" +
6224      //       value
6225      //   );
6226
6227      //   // TinyMCE user email
6228      //   tinymce.init({
6229      //     selector:
6230      //       "textarea#unlock_rewards_prize_email_body-" +
6231      //       value +
6232      //       ", textarea#unlock_rewards_coupon_email_body-" +
6233      //       value +
6234      //       ", textarea#unlock_rewards_coupon_directions-" +
6235      //       value,
6236      //     height: 300,
6237      //     menubar: false,
6238      //     branding: false,
6239      //     convert_urls: true,
6240      //     plugins: ["autolink", "lists", "code", "emoticons", "link"],
6241      //     toolbar:
6242      //       "undo redo | styles | bold italic | link unlink | alignleft aligncenter alignright al
6242ignjustify | outdent indent | numlist bullist | emoticons",
6243      //     content_style:
6244      //       'body { font-family:"Rubik", sans-serif; font-size:15px; border-color:#c4c4c4; }',
6245      //   });
6246      // });
6247    },
6248
6249    handle: ".unlock_rewards_each_handle",
6250    snap: ".unlock_rewards_each",
6251    stack: ".unlock_rewards_each",
6252    revertDuration: 1,
6253    appendTo: "body",
6254    helper: "clone",
6255    opacity: 0.8,
6256  });
6257
6258  // Enter methods - update values when dragged
6259  $("#sortable_one, #sortable_two").sortable({
6260    update: function (event, ui) {
6261      var productOrder_1 = $("#sortable_one").sortable("toArray").toString();
6262
6263      var productOrder_2 = $("#sortable_two").sortable("toArray").toString();
6264
6265      // Entry methods l1 + l2
6266      var entry_methods_container = (productOrder_1 + "," + productOrder_2)
6267        .replace(/[, ]+/g, ",")
6268        .trim()
6269        .replace(/(^,)|(,$)/g, "");
6270
6271      // Entry methods l1
6272      var entry_methods_container_l1 = productOrder_1
6273        .replace(/[, ]+/g, ",")
6274        .trim()
6275        .replace(/(^,)|(,$)/g, "");
6276
6277      // Entry methods l2
6278      var entry_methods_container_l2 = productOrder_2
6279        .replace(/[, ]+/g, ",")
6280        .trim()
6281        .replace(/(^,)|(,$)/g, "");
6282
6283      $('input[name="entry_methods_container"]').val(entry_methods_container);
6284
6285      var entry_level = $(this).attr("id");
6286
6287      // Level 1
6288      if (entry_level == "sortable_one") {
6289        widget_builder_reorder_example(entry_methods_container);
6290        $('input[name="entry_methods_container_l1"]').val(
6291          entry_methods_container_l1
6292        );
6293      }
6294
6295      // Level 2
6296      if (entry_level == "sortable_two") {
6297        $('input[name="entry_methods_container_l2"]').val(
6298          entry_methods_container_l2
6299        );
6300      }
6301    },
6302
6303    handle: ".handle",
6304    //revert: 400,
6305    snap: ".entry_method_each",
6306    stack: ".entry_method_each",
6307    revertDuration: 1,
6308    appendTo: "body",
6309    helper: "clone",
6310    opacity: 0.8,
6311  });
6312
6313  // Unlock rewards - append new reward
6314  $("#append_reward").on('click', function () {
6315    var user_id = getCookieValue("user_login");
6316    var website_plan = parseInt($("#user_website_plan").val());
6317    var trial_demo = 0;
6318
6319    // Unlock rewards next ID
6320    var unlock_rewards_next_id = parseInt(
6321      $("input[name=unlock_rewards_next_id]").val()
6322    );
6323
6324    // If empty, make it equal 1
6325    if (unlock_rewards_next_id == "") {
6326      var unlock_rewards_next_id = 1;
6327    }
6328
6329    // Unlock rewards container
6330    var unlock_rewards_container =
6331      $('input[name="unlock_rewards_container"]').val() +
6332      ", " +
6333      unlock_rewards_next_id;
6334
6335    // Reformat unlock rewards container (clean up commas before / after string)
6336    unlock_rewards_container = unlock_rewards_container
6337      .replace(/[, ]+/g, ",")
6338      .trim()
6339      .replace(/(^,)|(,$)/g, "");
6340
6341    // Unlock rewards container - set value
6342    $('input[name="unlock_rewards_container"]').val(unlock_rewards_container);
6343
6344    var unlock_rewards_prize_email_display = unlock_rewards_email_display(
6345      website_url,
6346      unlock_rewards_next_id,
6347      1
6348    );
6349    var unlock_rewards_coupon_email_display = unlock_rewards_email_display(
6350      website_url,
6351      unlock_rewards_next_id,
6352      2
6353    );
6354
6355    // Business or less
6356    if (
6357      plan_level("business", "equal_or_less", website_plan, payment_platform) ==
6358      true
6359    ) {
6360      var premium_button_classes = "entry_method_add_disallow_premium";
6361      var disabled_premium = 'disabled="disabled"';
6362      var disabled_premium_text =
6363        '<b class="available_in_pro_plan_text paid_plan_tip">&nbsp;&bull; Premium</b>';
6364    } else {
6365      var premium_button_classes = "";
6366      var disabled_premium = "";
6367      var disabled_premium_text = "";
6368    }
6369
6370    var reward_body =
6371      '<div id="unlock_rewards-' +
6372      unlock_rewards_next_id +
6373      '" class="unlock_rewards_each" data-rewards-int="' +
6374      unlock_rewards_next_id +
6375      '">' +
6376      '<div id="unlock_rewards_each_handle-' +
6377      unlock_rewards_next_id +
6378      '" class="unlock_rewards_each_handle" data-toggle="expand" data-rewards-int="' +
6379      unlock_rewards_next_id +
6380      '">' +
6381      '<div class="handle_inner"><span class="entry_method_drag_icon max-md:hidden"><i class="fa-solid fa-bars"></i></span><span>Unlock Reward</span></div>' +
6382      "</div>" +
6383      // Delete icon
6384      '<div id="unlock_rewards_delete-' +
6385      unlock_rewards_next_id +
6386      '" class="unlock_rewards_delete" data-rewards-int="' +
6387      unlock_rewards_next_id +
6388      '">' +
6389      "Remove" +
6390      "</div>" +
6391      // Body wrapper
6392      '<div id="unlock_rewards_body_inner-' +
6393      unlock_rewards_next_id +
6394      '" class="unlock_rewards_body_inner pb-[20px]">' +
6395      // Unlock rewards type
6396      '<div class="input_holder_1">' +
6397      '<div class="w-full mb-0 float-left">' +
6398      '<div id="unlock_rewards_entries_required_header-' +
6399      unlock_rewards_next_id +
6400      '" class="w-full mt-5 mb-[15px] text-[15px] float-left">' +
6401      "What type of reward is this?" +
6402      "</div>" +
6403      "</div>" +
6404      '<div class="w-full mb-0 float-left">' +
6405      '<div class="flex items-center">' + // Ensure everything is in one row
6406      '<label class="cursor-pointer mr-[15px] flex items-center">' + // Flex to align items
6407      '<input type="radio" name="unlock_rewards_type-' +
6408      unlock_rewards_next_id +
6409      '" class="sw-radio rewards_type_radio" value="1" data-rewards-int="' +
6410      unlock_rewards_next_id +
6411      '">' +
6412      "&nbsp;<span>Prize</span>" + // Keep labels inline
6413      "</label>" +
6414      '<a href="' +
6415      website_url +
6416      '/docs/add-locked-prizes-tiered-rewards-instant-coupons#unlock-prizes-setup" target="_blank" class="mr-[30px]">' + // Add some margin for spacing
6417      '<i class="fas fa-question-circle text-[#ccc] text-sm"></i>' + // Keep the original FontAwesome icons
6418      "</a>" +
6419      '<label class="cursor-pointer mr-[15px] flex items-center">' + // Flex to align items
6420      '<input type="radio" name="unlock_rewards_type-' +
6421      unlock_rewards_next_id +
6422      '" class="sw-radio rewards_type_radio" value="2" data-rewards-int="' +
6423      unlock_rewards_next_id +
6424      '">' +
6425      "&nbsp;<span>Coupon</span>" + // Keep labels inline
6426      "</label>" +
6427      '<a href="' +
6428      website_url +
6429      '/docs/add-locked-prizes-tiered-rewards-instant-coupons#instant-coupons-setup" target="_blank">' +
6430      '<i class="fas fa-question-circle text-[#ccc] text-sm"></i>' + // Keep the original FontAwesome icons
6431      "</a>" +
6432      "</div>" +
6433      "</div>" +
6434      "</div>" +
6435      // Unlock rewards entries required
6436      '<div class="input_holder_1">' +
6437      '<div id="unlock_rewards_entries_required_header-' +
6438      unlock_rewards_next_id +
6439      '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
6440      "Required entries #" +
6441      "</div>" +
6442      '<input type="text" name="unlock_rewards_entries_required-' +
6443      unlock_rewards_next_id +
6444      '" class="entry_input"  value="5" maxlength="255" data-rewards-int="' +
6445      unlock_rewards_next_id +
6446      '">' +
6447      '<div class="sw_entry_method_handle_hint"><strong>How many entries are required to unlock this reward?</strong></div>' +
6448      "</div>" +
6449      // PRIZE
6450
6451      // Unlock rewards prize wrapper
6452      '<div id="unlock_prize_wrapper-' +
6453      unlock_rewards_next_id +
6454      '" class="input_holder_full mt-[20px] mb-[20px] hidden border-t border-[#eee]">' +
6455      // Unlock rewards prize name
6456      '<div class="input_holder_1">' +
6457      '<div id="unlock_rewards_prize_name_header-' +
6458      unlock_rewards_next_id +
6459      '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
6460      "Name of prize" +
6461      "</div>" +
6462      '<input type="text" name="unlock_rewards_prize_name-' +
6463      unlock_rewards_next_id +
6464      '" class="entry_input"  value="" maxlength="255" data-rewards-int="' +
6465      unlock_rewards_next_id +
6466      '">' +
6467      '<div class="sw_entry_method_handle_hint"><strong>The name of the prize that you are giving away</strong></div>' +
6468      "</div>" +
6469      // Unlock rewards prize random or guaranteed
6470      '<div class="input_holder_1">' +
6471      '<div id="unlock_rewards_prize_random_or_guaranteed_header-' +
6472      unlock_rewards_next_id +
6473      '" class="w-full mt-5 mb-[15px] text-[15px] float-left">' +
6474      "Is this a random draw or a guaranteed prize?" +
6475      "</div>" +
6476      '<label class="cursor-pointer">' +
6477      '<input type="radio" name="unlock_rewards_prize_random_or_guaranteed-' +
6478      unlock_rewards_next_id +
6479      '" class="sw-radio" value="1" data-rewards-int="' +
6480      unlock_rewards_next_id +
6481      '" checked="1">' +
6482      "<span>Random draw</span>" +
6483      "</label>" +
6484      "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
6485      '<label class="cursor-pointer">' +
6486      '<input type="radio" name="unlock_rewards_prize_random_or_guaranteed-' +
6487      unlock_rewards_next_id +
6488      '" class="sw-radio" value="2" data-rewards-int="' +
6489      unlock_rewards_next_id +
6490      '">' +
6491      "<span>Guaranteed</span>" +
6492      "</label>" +
6493      "</div>" +
6494      // Instant win odds (prize)
6495      '<div class="unlock_rewards_instant_win_odds_wrapper-' + unlock_rewards_next_id + '" style="display:none;clear:both;padding:15px 0;">' +
6496      '<label style="display:block;font-size:15px;margin-bottom:8px;">Instant win chance</label>' +
6497      '<select name="unlock_rewards_prize_instant_win_odds-' + unlock_rewards_next_id + '" class="builder_input sw_instant_win_odds_select" style="width:auto;
6497min-width:200px;" data-rewards-int="' + unlock_rewards_next_id + '">' +
6498      '<option value="0">No instant win popup</option>' +
6499      '<option value="100">Everyone wins</option>' +
6500      '<option value="50">1 in 2 chance (50%)</option>' +
6501      '<option value="33">1 in 3 chance (33%)</option>' +
6502      '<option value="25">1 in 4 chance (25%)</option>' +
6503      '<option value="20">1 in 5 chance (20%)</option>' +
6504      '<option value="10">1 in 10 chance (10%)</option>' +
6505      '<option value="5">1 in 20 chance (5%)</option>' +
6506      '<option value="1">1 in 100 chance (1%)</option>' +
6507      '<option value="custom">Custom</option>' +
6508      '</select>' +
6509      '<input type="number" class="builder_input sw_instant_win_odds_custom" style="width:80px;display:none;margin-left:10px;vertical-align:middle;" min="1" max="100" placeholder="%" data-rewards-int="' + unlock_rewards_next_id + '" />' +
6510      '</div>' +
6511      // Unlock rewards prize if send email
6512      '<div class="input_holder_full">' +
6513      '<div id="unlock_rewards_prize_send_email_header-' +
6514      unlock_rewards_next_id +
6515      '" class="w-full mt-[30px] mb-[15px] text-[15px] float-left">' +
6516      "Automatically email the user when they unlock this reward&nbsp;&nbsp;" +
6517      '<a href="' +
6518      website_url +
6519      '/docs/add-locked-prizes-tiered-rewards-instant-coupons#unlock-prizes-email" target="_blank">' +
6520      '<i class="fas fa-question-circle text-[#ccc] text-sm"></i>' +
6521      "</a>" +
6522      "</div>" +
6523      '<label class="cursor-pointer">' +
6524      '<input type="radio" name="unlock_rewards_prize_send_email-' +
6525      unlock_rewards_next_id +
6526      '" class="sw-radio unlock_rewards_if_send_email" value="1" checked="1" data-rewards-int="' +
6527      unlock_rewards_next_id +
6528      '" data-type="prize">' +
6529      "<span>No</span>" +
6530      "</label>" +
6531      "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
6532      '<label class="cursor-pointer">' +
6533      '<input type="radio" name="unlock_rewards_prize_send_email-' +
6534      unlock_rewards_next_id +
6535      '" class="sw-radio unlock_rewards_if_send_email" value="2" data-rewards-int="' +
6536      unlock_rewards_next_id +
6537      '" data-type="prize">' +
6538      "<span>Default email</span>" +
6539      "</label>" +
6540      "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
6541      '<label class="' +
6542      premium_button_classes +
6543      ' cursor-pointer">' +
6544      '<input type="radio" name="unlock_rewards_prize_send_email-' +
6545      unlock_rewards_next_id +
6546      '" class="sw-radio unlock_rewards_if_send_email" value="3" data-rewards-int="' +
6547      unlock_rewards_next_id +
6548      '" data-type="prize" ' +
6549      disabled_premium +
6550      ">" +
6551      "<span>Custom email</span>" +
6552      " + logo &nbsp;" +
6553      disabled_premium_text +
6554      "</label>" +
6555      "</div>" +
6556      unlock_rewards_prize_email_display +
6557      "</div>" +
6558      // COUPON
6559
6560      // Unlock rewards coupon wrapper
6561      '<div id="unlock_coupon_wrapper-' +
6562      unlock_rewards_next_id +
6563      '" class="input_holder_full mt-[20px] mb-[20px] hidden border-t border-[#eee]">' +
6564      '<div class="w-full float-left">' +
6565      // Unlock rewards coupon name
6566      '<div class="input_holder_1">' +
6567      '<div id="unlock_rewards_coupon_name_header-' +
6568      unlock_rewards_next_id +
6569      '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
6570      "Name of coupon" +
6571      "</div>" +
6572      '<input type="text" name="unlock_rewards_coupon_name-' +
6573      unlock_rewards_next_id +
6574      '" class="entry_input"  value="" maxlength="255" data-rewards-int="' +
6575      unlock_rewards_next_id +
6576      '" />' +
6577      '<div class="sw_entry_method_handle_hint"><strong>The name of the coupon that you are giving away</strong></div>' +
6578      "</div>" +
6579      "</div>" +
6580      '<div class="w-full float-left">' +
6581      // Unlock rewards if coupon code
6582      '<div class="input_holder_1">' +
6583      '<div id="unlock_rewards_coupon_random_or_guaranteed_header-' +
6584      unlock_rewards_next_id +
6585      '" class="w-full mt-5 mb-[15px] text-[15px] float-left">' +
6586      "Is there a coupon code?" +
6587      "</div>" +
6588      '<label class="cursor-pointer">' +
6589      '<input type="radio" name="unlock_rewards_coupon_if_coupon_code-' +
6590      unlock_rewards_next_id +
6591      '" class="sw-radio unlock_rewards_coupon_if_coupon_code" value="1" data-rewards-int="' +
6592      unlock_rewards_next_id +
6593      '" checked="1">' +
6594      "<span>Yes</span>" +
6595      "</label>" +
6596      "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
6597      '<label class="cursor-pointer">' +
6598      '<input type="radio" name="unlock_rewards_coupon_if_coupon_code-' +
6599      unlock_rewards_next_id +
6600      '" class="sw-radio unlock_rewards_coupon_if_coupon_code" value="2" data-rewards-int="' +
6601      unlock_rewards_next_id +
6602      '">' +
6603      "<span>No code required</span>" +
6604      "</label>" +
6605      "</div>" +
6606      // Unlock rewards coupon code
6607      '<div id="unlock_rewards_coupon_code_wrapper-' +
6608      unlock_rewards_next_id +
6609      '" class="input_holder_full">' +
6610      '<div id="unlock_rewards_coupon_code_header-' +
6611      unlock_rewards_next_id +
6612      '" class="w-full mt-5 mb-[5px] text-[15px] float-left">' +
6613      "Coupon code/s (1 per line)&nbsp;&nbsp;" +
6614      '<a href="' +
6615      website_url +
6616      '/docs/add-locked-prizes-tiered-rewards-instant-coupons#instant-coupons-setup" target="_blank">' +
6617      '<i class="fas fa-question-circle text-[#ccc] text-sm"></i>' +
6618      "</a>" +
6619      "</div>" +
6620      '<div class="w-full float-left">' +
6621      '<textarea name="unlock_rewards_coupon_code-' +
6622      unlock_rewards_next_id +
6623      '" maxlength="1000000" class="sw-textarea" style="min-height:120px;" value="" data-rewards-int="' +
6624      unlock_rewards_next_id +
6625      '" placeholder="1 per line...">' +
6626      "</textarea>" +
6627      "</div>" +
6628      '<div class="sw_entry_method_handle_hint">If you add multiple coupons, the amount of coupon recipients will be limited to how many coupons you add. i.e. if you add 5 coupons, only 5 people can win it. Conversely, if you add only 1 coupon, unlimited people can win it.</div>' +
6629      "</div>" +
6630      "</div>" +
6631      '<div class="input_holder_full">' +
6632      // Unlock rewards coupon directions
6633      '<div id="unlock_rewards_coupon_directions_header-' +
6634      unlock_rewards_next_id +
6635      '" style="width:100%;margin-top:25px;margin-bottom:7px;font-size:15px;color:#444;float:left;">' +
6636      "Additional directions (optional)" +
6637      "</div>" +
6638      '<div class="w-full float-left">' +
6639      '<textarea class="sw-textarea" id="unlock_rewards_coupon_directions-' +
6640      unlock_rewards_next_id +
6641      '" name="unlock_rewards_coupon_directions-' +
6642      unlock_rewards_next_id +
6643      '" class="entry_input" maxlength="1000" data-rewards-int="' +
6644      unlock_rewards_next_id +
6645      '">' +
6646      "</div>" +
6647      "</textarea>" +
6648      '<div class="sw_entry_method_handle_hint"><strong>List any directions / steps the user must do to retrieve their coupon</strong></div>' +
6649      "</div>" +
6650      '<div class="input_holder_full mb-[20px]">' +
6651      // Unlock rewards hide progress bar
6652      '<div id="unlock_rewards_hide_progress_header-' +
6653      unlock_rewards_next_id +
6654      '" class="relative my-4">' +
6655      '<label for="unlock_rewards_hide_progress-' +
6656      unlock_rewards_next_id +
6657      '" class="cursor-pointer flex items-center">' +
6658      '<input type="checkbox" class="sw-checkbox" name="unlock_rewards_hide_progress-' +
6659      unlock_rewards_next_id +
6660      '" id="unlock_rewards_hide_progress-' +
6661      unlock_rewards_next_id +
6662      '" />' +
6663      "<span>Hide progress bar?</span>" +
6664      "</label>" +
6665      "</div>" +
6666      "</div>" +
6667      // Instant win odds (coupon)
6668      '<div class="unlock_rewards_instant_win_odds_wrapper-' + unlock_rewards_next_id + '" style="clear:both;padding:15px 0;">' +
6669      '<label style="display:block;font-size:15px;margin-bottom:8px;">Instant win chance</label>' +
6670      '<select name="unlock_rewards_coupon_instant_win_odds-' + unlock_rewards_next_id + '" class="builder_input sw_instant_win_odds_select" style="width:auto;
6670min-width:200px;" data-rewards-int="' + unlock_rewards_next_id + '">' +
6671      '<option value="0">No instant win popup</option>' +
6672      '<option value="100">Everyone wins</option>' +
6673      '<option value="50">1 in 2 chance (50%)</option>' +
6674      '<option value="33">1 in 3 chance (33%)</option>' +
6675      '<option value="25">1 in 4 chance (25%)</option>' +
6676      '<option value="20">1 in 5 chance (20%)</option>' +
6677      '<option value="10">1 in 10 chance (10%)</option>' +
6678      '<option value="5">1 in 20 chance (5%)</option>' +
6679      '<option value="1">1 in 100 chance (1%)</option>' +
6680      '<option value="custom">Custom</option>' +
6681      '</select>' +
6682      '<input type="number" class="builder_input sw_instant_win_odds_custom" style="width:80px;display:none;margin-left:10px;vertical-align:middle;" min="1" max="100" placeholder="%" data-rewards-int="' + unlock_rewards_next_id + '" />' +
6683      '</div>' +
6684      // Unlock rewards coupon if send email
6685      '<div class="input_holder_full">' +
6686      '<div id="unlock_rewards_coupon_send_email_header-' +
6687      unlock_rewards_next_id +
6688      '" class="w-full mt-[30px] mb-[15px] text-[15px] float-left">' +
6689      "Automatically email the user when they unlock this coupon&nbsp;&nbsp;" +
6690      '<a href="' +
6691      website_url +
6692      '/docs/add-locked-prizes-tiered-rewards-instant-coupons#instant-coupons-email" target="_blank">' +
6693      '<i class="fas fa-question-circle text-[#ccc] text-sm"></i>' +
6694      "</a>" +
6695      "</div>" +
6696      '<label class="cursor-pointer">' +
6697      '<input type="radio" name="unlock_rewards_coupon_send_email-' +
6698      unlock_rewards_next_id +
6699      '" class="sw-radio unlock_rewards_if_send_email" value="1" checked="1" data-rewards-int="' +
6700      unlock_rewards_next_id +
6701      '" data-type="coupon">' +
6702      "<span>No</span>" +
6703      "</label>" +
6704      "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
6705      '<label class="cursor-pointer">' +
6706      '<input type="radio" name="unlock_rewards_coupon_send_email-' +
6707      unlock_rewards_next_id +
6708      '" class="sw-radio unlock_rewards_if_send_email" value="2" data-rewards-int="' +
6709      unlock_rewards_next_id +
6710      '" data-type="coupon">' +
6711      "<span>Default email</span>" +
6712      "</label>" +
6713      "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
6714      '<label class="' +
6715      premium_button_classes +
6716      ' cursor-pointer">' +
6717      '<input type="radio" name="unlock_rewards_coupon_send_email-' +
6718      unlock_rewards_next_id +
6719      '" class="sw-radio unlock_rewards_if_send_email" value="3" data-rewards-int="' +
6720      unlock_rewards_next_id +
6721      '" data-type="coupon" ' +
6722      disabled_premium +
6723      ">" +
6724      "<span>Custom email</span>" +
6725      " + logo &nbsp;" +
6726      disabled_premium_text +
6727      "</label>" +
6728      "</div>" +
6729      unlock_rewards_coupon_email_display +
6730      "</div>" +
6731      '<div id="unlock_rewards_error_box-' +
6732      unlock_rewards_next_id +
6733      '" class="entry_method_error_box">' +
6734      "</div>" +
6735      "</div>" +
6736      "</div>";
6737
6738    $("#unlock_rewards_wrapper").append(reward_body);
6739
6740    var editors_ids_array = [
6741      "unlock_rewards_prize_email_body-" + unlock_rewards_next_id,
6742      "unlock_rewards_coupon_email_body-" + unlock_rewards_next_id,
6743      "unlock_rewards_coupon_directions-" + unlock_rewards_next_id,
6744    ];
6745
6746    // Initialize TinyMCE editors
6747    for (var i = 0; i < editors_ids_array.length; i++) {
6748      (function(eid) {
6749        sw_init_tinymce('#' + eid, {
6750          toolbar: 'bold italic | link | bullist numlist',
6751          height: 160
6752        });
6753      })(editors_ids_array[i]);
6754    }
6755
6756    // // TinyMCE user email
6757    // tinymce.init({
6758    //   selector:
6759    //     "textarea#unlock_rewards_prize_email_body-" +
6760    //     unlock_rewards_next_id +
6761    //     ", textarea#unlock_rewards_coupon_email_body-" +
6762    //     unlock_rewards_next_id +
6763    //     ", textarea#unlock_rewards_coupon_directions-" +
6764    //     unlock_rewards_next_id,
6765    //   height: 300,
6766    //   menubar: false,
6767    //   branding: false,
6768    //   convert_urls: true,
6769    //   plugins: ["autolink", "lists", "code", "emoticons", "link"],
6770    //   toolbar:
6771    //     "undo redo | styles | bold italic | link unlink | alignleft aligncenter alignright al
6771ignjustify | outdent indent | numlist bullist | emoticons",
6772    //   content_style:
6773    //     'body { font-family:"Rubik", sans-serif; font-size:15px; border-color:#c4c4c4; }',
6774    // });
6775
6776    // Unlock rewards next ID + 1
6777    unlock_rewards_next_id_next = unlock_rewards_next_id + 1;
6778
6779    // Unlock rewards next ID - set value
6780    $("input[name=unlock_rewards_next_id]").val(unlock_rewards_next_id_next);
6781  });
6782
6783  // Unlock rewards change email image loc
6784  $(document.body).on(
6785    "change",
6786    ".unlock_rewards_email_logo_image_loc_input",
6787    function () {
6788      // Get reward type (prize / coupon)
6789      var unlock_rewards_type_text = $(this).attr("data-type");
6790      var unlock_rewards_next_id = $(this).attr("data-rewards-int");
6791
6792      // Update the image preview display
6793      readURL_dynamic(this, unlock_rewards_type_text, unlock_rewards_next_id);
6794    }
6795  );
6796
6797  // Instant win odds dropdown — show/hide custom input and sync value
6798  $(document.body).on("change", ".sw_instant_win_odds_select", function () {
6799    var val = $(this).val();
6800    var rewardInt = $(this).attr("data-rewards-int");
6801    var customInput = $(this).siblings(".sw_instant_win_odds_custom");
6802    if (val === "custom") {
6803      customInput.show().focus();
6804    } else {
6805      customInput.hide().val("");
6806    }
6807  });
6808
6809  // Custom odds input — update the select value on form submit
6810  $(document.body).on("change", ".sw_instant_win_odds_custom", function () {
6811    var val = parseInt($(this).val()) || 0;
6812    if (val < 1) val = 1;
6813    if (val > 100) val = 100;
6814    $(this).val(val);
6815    // Add a custom option to the select with this value
6816    var select = $(this).siblings(".sw_instant_win_odds_select");
6817    select.find("option[value='custom']").val(val).text("Custom (" + val + "%)");
6818  });
6819
6820  // Unlock rewards, show / hide instant win odds when random/guaranteed changes
6821  $(document.body).on("change", "input[name^='unlock_rewards_prize_random_or_guaranteed-']", function () {
6822    var reward_int = $(this).attr("data-rewards-int");
6823    var value = $(this).val();
6824    if (value == "1") {
6825      $(".unlock_rewards_instant_win_odds_wrapper-" + reward_int).show();
6826    } else {
6827      $(".unlock_rewards_instant_win_odds_wrapper-" + reward_int).hide();
6828    }
6829  });
6830
6831  // Unlock rewards, show / hide email radio buttons
6832  $(document.body).on("click", ".unlock_rewards_if_send_email", function () {
6833    var value = $(this).val();
6834    var reward_int = $(this).attr("data-rewards-int");
6835    var unlock_rewards_type_text = $(this).attr("data-type");
6836
6837    // No
6838    if (value == 1) {
6839      $(
6840        "#unlock_rewards_email_" +
6841        unlock_rewards_type_text +
6842        "_default-" +
6843        reward_int
6844      ).hide();
6845      $(
6846        "#unlock_rewards_email_" +
6847        unlock_rewards_type_text +
6848        "_custom-" +
6849        reward_int
6850      ).hide();
6851
6852      // Default
6853    } else if (value == 2) {
6854      $(
6855        "#unlock_rewards_email_" +
6856        unlock_rewards_type_text +
6857        "_default-" +
6858        reward_int
6859      ).show();
6860      $(
6861        "#unlock_rewards_email_" +
6862        unlock_rewards_type_text +
6863        "_custom-" +
6864        reward_int
6865      ).hide();
6866
6867      // Custom
6868    } else if (value == 3) {
6869      $(
6870        "#unlock_rewards_email_" +
6871        unlock_rewards_type_text +
6872        "_default-" +
6873        reward_int
6874      ).hide();
6875      $(
6876        "#unlock_rewards_email_" +
6877        unlock_rewards_type_text +
6878        "_custom-" +
6879        reward_int
6880      ).show();
6881    }
6882  });
6883
6884  // Unlock rewards, prize or coupon click
6885  $(document.body).on("click", ".unlock_rewards_each_handle", function () {
6886    var reward_int = $(this).attr("data-rewards-int");
6887
6888    $("#unlock_rewards_body_inner-" + reward_int).slideToggle(200);
6889  });
6890
6891  // Unlock rewards, prize or coupon click
6892  $(document.body).on("click", ".unlock_rewards_delete", function () {
6893    var reward_int = $(this).attr("data-rewards-int");
6894
6895    $("#unlock_rewards-" + reward_int).remove();
6896
6897    var unlock_rewards_container = $(
6898      'input[name="unlock_rewards_container"]'
6899    ).val();
6900    var unlock_rewards_container_updated = unlock_rewards_container.replace(
6901      reward_int,
6902      ""
6903    );
6904    var unlock_rewards_container_updated =
6905      unlock_rewards_container_updated.replace(",,", ",");
6906    var unlock_rewards_container_updated =
6907      unlock_rewards_container_updated.replace(/^,|,$/g, "");
6908    $('input[name="unlock_rewards_container"]').val(
6909      unlock_rewards_container_updated
6910    );
6911  });
6912
6913  // Unlock rewards, prize or coupon click
6914  $(document.body).on("click", ".rewards_type_radio", function () {
6915    var value = $(this).val();
6916    var reward_int = $(this).attr("data-rewards-int");
6917
6918    if (value == 1) {
6919      $("#unlock_prize_wrapper-" + reward_int).show();
6920      $("#unlock_coupon_wrapper-" + reward_int).hide();
6921    } else if (value == 2) {
6922      $("#unlock_prize_wrapper-" + reward_int).hide();
6923      $("#unlock_coupon_wrapper-" + reward_int).show();
6924    }
6925  });
6926
6927  $(document.body).on(
6928    "click",
6929    ".unlock_rewards_coupon_if_coupon_code",
6930    function () {
6931      var value = $(this).val();
6932      var reward_int = $(this).attr("data-rewards-int");
6933
6934      if (value == 1) {
6935        $("#unlock_rewards_coupon_code_wrapper-" + reward_int).show();
6936      } else if (value == 2) {
6937        $("#unlock_rewards_coupon_code_wrapper-" + reward_int).hide();
6938      }
6939    }
6940  );
6941
6942  // Toggle viral share award bonus entries
6943  $(document.body).on(
6944    "change",
6945    ".entry_checkbox_if_viral_share_award_bonus_entries",
6946    function () {
6947      var entry_method_id = $(this).attr("data-entry_method_id");
6948      var entry_method_class = $(this).attr("data-entry_method_class");
6949
6950      if ($(this).is(":checked")) {
6951        $(
6952          "#viral_share_award_bonus_entries_amount_holder_" +
6953          entry_method_class +
6954          "_" +
6955          entry_method_id
6956        ).show();
6957      } else {
6958        $(
6959          "#viral_share_award_bonus_entries_amount_holder_" +
6960          entry_method_class +
6961          "_" +
6962          entry_method_id
6963        ).hide();
6964      }
6965    }
6966  );
6967
6968  // Toggle viral share max allowed referrals
6969  $(document.body).on(
6970    "change",
6971    ".entry_checkbox_if_viral_share_max_allowed_referrals",
6972    function () {
6973      var entry_method_id = $(this).attr("data-entry_method_id");
6974      var entry_method_class = $(this).attr("data-entry_method_class");
6975
6976      if ($(this).is(":checked")) {
6977        $(
6978          "#viral_share_max_allowed_referrals_amount_holder_" +
6979          entry_method_class +
6980          "_" +
6981          entry_method_id
6982        ).show();
6983      } else {
6984        $(
6985          "#viral_share_max_allowed_referrals_amount_holder_" +
6986          entry_method_class +
6987          "_" +
6988          entry_method_id
6989        ).hide();
6990      }
6991    }
6992  );
6993
6994  // Toggle only reward referral if earns X amount of entries
6995  $(document.body).on(
6996    "change",
6997    ".entry_checkbox_only_give_credit_after_friend_earns_entries",
6998    function () {
6999      var entry_method_id = $(this).attr("data-entry_method_id");
7000      var entry_method_class = $(this).attr("data-entry_method_class");
7001
7002      if ($(this).is(":checked")) {
7003        $(
7004          "#friend_required_entry_amount_holder_" +
7005          entry_method_class +
7006          "_" +
7007          entry_method_id
7008        ).show();
7009      } else {
7010        $(
7011          "#friend_required_entry_amount_holder_" +
7012          entry_method_class +
7013          "_" +
7014          entry_method_id
7015        ).hide();
7016      }
7017    }
7018  );
7019
7020  // Toggle required actions until unlock checkbox
7021  $(document.body).on(
7022    "click",
7023    ".required_actions_until_unlock_checkbox",
7024    function () {
7025      var entry_method_class = $(this).attr("data-entry_method_class");
7026      var entry_method_id = $(this).attr("data-entry_method_id");
7027
7028      // Show / hide required_actions_until_unlock_amount_wrapper
7029      // Only allow required or required_actions_until_unlock_amount_wrapper to be ticked (untick the other)
7030      if ($(this).is(":checked")) {
7031        $(
7032          "#required_actions_until_unlock_amount_wrapper_" +
7033          entry_method_class +
7034          "_" +
7035          entry_method_id
7036        ).show();
7037        $(
7038          "input[name=required_" +
7039          entry_method_class +
7040          "_" +
7041          entry_method_id +
7042          "]"
7043        ).prop("checked", false);
7044
7045        // If refer_friends
7046        // Force display refer_friends below with additional entry methods
7047        if (entry_method_class == "refer_friends") {
7048          $(
7049            "input[name=widget_display_" +
7050            entry_method_class +
7051            "_" +
7052            entry_method_id +
7053            "][value=1]"
7054          ).prop("checked", true);
7055        }
7056      } else {
7057        $(
7058          "#required_actions_until_unlock_amount_wrapper_" +
7059          entry_method_class +
7060          "_" +
7061          entry_method_id
7062        ).hide();
7063      }
7064    }
7065  );
7066
7067  // Show/hide advanced entry method custominations
7068  $(document.body).on(
7069    "click",
7070    'input[type="checkbox"].more_options_checkbox',
7071    function () {
7072      var id = $(this).attr("data-id");
7073      var entry_method_class = $(this).attr("data-entry_method_class");
7074
7075      if (this.checked) {
7076        $("#verify_wrapper_" + entry_method_class + "-" + id).show();
7077      } else {
7078        $("#verify_wrapper_" + entry_method_class + "-" + id).hide();
7079      }
7080    }
7081  );
7082
7083  // Only allow required or required_actions_until_unlock_amount_wrapper to be ticked (untick the other)
7084  $(document.body).on("click", ".entry_checkbox_required", function () {
7085    var entry_method_class = $(this).attr("data-entry_method_class");
7086    var entry_method_id = $(this).attr("data-entry_method_id");
7087
7088    // Show / hide required_actions_until_unlock_amount_wrapper
7089    if ($(this).is(":checked")) {
7090      $(
7091        "input[name=required_actions_until_unlock_checkbox_" +
7092        entry_method_class +
7093        "_" +
7094        entry_method_id +
7095        "]"
7096      ).prop("checked", false);
7097      $(
7098        "#required_actions_until_unlock_amount_wrapper_" +
7099        entry_method_class +
7100        "_" +
7101        entry_method_id
7102      ).hide();
7103    }
7104  });
7105
7106  // Twitter Tweet - initialize sortable for all wildcard entry groups
7107  // This happens on update widget if there's already an entry group
7108  if (is_update_widget == true) {
7109    var type = "wildcard";
7110    sortable_entry_group(type);
7111  }
7112
7113  // Populate widget builder example on "build-" page
7114  widget_builder_reorder_example($("#entry_methods_container").val());
7115
7116  // Geo-targeting multi-select picker
7117  (function () {
7118    var checkbox = document.getElementById('geo_targeting_checkbox');
7119    var wrapper = document.getElementById('geo_targeting_wrapper');
7120    var searchInput = document.getElementById('geo_country_search');
7121    var dropdown = document.getElementById('geo_country_dropdown');
7122    var pillsContainer = document.getElementById('geo_selected_pills');
7123    var statesWrapper = document.getElementById('geo_states_wrapper');
7124
7125    if (!checkbox || !searchInput) return;
7126
7127    // State: selected country codes and state selections
7128    var selectedCountries = [];
7129    var selectedStates = {}; // { "US": ["CA","NY"], ... } - empty array = all states
7130
7131    // Initialize from hidden field values
7132    var initIso = (document.getElementById('geo_countries_iso') || {}).value || '';
7133    var initStatesJson = (document.getElementById('geo_states') || {}).value || '';
7134    if (initIso) {
7135      selectedCountries = initIso.split(',').map(function(c) { return c.trim(); }
7135).filter(Boolean);
7136    }
7137    if (initStatesJson) {
7138      try { selectedStates = JSON.parse(initStatesJson); } catch(e) {}
7139    }
7140
7141    // Toggle wrapper visibility
7142    checkbox.addEventListener('change', function () {
7143      wrapper.style.display = this.checked ? '' : 'none';
7144      syncHiddenFields();
7145    });
7146
7147    // Radio buttons for allow/block
7148    $(document).on('change', 'input[name="geo_mode_radio"]', function () {
7149      syncHiddenFields();
7150    });
7151
7152    // Search input - show/filter dropdown
7153    searchInput.addEventListener('input', function () {
7154      var term = this.value.toLowerCase();
7155      if (term.length === 0) { dropdown.style.display = 'none'; return; }
7156      var matches = GEO_COUNTRIES.filter(function (c) {
7157        return c.name.toLowerCase().indexOf(term) !== -1 && selectedCountries.indexOf(c.code) === -1;
7158      });
7159      if (matches.length === 0) { dropdown.style.display = 'none'; return; }
7160      dropdown.innerHTML = '';
7161      matches.slice(0, 12).forEach(function (c) {
7162        var div = document.createElement('div');
7163        div.textContent = c.name;
7164        div.className = 'px-3 py-1.5 cursor-pointer hover:bg-gray-100 text-[14px]';
7165        div.setAttribute('data-code', c.code);
7166        div.addEventListener('mousedown', function (e) {
7167          e.preventDefault();
7168          addCountry(c.code);
7169          searchInput.value = '';
7170          dropdown.style.display = 'none';
7171        });
7172        dropdown.appendChild(div);
7173      });
7174      dropdown.style.display = 'block';
7175    });
7176
7177    searchInput.addEventListener('blur', function () {
7178      setTimeout(function () { dropdown.style.display = 'none'; }, 200);
7179    });
7180
7181    searchInput.addEventListener('focus', function () {
7182      if (this.value.length > 0) {
7183        this.dispatchEvent(new Event('input'));
7184      }
7185    });
7186
7187    function addCountry(code) {
7188      if (selectedCountries.indexOf(code) !== -1) return;
7189      selectedCountries.push(code);
7190      renderPills();
7191      renderStates(code);
7192      syncHiddenFields();
7193    }
7194
7195    function removeCountry(code) {
7196      selectedCountries = selectedCountries.filter(function(c) { return c !== code; });
7197      delete selectedStates[code];
7198      renderPills();
7199      // Remove state section
7200      var stateSection = document.getElementById('geo_state_section_' + code);
7201      if (stateSection) stateSection.remove();
7202      syncHiddenFields();
7203    }
7204
7205    function renderPills() {
7206      pillsContainer.innerHTML = '';
7207      selectedCountries.forEach(function (code) {
7208        var name = ISO_TO_NAME[code] || code;
7209        var pill = document.createElement('span');
7210        pill.className = 'inline-flex items-center gap-1 px-2 py-0.5 bg-blue-50 text-blue-700 text-[13px] rounded-md border border-blue-200';
7211        pill.innerHTML = '<span>' + name + '</span><button type="button" class="ml-0.5 text-blue-400 hover:text-blue-700 font-bold text-[14px] leading-none" data-code="' + code + '">&times;</button>';
7212        pill.querySelector('button').addEventListener('click', function () {
7213          removeCountry(code);
7214        });
7215        pillsContainer.appendChild(pill);
7216      });
7217    }
7218
7219    function renderStates(code) {
7220      if (GEO_STATE_COUNTRIES.indexOf(code) === -1 || !GEO_STATES[code]) return;
7221      var states = GEO_STATES[code];
7222      var countryName = ISO_TO_NAME[code] || code;
7223
7224      var section = document.createElement('div');
7225      section.id = 'geo_state_section_' + code;
7226      section.className = 'mb-3 border border-gray-200 rounded-md p-3';
7227
7228      var header = '<div class="flex items-center gap-3 mb-2">' +
7229        '<span class="text-[13px] font-medium text-gray-700">' + countryName + ' - States/Provinces</span>' +
7230        '<label class="flex items-center gap-1 cursor-pointer m-0"><input type="checkbox" class="sw-checkbox geo-select-all-states" data-country="' + code + '" checked /><span class="text-[12px] text-gray-500">All</span></label>' +
7231        '</div>';
7232
7233      var stateSearch = '<div class="mb-3"><input type="text" class="sw-input w-full text-[12px] geo-state-search" data-country="' + code + '" placeholder="Search states/provinces..." autocomplete="off" /></div>';
7234
7235      var checkboxes = '<div class="flex flex-wrap gap-x-4 gap-y-2 geo-state-list" data-country="' + code + '">';
7236      states.forEach(function (s) {
7237        var isChecked = !selectedStates[code] || selectedStates[code].length === 0 || selectedStates[code].indexOf(s.code) !== -1;
7238        checkboxes += '<label class="flex items-center gap-1 cursor-pointer m-0 w-[180px] geo-state-item" data-name="' + s.name.toLowerCase() + '">' +
7239          '<input type="checkbox" class="sw-checkbox geo-state-cb" data-country="' + code + '" data-state="' + s.code + '"' + (isChecked ? ' checked' : '') + ' />' +
7240          '<span class="text-[12px]">' + s.name + '</span></label>';
7241      });
7242      checkboxes += '</div>';
7243
7244      section.innerHTML = header + stateSearch + checkboxes;
7245      statesWrapper.appendChild(section);
7246    }
7247
7248    // Select all / deselect all states
7249    $(document).on('change', '.geo-select-all-states', function () {
7250      var cc = $(this).data('country');
7251      var checked = this.checked;
7252      $('#geo_state_section_' + cc + ' .geo-state-cb').prop('checked', checked);
7253      syncHiddenFields();
7254    });
7255
7256    // Individual state checkbox change
7257    $(document).on('change', '.geo-state-cb', function () {
7258      var cc = $(this).data('country');
7259      var allChecked = $('#geo_state_section_' + cc + ' .geo-state-cb:not(:checked)').length === 0;
7260      $('#geo_state_section_' + cc + ' .geo-select-all-states').prop('checked', allChecked);
7261      syncHiddenFields();
7262    });
7263
7264    // State search filter
7265    $(document).on('input', '.geo-state-search', function () {
7266      var query = this.value.toLowerCase();
7267      var cc = $(this).data('country');
7268      $('.geo-state-list[data-country="' + cc + '"] .geo-state-item').each(function () {
7269        this.style.display = this.getAttribute('data-name').indexOf(query) !== -1 ? '' : 'none';
7270      });
7271    });
7272
7273    function syncHiddenFields() {
7274      var isEnabled = checkbox.checked;
7275      var mode = isEnabled ? ($('input[name="geo_mode_radio"]:checked').val() || 'allow') : 'off';
7276
7277      // Build states object from checkboxes
7278      var statesObj = {};
7279      selectedCountries.forEach(function (cc) {
7280        if (GEO_STATE_COUNTRIES.indexOf(cc) === -1 || !GEO_STATES[cc]) return;
7281        var section = document.getElementById('geo_state_section_' + cc);
7282        if (!section) return;
7283        var allCbs = section.querySelectorAll('.geo-state-cb');
7284        var checkedCbs = section.querySelectorAll('.geo-state-cb:checked');
7285        // Only store if not all states selected (partial selection)
7286        if (checkedCbs.length < allCbs.length && checkedCbs.length > 0) {
7287          statesObj[cc] = [];
7288          checkedCbs.forEach(function (cb) { statesObj[cc].push(cb.getAttribute('data-state')); });
7289        }
7290      });
7291
7292      document.getElementById('geo_mode').value = mode;
7293      document.getElementById('geo_countries_iso').value = selectedCountries.join(',');
7294      document.getElementById('geo_states').value = Object.keys(statesObj).length > 0 ? JSON.stringify(statesObj) : '';
7295
7296      // Backwards compat: generate countries_allowed
7297      if (mode === 'off' || selectedCountries.length === 0) {
7298        document.getElementById('countries_allowed').value = 'Worldwide';
7299        document.getElementById('allowed_world_wide').value = '1';
7300      } else {
7301        var names = selectedCountries.map(function (c) { return ISO_TO_NAME[c] || c; });
7302        document.getElementById('countries_allowed').value = names.join(', ');
7303        document.getElementById('allowed_world_wide').value = '0';
7304      }
7305    }
7306
7307    // Initial render if there are pre-selected countries
7308    if (selectedCountries.length > 0) {
7309      renderPills();
7310      selectedCountries.forEach(function (code) {
7311        renderStates(code);
7312      });
7313    }
7314
7315    // Expose reinit for copy giveaway
7316    window.sw_geo_reinit = function () {
7317      var iso = (document.getElementById('geo_countries_iso') || {}).value || '';
7318      var statesJson = (document.getElementById('geo_states') || {}).value || '';
7319      selectedCountries = iso ? iso.split(',').map(function(c) { return c.trim(); }).filter(Boolean) : [];
7320      selectedStates = {};
7321      if (statesJson) {
7322        try { selectedStates = JSON.parse(statesJson); } catch(e) {}
7323      }
7324      pillsContainer.innerHTML = '';
7325      statesWrapper.innerHTML = '';
7326      renderPills();
7327      selectedCountries.forEach(function (code) {
7328        renderStates(code);
7329      });
7330      syncHiddenFields();
7331    };
7332  })();
7333
7334  // Trusted email domains toggle
7335  $('#if_trusted_email_domains').on('change', function () {
7336    $('#trusted_email_domains_wrapper').toggle(this.checked);
7337    if (!this.checked) {
7338      $('#trusted_email_domains').val('');
7339    }
7340  });
7341
7342  // Click on payment platform for entries for purchases
7343  $(document).on("click", ".platform-option", function () {
7344    var container = $(this).closest(".entries_for_purchase_platform_options");
7345    var shop_platform = $(this).attr("data-platform");
7346    var shop_platform_display = "";
7347
7348    // Shopify
7349    if (shop_platform == "shopify") {
7350      shop_platform_display = "Shopify";
7351    }
7352    // WooCommerce
7353    else if (shop_platform == "woocommerce") {
7354      shop_platform_display = "WooCommerce";
7355    }
7356
7357    // entry_method_class is parent data-entry_method_class
7358    var entry_method_class = $(this)
7359      .parent()
7360      .parent()
7361      .parent()
7362      .attr("data-entry_method_class");
7363
7364    // entry_method_id is parent data-entry_method_id
7365    var entry_method_id = $(this)
7366      .parent()
7367      .parent()
7368      .parent()
7369      .attr("data-entry_method_id");
7370
7371    $("button#connect_store_" + entry_method_class + "_" + entry_method_id)
7372      .prop("disabled", false)
7373      .text("Connect " + shop_platform_display + " Store");
7374
7375    container.find(".platform-option").css("opacity", "0.3");
7376    $(this).css("opacity", "1");
7377    $(this).prev('input[type="radio"]').prop("checked", true);
7378
7379    // Show the top and bottom of the entry method
7380    $(
7381      "#entry_method_each_body_show_hide_top_" +
7382      entry_method_class +
7383      "_" +
7384      entry_method_id
7385    ).show();
7386
7387    $(
7388      "#entry_method_each_body_show_hide_bottom_" +
7389      entry_method_class +
7390      "_" +
7391      entry_method_id
7392    ).show();
7393
7394    // Show the instructions for the platform
7395    $(".payment_platform_instructions").hide();
7396
7397    $(
7398      "#" +
7399      shop_platform +
7400      "_instructions_" +
7401      entry_method_class +
7402      "_" +
7403      entry_method_id
7404    ).show();
7405
7406    // Also show product selection for the selected platform
7407    $(
7408      "#" +
7409      shop_platform +
7410      "_product_selection_" +
7411      entry_method_class +
7412      "_" +
7413      entry_method_id
7414    ).show();
7415  });
7416
7417  // ========== PURCHASE ENTRY: Entry Rate Mode & Advanced Options ==========
7418
7419  // Toggle advanced purchase options
7420  $(document).on("click", ".advanced-options-toggle", function () {
7421    var cls = $(this).attr("data-entry_method_class");
7422    var id = $(this).attr("data-entry_method_id");
7423    var container = $("#advanced_purchase_options_" + cls + "_" + id);
7424    var chevron = $(this).find(".advanced-options-chevron");
7425
7426    container.slideToggle(200);
7427    chevron.toggleClass("rotate-180");
7428  });
7429
7430  // Entry mode radio toggle (global vs per-product)
7431  $(document).on("change", ".entry-mode-radio", function () {
7432    var cls = $(this).attr("data-entry_method_class");
7433    var id = $(this).attr("data-entry_method_id");
7434    var mode = $(this).val();
7435
7436    // Update hidden input
7437    var $wrapper = $(this).closest(".purchase-config-wrapper");
7438    $wrapper.find(".entry-mode-value-input").val(mode);
7439
7440    // Toggle global rate row visibility
7441    var $globalRow = $("#global_entry_rate_row_" + cls + "_" + id);
7442    if (mode === "per_product") {
7443      $globalRow.hide();
7444    } else {
7445      $globalRow.css("display", "flex");
7446    }
7447
7448    // Toggle per-product rate rows for checked products
7449    $(this).closest(".entry_method_each").find(".product-item").each(function () {
7450      var $rateRow = $(this).find(".per-product-rate-row");
7451      var isChecked = $(this).find(".product-checkbox").is(":checked");
7452      if (mode === "per_product" && isChecked) {
7453        $rateRow.css("display", "flex");
7454      } else {
7455        $rateRow.hide();
7456      }
7457    });
7458
7459    serializePerProductRates(cls, id);
7460  });
7461
7462  // Show/hide per-product rate row when product checkbox is toggled
7463  $(document).on("change", ".product-checkbox", function () {
7464    var $li = $(this).closest(".product-item");
7465    var $rateRow = $li.find(".per-product-rate-row");
7466    var $configWrapper = $(this).closest(".entry_method_each").find(".purchase-config-wrapper");
7467    var mode = $configWrapper.length ? $configWrapper.find(".entry-mode-value-input").val() : "global";
7468
7469    if (mode === "per_product") {
7470      if ($(this).is(":checked")) {
7471        $rateRow.css("display", "flex");
7472      } else {
7473        $rateRow.hide();
7474      }
7475    }
7476
7477    if ($configWrapper.length) {
7478      var cls = $configWrapper.attr("data-entry_method_class");
7479      var id = $configWrapper.attr("data-entry_method_id");
7480      serializePerProductRates(cls, id);
7481    }
7482  });
7483
7484  // Serialize per-product rates on input change
7485  $(document).on("input", ".per-product-entries, .per-product-dollars", function () {
7486    var cls = $(this).attr("data-entry_method_class");
7487    var id = $(this).attr("data-entry_method_id");
7488    serializePerProductRates(cls, id);
7489  });
7490
7491  function serializePerProductRates(cls, id) {
7492    var $wrapper = $("#purchase_config_wrapper_" + cls + "_" + id);
7493    var mode = $wrapper.find(".entry-mode-value-input").val();
7494    var rates = {};
7495
7496    if (mode === "per_product") {
7497      $wrapper.closest(".entry_method_each").find(".product-checkbox:checked").each(function () {
7498        var productId = $(this).val();
7499        var $li = $(this).closest(".product-item");
7500        var entries = parseInt($li.find(".per-product-entries").val()) || 1;
7501        var dollars = parseInt($li.find(".per-product-dollars").val()) || 1;
7502        rates[productId] = { entries: entries, dollars: dollars };
7503      });
7504    }
7505
7506    $wrapper.find(".per-product-rates-json-input").val(
7507      Object.keys(rates).length > 0 ? JSON.stringify(rates) : "{}"
7508    );
7509  }
7510
7511  // ========== Collection/Category Filter ==========
7512
7513  // Track all products checkbox - hide/show filter section
7514  $(document).on("change", ".track-all-products-checkbox", function () {
7515    var cls = $(this).attr("data-entry_method_class");
7516    var id = $(this).attr("data-entry_method_id");
7517    var $wrapper = $(this).closest(".purchase-platform-options");
7518    if ($(this).is(":checked")) {
7519      $wrapper.find(".product-filter-section").slideUp(200);
7520    } else {
7521      $wrapper.find(".product-filter-section").slideDown(200);
7522    }
7523  });
7524
7525  // Filter mode radio toggle
7526  $(document).on("change", ".filter-mode-radio", function () {
7527    var cls = $(this).attr("data-entry_method_class");
7528    var id = $(this).attr("data-entry_method_id");
7529    var platform = $(this).attr("data-platform");
7530    var mode = $(this).val();
7531    var suffix = platform === "shopify" ? "shopify" : "wc";
7532
7533    $("#filter_products_panel_" + suffix + "_" + cls + "_" + id).toggle(mode === "products");
7534    $("#filter_collections_panel_" + suffix + "_" + cls + "_" + id).toggle(mode === "collections");
7535
7536    // Update hidden input
7537    var $configWrapper = $(this).closest(".entry_method_each").find(".purchase-config-wrapper");
7538    $configWrapper.find(".filter-mode-value-input").val(mode);
7539  });
7540
7541  // Fetch collections button
7542  $(document).on("click", ".fetch-collections-btn", function () {
7543    var $btn = $(this);
7544    var cls = $btn.attr("data-entry_method_class");
7545    var id = $btn.attr("data-entry_method_id");
7546    var platform = $btn.attr("data-shop_platform");
7547    var suffix = platform === "shopify" ? "shopify" : "wc";
7548    var $list = $("#collections_list_" + suffix + "_" + cls + "_" + id);
7549
7550    $btn.prop("disabled", true).text("Loading...");
7551
7552    var postData = {
7553      shop_platform: platform,
7554      fetch_type: "collections"
7555    };
7556
7557    // WooCommerce needs credentials from the form
7558    if (platform === "woocommerce") {
7559      var $entryMethod = $btn.closest(".entry_method_each");
7560      postData.store_url = $entryMethod.find("input[name^='store_url_']").val();
7561      postData.consumer_key = $entryMethod.find("input[name^='consumer_key_']").val();
7562      postData.consumer_secret = $entryMethod.find("input[name^='consumer_secret_']").val();
7563    }
7564
7565    $.ajax({
7566      url: "/a/store_fetch_products.php",
7567      type: "POST",
7568      data: postData,
7569      dataType: "json",
7570      headers: { "X-Requested-With": "XMLHttpRequest" },
7571      success: function (response) {
7572        if (response.error) {
7573          $list.html($('<div class="text-red-500 p-3 text-sm">').text(response.error));
7574          $btn.prop("disabled", false).text(platform === "shopify" ? "Load Collections" : "Load Categories");
7575          return;
7576        }
7577
7578        var collections = response.collections || [];
7579        if (collections.length === 0) {
7580          $list.html('<div class="text-[13px] text-[#6b7280] p-3">No collections found.</div>');
7581          $btn.prop("disabled", false).text(platform === "shopify" ? "Load Collections" : "Load Categories");
7582          return;
7583        }
7584
7585        // Get currently selected IDs
7586        var $configWrapper = $btn.closest(".entry_method_each").find(".purchase-config-wrapper");
7587        var savedIds = [];
7588        try {
7589          savedIds = JSON.parse($configWrapper.find(".collection-ids-json-input").val() || "[]");
7590        } catch (e) { savedIds = []; }
7591
7592        var html = '<ul class="list-none m-0 p-0">';
7593        html += '<li class="py-2 px-3 border-b border-[#eee]"><label><input type="checkbox" class="sw-checkbox collection-select-all" /> <span class="font-bold text-sm">Select All</span></label></li>';
7594        for (var i = 0; i < collections.length; i++) {
7595          var col = collections[i];
7596          var colId = String(col.id);
7597          var checked = savedIds.indexOf(colId) !== -1 ? ' checked="checked"' : "";
7598          html += '<li class="collection-item py-2 px-3 border-b border-[#eee] flex items-center justify-between">';
7599          html += '<label class="flex items-center flex-1 min-w-0">';
7600          html += '<input type="checkbox" class="sw-checkbox collection-checkbox" value="' + colId + '"' + checked + " />";
7601          html += '<span class="text-sm truncate">' + $("<span>").text(col.name).html() + "</span>";
7602          html += "</label>";
7603          html += '<span class="text-[12px] text-[#9ca3af] ml-2">(' + col.count + " products)</span>";
7604          html += "</li>";
7605        }
7606        html += "</ul>";
7607        $list.html(html);
7608
7609        // Save the full collections list for page reload
7610        var $configWrapper = $btn.closest(".entry_method_each").find(".purchase-config-wrapper");
7611        var collectionsEncoded = btoa(unescape(encodeURIComponent(JSON.stringify(collections))));
7612        $configWrapper.find(".collections-json-input").val(collectionsEncoded);
7613
7614        $btn.prop("disabled", false).text(platform === "shopify" ? "Load Collections" : "Load Categories");
7615      },
7616      error: function () {
7617        $list.html('<div class="text-red-500 p-3 text-sm">Failed to fetch. Please try again.</div>');
7618        $btn.prop("disabled", false).text(platform === "shopify" ? "Load Collections" : "Load Categories");
7619      }
7620    });
7621  });
7622
7623  // Collection checkbox change - serialize selected IDs
7624  $(document).on("change", ".collection-checkbox", function () {
7625    var $panel = $(this).closest(".filter-collections-panel");
7626    serializeCollectionIds($panel);
7627  });
7628
7629  // Collection select all
7630  $(document).on("change", ".collection-select-all", function () {
7631    var $panel = $(this).closest(".filter-collections-panel");
7632    var isChecked = $(this).is(":checked");
7633    $panel.find(".collection-checkbox").prop("checked", isChecked);
7634    serializeCollectionIds($panel);
7635  });
7636
7637  function serializeCollectionIds($panel) {
7638    var ids = [];
7639    $panel.find(".collection-checkbox:checked").each(function () {
7640      ids.push($(this).val());
7641    });
7642    var $configWrapper = $panel.closest(".entry_method_each").find(".purchase-config-wrapper");
7643    $configWrapper.find(".collection-ids-json-input").val(JSON.stringify(ids));
7644  }
7645
7646  // Auto-fetch collections on page load if saved IDs exist but no collections rendered yet
7647  $(function() {
7648    $(".filter-collections-panel").each(function() {
7649      var $panel = $(this);
7650      var $configWrapper = $panel.closest(".entry_method_each").find(".purchase-config-wrapper");
7651      var savedIds = [];
7652      try { savedIds = JSON.parse($configWrapper.find(".collection-ids-json-input").val() || "[]"); } catch(e) {}
7653      // If there are saved IDs but no checkboxes rendered, auto-fetch
7654      if (savedIds.length > 0 && $panel.find(".collection-checkbox").length === 0) {
7655        $panel.find(".fetch-collections-btn").trigger("click");
7656      }
7657    });
7658  });
7659
7660  // Update "Add a/Another" button text based on entry method count
7661  function updateAddButtonLabels() {
7662    var entryCount = $('#sortable_two .entry_method_each').length;
7663    var loginCount = $('#sortable_one .entry_method_each').length;
7664    var entryWord = entryCount > 0 ? 'Another' : 'a';
7665    var loginWord = loginCount > 0 ? 'Another' : 'a';
7666    $('#entry_method_add_1 label').html('<i class="fas fa-plus text-[13px]"></i>&nbsp; Add ' + entryWord + ' Way to Enter');
7667    $('#custom_form_fields_add_1 label').html('<i class="fas fa-plus text-[13px]"></i>&nbsp; Add ' + loginWord + ' Custom Login Field');
7668  }
7669  $(function () { updateAddButtonLabels(); });
7670
7671});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.