import { h, F as Fragment, r as registerInstance, c as createEvent, H as Host, g as getElement } from './index-090d31ca.js';
import { s as sanitizeVegaComponent } from './component-7d906393.js';
import { c as MapToComponentField, V as VegaSlimmer, M as MapToComponentMethod, I as InjectVegaSlimmer } from './global-slimmer-registry-17c4efd4.js';
import { V as VegaComponentUsageRuntimeMetricsSlimmer, I as InjectVegaGlobalSlimmer } from './component-usage-runtime-metrics-46020a03.js';
import { c as createEventEmitSlimmer } from './event-emit-slimmer-27acc176.js';
import { i as VegaChange } from './vega-event-id-a6ccca66.js';
import { P as PageResizeObserverSlimmer } from './page-resize-observer-slimmer-e24d36c5.js';
import './dynamic-slimmer-90b8af32.js';
import './change-manager-6a7eb88c.js';
import './dom-node-subject-observer-factory-3897e95b.js';
import './observer-3959f9dd.js';
import './ui-64815a12.js';
import './internal-vega-event-manager-7cdf3c28.js';
import './try-get-document-bef0f526.js';
import './breakpoints-332702ed.js';
import './ui-93922c59.js';
import './breakpoints-d9faf11c.js';

var __decorate$4 = (undefined && undefined.__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;
};
class VegaSegmentControlRenderer extends VegaSlimmer {
  render() {
    var _a;
    return (h("div", { class: "vega-segment-control-container" }, (_a = this.segments) === null || _a === void 0 ? void 0 : _a.map((props) => {
      return this.segmentRenderer.render(props);
    })));
  }
}
__decorate$4([
  MapToComponentField()
], VegaSegmentControlRenderer.prototype, "segments", void 0);
__decorate$4([
  MapToComponentField()
], VegaSegmentControlRenderer.prototype, "segmentRenderer", void 0);

