import React from "react"; import { Constants, HitPointInfo, RuleData, RuleDataUtils, } from "@dndbeyond/character-rules-engine/es"; import { Inspiration } from "~/subApps/sheet/components/Inspiration"; interface Props { hitPointInfo: HitPointInfo; fails: number; successes: number; deathCause: string; inspiration: boolean; ruleData: RuleData; onHealthClick?: () => void; onInspirationClick?: () => void; isInteractive: boolean; } export default class StatusSummaryMobile extends React.PureComponent { static defaultProps = { isInteractive: true, }; handleHealthClick = (evt: React.MouseEvent): void => { const { onHealthClick } = this.props; if (onHealthClick) { evt.stopPropagation(); evt.nativeEvent.stopImmediatePropagation(); onHealthClick(); } }; handleInspirationToggle = (): void => { const { onInspirationClick } = this.props; if (onInspirationClick) { onInspirationClick(); } }; renderHitPointSummary = (): React.ReactNode => { const { hitPointInfo } = this.props; let tempHp: number = hitPointInfo.tempHp === null ? 0 : hitPointInfo.tempHp; let classNames: Array = [ "ct-status-summary-mobile__data", "ct-status-summary-mobile__hp", ]; if (tempHp > 0) { classNames.push("ct-status-summary-mobile__hp--has-temp"); } return (
{hitPointInfo.remainingHp + tempHp} / {hitPointInfo.totalHp + tempHp}
); }; renderDeathSavesSummaryMarkGroup = ( key: string, label: string, activeCount: number, totalCount: number ): React.ReactNode => { let marks: Array = []; for (let i = 0; i < totalCount; i++) { let classNames: Array = [ "ct-status-summary-mobile__deathsaves-mark", `ct-status-summary-mobile__deathsaves-mark--${ i < activeCount ? "active" : "inactive" }`, ]; marks.push(); } return (
{label} {marks}
); }; renderDeathSavesSummary = (): React.ReactNode => { const { fails, successes, ruleData } = this.props; return (
{this.renderDeathSavesSummaryMarkGroup( "fail", "f", fails, RuleDataUtils.getMaxDeathsavesFail(ruleData) )} {this.renderDeathSavesSummaryMarkGroup( "success", "s", successes, RuleDataUtils.getMaxDeathsavesSuccess(ruleData) )}
); }; renderDeathExhaustionSummary = (): React.ReactNode => { return (
Exhaustion Level 6
); }; render() { const { hitPointInfo, deathCause, isInteractive, inspiration } = this.props; let statusSummaryNode: React.ReactNode; let statusSummaryLabel: React.ReactNode; if (deathCause === Constants.DeathCauseEnum.CONDITION) { statusSummaryNode = this.renderDeathExhaustionSummary(); statusSummaryLabel = null; } else if (hitPointInfo.remainingHp <= 0) { statusSummaryNode = this.renderDeathSavesSummary(); statusSummaryLabel = "Death Saves"; } else { statusSummaryNode = this.renderHitPointSummary(); statusSummaryLabel = "Hit Points"; } return (
{statusSummaryLabel}
{statusSummaryNode}
); } }