/*
 * 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 v from"@typo3/backend/live-search/live-search-configurator.js";import h from"@typo3/backend/viewport.js";import{property as u,query as p,customElement as m}from"lit/decorators.js";import{LitElement as f,html as d,nothing as y}from"lit";import{lll as b}from"@typo3/core/lit-helper.js";import"@typo3/backend/live-search/element/result/item/item-container.js";import"@typo3/backend/live-search/element/result/result-detail-container.js";var s=function(l,e,i,n){var t=arguments.length,r=t<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,i):n,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(l,e,i,n);else for(var c=l.length-1;c>=0;c--)(a=l[c])&&(r=(t<3?a(r):t>3?a(e,i,r):a(e,i))||r);return t>3&&r&&Object.defineProperty(e,i,r),r};const k="typo3-backend-live-search-result-container";let o=class extends f{constructor(){super(...arguments),this.results=null,this.loading=!1}connectedCallback(){super.connectedCallback(),this.addEventListener("livesearch:request-actions",this.onActionsRequested),this.addEventListener("livesearch:invoke-action",this.onActionInvoked)}disconnectedCallback(){this.removeEventListener("livesearch:request-actions",this.onActionsRequested),this.removeEventListener("livesearch:invoke-action",this.onActionInvoked),super.disconnectedCallback()}createRenderRoot(){return this}render(){return this.loading?d`<div class="d-flex flex-fill align-items-center justify-content-center"><typo3-backend-spinner size=large></typo3-backend-spinner></div>`:this.results===null?y:this.results.length===0?d`<div class="alert alert-info">${b("liveSearch_listEmptyText")}</div>`:d`<typo3-backend-live-search-result-item-container .results=${this.results}></typo3-backend-live-search-result-item-container><typo3-backend-live-search-result-item-detail-container></typo3-backend-live-search-result-item-detail-container>`}onActionsRequested(e){this.resultDetailContainer.resultItem=e.detail.resultItem}onActionInvoked(e){const i=v.getInvokeHandlers(),n=e.detail.resultItem,t=e.detail.action;t!==void 0&&(typeof i[n.provider+"_"+t.identifier]=="function"?i[n.provider+"_"+t.identifier](n,t):h.ContentContainer.setUrl(t.url),this.dispatchEvent(new CustomEvent("live-search:item-chosen",{detail:{resultItem:n}})))}};s([u({type:Object})],o.prototype,"results",void 0),s([u({type:Boolean,attribute:!1})],o.prototype,"loading",void 0),s([p("typo3-backend-live-search-result-item-container")],o.prototype,"itemContainer",void 0),s([p("typo3-backend-live-search-result-item-detail-container")],o.prototype,"resultDetailContainer",void 0),o=s([m("typo3-backend-live-search-result-container")],o);export{o as ResultContainer,k as componentName};
