{% extends 'master.html' %}
{% from 'macros.html' import icon,render_nav_item %}

{% block title%}{{title if title else "Admin"}}{% endblock %}
{% block bodyclass %}{%endblock%}
{% block body_header %}{%endblock%}


{% block nav_bar %}
{% include "donation.html" %}
<!-- Navbar -->
<nav class="main-header hold-transition sidebar-mini-md navbar navbar-expand {{'navbar-dark' if g.darkmode else 'bg-white navbar-light' }} border-bottom">
  <!-- Left navbar links -->



  <div class="navbar-nav">
    <a class="nav-link" data-widget="pushmenu" href="#"><i class="fa fa-bars"></i> <span class="brand-text font-weight-light">{{_("master.page-title")}}
        <!-- <span class="badge d-none d-sm-inline-block">{{version}}</span> -->
        {% if hutils.node.is_parent() %}
        {{_("Parent Panel")}}
        {% elif hutils.node.is_child() %}
        Child Panel
        {% endif %}
    </a>
    <a class="nav-link" href="https://github.com/hiddify/Hiddify-Manager/" target="_blank">
      <img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/hiddify/hiddify-manager?style=social&logo=star&label=%E2%AD%90">

    </a>
  </div>
  <ul class="navbar-nav ml-auto">
    {% if g.darkmode %}
    <a class="nav-link btn" href="?darkmode=false">
      <i class="fa-solid fa-sun"></i>
    </a>
    {% else %}
    <a class="nav-link btn" href="?darkmode=true">
      <i class="fa-solid fa-moon"></i>
    </a>
    {% endif %}
    {% if 0 and not hutils.node.is_parent() %}


    <a class="nav-link btn btn-outline-secondary form_post d-none d-md-flex" href="{{hurl_for('admin.Actions:apply_configs')}}">
      {{icon('solid','bolt','nav-icon')}} {{_('admin.Actions:apply_configs')}}
    </a>

    {% endif %}

  </ul>
</nav>
<!-- /.navbar -->




<!-- Main Sidebar Container -->
<aside id="main-sidebar" class="main-sidebar {{'sidebar-dark-primary' if g.darkmode else ''}} elevation-4">
  <!-- Brand Logo -->

  <a href="https://github.com/hiddify/hiddify-manager/wiki" class="" style="text-align: center; color: white;display: block;">
    <img src="{{static_url_for(filename='images/WhiteLogo.png')}}" class=" " style="width: 50%;opacity: .8;margin: auto;display:block" />
    <div class="ltr" style="font-size: 8pt;">{{version}}</div>
    {% if False and hutils.node.is_parent() %}
    <br>
    <!-- <span class="badge">{{_("Parent Panel")}}</span> -->


    {% endif %}
  </a>



  <!-- Sidebar -->
  <div class="sidebar">
    <div>
      <!-- Sidebar user panel (optional) -->


      <!-- Sidebar Menu -->
      <nav class="mt-2">
        <div class="n3av nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
          <!-- Add icons to the links using the .nav-icon class
                 with font-awesome or any other icon font library -->
          {{ render_nav_item('admin.Dashboard:index', icon('solid','house','nav-icon')+(_("Parent Panel") if hutils.node.is_parent() else _('admin.menu.home')),_use_li=True)}}

          {% if hutils.node.is_child() %}
          {{ render_nav_item(hconfig(ConfigEnum.parent_panel)+"/"+g.account.uuid+"/admin/user/",icon('solid','user-secret','nav-icon')+_('admin.menu.user'),_badge=_('in parent panel') ,_use_li=True) }}
          {% else %}
          {{ render_nav_item('flask.user.index_view', icon('solid','user','nav-icon')+_('admin.menu.user'),_use_li=True)}}
          {% endif %}

          {% if hutils.node.is_child() %}
          {{ render_nav_item(hconfig(ConfigEnum.parent_panel)+"/"+g.account.uuid+"/admin/adminuser/",icon('solid','user-secret','nav-icon')+_('Admins'),_badge=_('in parent panel') ,_use_li=True) }}
          {% else %}
          {{ render_nav_item('flask.adminuser.index_view', icon('solid','user-secret','nav-icon')+_('Admins'),_use_li=True) }}
          {% endif %}


          {% if g.account.mode!="agent" %}
          {% set settings_active = False if request.endpoint and ("user" in request.endpoint or "Actions:" in
          request.endpoint or "Dashboard" in request.endpoint) else True %}
          <li class="nav-item {{'menu-open' if settings_active else ''}}">

            <a id="" href="#" data-target="#setting-sidebar" class="nav-link">{{icon('solid','gear','nav-icon')+_('admin.menu.config')}}</a>

          </li>
          {% endif %}
          {% if hconfig(ConfigEnum.license) %}
          {% else %}
          {% if false %}
          {{ render_nav_item('admin.CommercialInfo:index', icon('solid','dumpster','nav-icon')+
          _('Commercial use'),_use_li=True) }}
          {% endif %}
          {% endif %}
          {% set action_active = True if request.endpoint and "Actions:" in request.endpoint else False %}
          {% if g.account.mode=="super_admin" %}
          <li class="nav-item {{'menu-open' if action_active else ''}}">

            <a id=href="#" data-target="#action-sidebar" class="nav-link">{{icon('solid','suitcase','nav-icon')+_('admin.actions.title')}} <i class="right fas fa-angle-left"></i></a>

          </li>
          {% endif %}

          <li class="nav-item">
            <a href="https://github.com/hiddify/hiddify-manager/wiki/{{'%D9%87%D9%85%D9%87-%D8%A2%D9%85%D9%88%D8%B2%D8%B4%E2%80%8C%D9%87%D8%A7-%D9%88-%D9%88%DB%8C%D8%AF%D8%A6%D9%88%D9%87%D8%A7' if get_locale()=='fa' else 'All-tutorials-and-videos'}}"
              target="_blank" class=" nav-link">{{icon('solid','circle-question','nav-icon')+_('admin.menu.support')}}</a>
          </li>
          <li class="nav-item d-none">
            <a href="https://t.me/hiddify" target="_blank" class="nav-link">{{icon('brands','telegram','nav-icon')+_('admin.menu.telegram')}}</a>
          </li>
          <li class="nav-item">
            {% set issue_link = generate_github_issue_link_for_admin_sidebar() %}
          <li class="nav-item">
            <a href="{{issue_link}}" target="_blank" class=" nav-link">{{icon('solid','bug','nav-icon')+_('Bug')}}</a>
          </li>
          </li>
          <li class="nav-item">
            <a class="nav-item nav-link" role="button" data-toggle="modal" data-target="#modal-donation">
              {{icon('solid','heart','nav-icon')+_("Donation.title")}}
            </a>
          </li>
        </div>

      </nav>
      <!-- /.sidebar-menu -->
    </div>
  </div>
  <!-- /.sidebar -->
