ul#second_nav.self_clear
  - case active_menu

  - when :personal
    - if can? :manage, current_user
      = provider_submenu_link "Personal Details", edit_provider_admin_user_personal_details_path

    = provider_submenu_link 'Tokens', provider_admin_user_access_tokens_path

    - if can? :show, current_user.notification_preferences
      = provider_submenu_link "Notification Preferences", provider_admin_user_notification_preferences_path

  - when :account
    = provider_submenu_link "Overview",  provider_admin_account_path

    - if can? :export, :data
      = provider_submenu_link 'Export', new_provider_admin_account_data_exports_path

    - if (can? :update, :logo)
        = provider_submenu_link 'Logo', edit_provider_admin_account_logo_path

    - unless current_account.provider_can_use?(:new_notification_system)
      = provider_submenu_link "Notifications", provider_admin_account_notifications_path

    - if can? :read, Invoice
      = provider_submenu_link '3scale Invoices', provider_admin_account_invoices_path, title: 'invoices'

    - if can? :manage, :credit_card
      = provider_submenu_link 'Credit Card Details', provider_admin_account_braintree_blue_path

    - if can?(:manage, User)
      = provider_submenu_link 'Users', provider_admin_account_users_path
      - if can?(:manage, :multiple_users)
        = provider_submenu_link 'Invitations', provider_admin_account_invitations_path

  - when :monitoring
    = provider_submenu_link 'Analytics', admin_stats_root_path
    = provider_submenu_link 'Alerts', admin_alerts_path if current_account.multiservice?
    = provider_submenu_link 'Traffic', admin_transactions_path
    = provider_submenu_link 'Integration errors', admin_errors_path

  - when :serviceadmin
      = provider_submenu_link 'Overview', admin_services_path
      = provider_submenu_link 'ActiveDocs', admin_api_docs_services_path, title: 'ActiveDocs'

      - if current_account.settings.account_plans.allowed? && current_account.settings.account_plans_ui_visible?
        = provider_submenu_link 'Account Plans', admin_buyers_account_plans_path,
          title: 'Account Plans'

  - when :finance
    = provider_submenu_link 'Earnings by month', admin_finance_root_path, title: :overview
    = provider_submenu_link 'Invoices', admin_finance_invoices_path, title: :invoices
    = provider_submenu_link 'Log', admin_finance_log_entries_path if current_user.username == '3scaleadmin'

  - when :site, :settings
    = provider_submenu_link 'General', edit_admin_site_usage_rules_path
    = provider_submenu_link 'Developer Portal', admin_site_dns_path, title: :portal

    = provider_submenu_link 'Legal Terms', edit_legal_terms_url('signup_licence')

    = provider_submenu_link 'Billing', admin_finance_settings_path, title: :settings, switch: :finance
    = provider_submenu_link 'Policies', edit_admin_site_settings_path, switch: :finance

    = provider_submenu_link 'Fields Definitions', admin_fields_definitions_path

    = provider_submenu_link 'Web Hooks', edit_provider_admin_webhooks_path, title: :web_hooks, switch: :web_hooks, upgrade_notice: true
    = provider_submenu_link 'Emails', edit_admin_site_emails_path

  - when :buyers, :accounts
    - if can? :manage, :partners
      = provider_submenu_link 'Accounts', admin_buyers_accounts_path

    - if can?(:manage, :service_contracts) && current_account.settings.service_plans.allowed? && current_account.settings.service_plans_ui_visible?
      = provider_submenu_link 'Subscriptions', admin_buyers_service_contracts_path

    = provider_submenu_link 'Messages', provider_admin_messages_root_path

    - if current_account.forum_enabled?
      = provider_submenu_link 'Forum', admin_forum_path
  - when :cms
    = provider_submenu_link 'Content', provider_admin_cms_templates_path
    = provider_submenu_link pluralize(number_to_human(current_account.templates.with_draft.size), 'Draft'), provider_admin_cms_changes_path
    = provider_submenu_link 'Redirects', provider_admin_cms_redirects_path
    = provider_submenu_link 'Groups', provider_admin_cms_groups_path , switch: :groups, upgrade_notice: true
    = provider_submenu_link 'Feature Visibility', provider_admin_cms_switches_path

    - unless current_account.master?
      li
        = important_icon_link 'Visit Developer Portal',
                              'external-link',
                              access_code_url(host: current_account.domain, cms_token: current_account.settings.cms_token!,
                              access_code: current_account.site_access_code).html_safe,
                              target: "_blank",
                              class: "preview link--icon-last"