var __decorate$3 = (undefined && undefined.__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;
};
class VegaSegmentControlSelectedController extends VegaSlimmer {
  /**
   * Component lifecycle - [componentWillLoad]{@link VegaSegmentControl.componentWillLoad}
   */
  componentWillLoad() {
    this.setDefaultSelected();
  }
  watchSegments() {
    this.setDefaultSelected();
  }
  watchSelected() {
    this.changeEventEmitter.emit(this.selected);
  }
  setSelected(props) {
    this.selected = props.key;
  }
  setDefaultSelected() {
    var _a;
    if (((_a = this.segments) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
      !this.segments.find((segment) => segment.key === this.selected)) {
      this.selected = this.segments[0].key;
    }
  }
}
__decorate$3([
  MapToComponentField({ writable: true })
], VegaSegmentControlSelectedController.prototype, "selected", void 0);
__decorate$3([
  MapToComponentField()
], VegaSegmentControlSelectedController.prototype, "segments", void 0);
__decorate$3([
  MapToComponentField()
], VegaSegmentControlSelectedController.prototype, "changeEventEmitter", void 0);
__decorate$3([
  MapToComponentMethod('componentWillLoad')
], VegaSegmentControlSelectedController.prototype, "componentWillLoad", null);
__decorate$3([
  MapToComponentMethod('watchSegments')
], VegaSegmentControlSelectedController.prototype, "watchSegments", null);
__decorate$3([
  MapToComponentMethod('watchSelected')
], VegaSegmentControlSelectedController.prototype, "watchSelected", null);

var __decorate$2 = (undefined && undefined.__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;
};
class VegaSegmentOverflowController extends VegaSlimmer {
  watchSegments() {
    this.setIsOverflowBlockSegments();
  }
  /** The below method is e2e-test covered in
   *  @see{module:vega-segment-control-set-block-e2e}
   *  @see{module:vega-segment-control-set-block-resize-screen-e2e}
   */
  /* istanbul ignore next */
  watchBlock() {
    this.setIsOverflowBlockSegments();
  }
  watchSize() {
    this.setIsOverflowBlockSegments();
  }
  setIsOverflowBlockSegments() {
    this.isOverflowBlockSegments = this.isExceedContainerWidth();
  }
  /**
   * The below method is e2e-test covered in
   * @see{module:vega-segment-control-set-block-e2e}
   * @see{module:vega-segment-control-set-block-resize-screen-e2e}
   */
  /* istanbul ignore next */
  isExceedContainerWidth() {
    if (this.block) {
      const container = this.host.shadowRoot.querySelector('.vega-segment-control-container');
      const childrenWidth = container.children.length *
        VegaSegmentOverflowController.SEGMENTS_OVERFLOW_THRESHOLD[this.size] +
        4 * (container.children.length - 1) +
        5;
      return container.clientWidth < childrenWidth ? true : false;
    }
    return false;
  }
}
VegaSegmentOverflowController.SEGMENTS_OVERFLOW_THRESHOLD = {
  medium: 101.9,
  small: 82,
};
__decorate$2([
  MapToComponentField()
], VegaSegmentOverflowController.prototype, "host", void 0);
__decorate$2([
  MapToComponentField()
], VegaSegmentOverflowController.prototype, "block", void 0);
__decorate$2([
  MapToComponentField()
], VegaSegmentOverflowController.prototype, "size", void 0);
__decorate$2([
  MapToComponentField({ writable: true })
], VegaSegmentOverflowController.prototype, "isOverflowBlockSegments", void 0);
__decorate$2([
  MapToComponentMethod('watchSegments')
], VegaSegmentOverflowController.prototype, "watchSegments", null);
__decorate$2([
  MapToComponentMethod('watchBlock')
], VegaSegmentOverflowController.prototype, "watchBlock", null);
__decorate$2([
  MapToComponentMethod('watchSize')
], VegaSegmentOverflowController.prototype, "watchSize", null);

var __decorate$1 = (undefined && undefined.__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;
};
class VegaSegmentRenderer extends VegaSlimmer {
  render(props) {
    return (h("button", { key: props.key, class: {
        'vega-segment': true,
        'selected': this.selected === props.key,
        'disabled': props.disabled,
        [`${this.size}`]: true,
      }, 
      // eslint-disable-next-line react/jsx-no-bind
      onClick: () => this.selectedController.setSelected(props), disabled: props.disabled }, this.renderSegments(props)));
  }
  /** The below method is e2e-test covered in
   *  @see{module:vega-segment-control-set-block-e2e}
   *  @see{module:vega-segment-control-set-block-resize-screen-e2e}
   */
  /* istanbul ignore next */
  renderSegments(props) {
    return (h(Fragment, null,
      (this.isOverflowBlockSegments ||
        (!this.isOverflowBlockSegments && this.variant !== 'text-only')) &&
        props.icon &&
        this.renderIcon(props),
      ((this.isOverflowBlockSegments && !props.icon) ||
        (!this.isOverflowBlockSegments && this.variant !== 'icon-only')) &&
        props.text &&
        this.renderText(props)));
  }
  renderIcon(props) {
    return (h("vega-tooltip", { text: props.text, trigger: props.text &&
        (this.isOverflowBlockSegments ||
          (!this.isOverflowBlockSegments && this.variant === 'icon-only'))
        ? 'hover'
        : 'none', placement: ['bottom', 'top'], disableInteractive: false },
      h("vega-icon", { icon: props.icon, size: "size-16" })));
  }
  renderText(props) {
    return (h("vega-text", { overflow: "ellipsis", tooltip: { placement: ['bottom', 'top'] } }, props.text));
  }
}
__decorate$1([
  MapToComponentField()
], VegaSegmentRenderer.prototype, "host", void 0);
__decorate$1([
  MapToComponentField()
], VegaSegmentRenderer.prototype, "size", void 0);
__decorate$1([
  MapToComponentField()
], VegaSegmentRenderer.prototype, "selected", void 0);
__decorate$1([
  MapToComponentField()
], VegaSegmentRenderer.prototype, "variant", void 0);
__decorate$1([
  MapToComponentField()
], VegaSegmentRenderer.prototype, "block", void 0);
__decorate$1([
  MapToComponentField()
], VegaSegmentRenderer.prototype, "isOverflowBlockSegments", void 0);
__decorate$1([
  MapToComponentField()
], VegaSegmentRenderer.prototype, "selectedController", void 0);

const vegaSegmentControlCss = ":host{display:inline-block}.vega-segment-control-container{display:flex;gap:4px;border-radius:9999px;background-color:rgba(var(--v-bg-segment-control, 89, 96, 99, 0.1));padding:3px}:host(.vega-segment-control-block){display:block}:host(.vega-segment-control-block) .vega-segment{flex-basis:0;flex-grow:1}.vega-segment{display:flex;align-items:center;justify-content:center;gap:8px;color:rgba(var(--v-text-primary, 32, 54, 69, 1));border-radius:9999px;cursor:pointer;text-align:center;border-width:1px;border-style:solid;background-color:rgba(var(--v-bg-transparent, 0, 0, 0, 0));border-color:transparent}.vega-segment vega-icon{vertical-align:middle}.vega-segment.medium{padding-left:24px;padding-right:24px;padding-top:8px;padding-bottom:8px;font-family:\"Inter\", sans-serif;font-size:16px;font-weight:500;line-height:22px;letter-spacing:0px}@media screen and (min-width: 768px) and (max-width: 1023px){.vega-segment.medium{font-family:\"Inter\", sans-serif;font-size:16px;font-weight:500;line-height:22px;letter-spacing:0px}}@media screen and (min-width: 1024px) and (max-width: 1439px){.vega-segment.medium{font-family:\"Inter\", sans-serif;font-size:16px;font-weight:500;line-height:22px;letter-spacing:0px}}@media screen and (min-width: 1440px) and (max-width: 9999px){.vega-segment.medium{font-family:\"Inter\", sans-serif;font-size:16px;font-weight:500;line-height:22px;letter-spacing:0px}}.vega-segment.small{padding-left:16px;padding-right:16px;font-family:\"Inter\", sans-serif;font-size:14px;font-weight:400;line-height:18px;padding-top:3px;padding-bottom:3px}@media screen and (min-width: 768px) and (max-width: 1023px){.vega-segment.small{font-family:\"Inter\", sans-serif;font-size:14px;font-weight:400;line-height:18px}}@media screen and (min-width: 1024px) and (max-width: 1439px){.vega-segment.small{font-family:\"Inter\", sans-serif;font-size:14px;font-weight:400;line-height:18px}}@media screen and (min-width: 1440px) and (max-width: 9999px){.vega-segment.small{font-family:\"Inter\", sans-serif;font-size:14px;font-weight:400;line-height:18px}}.vega-segment.disabled{color:rgba(var(--v-text-disabled, 176, 180, 181, 1));pointer-events:none}.vega-segment:focus-visible{outline:2px solid rgba(var(--v-border-color-action, 19, 98, 226, 1));outline-offset:2px}.vega-segment:hover{background-color:rgba(var(--v-bg-segment-hover, 205, 209, 211, 1))}.vega-segment.selected{background-color:rgba(var(--v-bg-primary, 252, 252, 252, 1));border:1px solid rgba(var(--v-border-chip, 205, 209, 211, 1))}";

var __decorate = (undefined && undefined.__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;
};
const VegaSegmentControl = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.vegaChange = createEvent(this, "vegaChange", 7);
    this.change = createEvent(this, "change", 7);
    this.globalSlimmers = {};
    this.segmentControlRenderer = new VegaSegmentControlRenderer();
    this.segmentOverflowController = new VegaSegmentOverflowController();
    this.segmentRenderer = new VegaSegmentRenderer();
    this.selectedController = new VegaSegmentControlSelectedController();
    this.changeEventEmitter = createEventEmitSlimmer(VegaSegmentControl, VegaChange);
    this.pageResizeObserverSlimmer = new PageResizeObserverSlimmer({
      callback: /* istanbul ignore next */ () => {
        this.segmentControlWidth = this.host.clientWidth;
        this.segmentOverflowController.setIsOverflowBlockSegments();
      },
      shouldTrigger: /* istanbul ignore next */ () => {
        return this.host.clientWidth !== this.segmentControlWidth;
      },
    });
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    this.segmentControlWidth = 0;
    this.isOverflowBlockSegments = false;
    /**
     * Specifies whether the segment control spans the
     *    full width of its parent element.
     *
     * @vegaVersion 2.3.0
     */
    this.block = false;
    /**
     * Specifies the size of the segment control.
     *
     * @vegaVersion 2.3.0
     */
    this.size = 'medium';
    /**
     * Specifies the options available within the segment control.
     *    Please note that we advise against having more than four segments in a segment control.
     *
     * @vegaVersion 2.3.0
     */
    this.segments = [];
    /**
     * Specifies the variant of the segment control.
     *
     * The following options are available for the `variant` property:
     * - `default`:
     *      The segment control is rendered with both icon and text if configured,
     * - `text-only`:
     *      The segment control is rendered with text only regardless of the configuration of icon.
     * - `icon-only`:
     *      The segment control is rendered with icon only, text will be showed as the icon's tooltip if configured.
     *
     * @vegaVersion 2.3.0
     */
    this.variant = 'default';
  }
  /** The below method is e2e-test covered in
   *  @see{module:vega-segment-control-set-block-e2e}
   *  @see{module:vega-segment-control-set-block-resize-screen-e2e}
   */
  /* istanbul ignore next */
  watchBlock() {
  }
  watchSize() {
  }
  watchSegments() {
  }
  watchSelected() {
  }
  componentWillLoad() {
  }
  render() {
    return sanitizeVegaComponent(h(Host, { class: { 'vega-segment-control-block': this.block } }, this.segmentControlRenderer.render()), this.host);
  }
  get host() { return getElement(this); }
  static get watchers() { return {
    "block": ["watchBlock"],
    "size": ["watchSize"],
    "segments": ["watchSegments"],
    "selected": ["watchSelected"]
  }; }
};
__decorate([
  InjectVegaGlobalSlimmer()
], VegaSegmentControl.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaSegmentControl.prototype, "segmentControlRenderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaSegmentControl.prototype, "segmentOverflowController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaSegmentControl.prototype, "segmentRenderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaSegmentControl.prototype, "selectedController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaSegmentControl.prototype, "changeEventEmitter", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaSegmentControl.prototype, "pageResizeObserverSlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaSegmentControl.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
VegaSegmentControl.style = vegaSegmentControlCss;

export { VegaSegmentControl as vega_segment_control };