</aside>



<!-- Sub Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4 sub-sidebar">
  <!-- Sidebar -->
  <div class="sidebar">

    <!-- Sub Sidebar Menu -->
    <nav class="mt-2">
      <ul class="nav nav-pills nav-sidebar flex-column" id="sub-sidebar">

        <div class="nav-item" id="action-sidebar">
          {{ render_nav_item('admin.Actions:status',icon('solid','signal','nav-icon')+ _('admin.actions.status'),
          _use_li=True) }}
          {{ render_nav_item('admin.Actions:viewlogs',icon('solid','inbox','nav-icon')+ _('admin.actions.viewlogs'),
          _use_li=True) }}
          {{ render_nav_item('admin.Actions:apply_configs',icon('solid','bolt','nav-icon')+
          _('admin.actions.apply_configs'), _use_li=True,extra_class="form_post") }}
          {{ render_nav_item('admin.Actions:update',
          icon('solid','arrow-up-from-bracket','nav-icon')+_('admin.actions.update'),
          _use_li=True,extra_class="form_post") }}
          {{ render_nav_item('admin.Actions:reinstall', icon('solid','rotate','nav-icon')+_('admin.actions.reinstall'),
          _use_li=True,extra_class="form_post") }}
          {{ render_nav_item('admin.Actions:reset', icon('solid','power-off','nav-icon')+_('admin.actions.reset'),
          _use_li=True,extra_class="form_post") }}

        </div>
        <div class="nav-item" id="setting-sidebar">




          {{ render_nav_item('flask.domain.index_view',
          icon('solid','link','nav-icon')+_('admin.menu.domain'),_use_li=True) }}
          {{ render_nav_item('admin.ProxyAdmin:index',
          icon('solid','arrow-down-up-lock','nav-icon')+_('admin.menu.proxy'),_use_li=True) }}
          {% if g.account.mode=='super_admin' %}
          {{ render_nav_item('admin.SettingAdmin:index',icon('solid','gears','nav-icon')+
          _('admin.menu.config'),_use_li=True) }}
          {{ render_nav_item('admin.Backup:index',icon('solid','floppy-disk','nav-icon')+ _('Backup'), _use_li=True) }}
          {% endif %}

          {% if hconfig(ConfigEnum.telegram_bot_token) and g.bot %}
          {{ render_nav_item("tg://resolve?domain="+g.bot.username+"&start=admin_"+g.account.uuid,
          icon('brands','telegram','nav-icon')+_('Telegram Bot'),_use_li=True) }}
          {% endif %}

          {% if g.account.mode=="super_admin" %}
          {{ render_nav_item('openapi.docs', icon('solid','code','nav-icon')+_('admin.menu.api'),_use_li=True) }}
          {% endif %}

          {% if g.account.mode=="super_admin" %}
          {{render_nav_item(proxy_stats_url(),icon('solid','feed','nav-icon')+_('admin.menu.proxy_stats'),_use_li=True)}}
          {% endif %}

        </div>
      </ul>
    </nav>
    <!-- /.sub-sidebar-menu -->
  </div>

  <!-- /.sidebar -->
</aside>

{% endblock %}


{%block tail_js %}
{{super()}}
<!-- <script src="https://unpkg.com/gijgo@1.9.14/js/gijgo.min.js" type="text/javascript"></script>
<link href="https://unpkg.com/gijgo@1.9.14/css/gijgo.min.css" rel="stylesheet" type="text/css" /> -->
<form id="action_form" method="post"></form>
<script>
  $(document).ready(function () {
    // $('.datepicker').datepicker({uiLibrary: 'bootstrap4',format: 'yyyy-mm-dd'});
    if ($('#show-modal-donation').length) {
      $("#modal-donation").modal()
    }
    $('.form_post').click(function (e) {
      e.preventDefault();

      console.log(this); console.log(e);
      var link = this.href;
      $("#action_form").attr("action", link)

      bootbox.confirm({
        message: '{{_("Are you sure you want to do this action?")}}',
        locale: '{{get_locale()}}',
        callback: function (result) {
          if (result) {
            $("#action_form").submit()
          }
        }
      });
      return false;


    })
    // if ($('.').length){
    //   $("#modal-donation").modal()
    // }
  })

</script>

{% endblock %}