@extends('layouts.admin.app')

@section('content')
    <div class="card">

        <h5 class="card-header">
            <a href="{{ url('admin/users') }}" class="btn rounded-pill btn-label-primary">
                <i class="ti me-2 ti-arrow-forward-up"></i> {{ __('trans.user.title') }}
            </a>
            @yield('title')
        </h5>
        <div class="card-body">

            <form action="{{ route('users.update', $user->id) }}" method="POST" enctype="multipart/form-data">
                @method('put')
                @csrf
                <div class="row">

                    <div class="col-md-4 mb-3">
                        <label class="form-label">{{ __('trans.user.name') }} <b class="text-danger">*</b></label>
                        <input type="text" class="form-control" required name="name"
                            value="{{ old('name', $user->name) }}" placeholder="{{ __('trans.user.name') }}" />
                    </div>


                    <div class="col-md-4 mb-3">
                        <div class="form-password-toggle">
                            <label class="form-label">{{ __('trans.user.password') }}</label>
                            <div class="input-group input-group-merge">

                                <input type="password" class="form-control" name="password" value="{{ old('password') }}"
                                    placeholder="&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;&#xb7;" />
                                <span class="input-group-text cursor-pointer" id="basic-default-password">
                                    <i class="ti ti-eye-off"></i>
                                </span>
                            </div>
                        </div>
                    </div>


                    <div class="col-md-4 mb-3">
                        <label class="form-label">{{ __('trans.user.phone') }} <b class="text-danger">*</b></label>
                        <input type="text" class="form-control" required name="phone"
                            value="{{ old('phone', $user->phone) }}" placeholder="{{ __('trans.user.phone') }}"
                            id="phone" />
                    </div>


                    <div class="col-md-4 mb-3">
                        <label class="form-label">{{ __('trans.user.gender') }} <b class="text-danger">*</b></label>
                        <select name="gender" class="form-select">
                            <option value="male" @selected(old('gender', $user->gender) == 'male')>{{ __('trans.male') }}</option>
                            <option value="female" @selected(old('gender', $user->gender) == 'female')>{{ __('trans.female') }}</option>
                            <option value="other" @selected(old('gender', $user->gender) == 'other')>{{ __('trans.other') }}</option>
                        </select>
                    </div>


                    <div class="col-md-4 mb-3">
                        <label class="form-label">{{ __('trans.user.device_id') }}</label>
                        <input type="text" class="form-control" name="device_id"
                            value="{{ old('device_id', $user->device_id) }}"
                            placeholder="{{ __('trans.user.device_id') }}" />
                    </div>


                    <div class="col-md-4 mb-3">
                        <label class="form-label">{{ __('trans.user.device_type') }}</label>
                        <select name="device_type" class="form-select">
                            <option value="ios" @selected(old('device_type', $user->device_type) == 'ios')>{{ __('trans.ios') }}</option>
                            <option value="apk" @selected(old('device_type', $user->device_type) == 'apk')>{{ __('trans.apk') }}</option>
                        </select>
                    </div>


                    {{-- <div class="col-md-4 mb-3">
                        <label class="form-label">{{ __('trans.user.notification_id') }} <b
                                class="text-danger">*</b></label>
                        <input type="text" class="form-control" required name="notification_id"
                            value="{{ old('notification_id', $user->notification_id) }}"
                            placeholder="{{ __('trans.user.notification_id') }}" />
                    </div> --}}


                    <div class="col-md-4 mb-3">
                        <label class="form-label">{{ __('trans.user.allow_any_device') }} <b
                                class="text-danger">*</b></label>
                        <select name="allow_any_device" class="form-select">
                            <option value="1" @selected(old('allow_any_device', $user->allow_any_device) == '1')>{{ __('trans.yes') }}</option>
                            <option value="0" @selected(old('allow_any_device', $user->allow_any_device) == '0')>{{ __('trans.no') }}</option>
                        </select>
                    </div>


                    <div class="col-md-4 mb-3">
                        <label class="form-label">{{ __('trans.user.is_block') }} <b class="text-danger">*</b></label>
                        <select name="is_block" class="form-select">
                            <option value="0" @selected(old('is_block', $user->is_block) == '0')>{{ __('trans.no') }}</option>
                            <option value="1" @selected(old('is_block', $user->is_block) == '1')>{{ __('trans.yes') }}</option>
                        </select>
                    </div>


                    <div class="col-md-4 mb-3">
                        <label class="form-label">{{ __('trans.user.allow_notifications') }} <b
                                class="text-danger">*</b></label>
                        <select name="allow_notifications" class="form-select">
                            <option value="0" @selected(old('allow_notifications', $user->allow_notifications) == '0')>{{ __('trans.no') }}</option>
                            <option value="1" @selected(old('allow_notifications', $user->allow_notifications) == '1')>{{ __('trans.yes') }}</option>
                        </select>
                    </div>


                    <div class="col-md-12 mb-3">
                        <label class="form-label">{{ __('trans.user.is_block_message') }}</label>
                        <textarea name="is_block_message" class="form-control" rows="1"
                            placeholder="{{ __('trans.user.is_block_message') }}">{{ old('is_block_message', $user->is_block_message) }}</textarea>
                    </div>


                    <div class="col-md-4 mb-3">

                        <div class="input-group">
                            <label>{{ __('trans.user.img') }}</label>

                            <div class="input-group">
                                <span class="input-group-btn">
                                    <a id="lfm" data-input="thumbnail" data-preview="holder"
                                        class="UploadFile btn btn-primary">
                                        <i class="fa fa-picture-o"></i> {{ __('trans.choose') }}
                                    </a>
                                </span>
                                <input id="thumbnail" class="form-control" type="text" name="img"
                                    value="{{ old('img', $user->img) }}">
                            </div>
                        </div>

                        <div id="holder" style="margin-top:15px;max-height:100px;">
                            @if (!empty(old('img', $user->img)))
                                <img src="{{ old('img', $user->img) }}" style="height: 5rem;">
                            @endif
                        </div>
                    </div>


                    <div class="row">
                        <div class="col-md-12">
                            <button class="btn btn-primary btn-create w-100">{{ __('trans.save') }}</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
@endsection


@section('css')
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/intl-tel-input@25.3.1/build/css/intlTelInput.css">
    <style>
        .iti {
            display: block;
        }

        .iti__search-input {
            height: 38px;
            margin: 0;
            padding: 6px 12px;
            border-radius: 3px;
            color: inherit;
        }
    </style>
@endsection


@section('js')
    <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@25.3.1/build/js/intlTelInput.min.js"></script>

       <script>
        const input = document.querySelector("#phone");
        window.intlTelInput(input, {
            loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@25.3.1/build/js/utils.js"),

            hiddenInput: (telInputName) => ({
                phone: "phone_full",
                country: "country_code"
            }),

            initialCountry: "auto",
            geoIpLookup: (success, failure) => {
                fetch("https://ipapi.co/json")
                    .then((res) => res.json())
                    .then((data) => success(data.country_code))
                    .catch(() => failure());
            }
        });
    </script>

@endsection
