<?php
if(!$data->is_user) return;
$profile_fields = array();
$profile_fields = isset($data->custom_fields) && !empty($data->custom_fields) ? array_keys($data->custom_fields) : array();
?>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="rm-submission" id="rm_my_details_tab">
            <div class="rm-user-details-card">
                <div class="rm-user-fields-container1">
                    <?php
                    if ($data->user->first_name)
                    {
                        ?>
                        <div class="rm-user-field-row">
                            <div class="rm-user-field-label"><?php echo RM_UI_Strings::get('FIELD_TYPE_FNAME'); ?>:</div>
                            <div class="rm-user-field-value"><?php echo $data->user->first_name; ?></div>
                        </div>
                        <?php
                    }
                    if ($data->user->last_name)
                    {
                        ?>

                        <div class="rm-user-field-row">
                            <div class="rm-user-field-label"><?php echo RM_UI_Strings::get('FIELD_TYPE_LNAME'); ?>:</div>
                            <div class="rm-user-field-value"><?php echo $data->user->last_name; ?></div>
                        </div>
                        <?php
                    }
                    if ($data->user->description)
                    {
                        ?>

                        <div class="rm-user-field-row">
                            <div class="rm-user-field-label"><?php echo RM_UI_Strings::get('LABEL_BIO'); ?>:</div>
                            <div class="rm-user-field-value"><?php echo $data->user->description; ?></div>
                        </div>
                        <?php
                    }
                    if ($data->user->user_email)
                    {
                        ?>

                        <div class="rm-user-field-row">
                            <div class="rm-user-field-label"><?php echo RM_UI_Strings::get('LABEL_EMAIL'); ?>:</div>
                            <div class="rm-user-field-value"><?php echo $data->user->user_email; ?></div>
                        </div>
                        <?php
                    }
                    if ($data->user->sec_email)
                    {
                        ?>

                        <div class="rm-user-field-row">
                            <div class="rm-user-field-label"><?php echo RM_UI_Strings::get('LABEL_SECEMAIL'); ?>:</div>
                            <div class="rm-user-field-value"><?php echo $data->user->sec_email; ?></div>
                        </div>
                        <?php
                    }
                    if ($data->user->nickname)
                    {
                        ?>

                        <div class="rm-user-field-row">
                            <div class="rm-user-field-label"><?php echo RM_UI_Strings::get('FIELD_TYPE_NICKNAME'); ?>:</div>
                            <div class="rm-user-field-value"><?php echo $data->user->nickname; ?></div>
                        </div>
                        <?php
                    }
                    if ($data->user->user_url)
                    {
                        ?>

                        <div class="rm-user-field-row">
                            <div class="rm-user-field-label"><?php echo RM_UI_Strings::get('FIELD_TYPE_WEBSITE'); ?>:</div>
                            <div class="rm-user-field-value"><?php echo $data->user->user_url; ?></div>
                        </div>
                        <?php
                    }
                    if (is_array($data->custom_fields) || is_object($data->custom_fields))
                        foreach ($data->custom_fields as $field_id => $sub)
                        {
                            $key = $sub->label;
                            $meta = $sub->value;
                            $sub_original = $sub;
                            if(!isset($sub->type)){
                                $sub->type = '';
                            }

                            $meta = RM_Utilities::strip_slash_array(maybe_unserialize($meta));
                            ?>
                            <div class="rm-user-field-row">

                                <div class="rm-user-field-label"><?php echo $key; ?></div>
                                <div class="rm-user-field-value">
                                    <?php
                                    if (is_array($meta) || is_object($meta)) {
                                        if (isset($meta['rm_field_type']) && $meta['rm_field_type'] == 'File') {
                                            unset($meta['rm_field_type']);
                                            foreach ($meta as $sub) {

                                                $att_path = get_attached_file($sub);
                                                $att_url = wp_get_attachment_url($sub);
                                                ?>
                                                <div class="rm-submission-attachment">
                                                    <?php echo wp_get_attachment_link($sub, 'thumbnail', false, true, false); ?>
                                                    <div class="rm-submission-attachment-field"><?php echo basename($att_path); ?></div>
                                                    <div class="rm-submission-attachment-field"><a href="<?php echo $att_url; ?>"><?php echo RM_UI_Strings::get('LABEL_DOWNLOAD'); ?></a></div>
                                                </div>

                                                <?php
                                            }
                                        } elseif (isset($meta['rm_field_type']) && $meta['rm_field_type'] == 'Address') {
                                            $sub = $meta['original'] . '<br/>';
                                            if (count($meta) === 8) {
                                                $sub .= '<b>Street Address</b> : ' . $meta['st_number'] . ', ' . $meta['st_route'] . '<br/>';
                                                $sub .= '<b>City</b> : ' . $meta['city'] . '<br/>';
                                                $sub .= '<b>State</b> : ' . $meta['state'] . '<br/>';
                                                $sub .= '<b>Zip code</b> : ' . $meta['zip'] . '<br/>';
                                                $sub .= '<b>Country</b> : ' . $meta['country'];
                                            }
                                                echo $sub;
                                        } elseif ($sub->type == 'Time') {                                  
                                    echo $meta['time'].", Timezone: ".$meta['timezone'];
                                } elseif ($sub->type == 'Checkbox') {   
                                    echo implode(', ',RM_Utilities::get_lable_for_option($field_id, $meta));
                                } elseif ($sub->type == 'URL') {
                                    $url = esc_url($meta['url']);
                                    echo wp_kses_post("<a href='$url'>$url</a>");
                                } else {
                                            $sub = implode(', ', $meta);
                                            echo $sub;
                                        }
                                    } else {
                                        if($sub->type=='Rating')
                                        {
                                           echo RM_Utilities::enqueue_external_scripts('script_rm_rating', RM_ADDON_BASE_URL . 'public/js/rating3/jquery.rateit.js');
                                           $r_sub = array('value' => $sub->value,
                                                   'readonly' => 1,
                                                   'max_stars' => 5,
                                                   'star_face' => 'star',
                                                   'star_color' => 'FBC326');
                                            if(isset($sub->meta) && is_object($sub->meta)) {
                                                if(isset($sub->meta->max_stars))
                                                    $r_sub['max_stars'] = $sub->meta->max_stars;
                                                if(isset($sub->meta->star_face))
                                                    $r_sub['star_face'] = $sub->meta->star_face;
                                                if(isset($sub->meta->star_color))
                                                    $r_sub['star_color'] = $sub->meta->star_color;
                                            }
                                            $rf = new Element_Rating("", "", $r_sub);
                                            $rf->render();                 
                                 
                                        }
                                        elseif ($sub->type == 'Radio' || $sub->type == 'Select') {   
                                            echo RM_Utilities::get_lable_for_option($field_id, $meta);
                                        }elseif($sub->type == 'DigitalSign'){
                                            if(!empty($sub_data)){
                                                $sign_url  = RM_BASE_URL . 'plus/signature/signature-access.php?file='.$sub_data;
                                                
                                                ?>
                                                    <div class="rm-submission-attachment">
                                                        <img src="<?php echo esc_url($sign_url);?>" style="max-width:100px;">
                                                        <div class="rm-submission-attachment-field"><a href="<?php echo esc_url($sign_url); ?>"><?php echo wp_kses_post((string)RM_UI_Strings::get('LABEL_DOWNLOAD')); ?></a></div>
                                                    </div>

                                                <?php
                                            }
                                        }
                                        else
                                        echo $meta;
                                    }
                                    ?>
                                </div>
                            </div>
                    <?php
                        }
                    ?>
                    <?php 
                    $exclude_field_type = array('Fname','Lname','Email','Rating','WCBilling','WCShipping');
                    $user_id = get_current_user_id();
                    $user_rm_data = maybe_unserialize(get_user_meta($user_id, 'rm_woo_registration_data', true));
                    if(!empty($user_rm_data)){
                        foreach($user_rm_data as $field_id => $field_data){
                            if(!in_array($field_id,$profile_fields)){
                                if(isset($field_data->type) && !in_array($field_data->type,$exclude_field_type)){
                                    ?>
                                    <div class="rm-user-field-row">
                                        <div class="rm-user-field-label"><?php echo $field_data->label;?></div>
                                        <div class="rm-user-field-value">
                                            <?php
                                            $user_meta_value = $field_data->value;
                                            $meta_field_type = $field_data->type;
                                            if (is_array($user_meta_value) || is_object($user_meta_value)) {
                                                if ($meta_field_type == 'File') {
                                                    foreach ($user_meta_value as $sub) {
                                                        if(absint($sub)){
                                                            $att_path = get_attached_file($sub);
                                                            $att_url = wp_get_attachment_url($sub);
                                                            ?>
                                                            <div class="rm-submission-attachment">
                                                                <?php echo wp_get_attachment_link($sub, 'thumbnail', false, true, false); ?>
                                                                <div class="rm-submission-attachment-field"><?php echo basename($att_path); ?></div>
                                                                <div class="rm-submission-attachment-field"><a href="<?php echo $att_url; ?>"><?php echo RM_UI_Strings::get('LABEL_DOWNLOAD'); ?></a></div>
                                                            </div>

                                                        <?php
                                                        }
                                                    }
                                                } elseif ($meta_field_type == 'Address') {
                                                    $sub = isset($user_meta_value['original']) ? $user_meta_value['original'] : '' . '<br/>';
                                                    if (count($user_meta_value)) {
                                                        $sub .= '<b>Street Address</b> : ' . (isset($user_meta_value['address1']) ? $user_meta_value['address1'] : '') . ', ' . isset($user_meta_value['address2']) ? $user_meta_value['address2']: '' . '<br/>';
                                                        $sub .= '<b>City</b> : ' . isset($user_meta_value['city']) ? $user_meta_value['city'] : '' . '<br/>';
                                                        $sub .= '<b>State</b> : ' . isset($user_meta_value['state']) ? $user_meta_value['state'] : '' . '<br/>';
                                                        $sub .= '<b>Zip code</b> : ' . isset($user_meta_value['zip']) ? $user_meta_value['zip'] : '' . '<br/>';
                                                        $sub .= '<b>Country</b> : ' . isset($user_meta_value['country']) ? $user_meta_value['country'] :'';
                                                    }
                                                    echo $sub;
                                                } elseif ($meta_field_type == 'Time') {                                  
                                                        echo $user_meta_value['time'].", Timezone: ".$user_meta_value['timezone'];
                                                    } elseif ($meta_field_type == 'Checkbox') {   
                                                        echo implode(', ',RM_Utilities::get_lable_for_option($field_id, $user_meta_value));
                                                    } else {
                                                        $sub = implode(', ', $user_meta_value);
                                                        echo $sub;
                                                    }
                                                } else {
                                                if($meta_field_type=='Rating')
                                                {
                                                   echo RM_Utilities::enqueue_external_scripts('script_rm_rating', RM_ADDON_BASE_URL . 'public/js/rating3/jquery.rateit.js');
                                                   $r_sub = array('value' => $user_meta_value,
                                                           'readonly' => 1,
                                                           'max_stars' => 5,
                                                           'star_face' => 'star',
                                                           'star_color' => 'FBC326');

                                                    $rf = new Element_Rating("", "", $r_sub);
                                                    $rf->render();                 

                                                }
                                                elseif ($meta_field_type == 'Radio' || $meta_field_type == 'Select') {   
                                                    echo RM_Utilities::get_lable_for_option($field_id, $user_meta_value);
                                                }
                                                else{
                                                    echo $user_meta_value;
                                                }
                                            }
                                            ?>
                                        </div>
                                    </div>
                                    <?php
                                }
                            }
                        }
                    }
                    ?>
                    
                </div>
            </div>
    </div>
<style>
    #rm_my_details_tab .rm-user-field-row:nth-child(1) { border-top: 2px solid #e5e5e5;}
</style>