export var defaultTooltipPosition = {
  top: '-1000px',
  left: '-1000px',
  transform: 'none'
};
export var getPosition = function getPosition(placement, rect, offset) {
  var positions = {
    top: {
      top: "".concat(rect.top - offset, "px"),
      left: "".concat(rect.left + rect.width / 2, "px"),
      transform: 'translate(-50%, -100%)'
    },
    topStart: {
      top: "".concat(rect.top - offset, "px"),
      left: "".concat(rect.left, "px"),
      transform: 'translate(0, -100%)'
    },
    topEnd: {
      top: "".concat(rect.top - offset, "px"),
      left: "".concat(rect.left + rect.width, "px"),
      transform: 'translate(-100%, -100%)'
    },
    bottom: {
      top: "".concat(rect.bottom + offset, "px"),
      left: "".concat(rect.left + rect.width / 2, "px"),
      transform: 'translate(-50%, 0)'
    },
    bottomStart: {
      top: "".concat(rect.bottom + offset, "px"),
      left: "".concat(rect.left, "px"),
      transform: 'translate(0, 0)'
    },
    bottomEnd: {
      top: "".concat(rect.bottom + offset, "px"),
      left: "".concat(rect.left + rect.width, "px"),
      transform: 'translate(-100%, 0)'
    },
    left: {
      top: "".concat(rect.top + rect.height / 2, "px"),
      left: "".concat(rect.left - offset, "px"),
      transform: 'translate(-100%, -50%)'
    },
    leftStart: {
      top: "".concat(rect.top, "px"),
      left: "".concat(rect.left - offset, "px"),
      transform: 'translate(-100%, 0)'
    },
    leftEnd: {
      top: "".concat(rect.top + rect.height, "px"),
      left: "".concat(rect.left - offset, "px"),
      transform: 'translate(-100%, -100%)'
    },
    right: {
      top: "".concat(rect.top + rect.height / 2, "px"),
      left: "".concat(rect.right + offset, "px"),
      transform: 'translate(0, -50%)'
    },
    rightStart: {
      top: "".concat(rect.top, "px"),
      left: "".concat(rect.right + offset, "px"),
      transform: 'translate(0, 0)'
    },
    rightEnd: {
      top: "".concat(rect.top + rect.height, "px"),
      left: "".concat(rect.right + offset, "px"),
      transform: 'translate(0, -100%)'
    }
  };
  return positions[placement] || positions.top;
};

// export const getPosition = (
//   placement: Placement,
//   rect: ParentDomRect,
//   offset: number,
// ): TooltipPosition => {
//   // console.log(rect);
//   if (
//     !rect ||
//     rect.width <= 0 ||
//     rect.height <= 0 ||
//     Number.isNaN(rect.top) ||
//     Number.isNaN(rect.left)
//   ) {
//     return {
//       top: '0px',
//       left: '0px',
//       // move tooltip out of viewport safely until rect is valid
//       transform: 'translate(-9999px, -9999px)',
//     }
//   }

//   const viewportWidth = window.innerWidth
//   const viewportHeight = window.innerHeight

//   const clamp = (value: number, min: number, max: number) =>
//     Math.min(Math.max(value, min), max)

//   const centerX = rect.left + rect.width / 2
//   const centerY = rect.top + rect.height / 2

//   const safeTop = clamp(rect.top, 8, viewportHeight - 8)
//   const safeBottom = clamp(rect.bottom, 8, viewportHeight - 8)
//   const safeLeft = clamp(rect.left, 8, viewportWidth - 8)
//   const safeRight = clamp(rect.right, 8, viewportWidth - 8)

