import { type ButtonProps as RadixButtonProps } from '@radix-ui/themes';
import type { Breakpoint } from '@radix-ui/themes/props';
import type { ButtonProps } from '../atoms/button.type';

export const convertSizeStr = (
  size: ButtonProps['size']
): '1' | '2' | '3' | '4' => {
  switch (size) {
    case 'small':
      return '1';
    case 'medium':
      return '2';
    case 'large':
      return '3';
    default:
      return '2';
  }
};

export const convertSizeResponse = (
  size: ButtonProps['size']
): RadixButtonProps['size'] => {
  if (typeof size === 'string' || typeof size === 'undefined') {
    return convertSizeStr(size);
  }
  const radixSize: RadixButtonProps['size'] = {};
  let key: Breakpoint = 'initial';
  for (key in size) {
    radixSize[key] = convertSizeStr(size[key]);
  }
  return radixSize;
};

export const convertSize = (
  size: ButtonProps['size']
): RadixButtonProps['size'] => {
  if (typeof size === 'string') {
    return convertSizeStr(size);
  }
  return convertSizeResponse(size);
};
