<?php

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

if ( !class_exists( 'Reon' ) ) {

    return;
}

if ( !class_exists( 'Pricely_Admin_Data_List_CountDown_Inline_Designs' ) ) {

    class Pricely_Admin_Data_List_CountDown_Inline_Designs {

        private static $instance = null;

        public static function get_instance(): self {

            if ( null == self::$instance ) {

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

            return self::$instance;
        }

        public function get_data( $result, $pricely_settings ) {

            $options = array();

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

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

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

            foreach ( $options as $option ) {

                $result[ 'inline_' . $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__( 'Countdown - Style 1', 'pricely-dynamic-pricing-cart-discounts' );
        }

        private function get_default_options() {

            return array(
                array(
                    'admin_note' => esc_html__( 'Countdown - Style 1', 'pricely-dynamic-pricing-cart-discounts' ),
                    'ui_id' => '2234343',
                ),
            );
        }

    }

}