/*
 * 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"@typo3/backend/wizard/wizard.js";import{property as p,query as y,state as l,customElement as w}from"lit/decorators.js";import{TargetLanguageStep as b}from"@typo3/backend/localization/steps/target-language-step.js";import{SourceLanguageStep as z}from"@typo3/backend/localization/steps/source-language-step.js";import{ContentRecordSelectionStep as S}from"@typo3/backend/localization/steps/content-record-selection-step.js";import{ModeStep as g}from"@typo3/backend/localization/steps/mode-step.js";import{HandlerSelectionStep as v}from"@typo3/backend/localization/steps/handler-selection-step.js";import{Task as T}from"@lit/task";import k from"@typo3/core/ajax/ajax-request.js";import m from"@typo3/backend/modal.js";import{LitElement as L,html as u}from"lit";import{AutoAdvanceEvent as D}from"@typo3/backend/wizard/events/auto-advance-event.js";import{StepSummaryEvent as h}from"@typo3/backend/wizard/events/step-summary-event.js";import{LocalizationSubmissionService as $}from"@typo3/backend/localization/finisher/localization-submission-service.js";import f from"~labels/backend.wizards.localization";var n=function(s,t,e,o){var i=arguments.length,a=i<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,d;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(s,t,e,o);else for(var c=s.length-1;c>=0;c--)(d=s[c])&&(a=(i<3?d(a):i>3?d(t,e,a):d(t,e))||a);return i>3&&a&&Object.defineProperty(t,e,a),a};let r=class extends L{constructor(){super(...arguments),this.steps=[],this.recordInfoTask=new T(this,{task:async([t,e])=>{try{const i=await(await new k(TYPO3.settings.ajaxUrls.wizard_localization_get_record).withQueryArguments({recordType:t,recordUid:e}).get()).resolve();return this.closest("typo3-backend-modal")!==null&&m.currentModal&&(m.currentModal.modalTitle=`${f.get("localization_wizard.modal.title.record_prefix")} ${i.typeName}, ${i.title}`),i}catch(o){throw console.warn("Failed to fetch record info:",o),o}},args:()=>[this.recordType,this.recordUid]})}connectedCallback(){super.connectedCallback(),this.addEventListener(h.eventName,this.handleStepSummary)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(h.eventName,this.handleStepSummary)}firstUpdated(t){super.firstUpdated(t);const e={wizard:this.wizard,recordType:this.recordType,recordUid:this.recordUid,recordInfo:this.recordInfoTask.value,targetLanguage:this.targetLanguage,getStoreData:this.wizard.getStoreData.bind(this.wizard),setStoreData:this.wizard.setStoreData.bind(this.wizard),clearStoreData:this.wizard.clearStoreData.bind(this.wizard),getDataStore:this.wizard.getDataStore.bind(this.wizard),dispatchAutoAdvance:()=>this.wizard.dispatchEvent(new D)};this.submissionService=new $(e),this.steps=[new b(e),new z(e),...this.recordType==="pages"?[new S(e)]:[],new g(e),new v(e)]}createRenderRoot(){return this}render(){return u`<typo3-backend-wizard .steps=${this.steps} .submissionService=${this.submissionService} confirm-button-label=${f.get("localization_wizard.buttons.localize")}></typo3-backend-wizard>`}handleStepSummary(t){const e=this.recordInfoTask.value;t.detail.summaryData=[{label:e.typeName,value:u`<typo3-backend-icon identifier=${e.icon} size=small class=me-1></typo3-backend-icon>${e.title} <code>[${e.type}:${e.uid}]</code>`},...t.detail.summaryData]}};n([p({type:String,attribute:"record-type"})],r.prototype,"recordType",void 0),n([p({type:Number,attribute:"record-uid"})],r.prototype,"recordUid",void 0),n([p({type:Number,attribute:"target-language"})],r.prototype,"targetLanguage",void 0),n([y("typo3-backend-wizard")],r.prototype,"wizard",void 0),n([l()],r.prototype,"steps",void 0),n([l()],r.prototype,"submissionService",void 0),r=n([w("typo3-backend-localization-wizard")],r);export{r as LocalizationWizard};
