<?php

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

if ( !class_exists( 'Reon' ) ) {

    return;
}

if ( !class_exists( 'Pricely_Admin_Data_List_Price_Table_Designs' ) ) {

    class Pricely_Admin_Data_List_Price_Table_Designs {

        private $source_type;

        public function __construct() {

            $this->source_type = 'price_table_designs';
        }
        
        public function can_get_data( $source ) {

            return $this->source_type == $source;
        }

        public function get_data( $result, $data_args ) {

            global $pricely_settings;

            $options = array();

            if ( isset( $pricely_settings[ 'ui_pricing_tables' ] ) ) {

                $options = $pricely_settings[ 'ui_pricing_tables' ];
            } else {

                $options = $this->get_default_options();
            }

            foreach ( $options as $option ) {

                $result[ $option[ 'ui_id' ] ] = $this->get_title( $option );
            }

            return $result;
        }

        private function get_title( $option ) {

            if ( !empty( $option[ 'admin_note' ] ) ) {

                return $option[ 'admin_note' ];
            }

            return $this->get_default_title( $option[ 'ui_id' ] );
        }

        private function get_default_title( $option_id ) {

            foreach ( $this->get_default_options() as $option ) {

                if ( $option_id == $option[ 'ui_id' ] ) {

                    return $option[ 'admin_note' ];
                }
            }

            return esc_html__( 'Product Pricing Table', 'pricely-dynamic-pricing-cart-discounts' );
        }

        private function get_default_options() {

            return array(
                array(
                    'admin_note' => esc_html__( 'Product Pricing Table', 'pricely-dynamic-pricing-cart-discounts' ),
                    'ui_id' => '2234343',
                ),
            );
        }

    }

}

