import { jsxs as E, jsx as e } from "react/jsx-runtime";
import { px2 as x } from "./index-general.module.js";
import { inspectFileMimeTypeFromURL as _, downloadFile as g } from "./index-download-helpers.js";
import { Button as w, ButtonSizes as I, ButtonTypes as C } from "./index-Button.js";
import { ComponentContainer as G } from "./index-ComponentContainer.js";
import { Icon as M, IconSize as P } from "./index-Icon.js";
import { IconNames as c } from "./index-IconNames.js";
import { Render as D } from "./index-Render.js";
import { Text as p, FontWeights as F, TextTypes as f } from "./index-Text.js";
import { useState as A, useEffect as S } from "react";
import { CONTENT_TYPE_IMAGE_PNG as W, CONTENT_TYPE_IMAGE_JPG as v, CONTENT_TYPE_IMAGE_JPEG as z } from "./index-Document.types.js";
import r from "./index-DocumentDisplay.module.scss.js";
import h from "./index-Collapse2.js";
const K = (l) => {
  const {
    testId: i = "DocumentDisplay",
    fileSrc: t,
    width: o = "192px",
    height: n = "154px",
    documentName: u,
    showDownload: y = !0,
    fileName: m,
    fileMimeType: s
  } = l, [a, d] = A(s);
  S(() => {
    s == "unknown" ? _(t).then((T) => {
      d(T);
    }) : d(s);
  }, [t]);
  const N = () => [W, v, z].includes(a) ? e("div", {
    "data-testid": `${i}_IMAGE`,
    className: r.image,
    style: {
      width: o,
      height: n
    },
    children: e("img", {
      src: t
    })
  }) : a == "application/pdf" ? e("embed", {
    "data-testid": `${i}_PDF`,
    className: r.pdf,
    src: t,
    type: "application/pdf",
    width: o,
    height: n
  }) : e("div", {
    "data-testid": `${i}_IMAGE`,
    className: r.image,
    style: {
      width: o,
      height: n
    },
    children: e(M, {
      color: "--n400",
      type: P.large,
      children: c.document
    })
  });
  return E(G, {
    testId: i,
    className: r.container,
    children: [e(h, {
      in: !!u,
      children: e(p, {
        type: f.textHelp,
        fontWeight: F.medium,
        children: l.documentName
      })
    }), e(D, {
      if: y,
      children: e(w, {
        onClick: () => g(t, m, a),
        type: C.secondary,
        size: I.small,
        iconLeft: c.download,
        children: "Download"
      })
    }), N(), e(h, {
      in: !!m,
      children: e("div", {
        style: {
          maxWidth: o
        },
        children: e(p, {
          type: f.textCaption,
          color: "--n500",
          className: x,
          textWrap: "wrap",
          children: m
        })
      })
    })]
  });
};
export {
  K as DocumentDisplay
};
