text: import*as Common from"../common/common.js";import*as ARIAUtils from"./ARIAUtils.js";import{Keys}from"./KeyboardShortcut.js";import{createTextButton}from"./UIUtils.js";import{createShadowRootWithCoreStyles}from"./utils/create-shadow-root-with-core-styles.js";import{Widget}from"./Widget.js";export class Infobar{constructor(t,e,i,s){if(this.element=createElementWithClass("div","flex-none"),this._shadowRoot=createShadowRootWithCoreStyles(this.element,"ui/infobar.css"),this._contentElement=this._shadowRoot.createChild("div","infobar infobar-"+t),this._mainRow=this._contentElement.createChild("div","infobar-main-row"),this._detailsRows=this._contentElement.createChild("div","infobar-details-rows hidden"),this._infoContainer=this._mainRow.createChild("div","infobar-info-container"),this._infoMessage=this._infoContainer.createChild("div","infobar-info-message"),this._infoMessage.createChild("div",t+"-icon icon"),this._infoText=this._infoMessage.createChild("div","infobar-info-text"),this._infoText.textContent=e,ARIAUtils.markAsAlert(this._infoText),this._actionContainer=this._infoContainer.createChild("div","infobar-info-actions"),i)for(const t of i){const e=this._actionCallbackFactory(t);let i="infobar-button";t.highlight&&(i+=" primary-button");const s=createTextButton(t.text,e,i);this._actionContainer.appendChild(s)}if(this._disableSetting=s||null,s){const t=createTextButton(ls`Don't show again`,this._onDisable.bind(this),"infobar-button");this._actionContainer.appendChild(t)}this._closeContainer=this._mainRow.createChild("div","infobar-close-container"),this._toggleElement=createTextButton(ls`Learn more`,this._onToggleDetails.bind(this),"link-style devtools-link hidden"),this._closeContainer.appendChild(this._toggleElement),this._closeButton=this._closeContainer.createChild("div","close-button","dt-close-button"),this._closeButton.setTabbable(!0),ARIAUtils.setDescription(this._closeButton,ls`Close`),self.onInvokeElement(this._closeButton,this.dispose.bind(this)),this._contentElement.tabIndex=0,ARIAUtils.setAccessibleName(this._contentElement,e),this._contentElement.addEventListener("keydown",t=>t.keyCode===Keys.Esc.code?(this.dispose(),void t.consume()):t.target===this._contentElement&&"Enter"===t.key?(this._onToggleDetails(),void t.consume()):void 0),this._closeCallback=null}static create(t,e,i,s){return s&&s.get()?null:new Infobar(t,e,i,s)}dispose(){this.element.remove(),this._onResize(),this._closeCallback&&this._closeCallback.call(null)}setText(t){this._infoText.textContent=t,this._onResize()}setCloseCallback(t){this._closeCallback=t}setParentView(t){this._parentView=t}_actionCallbackFactory(t){return t.delegate?t.dismiss?(()=>{t.delegate(),this.dispose()}).bind(this):t.delegate:t.dismiss?this.dispose.bind(this):()=>{}}_onResize(){this._parentView&&this._parentView.doResize()}_onDisable(){this._disableSetting.set(!0),this.dispose()}_onToggleDetails(){this._detailsRows.classList.remove("hidden"),this._toggleElement.remove(),this._onResize()}createDetailsRowMessage(t){this._toggleElement.classList.remove("hidden");const e=this._detailsRows.createChild("div","infobar-details-row").createChild("span","infobar-row-message");return e.textContent=t||"",e}}export let InfobarAction;export const Type={Warning:"warning",Info:"info"};