@extends('admin.layouts.master')

@section('css')
    <!-- Internal Select2 css -->
    <link href="{{URL::asset('assets/plugins/select2/css/select2.min.css')}}" rel="stylesheet">

    <!---Internal Fileupload css-->
    <link href="{{URL::asset('assets/plugins/fileuploads/css/fileupload.css')}}" rel="stylesheet" type="text/css"/>
@endsection

@section('content')
    <!-- row -->
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="card-body">
                    <div class="main-content-label mg-b-5">
                        {{ trans('employees.add_new_employee') }}
                    </div>
                    <form action="{{ route('employees.store') }}" method="post" enctype="multipart/form-data">
                        @csrf
                        <div class="pd-30 pd-sm-40 bg-gray-200">
                            <div class="row row-xs">

                                <div class="col-sm-12 col-md-12 mb-2">
                                    <input type="file" name="main_image" class="dropify" data-height="200" />
                                    @error('main_image')
                                        <h2 class="text-danger">{{ $message }}</h2>
                                    @enderror
                                </div>

                                <div class="col-md-12 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.the_id') }}</p>
                                        <input class="form-control @error('the_id') is-invalid @enderror" placeholder="{{ trans('employees.the_id') }}" type="number" name="the_id" value="{{ old('the_id') }}">
                                        @error('the_id')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-lg-12">
                                    <div class="bg-gray-200">
                                        <div class="form-group">
                                            <p class="mg-b-10">{{ trans('employees.prefix') }}</p>
                                            <select class="form-control select2 @error('prefix_id') is-invalid @enderror" name="prefix_id">
                                                <option label="prefix">
                                                    {{ trans('employees.prefix') }}
                                                </option>
                                                @foreach ($prefixes as $prefix)
                                                    <option value="{{ $prefix->id }}" {{ old('prefix_id') == $prefix->id?'selected':'' }}>
                                                        {{ $prefix->name }}
                                                    </option>
                                                @endforeach
                                            </select>
                                            @error('prefix_id')
                                                <span class="invalid-feedback" role="alert">
                                                    <strong>{{ $message }}</strong>
                                                </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-6 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.name_arabic') }}</p>
                                        <input class="form-control @error('name_ar') is-invalid @enderror" placeholder="{{ trans('employees.name_arabic') }}" type="text" name="name_ar" value="{{ old('name_ar') }}">
                                        @error('name_ar')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-6 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.name_english') }}</p>
                                        <input class="form-control @error('name_en') is-invalid @enderror" placeholder="{{ trans('employees.name_english') }}" type="text" name="name_en" value="{{ old('name_en') }}">
                                        @error('name_en')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-6 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.name_in_business_card_arabic') }}</p>
                                        <input class="form-control @error('name_in_business_card_ar') is-invalid @enderror" placeholder="{{ trans('employees.name_in_business_card_arabic') }}" type="text" name="name_in_business_card_ar" value="{{ old('name_in_business_card_ar') }}">
                                        @error('name_in_business_card_ar')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-6 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.name_in_business_card_english') }}</p>
                                        <input class="form-control @error('name_in_business_card_en') is-invalid @enderror" placeholder="{{ trans('employees.name_in_business_card_english') }}" type="text" name="name_in_business_card_en" value="{{ old('name_in_business_card_en') }}">
                                        @error('name_in_business_card_en')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-12 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.name_in_id_card') }}</p>
                                        <input class="form-control @error('name_in_id_card') is-invalid @enderror" placeholder="{{ trans('employees.name_in_id_card') }}" type="text" name="name_in_id_card" value="{{ old('name_in_id_card') }}">
                                        @error('name_in_id_card')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-lg-4">
                                    <div class="bg-gray-200">
                                        <div class="form-group">
                                            <p class="mg-b-10">{{ trans('employees.position') }}</p>
                                            <select class="form-control select2 @error('position_id') is-invalid @enderror" name="position_id">
                                                <option label="position">
                                                    {{ trans('employees.position') }}
                                                </option>
                                                @foreach ($positions as $position)
                                                    <option value="{{ $position->id }}" {{ old('position_id') == $position->id?'selected':'' }}>
                                                        {{ $position->name }}
                                                    </option>
                                                @endforeach
                                            </select>
                                            @error('position_id')
                                                <span class="invalid-feedback" role="alert">
                                                    <strong>{{ $message }}</strong>
                                                </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>

                                <div class="col-lg-4">
                                    <div class="bg-gray-200">
                                        <div class="form-group">
                                            <p class="mg-b-10">{{ trans('employees.sector') }}</p>
                                            <select class="form-control select2 @error('sector_id') is-invalid @enderror " name="sector_id">
                                                <option label="sector">
                                                    {{ trans('employees.sector') }}
                                                </option>
                                                @foreach ($sectors as $sector)
                                                    <option value="{{ $sector->id }}" {{ old('sector_id') == $sector->id ?'selected':'' }}>
                                                        {{ $sector->name }}
                                                    </option>
                                                @endforeach
                                            </select>
                                            @error('sector_id')
                                                <span class="invalid-feedback" role="alert">
                                                    <strong>{{ $message }}</strong>
                                                </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>

                                <div class="col-lg-4">
                                    <div class="bg-gray-200">
                                        <div class="form-group">
                                            <p class="mg-b-10">{{ trans('employees.extension') }}</p>
                                            <select class="form-control select2 @error('extension_id') is-invalid @enderror" name="extension_id">
                                                <option label="extension">
                                                    {{ trans('employees.extension') }}
                                                </option>
                                                @foreach ($extensions as $extension)
                                                    <option value="{{ $extension->id }}" {{ old('extension_id') == $extension->id ?'selected':'' }}>
                                                        {{ $extension->name }}
                                                    </option>
                                                @endforeach
                                            </select>
                                            @error('extension_id')
                                                <span class="invalid-feedback" role="alert">
                                                    <strong>{{ $message }}</strong>
                                                </span>
                                            @enderror
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-4 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.mobile') }}</p>
                                        <input class="form-control @error('mobile') is-invalid @enderror" placeholder="{{ trans('employees.mobile') }}" type="text" name="mobile" value="{{ old('mobile') }}">
                                        @error('mobile')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-4 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.telephone') }}</p>
                                        <input class="form-control @error('telephone') is-invalid @enderror" placeholder="{{ trans('employees.telephone') }}" type="text" name="telephone" id="telephone" value="{{ old('telephone') }}">
                                        @error('telephone')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-4 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.fax') }}</p>
                                        <input class="form-control @error('fax') is-invalid @enderror" placeholder="{{ trans('employees.fax') }}" type="text" name="fax" id="fax" value="{{ old('fax') }}">
                                        @error('fax')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-12 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.address') }}</p>
                                        <select class="form-control select2 @error('address') is-invalid @enderror" name="address" id="address">
                                            <option value="" label="address">
                                                {{ trans('employees.address') }}
                                            </option>
                                            @foreach ($locations as $location)
                                                <option {{ old('address') == $location->name ?'selected':'' }}>
                                                    {{ $location->name }}
                                                </option>
                                            @endforeach
                                        </select>
                                        @error('address')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-6 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.email') }}</p>
                                        <input class="form-control @error('email') is-invalid @enderror" placeholder="{{ trans('employees.email') }}" type="text" name="email" value="{{ old('email') }}">
                                        @error('email')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-6 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.website') }}</p>
                                        <input class="form-control @error('website') is-invalid @enderror" placeholder="{{ trans('employees.website') }}" type="text" name="website" value="{{ old('website') ?? 'www.east-eg.com' }}">
                                        @error('website')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-12 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.moto_text') }}</p>
                                        <input class="form-control @error('moto_text') is-invalid @enderror" placeholder="{{ trans('employees.moto_text') }}" type="text" name="moto_text" value="{{ old('moto_text') ?? 'SUSTAINABILITY AND INNOVATION' }}">
                                        @error('moto_text')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-12 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.type') }}</p>
                                        <select class="form-control select2 @error('type') is-invalid @enderror" name="type" id="type">
                                            <option value=""></option>
                                            <option value="employee">{{ trans('employees.employee') }}</option>
                                            <option value="manager">{{ trans('employees.manager') }}</option>
                                        </select>
                                        @error('type')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-12 mg-t-10 mg-md-t-0" id="employees" style="visibility: hidden;">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.employees') }}</p>
                                        <select class="form-control select2 @error('employees') is-invalid @enderror" name="employees[]" multiple="multiple">
                                            @foreach ($users as $user)
                                                <option value="{{ $user->id }}">
                                                    {{ $user->{'name_' . $locale} }}
                                                </option>
                                            @endforeach
                                        </select>
                                        @error('employees')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>


                                {{--<div class="col-md-12 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.location') }}</p>
                                        <input class="form-control @error('location') is-invalid @enderror" placeholder="{{ trans('employees.location') }}" type="text" name="location" value="{{ old('location') }}">
                                        @error('location')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>

                                <div class="col-md-12 mg-t-10 mg-md-t-0">
                                    <div class="form-group">
                                        <p class="mg-b-10">{{ trans('employees.password') }}</p>
                                        <input class="form-control @error('password') is-invalid @enderror" placeholder="{{ trans('employees.password') }}" type="text" name="password" value="{{ old('password') }}">
                                        @error('password')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>
                                </div>--}}



                                <div class="col-md mt-4 mt-xl-0">
                                    <button class="btn btn-main-primary btn-block">{{ trans('dashboard.add') }}</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <!-- Internal Select2.min js -->
    <script src="{{URL::asset('assets/plugins/select2/js/select2.min.js')}}"></script>

    <!-- Internal form-elements js -->
    <script src="{{URL::asset('assets/js/form-layouts.js')}}"></script>

    <!--Internal Fileuploads js-->
    <script src="{{URL::asset('assets/plugins/fileuploads/js/fileupload.js')}}"></script>
    <script src="{{URL::asset('assets/plugins/fileuploads/js/file-upload.js')}}"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js" defer></script>

    <script>
        $(document).on('change', '#address', function(){
            axios.get('../get_locations/'+$('#address').val())
                .then((data) => {
                $('#telephone').val(data.data.telephone);
                $('#fax').val(data.data.fax);
            })
        })


        $(document).on('change', '#type', function(){
            if($('#type').val() == 'manager')
            {
                $('#employees').css('visibility', 'visible');
            }else{
                $('#employees').css('visibility', 'hidden');
            }
        });


    </script>

@endsection
