import{r as a,j as e,B as d}from"./main-pzSpmpV2.js";import{S as j}from"./setting-layout-D6T6m4Pd.js";import{C,a as D,b,d as k,c as N}from"./card-DyOnRGQP.js";import{A as S,C as v,a as w}from"./alert-B_Eu6yIO.js";import{S as m}from"./spinner-BwGdrg0I.js";import{D as P}from"./delete-dialog-DT_Wug03.js";import{L as R}from"./loader-2-fAceJRLq.js";import{X as A}from"./x-circle-onIZFz9u.js";import"./separator-C1IUkfHl.js";import"./dialog-CwPbkvSr.js";function J(){const[s,i]=a.useState({type:null,message:""}),[t,p]=a.useState(null),[g,n]=a.useState(!1),[r,y]=a.useState(null),[f,x]=a.useState(!1);async function h(l){x(!0),i({type:"loading",message:"Deleting data..."}),p(l);try{const o=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:l})})).json();if(!o.success)throw new Error(o.message||"Failed to reset");i({type:"success",message:o.message||"Data deleted successfully!"})}catch(u){console.error(u),i({type:"error",message:"Failed to reset data. Please try again."})}finally{x(!1),n(!1),p(null)}}const c=l=>{y(l),n(!0)};return e.jsx(j,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsx(P,{isOpen:g,isDeleting:f,itemType:"Click Data",itemName:r==="all"?"All Click Records":r==="90days"?"Click Records 90 Days":"Click Records 30 Days",onClose:()=>n(!1),onDelete:()=>r&&h(r)}),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."}),s.type&&e.jsx(S,{className:`mb-4 ${s.type==="success"?"border-green-500 bg-green-50":s.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:[s.type==="loading"&&e.jsx(R,{className:"h-4 w-4 animate-spin text-blue-600"}),s.type==="success"&&e.jsx(v,{className:"h-4 w-4 text-green-600"}),s.type==="error"&&e.jsx(A,{className:"h-4 w-4 text-red-600"}),e.jsx(w,{className:s.type==="success"?"text-green-800":s.type==="error"?"text-red-800":"text-blue-800",children:s.message})]})}),e.jsxs(C,{children:[e.jsxs(D,{children:[e.jsx(b,{children:"Delete Click Data"}),e.jsx(k,{children:"Choose a time range to remove old tracking data."})]}),e.jsxs(N,{className:"flex flex-wrap gap-3",children:[e.jsx(d,{onClick:()=>c("30days"),disabled:!!t,variant:"destructive",children:t==="30days"?e.jsx(m,{}):"Delete Clicks Older than 30 Days"}),e.jsx(d,{onClick:()=>c("90days"),disabled:!!t,variant:"destructive",children:t==="90days"?e.jsx(m,{}):"Delete Clicks Older than 90 Days"}),e.jsx(d,{onClick:()=>c("all"),disabled:!!t,variant:"destructive",children:t==="all"?e.jsx(m,{}):"Delete All Clicks Data"})]})]})]})})}export{J as default};
//# sourceMappingURL=reset-data-uj_rnaG0.js.map
