{% include 'header.twig' %}
{% if user['auth'] %}
  
<div class=" "></div>
<div class="container">
     <div class="well ofv mb-3">
          <div class="row">
               <div class="col-md-4">
                    <div class="dropdown servdd">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span class="fal fa-filter"></span> Filter Services</button></button>
                         <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="javascript:void(0);" onclick="javascript:filterService('All')">All</a></li>
            {% for category in serviceCategory %}
    <li><a href="javascript:void(0);" onclick="javascript:filterService('{{ category["category_name"] }}')">{{ category["category_name"] }}</a></li>
    {% endfor%}
                         </ul>
                    </div>
               </div>
               <div class="col-md-4">
               </div>
               <div class="col-md-4">
                    <div class="input-group">
            <input type="text" id="serv-inp" class="form-control" placeholder="Search">
                         <span class="input-group-btn">
        <button type="button" class="btn btn-default" data-filter-serch-btn="true"> <i class="fa fa-search"></i></button>
                         </span>
                    </div>
               </div>
          </div>
</div>
<div class="row">
          <div class="col-lg-12">
               <div class="well well-float tabwell br-0">
                <table id="serv-table" class="table">
                                <thead>
                                    <tr>
                                        <th>{{ lang['services.id'] }}</th>
                                        <th>{{ lang['services.name'] }}</th>
                                        <th>{{ lang['services.price'] }}</th>
                                        <th>{{ lang['services.min'] }}</th>
                                        <th>{{ lang['services.max'] }}</th>
										{% if avarageTime %}
                                        <th class="nowrap">{{ lang['services.avarage'] }} <span class="fa fa-exclamation-circle" data-toggle="tooltip" data-placement="top" title="The average time is based on 10 latest completed orders per 1000 quantity."></span>
                                        </th>
                                        {% endif %}
                                        <th>{{ lang['neworder.description'] }}</th>
                                    </tr>
                                </thead>
            <tbody>
								{% for category in serviceCategory %}
                                    <tr class="cattr" data-category="{{ category["category_name"] }}">
                        <td colspan="7"><strong>{{ category["category_name"] }}</strong></td>
                                    </tr>
									{% for service in category['services'] %}
									<tr data-category="{{ category["category_name"] }}">
                                        <td data-title="ID">{{ service["service_id"] }}</td>
                                        <td data-title="Service" class="service-name" >{{ service["service_name"] }}</td>
                                        <td data-title="PER 1K"><span>$&nbsp;{{ service["service_price"] }}</span> </td>
                                        <td data-title="Minimum">{{ service["service_min"] }}</td>
                                        <td data-title="Maximum">{{ service["service_max"] }}</td>
										{% if avarageTime %}
                                        <td data-title="Average Duration" class="nowrap">{{ service["service_speed"] }}</td>
										{% endif %}
                                        <td>
                                     <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#servisDetay{{ service["service_id"] }}"> View Details </button>
											<div class="modal fade" id="servisDetay{{ service["service_id"] }}">
												<div class="modal-dialog">
													<div class="modal-content">

														<!-- Modal Header -->
														<div class="modal-header">
															<h4 class="modal-title">{{ service["service_name"] }}</h4>
														</div>

														<!-- Modal body -->
														<div class="modal-body">
															{{ service["service_description"] }}		  
														</div>
														  <div class="modal-footer">
															<center><button type="button" class="btn btn-sm btn-primary" data-dismiss="modal">Close</button></center>	  
														  </div>
													</div>
												</div>
											</div> 
                                        </td>
                                    </tr>
                                  {% endfor%}	
								{% endfor%}	
            </tbody>
                </table>
               </div>
          </div>
     </div>
</div>

