<?php require view('theme/header'); ?>
<main class="app-main">
	<div class="page-content">
		<div class="container-fluid">

			<div class="row mt-4 pt-2">
				<div class="col-12">
					<form action="/autos" method="get" id="history-search">
					<div class="fg fg-dark">
						<div class="fg-icon" style="background-color: transparent;"><i class="far fa-search"></i></div>
						<input type="text" name="search" class="fg-control" placeholder="Sipariş Ara">
					</form>
					</div>
				</div>
			</div>

			<div class="order-list">

				<?php 
				if ($autos != NULL) {
				foreach($autos as $auto) { ?>
				<div id="order-items" class="card card-order mt-5">
					<div class="card-body">
						<div class="row">
							<div class="col-lg-auto col-md-auto col-12 co-part">
								<div class="coh-icon">
									<?=$auto[auto_id]?>
								</div>
							</div>
							<div class="col-lg col mb-lg-0 mb-3 co-part">
								<h4 class="co-text"><?=$name?></h4>
							</div>
							<div class="col-lg-auto pe-lg-0 co-part mb-lg-0 mb-4">
								<div class="order-input">
									<button class="btn btn-transparent btn-sm"
										onclick="copyToClipboard('<?=$auto[auto_link]?>')">
										<i class="far fa-copy"></i>
									</button>
									<a class="oi-control" href="<?=$auto[auto_link]?>"
										target="_blank"><?=$auto[auto_link]?></a>
								</div>
							</div>
							<div class="col-lg-auto col-12 co-part co-right">
								<div>
										<div class="order-status d-block os-<?php if($auto["auto_status"] == 1) {echo "processing"; }elseif($auto["auto_status"] == 2) {echo "cancel"; }else {echo "completed";}?>">
										<?php if($auto["auto_status"] == 1) {echo "{AUTO_STATUS_PROCESSING}"; }elseif($auto["auto_status"] == 2) {echo "{AUTO_STATUS_CANCELED}"; }else {echo "{AUTO_STATUS_COMPLETED}";}?>
										    </div>
								</div>
								<div class="co-right-right">
								<?php if($auto["auto_status"] == 1) { ?> 
										    <button class="order-status d-block os-cancel" onclick="stop_auto('<?=$auto["auto_id"]?>')">{STOP_AUTO}</button>
										    <?php }?>
										    </div>
								<div class="co-right-right">
									<button class="btn btn-dark orderToggle"><i
											class="fas fa-chevron-down"></i></button>
								</div>
							</div>
						</div>
						<div class="co-hidden" style="display: none;">
							<div class="row">
								<div class="col-xl-3 col-lg-6 col-md-12 mb-4">
									<div class="chid-item">
										<div class="d-flex align-items-center">
											<div class="coh-icon">
												<i class="far fa-chart-line"></i>
											</div>
											<div class="coh-details ps-2">
												<h3 class="coh-m-title"><?=$auto[auto_quantity]?></h3>
												<div class="coh-count">{AUTOS_QUANTITY}</div>
											</div>
										</div>
									</div>
								</div>
								<div class="col-xl-3 col-lg-6 col-md-12 mb-4">
									<div class="chid-item">
										<div class="d-flex align-items-center">
											<div class="coh-icon">
												<i class="far fa-chart-line"></i>
											</div>
											<div class="coh-details ps-2">
												<h3 class="coh-m-title"><?=$auto[auto_completed]."/".$auto[auto_limit]?></h3>
												<div class="coh-count">Limit</div>
											</div>
										</div>
									</div>
								</div>
								<div class="col-xl-3 col-lg-6 col-md-12 mb-4">
									<div class="chid-item">
										<div class="d-flex align-items-center">
											<div class="coh-icon">
												<i class="far fa-chart-line"></i>
											</div>
											<div class="coh-details ps-2">
												<h3 class="coh-m-title"><?=date("d.m.y H:i:s", $auto["auto_date"])?></h3>
												<div class="coh-count">{AUTOS_DATE}</div>
											</div>
										</div>
									</div>
								</div>
								<div class="col-xl-auto col-md-12 col-12 mb-4">
									<button class="btn btn-primary ahbtn btn-block bs-3" data-bs-toggle="modal"
										data-bs-target="#report<?=$auto["auto_id"]?>">
										<i class="fas fa-headset"></i>
										<span class="ms-3 d-inline-block d-xl-none">Create Ticket</span>
									</button>
								</div>
							</div>						
						</div>
					</div>
				</div><!-- card-order -->
				
						<div class="modal fade" id="report<?=$auto["auto_id"]?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
								   <div class="modal-dialog modal-dialog-centered">
									  <div class="modal-content">
										 <!-- Modal Header -->
										 <div class="modal-header">
											<h4 class="modal-title">Ticket Oluştur</h4>
											<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
										 </div>
										 <!-- Modal body -->
										 <div class="modal-body">
											<div class="payout">
											  
												 <form  id="create_ticket" onsubmit="return false;">
													<div id="sonuc"></div>
												  <div class="form-group mb-3">
													<label for="title" class="control-label">Konu</label>
													<select class="form-control" id="title" name="title">
														  <option value="Siparişimi iptal etmek istiyorum #<?=$auto["auto_id"]?>">Siparişimi iptal etmek istiyorum</option>
														  <option value="Gönderilen miktar düştü #<?=$auto["auto_id"]?>">Gönderilen miktar düştü</option>
														  <option value="Siparişim beklemede kaldı #<?=$auto["auto_id"]?>">Siparişim beklemede kaldı</option>
														  <option value="Siparişim neden iptal edildi? #<?=$auto["auto_id"]?>">Siparişim neden iptal edildi?</option>
														  <option value="Diğer #<?=$auto["auto_id"]?>">Diğer</option>  
													</select>
												  </div>
												  <div class="form-group">
													<label for="message" class="control-label">Mesaj</label>
													<textarea class="form-control" rows="7" id="message" name="message" required></textarea>
												  </div>
												  <input name="_csrf" value="{{csrftoken}}" type="hidden">
                                                    <input id="hmessage" name="TicketForm[message]" type="hidden">
                                                    <input type="hidden" name="_csrf" value="{{csrftoken}}">
												  <button id="buton<?=$auto["auto_id"]?>" class="btn btn-primary btn-block mt-3">Gönder</button>
												</form>
											  
											</div>
										  
										 </div>
									  </div>
								   </div>
								</div>  
							<script>
							$(document).ready(function(){
								$("#buton<?=$auto["auto_id"]?>").on("click", function(){
									var gonderilenform<?=$auto["auto_id"]?> = $("#gonderilenform<?=$auto["auto_id"]?>").serialize();
									
									$.ajax({
							  url:'https://adserveth.com/ticket-create', 
										type:'POST',
										data:gonderilenform<?=$auto["auto_id"]?>,   
										success:function(e){ 
											$("#sonuc").html("Talebiniz alınmıştır.");
										}
									});
									
								});
							});
							</script>  
				
				<?php }}else {?>
				<div class="card mt-3">
				<div class="card-body">
					<div class="noorders text-center">
							<img src="<?= theme("assets/images/smiley.svg"); ?>" class="img-fluid smiley my-5" />
							<p>Merhaba <strong>{USER_USERNAME}</strong>, daha önce hiç sipariş vermedin.</p>
							<p>Bakiye Ekleyip <a href="/">Yeni Sipariş</a> Sayfasından Dilediğin Hizmeti Verebilirsin...</p>
						<div class="d-flex justify-content-center mt-5">
							 <a href="/addfunds"><button class="btn btn-primary btn-lg mb-4 mx-1">Bakiye Yükle</button></a>
							 <a href="/"><button class="btn btn-dark btn-lg mb-4 mx-1">Sipariş Ver</button></a>
						</div>
					</div>
				</div>
			</div>
				<?php } ?>


			</div>
			

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

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