(globalThis.webpackChunkstoresuite=globalThis.webpackChunkstoresuite||[]).push([[696],{2753(e,t,s){"use strict";s.r(t),s.d(t,{default:()=>S});var a=s(7723),i=s(6087),r=s(7143),l=s(1455),n=s.n(l),o=s(6427),c=s(1993),d=s(6773),u=s(5),_=s(5373),g=s(6670),h=s(790);const p="woocommerce_excluded_report_order_statuses",m="woocommerce_actionable_order_statuses",y="woocommerce_default_date_range",b="woocommerce_date_type",x="period=month&compare=previous_year",f=["pending","failed","cancelled"],v=["processing","on-hold"],j=({label:e,help:t,statuses:s,value:a,onChange:i})=>(0,h.jsxs)("fieldset",{className:"storesuite-analytics-settings__field",children:[(0,h.jsx)("legend",{className:"storesuite-analytics-settings__label",children:e}),(0,h.jsx)("p",{className:"storesuite-analytics-settings__help",children:t}),(0,h.jsx)("div",{className:"storesuite-analytics-settings__statuses",children:Object.keys(s).map(e=>(0,h.jsx)(o.CheckboxControl,{__nextHasNoMarginBottom:!0,label:s[e],checked:a.includes(e),onChange:t=>i(t?[...a,e]:a.filter(t=>t!==e))},e))})]});function S(){const e=(0,r.useSelect)(e=>{const{getOption:t,hasFinishedResolution:s}=e(c.OPTIONS_STORE_NAME);return{excluded:t(p),actionable:t(m),dateRange:t(y),dateType:t(b),isLoading:!(s("getOption",[p])&&s("getOption",[m])&&s("getOption",[y])&&s("getOption",[b]))}}),{createNotice:t}=(0,r.useDispatch)("core/notices"),[s,l]=(0,i.useState)(!1),[S,N]=(0,i.useState)(null),[C,D]=(0,i.useState)(null),[w,O]=(0,i.useState)(null),[k,T]=(0,i.useState)(null);if((0,i.useEffect)(()=>{e.isLoading||(N(t=>null===t?e.excluded||f:t),D(t=>null===t?e.actionable||v:t),O(t=>null===t?e.dateRange||x:t),T(t=>null===t?e.dateType||"date_paid":t))},[e.isLoading]),e.isLoading||null===S)return null;const R={...(0,g.Qk)("orderStatuses",{}),...(0,g.Qk)("unregisteredOrderStatuses",{})},B=(0,_.parse)(String(w).replace(/&amp;/g,"&")),{period:F,compare:P,before:E,after:L}=(0,u.getDateParamsFromQuery)(B,x),{primary:Q,secondary:A}=(0,u.getCurrentDates)(B,x);return(0,h.jsxs)(o.Card,{className:"storesuite-analytics-settings",children:[(0,h.jsx)(o.CardHeader,{children:(0,h.jsx)("h2",{children:(0,a.__)("Analytics Settings","storesuite")})}),(0,h.jsxs)(o.CardBody,{children:[(0,h.jsx)(j,{label:(0,a.__)("Excluded statuses","storesuite"),help:(0,a.__)("Orders with these statuses are excluded from the totals in your reports.","storesuite"),statuses:R,value:S,onChange:N}),(0,h.jsx)(j,{label:(0,a.__)("Actionable statuses","storesuite"),help:(0,a.__)("Orders with these statuses require action on behalf of the store admin.","storesuite"),statuses:R,value:C,onChange:D}),(0,h.jsxs)("fieldset",{className:"storesuite-analytics-settings__field",children:[(0,h.jsx)("legend",{className:"storesuite-analytics-settings__label",children:(0,a.__)("Default date range","storesuite")}),(0,h.jsx)("p",{className:"storesuite-analytics-settings__help",children:(0,a.__)("Select a default date range. When no range is selected, reports will be viewed by the default date range.","storesuite")}),(0,h.jsx)(d.DateRangeFilterPicker,{query:B,onRangeSelect:e=>O((0,_.stringify)(e)),dateQuery:{period:F,compare:P,before:E,after:L,primaryDate:Q,secondaryDate:A},isoDateFormat:u.isoDateFormat})]}),(0,h.jsxs)("fieldset",{className:"storesuite-analytics-settings__field",children:[(0,h.jsx)("legend",{className:"storesuite-analytics-settings__label",children:(0,a.__)("Date type","storesuite")}),(0,h.jsx)(o.SelectControl,{__next40pxDefaultSize:!0,__nextHasNoMarginBottom:!0,help:(0,a.__)("Database date field considered for Revenue and Orders reports.","storesuite"),options:[{value:"date_created",label:(0,a.__)("Date created","storesuite")},{value:"date_paid",label:(0,a.__)("Date paid","storesuite")},{value:"date_completed",label:(0,a.__)("Date completed","storesuite")}],value:k,onChange:T})]}),(0,h.jsx)("div",{className:"storesuite-analytics-settings__actions",children:(0,h.jsx)(o.Button,{variant:"primary",isBusy:s,disabled:s,onClick:async()=>{l(!0);try{await n()({path:"/wc-analytics/settings/wc_admin/batch",method:"POST",data:{update:[{id:p,value:S},{id:m,value:C},{id:y,value:w},{id:b,value:k}]}}),t("success",(0,a.__)("Your settings have been successfully saved.","storesuite"),{type:"snackbar"})}catch(e){t("error",(0,a.__)("There was an error saving your settings. Please try again.","storesuite"),{type:"snackbar"})}l(!1)},children:(0,a.__)("Save settings","storesuite")})})]})]})}},2634(){}}]);