'use strict';
import { c } from 'react/compiler-runtime';
import { jsx } from 'react/jsx-runtime';
import { createContext, useState, useContext } from 'react';
import { createError } from '../../../../fd-toolbox/errors/errors.js';
import { metaErrorMessages } from '../../../meta/constants/meta-error-messages-constants.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
const SidebarItemsContext = createContext(void 0);
function SidebarItemsProvider(t0) {
  const $ = c(7);
  const {
    children,
    initialSidebarItems
  } = t0;
  let t1;
  if ($[0] !== initialSidebarItems) {
    t1 = initialSidebarItems ?? [];
    $[0] = initialSidebarItems;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const [sidebarItems, setSidebarItems] = useState(t1);
  const initSidebarItems = setSidebarItems;
  let t2;
  if ($[2] !== children || $[3] !== sidebarItems) {
    let t3;
    if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
      t3 = resource => setSidebarItems(prev => prev.concat(resource));
      $[5] = t3;
    } else {
      t3 = $[5];
    }
    const addSidebarItem = __name(t3, "addSidebarItem");
    let t4;
    if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
      t4 = resourceName => setSidebarItems(prev_0 => prev_0.filter(resource_0 => resource_0.displayName !== resourceName));
      $[6] = t4;
    } else {
      t4 = $[6];
    }
    const removeSidebarItem = __name(t4, "removeSidebarItem");
    const contextValue = {
      sidebarItems,
      addSidebarItem,
      removeSidebarItem,
      initSidebarItems
    };
    t2 = jsx(SidebarItemsContext.Provider, {
      value: contextValue,
      children
    });
    $[2] = children;
    $[3] = sidebarItems;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  return t2;
}
__name(SidebarItemsProvider, "SidebarItemsProvider");
function useSidebarItems() {
  const context = useContext(SidebarItemsContext);
  if (!context) {
    throw createError(metaErrorMessages.sidebarResourceNamesUsedOutside);
  }
  return context;
}
__name(useSidebarItems, "useSidebarItems");

export { SidebarItemsProvider, useSidebarItems };
