"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var attachment_bar_exports = {};
__export(attachment_bar_exports, {
  AttachmentBar: () => AttachmentBar
});
module.exports = __toCommonJS(attachment_bar_exports);
var import_design_system = require("@wix/design-system");
var import_wix_ui_icons_common = require("@wix/wix-ui-icons-common");
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../../ricos-context/index.js");
var import_uncreachable = require("./../../uncreachable.js");
var import_attachment_bar_scss = __toESM(require("./attachment-bar-scss.js"));
const resolveImageUrl = (url) => {
  if (url.startsWith("http://") || url.startsWith("https://")) {
    return url;
  }
  const mediaId = url.startsWith("media/") ? url : `media/${url}`;
  return `https://static.wixstatic.com/${mediaId}`;
};
const AttachmentBar = ({ attachments, onRemove }) => {
  return /* @__PURE__ */ import_react.default.createElement("div", { className: import_attachment_bar_scss.default.root }, attachments.map(
    (attachment) => ["png", "jpg", "jpeg"].includes(attachment.file.type) ? /* @__PURE__ */ import_react.default.createElement(ImageAttachment, { key: attachment.id, attachment, onRemove }) : /* @__PURE__ */ import_react.default.createElement(FileAttachment, { key: attachment.id, attachment, onRemove })
  ));
};
const ImageAttachment = ({
  attachment,
  onRemove
}) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: import_attachment_bar_scss.default.attachmentWrapper }, (() => {
    switch (attachment.status) {
      case "ok": {
        return /* @__PURE__ */ import_react.default.createElement(
          import_design_system.Image,
          {
            src: resolveImageUrl(attachment.file.url),
            showBorder: true,
            width: 48,
            height: "100%"
          }
        );
      }
      case "loading": {
        return /* @__PURE__ */ import_react.default.createElement("div", { className: import_attachment_bar_scss.default.statusIconContainer }, /* @__PURE__ */ import_react.default.createElement(import_design_system.Loader, { size: "tiny" }));
      }
      case "error": {
        return /* @__PURE__ */ import_react.default.createElement("div", { className: import_attachment_bar_scss.default.statusIconContainer }, /* @__PURE__ */ import_react.default.createElement(
          import_design_system.StatusIndicator,
          {
            status: "error",
            message: attachment.error,
            tooltipProps: { enterDelay: 300 }
          }
        ));
      }
      default:
        return null;
    }
  })(), /* @__PURE__ */ import_react.default.createElement(
    RemoveButton,
    {
      label: t("HtmlPlugin_AiWidget_Remove_Image_Attachment_Button_AriaLabel"),
      onRemove: () => onRemove(attachment.id)
    }
  ));
};
const FileAttachment = ({ attachment, onRemove }) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const { name, type } = attachment.file;
  const getAttachmentIcon = (fileType) => {
    switch (fileType) {
      case "csv":
        return /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.DataCollection, { color: "#fff" });
      case "pdf":
        return /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.Document, { color: "#fff" });
      case "text":
      default:
        return /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.Document, { color: "#000" });
    }
  };
  const getIconBackground = () => {
    switch (attachment.status) {
      case "ok":
        if (type === "csv") {
          return "#25A55A";
        }
        if (type === "pdf") {
          return "#E62214";
        }
        return "#ECEFF3";
      case "loading":
        return "#ECEFF3";
      case "error":
        return "#fde3e1";
      default:
        (0, import_uncreachable.unreachable)(attachment);
        return null;
    }
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: import_attachment_bar_scss.default.attachmentWrapper }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(import_attachment_bar_scss.default.fileAttachment, {
        [import_attachment_bar_scss.default.error]: attachment.status === "error"
      }),
      style: {
        "--ricos-internal-file-attachment-background-color": getIconBackground()
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: import_attachment_bar_scss.default.fileAttacmentIcon }, (() => {
      switch (attachment.status) {
        case "ok":
          return getAttachmentIcon(type);
        case "loading":
          return /* @__PURE__ */ import_react.default.createElement(import_design_system.Loader, { size: "tiny" });
        case "error":
          return /* @__PURE__ */ import_react.default.createElement(
            import_design_system.StatusIndicator,
            {
              status: "error",
              message: attachment.error,
              tooltipProps: { enterDelay: 300 }
            }
          );
        default:
          (0, import_uncreachable.unreachable)(attachment);
          return null;
      }
    })()),
    /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { direction: "vertical", width: 137 }, /* @__PURE__ */ import_react.default.createElement(import_design_system.Text, { size: "small", weight: "normal", ellipsis: true, enterDelay: 300 }, name), /* @__PURE__ */ import_react.default.createElement(
      import_design_system.Text,
      {
        size: "tiny",
        weight: "thin",
        ellipsis: true,
        enterDelay: 300,
        skin: attachment.status === "error" ? "error" : void 0
      },
      (() => {
        switch (attachment.status) {
          case "ok":
          case "loading":
            return type.toUpperCase();
          case "error":
            return t("UploadFile_Error_Generic_Toast");
          default:
            (0, import_uncreachable.unreachable)(attachment);
            return null;
        }
      })()
    ))
  ), /* @__PURE__ */ import_react.default.createElement(
    RemoveButton,
    {
      label: t("HtmlPlugin_AiWidget_Remove_Attachment_Button_AriaLabel", { fileName: name }),
      onRemove: () => onRemove(attachment.id)
    }
  ));
};
const RemoveButton = ({ label, onRemove }) => /* @__PURE__ */ import_react.default.createElement("div", { className: import_attachment_bar_scss.default.removeButton }, /* @__PURE__ */ import_react.default.createElement(import_design_system.CloseButton, { "aria-label": label, size: "small", skin: "standardFilled", onClick: onRemove }));
//# sourceMappingURL=attachment-bar.js.map
