/*
 * 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!
 */
var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};define(["require","exports","./Enum/Severity","jquery","./Modal","./Severity","./Icons"],(function(e,t,s,i,a,l,r){"use strict";i=__importDefault(i);class n{constructor(){this.setup={slides:[],settings:{},forceSelection:!0,$carousel:null},this.originalSetup=i.default.extend(!0,{},this.setup)}set(e,t){return this.setup.settings[e]=t,this}addSlide(e,t,i="",a=s.SeverityEnum.info,l){const r={identifier:e,title:t,content:i,severity:a,callback:l};return this.setup.slides.push(r),this}addFinalProcessingSlide(e){return e||(e=()=>{this.dismiss()}),r.getIcon("spinner-circle-dark",r.sizes.large,null,null).then(t=>{let s=(0,i.default)("<div />",{class:"text-center"}).append(t);this.addSlide("final-processing-slide",top.TYPO3.lang["wizard.processing.title"],s[0].outerHTML,l.info,e)})}show(){let e=this.generateSlides(),t=this.setup.slides[0];a.confirm(t.title,e,t.severity,[{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-"+l.getCssClass(t.severity),name:"next"}]),this.setup.forceSelection&&this.lockNextStep(),this.addProgressBar(),this.initializeEvents(),this.getComponent().on("wizard-visible",()=>{this.runSlideCallback(t,this.setup.$carousel.find(".carousel-item").first())}).on("wizard-dismissed",()=>{this.setup=i.default.extend(!0,{},this.originalSetup)})}getComponent(){return null===this.setup.$carousel&&this.generateSlides(),this.setup.$carousel}dismiss(){a.dismiss()}lockNextStep(){let e=this.setup.$carousel.closest(".modal").find('button[name="next"]');return e.prop("disabled",!0),e}unlockNextStep(){let e=this.setup.$carousel.closest(".modal").find('button[name="next"]');return e.prop("disabled",!1),e}setForceSelection(e){this.setup.forceSelection=e}initializeEvents(){let e=this.setup.$carousel.closest(".modal"),t=e.find(".modal-title"),s=e.find(".modal-footer"),r=s.find('button[name="next"]');r.on("click",()=>{this.setup.$carousel.carousel("next")}),this.setup.$carousel.on("slide.bs.carousel",()=>{let i=this.setup.$carousel.data("currentSlide")+1,a=this.setup.$carousel.data("currentIndex")+1;t.text(this.setup.slides[a].title),this.setup.$carousel.data("currentSlide",i),this.setup.$carousel.data("currentIndex",a),i>=this.setup.$carousel.data("realSlideCount")?(e.find(".modal-header .close").remove(),s.slideUp()):s.find(".progress-bar").width(this.setup.$carousel.data("initialStep")*i+"%").text(top.TYPO3.lang["wizard.progress"].replace("{0}",i).replace("{1}",this.setup.$carousel.data("slideCount"))),r.removeClass("btn-"+l.getCssClass(this.setup.slides[a-1].severity)).addClass("btn-"+l.getCssClass(this.setup.slides[a].severity)),e.removeClass("modal-severity-"+l.getCssClass(this.setup.slides[a-1].severity)).addClass("modal-severity-"+l.getCssClass(this.setup.slides[a].severity))}).on("slid.bs.carousel",e=>{let t=this.setup.$carousel.data("currentIndex"),s=this.setup.slides[t];this.runSlideCallback(s,(0,i.default)(e.relatedTarget)),this.setup.forceSelection&&this.lockNextStep()});let n=this.getComponent();n.on("wizard-dismiss",this.dismiss),a.currentModal.on("hidden.bs.modal",()=>{n.trigger("wizard-dismissed")}).on("shown.bs.modal",()=>{n.trigger("wizard-visible")})}runSlideCallback(e,t){"function"==typeof e.callback&&e.callback(t,this.setup.settings,e.identifier)}addProgressBar(){let e,t=this.setup.$carousel.find(".carousel-item").length,s=Math.max(1,t),a=this.setup.$carousel.closest(".modal").find(".modal-footer");e=Math.round(100/s),this.setup.$carousel.data("initialStep",e).data("slideCount",s).data("realSlideCount",t).data("currentIndex",0).data("currentSlide",1),s>1&&a.prepend((0,i.default)("<div />",{class:"progress"}).append((0,i.default)("<div />",{role:"progressbar",class:"progress-bar","aria-valuemin":0,"aria-valuenow":e,"aria-valuemax":100}).width(e+"%").text(top.TYPO3.lang["wizard.progress"].replace("{0}","1").replace("{1}",s))))}generateSlides(){if(null!==this.setup.$carousel)return this.setup.$carousel;let e='<div class="carousel slide" data-bs-ride="false"><div class="carousel-inner" role="listbox">';for(let t of Object.values(this.setup.slides)){let s=t.content;"object"==typeof s&&(s=s.html()),e+='<div class="carousel-item" data-bs-slide="'+t.identifier+'">'+s+"</div>"}return e+="</div></div>",this.setup.$carousel=(0,i.default)(e),this.setup.$carousel.find(".carousel-item").first().addClass("active"),this.setup.$carousel}}let d;try{window.opener&&window.opener.TYPO3&&window.opener.TYPO3.Wizard&&(d=window.opener.TYPO3.Wizard),parent&&parent.window.TYPO3&&parent.window.TYPO3.Wizard&&(d=parent.window.TYPO3.Wizard),top&&top.TYPO3&&top.TYPO3.Wizard&&(d=top.TYPO3.Wizard)}catch(e){}return d||(d=new n,"undefined"!=typeof TYPO3&&(TYPO3.Wizard=d)),d}));