{% extends '../_layouts/_main.twig' %}
{% block content %}
	<div class="panel panel-tabs">
		<div class="panel-body">

			<div class="cp-translation">
				<h4>Редактирование языковой переменной <strong class="color-primary">$msg[1002][760]</strong></h4>

				<strong>ID: 2.3.12255</strong> <a href="#" class="blank-link" target="_blank" title="Click to open page where this text is used"><i class="fa fa-external-link-square"></i></a>
				<br /><strong>$msg[1002][760]</strong>
				<br /><strong>Type: site_texts</strong>
				<br /><strong>Subtype: t_0000.php</strong>

				<br /><br />

				<div class="text-right">
					<button class="btn btn-primary disabled">Сохранить изменения</button>
				</div>

				<div class="mb-16"></div>

				{% set table = [
					{
						"iso2": "en",
						"label": "English",
						"status": "Source",
						"statusColor": "success",
						"text": "FREE Delivery from [sum][currency]",
						"details": 173062,
						"comment": "-",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:16:33"
					},
					{
						"iso2": "se",
						"label": "Swedish",
						"status": "Up to date",
						"statusColor": "success",
						"text": "GRATIS leverans från [sum][currency]",
						"details": 173064,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:16:54"
					},
					{
						"iso2": "ru",
						"label": "Russian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "БЕСПЛАТНАЯ доставка от [sum][currency]",
						"details": 527042,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:17:15"
					},
					{
						"iso2": "it",
						"label": "Italian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Consegna GRATUITA a partire da [sum][currency]",
						"details": 527050,
						"comment": "Lorem ipsum dolor sit amet",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:17:42"
					},
					{
						"iso2": "de",
						"label": "German",
						"status": "Up to date",
						"statusColor": "success",
						"text": "KOSTENLOSE Lieferung ab [sum][currency]",
						"details": 527058,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:17:58"
					},
					{
						"iso2": "dk",
						"label": "Danish",
						"status": "Up to date",
						"statusColor": "success",
						"text": "GRATIS levering fra [sum][currency]",
						"details": 527066,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:18:10"
					},
					{
						"iso2": "lt",
						"label": "Lithuanian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "NEMOKAMAS pristatymas nuo [sum][currency]",
						"details": 527074,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:18:24"
					},
					{
						"iso2": "ee",
						"label": "Estonian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "TASUTA kohaletoimetamine alates [sum][currency]",
						"details": 527082,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:18:38"
					},
					{
						"iso2": "rs",
						"label": "Serbian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "BESPLATNA isporuka za porudžbine od [sum][currency]",
						"details": 527090,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:18:52"
					},
					{
						"iso2": "cz",
						"label": "Czech",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Dodání ZDARMA od [sum][currency]",
						"details": 527098,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:19:05"
					},
					{
						"iso2": "lv",
						"label": "Latvian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "BEZMAKSAS piegāde pirkumiem no [sum][currency]",
						"details": 527106,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:19:24"
					},
					{
						"iso2": "fr",
						"label": "French",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Livraison GRATUITE à partir de [sum][currency]",
						"details": 527114,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:19:40"
					},
					{
						"iso2": "hu",
						"label": "Hungarian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "INGYENES szállítás [sum][currency] összegtől",
						"details": 527128,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:20:12"
					},
					{
						"iso2": "no",
						"label": "Norwegian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "GRATIS levering fra [sum][currency]",
						"details": 527136,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:20:54"
					},
					{
						"iso2": "es",
						"label": "Spanish",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Envío GRATIS a partir de [sum][currency]",
						"details": 527144,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:21:07"
					},
					{
						"iso2": "pt",
						"label": "Portuguese",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Entrega GRÁTIS a partir de [sum][currency]",
						"details": 527152,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:21:20"
					},
					{
						"iso2": "sk",
						"label": "Slovak",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Doprava ZDARMA od [sum][currency]",
						"details": 527162,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:23:41"
					},
					{
						"iso2": "by",
						"label": "Belorussian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "БЯСПЛАТНАЯ дастаўка пры заказе ад [sum][currency]",
						"details": 527170,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:33:01"
					},
					{
						"iso2": "sl",
						"label": "Slovenian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "BREZPLAČNA dostava od zneska [sum][currency] naprej",
						"details": 527176,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:37:33"
					},
					{
						"iso2": "fi",
						"label": "Finnish",
						"status": "Up to date",
						"statusColor": "success",
						"text": "ILMAINEN toimitus vähintään [sum]][currency] tilauksille",
						"details": 527184,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:43:16"
					},
					{
						"iso2": "pl",
						"label": "Polish",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Bezpłatna dostawa od [sum]][currency]",
						"details": 527192,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:43:31"
					},
					{
						"iso2": "is",
						"label": "Icelandic",
						"status": "Outdated",
						"statusColor": "danger",
						"text": "ÓKEYPIS sendingarkostnaður frá [sum]][currency]",
						"details": 1063968,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:43:45"
					},
					{
						"iso2": "nl",
						"label": "Dutch",
						"status": "Outdated",
						"statusColor": "danger",
						"text": "GRATIS bezorging vanaf [currency] [sum]",
						"details": 1424281,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:44:41"
					},
					{
						"iso2": "sa",
						"label": "Arabic",
						"status": "Outdated",
						"statusColor": "danger",
						"text": "توصيل مجاني من [sum] [currency]",
						"details": 1424295,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:54:53"
					},
					{
						"iso2": "my",
						"label": "Malay",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Penghantaran percuma daripada [sum][currency]",
						"details": 1424309,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:45:26"
					},
					{
						"iso2": "ua",
						"label": "Ukrainian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "БЕЗКОШТОВНА доставка на суму від [sum][currency]",
						"details": 1424323,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:45:53"
					},
					{
						"iso2": "tr",
						"label": "Turkish",
						"status": "Up to date",
						"statusColor": "success",
						"text": "[sum][currency] itibarıyla ÜCRETSİZ Kargo",
						"details": 1424337,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:47:33"
					},
					{
						"iso2": "hr",
						"label": "Croatian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "BESPLATNA dostava od [sum][currency]",
						"details": 1424351,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:47:54"
					},
					{
						"iso2": "ko",
						"label": "Korean",
						"status": "Up to date",
						"statusColor": "success",
						"text": "[sum][currency] 부터 무료 배송",
						"details": 1424365,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:48:12"
					},
					{
						"iso2": "bg",
						"label": "Bulgarian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "БЕЗПЛАТНА доставка от [sum][currency] нагоре",
						"details": 1424379,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:48:29"
					},
					{
						"iso2": "ro",
						"label": "Romanian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Livrare GRATUITĂ de la [sum][currency]",
						"details": 1424393,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:48:58"
					},
					{
						"iso2": "il",
						"label": "Hebrew",
						"status": "Up to date",
						"statusColor": "success",
						"text": "משלוח חינם בתשלום [sum][currency] או יותר<",
						"details": 1424407,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:49:18"
					},
					{
						"iso2": "ch",
						"label": "Chinese",
						"status": "Up to date",
						"statusColor": "success",
						"text": "[sum][currency] 起免费送货",
						"details": 1424421,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:51:29"
					},
					{
						"iso2": "th",
						"label": "Thai",
						"status": "Up to date",
						"statusColor": "success",
						"text": "การจัดส่งฟรีตั้งแต่ [sum][currency]",
						"details": 1424435,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:49:35"
					},
					{
						"iso2": "ge",
						"label": "Georgian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "უფასო მიწოდება [sum][currency]-დან",
						"details": 1424449,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:51:45"
					},
					{
						"iso2": "gr",
						"label": "Greek",
						"status": "Up to date",
						"statusColor": "success",
						"text": "ΔΩΡΕΑΝ Παράδοση από [sum][currency]",
						"details": 1424463,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:52:01"
					},
					{
						"iso2": "jp",
						"label": "Japanese",
						"status": "Up to date",
						"statusColor": "success",
						"text": "[sum][currency] 以上で送料無料",
						"details": 1424477,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:52:35"
					},
					{
						"iso2": "vn",
						"label": "Vietnamese",
						"status": "Up to date",
						"statusColor": "success",
						"text": "Giao hàng MIỄN PHÍ từ [sum][currency]",
						"details": 1424491,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:52:52"
					},
					{
						"iso2": "mk",
						"label": "Macedonian",
						"status": "Up to date",
						"statusColor": "success",
						"text": "БЕСПЛАТНА испорака за износ од [sum][currency]",
						"details": 1431553,
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "14.10.2022 - 12:53:13"
					},
					{
						"iso2": "az",
						"label": "Azerbaijani",
						"status": "No translation",
						"statusColor": "",
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "-"
					},
					{
						"iso2": "gl",
						"label": "Greenlandic",
						"status": "No translation",
						"statusColor": "",
						"comment": "",
						"translator": "Leonid Drozdov",
						"date": "-"
					}
				] %}
				<table class="cp-translation-edit table table-bordered">
					<thead class="thead-gray">
					<tr>
						<th style="width: 180px;">Language</th>
						<th style="width: 150px;">Status</th>
						<th>Text</th>
						<th style="width: 40px;">&nbsp;</th>
						<th>Comment</th>
						<th style="width: 150px;">Translator</th>
						<th style="width: 100px;">Last edit</th>
					</tr>
					</thead>
					<tbody>
					{% for tr in table %}
						<tr>
							<td><div class="icobox size_16"><img class="ico flag" src="/images/flag/{{ tr.iso2 }}.png">{{ tr.label }}</div></td>
							<td><span{% if tr.statusColor %} class="color-{{ tr.statusColor }}"{% endif %}>{{ tr.status }}</span></td>
							<td><textarea class="form-control dynamic-textarea" cols="" rows="1">{{ tr.text|default('') }}</textarea></td>
							{# TODO: Link OR Ajax Or ??? for eyes #}
							<td class="text-center"><a href="#modal-translate-details" class="blank-link" data-toggle="modal"><i class="fa fa-eye show-translation-details" data-id="{{ tr.details|default('') }}" title="Show translation details"></i></a></td>
							<td>
								<div class="b-comment{% if tr.comment is defined and tr.comment %} in{% endif %}">
									<div class="b-comment__text">{{ tr.comment }}</div>
									<div class="b-comment__control">
										<a href="#" class="edit" title="Редактировать комментарий" data-id="$msg[1002][760]" data-iso2="{{ tr.iso2 }}"><i class="fa fa-pencil-square"></i></a>
										<a href="#" class="remove" title="Удалить комментарий" data-id="$msg[1002][760]" data-iso2="{{ tr.iso2 }}"><i class="fa fa-ban color-danger"></i></a>
									</div>
								</div>
							</td>
							<td>{{ tr.translator|default('-') }}</td>
							<td><span class="text-nowrap">{{ tr.date|default('-') }}</span></td>
						</tr>
					{% endfor %}
					</tbody>
				</table>

				<div class="mb-16"></div>

				<div class="text-right">
					<button class="btn btn-primary disabled">Сохранить изменения</button>
				</div>
			</div>

		</div>
	</div>
{% endblock %}
{% block modals %}
	<div class="modal fade" id="modal-translate-details" tabindex="-1" role="dialog" aria-labelledby="">
		<div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
				<a href="#" class="cross" data-dismiss="modal"></a>
				<div class="modal-body">
					<br /><br />
					<table class="table table-bordered">
						<thead class="thead-gray">
						<tr>
							<th>Date</th>
							<th>Admin</th>
							<th>Text</th>
							<th class="text-right">Paid</th>
						</tr>
						</thead>
						<tbody>
						<tr>
							<td>22.11.2019 14:38:37</td>
							<td>Denis Garanin</td>
							<td>Lorem ipsum dolor sit amet.</td>
							<td class="text-right">0.1000</td>
						</tr>
						<tr>
							<td>12.07.2016 14:38:37</td>
							<td></td>
							<td>Lorem ipsum dolor sit amet.</td>
							<td class="text-right">0.0000</td>
						</tr>
						</tbody>
					</table>
					<br />
				</div>
			</div>
		</div>
	</div>
{% endblock %}
{% block addition %}
	<script type="text/javascript">
		$(function(){
			var isConfirmed = false;

			var checkTranslationsFields = function(field){
				var needConfirm = false;
				var fields = $('.dynamic-textarea');
				var buttons = $('.btn');
				fields.each(function(){
					if( $(this).val() != $(this).data('default') ){
						$(this).addClass('filled');
						//$(this).closest('tr').addClass('tr-filled');
						needConfirm = true;
					} else {
						$(this).removeClass('filled');
						//$(this).closest('tr').removeClass('tr-filled');
					}
				});
				if(needConfirm){
					buttons.removeClass('disabled');
					isConfirmed = true;
				} else {
					buttons.addClass('disabled');
					isConfirmed = false;
				}
			};

			$(".dynamic-textarea").each(function(){
				$(this).data('default', $(this).val());
				this.setAttribute("style", "height:" + (this.scrollHeight) + "px;");
				this.style.height = 0;
				this.style.height = (this.scrollHeight) + "px";
			}).on("input", function(){
				this.style.height = 0;
				this.style.height = (this.scrollHeight) + "px";
				checkTranslationsFields($(this));
			}).on('focusout', function(){
				checkTranslationsFields($(this));
			});

			$('.cp-translation-edit .b-comment__control .edit').on('click', function(){
				let $link = $(this),
					$commentBox = $link.closest('.b-comment'),
					comment = prompt('Please input comment', '-');
				somethingLoading($commentBox);
				$.ajax({
					method: "POST",
					url: $link.attr('href'),
					data: {
						id : $link.data('id'),
						iso2 : $link.data('iso2'),
					},
					cache : false,
				}).done(function(result){
					$('.b-comment__text', $commentBox).text(comment);
					if (comment) {
						$commentBox.addClass('in');
					} else {
						$commentBox.removeClass('in');
					}
				}).fail(function(jqXHR, textStatus){
					try {
						var response = JSON.parse(jqXHR.responseText);
						if (response.error) {
							globalNotifyAdd(response.error, 'alert-danger timer');
						} else {
							globalNotifyAdd(response.toString(), 'alert-danger timer');
						}
					} catch (error) {
						globalNotifyAdd('Something went wrong. Please try again later', 'alert-danger timer');
					}
				}).always(function(){
					somethingLoaded($commentBox);
				});
				return false;
			});

			$('.cp-translation-edit .b-comment__control .remove').on('click', function(){
				if(!confirm('Удалить комментарий?')) return false;
				let $link = $(this),
					$commentBox = $link.closest('.b-comment');
				somethingLoading($commentBox);
				$.ajax({
					method: "POST",
					url: $link.attr('href'),
					data: {
						id : $link.data('id'),
						iso2 : $link.data('iso2'),
					},
					cache : false,
				}).done(function(result){
					$('.b-comment__text', $commentBox).text('');
					$commentBox.removeClass('in');
				}).fail(function(jqXHR, textStatus){
					try {
						var response = JSON.parse(jqXHR.responseText);
						if (response.error) {
							globalNotifyAdd(response.error, 'alert-danger timer');
						} else {
							globalNotifyAdd(response.toString(), 'alert-danger timer');
						}
					} catch (error) {
						globalNotifyAdd('Something went wrong. Please try again later', 'alert-danger timer');
					}
				}).always(function(){
					somethingLoaded($commentBox);
				});
				return false;
			});

			/*$('#modal-translate-details').on('show.bs.modal', function (e) {

			});*/

			window.onbeforeunload = function (e) {
				if( isConfirmed ){
					e = e || window.event;
					if (e) {
						e.returnValue = 'Sure?';
					}
					return 'Sure?';
				}
			};
		});
	</script>
{% endblock %}