import{cloneDeep as e}from"lodash";import{getUnitPreference as t,convertValue as n}from"../../../../../utils/index.js";var r=function(e,t){var n=parseFloat(e),r=parseFloat(t);return Number.isNaN(n)||Number.isNaN(r)?null:(n*r).fixFloat(2)},i=function(i,a,o){var l,s,h,u,g,m,_,f,c=i.family,b=e(i);if(b[a]=o,"bit"===c)return"nozzle_sizes"===a&&(b.tfa=(l=b.nozzle_sizes||[],s=t("shortLength"),h=Math.PI/4*l.reduce((function(e,t){var r=t.count||0,i=t.size||0,a="in"!==s?32*n(i,"shortLength",s,"in"):i;return e+r*(a/32*(a/32))}),0),(u=n(1,"shortLength","in",s))*u*h)),b;switch(a){case"inner_diameter":case"outer_diameter":b.linear_weight=function(e,r){var i=t("shortLength"),a=parseFloat(r),o=parseFloat(e);if(Number.isNaN(a)||Number.isNaN(o)||o<a)return null;"in"!==i&&(a=n(a,"shortLength",i,"in"),o=n(o,"shortLength",i,"in"));var l=2.673*(o*o-a*a);return"in"!==i?n(l,"massPerLength","lb-ft"):l.fixFloat(2)}(b.outer_diameter,b.inner_diameter),b.weight=r(b.linear_weight,b.length);break;case"number_of_joints":case"component_length":b.length=(g=b.number_of_joints,m=b.component_length,_=parseFloat(g),f=parseFloat(m),Number.isFinite(_)&&Number.isFinite(f)?(_*f).fixFloat(2):null),b.weight=r(b.linear_weight,b.length);break;case"linear_weight":b.weight=r(b.linear_weight,b.length);break;case"length":b.weight=r(b.linear_weight,b.length),b.component_length=function(e,t){var n=parseFloat(e),r=parseFloat(t);return Number.isFinite(n)&&Number.isFinite(r)?(n/r).fixFloat(2):null}(b.length,b.number_of_joints)}return b};export{i as calculateComponent};
