/*
 * 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 p from"@typo3/core/ajax/ajax-request.js";import e from"@typo3/backend/storage/client.js";import{Sizes as h,States as f,MarkupIdentifiers as d}from"@typo3/backend/enum/icon-types.js";import{css as g}from"lit";import{DedupeAsyncTask as y}from"@typo3/core/cache/dedupe-async-task.js";class z{static getStyles(){return[g`:host{display:inline-flex;align-items:center;justify-content:center;height:var(--icon-size,1em);width:var(--icon-size,1em);line-height:var(--icon-size,1em);vertical-align:-22%}:host([raw]) .icon-size-default,:host([size=default]){--icon-size:1em}:host([raw]) .icon-size-small,:host([size=small]){--icon-size:var(--icon-size-small,16px)}:host([raw]) .icon-size-medium,:host([size=medium]){--icon-size:var(--icon-size-medium,32px)}:host([raw]) .icon-size-large,:host([size=large]){--icon-size:var(--icon-size-large,48px)}:host([raw]) .icon-size-mega,:host([size=mega]){--icon-size:var(--icon-size-mega,64px)}.icon{position:relative;display:flex;overflow:hidden;white-space:nowrap;color:var(--icon-color-primary,currentColor);height:var(--icon-size,1em);width:var(--icon-size,1em);line-height:var(--icon-size,1em);flex-shrink:0}.icon img,.icon svg{display:block;height:100%;width:100%}.icon *{display:block;line-height:inherit}.icon-markup{display:block;top:0;left:0}.icon-markup,.icon-overlay{position:absolute;text-align:center;right:0;bottom:0}.icon-overlay{height:68.75%;width:68.75%}.icon-spin .icon-markup{-webkit-animation:icon-spin 2s linear infinite;animation:icon-spin 2s linear infinite}@keyframes icon-spin{0%{transform:rotate(0)}to{transform:rotate(1turn)}}.icon-bidi:dir(rtl) .icon-markup{transform:scaleX(-1)}.icon-state-disabled .icon-markup{opacity:var(--icon-opacity-disabled,.5)}.icon-unify{line-height:var(--icon-size,1em);font-size:calc(var(--icon-size, 1em)*var(--icon-unify-modifier, .86))}.icon-overlay .icon-unify{line-height:calc(var(--icon-size, 1em)/1.6);font-size:calc((var(--icon-size, 1em)/1.6)*var(--icon-unify-modifier, .86))}`]}}class v{constructor(){this.sizes=h,this.states=f,this.markupIdentifiers=d,this.promiseCache=new y}async getIcon(t,n,c,s,o,i){n=n||h.default,s=s||f.default,o=o||d.default;const a=[t,n,c,s,o],l=a.join("_"),m=TYPO3?.settings?.cache?.iconCacheIdentifier??document.documentElement.dataset.iconCacheIdentifier;(!e.isset("icon_registry_cache_identifier")||e.get("icon_registry_cache_identifier")!==m)&&(e.unsetByPrefix("icon_"),e.set("icon_registry_cache_identifier",m));try{return await this.fetchFromLocal(l)}catch{return await this.fetchFromRemote(a,l,i)}}fetchFromRemote(t,n,c){return this.promiseCache.get(n,async s=>{const o=await new p(TYPO3.settings.ajaxUrls.icons).withQueryArguments({icon:JSON.stringify(t)}).get({signal:s}),i=await o.resolve();return!o.response.redirected&&i.startsWith("<span")&&i.includes("t3js-icon")&&i.includes('<span class="icon-markup">')&&e.set("icon_"+n,i),i},c)}fetchFromLocal(t){return e.isset("icon_"+t)?Promise.resolve(e.get("icon_"+t)):Promise.reject()}}let r;r||(r=new v,typeof TYPO3<"u"&&(TYPO3.Icons=r));var w=r;export{z as IconStyles,w as default};
