1import{r as x,b as ee,g as ge,u as Te,d as W,j as e,a as O,B as S,t as B,q as X}from"./index-CudHG6B4.js";import{u as ve}from"./useMutation-CBAYgnG2.js";import{C as re,b as we,c as je,a as oe}from"./card-5b9UOcPu.js";import{A as Y,b as z}from"./alert-kp6gCZ70.js";import{R as le,a as _}from"./textarea-C9FUOvKW.js";import{L as A}from"./label-B2onvOiF.js";import{S as Se,e as Re,D as q,g as F,h as V,i as H,j as pe,k as J}from"./AuthenticatedApplication-C2-e6xTS.js";import{C as f,B as Ne,P as Ce,E as Ae}from"./BackingDashboard-CVY4Rsg2.js";import{V as Z}from"./V2Layout-CQnVHc2g.js";import{F as Ee}from"./index27-CKXESgRO.js";import{e as R}from"./encodeFunctionData-DwwM52WO.js";import{u as ke,S as Ie}from"./SetupGateAlert-DkpLHFoI.js";import{A as Le}from"./arrow-left-lxn-dpfG.js";import{C as ue}from"./circle-alert-CRUc3mQk.js";import{D as Pe}from"./dollar-sign-BcfyEtLy.js";import{B as Ue}from"./building-2-CMfa6c9V.js";import{C as Me}from"./calendar-BTBtzozc.js";import{C as de}from"./circle-x-BHDARfrW.js";import{C as De}from"./chevron-right-Dr8cwl4J.js";import{C as G}from"./circle-check-CTosiqnS.js";import{E as Oe}from"./shield-Hr0aqzVI.js";import{C as ce}from"./clock-DzjvzExH.js";import"./index-C1iJF-SR.js";import"./circle-C1ccQMbh.js";import"./InstitutionRegister-CdUSyHyq.js";import"./input-kx1YXBs7.js";import"./badge-CMf0SrHQ.js";import"./chevron-up-qSRaMRim.js";import"./check-D8BjNWtW.js";import"./shield-check-ic92rXB7.js";import"./users-DX1W4CCh.js";import"./connectors-BciFpN0c.js";import"./user-DCnI1kiW.js";import"./skeleton-BegiI0pz.js";import"./triangle-alert-BA2tGhup.js";import"./file-text-76AiIfll.js";import"./AboutPage-CamkJ7cK.js";import"./PrivacyPage-Beavwhs0.js";import"./TermsPage-SeBMfIpe.js";import"./LandVerifyPage-NEwI3vUf.js";import"./layers-Ca3pv70P.js";import"./award-BusU1ju6.js";import"./hash-DyzAXdJv.js";import"./globe-NLl4Wr5a.js";import"./scale-DM0tAT-O.js";import"./trending-up-C66B21n6.js";import"./landmark-BA_0Cnnl.js";import"./LandCertificate-Du_3NAH9.js";import"./printer-C2HCk7DD.js";import"./OnchainDocsPage-DDA6342p.js";import"./book-open-DvSukaGG.js";import"./code-CMLileHq.js";import"./sprout-z_rucUaP.js";import"./TransparencyPage-Ylxz21fu.js";import"./ProtocolPage-UaH8jgc9.js";import"./LandProtocolDevRef-_yp8P5Ot.js";import"./InstitutionInvitePage-CIc8kA4i.js";import"./FlowOfFundsPage-BjbpHgzo.js";import"./CapitalProviderChoice-C78InrEx.js";import"./arrow-right-B1UlrPw0.js";import"./IndividualProviderRegister-DyWPKEYx.js";import"./index.web86-C0UG8lPf.js";import"./useWalletAddress-9figVuHe.js";import"./useVerificationStatus-9MXaCCCd.js";function me(i,n="wei"){return Se(i,n)}const $=[{inputs:[],stateMutability:"nonpayable",type:"constructor"}
1,{inputs:[],name:"AccessControlBadConfirmation",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"},{internalType:"bytes32",name:"neededRole",type:"bytes32"}],name:"AccessControlUnauthorizedAccount",type:"error"},{inputs:[{internalType:"address",name:"target",type:"address"}],name:"AddressEmptyCode",type:"error"},{inputs:[{internalType:"address",name:"implementation",type:"address"}],name:"ERC1967InvalidImplementation",type:"error"},{inputs:[],name:"ERC1967NonPayable",type:"error"},{inputs:[],name:"EnforcedPause",type:"error"},{inputs:[],name:"ExpectedPause",type:"error"},{inputs:[],name:"FailedCall",type:"error"},{inputs:[],name:"InvalidInitialization",type:"error"},{inputs:[],name:"NotInitializing",type:"error"},{inputs:[],name:"ReentrancyGuardReentrantCall",type:"error"},{inputs:[],name:"UUPSUnauthorizedCallContext",type:"error"},{inputs:[{internalType:"bytes32",name:"slot",type:"bytes32"}],name:"UUPSUnsupportedProxiableUUID",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"newUserAllocationBPS",type:"uint256"},{indexed:!1,internalType:"uint256",name:"newTreasuryAllocationBPS",type:"uint256"}],name:"AllocationUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"uint256",name:"positionIndex",type:"uint256"}],name:"CollateralDeposited",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"admin",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!0,internalType:"address",name:"recipient",type:"address"}],name:"EmergencyWithdrawal",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint64",name:"version",type:"uint64"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"previousAdminRole",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"newAdminRole",type:"bytes32"}],name:"RoleAdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleGranted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleRevoked",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"treasury",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!1,internalType:"uint256",name:"usltAmount",type:"uint256"}],name:"TreasuryUSLTMinted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!1,internalType:"uint256",name:"usltAmount",type:"uint256"},{indexed:!1,internalType:"uint256",name:"netAmount",type:"uint256"}],name:"USLTMinted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"user",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"},{indexed:!1,internalType:"uint256",name:"usltAmount",type:"uint256"},{indexed:!1,internalType:"uint256",name:"landReturned",type:"uint256"}],name:"USLTRedeemed",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"implementation",type:"address"}],name:"Upgraded",type:"event"},{inputs:[],name:"ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DEFAULT_ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"TREASURY_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"UPGRADE_INTERFACE_VERSION",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"depositCollateral",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address",name:"recipient",type:"address"}],name:"emergencyWithdrawStuckTokens",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"getAvailableTreasuryMint",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"positionIndex",type:"uint256"}],name:"getAvailableUserMint",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSystemStatus",outputs:[{internalType:"uint256",name:"totalCollateralValue",type:"uint256"},{internalType:"uint256",name:"totalUSLTSupply",type:"uint256"},{internalType:"uint256",name:"availableToMint",type:"uint256"},{internalType:"bool",name:"goldenRuleSatisfied",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"getTotalSystemValue",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"positionIndex",type:"uint256"}],name:"getUserPosition",outputs:[{components:[{internalType:"uint256",name:"landTokenId",type:"uint256"},{internalType:"uint256",name:"landTokenAmount",type:"uint256"},{internalType:"uint256",name:"usltMinted",type:"uint256"}],internalType:"struct CollateralVaultUpgradeable.CollateralPosition",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"}],name:"getUserPositionCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"grantRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"hasRole",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"_landToken",type:"address"},{internalType:"address",name:"_uslt",type:"address"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"landToken",outputs:[{internalType:"contract LandTokenUpgradeable",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"positionIndex",type:"uint256"},{internalType:"uint256",name:"usltAmount",type:"uint256"}],name:"mintUSLT",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"},{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"bytes",name:"",type:"bytes"}],name:"onERC1155BatchReceived",outputs:[{internalType:"bytes4",name:"",type:"bytes4"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"bytes",name:"",type:"bytes"}],name:"onERC1155Received",outputs:[{internalType:"bytes4",name:"",type:"bytes4"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"uint256",name:"",type:"uint256"}],name:"positions",outputs:[{internalType:"uint256",name:"landTokenId",type:"uint256"},{internalType:"uint256",name:"landTokenAmount",type:"uint256"},{internalType:"uint256",name:"usltMinted",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"proxiableUUID",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"positionIndex",type:"uint256"},{internalType:"uint256",name:"usltAmount",type:"uint256"}],name:"redeemUSLT",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"callerConfirmation",type:"address"}],name:"renounceRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"revokeRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"_userAllocationBPS",type:"uint256"},{internalType:"uint256",name:"_treasuryAllocationBPS",type:"uint256"}],name:"setAllocation",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"",type:"uint256"}],name:"totalLandLocked",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"treasuryAllocationBPS",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"uint256",name:"usltAmount",type:"uint256"}],name:"treasuryMintUSLT",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"",type:"uint256"}],name:"treasuryUsltMinted",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newImplementation",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],name:"upgradeToAndCall",outputs:[],stateMutability:"payable",type:"function"},{inputs:[],name:"userAllocationBPS",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"uslt",outputs:[{internalType:"contract USLTUpgradeable",name:"",type:"address"}],stateMutability:"view",type:"function"}],ye=[{inputs:[{name:"spender",type:"address"},{name:"value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],Be=[{inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],name:"setApprovalForAll",outputs:[],stateMutability:"nonpayable",type:"function"}];async function N(i,n=60){for(let l=0;l<n;l++)try{const c=await(await fetch(Ne,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",method:"eth_getTransactionReceipt",params:[i],id:1})})).json();if(c.result)return parseInt(c.result.status,16)===1?{success:!0}:{success:!1,error:"Transaction reverted onchain"};await new Promise(r=>setTimeout(r,1e3))}catch{await new Promise(y=>setTimeout(y,1e3))}return{success:!1,error:"Transaction confirmation timeout"}}function _e(){const{evmAddress:i}=Re(),{sendEvmTransaction:n}
1=Ee(),[l,y]=x.useState(!1),[c,r]=x.useState(""),[T,w]=x.useState(null),[K,h]=x.useState(null),Q=x.useCallback(async(k,m,U)=>{if(!i||!n){const p="CDP wallet not connected";throw w(p),new Error(p)}y(!0),w(null),h(null),r("Preparing settlement...");try{const p=await ee("POST",`/api/v2/land/${k}/settlement-prepare`,{method:m,sourceLandId:U});if(!p.ok){const d=await p.json().catch(()=>({}));throw new Error(d.message||`Settlement preparation failed (${p.status})`)}const s=await p.json();if(!s||s.status!=="ready")throw new Error(s.reason||"Failed to prepare settlement");if(!s.canSettle)throw new Error(s.reason||"Settlement not possible");const b=me(s.outstandingUslt);let v,o,u,j;if(m==="RETURN_BALANCE"){r("Approving USLT for vault...");const d=R({abi:ye,functionName:"approve",args:[f.CollateralVault.address,b]});v=(await n({evmAccount:i,network:"base-sepolia",transaction:{to:f.USLT.address,data:d,gas:BigInt(1e5),chainId:84532,type:"eip1559"}})).transactionHash;const I=await N(v);if(!I.success)throw new Error(I.error||"USLT approval failed");r("Returning land-backed value...");const C=R({abi:$,functionName:"redeemUSLT",args:[BigInt(s.positionIndex),b]});o=(await n({evmAccount:i,network:"base-sepolia",transaction:{to:f.CollateralVault.address,data:C,gas:BigInt(5e5),chainId:84532,type:"eip1559"}})).transactionHash;const P=await N(o);if(!P.success)throw new Error(P.error||"Redemption failed onchain")}else if(m==="USE_OTHER_PROPERTY"){if(!s.sourceLand)throw new Error("Source property configuration not found");const{sourceLand:d}=s;if(d.needsDeposit){r("Approving SPV tokens from source property...");const xe=R({abi:Be,functionName:"setApprovalForAll",args:[f.CollateralVault.address,!0]}),he=await n({evmAccount:i,network:"base-sepolia",transaction:{to:f.LandToken.address,data:xe,gas:BigInt(1e5),chainId:84532,type:"eip1559"}}),se=await N(he.transactionHash);if(!se.success)throw new Error(se.error||"SPV approval failed");r("Depositing SPV from source property...");const fe=me(d.availableSPV),be=R({abi:$,functionName:"depositCollateral",args:[BigInt(d.tokenId),fe]});u=(await n({evmAccount:i,network:"base-sepolia",transaction:{to:f.CollateralVault.address,data:be,gas:BigInt(5e5),chainId:84532,type:"eip1559"}})).transactionHash;const ie=await N(u);if(!ie.success)throw new Error(ie.error||"SPV deposit failed")}r("Minting USLT against source property...");const g=d.needsDeposit?s.positionCount:d.positionIndex,I=R({abi:$,functionName:"mintUSLT",args:[BigInt(g),b]});j=(await n({evmAccount:i,network:"base-sepolia",transaction:{to:f.CollateralVault.address,data:I,gas:BigInt(5e5),chainId:84532,type:"eip1559"}})).transactionHash;const L=await N(j);if(!L.success)throw new Error(L.error||"USLT minting failed");r("Approving USLT for vault...");const P=R({abi:ye,functionName:"approve",args:[f.CollateralVault.address,b]});v=(await n({evmAccount:i,network:"base-sepolia",transaction:{to:f.USLT.address,data:P,gas:BigInt(1e5),chainId:84532,type:"eip1559"}})).transactionHash;const D=await N(v);if(!D.success)throw new Error(D.error||"USLT approval failed");r("Returning land-backed value...");const t=R({abi:$,functionName:"redeemUSLT",args:[BigInt(s.positionIndex),b]});o=(await n({evmAccount:i,network:"base-sepolia",transaction:{to:f.CollateralVault.address,data:t,gas:BigInt(5e5),chainId:84532,type:"eip1559"}})).transactionHash;const ae=await N(o);if(!ae.success)throw new Error(ae.error||"Redemption failed")}r("Recording settlement...");const a=await ee("POST",`/api/v2/land/${k}/settlement-record`,{method:m,sourceLandId:U,amountSettled:s.outstandingUslt,txHashApprove:v,txHashRedeem:o,txHashDeposit:u,txHashMint:j});if(!a.ok){const d=await a.json().catch(()=>({}));console.error("Settlement record failed:",d);const g={status:"completed",method:m,amountSettled:s.outstandingUslt,newOutstanding:"0",txHashApprove:v,txHashRedeem:o,txHashDeposit:u,txHashMint:j,error:"Settlement succeeded onchain but database sync failed - contact support"};return h(g),r("Settlement complete (sync pending)"),g}const M={status:"completed",method:m,amountSettled:s.outstandingUslt,newOutstanding:"0",txHashApprove:v,txHashRedeem:o,txHashDeposit:u,txHashMint:j};return h(M),r("Settlement complete"),M}catch(p){const s=p.message||"Settlement failed";throw w(s),h({status:"failed",method:m,amountSettled:"0",newOutstanding:"",error:s}),p}finally{y(!1)}},[i,n]),E=x.useCallback(()=>{y(!1),r(""),w(null),h(null)},[]);return{executeSettlement:Q,reset:E,isExecuting:l,currentStep:c,error:T,result:K}}function Jt(){const i=ge(),n=i.landId?parseInt(i.landId):null,[,l]=Te(),{isFullySetup:y}
1=ke(),[c,r]=x.useState(""),[T,w]=x.useState(null),[K,h]=x.useState(!1),[Q,E]=x.useState(!1),[k,m]=x.useState(!1),{executeSettlement:U,reset:p,isExecuting:s,currentStep:b,error:v,result:o}=_e(),{data:u,isLoading:j}=W({queryKey:["/api/lands",n],queryFn:async()=>{const t=await fetch(`/api/lands/${n}`);if(!t.ok)throw new Error("Failed to fetch land");return t.json()},enabled:!!n}),{data:a,isLoading:M,refetch:d}=W({queryKey:["/api/v2/land",n,"deactivation-eligibility"],queryFn:async()=>{const t=await fetch(`/api/v2/land/${n}/deactivation-eligibility`);if(!t.ok)throw new Error("Failed to check eligibility");return t.json()},enabled:!!n}),{data:g,isLoading:I}=W({queryKey:["/api/v2/land",n,"deactivation-request"],queryFn:async()=>{const t=await fetch(`/api/v2/land/${n}/deactivation-request`);if(t.status===404)return null;if(!t.ok)throw new Error("Failed to fetch request");return t.json()},enabled:!!n&&(a==null?void 0:a.deactivationStatus)!=="active"}),C=ve({mutationFn:async()=>{const t=await ee("POST",`/api/v2/land/${n}/deactivation-request`,{confirm:!0});if(!t.ok){const ne=await t.json();throw new Error(ne.message)}return t.json()},onSuccess:()=>{h(!1),E(!0),X.invalidateQueries({queryKey:["/api/v2/land",n]}),X.invalidateQueries({queryKey:["/api/lands",n]}),d()},onError:t=>{B.error("Request failed",{description:t.message})}}),L=async()=>{if(!(!c||!n)){if(c==="USE_OTHER_PROPERTY"&&!T){B.error("Please select a property");return}m(!0),p();try{await U(n,c,T||void 0),B("Settlement complete",{description:"Your balance has been settled onchain"}),d(),X.invalidateQueries({queryKey:["/api/lands",n]})}catch(t){B.error("Settlement failed",{description:t.message||"Transaction failed onchain"})}}};if(j||M)return e.jsx(Z,{children:e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(O,{className:"h-8 w-8 animate-spin text-muted-foreground"})})});if(!u)return e.jsx(Z,{children:e.jsx("div",{className:"text-center py-16 text-muted-foreground",children:"Property not found"})});const te=g&&g.status!=="cancelled",D=(a==null?void 0:a.deactivationStatus)==="deactivation_requested"||te;return e.jsx(Z,{children:e.jsxs("div",{className:"max-w-2xl mx-auto space-y-6",children:[e.jsxs(S,{variant:"ghost",onClick:()=>l(`/land/${n}`),className:"mb-4",children:[e.jsx(Le,{className:"h-4 w-4 mr-2"}),"Back to ",u.name]}),!y&&e.jsx(Ie,{feature:"deactivate property"}),e.jsxs(re,{className:y?"":"opacity-60 pointer-events-none",children:[e.jsx(we,{children:e.jsxs(je,{className:"flex items-center gap-2",children:[e.jsx(ue,{className:"h-5 w-5 text-amber-500"}),"Deactivate Property"]})}),e.jsxs(oe,{className:"space-y-6",children:[e.jsxs("div",{className:"p-4 bg-muted/50 rounded-lg",children:[e.jsx("p",{className:"font-medium",children:u.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[u.county,", ",u.state," ⢠",u.acreage," acres"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Value: $",Number(u.value).toLocaleString()]})]}),D?e.jsx(qe,{request:g}):e.jsxs(e.Fragment,{children:[e.jsxs(Y,{children:[e.jsx(ue,{className:"h-4 w-4"}),e.jsx(z,{children:"Deactivating removes your property from the platform. Any outstanding land-backed value must be settled first. This process typically takes 2-4 weeks."})]}),a&&a.blockers.outstandingUSLT>0&&e.jsx(re,{className:"border-amber-200 bg-amber-50",children:e.jsxs(oe,{className:"pt-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium",children:"Outstanding balance"}),e.jsxs("span",{className:"text-lg font-semibold",children:["$",a.blockers.outstandingUSLT.toLocaleString()]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"You've used land-backed value that must be returned before deactivation."}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx(A,{className:"text-sm font-medium",children:"Choose how to settle:"}),e.jsxs(le,{value:c,onValueChange:t=>{r(t),w(null)},children:[a.settlementOptions.canReturnExistingBalance&&e.jsxs("div",{className:"flex items-start space-x-3 p-3 border rounded-lg hover:bg-muted/50 cursor-pointer",children:[e.jsx(_,{value:"RETURN_BALANCE",id:"return"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(A,{htmlFor:"return",className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(Pe,{className:"h-4 w-4"}),"Return from my balance"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Use funds from your connected wallet"})]})]}),a.settlementOptions.canUseAnotherProperty&&e.jsxs("div",{className:"flex items-start space-x-3 p-3 border rounded-lg hover:bg-muted/50 cursor-pointer",children:[e.jsx(_,{value:"USE_OTHER_PROPERTY",id:"other"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(A,{htmlFor:"other",className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(Ue,{className:"h-4 w-4"}),"Use another property"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Draw against another active property's value"})]})]}),a.settlementOptions.canScheduleSettlement&&e.jsxs("div",{className:"flex items-start space-x-3 p-3 border rounded-lg opacity-50",children:[e.jsx(_,{value:"SCHEDULE_SETTLEMENT",id:"schedule",disabled:!0}),e.jsxs("div",{className:"flex-1",children:[e.jsxs(A,{htmlFor:"schedule",className:"flex items-center gap-2",children:[e.jsx(Me,{className:"h-4 w-4"}),"Schedule settlement"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Coming soon"})]})]})]}),c==="USE_OTHER_PROPERTY"&&a.otherActiveProperties.length>0&&e.jsxs("div",{className:"pl-8 space-y-2",children:[e.jsx(A,{className:"text-sm",children:"Select property:"}),e.jsx(le,{value:(T==null?void 0:T.toString())||"",onValueChange:t=>w(parseInt(t)),children:a.otherActiveProperties.map(t=>e.jsxs("div",{className:`flex items-center justify-between p-3 border rounded-lg hover:bg-muted/50 cursor-pointer ${t.availableLiquidity<a.blockers.outstandingUSLT?"opacity-50":""}`,children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(_,{value:t.landId.toString(),id:`prop-${t.landId}`,disabled:t.availableLiquidity<a.blockers.outstandingUSLT}),e.jsx(A,{htmlFor:`prop-${t.landId}`,className:"cursor-pointer",children:t.name})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["$",t.availableLiquidity.toLocaleStr
1ing()," available"]})]},t.landId))})]}),c&&e.jsx(S,{onClick:L,disabled:s||c==="USE_OTHER_PROPERTY"&&!T,className:"w-full",children:s?e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"h-4 w-4 mr-2 animate-spin"}),b||"Processing..."]}):`Settle $${a.blockers.outstandingUSLT.toLocaleString()} Onchain`})]})]})}),a&&a.blockers.hasScheduledLiquidity&&e.jsxs(Y,{variant:"destructive",children:[e.jsx(de,{className:"h-4 w-4"}),e.jsx(z,{children:"You have scheduled liquidity requests for this property that must be cancelled or completed before deactivation."})]}),a&&a.blockers.hasPendingPayments&&e.jsxs(Y,{variant:"destructive",children:[e.jsx(de,{className:"h-4 w-4"}),e.jsx(z,{children:"Complete pending payments before requesting deactivation."})]}),(a==null?void 0:a.eligible)&&e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(S,{onClick:()=>h(!0),variant:"destructive",className:"w-full",children:["Request Deactivation",e.jsx(De,{className:"h-4 w-4 ml-2"})]}),e.jsx("p",{className:"text-xs text-center text-muted-foreground mt-2",children:"This will begin the property removal process"})]})]})]})]}),e.jsx(q,{open:K,onOpenChange:h,children:e.jsxs(F,{children:[e.jsxs(V,{children:[e.jsx(H,{children:"Confirm Deactivation"}),e.jsxs(pe,{children:["Are you sure you want to deactivate ",e.jsx("strong",{children:u.name}),"?"]})]}),e.jsxs("div",{className:"py-4 space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This will:"}),e.jsxs("ul",{className:"text-sm space-y-2 list-disc pl-5",children:[e.jsx("li",{children:"Remove your property from the platform"}),e.jsx("li",{children:"Close any liquidity options"}),e.jsx("li",{children:"Return full ownership to you"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-4",children:"Estimated processing time: 2-4 weeks"})]}),e.jsxs(J,{children:[e.jsx(S,{variant:"outline",onClick:()=>h(!1),children:"Cancel"}),e.jsx(S,{variant:"destructive",onClick:()=>C.mutate(),disabled:C.isPending,children:C.isPending?e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"h-4 w-4 mr-2 animate-spin"}),"Submitting..."]}):"Confirm Deactivation"})]})]})}),e.jsx(q,{open:Q,onOpenChange:E,children:e.jsxs(F,{children:[e.jsx(V,{children:e.jsxs(H,{className:"flex items-center gap-2",children:[e.jsx(G,{className:"h-5 w-5 text-primary"}),"Deactivation Requested"]})}),e.jsx("div",{className:"py-4",children:e.jsx("p",{className:"text-muted-foreground",children:"Your deactivation request has been submitted. We'll process this over the next 2-4 weeks and keep you updated on progress."})}),e.jsx(J,{children:e.jsx(S,{onClick:()=>{E(!1),l(`/land/${n}`)},children:"Return to Property"})})]})}),e.jsx(q,{open:k&&s,onOpenChange:t=>!t&&m(!1),children:e.jsxs(F,{className:"sm:max-w-md",children:[e.jsxs(V,{children:[e.jsx(H,{children:"Settling Balance Onchain"}),e.jsx(pe,{children:"Please approve the transactions in your wallet"})]}),e.jsxs("div",{className:"py-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(O,{className:"h-5 w-5 animate-spin text-primary"}),e.jsx("span",{className:"text-sm font-medium",children:b||"Preparing..."})]}),e.jsx(Ce,{value:s?50:100,className:"h-2"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This process requires blockchain transactions. Do not close this window."})]})]})}),o&&o.status==="completed"&&e.jsx(q,{open:k&&!s&&!!o,onOpenChange:t=>{t||(m(!1),p())},children:e.jsxs(F,{children:[e.jsx(V,{children:e.jsxs(H,{className:"flex items-center gap-2",children:[e.jsx(G,{className:"h-5 w-5 text-primary"}),"Settlement Complete"]})}),e.jsxs("div",{className:"py-4 space-y-3",children:[e.jsxs("p",{className:"text-muted-foreground",children:["Your outstanding balance of $",Number(o.amountSettled).toLocaleString()," has been settled onchain."]}),o.error&&e.jsx("p",{className:"text-sm text-amber-600 bg-amber-50 p-3 rounded-lg",children:o.error}),o.txHashRedeem&&e.jsxs("a",{href:`${Ae}/tx/${o.txHashRedeem}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 text-sm text-primary hover:underline",children:[e.jsx(Oe,{className:"h-4 w-4"}),"View transaction on BaseScan"]})]}),e.jsx(J,{children:e.jsx(S,{onClick:()=>{m(!1),p()},children:"Continue"})})]})})]})})}function qe({request:i}){if(!i)return e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:"Loading deactivation status..."});const n=l=>{switch(l){case"completed":return e.jsx(G,{className:"h-5 w-5 text-primary"});case"in_progress":return e.jsx(ce,{className:"h-5 w-5 text-amber-500"});default:return e.jsx(ce,{className:"h-5 w-5 text-muted-foreground"})}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-primary/10 rounded-lg",children:[e.jsx("span",{className:"font-medium",children:"Deactivation in progress"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Est. ",i.estimatedTime]})]}),e.jsx("div",{className:"space-y-1",children:i.timeline.map((l,y)=>e.jsxs("div",{className:"flex items-center gap-3 p-3",children:[n(l.status),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:`text-sm ${l.status==="completed"?"text-muted-foreground":"font-medium"}`,children:l.step}),l.completedAt&&e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(l.completedAt).toLocaleDateString()})]})]},y))}),i.status==="completed"&&e.jsxs(Y,{className:"bg-primary/10 border-primary",children:[e.jsx(G,{className:"h-4 w-4 text-primary"}),e.jsx(z,{children:"Deactivation complete. Full ownership has been restored to you."})]})]})}export{Jt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.