/**
 * Implements hook_block_info().
 */
function custom_slider_block_block_info() {
  try {
    var blocks = {};
    blocks['my_panel_block'] = {
      delta: 'my_panel_block',
      module: 'custom_slider_block'
    };
    blocks['my_panel_block_button'] = {
      delta: 'my_panel_block_button',
      module: 'custom_slider_block'
    };
    blocks['my_panel_block_anonymous'] = {
      delta: 'my_panel_block_anonymous',
      module: 'custom_slider_block'
    };
    blocks['my_panel_block_button_anonymous'] = {
      delta: 'my_panel_block_button_anonymous',
      module: 'custom_slider_block'
    }; 
    return blocks;
  }
  catch (error) { console.log('custom_slider_block_block_info - ' + error); }
}

/**
 * Implements hook_block_view().
 */
function custom_slider_block_block_view(delta, region) {
  try {
    var content = '';
    switch (delta) {

      // The slide menu (aka panel for authenticated users).
      case 'my_panel_block':
        var uid = Drupal.user.uid;
        var uname = Drupal.user.name;
        var attrs = {
          id: drupalgap_panel_id(delta),
          'data-role': 'panel',
          'data-position': 'left', // left or right
          'data-display': 'overlay', // overlay, reveal or push
          'class': 'ui-nodisc-icon',
        };
        var items = [
          bl('Home', 'hostels', {
              attributes: {
                'data-icon': 'home'
              }
          }),
          bl('My Profile', 'user-profile/'+uid, {
              attributes: {
                'data-icon': 'user',
                'class': 'ui-alt-icon',
              }
          }),
          bl('My Addressbook', 'user-dashboard/'+uid, {
              attributes: {
                'data-icon': 'user',
                'class': 'ui-alt-icon',
              }
          }),
          bl('My Orders', 'order-list', {
              attributes: {
                'data-icon': 'bullets',
                'class': 'ui-alt-icon',
              }
          }),
          
          bl('About Us', 'aboutus', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Privacy Policy', 'node/102', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Terms & Conditions', 'node/103', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Contact Us', 'contactusnew', {
              attributes: {
                'data-icon': 'mail',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Logout', 'user/logout', {
              attributes: {
                'data-icon': 'power',
                'class': 'ui-alt-icon',
              }
          }),
        ];
        content += '<div ' + drupalgap_attributes(attrs) + '><div style="margin-bottom:30px;background:#ffffff;"><div class="ui-icon-user" data-icon="user">&nbsp;</div>Welcome ' + uname + '<br><br></div>' +
          '<!-- panel content goes here -->' +
          theme('jqm_item_list', { items: items }) +
        '</div><!-- /panel -->';

        break;
      
          // The slide menu (aka panel for anonymous users).
        case 'my_panel_block_anonymous':

        var attrs = {
          id: drupalgap_panel_id(delta),
          'data-role': 'panel',
          'data-position': 'left', // left or right
          'data-display': 'overlay', // overlay, reveal or push
          'class': 'ui-nodisc-icon',
        };
        var items = [
          bl('Login', 'user/login', {
              attributes: {
                'data-icon': 'lock'
              }
          }),    
          bl('Home', 'hostels', {
              attributes: {
                'data-icon': 'home',
                'class': 'ui-alt-icon',
              }
          }),
          bl('About Us', 'aboutus', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          
          bl('Privacy Policy', 'node/102', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
                
              }
          }),
          bl('Terms & Conditions', 'node/103', {
              attributes: {
                'data-icon': 'info',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Contact Us', 'contactusnew', {
              attributes: {
                'data-icon': 'mail',
                'class': 'ui-alt-icon',
              }
          }),
          bl('Create New Account', 'user/register', {
              attributes: {
                'data-icon': 'user',
                'class': 'ui-alt-icon',
              }
          }),
        ];
        content += '<div ' + drupalgap_attributes(attrs) + '><div style="margin-bottom:30px;background:#ffffff;"><img src="images/gvmlogo.jpg" width="100%"></div>' +
          '<!-- panel content goes here -->' +
          theme('jqm_item_list', { items: items }) +
        '</div><!-- /panel -->';

        break;
      
      // The button to open the menu for authenticated users.
      case 'my_panel_block_button':

        content = bl('Open panel', '#' + drupalgap_panel_id('my_panel_block'), {
            attributes: {
              'data-icon': 'bars',
              'data-iconpos': 'notext',
              'class': 'ui-btn-right', 
              'class': 'ui-nodisc-icon',
            }
        });

        break;
        
        // The button to open the menu for anonymous users.
      case 'my_panel_block_button_anonymous':

        content = bl('Open panel', '#' + drupalgap_panel_id('my_panel_block_anonymous'), {
            attributes: {
              'data-icon': 'bars',
              'data-iconpos': 'notext',
              'class': 'ui-btn-right', 
              'class': 'ui-nodisc-icon',
            }
        });

        break;

    }
    return content;
  }
  catch (error) { console.log('custom_slider_block_block_view - ' + error); }
}
