import { __awaiter } from "tslib";
import { assert, createLogicSuite } from '@genesislcap/foundation-testing';
import { FoundationAiAssistant } from './main';
// Hold a reference so the custom-element registration isn't tree-shaken.
FoundationAiAssistant;
// GENC-1508 — image files become IMAGE attachments, not text.
//
// `processFiles` read every accepted file with `readAsText`, so an accepted .png
// arrived as mojibake the model "read" as prose — an accepted image was worse than a
// rejected one. The layout-apply flow attaches the picked mockup's PNG beside its
// spec, which is what forced the branch: images now read as base64 and ship as
// `{kind:'image'}`, the shape the transports render as real image blocks.
//
// Unconnected elements (createElement upgrades but does not connect), same as
// blocked-state.test.ts — processFiles touches no session state.
const Suite = createLogicSuite('FoundationAiAssistant file attachments');
function element(acceptedFiles) {
    const el = document.createElement('foundation-ai-assistant');
    el.chatConfig = { ui: { acceptedFiles } };
    return el;
}
/** A tiny valid PNG header is unnecessary — processFiles never parses pixels. */
const PNG_BYTES = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
Suite('an accepted image file becomes a kind:image attachment with raw base64', () => __awaiter(void 0, void 0, void 0, function* () {
    const el = element('.md,image/*');
    const { attachments, errors } = yield el.processFiles([
        new File([PNG_BYTES], 'layout-mockup.png', { type: 'image/png' }),
    ]);
    assert.equal(errors, []);
    const [img] = attachments;
    assert.is(img.kind, 'image');
    assert.is(img.name, 'layout-mockup.png');
    assert.is(img.mimeType, 'image/png');
    // RAW base64 — a `data:` prefix left on would be sent to the vendor inside the payload.
    assert.ok(img.data && !img.data.startsWith('data:'), 'data must be bare base64');
    assert.is(atob(img.data).length, PNG_BYTES.length);
}));
Suite('a text file on the same submit stays a text attachment', () => __awaiter(void 0, void 0, void 0, function* () {
    const el = element('.md,image/*');
    const { attachments } = yield el.processFiles([
        new File(['# spec'], 'layout-spec.md', { type: 'text/markdown' }),
        new File([PNG_BYTES], 'layout-mockup.png', { type: 'image/png' }),
    ]);
    const [text, img] = attachments;
    assert.is(text.kind, undefined);
    assert.is(text.content, '# spec');
    assert.is(img.kind, 'image');
}));
Suite('an image type the host did not accept is still refused', () => __awaiter(void 0, void 0, void 0, function* () {
    const el = element('.md,.txt');
    const { attachments, errors } = yield el.processFiles([
        new File([PNG_BYTES], 'layout-mockup.png', { type: 'image/png' }),
    ]);
    assert.equal(attachments, []);
    assert.is(errors.length, 1);
    assert.match(errors[0], /not an accepted file type/);
}));
Suite.run();
