import{d as E,$ as D,a0 as $,F as V,a1 as S,c as t,a5 as j,G,o as H,u as O,I as g,L as b,b as k,M as s,N as r,P as x,e as n,a6 as Q,O as C,t as A,Q as F,a as W,a7 as Z,aa as z,h as u,i as J,a8 as K,a2 as X}from"./main-2rA8bEUg.js";const Y=["href"],ee={style:{display:"flex"}},te={class:"y-center"},ae={key:0,class:"mr-10"},oe=E({__name:"index",setup(re){const m=D(),N=$(),L=V(""),h=V(),p=V(!1),T=V(),B=()=>{var o;return(o=T.value)==null?void 0:o.click()},I=o=>{var d;const e=new FileReader,l=(d=o.target.files)==null?void 0:d[0];l&&(e.onload=f=>{var w;try{const c=(w=f.target)==null?void 0:w.result,v=z(c);a.amountList=v.amounts.join(`
`),a.addressList=v.addresses.join(`
`)}catch(c){u(c.message,"error")}},e.onerror=()=>{u(t.lang.fileReadError,"error")},e.readAsText(l))},a=S({tokenAddress:"",addressList:"",amountList:"",amount:0}),R=S({tokenAddress:[{required:!0,message:t.lang.requiredField},{validator:j}],addressList:[{required:!0,message:t.lang.requiredField}]}),M=()=>{if(p.value){if(!a.amountList)return u(t.lang.amountListRequired,"error"),!1;const e=a.addressList.split(`
`),l=a.amountList.split(`
`);if(e.length!==l.length)return u(t.lang.addressAmountNotMatch,"error"),!1;if(!l.every(f=>!isNaN(Number(f))))return u(t.lang.amountsMustBeNumber,"error"),!1}else if(!a.amount)return u(t.lang.amountHaveToBeBiggerThanZero,"error"),!1;return a.addressList.split(`
`).every(e=>X(e.trim()))?!0:(u(t.lang.addressFormatError,"error"),!1)},P=async()=>new Promise(o=>{h.value&&h.value.validate(e=>{o(e&&M())})}),U=async o=>{const e=new m.service.assets.Token(o);try{return await e.getName(),await e.getSymbol(),await e.getDecimals(),await e.getTotalSupply(),!0}catch{return!1}},q=async()=>{var o;if(await P())try{if(J(),await((o=m.provider)==null?void 0:o.checkRpcConnection())!==!0)return u(t.lang.rpcConnectionError,"error");if(!await U(a.tokenAddress))return u(t.lang.invalidTokenAddress,"error");const e=m.service,l=m.getFeeMap();if(await e.getBalance()<l.airdrop)return u(K(m.network,l.airdrop),"error");const d=p.value?a.amountList.split(`
`).reduce((_,i)=>_+Number(i),0):a.amount;if(await new m.service.assets.Token(a.tokenAddress).getBalance(N.address)<d)return u(t.lang.airdropBalanceError,"error");const c=a.addressList.split(`
`).map(_=>_.trim()),v=p.value?a.amountList.split(`
`).map(_=>Number(_)):Array(c.length).fill(a.amount),y=await e.airdrop({tokenAddress:a.tokenAddress,addresses:c,amounts:v});typeof y=="string"?(L.value=new m.service.models.Transaction(y).getUrl(),u(t.lang.success,"success")):(console.error(y),u(t.lang.failed,"error"))}catch(e){u(e.message,"error")}};return G(()=>{var o;return(o=m.network)==null?void 0:o.id},()=>{var o;a.tokenAddress&&((o=h.value)==null||o.validateField("tokenAddress"))}),H(()=>{const{setTitle:o}=O();o(t.lang.createNewAirdrop)}),(o,e)=>{const l=g("el-form-item"),d=g("el-col"),f=g("el-input"),w=g("el-input-number"),c=g("el-row"),v=g("el-switch"),y=g("el-button"),_=g("el-form");return k(),b(_,{rules:R,model:a,ref_key:"formRef",ref:h,"label-width":"auto","label-position":"top",style:{"max-width":"1400px",margin:"0 auto"}},{default:s(()=>[r(c,{gutter:20},{default:s(()=>[r(d,{lg:p.value?12:8,md:24},{default:s(()=>[r(l,{label:n(t).lang.blockchainNetwork+":"},{default:s(()=>[r(Q)]),_:1},8,["label"])]),_:1},8,["lg"]),r(d,{lg:p.value?12:8,md:24},{default:s(()=>[r(l,{label:n(t).lang.contractAddress+":",prop:"tokenAddress"},{default:s(()=>[r(f,{modelValue:a.tokenAddress,"onUpdate:modelValue":e[0]||(e[0]=i=>a.tokenAddress=i),placeholder:n(m).addressPlaceholder},null,8,["modelValue","placeholder"])]),_:1},8,["label"])]),_:1},8,["lg"]),p.value?x("",!0):(k(),b(d,{key:0,lg:8,md:24},{default:s(()=>[r(l,{label:n(t).lang.airDropAmount+":",prop:"amount"},{default:s(()=>[r(w,{"controls-position":"right",modelValue:a.amount,"onUpdate:modelValue":e[1]||(e[1]=i=>a.amount=i),min:0},null,8,["modelValue"])]),_:1},8,["label"])]),_:1}))]),_:1}),r(c,{gutter:20},{default:s(()=>[r(d,{lg:p.value?12:24,md:24},{default:s(()=>[r(l,{label:n(t).lang.addressList+":"},{default:s(()=>[r(f,{rows:2,type:"textarea",class:"list-textarea",modelValue:a.addressList,"onUpdate:modelValue":e[2]||(e[2]=i=>a.addressList=i),placeholder:n(t).lang.oneLinePerAddress},null,8,["modelValue","placeholder"])]),_:1},8,["label"])]),_:1},8,["lg"]),p.value?(k(),b(d,{key:0,lg:12,md:24},{default:s(()=>[r(l,{label:n(t).lang.amountList+":"},{default:s(()=>[r(f,{rows:2,type:"textarea",class:"list-textarea",modelValue:a.amountList,"onUpdate:modelValue":e[3]||(e[3]=i=>a.amountList=i),placeholder:n(t).lang.oneLinePerAmount},null,8,["modelValue","placeholder"])]),_:1},8,["label"])]),_:1})):x("",!0)]),_:1}),L.value?(k(),b(c,{key:0,gutter:20},{default:s(()=>[r(d,{span:24},{default:s(()=>[r(l,{label:n(t).lang.transactionLink+":"},{default:s(()=>[C("a",{href:L.value,target:"_blank",class:"custom-a-color"},A(L.value),9,Y)]),_:1},8,["label"])]),_:1})]),_:1})):x("",!0),r(c,{gutter:20},{default:s(()=>[r(d,{span:24,class:"form-footer"},{default:s(()=>[C("div",ee,[r(v,{class:"mb-2",modelValue:p.value,"onUpdate:modelValue":e[4]||(e[4]=i=>p.value=i),"active-text":n(t).lang.amountForPerAddress,"inactive-text":n(t).lang.equalAmountForAll},null,8,["modelValue","active-text","inactive-text"]),C("input",{type:"file",ref_key:"fileInput",ref:T,accept:".csv",onChange:e[5]||(e[5]=i=>I(i)),hidden:""},null,544),r(y,{type:"primary",onClick:B,style:{"margin-left":"10px"}},{default:s(()=>[F(A(n(t).lang.uploadCsv),1)]),_:1})]),C("div",te,[n(N).isConnected?(k(),W("span",ae,A(n(m).getFeeStr("airdrop")),1)):x("",!0),n(N).isConnected?(k(),b(y,{key:1,type:"primary",onClick:e[6]||(e[6]=i=>q())},{default:s(()=>[F(A(n(t).lang.crateAirdrop),1)]),_:1})):(k(),b(Z,{key:2}))])]),_:1})]),_:1}),r(c,{gutter:20,style:{"margin-top":"20px"}},{default:s(()=>[r(d,{span:24},{default:s(()=>[F(A(n(t).lang.testedUpTo1000Address),1)]),_:1})]),_:1})]),_:1},8,["rules","model"])}}});export{oe as default};
