{"version":3,"file":"ButtonGroup.cjs","sources":["../../../../src/components/Button/ButtonGroup.tsx"],"sourcesContent":["import type { ComponentProps, FC, ReactElement, ReactNode } from \"react\";\nimport { Children, cloneElement, isValidElement, useMemo } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { mergeDeep } from \"../../helpers/merge-deep\";\nimport { getTheme } from \"../../theme-store\";\nimport type { DeepPartial } from \"../../types\";\nimport type { ButtonProps } from \"../Button\";\n\nexport interface FlowbiteButtonGroupTheme {\n  base: string;\n  position: PositionInButtonGroup;\n}\n\nexport interface PositionInButtonGroup {\n  none: string;\n  start: string;\n  middle: string;\n  end: string;\n}\n\nexport interface ButtonGroupProps extends ComponentProps<\"div\">, Pick<ButtonProps, \"outline\" | \"pill\"> {\n  theme?: DeepPartial<FlowbiteButtonGroupTheme>;\n}\n\nconst processChildren = (\n  children: React.ReactNode,\n  outline: boolean | undefined,\n  pill: boolean | undefined,\n): ReactNode => {\n  return Children.map(children as ReactElement<ButtonProps>[], (child, index) => {\n    if (isValidElement(child)) {\n      // Check if the child has nested children\n      if (child.props.children) {\n        // Recursively process nested children\n        return cloneElement(child, {\n          ...child.props,\n          children: processChildren(child.props.children, outline, pill),\n          positionInGroup: determinePosition(index, Children.count(children)),\n        });\n      } else {\n        return cloneElement(child, {\n          outline,\n          pill,\n          positionInGroup: determinePosition(index, Children.count(children)),\n        });\n      }\n    }\n    return child;\n  });\n};\n\nconst determinePosition = (index: number, totalChildren: number) => {\n  return index === 0 ? \"start\" : index === totalChildren - 1 ? \"end\" : \"middle\";\n};\n\nexport const ButtonGroup: FC<ButtonGroupProps> = ({\n  children,\n  className,\n  outline,\n  pill,\n  theme: customTheme = {},\n  ...props\n}: ButtonGroupProps) => {\n  const items = useMemo(() => processChildren(children, outline, pill), [children, outline, pill]);\n\n  const theme = mergeDeep(getTheme().buttonGroup, customTheme);\n\n  return (\n    <div className={twMerge(theme.base, className)} role=\"group\" {...props}>\n      {items}\n    </div>\n  );\n};\n\nButt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