<?php
defined('ABSPATH') || die('Cheatin\' uh?');

class Strb_Edit_Author{

   public static function add(){
    //show_user_profile
        add_action('show_user_profile',array('Strb_Edit_Author','extra_field_func'));
        add_action('edit_user_profile',array('Strb_Edit_Author','extra_field_func'));
        add_action('edit_user_profile_update',array('Strb_Edit_Author','save_extra_user_field'));
        add_action('personal_options_update',array('Strb_Edit_Author','save_extra_user_field'));
    }
    static function extra_field_func($user){
        $id=$user->ID;
        $STB_user_data = new STRB_Models_ThemeUserData();
        $STB_user_data ->loadUserDataByID($id);        
    ?>

    


    <!--Social-->
    <link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'> 
    <div style="width:40vw;background-color:white;padding-bottom:20px;padding-left:20px;padding-top:20px;box-shadow:0 0 4px gray;border-radius:6px;margin-top:20px; ">
    
    <div style="display:flex;gap:70px;">

    <div class="fields" style="display:flex;flex-direction:column;gap:15px;">   
        <div class="input-fields">
            <div>
                <label style="font-weight:500;font-size:16px;">Social text:</label>  
            </div>
            <input type="text" name ='isocial' placeholder="<?php echo esc_html__("Social text", 'squirrly-seo'); ?>" 
            value="<?php echo $STB_user_data->getData("social");?>">
        </div>

        <div class="input-fields">
            <div style="display:flex;align-items:center;font-size:18px;">
                <i class="bx bxl-facebook-circle" style="color:#3c434a"></i>
                <label style="font-weight:500;margin-left:5px;margin-top:-3px;font-size:16px;">Facebook:</label>  
            </div> 
            <input type="text" name ='ifacebook' style="margin-top:2px;" placeholder="Facebook" value="<?php echo $STB_user_data->getData("facebook");?>">
        </div>
               
        <div class="input-fields">
            <div style="display:flex;align-items:center;font-size:18px;">
                <i class="bx bxl-twitter" style="color:#3c434a"></i>
                <label style="font-weight:500;margin-left:5px;margin-top:-3px;font-size:16px;">Twitter:</label>
            </div>   
            <input type="text" name ='itwitter' style="margin-top:2px;" placeholder="Twitter" value="<?php echo $STB_user_data->getData("twitter");?>">
        </div>
           
        <div class="input-fields">
            <div style="display:flex;align-items:center;font-size:18px;">
                <i class="bx bxl-github" style="color:#3c434a;"></i>
                <label style="font-weight:500;margin-left:5px;margin-top:-3px;font-size:16px;">Github:</label>
            </div>   
            <input type="text" name ='igit' style="margin-top:2px;" placeholder="Github" value="<?php echo $STB_user_data->getData("git");?>">
        </div>

        <div class="input-fields">
            <div style="display:flex;align-items:center;font-size:18px;">
                <i class="bx bxl-instagram-alt" style="color:#3c434a;"></i>
                <label style="font-weight:500;margin-left:5px;margin-top:-3px;font-size:16px;">Instagram:</label>
            </div>   
            <input type="text" name ='iinsta' style="margin-top:2px;" placeholder="Instagram" value="<?php echo $STB_user_data->getData("insta");?>">
        </div>

        <div class="input-fields">
            <div style="display:flex;align-items:center;font-size:18px;">
                <i class="bx bxl-youtube" style="color:#3c434a;"></i>
                <label style="font-weight:500;margin-left:5px;margin-top:-3px;font-size:16px;">Youtube:</label>
            </div>   
            <input type="text" name ='iyoutube' style="margin-top:2px;" placeholder="Youtube" value="<?php echo $STB_user_data->getData("youtube");?>">
        </div>
        
        <div class="input-fields">
            <div style="display:flex;align-items:center;font-size:18px;">
                <i class="bx bxl-pinterest" style="color:#3c434a;"></i>
                <label style="font-weight:500;margin-left:5px;margin-top:-3px;font-size:16px;">Pinterest:</label>
            </div>   
            <input type="text" name ='ipin' style="margin-top:2px;" placeholder="Pinterest" value="<?php echo $STB_user_data->getData("pin");?>">
        </div>

        <div class="input-fields">
            <div style="display:flex;align-items:center;font-size:18px;">
                <i class="bx bxl-gmail" style="color:#3c434a;"></i>
                <label style="font-weight:500;margin-left:5px;margin-top:-3px;font-size:16px;">Email:</label>
            </div>   
            <input type="text" name ='iemail' style="margin-top:2px;" placeholder="Email" value="<?php echo $STB_user_data->getData("email");?>">
        </div>  

        <div class="input-fields">
            <div style="display:flex;align-items:center;font-size:18px;">
                <i class="bx bxl-tiktok" style="color:#3c434a;"></i>
                <label style="font-weight:500;margin-left:5px;margin-top:-3px;font-size:16px;">Tiktok:</label>
            </div>   
            <input type="text" name ='itok' style="margin-top:2px;" placeholder="Tiktok" value="<?php echo $STB_user_data->getData("tok");?>">
        </div> 

        <div class="input-fields">
            <div style="display:flex;align-items:center;font-size:18px;">
                <i class="bx bxl-linkedin-square" style="color:#3c434a;"></i>
                <label style="font-weight:500;margin-left:5px;margin-top:-3px;font-size:16px;">LinkedIn:</label>
            </div>   
            <input type="text" name ='itok' style="margin-top:2px;" placeholder="LinkedIn" value="<?php echo $STB_user_data->getData("tok");?>">
        </div> 
    </div>


    <div style="">
        <div>
        <div>   
            <label style="font-weight:500;font-size:15px;">Job Title:</label>
        </div>
        <input type="text" name ='ijob' style="margin-top:2px;" placeholder="Enter your job title" value="<?php echo $STB_user_data->getData("job");?>" >
        </div>
                    
        <div style="margin-top:12px;">
        <div>
            <label style="font-weight:500;font-size:15px;">Company:</label>
        </div>
        <input type="text" name ='icompany' style="margin-top:2px;"  placeholder="Enter company name" value="<?php echo $STB_user_data->getData("company");?>" >
        </div>
                        
        <div style="margin-top:12px;">
        <div>
            <label style="font-weight:500;font-size:15px;">Company URL:</label>
        </div>
        <input type="text" name ='icompanyurl' style="margin-top:2px;" placeholder="Enter company url" value="<?php echo $STB_user_data->getData("companyurl");?>" >
        </div>

        <div style="margin-left:0px;margin-top:20px;">
            <div>
                <input type="hidden" value="empty" class="user-image" name="image"/>
                <?php wp_enqueue_media();?>
            </div>
            <div class="show-image" style="width:130px;height:110px;object-fit:cover;border-radius:0px;border: 2px solid rgb(215, 215, 228);"></div>
            <input class="img-select" type="button" style="width:100px;margin-left:15px;margin-top:10px;" value="Load Image" id="btn" >
        </div>
    </div>
    </div>
 
    </div>

   
    

    <?php
    }
    /**
     * save extra user field
     */
   static function save_extra_user_field($user_id){
        if(empty($user_id)){
            return;}

        if(empty($_POST['_wpnonce']) || wp_verify_nonce($_POST['_wpnonce'],
        'update-user'.$user_id)){
            return;}
           
        if(!current_user_can('manage_options')){
            return;}

        $STB_user_data = new STRB_Models_ThemeUserData();

        $STB_user_data->setData("job",$_POST['ijob']);
        $STB_user_data->setData("company",$_POST['icompany'] );
        $STB_user_data->setData("companyurl",$_POST['icompanyurl'] );
        $STB_user_data->setData("img",$_POST['image']);   
        $STB_user_data->setData("social",$_POST['isocial'] );
        $STB_user_data->setData("facebook",$_POST['ifacebook']);
        $STB_user_data->setData("twitter",$_POST['itwitter']);
        $STB_user_data->setData("git",$_POST['igit']);
        $STB_user_data->setData("insta",$_POST['iinsta'] );
        $STB_user_data->setData("youtube",$_POST['iyoutube']);
        $STB_user_data->setData("pin",$_POST['ipin']);
        $STB_user_data->setData("email",$_POST['iemail']);
        $STB_user_data->setData("tok",$_POST['itok'] );
        
        STRB_Classes_Helpers_Tools::saveUserMeta('strb_user_main_meta', $STB_user_data->toMysql(),$user_id);
        
        // if($_POST['image']!='')
        // update_user_meta($user_id,'strb_img',$_POST['image']);
    }
}