import type { Meta, StoryObj } from '@storybook/react';
import { fn } from '@storybook/test';
import StartNode from './StartNode';
import { withNodeContext } from '../../../.storybook/decorators';

const meta: Meta<typeof StartNode> = {
  title: 'Components/Nodes/StartNode',
  component: StartNode,
  decorators: [withNodeContext],
  parameters: {
    layout: 'centered',
  },
  args: {
    id: 'start_1',
    type: 'start',
    selected: false,
    dragging: false,
    isConnectable: true,
    xPos: 0,
    yPos: 0,
    zIndex: 0,
    data: {
      label: 'Content Created',
      plugin: 'eca_content:entity_insert',
      locked: false,
      annotation: '',
      isAnnotationVisible: false,
      isLocked: false,
      onDelete: fn(),
      onToggleAnnotation: fn(),
    },
  },
  argTypes: {
    selected: {
      control: 'boolean',
      description: 'Whether the node is selected',
    },
    'data.label': {
      control: 'text',
      description: 'Node label text',
    },
    'data.plugin': {
      control: 'text',
      description: 'Plugin identifier',
    },
    'data.locked': {
      control: 'boolean',
      description: 'Whether the node is locked',
    },
    'data.annotation': {
      control: 'text',
      description: 'Annotation text for the node',
    },
    'data.isAnnotationVisible': {
      control: 'boolean',
      description: 'Whether the annotation is visible',
    },
  },
};

export default meta;
type Story = StoryObj<typeof StartNode>;

/**
 * Default start/event node
 */
export const Default: Story = {};

/**
 * Selected start node
 */
export const Selected: Story = {
  args: {
    selected: true,
  },
};

/**
 * Locked start node
 */
export const Locked: Story = {
  args: {
    data: {
      label: 'User Login',
      plugin: 'eca_user:user_login',
      locked: true,
      isLocked: true,
      onDelete: fn(),
      onToggleAnnotation: fn(),
    },
  },
};

/**
 * Start node with visible annotation
 */
export const WithAnnotation: Story = {
  args: {
    data: {
      label: 'Cron Triggered',
      plugin: 'eca_base:eca_cron',
      annotation: 'Runs every 15 minutes to check for pending tasks.',
      isAnnotationVisible: true,
      onDelete: fn(),
      onToggleAnnotation: fn(),
    },
  },
};

/**
 * Start node without plugin info
 */
export const NoPlugin: Story = {
  args: {
    data: {
      label: 'Custom Event',
      onDelete: fn(),
      onToggleAnnotation: fn(),
    },
  },
};

/**
 * Long label text
 */
export const LongLabel: Story = {
  args: {
    data: {
      label: 'Content Entity Insert Event for Published Articles with Taxonomy Terms',
      plugin: 'eca_content:entity_insert',
      onDelete: fn(),
      onToggleAnnotation: fn(),
    },
  },
};

/**
 * Start node with quick-add button visible (unlocked node with onQuickAdd handler)
 */
export const WithQuickAdd: Story = {
  args: {
    data: {
      label: 'Content Created',
      plugin: 'eca_content:entity_insert',
      locked: false,
      isLocked: false,
      onDelete: fn(),
      onToggleAnnotation: fn(),
      onQuickAdd: fn(),
    },
  },
};
