/*
 * 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},(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=(0,s.default)("<p />").html(t);void 0!==e&&e.length>0&&o.prepend((0,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=(0,s.default)("<li />",{role:"presentation",class:"nav-item","data-identifier":l}).append((0,s.default)("<a />",{"aria-controls":l,"data-bs-toggle":"tab",class:"nav-link",href:"#"+l,role:"tab"}).text(n+" ").append((0,s.default)("<span />",{class:"badge"}))).on("shown.bs.tab",t=>{(0,s.default)(t.currentTarget).find(".badge").text("")}),d.append(c),i.append((0,s.default)("<div />",{role:"tabpanel",class:"tab-pane",id:l}).append((0,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=(0,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=(0,s.default)("<div />",{id:"typo3-debug-console"}).append((0,s.default)("<div />",{class:"t3js-topbar topbar"}).append((0,s.default)("<p />",{class:"float-start"}).text(" TYPO3 Debug Console").prepend((0,s.default)("<span />",{class:"fa fa-terminal topbar-icon"})).append((0,s.default)("<span />",{class:"badge"})),(0,s.default)("<div />",{class:"t3js-buttons btn-group float-end"})),(0,s.default)("<div />").append((0,s.default)("<div />",{role:"tabpanel"}).append((0,s.default)("<ul />",{class:"nav nav-tabs t3js-debuggroups",role:"tablist"})),(0,s.default)("<div />",{class:"tab-content t3js-debugcontent"}))),this.addButton((0,s.default)("<button />",{class:"btn btn-default btn-sm "+(this.settings.autoscroll?"active":""),title:TYPO3.lang["debuggerconsole.autoscroll"]}).append((0,s.default)("<span />",{class:"t3-icon fa fa-magnet"})),()=>{(0,s.default)(this).button("toggle"),this.settings.autoscroll=!this.settings.autoscroll}).addButton((0,s.default)("<button />",{class:"btn btn-default btn-sm",title:TYPO3.lang["debuggerconsole.toggle.collapse"]}).append((0,s.default)("<span />",{class:"t3-icon fa fa-chevron-down"})),t=>{let e=(0,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((0,s.default)("<button />",{class:"btn btn-default btn-sm",title:TYPO3.lang["debuggerconsole.clear"]}).append((0,s.default)("<span />",{class:"t3-icon fa fa-undo"})),()=>{this.flush()}).addButton((0,s.default)("<button />",{class:"btn btn-default btn-sm",title:TYPO3.lang["debuggerconsole.close"]}).append((0,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=(0,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}));