import{w as f,o as V,m as x,f as n,g as r,h as s,V as A,W as I,j as e,t as D,H as b,e as c,X as h,x as j,Y as N,Z as T,b as F,i as y,y as L}from"./index-CyFlkMEw.js";import{r as u}from"./vendor-animations-CsoOZIH8.js";import{B as H}from"./BaseLayout-DrT4hx3s.js";import{P,D as k}from"./DonationFooter-QuQsxBNa.js";import{B as E}from"./BrandingBackdrop-B1H1MdJE.js";import{T as $}from"./TextInput-CEEFZF3W.js";import{A as R}from"./AmountInput-e6IYV6PV.js";import{R as w}from"./RadioInput-BH1_O30k.js";import{P as C,i as g,R as _,D as B}from"./inMemoryDonator-Cg_6sgi6.js";import{D as S}from"./DonationPage-CBwvQmSQ.js";import{F as M}from"./FormErrors-P1fhIM8A.js";import"./useJivoExternalScript-yyZ--K1Q.js";import"./getSocialFormat-sNKDLQQA.js";import"./pluralize-BqhPSiJS.js";import"./copyToClipboard-DmUeNVa1.js";import"./inputmask-Cr-e3LsO.js";import"./TextInput-yFeM-_iX.js";import"./DonationVoice-ECcRX9sJ.js";import"./getVotesFormat-CTrf3mHq.js";const d="send-i-have-to-donation-form";class O extends u.Component{constructor(t){super(t),this.page=new S,this.isLoading=!1,this.isRejected=!1,this.isNotFound=!1,this.name="",this.amount="",this.voteId="",this.paymentId=C.Russia,this.errors=new M,x(this,{isLoading:n,name:n,amount:n,voteId:n,isRejected:n,isNotFound:n,minAmount:r,maxAmount:r,isValid:r,amountValue:r,isValidAmount:r,selectedVariant:r,setName:s.bound,setLoading:s.bound,setAmount:s.bound,setVoteId:s.bound,setRejected:s.bound,setNotFound:s.bound,onVote:s.bound,onAmountBlur:s.bound}),this.initDonator(),this.fetchDonate()}get isValid(){return!!this.amount&&this.isValidAmount&&!!this.voteId&&!!this.paymentId&&!!this.name.trim()}get amountValue(){return Number(this.amount||0)}get isValidAmount(){return this.amountValue>=this.minAmount&&this.amountValue<=this.maxAmount}get minAmount(){return Math.max(50,Number(this.page.votePrice)||50)}get maxAmount(){return A}get selectedVariant(){return this.voteId?this.voteId==="firstVariant"?this.page.firstVariant:this.page.secondVariant:""}initDonator(){const t=g.get();t.name&&h(()=>this.name=t.name)}setLoading(t){this.isLoading=t}setRejected(t){this.isRejected=t}setNotFound(t){this.isNotFound=t}setName(t){this.name=t.target.value}setAmount(t){this.amount=t,this.isValidAmount&&this.errors.setError("amount","")}setVoteId(t){this.voteId=t}setPaymentId(t){}onAmountBlur(){if(!this.isValidAmount){if(this.amountValue<this.minAmount){this.errors.setError("amount",this.props.t("validation:minAmount",{amount:this.minAmount}));return}this.errors.setError("amount",this.props.t("validation:maxAmount",{amount:this.maxAmount}))}}onVote(){if(!this.page.isAvailable){this.setRejected(!0);return}const t={amount:this.amount,donatorName:this.name,paymentId:this.paymentId,currency:"rub",pageId:this.props.pageId,selectedVariant:this.voteId,message:this.selectedVariant,anotherData:{},typeId:I.IHaveTo,isSafeEnabled:!1,isTTSEnable:!1};g.set({name:this.name}),this.props.store.createDonation(t).then(({paymentUrl:i})=>{this.navigateToPay(i)})}navigateToPay(t){window.location.href=t}render(){if(this.isNotFound)return e.jsx(D,{});const{t}=this.props,i=this.page.login?`Донат "${this.page.login} должен" | iHAQDonate`:"Супер-донаты | iHAQDonate",a=this.page.login?`Отправить донат "Я должен" Ð´Ð»Ñ Ñтримера ${this.page.login} на iHAQDonate`:'Отправить Ñупер-донат "Я должен" Ñтримеру на iHAQDonate';return e.jsxs("div",{className:`${d}__wrapper`,children:[e.jsxs(b,{children:[e.jsx("title",{children:i}),e.jsx("meta",{name:"description",content:a}),e.jsx("meta",{property:"og:title",content:i}),e.jsx("meta",{property:"og:description",content:a}),this.page.avatar&&e.jsx("meta",{property:"og:image",content:this.page.avatar})]}),e.jsx(E,{branding:this.page.branding,isLoading:this.page.isLoading}),e.jsx("div",{children:e.jsxs("div",{className:d,children:[e.jsx(c,{value:t("sendIHaveToDonation:title"),size:"xl"}),e.jsx(P,{isLoading:this.page.isLoading,isPro:this.page.isPro,isVip:this.page.isVip,login:this.page.login,username:this.page.username,avatar:this.page.avatar,telegram:this.page.telegram,youtube:this.page.youtube,twitch:this.page.twitch,vk:this.page.vk,vkLive:this.page.vkLive,kick:this.page.kick}),this.renderForm(),this.renderPoll(),this.renderFromDonate(),this.renderFooter()]})}),e.jsx(_,{isVisible:this.isRejected,onClose:()=>this.setRejected(!1),page:this.page})]})}fetchDonate(){this.setLoading(!0),this.page.setLoading(!0),this.props.store.getDonationPage(this.props.pageId).then(t=>{if(!t.data.iHaveTo.firstVariant||!t.data.iHaveTo.secondVariant){this.setNotFound(!0);return}this.page.setFromApi(t.data),t.data.viewer.login&&h(()=>this.name=t.data.viewer.login);let i=100;if(t.data.iHaveTo.votePrice){const a=Number(t.data.iHaveTo.votePrice);a>100&&(i=a)}h(()=>this.amount=String(i))}).catch(t=>{j(t)&&this.setNotFound(!0)}).finally(()=>{this.setLoading(!1),this.page.setLoading(!1)})}renderForm(){if(this.isLoading)return e.jsx(B,{});const{t}=this.props;return e.jsxs("div",{className:`${d}__form`,children:[e.jsx($,{maxlength:N,type:"text",name:"name",value:this.name,title:t("sendDonation:donation:name:title"),placeholder:t("sendDonation:donation:name:placeholder"),onChange:this.setName}),e.jsx(R,{maxLength:6,value:this.amount,name:"amount",title:t("sendIHaveToDonation:amount:title"),placeholder:t("sendIHaveToDonation:amount:placeholder"),hintText:`${t("sendIHaveToDonation:amount:info")} ${T(Number(this.page.votePrice)||1,{rmSpacer:!0})}`,errorText:this.errors.getErrorBy("amount"),setValue:this.setAmount,onBlur:this.onAmountBlur})]})}renderPoll(){if(this.isLoading)return null;const{t}=this.props,i=t("sendIHaveToDonation:collected","Собрано"),a=[{id:"firstVariant",title:`${this.page.firstVariant} (${i} ${this.page.firstVariantCollectedVotesFormatted})`,description:this.page.firstVariantDescription},{id:"secondVariant",title:`${this.page.secondVariant} (${i} ${this.page.secondVariantCollectedVotesFormatted})`,description:this.page.secondVariantDescription}];return e.jsxs("div",{className:`${d}__poll`,children:[e.jsx(c,{value:t("sendIHaveToDonation:question"),size:"m"}),e.jsx(w,{allVariants:a,onChangeVariant:this.setVoteId,currentVariant:this.voteId})]})}renderFromDonate(){return this.props,null}renderFooter(){const{t}=this.props,i=t("sendIHaveToDonation:vote");return e.jsx(k,{buttonText:i,isDisabled:!this.isValid,isLoading:this.isLoading,onClick:this.onVote})}}const Q=f()(V(O)),mt=()=>{const{store:l}=u.useContext(F),t=y(),i=L();return u.useEffect(()=>{let a=i.pageId||"";a.startsWith("@")&&(a=a.substring(1));const v=`https://ihaqdonate.com/d/2/${a}`;let o=document.querySelector("link[rel='canonical']"),p=!1,m=null;return o?m=o.getAttribute("href"):(o=document.createElement("link"),o.setAttribute("rel","canonical"),document.head.appendChild(o),p=!0),o.setAttribute("href",v),()=>{p&&o?document.head.removeChild(o):o&&m!==null?o.setAttribute("href",m):o&&o.removeAttribute("href")}},[i.pageId]),e.jsx(H,{children:e.jsx(Q,{store:l,navigate:t,pageId:i.pageId||""})})};export{mt as HaveToDonatePage};