All files / libs/lti/components/src/lib/enrollment/kpi-structure-widget KpiStructureWidgetGrantedSharesForKpi.tsx

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

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 97 98 99 100 101 102 103 104                                                                                                                                                                                                               
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 { useFormatPercent } from '@amalia/kernel/intl/components';
import { type CompanyShareWithPrice, type LtiPlanKpi } from '@amalia/lti/types';
import { ChartSeriesIcon, useChartColor } from '@amalia/reporting/dashboards-v2/components';
import { ChartSeriesType } from '@amalia/reporting/dashboards-v2/types';

import { MonetaryValueForWidget } from '../common/MonetaryValueForWidget';

type KpiStructureWidgetGrantedSharesForKpiProps = {
  readonly kpi: Pick<LtiPlanKpi, 'color' | 'id' | 'name' | 'weight'>;
  readonly sharesCount: number;
  readonly sharePrice?: CompanyShareWithPrice;
  readonly showMonetaryValue?: boolean;
  readonly showGrantedSharesBreakdown?: boolean;
};

export const KpiStructureWidgetGrantedSharesForKpi = memo(function KpiStructureWidgetGrantedSharesForKpi({
  kpi,
  sharesCount,
  sharePrice,
  showGrantedSharesBreakdown,
  showMonetaryValue,
}: KpiStructureWidgetGrantedSharesForKpiProps) {
  const chartColors = useChartColor();
  const formatPercent = useFormatPercent();

  const sharesCountForKpi = sharesCount * kpi.weight;
  const sharesPriceForKpi = sharesCountForKpi * (sharePrice?.value ?? 0);

  return (
    <Stack
      gap={16}
      css={css`
        padding: 20px 32px 20px 40px;
        flex: 1;

        & + & {
          border-left: 1px solid var(--ds-border-color-100);
        }
      `}
    >
      <Group justify="space-between">
        <Group
          align="center"
          gap={12}
        >
          <ChartSeriesIcon series={{ color: chartColors[kpi.color], type: ChartSeriesType.BAR }} />
          <Typography
            variant="bodyBaseMedium"
            css={css`
              color: var(--ds-text-color-800);
            `}
          >
            {kpi.name}
          </Typography>
        </Group>

        <Typography
          variant="bodyBaseMedium"
          css={css`
            color: var(--ds-text-color-800);
          `}
        >
          {formatPercent(kpi.weight)}
        </Typography>
      </Group>

      {!!showGrantedSharesBreakdown && (
        <Stack gap={6}>
          <Typography
            variant="bodySmallRegular"
            css={css`
              color: var(--ds-text-color-500);
            `}
          >
            <FormattedMessage defaultMessage="Granted shares" />
          </Typography>

          <Group
            align="baseline"
            justify="space-between"
          >
            <Typography variant="heading4Medium">
              <FormattedNumber value={sharesCountForKpi} />
            </Typography>

            {!!(showMonetaryValue && sharePrice) && (
              <MonetaryValueForWidget
                symbol={sharePrice.currency}
                value={sharesPriceForKpi}
                valueTypographyVariant="bodyLargeRegular"
              />
            )}
          </Group>
        </Stack>
      )}
    </Stack>
  );
});