import {
DotsHorizontalIcon,
PencilIcon,
CheckIcon,
} from '@heroicons/react/outline'
import clsx from 'clsx'
import dayjs from 'dayjs'
import { uniqBy } from 'lodash'
import { useState } from 'react'
import { Bet } from 'common/bet'
import { Contract, contractField } from 'common/contract'
import { formatMoney } from 'common/util/format'
import {
contractPath,
contractPool,
getBinaryProbPercent,
updateContract,
} from 'web/lib/firebase/contracts'
import { AddLiquidityPanel } from '../add-liquidity-panel'
import { CopyLinkButton } from '../copy-link-button'
import { Col } from '../layout/col'
import { Modal } from '../layout/modal'
import { Row } from '../layout/row'
import { ShareEmbedButton } from '../share-embed-button'
import { TagsInput } from '../tags-input'
import { Title } from '../title'
import { TweetButton } from '../tweet-button'
const formatTime = (dt: number) => dayjs(dt).format('MMM DD, YYYY hh:mm a z')
export function ContractInfoDialog(props: {
contract: Contract
bets: Bet[]
isCreator: boolean
}) {
const { contract, bets, isCreator } = props
const [open, setOpen] = useState(false)
const {
createdTime,
closeTime,
resolutionTime,
autoResolutionTime,
autoResolution,
} = contract
const tradersCount = uniqBy(bets, 'userId').length
return (
<>
{closeTime && (
Market created
{formatTime(createdTime)}
)}
{autoResolutionTime && !resolutionTime && (
<>
Market close{closeTime > Date.now() ? 's' : 'd'}
{formatTime(closeTime)}
>
)}
{resolutionTime && (
Auto resolution
{contract.autoResolution}
)}
Market resolved
{formatTime(resolutionTime)}
Volume
{formatMoney(contract.volume)}
Creator earnings
{formatMoney(contract.collectedFees.creatorFee)}
Traders
{tradersCount}
Pool
{contractPool(contract)}