@extends('layout.app')


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

        <form action="{{ route('pop.store') }}" method="POST" id="form">

            @csrf

            <div class="row">



                    <div class="form-group col-md-4">
                        <label for="popname" class="block text-sm font-medium text-gray-700">
                            POP Name*
                        </label>
                        <input type="text" name="popname" id="popname" value="{{old('popname')}}" class="form-control"
                            placeholder="Pop/Zone Name" autocomplete="off" autofocus required>
                        @error('popname')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror
                    </div>
                    <div class="form-group col-md-4">
                        <label for="reseller_id" class="block text-sm font-medium text-gray-700">
                            Manager Name*
                        </label>

                        <select name="reseller_id" id="reseller" class="select2 form-control" required>
                            <option value="">Select Reseller</option>
                            @foreach ($resellers as $reseller)

                            <option class="p-5" data-reseller_type="{{$reseller->reseller_type}}" value="{{ $reseller->id }}">{{ $reseller->name }}</option>

                            @endforeach

                        </select>

                        @error('reseller_id')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror
                    </div>
                    <div class="form-group col-md-4">
                        <label for="pop_location" class="block text-sm font-medium text-gray-700">
                            POP Location*
                        </label>
                        <input type="text" name="pop_location" id="pop_location" class="form-control"
                            placeholder="pop_location" value="{{old('pop_location')}}" autocomplete="off" required>
                        @error('pop_location')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror

                    </div>
                    <div class="form-group col-md-4">
                        <label for="pop_contact" class="block text-sm font-medium text-gray-700">
                            POP Contact*
                        </label>

                        <input type="text" name="pop_contact" id="pop_contact" class="form-control"
                            placeholder="pop_contact" value="{{old('pop_contact')}}" autocomplete="off" required>

                        @error('pop_contact')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror

                    </div>
                    <div class="form-group col-md-4">
                        <label for="nas_id" class="block text-sm font-medium text-gray-700">
                            Mikrotik IP*
                        </label>
                        <select name="nas_id" id="nas_id" class="select2 form-control" required>
                            <option value="">Select Mikrotik Router</option>
                            @foreach ($naslist as $nas)
                            <option class="p-5" value="{{ $nas->id }}">{{ $nas->shortname }} (
                                {{$nas->nasname  }})</option>
                            @endforeach
                        </select>

                        @error('nas_id')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror
                    </div>

                    <div class="form-group col-md-4" style="display: none;">
                        <label for="bill_generate" class="block text-sm font-medium text-gray-700">
                            Customer Bill Generate
                        </label>

                        <select name="bill_generate" id="bill_generate" class="form-control" required disabled>
                            <option value="">Select Bill Generate</option>
                            <option value="no">No</option>
                            <option value="yes">Yes</option>
                        </select>
                        <input type="hidden" id="bill_generate_value" name="bill_generate_value">

                        @error('bill_generate')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror
                    </div>


                    <div class="form-group col-md-4 d-none">
                        <label for="server_authentication" class="block text-sm font-medium text-gray-700">
                            Server Authentication
                        </label>
                        <select name="server_authentication" id="server_authentication" class="select2 form-control">
                            <option value="yes" selected>Yes</option>
                            <option value="no">No</option>


                        </select>

                        @error('server_authentication')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror

                    </div>
                    <div class="form-group col-md-4">
                        <label for="longitude" class="block text-sm font-medium text-gray-700">
                            Longitude*
                        </label>
                        <input type="text" name="longitude" id="longitude" class="form-control" placeholder="longitude"
                            value="{{ old('longitude', 'YY') }}" autocomplete="off" required>

                        @error('longitude')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror
                    </div>
                    <div class="form-group col-md-4">
                        <label for="latitude" class="block text-sm font-medium text-gray-700">
                            Latitude*
                        </label>
                        <input type="text" name="latitude" id="latitude" class="form-control" placeholder="Latitude"
                            value="{{ old('latitude', 'XX') }}" autocomplete="off" required>

                        @error('latitude')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror
                    </div>
                    <div class="form-group col-md-4 d-none">
                        <label for="billable" class="block text-sm font-medium text-gray-700">
                            Billable
                        </label>
                        <select name="billable" id="billable" class="select2 form-control">
                            <option value="no">No</option>
                            <option value="yes" selected>Yes</option>
                        </select>

                        @error('billable')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror
                    </div>
                    <div class="form-group col-md-4">
                        <label for="subreseller" class="block text-sm font-medium text-gray-700">
                            Sub Manager
                        </label>
                        <select name="subreseller" id="subreseller" class="select2 form-control">
                            <option value="no">No</option>
                            <option value="yes">Yes</option>

                        </select>

                        @error('subreseller')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror
                    </div>

                    @can('set-pop-commission')
                        <div class="form-group col-md-4">
                            <label for="remark" class="block text-sm font-medium text-gray-700">
                                Sub Manager Miscellaneous Expense
                            </label>
                            <div class=" flex rounded-md shadow-sm">

                            <input type="number" step=".01" name="commission_percentage" id="commission_percentage" class="form-control" placeholder="Commission in percentage"
                                    value="{{ old('commission_percentage') }}" autocomplete="off">
                            </div>
                            @error('commission_percentage')
                                <div class="alert alert-dangers">
                                    {{ $message }}
                                </div>
                            @enderror
                        </div>
                    @endcan

                    <div class="form-group d-none">
                        <label for="package_change_pricing" class="block text-sm font-medium text-gray-700">
                            Package Change Pricing
                        </label>
                        <select name="package_change_pricing" id="package_change_pricing"
                            class="w-full p-2 bg-white border">
                            <option value="full_month">Full Month</option>
                            <option value="day_by_day">Day By Day</option>

                        </select>

                        @error('package_change_pricing')
                        <div class="text-red-500 mt-2 text-sm">
                            {{$message}}
                        </div>
                        @enderror
                    </div>

                    @if(checkSettings('pop-online-recharge') == 'enable')
                        <div class="form-group col-md-4">
                            <label for="payment_charges">Gateway Charges In %</label>

                            <table class="table table-responsive table-condensed">
                                <tr>
                                    <td>Bkash</td>
                                    <td>
                                        <input type="number" step="any" name="bkash_charges" id="bkash_charges" class="form-control"
                                            placeholder="Bkash Charges" value="{{ old('bkash_charges') }}" autocomplete="off">
                                    </td>
                                </tr>
                                <tr>
                                    <td>Nagad</td>
                                    <td>
                                        <input type="number" step="any" name="nagad_charges" id="nagad_charges" class="form-control"
                                            placeholder="Nagad Charges" value="{{ old('nagad_charges') }}" autocomplete="off">
                                    </td>
                                </tr>
                                <tr>
                                    <td>Upay</td>
                                    <td>
                                        <input type="number" step="any" name="upay_charges" id="upay_charges" class="form-control"
                                            placeholder="Upay Charges" value="{{ old('upay_charges') }}" autocomplete="off">
                                    </td>
                                </tr>
                            </table>
                        </div>
                    @endif



                <div class="col-sm-12">
                    <button type="submit" class="btn btn-primary float-right">
                        Save
                    </button>
                </div>
            </div>


        </form>



    </div>
</div>




@endsection

@section('ajax')

<script>

    $(function(){

        $('#reseller').on('change',function(){
            let reseller = $('#reseller').find(':selected').data('reseller_type');
            console.log(reseller);
            $('#bill_generate').attr('disabled');
            if(reseller === 'own'){
                $('#bill_generate').val('yes');
                $('#bill_generate_value').val('yes');

            }else{
                $('#bill_generate').val('no');
                $('#bill_generate_value').val('no');
            }
        });

    });
</script>


@endsection
