import { useState, useEffect, useRef } from 'react'; import { InputField } from '../../../../../Components/Forms/InputField.jsx'; import { Form, Radio } from 'antd'; import Buttons from '../../../../../Components/Forms/Buttons.jsx'; import { ArrowRightOutlined } from '@ant-design/icons'; import "./WeightCalculatePrice.scss" const WeightCalculatePrice = ({ itemData, CartOrderDetails, onSubmit }) => { const [enteredPrice, setEnteredPrice] = useState(''); const [enteredQty, setEnteredQty] = useState(''); const [calculatedQty, setCalculatedQty] = useState(0); const [calcMode, setCalcMode] = useState('amt'); const priceInputRef = useRef(null); const [form] = Form.useForm(); const basePrice = parseFloat( itemData?.OrderRate || itemData?.SellingPrice || 0 ); // Auto focus input useEffect(() => { setTimeout(() => { const input = priceInputRef.current?.querySelector('input'); if (input) input.focus(); }, 100); }, [calcMode]); // AMT → calculate QTY const handlePriceChange = (e) => { const value = e.target.value; setEnteredPrice(value); if (value && basePrice > 0) { const qty = parseFloat(value) / basePrice; setCalculatedQty(qty); } else { setCalculatedQty(0); } }; // KGS → calculate AMT const handleQtyChange = (e) => { const value = e.target.value; setEnteredQty(value); if (value && basePrice > 0) { const qty = parseFloat(value); const price = qty * basePrice; setEnteredPrice(price.toFixed(2)); setCalculatedQty(qty); } else { setEnteredPrice(''); setCalculatedQty(0); } }; const handleSubmit = (e) => { if (e && e.preventDefault) e.preventDefault(); if (calculatedQty > 0 && enteredPrice > 0) { onSubmit?.({ price: parseFloat(enteredPrice), quantity: parseFloat(calculatedQty), }); } }; return (