/*
 * 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!
 */
var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};define(["require","exports","jquery"],(function(t,e,s){"use strict";s=__importDefault(s);class a{constructor(){this.settings={autoscroll:!0},s.default(()=>{this.createDom()})}static incrementInactiveTabCounter(t){if(!t.hasClass("active")){const e=t.find(".badge");let s=parseInt(e.text(),10);isNaN(s)&&(s=0),e.text(++s)}}add(t,e,n){this.attachToViewport();const o=s.default("<p />").html(t);void 0!==e&&e.length>0&&o.prepend(s.default("<strong />").text(e)),void 0!==n&&0!==n.length||(n="Debug");const l="debugtab-"+n.toLowerCase().replace(/\W+/g,"-"),d=this.$consoleDom.find(".t3js-debuggroups"),i=this.$consoleDom.find(".t3js-debugcontent");let c=this.$consoleDom.find(".t3js-debuggroups li[data-identifier="+l+"]");0===c.length&&(c=s.default("<li />",{role:"presentation",class:"nav-item","data-identifier":l}).append(s.default("<a />",{"aria-controls":l,"data-bs-toggle":"tab",class:"nav-link",href:"#"+l,role:"tab"}).text(n+" ").append(s.default("<span />",{class:"badge"}))).on("shown.bs.tab",t=>{s.default(t.currentTarget).find(".badge").text("")}),d.append(c),i.append(s.default("<div />",{role:"tabpanel",class:"tab-pane",id:l}).append(s.default("<div />",{class:"t3js-messages messages"})))),0===d.find(".active").length&&d.find("a:first").tab("show"),a.incrementInactiveTabCounter(c),this.incrementUnreadMessagesIfCollapsed();const r=s.default("#"+l+" .t3js-messages"),u=r.parent().hasClass("active");r.append(o),this.settings.autoscroll&&u&&r.scrollTop(r.prop("scrollHeight"))}createDom(){void 0===this.$consoleDom&&(this.$consoleDom=s.default("<div />",{id:"typo3-debug-console"}).append(s.default("<div />",{class:"t3js-topbar topbar"}).append(s.default("<p />",{class:"pull-left"}).text(" TYPO3 Debug Console").prepend(s.default("<span />",{class:"fa fa-terminal topbar-icon"})).append(s.default("<span />",{class:"badge"})),s.default("<div />",{class:"t3js-buttons btn-group pull-right"})),s.default("<div />").append(s.default("<div />",{role:"tabpanel"}).append(s.default("<ul />",{class:"nav nav-tabs t3js-debuggroups",role:"tablist"})),s.default("<div />",{class:"tab-content t3js-debugcontent"}))),this.addButton(s.default("<button />",{class:"btn btn-default btn-sm "+(this.settings.autoscroll?"active":""),title:TYPO3.lang["debuggerconsole.autoscroll"]}).append(s.default("<span />",{class:"t3-icon fa fa-magnet"})),()=>{s.default(this).button("toggle"),this.settings.autoscroll=!this.settings.autoscroll}).addButton(s.default("<button />",{class:"btn btn-default btn-sm",title:TYPO3.lang["debuggerconsole.toggle.collapse"]}).append(s.default("<span />",{class:"t3-icon fa fa-chevron-down"})),t=>{let e=s.default(t.currentTarget),a=e.find(".t3-icon"),n=this.$consoleDom.find(".t3js-topbar").next();n.toggle(),n.is(":visible")?(e.attr("title",TYPO3.lang["debuggerconsole.toggle.collapse"]),a.toggleClass("fa-chevron-down",!0).toggleClass("fa-chevron-up",!1),this.resetGlobalUnreadCounter()):(e.attr("title",TYPO3.lang["debuggerconsole.toggle.expand"]),a.toggleClass("fa-chevron-down",!1).toggleClass("fa-chevron-up",!0))}).addButton(s.default("<button />",{class:"btn btn-default btn-sm",title:TYPO3.lang["debuggerconsole.clear"]}).append(s.default("<span />",{class:"t3-icon fa fa-undo"})),()=>{this.flush()}).addButton(s.default("<button />",{class:"btn btn-default btn-sm",title:TYPO3.lang["debuggerconsole.close"]}).append(s.default("<span />",{class:"t3-icon fa fa-times"})),()=>{this.destroy(),this.createDom()}))}addButton(t,e){return t.on("click",e),this.$consoleDom.find(".t3js-buttons").append(t),this}attachToViewport(){const t=s.default(".t3js-scaffold-content");0===t.has(this.$consoleDom).length&&t.append(this.$consoleDom)}incrementUnreadMessagesIfCollapsed(){const t=this.$consoleDom.find(".t3js-topbar");if(t.next().is(":hidden")){const e=t.find(".badge");let s=parseInt(e.text(),10);isNaN(s)&&(s=0),e.text(++s)}}resetGlobalUnreadCounter(){this.$consoleDom.find(".t3js-topbar").find(".badge").text("")}flush(){const t=this.$consoleDom.find(".t3js-debuggroups"),e=this.$consoleDom.find(".t3js-debugcontent");t.children().remove(),e.children().remove()}destroy(){this.$consoleDom.remove(),this.$consoleDom=void 0}}const n=new a;return TYPO3.DebugConsole=n,n}));