/**
 * Implements hook_menu().
 */
function custom_userprofile_menu() {
  try {
    var uid = Drupal.user.uid;
    var items = {};
    items['user-profile/%'] = {
      title: 'My Profile',
      page_callback: 'custom_userprofile_page',
      options:{
          reloadPage:true
       }
    };
    items['accountpage'] = {
      title: 'My Account',
      page_callback: 'custom_account_page',
      options:{
          reloadPage:true
       }
    };
    return items;
  }
  catch (error) {
    console.log('custom_userprofile_menu - ' + error);
  }
}

function custom_account_page() {
  try {
    var uid = Drupal.user.uid;  
    var content = {};
    if(uid > 0){
    var items = [
          bl('Home', 'home', {
              attributes: {
                'data-icon': 'home'
              }
          }),
          bl('My Profile', 'user-profile/'+uid, {
              attributes: {
                'data-icon': 'user',
                'class': 'ui-alt-icon',
              }
          }),
          bl('About GVM', 'node/2', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('About Churna', 'node/7', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Donate', 'node/3', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Online Products', 'node/8', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Privacy Policy', 'node/6', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Terms & Conditions', 'node/9', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Logout', 'user/logout', {
              attributes: {
                'data-icon': 'power',
                'class': 'ui-alt-icon',
              }
          }),
        ];    
    }else{
    var items = [
              bl('Login', 'user/login', {
                  attributes: {
                    'data-icon': 'lock'
                  }
              }),    
              bl('Home', 'home', {
                  attributes: {
                    'data-icon': 'home',
                    'class': 'ui-alt-icon',
                  }
              }),
              bl('About GVM', 'node/2', {
                  attributes: {
                    'data-icon': 'info',
                    'class': 'ui-alt-icon',
                  }
              }),
              bl('About Churna', 'node/7', {
                  attributes: {
                    'data-icon': 'info',
                    'class': 'ui-alt-icon',
                  }
              }),
              bl('Donate', 'node/3', {
                  attributes: {
                    'data-icon': 'info',
                    'class': 'ui-alt-icon',
                  }
              }),
              bl('Online Products', 'node/8', {
                  attributes: {
                    'data-icon': 'info',
                    'class': 'ui-alt-icon',
                  }
              }),
              bl('Privacy Policy', 'node/6', {
                  attributes: {
                    'data-icon': 'info',
                    'class': 'ui-alt-icon',
                  }
              }),
              bl('Terms & Conditions', 'node/9', {
                  attributes: {
                    'data-icon': 'info',
                    'class': 'ui-alt-icon',
                  }
              }),
            ];
        }
        if(uid > 0){
            var uname = Drupal.user.name;
            var uemail = Drupal.user.mail;
            //var firstletter = uname.charAt(0).toUpperCase();
            //var initialcircle = "<div style='border-radius:50%;background:green;'>"+ firstletter +"</div>";
            content = '<div><div style="margin-bottom:20px;background:#ffffff;"><table border="0"><tr><td><img src="app/modules/custom/custom_userprofile/avatar101.png" style="width:70px;height:70px;border-radius:50%"></td><td>&nbsp;</td><td>' + uname  + '<br>' + uemail +'</td></tr></table></div>' +  theme('jqm_item_list', { items: items }) +  '</div>';
        }else{
            var uname = "Welcome";
            var uemail = "User";
            content = '<div><div style="margin-bottom:20px;background:#ffffff;"><table border="0"><tr><td><img src="app/modules/custom/custom_userprofile/avatar101.png" style="width:70px;height:70px;border-radius:50%"></td><td>&nbsp;</td><td>' + uname  + '<br>' + uemail +'</td></tr></table></div>' +  theme('jqm_item_list', { items: items }) +  '</div>'; 
        }
        
    return content;
  }
  catch (error) { console.log('custom_account_page - ' + error); }
}
///////////
function custom_userprofile_page() {
  try {
    var content = {};
    content['userprofile'] = {
      theme: 'view',
      format: 'ul', 
      path: 'user-detail-for-mobile-app-json',
      row_callback: 'custom_userprofile_page_row',
      empty_callback: 'custom_userprofile_page_empty'
    };
    return content;
  }
  catch (error) { console.log('custom_userprofile_page - ' + error); }
}

function custom_userprofile_page_row(view, row) {
  try {
    var uid = Drupal.user.uid;
    /*var imgurlarr = [];
    user_load(uid, {
        success: function(account) { console.log(account);
            if (account.picture && account.picture.fid) {
                //
                var image_url  = account.picture.url; 
                imgurlarr.push(image_url);
                var img_obj = {'imgurl':image_url};
                //
            }else{
                var image_url ="";
                imgurlarr.push(image_url);
                var img_obj = {'imgurl':image_url};
            }
            
            console.log(image_url);
        }});*/
    //console.log("array");
    //console.log(Drupal.user); 
 

    
    
    var user_pic = "<br><div style='text-align:center;'><img src='app/modules/custom/custom_userprofile/f1.png' style='border-radius:50%; width:160px !important; text-align:center;'></div><br>";
    var profile_basic_detail = "<fieldset style='border-radius:10%; background:#f2f2f2;padding:20px;'><legend style='font-size:20px;color:#f76e00;'>User Detail</legend>";
        profile_basic_detail += "<div style='font-size:14px;'><table border='0' cellspacing='0' cellpadding='5'>";
        profile_basic_detail += "<tr><td><b>Username</b><br>"+ row.username +"</td></tr>";
        profile_basic_detail += "<tr><td><b>Email ID</b><br>"+ row.email +"</td></tr>";
        profile_basic_detail += "<tr><td><b>Roles</b><br>"+ row.roles +"</td></tr>";
        profile_basic_detail += "</table></div>";
        profile_basic_detail += "</fieldset>";
        
    var profile_basic_detail1 = "<br><fieldset style='border-radius:10%; background:#f2f2f2;padding:20px;'><legend style='font-size:20px;color:#f76e00;'>Other Detail</legend>";
        profile_basic_detail1 += "<div style='font-size:14px;'><table border='0' cellspacing='0' cellpadding='5'>";
        profile_basic_detail1 += "<tr><td><b>Member Since</b><br>"+ row.member_since +"</td></tr>";
        profile_basic_detail1 += "<tr><td><b>Last Access</b><br>"+ row.last_access +"</td></tr>";
        profile_basic_detail1 += "</table></div>";
        profile_basic_detail1 += "</fieldset>";    
    
    var html = user_pic  + profile_basic_detail + profile_basic_detail1;
    return html;
  }
  catch (error) { console.log('custom_userprofile_page_row - ' + error); }
}

function custom_userprofile_page_empty(view) {
  try {
    return "No data found.";
  }
  catch (error) { console.log('custom_userprofile_page_empty - ' + error); }
}

 