@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/webhookstore?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-12">
						<fieldset class="sbox" style="border-top:0; border-radius: 5px;"><legend> webhookstore</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  <span class="asterix"> * </span>  </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' required     ></select> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-network_id  " >
										<label for="ipt" class=" control-label "> Affiliate Network  <span class="asterix"> * </span>  </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 Affiliate Network'   placeholder='Select Affiliate Network' required     ></select> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-secret_key  " >
										<label for="ipt" class=" control-label "> Secret Key  <span class="asterix"> * </span>  </label>
										
										
										  <?php if( !isset($row['secret_key']))  $row['secret_key'] = null;   ?>
		<input  type='text' name='secret_key' id='secret_key' value='{{ $row['secret_key'] }}' 
						required       class='form-control input-sm ' /> 						
									  </div> 					
									  <div class="form-group  depen-  wrap-is_active  " >
										<label for="ipt" class=" control-label "> Enabled  <span class="asterix"> * </span>  </label>
										
										
										  <?php if( strlen($row['is_active']) < 1 )  $row['is_active']  = '1'; 	  ?>
		<div class='switch-wrap'> <label class='switch'>
				    <input type='hidden' name='is_active' value ='0' />
					<input type='checkbox' name='is_active' value ='1' 
					@if($row['is_active']) checked @endif 
					 />   <span class="slider round"></span></label></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() { 
		
		
		
		$("#store_id").select2({
			ajax: {
				url: "{{url('/manage/webhookstore/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/webhookstore/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

		
		$("#network_id").select2({
			ajax: {
				url: "{{url('/manage/webhookstore/ajaxselect?filter=networks: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: 0,
			width:'100%'
		});
		

		@if( strlen($row["network_id"]) > 0  )
		// Fetch the preselected item, and add to the control
			var network_idSelect = $('#network_id');
			$.ajax({
				type: 'GET',
				url: "{!! url('/manage/webhookstore/ajaxselect?filter=networks:id:name&values='.urlencode($row["network_id"])) !!}",
			}).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);
											network_idSelect.append(option).trigger('change');

										});


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

			network_idSelect.select2_sortable();
			@endif

		 		 

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