@extends('admin.layout.page-app')
@section('page_title', __('label.edit_company'))
@section('tab_title', __('label.edit_company'))

@section('content')
	@include('admin.layout.sidebar')

	<div class="right-content">
		@include('admin.layout.header')

		<!-- Select2 -->
    	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" />

  		<div class="body-content">
  			<!-- mobile title -->
  			<h1 class="page-title-sm">{{__('label.edit_company')}}</h1>

  			<div class="border-bottom row">
  				<div class="col-sm-10">
  					<ol class="breadcrumb">
  						<li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">{{__('label.dashboard')}}</a></li>
  						<li class="breadcrumb-item"><a href="{{ route('company.index') }}">{{__('label.company')}}</a></li>
  						<li class="breadcrumb-item active" aria-current="page">{{__('label.edit_company')}}</li>
  					</ol>
  				</div>
  				<div class="col-sm-2 d-flex align-items-center justify-content-end">
  					<a href="{{ route('company.index') }}" class="btn btn-default mw-120" style="margin-top:-14px">{{__('label.company')}}</a>
  				</div>
  			</div>

			<form id="edit_company" enctype="multipart/form-data">
				<div class="card custom-border-card mt-3">
					<div class="card-body">
						<input type="hidden" name="id" value="{{$result->id}}">
                        <input type="hidden" name="country_name" value="BZ">
						<div class="form-row">
							<div class="col-md-10">
								<div class="form-row">
									<div class="col-6">
										<div class="form-group">
											<label>{{__('label.citizen')}}<span class="text-danger">*</span></label>
											<select class="form-control" name="user_id" id="user_id">
												<option value="">{{__('label.select_citizen')}}</option>
												@foreach ($user as $key => $value)
													<option value="{{$value->id}}" {{ $result->user_id == $value->id ? 'selected' : ""}}>
														{{ $value->full_name }}
													</option>
												@endforeach
											</select>
										</div>
									</div>
									<div class="col-md-6">
										<div class="form-group">
											<label>{{__('label.name')}}<span class="text-danger">*</span></label>
											<input name="name" type="text" class="form-control" value="{{$result->name}}" placeholder="{{__('label.name_here')}}" autofocus>
										</div>
									</div>
								</div>
								<div class="form-row">
									<div class="col-md-2">
										<div class="form-group">
											<label>{{__('label.country_code')}}<span class="text-danger">*</span></label>
											<input name="country_code" type="text" class="form-control" value="{{$result->country_code}}" placeholder="{{__('label.+91')}}">
										</div>
									</div>
									<div class="col-md-4">
										<div class="form-group">
											<label>{{__('label.mobile_number')}}<span class="text-danger">*</span></label>
											<input name="mobile_number" type="text" class="form-control" value="{{$result->mobile_number}}" placeholder="{{__('label.mobile_number_here')}}">
										</div>
									</div>
									<div class="col-md-6">
										<div class="form-group">
											<label>{{__('label.position')}}</label>
											<input name="position" type="text" class="form-control" value="{{$result->position}}" placeholder="{{__('label.position_here')}}">
										</div>
									</div>
								</div>
								<div class="form-row">
									<div class="col-md-12">
										<div class="form-group">
											<label>{{__('label.activity')}}</label>
											<textarea name="activity" type="text" class="form-control" placeholder="{{__('label.activity_here')}}">{{$result->activity}}</textarea>
										</div>
									</div>
								</div>
							</div>
							<div class="col-md-2">
								<div class="form-group ml-2">
									<label>{{__('label.logo')}}</label>
									<div class="avatar-upload">
										<div class="avatar-edit">
											<input type='file' name="logo" id="imageUpload" accept=".png, .jpg, .jpeg" />
											<label for="imageUpload" title="{{__('label.upload_file')}}"></label>
										</div>
										<div class="avatar-preview">
											<img src="{{$result->logo}}" id="imagePreview">
										</div>
									</div>
									<input type="hidden" name="old_logo" value="{{$result->logo}}">
									<label class="mt-3 text-gray">{{__('label.max_size_5mb')}}</label>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="card custom-border-card">
					<h5 class="card-header">{{__('label.address')}}</h5>
					<div class="card-body">
						<div class="form-row">
							<div class="col-4">
								<div class="form-group">
									<label>{{__('label.address')}}</label>
									<input name="address" type="text" value="{{$result->address}}" class="form-control" placeholder="{{__('label.address_here')}}">
								</div>
							</div>
							<div class="col-4">
								<div class="form-group">
									<label>{{__('label.area')}}</label>
									<input name="area" type="text" value="{{$result->area}}" class="form-control" placeholder="{{__('label.area_here')}}">
								</div>
							</div>
							<div class="col-4">
								<div class="form-group">
									<label>{{__('label.city')}}</label>
									<input name="city" type="text" value="{{$result->city}}" class="form-control" placeholder="{{__('label.city_here')}}">
								</div>
							</div>
							<div class="col-4">
								<div class="form-group">
									<label>{{__('label.state')}}</label>
									<input name="state" type="text" value="{{$result->state}}" class="form-control" placeholder="{{__('label.state_here')}}">
								</div>
							</div>
							<div class="col-4">
								<div class="form-group">
									<label>{{__('label.country')}}</label>
									<input name="country" type="text" value="{{$result->country}}" class="form-control" placeholder="{{__('label.country_here')}}">
								</div>
							</div>
							<div class="col-4">
								<div class="form-group">
									<label>{{__('label.pincode')}}</label>
									<input name="pincode" type="text"  value="{{$result->pincode}}"class="form-control" placeholder="{{__('label.pincode_here')}}">
								</div>
							</div>
							<div class="col-4">
								<div class="form-group">
									<label>{{__('label.latitude')}}</label>
									<input name="latitude" type="text" value="{{$result->latitude}}" class="form-control" placeholder="{{__('label.latitude_here')}}">
								</div>
							</div>
							<div class="col-4">
								<div class="form-group">
									<label>{{__('label.longitude')}}</label>
									<input name="longitude" type="text" value="{{$result->longitude}}" class="form-control" placeholder="{{__('label.longitude_here')}}">
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="pt-3 text-right">
					<button type="button" class="btn btn-default mw-120" onclick="edit_company()">{{__('label.update')}}</button>
					<a href="{{route('company.index')}}" class="btn btn-cancel mw-120 ml-2">{{__('label.cancel')}}</a>
					<input type="hidden" name="_method" value="PATCH">
				</div>
			</form>
		</div>
  	</div>		
@endsection

@section('pagescript')
	<!-- Select2 -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>

	<script>
		$('#user_id').select2();
		function edit_company(){

			var Demo_Mode = '<?php echo Demo_Mode(); ?>';
            if(Demo_Mode == 1){

				$("#dvloader").show();
				var formData = new FormData($("#edit_company")[0]);
				$.ajax({
					type:'POST',
					url:'{{ route("company.update", [$result->id]) }}',
					data:formData,
					cache:false,
					contentType: false,
					processData: false,
					success:function(resp){
						$("#dvloader").hide();
						get_responce_message(resp, 'edit_company', '{{ route("company.index") }}');
					},
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        $("#dvloader").hide();
                        toastr.error(errorThrown, textStatus);
                    }
				});
			} else {
                showError();
            }
		}
	</script>
@endsection