import t from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/helpers/toConsumableArray";import e from"lodash/sumBy";import n from"lodash/chunk";function o(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function i(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?o(Object(n),!0).forEach((function(e){t(r,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}var p="SMALL",a="MEDIUM",s="LARGE",u="XLARGE",c=37.7952755906,l=18.8976377953,m=function(t){var r=t.width,e=t.height;return{pixelWidth:Math.round(18.8976377953*r),pixelHeight:Math.round(18.8976377953*e),realWidth:Math.round(2*r*18.8976377953),realHeight:Math.round(2*e*18.8976377953)}},h={type:"QUATER",columns:{min:1,max:2},rows:{min:1,max:10},slots:1,height:8.4,width:10.3},f={NORMAL:{type:"NORMAL",columns:{min:1,max:7},rows:{min:1,max:1e3},slots:1,height:17.5,width:20.8},WIDE:{type:"WIDE",columns:{min:8,max:12},rows:{min:1,max:25},slots:2,height:17.5,width:41.8},HALFSCREEN:{type:"HALFSCREEN",columns:{min:8,max:12},rows:{min:26,max:40},slots:4,height:26.5,width:41.8},FULLSCREEN:{type:"FULLSCREEN",columns:{min:8,max:12},rows:{min:41,max:1e3},slots:6,height:53.3,width:41.8}},y=function(t){var e=r(t);return e.sort((function(t,r){var e=t.coordinates.y,n=r.coordinates.y;if(e<n)return-1;if(e>n)return 1;if(e===n){var o=t.coordinates.x,i=r.coordinates.x;if(o<i)return-1;if(o>i)return 1}return 0})),e},v=Object.values(f);function d(t,r){var e=t.coordinates,n=t.isFullScreenReport,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:v;if("singleApp"===r||n)return f.FULLSCREEN;var i=e.w,p=e.h;return o.find((function(t){return i>=t.columns.min&&i<=t.columns.max&&p>=t.rows.min&&p<=t.rows.max}))}var E=function(t,r,e){if(!("compact"===e))return{quaterApps:[],otherApps:t.map((function(t){return i(i({},t),{},{appType:d(t,r,v)})}))};var n={quaterApps:[],otherApps:[]},o=[h].concat(v);return t.forEach((function(t){var e=d(t,r,o),p=i(i({},t),{},{appType:e});e.type===h.type?n.quaterApps.push(p):n.otherApps.push(p)})),n};function g(t){var e=E(t),n=e.otherApps,o=e.quaterApps;return[].concat(r(y(n)),r(y(o)))}function A(t,o,i){var p=E(t,o,i),a=p.otherApps,s=p.quaterApps,u=y(a),c=y(s),l=0,m=u.reduce((function(t,n,o,i){var p=n.appType,a=p.slots,s=p.type;if(s!==f.FULLSCREEN.type){var u=i[o+1];if(u){var c=u.appType;if(console.log(u),l%2==0&&1===a&&c.slots%2==0){var m=f.WIDE;a=m.slots,s=m.type}}else if(o%2==0){var h=f.WIDE;a=h.slots,s=h.type}}l+=a;var y={app:n,slots:a,reportAppSize:n.appType},v=!1,d=t.map((function(t){if(v)return t;var n=6-e(t,"slots");return n>=a&&(v=!0),n>=a?[].concat(r(t),[y]):t}));return v?d:[].concat(r(d),[[y]])}),[[]]);if(!c.length)return m;var v=m[m.length-1],d=4*(6-e(v,"slots")),g=c.map((function(t){return{app:t,reportAppSize:h}})),A=[].concat(r(v),r(g.slice(0,d))),w=n(g.slice(d),24);return[].concat(r(m.slice(0,m.length-1)),[A],r(w))}function w(t){var r=t.w,e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e?u:r>=5?s:r>=3?a:p}export{l as PDF_REPORT_PIXEL_RATIO,c as PIXELS_IN_CM,f as REPORT_APP_GRID_TYPES,d as getAppType,m as getPDFAppPixelSize,w as getPDFAppSize,A as getPages,g as sortPDFDashboardApps};
