import { append, $ } from "../../../../base/browser/dom.mjs";
import { ActionBar } from "../../../../base/browser/ui/actionbar/actionbar.mjs";
import { DisposableStore } from "../../../../base/common/lifecycle.mjs";
import { suggestWidgetStatusbarMenu } from "./suggest.mjs";
import { localize } from "../../../../nls.mjs";
import { MenuEntryActionViewItem } from "../../../../platform/actions/browser/menuEntryActionViewItem.mjs";
import { IMenuService, MenuItemAction } from "../../../../platform/actions/common/actions.mjs";
import { IContextKeyService } from "../../../../platform/contextkey/common/contextkey.mjs";
import { IInstantiationService } from "../../../../platform/instantiation/common/instantiation.mjs";
var __decorate = globalThis && globalThis.__decorate || function(decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1; i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = globalThis && globalThis.__param || function(paramIndex, decorator) {
  return function(target, key) {
    decorator(target, key, paramIndex);
  };
};
class StatusBarViewItem extends MenuEntryActionViewItem {
  updateLabel() {
    const kb = this._keybindingService.lookupKeybinding(this._action.id, this._contextKeyService);
    if (!kb) {
      return super.updateLabel();
    }
    if (this.label) {
      this.label.textContent = localize("ddd", "{0} ({1})", this._action.label, StatusBarViewItem.symbolPrintEnter(kb));
    }
  }
  static symbolPrintEnter(kb) {
    var _a;
    return (_a = kb.getLabel()) === null || _a === void 0 ? void 0 : _a.replace(/\benter\b/gi, "⏎");
  }
}
let SuggestWidgetStatus = class SuggestWidgetStatus2 {
  constructor(container, instantiationService, _menuService, _contextKeyService) {
    this._menuService = _menuService;
    this._contextKeyService = _contextKeyService;
    this._menuDisposables = new DisposableStore();
    this.element = append(container, $(".suggest-status-bar"));
    const actionViewItemProvider = (action) => {
      return action instanceof MenuItemAction ? instantiationService.createInstance(StatusBarViewItem, action, void 0) : void 0;
    };
    this._leftActions = new ActionBar(this.element, { actionViewItemProvider });
    this._rightActions = new ActionBar(this.element, { actionViewItemProvider });
    this._leftActions.domNode.classList.add("left");
    this._rightActions.domNode.classList.add("right");
  }
  dispose() {
    this._menuDisposables.dispose();
    this.element.remove();
  }
  show() {
    const menu = this._menuService.createMenu(suggestWidgetStatusbarMenu, this._contextKeyService);
    const renderMenu = () => {
      const left = [];
      const right = [];
      for (let [group, actions] of menu.getActions()) {
        if (group === "left") {
          left.push(...actions);
        } else {
          right.push(...actions);
        }
      }
      this._leftActions.clear();
      this._leftActions.push(left);
      this._rightActions.clear();
      this._rightActions.push(right);
    };
    this._menuDisposables.add(menu.onDidChange(() => renderMenu()));
    this._menuDisposables.add(menu);
  }
  hide() {
    this._menuDisposables.clear();
  }
};
SuggestWidgetStatus = __decorate([
  __param(1, IInstantiationService),
  __param(2, IMenuService),
  __param(3, IContextKeyService)
], SuggestWidgetStatus);
export {
  SuggestWidgetStatus
};
