import { __assign, __rest } from "tslib";
import React, { useContext, useState } from 'react';
import classNames from 'classnames';
import { SidebarContext } from './sidebar-context';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
var Layout = React.forwardRef(function (props, ref) {
    var _a;
    var className = props.className, children = props.children, customisedCls = props.prefixCls, otherProps = __rest(props, ["className", "children", "prefixCls"]);
    var _b = useState(false), hasSidebar = _b[0], setHasSidebar = _b[1];
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('layout', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className, (_a = {},
        _a[prefixCls + "_has-sidebar"] = hasSidebar,
        _a));
    return (React.createElement(SidebarContext.Provider, { value: {
            addSidebar: function () { return setHasSidebar(true); },
            removeSidebar: function () { return setHasSidebar(false); },
        } },
        React.createElement("section", __assign({}, otherProps, { ref: ref, className: cls }), children)));
});
Layout.displayName = 'Layout';
function generator(_props) {
    var tagName = _props.tagName, displayName = _props.displayName, defaultCls = _props.prefixCls;
    var SubComponent = React.forwardRef(function (props, ref) {
        var className = props.className, children = props.children, customisedCls = props.prefixCls, otherProps = __rest(props, ["className", "children", "prefixCls"]);
        var configContext = useContext(ConfigContext);
        var prefixCls = getPrefixCls(defaultCls, configContext.prefixCls, customisedCls);
        var cls = classNames(prefixCls, className);
        return React.createElement(tagName, __assign({ ref: ref, className: cls }, otherProps), children);
    });
    SubComponent.displayName = displayName;
    return SubComponent;
}
var Header = generator({
    prefixCls: 'layout-header',
    tagName: 'header',
    displayName: 'Header',
});
var Footer = generator({
    prefixCls: 'layout-footer',
    tagName: 'footer',
    displayName: 'Footer',
});
var Content = generator({
    prefixCls: 'layout-content',
    tagName: 'main',
    displayName: 'Content',
});
export { Header, Footer, Content };
export default Layout;
//# sourceMappingURL=layout.js.map