@extends('admin.layouts.container')

@section('content')
    <div class="side-title">
        <h3>{{ $head ?? '' }}</h3>
    </div>

    <div class="border-item">
        <form class="form-row" method="post" onsubmit="saveForm(this)" action="{{ $action }}">
            @if($parent ?? ''  && $parent->id)
                @method('PUT')
            @endif
            @CSRF

            <div class="form-group col-lg-6">
                <label>{{ meta('name', getCurrentLocale()) ?? __('parents.name') }} </label>
                <input type="text" class="form-control {{ $errors->has('name') ? 'is-invalid' : '' }}" name="name" placeholder="{{ meta('name', getCurrentLocale()) ??__('parents.name') }}" value='{{ old("name", $parent->name ?? "") }}'/>
            </div>

            <div class="form-group col-lg-6">
                <label>{{ meta('last_name', getCurrentLocale()) ?? __('parents.last_name') }} </label>
                <input type="text" class="form-control {{ $errors->has('last_name') ? 'is-invalid' : '' }}" name="last_name" placeholder="{{ meta('last_name', getCurrentLocale()) ??__('parents.last_name') }}" value='{{ old("last_name", $parent->last_name ?? "") }}'/>
            </div>

            <div class="form-group col-lg-6">
                <label>{{ meta('phone', getCurrentLocale()) ?? __('parents.phone') }} </label>
                <input type="number" class="form-control {{ $errors->has('phone') ? 'is-invalid' : '' }}" name="phone" placeholder="{{ meta('phone', getCurrentLocale()) ?? __('parents.phone') }}" value='{{ old("phone", $parent->phone ?? "") }}'/>
            </div>

            <div class="form-group col-lg-6">
                <label>{{ meta('id_number', getCurrentLocale()) ?? __('parents.id_number') }} </label>
                <input type="text" class="form-control {{ $errors->has('id_number') ? 'is-invalid' : '' }}" name="id_number" placeholder="{{ meta('id_number', getCurrentLocale()) ?? __('parents.id_number') }}" value='{{ old("id_number", $parent->id_number ?? "") }}'/>
            </div>


            <div class="form-group col-lg-6">
                <label>{{ meta('password', getCurrentLocale()) ?? __('parents.password') }} </label>
                <input type="password" class="form-control {{ $errors->has('password') ? 'is-invalid' : '' }}" name="password" placeholder="{{ meta('password', getCurrentLocale()) ?? __('parents.password') }}" value='{{ old("password", "") }}'/>
                @if($parent ?? ''  && $parent->id) <small style="color: red">** {{__('parents.password_hint')}}</small> @endif
            </div>

            <div class="form-group col-lg-6">
                <label>{{ meta('password_confirmation', getCurrentLocale()) ?? __('parents.password_confirmation') }} </label>
                <input type="password" class="form-control {{ $errors->has('password_confirmation') ? 'is-invalid' : '' }}" name="password_confirmation" placeholder="{{ meta('password_confirmation', getCurrentLocale()) ?? __('parents.password_confirmation') }}" value='{{ old("password_confirmation", "") }}'/>
            </div>


            {{--Start image container--}}
                <div class="form-group col-lg-6">
                    <label>{{ meta('photo', getCurrentLocale()) ?? __('parents.photo') }} </label>
                    <input id="image_thumbnail" class="image_thumbnail" type="hidden" name="photo" value="{{old("photo", $parent->photo ?? "")}}"/>

                    <div class="photos main_photo {{ old('photo', $parent->photo ?? '') ? ' wow fadeInUp' : 'hide' }}">
                        <div class="col-lg-4">
                            <div class="items">
                                <div class="img">
                                    <a href="#" id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" class="lfm" data-hide=".pick_button">
                                        <img src="{{asset(old('photo', $parent->photo ?? ''))}} "  id="image_holder" class="image_holder"/>
                                    </a>
                                </div>
                                <a href="#" class="showHide resetImage close" data-empty=".image_thumbnail" data-hide=".main_photo" data-show=".pick_button"><i class="fas fa-times"></i></a>
                            </div>
                        </div>
                    </div>

                    <div class="clearfix"></div>
                    <span class="input-group-btn pick_button {{ old('photo', $parent->photo ?? '') ? 'hide' : '' }} ">
                        <a id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" data-show=".main_photo" data-hide=".pick_button" class="lfm btn btn-primary text-light">
                            <i class="fas fa-camera-retro"></i> Choose
                        </a>
                    </span>
                </div>
            {{--End image container--}}
            @if($parent ?? ''  && $parent->id)
                <div class="col-lg-12 mb-3">
                        <h5 class="text-uppercase font-weight-bold">{{__('parents.children')}}</h5>
                        <div class="new-users border-item  table-responsive no-padding">
                            <table class="table table-bordered table-hover" style="text-align:center">
                                <thead>
                                    <th>{{__('parents.child_name')}}</th>
                                    <th>{{__('parents.gender')}}</th>
                                    <th>{{__('parents.school')}}</th>
                                    <th>{{__('parents.cash_per_day')}}</th>
                                    <th>{{ __('dashboard.created_at') }}</th>
                                    <th>{{ __('dashboard.processes') }}</th>
                                </thead>
                                <tbody>
                                    @if(count($children))
                                        @foreach($children as $row)
                                            <tr>
                                                <td>{{$row->name}}</td>
                                                <td>{{__('parents.genders.'.$row->gender)}}</td>
                                                <td>{{$row->school->currentDescription->title}}</td>
                                                <td>{{$row->cash_per_day}}</td>
                                                <td>{{$row->created_at}}</td>
                                                <td>
                                                    <a href="{{ route ('parents.children', $row->id) }}" class="dropdown-item" title="{{ __('dashboard.edit') }}"> <i class="bi bi-pen ml-1"></i> {{ __('dashboard.edit') }} </a>
                                                </td>
                                            </tr>
                                        @endforeach
                                    @else
                                        <tr>
                                            <td colspan="6">{{__('parents.not_exist_children')}}</td>
                                        </tr>
                                    @endif
                                </tbody>
                            </table>

                        </div>
                    </div>
            @endif


            <div class="text-center mt-5 col-12">
                <button class="butn"><span>{{ __('dashboard.save') }}</span></button>
            </div>
        </form>
    </div>

@endsection

@section('inner_js')
    <!-- Editor JS orders -->
    <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
