/**
 * WooCommerce Button Text Changer
 * Admin JavaScript
 *
 * @package WooCommerce_Button_Text_Changer
 */

(function ($) {
	'use strict';

	/**
	 * Initialize admin functionality.
	 */
	function initWBTCAdmin() {

		var $enableCheckbox = $('#wbtc-enabled');

		if (!$enableCheckbox.length) {
			return;
		}

		/**
		 * Enable / disable button text fields.
		 */
		function toggleButtonFields() {

			var enabled = $enableCheckbox.is(':checked');

			$('.wbtc-button-text-field').each(function () {

				$(this).prop('disabled', !enabled);

			});
		}

		/**
		 * Initial state.
		 */
		toggleButtonFields();

		/**
		 * Checkbox change.
		 */
		$enableCheckbox.on('change', function () {

			toggleButtonFields();

		});

	}

	/**
	 * DOM ready.
	 */
	$(document).ready(function () {

		initWBTCAdmin();

	});

})(jQuery);