import type { FilterGroup } from "@fn-sphere/core"; import { useCallback, type ReactNode } from "react"; import { useFilterGroup } from "../hooks/use-filter-group.js"; import { useRootRule } from "../hooks/use-root-rule.js"; import { useView } from "../theme/hooks.js"; import type { CommonProps } from "./types.js"; export type FilterGroupContainerProps = { rule: FilterGroup; children?: ReactNode; } & CommonProps; export const FilterGroupContainer = ({ rule, children, ...props }: FilterGroupContainerProps) => { const { getLocaleText } = useRootRule(); const { ruleState: { isRoot, depth }, toggleGroupOp, appendChildRule, appendChildGroup, removeGroup, } = useFilterGroup(rule); const { Button, ErrorBoundary } = useView("components"); const text = rule.op === "or" ? getLocaleText("operatorOr") : getLocaleText("operatorAnd"); const handleToggleGroupOp = useCallback(() => { toggleGroupOp(); }, [toggleGroupOp]); const handleAddCondition = useCallback(() => { appendChildRule(); }, [appendChildRule]); const handleAddGroup = useCallback(() => { appendChildGroup(); }, [appendChildGroup]); const handleDeleteGroup = useCallback(() => { removeGroup(); }, [removeGroup]); return (
{children}
{depth < 3 && ( )} {!isRoot && ( )}
); };