import t from"file-saver";function r(r,n){var e=new Blob([n],{type:"text/plain;charset=utf-8"});t.saveAs(e,r)}function n(t,r,n){var e;return Object.keys(t).forEach((function(o){-1!==r[n].toLowerCase().indexOf(o)&&(e=t[o])})),e}function e(t,r,e,o,c){try{var a,l,f,i=t.split(/[\r\n]+/),h=[],u=i.length,p=0;for(a=0;a<i.length;a+=1){var g=i[a].split(",");for(h[a]=[],l=0;l<g.length;l+=1){var v=void 0;0===a?(v=n(r,g,l),p+=1):v=1===a?e[g[l]]:parseFloat(g[l]),h[a][l]=v}}var s={},b=[],j=0,y=i[0].split(",");for(a=0;a<p/2;a+=1){for(b=[],l=2;l<u;l+=1){var O={};for(f=0;f<2;f+=1)O[h[1][2*a+f]]=h[l][2*a+f];b.push(O)}var d={openhole_friction_factor:j,casing_friction_factor:j,points:b,title:y[2*a]};j+=1;[].push(d);var _=h[0][2*a]?h[0][2*a]:"pick_up";s[_]||(s[_]=[]),s[_].push(d)}return 0===Object.keys(s).length?null:{data:{curves:s},effective_depth:o,end_depth:c}}catch(t){return null}}function o(t,r,n,e){for(var o="",c=0;c<t.length;c+=1)r[n[c]]?o+=e+r[n[c]]:o+=n[c],o+=c<t.length-1?",":"";t.length>0&&(o+="\n");for(var a=0;a<t.length;a+=1)o+=t[a],o+=a<t.length-1?",":"";return o}function c(t,r,n,e){var a=[],l=[],f="",i="";return e||(e=""),"[object Array]"===Object.prototype.toString.call(t)?function(t,r,n,e){if(!t||0===t.length)return"";for(var o="",a=Object.keys(t[0]),l=a.length,f=l,i=[],h=!1,u=0;u<t.length;u+=1)for(var p=0;p<l;p+=1)"[object Array]"===Object.prototype.toString.call(t[u][a[p]])&&(f=p);if(r)for(var g=0;g<f;g+=1)r[a[g]]?i[g]=e+r[a[g]]:i[g]=a[g];"\n"!==o[o.length-1]&&(o+="\n");for(var v=0;v<t.length;v+=1){if(!v||h){for(var s=0;s<f;s+=1)r&&(o+=i[s]),o+=s<f-1?",":"";o+="\n"}for(var b=0;b<l;b+=1)if("[object Array]"===Object.prototype.toString.call(t[v][a[b]])){h=!0;var j=n&&n[a[b]]?"".concat(n[a[b]]," "):"";o+="\n".concat(c(t[v][a[b]],r,n,e+j))}else(t[v][a[b]]||0===t[v][a[b]])&&(o+=t[v][a[b]]),o+=b<l-1?",":"";o+="\n"}return o}(t,r,n,e):(Object.keys(t).forEach((function(h){"[object Array]"===Object.prototype.toString.call(t[h])?(f+=o(a,r,l,e),a=[],l=[],"\n"!==f[f.length-1]&&(f+="\n"),i=n&&n[h]?"".concat(n[h]," "):"",f+=c(t[h],r,n,e+i)):"[object Object]"===Object.prototype.toString.call(t[h])?(f+=o(a,r,l,e),a=[],l=[],f.length>0&&"\n"!==f[f.length-1]&&(f+="\n"),i=n&&n[h]?"".concat(n[h]," "):"",f+=c(t[h],r,n,e+i)):t[h]&&t[h].toString().length>0&&(a.push(t[h]),l.push(h))})),"\n"!==f[f.length-1]&&(f+="\n"),(f+=o(a,r,l,e)).trim())}function a(t){return t.reduce((function(t,r){var n=r.title,e=r.csv;return"".concat(t,"\n").concat(n).concat(e)}),"")}export{a as concatCsv,e as convertCsvToJson,c as convertJsonToCsv,r as downloadFile};
