import { Children, Fragment, isValidElement, type ReactNode } from "react";
import { cn } from "../../lib/utils";
import { SectionPanel } from "./SectionPanel";
export function BusinessDetailWorkspace({
children,
className,
testId,
}: {
children: ReactNode;
className?: string;
testId?: string;
}) {
return (
{children}
);
}
export function BusinessDetailMain({
children,
className,
}: {
children: ReactNode;
className?: string;
}) {
return {children}
;
}
export function BusinessDetailAside({
children,
className,
}: {
children: ReactNode;
className?: string;
}) {
return {children}
;
}
export function BusinessDetailFactGrid({
children,
className,
testId,
}: {
children: ReactNode;
className?: string;
testId?: string;
}) {
return (
{children}
);
}
export function BusinessDetailFact({
label,
children,
className,
}: {
label: ReactNode;
children: ReactNode;
className?: string;
}) {
return (
);
}
function hasVisibleNode(node: ReactNode): boolean {
return Children.toArray(node).some((child) => {
if (isValidElement(child) && child.type === Fragment) {
return hasVisibleNode(child.props.children);
}
return true;
});
}
export function BusinessDetailActionPanel({
title = "操作",
status,
beforeActions,
primaryAction,
secondaryActions,
moreActions,
summary,
children,
className,
testId,
}: {
title?: string;
status?: ReactNode;
beforeActions?: ReactNode;
primaryAction?: ReactNode;
secondaryActions?: ReactNode;
moreActions?: ReactNode;
summary?: ReactNode;
children?: ReactNode;
className?: string;
testId?: string;
}) {
const hasStatus = hasVisibleNode(status);
const hasBeforeActions = hasVisibleNode(beforeActions);
const hasPrimaryAction = hasVisibleNode(primaryAction);
const hasSecondaryActions = hasVisibleNode(secondaryActions);
const hasMoreActions = hasVisibleNode(moreActions);
const hasSummary = hasVisibleNode(summary);
const hasChildren = hasVisibleNode(children);
const hasActionContent = hasPrimaryAction || hasSecondaryActions || hasMoreActions;
const hasContentBeforeSummary = hasBeforeActions || hasActionContent || hasChildren;
if (!hasStatus && !hasBeforeActions && !hasActionContent && !hasSummary && !hasChildren) {
return null;
}
return (
{hasBeforeActions ?
{beforeActions}
: null}
{hasPrimaryAction ?
{primaryAction}
: null}
{hasSecondaryActions ?
{secondaryActions}
: null}
{hasMoreActions ?
{moreActions}
: null}
{hasChildren ? (
{children}
) : null}
{hasSummary ? (
) : null}
);
}