@extends('layouts.app')

@section('content')
<section class="page-header row">
	<h2> {{ $pageTitle }} </h2>
	<ol class="breadcrumb">
		<li><a href="{{ url('') }}"> Dashboard </a></li>
		<li><a href="{{ url('/manage/'.$pageModule) }}"> {{ $pageTitle }} </a></li>
		<li class="active"> Form  </li>		
	</ol>
</section>
<div class="page-content row">
	<div class="page-content-wrapper no-margin">
	
	{!! Form::open(array('url'=>'/manage/brands?return='.$return, 'class'=>'form-vertical validated','files' => true )) !!}
	<input type="hidden" name="status_type" value="{{ $pageTitle }}" />
	
		<div class="sbox-title clearfix">
			<div class="sbox-tools pull-right" >
				<a href="{{ url('/manage/'.$pageModule.'?return='.$return) }}" class="tips btn btn-sm "  title="{{ __('core.btn_back') }}" ><i class="fa  fa-times"></i></a> 
			</div>
			<div class="sbox-tools1 pull-left1" >
				<button name="apply" class="btn btn-sm btn-primary  "  title="{{ __('core.btn_back') }}" ><i class="fa  fa-check"></i> {{ __('core.sb_apply') }} </button>
				<button name="save" class="btn btn-sm btn-success"  title="{{ __('core.btn_back') }}" ><i class="fa  fa-paste"></i> {{ __('core.sb_save') }} </button> 
				<?php if($frontendSlug!='') {
				$fsconfig = explode('@',$frontendSlug);
				if( ($row[$fsconfig[1]]) ) 
				echo '<a  class="btn btn-sm btn-outline-primary" target="_blank"  title="FrontEnd" href="'. (config('website.cnf_appurl') .'/'.config('website.cnf_lang') . str_replace('//','/',('/'.$fsconfig[0].'/'.$row[$fsconfig[1]]))).'"><i class="fa  fa-desktop"></i> FrontEnd</a>';
				 } ?>
			</div>
		</div>	
		<div class="sbox1">
		<div class="sbox-content clearfix row">
		<div class="col-xs-12">
	<ul class="parsley-error-list">
		@foreach($errors->all() as $error)
			<li>{{ $error }}</li>
		@endforeach
	</ul>		

	<?php $curTime = time();?>

