"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_stat_exports = {};
__export(cell_stat_exports, {
  CellStat: () => CellStat
});
module.exports = __toCommonJS(cell_stat_exports);
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/index.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_stat_scss = __toESM(require("./cell-stat-scss.js"));
const CIRCLE_RADIUS = 50;
const CellStat = ({ type, 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, hasParsedValue } = (0, import_cell_numeric_value.getCellNumericValue)(label);
  const progressProps = {
    role: "progressbar",
    "aria-valuemin": 0,
    "aria-valuemax": 100,
    "aria-valuenow": hasParsedValue ? clampedValue : void 0,
    "aria-valuetext": rawLabel || void 0
  };
  const variantInputClass = type === "BAR_STATS" ? import_cell_stat_scss.default.cellStatBarValueInput : type === "CIRCLE_STATS" ? import_cell_stat_scss.default.cellStatCircleValueInput : import_cell_stat_scss.default.cellStatStatsValueInput;
  const variantTextClass = type === "BAR_STATS" ? import_cell_stat_scss.default.cellStatBarValueText : type === "CIRCLE_STATS" ? import_cell_stat_scss.default.cellStatCircleValueText : import_cell_stat_scss.default.cellStatStatsValueText;
  const labelElement = isEditorMode ? /* @__PURE__ */ import_react.default.createElement(
    "input",
    {
      type: "text",
      className: `${import_cell_stat_scss.default.cellStatValue} ${import_cell_stat_scss.default.cellStatValueInput} ${variantInputClass}`,
      value: rawLabel,
      placeholder: t("SmartBlock_CellStat_LabelPlaceholder"),
      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_stat_scss.default.cellStatValue} ${variantTextClass}` }, rawLabel) : null;
  if (type === "STATS") {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: import_cell_stat_scss.default.cellStatStats }, labelElement);
  }
  if (type === "BAR_STATS") {
    return /* @__PURE__ */ import_react.default.createElement("div", { className: import_cell_stat_scss.default.cellStatBar }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_cell_stat_scss.default.cellStatBarProgress, ...progressProps }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_cell_stat_scss.default.cellStatBarTrack }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_cell_stat_scss.default.cellStatBarFill, style: { width: `${clampedValue}%` } }))), /* @__PURE__ */ import_react.default.createElement("div", { className: import_cell_stat_scss.default.cellStatBarValue }, labelElement));
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: import_cell_stat_scss.default.cellStatCircle }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_cell_stat_scss.default.cellStatCircleProgress, ...progressProps }, /* @__PURE__ */ import_react.default.createElement(
    "svg",
    {
      className: import_cell_stat_scss.default.cellStatCircleSvg,
      viewBox: "0 0 120 120",
      "aria-hidden": true,
      focusable: "false"
    },
    /* @__PURE__ */ import_react.default.createElement("circle", { className: import_cell_stat_scss.default.cellStatCircleTrack, cx: "60", cy: "60", r: CIRCLE_RADIUS }),
    /* @__PURE__ */ import_react.default.createElement(
      "circle",
      {
        className: import_cell_stat_scss.default.cellStatCircleFill,
        cx: "60",
        cy: "60",
        r: CIRCLE_RADIUS,
        pathLength: 100,
        strokeDasharray: "100",
        strokeDashoffset: 100 - clampedValue
      }
    )
  ), /* @__PURE__ */ import_react.default.createElement("div", { className: import_cell_stat_scss.default.cellStatCircleValue }, labelElement)));
};
//# sourceMappingURL=cell-stat.js.map
