"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 cell_star_rating_exports = {};
__export(cell_star_rating_exports, {
  CellStarRating: () => CellStarRating
});
module.exports = __toCommonJS(cell_star_rating_exports);
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/ricos-context.js");
var import_use_is_editor_mode = require("./../../_shared/use-is-editor-mode.js");
var import_cell_numeric_value = require("../utils/cell-numeric-value.js");
var import_smart_block_context = require("../utils/smart-block-context.js");
var import_cell_star_rating_scss = __toESM(require("./cell-star-rating-scss.js"));
var import_stars = require("./stars.js");
const MAX_RATING = 5;
const CellStarRating = ({ label }) => {
  const onLabelChange = (0, import_smart_block_context.useSmartBlockCellEditorContext)()?.onLabelChange;
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const isEditorMode = (0, import_use_is_editor_mode.useIsEditorMode)();
  const {
    rawLabel,
    clampedValue: rating,
    hasParsedValue
  } = (0, import_cell_numeric_value.getCellNumericValue)(label, {
    max: MAX_RATING
  });
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: import_cell_star_rating_scss.default.cellStarRating,
      role: "img",
      "aria-valuemin": 0,
      "aria-valuemax": MAX_RATING,
      "aria-valuenow": hasParsedValue ? rating : void 0,
      "aria-valuetext": rawLabel || void 0
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_stars.Stars,
      {
        rating,
        className: import_cell_star_rating_scss.default.cellStarRatingStars,
        a11yLabel: t("SmartBlock_StarRating_AriaLabel", { rating })
      }
    ),
    isEditorMode ? /* @__PURE__ */ import_react.default.createElement(
      "input",
      {
        type: "text",
        className: (0, import_classnames.default)(import_cell_star_rating_scss.default.cellStarRatingValueText, import_cell_star_rating_scss.default.cellStarRatingValueInput),
        value: rawLabel,
        placeholder: t("SmartBlock_CellStarRating_LabelPlaceholder"),
        size: Math.max(rawLabel.length, 4),
        onChange: (event) => onLabelChange?.(event.target.value || null),
        onMouseDown: (event) => event.stopPropagation(),
        onClick: (event) => event.stopPropagation()
      }
    ) : rawLabel ? /* @__PURE__ */ import_react.default.createElement("span", { className: import_cell_star_rating_scss.default.cellStarRatingValueText }, rawLabel) : null
  );
};
//# sourceMappingURL=cell-star-rating.js.map
