<?php
pxl_add_custom_widget(
    array(
        'name' => 'pxl_chart',
        'title' => esc_html__('Case Chart', 'hubsteel' ),
        'icon' => 'eicon-accordion',
        'categories' => array('pxltheme-core'),
        'scripts' => array(
            'pxl-chart',
            'chart',
        ),
        'params' => array( 
            'sections' => array(
                array(
                    'name' => 'section_layout',
                    'label' => esc_html__('Layout', 'hubsteel' ),
                    'tab' => \Elementor\Controls_Manager::TAB_LAYOUT,
                    'controls' => array(
                        array(
                            'name' => 'layout',
                            'label' => esc_html__('Templates', 'hubsteel' ),
                            'type' => 'layoutcontrol',
                            'default' => '1',
                            'options' => [
                                '1' => [
                                    'label' => esc_html__('Layout 1', 'hubsteel' ),
                                    'image' => get_template_directory_uri() . '/elements/widgets/img-layout/pxl_chart/layout1.jpg'
                                ],
                                '2' => [
                                    'label' => esc_html__('Layout 2', 'hubsteel' ),
                                    'image' => get_template_directory_uri() . '/elements/widgets/img-layout/pxl_chart/layout2.jpg'
                                ],
                            ],
                        ),
                    ),
                ),
                array(
                    'name'     => 'chart_section',
                    'label'    => esc_html__( 'Chart Content', 'hubsteel' ),
                    'tab'      => \Elementor\Controls_Manager::TAB_CONTENT,
                    'controls' => array_merge(
                        array(
                            array(
                                'name'    => 'pxl_chart',
                                'label'   => esc_html__( 'Chart Items', 'hubsteel' ),
                                'type'    => \Elementor\Controls_Manager::REPEATER,
                                'controls' => array(

                                    // array(
                                    //     'name'  => 'label_line_title',
                                    //     'label' => esc_html__( 'Label Line Chart', 'hubsteel' ),
                                    //     'type'  => \Elementor\Controls_Manager::TEXT,
                                    // ),
                                    array(
                                        'name'  => 'chart_title',
                                        'label' => esc_html__( 'Title', 'hubsteel' ),
                                        'type'  => \Elementor\Controls_Manager::TEXT,
                                    ),
                                    array(
                                        'name'  => 'chart_value',
                                        'label' => esc_html__( 'Value', 'hubsteel' ),
                                        'type'  => \Elementor\Controls_Manager::NUMBER,
                                    ),
                                    array(
                                        'name'  => 'chart_color',
                                        'label' => esc_html__( 'Color', 'hubsteel' ),
                                        'type'  => \Elementor\Controls_Manager::COLOR, 
                                    ),
                                    
                                ),
                                'default' => [
                                    [
                                        'chart_title'      => 'Retail',
                                        'chart_value'      => 40,
                                        'chart_color'      => '#9bcb3b',
                                    ],
                                    [
                                        'chart_title'      => 'Sciences',
                                        'chart_value'      => 20,
                                        'chart_color'      => '#5553ce',
                                    ],
                                    [
                                        'chart_title'      => 'Industrial',
                                        'chart_value'      => 15,
                                        'chart_color'      => '#f13a30',
                                    ],
                                    [
                                        'chart_title'      => 'Power',
                                        'chart_value'      => 15,
                                        'chart_color'      => '#f8a137',
                                    ],
                                    [
                                        'chart_title'      => 'Oil & Gas',
                                        'chart_value'      => 10,
                                        'chart_color'      => '#1875f0',
                                    ]
                                ],
                                'title_field' => '{{{ chart_title }}} ({{{ chart_value }}})',
                                'separator'   => 'after',
                            ),
                            array(
                                'name' => 'h_width',
                                'label' => esc_html__('Max Width', 'hubsteel' ),
                                'type' => \Elementor\Controls_Manager::SLIDER,
                                'control_type' => 'responsive',
                                'size_units' => [ 'px', '%' ],
                                'range' => [
                                    'px' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-chart ' => 'width: {{SIZE}}{{UNIT}} !important;',
                                ],
                            ),
                            array(
                                'name' => 'h_height',
                                'label' => esc_html__('Max Height', 'hubsteel' ),
                                'type' => \Elementor\Controls_Manager::SLIDER,
                                'control_type' => 'responsive',
                                'size_units' => [ 'px', '%' ],
                                'range' => [
                                    'px' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-chart canvas' => 'height: {{SIZE}}{{UNIT}} !important;',
                                ],
                            ),
                        )
)
),
array(
    'name'     => 'style_section',
    'label'    => esc_html__( 'Style Settings', 'hubsteel' ),
    'tab'      => \Elementor\Controls_Manager::TAB_STYLE,
    'controls' => [
        array(
            'name'    => 'pxl_chart_type',
            'label'   => esc_html__( 'Chart Type', 'hubsteel' ),
            'type'    => \Elementor\Controls_Manager::SELECT,
            'condition' => [
                'layout' => ['2'],
            ],
            'options' => array(
                'doughnut'  => __('Doughnut','hubsteel'),
                'bar'  => __('Bar','hubsteel'),
            ),
            'default' => 'doughnut'
        ),
        array(
            'name'  => 'chart_border_color',
            'label' => esc_html__( 'Line Color', 'hubsteel' ),
            'type'  => \Elementor\Controls_Manager::COLOR,
            'condition' => [
                'layout' => ['1'],
            ],
        ),

        array(
            'name'         => 'pxl_chart_dimensions',
            'label'        => esc_html__( 'Chart Dimensions', 'hubsteel' ),
            'type'         => \Elementor\Controls_Manager::SLIDER,
            'control_type' => 'responsive',
            'range' => [
                'px' => [
                    'min' => 100,
                    'max' => 1000,
                ]
            ],
            'condition' => [
                'layout' => ['2'],
            ],
            'default' => [
                'size' => 400
            ],
            'selectors' => [
                '{{WRAPPER}} .pxl-chart canvas' => 'height:{{SIZE}}px !important;',
                '{{WRAPPER}} .pxl-chart .chart-bar' => 'width:{{SIZE}}px !important;',
            ],
            'separator' => 'before'
        ),
        
        array(
            'name'         => 'chart_border_width',
            'label'        => esc_html__( 'Chart Border Width (Line Width) ', 'hubsteel' ),
            'description' => ' Value > 0',
            'type'         => \Elementor\Controls_Manager::NUMBER,
            'control_type' => 'responsive',
            'separator' => 'before'
        ),

        array(
            'name'         => 'pxl_point_width',
            'label'        => esc_html__( 'Chart Point Width (Point Width) ', 'hubsteel' ),
            'description' => ' Value > 0',
            'type'         => \Elementor\Controls_Manager::NUMBER,
            'control_type' => 'responsive',
            'separator' => 'before'
        ),

        array(
            'name'         => 'pxl_point_radius',
            'label'        => esc_html__( 'Chart Point Radius (Point Radius) ', 'hubsteel' ),
            'description' => ' Value > 0',
            'type'         => \Elementor\Controls_Manager::NUMBER,
            'control_type' => 'responsive',
            'separator' => 'before'
        ),

        array(
            'name'         => 'pxl_point_hover',
            'label'        => esc_html__( 'Chart Point Hover (Point Hover) ', 'hubsteel' ),
            'description' => ' Value > 0',
            'type'         => \Elementor\Controls_Manager::NUMBER,
            'control_type' => 'responsive',
            'separator' => 'before'
        ),
        
        array(
            'name' => 'boxcolor',
            'label' => esc_html__('Box Color', 'hubsteel' ),
            'type' => \Elementor\Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .pxl-chart' => 'background-color: {{VALUE}};',
            ],
        ),
        array(
            'name'  => 'width_chart',
            'label' => esc_html__( 'Cutout', 'hubsteel' ),
            'type'  => \Elementor\Controls_Manager::NUMBER,
            'condition' => [
                'layout' => ['2'],
            ],
        ),
    ]
),
hubsteel_widget_animation_settings(),
),
),
),hubsteel_get_class_widget_path()
);