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

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

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

		<div class="body-content">
			<!-- mobile title -->
			<h1 class="page-title-sm">Profile</h1>

			<div class="border-bottom row mb-3">
				<div class="col-sm-12">
					<ol class="breadcrumb">
						<li class="breadcrumb-item">
							<a href="{{ route('incharge.dashboard') }}">{{__('label.dashboard')}}</a>
						</li>
						<li class="breadcrumb-item active" aria-current="page">
							Profile
						</li>
					</ol>
				</div>
			</div>

            <form id="profile" enctype="multipart/form-data" autocomplete="off">
                <input type="hidden" name="id" value="@if($data){{$data->id}}@endif">
                <div class="card custom-border-card">
                    <h5 class="card-header">{{__('label.personal_info')}}</h5>
                    <div class="card-body">
                        <div class="form-row">
                            <div class="col-md-8">
                                <div class="form-row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>{{__('label.full_name')}}<span class="text-danger">*</span></label>
                                            <input name="full_name" type="text" value="{{$data->full_name}}" class="form-control" placeholder="{{__('label.full_name_here')}}">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>{{__('label.email')}}<span class="text-danger">*</span></label>
                                            <input name="email" type="email" value="{{$data->email}}" class="form-control" placeholder="{{__('label.email_here')}}">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-row">
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>{{__('label.country_code')}}<span class="text-danger">*</span></label>
                                            <input name="country_code" type="text" value="{{$data->country_code}}" class="form-control" placeholder="{{__('label.+91')}}">
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label>{{__('label.country_name')}}<span class="text-danger">*</span></label>
                                            <input name="country_name" type="text" value="{{$data->country_name}}" class="form-control" placeholder="{{__('label.ind')}}">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label>{{__('label.mobile_number')}}<span class="text-danger">*</span></label>
                                            <input name="mobile_number" type="text" value="{{$data->mobile_number}}" class="form-control" placeholder="{{__('label.mobile_number_here')}}">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group ml-5">
                                    <label>{{__('label.image')}}<span class="text-danger">*</span></label>
                                    <div class="avatar-upload">
                                        <div class="avatar-edit">
                                            <input type='file' name="image" id="imageUpload" accept=".png, .jpg, .jpeg" />
                                            <label for="imageUpload" title="{{__('label.upload_file')}}"></label>
                                        </div>
                                        <div class="avatar-preview">
                                            <img src="{{$data->image}}" id="imagePreview">
                                        </div>
                                    </div>
                                    <input type="hidden" name="old_image" value="{{$data->image}}">
                                    <label class="mt-3 text-gray">{{__('label.max_size_5mb')}}</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card custom-border-card mt-3">
                    <h5 class="card-header">{{__('label.department_info')}}</h5>
                    <div class="card-body">
                        <input type="hidden" name="department_id" value="@if($data->department){{$data->department->id}}@endif">
                        <div class="form-row">
                            <div class="col-md-8">
                                <div class="form-row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label>{{__('label.name')}}<span class="text-danger">*</span></label>
                                            <input type="text" name="name" class="form-control" value="@if($data->department){{$data->department->name}}@endif" placeholder="{{__('label.name_here')}}" readonly>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label>{{__('label.department_color')}}<span class="text-danger">*</span></label>
                                            <div class="input-group colorpicker-component">
                                                <input type="text" id="hexcolor-1" class="form-control hexcolor" value="@if($data->department){{$data->department->department_color}}@endif" pattern="^#+([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$">
                                                <input type="color" id="colorpicker-1" name="department_color" value="@if($data->department){{$data->department->department_color}}@endif" class="colorpicker" pattern="^#+([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group ml-4">
                                    <label>{{__('label.department_icon')}}<span class="text-danger">*</span></label>
                                    <div class="avatar-upload">
                                        <div class="avatar-edit">
                                            <input type='file' name="department_icon" id="imageUploadModel" accept=".png, .jpg, .jpeg" />
                                            <label for="imageUploadModel" title="{{__('label.upload_file')}}"></label>
                                        </div>
                                        <div class="avatar-preview">
                                            <img src="@if($data->department){{$data->department->department_icon}}@endif" id="imagePreviewModel">
                                        </div>
                                    </div>
                                    <input type="hidden" name="old_department_icon" value="@if($data->department){{$data->department->department_icon}}@endif">
                                    <label class="mt-3 text-gray">{{__('label.max_size_5mb')}}</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="text-right">
                    <button type="button" class="btn btn-default mw-120" onclick="update_profile()">{{__('label.update')}}</button>
                    <input type="hidden" name="_method" value="PATCH">
                </div>
            </form>
		</div>
	</div>
@endsection

@section('pagescript')
	<script>
		function update_profile(){

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

                $("#dvloader").show();
                var formData = new FormData($("#profile")[0]);

                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    enctype: 'multipart/form-data',
                    type: 'POST',
                    url: '{{route("inprofile.update", [$data->id])}}',
                    data: formData,
                    cache:false,
                    contentType: false,
                    processData: false,
                    success:function(resp){
                        $("#dvloader").hide();
                        get_responce_message(resp, 'profile', '{{ route("inprofile.index") }}');
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        $("#dvloader").hide();
                        toastr.error(errorThrown, textStatus);;         
                    }
                });
            } else {
                showError();
            }
		}
	</script>
@endsection