/**
 * @file assets/js/adminjs/admin-categorization.js
 * Tab panel switching inside MBS_Metabox_Categorization for Tags, Themes, and Content Warnings.
 * @package MyBookShowroom
 * @since   1.0.0
 */
( function () {
	'use strict';

	var box = document.querySelector( '.mbs-cat-metabox' );
	if ( ! box ) {
		return;
	}

	box.addEventListener( 'click', function ( e ) {
		var btn = e.target.closest( '.mbs-cat-tab-btn' );
		if ( ! btn ) {
			return;
		}

		var tabId = btn.dataset.tab;

		box.querySelectorAll( '.mbs-cat-tab-btn' ).forEach( function ( b ) {
			b.classList.remove( 'mbs-cat-tab-btn--active' );
			b.setAttribute( 'aria-selected', 'false' );
		} );

		box.querySelectorAll( '.mbs-cat-panel' ).forEach( function ( p ) {
			p.classList.remove( 'mbs-cat-panel--active' );
		} );

		btn.classList.add( 'mbs-cat-tab-btn--active' );
		btn.setAttribute( 'aria-selected', 'true' );

		var panel = box.querySelector( '#mbs-cat-panel-' + tabId );
		if ( panel ) {
			panel.classList.add( 'mbs-cat-panel--active' );
		}
	} );
}() );
