/**
 * Eryndo admin welcome notice interactions.
 */
( function ( $ ) {
	'use strict';

	function initEryndoAdminNotice() {
		var $notice = $( '.eryndo-zoloblocks-notice' );

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

		var nonce = $notice.data( 'nonce' );

		$notice.on( 'click', '.notice-dismiss', function () {
			$.post( ajaxurl, {
				action: 'eryndo_dismiss_notice',
				nonce: nonce,
			} );
		} );

		$notice.on( 'click', '.eryndo-notice-toggle', function ( event ) {
			event.preventDefault();

			var $button = $( this );
			var $details = $notice.find( '.eryndo-notice-details' );
			var isOpen = $details.hasClass( 'is-open' );
			var showLabel = $button.data( 'label-show' );
			var hideLabel = $button.data( 'label-hide' );

			if ( isOpen ) {
				$details.removeClass( 'is-open' ).slideUp( 200 );
				$button.removeClass( 'is-open' ).attr( 'aria-expanded', 'false' );
				$button.find( '.eryndo-toggle-label' ).text( showLabel );
			} else {
				$details.addClass( 'is-open' ).slideDown( 200 );
				$button.addClass( 'is-open' ).attr( 'aria-expanded', 'true' );
				$button.find( '.eryndo-toggle-label' ).text( hideLabel );
			}
		} );
	}

	$( initEryndoAdminNotice );
}( jQuery ) );
