'use server';
import { resolve } from '../../lib/server-container.js';
export async function createPage(input) {
    if (!input.title?.trim()) {
        return { error: 'Page title is required' };
    }
    try {
        const useCase = resolve('CreatePageUseCase');
        const result = await useCase.execute(input);
        if (!result.ok)
            return { error: result.error };
        return { page: result.page };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to create page';
        return { error: message };
    }
}
export async function listPages(projectId) {
    try {
        const useCase = resolve('ListPagesUseCase');
        const result = await useCase.execute(projectId);
        return { pages: result.pages };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to list pages';
        return { error: message };
    }
}
export async function getPage(pageId) {
    try {
        const useCase = resolve('GetPageUseCase');
        const result = await useCase.execute(pageId);
        if (!result.ok)
            return { error: result.error };
        return { page: result.page };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to get page';
        return { error: message };
    }
}
export async function updatePage(pageId, fields) {
    try {
        const useCase = resolve('UpdatePageUseCase');
        const result = await useCase.execute({ pageId, ...fields });
        if (!result.ok)
            return { error: result.error };
        return { page: result.page };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to update page';
        return { error: message };
    }
}
export async function deletePage(pageId) {
    try {
        const useCase = resolve('DeletePageUseCase');
        const result = await useCase.execute(pageId);
        if (!result.ok)
            return { error: result.error };
        return {};
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to delete page';
        return { error: message };
    }
}
