

		 {!! Form::open(array('url'=>'storecashback/savepublic', 'class'=>'form-horizontal','files' => true , 'parsley-validate'=>'','novalidate'=>' ')) !!}

	@if(Session::has('messagetext'))
	  
		   {!! Session::get('messagetext') !!}
	   
	@endif
	<ul class="parsley-error-list">
		@foreach($errors->all() as $error)
			<li>{{ $error }}</li>
		@endforeach
	</ul>		


<div class="sbox1"><div class="col-md-6">
						<fieldset class="sbox" style="border-top:0; border-radius: 5px;"><legend> Store Cashback</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-store_id  " >
										<label for="Store" class=" control-label col-md-3 text-left"> Store <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['store_id']))  $row['store_id'] = null;   ?>
		 
					<?php $row['store_id'] = trim($row['store_id'],'[]'); ?>

					 <select name='store_id' rows='5' id='store_id' class='select2 '  data-placeholder='Select Store'   placeholder='Select Store' required     ></select> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-title  " >
										<label for="Cashback Structure Title" class=" control-label col-md-3 text-left"> Cashback Structure Title <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['title']))  $row['title'] = null;   ?>
		 <?php $val = json_decode($row['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='#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='title_{{$ilang}}_{{$curTime}}'>
				<input  type='text' name="title[{{$ilang}}]" id='title' value='{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}' 
						required  placeholder='Cashback Structure Title - {{$ilang}}'     class='form-control input-sm ' />
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-image  " >
										<label for="Image" class=" control-label col-md-3 text-left"> Image </label>
										<a class="adtip" data-toggle="tooltip" data-placement="bottom" title="Optional, required to show as cashback categories"><i class="fa fa-info-circle"></i></a>
										
										<div class="col-md-9">
										  <?php if( !isset($row['image']))  $row['image'] = null;   ?>
		<input  type='hidden' name='image' id='image' value='{{ $row['image'] }}' class='image    form-control input-sm '    />

							
                <button class='btn btn-primary mr-5' data-type='mediaUpload' data-target='.image' type='button'>Choose file</button>
				<button class='btn btn-danger unUploadImage' data-type='mediaUnUpload' data-target='image' type='button'>Remove File</button>
            
			
							<div class='image_preview'></div>
							<div class='imagePreview'>
					 	<div class='img-preview'>
						{!! SiteHelpers::showUploadedFile($row['image'],'/uploads/images/store/') !!}
						
						</div>					
						</div>					
					 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-rate_type  " >
										<label for="Rate Type" class=" control-label col-md-3 text-left"> Rate Type <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( strlen($row['rate_type']) < 1 )  $row['rate_type']  = 'percent'; 	  ?>
		
					<?php $rate_type = explode(',',$row['rate_type']);
					$rate_type_opt = array( 'fixed' => 'Fixed' ,  'percent' => 'Percent' , ); ?>
					<select name='rate_type' rows='5' required  placeholder='Select Rate Type' data-placeholder='Select Rate Type'    class='regSel form-control'  > 
						<?php 
						foreach($rate_type_opt as $key=>$val)
						{
							echo "<option  value ='$key' ".($row['rate_type'] == $key ? " selected='selected' " : '' ).">$val</option>"; 						
						}						
						?></select> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-rate_amount_network  " >
										<label for="Network Rate" class=" control-label col-md-3 text-left"> Network Rate </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['rate_amount_network']))  $row['rate_amount_network'] = null;   ?>
		<input  type='text' name='rate_amount_network' id='rate_amount_network' value='{{ $row['rate_amount_network'] }}' 
						   data-parsley-maxlength="10"    class='form-control is_decimal' onkeypress='return isNumberKey(event,this)'  /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-link  " >
										<label for="Link" class=" control-label col-md-3 text-left"> Link </label>
										<a class="adtip" data-toggle="tooltip" data-placement="bottom" title="Optional, required to show as cashback categories"><i class="fa fa-info-circle"></i></a>
										
										<div class="col-md-9">
										  <?php if( !isset($row['link']))  $row['link'] = null;   ?>
		<input  type='text' name='link' id='link' value='{{ $row['link'] }}' 
						   data-parsley-maxlength="5000"    class='form-control input-sm ' /> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-enabled  " >
										<label for="Enabled" class=" control-label col-md-3 text-left"> Enabled <span class="asterix"> * </span></label>
										
										
										<div class="col-md-9">
										  <?php if( strlen($row['enabled']) < 1 )  $row['enabled']  = '1'; 	  ?>
		<div class='switch-wrap'> <label class='switch'>
				    <input type='hidden' name='enabled' value ='0' />
					<input type='checkbox' name='enabled' value ='1' 
					@if($row['enabled']) checked @endif 
					 />   <span class="slider round"></span></label></div> 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> </fieldset>
			</div>
			
			<div class="col-md-6">
						<fieldset class="sbox" style="border-top:0; border-radius: 5px;"><legend> Additional Information</legend>
									
									  <div class="form-group depen- wrap-description  " >
										<label for="Description" class=" control-label col-md-3 text-left"> Description </label>
										
										
										<div class="col-md-9">
										  <?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 input-sm '  
				             >{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}</textarea>
				
				
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> 					
									  <div class="form-group depen- wrap-exclusion  " >
										<label for="Exclusion" class=" control-label col-md-3 text-left"> Exclusion </label>
										
										
										<div class="col-md-9">
										  <?php if( !isset($row['exclusion']))  $row['exclusion'] = null;   ?>
		 <?php $val = json_decode($row['exclusion']); $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='#exclusion_{{$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='exclusion_{{$ilang}}_{{$curTime}}'>
				
				<textarea name="exclusion[{{$ilang}}]" rows='5' id='exclusion' class='form-control input-sm '  
				             >{{   isset($val->{$ilang}) ? $val->{$ilang} : ''   }}</textarea>
				
				
						</div>
						<?php  $is_first = false;?>
						@endforeach
						</div>
						 
										 </div> 
										 <div class="col-md-2">
										 	
										 </div>
									  </div> </fieldset>
			</div>
			
			
		</div>
		
		

			<div style="clear:both"></div>	
				
					
				  <div class="form-group">
					<label class="col-sm-4 text-right">&nbsp;</label>
					<div class="col-sm-8">	
					<button type="submit" name="apply" class="btn btn-info btn-sm" ><i class="fa  fa-check-circle"></i> {{ Lang::get('core.sb_apply') }}</button>
					<button type="submit" name="submit" class="btn btn-primary btn-sm" ><i class="fa  fa-save "></i> {{ Lang::get('core.sb_save') }}</button>
				  </div>	  
			
		</div> 
		 <input type="hidden" name="action_task" value="public" />
		 {!! Form::close() !!}
		 
   <script type="text/javascript">
	$(document).ready(function() { 
		
		
		$("#store_id").select2({
			ajax: {
				url: "{{url('/manage/storecashback/ajaxselect?filter=stores:id:slug')}}",
				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,'slug')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 0,
			width:'100%'
		});
		

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

										});


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

			store_idSelect.select2_sortable();
			@endif

		 

		$('.removeCurrentFiles').on('click',function(){
			var removeUrl = $(this).attr('href');
			$.get(removeUrl,function(response){});
			$(this).parent('div').empty();	
			return false;
		});		
		
	});
	</script>		 
