/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */
import{SeverityEnum as m}from"@typo3/backend/enum/severity.js";import l from"jquery";import{Carousel as f}from"bootstrap";import p from"@typo3/backend/modal.js";import u from"@typo3/backend/severity.js";import h from"@typo3/backend/icons.js";import{topLevelModuleImport as g}from"@typo3/backend/utility/top-level-module-import.js";class b{constructor(){console.warn("The module `@typo3/backend/wizard.js` has been marked as deprecated and will be removed in TYPO3 v14.0. Consider migrating to `@typo3/backend/multi-step-wizard.js`."),this.setup={slides:[],settings:{},forceSelection:!0,$carousel:null,carousel:null},this.originalSetup=l.extend(!0,{},this.setup)}set(e,t){return this.setup.settings[e]=t,this}addSlide(e,t,s="",n=m.notice,d){const i={identifier:e,title:t,content:s,severity:n,callback:d};return this.setup.slides.push(i),this}addFinalProcessingSlide(e){return e||(e=()=>{this.dismiss()}),h.getIcon("spinner-circle",h.sizes.large,null,null).then(t=>{const s=l("<div />",{class:"text-center"}).append(t);this.addSlide("final-processing-slide",top.TYPO3.lang["wizard.processing.title"],s[0].outerHTML,u.notice,e)})}show(){const e=this.generateSlides(),t=this.setup.slides[0];p.advanced({title:t.title,content:e,severity:t.severity,staticBackdrop:!0,buttons:[{text:top.TYPO3.lang["wizard.button.cancel"],active:!0,btnClass:"btn-default",name:"cancel",trigger:()=>{this.getComponent().trigger("wizard-dismiss")}},{text:top.TYPO3.lang["wizard.button.next"],btnClass:"btn-primary",name:"next"}],callback:s=>{g("@typo3/backend/element/progress-bar-element.js").then(()=>{this.setup.carousel=new f(s.querySelector(".carousel")),this.addProgressBar(),this.initializeEvents(s)})}}),this.setup.forceSelection&&this.lockNextStep(),this.getComponent().on("wizard-visible",()=>{this.runSlideCallback(t,this.setup.$carousel.find(".carousel-item").first())}).on("wizard-dismissed",()=>{this.setup=l.extend(!0,{},this.originalSetup)})}getComponent(){return this.setup.$carousel===null&&this.generateSlides(),this.setup.$carousel}dismiss(){p.dismiss()}lockNextStep(){const e=this.setup.$carousel.closest(".modal").find('button[name="next"]');return e.prop("disabled",!0),e}unlockNextStep(){const e=this.setup.$carousel.closest(".modal").find('button[name="next"]');return e.prop("disabled",!1),e}setForceSelection(e){this.setup.forceSelection=e}initializeEvents(e){const t=this.setup.$carousel.closest(".modal"),s=t.find(".modal-title"),n=t.find(".modal-footer");n.find('button[name="next"]').on("click",()=>{this.setup.carousel.next()}),this.setup.$carousel.get(0).addEventListener("slide.bs.carousel",()=>{const a=this.setup.$carousel.data("currentSlide")+1,r=this.setup.$carousel.data("currentIndex")+1;if(s.text(this.setup.slides[r].title),this.setup.$carousel.data("currentSlide",a),this.setup.$carousel.data("currentIndex",r),a>=this.setup.$carousel.data("realSlideCount"))t.find(".modal-header .close").remove(),n.slideUp();else{const c=n.find("typo3-backend-progress-bar");c.attr("value",r),c.attr("label",top.TYPO3.lang["wizard.progress"].replace("{0}",a).replace("{1}",this.setup.$carousel.data("slideCount")))}t.removeClass("modal-severity-"+u.getCssClass(this.setup.slides[r-1].severity)).addClass("modal-severity-"+u.getCssClass(this.setup.slides[r].severity))}),this.setup.$carousel.get(0).addEventListener("slid.bs.carousel",a=>{const r=this.setup.$carousel.data("currentIndex"),c=this.setup.slides[r];this.runSlideCallback(c,l(a.relatedTarget)),this.setup.forceSelection&&this.lockNextStep()});const i=this.getComponent();i.on("wizard-dismiss",this.dismiss),e.addEventListener("typo3-modal-hidden",()=>{i.trigger("wizard-dismissed")}),e.addEventListener("typo3-modal-shown",()=>{i.trigger("wizard-visible")})}runSlideCallback(e,t){typeof e.callback=="function"&&e.callback(t,this.setup.settings,e.identifier)}addProgressBar(){const e=this.setup.$carousel.find(".carousel-item").length,t=Math.max(1,e),s=Math.round(100/t),d=this.setup.$carousel.closest(".modal").find(".modal-footer");if(this.setup.$carousel.data("initialStep",s).data("slideCount",t).data("realSlideCount",e).data("currentIndex",0).data("currentSlide",1),t>1){const i=document.createElement("typo3-backend-progress-bar");i.value=0,i.max=t-1,i.label=top.TYPO3.lang["wizard.progress"].replace("{0}","1").replace("{1}",t.toString()),d.prepend(i)}}generateSlides(){if(this.setup.$carousel!==null)return this.setup.$carousel;let e='<div class="carousel slide" data-bs-ride="false"><div class="carousel-inner" role="listbox">';for(const t of Object.values(this.setup.slides)){let s=t.content;typeof s=="object"&&(s=s.html()),e+='<div class="carousel-item" data-bs-slide="'+t.identifier+'">'+s+"</div>"}return e+="</div></div>",this.setup.$carousel=l(e),this.setup.$carousel.find(".carousel-item").first().addClass("active"),this.setup.$carousel}}let o;try{window.opener&&window.opener.TYPO3&&window.opener.TYPO3.Wizard&&(o=window.opener.TYPO3.Wizard),parent&&parent.window.TYPO3&&parent.window.TYPO3.Wizard&&(o=parent.window.TYPO3.Wizard),top&&top.TYPO3&&top.TYPO3.Wizard&&(o=top.TYPO3.Wizard)}catch{}o||(o=new b,typeof TYPO3<"u"&&(TYPO3.Wizard=o));var $=o;export{$ as default};
