#!/usr/bin/env node
import {
  ViewTitle
} from "./chunk-B4QYXVPZ.js";
import {
  CLI_COLORS,
  UI_SYMBOLS
} from "./chunk-FTD5Z6QD.js";
import {
  init_esm_shims
} from "./chunk-DHET7RCE.js";

// src/cli/components/wizard/checkbox-grid.tsx
init_esm_shims();
import { Box, Text, useInput } from "ink";
import { useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
var CheckboxGrid = ({
  title,
  subtitle,
  items,
  selectedIds,
  onToggle,
  onContinue,
  onBack,
  continueLabel = (count) => `Continue with ${count} item(s)`,
  emptyMessage = "Please select at least one item"
}) => {
  const totalItems = items.length + 1;
  const [focusedIndex, setFocusedIndex] = useState(0);
  useInput((input, key) => {
    if (key.escape) {
      onBack();
      return;
    }
    if (key.upArrow || input === "k") {
      setFocusedIndex((prev) => prev <= 0 ? totalItems - 1 : prev - 1);
      return;
    }
    if (key.downArrow || input === "j") {
      setFocusedIndex((prev) => prev >= totalItems - 1 ? 0 : prev + 1);
      return;
    }
    if (key.return) {
      onContinue();
      return;
    }
    if (input === " ") {
      const item = items[focusedIndex];
      if (item) {
        onToggle(item.id);
      }
    }
  });
  const continueIndex = items.length;
  return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
    /* @__PURE__ */ jsx(ViewTitle, { children: title }),
    subtitle && /* @__PURE__ */ jsx(Text, { dimColor: true, children: subtitle }),
    items.map((item, index) => {
      const isFocused = index === focusedIndex;
      const isSelected = selectedIds.includes(item.id);
      const checkbox = isSelected ? "[\u2713]" : "[ ]";
      const pointer = isFocused ? UI_SYMBOLS.CHEVRON : UI_SYMBOLS.CHEVRON_SPACER;
      return /* @__PURE__ */ jsxs(Text, { children: [
        /* @__PURE__ */ jsx(Text, { color: isFocused ? CLI_COLORS.PRIMARY : void 0, children: pointer }),
        /* @__PURE__ */ jsxs(Text, { color: isSelected || isFocused ? CLI_COLORS.PRIMARY : void 0, bold: isFocused, children: [
          " ",
          checkbox,
          " ",
          item.label
        ] }),
        isFocused && /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
          "  ",
          item.description
        ] })
      ] }, item.id);
    }),
    /* @__PURE__ */ jsx(
      Text,
      {
        color: focusedIndex === continueIndex ? CLI_COLORS.PRIMARY : void 0,
        bold: focusedIndex === continueIndex
      }
    ),
    selectedIds.length > 0 ? /* @__PURE__ */ jsxs(Text, { children: [
      "\n",
      "Selected: ",
      /* @__PURE__ */ jsx(Text, { color: CLI_COLORS.WARNING, children: selectedIds.join(", ") })
    ] }) : emptyMessage ? /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
      "\n",
      emptyMessage
    ] }) : null
  ] });
};

export {
  CheckboxGrid
};
//# sourceMappingURL=chunk-M4P5YJ45.js.map