<?php
    /**
     * Colors Section
     * 
     * @package Blog Bee
     * @since 1.0.0
     */
    namespace BBE\Customizer\Section;

    use BBE\Customizer\Section\Section as Section;
    use BBE\Customizer\Theme_Defaults as Theme_Defaults;
    use BBE\Helpers as Helpers;

    use function esc_html__;
    use function esc_attr;

    if( ! class_exists( __NAMESPACE__ . '\\Colors' ) ) {
        /**
         * Colors class
         */
        class Colors extends Section {
            /**
             * Section Id
             * 
             * @since 1.0.0
             * @var string
             */
            public static $id = 'bbe-colors';

            /**
             * Register controls
             * 
             * @since 1.0.0
             */
            public function register_controls() {
                $this->tab = 'general';
                $this->section = 'colors';
                $this->manager->get_section( $this->section )->title = esc_html__( 'Theme Colors / Presets', 'blog-bee' );
                $this->manager->get_section( $this->section )->panel = 'colors_panel';
                $this->add_control( 'solid_theme_color' );
                $this->add_control( 'gradient_theme_color' );
                $this->add_control( 'site_links_color' );
                $this->add_control( 'site_heading_color' );
                $this->add_control( 'site_body_text_color' );
                $this->add_control( 'solid_color_palette' );
                $this->add_control( 'gradient_color_palette' );

            }

            /**
             * Settings
             * 
             * @since 1.0.0
             */
            public function get_settings( $id = '' ) {
                $settings = [
                    'solid_theme_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'gradient_theme_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'site_links_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'site_heading_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'site_body_text_color' =>  [
                        'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'solid_color_palette' =>  [
                        // 'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                    'gradient_color_palette' =>  [
                        // 'sanitize_callback' =>  [ $this, 'sanitize_color' ],
                        'transport' =>  'postMessage',
                        'default'   =>  Theme_Defaults::get_defaults( $id )
                    ],
                ];
                return $id ? $settings[ $id ] : $settings;
            }

            /**
             * Controls
             * 
             * @since 1.0.0
             */
            public function get_controls( $id = '' ) {
                $controls = [
                    'solid_theme_color' =>  [
                        'label' =>  esc_html__( 'Theme Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_preset' => false,
                    ],
                    'gradient_theme_color' =>  [
                        'label' =>  esc_html__( 'Gradient Theme Color', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                        'include_preset' => false,
                        'color_types' => [ 'gradient' ]
                    ],
                    'site_links_color' =>  [
                        'label' =>  esc_html__( 'Links Color', 'blog-bee' ),
                        'description' =>  esc_html__( 'Affects all the clickable texts except headings(h1-h6).', 'blog-bee' ),
                        'include_hover' =>  true,
                        'type'  =>  'bbe-color',
                    ],
                    'site_heading_color' =>  [
                        'label' =>  esc_html__( 'Heading(H1-H6) Color', 'blog-bee' ),
                        'description' =>  esc_html__( 'Affects only the heading tags.', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                    ],
                    'site_body_text_color' =>  [
                        'label' =>  esc_html__( 'Body Color', 'blog-bee' ),
                        'description' =>  esc_html__( 'Affects all the non clickable text like paragraphs.', 'blog-bee' ),
                        'type'  =>  'bbe-color',
                    ],
                    'solid_color_palette' =>  [
                        'label' =>  esc_html__( 'Solid Color Palette', 'blog-bee' ),
                        'type'  =>  'bbe-color-palette'
                    ],
                    'gradient_color_palette' =>  [
                        'label' =>  esc_html__( 'Gradient Color Palette', 'blog-bee' ),
                        'type'  =>  'bbe-color-palette',
                        'color_type'    =>  'gradient'
                    ],
                ];
                return $id ? $controls[ $id ] : $controls;
            }

            /**
             * Defaults
             * 
             * @since 1.0.0
             */
            public function set_defaults() {
                Theme_Defaults::update_theme_defaults( [
                    'solid_theme_color' => $this->get_color( [ 'value' => '#E78371' ] ),
                    'gradient_theme_color' => $this->get_color( [
                        'type'  =>  'gradient',
                        'value' =>  'linear-gradient(90deg, #2563eb, #06b6d4)',
                    ] ),
                    'site_links_color' => [
                        'initial'   =>  $this->get_color( [ 'value' => '' ] ),
                        'hover'     =>  $this->get_color( [ 'value' => '' ] )
                    ],
                    'site_heading_color' => $this->get_color( [ 'value' => '#30344b' ] ),
                    'site_body_text_color' => $this->get_color( [ 'value' => '#50565e' ] ),
                    'solid_color_palette'   =>  [
                        'palettes'   =>  [
                            'one'   =>  [ '#2323FF', '#807D52', '#FFBD24', '#FFF224', '#FF5733', '#2ECC71', '#9B59B6', '#1ABC9C', '#E74C3C', '#3498DB', null, null ],
                            'two'   =>  [ '#2323FF', '#24AEFF', '#C04AFF', '#7E3DFF', '#5A2FE0', '#3D8BFF', '#9C4AE6', '#6A5ACD', '#4169E1', '#A04AFF', null, null ],
                            'three' =>  [ '#E0AFFF', '#C4D6FF', '#DD68E3', '#8866DE', '#B89CE8', '#E8B8E0', '#9DB8F0', '#C77FD4', '#7E6FE0', '#D4A8F0', null, null ],
                            'four'  =>  [ '#FF634A', '#D2D2D4', '#E7E7E7', '#F4F4F6', '#FF8A6E', '#B8B8BA', '#FFAB94', '#9A9A9C', '#FFC9B8', '#E0E0E2', null, null ],
                            'five'  =>  [ '#2C4C5C', '#6C8494', '#B8BFC1', '#F3E308', '#3D6478', '#8FA0AC', '#D6CC4A', '#1E3640', '#A8B0A8', '#5C7484', null, null ],
                            'six'   =>  [ '#252525', '#CFCFCF', '#7D7D7D', '#545454', '#3A3A3A', '#9A9A9A', '#1A1A1A', '#B5B5B5', '#666666', '#E0E0E0', null, null ],
                            'seven' =>  [ '#FFDBBB', '#CCBEB1', '#997E67', '#664930', '#4A3320', '#B89A7C', '#E0C29C', '#80604A', '#D9B896', '#523A22', null, null ],
                            'eight' =>  [ '#7B9669', '#6C8480', '#E6E6E6', '#BAC8B1', '#404E3B', '#8FA67A', '#5A7058', '#D4DECB', '#324530', '#486238', null, null ],
                            'nine'  =>  [ '#0474C4', '#5379AE', '#2C444C', '#A8C4EC', '#06457F', '#262B40', '#3C8FD4', '#1A2E50', '#5ca8ec', '#2c4570', null, null ],
                            'ten'   =>  [ '#805232', '#326080', '#B5D2E6', '#FFF1E7', '#4A7C9E', '#A86B40', '#D8E8F0', '#6B4226', '#3D6B8C', '#C98E5C', null, null ],
                        ],
                        'active' => 'one'
                    ],
                    'gradient_color_palette'   =>  [
                        'palettes'   =>  [
                            'one' => [
                                'linear-gradient(90deg, #1a1acc, #4d4dff)',
                                'linear-gradient(90deg, #66643f, #99966b)',
                                'linear-gradient(90deg, #cc971c, #ffd24d)',
                                'linear-gradient(90deg, #ccc91c, #ffff4d)',
                                'linear-gradient(90deg, #cc6b1a, #ff9a4d)',
                                'linear-gradient(90deg, #2d8a3e, #5fc26e)',
                                'linear-gradient(90deg, #7a3acc, #a86aff)',
                                'linear-gradient(90deg, #1a9ecc, #4dcfff)',
                                'linear-gradient(90deg, #b3331c, #ff664d)',
                                'linear-gradient(90deg, #1a6dcc, #4d9fff)',
                                null, null,
                            ],
                            'two' => [
                                'linear-gradient(90deg, #1a1acc, #4d4dff)',
                                'linear-gradient(90deg, #1c8acc, #4dc2ff)',
                                'linear-gradient(90deg, #9a3bcc, #d86aff)',
                                'linear-gradient(90deg, #5f2dcc, #9d66ff)',
                                'linear-gradient(90deg, #3a1ab3, #6a4dff)',
                                'linear-gradient(90deg, #1c5ecc, #4d96ff)',
                                'linear-gradient(90deg, #7e1ccc, #b14dff)',
                                'linear-gradient(90deg, #4a6acc, #7d9eff)',
                                'linear-gradient(90deg, #2c1ccc, #5d4dff)',
                                'linear-gradient(90deg, #a01ccc, #d34dff)',
                                null, null,
                            ],
                            'three' => [
                                'linear-gradient(90deg, #b38ccc, #f0c2ff)',
                                'linear-gradient(90deg, #9db0cc, #d6e4ff)',
                                'linear-gradient(90deg, #b653b6, #ff7cff)',
                                'linear-gradient(90deg, #6a52b3, #a58cff)',
                                'linear-gradient(90deg, #8c6ab3, #c2a3ff)',
                                'linear-gradient(90deg, #b38ca8, #ffc2e9)',
                                'linear-gradient(90deg, #7c9dcc, #b0d6ff)',
                                'linear-gradient(90deg, #a073c2, #d6a8ff)',
                                'linear-gradient(90deg, #5e6ab3, #93a3ff)',
                                'linear-gradient(90deg, #c294d6, #ffc9ff)',
                                null, null,
                            ],
                            'four' => [
                                'linear-gradient(90deg, #cc4f3b, #ff7a66)',
                                'linear-gradient(90deg, #a8a8aa, #f0f0f2)',
                                'linear-gradient(90deg, #bcbcbc, #ffffff)',
                                'linear-gradient(90deg, #c8c8ca, #ffffff)',
                                'linear-gradient(90deg, #cc7a66, #ffa896)',
                                'linear-gradient(90deg, #969698, #d4d4d6)',
                                'linear-gradient(90deg, #cc998c, #ffc9bc)',
                                'linear-gradient(90deg, #828284, #b8b8ba)',
                                'linear-gradient(90deg, #ccb3ab, #ffe2d9)',
                                'linear-gradient(90deg, #aeaeb0, #e8e8ea)',
                                null, null,
                            ],
                            'five' => [
                                'linear-gradient(90deg, #223c49, #3d6a7a)',
                                'linear-gradient(90deg, #566a77, #8fa5b3)',
                                'linear-gradient(90deg, #92999b, #dce2e4)',
                                'linear-gradient(90deg, #c2b806, #fff933)',
                                'linear-gradient(90deg, #2f5266, #4d869c)',
                                'linear-gradient(90deg, #748c99, #aac0cc)',
                                'linear-gradient(90deg, #a89c0c, #d6c93d)',
                                'linear-gradient(90deg, #1a2e38, #335c70)',
                                'linear-gradient(90deg, #8c9690, #c2ccc6)',
                                'linear-gradient(90deg, #4a6272, #7396a3)',
                                null, null,
                            ],
                            'six' => [
                                'linear-gradient(90deg, #1b1b1b, #3a3a3a)',
                                'linear-gradient(90deg, #a6a6a6, #ffffff)',
                                'linear-gradient(90deg, #646464, #969696)',
                                'linear-gradient(90deg, #444444, #6a6a6a)',
                                'linear-gradient(90deg, #2e2e2e, #525252)',
                                'linear-gradient(90deg, #8a8a8a, #c2c2c2)',
                                'linear-gradient(90deg, #121212, #2a2a2a)',
                                'linear-gradient(90deg, #b8b8b8, #e8e8e8)',
                                'linear-gradient(90deg, #525252, #7a7a7a)',
                                'linear-gradient(90deg, #d6d6d6, #ffffff)',
                                null, null,
                            ],
                            'seven' => [
                                'linear-gradient(90deg, #ccaf96, #ffe7cc)',
                                'linear-gradient(90deg, #a3978d, #e0d4c7)',
                                'linear-gradient(90deg, #7a6654, #b89a7d)',
                                'linear-gradient(90deg, #4d3724, #805a3c)',
                                'linear-gradient(90deg, #3d2918, #6a4730)',
                                'linear-gradient(90deg, #967a5e, #c9a37d)',
                                'linear-gradient(90deg, #c2997a, #f0c7a3)',
                                'linear-gradient(90deg, #6a4d38, #a3795a)',
                                'linear-gradient(90deg, #b89373, #e8c2a0)',
                                'linear-gradient(90deg, #44301f, #735338)',
                                null, null,
                            ],
                            'eight' => [
                                'linear-gradient(90deg, #637a54, #93b37f)',
                                'linear-gradient(90deg, #566a66, #8fa5a0)',
                                'linear-gradient(90deg, #bcbcbc, #ffffff)',
                                'linear-gradient(90deg, #96a08d, #d3ddca)',
                                'linear-gradient(90deg, #2f3a2c, #596b52)',
                                'linear-gradient(90deg, #7a9268, #a8c294)',
                                'linear-gradient(90deg, #485c46, #74916c)',
                                'linear-gradient(90deg, #c2cdb8, #eef2e8)',
                                'linear-gradient(90deg, #28361f, #486238)',
                                'linear-gradient(90deg, #6e8862, #a0bd8e)',
                                null, null,
                            ],
                            'nine' => [
                                'linear-gradient(90deg, #035ca0, #2a8be0)',
                                'linear-gradient(90deg, #3f5c86, #6f95d0)',
                                'linear-gradient(90deg, #22353b, #3e5c66)',
                                'linear-gradient(90deg, #7fa0c6, #d1e2ff)',
                                'linear-gradient(90deg, #04365f, #0a5fa8)',
                                'linear-gradient(90deg, #1b1f30, #3a4160)',
                                'linear-gradient(90deg, #2c75b8, #5ca8ec)',
                                'linear-gradient(90deg, #15243f, #2c4570)',
                                'linear-gradient(90deg, #4a7fae, #82b4e0)',
                                'linear-gradient(90deg, #0a2540, #1c4a78)',
                                null, null,
                            ],
                            'ten' => [
                                'linear-gradient(90deg, #664229, #a36a42)',
                                'linear-gradient(90deg, #284d66, #4d8fb3)',
                                'linear-gradient(90deg, #8fa8b8, #e0f0ff)',
                                'linear-gradient(90deg, #ccc1b8, #ffffff)',
                                'linear-gradient(90deg, #3d6088, #5fa3cc)',
                                'linear-gradient(90deg, #82542e, #b8825a)',
                                'linear-gradient(90deg, #c2d8e6, #eef7ff)',
                                'linear-gradient(90deg, #4d2f1a, #7d5232)',
                                'linear-gradient(90deg, #5a8aab, #8fc0e0)',
                                'linear-gradient(90deg, #9c6d3f, #c89a6a)',
                                null, null,
                            ],
                        ],
                        'active' => 'one'
                    ],
                ] );
            }

            /**
             * Get dynamic css args
             * 
             * @since 1.0.0
             */
            public function get_dynamic_css_args(): array {
                $dynamic_args = [
                    'solid_theme_color'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'solid_theme_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'solid_theme_color' ),
                        'selector'  =>  'body',
                        'property'  =>  '--bbe-theme-color'
                    ],
                    'gradient_theme_color'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'gradient_theme_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'gradient_theme_color' ),
                        'selector'  =>  '.bbe-light',
                        'property'  =>  '--bbe-site-bg-color'
                    ],
                    'site_links_color'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'site_links_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'site_links_color' ),
                        'selector'  =>  'body.bbe-light .site .bbe-article .entry-meta > div a, body.bbe-light .site .bbe-ticker-news .bbe-article .post-date a',
                        'property'  =>  '--bbe-site-meta-color'
                    ],
                    'site_heading_color'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'site_heading_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'site_heading_color' ),
                        'selector'  =>  '.bbe-light h1, .bbe-light h2, .bbe-light h3, .bbe-light h4, .bbe-light h5, .bbe-light h6, .bbe-light .entry-title a, .bbe-light .site .widget-area .bbe-article h1 a, .bbe-light .site .widget-area .bbe-article h2 a, .bbe-light .site .widget-area .bbe-article h3 a, .bbe-light .site .widget-area .bbe-article h4 a, .bbe-light .site .widget-area .bbe-article h5 a, .bbe-light .site .widget-area .bbe-article h6 a',
                        'property'  =>  '--bbe-site-color'
                    ],
                    'site_body_text_color'    =>  [
                        'value' =>  Theme_Defaults::get_theme_option( 'site_body_text_color' ),
                        'default' =>  Theme_Defaults::get_defaults( 'site_body_text_color' ),
                        'selector'  =>  'body.bbe-light',
                        'property'  =>  '--bbe-site-excerpt-color'
                    ],
                ];
                return $dynamic_args;
            }

            /**
             * Render HTML
             * 
             * @since 1.0.0
             */
            public function render_html() {}
        }
        Colors::get_instance();
    }