<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

if ( ! class_exists( 'Gridpress_Form_Fields' ) ) {

    class Gridpress_Form_Fields {

        public static function gridpress_allowed_tags_attributes($gridpress_ext_attr_list = []) {

            $gridpress_attr_list = [
                'type'     => [],
                'id'       => [],
                'name'     => [],
                'value'    => [],
                'readonly' => [],
                'required' => [],
                'class'    => [],
                'for'      => [],
                'multiple' => [],
                'selected' => [],
                'checked'  => [],
                'src'      => [],
                'alt'      => [],
                'style'    => [],
            ];

            if (!empty($gridpress_ext_attr_list)) {
                foreach ($gridpress_ext_attr_list as $gridpress_attr_name => $gridpress_attr_val) {
                    $gridpress_attr_list[sanitize_key($gridpress_attr_name)] = [];
                }
            }

            $gridpress_tags_list = [
                'div'      => $gridpress_attr_list,
                'label'    => $gridpress_attr_list,
                'span'     => $gridpress_attr_list,
                'strong'   => $gridpress_attr_list,
                'img'      => $gridpress_attr_list,
                'button'   => $gridpress_attr_list,
                'input'    => $gridpress_attr_list,
                'select'   => $gridpress_attr_list,
                'option'   => $gridpress_attr_list,
                'textarea' => $gridpress_attr_list,
            ];

            return apply_filters('gridpress_fromfield_allowed_tags_attributes', $gridpress_tags_list);
        }

        private static function gridpress_render_classes_attr($gridpress_classes) {
            $gridpress_classes_str = 'gridpress-form-field';
            if (!empty($gridpress_classes)) {
                if (is_array($gridpress_classes)) {
                    $gridpress_classes_clean = array_map('sanitize_html_class', $gridpress_classes);
                    $gridpress_classes_str  .= ' ' . implode(' ', $gridpress_classes_clean);
                } else {
                    $gridpress_classes_str .= ' ' . sanitize_html_class($gridpress_classes);
                }
            }

            return $gridpress_classes_str;
        }

        private static function gridpress_render_extra_attr( $gridpress_attr_list ) {
            $gridpress_attr_str = '';

            if ( ! empty( $gridpress_attr_list ) && is_array( $gridpress_attr_list ) ) {
                foreach ( $gridpress_attr_list as $gridpress_attr_name => $gridpress_attr_val ) {
                    $gridpress_attr_name = sanitize_key( $gridpress_attr_name );
                    if ( '' === $gridpress_attr_val || null === $gridpress_attr_val ) {
                        $gridpress_attr_str .= ' ' . esc_attr( $gridpress_attr_name );
                        continue;
                    }
                    $gridpress_attr_str .= sprintf(
                        /* translators: 1: Attribute HTML name, 2: Attribute HTML value. */
                        ' %s="%s"',
                        esc_attr( $gridpress_attr_name ),
                        esc_attr( $gridpress_attr_val )
                    );
                }
            }
            return $gridpress_attr_str;
        }

        private static function gridpress_input_esc_sanitize($gridpress_value, $gridpress_args = []) {
            if (isset($gridpress_args['validation_type']) && $gridpress_args['validation_type'] == 'email') {
                $gridpress_value = sanitize_email( $gridpress_value );
            } else if (isset($gridpress_args['validation_type']) && $gridpress_args['validation_type'] == 'url') {
                $gridpress_value = esc_url_raw( $gridpress_value );
            } else {
                $gridpress_value = sanitize_text_field( $gridpress_value );
            }

            return $gridpress_value;
        }

        public static function gridpress_input($gridpress_args) {
            $gridpress_input_type_str = isset( $gridpress_args['input_type'] ) ? $gridpress_args['input_type'] : 'text';
            $gridpress_id             = isset( $gridpress_args['id'] ) ? $gridpress_args['id'] : '';
            $gridpress_name           = isset( $gridpress_args['name'] ) ? $gridpress_args['name'] : '';
            $gridpress_default        = isset( $gridpress_args['default'] ) ? $gridpress_args['default'] : '';
            $gridpress_value          = isset( $gridpress_args['value'] ) ? $gridpress_args['value'] : '';
            $gridpress_return         = isset( $gridpress_args['return'] ) ? $gridpress_args['return'] : false;
            $gridpress_classes_arg    = isset( $gridpress_args['classes'] ) ? $gridpress_args['classes'] : '';
            $gridpress_attr_list      = isset( $gridpress_args['extra_attributes'] ) ? $gridpress_args['extra_attributes'] : [];

            $gridpress_attr_id = '';
            if (!empty($gridpress_id)) {
                $gridpress_attr_id = ' id="' . esc_attr($gridpress_id) . '"';
            }

            $gridpress_attr_name = '';
            if (!empty($gridpress_name)) {
                $gridpress_attr_name = ' name="' . esc_attr($gridpress_name) . '"';
            }

            $gridpress_attr_class = self::gridpress_render_classes_attr($gridpress_classes_arg);

            $gridpress_attr_value = '';
            if ( !empty( $gridpress_default ) ) {
                $gridpress_attr_value = ' value="' . esc_attr( self::gridpress_input_esc_sanitize( $gridpress_default, $gridpress_args ) ) . '"';
            }
            if ( !empty( $gridpress_value ) ) {
                $gridpress_attr_value = ' value="' . esc_attr( self::gridpress_input_esc_sanitize( $gridpress_value, $gridpress_args ) ) . '"';
            }
            $gridpress_extra_attr = self::gridpress_render_extra_attr($gridpress_attr_list);

            $gridpress_html = '<input type="' . esc_attr($gridpress_input_type_str) . '"' . $gridpress_attr_id . $gridpress_attr_name . ' class="' . esc_attr($gridpress_attr_class) . '"' . $gridpress_attr_value . $gridpress_extra_attr . '>';

            $gridpress_allowed_tags = self::gridpress_allowed_tags_attributes($gridpress_attr_list);

            if ( $gridpress_return ) {
                return wp_kses( $gridpress_html, $gridpress_allowed_tags );
            }

            echo wp_kses( $gridpress_html, $gridpress_allowed_tags );
        }

        public static function gridpress_textarea($gridpress_args) {
            $gridpress_id          = isset( $gridpress_args['id'] ) ? $gridpress_args['id'] : '';
            $gridpress_name        = isset( $gridpress_args['name'] ) ? $gridpress_args['name'] : '';
            $gridpress_default     = isset( $gridpress_args['default'] ) ? $gridpress_args['default'] : '';
            $gridpress_value       = isset( $gridpress_args['value'] ) ? $gridpress_args['value'] : '';
            $gridpress_return      = isset( $gridpress_args['return'] ) ? $gridpress_args['return'] : false;
            $gridpress_classes_arg = isset( $gridpress_args['classes'] ) ? $gridpress_args['classes'] : '';
            $gridpress_attr_list   = isset( $gridpress_args['extra_attributes'] ) ? $gridpress_args['extra_attributes'] : [];

            $gridpress_attr_id = '';
            if ( !empty($gridpress_id) ) {
                $gridpress_attr_id = ' id="' . esc_attr($gridpress_id) . '"';
            }

            $gridpress_attr_name = '';
            if ( !empty($gridpress_name) ) {
                $gridpress_attr_name = ' name="' . esc_attr($gridpress_name) . '"';
            }

            $gridpress_attr_class = self::gridpress_render_classes_attr($gridpress_classes_arg);

            $gridpress_text_value = '';
            if ( !empty($gridpress_default) ) {
                $gridpress_text_value = $gridpress_default;
            }
            if ( !empty($gridpress_value) ) {
                $gridpress_text_value = $gridpress_value;
            }

            $gridpress_extra_attr = self::gridpress_render_extra_attr($gridpress_attr_list);

            $gridpress_html = '<textarea' . $gridpress_attr_id . $gridpress_attr_name . ' class="' . esc_attr($gridpress_attr_class) . '"' . $gridpress_extra_attr . '>' . esc_textarea($gridpress_text_value) . '</textarea>';

            $gridpress_allowed_tags = self::gridpress_allowed_tags_attributes($gridpress_attr_list);

            if ( $gridpress_return ) {
                return wp_kses($gridpress_html, $gridpress_allowed_tags);
            }

            echo wp_kses($gridpress_html, $gridpress_allowed_tags);
        }

        public static function gridpress_switch_button($gridpress_args) {
            $gridpress_id          = isset( $gridpress_args['id'] ) ? $gridpress_args['id'] : '';
            $gridpress_name        = isset( $gridpress_args['name'] ) ? $gridpress_args['name'] : '';
            $gridpress_default     = isset( $gridpress_args['default'] ) ? $gridpress_args['default'] : '';
            $gridpress_value       = isset( $gridpress_args['value'] ) ? $gridpress_args['value'] : '';
            $gridpress_return      = isset( $gridpress_args['return'] ) ? $gridpress_args['return'] : false;
            $gridpress_classes_arg = isset( $gridpress_args['classes'] ) ? $gridpress_args['classes'] : '';
            $gridpress_attr_list   = isset( $gridpress_args['extra_attributes'] ) ? $gridpress_args['extra_attributes'] : [];

            $gridpress_attr_id = '';
            if ( !empty($gridpress_id) ) {
                $gridpress_attr_id = ' id="' . esc_attr($gridpress_id) . '"';
            }

            $gridpress_attr_name = '';
            if ( !empty($gridpress_name) ) {
                $gridpress_attr_name = ' name="' . esc_attr($gridpress_name) . '"';
            }

            $gridpress_attr_class = self::gridpress_render_classes_attr($gridpress_classes_arg);

            $gridpress_text_value = '';
            if ( !empty($gridpress_default) ) {
                $gridpress_text_value = $gridpress_default;
            }
            if ( !empty($gridpress_value) ) {
                $gridpress_text_value = $gridpress_value;
            }

            if ($gridpress_text_value != 'on') {
                $gridpress_text_value = 'off';
            }

            $gridpress_extra_attr = self::gridpress_render_extra_attr($gridpress_attr_list);

            $gridpress_html = '
            <label class="gridpress-form-switch">
                <input type="hidden"' . $gridpress_attr_name . ' value="' . esc_attr( self::gridpress_input_esc_sanitize($gridpress_text_value, $gridpress_args) ) . '">
                <input type="checkbox"' . $gridpress_attr_id . ' class="' . esc_attr($gridpress_attr_class) . '"' . $gridpress_extra_attr . checked( $gridpress_text_value, 'on', false ) . '>
                <span class="gridpress-btn-slider"></span>
            </label>';

            $gridpress_allowed_tags = self::gridpress_allowed_tags_attributes($gridpress_attr_list);

            if ( $gridpress_return ) {
                return wp_kses($gridpress_html, $gridpress_allowed_tags);
            }

            echo wp_kses($gridpress_html, $gridpress_allowed_tags);
        }

        public static function gridpress_option_buttons($gridpress_args) {
            $gridpress_id          = isset( $gridpress_args['id'] ) ? $gridpress_args['id'] : '';
            $gridpress_name        = isset( $gridpress_args['name'] ) ? $gridpress_args['name'] : '';
            $gridpress_default     = isset( $gridpress_args['default'] ) ? $gridpress_args['default'] : '';
            $gridpress_value       = isset( $gridpress_args['value'] ) ? $gridpress_args['value'] : '';
            $gridpress_return      = isset( $gridpress_args['return'] ) ? $gridpress_args['return'] : false;
            $gridpress_classes_arg = isset( $gridpress_args['classes'] ) ? $gridpress_args['classes'] : '';
            $gridpress_attr_list   = isset( $gridpress_args['extra_attributes'] ) ? $gridpress_args['extra_attributes'] : [];
            $gridpress_options     = isset( $gridpress_args['options'] ) ? $gridpress_args['options'] : [];
            $gridpress_multiple    = isset( $gridpress_args['multiple'] ) ? $gridpress_args['multiple'] : false;

            $gridpress_attr_id = '';
            if ( !empty($gridpress_id) ) {
                $gridpress_attr_id = ' id="' . esc_attr($gridpress_id) . '"';
            }

            $gridpress_is_multi = (bool) $gridpress_multiple;

            $gridpress_attr_name = '';
            if ( !empty($gridpress_name) ) {
                $gridpress_attr_name = ' name="' . esc_attr($gridpress_name) . '"';
            }

            $gridpress_attr_class = self::gridpress_render_classes_attr($gridpress_classes_arg);

            $gridpress_btns_value = '';
            if ( !empty($gridpress_default) ) {
                $gridpress_btns_value = $gridpress_default;
            }
            if ( !empty($gridpress_value) ) {
                $gridpress_btns_value = $gridpress_value;
            }

            $gridpress_extra_attr = self::gridpress_render_extra_attr($gridpress_attr_list);

            $gridpress_html = '<div' . $gridpress_attr_id . ' class="gridpress-form-optbtns ' . esc_attr($gridpress_is_multi ? 'gridpress-checkbox-optbtns' : 'gridpress-radio-optbtns') . '">' . "\n";
            if ( !empty($gridpress_options) && is_array($gridpress_options) ) {
                foreach ($gridpress_options as $gridpress_option_key => $gridpress_option_itm) {
                    $gridpress_rand = wp_rand(1000000, 9999999);
                    if (is_array($gridpress_option_itm) && isset($gridpress_option_itm['label'])) {
                        $gridpress_option_label = $gridpress_option_itm['label'];
                    } else {
                        $gridpress_option_label = $gridpress_option_itm;
                    }

                    $is_checked = false;
                    if (!empty($gridpress_btns_value)) {
                        if (is_array($gridpress_btns_value) && in_array($gridpress_option_key, $gridpress_btns_value)) {
                            $is_checked = true;
                        } else if (!is_array($gridpress_btns_value) && $gridpress_option_key == $gridpress_btns_value) {
                            $is_checked = true;
                        }
                    }
                    $gridpress_checked = $is_checked ? ' checked="checked"' : '';

                    $gridpress_btn_lbl_for = !empty($gridpress_id) ? sanitize_title($gridpress_id) : 'gridpress-optbtn';

                    $gridpress_html .= '<div class="gridpress-form-optbtn' . (!empty($gridpress_checked) ? ' gridpress-chked-optbtn' : '') . '">
                        <input id="' . esc_attr($gridpress_btn_lbl_for . '-' . $gridpress_rand) . '" type="' . esc_attr($gridpress_is_multi ? 'checkbox' : 'radio') . '" class="' . esc_attr($gridpress_attr_class) . '"' . $gridpress_attr_name . $gridpress_extra_attr . ' value="' . esc_attr($gridpress_option_key) . '"' . $gridpress_checked . ' />';
                        if ( is_array( $gridpress_option_itm ) && isset( $gridpress_option_itm['image_url'] ) ) {

                            $gridpress_image_url = esc_url( $gridpress_option_itm['image_url'] );

                            $gridpress_html .= '<div class="chkinp-chkimg-hcon">
                                <span style="' . esc_attr( sprintf( 'background-image:url(%s);', $gridpress_image_url ) ) . '"></span>
                            </div>';
                        } else {
                            $gridpress_html .= '<span class="chkinp-chkmrk"></span>';
                        }
                        $gridpress_html .= '
                        <label for="' . esc_attr($gridpress_btn_lbl_for . '-' . $gridpress_rand) . '" class="gridpress-form-optlbl">
                            <span>' . esc_html($gridpress_option_label) . '</span>
                        </label>
                    </div>' . "\n";
                }
            }
            $gridpress_html .= '</div>' . "\n";

            $gridpress_allowed_tags = self::gridpress_allowed_tags_attributes($gridpress_attr_list);

            if ( $gridpress_return ) {
                return wp_kses($gridpress_html, $gridpress_allowed_tags);
            }
            echo wp_kses($gridpress_html, $gridpress_allowed_tags);
        }

        public static function gridpress_select($gridpress_args) {
            $gridpress_id          = isset( $gridpress_args['id'] ) ? $gridpress_args['id'] : '';
            $gridpress_name        = isset( $gridpress_args['name'] ) ? $gridpress_args['name'] : '';
            $gridpress_default     = isset( $gridpress_args['default'] ) ? $gridpress_args['default'] : '';
            $gridpress_value       = isset( $gridpress_args['value'] ) ? $gridpress_args['value'] : '';
            $gridpress_return      = isset( $gridpress_args['return'] ) ? $gridpress_args['return'] : false;
            $gridpress_classes_arg = isset( $gridpress_args['classes'] ) ? $gridpress_args['classes'] : '';
            $gridpress_attr_list   = isset( $gridpress_args['extra_attributes'] ) ? $gridpress_args['extra_attributes'] : [];
            $gridpress_options     = isset( $gridpress_args['options'] ) ? $gridpress_args['options'] : [];
            $gridpress_multiple    = isset( $gridpress_args['multiple'] ) ? $gridpress_args['multiple'] : false;

            $gridpress_attr_id = '';
            if ( !empty($gridpress_id) ) {
                $gridpress_attr_id = ' id="' . esc_attr($gridpress_id) . '"';
            }

            $gridpress_is_multi = (bool) $gridpress_multiple;

            $gridpress_attr_name = '';
            if ( !empty($gridpress_name) ) {
                $gridpress_attr_name = ' name="' . esc_attr($gridpress_name) . '"';
            }

            $gridpress_attr_class = self::gridpress_render_classes_attr($gridpress_classes_arg);

            $gridpress_dropdown_value = '';
            if ( !empty($gridpress_default) ) {
                $gridpress_dropdown_value = $gridpress_default;
            }
            if ( !empty($gridpress_value) ) {
                $gridpress_dropdown_value = $gridpress_value;
            }

            $gridpress_extra_attr = self::gridpress_render_extra_attr($gridpress_attr_list);

            $gridpress_html  = '<div class="gridpress-select-field' . ($gridpress_is_multi ? ' gridpress-multiselect-field' : '') . '">' . "\n";
            $gridpress_html .= '<select' . $gridpress_attr_id . $gridpress_attr_name . ($gridpress_is_multi ? ' multiple' : '') . ' class="' . esc_attr($gridpress_attr_class) . '"' . $gridpress_extra_attr . '>' . "\n";
            if ( !empty($gridpress_options) && is_array($gridpress_options) ) {
                foreach ($gridpress_options as $gridpress_option_key => $gridpress_option_val) {
                    $gridpress_selected = '';
                    if ($gridpress_is_multi) {
                        if (is_array($gridpress_dropdown_value) && in_array($gridpress_option_key, $gridpress_dropdown_value)) {
                            $gridpress_selected = ' selected="selected"';
                        }
                    } else {
                        if (!is_array($gridpress_dropdown_value)) {
                            $gridpress_selected = $gridpress_dropdown_value == $gridpress_option_key ? ' selected="selected"' : '';
                        }
                    }
                    $gridpress_html .= '<option' . $gridpress_selected . ' value="' . esc_attr( self::gridpress_input_esc_sanitize($gridpress_option_key) ) . '">' . esc_html($gridpress_option_val) . '</option>' . "\n";
                }
            }
            $gridpress_html .= '</select>' . "\n";
            $gridpress_html .= '</div>' . "\n";

            $gridpress_allowed_tags = self::gridpress_allowed_tags_attributes($gridpress_attr_list);

            if ( $gridpress_return ) {
                return wp_kses($gridpress_html, $gridpress_allowed_tags);
            }

            echo wp_kses($gridpress_html, $gridpress_allowed_tags);
        }

        public static function gridpress_color_pickr($gridpress_args) {
            $gridpress_id          = isset( $gridpress_args['id'] ) ? $gridpress_args['id'] : '';
            $gridpress_name        = isset( $gridpress_args['name'] ) ? $gridpress_args['name'] : '';
            $gridpress_default     = isset( $gridpress_args['default'] ) ? $gridpress_args['default'] : '';
            $gridpress_value       = isset( $gridpress_args['value'] ) ? $gridpress_args['value'] : '';
            $gridpress_return      = isset( $gridpress_args['return'] ) ? $gridpress_args['return'] : false;
            $gridpress_classes_arg = isset( $gridpress_args['classes'] ) ? $gridpress_args['classes'] : '';
            $gridpress_attr_list   = isset( $gridpress_args['extra_attributes'] ) ? $gridpress_args['extra_attributes'] : [];

            $gridpress_attr_id = '';
            if ( !empty($gridpress_id) ) {
                $gridpress_attr_id = ' id="' . esc_attr($gridpress_id) . '"';
            }

            $gridpress_attr_name = '';
            if ( !empty($gridpress_name) ) {
                $gridpress_attr_name = ' name="' . esc_attr($gridpress_name) . '"';
            }

            if (is_array($gridpress_classes_arg)) {
                $gridpress_classes_arg[] = 'gridpress-color-field';
            } else {
                $gridpress_classes_arg .= ' gridpress-color-field';
            }
            $gridpress_attr_class = self::gridpress_render_classes_attr($gridpress_classes_arg);

            $gridpress_color_value = '';
            if ( !empty($gridpress_default) ) {
                $gridpress_color_value = $gridpress_default;
            }
            if ( !empty($gridpress_value) ) {
                $gridpress_color_value = $gridpress_value;
            }

            $gridpress_extra_attr = self::gridpress_render_extra_attr($gridpress_attr_list);

            $gridpress_html = '<input type="text"' . $gridpress_attr_id . $gridpress_attr_name . ' class="' . esc_attr($gridpress_attr_class) . '" value="' . esc_attr( self::gridpress_input_esc_sanitize($gridpress_color_value) ) . '"' . $gridpress_extra_attr . '>';

            $gridpress_allowed_tags = self::gridpress_allowed_tags_attributes($gridpress_attr_list);

            if ( $gridpress_return ) {
                return wp_kses($gridpress_html, $gridpress_allowed_tags);
            }

            echo wp_kses($gridpress_html, $gridpress_allowed_tags);
        }

        public static function gridpress_image($gridpress_args) {
            $gridpress_id          = isset( $gridpress_args['id'] ) ? $gridpress_args['id'] : '';
            $gridpress_name        = isset( $gridpress_args['name'] ) ? $gridpress_args['name'] : '';
            $gridpress_id_name     = isset( $gridpress_args['id_name'] ) ? $gridpress_args['id_name'] : '';
            $gridpress_default     = isset( $gridpress_args['default'] ) ? $gridpress_args['default'] : '';
            $gridpress_value       = isset( $gridpress_args['value'] ) ? $gridpress_args['value'] : '';
            $gridpress_id_value    = isset( $gridpress_args['id_value'] ) ? $gridpress_args['id_value'] : '';
            $gridpress_return      = isset( $gridpress_args['return'] ) ? $gridpress_args['return'] : false;
            $gridpress_classes_arg = isset( $gridpress_args['classes'] ) ? $gridpress_args['classes'] : '';
            $gridpress_attr_list   = isset( $gridpress_args['extra_attributes'] ) ? $gridpress_args['extra_attributes'] : [];

            $gridpress_attr_id = '';
            if ( !empty($gridpress_id) ) {
                $gridpress_attr_id = ' id="' . esc_attr($gridpress_id) . '"';
            }

            $gridpress_attr_name = '';
            if ( !empty($gridpress_name) ) {
                $gridpress_attr_name = ' name="' . esc_attr($gridpress_name) . '"';
            }

            $gridpress_attr_id_name = '';
            if ( !empty($gridpress_id_name) ) {
                $gridpress_attr_id_name = ' name="' . esc_attr($gridpress_id_name) . '"';
            }

            $gridpress_attr_class = self::gridpress_render_classes_attr($gridpress_classes_arg);

            $gridpress_img_value = '';
            if ( !empty($gridpress_default) ) {
                $gridpress_img_value = $gridpress_default;
            }
            if ( !empty($gridpress_value) ) {
                $gridpress_img_value = $gridpress_value;
            }

            $gridpress_img_id_value = 0;
            if ( !empty($gridpress_id_value) ) {
                $gridpress_img_id_value = $gridpress_id_value;
            }
            $gridpress_extra_attr     = self::gridpress_render_extra_attr($gridpress_attr_list);
            $gridpress_url_valid_args = ['validation_type' => 'url'];

            $gridpress_html = "\n" . '<div class="gridpress-form-imgfield">
                <div class="gridpress-field-imgcon' . esc_attr($gridpress_img_value == '' ? ' gridpress-hide' : '') . '">
                    <img src="' . esc_url( self::gridpress_input_esc_sanitize($gridpress_img_value, $gridpress_url_valid_args) ) . '" alt="">
                </div>
                <div class="gridpress-field-inputcon">
                    <input type="text"' . $gridpress_attr_id . $gridpress_attr_name . ' class="' . esc_attr($gridpress_attr_class) . '"' . ' value="' . esc_attr( self::gridpress_input_esc_sanitize($gridpress_img_value, $gridpress_url_valid_args) ) . '" readonly' . $gridpress_extra_attr . ' />
                    <input type="hidden"' . $gridpress_attr_id_name . ' value="' . esc_attr($gridpress_img_id_value) . '" />
                </div>
                <div class="gridpress-field-btnscon">
                    <button type="button" class="gridpress-upload-imgbtn button gridpress-button">' . esc_html__('Browse Image', 'gridpress-grid-layout-design') . '</button>
                    <button type="button" class="gridpress-remvupload-imgbtn button gridpress-button' . esc_attr($gridpress_img_value == '' ? ' gridpress-hide' : '') . '">' . esc_html__('Remove', 'gridpress-grid-layout-design') . '</button>
                </div>
            </div>' . "\n";
            $gridpress_allowed_tags = self::gridpress_allowed_tags_attributes($gridpress_attr_list);

            if ( $gridpress_return ) {
                return wp_kses($gridpress_html, $gridpress_allowed_tags);
            }
            echo wp_kses($gridpress_html, $gridpress_allowed_tags);
        }

        public static function gridpress_file($gridpress_args) {
            $gridpress_id          = isset( $gridpress_args['id'] ) ? $gridpress_args['id'] : '';
            $gridpress_name        = isset( $gridpress_args['name'] ) ? $gridpress_args['name'] : '';
            $gridpress_default     = isset( $gridpress_args['default'] ) ? $gridpress_args['default'] : '';
            $gridpress_value       = isset( $gridpress_args['value'] ) ? $gridpress_args['value'] : '';
            $gridpress_btn_txt     = isset( $gridpress_args['btn_txt'] ) ? $gridpress_args['btn_txt'] : '';
            $gridpress_return      = isset( $gridpress_args['return'] ) ? $gridpress_args['return'] : false;
            $gridpress_classes_arg = isset( $gridpress_args['classes'] ) ? $gridpress_args['classes'] : '';
            $gridpress_attr_list   = isset( $gridpress_args['extra_attributes'] ) ? $gridpress_args['extra_attributes'] : [];

            $gridpress_attr_id = '';
            if ( !empty($gridpress_id) ) {
                $gridpress_attr_id = ' id="' . esc_attr($gridpress_id) . '"';
            }

            $gridpress_attr_name = '';
            if ( !empty($gridpress_name) ) {
                $gridpress_attr_name = ' name="' . esc_attr($gridpress_name) . '"';
            }

            $gridpress_attr_class = self::gridpress_render_classes_attr($gridpress_classes_arg);

            $gridpress_browse_txt = esc_html__('Browse File', 'gridpress-grid-layout-design');
            if ( !empty($gridpress_btn_txt) ) {
                $gridpress_browse_txt = esc_html($gridpress_btn_txt);
            }

            $gridpress_file_value = '';
            if ( !empty($gridpress_default) ) {
                $gridpress_file_value = $gridpress_default;
            }
            if ( !empty($gridpress_value) ) {
                $gridpress_file_value = $gridpress_value;
            }
            $gridpress_extra_attr     = self::gridpress_render_extra_attr($gridpress_attr_list);
            $gridpress_url_valid_args = ['validation_type' => 'url'];
            $gridpress_html           = "\n" . '<div class="gridpress-form-filefield">
                <div class="gridpress-field-inputcon">
                    <input type="text"' . $gridpress_attr_id . $gridpress_attr_name . ' class="' . esc_attr($gridpress_attr_class) . '"' . ' value="' . esc_attr( self::gridpress_input_esc_sanitize($gridpress_file_value, $gridpress_url_valid_args) ) . '" ' . $gridpress_extra_attr . ' />
                </div>
                <div class="gridpress-field-btnscon">
                    <button type="button" class="gridpress-upload-filebtn button gridpress-button">' . $gridpress_browse_txt . '</button>
                </div>
            </div>' . "\n";
            $gridpress_allowed_tags = self::gridpress_allowed_tags_attributes($gridpress_attr_list);

            if ( $gridpress_return ) {
                return wp_kses($gridpress_html, $gridpress_allowed_tags);
            }
            echo wp_kses($gridpress_html, $gridpress_allowed_tags);
        }
    }

}