/**
 * Built-in Layout Commands
 *
 * Commands for layout operations:
 * - forceLayout: Apply force-directed layout
 * - treeLayout: Hierarchical tree (top-down)
 * - gridLayout: Uniform grid
 * - horizontalLayout: Tree (left-to-right)
 */

import type { CommandDefinition } from '../types';
import { registerCommand } from '../registry';

export const forceLayoutCommand: CommandDefinition = {
	name: 'forceLayout',
	description: 'Apply force-directed layout to all nodes',
	aliases: ['force', 'autoLayout'],
	category: 'layout',
	inputs: [],
	execute: async (_inputs, ctx) => {
		await ctx.layout.applyForceLayout();
	},
};

export const treeLayoutCommand: CommandDefinition = {
	name: 'treeLayout',
	description: 'Arrange nodes in a hierarchical tree (top-down)',
	aliases: ['tree'],
	category: 'layout',
	inputs: [],
	execute: async (_inputs, ctx) => {
		await ctx.layout.applyTreeLayout();
	},
};

export const gridLayoutCommand: CommandDefinition = {
	name: 'gridLayout',
	description: 'Arrange nodes in a uniform grid',
	aliases: ['grid'],
	category: 'layout',
	inputs: [],
	execute: async (_inputs, ctx) => {
		await ctx.layout.applyGridLayout();
	},
};

export const horizontalLayoutCommand: CommandDefinition = {
	name: 'horizontalLayout',
	description: 'Arrange nodes in a horizontal tree (left-to-right)',
	aliases: ['horizontal', 'hLayout'],
	category: 'layout',
	inputs: [],
	execute: async (_inputs, ctx) => {
		await ctx.layout.applyTreeLayout({ direction: 'left-right' });
	},
};

export function registerLayoutCommands(): void {
	registerCommand(forceLayoutCommand);
	registerCommand(treeLayoutCommand);
	registerCommand(gridLayoutCommand);
	registerCommand(horizontalLayoutCommand);
}
