import { jsxs as l, jsx as o } from "react/jsx-runtime";
import { translationService as F } from "./index-translation.service.js";
import { Button as S, ButtonSizes as y, ButtonTypes as g } from "./index-Button.js";
import { ComponentContainer as m } from "./index-ComponentContainer.js";
import { ContentType as n } from "./index-Document.types.js";
import { DocumentContentProcessor as U } from "./index-DocumentContentProcessor.js";
import { ImageContentProcessor as B } from "./index-ImageContentProcessor.js";
import { ImageCompressorTransformer as R } from "./index-ImageCompressorTransformer.js";
import { FileSizeValidator as A } from "./index-FileSizeValidator.js";
import { MediaItemSelectInput as O } from "./index-MediaItemSelectInput.js";
import { Icon as W, IconSize as _ } from "./index-Icon.js";
import { IconNames as V } from "./index-IconNames.js";
import { Render as T } from "./index-Render.js";
import { snackbarService as j } from "./index-SnackBarService.js";
import { Text as D, FontWeights as P, TextTypes as H } from "./index-Text.js";
import { useState as x } from "react";
import s from "./index-DocumentUpload.module.scss.js";
import J from "./index-Collapse2.js";
import { DocumentDisplay as q } from "./index-DocumentDisplay.js";
const L = new R({
  compressorOptions: {
    maxWidth: 3e3,
    maxHeight: 3e3,
    quality: 0.8,
    convertSize: 5242880
  }
}), K = new U(), Q = new B({}), X = new A({
  maxSize: 5242880
}), Se = (t) => {
  const {
    testId: N = "DocumentUpload",
    onDocumentSelected: k,
    onDocumentRemoved: v,
    width: a = "192px",
    height: c = "154px",
    documentName: r
  } = t, [e, p] = x(), [w, d] = x(!1), z = r ? F.get("Upload %documentName%", {
    documentName: r
  }).value : "Upload document", M = (G) => {
    var C, I;
    const i = G[0];
    if (!i) return;
    if (i.isInvalid) {
      j.openErrorSnackbar("File size must be between 10kb and 5MB.");
      return;
    }
    const h = (C = i.mediaItemContent) == null ? void 0 : C.base64EncodedContent;
    if (!h) return;
    const E = ((I = i.file) == null ? void 0 : I.name) ?? "document", u = {
      srcIsBase64: !0,
      fileSrc: h,
      fileName: E,
      fileMimeType: i.fileType,
      documentName: r
    };
    p(u), k(u);
  }, b = () => {
    p(void 0), v();
  }, f = () => {
    d(!0);
  };
  return l(m, {
    testId: N,
    className: s.container,
    children: [o(D, {
      type: H.textHelp,
      fontWeight: P.medium,
      children: r
    }), o(J, {
      in: !!(e != null && e.fileSrc),
      children: o(Z, {
        onRemove: b,
        onChange: f
      })
    }), o(T, {
      if: !(e != null && e.fileSrc) || !(e != null && e.fileMimeType),
      children: o("div", {
        style: {
          width: a,
          height: c
        },
        children: o(Y, {
          text: z,
          onClick: f
        })
      })
    }), o(T, {
      if: !!(e != null && e.fileSrc) && !!(e != null && e.fileMimeType),
      children: o(q, {
        fileName: (e == null ? void 0 : e.fileName) ?? "file",
        fileSrc: (e == null ? void 0 : e.fileSrc) ?? "",
        fileMimeType: e == null ? void 0 : e.fileMimeType,
        width: a,
        height: c,
        showDownload: !1
      })
    }), o(O, {
      isOpen: w,
      openCallback: () => d(!1),
      accept: [n.APPLICATION_PDF, n.IMAGE_PNG, n.IMAGE_JPG, n.IMAGE_JPEG],
      mediaItemTransformers: [L],
      mediaItemProcessors: [K, Q],
      mediaItemValidators: [X],
      onFilesSelected: M
    })]
  });
}, Y = (t) => l(m, {
  testId: "UploadDocumentPlaceholder",
  onClick: t.onClick,
  className: s.button,
  children: [o(W, {
    type: _.large,
    hasCircle: !0,
    color: "--n000",
    fillColor: "--p500",
    circleSize: 40,
    children: V.add
  }), o(D, {
    fontWeight: P.bold,
    color: "--p500",
    children: t.text
  })]
}), Z = (t) => l(m, {
  testId: "UploadDocumentEditGroup",
  className: s.editGroup,
  children: [o(S, {
    onClick: t.onRemove,
    type: g.secondary,
    size: y.small,
    children: "Remove"
  }), o(S, {
    onClick: t.onChange,
    type: g.secondary,
    size: y.small,
    children: "Change"
  })]
});
export {
  Se as DocumentUpload
};
