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

const meta: Meta<typeof GatewayNode> = {
  title: 'Components/Nodes/GatewayNode',
  component: GatewayNode,
  decorators: [withNodeContext],
  parameters: {
    layout: 'centered',
  },
  args: {
    id: 'gateway_1',
    type: 'gateway',
    selected: false,
    dragging: false,
    isConnectable: true,
    xPos: 0,
    yPos: 0,
    zIndex: 0,
    data: {
      label: 'Check Role',
      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.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 GatewayNode>;

/**
 * Default gateway/condition node with diamond shape
 */
export const Default: Story = {};

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

/**
 * Locked gateway node
 */
export const Locked: Story = {
  args: {
    data: {
      label: 'Is Admin?',
      locked: true,
      isLocked: true,
      onDelete: fn(),
      onToggleAnnotation: fn(),
    },
  },
};

/**
 * Gateway with visible annotation
 */
export const WithAnnotation: Story = {
  args: {
    data: {
      label: 'Has Permission',
      annotation: 'Checks if the current user has the required permission to proceed.',
      isAnnotationVisible: true,
      onDelete: fn(),
      onToggleAnnotation: fn(),
    },
  },
};

/**
 * Short label (compact diamond)
 */
export const ShortLabel: Story = {
  args: {
    data: {
      label: 'OK?',
      onDelete: fn(),
      onToggleAnnotation: fn(),
    },
  },
};

/**
 * Long label (expanded diamond)
 */
export const LongLabel: Story = {
  args: {
    data: {
      label: 'User Has Administrator Role and Content Access Permission',
      onDelete: fn(),
      onToggleAnnotation: fn(),
    },
  },
};

/**
 * Gateway node with quick-add button visible (unlocked node with onQuickAdd handler)
 */
export const WithQuickAdd: Story = {
  args: {
    data: {
      label: 'Check Role',
      locked: false,
      isLocked: false,
      onDelete: fn(),
      onToggleAnnotation: fn(),
      onQuickAdd: fn(),
    },
  },
};
