import*as i18n from"../i18n/i18n.js";import*as ObjectUI from"../object_ui/object_ui.js";import*as TextEditor from"../text_editor/text_editor.js";import*as UI from"../ui/ui.js";const UIStrings={breakpointType:"Breakpoint type",breakpoint:"Breakpoint",conditionalBreakpoint:"Conditional breakpoint",logpoint:"Logpoint",expressionToCheckBeforePausingEg:"Expression to check before pausing, e.g. x > 5",pauseOnlyWhenTheConditionIsTrue:"Pause only when the condition is true",logMessageEgXIsX:"Log message, e.g. 'x is', x",logAMessageToConsoleDoNotBreak:"Log a message to Console, do not break"},str_=i18n.i18n.registerUIStrings("sources/BreakpointEditDialog.js",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class BreakpointEditDialog extends UI.Widget.Widget{constructor(t,i,e,o){super(!0),this.registerRequiredCSS("sources/breakpointEditDialog.css",{enableLegacyPatching:!0}),this._onFinish=o,this._finished=!1,this._editor=null,this.element.tabIndex=-1;const n=LogpointPrefix,s=LogpointSuffix;this._isLogpoint=i.startsWith(n)&&i.endsWith(s),this._isLogpoint&&(i=i.substring(n.length,i.length-s.length)),this._isLogpoint=this._isLogpoint||e,this.element.classList.add("sources-edit-breakpoint-dialog");const r=new UI.Toolbar.Toolbar("source-frame-breakpoint-toolbar",this.contentElement);r.appendText(`Line ${t+1}:`),this._typeSelector=new UI.Toolbar.ToolbarComboBox(this._onTypeChanged.bind(this),i18nString(UIStrings.breakpointType)),this._typeSelector.createOption(i18nString(UIStrings.breakpoint),BreakpointType.Breakpoint);const a=this._typeSelector.createOption(i18nString(UIStrings.conditionalBreakpoint),BreakpointType.Conditional),p=this._typeSelector.createOption(i18nString(UIStrings.logpoint),BreakpointType.Logpoint);this._typeSelector.select(this._isLogpoint?p:a),r.appendToolbarItem(this._typeSelector);const d=TextEditor.CodeMirrorTextEditor.CodeMirrorTextEditorFactory.instance(),l={lineNumbers:!1,lineWrapping:!0,mimeType:"javascript",autoHeight:!0,bracketMatchingSetting:void 0,devtoolsAccessibleName:void 0,padBottom:void 0,maxHighlightLength:void 0,placeholder:void 0,lineWiseCopyCut:void 0,inputStyle:void 0};this._editor=d.createEditor(l),this._updatePlaceholder(),this._editor.widget().element.classList.add("condition-editor"),this._editor.configureAutocomplete(ObjectUI.JavaScriptAutocomplete.JavaScriptAutocompleteConfig.createConfigForEditor(this._editor)),i&&this._editor.setText(i),this._editor.widget().markAsExternallyManaged(),this._editor.widget().show(this.contentElement),this._editor.setSelection(this._editor.fullRange()),this._editor.widget().focus(),this._editor.widget().element.addEventListener("keydown",this._onKeyDown.bind(this),!0),this.element.addEventListener("blur",(t=>{t.relatedTarget&&!t.relatedTarget.isSelfOrDescendant(this.element)&&this._finishEditing(!0)}),!0)}static _conditionForLogpoint(t){return`${LogpointPrefix}${t}${LogpointSuffix}`}_onTypeChanged(){const t=this._typeSelector.selectedOption();if(!t||!this._editor)return;const i=t.value;this._isLogpoint=i===BreakpointType.Logpoint,this._updatePlaceholder(),i===BreakpointType.Breakpoint&&(this._editor.setText(""),this._finishEditing(!0))}_updatePlaceholder(){const t=this._typeSelector.selectedOption();if(!t||!this._editor)return;const i=t.value;i===BreakpointType.Conditional?(this._editor.setPlaceholder(i18nString(UIStrings.expressionToCheckBeforePausingEg)),UI.Tooltip.Tooltip.install(this._typeSelector.element,i18nString(UIStrings.pauseOnlyWhenTheConditionIsTrue))):i===BreakpointType.Logpoint&&(this._editor.setPlaceholder(i18nString(UIStrings.logMessageEgXIsX)),UI.Tooltip.Tooltip.install(this._typeSelector.element,i18nString(UIStrings.logAMessageToConsoleDoNotBreak)))}_finishEditing(t){if(this._finished)return;if(this._finished=!0,!this._editor)return;this._editor.widget().detach();let i=this._editor.text();this._isLogpoint&&(i=BreakpointEditDialog._conditionForLogpoint(i)),this._onFinish({committed:t,condition:i})}async _onKeyDown(t){if(t instanceof KeyboardEvent&&this._editor){if("Enter"===t.key&&!t.shiftKey){t.consume(!0);const i=this._editor.text();t.ctrlKey||await ObjectUI.JavaScriptAutocomplete.JavaScriptAutocomplete.isExpressionComplete(i)?this._finishEditing(!0):this._editor.newlineAndIndent()}isEscKey(t)&&(this._finishEditing(!1),t.stopImmediatePropagation())}}}export const LogpointPrefix="/** DEVTOOLS_LOGPOINT */ console.log(";export const LogpointSuffix=")";export const BreakpointType={Breakpoint:"Breakpoint",Conditional:"Conditional",Logpoint:"Logpoint"};