import { format, addMilliseconds } from "date-fns"
import { BLOCK_TIME } from "../../constants"

/* end */
export const estimateTime = (current: number, next: number) => {
  const estimated = addMilliseconds(new Date(), (next - current) * BLOCK_TIME)
  return format(estimated, "EEE, LLL dd, HH:mm aa")
}

/* link */
export const replaceLink = (paragraph: string = "") => {
  const replaced = paragraph.replace(
    /(https?:\/\/[^\s]+)/g,
    '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>'
  )

  return { dangerouslySetInnerHTML: { __html: replaced } }
}

{'avg_line_length': 30.210526315789473, 'max_line_length': 78, 'alphanum_fraction': 0.6428571428571429, 'licenses': ['Apache-2.0'], 'repository_name': 'theweaver19/terra-web-app', 'path': 'src/pages/Poll/pollHelpers.ts', 'size': 574, 'lang': 'TypeScript'}