'use server';
import { isAbsolute } from 'node:path';
import { getSettings } from '../../../../../packages/core/src/infrastructure/services/settings.service.js';
import { resolve } from '../../lib/server-container.js';
export async function openIde(input) {
    const { repositoryPath, branch } = input;
    if (!repositoryPath || !isAbsolute(repositoryPath)) {
        return { success: false, error: 'repositoryPath must be an absolute path' };
    }
    const settings = getSettings();
    const editor = settings.environment.defaultEditor;
    const useCase = resolve('LaunchIdeUseCase');
    const result = await useCase.execute({
        editorId: editor,
        repositoryPath,
        branch,
        checkAvailability: true,
    });
    if (!result.ok) {
        return { success: false, error: result.message };
    }
    return { success: true, editor: result.editorName, path: result.worktreePath };
}
