import{w as f,o as V,m as A,f as r,g as s,h as n,O as x,Q as I,j as e,H as D,e as c,R as h,t as b,V as j,W as T,b as y,u as H,v as L}from"./index-zM9vIFRQ.js";import{r as l}from"./vendor-animations-CsoOZIH8.js";import{B as P}from"./BaseLayout-MetYKNt_.js";import{P as N,D as F}from"./DonationFooter-Cn40dmCz.js";import{B as E}from"./BrandingBackdrop-BgHUOUMf.js";import{T as R}from"./TextInput-BdBCNDVO.js";import{A as $}from"./AmountInput-nLONaWPj.js";import{R as C}from"./RadioInput-DO3S4Kkp.js";import{P as w,i as g,R as _,D as B}from"./inMemoryDonator-vni4T3Jw.js";import{D as S}from"./DonationPage-D8s3UKXA.js";import{F as k}from"./FormErrors-ZGNRI_YF.js";import"./useJivoExternalScript-yyZ--K1Q.js";import"./getSocialFormat-CDK45c1l.js";import"./pluralize-BqhPSiJS.js";import"./copyToClipboard-DRZ9ijAN.js";import"./inputmask-Cr-e3LsO.js";import"./TextInput-CBGy_Nu6.js";import"./DonationVoice-DrDo2_CY.js";import"./getVotesFormat-CTrf3mHq.js";const m="send-i-have-to-donation-form";class M extends l.Component{constructor(t){super(t),this.page=new S,this.isLoading=!1,this.isRejected=!1,this.name="",this.amount="",this.voteId="",this.paymentId=w.Russia,this.errors=new k,A(this,{isLoading:r,name:r,amount:r,voteId:r,isRejected:r,minAmount:s,maxAmount:s,isValid:s,amountValue:s,isValidAmount:s,selectedVariant:s,setName:n.bound,setLoading:n.bound,setAmount:n.bound,setVoteId:n.bound,setRejected:n.bound,onVote:n.bound,onAmountBlur:n.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 x}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}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:a})=>{this.navigateToPay(a)})}navigateToPay(t){window.location.href=t}render(){const{t}=this.props,a=this.page.login?`Донат "${this.page.login} должен" | iHAQDonate`:"Супер-донаты | iHAQDonate",i=this.page.login?`Отправить донат "Я должен" Ð´Ð»Ñ Ñтримера ${this.page.login} на iHAQDonate`:'Отправить Ñупер-донат "Я должен" Ñтримеру на iHAQDonate';return e.jsxs("div",{className:`${m}__wrapper`,children:[e.jsxs(D,{children:[e.jsx("title",{children:a}),e.jsx("meta",{name:"description",content:i}),e.jsx("meta",{property:"og:title",content:a}),e.jsx("meta",{property:"og:description",content:i}),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:m,children:[e.jsx(c,{value:t("sendIHaveToDonation:title"),size:"xl"}),e.jsx(N,{isLoading:this.page.isLoading,isPro:this.page.isPro,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}),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.props.navigate("/404",{replace:!0});return}this.page.setFromApi(t.data),t.data.viewer.login&&h(()=>this.name=t.data.viewer.login);let a=100;if(t.data.iHaveTo.votePrice){const i=Number(t.data.iHaveTo.votePrice);i>100&&(a=i)}h(()=>this.amount=String(a))}).catch(t=>{b(t)&&this.props.navigate("/404",{replace:!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:`${m}__form`,children:[e.jsx(R,{maxlength:j,type:"text",name:"name",value:this.name,title:t("sendDonation:donation:name:title"),placeholder:t("sendDonation:donation:name:placeholder"),onChange:this.setName}),e.jsx($,{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,a=t("sendIHaveToDonation:collected","Собрано"),i=[{id:"firstVariant",title:`${this.page.firstVariant} (${a} ${this.page.firstVariantCollectedVotesFormatted})`,description:this.page.firstVariantDescription},{id:"secondVariant",title:`${this.page.secondVariant} (${a} ${this.page.secondVariantCollectedVotesFormatted})`,description:this.page.secondVariantDescription}];return e.jsxs("div",{className:`${m}__poll`,children:[e.jsx(c,{value:t("sendIHaveToDonation:question"),size:"m"}),e.jsx(C,{allVariants:i,onChangeVariant:this.setVoteId,currentVariant:this.voteId})]})}renderFromDonate(){return this.props,null}renderFooter(){const{t}=this.props,a=t("sendIHaveToDonation:vote");return e.jsx(F,{buttonText:a,isDisabled:!this.isValid,isLoading:this.isLoading,onClick:this.onVote})}}const O=f()(V(M)),mt=()=>{const{store:u}=l.useContext(y),t=H(),a=L();return l.useEffect(()=>{let i=a.pageId||"";i.startsWith("@")&&(i=i.substring(1));const v=`https://ihaqdonate.com/d/2/${i}`;let o=document.querySelector("link[rel='canonical']"),p=!1,d=null;return o?d=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&&d!==null?o.setAttribute("href",d):o&&o.removeAttribute("href")}},[a.pageId]),e.jsx(P,{children:e.jsx(O,{store:u,navigate:t,pageId:a.pageId||""})})};export{mt as HaveToDonatePage};