import { c as create_ssr_component, a as compute_rest_props, j as createEventDispatcher, s as setContext, b as spread, d as escape_object, n as getContext, e as escape_attribute_value, g as add_attribute, i as add_classes, f as escape } from "./index-27250121.js";
import { w as writable } from "./pages-a57618e2.js";
const ContentSwitcher = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let currentIndex;
  let switches;
  let $$restProps = compute_rest_props($$props, ["selectedIndex", "size"]);
  let { selectedIndex = 0 } = $$props;
  let { size = void 0 } = $$props;
  const dispatch = createEventDispatcher();
  const currentId = writable(null);
  setContext("ContentSwitcher", {
    currentId,
    add: ({ id, text, selected }) => {
      if (selected) {
        selectedIndex = switches.length;
      }
      switches = [...switches, { id, text, selected }];
    },
    update: (id) => {
      selectedIndex = switches.map(({ id: id2 }) => id2).indexOf(id);
    },
    change: (direction) => {
      let index = currentIndex + direction;
      if (index < 0) {
        index = switches.length - 1;
      } else if (index >= switches.length) {
        index = 0;
      }
      selectedIndex = index;
    }
  });
  if ($$props.selectedIndex === void 0 && $$bindings.selectedIndex && selectedIndex !== void 0)
    $$bindings.selectedIndex(selectedIndex);
  if ($$props.size === void 0 && $$bindings.size && size !== void 0)
    $$bindings.size(size);
  currentIndex = -1;
  switches = [];
  {
    if (switches[currentIndex]) {
      dispatch("change", currentIndex);
      currentId.set(switches[currentIndex].id);
    }
  }
  return `
<div${spread([{ role: "tablist" }, escape_object($$restProps)], {
    classes: "bx--content-switcher " + (size === "sm" ? "bx--content-switcher--sm" : "") + " " + (size === "xl" ? "bx--content-switcher--xl" : "")
  })}>${slots.default ? slots.default({}) : ``}</div>`;
});
const ContentSwitcher$1 = ContentSwitcher;
const Switch = create_ssr_component(($$result, $$props, $$bindings, slots) => {
  let $$restProps = compute_rest_props($$props, ["text", "selected", "disabled", "id", "ref"]);
  let { text = "Provide text" } = $$props;
  let { selected = false } = $$props;
  let { disabled = false } = $$props;
  let { id = "ccs-" + Math.random().toString(36) } = $$props;
  let { ref = null } = $$props;
  const ctx = getContext("ContentSwitcher");
  ctx.add({ id, text, selected });
  ctx.currentId.subscribe(($) => {
    selected = $ === id;
  });
  if ($$props.text === void 0 && $$bindings.text && text !== void 0)
    $$bindings.text(text);
  if ($$props.selected === void 0 && $$bindings.selected && selected !== void 0)
    $$bindings.selected(selected);
  if ($$props.disabled === void 0 && $$bindings.disabled && disabled !== void 0)
    $$bindings.disabled(disabled);
  if ($$props.id === void 0 && $$bindings.id && id !== void 0)
    $$bindings.id(id);
  if ($$props.ref === void 0 && $$bindings.ref && ref !== void 0)
    $$bindings.ref(ref);
  return `
<button${spread(
    [
      { type: "button" },
      { role: "tab" },
      {
        tabindex: escape_attribute_value(selected ? "0" : "-1")
      },
      {
        "aria-selected": escape_attribute_value(selected)
      },
      { disabled: disabled || null },
      { id: escape_attribute_value(id) },
      escape_object($$restProps)
    ],
    {
      classes: "bx--content-switcher-btn " + (selected ? "bx--content-switcher--selected" : "")
    }
  )}${add_attribute("this", ref, 0)}><span${add_classes("bx--content-switcher__label".trim())}>${slots.default ? slots.default({}) : `${escape(text)}`}</span></button>`;
});
const Switch$1 = Switch;
export {
  ContentSwitcher$1 as C,
  Switch$1 as S
};
