<?php

namespace PWH_DCFH\App\Frontend\DiviContactForm\Features;

use DOMException;
use ET_Builder_Element;
use PWH_DCFH\App\Base\PWH_DCFH_Strings;
use PWH_DCFH\App\Controllers\PWH_DCFH_DOM;

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

        public $output;

        public $props = [];

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

        /**
         * Render Output
         * @throws DOMException
         */
        public function output()
        {
            $dom = PWH_DCFH_DOM::dom($this->output);
            $input = $dom->getElementsByTagName('input');
            $p_tag = $dom->getElementsByTagName('p');
            $upload_tmp_dir = pwh_dcfh_file_helpers()::get_tmp_upload_dir();
            // If Directory Does Not Exist Return
            if (!is_dir($upload_tmp_dir)) {
                if (((isset($input->length) && 0 !== $input->length)) && is_user_logged_in() && current_user_can('administrator')) {
                    $p_item = $p_tag->item(0);
                    $warning_ele = $dom->createElement('span', __('The plugin temporary upload directory does not exist. Please consider reactivating the plugin. Alternatively, if you encounter this issue, it may be related to server problems. In such cases, it\'s advisable to verify and rectify any directory write permission rules on your server.', 'pwh-dcfh'));
                    $warning_ele->setAttribute('style', 'color: red;');
                    $p_item->appendChild($warning_ele);
                    $this->output = $dom->saveHTML();
                }

                return $this->output;
            }
            if ((isset($input->length) && 0 !== $input->length) && (isset($p_tag->length) && 0 !== $p_tag->length)) {
                $file_size = isset($this->props['file_size']) ? preg_replace('/\D/', '', $this->props['file_size']) : '1024';
                if (is_numeric($file_size)) {
                    $file_size = $file_size * KB_IN_BYTES;      // Convert User Size To Bytes
                    $wp_max_upload_size = wp_max_upload_size(); // WordPress Max File Size In Bytes
                    // Overide User File Size With WP File Size If Exceeds
                    if ($file_size > $wp_max_upload_size) {
                        $file_size = $wp_max_upload_size;
                    }
                    $input_item = $input->item(0);
                    $p_item = $p_tag->item(0);
                    $p_class = $p_item->getAttribute('class');
                    $field_order_class = ET_Builder_Element::get_module_order_class($this->render_slug);
                    $field_id = pwh_dcfh_helpers()::get_field_index($field_order_class);
                    // Add Custom Class To P Tag
                    $p_item->setAttribute('class', "$p_class et_pb_files_container");
                    $file_mimes = isset($this->props['file_mime']) ? $this->props['file_mime'] : '';
                    if (!empty($file_mimes)) {
                        $processed_mimes = pwh_dcfh_module_helpers()::process_multiple_mimes_checkboxes_value($file_mimes);
                        $files_extentions = $processed_mimes['values'];
                        $files_mimes = $processed_mimes['keys'];
                        $file_size_formatted = size_format($file_size);
                        $files_limit = isset($this->props['files_limit']) ? $this->props['files_limit'] : 2;
                        $frontend_i10 = PWH_DCFH_Strings::instance()->strings('frontend_i10');
                        $file_desc = sprintf('%1$s %2$s. %3$s %4$s', $frontend_i10['accepted_file_text'], $files_extentions, $frontend_i10['max_filesize_text'], $file_size_formatted);
                        // Default Input
                        $input_name = $input_item->getAttribute('name');
                        $input_class = $input_item->getAttribute('class').' et_pb_file_input';
                        $input_item->setAttribute('class', 'et_pb_contact_hidden_files');
                        $input_item->setAttribute('data-field-id', $field_id);
                        // File Input
                        $file_label = $dom->createElement('label', 'File Input');
                        $file_label->setAttribute('for', "et_pb_file_input_$field_id");
                        $file_label->setAttribute('class', 'et_pb_visually_hidden');
                        $file_input = $dom->createElement('input');
                        $file_input->setAttribute('type', 'file');
                        $file_input->setAttribute('class', $input_class);
                        $file_input->setAttribute('id', "et_pb_file_input_$field_id");
                        $file_input->setAttribute('name', $input_name);
                        if ($files_limit > 1) {
                            $file_input->setAttribute('data-limit', $files_limit);
                            $file_input->setAttribute('multiple', 'multiple');
                        }
                        $file_input->setAttribute('data-field-id', $field_id);
                        $file_input->setAttribute('data-size', $file_size);
                        $file_input->setAttribute('data-size-formatted', $file_size_formatted);
                        $p_item->appendChild($file_label);
                        $p_item->appendChild($file_input);
                        // Upload Button
                        $file_upload_button = $dom->createElement('button', $frontend_i10['file_upload_btn_text']);
                        $file_upload_button->setAttribute('type', 'button');
                        $file_upload_button->setAttribute('class', 'et_pb_file_upload_button et_pb_button et_pb_icon');
                        $file_chosen_span = $dom->createElement('span', $frontend_i10['chosen_file_text']);
                        $file_chosen_span->setAttribute('class', 'et_pb_file_chosen_desc');
                        $p_item->appendChild($file_upload_button);
                        $p_item->appendChild($file_chosen_span);
                        // Hidden Field
                        $file_hidden_input = $dom->createElement('input');
                        $file_hidden_input->setAttribute('type', 'hidden');
                        $file_hidden_input->setAttribute('name', $input_name.'_is_file');
                        $file_hidden_input->setAttribute('value', 'yes');
                        $p_item->appendChild($file_hidden_input);
                        // File Token
                        $file_token_input = $dom->createElement('input');
                        $file_token_input->setAttribute('type', 'hidden');
                        $file_token_input->setAttribute('name', $input_name.'_file_token');
                        $file_token_input->setAttribute('value', pwh_dcfh_helpers()::encrypt_decrypt(wp_json_encode([
                            'size' => $file_size,
                            'extentions' => $files_extentions,
                            'mimetypes' => $files_mimes,
                            'limit' => $files_limit,
                        ])));
                        $p_item->appendChild($file_token_input);
                        // File Description
                        $file_description = $dom->createElement('span');
                        $file_description->setAttribute('id', "et_pb_accepted_files_desc_$field_id");
                        $file_description->setAttribute('class', 'et_pb_accepted_files_desc');
                        $file_description->setAttribute('data-description', $file_desc);
                        $p_item->appendChild($file_description);
                        $description = $dom->createTextNode($file_desc);
                        $file_description->appendChild($description);
                        // Files List
                        $files_list = $dom->createElement('span');
                        $files_list->setAttribute('id', "et_pb_files_list_$field_id");
                        $files_list->setAttribute('class', 'et_pb_files_list');
                        $p_item->appendChild($files_list);
                        $this->output = $dom->saveHTML();
                    }
                }
            }

            return $this->output;
        }

        /**
         * Render Css
         * @return void
         */
        public function css()
        {
            $container_class = '%%order_class%% .et_pb_files_container';
            /**
             * Container
             */
            $d_files_container_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'files_container_background'));
            et_pb_responsive_options()->generate_responsive_css($d_files_container_background, $container_class, 'background', $this->render_slug, "!important;", 'color');
            if (et_pb_hover_options()->is_enabled('files_container_background', $this->props)) {
                $files_container_background_hover = et_pb_hover_options()->get_value('files_container_background', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$container_class:hover",
                    'declaration' => "background:$files_container_background_hover !important;"
                ]);
            }
            $d_files_container_margin = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props(et_pb_responsive_options()->get_property_values($this->props, 'files_container_margin'));
            et_pb_responsive_options()->generate_responsive_css($d_files_container_margin, $container_class, 'margin', $this->render_slug, '', 'custom_padding');
            $d_files_container_padding = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props(et_pb_responsive_options()->get_property_values($this->props, 'files_container_padding'));
            et_pb_responsive_options()->generate_responsive_css($d_files_container_padding, $container_class, 'padding', $this->render_slug, '!important;', 'custom_padding');
            $d_files_container_border = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props(et_pb_responsive_options()->get_property_values($this->props, 'files_container_border'));
            et_pb_responsive_options()->generate_responsive_css($d_files_container_border, $container_class, 'border-radius', $this->render_slug, '', 'border-radius');
            $d_files_container_border_color = et_pb_responsive_options()->get_property_values($this->props, 'files_container_border_color');
            et_pb_responsive_options()->generate_responsive_css($d_files_container_border_color, $container_class, 'border-color', $this->render_slug, '', 'color');
            if (et_pb_hover_options()->is_enabled('files_container_border_color', $this->props)) {
                $files_container_border_color_hover = et_pb_hover_options()->get_value('files_container_border_color', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$container_class:hover",
                    'declaration' => "border-color:$files_container_border_color_hover !important;"
                ]);
            }
            $d_files_container_border_width = et_pb_responsive_options()->get_property_values($this->props, 'files_container_border_width');
            et_pb_responsive_options()->generate_responsive_css($d_files_container_border_width, $container_class, 'border-width', $this->render_slug);
            $d_files_container_border_style = et_pb_responsive_options()->get_property_values($this->props, 'files_container_border_style');
            et_pb_responsive_options()->generate_responsive_css($d_files_container_border_style, $container_class, 'border-style', $this->render_slug, '', 'select');
            $files_container_shadow = isset($this->props['files_container_shadow']) ? $this->props['files_container_shadow'] : null;
            if (!empty($files_container_shadow) && 'none' !== $files_container_shadow) {
                $shadow = pwh_dcfh_module_helpers()::get_shadow_presets_values($files_container_shadow);
                $horizontal = isset($this->props['files_container_shadow_horizontal']) ? $this->props['files_container_shadow_horizontal'] : $shadow['horizontal'];
                $vertical = isset($this->props['files_container_shadow_vertical']) ? $this->props['files_container_shadow_vertical'] : $shadow['vertical'];
                $blur = isset($this->props['files_container_shadow_blur']) ? $this->props['files_container_shadow_blur'] : $shadow['blur'];
                $spread = isset($this->props['files_container_shadow_spread']) ? $this->props['files_container_shadow_spread'] : $shadow['spread'];
                $color = isset($this->props['files_container_shadow_color']) ? $this->props['files_container_shadow_color'] : 'rgba(0,0,0,0.3)';
                $position = isset($this->props['files_container_shadow_position']) ? $this->props['files_container_shadow_position'] : $shadow['position'];
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => $container_class,
                    '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;",
                ]);
            }
            $d_files_container_list_color = et_pb_responsive_options()->get_property_values($this->props, 'files_container_list_color');
            et_pb_responsive_options()->generate_responsive_css($d_files_container_list_color, "$container_class .et_pb_files_list .et_pb_file_name", 'color', $this->render_slug, '!important;', 'color');
            et_pb_responsive_options()->generate_responsive_css($d_files_container_list_color, "$container_class .et_pb_files_list .et_pb_file_size", 'color', $this->render_slug, '!important;', 'color');
            if (et_pb_hover_options()->is_enabled('files_container_list_color', $this->props)) {
                $files_container_list_color_hover = et_pb_hover_options()->get_value('files_container_list_color', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$container_class .et_pb_files_list .et_pb_file_name:hover,$container_class .et_pb_files_list .et_pb_file_size:hover",
                    'declaration' => "color:$files_container_list_color_hover !important;"
                ]);
            }
            /**
             * Accepted Files
             */
            $accepted_files_class = '%%order_class%% .et_pb_files_container .et_pb_accepted_files_desc';
            $d_accepted_file_color = et_pb_responsive_options()->get_property_values($this->props, 'accepted_file_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_accepted_file_color, "$accepted_files_class", 'color', $this->render_slug, '', 'color');
            if (et_pb_hover_options()->is_enabled('accepted_file_text_color', $this->props)) {
                $accepted_file_text_color_hover = et_pb_hover_options()->get_value('accepted_file_text_color', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$accepted_files_class:hover",
                    'declaration' => "color:$accepted_file_text_color_hover !important;"
                ]);
            }
            $d_accepted_file_size = et_pb_responsive_options()->get_property_values($this->props, 'accepted_file_text_size');
            et_pb_responsive_options()->generate_responsive_css($d_accepted_file_size, "$accepted_files_class", 'font-size', $this->render_slug);
            $accepted_file_text_font = isset($this->props['accepted_file_text_font']) ? $this->props['accepted_file_text_font'] : null;
            $is_accepted_file_font_responsive = et_pb_responsive_options()->is_responsive_enabled($this->props, 'accepted_file_text_font');
            if (!empty($accepted_file_text_font)) {
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$accepted_files_class",
                    'declaration' => sprintf('%s;', et_builder_set_element_font($accepted_file_text_font)),
                ]);
            }
            if ($is_accepted_file_font_responsive) {
                $accepted_file_text_font_tablet = isset($this->props['accepted_file_text_font_tablet']) ? $this->props['accepted_file_text_font_tablet'] : null;
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$accepted_files_class",
                    'declaration' => sprintf('%s;', et_builder_set_element_font($accepted_file_text_font_tablet)),
                    'media_query' => ET_Builder_Element::get_media_query('max_width_980'),
                ]);
            }
            if ($is_accepted_file_font_responsive) {
                $accepted_file_text_font_phone = isset($this->props['accepted_file_text_font_phone']) ? $this->props['accepted_file_text_font_phone'] : null;
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$accepted_files_class",
                    'declaration' => sprintf('%s;', et_builder_set_element_font($accepted_file_text_font_phone)),
                    'media_query' => ET_Builder_Element::get_media_query('768_980'),
                ]);
            }
            $d_accepted_file_letter = et_pb_responsive_options()->get_property_values($this->props, 'accepted_file_text_letterspace');
            et_pb_responsive_options()->generate_responsive_css($d_accepted_file_letter, "$accepted_files_class", 'letter-spacing', $this->render_slug);
            $d_accepted_file_line_height = et_pb_responsive_options()->get_property_values($this->props, 'accepted_file_text_lineheight');
            et_pb_responsive_options()->generate_responsive_css($d_accepted_file_line_height, "$accepted_files_class", 'line-height', $this->render_slug);
            $d_accepted_file_alignment = et_pb_responsive_options()->get_property_values($this->props, 'accepted_file_text_alignment');
            et_pb_responsive_options()->generate_responsive_css($d_accepted_file_alignment, "$accepted_files_class", 'text-align', $this->render_slug, '', 'text_alignment');
            $d_accepted_file_margin = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props(et_pb_responsive_options()->get_property_values($this->props, 'accepted_file_text_margin'));
            et_pb_responsive_options()->generate_responsive_css($d_accepted_file_margin, "$accepted_files_class", 'margin', $this->render_slug, '', 'custom_padding');
            $d_accepted_file_padding = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props(et_pb_responsive_options()->get_property_values($this->props, 'accepted_file_text_padding'));
            et_pb_responsive_options()->generate_responsive_css($d_accepted_file_padding, "$accepted_files_class", 'padding', $this->render_slug, '', 'custom_padding');
            /**
             * Chosen Files
             */
            $file_chosen_class = '%%order_class%% .et_pb_files_container .et_pb_file_chosen_desc';
            $d_chosen_file_color = et_pb_responsive_options()->get_property_values($this->props, 'chosen_file_text_color');
            et_pb_responsive_options()->generate_responsive_css($d_chosen_file_color, $file_chosen_class, 'color', $this->render_slug, '!important;', 'color');
            if (et_pb_hover_options()->is_enabled('chosen_file_text_color', $this->props)) {
                $chosen_file_text_color_hover = et_pb_hover_options()->get_value('chosen_file_text_color', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_chosen_class:hover",
                    'declaration' => "color:$chosen_file_text_color_hover !important;"
                ]);
            }
            $d_chosen_file_size = et_pb_responsive_options()->get_property_values($this->props, 'chosen_file_text_size');
            et_pb_responsive_options()->generate_responsive_css($d_chosen_file_size, $file_chosen_class, 'font-size', $this->render_slug);
            $chosen_file_text_font = isset($this->props['chosen_file_text_font']) ? $this->props['chosen_file_text_font'] : null;
            $is_chosen_file_font_responsive = et_pb_responsive_options()->is_responsive_enabled($this->props, 'chosen_file_text_font');
            if (!empty($chosen_file_text_font)) {
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => $file_chosen_class,
                    'declaration' => sprintf('%s;', et_builder_set_element_font($chosen_file_text_font)),
                ]);
            }
            if ($is_chosen_file_font_responsive) {
                $chosen_file_text_font_tablet = isset($this->props['chosen_file_text_font_tablet']) ? $this->props['chosen_file_text_font_tablet'] : null;
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => $file_chosen_class,
                    'declaration' => sprintf('%s;', et_builder_set_element_font($chosen_file_text_font_tablet)),
                    'media_query' => ET_Builder_Element::get_media_query('max_width_980'),
                ]);
            }
            if ($is_chosen_file_font_responsive) {
                $chosen_file_text_font_phone = isset($this->props['chosen_file_text_font_phone']) ? $this->props['chosen_file_text_font_phone'] : null;
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => $file_chosen_class,
                    'declaration' => sprintf('%s;', et_builder_set_element_font($chosen_file_text_font_phone)),
                    'media_query' => ET_Builder_Element::get_media_query('768_980'),
                ]);
            }
            $d_chosen_file_letter = et_pb_responsive_options()->get_property_values($this->props, 'chosen_file_text_letterspace');
            et_pb_responsive_options()->generate_responsive_css($d_chosen_file_letter, $file_chosen_class, 'letter-spacing', $this->render_slug);
            /**
             * Button
             */
            $use_file_button_icon = isset($this->props['use_file_button_icon']) ? $this->props['use_file_button_icon'] : 'on';
            $file_button_class = '%%order_class%% .et_pb_files_container .et_pb_file_upload_button.et_pb_button';
            $file_button_font = isset($this->props['file_button_font']) ? $this->props['file_button_font'] : null;
            $is_file_button_font_responsive = et_pb_responsive_options()->is_responsive_enabled($this->props, 'file_button_font');
            if (!empty($file_button_font)) {
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => $file_button_class,
                    'declaration' => sprintf('%s;', et_builder_set_element_font($file_button_font)),
                ]);
            }
            if ($is_file_button_font_responsive) {
                $file_button_font_tablet = isset($this->props['file_button_font_tablet']) ? $this->props['file_button_font_tablet'] : null;
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => $file_button_class,
                    'declaration' => sprintf('%s;', et_builder_set_element_font($file_button_font_tablet)),
                    'media_query' => ET_Builder_Element::get_media_query('max_width_980'),
                ]);
            }
            if ($is_file_button_font_responsive) {
                $file_button_font_phone = isset($this->props['file_button_font_phone']) ? $this->props['file_button_font_phone'] : null;
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => $file_button_class,
                    'declaration' => sprintf('%s;', et_builder_set_element_font($file_button_font_phone)),
                    'media_query' => ET_Builder_Element::get_media_query('max_width_767'),
                ]);
            }
            $d_file_button_color = et_pb_responsive_options()->get_property_values($this->props, 'file_button_color');
            et_pb_responsive_options()->generate_responsive_css($d_file_button_color, $file_button_class, 'color', $this->render_slug, '', 'color');
            if (et_pb_hover_options()->is_enabled('file_button_color', $this->props)) {
                $file_button_color_hover = et_pb_hover_options()->get_value('file_button_color', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:hover",
                    'declaration' => "color:$file_button_color_hover !important;"
                ]);
            }
            $d_file_button_background = pwh_dcfh_module_helpers()::get_global_color(et_pb_responsive_options()->get_property_values($this->props, 'file_button_background'));
            et_pb_responsive_options()->generate_responsive_css($d_file_button_background, $file_button_class, 'background', $this->render_slug, '', 'color');
            if (et_pb_hover_options()->is_enabled('file_button_background', $this->props)) {
                $file_button_background_hover = et_pb_hover_options()->get_value('file_button_background', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:hover",
                    'declaration' => "background:$file_button_background_hover !important;"
                ]);
            }
            $d_file_button_size = et_pb_responsive_options()->get_property_values($this->props, 'file_button_size');
            et_pb_responsive_options()->generate_responsive_css($d_file_button_size, $file_button_class, 'font-size', $this->render_slug);
            if (et_pb_hover_options()->is_enabled('file_button_size', $this->props)) {
                $file_button_size_hover = et_pb_hover_options()->get_value('file_button_size', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:hover",
                    'declaration' => "font-size:$file_button_size_hover !important;"
                ]);
            }
            $d_file_button_letter = et_pb_responsive_options()->get_property_values($this->props, 'file_button_letter_space');
            if (et_pb_hover_options()->is_enabled('file_button_letter_space', $this->props)) {
                $file_button_letter_space_hover = et_pb_hover_options()->get_value('file_button_letter_space', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:hover",
                    'declaration' => "letter-spacing:$file_button_letter_space_hover !important;"
                ]);
            }
            et_pb_responsive_options()->generate_responsive_css($d_file_button_letter, $file_button_class, 'letter-spacing', $this->render_slug);
            $d_file_button_line_height = et_pb_responsive_options()->get_property_values($this->props, 'file_button_line_height');
            et_pb_responsive_options()->generate_responsive_css($d_file_button_line_height, $file_button_class, 'line-height', $this->render_slug);
            if (et_pb_hover_options()->is_enabled('file_button_line_height', $this->props)) {
                $file_button_line_height_hover = et_pb_hover_options()->get_value('file_button_line_height', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:hover",
                    'declaration' => "line-height:$file_button_line_height_hover !important;"
                ]);
            }
            $d_file_button_margin = et_pb_responsive_options()->get_property_values($this->props, 'file_button_margin');
            $d_file_button_margin = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props($d_file_button_margin);
            et_pb_responsive_options()->generate_responsive_css($d_file_button_margin, $file_button_class, 'margin', $this->render_slug, '', 'custom_padding');
            if (et_pb_hover_options()->is_enabled('file_button_margin', $this->props)) {
                $file_button_margin_hover = explode('|', et_pb_hover_options()->get_value('file_button_margin', $this->props));
                if (count($file_button_margin_hover) >= 4) {
                    list($top, $right, $bottom, $left) = $file_button_margin_hover;
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$file_button_class:hover",
                        'declaration' => "margin:$top $right $bottom $left;"
                    ]);
                }

            }
            $d_file_button_padding = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props(et_pb_responsive_options()->get_property_values($this->props, 'file_button_padding'));
            et_pb_responsive_options()->generate_responsive_css($d_file_button_padding, $file_button_class, 'padding', $this->render_slug, '!important;', 'custom_padding');
            if (et_pb_hover_options()->is_enabled('file_button_padding', $this->props)) {
                $file_button_padding_hover = explode('|', et_pb_hover_options()->get_value('file_button_padding', $this->props));
                if (count($file_button_padding_hover) >= 4) {
                    list($top, $right, $bottom, $left) = $file_button_padding_hover;
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$file_button_class:hover",
                        'declaration' => "padding:$top $right $bottom $left;"
                    ]);
                }
            }
            $d_file_button_border = et_pb_responsive_options()->get_property_values($this->props, 'file_button_border');
            $d_file_button_border = pwh_dcfh_module_helpers()::get_responsive_margin_padding_border_props($d_file_button_border);
            et_pb_responsive_options()->generate_responsive_css($d_file_button_border, $file_button_class, 'border-radius', $this->render_slug, '', 'border-radius');
            $d_file_button_border_color = et_pb_responsive_options()->get_property_values($this->props, 'file_button_border_color');
            et_pb_responsive_options()->generate_responsive_css($d_file_button_border_color, $file_button_class, 'border-color', $this->render_slug, '', 'color');
            if (et_pb_hover_options()->is_enabled('file_button_border_color', $this->props)) {
                $file_button_border_color_hover = et_pb_hover_options()->get_value('file_button_border_color', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:hover",
                    'declaration' => "border-color:$file_button_border_color_hover !important;"
                ]);
            }
            $d_file_button_border_width = et_pb_responsive_options()->get_property_values($this->props, 'file_button_border_width');
            et_pb_responsive_options()->generate_responsive_css($d_file_button_border_width, $file_button_class, 'border-width', $this->render_slug);
            if (et_pb_hover_options()->is_enabled('file_button_border_width', $this->props)) {
                $file_button_border_width = et_pb_hover_options()->get_value('file_button_border_width', $this->props);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:hover",
                    'declaration' => "border-width:$file_button_border_width !important;"
                ]);
            }
            $d_file_button_border_style = et_pb_responsive_options()->get_property_values($this->props, 'file_button_border_style');
            et_pb_responsive_options()->generate_responsive_css($d_file_button_border_style, $file_button_class, 'border-style', $this->render_slug, '', 'select');
            if ('on' === $use_file_button_icon) {
                $file_button_icon = !empty($this->props['file_button_icon']) ? $this->props['file_button_icon'] : '5';
                $file_button_icon_processed = html_entity_decode(esc_attr(et_pb_process_font_icon($file_button_icon)));
                if ((function_exists('et_pb_get_icon_font_family') && function_exists('et_pb_get_icon_font_weight'))) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$file_button_class:after, $file_button_class:before",
                        'declaration' => sprintf("font-family:%s !important;font-weight:%s !important;", et_pb_get_icon_font_family($file_button_icon), et_pb_get_icon_font_weight($file_button_icon)),
                    ]);
                }
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:after, $file_button_class:before",
                    'declaration' => "content:'$file_button_icon_processed' !important;",
                ]);
                $d_file_button_icon_color = et_pb_responsive_options()->get_property_values($this->props, 'file_button_icon_color');
                et_pb_responsive_options()->generate_responsive_css($d_file_button_icon_color, "$file_button_class:before,$file_button_class:after", 'color', $this->render_slug, '!important;', 'color');
                if (et_pb_hover_options()->is_enabled('file_button_icon_color', $this->props)) {
                    $file_button_icon_color_hover = et_pb_hover_options()->get_value('file_button_icon_color', $this->props);
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$file_button_class:hover:before,$file_button_class:hover:after",
                        'declaration' => "color:$file_button_icon_color_hover !important;"
                    ]);
                }
                $d_file_button_icon_size['desktop'] = '';
                $d_file_button_icon_size['tablet'] = '';
                $d_file_button_icon_size['phone'] = '';
                if ('20px' !== $d_file_button_size['desktop']) {
                    $d_file_button_icon_size['desktop'] = '1.6em';
                }
                if (!empty($d_file_button_size['tablet']) && '20px' !== $d_file_button_size['tablet']) {
                    $d_file_button_icon_size['tablet'] = '1.6em';
                }
                if (!empty($d_file_button_size['phone']) && '20px' !== $d_file_button_size['phone']) {
                    $d_file_button_icon_size['phone'] = '1.6em';
                }
                et_pb_responsive_options()->generate_responsive_css($d_file_button_icon_size, "$file_button_class:before,$file_button_class:after", 'font-size', $this->render_slug);
                $file_button_icon_on_hover = isset($this->props['file_button_icon_on_hover']) ? $this->props['file_button_icon_on_hover'] : 'on';
                $file_button_icon_placement_desktop = isset($this->props['file_button_icon_placement']) ? $this->props['file_button_icon_placement'] : 'right';
                $file_button_icon_placement_tablet = isset($this->props['file_button_icon_placement_tablet']) ? $this->props['file_button_icon_placement_tablet'] : 'right';
                $file_button_icon_placement_phone = isset($this->props['file_button_icon_placement_phone']) ? $this->props['file_button_icon_placement_phone'] : 'right';
                if ('off' === $file_button_icon_on_hover) {
                    if ('right' === $file_button_icon_placement_desktop) {
                        ET_Builder_Element::set_style($this->render_slug, [
                            'selector' => "$file_button_class",
                            'declaration' => "padding-right: 2em;padding-left: 0.7em;",
                        ]);
                        ET_Builder_Element::set_style($this->render_slug, [
                            'selector' => "$file_button_class:after",
                            'declaration' => "display: inline-block;opacity: 1; margin-left:0; left: auto;",
                        ]);
                    }
                    if ('left' === $file_button_icon_placement_desktop) {
                        ET_Builder_Element::set_style($this->render_slug, [
                            'selector' => "$file_button_class",
                            'declaration' => "padding-right: 0.7em;padding-left: 2em;",
                        ]);
                        ET_Builder_Element::set_style($this->render_slug, [
                            'selector' => "$file_button_class:before",
                            'declaration' => "display: inline-block;opacity: 1; margin-right: 0; right: auto;",
                        ]);
                    }
                }
                if ('left' === $file_button_icon_placement_desktop) {
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$file_button_class:hover:after",
                        'declaration' => "display:none;",
                    ]);
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$file_button_class:hover",
                        'declaration' => "padding-right: 0.7em;padding-left: 2em;",
                    ]);
                    ET_Builder_Element::set_style($this->render_slug, [
                        'selector' => "$file_button_class:hover:before",
                        'declaration' => "display:inline-block;opacity:1;margin-right:0;",
                    ]);
                }

            }
            if ('off' === $use_file_button_icon) {
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:after, $file_button_class:before",
                    'declaration' => 'content:""',
                ]);
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => "$file_button_class:hover",
                    'declaration' => 'padding:0.3em 1em;',
                ]);
            }
            $file_button_shadow = isset($this->props['file_button_shadow']) ? $this->props['file_button_shadow'] : null;
            if (!empty($file_button_shadow) && 'none' !== $file_button_shadow) {
                $shadow = pwh_dcfh_module_helpers()::get_shadow_presets_values($file_button_shadow);
                $horizontal = isset($this->props['file_button_shadow_horizontal']) ? $this->props['file_button_shadow_horizontal'] : $shadow['horizontal'];
                $vertical = isset($this->props['file_button_shadow_vertical']) ? $this->props['file_button_shadow_vertical'] : $shadow['vertical'];
                $blur = isset($this->props['file_button_shadow_blur']) ? $this->props['file_button_shadow_blur'] : $shadow['blur'];
                $spread = isset($this->props['file_button_shadow_spread']) ? $this->props['file_button_shadow_spread'] : $shadow['spread'];
                $color = isset($this->props['file_button_shadow_color']) ? $this->props['file_button_shadow_color'] : 'rgba(0,0,0,0.3)';
                $position = isset($this->props['file_button_shadow_position']) ? $this->props['file_button_shadow_position'] : $shadow['position'];
                ET_Builder_Element::set_style($this->render_slug, [
                    'selector' => $file_button_class,
                    '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;",
                ]);
            }
        }

    }
}