export const freightClass = (
    weight: number,
    length: number,
    width: number,
    height: number
) => {
    // mm to in conversion
    const convertMM = 25.4;

    const convertKG = 2.20462;
    // Inputs
    const weightPounds = weight * convertKG;
    const lengthInches = length / convertMM;
    const widthInches = width / convertMM;
    const heightInches = height / convertMM;

    // Calculate volume in cubic inches
    const volumeCubicInches = lengthInches * widthInches * heightInches;

    // Convert cubic inches to cubic feet
    const volumeCubicFeet = volumeCubicInches / 1728;

    // Calculate density
    const density = weightPounds / volumeCubicFeet;

    // Determine freight class
    let freightClass;

    if (density >= 50) {
        freightClass = 50;
    } else if (density >= 35) {
        freightClass = 55;
    } else if (density >= 30) {
        freightClass = 60;
    } else if (density >= 22.5) {
        freightClass = 65;
    } else if (density >= 15) {
        freightClass = 70;
    } else if (density >= 13.5) {
        freightClass = 77.5;
    } else if (density >= 12) {
        freightClass = 85;
    } else if (density >= 10.5) {
        freightClass = 92.5;
    } else if (density >= 9) {
        freightClass = 100;
    } else if (density >= 8) {
        freightClass = 110;
    } else if (density >= 7) {
        freightClass = 125;
    } else if (density >= 6) {
        freightClass = 150;
    } else if (density >= 5) {
        freightClass = 175;
    } else if (density >= 4) {
        freightClass = 200;
    } else if (density >= 3) {
        freightClass = 250;
    } else if (density >= 2) {
        freightClass = 300;
    } else if (density >= 1) {
        freightClass = 400;
    } else {
        freightClass = 500;
    }

    // Output the freight class
    return freightClass;
};
