#!/usr/bin/env node
import {
  getAvailableSkills,
  resolveAlias
} from "./chunk-GFDGYQ6M.js";
import {
  init_esm_shims
} from "./chunk-DHET7RCE.js";

// src/cli/lib/wizard/build-step-logic.ts
init_esm_shims();
import { sortBy } from "remeda";
var FRAMEWORK_SUBCATEGORY_ID = "web-framework";
var WEB_DOMAIN_ID = "web";
function validateBuildStep(categories, selections) {
  for (const category of categories) {
    if (category.required) {
      const categorySelections = selections[category.id] || [];
      if (categorySelections.length === 0) {
        return {
          valid: false,
          message: `Select at least one skill from the ${category.displayName} category. Use arrow keys to navigate, then SPACE to select.`
        };
      }
    }
  }
  return { valid: true };
}
function computeOptionState(skill) {
  if (skill.disabled) {
    return "disabled";
  }
  if (skill.discouraged) {
    return "discouraged";
  }
  if (skill.recommended) {
    return "recommended";
  }
  return "normal";
}
function getSkillDisplayLabel(skill) {
  return skill.displayName || skill.id;
}
function getStateReason(skill) {
  if (skill.disabled && skill.disabledReason) {
    return skill.disabledReason;
  }
  if (skill.discouraged && skill.discouragedReason) {
    return skill.discouragedReason;
  }
  if (skill.recommended && skill.recommendedReason) {
    return skill.recommendedReason;
  }
  return void 0;
}
function isFrameworkSelected(selections) {
  const frameworkSelections = selections[FRAMEWORK_SUBCATEGORY_ID] ?? [];
  return frameworkSelections.length > 0;
}
function getSelectedFrameworks(selections, matrix) {
  const frameworkSelections = selections[FRAMEWORK_SUBCATEGORY_ID] ?? [];
  return frameworkSelections.map((alias) => resolveAlias(alias, matrix));
}
function isCompatibleWithSelectedFrameworks(skillId, selectedFrameworkIds, matrix) {
  const skill = matrix.skills[skillId];
  if (!skill) return false;
  if (skill.compatibleWith.length === 0) {
    return true;
  }
  return selectedFrameworkIds.some((frameworkId) => skill.compatibleWith.includes(frameworkId));
}
function buildCategoriesForDomain(domain, allSelections, matrix, expertMode, selections, installedSkillIds) {
  const frameworkSource = selections;
  const frameworkSelected = isFrameworkSelected(frameworkSource);
  const selectedFrameworkIds = frameworkSelected ? getSelectedFrameworks(frameworkSource, matrix) : [];
  const subcategories = sortBy(
    Object.values(matrix.categories).filter(
      (cat) => cat.domain === domain
    ),
    (cat) => cat.order ?? 0
  );
  const categoryRows = subcategories.map((cat) => {
    const skillOptions = getAvailableSkills(cat.id, allSelections, matrix, {
      expertMode
    });
    const useFrameworkFilter = domain === WEB_DOMAIN_ID && cat.id !== FRAMEWORK_SUBCATEGORY_ID && frameworkSelected;
    const filteredSkillOptions = useFrameworkFilter ? skillOptions.filter(
      (skill) => isCompatibleWithSelectedFrameworks(skill.id, selectedFrameworkIds, matrix)
    ) : skillOptions;
    const options = filteredSkillOptions.map((skill) => ({
      id: skill.id,
      label: getSkillDisplayLabel(skill),
      state: computeOptionState(skill),
      stateReason: getStateReason(skill),
      selected: skill.selected,
      local: matrix.skills[skill.id]?.local,
      installed: installedSkillIds?.includes(skill.id) || false
    }));
    return {
      id: cat.id,
      displayName: cat.displayName,
      required: cat.required ?? false,
      exclusive: cat.exclusive ?? true,
      options
    };
  });
  return categoryRows.filter((row) => row.options.length > 0);
}

export {
  validateBuildStep,
  getSkillDisplayLabel,
  buildCategoriesForDomain
};
//# sourceMappingURL=chunk-INKJBMPJ.js.map