import { describe, expect, test } from "bun:test";
import { formatPrice, formatWeight } from "../src/client/lib/formatters";

describe("formatPrice", () => {
	test("returns -- for null", () => {
		expect(formatPrice(null)).toBe("--");
	});

	test("returns -- for undefined", () => {
		expect(formatPrice(undefined)).toBe("--");
	});

	test("formats USD with en locale", () => {
		const result = formatPrice(12345, "USD", "en");
		expect(result).toContain("123.45");
		expect(result).toContain("$");
	});

	test("formats EUR with de locale", () => {
		const result = formatPrice(12345, "EUR", "de");
		// German uses comma for decimal
		expect(result).toContain("123,45");
	});

	test("formats JPY with no decimals", () => {
		const result = formatPrice(10000, "JPY", "en");
		expect(result).toContain("100");
	});

	test("formats large amounts with en locale", () => {
		const result = formatPrice(123456789, "USD", "en");
		expect(result).toContain("$");
	});

	test("defaults to en locale when no locale provided", () => {
		const result = formatPrice(12345, "USD");
		expect(result).toContain("$");
	});
});

describe("formatWeight", () => {
	test("returns -- for null", () => {
		expect(formatWeight(null)).toBe("--");
	});

	test("returns -- for undefined", () => {
		expect(formatWeight(undefined)).toBe("--");
	});

	test("formats grams with en locale", () => {
		const result = formatWeight(500, "g", "en");
		expect(result).toBe("500g");
	});

	test("formats large grams with en locale thousands separator", () => {
		const result = formatWeight(1234, "g", "en");
		expect(result).toContain("g");
	});

	test("formats ounces", () => {
		const result = formatWeight(100, "oz", "en");
		expect(result).toContain("oz");
	});

	test("formats kilograms", () => {
		const result = formatWeight(1500, "kg", "en");
		expect(result).toContain("kg");
	});

	test("formats pounds", () => {
		const result = formatWeight(1000, "lb", "en");
		expect(result).toContain("lb");
	});

	test("defaults to en locale when no locale provided", () => {
		const result = formatWeight(500, "g");
		expect(result).toBe("500g");
	});
});
