<?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}";
$html_id = pxl_get_element_id($settings);
?>
<?php if(isset($settings['box_lv3']) && !empty($settings['box_lv3']) && count($settings['box_lv3'])): ?>
<div class="pxl-grid pxl-box-grid pxl-box-grid3" data-layout="<?php echo esc_attr($settings['data_layout']); ?>">
    <div class="pxl-inner-change">
        <div class="bgr-change"></div>
    </div>
    <div class="pxl-grid-inner pxl-grid-masonry row" data-gutter="15">
        <?php foreach ($settings['box_lv3'] as $key => $value):
            $title_lv3 = isset($value['title_lv3']) ? $value['title_lv3'] : '';
            $title_content = isset($value['title_content']) ? $value['title_content'] : '';
            $desc_lv3 = isset($value['desc_lv3']) ? $value['desc_lv3'] : '';
            $image_lv3 = isset($value['image_lv3']) ? $value['image_lv3'] : '';
            $title_btn = isset($value['title_btn']) ? $value['title_btn'] : '';
            $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 );

            // Xử lý video link nếu có
            if ( ! empty( $value['video_link']['url'] ) ) {
                $widget->add_render_attribute( 'video_link', 'href', $value['video_link']['url'] );

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

                if ( $value['video_link']['nofollow'] ) {
                    $widget->add_render_attribute( 'video_link', 'rel', 'nofollow' );
                }
            }
            ?>
            <div id="<?php echo esc_attr($html_id.$key); ?>" class="<?php echo esc_attr($item_class); ?>" style="background-image: url(<?php echo esc_attr($value['image_lv3']['url']); ?>);">
                <div class="pxl-item-box">
                    <div class="wrap-inner-content">
                        <div class="pxl-item--inner">
                            <div class="pxl-item--content">
                                <div class="pxl-box-top">
                                    <div class="pxl-content-title">
                                        <div class="pxl-title-content">
                                            <?php echo pxl_print_html($title_content); ?>
                                        </div>
                                    </div>
                                    <div class="pxl-desc-btn">
                                        <div class="pxl-item-desc">
                                            <?php echo pxl_print_html($desc_lv3); ?>
                                        </div>
                                        <div class="pxl-item-btn">
                                            <a <?php echo implode( ' ', [ $link_attributes ] ); ?>>
                                                <span class="pxl--btn-text">
                                                    <?php echo pxl_print_html($title_btn); ?>
                                                </span>
                                                <span class="pxl-btn-icon pxl-ml-10">
                                                    <svg xmlns="http://www.w3.org/2000/svg" fill="#000" height="512" viewBox="0 0 24 24" width="512"><path d="m16.0039 9.414-8.60699 8.607-1.414-1.414 8.60599-8.607h-7.58499v-2h10.99999v11h-2z" fill="rgb(0,0,0)"></path></svg>
                                                </span>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                <div id="<?php echo esc_attr($html_id) ?>" class="pxl-button-video">
                                    <div class="pxl-item--inner">
                                        <div class="pxl-item--video">
                                            <?php if ( ! empty( $value['video_link']['url'] ) ) { ?><a class="pxl-btn-video pxl-action-popup" <?php pxl_print_html($widget->get_render_attribute_string( 'video_link' )); ?>><?php } ?>
                                                <span><i class="caseicon-play1"></i></span>
                                            <?php if ( ! empty( $value['video_link']['url'] ) ) { ?></a><?php } ?>
                                        </div>
                                    </div>
                                </div>
                                
                            </div>
                            <div class="pxl-inner-content">
                                <span class="pxl-item--title">
                                    <span class="pxl-item--icon pxl-mr-10">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="#000000" viewBox="0 0 256 256"><path d="M229.66,77.66l-128,128a8,8,0,0,1-11.32,0l-56-56a8,8,0,0,1,11.32-11.32L96,188.69,218.34,66.34a8,8,0,0,1,11.32,11.32Z"></path></svg>
                                    </span>
                                    <span>
                                        <?php echo pxl_print_html($title_lv3); ?>
                                    </span>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
        <div class="grid-sizer <?php echo esc_attr($grid_sizer); ?>"></div>
    </div>
</div>
<?php endif; ?>
