(()=>{"use strict";
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 */
const{$:o}=window;const e=class{constructor(){var e;this.$panelSelection=o("#modules-position-selection-panel"),this.$panelSelectionSingleSelection=o("#modules-position-single-selection"),this.$panelSelectionMultipleSelection=o("#modules-position-multiple-selection");const t=o("#content-message-box + .alert");this.$panelSelectionOriginalY=null==(e=this.$panelSelection.offset())?void 0:e.top,t.length>0&&(this.$panelSelectionOriginalY+=t.outerHeight()),this.$showModules=o("#show-modules"),this.$modulesList=o(".modules-position-checkbox"),this.$hookPosition=o("#hook-position"),this.$hookSearch=o("#hook-search"),this.$modulePositionsForm=o("#module-positions-form"),this.$moduleUnhookButton=o("#unhook-button-position-bottom"),this.$moduleButtonsUpdate=o(".module-buttons-update .btn"),this.$hooksList=[],this.$transplantModuleButton=o(".transplant-module-button"),this.handleList(),this.handleSortable(),this.$modulesList.trigger("change"),this.$modulesList.trigger("scroll"),o('input[name="general[enable_tos]"]').on("change",(()=>{this.handleList(),this.handleSortable()}))}handleList(){const e=this;o(window).on("scroll",(()=>{const t=o(window).scrollTop();e.$panelSelection.css("top",t<20?0:t-e.$panelSelectionOriginalY)})),e.$modulesList.on("change",(()=>{const t=e.$modulesList.filter(":checked").length;0===t?(e.$moduleUnhookButton.hide(),e.$panelSelection.hide(),e.$panelSelectionSingleSelection.hide(),e.$panelSelectionMultipleSelection.hide()):1===t?(e.$moduleUnhookButton.show(),e.$panelSelection.show(),e.$panelSelectionSingleSelection.show(),e.$panelSelectionMultipleSelection.hide()):(e.$moduleUnhookButton.show(),e.$panelSelection.show(),e.$panelSelectionSingleSelection.hide(),e.$panelSelectionMultipleSelection.show(),o("#modules-position-selection-count").html(t))})),e.$panelSelection.find("button").on("click",(()=>{o('button[name="unhookform"]').trigger("click")})),e.$hooksList=[],o("section.hook-panel .hook-name").each((function(){const t=o(this);e.$hooksList.push({title:t.html(),element:t,container:t.parents(".hook-panel")})})),e.$showModules.select2(),e.$showModules.on("change",(()=>{e.modulesPositionFilterHooks()})),e.$hookPosition.on("change",(()=>{e.modulesPositionFilterHooks()})),e.$hookSearch.on("input",(()=>{e.modulesPositionFilterHooks()})),e.modulesPositionFilterHooks(),e.$hookSearch.on("keypress",(o=>13!==(o.keyCode||o.which))),o(".hook-checker").on("click",(function(){o(`.hook${o(this).data("hook-id")}`).prop("checked",o(this).prop("checked"))})),e.$modulesList.on("click",(function(){o(`#Ghook${o(this).data("hook-id")}`).prop("checked",0===o(`.hook${o(this).data("hook-id")}:not(:checked)`).length)})),e.$moduleButtonsUpdate.on("click",(function(){const t=o(this),s=t.closest(".module-item");let i;return i=t.data("way")?s.next(".module-item"):s.prev(".module-item"),0===i.length||(t.data("way")?s.insertAfter(i):s.insertBefore(i),e.updatePositions({hookId:t.data("hook-id"),moduleId:t.data("module-id"),way:t.data("way"),positions:[]},t.closest("ul"))),!1}))}handleSortable(){const e=this;o(".sortable").sortable({forcePlaceholderSize:!0,start(e,t){o(this).data("previous-index",t.item.index())},update(t,s){const[i,n]=s.item.attr("id").split("_"),l={hookId:i,moduleId:n,way:o(this).data("previous-index")<s.item.index()?1:0,positions:[]};e.updatePositions(l,o(t.target))}})}updatePositions(e,t){o.each(t.children(),((t,s)=>{e.positions.push(o(s).attr("id"))})),o.ajax({type:"POST",headers:{"cache-control":"no-cache"},url:this.$modulePositionsForm.data("update-url"),data:e,success:()=>{let e=0;o.each(t.children(),((t,s)=>{e+=1,o(s).find(".index-position").html(e)})),window.showSuccessMessage(window.update_success_msg)}})}modulesPositionFilterHooks(){const e=this,t=e.$hookSearch.val(),s=e.$showModules.val(),i=new RegExp(`(${t})`,"gi"),n=new URL(this.$transplantModuleButton.prop("href"));n.searchParams.set("show_modules",s),this.$transplantModuleButton.attr("href",n.toString());const l=""===t&&"all"===s;for(let o=0;o<e.$hooksList.length;o+=1)e.$hooksList[o].container.toggleClass("hook-visible",l),e.$hooksList[o].container.toggle(l),e.$hooksList[o].element.html(e.$hooksList[o].title),e.$hooksList[o].container.find(".module-item").removeClass("highlight");if(""!==t||"all"!==s){let n,l,h=o(),a=o();for(let o=0;o<e.$hooksList.length;o+=1)"all"!==s&&(n=e.$hooksList[o].container.find(`.module-position-${s}`),n.length>0&&(h=h.add(e.$hooksList[o].container),n.addClass("highlight"))),""!==t&&(l=e.$hooksList[o].title.toLowerCase().search(t.toLowerCase()),-1!==l&&(a=a.add(e.$hooksList[o].container),e.$hooksList[o].element.html(e.$hooksList[o].title.replace(i,'<span class="highlight">$1</span>'))));"all"===s&&""!==t?(a.toggleClass("hook-visible",!0),a.show()):""===t&&"all"!==s?(h.toggleClass("hook-visible",!0),h.show()):(a.filter(h).toggleClass("hook-visible",!0),a.filter(h).show())}if(!e.$hookPosition.prop("checked"))for(let o=0;o<e.$hooksList.length;o+=1)e.$hooksList[o].container.is(".hook-position")&&(e.$hooksList[o].container.toggleClass("hook-visible",!1),e.$hooksList[o].container.hide())}},{$:t}=window;const s=class{constructor(){const o=this;this.$hookStatus=t(".hook-switch-action"),this.$modulePositionsForm=t("#module-positions-form"),this.$hookStatus.on("change",(function(e){e.stopImmediatePropagation(),o.toogleHookStatus(t(this))}))}toogleHookStatus(o){t.ajax({type:"POST",headers:{"cache-control":"no-cache"},url:this.$modulePositionsForm.data("togglestatus-url"),data:{hookId:o.data("hook-id")},success(e){if(e.status){window.showSuccessMessage(e.message);o.closest(".hook-panel").find(".module-list, .module-list-disabled").fadeTo(500,e.hook_status?1:.5)}else window.showErrorMessage(e.message)}})}},{$:i}=window;i((()=>{new e,new s})),window.improve_design_positions={}})();