/* 見積もりフォームの商品を選択したときの処理 */
const radioButtons = document.getElementsByName('estimate-items');
const estimateAmount = document.getElementById('estimateAmount');
const selectedItem = document.getElementsByName('selected-item')[0];

const radioButtonIsChecked = radioButton => {
  estimateAmount.textContent = Number(radioButton.dataset.price).toLocaleString();
  selectedItem.value = radioButton.value;
}

radioButtons.forEach(radioButton => {
  radioButton.onchange = () => radioButtonIsChecked(radioButton);
});

radioButtonIsChecked(radioButtons[0]);
