'use strict';
import { c } from 'react/compiler-runtime';
import { jsx } from 'react/jsx-runtime';
import { useState } from 'react';
import { CardBigDigits } from '../../../fd-component-toolbox/card/CardBigDigits.js';
import { useAsyncEffect } from '../../../../fd-toolbox/hooks/use-async-effect.js';
import { initReportCard } from './ReportCard.funcs.js';
import { ensureString } from '../../../../fd-toolbox/types/ensure-type.js';
import { useOptionalPromise } from '../../../../fd-toolbox/hooks/use-optional-promise.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function ReportCard(t0) {
  const $ = c(9);
  const {
    report,
    reportId
  } = t0;
  const optionalReport = useOptionalPromise(report);
  const [internalReport, setInternalReport] = useState(optionalReport);
  const [reportData, setReportData] = useState();
  let t1;
  let t2;
  if ($[0] !== optionalReport || $[1] !== reportId) {
    t1 = async () => {
      await initReportCard(setInternalReport, setReportData, optionalReport, reportId);
    };
    t2 = [optionalReport, reportId];
    $[0] = optionalReport;
    $[1] = reportId;
    $[2] = t1;
    $[3] = t2;
  } else {
    t1 = $[2];
    t2 = $[3];
  }
  useAsyncEffect(t1, t2);
  if (!reportData || !internalReport) {
    let t3;
    if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
      t3 = jsx("div", {
        children: "Loading report..."
      });
      $[4] = t3;
    } else {
      t3 = $[4];
    }
    return t3;
  }
  let t3;
  if ($[5] !== internalReport?.description || $[6] !== internalReport?.name || $[7] !== reportData) {
    const displayValue = ensureString(reportData) ?? "0";
    const title = internalReport?.name ?? "Untitled Report";
    const subtitle = internalReport?.description;
    t3 = jsx(CardBigDigits, {
      title,
      value: displayValue,
      subtitle
    });
    $[5] = internalReport?.description;
    $[6] = internalReport?.name;
    $[7] = reportData;
    $[8] = t3;
  } else {
    t3 = $[8];
  }
  return t3;
}
__name(ReportCard, "ReportCard");

export { ReportCard };
