jQuery(document).ready(function () {
  initalizeUserEdit();
  editUserData();
  //changeBackImgTheme();
});
function initalizeUserEdit() {
  jQuery(".img-select").on("click", function (event) {
    console.log("click", this);
    event.preventDefault();

    images = wp
      .media({
        tile: "Upload Image",
        multiple: false,
      })
      .open()
      .on("select", function (e) {
        var uploadedImages = images.state().get("selection").first();
        var getImageUrl = uploadedImages.toJSON().url;
        jQuery(".show-image").html(
          "<img class='strb-backgournd' style='width:100%;height:100%;object-fit:contain;' src='" +
            getImageUrl +
            "' />"
        );
        jQuery(".user-image").val(getImageUrl);
      });
  });
}
function editUserData() {
  //Edit user data
  jQuery(".edit-user-data-btn").click(() => {
    return jQuery
      .post(sqQuery.ajaxurl, {
        form: jQuery(".edit-user-data-form").serialize(),
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_edit_auth_data",
      })
      .done(function (data) {
        jQuery(".add-author").css("display", "none");
        jQuery(".authors").css("display", "block");
        jQuery(".display-all-themes").css("display", "block");
        location.reload();
      });
  });
}
//EDIT THEME
function changeBackImgTheme() {
  jQuery(".choose-img").on("click", function (event) {
    event.preventDefault();

    images = wp
      .media({
        tile: "Upload Image",
        multiple: false,
      })
      .open()
      .on("select", function () {
        var uploadedImages = images.state().get("selection").first();
        var getImageUrl = uploadedImages.toJSON().url;
        jQuery(".squirrly-strb-background-image").attr("src", getImageUrl);
        jQuery(".background-img").val(getImageUrl);
      });
  });
}

