<?php require view('theme/header'); ?>

<?php if (session('user_id')) : ?>
<?php else : ?>
<style>.app-main{padding-top: 125px}</style>
<?php endif; ?>

<main class="app-main">
    <div class="page-content">
        
<?php if (session('user_id')) : ?>
<div class="container-fluid">
<?php else : ?>
<div class="container">
<?php endif; ?>



            <div class="row mt-4 pt-2">
                <div class="col-lg-4 col-md-6 col-12">
                    <div class="dropdown s-filter">
                        <button class="btn btn-primary btn-lg btn-block dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="fas fa-filter" style="font-size: 14px"></i> Servis Filtrele
                        </button>
                        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
                        <li><a href="#" class="dropdown-item" onclick="javascript:filterService('All')">Tüm Servisler</a></li>	
						<?php
                              foreach ($categories as $category) {



                                 $query = $db->from('services')

                                 ->where('category_id', $category['category_id'])

                                 ->where('service_status', 1)

                                 ->orderby('service_number', 'ASC')

                                 ->all();



                                 if ($query) {
                                    $category_icon = $category["category_icon"];
                                    if (strlen($category_icon) > 0) {
                                       $category_icon = '<i style="color:' . $category['category_icon_color'] . '" class="' . $category_icon . '"></i> ';
                                    }
                                    $category_name = json_decode($category["category_name"], true);

                                    foreach ($category_name as $details) {

                                       if ($details["lang"] == 1) {

                                          $category_name = $details["name"];
                                       }

                                       if ($details["lang"] == $lang) {

                                          $category_name = $details["name"];

                                          break;
                                       }
                                    }
                                    ?>
						<li><a href="#" class="dropdown-item" onclick="javascript:filterService('<?= $category_name ?>')"><?= $category_name ?></a></li>
							<?php }} ?>
                        </ul>
                    </div>
                </div>
				<div class="col-lg-8 col-md-6 col-12 mb-4 mb-md-0">
                    <div class="fg fg-dark">
                        <div class="fg-icon" style="background-color: transparent;"><i class="far fa-search"></i></div>
                        <input type="text" class="fg-control" id="searchService" placeholder="Servislerde Arayın">
                    </div>
                </div>            
			</div>

            <div class="services-list mb-5 mt-5">
                <div class="tservice-head">
                    <div class="tservices-row">
                        <div class="tservice-id">ID</div>
                        <div class="tservice-name">Servis Adı</div>
                        <div class="tservice-per">Miktar</div>
                        <div class="tservice-min">Min</div>
                        <div class="tservice-max">Max</div>
						
						<?php if ($settings['service_speed'] == 1) { ?>
                            <div class="tservice-avg">Ortalama Süre</div>
                        <?php } else { ?>

                        <?php } ?>
                        <div class="tservice-des">Açıklama</div>
                    </div>
                </div>
                <div class="services-all">
				<?php
                              foreach ($categories as $category) {



                                 $query = $db->from('services')

                                 ->where('category_id', $category['category_id'])

                                 ->where('service_status', 1)

                                 ->orderby('service_number', 'ASC')

                                 ->all();



                                 if ($query) {
                                    $category_icon = $category["category_icon"];
                                    if (strlen($category_icon) > 0) {
                                       $category_icon = '<i style="color:' . $category['category_icon_color'] . '" class="' . $category_icon . '"></i> ';
                                    }
                                    $category_name = json_decode($category["category_name"], true);

                                    foreach ($category_name as $details) {

                                       if ($details["lang"] == 1) {

                                          $category_name = $details["name"];
                                       }

                                       if ($details["lang"] == $lang) {

                                          $category_name = $details["name"];

                                          break;
                                       }
                                    }
                                    ?>
                    <div class="service-title" data-category="<?= $category_name ?>">
                        
                        <span><?= $category_name ?></span>
                    </div>
                    <?php
                                    $services = $query;

                                    foreach ($services as $service) {

                                       $service_name = json_decode($service["service_name"], true);

                                       foreach ($service_name as $details) {

                                          if ($details["lang"] == 1) {

                                             $service_name = $details["name"];
                                          }

                                          if ($details["lang"] == $lang) {

                                             $service_name = $details["name"];

                                             break;
                                          }
                                       }

                                       $service_desc = json_decode($service["service_desc"], true);

                                       foreach ($service_desc as $details) {

                                          if ($details["lang"] == 1) {

                                             $service_desc = $details["name"];
                                          }

                                          if ($details["lang"] == $lang) {

                                             $service_desc = $details["name"];

                                             break;
                                          }
                                       }
                                       $service_desc = html_entity_decode($service_desc);
                                       $charge = offer($service);

                                       /* Servisler Buraya */


                                       ?>
                    
                    <div class="service-item" id="servisDetay" data-category="<?= $category_name ?>">
                        <div class="tservices-row">
                            <div class="tservice-id">
                                <div class="service-id-box"><?= $service["service_id"] ?></div>
                            </div>
                            <div class="tservice-name">
                                <div class="t-service-m-title">Servis</div>
                                <?= $service_name ?>
                            </div>
                            <div class="tservice-per">
                                <div class="t-service-m-title">Fiyat</div>
                                {CURRENCY_SYMBOL} <?= $charge ?>
                            </div>
                            <div class="tservice-min">
                                <div class="t-service-m-title">Min</div>
                                <?= $service["service_min"] ?>
                            </div>
                            <div class="tservice-max">
                                <div class="t-service-m-title">Max</div>
                                <?= $service["service_max"] ?>
                            </div>
                            <?php if ($settings['service_speed'] == 1) { ?>
                            <div class="tservice-avg">
                                <div class="t-service-m-title">Ort. Süre</div>
                                <?= getservicetime($service["service_id"]) ?>
                            </div>
							<?php } else { ?>

                                       <?php } ?>
                            <div class="tservice-des">
                                <button data-bs-toggle="modal" data-bs-target="#sDet<?= $service["service_id"] ?>" class="btn btn-dark btn-sm"><i class="fas fa-bars"></i></button>
                            </div>
                        </div>
							<div class="modal fade" id="sDet<?= $service["service_id"] ?>" tabindex="-1" aria-labelledby="servisDetayLabel" aria-hidden="true">
								<div class="modal-dialog">
									<div class="modal-content">
										<div class="modal-header">
											<img src="{SITE_LOGO}" height="35" alt="{SITE_TITLE}" title="{SITE_TITLE}">
											<button class="btn ahbtn bs-2" data-bs-dismiss="modal" aria-label="Close">
												<i class="fas fa-times"></i>
											</button>
										</div>
										<div class="modal-body">
											<div class="service-id-box">
												Servis #<?= $service["service_id"] ?>
											</div>
											<h3><?= $service_name ?></h3>
											<p>
												<?= html_entity_decode($service_desc) ?>
											</p>
											
											<div class="services-info">
												
												<div class="d-flex justify-content-between">
													<div class="si-item">
														<div class="si-circle">
															<i class="fas fa-bolt"></i>
														</div>
														<small>Fiyat</small>
														<p>{CURRENCY_SYMBOL} <?= $charge ?></p>
													</div>
													<div class="si-item">
														<div class="si-circle">
															<i class="fas fa-arrow-alt-to-bottom"></i>
														</div>
														<small>Min</small>
														<p><?= $service["service_min"] ?></p>
													</div>	
													<div class="si-item">
														<div class="si-circle">
															<i class="fas fa-arrow-alt-from-bottom"></i>
														</div>
														<small>Max</small>
														<p><?= $service["service_max"] ?></p>
													</div>
												</div>
												<a href="/?cat_id=<?= $category["category_id"] ?>&service_id=<?= $service["service_id"] ?>" class="btn btn-primary btn-block">Servisi Satın Al</a>
											</div>
											<div class="si-overlay"></div>
										</div>
									</div>
								</div>
							</div> 
							
                    </div><!-- service-item -->
					<?php }
                              }
                           } ?>
                </div>
            </div>

        </div>
    </div>
</main>



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

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










<?php require view('theme/footer'); ?>





<!----------------------------------------------------------------------------------------------------------------------------------->