import React__default, { forwardRef, useContext, useState } from "react";
import cs from "../_util/classNames.js";
import SiderComponent from "./sider.js";
import { SiderContext } from "./sider.js";
import Header from "./header.js";
import Footer from "./footer.js";
import Content from "./content.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import { jsx } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var __spreadArray = globalThis && globalThis.__spreadArray || function(to, from, pack) {
  if (pack || arguments.length === 2)
    for (var i = 0, l = from.length, ar; i < l; i++) {
      if (ar || !(i in from)) {
        if (!ar)
          ar = Array.prototype.slice.call(from, 0, i);
        ar[i] = from[i];
      }
    }
  return to.concat(ar || Array.prototype.slice.call(from));
};
function Layout(baseProps, ref) {
  var _a;
  var _b = useContext(ConfigContext), getPrefixCls = _b.getPrefixCls, componentConfig = _b.componentConfig;
  var props = useMergeProps(baseProps, {}, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Layout);
  var className = props.className, hasSider = props.hasSider, children = props.children, rest = __rest(props, ["className", "hasSider", "children"]);
  var _c = __read(useState([]), 2), siders = _c[0], setSiders = _c[1];
  var prefixCls = getPrefixCls("layout");
  var classNames = cs(prefixCls, (_a = {}, _a[prefixCls + "-has-sider"] = typeof hasSider === "boolean" ? hasSider : siders.length > 0, _a), className);
  return /* @__PURE__ */ jsx("section", {
    ...__assign({
      ref
    }, rest, {
      className: classNames
    }),
    children: React__default.Children.map(children, function(child) {
      if (child && child.props && child.props.sign === "sider") {
        return React__default.cloneElement(child, {
          onSiderMount: function(id) {
            return setSiders(__spreadArray(__spreadArray([], __read(siders), false), [id], false));
          },
          onSiderUnmount: function(id) {
            return setSiders(siders.filter(function(currentId) {
              return currentId !== id;
            }));
          }
        });
      }
      return child;
    })
  });
}
var ForwardRefLayout = forwardRef(Layout);
var LayoutComponent = ForwardRefLayout;
LayoutComponent.displayName = "Layout";
LayoutComponent.Sider = SiderComponent;
LayoutComponent.Header = Header;
LayoutComponent.Footer = Footer;
LayoutComponent.Content = Content;
export {
  SiderContext,
  LayoutComponent as default
};
//# sourceMappingURL=index.js.map
