import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { isValidElement } from 'react';
import { PageAside } from '../PageAside';
import { PageContent } from '../PageContent';
import { PageContextProvider } from '../PageContext';
import { PageHeader } from '../PageHeader';
import { PageLayoutContainer, pageLayoutClassnames, } from '../PageLayoutContainer';
import { LoadingPlaceholder } from '../placeholders/LoadingPlaceholder';
import { classNames } from '../utils/classNames';
import { DesktopAlertWrapper, LoaderWrapper, MobileAlertWrapper, } from './styles';
import { useLogic } from './useLogic';
export const PageLayout = (props) => {
    const { header, content, aside, footer, className, alert, isLoading } = props;
    const { hasAside, ref } = useLogic(props);
    return (_jsxs(PageContextProvider, { hasAside: hasAside, isLoading: isLoading, children: [alert && _jsx(DesktopAlertWrapper, { children: alert }), _jsxs(PageLayoutContainer, { className: classNames(className, {
                    [pageLayoutClassnames.withoutHeader]: !header,
                }), ref: ref, children: [alert && _jsx(MobileAlertWrapper, { children: alert }), isValidElement(header)
                        ? header
                        : header && _jsx(PageHeader, { ...header }), isLoading ? (_jsx(LoaderWrapper, { children: _jsx(LoadingPlaceholder, { title: "\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0434\u0430\u043D\u043D\u044B\u0445..." }) })) : (_jsxs(_Fragment, { children: [isValidElement(content) ? (content) : (_jsx(PageContent, { ...content, footer: footer })), aside && !isValidElement(aside) && (_jsx(PageAside, { ...aside })), isValidElement(aside) && aside] }))] })] }));
};
export default PageLayout;
