<?php

if ( !defined( 'ABSPATH' ) ) {

    exit;
}

if ( !class_exists( 'Pricely_Pipeline_View_Positions' ) ) {

    require_once 'view-positions-shop.php';
    require_once 'view-positions-single-product.php';
    require_once 'view-positions-shortcode.php';

    class Pricely_Pipeline_View_Positions {

        private static $instance;
        private $pipeline_product;
        private $views;

        public static function get_instance(): self {

            if ( !self::$instance ) {

                self::$instance = new self();
            }
            

            return self::$instance;
        }

        public function get_view_position_by_id( $page_id, $position_id ) {

            $view_positions = $this->get_view_positions();
           
            if ( isset( $view_positions[ $page_id ][ $position_id ] ) ) {
            
                return $view_positions[ $page_id ][ $position_id ];
            }

            return false;
        }

        public function get_views_by_position( $page_id, $position_id, $product, $variation = null ) {

            if ( is_null( $this->pipeline_product ) ) {

                $this->pipeline_product = Pricely_Pipeline_Product::get_instance();
            }
            
            $views = $this->pipeline_product->get_views( $page_id, $position_id, $product, $variation );
            
            if ( !$views ) {

                return false;
            }

            return $views;
        }
        
        public function render_view( $view_data ) {

            if ( is_null( $this->views ) ) {

                $this->views = Pricely_Views::get_instance();
            }

            return $this->views->render_view( $view_data );
        }

        private function get_view_positions() {

            return Pricely_Views::get_instance()->get_view_positions();
        }

    }

    Pricely_Pipeline_View_Positions::get_instance();
    Pricely_Pipeline_View_Position_Shop::get_instance();
    Pricely_Pipeline_View_Position_Single_Product::get_instance();
    Pricely_Pipeline_View_Position_Shortcode::get_instance();
}

