import React, { useContext, useEffect, useMemo } from 'react';
import classNames from 'classnames';
import omit from 'omit.js';
import ConfigProvider from '../config-provider';
import RouteContext from '../wau-route-context';
import './style';
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const FooterToolbar = props => {
  const {
    children,
    className,
    extra,
    style,
    renderContent,
    ...restProps
  } = props;
  const {
    getPrefixCls
  } = useContext(ConfigProvider.ConfigContext);
  const {
    prefixCls = getPrefixCls('pro')
  } = props;
  const baseClassName = `${prefixCls}-footer-bar`;
  const value = useContext(RouteContext);
  const width = useMemo(() => {
    const {
      hasSiderMenu,
      isMobile,
      siderWidth
    } = value;
    if (!hasSiderMenu) {
      return undefined;
    }
    // 0 or undefined
    if (!siderWidth) {
      return '100%';
    }
    return isMobile ? '100%' : `calc(100% - ${siderWidth}px)`;
  }, [value.collapsed, value.hasSiderMenu, value.isMobile, value.siderWidth]);
  const dom = /*#__PURE__*/_jsxs(_Fragment, {
    children: [/*#__PURE__*/_jsx("div", {
      className: `${baseClassName}-left`,
      children: extra
    }), /*#__PURE__*/_jsx("div", {
      className: `${baseClassName}-right`,
      children: children
    })]
  });

  /** 告诉 props 是否存在 footerBar */
  useEffect(() => {
    if (!value || !(value !== null && value !== void 0 && value.setHasFooterToolbar)) {
      return;
    }
    value === null || value === void 0 ? void 0 : value.setHasFooterToolbar(true);
    return () => {
      var _value$setHasFooterTo;
      value === null || value === void 0 || (_value$setHasFooterTo = value.setHasFooterToolbar) === null || _value$setHasFooterTo === void 0 ? void 0 : _value$setHasFooterTo.call(value, false);
    };
  }, []);
  return /*#__PURE__*/_jsx("div", {
    className: classNames(className, `${baseClassName}`),
    style: {
      width,
      ...style
    },
    ...omit(restProps, ['prefixCls']),
    children: renderContent ? renderContent({
      ...props,
      ...value,
      leftWidth: width
    }, dom) : dom
  });
};
export default FooterToolbar;