import { describe, it, expect } from 'vitest';
import { analyzeDesign } from '../design-scorer.js';
function makeBalancedPage() {
    return {
        id: 'page-1',
        type: 'page',
        children: [
            {
                id: 'sec-hero',
                type: 'section',
                settings: { paddingTop: '64px', paddingBottom: '64px', background: '#ffffff' },
                children: [
                    {
                        id: 'row-hero',
                        type: 'row',
                        settings: { gap: '24px', wrapOnMobile: true },
                        children: [
                            {
                                id: 'col-hero',
                                type: 'column',
                                settings: { width: 12 },
                                children: [
                                    {
                                        id: 'blk-hero',
                                        type: 'block',
                                        settings: { blockType: 'hero' },
                                        data: {
                                            title: 'Welcome',
                                            subtitle: 'Great things ahead',
                                            ctaText: 'Learn More',
                                            ctaLink: '/about',
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                ],
            },
            {
                id: 'sec-content',
                type: 'section',
                settings: { paddingTop: '64px', paddingBottom: '64px', background: '#f5f5f5' },
                children: [
                    {
                        id: 'row-content',
                        type: 'row',
                        settings: { gap: '24px', wrapOnMobile: true },
                        children: [
                            {
                                id: 'col-content-1',
                                type: 'column',
                                settings: { width: 6 },
                                children: [
                                    {
                                        id: 'blk-text-1',
                                        type: 'block',
                                        settings: { blockType: 'text' },
                                        data: {
                                            heading: 'Our Mission',
                                            headingLevel: 2,
                                            body: '<p>We build great things.</p>',
                                        },
                                    },
                                ],
                            },
                            {
                                id: 'col-content-2',
                                type: 'column',
                                settings: { width: 6 },
                                children: [
                                    {
                                        id: 'blk-image-1',
                                        type: 'block',
                                        settings: { blockType: 'image' },
                                        data: { src: '/mission.jpg', alt: 'Our mission in action' },
                                    },
                                ],
                            },
                        ],
                    },
                ],
            },
            {
                id: 'sec-cta',
                type: 'section',
                settings: { paddingTop: '64px', paddingBottom: '64px', background: '#ffffff' },
                children: [
                    {
                        id: 'row-cta',
                        type: 'row',
                        settings: { gap: '24px', wrapOnMobile: true },
                        children: [
                            {
                                id: 'col-cta',
                                type: 'column',
                                settings: { width: 12 },
                                children: [
                                    {
                                        id: 'blk-cta',
                                        type: 'block',
                                        settings: { blockType: 'cta' },
                                        data: {
                                            heading: 'Get Started',
                                            body: 'Join today',
                                            buttonText: 'Sign Up',
                                            buttonLink: '/signup',
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                ],
            },
        ],
    };
}
function makePageMissingCta() {
    return {
        id: 'page-1',
        type: 'page',
        children: [
            {
                id: 'sec-1',
                type: 'section',
                settings: { paddingTop: '64px', paddingBottom: '64px' },
                children: [
                    {
                        id: 'row-1',
                        type: 'row',
                        settings: { gap: '24px' },
                        children: [
                            {
                                id: 'col-1',
                                type: 'column',
                                settings: { width: 12 },
                                children: [
                                    {
                                        id: 'blk-text',
                                        type: 'block',
                                        settings: { blockType: 'text' },
                                        data: {
                                            heading: 'Hello',
                                            headingLevel: 2,
                                            body: '<p>Some text content here.</p>',
                                        },
                                    },
                                ],
                            },
                        ],
                    },
                ],
            },
        ],
    };
}
function makeInconsistentSpacingPage() {
    return {
        id: 'page-1',
        type: 'page',
        children: [
            {
                id: 'sec-1',
                type: 'section',
                settings: { paddingTop: '16px', paddingBottom: '32px' },
                children: [
                    {
                        id: 'row-1',
                        type: 'row',
                        settings: { gap: '8px' },
                        children: [
                            {
                                id: 'col-1',
                                type: 'column',
                                settings: { width: 12 },
                                children: [
                                    {
                                        id: 'blk-1',
                                        type: 'block',
                                        settings: { blockType: 'text' },
                                        data: { body: 'A' },
                                    },
                                ],
                            },
                        ],
                    },
                ],
            },
            {
                id: 'sec-2',
                type: 'section',
                settings: { paddingTop: '64px', paddingBottom: '48px' },
                children: [
                    {
                        id: 'row-2',
                        type: 'row',
                        settings: { gap: '24px' },
                        children: [
                            {
                                id: 'col-2',
                                type: 'column',
                                settings: { width: 12 },
                                children: [
                                    {
                                        id: 'blk-2',
                                        type: 'block',
                                        settings: { blockType: 'text' },
                                        data: { body: 'B' },
                                    },
                                ],
                            },
                        ],
                    },
                ],
            },
            {
                id: 'sec-3',
                type: 'section',
                settings: { paddingTop: '80px', paddingBottom: '100px' },
                children: [
                    {
                        id: 'row-3',
                        type: 'row',
                        settings: { gap: '40px' },
                        children: [
                            {
                                id: 'col-3',
                                type: 'column',
                                settings: { width: 12 },
                                children: [
                                    {
                                        id: 'blk-3',
                                        type: 'block',
                                        settings: { blockType: 'text' },
                                        data: { body: 'C' },
                                    },
                                ],
                            },
                        ],
                    },
                ],
            },
        ],
    };
}
describe('analyzeDesign', () => {
    it('returns score between 0 and 100', () => {
        const tree = makeBalancedPage();
        const result = analyzeDesign(tree);
        expect(result.score).toBeGreaterThanOrEqual(0);
        expect(result.score).toBeLessThanOrEqual(100);
    });
    it('scores 6 categories', () => {
        const tree = makeBalancedPage();
        const result = analyzeDesign(tree);
        expect(result.categories.length).toBe(6);
        expect(result.categories.map((c) => c.name)).toEqual([
            'visualHierarchy',
            'spacingConsistency',
            'contentDensity',
            'colorUsage',
            'imageQuality',
            'mobileReadiness',
        ]);
    });
    it('generates suggestions for missing trust element', () => {
        const tree = makeBalancedPage();
        const result = analyzeDesign(tree);
        const trustSuggestion = result.suggestions.find((s) => s.id === 'missing-trust');
        expect(trustSuggestion).toBeDefined();
        expect(trustSuggestion.category).toBe('trust');
    });
    it('generates suggestions for missing CTA', () => {
        const tree = makePageMissingCta();
        const result = analyzeDesign(tree);
        const ctaSuggestion = result.suggestions.find((s) => s.id === 'missing-cta');
        expect(ctaSuggestion).toBeDefined();
        expect(ctaSuggestion.severity).toBe('important');
        expect(ctaSuggestion.category).toBe('conversion');
    });
    it('penalizes inconsistent spacing', () => {
        const tree = makeInconsistentSpacingPage();
        const result = analyzeDesign(tree);
        const spacingCategory = result.categories.find((c) => c.name === 'spacingConsistency');
        expect(spacingCategory).toBeDefined();
        expect(spacingCategory.score).toBeLessThan(spacingCategory.maxScore);
    });
    it('gives high score to a well-structured page', () => {
        const tree = makeBalancedPage();
        const result = analyzeDesign(tree);
        expect(result.score).toBeGreaterThan(60);
    });
    it('handles empty page gracefully', () => {
        const tree = { id: 'page-1', type: 'page', children: [] };
        const result = analyzeDesign(tree);
        expect(result.score).toBeGreaterThanOrEqual(0);
        expect(result.score).toBeLessThanOrEqual(100);
    });
});
//# sourceMappingURL=design-scorer.test.js.map