import{c as p,j as e,a as y,o as C,r,B as o}from"./main-C5rJoLCl.js";import{S as D}from"./setting-layout-HHrMlMhZ.js";import{C as k,a as b,b as N,d as S,c as w}from"./card-CQVKDPP8.js";import{L as P,S as m}from"./spinner-zDOxBldC.js";import{D as R}from"./delete-dialog-D6C7P-AV.js";import"./separator-CJhMgss0.js";import"./dialog-DoT6WXg8.js";/**
 * @license lucide-react v0.302.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const O=p("CheckCircle2",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/**
 * @license lucide-react v0.302.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const A=p("XCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]),L=C("relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",{variants:{variant:{default:"bg-card text-card-foreground",destructive:"text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"}},defaultVariants:{variant:"default"}});function z({className:t,variant:a,...s}){return e.jsx("div",{"data-slot":"alert",role:"alert",className:y(L({variant:a}),t),...s})}function T({className:t,...a}){return e.jsx("div",{"data-slot":"alert-description",className:y("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",t),...a})}function $(){const[t,a]=r.useState({type:null,message:""}),[s,g]=r.useState(null),[f,c]=r.useState(!1),[l,h]=r.useState(null),[j,u]=r.useState(!1);async function v(i){u(!0),a({type:"loading",message:"Deleting data..."}),g(i);try{const d=await(await fetch(`${linkfiliate==null?void 0:linkfiliate.pluginApiUrl}/reset-clicks`,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":linkfiliate==null?void 0:linkfiliate.nonce},body:JSON.stringify({period:i})})).json();if(!d.success)throw new Error(d.message||"Failed to reset");a({type:"success",message:d.message||"Data deleted successfully!"})}catch(x){console.error(x),a({type:"error",message:"Failed to reset data. Please try again."})}finally{u(!1),c(!1),g(null)}}const n=i=>{h(i),c(!0)};return e.jsx(D,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsx(R,{isOpen:f,isDeleting:j,itemType:"Click Data",itemName:l==="all"?"All Click Records":l==="90days"?"Click Records 90 Days":"Click Records 30 Days",onClose:()=>c(!1),onDelete:()=>l&&v(l)}),e.jsx("h2",{className:"text-lg font-semibold",children:"Reset Analytics Data"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Permanently delete click records for a specific time range."}),t.type&&e.jsx(z,{className:`mb-4 ${t.type==="success"?"border-green-500 bg-green-50":t.type==="error"?"border-red-500 bg-red-50":"border-blue-500 bg-blue-50"}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[t.type==="loading"&&e.jsx(P,{className:"h-4 w-4 animate-spin text-blue-600"}),t.type==="success"&&e.jsx(O,{className:"h-4 w-4 text-green-600"}),t.type==="error"&&e.jsx(A,{className:"h-4 w-4 text-red-600"}),e.jsx(T,{className:t.type==="success"?"text-green-800":t.type==="error"?"text-red-800":"text-blue-800",children:t.message})]})}),e.jsxs(k,{children:[e.jsxs(b,{children:[e.jsx(N,{children:"Delete Click Data"}),e.jsx(S,{children:"Choose a time range to remove old tracking data."})]}),e.jsxs(w,{className:"flex flex-wrap gap-3",children:[e.jsx(o,{onClick:()=>n("30days"),disabled:!!s,variant:"destructive",children:s==="30days"?e.jsx(m,{}):"Delete Clicks Older than 30 Days"}),e.jsx(o,{onClick:()=>n("90days"),disabled:!!s,variant:"destructive",children:s==="90days"?e.jsx(m,{}):"Delete Clicks Older than 90 Days"}),e.jsx(o,{onClick:()=>n("all"),disabled:!!s,variant:"destructive",children:s==="all"?e.jsx(m,{}):"Delete All Clicks Data"})]})]})]})})}export{$ as default};
//# sourceMappingURL=reset-data-2gcrVc20.js.map
