import {expect} from 'chai';
import {extractKeys} from "../../../../source/dom/util/extract-keys.mjs";


describe('extractKeys', () => {
    it('should extract keys from the given object', () => {
        const obj = {
            firstName: 'John',
            lastName: 'Doe',
            address: {
                street: '123 Main St',
                city: 'New York',
            },
        };

        const result = extractKeys(obj);

        expect(result.get('firstname')).to.equal('firstName');
        expect(result.get('first-name')).to.equal('firstName');
        expect(result.get('lastname')).to.equal('lastName');
        expect(result.get('last-name')).to.equal('lastName');
        expect(result.get('address-street')).to.equal('address.street');
        expect(result.get('address-city')).to.equal('address.city');
    });

    it('should use custom key and value separators', () => {
        const obj = {
            firstName: 'John',
            lastName: 'Doe',
        };

        const result = extractKeys(obj, 'prefix', '+', '+');

        expect(result.get('prefix+firstname')).to.equal('prefix+firstName');
        expect(result.get('prefix+first-name')).to.equal('prefix+firstName');
        expect(result.get('prefix+lastname')).to.equal('prefix+lastName');
        expect(result.get('prefix+last-name')).to.equal('prefix+lastName');
    });

    it('check if value is null', () => {
        const obj = {
            firstName: 'John',
            lastName: 'Doe',
            address: null,
        };

        const result = extractKeys(obj);

        expect(result.get('firstname')).to.equal('firstName');
        expect(result.get('first-name')).to.equal('firstName');
        expect(result.get('lastname')).to.equal('lastName');
        expect(result.get('last-name')).to.equal('lastName');
        expect(result.get('address')).to.equal('address');
    });

    it('should expose kebab-case aliases for camelCase nested keys', () => {
        const obj = {
            popper: {
                contentOverflow: 'both',
            },
            message: {
                width: {
                    viewportRatio: 0.7,
                },
            },
        };

        const result = extractKeys(obj);

        expect(result.get('popper-contentoverflow')).to.equal('popper.contentOverflow');
        expect(result.get('popper-content-overflow')).to.equal('popper.contentOverflow');
        expect(result.get('message-width-viewportratio')).to.equal('message.width.viewportRatio');
        expect(result.get('message-width-viewport-ratio')).to.equal('message.width.viewportRatio');
    });
});
