import { useState } from 'react'
import {
compute,
Contract,
deleteContract,
setContract,
} from '../lib/firebase/contracts'
import { Col } from './layout/col'
import { Spacer } from './layout/spacer'
import { ContractProbGraph } from './contract-prob-graph'
import router from 'next/router'
import { useUser } from '../hooks/use-user'
import { Row } from './layout/row'
import dayjs from 'dayjs'
import { Linkify } from './linkify'
import clsx from 'clsx'
import { ContractDetails } from './contract-card'
function ContractDescription(props: {
contract: Contract
isCreator: boolean
}) {
const { contract, isCreator } = props
const [editing, setEditing] = useState(false)
const editStatement = () => `${dayjs().format('MMM D, h:mma')}: `
const [description, setDescription] = useState(editStatement())
// Append the new description (after a newline)
async function saveDescription(e: any) {
e.preventDefault()
setEditing(false)
contract.description = `${contract.description}\n${description}`.trim()
await setContract(contract)
setDescription(editStatement())
}
return (
{isCreator &&
!contract.resolution &&
(editing ? (
) : (
))}
)
}
function ResolutionOrChance(props: {
resolution?: 'YES' | 'NO' | 'MKT' | 'CANCEL'
probPercent: string
className?: string
}) {
const { resolution, probPercent, className } = props
const resolutionColor = {
YES: 'text-primary',
NO: 'text-red-400',
MKT: 'text-blue-400',
CANCEL: 'text-yellow-400',
'': '', // Empty if unresolved
}[resolution || '']
return (
{resolution ? (
<>
Resolved
{resolution === 'CANCEL' ? 'N/A' : resolution}
>
) : (
<>
{probPercent}
chance
>
)}
)
}
export const ContractOverview = (props: {
contract: Contract
className?: string
}) => {
const { contract, className } = props
const { resolution, creatorId } = contract
const { probPercent, truePool } = compute(contract)
const user = useUser()
const isCreator = user?.id === creatorId
return (
{((isCreator && !contract.resolution) || contract.description) && (
)}
{/* Show a delete button for contracts without any trading */}
{isCreator && truePool === 0 && (
<>
>
)}
)
}