{% else %}
<div class="userwrapper">
<!-- Main variables *content* -->
<div class="userpad">
     <div class="container">
          <div class="well ofv mb-3">
               <div class="row">
                    <div class="col-md-4">
                    <div class="dropdown servdd">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span class="fal fa-filter"></span> Filter Services</button></button>
                         <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="javascript:void(0);" onclick="javascript:filterService('All')">All</a></li>
            {% for category in serviceCategory %}
    <li><a class="dropdown-item" href="javascript:void(0);" onclick="javascript:filterService('{{ category["category_name"] }}')">{{ category["category_name"] }}</a></li>
            {% endfor%}
                         </ul>
                    </div>
                    </div>
        
         <div class="col-md-4"></div>
        
               <div class="col-md-4">
                    <div class="input-group">
            <input type="text" id="serv-inp" class="form-control" placeholder="Search">
                         <span class="input-group-btn">
        <button type="button" class="btn btn-default" data-filter-serch-btn="true"> <i class="fa fa-search"></i></button>
                         </span>
                    </div>
               </div>
               </div>
          </div>
          <div class="row">
               <div class="col-lg-12">
                    <div class="well well-float tabwell br-0">
                <table class="table " id="serv-table">
                                <thead>
                                    <tr>
                                        <th>{{ lang['services.id'] }}</th>
                                        <th>{{ lang['services.name'] }}</th>
                                        <th>{{ lang['services.price'] }}</th>
                                        <th>{{ lang['services.min'] }}</th>
                                        <th>{{ lang['services.max'] }}</th>
										{% if avarageTime %}
                                        <th class="nowrap">{{ lang['services.avarage'] }}<span class="fa fa-exclamation-circle" data-toggle="tooltip" data-placement="top" title="The average time is based on 10 latest completed orders per 1000 quantity."></span>
                                        </th>
                                        {% endif %}
                                        <th>{{ lang['neworder.description'] }}</th>
                                    </tr>
                                </thead>
            <tbody>
								{% for category in serviceCategory %}
                                    <tr class="cattr" data-category="{{ category["category_name"] }}">
                        <td colspan="7"><strong>{{ category["category_name"] }}</strong></td>
                                    </tr>
									{% for service in category['services'] %}
									<tr data-category="{{ category["category_name"] }}">
                                        <td data-title="ID">{{ service["service_id"] }}</td>
                                        <td data-title="Service" class="service-name" >{{ service["service_name"] }}</td>
                                        <td data-title="PER 1K"><span>₹&nbsp;{{ service["service_price"] }}</span> </td>
                                        <td data-title="Minimum">{{ service["service_min"] }}</td>
                                        <td data-title="Maximum">{{ service["service_max"] }}</td>
										{% if avarageTime %}
                                        <td data-title="Average Duration" class="nowrap">{{ service["service_speed"] }}</td>
										{% endif %}
                                        <td>
                                     <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#servisDetay{{ service["service_id"] }}"> View Details </button>
											<div class="modal fade" id="servisDetay{{ service["service_id"] }}">
												<div class="modal-dialog">
													<div class="modal-content">

														<!-- Modal Header -->
														<div class="modal-header">
															<h4 class="modal-title">{{ service["service_name"] }}</h4>
														</div>

														<!-- Modal body -->
														<div class="modal-body">
															{{ service["service_description"] }}		  
														</div>
														  <div class="modal-footer">
														<center><button type="button" class="btn btn-sm btn-primary" data-dismiss="modal">Close</button></center>	  
														  </div>
													</div>
												</div>
											</div> 
                                        </td>
                                    </tr>
                                  {% endfor%}	
								{% endfor%}	
            </tbody>
                </table>
                    </div>
               </div>
          </div>
     </div>
</div>
</div>
{% endif %}
  


<script>
      function filterService(category) {
        if (category == 'All')
          $('tbody tr.hidden').removeClass('hidden');
        else {
          $('tbody tr').addClass('hidden');
          $('tbody tr[data-category="' + category + '"]').removeClass('hidden');
        }
        removeEmptyCategory();
      }

      function removeEmptyCategory() {
        $('.services-header').each(function () {
            var next = $(this).next();
            var services = $(this).nextUntil('.services-header');
            var empty = true;
            services.each(function() {
              if (!$(this).hasClass('hidden')) empty = false;
            });
            if (empty) $(this).addClass('hidden');
        })
      }
</script>
{% include 'footer.twig' %}