2021-03-31 06:45:21 +02:00
|
|
|
import * as React from "react";
|
|
|
|
import { numeralWrapper } from "../../ui/numeralFormat";
|
2021-09-04 09:27:31 +02:00
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
2021-10-01 19:08:37 +02:00
|
|
|
import { Theme } from "@mui/material/styles";
|
|
|
|
import makeStyles from "@mui/styles/makeStyles";
|
|
|
|
import createStyles from "@mui/styles/createStyles";
|
|
|
|
|
|
|
|
const useStyles = makeStyles((theme: Theme) =>
|
|
|
|
createStyles({
|
|
|
|
unbuyable: {
|
|
|
|
color: theme.palette.action.disabled,
|
|
|
|
},
|
|
|
|
money: {
|
|
|
|
color: theme.colors.money,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2021-03-31 06:45:21 +02:00
|
|
|
|
2021-09-04 09:27:31 +02:00
|
|
|
interface IProps {
|
2021-09-05 01:09:30 +02:00
|
|
|
money: number | string;
|
|
|
|
player?: IPlayer;
|
2021-09-04 09:27:31 +02:00
|
|
|
}
|
2021-10-01 19:08:37 +02:00
|
|
|
export function Money(props: IProps): React.ReactElement {
|
|
|
|
const classes = useStyles();
|
2021-09-05 01:09:30 +02:00
|
|
|
if (props.player !== undefined) {
|
2021-09-09 05:47:34 +02:00
|
|
|
if (typeof props.money !== "number") throw new Error("if player if provided, money should be number, contact dev");
|
2021-09-05 01:09:30 +02:00
|
|
|
if (!props.player.canAfford(props.money))
|
2021-10-01 19:08:37 +02:00
|
|
|
return <span className={classes.unbuyable}>{numeralWrapper.formatMoney(props.money)}</span>;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
return (
|
2021-10-01 19:08:37 +02:00
|
|
|
<span className={classes.money}>
|
2021-09-09 05:47:34 +02:00
|
|
|
{typeof props.money === "number" ? numeralWrapper.formatMoney(props.money) : props.money}
|
2021-09-05 01:09:30 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|