<div class="sbox1"><div class="col-md-6">
						<fieldset class="sbox" style="border-top:0; border-radius: 5px;"><legend> Brands Details</legend>
				<?php if( !isset($row['id']))  $row['id'] = null;   ?>
		<input  type='hidden' name='id' id='id' value='{{$row['id']}}' />
									
									  <div class="form-group  depen-  wrap-name  " >
										<label for="ipt" class=" control-label "> Brand Name  <span class="asterix"> * </span>  </label>
										
										
										  <?php if( !isset($row['name']))  $row['name'] = null;   ?>
		 <?php $val = json_decode($row['name']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#name_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}}  {{$is_first ? "active" : null}}' id='name_{{$ilang}}_{{$curTime}}'>
				<input  type='text' name="name[{{$ilang}}]" id='name' value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}' 
						required  placeholder='Brand Name - {{$ilang}}'     class='form-control input-sm ' />
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 						
									  </div> 					
									  <div class="form-group  depen-  wrap-slug  " >
										<label for="ipt" class=" control-label "> Slug    </label>
										<a class="adtip" data-toggle="tooltip" data-placement="bottom" title="Do not enter any special character or blank SPACE. Keep this value unique."><i class="fa fa-info-circle"></i></a>
										
										  <?php if( !isset($row['slug']))  $row['slug'] = null;   ?>
		<input  type='text' name='slug' id='slug' value='{{ $row['slug'] }}' 
						       class='form-control input-sm ' /> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-icon  " >
										<label for="ipt" class=" control-label "> Icon    </label>
										<a class="adtip" data-toggle="tooltip" data-placement="bottom" title="Preferred icon size: 150 px X 50px"><i class="fa fa-info-circle"></i></a>
										
										  <?php if( !isset($row['icon']))  $row['icon'] = null;   ?>
		<input  type='hidden' name='icon' id='icon' value='{{ $row['icon'] }}' class='icon    form-control input-sm '    />

							
                <button class='btn btn-primary mr-5' data-type='mediaUpload' data-target='.icon' type='button'>Choose file</button>
				<button class='btn btn-danger unUploadImage' data-type='mediaUnUpload' data-target='icon' type='button'>Remove File</button>
            
			
							<div class='icon_preview'></div>
							<div class='iconPreview'>
					 	<div class='img-preview'>
						{!! SiteHelpers::showUploadedFile($row['icon'],'/uploads/images/brand/') !!}
						
						</div>					
						</div>					
					 						
									  </div> 					
									  <div class="form-group  depen-  wrap-header_image  " >
										<label for="ipt" class=" control-label "> Header Image    </label>
										
										
										  <?php if( !isset($row['header_image']))  $row['header_image'] = null;   ?>
		<input  type='hidden' name='header_image' id='header_image' value='{{ $row['header_image'] }}' class='header_image    form-control input-sm '    />

							
                <button class='btn btn-primary mr-5' data-type='mediaUpload' data-target='.header_image' type='button'>Choose file</button>
				<button class='btn btn-danger unUploadImage' data-type='mediaUnUpload' data-target='header_image' type='button'>Remove File</button>
            
			
							<div class='header_image_preview'></div>
							<div class='header_imagePreview'>
					 	<div class='img-preview'>
						{!! SiteHelpers::showUploadedFile($row['header_image'],'') !!}
						
						</div>					
						</div>					
					 						
									  </div> 					
									  <div class="form-group  depen-  wrap-description  " >
										<label for="ipt" class=" control-label "> Description    </label>
										
										
										  <?php if( !isset($row['description']))  $row['description'] = null;   ?>
		 <?php $val = json_decode($row['description']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#description_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='description_{{$ilang}}_{{$curTime}}'>
				
				<textarea name="description[{{$ilang}}]" rows='5' id='description'   class='form-control editor input-sm '  
				             >{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}</textarea>
				
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 						
									  </div> <?php if( strlen($row['visits']) < 1 )  $row['visits']  = '0'; 	  ?>
		<input  type='hidden' name='visits' id='visits' value='{{$row['visits']}}' />
									
									  <div class="form-group  depen-  wrap-exclude_sitemap  " >
										<label for="ipt" class=" control-label "> Exclude Sitemap  <span class="asterix"> * </span>  </label>
										
										
										  <?php if( strlen($row['exclude_sitemap']) < 1 )  $row['exclude_sitemap']  = '0'; 	  ?>
		<div class='switch-wrap'> <label class='switch'>
				    <input type='hidden' name='exclude_sitemap' value ='0' />
					<input type='checkbox' name='exclude_sitemap' value ='1' 
					@if($row['exclude_sitemap']) checked @endif 
					 />   <span class="slider round"></span></label></div> 						
									  </div> <?php if( !isset($row['filter']))  $row['filter'] = null;   ?>
		<input  type='hidden' name='filter' id='filter' value='{{$row['filter']}}' />
				</fieldset>
			</div>
			
			<div class="col-md-6">
						<fieldset class="sbox" style="border-top:0; border-radius: 5px;"><legend> Additional Details</legend>
									
									  <div class="form-group  depen-  wrap-override_stores  " >
										<label for="ipt" class=" control-label "> Override Stores  <span class="asterix"> * </span>  </label>
										<a class="adtip" data-toggle="tooltip" data-placement="bottom" title="Switch this ON if you wish to select the recommended stores manually and retain the same."><i class="fa fa-info-circle"></i></a>
										
										  <?php if( strlen($row['override_stores']) < 1 )  $row['override_stores']  = '0'; 	  ?>
		<div class='switch-wrap'> <label class='switch'>
				    <input type='hidden' name='override_stores' value ='0' />
					<input type='checkbox' name='override_stores' value ='1' 
					@if($row['override_stores']) checked @endif 
					 />   <span class="slider round"></span></label></div> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-recom_store  " >
										<label for="ipt" class=" control-label "> Recommended Stores    </label>
										<a class="adtip" data-toggle="tooltip" data-placement="bottom" title="When Override Stores is OFF, this list is generated automatically at regular interval. However, you may select manually by switching it ON."><i class="fa fa-info-circle"></i></a>
										
										  <?php if( !isset($row['recom_store']))  $row['recom_store'] = null;   ?>
		 
					<?php $row['recom_store'] = trim($row['recom_store'],'[]'); ?>

					 <select name='recom_store[]' multiple rows='5' id='recom_store' class='select2 '  data-placeholder='Select Recommended Stores'   placeholder='Select Recommended Stores'      ></select> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-h1_tag  " >
										<label for="ipt" class=" control-label "> H1 Tag    </label>
										
										
										  <?php if( !isset($row['h1_tag']))  $row['h1_tag'] = null;   ?>
		 <?php $val = json_decode($row['h1_tag']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#h1_tag_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}}  {{$is_first ? "active" : null}}' id='h1_tag_{{$ilang}}_{{$curTime}}'>
				<input  type='text' name="h1_tag[{{$ilang}}]" id='h1_tag' value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}' 
						  placeholder='H1 Tag - {{$ilang}}'     class='form-control input-sm ' />
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 						
									  </div> 					
									  <div class="form-group  depen-  wrap-h2_tag  " >
										<label for="ipt" class=" control-label "> H2 Tag    </label>
										
										
										  <?php if( !isset($row['h2_tag']))  $row['h2_tag'] = null;   ?>
		 <?php $val = json_decode($row['h2_tag']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#h2_tag_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}}  {{$is_first ? "active" : null}}' id='h2_tag_{{$ilang}}_{{$curTime}}'>
				<input  type='text' name="h2_tag[{{$ilang}}]" id='h2_tag' value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}' 
						  placeholder='H2 Tag - {{$ilang}}'     class='form-control input-sm ' />
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 						
									  </div> 					
									  <div class="form-group  depen-  wrap-meta_title  " >
										<label for="ipt" class=" control-label "> Meta Title    </label>
										
										
										  <?php if( !isset($row['meta_title']))  $row['meta_title'] = null;   ?>
		 <?php $val = json_decode($row['meta_title']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#meta_title_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}}  {{$is_first ? "active" : null}}' id='meta_title_{{$ilang}}_{{$curTime}}'>
				<input  type='text' name="meta_title[{{$ilang}}]" id='meta_title' value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}' 
						  placeholder='Meta Title - {{$ilang}}'     class='form-control input-sm ' />
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 						
									  </div> 					
									  <div class="form-group  depen-  wrap-meta_desc  " >
										<label for="ipt" class=" control-label "> Meta Description    </label>
										
										
										  <?php if( !isset($row['meta_desc']))  $row['meta_desc'] = null;   ?>
		 <?php $val = json_decode($row['meta_desc']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#meta_desc_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}} {{$is_first ? "active" : null}}' id='meta_desc_{{$ilang}}_{{$curTime}}'>
				
				<textarea name="meta_desc[{{$ilang}}]" rows='5' id='meta_desc' class='form-control input-sm '  
				             >{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}</textarea>
				
				
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 						
									  </div> 					
									  <div class="form-group  depen-  wrap-meta_kw  " >
										<label for="ipt" class=" control-label "> Meta Keywords    </label>
										
										
										  <?php if( !isset($row['meta_kw']))  $row['meta_kw'] = null;   ?>
		 <?php $val = json_decode($row['meta_kw']); $is_first = true; ?>	
				<ul class='editor-nav nav nav-tabs'>

				@foreach(explode(',', config('website.cnf_langs')) as $ilang )<li class='{{$is_first ? "active" : null}} '><a  href='#meta_kw_{{$ilang}}_{{$curTime}}' data-toggle='tab'>{{$ilang}}</a></li>
				<?php  $is_first = false;?>
				@endforeach </ul>
				
				<div class="tab-content ">
				<?php $is_first = true; ?>
				@foreach(explode(',', config('website.cnf_langs')) as $ilang )
				<div class='tab-pane tab_{{$ilang}}  {{$is_first ? "active" : null}}' id='meta_kw_{{$ilang}}_{{$curTime}}'>
				<input  type='text' name="meta_kw[{{$ilang}}]" id='meta_kw' value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}' 
						  placeholder='Meta Keywords - {{$ilang}}'     class='form-control input-sm ' />
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 						
									  </div> </fieldset>
			</div>
			
			
		</div>
		
		
</div>
</div>
</div>
@include('/manage/'.$pageModule.'/subform')

		
		
		<div class="sbox-title clearfix">
			<div class="sbox-tools pull-right" >
				<a href="{{ url('/manage/'.$pageModule.'?return='.$return) }}" class="tips btn btn-sm "  title="{{ __('core.btn_back') }}" ><i class="fa  fa-times"></i></a> 
			</div>
			<div class="sbox-tools pull-left" >
				<button name="apply" class=" btn btn-sm btn-primary  "  title="{{ __('core.btn_back') }}" ><i class="fa  fa-check"></i> {{ __('core.sb_apply') }} </button>
				<button name="save" class=" btn btn-sm btn-success"  title="{{ __('core.btn_back') }}" ><i class="fa  fa-paste"></i> {{ __('core.sb_save') }} </button> 
			</div>
		</div>	
		
	
	
	<input type="hidden" name="action_task" value="save" />
	{!! Form::close() !!}
	</div>
</div>		

	
		 
   <script type="text/javascript">
	$(document).ready(function() { 
		
		
		
		$("#recom_store").select2({
			ajax: {
				url: "{{url('/manage/brands/ajaxselect?filter=stores:id:name')}}",
				data: function (params) {
					return {
						search: params.term,
						page: params.page || 1
					};
				},
				dataType: 'json',
				processResults: function (data) {
					data.page = data.page || 1;
					return {
						results: data.items.map(function (item) {
							return {
								id: item.id,
								text: selctToJson(item,'name')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 1,
			width:'100%'
		});
		

		@if( strlen($row["recom_store"]) > 0  )
		// Fetch the preselected item, and add to the control
			var recom_storeSelect = $('#recom_store');
			$.ajax({
				type: 'GET',
				url: "{!! url('/manage/brands/ajaxselect?filter=stores:id:name&values='.urlencode($row["recom_store"])) !!}",
			}).then(function (data) {
				// create the option and append to Select2
				data.items.map(function (item) {
											var option = new Option(selctToJson(item,'name'), item.id, true, true);
											recom_storeSelect.append(option).trigger('change');

										});


				// manually trigger the `select2:select` event
				recom_storeSelect.trigger({
					type: 'select2:select',
					params: {
						data: data
					}
				});
			});

			recom_storeSelect.select2_sortable();
			@endif

		 		 

		$('.removeMultiFiles').on('click',function(){
			var removeUrl = '{{ url("brands/removefiles?file=")}}'+$(this).attr('url');
			$(this).parent().remove();
			$.get(removeUrl,function(response){});
			$(this).parent('div').empty();	
			return false;
		});		
		
	});
	</script>		 
@stop