"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),p=require("@argent/x-shared"),$=require("@argent/x-shared/swap"),R=require("../icons/FilterSecondaryIcon.cjs"),u=require("@chakra-ui/react"),x=require("react"),E=require("react-i18next"),j=require("../../components/CompoundInputDeprecated/index.cjs"),D=require("./SwapDetails.cjs"),U=require("./SwapSwitchDirectionButton.cjs"),O=require("./types.cjs"),h=require("../../components/CompoundDialogBottomSheet/index.cjs"),T=require("../../components/CompoundInput/index.cjs"),_=require("../../components/typography.generated.cjs");function V({assetSelect:a,slippage:r,pay:m,receive:y,onSwitchTokens:A,error:S,isDisabled:q,showDetails:N,trade:e,isLoadingTrade:l,submitButton:w={show:!0,type:"submit"}}){var k;const{t:o}=E.useTranslation(),v=((k=r.options)==null?void 0:k.multiplier)||100,{isOpen:F,onOpen:C,onClose:g}=u.useDisclosure(),{isOpen:P,onOpen:I,onClose:f}=u.useDisclosure(),[B,s]=x.useMemo(function(){if(e){const t=p.bigDecimal.formatUnits({value:BigInt(e.payAmount),decimals:e.payToken.decimals??18}),i=p.bigDecimal.formatUnits({value:BigInt(e.receiveAmount),decimals:e.receiveToken.decimals??18}),d=p.prettifyCurrencyNumber(Number(i)/Number(t));let c=!!(e.payAmountInCurrency&&e.receiveAmountInCurrency&&Number(e.payAmountInCurrency)!==0&&Number(e.receiveAmountInCurrency)!==0)?(Number(e.payAmountInCurrency)-Number(e.receiveAmountInCurrency))/Number(e.receiveAmountInCurrency)*100:null;return c=c===null||c===0?c:c*-1,[d,c]}return[null,null]},[e]),b=x.useMemo(function(){var t;if(e){const{value:i,decimals:d}=$.minimumAmountOutFromTrade(e,r.value);return p.prettifyTokenAmount({amount:i,decimals:d,symbol:(t=e.receiveToken)==null?void 0:t.symbol})}},[e,r]),M=x.useMemo(function(){if(e){const t=[{property:o("swap.swapFee"),value:`${e.totalFeePercentage*100}%`},{property:o("swap.minReceivedInclFees"),value:`${b}`},{property:o("swap.maxSlippage"),value:(r.value/v).toString(),buttonProps:{icon:n.jsx(R,{}),"aria-label":"some label",onClick:I},alert:r.value/v>1?o("swap.yourTransactionMayBeFrontrunAndResultInAnUnfavorableTrade"):""},{property:o("swap.providers"),value:e.route.name}];return s?t.push({property:o("swap.priceImpact"),value:`${p.prettifyNumber(s)}%`,alert:s&&s<-1?o("swap.yourTradeWillHaveASignificantImpactOnThePrice"):""}):e&&s===null&&t.push({property:o("swap.priceImpact"),value:"",alert:o("swap.noPriceFoundCannotDeterminePriceImpact")}),t}return[]},[e,b,r.value,v,I,s,o]);return n.jsxs(n.Fragment,{children:[n.jsx(h.CompoundDialogBottomSheet,{isOpen:F,onClose:()=>g(),bottomSheetProps:{expandOnContentDrag:!0,snapPoints:({maxHeight:t})=>[t-(a.bottomSheetTopMargin??80)/2]},children:n.jsx(h.CompoundDialogBottomSheet.SelectAsset,{loading:a.loading,tokens:a.tokens,onSelect:t=>{a.onSelect(t),g()}})}),n.jsx(h.CompoundDialogBottomSheet,{isOpen:P,onClose:()=>f(),bottomSheetProps:{expandOnContentDrag:!0},children:n.jsx(h.CompoundDialogBottomSheet.SlippageInput,{onSave:t=>{r.onSave(t),f()},value:r.value,options:r.options})}),n.jsxs(u.Flex,{direction:"column",gap:"4",children:[n.jsxs(u.Flex,{w:"full",direction:"column",gap:"1",children:[n.jsxs(u.Flex,{pos:"relative",children:[n.jsx(T.CompoundInput,{amount:m.amount,token:{...m.token,onClick:t=>{var i;(i=m.token)==null||i.onClick(t),C()}},isLoading:m.isLoading,children:n.jsx(j.CompoundInputDeprecated.Default,{title:o("swap.pay")})}),n.jsx(U.SwapSwitchDirectionButton,{onClick:A})]}),n.jsx(T.CompoundInput,{amount:y.amount,token:{...y.token,onClick:t=>{var i;(i=y.token)==null||i.onClick(t),C()}},isLoading:y.isLoading,children:n.jsx(j.CompoundInputDeprecated.Default,{title:o("swap.receive")})})]}),!e&&l&&n.jsxs(u.Flex,{bg:"surface-elevated",justifyContent:"space-between",alignItems:"center",p:"4",rounded:"lg",fontWeight:"500",children:[n.jsx(_.P3,{children:o("swap.findingTheBestRate")}),n.jsx(u.Spinner,{})]}),N&&e&&n.jsx(D.SwapDetails,{children:n.jsx(D.SwapDetails.Default,{header:{primary:{property:o("swap.bestPrice"),value:`1 ${e.payToken.symbol} = ${B} ${e.receiveToken.symbol}`},secondary:{property:o(l?"swap.updatingQuote":"swap.quoteUpToDate"),icon:l?n.jsx(u.Spinner,{w:"2",h:"2"}):void 0}},items:M})})]}),w.show&&n.jsx(u.Button,{type:w.type,onClick:w.onClick,colorScheme:!l&&S&&![O.SwapInputError.NO_TOKEN,O.SwapInputError.NO_AMOUNT].includes(S)?"danger":"primary",w:"full",isDisabled:q,children:o(l?"swap.loading":S||"swap.review")})]})}exports.Swap=V;
