#!/usr/bin/env node
import {
  useKeyboardNavigation
} from "./chunk-KUV24B5M.js";
import {
  CLI_COLORS
} from "./chunk-FTD5Z6QD.js";
import {
  init_esm_shims
} from "./chunk-DHET7RCE.js";

// src/cli/components/wizard/search-modal.tsx
init_esm_shims();
import { useCallback } from "react";
import { Box, Text } from "ink";
import { jsx, jsxs } from "react/jsx-runtime";
var MARKER_FOCUSED = "\u25B8";
var MARKER_SPACER = " ";
var ResultRow = ({ candidate, isFocused }) => {
  const marker = isFocused ? MARKER_FOCUSED : MARKER_SPACER;
  const sourceLabel = `${candidate.sourceName}/${candidate.id}`;
  return /* @__PURE__ */ jsxs(Box, { children: [
    /* @__PURE__ */ jsxs(Text, { bold: isFocused, color: isFocused ? CLI_COLORS.PRIMARY : void 0, children: [
      marker,
      " "
    ] }),
    /* @__PURE__ */ jsx(Text, { bold: isFocused, color: isFocused ? CLI_COLORS.PRIMARY : void 0, children: sourceLabel }),
    candidate.description && /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
      "   ",
      candidate.description
    ] })
  ] });
};
var SearchModal = ({ results, alias, onBind, onClose }) => {
  const handleEnter = useCallback(
    (index) => {
      if (results.length > 0) {
        const selected = results[index];
        if (selected) {
          onBind(selected);
        }
      }
    },
    [results, onBind]
  );
  const { focusedIndex } = useKeyboardNavigation(
    results.length,
    { onEnter: handleEnter, onEscape: onClose },
    { vimKeys: false }
  );
  return /* @__PURE__ */ jsxs(
    Box,
    {
      flexDirection: "column",
      borderStyle: "single",
      borderColor: CLI_COLORS.NEUTRAL,
      paddingX: 1,
      paddingY: 0,
      marginTop: 1,
      children: [
        /* @__PURE__ */ jsxs(Text, { bold: true, children: [
          'Search results for "',
          alias,
          '"'
        ] }),
        /* @__PURE__ */ jsx(Text, { children: " " }),
        results.length === 0 ? /* @__PURE__ */ jsx(Text, { dimColor: true, children: "No results found" }) : results.map((candidate, index) => /* @__PURE__ */ jsx(
          ResultRow,
          {
            candidate,
            isFocused: index === focusedIndex
          },
          `${candidate.sourceName}-${candidate.id}`
        )),
        /* @__PURE__ */ jsx(Text, { children: " " }),
        /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
          "\u2191",
          "/",
          "\u2193",
          " navigate ENTER bind ESC close"
        ] })
      ]
    }
  );
};

export {
  SearchModal
};
//# sourceMappingURL=chunk-VSZ5GDET.js.map