"use strict";
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="560c9643-1689-5d97-903d-7bee165148b5")}catch(e){}}();
(globalThis.webpackChunkwoocommerce_shipping=globalThis.webpackChunkwoocommerce_shipping||[]).push([[180],{2180(e,r,t){t.r(r),t.d(r,{default:()=>$});var a={};t.r(a),t.d(a,{getLabelsReport:()=>k,getState:()=>S});var o={};t.r(o),t.d(o,{fetchLabelsSuccess:()=>x});var i={};t.r(i),t.d(i,{getLabelsReport:()=>C});var s=t(4886),n=t(7143),c=t(6161),l=t(8468);const p=e=>(0,l.mapKeys)(e,((e,r)=>(0,l.camelCase)(r)));t(5703);var d=t(8443),m=t(7723);(0,l.memoize)((e=>(0,l.groupBy)(e,"serviceId")));const u=e=>{try{return new ActiveXObject(e)}catch{}};(0,l.memoize)((()=>(0,l.get)(window,"navigator.msSaveOrOpenBlob")?"ie":/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|mobile|CriOS/i.test(navigator.userAgent)&&!window.MSStream?"addon":(0,l.includes)(navigator.userAgent,"Firefox")?parseFloat(navigator.userAgent.split("Firefox/")[1])>=94?"native_ff":"addon":(0,l.includes)(navigator.userAgent,"Safari")&&!(0,l.includes)(navigator.userAgent,"Chrome")?"addon":navigator.mimeTypes?.["application/pdf"]||navigator.pdfViewerEnabled?"native":!(!u("AcroPDF.PDF")&&!u("PDF.PdfCtrl"))&&"addon")),Error;var g=t(3832);t(8490);var h=t(4993);const w=["created_date","order_id","rate","service_name","refund","tracking","carrier_id"],f=e=>{return(0,g.addQueryArgs)("/wcshipping/v1/reports/labels",(r=(e=>{const{period:r,compare:t,before:a,after:o}=(0,h.getDateParamsFromQuery)(e),{primary:i,secondary:s}=(0,h.getCurrentDates)(e);return{period:r,compare:t,before:a,after:o,primary:i,secondary:s}})(e),t={perPage:e.perPage,offset:e.offset},{after:encodeURIComponent((0,h.appendTimestamp)(r.primary.after,"start")),before:encodeURIComponent((0,h.appendTimestamp)(r.primary.before,"end")),per_page:t.perPage,offset:t.offset,fields:w}));var r,t};var y=t(1455),v=t.n(y);const b="ANALYTICS/FETCH_LABELS_SUCCESS",_=(e=>{const r={},t=()=>(t=e,a)=>{const o=r[a.type];return"function"==typeof o?o(t,a):t},a=(e,o)=>(r[e]=o,{on:a,bind:t});return{on:a,bind:t}})({data:void 0}).on(b,((e,{payload:{query:r,result:t}})=>{var a;return{...e,data:{...null!==(a=e.data)&&void 0!==a?a:{},[JSON.stringify(r)]:{rows:t.rows,meta:t.meta}}}})).bind(),S=e=>e,k=(e,r)=>e.data?.[JSON.stringify(r)],x=e=>({type:b,payload:e});function*C(e){const{rows:r,meta:t}=yield(0,c.apiFetch)({path:f(e),method:"GET"});return x({query:e,result:{rows:r.map(p),meta:p(t)}})}let A;var P=t(8846),j=t(1894),F=t(4669),D=t(9174),L=t(6087),I=t(1554),T=t(790);const N=()=>(0,T.jsx)("svg",{role:"img","aria-hidden":"true",focusable:"false",version:"1.1",xmlns:"http://www.w3.org/2000/svg",x:"0px",y:"0px",viewBox:"0 0 24 24",style:{width:"24px",height:"24px",marginRight:"8px"},children:(0,T.jsx)("path",{d:"M18,9c-0.009,0-0.017,0.002-0.025,0.003C17.72,5.646,14.922,3,11.5,3C7.91,3,5,5.91,5,9.5c0,0.524,0.069,1.031,0.186,1.519 C5.123,11.016,5.064,11,5,11c-2.209,0-4,1.791-4,4c0,1.202,0.541,2.267,1.38,3h18.593C22.196,17.089,23,15.643,23,14 C23,11.239,20.761,9,18,9z M12,16l-4-5h3V8h2v3h3L12,16z"})}),R=({href:e,children:r,type:t="wc-admin",...a})=>{const o={...a,"data-link-type":t};return"wc-admin"===t&&(o.onClick=(0,l.partial)(((e,r)=>{if(!(r?.ctrlKey||r?.metaKey||r?.altKey||r?.shiftKey)&&(r?.preventDefault(),!1!==(!e||!r||e(r))&&r?.target instanceof Element)){const e=r.target.closest("a")?.getAttribute("href");e?window.history.pushState({},"",e):console.error("Link is trying to push an undefined state into navigation stack")}}),o.onClick)),(0,T.jsx)("a",{href:e,...o,children:r})};var q=t(3487);const E={usps:e=>`https://tools.usps.com/go/TrackConfirmAction.action?tLabels=${e}`,fedex:e=>`https://www.fedex.com/apps/fedextrack/?action=track&tracknumbers=${e}`,ups:e=>`https://www.ups.com/track?loc=en_US&tracknum=${e}`,upsdap:e=>`https://www.ups.com/track?loc=en_US&tracknum=${e}`,dhlexpress:e=>`https://www.dhl.com/en/express/tracking.html?AWB=${e}&brand=DHL`},B=e=>r=>{var t,a;const o=r.createdDate?(0,d.dateI18n)("M d, Y g:i a",new Date(r.createdDate),!1):null;return[{display:o,value:o},{display:(0,T.jsx)(R,{href:`post.php?post=${r.orderId}&action=edit`,type:"wp-admin",target:"_blank",children:`#${r.orderId}`}),value:r.orderId},{display:e?.render(null!==(t=r.rate)&&void 0!==t?t:0),value:null!==(a=r.rate)&&void 0!==a?a:0},{display:r.serviceName,value:r.serviceName},{display:r.carrierId&&r.tracking&&E[r.carrierId]?(0,T.jsx)(q.A,{href:E[r.carrierId](r.tracking),children:r.tracking}):r.tracking,value:r.tracking},{display:r.refund?.status,value:r.refund?.status}]},O=[{key:"createdDate",label:(0,m.__)("Date","woocommerce-shipping"),isLeftAligned:!0,isSortable:!1,required:!0},{key:"orderId",label:(0,m.__)("Order","woocommerce-shipping"),isSortable:!1,isNumeric:!1,required:!0},{key:"rate",label:(0,m.__)("Price","woocommerce-shipping"),isSortable:!1,isNumeric:!0,required:!0},{key:"serviceName",label:(0,m.__)("Service","woocommerce-shipping"),isSortable:!1,isNumeric:!1,required:!0},{key:"tracking",label:(0,m.__)("Tracking Number","woocommerce-shipping"),isSortable:!1,isLeftAligned:!0,isNumeric:!0,required:!1},{key:"refund",label:(0,m.__)("Refund status","woocommerce-shipping"),isSortable:!1,isNumeric:!1}],M=({query:e,path:r,currency:t})=>{var a;const[o,i]=(0,L.useState)({perPage:25,paged:1}),[s,c]=(0,L.useState)(!1),[d,u]=(0,L.useState)([]),g={rows:[],summary:[]},w=(0,n.useSelect)((r=>(u([]),r(A).getLabelsReport({...e,perPage:o.perPage.toString(),offset:""+(o.paged-1)*o.perPage}))),[e,r,o]);w?.rows&&w.meta&&(g.rows=w.rows.map(B(t)),g.summary=[{key:"total_count",label:(0,m.__)("Labels purchased in this period","woocommerce-shipping"),value:w.meta.totalCount},{key:"total_cost",label:(0,m.__)("Total label cost in this period","woocommerce-shipping"),value:t?.render(w.meta.totalCost)},{key:"total_refunds",label:(0,m.__)("Refund in this period","woocommerce-shipping"),value:w.meta.totalRefunds}]);const y=void 0===w;return(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(P.ReportFilters,{query:e,path:r,isoDateFormat:h.isoDateFormat}),(0,T.jsx)(j.A,{status:"info",isDismissible:!1,children:(0,m.sprintf)(
// translators: %d is the cache expiration in minutes
// translators: %d is the cache expiration in minutes
(0,m.__)("To improve performance, the data shown here may be up to %d minutes old.","woocommerce-shipping"),window.WCShipping_Config.cacheExpirationInSeconds/60)}),(0,T.jsx)(F.A,{marginBottom:3}),d.length>0&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(j.A,{status:"error",children:d.map(((e,r)=>(0,T.jsx)("p",{children:e},r)))}),(0,T.jsx)(F.A,{marginBottom:3})]}),(0,T.jsx)(P.TableCard,{title:(0,m.__)("Labels in this period","woocommerce-shipping"),rows:g.rows,headers:O,rowsPerPage:o.perPage,totalRows:null!==(a=w?.meta.totalCount)&&void 0!==a?a:0,summary:g.summary,isLoading:y,query:o,actions:[(0,T.jsxs)(D.Ay,{disabled:y||0===g.rows.length||s,onClick:async()=>{let{rows:r}=g;if(u([]),w?.meta.totalCount&&w.meta.totalCount>o.perPage){c(!0);try{r=(await v()({path:f({...e,perPage:"-1",offset:"0"}),method:"GET"})).rows.map(p).map(B(t))}catch{return void u([...d,(0,m.__)("Failed to fetch data for export.","woocommerce-shipping")])}finally{c(!1)}}try{const t={...e};(0,I.downloadCSVFile)((0,I.generateCSVFileName)((0,m.__)("Shipping Labels","woocommerce-shipping"),t),(0,I.generateCSVDataFromTable)(O,r))}catch{u([...d,(0,m.__)("Failed to request download of CSV file.","woocommerce-shipping")])}},title:(0,m.__)("Export CSV","woocommerce-shipping"),isBusy:s,children:[(0,T.jsx)(N,{}),(0,m.__)("Download","woocommerce-shipping")]},"download")],onQueryChange:e=>r=>{"page_size"!==e&&"paged"!==e||i({...o,[(0,l.camelCase)(e)]:parseInt(r,10)})}})]})},V=(0,s.Ay)();A=A||(0,n.createReduxStore)("wcshipping/analytics",{reducer:_,actions:o,selectors:a,controls:c.controls,resolvers:i}),(0,n.register)(A);const $=e=>(0,T.jsx)("div",{className:"wcshipping-label-analytics",children:(0,T.jsx)(M,{...e,currency:V})})}}]);
//# sourceMappingURL=180.js.map
//# debugId=560c9643-1689-5d97-903d-7bee165148b5