"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const dom = require("../../../../base/browser/dom.js");
const actionbar = require("../../../../base/browser/ui/actionbar/actionbar.js");
const lifecycle = require("../../../../base/common/lifecycle.js");
const suggest = require("./suggest.js");
const nls = require("../../../../nls.js");
const menuEntryActionViewItem = require("../../../../platform/actions/browser/menuEntryActionViewItem.js");
const actions = require("../../../../platform/actions/common/actions.js");
const contextkey = require("../../../../platform/contextkey/common/contextkey.js");
const instantiation = require("../../../../platform/instantiation/common/instantiation.js");
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.MenuEntryActionViewItem {
  updateLabel() {
    const kb = this._keybindingService.lookupKeybinding(this._action.id, this._contextKeyService);
    if (!kb) {
      return super.updateLabel();
    }
    if (this.label) {
      this.label.textContent = nls.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, "⏎");
  }
}
exports.SuggestWidgetStatus = class SuggestWidgetStatus {
  constructor(container, instantiationService, _menuService, _contextKeyService) {
    this._menuService = _menuService;
    this._contextKeyService = _contextKeyService;
    this._menuDisposables = new lifecycle.DisposableStore();
    this.element = dom.append(container, dom.$(".suggest-status-bar"));
    const actionViewItemProvider = (action) => {
      return action instanceof actions.MenuItemAction ? instantiationService.createInstance(StatusBarViewItem, action, void 0) : void 0;
    };
    this._leftActions = new actionbar.ActionBar(this.element, { actionViewItemProvider });
    this._rightActions = new actionbar.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(suggest.suggestWidgetStatusbarMenu, this._contextKeyService);
    const renderMenu = () => {
      const left = [];
      const right = [];
      for (let [group, actions2] of menu.getActions()) {
        if (group === "left") {
          left.push(...actions2);
        } else {
          right.push(...actions2);
        }
      }
      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();
  }
};
exports.SuggestWidgetStatus = __decorate([
  __param(1, instantiation.IInstantiationService),
  __param(2, actions.IMenuService),
  __param(3, contextkey.IContextKeyService)
], exports.SuggestWidgetStatus);
