<?php
namespace Elementor;

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

class Rivax_Elementor_Sticky_Section {

    /**
     * A reference to an instance of this class.
     */
    private static $instance = null;


    public function __construct(){

        add_action( 'elementor/element/container/section_layout/after_section_end', array( $this, 'container_settings' ) );
        add_action( 'elementor/frontend/container/before_render',  array( $this, 'container_before_render' ) );


    }


    /**
     * Returns the instance.
     *
     * @since  1.0.0
     * @access public
     * @return object
     */
    public static function get_instance() {
        // If the single instance hasn't been set, set it now.
        if ( null == self::$instance ) {
            self::$instance = new self;
        }
        return self::$instance;
    }

    public function container_settings ( $element ) {

        $element->start_controls_section(
            'rivax_container_sticky_section',
            array(
                'label' => esc_html__( 'Sticky Section', 'newsfy' ),
                'tab'   => Controls_Manager::TAB_ADVANCED,
            )
        );

        $element->add_control(
            'rivax_sticky_column_enable',
            [
                'label'        => esc_html__( 'Sticky Column', 'newsfy' ),
                'type'         => Controls_Manager::SWITCHER,
            ]
        );

        $element->end_controls_section();

    }


    /**
     * Before container render callback.
     *
     * @param object $element
     *
     * @return void
     */
    public function container_before_render( $element ) {
        $data     = $element->get_data();
        $settings = $data['settings'];

        if ( !empty($settings['rivax_sticky_column_enable']) ) {

            $element->add_render_attribute( '_wrapper', array(
                'class' => 'rivax-sticky-column',
            ) );
        }
    }

}

Rivax_Elementor_Sticky_Section::get_instance();
