import { Tooltip } from "antd";
import dayjs from "../utils/day";

export function DateFormatter(props) {
  return props.children ? dayjs(props.children).format(props.includeDay ? "ddd MM/DD/YYYY" : "MM/DD/YYYY") : null;
}

export function DateTimeFormatter({ hideTime, ...props }) {
  return props.children
    ? dayjs(props.children).format(props.format ? props.format : `MM/DD/YYYY${hideTime ? "" : " hh:mm a"}`)
    : null;
}

export function DateTimeFormatterFunction(date) {
  return dayjs(date).format("MM/DD/YYYY hh:mm a");
}

export function TimeFormatter(props) {
  return props.children ? dayjs(props.children).format(props.format ? props.format : "hh:mm a") : null;
}

export function TimeAgoFormatter({ removeAgoString = false, ...props }) {
  const m = dayjs(props.children);
  return props.children ? (
    <Tooltip placement="top" title={m.format("MM/DD/YYYY hh:mm A")}>
      {m.fromNow(removeAgoString)}
    </Tooltip>
  ) : null;
}

export function DateTimeFormat(value) {
  return dayjs(value).format("MM/DD/YYYY hh:mm A");
}
