<?php

namespace PWH_DCFH\App\Frontend\DiviContactForm\Features;

use DateTime;
use DOMException;
use ET_Builder_Element;
use Exception;
use PWH_DCFH\App\Admin\Controllers\PWH_DCFH_Syn_ICS_URL;
use PWH_DCFH\App\Controllers\PWH_DCFH_DOM;

if (!defined('ABSPATH')) {
    exit;
}
if (!class_exists('PWH_DCFH_Field_Date_Time')) {
    class PWH_DCFH_Field_Date_Time
    {
        public $render_slug;

        public $output;

        public $props = [];

        public $contact_form_order_class;

        public $field_order_class;

        /**
         * Class Constructor
         */
        public function __construct($render_slug, $output, $props)
        {
            $this->render_slug = $render_slug;
            $this->output = $output;
            $this->props = $props;
        }

        /**
         * Render Output
         * @throws DOMException|Exception
         */
        public function output()
        {
            $dom = PWH_DCFH_DOM::dom($this->output);
            $input = $dom->getElementsByTagName('input');
            if (isset($input->length) && 0 !== $input->length) {
                $config = [];
                $date_format = '';
                $time_format = '';
                $input_item = $input->item(0);
                $conditional_logic = isset($this->props['conditional_logic']) ? $this->props['conditional_logic'] : 'off';
                $datetime_inline = isset($this->props['datetime_inline']) ? $this->props['datetime_inline'] : 'off';
                $datetime_type = isset($this->props['datetime_type']) ? $this->props['datetime_type'] : 'both';
                $custom_locale = isset($this->props['datetime_locale']) ? $this->props['datetime_locale'] : 'en';
                $datetime_week_start = isset($this->props['datetime_week_start']) ? date_i18n("w", strtotime($this->props['datetime_week_start'])) : 'sunday';
                $time_steps = isset($this->props['time_steps']) ? $this->props['time_steps'] : '30';
                $datetime_disabled_weeks = isset($this->props['datetime_disabled_weeks']) ? $this->props['datetime_disabled_weeks'] : 'on';
                // Locale
                $datetime_locale = pwh_dcfh_wp_helpers()::get_wp_locale();
                if ($custom_locale !== $datetime_locale) {
                    $datetime_locale = $custom_locale;
                }
                // Date & Time Format
                if ('both' === $datetime_type) {
                    $datetime_format = isset($this->props['datetime_format']) ? $this->props['datetime_format'] : 'Y/m/d_dt_h:ia';
                    $datetime_format = explode('_dt_', $datetime_format);
                    $date_format = isset($datetime_format[0]) ? $datetime_format[0] : '';
                    $time_format = isset($datetime_format[1]) ? $datetime_format[1] : '';
                }
                if ('date' === $datetime_type) {
                    $date_format = isset($this->props['date_format']) ? $this->props['date_format'] : 'y/m/d';
                }
                if ('time' === $datetime_type) {
                    $time_format = isset($this->props['time_format']) ? $this->props['time_format'] : 'h:ia';
                }
                // Custom Date & Time Format
                $custom_date_format = isset($this->props['custom_date_format']) ? $this->props['custom_date_format'] : '';
                if ('' !== $custom_date_format) {
                    $date_format = $custom_date_format;
                }
                $custom_time_format = isset($this->props['custom_time_format']) ? $this->props['custom_time_format'] : '';
                if ('' !== $custom_time_format) {
                    $time_format = $custom_time_format;
                }
                $config['locale'] = $datetime_locale;
                $config['week_start'] = $datetime_week_start;
                $config['disabled_weeks'] = $datetime_disabled_weeks;
                $config['time_steps'] = absint($time_steps);
                $config['type'] = $datetime_type;
                $config['date_format'] = $date_format;
                $config['time_format'] = $time_format;

                // Set Data Attributes
                $input_class = ('on' === $conditional_logic && 'on' === $datetime_inline) ? ' et_pb_datetimepicker_conditional et_pb_datetimepicker_input' : '  et_pb_datetimepicker_input';
                $input_item->setAttribute('class', $input_item->getAttribute('class').$input_class);
                $input_item->setAttribute('autocomplete', 'off');
                $input_item->setAttribute('inputmode', 'none');
                $input_item->setAttribute('readonly', 'readonly');
                // Disabled Week Days
                $disabled_week_days = isset($this->props['datetime_disabled_week_days']) ? $this->props['datetime_disabled_week_days'] : '';
                if (!empty($disabled_week_days)) {
                    $disabled_week_days = pwh_dcfh_module_helpers()::process_multiple_checkboxes_value($disabled_week_days, array_keys(pwh_dcfh_module_helpers()::get_week_day_names()));
                    $config['disabled_week_days'] = $disabled_week_days;
                }
                // Disabled Past Days
                if (isset($this->props['datetime_disabled_past_days']) && 'on' === $this->props['datetime_disabled_past_days']) {
                    $config['disabled_past_days'] = 'on';
                }
                // Disabled Past Days
                if (isset($this->props['datetime_disabled_current_date']) && 'on' === $this->props['datetime_disabled_current_date']) {
                    $config['disabled_current_date'] = 'on';
                    $config['current_date'] = date_i18n('Y-m-d', time());
                }

                // Inline
                if ('on' === $datetime_inline) {
                    $config['show_inline'] = 'on';
                }
                // Set Current Datetime
                if (isset($this->props['datetime_setcurrent_datetime']) && 'on' === $this->props['datetime_setcurrent_datetime']) {
                    $config['setcurrent_datetime'] = 'on';
                }
                // RTL
                if (isset($this->props['datetime_locale_direction']) && 'on' === $this->props['datetime_locale_direction']) {
                    $config['rtl'] = 'on';
                }
                // Minimum Date
                $minimum_date_type = isset($this->props['min_date_type']) ? $this->props['min_date_type'] : 'off';
                if ('off' !== $minimum_date_type) {
                    $min_date = '';
                    $minimum_date_fixed = isset($this->props['fixed_min_date']) ? $this->props['fixed_min_date'] : '';
                    if ('fixed' === $minimum_date_type && '' !== $minimum_date_fixed) {
                        $min_date = $minimum_date_fixed;
                        if (0 !== $minimum_date_fixed) {
                            $min_date = date_i18n('Y-m-d', strtotime($minimum_date_fixed));
                        }
                    }
                    $minimum_date_relative = isset($this->props['relative_min_date']) ? $this->props['relative_min_date'] : '';
                    if ('relative' === $minimum_date_type && '' !== $minimum_date_relative) {
                        $min_relative_date = absint($minimum_date_relative);
                        if (strpos($minimum_date_relative, '+') !== false) {
                            $min_date = '+1970-01-'.$min_relative_date;
                        } elseif (strpos($minimum_date_relative, '-') !== false) {
                            $min_date = '-1970-01-'.$min_relative_date;
                        }
                    }
                    if ('' !== $min_date) {
                        $config['min_date_type'] = $minimum_date_type;
                        $config['min_date'] = $min_date;
                    }
                }
                // Maximum Date
                $maximum_date_type = isset($this->props['max_date_type']) ? $this->props['max_date_type'] : 'off';
                if ('off' !== $maximum_date_type) {
                    $max_date = '';
                    $maximum_date_fixed = isset($this->props['fixed_max_date']) ? $this->props['fixed_max_date'] : '';
                    if ('fixed' === $maximum_date_type && '' !== $maximum_date_fixed) {
                        $max_date = date_i18n('Y-m-d', strtotime($maximum_date_fixed));
                    }
                    $maximum_date_relative = isset($this->props['relative_max_date']) ? $this->props['relative_max_date'] : '';
                    if ('relative' === $maximum_date_type && '' !== $maximum_date_relative) {
                        $max_date = '+1970-01-'.absint($maximum_date_relative);
                    }
                    if ('' !== $max_date) {
                        $config['max_date_type'] = $maximum_date_type;
                        $config['max_date'] = $max_date;
                    }
                }
                // Available Dates
                $available_dates = isset($this->props['available_dates']) ? preg_replace('/\s*,\s*/', ',', $this->props['available_dates']) : '';
                if ('' !== $available_dates) {
                    $dates_array = array_filter(explode(',', $available_dates));
                    foreach ($dates_array as $date) {
                        $config['available_dates'][] = date_i18n('Y-m-d', strtotime($date));
                    }
                }
                // Unavailable Dates
                $unavailable_dates = isset($this->props['unavailable_dates']) ? preg_replace('/\s*,\s*/', ',', $this->props['unavailable_dates']) : '';
                if ('' !== $unavailable_dates) {
                    $dates_array = array_filter(explode(',', $unavailable_dates));
                    foreach ($dates_array as $date) {
                        $config['unavailable_dates'][] = date_i18n('Y-m-d', strtotime($date));
                    }
                }
                // Minimum Time
                $min_time = isset($this->props['min_time']) ? $this->props['min_time'] : '';
                if ('' !== $min_time) {
                    $config['min_time'] = $min_time;
                }
                // Maximum Time
                $max_time = isset($this->props['max_time']) ? $this->props['max_time'] : '';
                if ('' !== $max_time) {
                    $config['max_time'] = $max_time;
                }
                // Available Times Global
                $available_times = isset($this->props['available_times']) ? $this->props['available_times'] : '';
                if ('' !== $available_times) {
                    $config['available_times'] = preg_replace('/\s*,\s*/', ',', $available_times);
                }
                // Unavailable Times Global
                $unavailable_times = isset($this->props['unavailable_times']) ? $this->props['unavailable_times'] : '';
                if ('' !== $unavailable_times) {
                    $explode_unavailable_times = explode(',', $unavailable_times);
                    $implode_unavailable_times = implode(',', array_map(function ($value) use ($time_format) {
                        return date_i18n($time_format, strtotime($value));
                    }, $explode_unavailable_times));
                    $config['unavailable_times'] = preg_replace('/\s*,\s*/', ',', $implode_unavailable_times);
                }
                // Dayswise Available Times
                $available_day_times = array_filter($this->props, function ($key) {
                    return strpos($key, 'available_times_') === 0;
                }, ARRAY_FILTER_USE_KEY);
                if ('' !== $available_day_times) {
                    $available_day_times = array_filter($available_day_times, 'strlen');
                    if (!empty($available_day_times)) {
                        $available_day_times = preg_replace('/\s*,\s*/', ',', $available_day_times);
                        $config['available_day_times'] = $available_day_times;
                    }
                }
                // Dayswise Unavailable Times
                $unavailable_day_times = array_filter($this->props, function ($key) {
                    return strpos($key, 'unavailable_times_') === 0;
                }, ARRAY_FILTER_USE_KEY);
                if ('' !== $unavailable_day_times) {
                    $unavailable_day_times = array_filter($unavailable_day_times, 'strlen');
                    if (!empty($unavailable_day_times)) {
                        $unavailable_day_times = preg_replace('/\s*,\s*/', ',', $unavailable_day_times);
                        $config['unavailable_day_times'] = $unavailable_day_times;
                    }
                }
                // Disabled Past Times
                if (isset($this->props['disabled_past_times']) && 'on' === $this->props['disabled_past_times']) {
                    $config['disabled_past_times'] = 0;
                }
                // Auto Sync
                $ics_sync_url = isset($this->props['datetime_ics_sync_url']) ? $this->props['datetime_ics_sync_url'] : '';
                if ((isset($this->props['use_datetime_icscalendar_sync']) && 'on' === $this->props['use_datetime_icscalendar_sync']) && !empty($ics_sync_url)) {
                    $ics_obj = new PWH_DCFH_Syn_ICS_URL($ics_sync_url, $time_steps, $time_format);
                    $ics_data = $ics_obj->data();
                    if (!empty($ics_data)) {
                        $config['ics_data'] = $ics_data['ics_data'];
                    }
                }
                // Add Configs
                $input_item->setAttribute('data-config', wp_json_encode($config));
                $this->output = $dom->saveHTML();
            }

            return $this->output;
        }

        /**
         * Render Css
         * @return void
         */
        public function css()
        {
            $css_selector = '%%order_class%%.xdsoft_datetimepicker';
            $contact_form_order_class = $this->contact_form_order_class;
            /**
             * General
             */
            ET_Builder_Element::set_style($this->render_slug, [
                'selector' => ".xdsoft_datetimepicker.$contact_form_order_class",
                'declaration' => 'width:auto !important;',
            ]);
            ET_Builder_Element::set_style($this->render_slug, [
                'selector' => "$css_selector .xdsoft_timepicker .xdsoft_time_box > div > div",
                'declaration' => 'height:auto !important;',
            ]);
            ET_Builder_Element::set_style($this->render_slug, [
                'selector' => "$css_selector .xdsoft_calendar td.xdsoft_today.xdsoft_disabled",
                'declaration' => 'color:red !important;',
            ]);
            /**
             * Wrapper
             */
            $d_datetimepicker_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'datetimepicker_background'));
            et_pb_responsive_options()->generate_responsive_css($d_datetimepicker_background, "$css_selector, $css_selector .xdsoft_datepicker .xdsoft_month,$css_selector .xdsoft_datepicker .xdsoft_year ", 'background', $this->render_slug, "!important;", 'color');
            $d_padding = et_pb_responsive_options()->get_property_values($this->props, 'datetimepicker_padding');
            $d_padding = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props($d_padding);
            et_pb_responsive_options()->generate_responsive_css($d_padding, $css_selector, 'padding', $this->render_slug, '', 'custom_padding');
            $d_margin = et_pb_responsive_options()->get_property_values($this->props, 'datetimepicker_margin');
            $d_margin = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props($d_margin);
            et_pb_responsive_options()->generate_responsive_css($d_margin, $css_selector, 'margin', $this->render_slug, '', 'custom_padding');
            $d_border = et_pb_responsive_options()->get_property_values($this->props, 'datetimepicker_border');
            $d_border = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props($d_border);
            et_pb_responsive_options()->generate_responsive_css($d_border, $css_selector, 'border-radius', $this->render_slug, '', 'border-radius');
            $d_border_color = et_pb_responsive_options()->get_property_values($this->props, 'datetimepicker_border_color');
            et_pb_responsive_options()->generate_responsive_css($d_border_color, $css_selector, 'border-color', $this->render_slug, '', 'color');
            $d_border_width = et_pb_responsive_options()->get_property_values($this->props, 'datetimepicker_border_width');
            et_pb_responsive_options()->generate_responsive_css($d_border_width, $css_selector, 'border-width', $this->render_slug);
            $d_border_style = et_pb_responsive_options()->get_property_values($this->props, 'datetimepicker_border_style');
            et_pb_responsive_options()->generate_responsive_css($d_border_style, $css_selector, 'border-style', $this->render_slug, '', 'select');
            $shadow_preset = isset($this->props['datetimepicker_shadow']) ? $this->props['datetimepicker_shadow'] : null;
            if (!empty($shadow_preset) && 'none' !== $shadow_preset) {
                $shadow = pwh_dcfh_module_helpers()::get_shadow_presets_values($shadow_preset);
                $horizontal = isset($this->props['datetimepicker_shadow_horizontal']) ? $this->props['datetimepicker_shadow_horizontal'] : $shadow['horizontal'];
                $vertical = isset($this->props['datetimepicker_shadow_vertical']) ? $this->props['datetimepicker_shadow_vertical'] : $shadow['vertical'];
                $blur = isset($this->props['datetimepicker_shadow_blur']) ? $this->props['datetimepicker_shadow_blur'] : $shadow['blur'];
                $spread = isset($this->props['datetimepicker_shadow_spread']) ? $this->props['datetimepicker_shadow_spread'] : $shadow['spread'];
                $color = isset($this->props['datetimepicker_shadow_color']) ? $this->props['datetimepicker_shadow_color'] : 'rgba(0,0,0,0.3)';
                $position = isset($this->props['datetimepicker_shadow_position']) ? $this->props['datetimepicker_shadow_position'] : $shadow['position'];
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => $css_selector,
                    'declaration' => "-webkit-box-shadow: $position $horizontal $vertical $blur $spread $color;-moz-box-shadow: $position $horizontal $vertical $blur $spread $color; box-shadow: $position $horizontal $vertical $blur $spread $color;",
                ]);
            }
            /**
             * Datepicker
             */
            $d_width = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_width');
            $d_width['tablet'] = (isset($d_width['tablet']) && empty($d_width['tablet'])) ? '224px' : $d_width['tablet'];
            $d_width['phone'] = (isset($d_width['phone']) && empty($d_width['phone'])) ? '224px' : $d_width['phone'];
            et_pb_responsive_options()->generate_responsive_css($d_width, "$css_selector .xdsoft_datepicker", 'width', $this->render_slug, '!important;');
            $d_height = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_height');
            $d_height['tablet'] = (isset($d_height['tablet']) && empty($d_height['tablet'])) ? '' : $d_height['tablet'];
            $d_height['phone'] = (isset($d_height['phone']) && empty($d_height['phone'])) ? '' : $d_height['phone'];
            et_pb_responsive_options()->generate_responsive_css($d_height, "$css_selector .xdsoft_calendar table", 'height', $this->render_slug);
            $desktop_font = isset($this->props['datepicker_yearmonth_font']) ? $this->props['datepicker_yearmonth_font'] : null;
            $is_datepicker_yearmonth_font_responsive = et_pb_responsive_options()->is_responsive_enabled($this->props, 'datepicker_yearmonth_font');
            ET_Builder_Element::set_style($this->render_slug, [
                'selector' => "$css_selector .xdsoft_datepicker .xdsoft_month,$css_selector .xdsoft_datepicker .xdsoft_year",
                'declaration' => sprintf('%s;', et_builder_set_element_font($desktop_font)),
            ]);
            if ($is_datepicker_yearmonth_font_responsive) {
                $tablet_font = isset($this->props['datepicker_yearmonth_font_tablet']) ? $this->props['datepicker_yearmonth_font_tablet'] : null;
                $phone_font = isset($this->props['datepicker_yearmonth_font_phone']) ? $this->props['datepicker_yearmonth_font_phone'] : null;
                if (!empty($tablet_font)) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$css_selector .xdsoft_datepicker .xdsoft_month,$css_selector .xdsoft_datepicker .xdsoft_year",
                        'declaration' => sprintf('%s;', et_builder_set_element_font($tablet_font)),
                        'media_query' => ET_Builder_Element::get_media_query('max_width_980'),
                    ]);
                }
                if (!empty($phone_font)) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$css_selector .xdsoft_datepicker .xdsoft_month,$css_selector .xdsoft_datepicker .xdsoft_year",
                        'declaration' => sprintf('%s;', et_builder_set_element_font($phone_font)),
                        'media_query' => ET_Builder_Element::get_media_query('max_width_767'),
                    ]);
                }
            }
            $d_alignment = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_yearmonth_alignment');
            et_pb_responsive_options()->generate_responsive_css($d_alignment, "$css_selector .xdsoft_monthselect,$css_selector .xdsoft_month", 'text-align', $this->render_slug, '', 'text_alignment');
            $d_color = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_yearmonth_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_color, "$css_selector .xdsoft_datepicker .xdsoft_month,$css_selector .xdsoft_datepicker .xdsoft_year", 'color', $this->render_slug, '', 'color');
            $d_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'datepicker_yearmonth_background'));
            et_pb_responsive_options()->generate_responsive_css($d_background, "$css_selector .xdsoft_monthselect .xdsoft_option.xdsoft_current,$css_selector .xdsoft_yearselect .xdsoft_option.xdsoft_current", 'background', $this->render_slug, "!important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_background, "$css_selector .xdsoft_monthselect .xdsoft_option.xdsoft_current,$css_selector .xdsoft_yearselect .xdsoft_option.xdsoft_current", 'box-shadow', $this->render_slug, " 1px 3px 0 inset !important;", 'color');
            if (et_pb_hover_options()->is_enabled('datepicker_yearmonth_background', $this->props)) {
                $d_datepicker_yearmonth_background = et_pb_hover_options()->get_value('datepicker_yearmonth_background', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$css_selector .xdsoft_monthselect .xdsoft_option:hover,$css_selector .xdsoft_yearselect .xdsoft_option:hover",
                    'declaration' => "background:$d_datepicker_yearmonth_background !important;"
                ]);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$css_selector .xdsoft_monthselect .xdsoft_option:hover,$css_selector .xdsoft_yearselect .xdsoft_option:hover",
                    'declaration' => "box-shadow:$d_datepicker_yearmonth_background 1px 3px 0 inset !important;"
                ]);
            }
            $d_size = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_yearmonth_size');
            et_pb_responsive_options()->generate_responsive_css($d_size, "$css_selector .xdsoft_datepicker .xdsoft_month,$css_selector .xdsoft_datepicker .xdsoft_year", 'font-size', $this->render_slug);
            $d_letter = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_yearmonth_letter_space');
            et_pb_responsive_options()->generate_responsive_css($d_letter, "$css_selector .xdsoft_datepicker .xdsoft_month,$css_selector .xdsoft_datepicker .xdsoft_year", 'letter-spacing', $this->render_slug);
            $line_height_important = et_builder_has_limitation('force_use_global_important') ? ' !important;' : '';
            $d_line_height = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_yearmonth_line_height');
            et_pb_responsive_options()->generate_responsive_css($d_line_height, "$css_selector .xdsoft_datepicker .xdsoft_month,$css_selector .xdsoft_datepicker .xdsoft_year", 'line-height', $this->render_slug, $line_height_important);
            /**
             * Week Days
             */
            $desktop_font = isset($this->props['datepicker_weekdays_font']) ? $this->props['datepicker_weekdays_font'] : null;
            $is_fdatepicker_weekdays_font_responsive = et_pb_responsive_options()->is_responsive_enabled($this->props, 'datepicker_weekdays_font');
            ET_Builder_Element::set_style($this->render_slug, [
                'selector' => "$css_selector .xdsoft_calendar th",
                'declaration' => sprintf('%s;', et_builder_set_element_font($desktop_font)),
            ]);
            if ($is_fdatepicker_weekdays_font_responsive) {
                $tablet_font = isset($this->props['datepicker_weekdays_font_tablet']) ? $this->props['datepicker_weekdays_font_tablet'] : null;
                $phone_font = isset($this->props['datepicker_weekdays_font_phone']) ? $this->props['datepicker_weekdays_font_phone'] : null;
                if (!empty($tablet_font)) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$css_selector .xdsoft_calendar th",
                        'declaration' => sprintf('%s;', et_builder_set_element_font($tablet_font)),
                        'media_query' => ET_Builder_Element::get_media_query('max_width_980'),
                    ]);
                }
                if (!empty($phone_font)) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$css_selector .xdsoft_calendar th",
                        'declaration' => sprintf('%s;', et_builder_set_element_font($phone_font)),
                        'media_query' => ET_Builder_Element::get_media_query('max_width_767'),
                    ]);
                }
            }
            $d_alignment = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_weekdays_alignment');
            et_pb_responsive_options()->generate_responsive_css($d_alignment, "$css_selector .xdsoft_calendar th", 'text-align', $this->render_slug, '', 'text_alignment');
            $d_color = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_weekdays_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_color, "$css_selector .xdsoft_calendar th", 'color', $this->render_slug, '', 'color');
            $d_size = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_weekdays_size');
            et_pb_responsive_options()->generate_responsive_css($d_size, "$css_selector .xdsoft_calendar th", 'font-size', $this->render_slug);
            $d_letter = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_weekdays_letter_space');
            et_pb_responsive_options()->generate_responsive_css($d_letter, "$css_selector .xdsoft_calendar th", 'letter-spacing', $this->render_slug);
            $line_height_important = et_builder_has_limitation('force_use_global_important') ? ' !important;' : '';
            $d_line_height = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_weekdays_line_height');
            et_pb_responsive_options()->generate_responsive_css($d_line_height, "$css_selector .xdsoft_calendar th", 'line-height', $this->render_slug, $line_height_important);
            /**
             * Calendar Days
             */
            $desktop_font = isset($this->props['datepicker_dates_font']) ? $this->props['datepicker_dates_font'] : null;
            $is_datepicker_dates_font_responsive = et_pb_responsive_options()->is_responsive_enabled($this->props, 'datepicker_dates_font');
            ET_Builder_Element::set_style($this->render_slug, [
                'selector' => "$css_selector .xdsoft_date",
                'declaration' => sprintf('%s;', et_builder_set_element_font($desktop_font)),
            ]);
            if ($is_datepicker_dates_font_responsive) {
                $tablet_font = isset($this->props['datepicker_dates_font_tablet']) ? $this->props['datepicker_dates_font_tablet'] : null;
                $phone_font = isset($this->props['datepicker_dates_font_phone']) ? $this->props['datepicker_dates_font_phone'] : null;
                if (!empty($tablet_font)) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$css_selector .xdsoft_date",
                        'declaration' => sprintf('%s;', et_builder_set_element_font($tablet_font)),
                        'media_query' => ET_Builder_Element::get_media_query('max_width_980'),
                    ]);
                }
                if (!empty($phone_font)) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$css_selector .xdsoft_date",
                        'declaration' => sprintf('%s;', et_builder_set_element_font($phone_font)),
                        'media_query' => ET_Builder_Element::get_media_query('max_width_767'),
                    ]);
                }
            }
            $d_alignment = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_dates_alignment');
            et_pb_responsive_options()->generate_responsive_css($d_alignment, "$css_selector .xdsoft_calendar td>div", 'text-align', $this->render_slug, '', 'text_alignment');
            $d_color = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_dates_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_color, "$css_selector .xdsoft_date", 'color', $this->render_slug, '', 'color');
            $d_size = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_dates_size');
            et_pb_responsive_options()->generate_responsive_css($d_size, "$css_selector .xdsoft_date", 'font-size', $this->render_slug);
            $d_letter = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_dates_letter_space');
            et_pb_responsive_options()->generate_responsive_css($d_letter, "$css_selector .xdsoft_date", 'letter-spacing', $this->render_slug);
            $line_height_important = et_builder_has_limitation('force_use_global_important') ? ' !important;' : '';
            $d_line_height = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_dates_line_height');
            et_pb_responsive_options()->generate_responsive_css($d_line_height, "$css_selector .xdsoft_date", 'line-height', $this->render_slug, $line_height_important);
            /**
             * Current Date Background and Text Color
             */
            $d_datepicker_current_date_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'datepicker_current_date_background'));
            $d_datepicker_current_date_color = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_current_date_color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_current_date_background, "$css_selector .xdsoft_date.xdsoft_today", 'background', $this->render_slug, "!important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_current_date_background, "$css_selector .xdsoft_date.xdsoft_today", 'box-shadow', $this->render_slug, " 1px 3px 0 inset !important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_current_date_color, "$css_selector .xdsoft_date.xdsoft_today", 'color', $this->render_slug, "!important;", 'color');
            if (et_pb_hover_options()->is_enabled('datepicker_current_date_background', $this->props)) {
                $d_datepicker_date_hover_background = et_pb_hover_options()->get_value('datepicker_current_date_background', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$css_selector td.xdsoft_today > div:hover",
                    'declaration' => "background:$d_datepicker_date_hover_background !important;"
                ]);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$css_selector  td.xdsoft_today > div:hover",
                    'declaration' => "box-shadow:$d_datepicker_date_hover_background 1px 3px 0 inset !important;"
                ]);
            }
            /**
             * Selected Date Background and Text Color
             */
            $d_datepicker_selected_date_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'datepicker_selected_date_background'));
            $d_datepicker_selected_date_color = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_selected_date_color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_selected_date_background, "$css_selector .xdsoft_date.xdsoft_current:not(.xdsoft_today)", 'background', $this->render_slug, "!important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_selected_date_background, "$css_selector.xdsoft_datetimepicker .xdsoft_calendar td:hover", 'background', $this->render_slug, "!important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_selected_date_background, "$css_selector .xdsoft_date.xdsoft_current:not(.xdsoft_today)", 'box-shadow', $this->render_slug, " 1px 3px 0 inset !important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_selected_date_color, "$css_selector .xdsoft_date.xdsoft_current:not(.xdsoft_today)", 'color', $this->render_slug, "!important;", 'color');
            /**
             * Available Dates Background and Text Color
             */
            $d_datepicker_available_dates_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'datepicker_available_dates_background'));
            $d_datepicker_available_dates_text_color = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_available_dates_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_available_dates_background, "$css_selector .xdsoft_date:not(.xdsoft_disabled):not(.xdsoft_current)", 'background', $this->render_slug, "!important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_available_dates_text_color, "$css_selector .xdsoft_date:not(.xdsoft_disabled):not(.xdsoft_current)", 'color', $this->render_slug, "!important;", 'color');
            /**
             * Unvailable Dates Background and Text Color
             */
            $d_datepicker_unavailable_dates_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'datepicker_unavailable_dates_background'));
            $d_datepicker_unavailable_dates_text_color = et_pb_responsive_options()->get_property_values($this->props, 'datepicker_unavailable_dates_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_unavailable_dates_background, "$css_selector .xdsoft_date.xdsoft_disabled", 'background', $this->render_slug, "!important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_datepicker_unavailable_dates_text_color, "$css_selector .xdsoft_date.xdsoft_disabled", 'color', $this->render_slug, "!important;", 'color');
            /**
             * Timepicker
             */
            $d_width = et_pb_responsive_options()->get_property_values($this->props, 'timepicker_width');
            $d_width['tablet'] = (isset($d_width['tablet']) && empty($d_width['tablet'])) ? '58px' : $d_width['tablet'];
            $d_width['phone'] = (isset($d_width['phone']) && empty($d_width['phone'])) ? '58px' : $d_width['phone'];
            et_pb_responsive_options()->generate_responsive_css($d_width, "$css_selector .xdsoft_timepicker", 'width', $this->render_slug);
            $d_height = et_pb_responsive_options()->get_property_values($this->props, 'timepicker_height');
            $d_height['tablet'] = (isset($d_height['tablet']) && empty($d_height['tablet'])) ? '151px' : $d_height['tablet'];
            $d_height['phone'] = (isset($d_height['phone']) && empty($d_height['phone'])) ? '151px' : $d_height['phone'];
            et_pb_responsive_options()->generate_responsive_css($d_height, "$css_selector .xdsoft_timepicker .xdsoft_time_box", 'height', $this->render_slug);
            $desktop_font = isset($this->props['timepicker_time_font']) ? $this->props['timepicker_time_font'] : null;
            $is_timepicker_time_font_responsive = et_pb_responsive_options()->is_responsive_enabled($this->props, 'timepicker_time_font');
            ET_Builder_Element::set_style($this->render_slug, [
                'selector' => "$css_selector .xdsoft_time",
                'declaration' => sprintf('%s;', et_builder_set_element_font($desktop_font)),
            ]);
            if ($is_timepicker_time_font_responsive) {
                $tablet_font = isset($this->props['timepicker_time_font_tablet']) ? $this->props['timepicker_time_font_tablet'] : null;
                $phone_font = isset($this->props['timepicker_time_font_phone']) ? $this->props['timepicker_time_font_phone'] : null;
                if (!empty($tablet_font)) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$css_selector .xdsoft_time",
                        'declaration' => sprintf('%s;', et_builder_set_element_font($tablet_font)),
                        'media_query' => ET_Builder_Element::get_media_query('max_width_980'),
                    ]);
                }
                if (!empty($phone_font)) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$css_selector .xdsoft_time",
                        'declaration' => sprintf('%s;', et_builder_set_element_font($phone_font)),
                        'media_query' => ET_Builder_Element::get_media_query('max_width_767'),
                    ]);
                }
            }
            $d_color = et_pb_responsive_options()->get_property_values($this->props, 'timepicker_time_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_color, "$css_selector .xdsoft_timepicker .xdsoft_time_box>div>div", 'color', $this->render_slug, '', 'color');
            $d_alignment = et_pb_responsive_options()->get_property_values($this->props, 'timepicker_time_alignment');
            et_pb_responsive_options()->generate_responsive_css($d_alignment, "$css_selector .xdsoft_timepicker .xdsoft_time_box>div>div", 'text-align', $this->render_slug, '', 'text_alignment');
            $d_size = et_pb_responsive_options()->get_property_values($this->props, 'timepicker_time_size');
            et_pb_responsive_options()->generate_responsive_css($d_size, "$css_selector .xdsoft_time", 'font-size', $this->render_slug, '!important');
            $d_letter = et_pb_responsive_options()->get_property_values($this->props, 'timepicker_time_letter_space');
            et_pb_responsive_options()->generate_responsive_css($d_letter, "$css_selector .xdsoft_time", 'letter-spacing', $this->render_slug);
            $line_height_important = et_builder_has_limitation('force_use_global_important') ? ' !important' : '';
            $d_line_height = et_pb_responsive_options()->get_property_values($this->props, 'timepicker_time_line_height');
            et_pb_responsive_options()->generate_responsive_css($d_line_height, "$css_selector .xdsoft_timepicker .xdsoft_time_box>div>div", 'line-height', $this->render_slug, $line_height_important);
            $d_timpicker_selected_time_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'timpicker_selected_time_background'));
            $d_timpicker_selected_time_color = et_pb_responsive_options()->get_property_values($this->props, 'timpicker_selected_time_color');
            et_pb_responsive_options()->generate_responsive_css($d_timpicker_selected_time_background, "$css_selector .xdsoft_time.xdsoft_current", 'background', $this->render_slug, "!important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_timpicker_selected_time_background, "$css_selector .xdsoft_time.xdsoft_current", 'box-shadow', $this->render_slug, " 1px 3px 0 inset !important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_timpicker_selected_time_color, "$css_selector .xdsoft_time.xdsoft_current", 'color', $this->render_slug, "!important;", 'color');
            if (et_pb_hover_options()->is_enabled('timpicker_selected_time_background', $this->props)) {
                $d_timpicker_hover_background = et_pb_hover_options()->get_value('timpicker_selected_time_background', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$css_selector .xdsoft_timepicker .xdsoft_time_box > div > div:hover",
                    'declaration' => "background:$d_timpicker_hover_background !important;"
                ]);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$css_selector .xdsoft_timepicker .xdsoft_time_box > div > div:hover",
                    'declaration' => "box-shadow:$d_timpicker_hover_background 1px 3px 0 inset !important;"
                ]);
            }
            $d_timpicker_available_times_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'timpicker_available_times_background'));
            $d_timpicker_available_times_text_color = et_pb_responsive_options()->get_property_values($this->props, 'timpicker_available_times_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_timpicker_available_times_background, "$css_selector .xdsoft_time:not(.xdsoft_disabled):not(.xdsoft_current)", 'background', $this->render_slug, "!important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_timpicker_available_times_text_color, "$css_selector .xdsoft_time:not(.xdsoft_disabled):not(.xdsoft_current)", 'color', $this->render_slug, "!important;", 'color');
            $d_timpicker_unavailable_times_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'timpicker_unavailable_times_background'));
            $d_timpicker_unavailable_times_text_color = et_pb_responsive_options()->get_property_values($this->props, 'timpicker_unavailable_times_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_timpicker_unavailable_times_background, "$css_selector .xdsoft_time.xdsoft_disabled", 'background', $this->render_slug, "!important;", 'color');
            et_pb_responsive_options()->generate_responsive_css($d_timpicker_unavailable_times_text_color, "$css_selector .xdsoft_time.xdsoft_disabled", 'color', $this->render_slug, "!important;", 'color');
        }
    }
}