import { str2rgba, isColor, rgba2str, rgbaMix } from "../internal/color.js";
import { themeLight, themeDark } from "../internal/Theme/theme.js";
import { RunState, CheckpointState, CommandState, ResourceState, SlotState, JobState } from "../internal/types.js";
import { themeBase } from "./themeUtils.js";
import { Spacing } from "./themeUtils.js";
const ShirtSize = {
  Small: "small",
  Medium: "medium",
  Large: "large"
};
const STRONG_WEAK_DELTA = 45;
const generateStrongWeak = (theme) => {
  const rgbaStrong = str2rgba(theme.strong);
  const rgbaWeak = str2rgba(theme.weak);
  for (const [key, value] of Object.entries(theme)) {
    const matches = key.match(/^(.+)(Strong|Weak)$/);
    if ((matches == null ? void 0 : matches.length) === 3 && value === void 0) {
      const isStrong = matches[2] === "Strong";
      const baseKey = matches[1];
      const baseValue = theme[baseKey];
      if (baseValue && isColor(baseValue)) {
        const rgba = str2rgba(baseValue);
        const mixer = isStrong ? rgbaStrong : rgbaWeak;
        theme[key] = rgba2str(rgbaMix(rgba, mixer, STRONG_WEAK_DELTA));
      }
    }
  }
  return theme;
};
const themeLightDetermined = generateStrongWeak(Object.assign({}, themeBase, themeLight));
const themeDarkDetermined = generateStrongWeak(Object.assign({}, themeBase, themeDark));
const themeHpe = { brand: "rgba(1, 169, 130, 1.0)" };
const themeLightHpe = generateStrongWeak(Object.assign({}, themeBase, themeLight, themeHpe));
const themeDarkHpe = generateStrongWeak(Object.assign({}, themeBase, themeDark, themeHpe));
const DefaultTheme = {
  Light: themeLightDetermined,
  Dark: themeDarkDetermined,
  HPELight: themeLightHpe,
  HPEDark: themeDarkHpe
};
const stateColorMapping = {
  [RunState.Active]: "active",
  [RunState.Canceled]: "inactive",
  [RunState.Completed]: "success",
  [RunState.Deleted]: "critical",
  [RunState.Deleting]: "critical",
  [RunState.DeleteFailed]: "critical",
  [RunState.Error]: "critical",
  [RunState.Paused]: "warning",
  [RunState.StoppingCanceled]: "inactive",
  [RunState.StoppingCompleted]: "success",
  [RunState.StoppingError]: "critical",
  [RunState.StoppingKilled]: "killed",
  [CheckpointState.PartiallyDeleted]: "warning",
  [RunState.Unspecified]: "inactive",
  [RunState.Queued]: "warning",
  [RunState.Pulling]: "pending",
  [RunState.Starting]: "pending",
  [RunState.Running]: "active",
  [CommandState.Waiting]: "inactive",
  [CommandState.Pulling]: "active",
  [CommandState.Starting]: "active",
  [CommandState.Running]: "active",
  [CommandState.Terminating]: "inactive",
  [CommandState.Terminated]: "inactive",
  [ResourceState.Unspecified]: "inactive",
  [ResourceState.Running]: "active",
  [ResourceState.Assigned]: "pending",
  [ResourceState.Pulling]: "pending",
  [ResourceState.Starting]: "pending",
  [ResourceState.Warm]: "free",
  [SlotState.Free]: "free",
  [SlotState.Pending]: "pending",
  [SlotState.Running]: "active",
  [SlotState.Potential]: "potential",
  [JobState.SCHEDULED]: "active",
  [JobState.SCHEDULEDBACKFILLED]: "active",
  [JobState.QUEUED]: "warning",
  [JobState.UNSPECIFIED]: "inactive"
};
const getStateColorCssVar = (state, options = {}) => {
  const name = state ? stateColorMapping[state] : "active";
  const on = options.isOn ? "-on" : "";
  const strongWeak = options.strongWeak ? `-${options.strongWeak}` : "";
  return `var(--theme-status-${name}${on}${strongWeak})`;
};
export {
  DefaultTheme,
  ShirtSize,
  Spacing,
  getStateColorCssVar,
  stateColorMapping
};
