<?php
/**
 * @package DhlPolska\WooCommerceSettings
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

?>

<script type="text/javascript">
	function dhl_polska_settings_change_event( event ) {
		var is_sandbox = document.querySelector( '.js--environment-field' ).checked;
		var sandbox_fields = document.querySelectorAll( '.js--sandbox-field' );
		var production_fields = document.querySelectorAll( '.js--production-field' );


		sandbox_fields.forEach( function ( button ) {
			button.required = is_sandbox;
			button.closest( 'tr' ).style.display = is_sandbox ? 'table-row' : 'none'
		} );

		production_fields.forEach( function ( button ) {
			button.required = !is_sandbox;
			button.closest( 'tr' ).style.display = !is_sandbox ? 'table-row' : 'none'
		} );
	}

	document.addEventListener( "DOMContentLoaded", function ( event ) {
		var env_field = document.querySelector( '.js--environment-field' );
		if ( env_field ) {
			env_field.addEventListener( "change", dhl_polska_settings_change_event );
			dhl_polska_settings_change_event();
		}
	} );
</script>
