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 } from 'common/contract'
import { formatMoney } from 'common/util/format'
import {
contractPath,
contractPool,
getBinaryProbPercent,
updateContract,
} from 'web/lib/firebase/contracts'
import { LiquidityPanel } from '../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'
import { InfoTooltip } from '../info-tooltip'
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,
mechanism,
outcomeType,
autoResolutionTime,
} = contract
const tradersCount = uniqBy(
bets.filter((bet) => !bet.isAnte),
'userId'
).length
const typeDisplay =
outcomeType === 'BINARY'
? 'YES / NO'
: outcomeType === 'FREE_RESPONSE'
? 'Free response'
: 'Numeric'
return (
<>
Type
{typeDisplay}
Payout
{mechanism === 'cpmm-1' ? (
<>
Fixed{' '}
{closeTime && (
Market created
{formatTime(createdTime)}
)}
{autoResolutionTime && !resolutionTime && (
Market close{closeTime > Date.now() ? 's' : 'd'}
{formatTime(closeTime)}
)}
Market resolved
{formatTime(resolutionTime)}
Volume
{formatMoney(contract.volume)}
Creator earnings
{formatMoney(contract.collectedFees.creatorFee)}
Traders
{tradersCount}
{mechanism === 'cpmm-1' ? 'Liquidity pool' : 'Betting pool'}
{contractPool(contract)}