// Force strict mode and setup for ESM
"use strict";
import {
  init_esbuild_shims
} from "./chunk-5O2XNYP6.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/cli/src/config/skill-settings.ts
init_esbuild_shims();
function normalizeSkillNames(value) {
  if (!Array.isArray(value)) return /* @__PURE__ */ new Set();
  return new Set(
    value.filter((name) => typeof name === "string").map((name) => name.trim().toLowerCase()).filter(Boolean)
  );
}
__name(normalizeSkillNames, "normalizeSkillNames");
function skillSettingStrings(settings, scope, key) {
  const value = settings.forScope(scope).settings.skills?.[key];
  return Array.isArray(value) ? value.filter((name) => typeof name === "string") : [];
}
__name(skillSettingStrings, "skillSettingStrings");
function resolveSkillSettings(settings) {
  const hardDisabled = normalizeSkillNames(settings.merged.skills?.disabled);
  const defaultDisabled = normalizeSkillNames(
    settings.merged.skills?.defaultDisabled
  );
  const enabled = normalizeSkillNames(settings.merged.skills?.enabled);
  const disablements = /* @__PURE__ */ new Map();
  for (const name of defaultDisabled) {
    if (!enabled.has(name)) disablements.set(name, { reason: "default" });
  }
  const lockedScopes = [
    ["SystemDefaults" /* SystemDefaults */, "systemDefaults"],
    ["User" /* User */, "user"],
    ["System" /* System */, "system"]
  ];
  const lockedByName = /* @__PURE__ */ new Map();
  for (const [scope, label] of lockedScopes) {
    for (const name of normalizeSkillNames(
      skillSettingStrings(settings, scope, "disabled")
    )) {
      lockedByName.set(name, label);
    }
  }
  for (const name of hardDisabled) {
    const lockedScope = lockedByName.get(name);
    disablements.set(name, {
      reason: "hard",
      ...lockedScope ? { lockedScope } : {}
    });
  }
  return {
    disabledNames: new Set(disablements.keys()),
    defaultDisabledNames: defaultDisabled,
    enabledNames: enabled,
    disablements
  };
}
__name(resolveSkillSettings, "resolveSkillSettings");
function updateTarget(names, skillName, include) {
  const normalizedName = skillName.trim().toLowerCase();
  const next = [];
  let found = false;
  for (const name of names) {
    if (name.trim().toLowerCase() !== normalizedName) {
      next.push(name);
    } else if (include && !found) {
      next.push(skillName);
      found = true;
    }
  }
  if (include && !found) next.push(skillName);
  return next;
}
__name(updateTarget, "updateTarget");
function updateWorkspaceSkillSettingLists(lists, skillName, enabled, defaultDisabled) {
  const normalizedName = skillName.trim().toLowerCase();
  const hadExplicitEnable = lists.enabled.some(
    (name) => name.trim().toLowerCase() === normalizedName
  );
  if (enabled) {
    return {
      disabled: updateTarget(lists.disabled, skillName, false),
      enabled: defaultDisabled || hadExplicitEnable ? updateTarget(lists.enabled, skillName, true) : lists.enabled
    };
  }
  return {
    disabled: updateTarget(lists.disabled, skillName, true),
    enabled: updateTarget(lists.enabled, skillName, false)
  };
}
__name(updateWorkspaceSkillSettingLists, "updateWorkspaceSkillSettingLists");
function computeWorkspaceSkillListUpdates(workspaceDisabled, lockedNames, workspaceEnabled, toggles) {
  const previousDisabled = workspaceDisabled.filter(
    (name) => !lockedNames.has(name.trim().toLowerCase())
  );
  const previousEnabled = [...workspaceEnabled];
  let next = {
    disabled: previousDisabled,
    enabled: previousEnabled
  };
  for (const toggle of toggles) {
    if (toggle.wasEnabled === toggle.isEnabled) continue;
    next = updateWorkspaceSkillSettingLists(
      next,
      toggle.name,
      toggle.isEnabled,
      toggle.defaultDisabled
    );
  }
  return {
    disabled: next.disabled,
    enabled: next.enabled,
    disabledChanged: JSON.stringify(previousDisabled) !== JSON.stringify(next.disabled),
    enabledChanged: JSON.stringify(previousEnabled) !== JSON.stringify(next.enabled)
  };
}
__name(computeWorkspaceSkillListUpdates, "computeWorkspaceSkillListUpdates");

export {
  normalizeSkillNames,
  skillSettingStrings,
  resolveSkillSettings,
  updateWorkspaceSkillSettingLists,
  computeWorkspaceSkillListUpdates
};
/**
 * @license
 * Copyright 2026 Qwen
 * SPDX-License-Identifier: Apache-2.0
 */
