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