"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("./bannerController.css.js");
const dom = require("../../../../base/browser/dom.js");
const actionbar = require("../../../../base/browser/ui/actionbar/actionbar.js");
const actions = require("../../../../base/common/actions.js");
const lifecycle = require("../../../../base/common/lifecycle.js");
const markdownRenderer = require("../../markdownRenderer/browser/markdownRenderer.js");
const instantiation = require("../../../../platform/instantiation/common/instantiation.js");
const link = require("../../../../platform/opener/browser/link.js");
const iconRegistry = require("../../../../platform/theme/common/iconRegistry.js");
const themeService = require("../../../../platform/theme/common/themeService.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);
  };
};
const BANNER_ELEMENT_HEIGHT = 26;
exports.BannerController = class BannerController extends lifecycle.Disposable {
  constructor(_editor, instantiationService) {
    super();
    this._editor = _editor;
    this.instantiationService = instantiationService;
    this.banner = this._register(this.instantiationService.createInstance(Banner));
  }
  hide() {
    this._editor.setBanner(null, 0);
    this.banner.clear();
  }
  show(item) {
    this.banner.show(Object.assign(Object.assign({}, item), { onClose: () => {
      this.hide();
      if (item.onClose) {
        item.onClose();
      }
    } }));
    this._editor.setBanner(this.banner.element, BANNER_ELEMENT_HEIGHT);
  }
};
exports.BannerController = __decorate([
  __param(1, instantiation.IInstantiationService)
], exports.BannerController);
let Banner = class Banner2 extends lifecycle.Disposable {
  constructor(instantiationService) {
    super();
    this.instantiationService = instantiationService;
    this.markdownRenderer = this.instantiationService.createInstance(markdownRenderer.MarkdownRenderer, {});
    this.element = dom.$("div.editor-banner");
    this.element.tabIndex = 0;
  }
  getAriaLabel(item) {
    if (item.ariaLabel) {
      return item.ariaLabel;
    }
    if (typeof item.message === "string") {
      return item.message;
    }
    return void 0;
  }
  getBannerMessage(message) {
    if (typeof message === "string") {
      const element = dom.$("span");
      element.innerText = message;
      return element;
    }
    return this.markdownRenderer.render(message).element;
  }
  clear() {
    dom.clearNode(this.element);
  }
  show(item) {
    dom.clearNode(this.element);
    const ariaLabel = this.getAriaLabel(item);
    if (ariaLabel) {
      this.element.setAttribute("aria-label", ariaLabel);
    }
    const iconContainer = dom.append(this.element, dom.$("div.icon-container"));
    iconContainer.setAttribute("aria-hidden", "true");
    if (item.icon) {
      iconContainer.appendChild(dom.$(`div${themeService.ThemeIcon.asCSSSelector(item.icon)}`));
    }
    const messageContainer = dom.append(this.element, dom.$("div.message-container"));
    messageContainer.setAttribute("aria-hidden", "true");
    messageContainer.appendChild(this.getBannerMessage(item.message));
    this.messageActionsContainer = dom.append(this.element, dom.$("div.message-actions-container"));
    if (item.actions) {
      for (const action of item.actions) {
        this._register(this.instantiationService.createInstance(link.Link, this.messageActionsContainer, Object.assign(Object.assign({}, action), { tabIndex: -1 }), {}));
      }
    }
    const actionBarContainer = dom.append(this.element, dom.$("div.action-container"));
    this.actionBar = this._register(new actionbar.ActionBar(actionBarContainer));
    this.actionBar.push(this._register(new actions.Action("banner.close", "Close Banner", themeService.ThemeIcon.asClassName(iconRegistry.widgetClose), true, () => {
      if (typeof item.onClose === "function") {
        item.onClose();
      }
    })), { icon: true, label: false });
    this.actionBar.setFocusable(false);
  }
};
Banner = __decorate([
  __param(0, instantiation.IInstantiationService)
], Banner);
