JezK
Edit File: analytics-settings.js
"use strict";(globalThis.webpackChunk_wcAdmin_webpackJsonp=globalThis.webpackChunk_wcAdmin_webpackJsonp||[]).push([[5941],{95266:(e,t,o)=>{o.d(t,{gV:()=>d,zm:()=>u,$W:()=>b});var s=o(27723),r=o(52619),a=o(85703),i=o(98846),c=o(40314),n=o(77374),l=o(39793);var m=o(90212);const d=["processing","on-hold"],p=["completed","processing","refunded","cancelled","failed","pending","on-hold"],u="woocommerce_analytics_scheduled_import",h=Object.keys(m.wm).filter(e=>"refunded"!==e).map(e=>({value:e,label:m.wm[e],description:(0,s.sprintf)((0,s.__)("Exclude the %s status from reports","woocommerce"),m.wm[e])})),_=(0,m.Qk)("unregisteredOrderStatuses",{}),g=[{key:"defaultStatuses",options:h.filter(e=>p.includes(e.value))},{key:"customStatuses",label:(0,s.__)("Custom Statuses","woocommerce"),options:h.filter(e=>!p.includes(e.value))},{key:"unregisteredStatuses",label:(0,s.__)("Unregistered Statuses","woocommerce"),options:Object.keys(_).map(e=>({value:e,label:e,description:(0,s.sprintf)((0,s.__)("Exclude the %s status from reports","woocommerce"),e)}))}],w={woocommerce_excluded_report_order_statuses:{label:(0,s.__)("Excluded statuses:","woocommerce"),inputType:"checkboxGroup",options:g,helpText:(0,a.A)({mixedString:(0,s.__)("Orders with these statuses are excluded from the totals in your reports. The {{strong}}Refunded{{/strong}} status can not be excluded.","woocommerce"),components:{strong:(0,l.jsx)("strong",{})}}),defaultValue:["pending","cancelled","failed"]},woocommerce_actionable_order_statuses:{label:(0,s.__)("Actionable statuses:","woocommerce"),inputType:"checkboxGroup",options:g,helpText:(0,s.__)("Orders with these statuses require action on behalf of the store admin. These orders will show up in the Home Screen - Orders task.","woocommerce"),defaultValue:d},woocommerce_default_date_range:{name:"woocommerce_default_date_range",label:(0,s.__)("Default date range:","woocommerce"),inputType:"component",component:({value:e,onChange:t})=>{const{wcAdminSettings:o}=(0,c.useSettings)("wc_admin",["wcAdminSettings"]),{woocommerce_default_date_range:s}=o,r=Object.fromEntries(new URLSearchParams(e.replace(/&/g,"&"))),{period:a,compare:m,before:d,after:p}=(0,n.getDateParamsFromQuery)(r,s),{primary:u,secondary:h}=(0,n.getCurrentDates)(r,s),_={period:a,compare:m,before:d,after:p,primaryDate:u,secondaryDate:h};return(0,l.jsx)(i.DateRangeFilterPicker,{query:r,onRangeSelect:e=>{const o=Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e));t({target:{name:"woocommerce_default_date_range",value:new URLSearchParams(o).toString()}})},dateQuery:_,isoDateFormat:n.isoDateFormat})},helpText:(0,s.__)("Select a default date range. When no range is selected, reports will be viewed by the default date range.","woocommerce"),defaultValue:"period=month&compare=previous_year"},woocommerce_date_type:{name:"woocommerce_date_type",label:(0,s.__)("Date type:","woocommerce"),inputType:"select",options:[{label:(0,s.__)("Select a date type","woocommerce"),value:"",disabled:!0},{label:(0,s.__)("Date created","woocommerce"),value:"date_created",key:"date_created"},{label:(0,s.__)("Date paid","woocommerce"),value:"date_paid",key:"date_paid"},{label:(0,s.__)("Date completed","woocommerce"),value:"date_completed",key:"date_completed"}],helpText:(0,s.__)("Database date field considered for Revenue and Orders reports","woocommerce"),defaultValue:"date_paid"}},v=(0,m.Qk)("woocommerce_analytics_import_interval",(0,s.__)("12 hours","woocommerce"));w[u]={name:u,label:(0,s.__)("Updates:","woocommerce"),inputType:"radio",options:[{label:(0,s.__)("Scheduled (recommended)","woocommerce"),value:"yes",description:(0,s.sprintf)((0,s.__)("Updates automatically every %s. Lowest impact on your site.","woocommerce"),v)},{label:(0,s.__)("Immediately","woocommerce"),value:"no",description:(0,s.__)("Updates as soon as new data is available. May slow busy stores.","woocommerce")}],defaultValue:"yes"};const b=(0,r.applyFilters)("woocommerce_admin_analytics_settings",w)},38176:(e,t,o)=>{o.r(t),o.d(t,{default:()=>R});var s=o(27723),r=o(56427),a=o(86087),i=o(29491),c=o(47143),n=o(98846),l=o(40314),m=o(83306),d=o(95266),p=o(66087),u=o(39793);class h extends a.Component{constructor(e){super(e),this.state={disabled:!1}}renderInput=()=>{const{handleChange:e,name:t,inputText:o,inputType:s,options:a,value:i,component:c}=this.props,{disabled:n}=this.state;switch(s){case"checkboxGroup":return a.map(e=>e.options.length>0&&(0,u.jsxs)("div",{className:"woocommerce-setting__options-group","aria-labelledby":t+"-label",children:[e.label&&(0,u.jsx)("span",{className:"woocommerce-setting__options-group-label",children:e.label}),this.renderCheckboxOptions(e.options)]},e.key));case"checkbox":return this.renderCheckboxOptions(a);case"button":return(0,u.jsx)(r.Button,{variant:"secondary",onClick:this.handleInputCallback,disabled:n,children:o});case"component":const s=c;return(0,u.jsx)(s,{value:i,onChange:e,...this.props});case"select":return(0,u.jsx)(r.SelectControl,{__next40pxDefaultSize:!0,options:a,value:i,onChange:o=>e({target:{name:t,type:"select",value:o}})});case"radio":return(0,u.jsx)(r.RadioControl,{selected:i,options:a,onChange:o=>e({target:{name:t,type:"radio",value:o}})});default:const l=(0,p.uniqueId)(t);return(0,u.jsx)("input",{id:l,type:"text",name:t,onChange:e,value:i,placeholder:o,disabled:n})}};handleInputCallback=()=>{const{createNotice:e,callback:t}=this.props;if("function"==typeof t)return new Promise((o,s)=>{this.setState({disabled:!0}),t(o,s,e)}).then(()=>{this.setState({disabled:!1})}).catch(()=>{this.setState({disabled:!1})})};renderCheckboxOptions(e){const{handleChange:t,name:o,value:s}=this.props,{disabled:a}=this.state;return e.map(e=>(0,u.jsx)(r.CheckboxControl,{label:e.label,name:o,checked:s&&s.includes(e.value),onChange:s=>t({target:{checked:s,name:o,type:"checkbox",value:e.value}}),disabled:a},o+"-"+e.value))}render(){const{helpText:e,label:t,name:o}=this.props;return(0,u.jsxs)("div",{className:"woocommerce-setting",children:[(0,u.jsx)("div",{className:"woocommerce-setting__label",id:o+"-label",children:t}),(0,u.jsxs)("div",{className:"woocommerce-setting__input",children:[this.renderInput(),e&&(0,u.jsx)("span",{className:"woocommerce-setting__help",children:e})]})]})}}const _=(0,i.compose)((0,c.withDispatch)(e=>{const{createNotice:t}=e("core/notices");return{createNotice:t}}))(h);var g=o(76154),w=o.n(g);const v=(e,t,o)=>{const s={};if(o&&(s.skip_existing=!0),"all"!==t.label)if("custom"===t.label){const o=w()().diff(w()(t.date,e),"days",!0);s.days=Math.floor(o)}else s.days=parseInt(t.label,10);return s};var b=o(93832);const f=(0,i.compose)([(0,c.withSelect)(e=>{const{getFormSettings:t}=e(l.importStore),{period:o,skipPrevious:s}=t();return{selectedPeriod:o,skipChecked:s}}),(0,c.withDispatch)(e=>{const{updateImportation:t,setImportStarted:o}=e(l.importStore),{createNotice:s}=e("core/notices");return{createNotice:s,setImportStarted:o,updateImportation:t}})])(function({clearStatusAndTotalsCache:e,createNotice:t,dateFormat:o,importDate:i,onImportStarted:c,selectedPeriod:n,stopImport:l,skipChecked:d,status:p,setImportStarted:h,updateImportation:_}){const g=(e,o,s=!1)=>{_(e,s).then(e=>{"success"===e.status?t("success",e.message):(t("error",o),h(!1),l())}).catch(e=>{e&&e.message&&(t("error",e.message),h(!1),l())})},w=()=>{const e=(0,b.addQueryArgs)("/wc-analytics/reports/import",v(o,n,d)),t=(0,s.__)("There was a problem rebuilding your report data.","woocommerce");g(e,t,!0),c()},f=()=>{l();const e=(0,s.__)("There was a problem stopping your current import.","woocommerce");g("/wc-analytics/reports/import/cancel",e)},y=()=>{const e=(0,s.__)("There was a problem deleting your previous data.","woocommerce");g("/wc-analytics/reports/import/delete",e),(0,m.recordEvent)("analytics_import_delete_previous"),h(!1)},S=()=>{h(!1),e()};return(0,u.jsx)("div",{className:"woocommerce-settings__actions woocommerce-settings-historical-data__actions",children:(()=>{const e="ready"!==p;return["initializing","customers","orders","finalizing"].includes(p)?(0,u.jsxs)(a.Fragment,{children:[(0,u.jsx)(r.Button,{className:"woocommerce-settings-historical-data__action-button",isPrimary:!0,onClick:f,children:(0,s.__)("Stop Import","woocommerce")}),(0,u.jsxs)("div",{className:"woocommerce-setting__help woocommerce-settings-historical-data__action-help",children:[(0,s.__)("Imported data will not be lost if the import is stopped.","woocommerce"),(0,u.jsx)("br",{}),(0,s.__)("Navigating away from this page will not affect the import.","woocommerce")]})]}):["ready","nothing"].includes(p)?i?(0,u.jsxs)(a.Fragment,{children:[(0,u.jsx)(r.Button,{isPrimary:!0,onClick:w,disabled:e,children:(0,s.__)("Start","woocommerce")}),(0,u.jsx)(r.Button,{isSecondary:!0,onClick:y,children:(0,s.__)("Delete Previously Imported Data","woocommerce")})]}):(0,u.jsx)(a.Fragment,{children:(0,u.jsx)(r.Button,{isPrimary:!0,onClick:w,disabled:e,children:(0,s.__)("Start","woocommerce")})}):("error"===p&&t("error",(0,s.__)("Something went wrong with the importation process.","woocommerce")),(0,u.jsxs)(a.Fragment,{children:[(0,u.jsx)(r.Button,{isSecondary:!0,onClick:S,children:(0,s.__)("Re-import Data","woocommerce")}),(0,u.jsx)(r.Button,{isSecondary:!0,onClick:y,children:(0,s.__)("Delete Previously Imported Data","woocommerce")})]}))})()})});var y=o(77374);const S=(0,c.withDispatch)(e=>{const{setImportPeriod:t}=e(l.importStore);return{setImportPeriod:t}})(function({dateFormat:e,disabled:t,setImportPeriod:o,value:a}){const i=t=>{const s=!0;t.date&&t.date.isValid?o(t.date.format(e),s):o(t.text,s)},c=t=>t.isValid()&&a.date.length===e.length?t.isAfter(new Date,"day")?y.dateValidationMessages.future:null:y.dateValidationMessages.invalid;return(0,u.jsxs)("div",{className:"woocommerce-settings-historical-data__columns",children:[(0,u.jsx)("div",{className:"woocommerce-settings-historical-data__column",children:(0,u.jsx)(r.SelectControl,{__next40pxDefaultSize:!0,label:(0,s.__)("Import historical data","woocommerce"),value:a.label,disabled:t,onChange:e=>{o(e)},options:[{label:"All",value:"all"},{label:"Last 365 days",value:"365"},{label:"Last 90 days",value:"90"},{label:"Last 30 days",value:"30"},{label:"Last 7 days",value:"7"},{label:"Last 24 hours",value:"1"},{label:"Custom",value:"custom"}]})}),"custom"===a.label&&(()=>{const o=w()(a.date,e);return(0,u.jsxs)("div",{className:"woocommerce-settings-historical-data__column",children:[(0,u.jsx)("div",{className:"woocommerce-settings-historical-data__column-label",children:(0,s.__)("Beginning on","woocommerce")}),(0,u.jsx)(n.DatePicker,{date:o.isValid()?o.toDate():null,dateFormat:e,disabled:t,error:c(o),isInvalidDate:e=>w()(e).isAfter(new Date,"day"),onUpdate:i,text:a.date})]})})()]})}),x=function({label:e,progress:t,total:o}){const r=(0,s.sprintf)((0,s.__)("Imported %(label)s","woocommerce"),{label:e}),a=(0,p.isNil)(o)?null:(0,s.sprintf)((0,s.__)("%(progress)s of %(total)s","woocommerce"),{progress:t||0,total:o});return(0,u.jsxs)("div",{className:"woocommerce-settings-historical-data__progress",children:[(0,u.jsx)("span",{className:"woocommerce-settings-historical-data__progress-label",children:r}),a&&(0,u.jsx)("span",{className:"woocommerce-settings-historical-data__progress-label",children:a}),(0,u.jsx)("progress",{className:"woocommerce-settings-historical-data__progress-bar",max:o,value:t||0})]})};var I=o(52619);const k=function({importDate:e,status:t}){const o=(0,I.applyFilters)("woocommerce_admin_import_status",{nothing:(0,s.__)("Nothing To Import","woocommerce"),ready:(0,s.__)("Ready To Import","woocommerce"),initializing:[(0,s.__)("Initializing","woocommerce"),(0,u.jsx)(r.Spinner,{},"spinner")],customers:[(0,s.__)("Importing Customers","woocommerce"),(0,u.jsx)(r.Spinner,{},"spinner")],orders:[(0,s.__)("Importing Orders","woocommerce"),(0,u.jsx)(r.Spinner,{},"spinner")],finalizing:[(0,s.__)("Finalizing","woocommerce"),(0,u.jsx)(r.Spinner,{},"spinner")],finished:-1===e?(0,s.__)("All historical data imported","woocommerce"):(0,s.sprintf)((0,s.__)("Historical data from %s onward imported","woocommerce"),w()(e).format("YYYY-MM-DD"))});return(0,u.jsxs)("span",{className:"woocommerce-settings-historical-data__status",children:[(0,s.__)("Status:","woocommerce")+" ",o[t]]})},C=(0,c.withDispatch)(e=>{const{setSkipPrevious:t}=e(l.importStore);return{setSkipPrevious:t}})(function({checked:e,disabled:t,setSkipPrevious:o}){return(0,u.jsx)(r.CheckboxControl,{className:"woocommerce-settings-historical-data__skip-checkbox",checked:e,disabled:t,label:(0,s.__)("Skip previously imported customers and orders","woocommerce"),onChange:e=>{o(e)}})});var j=o(1455),N=o.n(j),T=o(15703);const D=function(){const[e,t]=(0,a.useState)(null),[o,i]=(0,a.useState)(!1),{createNotice:n}=(0,c.useDispatch)("core/notices"),l=(0,a.useCallback)(async()=>{try{const e=await N()({path:"/wc-analytics/imports/status"});t(e)}catch(e){}},[]);(0,a.useEffect)(()=>{l()},[l]);const m=e?.failed_count??0,d=e?.failed_overflow_count??0;if(0===m)return null;const p=(0,u.jsx)("a",{href:(0,T.getAdminLink)("admin.php?page=wc-status&tab=logs&source=wc-analytics-order-import"),"aria-label":(0,s.__)("View the order import log","woocommerce")}),h=d>0?(0,s.__)('More than %d orders failed to import. To recover all missed orders, run the import above with "Skip previously imported customers and orders" checked. <link>View the log</link> for details.',"woocommerce"):(0,s._n)("%d order failed to import. <link>View the log</link> for details.","%d orders failed to import. <link>View the log</link> for details.",m,"woocommerce"),_=(0,a.createInterpolateElement)((0,s.sprintf)(h,m),{link:p});return(0,u.jsxs)(r.Notice,{className:"woocommerce-settings-historical-data__failed-orders",status:"warning",isDismissible:!1,children:[(0,u.jsx)("p",{children:_}),(0,u.jsx)(r.Button,{variant:"secondary",isBusy:o,disabled:o,"aria-disabled":o,onClick:async()=>{i(!0);try{const e=await N()({path:"/wc-analytics/imports/retry-failed",method:"POST"});n("success",e.message),await l()}catch(e){n("error",function(e,t){return"object"==typeof e&&null!==e&&"message"in e&&"string"==typeof e.message&&""!==e.message?e.message:t}(e,(0,s.__)("Failed to retry order imports.","woocommerce")))}finally{i(!1)}},children:(0,s.__)("Retry failed imports","woocommerce")})]})};class P extends a.Component{render(){const{customersProgress:e,customersTotal:t,dateFormat:o,importDate:r,inProgress:i,lastImportStartTimestamp:c,clearStatusAndTotalsCache:l,ordersProgress:m,ordersTotal:d,onImportStarted:p,period:h,stopImport:_,skipChecked:g,status:w}=this.props;return(0,u.jsxs)(a.Fragment,{children:[(0,u.jsx)(n.SectionHeader,{title:(0,s.__)("Import historical data","woocommerce")}),(0,u.jsx)("div",{className:"woocommerce-settings__wrapper",children:(0,u.jsx)("div",{className:"woocommerce-setting",children:(0,u.jsxs)("div",{className:"woocommerce-setting__input",children:[(0,u.jsx)("span",{className:"woocommerce-setting__help",children:(0,s.__)("This tool populates historical analytics data by processing customers and orders created prior to activating WooCommerce Admin.","woocommerce")}),"finished"!==w&&(0,u.jsxs)(a.Fragment,{children:[(0,u.jsx)(S,{dateFormat:o,disabled:i,value:h}),(0,u.jsx)(C,{disabled:i,checked:g}),(0,u.jsx)(x,{label:(0,s.__)("Registered Customers","woocommerce"),progress:e,total:t}),(0,u.jsx)(x,{label:(0,s.__)("Orders and Refunds","woocommerce"),progress:m,total:d})]}),(0,u.jsx)(k,{importDate:r,status:w}),(0,u.jsx)(D,{})]})})}),(0,u.jsx)(f,{clearStatusAndTotalsCache:l,dateFormat:o,importDate:r,lastImportStartTimestamp:c,onImportStarted:p,stopImport:_,status:w})]})}}const F=(0,c.withSelect)((e,t)=>{const{getImportError:o,getImportStatus:s,getImportTotals:r}=e(l.importStore),{activeImport:a,cacheNeedsClearing:i,dateFormat:c,inProgress:n,onImportStarted:m,onImportFinished:d,period:u,startStatusCheckInterval:h,skipChecked:_}=t,g=v(c,u,_),{customers:w,orders:b,lastImportStartTimestamp:f}=r(g),{customers:y,imported_from:S,is_importing:x,orders:I}=s(f),{imported:k,total:C}=y||{},{imported:j,total:N}=I||{},T=Boolean(o(f)||o(g));Boolean(!f&&!n&&!0===x)&&m();const D=Boolean(n&&!i&&!1===x&&(C>0||N>0)&&k===C&&j===N);let P={customersTotal:w,isError:T,ordersTotal:b};a&&(P={cacheNeedsClearing:i,customersProgress:k,customersTotal:(0,p.isNil)(C)?w:C,inProgress:n,isError:T,ordersProgress:j,ordersTotal:(0,p.isNil)(N)?b:N});const F=(({cacheNeedsClearing:e,customersProgress:t,customersTotal:o,isError:s,inProgress:r,ordersProgress:a,ordersTotal:i})=>s?"error":r?(0,p.isNil)(t)||(0,p.isNil)(a)||(0,p.isNil)(o)||(0,p.isNil)(i)||e?"initializing":t<o?"customers":a<i?"orders":"finalizing":o>0||i>0?t===o&&a===i?"finished":"ready":"nothing")(P);return"initializing"===F&&h(),D&&d(),{...P,importDate:S,status:F}})(P);class A extends a.Component{constructor(){super(...arguments),this.dateFormat=(0,s.__)("MM/DD/YYYY","woocommerce"),this.intervalId=-1,this.lastImportStopTimestamp=0,this.cacheNeedsClearing=!0,this.onImportFinished=this.onImportFinished.bind(this),this.onImportStarted=this.onImportStarted.bind(this),this.clearStatusAndTotalsCache=this.clearStatusAndTotalsCache.bind(this),this.stopImport=this.stopImport.bind(this),this.startStatusCheckInterval=this.startStatusCheckInterval.bind(this),this.cancelStatusCheckInterval=this.cancelStatusCheckInterval.bind(this)}startStatusCheckInterval(){this.intervalId<0&&(this.cacheNeedsClearing=!0,this.intervalId=setInterval(()=>{this.clearCache("getImportStatus")},3*l.SECOND))}cancelStatusCheckInterval(){clearInterval(this.intervalId),this.intervalId=-1}clearCache(e,t){const{invalidateResolution:o,lastImportStartTimestamp:s}=this.props;o(e,["getImportStatus"===e?s:t]).then(()=>{this.cacheNeedsClearing=!1})}stopImport(){this.cancelStatusCheckInterval(),this.lastImportStopTimestamp=Date.now()}onImportFinished(){const{debouncedSpeak:e}=this.props;this.cacheNeedsClearing||(e("Import complete"),this.stopImport())}onImportStarted(){const{notes:e,setImportStarted:t,updateNote:o}=this.props,s=e.find(e=>"wc-admin-historical-data"===e.name);s&&o(s.id,{status:"actioned"}),t(!0)}clearStatusAndTotalsCache(){const{selectedPeriod:e,skipChecked:t}=this.props,o=v(this.dateFormat,e,t);this.clearCache("getImportTotals",o),this.clearCache("getImportStatus")}isImportationInProgress(){const{lastImportStartTimestamp:e}=this.props;return void 0!==e&&void 0===this.lastImportStopTimestamp||e>this.lastImportStopTimestamp}render(){const{activeImport:e,createNotice:t,lastImportStartTimestamp:o,selectedPeriod:s,skipChecked:r}=this.props;return(0,u.jsx)(F,{activeImport:e,cacheNeedsClearing:this.cacheNeedsClearing,createNotice:t,dateFormat:this.dateFormat,inProgress:this.isImportationInProgress(),onImportFinished:this.onImportFinished,onImportStarted:this.onImportStarted,lastImportStartTimestamp:o,clearStatusAndTotalsCache:this.clearStatusAndTotalsCache,period:s,skipChecked:r,startStatusCheckInterval:this.startStatusCheckInterval,stopImport:this.stopImport})}}const E=(0,i.compose)([(0,c.withSelect)(e=>{const{getNotes:t}=e(l.notesStore),{getImportStarted:o,getFormSettings:s}=e(l.importStore),r=t({page:1,per_page:l.QUERY_DEFAULTS.pageSize,type:"update",status:"unactioned"}),{activeImport:a,lastImportStartTimestamp:i}=o(),{period:c,skipPrevious:n}=s();return{activeImport:a,lastImportStartTimestamp:i,notes:r,selectedPeriod:c,skipChecked:n}}),(0,c.withDispatch)(e=>{const{updateNote:t}=e(l.notesStore),{invalidateResolution:o,setImportStarted:s}=e(l.importStore);return{invalidateResolution:o,setImportStarted:s,updateNote:t}}),r.withSpokenMessages])(A),O=({isOpen:e,onClose:t,onConfirm:o})=>e?(0,u.jsx)(r.Modal,{title:(0,s.__)("Are you sure?","woocommerce"),onRequestClose:t,className:"woocommerce-analytics-import-mode-confirmation-modal",size:"medium",children:(0,u.jsxs)(r.Flex,{direction:"column",gap:6,children:[(0,u.jsx)(r.__experimentalText,{children:(0,s.__)("Immediate updates to Analytics can impact your performance as it may slow busy stores.","woocommerce")}),(0,u.jsxs)(r.Flex,{direction:"row",className:"woocommerce-analytics-import-mode-confirmation-modal__buttons",justify:"flex-end",children:[(0,u.jsx)(r.Button,{variant:"tertiary",onClick:t,"aria-label":(0,s.__)("Cancel import mode change","woocommerce"),children:(0,s.__)("Cancel","woocommerce")}),(0,u.jsx)(r.Button,{variant:"primary",onClick:o,"aria-label":(0,s.__)("Confirm switching to immediate import mode","woocommerce"),children:(0,s.__)("Confirm","woocommerce")})]})]})}):null,R=(0,i.compose)((0,c.withDispatch)(e=>{const{createNotice:t}=e("core/notices");return{createNotice:t}}))(({createNotice:e,query:t})=>{const{settingsError:o,isRequesting:i,isDirty:c,persistSettings:p,updateAndPersistSettings:h,updateSettings:g,wcAdminSettings:w}=(0,l.useSettings)("wc_admin",["wcAdminSettings"]),v=(0,a.useRef)(!1),[b,f]=(0,a.useState)(!1),[y,S]=(0,a.useState)(null);(0,a.useEffect)(()=>{function e(e){if(c)return e.returnValue=(0,s.__)("You have unsaved changes. If you proceed, they will be lost.","woocommerce"),e.returnValue}return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[c]),(0,a.useEffect)(()=>{i?v.current=!0:!i&&v.current&&(o?e("error",(0,s.__)("There was an error saving your settings. Please try again.","woocommerce")):e("success",(0,s.__)("Your settings have been successfully saved.","woocommerce")),v.current=!1)},[i,o,e]);const x=e=>{if(b)return;const{checked:t,name:o,type:s,value:r}=e.target;if(o===d.zm&&d.$W[d.zm]&&"yes"===w[o]&&"no"===r)return S({name:o,value:r}),void f(!0);const a={...w};a[o]="checkbox"===s?t?[...a[o],r]:a[o].filter(e=>e!==r):r,g("wcAdminSettings",a)},I=e=>e!==d.zm||w[e]?w[e]:"no";return(0,u.jsxs)(a.Fragment,{children:[(0,u.jsx)(n.SectionHeader,{title:(0,s.__)("Analytics settings","woocommerce")}),(0,u.jsxs)("div",{className:"woocommerce-settings__wrapper",children:[Object.keys(d.$W).map(e=>(0,u.jsx)(_,{handleChange:x,value:I(e),name:e,...d.$W[e]},e)),(0,u.jsxs)("div",{className:"woocommerce-settings__actions",children:[(0,u.jsx)(r.Button,{variant:"secondary",onClick:()=>{if(window.confirm((0,s.__)("Are you sure you want to reset all settings to default values?","woocommerce"))){const e=Object.keys(d.$W).reduce((e,t)=>(e[t]=d.$W[t].defaultValue,e),{});h("wcAdminSettings",e),(0,m.recordEvent)("analytics_settings_reset_defaults")}},children:(0,s.__)("Reset defaults","woocommerce")}),(0,u.jsx)(r.Button,{variant:"primary",isBusy:i,onClick:()=>{p(),(0,m.recordEvent)("analytics_settings_save",w),t.period=void 0,t.compare=void 0,t.before=void 0,t.after=void 0,t.interval=void 0,t.type=void 0,window.wpNavMenuUrlUpdate(t)},children:(0,s.__)("Save settings","woocommerce")})]})]}),"true"===t.import?(0,u.jsx)(n.ScrollTo,{offset:"-56",children:(0,u.jsx)(E,{createNotice:e})}):(0,u.jsx)(E,{createNotice:e}),d.$W[d.zm]&&(0,u.jsx)(O,{isOpen:b,onClose:()=>{f(!1),S(null)},onConfirm:()=>{if(y){const e={...w};e[y.name]=y.value,g("wcAdminSettings",e)}f(!1),S(null)}})]})})}}]);