

		 {!! Form::open(array('url'=>'clicks/savepublic', 'class'=>'form-vertical','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> Clicks Data</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="ipt" class=" control-label "> Store    </label>
										
										
										  <?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'      ></select> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-user_id  " >
										<label for="ipt" class=" control-label "> User    </label>
										
										
										  <?php if( !isset($row['user_id']))  $row['user_id'] = null;   ?>
		 
					<?php $row['user_id'] = trim($row['user_id'],'[]'); ?>

					 <select name='user_id' rows='5' id='user_id' class='select2 '  data-placeholder='Select User'   placeholder='Select User'      ></select> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-link_id  " >
										<label for="ipt" class=" control-label "> Link Id    </label>
										
										
										  <?php if( !isset($row['link_id']))  $row['link_id'] = null;   ?>
		 
					<?php $row['link_id'] = trim($row['link_id'],'[]'); ?>

					 <select name='link_id' rows='5' id='link_id' class='select2 '  data-placeholder='Select Link Id'   placeholder='Select Link Id'      ></select> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-click_time  " >
										<label for="ipt" class=" control-label "> Click Time    </label>
										
										
										  <?php if( strlen($row['click_time']) < 1 )  $row['click_time']  = '2019-11-05 06:30:39'; 	  ?>
		
				<div class="input-group m-b" style="width:150px !important;">
				
				<input  type='text' name='click_time' id='click_time' value='{{ $row['click_time'] }}' 
				       class='form-control input-sm @if(trim('  ')!='readonly') datetime @endif ' />

					<span class="input-group-addon calwrap"><i class="fa fa-calendar"></i></span>
				</div>
				 						
									  </div> 					
									  <div class="form-group  depen-  wrap-ip_address  " >
										<label for="ipt" class=" control-label "> Ip Address    </label>
										
										
										  <?php if( !isset($row['ip_address']))  $row['ip_address'] = null;   ?>
		<input  type='text' name='ip_address' id='ip_address' value='{{ $row['ip_address'] }}' 
						       class='form-control input-sm ' /> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-cashback_enabled  " >
										<label for="ipt" class=" control-label "> Cashback Enabled  <span class="asterix"> * </span>  </label>
										
										
										  <?php if( strlen($row['cashback_enabled']) < 1 )  $row['cashback_enabled']  = '0'; 	  ?>
		<div class='switch-wrap'> <label class='switch'>
				    <input type='hidden' name='cashback_enabled' value ='0' />
					<input type='checkbox' name='cashback_enabled' value ='1' 
					@if($row['cashback_enabled']) checked @endif 
					 />   <span class="slider round"></span></label></div> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-cashback_percent  " >
										<label for="ipt" class=" control-label "> Cashback Percent  <span class="asterix"> * </span>  </label>
										
										
										  <?php if( strlen($row['cashback_percent']) < 1 )  $row['cashback_percent']  = '0'; 	  ?>
		<input  type='number' name='cashback_percent' id='cashback_percent' value='{{ $row['cashback_percent'] }}' 
						required       class='form-control is_number'  /> 						
									  </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-original_link  " >
										<label for="ipt" class=" control-label "> Original Link    </label>
										
										
										  <?php if( !isset($row['original_link']))  $row['original_link'] = null;   ?>
		<input  type='text' name='original_link' id='original_link' value='{{ $row['original_link'] }}' 
						       class='form-control input-sm ' /> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-redirect_link  " >
										<label for="ipt" class=" control-label "> Redirect Link  <span class="asterix"> * </span>  </label>
										
										
										  <?php if( !isset($row['redirect_link']))  $row['redirect_link'] = null;   ?>
		<input  type='text' name='redirect_link' id='redirect_link' value='{{ $row['redirect_link'] }}' 
						required       class='form-control input-sm ' /> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-http_referrer  " >
										<label for="ipt" class=" control-label "> Http Referrer    </label>
										
										
										  <?php if( !isset($row['http_referrer']))  $row['http_referrer'] = null;   ?>
		<input  type='text' name='http_referrer' id='http_referrer' value='{{ $row['http_referrer'] }}' 
						       class='form-control input-sm ' /> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-source_id  " >
										<label for="ipt" class=" control-label "> Source Id    </label>
										
										
										  <?php if( !isset($row['source_id']))  $row['source_id'] = null;   ?>
		<input  type='text' name='source_id' id='source_id' value='{{ $row['source_id'] }}' 
						       class='form-control input-sm ' /> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-source_type  " >
										<label for="ipt" class=" control-label "> Source Type    </label>
										
										
										  <?php if( !isset($row['source_type']))  $row['source_type'] = null;   ?>
		<?php $source_type = (isset($row['source_type'])) ? $row['source_type'] : null ; ?>
					
					<input type='radio' name='source_type' value ='store'     @if( $source_type == 'store') checked="checked" @endif class='minimal-red' > Store 
					
					<input type='radio' name='source_type' value ='coupon'     @if( $source_type == 'coupon') checked="checked" @endif class='minimal-red' > Coupon 
					
					<input type='radio' name='source_type' value ='slider'     @if( $source_type == 'slider') checked="checked" @endif class='minimal-red' > Slider  						
									  </div> 					
									  <div class="form-group  depen-  wrap-network_id  " >
										<label for="ipt" class=" control-label "> Network    </label>
										
										
										  <?php if( !isset($row['network_id']))  $row['network_id'] = null;   ?>
		 
					<?php $row['network_id'] = trim($row['network_id'],'[]'); ?>

					 <select name='network_id' rows='5' id='network_id' class='select2 '  data-placeholder='Select Network'   placeholder='Select Network'      ></select> 						
									  </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/clicks/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/clicks/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

		
		$("#user_id").select2({
			ajax: {
				url: "{{url('/manage/clicks/ajaxselect?filter=users:user_id:first_name|last_name|email')}}",
				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.user_id,
								text: selctToJson(item,'first_name|last_name|email')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 0,
			width:'100%'
		});
		

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

										});


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

			user_idSelect.select2_sortable();
			@endif

		
		$("#link_id").select2({
			ajax: {
				url: "{{url('/manage/clicks/ajaxselect?filter=user_links:id:offer_link')}}",
				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,'offer_link')
							};
						}),
						pagination: {
							more: data.pagination
						}
					}
				},
				cache: true,
				delay: 250
			},
			// minimumInputLength: 2,
			multiple: 0,
			width:'100%'
		});
		

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

										});


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

			link_idSelect.select2_sortable();
			@endif

		
		$("#network_id").jCombo("{!! url('/manage/clicks/comboselect?filter=networks:id:name&values='.$row["network_id"]) !!}",
		{  selected_value : '{{ $row["network_id"] }}' });
		 

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