"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 node_styles_exports = {};
__export(node_styles_exports, {
  getContainerData: () => getContainerData,
  getNodeWidth: () => getNodeWidth,
  getPluginContainerClassNames: () => getPluginContainerClassNames,
  getPluginFocusClassNames: () => getPluginFocusClassNames,
  getPluginPlacementClassNames: () => getPluginPlacementClassNames
});
module.exports = __toCommonJS(node_styles_exports);
var import_classnames = __toESM(require("classnames"));
var import_lodash = __toESM(require("lodash"));
var import_v1 = require("./../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_general_scss = __toESM(require("./../wix-rich-content-common/statics/styles/general-scss.js"));
var import_general_scss2 = __toESM(require("./../editor-common/statics/styles/general-scss.js"));
var import_consts = require("./../plugin-shape/utils/consts.js");
const stylesWithRTL = { ...import_general_scss2.default, ...import_general_scss.default };
const getAlignmentClassName = (alignment) => {
  if (!alignment || alignment === import_v1.PluginContainerData_Alignment.UNRECOGNIZED) {
    return "";
  }
  return stylesWithRTL[`align${import_lodash.default.upperFirst(alignment.toLowerCase())}`];
};
const getSizeClassName = (size) => {
  if (!size || size === import_v1.PluginContainerData_Width_Type.UNRECOGNIZED) {
    return "";
  }
  return stylesWithRTL[`size${import_lodash.default.upperFirst(import_lodash.default.camelCase(size))}`];
};
const getTextWrapClassName = (textWrap) => textWrap === false ? stylesWithRTL.textWrapNowrap : "";
const isCustomWidthDisabled = (node, isMobile) => {
  if (node.type.name === import_v1.Node_Type.IMAGE) {
    const componentData = node.attrs;
    return !!(isMobile && componentData?.image?.width && Number(componentData?.containerData?.width?.custom || 0) > 150);
  }
  return false;
};
const getOriginalWidth = (node) => {
  switch (node.type.name) {
    case import_v1.Node_Type.IMAGE:
      return node.attrs?.image?.width;
    case import_v1.Node_Type.GIF:
      return node.attrs?.width;
    case import_v1.Node_Type.SHAPE:
      return import_consts.ORIGINAL_SHAPE_WIDTH;
    default:
      return void 0;
  }
};
const getPluginContainerClassNames = (isMobile) => (0, import_classnames.default)(stylesWithRTL.pluginContainer, isMobile && stylesWithRTL.pluginContainerMobile);
const getPluginPlacementClassNames = (node, isTextWrapEnabled) => {
  const containerData = node.attrs?.containerData;
  return (0, import_classnames.default)(
    getAlignmentClassName(containerData?.alignment),
    getSizeClassName(containerData?.width?.size),
    getTextWrapClassName(isTextWrapEnabled && containerData?.textWrap)
  );
};
const getPluginFocusClassNames = (isFocused) => (0, import_classnames.default)(
  stylesWithRTL.isFocusable,
  isFocused && stylesWithRTL.hasFocus,
  !isFocused && stylesWithRTL.hideTextSelection
);
const getNodeWidth = (node, isMobile) => {
  const containerData = node.attrs?.containerData;
  const disableCustomWidth = isCustomWidthDisabled(node, isMobile);
  const customWidth = !disableCustomWidth && containerData?.width?.custom;
  const originalWidth = (containerData?.width?.size === "ORIGINAL" || disableCustomWidth) && getOriginalWidth(node);
  return customWidth || originalWidth;
};
const getContainerData = (node) => {
  const data = `${import_lodash.default.camelCase(node.type)}Data`;
  return node?.[data]?.containerData;
};
//# sourceMappingURL=node-styles.js.map
