// @flow
import type { ThemeProps } from '../../../types';
import type { UnstyledButtonProps } from './unstyled-button.proptypes';
import {
  focusedBoxShadow,
  focusedBorderShadow,
  focusedBorderColor,
  getBaseFocusState,
  darkModeBoxShadow,
  type FocusProps,
} from '../../../mixins/focus';

type BoxShadowProps = UnstyledButtonProps & ThemeProps & FocusProps;

export const getBoxShadow = (props: BoxShadowProps) => {
  if (props.isDarkMode) {
    return `${darkModeBoxShadow(props)}`;
  }

  // eslint-disable-next-line no-extra-boolean-cast
  if (!!props.insetFocus) {
    return `${focusedBoxShadow(props)}, ${focusedBorderShadow({
      inset: true,
    })} ${focusedBorderColor(props)}`;
  }

  return `${focusedBorderShadow({ inset: false })} ${focusedBorderColor(
    props,
  )}, ${focusedBoxShadow(props)}`;
};

export const getFocusState = ({ hasTransition = true }: UnstyledButtonProps) =>
  hasTransition
    ? getBaseFocusState({})
    : getBaseFocusState({ baseTransition: false, hoverTransition: false });
