/*
 * 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","TYPO3/CMS/Backend/FormEngine","bootstrap"],(function(t,e,i,a){"use strict";i=__importDefault(i);class l{constructor(){this.checkForReviewableField=()=>{const t=this,e=l.findInvalidField(),a=i.default("."+this.toggleButtonClass);if(e.length>0){const l=i.default("<div />",{class:"list-group"});e.each((function(){const e=i.default(this),a=e.find("[data-formengine-validation-rules]");let n=a.attr("id");void 0===n&&(n=a.parent().children("[id]").first().attr("id")),l.append(i.default("<a />",{class:"list-group-item "+t.fieldListItemClass,"data-field-id":n,href:"#"}).text(e.find(t.labelSelector).text()))})),a.removeClass("hidden");const n=a.data("bs.popover");n&&(n.options.html=!0,n.options.content=l.wrapAll("<div>").parent().html(),n.setContent(n.$tip),n.$tip.addClass(n.options.placement))}else a.addClass("hidden").popover("hide")},this.switchToField=t=>{t.preventDefault();const e=i.default(t.currentTarget).data("fieldId"),a=i.default("#"+e);a.parents('[id][role="tabpanel"]').each((function(){i.default('[aria-controls="'+i.default(this).attr("id")+'"]').tab("show")})),a.focus()},this.toggleButtonClass="t3js-toggle-review-panel",this.fieldListItemClass="t3js-field-item",this.labelSelector=".t3js-formengine-label",this.initialize()}static findInvalidField(){return i.default(document).find(".tab-content ."+a.Validation.errorClass)}static attachButtonToModuleHeader(t){const e=i.default(".t3js-module-docheader-bar-buttons").children().last().find('[role="toolbar"]'),a=i.default("<a />",{class:"btn btn-danger btn-sm hidden "+t.toggleButtonClass,href:"#",title:TYPO3.lang["buttons.reviewFailedValidationFields"]}).append(i.default("<span />",{class:"fa fa-fw fa-info"}));a.popover({container:"body",html:!0,placement:"bottom"}),e.prepend(a)}initialize(){const t=this,e=i.default(document);i.default(()=>{l.attachButtonToModuleHeader(t)}),e.on("click","."+this.fieldListItemClass,this.switchToField),e.on("t3-formengine-postfieldvalidation",this.checkForReviewableField)}}return new l}));