import { jsx as _jsx } from "react/jsx-runtime";
// @vitest-environment happy-dom
import { describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { createSection } from '../../lib/page-editor-service.js';
import { SectionInspector, repeaterRowSummary } from '../../views/page-editor/SectionInspector.js';
/**
 * Repeater rows derive a scannable header from their values ("Pro · $79/mo")
 * instead of only the positional "Plan 2" label, so editors can find a row
 * without expanding every form (Upchat feedback: "repeaters feel like
 * spreadsheets").
 */
const PLAN_FIELDS = [
    { key: 'name', label: 'Name', type: 'text' },
    { key: 'price', label: 'Price', type: 'text' },
    { key: 'description', label: 'Description', type: 'textarea' },
    {
        key: 'tier',
        label: 'Tier',
        type: 'select',
        options: [{ label: 'Most popular', value: 'popular' }],
    },
];
describe('repeaterRowSummary', () => {
    it('joins the first two short text values', () => {
        expect(repeaterRowSummary(PLAN_FIELDS, { name: 'Pro', price: '$79/mo' })).toBe('Pro · $79/mo');
    });
    it('skips empty values and long-form fields', () => {
        expect(repeaterRowSummary(PLAN_FIELDS, {
            name: '  ',
            price: '$79/mo',
            description: 'long prose that must never appear',
        })).toBe('$79/mo');
    });
    it('maps select values to their human label', () => {
        expect(repeaterRowSummary(PLAN_FIELDS, { tier: 'popular' })).toBe('Most popular');
    });
    it('returns null for a blank row (caller falls back to "Plan N")', () => {
        expect(repeaterRowSummary(PLAN_FIELDS, {})).toBeNull();
        expect(repeaterRowSummary(PLAN_FIELDS, { name: '', price: '' })).toBeNull();
    });
    it('truncates very long summaries with an ellipsis', () => {
        const summary = repeaterRowSummary(PLAN_FIELDS, { name: 'x'.repeat(100) });
        expect(summary.length).toBeLessThanOrEqual(60);
        expect(summary.endsWith('…')).toBe(true);
    });
});
describe('SectionInspector repeater rows', () => {
    function renderStatsInspector(stats) {
        const section = createSection('stats');
        section.content = { ...section.content, stats };
        render(_jsx(SectionInspector, { section: section, canEdit: true, onClose: vi.fn(), onContentChange: vi.fn(), onSettingsChange: vi.fn(), onMetaChange: vi.fn(), onToggleVisibility: vi.fn() }));
    }
    it('shows value-derived row headers instead of "Stat N"', () => {
        renderStatsInspector([
            { value: '99.99%', label: 'Uptime', description: '' },
            { value: '3M+', label: 'API requests', description: '' },
        ]);
        expect(screen.getByText('99.99% · Uptime')).toBeTruthy();
        expect(screen.getByText('3M+ · API requests')).toBeTruthy();
        expect(screen.queryByText('Stat 1')).toBeNull();
    });
    it('falls back to the positional label for blank rows', () => {
        renderStatsInspector([{ value: '', label: '', description: '' }]);
        expect(screen.getByText('Stat 1')).toBeTruthy();
    });
});
//# sourceMappingURL=section-inspector-repeater.render.test.js.map