import type { Meta, StoryObj } from '../../../story.types';
import { TableSearch } from './table-search.component';

type Story = StoryObj<TableSearch>;

const meta: Meta<TableSearch> = {
  title: '@aurora/components/data-table/table-search',
  component: TableSearch,
  tags: ['autodocs'],
  argTypes: {
    placeholder: {
      control: 'text',
      description: 'Placeholder shown inside the input when empty.',
    },
    debounce: {
      control: { type: 'number', min: 0, step: 100 },
      description: 'Milliseconds to debounce the value before emitting `search`.',
    },
    search: {
      action: 'search',
      description:
        'Emits the debounced input value each time the user pauses typing for `debounce` ms. Duplicate consecutive values are suppressed.',
    },
  },
  args: {
    placeholder: 'Filter...',
    debounce: 300,
  },
  parameters: {
    aurora: {
      category: 'data-table',
      when: 'A free-text search box that debounces user input and emits a single value once the user pauses typing, typically wired into a TanStack Table global filter.',
      whenNot:
        'For column-scoped filtering with operators (equals, contains, greater-than), use `TableFilters` — `TableSearch` does not expose operator selection or per-column targeting.',
    },
  },
};

export default meta;

export const Default: Story = {};

export const TranslatedPlaceholder: Story = {
  name: 'Translated placeholder (Transloco)',
  args: {
    placeholder: 'Filtrar por todas las columnas...',
  },
  parameters: {
    docs: {
      description: {
        story:
          'Seed variant showing the placeholder rendered from the Transloco `FilterPlaceholder` key (Spanish default scope). In production screens the placeholder is usually bound via `| transloco` or the Transloco directive.',
      },
    },
  },
};

export const FastDebounce: Story = {
  name: 'Short debounce (50 ms)',
  args: {
    debounce: 50,
  },
  parameters: {
    docs: {
      description: {
        story:
          'Demonstrates a short debounce window (50 ms) for cases where the consumer needs near-immediate feedback. With `debounce: 50`, typing "hello" character-by-character emits `"hello"` on `search` about 50 ms after the last keystroke. A `play` interaction verifying this emit should be added when Storybook is reintroduced (see `catalyst-component-catalog/STORIES.md`).',
      },
    },
  },
};
