/** Preview-only allocation. This module does not create connections or orders. */
export function previewCapitalUnits(value:string):bigint|null {
 if(!/^\d{1,15}(?:\.\d)?$/.test(value))return null;
 const [whole,fraction='0']=value.split('.');
 const units=BigInt(whole)*BigInt(10)+BigInt(fraction);
 return units>BigInt(0)?units:null;
}

/** Keep the complete demo budget, including the rounding remainder. */
export function previewAllocations(value:string,weights:readonly number[]):string[]|null {
 const total=previewCapitalUnits(value);
 if(total===null||weights.length===0||weights.some(weight=>!Number.isSafeInteger(weight)||weight<=0)||weights.reduce((sum,weight)=>sum+weight,0)!==100)return null;
 let remaining=total;
 return weights.map((weight,index)=>{
  const units=index===weights.length-1?remaining:total*BigInt(weight)/BigInt(100);
  remaining-=units;
  return `${units/BigInt(10)}${units%BigInt(10)?'.'+String(units%BigInt(10)):''}`;
 });
}