//AXAJ
(function ($) {
  "use strict";
  $(document).ready(function () {
    //Open and preview theme
    var propselectedonpreview;
    var backImg;
    var themetodisplayonoption;
    var prevTheme;
    var propselectedonoption;
    $(".preview").click((event) => {
      propselectedonoption = null;
      $(".preview-input-st").css("display", "none");
      $(".preview-input").css("display", "block");
      $(".preview-box").css("display", "block");

      var prevFolder = $(event.currentTarget).siblings("img").attr("id");
      backImg = $(event.currentTarget).siblings("img").attr("src");
      prevTheme = $(event.currentTarget).prop("name");
      propselectedonpreview = prevTheme;

      $(".background-img").val(backImg);
      $(".strb_theme").val(prevTheme);

      return $.post(sqQuery.ajaxurl, {
        previewTheme: prevTheme,
        backgroundImg: backImg,
        previewFolder: prevFolder,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_preview_theme",
      }).done(function (data) {
        $(".swiper").css("display", "block");
        $(".preview-left").css("margin-top", "0vw");

        $(".preview-left").html($(data["theme"]));

        $("#prevOne").attr("src", data["prevFolder"] + "/ph1.png");
        $("#prevTwo").attr("src", data["prevFolder"] + "/ph2.png");
        $("#prevThree").attr("src", data["prevFolder"] + "/ph3.png");
        $("#prevFour").attr("src", data["prevFolder"] + "/ph4.png");
        $("#prevFive").attr("src", data["prevFolder"] + "/ph5.png");
        $("#prevSix").attr("src", data["prevFolder"] + "/ph6.png");
        $("#prevSeven").attr("src", data["prevFolder"] + "/ph7.png");
        $("#prevEight").attr("src", data["prevFolder"] + "/ph8.png");
        $(".new-theme-check").val("1");
        if ($(event.currentTarget).hasClass("standard")) {
          $(".preview-options").css("display", "none");
        } else $(".preview-options").css("display", "block");

        $(".preview-box").css("display", "block");
        $(".preview-box")[0].scrollIntoView({
          behavior: "smooth",
          block: "start",
        });
      });
    });

    $(".preview-standard").click((event) => {
      var prevStandardTheme = $(event.currentTarget).prop("name");
      backImg = $(event.currentTarget).siblings("img").attr("src");
      $(".background-img").val(".");

      $(".preview-input-st").css("display", "block");
      $(".preview-input").css("display", "none");

      $(".preview-input-st").attr("name", $(event.currentTarget).prop("name"));

      return $.post(sqQuery.ajaxurl, {
        previewStandardTheme: prevStandardTheme,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_preview_standard",
      }).done(function (data) {
        $(".preview-box").css("display", "block");
        $(".preview-box")[0].scrollIntoView({
          behavior: "smooth",
          block: "start",
        });
        $(".swiper").css("display", "none");
        $(".preview-left").css("margin-top", "6vw");
        $(".preview-left").html(data);
      });
    });

    $(".preview-input-st").on("click", () => {
      $(".preview-box").css("display", "none");
      $(".background-img").val(".");
    });

    $(".theme-index").each(function () {
      $(this).on("click", function () {
        propselectedonoption = $(this).val();
        themetodisplayonoption = propselectedonpreview.concat(
          "/",
          propselectedonoption
        );

        return $.post(sqQuery.ajaxurl, {
          editTheme: themetodisplayonoption,
          backgroundImg: backImg,
          strb_nonce: sqQuery.nonce,
          action: "strb_ajax_edit_preview_theme",
        }).done(function (data) {
          if (data) {
            $(".preview-left").html(data);
          }
        });
      });
    });

    $("#select-theme-edit").click(() => {
      if (propselectedonoption == null || propselectedonoption == "indexone") {
        themetodisplayonoption = prevTheme + "/indexone";
      } else themetodisplayonoption = prevTheme + "/" + propselectedonoption;

      console.log(propselectedonoption);
      if (backImg != "") {
        $(".background-img").val(backImg);

        console.log(themetodisplayonoption);
      } else $(".background-img").val("");
      $(".strb_theme").val(themetodisplayonoption);

      return $.post(sqQuery.ajaxurl, {
        editTheme: themetodisplayonoption,
        backgroundImg: backImg,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_edit_preview_theme",
      }).done(function (data) {
        if (data) {
          $(".edit-theme").css("display", "block");

          $(".all-themes").css("display", "none");
          $(".top-menu-themes").css("display", "none");
          $(".back-setup").css("display", "none");
          $(".change-theme-setup").css("display", "block");

          $(".preview-theme-edit").html(data);

          $(".edit-theme").css("display", "block");
          $(".edit-theme")[0].scrollIntoView({
            behavior: "smooth",
            block: "start",
          });
          $(".preview-box").css("display", "none");
        }
      });
    });

    $(".select").click((event) => {
      let selectTheme = $(event.currentTarget).prop("name");
      backImg = $(event.currentTarget).siblings("img").attr("src");
      $(".strb_theme").val(selectTheme);
      $(".background-img").val(backImg);

      return $.post(sqQuery.ajaxurl, {
        editTheme: selectTheme,
        backgroundImg: backImg,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_edit_preview_theme",
      }).done(function (data) {
        if (data) {
          $(".edit-theme").css("display", "block");

          $(".all-themes").css("display", "none");
          $(".top-menu-themes").css("display", "none");
          $(".back-setup").css("display", "none");
          $(".change-theme-setup").css("display", "block");

          $(".preview-theme-edit").html(data);
          changeBackImgTheme();
          $(".new-theme-check").val("1");
        }
      });
    });

    //New auth ajax
    $(".new-user-data-btn").click(() => {
      return $.post(sqQuery.ajaxurl, {
        form: $("#input_form").serialize(),
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_new_auth_data",
      }).done(function (data) {
        if (data) {
          $(".add-new-author").css("display", "none");
          $(".strb-menu-hide").css("display", "none");
          $(".add-author").css("display", "none");
          $(".theme_edit_container").css("display", "block");
          $(".authors").css("display", "none");
          $(".display-all-themes").css("display", "none");
        }
      });
    });

    $(".strb-dont-show-box-for-auth").click((event) => {
      return $.post(sqQuery.ajaxurl, {
        id: $(event.currentTarget).val(),
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_dont_show_author_box",
      }).done(function (data) {
        if (data) {
          location.reload();
        }
      });
    });

    $(".show-author-box").click((event) => {
      console.log($(event.currentTarget).val());
      return $.post(sqQuery.ajaxurl, {
        userId: $(event.currentTarget).val(),
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_show_author_box",
      }).done(function (data) {
        if (data) {
          location.reload();
        }
      });
    });

    //Change theme setup

    $(".change-theme-setup").click(() => {
      $(".change-theme-setup").css("display", "none");
      $(".back-setup").css("display", "block");
      $(".top-menu-themes").css("display", "flex");
      $(".edit-theme").css("display", "none");
      $(".all-themes").css("display", "block");
    });
    //Send user id to edit theme
    var editId;
    $(".edit_theme_info").click((event) => {
      //$("#theme_edit_container").css("display", "block");
      $("body").css("height", "100%");
      $("body").css("overflow", "hidden");
      console.log("hide");
      $(".strb-menu-hide").css("display", "none");
      $(".edit-theme-options").css("display", "block");
      $(".change-theme").css("display", "block");
      $(".authors").css("display", "none");
      $(".display-all-themes").css("display", "none");
      var theme = $(event.currentTarget).siblings("input").attr("value");
      var image = $(event.currentTarget).siblings("input").attr("name");
      editId = $(event.currentTarget).val();
      $(".edit_current_id").val(editId);
      $(".strb_theme").val(theme);
      $(".background-img").val(image);
      return $.post(sqQuery.ajaxurl, {
        edit_id: editId,

        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_edit_theme",
      }).done(function (data) {
        changeBackImgTheme();
        $(".preview-theme-edit").html(data);
      });
    });

    $(".edit_theme_info_customize").click((event) => {
      //$("#theme_edit_container").css("display", "block");
      $(".edit-theme-options").css("display", "block");
      $(".strb-menu-hide").css("display", "none");
      $(".customize-pannel").css("display", "none");
      var theme = $(event.currentTarget).siblings("input").attr("value");
      var image = $(event.currentTarget).siblings("input").attr("name");
      editId = $(event.currentTarget).val();
      $(".edit_current_id").val(editId);
      $(".strb_theme").val(theme);
      $(".background-img").val(image);
      return $.post(sqQuery.ajaxurl, {
        edit_id: editId,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_edit_theme",
      }).done(function (data) {
        changeBackImgTheme();
        $(".preview-theme-edit").html(data);
      });
    });

    //Edit user data
    $(".edit-author-info-btn").click((event) => {
      let editUserId = $(event.currentTarget).val();

      $(".add-author").css("display", "block");

      $(".display-all-themes").css("display", "none");

      return $.post(sqQuery.ajaxurl, {
        user_id: editUserId,

        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_edit_author",
      }).done(function (data) {
        $(".add-author").html(data);
        initalizeUserEdit();
        editUserData();
      });
    });
    //close edith btn
    $(".close-edith").click(() => {
      $(".edit-theme-options").css("display", "none");
      $(".authors").css("display", "block");
      $(".display-all-themes").css("display", "block");
      location.reload();
    });
    //choose different theme on edith
    $(".change-theme").click((event) => {
      event.preventDefault();

      $(".edit-theme-options").css("display", "none");
      $(".theme_edit_container").css("display", "block");

      $(".close-edith").css("display", "none");
    });

    //Open auth edit bttn function
    $("#add_auth_btn").click(() => {
      $(".add-new-author").css("display", "block");
      $(".display-all-themes").css("display", "none");
    });
    //Search for an autor
    $("#search-author").keyup(() => {
      var search = $("#search-author").val();
      return $.post(sqQuery.ajaxurl, {
        result: search,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_find_author",
      }).done(function (data) {
        if (search === "") {
          $(".searched-author").html("");
          $(".queried-author").css("display", "none");
        } else {
          $(".queried-author").css("display", "block").delay(2000);
          $(".searched-author").html(data[0][0]);
        }
      });
    });
    //Delete a theme
    $(".delete_theme").click(() => {
      var id = $(event.currentTarget).val();
      return $.post(sqQuery.ajaxurl, {
        user_id: id,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_delete_author",
      }).done(function (data) {
        alert(data);
        location.reload();
      });
    });

    //Display Options
    //All
    $(".all-post-types").click(() => {
      $(".specific-pos").css("display", "none");
      $(".add-specific-post-types").prop("checked", false);
      if ($(".all-post-types").is(":checked")) {
        var val = "true";
      } else val = "false";

      return $.post(sqQuery.ajaxurl, {
        checked: val,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_display_all_posts",
      }).done(function (data) {});
    });
    //Specific Post types

    $(".add-specific-post-types").click(() => {
      $(".all-post-types").prop("checked", false);

      if ($(".add-specific-post-types").is(":checked")) {
        $(".specific-pos").css("display", "flex");
        var val = "true";
      } else {
        val = "false";
        $(".specific-pos").css("display", "none");
      }

      return $.post(sqQuery.ajaxurl, {
        checked: val,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_display_specific_posts",
      }).done(function (data) {});
    });
    //
    $(".add-specific-post").click(() => {
      if ($(".add-specific-post").is(":checked")) {
        var val = "true";
      } else val = "false";

      return $.post(sqQuery.ajaxurl, {
        checked: val,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_display_posts",
      }).done(function (data) {});
    });
    //
    $(".add-specific-pages").click(() => {
      if ($(".add-specific-pages").is(":checked")) {
        var val = "true";
      } else val = "false";

      return $.post(sqQuery.ajaxurl, {
        checked: val,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_display_pages",
      }).done(function (data) {});
    });

    //Display options

    $(".save-display-options").click((e) => {
      e.preventDefault();
      if ($(".delete-data-toggler").is(":checked")) var deleteData = "true";
      else deleteData = "false";
      return jQuery
        .post(sqQuery.ajaxurl, {
          formChecked: jQuery(".display-options-form").serialize(),
          deleteCheck: deleteData,
          strb_nonce: sqQuery.nonce,
          action: "strb_ajax_display_options",
        })
        .done(function (data) {
          // jQuery(".add-author").css("display", "none");
          // jQuery(".authors").css("display", "block");
          // jQuery(".display-all-themes").css("display", "block");
          //console.log(data);
          location.reload();
        });
    });
    $(".finish-f-t-s").click((e) => {
      e.preventDefault();
      return jQuery
        .post(sqQuery.ajaxurl, {
          formChecked: jQuery(".display-options-form-f-t-s").serialize(),
          strb_nonce: sqQuery.nonce,
          action: "finish-f-t-s",
        })
        .done(function (data) {
          window.location.href = data;
          // jQuery(".add-author").css("display", "none");
          // jQuery(".authors").css("display", "block");
          // jQuery(".display-all-themes").css("display", "block");
          //console.log(data);
        });
    });

    //Token
    $(".strb-check-token").click(() => {
      let token = $(".input-tk").val();

      return $.post(sqQuery.ajaxurl, {
        token: token,
        strb_nonce: sqQuery.nonce,
        action: "strb_ajax_check_token",
      }).done(function (data) {
        console.log(data);
        if (data == 1) location.reload();
        else {
          $(".token-alert").css("display", "block");
          $(".input-tk").css("border", "1px solid red");
        }
      });
    });

    $(".edit_theme_info_customize").click(() => {
      $("#theme_edit_container").css("display", "block");
      $(".general-author").css("display", "none");
      $("#close_theme").attr("id", "close-custom");
    });

    $(document).on("click", "#close-custom", function (e) {
      $(".general-author").css("display", "block");
    });

    //Close theme selector
    $("#close_theme").click(() => {
      $("#theme_edit_container").css("display", "none");
      $(".authors").css("display", "block");
      location.reload();
    });

    $(".img-close").click(() => {
      $(".preview-box").css("display", "none");
    });
    //Toggle users
    $(".select-btn").click(() => {
      $(".select-menu").toggleClass("active");
    });
    //Select user
    $(".strb-select-author").click((event) => {
      $(".select-menu").removeClass("active");
      $(".userid").val($(event.currentTarget).val());
      $(".user-selected").val("1");
      $(".initial-alert").css("display", "none");

      //First name length check
      if (
        $(event.currentTarget).siblings(".author-firstName").val().length > 8
      ) {
        $(".first-name-alert").css("display", "block");
        $(".firstName").css("border", "1px solid red");
      } else if (
        $(event.currentTarget).siblings(".author-firstName").val().length < 8
      ) {
        $(".first-name-alert").css("display", "none");
        $(".firstName").css("border", "1px solid #D0D0D0");
      }

      if (
        $(event.currentTarget).siblings(".author-lastName").val().length > 8
      ) {
        $(".last-name-alert").css("display", "block");
        $(".lastName").css("border", "1px solid red");
      } else if (
        $(event.currentTarget).siblings(".author-lastName").val().length < 8
      ) {
        $(".last-name-alert").css("display", "none");
        $(".lastName").css("border", "1px solid #D0D0D0");
      }

      $(".firstName").val(
        $(event.currentTarget).siblings(".author-firstName").val()
      );
      $(".lastName").val(
        $(event.currentTarget).siblings(".author-lastName").val()
      );
      $(".userBio").val($(event.currentTarget).siblings(".author-bio").val());
      $(".btn-text").text($(event.currentTarget).text());
    });
    $(".submit-initial").click((e) => {
      if ($(".user-selected").val() != 1) {
        $(".initial-alert").css("display", "block");
        e.preventDefault();
        $(".author")[0].scrollIntoView({
          behavior: "smooth", // or "auto" or "instant"
          block: "start", // or "end"
        });
      }
    });
    $(".firstName").keydown(() => {
      if ($(".firstName").val().length < 10) {
        $(".first-name-alert").css("display", "none");
        $(".firstName").css("border", "1px solid #D0D0D0");
      } else {
        $(".first-name-alert").css("display", "block");
        $(".firstName").css("border", "1px solid red");
      }
    });

    $(".lastName").keydown(() => {
      if ($(".lastName").val().length < 10) {
        $(".last-name-alert").css("display", "none");
        $(".lastName").css("border", "1px solid #D0D0D0");
      } else {
        $(".first-name-alert").css("display", "block");
        $(".firstName").css("border", "1px solid red");
      }
    });

    $(".option").click((event) => {
      $(".btn-text").text($(event.currentTarget).text());
      $(".select-menu").toggleClass("active");

      if ($(event.currentTarget).attr("id") == "all") {
        $(".crafts-wrap").css("display", "block");
        $(".fashion-wrap").css("display", "block");
        $(".fitness-wrap").css("display", "block");
        $(".food-blogger-wrap").css("display", "block");
        $(".geek-wrap").css("display", "block");
        $(".holiday-wrap").css("display", "block");
        $(".interior-design-wrap").css("display", "block");
        $(".parenting-wrap").css("display", "block");
        $(".pet-blogger-wrap").css("display", "block");
        $(".photo-wrap").css("display", "block");
        $(".real-estate-wrap").css("display", "block");
        $(".tech-wrap").css("display", "block");
        $(".travel-wrap").css("display", "block");
        $(".wedding-blogger-wrap").css("display", "block");
      }

      if ($(event.currentTarget).attr("id") == "crafts") {
        $(".visual-category").css("display", "none");
        $(".crafts-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "fashion") {
        $(".visual-category").css("display", "none");
        $(".fashion-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "fitness") {
        $(".visual-category").css("display", "none");
        $(".fitness-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "food") {
        $(".visual-category").css("display", "none");
        $(".food-blogger-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "geek") {
        $(".visual-category").css("display", "none");
        $(".geek-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "holiday") {
        $(".visual-category").css("display", "none");
        $(".holiday-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "interior-design") {
        $(".visual-category").css("display", "none");
        $(".interior-design-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "parenting") {
        $(".visual-category").css("display", "none");
        $(".parenting-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "pets") {
        $(".visual-category").css("display", "none");
        $(".pet-blogger-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "photograpy") {
        $(".visual-category").css("display", "none");
        $(".photo-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "real-estate") {
        $(".visual-category").css("display", "none");
        $(".real-estate-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "tech") {
        $(".visual-category").css("display", "none");
        $(".tech-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "travel") {
        $(".visual-category").css("display", "none");
        $(".travel-wrap").css("display", "block");
      }
      if ($(event.currentTarget).attr("id") == "wedding") {
        $(".visual-category").css("display", "none");
        $(".wedding-blogger-wrap").css("display", "block");
      }
    });
    //Select edit option
    $(".switch-edit-options").click(() => {
      $(".edit-option").toggleClass("active");
    });

    $(".image-editor-button").click(() => {
      $(".image-editor-select").css("display", "block");
      $(".border-editor-select").css("display", "none");
      $(".pannel-editor-select").css("display", "none");
      $(".edit-option").toggleClass("active");
      $(".btn-text-edit").text("Background Image");
    });
    $(".border-editor-button").click(() => {
      $(".border-editor-select").css("display", "block");
      $(".image-editor-select").css("display", "none");
      $(".pannel-editor-select").css("display", "none");
      $(".edit-option").toggleClass("active");
      $(".btn-text-edit").text("Border");
    });
    $(".pannel-editor-button").click(() => {
      $(".pannel-editor-select").css("display", "block");
      $(".border-editor-select").css("display", "none");
      $(".image-editor-select").css("display", "none");
      $(".edit-option").toggleClass("active");
      $(".btn-text-edit").text("Pannel");
    });
    //Edit theme

    let brightness_jpg = 99,
      opacity_jpg = 99,
      grayscale_jpg = 1,
      saturation_jpg = 1;
    const updateFilter = (val) => {
      $(".filter-info-editor .value").text(`${val}%`);

      if ($(".filter-editor .active").attr("id") === "brightness") {
        $(".check-brightness-change").val(0);
        brightness_jpg = val;
        $(".input-brightness").val(val);
      } else if ($(".filter-editor .active").attr("id") === "opacity") {
        $(".check-opacity-change").val(0);
        opacity_jpg = val;
        $(".input-opacity").val(val);
      } else if ($(".filter-editor .active").attr("id") === "grayscale") {
        $(".check-grayscale-change").val(0);
        grayscale_jpg = val;
        $(".input-grayscale").val(val);
      } else if ($(".filter-editor .active").attr("id") === "saturation") {
        $(".check-saturation-change").val(0);
        saturation_jpg = val;
        $(".input-saturation").val(val);
      }
      applyFilters();
    };
    //Reset Options

    $(".reset-options").click(() => {
      $(".preview-theme-edit .edit-clr").css("opacity", "0.95");
      var currentColor = "black";
      if (
        $(".preview-theme-edit .edit-clr").hasClass(
          "squirrly-strb-pnl-color-white"
        )
      ) {
        currentColor = "white";
        $(".preview-theme-edit .edit-clr").css("opacity", "0.9");
      } else if (
        $(".preview-theme-edit .edit-clr").hasClass(
          "squirrly-strb-pnl-color-transparent"
        )
      ) {
        $(".preview-theme-edit .edit-clr").css("background", "transparent");
        currentColor = "transparent";
        $(".preview-theme-edit .edit-clr").css("box-shadow", "none");
      } else if (
        $(".preview-theme-edit .edit-clr").hasClass("business-black")
      ) {
        currentColor = "black";

        $(".preview-theme-edit .edit-clr").css("box-shadow", "0 0 10px black");
        $(".preview-theme-edit .edit-clr").css("opacity", "1");
      } else if (
        $(".preview-theme-edit .edit-clr").hasClass("business-white")
      ) {
        currentColor = "white";
        $(".preview-theme-edit .edit-clr").css("box-shadow", "0 0 10px black");
        $(".preview-theme-edit .edit-clr").css("opacity", "1");
      } else if ($(".preview-theme-edit .edit-clr").hasClass("business-blue")) {
        currentColor = "rgb(93, 97, 213)";
        $(".preview-theme-edit .edit-clr").css("box-shadow", "0 0 10px black");
        $(".preview-theme-edit .edit-clr").css("opacity", "1");
      } else currentColor = "rgba(10, 24, 24, 0.9)";

      (brightness_jpg = 99),
        (opacity_jpg = 99),
        (grayscale_jpg = 1),
        (saturation_jpg = 1);

      up = 0;
      left = 0;
      $(".preview-theme-edit .edit-clr").css("background-color", currentColor);
      if (
        !$(".preview-theme-edit .edit-clr").hasClass(
          "squirrly-strb-pnl-color-transparent"
        )
      )
        $(".preview-theme-edit .edit-clr").css("box-shadow", "0 0 10px black");
      // $(".preview-theme-edit .edit-clr").css("opacity", "0.9");
      $(".squirrly-strb-innerContainer").animate({ marginTop: "0px" }, 100);
      $(".squirrly-strb-innerContainer").animate({ marginLeft: "0px" }, 100);
      applyFilters();
      $(".margin-up-pannel").val(up);
      $(".margin-left-pannel").val(left);
      $(".input-pnl-clr").val(currentColor);
      $(".input-brightness").val(brightness_jpg);
      $(".input-opacity").val(opacity_jpg);
      $(".input-grayscale").val(grayscale_jpg);
      $(".input-saturation").val(saturation_jpg);

      if (
        !$(".preview-theme-edit .edit-clr").hasClass(
          "squirrly-strb-pnl-color-white"
        )
      )
        $(".input-pnl-opacity").val(95);
      else $(".input-pnl-opacity").val(91);
      $(".input-pnl-brd").val("black");
      $(".check-brightness-change").val(0);
      $(".check-opacity-change").val(0);
      $(".check-grayscale-change").val(0);
      $(".check-saturation-change").val(0);
      $(".reset-up").val(0);
      $(".reset-left").val(0);
    });
    //Switch betwen theme edit btns
    $(".filter-editor button").click((e) => {
      $(".filter-editor .active").removeClass("active");
      $(e.currentTarget).addClass("active");

      if ($(e.currentTarget).attr("id") === "brightness") {
        $(".filter-info-editor .name").text($(e.currentTarget).text());
        $(".filter-info-editor .value").text(`${brightness_jpg}%`);
        $(".slider-editor input").val(brightness_jpg);
      } else if ($(e.currentTarget).attr("id") === "opacity") {
        $(".filter-info-editor .name").text($(e.currentTarget).text());
        $(".filter-info-editor .value").text(`${opacity_jpg}%`);
        $(".slider-editor input").val(opacity_jpg);
      } else if ($(e.currentTarget).attr("id") === "grayscale") {
        $(".filter-info-editor .name").text($(e.currentTarget).text());
        $(".filter-info-editor .value").text(`${grayscale_jpg}%`);
        $(".slider-editor input").val(grayscale_jpg);
      } else if ($(e.currentTarget).attr("id") === "saturation") {
        $(".filter-info-editor .name").text($(e.currentTarget).text());
        $(".filter-info-editor .value").text(`${saturation_jpg}%`);
        $(".slider-editor input").val(saturation_jpg);
      }
    });
    const applyFilters = () => {
      $(".preview-theme-edit .squirrly-strb-background-img > img").css({
        "-webkit-filter":
          "brightness(" +
          brightness_jpg +
          "%)" +
          "opacity(" +
          opacity_jpg +
          "%)" +
          "grayscale(" +
          grayscale_jpg +
          "%)" +
          "saturate(" +
          saturation_jpg +
          ")",
      });
    };

    $(".slider-input").on("input change", (e) => {
      updateFilter($(e.currentTarget).val());
    });

    let up = 0;
    let left = 0;
    $(".down").click(() => {
      $(".squirrly-strb-innerContainer").animate({ marginTop: "+=10px" }, 100);
      up += 10;
      $(".margin-up-pannel").val(up);
    });
    $(".up").click(() => {
      $(".squirrly-strb-innerContainer").animate({ marginTop: "-=10px" }, 100);

      up -= 10;
      $(".margin-up-pannel").val(up);
    });
    $(".left").click(() => {
      $(".squirrly-strb-innerContainer").animate({ marginLeft: "-=10px" }, 100);

      left -= 10;
      $(".margin-left-pannel").val(left);
    });
    $(".right").click(() => {
      $(".squirrly-strb-innerContainer").animate({ marginLeft: "+=10px" }, 100);

      left += 10;
      $(".margin-left-pannel").val(left);
    });
    //Pannel Colors
    $(".pannel-color").click(() => {
      $(".pannel-styles").css("display", "none");
      $(".pannel-colors").css("display", "block");
    });

    $(".pnl-clr").click((e) => {
      $(".preview-theme-edit .edit-clr").css(
        "background-color",
        $(e.currentTarget).css("background-color")
      );
      $(".input-pnl-clr").val($(e.currentTarget).css("background-color"));
    });
    $(".color-pannel-custom").on("input", () => {
      $(".preview-theme-edit .edit-clr").css(
        "background-color",
        $(".color-pannel-custom").val()
      );
      $(".input-pnl-clr").val($(".color-pannel-custom").val());
    });
    //Pannel style
    $(".pannel-style").click(() => {
      $(".pannel-styles").css("display", "block");
      $(".pannel-colors").css("display", "none");
    });
    $(".pannel-opacity").on("input", (e) => {
      console.log($(e.currentTarget).val());
      $(".pannel-opacity-value").text($(e.currentTarget).val());
      $(".preview-theme-edit .edit-clr").css(
        "opacity",
        `0.${$(e.currentTarget).val()}`
      );
      $(".input-pnl-opacity").val($(e.currentTarget).val());
    });
    //Border color
    $(".pnl-brd").click((e) => {
      $(".preview-theme-edit .squirrly-strb-pnl-color").css(
        "box-shadow",
        `0 0 10px ${$(e.currentTarget).css("background-color")}`
      );
      $(".classic-content").css(
        "border-top",
        ` 1px solid ${$(e.currentTarget).css("background-color")}`
      );
      $(".classic-content").css(
        "border-bottom",
        ` 1px solid ${$(e.currentTarget).css("background-color")}`
      );
      $(".business-edit-clr").css(
        "box-shadow",
        `0 0 10px ${$(e.currentTarget).css("background-color")}`
      );
      $(".input-pnl-brd").val($(e.currentTarget).css("background-color"));
    });

    $(".wrapper-box").click((e) => {
      $(".wrapper-box").removeClass("active");
      $(e.currentTarget).addClass("active");
      if ($(e.currentTarget).attr("id") === "visual") {
        $(".poster-img").css("filter", "grayscale(100%)");
        $(".btn-text").text("All");
        $(".visual").css("filter", "grayscale(0%)");
        $(".poster-wrapper").addClass("active");
        $(".poster-wrapper-standard").removeClass("active");
        $(".poster-wrapper-modern").removeClass("active");
        $(".filteredb").css("display", "block");
      } else if ($(e.currentTarget).attr("id") === "standard") {
        $(".poster-img").css("filter", "grayscale(100%)");
        $(".standard").css("filter", "grayscale(0%)");
        $(".poster-wrapper-standard").addClass("active");
        $(".poster-wrapper").removeClass("active");
        $(".poster-wrapper-modern").removeClass("active");
        $(".filteredb").css("display", "none");
      } else if ($(e.currentTarget).attr("id") === "all") {
        //all visual
        $(".crafts-wrap").css("display", "block");
        $(".fashion-wrap").css("display", "block");
        $(".fitness-wrap").css("display", "block");
        $(".food-blogger-wrap").css("display", "block");
        $(".geek-wrap").css("display", "block");
        $(".holiday-wrap").css("display", "block");
        $(".interior-design-wrap").css("display", "block");
        $(".parenting-wrap").css("display", "block");
        $(".pet-blogger-wrap").css("display", "block");
        $(".photo-wrap").css("display", "block");
        $(".real-estate-wrap").css("display", "block");
        $(".tech-wrap").css("display", "block");
        $(".travel-wrap").css("display", "block");
        $(".wedding-blogger-wrap").css("display", "block");

        $(".poster-img").css("filter", "grayscale(100%)");
        $(".all").css("filter", "grayscale(0%)");
        $(".poster-wrapper").addClass("active");
        $(".poster-wrapper-standard").addClass("active");
        $(".poster-wrapper-modern").addClass("active");
        $(".filteredb").css("display", "none");
      } else if ($(e.currentTarget).attr("id") === "modern") {
        console.log("modern");
        $(".poster-img").css("filter", "grayscale(100%)");
        $(".modern").css("filter", "grayscale(0%)");
        $(".poster-wrapper-modern").addClass("active");
        $(".poster-wrapper-standard").removeClass("active");
        $(".poster-wrapper").removeClass("active");
        $(".filteredb").css("display", "none");
      } else if ($(e.currentTarget).attr("id") === "sidebar") {
        console.log("sidebar");
        $(".poster-img").css("filter", "grayscale(100%)");
        $(".sidebar").css("filter", "grayscale(0%)");
        $(".poster-wrapper-sidebar").addClass("active");
        $(".poster-wrapper-standard").removeClass("active");
        $(".poster-wrapper").removeClass("active");
        $(".filteredb").css("display", "none");
      }
    });
    $("#btn-next").click(() => {
      $(".no-reddirect").val("redirect");
    });

    $(".strb-about").click((e) => {
      $(".classic-bio").css("display", "block");
      $(".business-social-display").css("display", "block");
      $(".classic-posts").css("display", "none");
      $(e.currentTarget)
        .siblings(".strb-latest-posts")
        .css("background-color", "white");
      $(e.currentTarget).css("background-color", "#bdb9b9ee");
    });
    $(".strb-latest-posts").click((e) => {
      console.log("posts");
      $(".classic-bio").css("display", "none");
      $(".business-social-display").css("display", "none");
      $(".classic-posts").css("display", "block");
      $(e.currentTarget)
        .siblings(".strb-about")
        .css("background-color", "white");
      $(e.currentTarget).css("background-color", "#bdb9b9ee");
    });

    $(".about2").click((e) => {
      $(".classic-bio").css("display", "block");
      $(".business-social-display").css("display", "block");
      $(".classic-posts").css("display", "none");
      $(e.currentTarget).css("border", "1px solid black");
      $(e.currentTarget).siblings(".latest-posts").css("border", "none");
      $(e.currentTarget)
        .siblings(".latest-posts")
        .css("background-color", "white");
      $(e.currentTarget).css("background-color", "#bdb9b9ee");
    });
    $(".latest-posts2").click((e) => {
      $(".classic-bio").css("display", "none");
      $(".business-social-display").css("display", "none");
      $(".classic-posts").css("display", "block");
      $(e.currentTarget).css("border", "1px solid black");
      $(e.currentTarget).siblings(".about").css("border", "none");
      $(e.currentTarget).siblings(".about").css("background-color", "white");
      $(e.currentTarget).css("background-color", "#bdb9b9ee");
    });

    $(document).click((event) => {
      if (
        $(event.target).attr("class") != "select-btn" &&
        $(event.target).attr("class") != "btn-text"
      )
        $(".select-menu").removeClass("active");
    });
    $(document).click((event) => {
      if (
        $(event.target).attr("class") != "switch-edit-options" &&
        $(event.target).attr("class") != "btn-text-edit"
      )
        $(".edit-option").removeClass("active");
    });

    $(document).click((e) => {
      var container = $(".preview-box");
      if (!container.is(e.target) && container.has(e.target).length === 0) {
        $(".preview-box").css("display", "none");
      }
    });

    $(".close-theme-select").click(() => {
      $(".theme_edit_container").css("display", "none");
      $(".display-all-themes").css("display", "block");
      $(".strb-menu-hide").css("display", "block");
    });
  });
})(jQuery);
