<?php
/**
 * Offcanvas Button Widget Content View file.
 *
 * @package    CodexShaper_Framework
 * @author     CodexShaper <info@codexshaper.com>
 * @license    https://www.gnu.org/licenses/gpl-2.0.html
 * @link       https://codexshaper.com
 * @since      1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

use Elementor\Utils;

$link_url = isset( $settings['csmf_button_link'] ) && ! empty( $settings['csmf_button_link'] ) ? $settings['csmf_button_link']['url'] : '#';

$instance->add_render_attribute( 'button_wrapper', 'class', 'csmf--btn' );
$instance->add_render_attribute(
	'link',
	array(
		'class'      => "csmf--btn-{$settings['csmf_button_style']}",
		'aria-label' => "{$settings['csmf_button_aria_label']}",

	)
);

if ( 'a' === $settings['csmf_button_type'] ) {
	$instance->add_render_attribute( 'link', 'href', $link_url );
}

if ( 'right' === $settings['csmf_button_icon_align'] ) {
	$instance->add_render_attribute( 'button_wrapper', 'class', 'icon-position-after' );
}

if ( '' !== $settings['csmf_button_effect'] ) {
	$instance->add_render_attribute( 'link', 'class', "csmf--btn-{$settings['csmf_button_effect']}" );
}

if ( 'mask' === $settings['csmf_button_style'] ) {
	$instance->add_render_attribute( 'link', 'data-text', $settings['csmf_button_text'] );
}

$button_opening_tag = sprintf(
	'<%1$s %2$s>',
	Utils::validate_html_tag( $settings['csmf_button_type'] ),
	$instance->get_render_attribute_string( 'link' ),
);
$button_closing_tag = sprintf( '</%1$s>', Utils::validate_html_tag( $settings['csmf_button_type'] ) );
?>
<div <?php $instance->print_render_attribute_string( 'button_wrapper' ); ?>>
	<?php Utils::print_unescaped_internal_string( $button_opening_tag ); ?>
	<?php if ( empty( $settings['csmf_button_icon_align'] ) || 'left' === $settings['csmf_button_icon_align'] ) : ?>
		<span class="csmf--btn_icon">
			<?php $instance->maybe_render_icon( $settings ); ?>
		</span>
	<?php endif; ?>
	<?php echo esc_html( $settings['csmf_button_text'] ); ?>
	<?php if ( 'right' === $settings['csmf_button_icon_align'] ) : ?>
		<span class="csmf--btn_icon">
			<?php $instance->maybe_render_icon( $settings ); ?>
		</span>
	<?php endif; ?>
	<?php utils::print_unescaped_internal_string( $button_closing_tag ); ?>
</div>
