import{o as f,r as p,b as x,j as e,M as y,n as o,aw as j,i as v,ax as k}from"./index-7c7a558c.js";import{G as _}from"./Group-801c960a.js";function C({refetchFn:l}){const[m,{open:h,close:c}]=f(!1),[t,r]=p.useState({withdraw_amount:"",withdraw_method:"",withdraw_description:""}),{mutate:n,isLoading:s}=x(j,{onSuccess:a=>{var i,d;(i=a==null?void 0:a.data)!=null&&i.success&&o.success((d=a==null?void 0:a.data)==null?void 0:d.success),r({withdraw_amount:"",withdraw_method:"",withdraw_description:""}),c(),l()},onError:a=>{var i,d,g,w;(d=(i=a==null?void 0:a.response)==null?void 0:i.data)!=null&&d.error?o.error((w=(g=a==null?void 0:a.response)==null?void 0:g.data)==null?void 0:w.error):o.error("something went wrong!")}}),u=()=>t.withdraw_amount?t.withdraw_method?t.withdraw_description?!1:(o.error("Withdrawal description is required"),!0):(o.error("Payment method is required"),!0):(o.error("Amount is required"),!0),b=async a=>{a.preventDefault(),u()==!1&&!s&&n({formdata:t})};return e.jsxs(e.Fragment,{children:[e.jsx(y,{opened:m,onClose:c,title:"Withdraw Request",centered:!0,classNames:{content:"bg-gray-900 text-white",header:"bg-gray-900 text-white"},children:e.jsx("div",{className:"px-6 py-6 lg:px-8",children:e.jsxs("form",{className:"space-y-6",onSubmit:b,children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"amount",className:"block mb-2 text-sm font-medium text-gray-900",children:"Withdrawal Amount"}),e.jsx("input",{type:"text",name:"amount",id:"amount",defaultValue:t.withdraw_amount,onChange:a=>r({...t,withdraw_amount:a.target.value}),className:"bg-gray-50 dark:bg-gray-800 text-black dark:text-white border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 ",placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"withdraw_method",className:"block mb-2 text-sm font-medium text-gray-900",children:"Withdrawal Method"}),e.jsxs("select",{name:"withdraw_method",id:"withdraw_method",defaultValue:t.withdraw_method,onChange:a=>r({...t,withdraw_method:a.target.value}),className:"bg-gray-50 dark:bg-gray-800 text-black dark:text-white border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 ",children:[e.jsx("option",{value:"",children:"Select a payment method"}),e.jsx("option",{value:"bkash",children:"Bkash"}),e.jsx("option",{value:"rocket",children:"Rocket"}),e.jsx("option",{value:"upay",children:"Upay"}),e.jsx("option",{value:"nagad",children:"Nagad"}),e.jsx("option",{value:"google pay",children:"Google Pay"}),e.jsx("option",{value:"PhonePe",children:"PhonePe"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"withdraw_description",className:"block mb-2 text-sm font-medium text-gray-900",children:"Withdrawal Description"}),e.jsx("textarea",{name:"withdraw_description",id:"withdraw_description",defaultValue:t.withdraw_description,onChange:a=>r({...t,withdraw_description:a.target.value}),className:"bg-gray-50 dark:bg-gray-800 text-black dark:text-white border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 ",placeholder:"Phone Details, Trx Id"})]}),e.jsx("button",{type:"submit",className:"w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center",children:s?"Sending...":"Send Request"})]})})}),e.jsx(_,{position:"center",children:e.jsx("button",{onClick:h,className:"block text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center",children:"Withdraw Now"})})]})}function P(){const{isLoading:l,mutate:m}=x(k,{onSuccess:t=>{var r;(r=t==null?void 0:t.data)!=null&&r.success&&o.success("Successful! You can now withdrawal your amount!")},onError:t=>{var r,n,s,u;(n=(r=t==null?void 0:t.response)==null?void 0:r.data)!=null&&n.error?o.error((u=(s=t==null?void 0:t.response)==null?void 0:s.data)==null?void 0:u.error):o.error("something went wrong. Please try again")}});function h(){const t=new Date().getTime(),r=Math.random().toString(36).substr(2,10);return`${t}_${r}`}const c=t=>{t.preventDefault(),l||(o.dismiss(),m({formdata:{_token:h(),permission:"allowed"}}))};return e.jsx("div",{children:e.jsx("div",{className:"",children:e.jsxs("h4",{className:"flex gap-2 items-center",children:[e.jsx("span",{children:"Permit to cut 500/- from your balance: "}),e.jsx("button",{className:"flex gap-2 bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500 hover:from-indigo-500 hover:from-10% hover:via-sky-500 hover:via-30% hover:to-emerald-500 hover:to-90% hover:bg-gradient-to-l text-white p-2 rounded-lg px-6 my-6",onClick:c,children:l?e.jsx(v,{color:"dark",size:"lg",variant:"dots"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"Allow"}),e.jsx("span",{})]})})]})})})}export{P as A,C as W};
