jQuery(document).ready(function ($) {
  // Media uploader functionality
  $(".category-media-upload").click(function (e) {
    e.preventDefault();
    var target = $(this).data("target");
    var preview = $(target + "_preview");

    var frame = wp.media({
      title: "Select Image",
      button: { text: "Use this image" },
      multiple: false,
    });

    frame.on("select", function () {
      var attachment = frame.state().get("selection").first().toJSON();
      $(target).val(attachment.url);
      preview.attr("src", attachment.url).show();
    });

    frame.open();
  });

  // Initialize color picker
  $(".sp-custom-color-picker").wpColorPicker();
});