/* * 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{html as s}from"lit";import{live as g}from"lit/directives/live.js";import{Task as u,TaskStatus as d}from"@lit/task";import h from"@typo3/core/ajax/ajax-request.js";import"@typo3/backend/localization/localization-wizard.js";import r from"~labels/backend.wizards.localization";class c{constructor(t){this.context=t,this.key="targetLanguage",this.title=r.get("step.target_language.title"),this.autoAdvance=!0,this.hasDispatchedAutoAdvance=!1,this.selectedLanguage=null,this.task=new u(this.context.wizard,{task:async([a,e])=>{try{let i=await(await new h(TYPO3.settings.ajaxUrls.wizard_localization_get_targets).withQueryArguments({recordType:a,recordUid:e}).get()).resolve();const l=this.context.targetLanguage;return l!=null&&(i=i.filter(o=>o.uid===l)),i}catch(n){return console.warn("Failed to fetch target languages:",n),[]}},args:()=>[this.context.recordType,this.context.recordUid],autoRun:!1})}isComplete(){return this.getValue()!=null}render(){return this.task.status===d.INITIAL&&this.task.run(),this.task.render({complete:t=>{if(this.getValue()==null){const e=this.context.getStoreData("targetLanguage");e!=null&&this.setValue(e)}let a=!1;if(this.getValue()==null){const e=this.context.targetLanguage;if(e!=null?(this.setValue(e),a=!0):t.length>0&&(this.setValue(t[0].uid),t.length===1&&(a=!0)),a&&!this.hasDispatchedAutoAdvance)return this.hasDispatchedAutoAdvance=!0,this.context.dispatchAutoAdvance(),this.context.wizard.renderLoader()}return t.length===0?s`
${r.get("step.target_language.none_available")}
${r.get("step.target_language.description")}