@extends('web.layouts.layout')
@section('content')

    <main>
        <!-- Start section -->
        @include('web.layouts.header')

            <section class="cart_pg section">
            <div class="container">
                <form method="post" action="{{route('checkouting.location')}}" onsubmit="formAction(this)">
                    @CSRF
                    <h2 class="sec_title text-uppercase color-primary fw-bold mb-5">
                        {{ __('web.location_details') }}
                        <img src="{{url('')}}/assets/web/images/title_line.svg" class="d-block " alt="">
                    </h2>
                    <div class="row">
                        <div class="col-lg-9">
                            <div class="inner">
                                <div class="location-options">
                                    <div class="row">
                                        <div class="col-lg-3">
                                            <div class="form-check mb-4">
                                                <input class="form-check-input"  type="radio" name="status" value="previous"  id="locationType1">
                                                <label class="form-check-label" for="locationType1"> {{ __('web.previous_location') }}   </label>
                                            </div>
                                        </div>
                                        <div class="col-lg-3">
                                            <div class="form-check mb-4">
                                                <input class="form-check-input" type="radio" name="status" value="new"  id="locationType2" checked>
                                                <label class="form-check-label" for="locationType2"> {{ __('web.new_location') }}    </label>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="oldLocation-form mt-4" id="oldLocation-form">
                                        <div class="form-group">
                                            <select name="location_id" class="form-control form-select">
                                                <option value=""> {{__('web.select')}} </option>
                                                @foreach($locations as $row)
                                                    <option value="{{$row->id}}"> {{$row->address}} </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>

                                    <div class="location-form newLocation-form mt-4" id="newLocation-form">
                                        <div class="row">
                                            @if($status == 'visitor')
                                                <div class="col-md-12">
                                                    <div class="form-group mb-4">
                                                        <input type="text" name="name" value="{{$user->name}}" class="form-control" placeholder="{{ __('web.name') }}">
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group mb-4">
                                                        <input type="email" name="email" value="{{$user->email}}" class="form-control" placeholder="{{ __('web.email') }}">
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group mb-4">
                                                        <input type="number" name="phone" value="{{$user->phone}}" class="form-control" placeholder="{{ __('web.phone') }}">
                                                    </div>
                                                </div>
                                            @endif
                                            <div class="col-md-6">
                                                <div class="form-group mb-4">
                                                    <select name="country_id" onchange="fetchCities(this)" target-id="city_id" class="form-control form-select">
                                                        <option selected value="" disabled>{{ __('web.country') }}</option>
                                                        @foreach($countries as $row)
                                                            <option value="{{$row->id}}">{{$row->name}}</option>
                                                        @endforeach
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group mb-4">
                                                    <select name="city_id" id="city_id" class="form-control form-select">
                                                        <option selected disabled>{{ __('web.city') }}</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <div class="form-group mb-4">
                                                    <textarea rows="6" name="address" class="form-control" placeholder="{{ __('web.location_details') }}" ></textarea>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                            <div class="in-flex mt-5 flex-wrap" >
                                <a href="{{route('product.carts')}}" class="butn white_butn fw-bold">
                                    <i class="fas fa-angle-left me-3"></i>  {{ __('web.back') }}
                                </a>

                                <button type="submit" class="butn primary_butn fw-bold">
                                    {{ __('web.continue') }} <i class="fas fa-angle-right ms-3"></i>
                                </button>
                            </div>
                        </div>
                        <div class="col-lg-3 order_sm_1">
                        </div>
                    </div>
                </form>
            </div>
        </section>

        <!-- Start section -->
        @include('web.layouts.newsletter')
    </main>

@section('inject_js')
    <script>
        $("#oldLocation-form").hide();
        // $("#newLocation-form").hide();

        $('input[type="radio"]').click(function() {
            if ($(this).attr("value") == "new") {
                $("#newLocation-form").show();
                $("#oldLocation-form").hide();
            }  else if ($(this).attr("value") == "previous") {
                $("#oldLocation-form").show();
                $("#newLocation-form").hide();
            }
        });
    </script>
@endsection

@stop
