<?php
/**
 * Info List element.
 *
 * A repeatable list of icon + title + description rows - the "feature list" /
 * "icon list" staple. Each item can link out. Three arrangements (icon left,
 * icon on top, inline row) plus a vertical/horizontal connector "timeline"
 * line, optional dividers, icon shapes (circle / square / rounded, filled or
 * framed) and full typography control over the title and description.
 *
 * Best-of from the competitors: Elementor's inline + divider, Essential
 * Addons' connector line and icon shapes, Ultimate Addons' orientation.
 *
 * @package CraftAddonsForWPBakery
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class CAFW_Element_Info_List
 */
class CAFW_Element_Info_List extends CAFW_Element_Base {

	/**
	 * {@inheritDoc}
	 */
	public function get_shortcode_tag() {
		return 'cafw_info_list';
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_label() {
		return esc_html__( 'Feature List', 'craft-addons-for-wpbakery' );
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_description() {
		return esc_html__( 'Icon, title and text rows.', 'craft-addons-for-wpbakery' );
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_admin_icon() {
		return 'dashicons-editor-ul';
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_editor_icon() {
		return 'cafw-vc-icon cafw-vc-icon-info-list';
	}

	/**
	 * {@inheritDoc}
	 */
	protected function get_defaults() {
		return array(
			'items'             => $this->default_items(),
			'layout'            => 'left',
			'align'             => 'left',
			'connector'         => '',
			'divider'           => '',
			'gap'               => '24',
			'icon_gap'          => '16',
			'icon_shape'        => 'circle',
			'icon_color'        => '#502bf8',
			'icon_bg'           => '#f4f1ff',
			'icon_size'         => '20',
			'icon_pad'          => '12',
			'icon_border_color' => '',
			'icon_border_width' => '',
			'icon_hover_color'  => '',
			'icon_bg_hover'     => '',
			'title_hover_color' => '',
			'connector_color'   => '#d9cef8',
			'connector_width'   => '2',
			'connector_style'   => 'solid',
			'divider_color'     => '#ececec',
			'title_font'        => '',
			'title_google_font' => '',
			'desc_font'         => '',
			'desc_google_font'  => '',
		);
	}

	/**
	 * Default items shown when the element is first dropped in.
	 *
	 * @return string URL-encoded JSON understood by the param_group field.
	 */
	private function default_items() {
		$rows = array(
			array(
				'icon'  => 'fa fa-solid fa-rocket',
				'title' => esc_html__( 'Fast & lightweight', 'craft-addons-for-wpbakery' ),
				'desc'  => esc_html__( 'A short line describing this feature.', 'craft-addons-for-wpbakery' ),
			),
			array(
				'icon'  => 'fa fa-solid fa-shield',
				'title' => esc_html__( 'Secure by default', 'craft-addons-for-wpbakery' ),
				'desc'  => esc_html__( 'A short line describing this feature.', 'craft-addons-for-wpbakery' ),
			),
			array(
				'icon'  => 'fa fa-solid fa-wand-magic-sparkles',
				'title' => esc_html__( 'Easy to customise', 'craft-addons-for-wpbakery' ),
				'desc'  => esc_html__( 'A short line describing this feature.', 'craft-addons-for-wpbakery' ),
			),
		);
		return rawurlencode( wp_json_encode( $rows ) );
	}

	/**
	 * Wireframe thumbnail for a layout picker option.
	 *
	 * @param string $type Layout key.
	 * @return string Inline SVG.
	 */
	private function layout_thumb( $type ) {
		$ico = '#502bf8'; // icon.
		$t   = '#bcb9cc'; // title line.
		$x   = '#d8d5e4'; // text line.
		if ( 'top' === $type ) {
			// Two icon-on-top items, stacked and centred, with room to breathe.
			$item  = function ( $cy ) use ( $ico, $t, $x ) {
				return '<circle cx="30" cy="' . $cy . '" r="4" fill="' . $ico . '"/>'
					. '<rect x="20" y="' . ( $cy + 7 ) . '" width="20" height="3" rx="1.5" fill="' . $t . '"/>'
					. '<rect x="24" y="' . ( $cy + 12 ) . '" width="12" height="2.4" rx="1.2" fill="' . $x . '"/>';
			};
			$inner = $item( 8 ) . $item( 26 );
		} elseif ( 'inline' === $type ) {
			// Three side-by-side icon-on-top columns.
			$col   = function ( $cx ) use ( $ico, $t, $x ) {
				return '<circle cx="' . $cx . '" cy="15" r="4" fill="' . $ico . '"/>'
					. '<rect x="' . ( $cx - 7 ) . '" y="24" width="14" height="3" rx="1.5" fill="' . $t . '"/>'
					. '<rect x="' . ( $cx - 5 ) . '" y="29" width="10" height="2.4" rx="1.2" fill="' . $x . '"/>';
			};
			$inner = $col( 14 ) . $col( 30 ) . $col( 46 );
		} else { // left: three icon-left rows.
			$row   = function ( $cy ) use ( $ico, $t, $x ) {
				return '<circle cx="10" cy="' . $cy . '" r="3.8" fill="' . $ico . '"/>'
					. '<rect x="18" y="' . ( $cy - 3.5 ) . '" width="30" height="3" rx="1.5" fill="' . $t . '"/>'
					. '<rect x="18" y="' . ( $cy + 1.5 ) . '" width="20" height="2.4" rx="1.2" fill="' . $x . '"/>';
			};
			$inner = $row( 10 ) . $row( 21 ) . $row( 32 );
		}
		return '<svg viewBox="0 0 60 42" width="60" height="42" xmlns="http://www.w3.org/2000/svg">'
			. '<rect width="60" height="42" rx="4" fill="#f6f5fb"/>' . $inner . '</svg>';
	}

	/**
	 * {@inheritDoc}
	 */
	public function get_params() {
		$styles        = esc_html__( 'Styles', 'craft-addons-for-wpbakery' );
		$connector_dep = array(
			'element' => 'connector',
			'value'   => 'yes',
		);
		$divider_dep   = array(
			'element' => 'divider',
			'value'   => 'yes',
		);

		return array_merge(
			array(
				array(
					'type'       => 'cafw_layout',
					'heading'    => esc_html__( 'Layout', 'craft-addons-for-wpbakery' ),
					'param_name' => 'layout',
					'std'        => 'left',
					'options'    => array(
						'left'   => array(
							'label' => esc_html__( 'Icon left', 'craft-addons-for-wpbakery' ),
							'thumb' => $this->layout_thumb( 'left' ),
						),
						'top'    => array(
							'label' => esc_html__( 'Icon on top', 'craft-addons-for-wpbakery' ),
							'thumb' => $this->layout_thumb( 'top' ),
						),
						'inline' => array(
							'label' => esc_html__( 'Inline row', 'craft-addons-for-wpbakery' ),
							'thumb' => $this->layout_thumb( 'inline' ),
						),
					),
				),
				array(
					'type'        => 'param_group',
					'heading'     => esc_html__( 'List items', 'craft-addons-for-wpbakery' ),
					'param_name'  => 'items',
					'value'       => $this->default_items(),
					'description' => esc_html__( 'Add, remove and reorder the rows.', 'craft-addons-for-wpbakery' ),
					'params'      => array(
						array(
							'type'       => 'iconpicker',
							'heading'    => esc_html__( 'Icon', 'craft-addons-for-wpbakery' ),
							'param_name' => 'icon',
							'value'      => 'fa fa-solid fa-check',
							'settings'   => array(
								'emptyIcon'    => true,
								'type'         => 'fontawesome',
								'iconsPerPage' => 200,
							),
						),
						array(
							'type'        => 'textfield',
							'heading'     => esc_html__( 'Title', 'craft-addons-for-wpbakery' ),
							'param_name'  => 'title',
							'admin_label' => true,
						),
						array(
							'type'       => 'textarea',
							'heading'    => esc_html__( 'Description', 'craft-addons-for-wpbakery' ),
							'param_name' => 'desc',
						),
						array(
							'type'        => 'vc_link',
							'heading'     => esc_html__( 'Link', 'craft-addons-for-wpbakery' ),
							'param_name'  => 'link',
							'description' => esc_html__( 'Optional - makes the whole row a link.', 'craft-addons-for-wpbakery' ),
						),
					),
				),
				array(
					'type'             => 'dropdown',
					'heading'          => esc_html__( 'Alignment', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'align',
					'value'            => array(
						esc_html__( 'Left', 'craft-addons-for-wpbakery' )   => 'left',
						esc_html__( 'Center', 'craft-addons-for-wpbakery' ) => 'center',
						esc_html__( 'Right', 'craft-addons-for-wpbakery' )  => 'right',
					),
					'std'              => 'left',
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Gap between items (px)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'gap',
					'value'            => '24',
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'checkbox',
					'heading'          => esc_html__( 'Connector line', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'connector',
					'value'            => array( esc_html__( 'Connect the icons with a line', 'craft-addons-for-wpbakery' ) => 'yes' ),
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'checkbox',
					'heading'          => esc_html__( 'Divider', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'divider',
					'value'            => array( esc_html__( 'Show a line between rows', 'craft-addons-for-wpbakery' ) => 'yes' ),
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				// ---- Styles: icon ----
				array(
					'type'             => 'dropdown',
					'heading'          => esc_html__( 'Icon shape', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_shape',
					'value'            => array(
						esc_html__( 'None', 'craft-addons-for-wpbakery' )    => 'none',
						esc_html__( 'Circle', 'craft-addons-for-wpbakery' )  => 'circle',
						esc_html__( 'Square', 'craft-addons-for-wpbakery' )  => 'square',
						esc_html__( 'Rounded', 'craft-addons-for-wpbakery' ) => 'rounded',
					),
					'std'              => 'circle',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Icon size (px)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_size',
					'value'            => '20',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Icon color', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_color',
					'value'            => '#502bf8',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-4 vc_column',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Icon background', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_bg',
					'value'            => '#f4f1ff',
					'description'      => esc_html__( 'Used for the circle / square shapes.', 'craft-addons-for-wpbakery' ),
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-4 vc_column',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Icon border', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_border_color',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-4 vc_column',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Icon padding (px)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_pad',
					'value'            => '12',
					'description'      => esc_html__( 'Space inside the shape, around the glyph.', 'craft-addons-for-wpbakery' ),
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-4 vc_column',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Icon border width (px)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_border_width',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-4 vc_column',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Icon-text gap (px)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_gap',
					'value'            => '16',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-4 vc_column',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Icon color (hover)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_hover_color',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Icon background (hover)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'icon_bg_hover',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column cafw-bg-sep',
				),
			),
			// ---- Styles: title + description typography ----
			$this->typography_params(
				'title',
				esc_html__( 'Title', 'craft-addons-for-wpbakery' ),
				array(
					'tag' => true,
					'sep' => true,
				)
			),
			array(
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Title color (hover)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'title_hover_color',
					'group'            => $styles,
					'edit_field_class' => 'vc_col-sm-6 vc_column',
				),
			),
			$this->typography_params( 'desc', esc_html__( 'Description', 'craft-addons-for-wpbakery' ), array( 'sep' => true ) ),
			array(
				// ---- Styles: connector (shown when on) ----
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Connector color', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'connector_color',
					'value'            => '#d9cef8',
					'group'            => $styles,
					'dependency'       => $connector_dep,
					'edit_field_class' => 'vc_col-sm-4 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'textfield',
					'heading'          => esc_html__( 'Connector width (px)', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'connector_width',
					'value'            => '2',
					'group'            => $styles,
					'dependency'       => $connector_dep,
					'edit_field_class' => 'vc_col-sm-4 vc_column cafw-bg-sep',
				),
				array(
					'type'             => 'dropdown',
					'heading'          => esc_html__( 'Connector style', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'connector_style',
					'value'            => array(
						esc_html__( 'Solid', 'craft-addons-for-wpbakery' )  => 'solid',
						esc_html__( 'Dashed', 'craft-addons-for-wpbakery' ) => 'dashed',
						esc_html__( 'Dotted', 'craft-addons-for-wpbakery' ) => 'dotted',
					),
					'std'              => 'solid',
					'group'            => $styles,
					'dependency'       => $connector_dep,
					'edit_field_class' => 'vc_col-sm-4 vc_column cafw-bg-sep',
				),
				// ---- Styles: divider (shown when on) ----
				array(
					'type'             => 'colorpicker',
					'heading'          => esc_html__( 'Divider color', 'craft-addons-for-wpbakery' ),
					'param_name'       => 'divider_color',
					'value'            => '#ececec',
					'group'            => $styles,
					'dependency'       => $divider_dep,
					'edit_field_class' => 'vc_col-xs-12 vc_column cafw-bg-sep',
				),
			)
		);
	}

	/**
	 * Append "px" to a numeric value, or return '' when blank.
	 *
	 * @param mixed $value Raw value.
	 * @return string
	 */
	private function px( $value ) {
		$value = trim( (string) $value );
		if ( '' === $value || ! is_numeric( $value ) ) {
			return '';
		}
		return absint( $value ) . 'px';
	}

	/**
	 * {@inheritDoc}
	 */
	public function render( $atts, $content, $el_id ) {
		$layout = in_array( $atts['layout'], array( 'left', 'top', 'inline' ), true ) ? $atts['layout'] : 'left';
		$align  = in_array( $atts['align'], array( 'left', 'center', 'right' ), true ) ? $atts['align'] : 'left';
		$shape  = in_array( $atts['icon_shape'], array( 'none', 'circle', 'square', 'rounded' ), true ) ? $atts['icon_shape'] : 'circle';
		$cstyle = in_array( $atts['connector_style'], array( 'solid', 'dashed', 'dotted' ), true ) ? $atts['connector_style'] : 'solid';

		$has_connector = ( false !== strpos( (string) $atts['connector'], 'yes' ) );
		$has_divider   = ( false !== strpos( (string) $atts['divider'], 'yes' ) );

		// Parse the repeatable rows.
		$items = array();
		if ( ! empty( $atts['items'] ) && function_exists( 'vc_param_group_parse_atts' ) ) {
			$items = vc_param_group_parse_atts( $atts['items'] );
		}
		if ( empty( $items ) || ! is_array( $items ) ) {
			return '';
		}

		// Icon geometry: the wrapper is a fixed square so the connector can be
		// centred on it. Filled/framed shapes add padding; "none" is just the glyph.
		$icon_size = absint( $atts['icon_size'] );
		$icon_size = $icon_size ? $icon_size : 20;
		$icon_pad  = ( 'none' === $shape ) ? 0 : absint( $atts['icon_pad'] );
		$icon_box  = $icon_size + ( 2 * $icon_pad );

		// CSS custom properties that skin every row.
		$vars = array(
			'--cafw-il-gap'             => $this->px( $atts['gap'] ),
			'--cafw-il-icon-gap'        => $this->px( $atts['icon_gap'] ),
			'--cafw-il-icon-color'      => sanitize_hex_color( $atts['icon_color'] ),
			'--cafw-il-icon-size'       => $icon_size . 'px',
			'--cafw-il-icon-box'        => $icon_box . 'px',
			'--cafw-il-icon-pad'        => $icon_pad . 'px',
			'--cafw-il-connector-color' => sanitize_hex_color( $atts['connector_color'] ),
			'--cafw-il-connector-width' => $this->px( $atts['connector_width'] ),
			'--cafw-il-connector-style' => $cstyle,
			'--cafw-il-divider-color'   => sanitize_hex_color( $atts['divider_color'] ),
		);
		if ( 'none' !== $shape ) {
			$bg = sanitize_hex_color( $atts['icon_bg'] );
			if ( $bg ) {
				$vars['--cafw-il-icon-bg'] = $bg;
			}
			$bw = absint( $atts['icon_border_width'] );
			$bc = sanitize_hex_color( $atts['icon_border_color'] );
			if ( $bw && $bc ) {
				$vars['--cafw-il-icon-border'] = $bw . 'px solid ' . $bc;
			}
		}

		$vars = array_filter( $vars ); // drop empties.

		// Hover colours, scoped to this instance.
		$hover = '';
		$ihc   = sanitize_hex_color( $atts['icon_hover_color'] );
		$ibgh  = sanitize_hex_color( $atts['icon_bg_hover'] );
		$thc   = sanitize_hex_color( $atts['title_hover_color'] );
		if ( $ihc ) {
			$hover .= '#' . $el_id . ' .cafw-info-list__item:hover .cafw-info-list__icon{color:' . $ihc . '!important}';
		}
		if ( $ibgh ) {
			$hover .= '#' . $el_id . ' .cafw-info-list__item:hover .cafw-info-list__icon{background-color:' . $ibgh . '!important}';
		}
		if ( $thc ) {
			$hover .= '#' . $el_id . ' .cafw-info-list__item:hover .cafw-info-list__title{color:' . $thc . '!important}';
		}
		if ( '' !== $hover ) {
			CAFW_Element_Base::add_inline_style( $hover );
		}

		// Typography for the title + description (shared by all rows).
		$title_type = $this->part_typography( $atts, 'title' );
		$desc_type  = $this->part_typography( $atts, 'desc' );
		$title_tag  = in_array( $title_type['tag'], array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div' ), true ) ? $title_type['tag'] : 'h4';
		$title_attr = $this->style_attr( $title_type['styles'] );
		$desc_attr  = $this->style_attr( $desc_type['styles'] );

		$classes = array(
			'cafw-info-list',
			'cafw-info-list--' . $layout,
			'cafw-info-list--align-' . $align,
			'cafw-info-list--shape-' . $shape,
		);
		if ( $has_connector ) {
			$classes[] = 'cafw-info-list--connector';
		}
		if ( $has_divider ) {
			$classes[] = 'cafw-info-list--divider';
		}
		$dclass = CAFW_Element_Base::design_options_class( $atts );
		if ( $dclass ) {
			$classes[] = $dclass;
		}
		if ( '' !== trim( (string) $atts['el_class'] ) ) {
			$classes[] = $atts['el_class'];
		}

		$enqueued = false;

		ob_start();
		?>
		<div id="<?php echo esc_attr( $el_id ); ?>" class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"<?php echo $this->style_attr( $vars ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- style_attr escapes internally. ?>>
			<?php
			foreach ( $items as $item ) {
				$icon  = isset( $item['icon'] ) ? (string) $item['icon'] : '';
				$title = isset( $item['title'] ) ? (string) $item['title'] : '';
				$desc  = isset( $item['desc'] ) ? (string) $item['desc'] : '';

				if ( '' === $icon && '' === $title && '' === $desc ) {
					continue;
				}

				if ( '' !== $icon && ! $enqueued && function_exists( 'vc_icon_element_fonts_enqueue' ) ) {
					vc_icon_element_fonts_enqueue( 'fontawesome' );
					$enqueued = true;
				}

				// Optional whole-row link.
				$href = '';
				$rel  = '';
				$tgt  = '';
				if ( ! empty( $item['link'] ) && function_exists( 'vc_build_link' ) ) {
					$link = vc_build_link( $item['link'] );
					if ( ! empty( $link['url'] ) ) {
						$href = $link['url'];
						$tgt  = ! empty( $link['target'] ) ? trim( $link['target'] ) : '';
						$rel  = ! empty( $link['rel'] ) ? trim( $link['rel'] ) : '';
					}
				}
				$tag      = $href ? 'a' : 'div';
				$href_str = $href ? ' href="' . esc_url( $href ) . '"' : '';
				$tgt_str  = $tgt ? ' target="' . esc_attr( $tgt ) . '"' : '';
				$rel_str  = $rel ? ' rel="' . esc_attr( $rel ) . '"' : '';
				?>
				<<?php echo esc_attr( $tag ); ?> class="cafw-info-list__item"<?php echo $href_str . $tgt_str . $rel_str; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- each part escaped above. ?>>
					<span class="cafw-info-list__icon" aria-hidden="true">
						<?php if ( '' !== $icon ) : ?>
							<span class="<?php echo esc_attr( $icon ); ?>"></span>
						<?php endif; ?>
					</span>
					<?php if ( '' !== $title || '' !== $desc ) : ?>
						<span class="cafw-info-list__content">
							<?php if ( '' !== $title ) : ?>
								<<?php echo esc_attr( $title_tag ); ?> class="cafw-info-list__title"<?php echo $title_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- style_attr escapes internally. ?>><?php echo esc_html( $title ); ?></<?php echo esc_attr( $title_tag ); ?>>
							<?php endif; ?>
							<?php if ( '' !== $desc ) : ?>
								<span class="cafw-info-list__desc"<?php echo $desc_attr; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- style_attr escapes internally. ?>><?php echo wp_kses_post( $desc ); ?></span>
							<?php endif; ?>
						</span>
					<?php endif; ?>
				</<?php echo esc_attr( $tag ); ?>>
				<?php
			}
			?>
		</div>
		<?php
		return ob_get_clean();
	}
}
