"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const DataEditor = require("@glideapps/glide-data-grid");
const _ = require("lodash");
const kit_internal_functions = require("../internal/functions.cjs");
const kit_DataGrid_customRenderers_cells_checkboxCell = require("./custom-renderers/cells/checkboxCell.cjs");
require("./custom-renderers/cells/linkCell.cjs");
require("./custom-renderers/cells/loadingCell.cjs");
require("./custom-renderers/cells/progressCell.cjs");
require("./custom-renderers/cells/sparklineCell.cjs");
require("./custom-renderers/cells/stateCell.cjs");
require("./custom-renderers/cells/tagsCell.cjs");
const kit_DataGrid_customRenderers_cells_textCell = require("./custom-renderers/cells/textCell.cjs");
require("./custom-renderers/cells/userAvatarCell.cjs");
const DEFAULT_COLUMN_WIDTH = 140;
const MIN_COLUMN_WIDTH = 40;
const MULTISELECT = "selected";
function defaultTextColumn(columnId, columnTitle, columnWidth, dataPath) {
  return {
    id: columnId,
    renderer: (record) => {
      const data = dataPath !== void 0 ? _.get(record, dataPath) : void 0;
      return {
        allowOverlay: false,
        copyData: String(data ?? ""),
        data: { kind: kit_DataGrid_customRenderers_cells_textCell.TEXT_CELL },
        kind: DataEditor.GridCellKind.Custom
      };
    },
    title: columnTitle,
    tooltip: () => void 0,
    width: columnWidth ?? DEFAULT_COLUMN_WIDTH
  };
}
const getHeatmapPercentage = (min, max, value) => {
  if (min >= max || value >= max)
    return 1;
  if (value <= min)
    return 0;
  return (value - min) / (max - min);
};
const getHeatmapColor = (min, max, value) => {
  const p = getHeatmapPercentage(min, max, value);
  const red = [44, 222];
  const green = [119, 66];
  const blue = [176, 91];
  return `rgb(${red[0] + (red[1] - red[0]) * p}, ${green[0] + (green[1] - green[0]) * p}, ${blue[0] + (blue[1] - blue[0]) * p})`;
};
function defaultNumberColumn(columnId, columnTitle, columnWidth, dataPath, heatmapProps) {
  return {
    id: columnId,
    renderer: (record) => {
      const data = dataPath !== void 0 ? _.get(record, dataPath) : void 0;
      let theme = {};
      if (heatmapProps && data !== void 0) {
        const { min, max } = heatmapProps;
        theme = {
          accentLight: getHeatmapColor(min, max, data),
          bgCell: getHeatmapColor(min, max, data),
          textDark: "white"
        };
      }
      return {
        allowOverlay: false,
        copyData: String(data ?? ""),
        data: { kind: kit_DataGrid_customRenderers_cells_textCell.TEXT_CELL },
        kind: DataEditor.GridCellKind.Custom,
        themeOverride: theme
      };
    },
    title: columnTitle,
    tooltip: () => void 0,
    width: columnWidth ?? DEFAULT_COLUMN_WIDTH
  };
}
function defaultSelectionColumn(rowSelection, selectAll) {
  return {
    icon: selectAll ? "allSelected" : rowSelection.length ? "someSelected" : "noneSelected",
    id: MULTISELECT,
    renderer: (_2, idx) => ({
      allowOverlay: false,
      contentAlign: "left",
      copyData: String(rowSelection.hasIndex(idx)),
      data: {
        checked: rowSelection.hasIndex(idx),
        kind: kit_DataGrid_customRenderers_cells_checkboxCell.CHECKBOX_CELL
      },
      kind: DataEditor.GridCellKind.Custom
    }),
    themeOverride: { cellHorizontalPadding: 10 },
    title: "",
    tooltip: () => void 0,
    width: 40
  };
}
function defaultDateColumn(columnId, columnTitle, columnWidth, dataPath) {
  return {
    id: columnId,
    renderer: (record) => {
      const data = dataPath !== void 0 ? _.get(record, dataPath) : void 0;
      return {
        allowOverlay: false,
        copyData: data ? kit_internal_functions.formatDatetime(String(data), { outputUTC: false }) : "",
        data: { kind: kit_DataGrid_customRenderers_cells_textCell.TEXT_CELL },
        kind: DataEditor.GridCellKind.Custom
      };
    },
    title: columnTitle,
    tooltip: () => void 0,
    width: columnWidth ?? DEFAULT_COLUMN_WIDTH
  };
}
function defaultArrayColumn(columnId, columnTitle, columnWidth, dataPath) {
  return {
    id: columnId,
    renderer: (record) => {
      const data = dataPath !== void 0 ? _.get(record, dataPath) : void 0;
      return {
        allowOverlay: false,
        copyData: data !== void 0 ? JSON.stringify(data) : "",
        data: { kind: kit_DataGrid_customRenderers_cells_textCell.TEXT_CELL },
        kind: DataEditor.GridCellKind.Custom
      };
    },
    title: columnTitle,
    tooltip: () => void 0,
    width: columnWidth ?? DEFAULT_COLUMN_WIDTH
  };
}
exports.DEFAULT_COLUMN_WIDTH = DEFAULT_COLUMN_WIDTH;
exports.MIN_COLUMN_WIDTH = MIN_COLUMN_WIDTH;
exports.MULTISELECT = MULTISELECT;
exports.defaultArrayColumn = defaultArrayColumn;
exports.defaultDateColumn = defaultDateColumn;
exports.defaultNumberColumn = defaultNumberColumn;
exports.defaultSelectionColumn = defaultSelectionColumn;
exports.defaultTextColumn = defaultTextColumn;
exports.getHeatmapColor = getHeatmapColor;
