import { isSpacingTokenType, isDirectionalSpacingType } from '../../../types/type-guard';
import { LogUtility } from '../../../utils/log';
import { Spacing } from '../../../constants/tokens/spacing';
import { ResponsiveCSSTextFormatter } from './responsive-css-text-formatter';
const MARGIN_DIRECTION_STYLE_MAP = {
  top: ['margin-top'],
  bottom: ['margin-bottom'],
  left: ['margin-left'],
  right: ['margin-right'],
  x: ['margin-left', 'margin-right'],
  y: ['margin-top', 'margin-bottom'],
};
/**
 * Get the padding style content.
 */
class ResponsiveMarginStyleFormatter extends ResponsiveCSSTextFormatter {
  /**
   * Given a margin type, return a string of style content that can be used to apply the margin to an element
   *
   * @param {MarginType} input - MarginType
   * @returns {string} - A string of style content.
   */
  formatToken(input) {
    if (isSpacingTokenType(input)) {
      return `margin:${Spacing[input]}px`;
    }
    else if (isDirectionalSpacingType(input)) {
      return Object.keys(input)
        .map((direction) => {
        return MARGIN_DIRECTION_STYLE_MAP[direction]
          .map((item) => {
          return `${item}:${Spacing[input[direction]]}px`;
        })
          .join(';');
      })
        .join(';');
    }
    else {
      LogUtility.warn(`The margin value ${input} is invalid, it must be a value of: `, Spacing);
      return '';
    }
  }
}
export default new ResponsiveMarginStyleFormatter();
