import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, } from "react";
import { AlertTitle } from "../alertTitle";
import "./styles.css";
/**
 * Context for sharing alert container properties with child components
 * @internal
 */
const AlertContainerContext = createContext({});
/**
 * Custom hook to access the AlertContainer context
 *
 * @returns {AlertContainerProps} The current alert container properties including schema and HTML attributes
 *
 * @example
 * function CustomAlertContent() {
 *   const { schema } = useAlertContainer();
 *   return <div>Current schema: {schema}</div>;
 * }
 */
function useAlertContainer() {
    return useContext(AlertContainerContext);
}
/**
 * AlertContainer - A flexible alert component that displays messages with different visual styles
 *
 * This component automatically adjusts its layout based on whether an AlertTitle component
 * is present among its children. When AlertTitle is detected, the content is left-aligned;
 * otherwise, it's centered.
 *
 * @component
 * @memberof Alert
 *
 * @param {AlertContainerProps} props - Component properties
 * @param {"success" | "danger" | "warning" | "info"} props.schema - Determines the visual styling and semantic meaning of the alert
 * @param {ReactNode} props.children - Content to be rendered inside the alert, can include AlertTitle and other components
 * @param {string} [props.className] - Additional CSS classes to customize the alert appearance
 *
 * @returns {JSX.Element} A styled alert container with context provider for child components
 *
 * @requires react - For createContext, useContext, ReactNode
 *
 * @example
 * // Basic usage
 * <AlertContainer schema="success">
 *  {children}
 * </AlertContainer>
 *
 * @example
 * // Complete alert example
 * <AlertContainer schema="success">
 *  <AlertIcon />
 *  <AlertContent>
 *    <AlertTitle>Success!</AlertTitle>
 *    <AlertDescription>
 *      You are premium user now!
 *    </AlertDescription>
 *  </AlertContent>
 * </AlertContainer>
 */
function AlertContainer(props) {
    const { schema, children, className: baseClassName, ...rest } = props;
    const hasAlertTitle = (children) => {
        let found = false;
        const searchForAlertTitle = (nodes) => {
            if (Array.isArray(nodes)) {
                nodes.forEach(searchForAlertTitle);
            }
            else if (nodes && typeof nodes === "object" && "type" in nodes) {
                if (nodes.type === AlertTitle) {
                    found = true;
                }
                else if (nodes.props &&
                    typeof nodes.props === "object" &&
                    nodes.props !== null &&
                    "children" in nodes.props) {
                    searchForAlertTitle(nodes.props.children);
                }
            }
        };
        searchForAlertTitle(children);
        return found;
    };
    const shouldAlignCenter = !hasAlertTitle(children);
    const finalClassName = shouldAlignCenter
        ? "nonExistsAlertTitle"
        : "existsAlertTitle";
    const className = `arkynAlertContainer ${schema} ${finalClassName} ${baseClassName}`;
    return (_jsx(AlertContainerContext.Provider, { value: props, children: _jsx("div", { className: className.trim(), ...rest, children: children }) }));
}
export { AlertContainer, useAlertContainer };
