/*
 * 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/document-service.js";import{property as v,customElement as d}from"lit/decorators.js";import{LitElement as h,html as a,css as y}from"lit";import"@typo3/backend/live-search/element/result/item/action/action.js";var u=function(r,e,t,i){var o=arguments.length,n=o<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,e,t,i);else for(var l=r.length-1;l>=0;l--)(s=r[l])&&(n=(o<3?s(n):o>3?s(e,t,n):s(e,t))||n);return o>3&&n&&Object.defineProperty(e,t,n),n};const f="typo3-backend-live-search-result-item-action-container";let c=class extends h{constructor(){super(...arguments),this.resultItem=null}createRenderRoot(){return this}render(){return a`<typo3-backend-live-search-result-action-list>${this.resultItem.actions.map(e=>this.renderActionItem(this.resultItem,e))}</typo3-backend-live-search-result-action-list>`}renderActionItem(e,t){return a`<typo3-backend-live-search-result-item-action .resultItem=${e} .resultItemAction=${t} @click=${()=>this.invokeAction(this.resultItem,t)}></typo3-backend-live-search-result-item-action>`}invokeAction(e,t){this.closest("typo3-backend-live-search-result-container").dispatchEvent(new CustomEvent("livesearch:invoke-action",{detail:{resultItem:e,action:t}}))}};u([v({type:Object,attribute:!1})],c.prototype,"resultItem",void 0),c=u([d("typo3-backend-live-search-result-item-action-container")],c);let m=class extends h{static{this.styles=y`:host{display:block}`}async connectedCallback(){await p.ready(),this.parentContainer=this.closest("typo3-backend-live-search-result-container"),this.resultItemContainer=this.parentContainer.querySelector("typo3-backend-live-search-result-item-container"),super.connectedCallback(),this.addEventListener("keydown",this.handleKeyDown),this.addEventListener("keyup",this.handleKeyUp)}disconnectedCallback(){this.removeEventListener("keydown",this.handleKeyDown),this.removeEventListener("keyup",this.handleKeyUp),super.disconnectedCallback()}render(){return a`<slot></slot>`}handleKeyDown(e){if(!["ArrowDown","ArrowUp","ArrowLeft"].includes(e.key)||document.activeElement.tagName.toLowerCase()!=="typo3-backend-live-search-result-item-action")return;e.preventDefault();let t;e.key==="ArrowDown"?t=document.activeElement.nextElementSibling:e.key==="ArrowUp"?t=document.activeElement.previousElementSibling:e.key==="ArrowLeft"&&(t=this.resultItemContainer.querySelector("typo3-backend-live-search-result-item.active")),t!==null&&t.focus()}handleKeyUp(e){if(!["Enter"," "].includes(e.key))return;e.preventDefault();const t=e.target;this.parentContainer.dispatchEvent(new CustomEvent("livesearch:invoke-action",{detail:{resultItem:t.resultItem,action:t.resultItemAction}}))}};m=u([d("typo3-backend-live-search-result-action-list")],m);export{c as ActionContainer,m as ActionList,f as componentName};
