<?php
/**
 * WeCodeArt Framework.
 *
 * WARNING: This file is part of the core WeCodeArt Framework. DO NOT edit this file under any circumstances.
 * Please do all modifications in the form of a child theme.
 *
 * @package 	WeCodeArt Framework
 * @subpackage  Toggler HTML
 * @since	 	5.0.0
 * @version    	6.4.5
 */

defined( 'ABSPATH' ) || exit;

use function WeCodeArt\Functions\{ get_prop, toJSON };

wecodeart( 'styles' )->Components->load( [ 'toggler' ] );

/**
 * @param   string	$id			ID
 * @param   string	$toggle		Type
 * @param   string	$toggle		Class
 * @param   bool	$icon		Icon
 * @param   array	$options	Options
 */

$type 	= $type ?? 'offcanvas';
$label	= $label ?? __( 'Menu', 'wecodeart' );
$class 	= $class ?? 'wp-element-button'; 
$opts	= $options ?? [
	'isOpen' => false
];

$classnames = (array) $class;

?>
<button 
	class="<?php echo esc_attr( join( ' ', $classnames ) ); ?>"
	id="<?php echo esc_attr( $id ); ?>-toggle"
	<?php switch( $type ) : 
		case 'offcanvas':
	?>
	data-wp-interactive="wecodeart/offcanvas" 
	data-wp-context="<?php echo esc_attr( toJSON( $opts ) ); ?>"
	data-wp-init--validate="callbacks.validateConfig"
	data-wp-init--setup="callbacks.onInit"
	data-wp-bind--aria-expanded="context.isOpen"
	data-wp-on--click="actions.toggle"
	aria-label="<?php esc_attr_e( 'Toggle navigation', 'wecodeart' ); ?>"
	aria-controls="<?php echo esc_attr( $id ); ?>-offcanvas"
	<?php
		break;
		case 'collapse':
			if( get_prop( $opts, [ 'isOpen' ] ) === false ) {
				$classnames[] = 'collapsed';
			}
	?>
	data-wp-interactive="wecodeart/collapse" 
	data-wp-context="<?php echo esc_attr( toJSON( $opts ) ); ?>"
	data-wp-bind--aria-label="state.ariaLabel"
	data-wp-bind--aria-expanded="context.isOpen"
	data-wp-class--collapsed="!context.isOpen"
	data-wp-on--click="actions.toggle"
	aria-label="<?php esc_attr_e( 'Open item', 'wecodeart' ); ?>"
	aria-controls="<?php echo esc_attr( $id ); ?>-content"
	<?php 
		break;
	endswitch; ?>
	aria-expanded="<?php echo esc_attr( get_prop( $opts, [ 'isOpen' ] ) ? 'true' : 'false' ); ?>"
	type="button"
>
	<?php if ( $icon ?? false ) : ?>
	<?php if ( is_array( $icon ) ) :
		wecodeart( 'dom' )->SVG::add( $id, $icon );
		wecodeart( 'dom' )->SVG::render( $id, [ 'class' => 'fa-fw' ] );
	?>
	<?php else : ?>
	<span class="navbar-toggler-icon"></span>
	<?php endif; ?>
	<?php else : ?>
	<span><?php echo esc_html( $label ); ?></span>
	<?php endif; ?>
</button>