//   const positions: Record<Placement, TooltipPosition> = {
//     top: {
//       top: `${clamp(rect.top - offset, 8, viewportHeight - 8)}px`,
//       left: `${clamp(centerX, 8, viewportWidth - 8)}px`,
//       transform: 'translate(-50%, -100%)',
//     },
//     topStart: {
//       top: `${clamp(rect.top - offset, 8, viewportHeight - 8)}px`,
//       left: `${safeLeft}px`,
//       transform: 'translate(0, -100%)',
//     },
//     topEnd: {
//       top: `${clamp(rect.top - offset, 8, viewportHeight - 8)}px`,
//       left: `${safeRight}px`,
//       transform: 'translate(-100%, -100%)',
//     },
//     bottom: {
//       top: `${clamp(rect.bottom + offset, 8, viewportHeight - 8)}px`,
//       left: `${clamp(centerX, 8, viewportWidth - 8)}px`,
//       transform: 'translate(-50%, 0)',
//     },
//     bottomStart: {
//       top: `${clamp(rect.bottom + offset, 8, viewportHeight - 8)}px`,
//       left: `${safeLeft}px`,
//       transform: 'translate(0, 0)',
//     },
//     bottomEnd: {
//       top: `${clamp(rect.bottom + offset, 8, viewportHeight - 8)}px`,
//       left: `${safeRight}px`,
//       transform: 'translate(-100%, 0)',
//     },
//     left: {
//       top: `${clamp(centerY, 8, viewportHeight - 8)}px`,
//       left: `${clamp(rect.left - offset, 8, viewportWidth - 8)}px`,
//       transform: 'translate(-100%, -50%)',
//     },
//     leftStart: {
//       top: `${safeTop}px`,
//       left: `${clamp(rect.left - offset, 8, viewportWidth - 8)}px`,
//       transform: 'translate(-100%, 0)',
//     },
//     leftEnd: {
//       top: `${safeBottom}px`,
//       left: `${clamp(rect.left - offset, 8, viewportWidth - 8)}px`,
//       transform: 'translate(-100%, -100%)',
//     },
//     right: {
//       top: `${clamp(centerY, 8, viewportHeight - 8)}px`,
//       left: `${clamp(rect.right + offset, 8, viewportWidth - 8)}px`,
//       transform: 'translate(0, -50%)',
//     },
//     rightStart: {
//       top: `${safeTop}px`,
//       left: `${clamp(rect.right + offset, 8, viewportWidth - 8)}px`,
//       transform: 'translate(0, 0)',
//     },
//     rightEnd: {
//       top: `${safeBottom}px`,
//       left: `${clamp(rect.right + offset, 8, viewportWidth - 8)}px`,
//       transform: 'translate(0, -100%)',
//     },
//   }

//   return positions[placement] || positions.top
// }

export var getIconPosition = function getIconPosition(placement, offsetX, offsetY) {
  var offsetAbsolute = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '3px';
  var positions = {
    top: {
      top: 'auto',
      right: 'auto',
      left: '50%',
      bottom: "".concat(offsetAbsolute),
      transform: 'translate(-50%, 100%) rotate(-90deg)'
    },
    topStart: {
      top: 'auto',
      right: 'auto',
      left: "".concat(offsetX),
      bottom: "".concat(offsetAbsolute),
      transform: 'translate(0, 100%) rotate(-90deg)'
    },
    topEnd: {
      top: 'auto',
      right: "".concat(offsetX),
      left: 'auto',
      bottom: "".concat(offsetAbsolute),
      transform: 'translate(0, 100%) rotate(-90deg)'
    },
    bottom: {
      top: "".concat(offsetAbsolute),
      right: 'auto',
      left: '50%',
      bottom: 'auto',
      transform: 'translate(-50%, -100%) rotate(90deg)'
    },
    bottomStart: {
      top: "".concat(offsetAbsolute),
      right: 'auto',
      left: "".concat(offsetX),
      bottom: 'auto',
      transform: 'translate(0, -100%) rotate(90deg)'
    },
    bottomEnd: {
      top: "".concat(offsetAbsolute),
      right: "".concat(offsetX),
      left: 'auto',
      bottom: 'auto',
      transform: 'translate(0, -100%) rotate(90deg)'
    },
    left: {
      top: '50%',
      right: '0',
      left: 'auto',
      bottom: 'auto',
      transform: 'translate(100%, -50%) rotate(180deg)'
    },
    leftStart: {
      top: "".concat(offsetY),
      right: '0',
      left: 'auto',
      bottom: 'auto',
      transform: 'translate(100%, -50%) rotate(180deg)'
    },
    leftEnd: {
      top: 'auto',
      right: '0',
      left: 'auto',
      bottom: "".concat(offsetY),
      transform: 'translate(100%, 50%) rotate(180deg)'
    },
    right: {
      top: '50%',
      right: 'auto',
      left: '0',
      bottom: 'auto',
      transform: 'translate(-100%, -50%) rotate(0deg)'
    },
    rightStart: {
      top: "".concat(offsetY),
      right: 'auto',
      left: '0',
      bottom: 'auto',
      transform: 'translate(-100%, -50%) rotate(0deg)'
    },
    rightEnd: {
      top: 'auto',
      right: 'auto',
      left: '0',
      bottom: "".concat(offsetY),
      transform: 'translate(-100%, 50%) rotate(0deg)'
    }
  };
  return positions[placement] || positions.top;
};