/**
 * @package Helix Ultimate Framework
 * @author JoomShaper https://www.joomshaper.com
 * Copyright (c) 2010 - 2025 JoomShaper
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
 */
jQuery((function(e){let t=e(".hu-presets #presets-data"),a=e(".hu-presets .hu-preset"),s=t.val();function n(n,o,r,l){s[o].data=n,console.log(n),t.val(JSON.stringify(s)),a.each((function(){let t=this;e(this).data("preset")===o&&Object.entries(n).forEach((function([a,s]){e(t).attr(`data-${a}`,s),e(t).data(a,s)}))})),r.html(l.find("> div")),window.purgeCss(),e(".hu-options-modal-overlay, .hu-options-modal").remove(),e("body").removeClass("hu-options-modal-open");let i=function(e){let t=Object.values(e).reduce((function(e,t){return e[t]=(e[t]||0)+1,e}),{}),a=0;return Object.entries(t).reduce((function(e,[t,s]){return s>=a&&(a=s,e=t),e}),"")}(n),u=e(`.hu-preset[data-preset=${o}]`);u.css({"background-color":i}),u.find(".hu-edit-preset").css({color:i}),e(`.hu-preset[data-preset=${o}]`).click()}"string"==typeof s&&s.length&&(s=JSON.parse(s)),e(document).on("click",".hu-edit-preset",(function(t){t.preventDefault(),t.stopPropagation();let a=e(this).data("preset_data")||"",{name:s,data:o}=a,r=e(`.hu-preset-container#${s}`),l=r.clone(!0);l.each((function(){e(this).find("input").removeAttr("id")})),e(this).helixUltimateOptionsModal({flag:"edit-presets",title:`<span class='fas fa-cogs hu-mr-2'></span> Edit Preset: ${s}`,class:`hu-modal-small edit-preset-modal modal-${s}`,applyBtnClass:"hu-save-preset",footerButtons:['<a href="#" class="hu-btn hu-btn-secondary helix-preset-reset hu-ml-auto"><span class="fas fa-sync-alt" aria-hidden="true"></span> Reset to Default</a>']}),e(".hu-options-modal-inner").html(l.removeAttr("id").removeAttr("style").addClass("hu-options-modal-content")),l.find("input.preset-control").each((function(){e(this).on("change",(function(t){t.preventDefault();let a=e(this).attr("name"),s=e(this).val();o[a]=s}))}));let i=e(`.edit-preset-modal.modal-${s}`).find(".hu-save-preset"),u=e(`.edit-preset-modal.modal-${s}`).find(".helix-preset-reset");i.length&&(i.on("click",(function(e){e.preventDefault(),n(o,s,r,l)})),u.on("click",(function(t){if(t.preventDefault(),window.confirm("Do you really want to reset your changes to default?")){n(JSON.parse(e("#default-values").val())[s],s,r,l)}})))}))}));