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