import { describe, it, expect } from 'vitest';
import { Dimension } from './Dimension.js';
describe('Dimension math functions', () => {
    it('works with two grid units', () => {
        const added = Dimension.add(Dimension.gridUnit(1), Dimension.gridUnit(3));
        const minused = Dimension.minus(Dimension.gridUnit(1), Dimension.gridUnit(3));
        const maxed = Dimension.max(Dimension.gridUnit(1), Dimension.gridUnit(3));
        const minned = Dimension.min(Dimension.gridUnit(1), Dimension.gridUnit(3));
        expect(added.asFirst()).toEqual({
            value: 4,
            mode: 'gridUnit'
        });
        expect(added.asSecond()).toEqual({
            value: 4,
            mode: 'gridUnit'
        });
        expect(added.value).toEqual(4);
        expect(minused.asFirst()).toEqual({
            value: -2,
            mode: 'gridUnit'
        });
        expect(minused.asSecond()).toEqual({
            value: -2,
            mode: 'gridUnit'
        });
        expect(minused.value).toEqual(-2);
        expect(maxed.asFirst()).toEqual({
            value: 3,
            mode: 'gridUnit'
        });
        expect(maxed.asSecond()).toEqual({
            value: 3,
            mode: 'gridUnit'
        });
        expect(maxed.value).toEqual(3);
        expect(minned.asFirst()).toEqual({
            value: 1,
            mode: 'gridUnit'
        });
        expect(minned.asSecond()).toEqual({
            value: 1,
            mode: 'gridUnit'
        });
        expect(minned.value).toEqual(1);
    });
    it('works with two grid like units', () => {
        const added = Dimension.add(Dimension.gridUnit(1), Dimension.fitContent(3));
        const minused = Dimension.minus(Dimension.gridUnit(1), Dimension.fitContent(3));
        const maxed = Dimension.max(Dimension.gridUnit(1), Dimension.fitContent(3));
        const minned = Dimension.min(Dimension.gridUnit(1), Dimension.fitContent(3));
        expect(added.asFirst()).toEqual({
            value: 4,
            mode: 'gridUnit'
        });
        expect(added.asSecond()).toEqual({
            value: 4,
            mode: 'fitContent'
        });
        expect(added.value).toEqual(4);
        expect(added.as('gridUnit')).toEqual({
            value: 4,
            mode: 'gridUnit'
        });
        expect(added.as('fitContent')).toEqual({
            value: 4,
            mode: 'fitContent'
        });
        expect(minused.asFirst()).toEqual({
            value: -2,
            mode: 'gridUnit'
        });
        expect(minused.asSecond()).toEqual({
            value: -2,
            mode: 'fitContent'
        });
        expect(minused.value).toEqual(-2);
        expect(minused.as('gridUnit')).toEqual({
            value: -2,
            mode: 'gridUnit'
        });
        expect(minused.as('fitContent')).toEqual({
            value: -2,
            mode: 'fitContent'
        });
        expect(maxed.asFirst()).toEqual({
            value: 3,
            mode: 'gridUnit'
        });
        expect(maxed.asSecond()).toEqual({
            value: 3,
            mode: 'fitContent'
        });
        expect(maxed.value).toEqual(3);
        expect(maxed.as('gridUnit')).toEqual({
            value: 3,
            mode: 'gridUnit'
        });
        expect(maxed.as('fitContent')).toEqual({
            value: 3,
            mode: 'fitContent'
        });
        expect(minned.asFirst()).toEqual({
            value: 1,
            mode: 'gridUnit'
        });
        expect(minned.asSecond()).toEqual({
            value: 1,
            mode: 'fitContent'
        });
        expect(minned.value).toEqual(1);
        expect(minned.as('gridUnit')).toEqual({
            value: 1,
            mode: 'gridUnit'
        });
        expect(minned.as('fitContent')).toEqual({
            value: 1,
            mode: 'fitContent'
        });
    });
    it('works with two px units', () => {
        const added = Dimension.add(Dimension.px(1), Dimension.px(3));
        const minused = Dimension.minus(Dimension.px(1), Dimension.px(3));
        const maxed = Dimension.max(Dimension.px(1), Dimension.px(3));
        const minned = Dimension.min(Dimension.px(1), Dimension.px(3));
        expect(added.asFirst()).toEqual({
            value: 4,
            mode: 'px'
        });
        expect(added.asSecond()).toEqual({
            value: 4,
            mode: 'px'
        });
        expect(added.value).toEqual(4);
        expect(added.as('px')).toEqual({
            value: 4,
            mode: 'px'
        });
        // testing just-in-case behavior
        expect(added.as('gridUnit')).toEqual({
            value: 4 / 12,
            mode: 'gridUnit'
        });
        expect(minused.asFirst()).toEqual({
            value: -2,
            mode: 'px'
        });
        expect(minused.asSecond()).toEqual({
            value: -2,
            mode: 'px'
        });
        expect(minused.value).toEqual(-2);
        expect(maxed.asFirst()).toEqual({
            value: 3,
            mode: 'px'
        });
        expect(maxed.asSecond()).toEqual({
            value: 3,
            mode: 'px'
        });
        expect(maxed.value).toEqual(3);
        expect(minned.asFirst()).toEqual({
            value: 1,
            mode: 'px'
        });
        expect(minned.asSecond()).toEqual({
            value: 1,
            mode: 'px'
        });
        expect(minned.value).toEqual(1);
    });
    it('works with px and grid like units', () => {
        const inPx = Dimension.px(70);
        const inGU = Dimension.gridUnit(3);
        const inFitContent = Dimension.fitContent(3);
        const parentSpace = 10;
        const added1 = Dimension.add(inPx, inGU, parentSpace);
        const added2 = Dimension.add(inGU, inPx, parentSpace);
        const added3 = Dimension.add(inPx, inFitContent, parentSpace);
        // just going to assume if added1, added2, added3 both work then the permutations for the others will work too
        const minused1 = Dimension.minus(inPx, inGU, parentSpace);
        const maxed1 = Dimension.max(inPx, inGU, parentSpace);
        const minned1 = Dimension.min(inPx, inGU, parentSpace);
        expect(added1.asFirst()).toEqual({
            value: 100,
            mode: 'px'
        });
        expect(added1.asSecond()).toEqual({
            value: 10,
            mode: 'gridUnit'
        });
        expect(added1.value).toEqual(100);
        expect(added1.as('px')).toEqual({
            value: 100,
            mode: 'px'
        });
        expect(added1.as('gridUnit')).toEqual({
            value: 10,
            mode: 'gridUnit'
        });
        expect(added2.asFirst()).toEqual({
            value: 10,
            mode: 'gridUnit'
        });
        expect(added2.asSecond()).toEqual({
            value: 100,
            mode: 'px'
        });
        expect(added2.value).toEqual(100);
        expect(added2.as('px')).toEqual({
            value: 100,
            mode: 'px'
        });
        expect(added2.as('gridUnit')).toEqual({
            value: 10,
            mode: 'gridUnit'
        });
        expect(added3.asFirst()).toEqual({
            value: 100,
            mode: 'px'
        });
        expect(added3.asSecond()).toEqual({
            value: 10,
            mode: 'fitContent'
        });
        expect(added3.value).toEqual(100);
        expect(added3.as('px')).toEqual({
            value: 100,
            mode: 'px'
        });
        expect(added3.as('fitContent')).toEqual({
            value: 10,
            mode: 'fitContent'
        });
        expect(minused1.asFirst()).toEqual({
            value: 40,
            mode: 'px'
        });
        expect(minused1.asSecond()).toEqual({
            value: 4,
            mode: 'gridUnit'
        });
        expect(minused1.value).toEqual(40);
        expect(minused1.as('px')).toEqual({
            value: 40,
            mode: 'px'
        });
        expect(minused1.as('gridUnit')).toEqual({
            value: 4,
            mode: 'gridUnit'
        });
        expect(maxed1.asFirst()).toEqual({
            value: 70,
            mode: 'px'
        });
        expect(maxed1.asSecond()).toEqual({
            value: 7,
            mode: 'gridUnit'
        });
        expect(maxed1.value).toEqual(70);
        expect(maxed1.as('px')).toEqual({
            value: 70,
            mode: 'px'
        });
        expect(maxed1.as('gridUnit')).toEqual({
            value: 7,
            mode: 'gridUnit'
        });
        expect(minned1.asFirst()).toEqual({
            value: 30,
            mode: 'px'
        });
        expect(minned1.asSecond()).toEqual({
            value: 3,
            mode: 'gridUnit'
        });
        expect(minned1.value).toEqual(30);
        expect(minned1.as('px')).toEqual({
            value: 30,
            mode: 'px'
        });
        expect(minned1.as('gridUnit')).toEqual({
            value: 3,
            mode: 'gridUnit'
        });
    });
});
// eslint-disable-next-line
const typeTest = () => {
    // This should cause typescript error because if we're mixing px with non px then parentColumnSpace should be required
    // @ts-expect-error
    Dimension.add(Dimension.gridUnit(1), Dimension.px(1));
    Dimension.add(Dimension.gridUnit(1), Dimension.px(1), 1);
    // should be allowed to pass parentColumnSpace even if we know we're not mixing types
    Dimension.add(Dimension.gridUnit(1), Dimension.gridUnit(1), 1);
};
//# sourceMappingURL=Dimension.test.js.map