<?php

if ( !defined( 'ABSPATH' ) ) {

    exit;
}

if ( !class_exists( 'Pricely_Views_CSS_Util' ) ) {

    class Pricely_Views_CSS_Util {

        private static $instance;

        public static function get_instance(): self {

            if ( !self::$instance ) {

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

            return self::$instance;
        }

        public function get_size_css_prop( $ui_size = array(), $default = '', $use_force = false, $size_key = 'size' ) {

            $important = '';

            if ( $use_force ) {
                $important = '!important';
            }

            if ( !isset( $ui_size[ $size_key ] ) || '' == $ui_size[ $size_key ] ) {

                return $default . $important;
            }

            if ( !isset( $ui_size[ 'unit' ] ) || empty( $ui_size[ 'unit' ] ) ) {

                $ui_size[ 'unit' ] = 'px';
            }

            return $ui_size[ $size_key ] . $ui_size[ 'unit' ] . $important;
        }

        public function get_sides_size_css_prop( $ui_sides_size = array(), $default = array(), $use_force = false ) {

            $important = '';

            if ( $use_force ) {
                $important = '!important';
            }


            $unit = 'px';

            if ( isset( $ui_sides_size[ 'unit' ] ) && !empty( $ui_sides_size[ 'unit' ] ) ) {

                $unit = $ui_sides_size[ 'unit' ];
            }

            $top_bottom = $this->get_boundary_side( 'top_bottom', $ui_sides_size, $unit, $default );
            $left_right = $this->get_boundary_side( 'left_right', $ui_sides_size, $unit, $default );


            return $top_bottom . ' ' . $left_right;
        }

        public function get_boundary_css_prop( $ui_boundary_size = array(), $default = array(), $use_force = false ) {

            $important = '';

            if ( $use_force ) {

                $important = '!important';
            }


            $unit = 'px';

            if ( isset( $ui_boundary_size[ 'unit' ] ) && !empty( $ui_boundary_size[ 'unit' ] ) ) {

                $unit = $ui_boundary_size[ 'unit' ];
            }

            $top = $this->get_boundary_side( 'top', $ui_boundary_size, $unit, $default );
            $right = $this->get_boundary_side( 'right', $ui_boundary_size, $unit, $default );
            $bottom = $this->get_boundary_side( 'bottom', $ui_boundary_size, $unit, $default );
            $left = $this->get_boundary_side( 'left', $ui_boundary_size, $unit, $default );

            return $top . ' ' . $right . ' ' . $bottom . ' ' . $left;
        }

        private function get_boundary_side( $side, $ui_boundary_size, $unit, $default ) {


            if ( !isset( $ui_boundary_size[ $side ] ) || '' == $ui_boundary_size[ $side ] ) {

                if ( !is_array( $default ) ) {

                    return $default;
                }

                if ( 1 == count( $default ) ) {

                    return $default[ 0 ];
                }

                if ( isset( $default[ $side ] ) ) {

                    return $default[ $side ];
                }

                return '';
            } else {

                return $ui_boundary_size[ $side ] . $unit;
            }
        }

        private function get_options( $options ) {

            return Pricely::get_instance()->get_options( $this->option_key, $this->get_default_options(), $options );
        }

        public function get_theme_prop( $key ) {

            $theme_values = array(
                'accent_color_3' => '#efa400',
                'accent_color_4' => '#57bf6d',
                'color_1' => '#222',
                'color_2' => '#999',
                'color_3' => '#ddd',
                'color_4' => '#eee',
                'color_5' => '#fff',
            );

            return $theme_values[ $key ];
        }

    }

}