<?php
$col_xs = $widget->get_setting('col_xs', '');
$col_sm = $widget->get_setting('col_sm', '');
$col_md = $widget->get_setting('col_md', '');
$col_lg = $widget->get_setting('col_lg', '');
$col_xl = $widget->get_setting('col_xl', '');

$col_xl = 12 / intval($col_xl);
$col_lg = 12 / intval($col_lg);
$col_md = 12 / intval($col_md);
$col_sm = 12 / intval($col_sm);
$col_xs = 12 / intval($col_xs);

$grid_sizer = "col-xl-{$col_xl} col-lg-{$col_lg} col-md-{$col_md} col-sm-{$col_sm} col-{$col_xs}";
$item_class = "pxl-grid-item col-xl-{$col_xl} col-lg-{$col_lg} col-md-{$col_md} col-sm-{$col_sm} col-{$col_xs}";
?>
<?php if(isset($settings['meta']) && !empty($settings['meta']) && count($settings['meta'])):
    $is_new = \Elementor\Icons_Manager::is_migration_allowed(); ?>
    <div class="pxl-grid pxl-meta-grid pxl-meta-grid1" data-layout="<?php echo esc_attr($settings['data_layout']); ?>">
        <div class="pxl-grid-inner pxl-grid-masonry row" data-gutter="15">
            <?php foreach ($settings['meta'] as $key => $value):
                $icon_key = $widget->get_repeater_setting_key( 'pxl_icon', 'icons', $key );
                $widget->add_render_attribute( $icon_key, [
                    'class' => $value['pxl_icon'],
                    'aria-hidden' => 'true',
                ] );
    			$title = isset($value['title']) ? $value['title'] : '';
                $title_link1 = isset($value['title_link1']) ? $value['title_link1'] : '';
                $title_link2 = isset($value['title_link2']) ? $value['title_link2'] : '';
                $link_key = $widget->get_repeater_setting_key( 'item_link', 'value', $key );
                if ( ! empty( $value['item_link']['url'] ) ) {
                    $widget->add_render_attribute( $link_key, 'href', $value['item_link']['url'] );

                    if ( $value['item_link']['is_external'] ) {
                        $widget->add_render_attribute( $link_key, 'target', '_blank' );
                    }

                    if ( $value['item_link']['nofollow'] ) {
                        $widget->add_render_attribute( $link_key, 'rel', 'nofollow' );
                    }
                }
                $link_attributes = $widget->get_render_attribute_string( $link_key );
                $link_key = $widget->get_repeater_setting_key( 'item_link2', 'value', $key );
                if ( ! empty( $value['item_link2']['url'] ) ) {
                    $widget->add_render_attribute( $link_key, 'href', $value['item_link2']['url'] );

                    if ( $value['item_link2']['is_external'] ) {
                        $widget->add_render_attribute( $link_key, 'target', '_blank' );
                    }

                    if ( $value['item_link2']['nofollow'] ) {
                        $widget->add_render_attribute( $link_key, 'rel', 'nofollow' );
                    }
                }
                $link_attributes2 = $widget->get_render_attribute_string( $link_key );
                ?>
                <div class="<?php echo esc_attr($item_class); ?>">
                    <div class="pxl-item--inner <?php echo esc_attr($settings['pxl_animate']); ?>">
                        <?php if ( ! empty( $value['pxl_icon'] ) ) : ?>
                            <div class="pxl-item--icon pxl-mr-33">
                                <?php if ( $is_new ):
                                    \Elementor\Icons_Manager::render_icon( $value['pxl_icon'], [ 'aria-hidden' => 'true' ] );
                                elseif(!empty($value['pxl_icon'])): ?>
                                    <i class="<?php echo esc_attr( $value['pxl_icon'] ); ?>" aria-hidden="true"></i>
                                <?php endif; ?>
                            </div>
                        <?php endif; ?>
                        <div class="pxl-item--holder">
                            <h5 class="pxl-item--title">
                                <?php echo pxl_print_html($title); ?>
                            </h5>
                            <a class="pxl-item-link" <?php echo implode( ' ', [ $link_attributes ] ); ?>><?php echo pxl_print_html($title_link1); ?></a>
                            <a class="pxl-item-link" <?php echo implode( ' ', [ $link_attributes2 ] ); ?>><?php echo pxl_print_html($title_link2); ?></a>
                        </div>
                   </div>
                </div>
            <?php endforeach; ?>
            <div class="grid-sizer <?php echo esc_attr($grid_sizer); ?>"></div>
        </div>
    </div>
<?php endif; ?>
