/*
 * 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 h}from"lit";import{property as c,customElement as p}from"lit/decorators.js";import{PseudoButtonLitElement as m}from"@typo3/backend/element/pseudo-button.js";import y from"@typo3/backend/storage/persistent.js";import f from"~labels/backend.layout";import"@typo3/backend/element/icon-element.js";import{HiddenContentCountChangedEvent as u}from"@typo3/backend/layout-module/page-layout-event.js";var l=function(r,t,n,e){var i=arguments.length,o=i<3?t:e===null?e=Object.getOwnPropertyDescriptor(t,n):e,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,t,n,e);else for(var d=r.length-1;d>=0;d--)(a=r[d])&&(o=(i<3?a(o):i>3?a(t,n,o):a(t,n))||o);return i>3&&o&&Object.defineProperty(t,n,o),o};let s=class extends m{constructor(){super(...arguments),this.active=!1,this.count=0,this.onCountChanged=t=>{this.count=t.detail.count}}connectedCallback(){super.connectedCallback(),this.syncDropdownToggleStatus(),document.addEventListener(u.eventName,this.onCountChanged)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(u.eventName,this.onCountChanged)}updated(t){t.has("active")&&this.syncDropdownToggleStatus()}createRenderRoot(){return this}render(){return h`<span class=dropdown-item-status></span><typo3-backend-icon identifier=actions-eye size=small></typo3-backend-icon>${f.get("hiddenCE")} (${this.count})`}buttonActivated(){if(this.hasAttribute("disabled"))return;this.setAttribute("disabled","");const t=!this.active,n=document.querySelectorAll(".t3js-hidden-record");for(const e of n){e.style.display="flow-root";const i=e.scrollHeight;e.style.overflow="clip",t?(e.addEventListener("transitionend",()=>{e.style.display="",e.style.overflow="",e.style.height=""},{once:!0}),e.style.height=i+"px"):(e.addEventListener("transitionend",()=>{e.style.display="none",e.style.overflow=""},{once:!0}),requestAnimationFrame(()=>{e.style.height=i+"px",requestAnimationFrame(()=>{e.style.height="0px"})}))}this.active=t,y.set("moduleData.web_layout.showHidden",t?"1":"0").then(()=>{this.removeAttribute("disabled")})}syncDropdownToggleStatus(){this.dataset.dropdowntoggleStatus=this.active?"active":"inactive"}};l([c({type:Boolean,reflect:!0})],s.prototype,"active",void 0),l([c({type:Number})],s.prototype,"count",void 0),s=l([p("typo3-backend-page-layout-toggle-hidden")],s);export{s as PageLayoutToggleHidden};
