/**
 * AddressZen Admin Settings JavaScript
 * 
 * Handles dynamic behavior in the admin settings page
 */

jQuery(document).ready(function($) {
  // Function to toggle visibility of the hide_address_fields option
  function toggleHideAddressFields() {
    // Use the field name attribute which is more reliable than ID
    var separateFinderField = $('input[name="woocommerce_addresszen_addresszen_separate_finder"]');
    var hideAddressFieldsRow = $('input[name="woocommerce_addresszen_addresszen_hide_address_fields"]').closest('tr');
    var separateFinderChecked = separateFinderField.is(':checked');

    if (separateFinderChecked) {
      hideAddressFieldsRow.show();
    } else {
      hideAddressFieldsRow.hide();
    }
  }

  // Run on page load
  toggleHideAddressFields();

  // Run when the separate_finder checkbox changes
  $('input[name="woocommerce_addresszen_addresszen_separate_finder"]').change(function() {
    toggleHideAddressFields();
  });
});
