import { c as _c } from "react/compiler-runtime";
import * as React from 'react';
import { useMemo } from 'react';
import { type Command, formatDescriptionWithSource } from '../../commands.js';
import { Box, Text } from '../../ink.js';
import { truncate } from '../../utils/format.js';
import { Select } from '../CustomSelect/select.js';
import { useTabHeaderFocus } from '../design-system/Tabs.js';
type Props = {
  commands: Command[];
  maxHeight: number;
  columns: number;
  title: string;
  onCancel: () => void;
  emptyMessage?: string;
};
export function Commands(t0) {
  const $ = _c(14);
  const {
    commands,
    maxHeight,
    columns,
    title,
    onCancel,
    emptyMessage
  } = t0;
  const {
    headerFocused,
    focusHeader
  } = useTabHeaderFocus();
  const maxWidth = Math.max(1, columns - 10);
  const visibleCount = Math.max(1, Math.floor((maxHeight - 10) / 2));
  let t1;
  if ($[0] !== commands || $[1] !== maxWidth) {
    const seen = new Set();
    let t2;
    if ($[3] !== maxWidth) {
      t2 = cmd_0 => ({
        label: `/${cmd_0.name}`,
        value: cmd_0.name,
        description: truncate(formatDescriptionWithSource(cmd_0), maxWidth, true)
      });
      $[3] = maxWidth;
      $[4] = t2;
    } else {
      t2 = $[4];
    }
    t1 = commands.filter(cmd => {
      if (seen.has(cmd.name)) {
        return false;
      }
      seen.add(cmd.name);
      return true;
    }).sort(_temp).map(t2);
    $[0] = commands;
    $[1] = maxWidth;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const options = t1;
  let t2;
  if ($[5] !== commands.length || $[6] !== emptyMessage || $[7] !== focusHeader || $[8] !== headerFocused || $[9] !== onCancel || $[10] !== options || $[11] !== title || $[12] !== visibleCount) {
    t2 = <Box flexDirection="column" paddingY={1}>{commands.length === 0 && emptyMessage ? <Text dimColor={true}>{emptyMessage}</Text> : <><Text>{title}</Text><Box marginTop={1}><Select options={options} visibleOptionCount={visibleCount} onCancel={onCancel} disableSelection={true} hideIndexes={true} layout="compact-vertical" onUpFromFirstItem={focusHeader} isDisabled={headerFocused} /></Box></>}</Box>;
    $[5] = commands.length;
    $[6] = emptyMessage;
    $[7] = focusHeader;
    $[8] = headerFocused;
    $[9] = onCancel;
    $[10] = options;
    $[11] = title;
    $[12] = visibleCount;
    $[13] = t2;
  } else {
    t2 = $[13];
  }
  return t2;
}
function _temp(a, b) {
  return a.name.localeCompare(b.name);
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJSZWFjdCIsInVzZU1lbW8iLCJDb21tYW5kIiwiZm9ybWF0RGVzY3JpcHRpb25XaXRoU291cmNlIiwiQm94IiwiVGV4dCIsInRydW5jYXRlIiwiU2VsZWN0IiwidXNlVGFiSGVhZGVyRm9jdXMiLCJQcm9wcyIsImNvbW1hbmRzIiwibWF4SGVpZ2h0IiwiY29sdW1ucyIsInRpdGxlIiwib25DYW5jZWwiLCJlbXB0eU1lc3NhZ2UiLCJDb21tYW5kcyIsInQwIiwiJCIsIl9jIiwiaGVhZGVyRm9jdXNlZCIsImZvY3VzSGVhZGVyIiwibWF4V2lkdGgiLCJNYXRoIiwibWF4IiwidmlzaWJsZUNvdW50IiwiZmxvb3IiLCJ0MSIsInNlZW4iLCJTZXQiLCJ0MiIsImNtZF8wIiwibGFiZWwiLCJjbWQiLCJuYW1lIiwidmFsdWUiLCJkZXNjcmlwdGlvbiIsImZpbHRlciIsImhhcyIsImFkZCIsInNvcnQiLCJfdGVtcCIsIm1hcCIsIm9wdGlvbnMiLCJsZW5ndGgiLCJhIiwiYiIsImxvY2FsZUNvbXBhcmUiXSwic291cmNlcyI6WyJDb21tYW5kcy50c3giXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0ICogYXMgUmVhY3QgZnJvbSAncmVhY3QnXG5pbXBvcnQgeyB1c2VNZW1vIH0gZnJvbSAncmVhY3QnXG5pbXBvcnQgeyB0eXBlIENvbW1hbmQsIGZvcm1hdERlc2NyaXB0aW9uV2l0aFNvdXJjZSB9IGZyb20gJy4uLy4uL2NvbW1hbmRzLmpzJ1xuaW1wb3J0IHsgQm94LCBUZXh0IH0gZnJvbS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