import { CONSTANTS } from "./constants";

/* eslint-disable no-bitwise */
const DEFAULT = {
  POSITION: CONSTANTS.DEFAULT_POSITION,
  TRANSFORM: CONSTANTS.DEFAULT_TRANSFORM,
};

/**
 * Exports border color based on type of notification
 * @param {*} type type of notification (success/warning/error/default)
 * @param {*} colors colors from Haptik's Design System
 */
export const getBorderColor = (type, colors) => {
  if (type === CONSTANTS.TYPES.DEFAULT) {
    return colors.blue.haptik;
  }

  if (type === CONSTANTS.TYPES.SUCCESS) {
    return colors.green.haptik;
  }

  if (type === CONSTANTS.TYPES.WARNING) {
    return colors.yellow.haptik;
  }

  if (type === CONSTANTS.TYPES.ERROR) {
    return colors.red.haptik;
  }

  if (type === CONSTANTS.TYPES.INFO) {
    return colors.grey.deep;
  }

  return colors.blue.haptik;
};

/**
 * Displays notification container based on position specified
 * @param {*} position position of notification (top-left/top-center/top-right/same for bottom)
 * @param {*} offset offset adjustment for container
 * @returns
 */
export const getPositionStyles = (position, offset, active) => {
  const positionStyle = {};
  switch (position) {
    case CONSTANTS.POSITIONS.TOP_LEFT: {
      positionStyle.top =
        offset && offset.top ? DEFAULT.POSITION + offset.top : DEFAULT.POSITION;
      positionStyle.left =
        offset && offset.left
          ? DEFAULT.POSITION + offset.left
          : DEFAULT.POSITION;
      positionStyle.transform = `translateX(${
        active ? 0 : `-${DEFAULT.TRANSFORM}px`
      })`;
      break;
    }

    case CONSTANTS.POSITIONS.TOP_CENTER: {
      positionStyle.top =
        offset && offset.top ? DEFAULT.POSITION + offset.top : DEFAULT.POSITION;
      positionStyle.left = offset && offset.left ? offset.left : 0;
      positionStyle.right = 0;
      positionStyle.margin = "0 auto";
      positionStyle.transform = `translateY(${
        active ? 0 : `-${DEFAULT.TRANSFORM}px`
      })`;
      break;
    }

    case CONSTANTS.POSITIONS.TOP_RIGHT: {
      positionStyle.top =
        offset && offset.top ? DEFAULT.POSITION + offset.top : DEFAULT.POSITION;
      positionStyle.right =
        offset && offset.left
          ? DEFAULT.POSITION + offset.left
          : DEFAULT.POSITION;
      positionStyle.transform = `translateX(${
        active ? 0 : `${DEFAULT.TRANSFORM}px`
      })`;
      break;
    }

    case CONSTANTS.POSITIONS.BOTTOM_LEFT: {
      positionStyle.bottom =
        offset && offset.top ? DEFAULT.POSITION + offset.top : DEFAULT.POSITION;
      positionStyle.left =
        offset && offset.left
          ? DEFAULT.POSITION + offset.left
          : DEFAULT.POSITION;

      positionStyle.transform = `translateX(${
        active ? 0 : `-${DEFAULT.TRANSFORM}px`
      })`;
      break;
    }

    case CONSTANTS.POSITIONS.BOTTOM_CENTER: {
      positionStyle.bottom =
        offset && offset.top ? DEFAULT.POSITION + offset.top : DEFAULT.POSITION;
      positionStyle.left = offset && offset.left ? offset.left : 0;
      positionStyle.right = 0;
      positionStyle.marginLeft = "auto";
      positionStyle.marginRight = "auto";
      positionStyle.transform = `translateY(${
        active ? 0 : `${DEFAULT.TRANSFORM}px`
      })`;
      break;
    }

    case CONSTANTS.POSITIONS.BOTTOM_RIGHT: {
      positionStyle.bottom =
        offset && offset.top ? DEFAULT.POSITION + offset.top : DEFAULT.POSITION;
      positionStyle.right =
        offset && offset.left
          ? DEFAULT.POSITION + offset.left
          : DEFAULT.POSITION;

      positionStyle.transform = `translateX(${
        active ? 0 : `${DEFAULT.TRANSFORM}px`
      })`;
      break;
    }

    default: {
      positionStyle.top = DEFAULT.POSITION;
      positionStyle.left = DEFAULT.POSITION;
      break;
    }
  }
  return positionStyle;
};
