var __decorate = (this && this.__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;
};
import { h } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { createEnterKeyHandlerToTriggerClick } from '../../../../utils/accessibility';
import sidenavChevronRight from '../../icons/chevron-right';
import sidenavToggleButtonBg from '../../icons/toggle-button-bg';
import { VegaInternalIconManager } from '../../../../helpers/icon/internal-icon-manager';
import { VegaIconManager } from '../../../../helpers/icon/icon-manager';
/** Renders a collapsible button for a sidebar with specific functionality and styling. */
export class VegaSidenavCollapseButtonRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.collapseButtonRef = null;
    /**
     * The below method is e2e-test covered in
     * @see{module:vega-sidenav-e2e-mouse-enter-and-mouse-leave-and-click}
     * @see{module:vega-sidenav-desktop-click-icon-change-position}
     */
    /* istanbul ignore next */
    this.handleClickSidebarIcon = async () => {
      await this.host.toggle();
    };
  }
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-sidenav-e2e-openByDefault-resize-screen-size}
   */
  /* istanbul ignore next */
  /**
   * Update the visibility of the collapse button base on the property canCollapseSidenav
   *
   * @param {boolean} canCollapseSidenav The component could collapse or not
   */
  updateHandlerIconAvailability(canCollapseSidenav) {
    if (this.collapseButtonRef) {
      if (!canCollapseSidenav) {
        this.collapseButtonRef.classList.add('disable-collapse');
      }
      else {
        this.collapseButtonRef.classList.remove('disable-collapse');
      }
    }
  }
  /**
   * Render an action button, the button has a special background and chevron left or right icon.
   *
   * @returns {HTMLElement} The button element
   */
  render() {
    const maskImageStyle = this.getButtonMaskImage();
    return (h("i", { role: 'button', onClick: this.handleClickSidebarIcon, onKeyDown: createEnterKeyHandlerToTriggerClick(), class: "vega-handler-icon", tabIndex: 0, "aria-label": "Handle Sidebar Icon", ref: (node) => (this.collapseButtonRef = node) },
      h("style", null, maskImageStyle),
      h("vega-icon", { size: "size-16", icon: VegaInternalIconManager.getIconKey('sidenav-chevron-right') })));
  }
  /**
   * Generating a CSS `mask-image` property value using an SVG icon retrieved from the `VegaIconManager` and`VegaInternalIconManager`.
   *
   * @returns {string} The svg content string after encode
   */
  getButtonMaskImage() {
    const svg = VegaIconManager.getIcon(VegaInternalIconManager.getIconKey('sidenav-toggle-button-bg')).icon;
    const svgUrl = `url(data:image/svg+xml,${globalThis.encodeURIComponent(svg)})`;
    return `.vega-handler-icon{-webkit-mask-image:${svgUrl};mask-image:${svgUrl}}`;
  }
}
(() => {
  VegaInternalIconManager.register({
    'sidenav-chevron-right': sidenavChevronRight,
    'sidenav-toggle-button-bg': sidenavToggleButtonBg,
  });
})();
__decorate([
  MapToComponentField()
], VegaSidenavCollapseButtonRenderer.prototype, "host", void 0);
