import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect } from 'react';
import { StateGroup, Priority } from '../../../../../../packages/core/src/domain/generated/output.js';
import { SelectableWorkItemRow } from './selectable-work-item-row.js';
import { BulkSelectionProvider, useBulkSelection } from './bulk-selection-context.js';
const mockState = {
    id: 's1',
    projectId: 'proj-1',
    name: 'In Progress',
    color: '#f59e0b',
    stateGroup: StateGroup.Started,
    displayOrder: 2,
    isDefault: false,
    createdAt: new Date(),
    updatedAt: new Date(),
};
const mockWorkItem = {
    id: 'wi-1',
    projectId: 'proj-1',
    sequenceId: 42,
    identifierPrefix: 'FE',
    title: 'Implement the project management list view',
    stateId: 's1',
    priority: Priority.High,
    sortOrder: 0,
    createdAt: new Date(),
    updatedAt: new Date(),
};
const mockWorkItems = [
    mockWorkItem,
    {
        id: 'wi-2',
        projectId: 'proj-1',
        sequenceId: 43,
        identifierPrefix: 'FE',
        title: 'Add bulk operations support',
        stateId: 's1',
        priority: Priority.Medium,
        sortOrder: 1,
        createdAt: new Date(),
        updatedAt: new Date(),
    },
    {
        id: 'wi-3',
        projectId: 'proj-1',
        sequenceId: 44,
        identifierPrefix: 'FE',
        title: 'Design the settings page layout',
        stateId: 's1',
        priority: Priority.Low,
        sortOrder: 2,
        createdAt: new Date(),
        updatedAt: new Date(),
    },
    {
        id: 'wi-4',
        projectId: 'proj-1',
        sequenceId: 45,
        identifierPrefix: 'FE',
        title: 'Fix critical authentication bypass vulnerability in the login flow',
        stateId: 's1',
        priority: Priority.Urgent,
        sortOrder: 3,
        createdAt: new Date(),
        updatedAt: new Date(),
    },
];
/**
 * Helper that pre-selects specified items on mount.
 */
function PreSelectItems({ ids, children }) {
    const { selectAll } = useBulkSelection();
    useEffect(() => {
        selectAll(ids);
    }, []); // eslint-disable-line react-hooks/exhaustive-deps
    return children;
}
const meta = {
    title: 'PM/BulkOperations/SelectableWorkItemRow',
    component: SelectableWorkItemRow,
    parameters: {
        layout: 'padded',
    },
    tags: ['autodocs'],
    decorators: [
        (Story) => (_jsx(BulkSelectionProvider, { children: _jsx("div", { className: "rounded-lg border", children: _jsx(Story, {}) }) })),
    ],
};
export default meta;
export const Default = {
    args: {
        workItem: mockWorkItem,
        state: mockState,
        projectPrefix: 'FE',
    },
};
export const Selected = {
    args: {
        workItem: mockWorkItem,
        state: mockState,
        projectPrefix: 'FE',
    },
    decorators: [
        (Story) => (_jsx(PreSelectItems, { ids: ['wi-1'], children: _jsx(Story, {}) })),
    ],
};
export const MultipleRows = {
    decorators: [
        (_Story) => (_jsx("div", { className: "divide-y", children: mockWorkItems.map((wi) => (_jsx(SelectableWorkItemRow, { workItem: wi, state: mockState, projectPrefix: "FE" }, wi.id))) })),
    ],
};
export const MultipleRowsWithSelection = {
    decorators: [
        (_Story) => (_jsx(PreSelectItems, { ids: ['wi-1', 'wi-3'], children: _jsx("div", { className: "divide-y", children: mockWorkItems.map((wi) => (_jsx(SelectableWorkItemRow, { workItem: wi, state: mockState, projectPrefix: "FE" }, wi.id))) }) })),
    ],
};
export const NoState = {
    args: {
        workItem: mockWorkItem,
        state: undefined,
        projectPrefix: 'FE',
    },
};
