<?php if(@$error): ?>
	<div class="alert alert-dismissible alert-danger">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Hata!</strong> <?=$errorText?>
	</div>
<?php endif; ?>
<?php if(@$success): ?>
	<div class="alert alert-dismissible alert-success">
		<button type="button" class="close" data-dismiss="alert">×</button>
		<strong>Başarılı!</strong> <?=$success?>
	</div>
<?php endif; ?>
<?php if(!route(3)): ?>
	<a href="#" class="btn btn-success" style="margin-bottom:20px;" data-toggle="modal" data-target="#addApi">Yeni Dil Oluştur</a>
	<div class="panel panel-default">
		<div class="panel-body" style="padding:0;">
			<table class="table" style="margin-bottom:0;">
				<thead>
					<tr>
						<th class="p-l" width="45%">Dil</th>
						<th></th>
					</tr>
				</thead>
				<tbody>
					<?php foreach($languages as $language): ?>
						<tr>
							<td><?=$language["lang_name"];?></td>
							<td>
								<div class="dropdown pull-right">
									<button class="btn btn-xs btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">İşlemler<span class="caret"></span></button>
									<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
										<li><a href="<?=admin_url('appearence/language/'. $language["lang_id"])?>">Düzenle</a></li>
										<li><a href="#" onclick="delete_language(<?=$language["lang_id"];?>)">Sil</a></li>
									</ul>
								</div>
							</td>
							<input type="hidden" name="privder_changes" value="privder_changes">
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	</div>

	<div id="addApi" class="modal fade" role="dialog">
		<div class="modal-dialog">

			<!-- Modal content-->
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title">Yeni Dil Oluştur</h4>
				</div>
				<div class="modal-body">
					<form id="add_language" onsubmit="return false;" data-reset="1">
						<div class="form-group">
							<div class="input-group">
								<span class="input-group-addon"><b>Dil Adı</b></span>
								<input type="text" name="name" class="form-control"required>
							</div>
						</div>
						<div class="form-group">
							<div class="input-group">
								<span class="input-group-addon"><b>Dil Kodu</b></span>
								<input type="text" name="code" class="form-control"required>
							</div>
						</div>
						<div class="form-group text-right">
							<button type="button" class="btn btn-default" data-dismiss="modal">Vazgeç</button>
							<button type="submit" class="btn btn-success">Oluştur</button>
						</div>
					</form>
				</div>
			</div>

		</div>
	</div>
	<?php elseif(route(3)): ?>

		<a href="#" class="btn btn-success" style="margin-bottom:20px;" data-toggle="modal" data-target="#editlanguage">Çerviriler</a>

		<div class="panel panel-default">
			<div class="panel-body">
				<form id="update_language" onsubmit="return false;" data-reset="0">
					<div class="form-loader">
						<span class="intro-banner-vdo-play-btn pinkBg">
							<span class="ripple pinkBg"></span>
							<span class="ripple pinkBg"></span>
							<span class="ripple pinkBg"></span>
						</span>
					</div>
					<input type="hidden" name="id" value="<?=$language["lang_id"]?>" />
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>Dil Adı</b></span>
							<input type="text" name="name" class="form-control" value="<?=$language["lang_name"];?>" />
						</div>
					</div>
					<div class="form-group">
						<div class="input-group">
							<span class="input-group-addon"><b>Dil Kodu</b></span>
							<input type="text" name="code" class="form-control" value="<?=$language["lang_code"];?>" />
						</div>
					</div>
					<div class="form-group text-right">
						<a href="<?=admin_url('appearence/language')?>" class="btn btn-warning">Dillere Geri Dön</a>
						<button type="submit" class="btn btn-success">Güncelle</button>
					</div>
				</form>
			</div>
		</div>

		<script type="text/javascript">
			window.addEventListener('load', function () {
				get_translations($("#lang").val());
			}, false);
		</script>

		<div id="editlanguage" class="modal fade" role="dialog">
			<div class="modal-dialog">

				<!-- Modal content-->
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">&times;</button>
						<h4 class="modal-title">Çeviriler</h4>
					</div>
					<form id="update_translations" onsubmit="return false;" data-reset="0">
						<div class="modal-body mb-2" style="max-height:400px;overflow:auto;">
							<input type="hidden" name="id" value="<?=$language["lang_id"]?>" />
							<div class="alert alert-info">Yüzde(%) işareti arasında yazan yazılar çeviri kodlarıdır, karşılığı olmadıkları için yazarlar. Sitede gözükmezler.</div>
							<table class="table table-bordered">
								<thead>
									<tr>
										<th>
											<select id="lang" onchange="get_translations()" class="form-control form-control-sm">
												<?php foreach($languages as $l): ?>
													<option value="<?=$l["lang_id"];?>"><?=$l["lang_code"];?></option>
												<?php endforeach; ?>
											</select>
										</th>
										<th><?=$language["lang_code"]?></th>
									</tr>
								</thead>
								<tbody>
									<?php foreach($codes as $code): ?>
										<tr>
											<td>
												<input type="text" id="code_<?=$code["code_id"];?>" class="form-control form-control-sm" /readonly>
											</td>
											<td>
												<input type="text" name="code[<?=$code["code_id"];?>]" class="form-control form-control-sm" value="<?=$code["translation_text"];?>" />
											</td>
										</tr>
									<?php endforeach; ?>
								</tbody>
							</table>
						</div>
						<div class="modal-footer">
							<button type="submit" class="btn btn-success">Güncelle</button>
						</div>
					</form>
				</div>

			</div>
		</div>

	<?php endif; ?>