All files / libs/lti/components/src/lib/enrollment/simulation-widget/kpi-chart SimulationWidgetPresentationKpiChart.tsx

0% Statements 0/95
0% Branches 0/1
0% Functions 0/1
0% Lines 0/95

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96                                                                                                                                                                                               
import { css } from '@emotion/react';
import { memo } from 'react';
import { FormattedMessage, FormattedNumber } from 'react-intl';

import { Group, Stack, Typography } from '@allshares/studio-design-system';
import { type CurrencySymbolsEnum } from '@amalia/ext/iso-4217';
import { type CompanyShareWithPrice, type EnrollmentSimulationWidget, type LtiPlanKpi } from '@amalia/lti/types';

import { KpiPerformanceChart } from '../../../forms/fields/kpi-performance/chart/KpiPerformanceChart';
import { MonetaryValueForWidget } from '../../common/MonetaryValueForWidget';
import { type SimulationWidgetSize } from '../types';

export type SimulationWidgetPresentationKpiChartProps = {
  readonly kpi: LtiPlanKpi;
  readonly sharePrice?: CompanyShareWithPrice;
  readonly sharesEarned: number;
  readonly simulatedKpiValue?: number;
  readonly simulatedSharePrice: number;
  readonly currency: CurrencySymbolsEnum;
  readonly size: SimulationWidgetSize;

  readonly widgetConfiguration: Pick<
    EnrollmentSimulationWidget,
    'showKpiBreakdown' | 'showMonetaryValues' | 'showSharePriceSlider'
  >;
};

export const SimulationWidgetPresentationKpiChart = memo(function SimulationWidgetPresentationKpiChart({
  kpi,
  sharePrice,
  sharesEarned,
  simulatedKpiValue,
  simulatedSharePrice,
  currency,
  size,
  widgetConfiguration,
}: SimulationWidgetPresentationKpiChartProps) {
  return (
    <Stack
      gap={size === 'compact' ? 16 : 24}
      css={css`
        flex: none;
        width: var(--widget-block-width);
        padding: ${size === 'compact' ? '24px 32px 16px' : '24px 40px 20px'};
      `}
    >
      <Group justify="space-between">
        <Stack
          grow
          gap={size === 'compact' ? 6 : 8}
        >
          <Typography
            variant={size === 'compact' ? 'bodyXsmallRegular' : 'bodySmallRegular'}
            css={css`
              color: var(--ds-text-color-500);
            `}
          >
            <FormattedMessage
              defaultMessage="Shares from {kpiName}"
              values={{ kpiName: kpi.name }}
            />
          </Typography>

          <Group
            align="baseline"
            justify="space-between"
          >
            <Typography variant={size === 'compact' ? 'heading4Medium' : 'heading1Medium'}>
              <FormattedNumber value={sharesEarned} />
            </Typography>

            {!!(sharePrice && widgetConfiguration.showMonetaryValues) && (
              <MonetaryValueForWidget
                symbol={sharePrice.currency}
                symbolTypographyVariant={size === 'compact' ? 'bodyXsmallRegular' : 'bodyLargeRegular'}
                value={sharesEarned * simulatedSharePrice}
                valueTypographyVariant={size === 'compact' ? 'bodyLargeRegular' : 'heading2Regular'}
                css={css`
                  justify-self: end;
                `}
              />
            )}
          </Group>
        </Stack>
      </Group>

      <KpiPerformanceChart
        kpi={kpi}
        kpiCurrencySymbol={currency}
        simulatedKpiValue={simulatedKpiValue ?? 0}
        style={{ height: size === 'compact' ? '140px' : '180px' }}
      />
    </Stack>
  );
});