import clsx from 'clsx'
import { Answer } from 'common/answer'
import { getProbability } from 'common/calculate'
import { getValueFromBucket } from 'common/calculate-dpm'
import {
Binary,
Contract,
CPMM,
DPM,
FreeResponse,
FreeResponseContract,
FullContract,
NumericContract,
} from 'common/contract'
import { formatPercent } from 'common/util/format'
import { ClientRender } from './client-render'
export function OutcomeLabel(props: {
contract: Contract
outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' | string
truncate: 'short' | 'long' | 'none'
value?: number
}) {
const { outcome, contract, truncate, value } = props
if (contract.outcomeType === 'BINARY')
return
if (contract.outcomeType === 'NUMERIC')
return (
{value ?? getValueFromBucket(outcome, contract as NumericContract)}
)
return (
}
resolution={outcome}
truncate={truncate}
answerClassName={'font-bold text-base-400'}
/>
)
}
export function BinaryOutcomeLabel(props: {
outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT'
}) {
const { outcome } = props
if (outcome === 'YES') return
if (outcome === 'NO') return
if (outcome === 'MKT') return
return
}
export function BinaryContractOutcomeLabel(props: {
contract: FullContract
resolution: 'YES' | 'NO' | 'CANCEL' | 'MKT'
}) {
const { contract, resolution } = props
if (resolution === 'MKT') {
const prob = contract.resolutionProbability ?? getProbability(contract)
return
}
return
}
export function FreeResponseOutcomeLabel(props: {
contract: FreeResponseContract
resolution: string | 'CANCEL' | 'MKT'
truncate: 'short' | 'long' | 'none'
answerClassName?: string
}) {
const { contract, resolution, truncate, answerClassName } = props
if (resolution === 'CANCEL') return
if (resolution === 'MKT') return
const { answers } = contract
const chosen = answers?.find((answer) => answer.id === resolution)
if (!chosen) return
return (
TOP
{/* */}
)
}
export const OUTCOME_TO_COLOR = {
YES: 'primary',
NO: 'red-400',
CANCEL: 'yellow-400',
MKT: 'blue-400',
}
export function YesLabel() {
return YES
}
export function NoLabel() {
return NO
}
export function CancelLabel() {
return N/A
}
export function ProbLabel() {
return PROB
}
export function MultiLabel() {
return MANY
}
export function ProbPercentLabel(props: { prob: number }) {
const { prob } = props
return {formatPercent(prob)}
}
export function AnswerNumberLabel(props: { number: string }) {
return #{props.number}
}
export function AnswerLabel(props: {
answer: Answer
truncate: 'short' | 'long' | 'none'
className?: string
}) {
const { answer, truncate, className } = props
const { text } = answer
let truncated = text
if (truncate === 'short' && text.length > 20) {
truncated = text.slice(0, 10) + '...' + text.slice(-10)
} else if (truncate === 'long' && text.length > 75) {
truncated = text.slice(0, 75) + '...'
}
return (
{truncated}
)
}
function FreeResponseAnswerToolTip(props: {
text: string
children?: React.ReactNode
}) {
const { text } = props
return (
<>
{props.children}
{props.children}
>
)
}