/**
 * EasySite Site Settings – logo picker
 */
(function ($) {
	'use strict';

	$('#easysite-pick-logo').on('click', function (e) {
		e.preventDefault();
		var frame = wp.media({
			title: 'Choose logo',
			button: { text: 'Use this logo' },
			multiple: false
		});
		frame.on('select', function () {
			var attachment = frame.state().get('selection').first().toJSON();
			$('#custom_logo_id').val(attachment.id);
			$('#easysite-logo-preview').attr('src', attachment.url).show();
			$('#easysite-remove-logo').show();
		});
		frame.open();
	});

	$('#easysite-remove-logo').on('click', function (e) {
		e.preventDefault();
		$('#custom_logo_id').val('');
		$('#easysite-logo-preview').hide();
		$(this).hide();
	});

	$('#gradient_preset').on('change', function () {
		var val = $(this).val();
		$('.easysite-gradient-swatch').removeClass('is-active');
		$('.easysite-gradient-swatch[data-gradient="' + val + '"]').addClass('is-active');
	});
})(jQuery);
