Page({
  data: {
    fatherHeight: null,
    motherHeight: null,
    childGender: 'male',
    targetHeight: null
  },

  onClickLeft() {
    wx.navigateBack()
  },

  onLoad() {
    // Initialization if needed
  },

  inputFatherHeight(e) {
    this.setData({ fatherHeight: e.detail.value });
  },

  inputMotherHeight(e) {
    this.setData({ motherHeight: e.detail.value });
  },

  selectGender(e) {
    const gender = e.currentTarget.dataset.gender;
    this.setData({ childGender: gender });
  },

  calculate() {
    const { fatherHeight, motherHeight, childGender } = this.data;
    if (!fatherHeight || !motherHeight) return;
    
    const father = parseFloat(fatherHeight);
    const mother = parseFloat(motherHeight);
    
    // Genetic target height formula
    let target = 0;
    if (childGender === 'male') {
      target = (father + mother + 13) / 2;
    } else {
      target = (father + mother - 13) / 2;
    }
    
    this.setData({
      targetHeight: target.toFixed(1)
    });
  },

  reset() {
    this.setData({
      fatherHeight: null,
      motherHeight: null,
      childGender: 'male',
      targetHeight: null
    });
  }
});
