@extends('admin.layouts.master')
@section('page_title')
    Profile
@endsection

@push('styles')
    <!--suppress HtmlFormInputWithoutLabel -->
    <link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" />
    <link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" />
    <link rel="stylesheet" href="{{asset('assets/examples/css/pages/profile.min3f0d.css?v2.2.0')}}">
@endpush

@section('page_content')
    <div class="page-content container-fluid">
        <div class="row">

            <div class="col-md-12">
                <div class="panel">
                    <div class="panel-body nav-tabs-animate nav-tabs-horizontal">

                        <form method="post" enctype="multipart/form-data" class="registration lato">
                            @if(session('success'))
                                <div class="alert alert-success">
                                    <ul>
                                        <li>{{ session('success') }}</li>
                                    </ul>
                                </div>
                            @endif

                            @csrf
                            <div class="row">
                                <div class="col-md-12 text-center">
                                    <h3><em>Company / Individual Registration</em></h3>
                                    <hr>
                                </div>
                                <div class="col-md-12 text-center">
                                    <a id="terms" class="btn btn-sm" style="background-color: #CC0000; color: white"><i class="fa"></i> TERMS & CONDITIONS</a>
                                </div>

                            </div>

                            <hr>

                            <div class="form-group col-md-12 text-center {{ $errors->has('register_as') ? ' has-error' : '' }}">
                                <label for="inputEmail4"><strong>Register As</strong> <em
                                        class="text-danger">*</em></label>
                                <div class="row">
                                    <div class="col-md-4 col-md-offset-4">
                                        @php $var = old('register_as',$company->users->role_id) @endphp
                                        <select class="form-control " required name="register_as">
                                            <option></option>
                                            <option value="user" {{$var == 2 ? 'selected' : ''}}>Client</option>
                                            <option value="reseller" {{$var == 3 ? 'selected' : ''}}>Reseller</option>
                                        </select>
                                        @if ($errors->has('register_as'))
                                            <span class="text-danger help-block">
                                        		<strong>{{ $errors->first('register_as') }} </strong>
                                    		</span>
                                        @endif
                                    </div>
                                </div>
                            </div>

                            <div class="row">

                                <div class="form-group col-md-6 {{ $errors->has('name') ? 'has-error' : '' }}">
                                    <label for="inputEmail4">Name Of Company / Individual <em class="text-danger">*</em></label>
                                    <input type="text" class="form-control" value="{{old('name',$company->name)}}" name="name"
                                           placeholder="" required>
                                    @if ($errors->has('name'))
                                        <strong class="text-danger">{{ $errors->first('name') }} </strong>
                                    @endif
                                </div>

                                <div class="form-group {{ $errors->has('nature_of_business') ? 'has-error' : '' }} col-md-6">
                                    <label for="inputAddress">Nature Of Business <em class="text-danger"></em></label>
                                    <input type="text" class="form-control" value="{{old('nature_of_business',$company->nature_of_business)}}" name="nature_of_business" placeholder="nature of business">

                                    @if ($errors->has('nature_of_business'))
                                        <strong class="text-danger">{{ $errors->first('nature_of_business') }} </strong>
                                    @endif
                                </div>

                                <div class="form-group {{ $errors->has('physical_address') ? 'has-error' : '' }} col-md-6">
                                    <label for="inputCity">Business Location <em class="text-danger"></em></label>
                                    <input type="text" class="form-control" value="{{old('physical_address',$company->physical_address)}}"
                                           name="physical_address" placeholder="Location, Region" required>
                                    @if ($errors->has('physical_address'))
                                        <strong class="text-danger">{{ $errors->first('physical_address') }} </strong>
                                    @endif
                                </div>

                                <div class="form-group {{ $errors->has('company_phone_number') ? 'has-error' : '' }} col-md-6">
                                    <label for="inputState">Company / Individual Phone number <em class="text-danger"></em></label>
                                    <input type="text" class="form-control company-phone" name="company_phone_number" value="{{old('company_phone_number',$company->company_phone_number)}}" placeholder="Registered MTN, AIRTELTIGO, VODAFONE, GLO">
                                    <span class="text-danger" id="mm-phone"><em></em></span>
                                    <span class="badge badge-danger company-alert"></span>
                                    @if ($errors->has('company_phone_number'))
                                        <strong class="text-danger">{{ $errors->first('company_phone_number') }} </strong>
                                    @endif
                                </div>

                                <div class="form-group {{ $errors->has('mobile_money_number') ? 'has-error' : '' }} col-md-6">
                                    <label for="mobile_money_number">Mobile Money Number <em class="text-danger"></em></label>
                                    <input id="mobile_money_number" type="text" class="form-control " name="mobile_money_number" value="{{old('mobile_money_number',$company->mobile_money_number)}}" placeholder="Mobile Money Number" required>
                                    <span class="text-danger" id="mm-phone"><small>(Credit purchase can be done on this number or changed upon credit purchasing)</small></span>

                                    @if ($errors->has('mobile_money_number'))
                                        <strong class="text-danger">{{ $errors->first('mobile_money_number') }} </strong>
                                    @endif
                                </div>

                                <hr>

                                <div class="form-group {{ $errors->has('business_logo') ? 'has-error' : '' }} col-md-6">
                                    <label for="mobile_money_number">Business Registration Logo <em class="text-danger"></em></label>
                                    <input type="file"  accept="image/*"  class="form-control " name="business_logo" value="{{old('business_logo')}}">
                                    <a class="btn btn-sm" href="{{asset("storage/business_logo/$company->business_logo")}}">{{$company->business_logo}}</a>

                                    @if ($errors->has('business_logo'))
                                        <strong class="text-danger">{{ $errors->first('business_logo') }} </strong>
                                    @endif
                                </div>

                            </div>

                            <div class="row">
                                <div class="form-group {{ $errors->has('username') ? 'has-error' : '' }} col-md-6">
                                    <label for="username">Preferred Username <em class="text-danger">*</em></label>
                                    <input type="text" class="form-control" id="username" name="username" value="{{old('username',$company->users->username)}}">
                                    @if ($errors->has('username'))
                                        <strong class="text-danger">{{ $errors->first('username') }} </strong>
                                    @else
                                        <h4 class="" id="user"></h4>
                                    @endif
                                </div>
                            </div>

                            <hr>

                            <h4>Contact Person Information <em class="text-danger">*</em></h4>
                            <hr>

                            <div class="row">
                                <div class="form-group {{ $errors->has('contact_person') ? 'has-error' : '' }} col-md-6">
                                    <label for="inputState">Name <em class="text-danger">*</em></label>
                                    <input type="text" class="form-control" value="{{old('contact_person',$company->contact_person)}}"
                                           name="contact_person" placeholder="Contact Person's name" required>

                                    @if ($errors->has('contact_person'))
                                        <strong class="text-danger">{{ $errors->first('contact_person') }} </strong>
                                    @endif
                                </div>

                                <div class="form-group {{ $errors->has('contact_person_email') ? 'has-error' : '' }} col-md-6">
                                    <label for="inputState">Email <em class="text-danger">*</em></label>
                                    <input type="text" class="form-control email" value="{{old('contact_person_email',$company->contact_person_email)}}" name="contact_person_email" placeholder="Contact Person's email" required>
                                    <span class="badge badge-danger email-alert"></span>

                                    @if ($errors->has('contact_person_email'))
                                        <strong class="text-danger">{{ $errors->first('contact_person_email') }} </strong>
                                    @endif
                                </div>
                            </div>
                            <div class="row">

                                <div class="form-group {{ $errors->has('contact_person_phone') ? 'has-error' : '' }} col-md-6">
                                    <label for="inputState">Phone Number <em class="text-danger">*</em></label>
                                    <input type="text" class="form-control" id="contact_person_phone" value="{{old('contact_person_phone',$company->contact_person_phone)}}" name="contact_person_phone"  placeholder="Contact Person's phone" required>
                                    <span class="text-danger"><em>(All OTPs for verification will be sent to this number)</em></span>

                                    @if ($errors->has('contact_person_phone'))
                                        <br/> <strong class="text-danger">{{ $errors->first('contact_person_phone') }} </strong>
                                    @endif
                                </div>


                                <div class="form-group {{ $errors->has('contact_person_id') ? 'has-error' : '' }} col-md-6">
                                    <label for="inputState">ID <em class="text-danger"></em></label>
                                    <input type="file" class="form-control" value="{{old('contact_person_id')}}" name="contact_person_id" placeholder="Contact Person  Id">

                                    @if ($errors->has('contact_person_id'))
                                        <strong class="text-danger">{{ $errors->first('contact_person_id') }} </strong>
                                    @endif
                                </div>
                            </div>

                            <hr>
                            <div class="form-row text-center">
                                <div class="col-md-12">
                                    <button type="submit" class="btn then-submit" style="background-color: #4285F4; color: white"><i class="fa fa-plus-circle"></i> SUBMIT</button>
{{--                                    <a type="submit" class="btn otp-btn" style="background-color: #CC0000; color: white"><i class="fa fa-shield"></i> GET OTP</a>--}}
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@push('scripts')
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>
    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    <script>

        var sends = {!! $sends !!};
        var dirs = {!! $dirs !!};


        $("#directors").jsGrid({
            width: "100%",
            height: "250px",

            inserting: true,
            editing: true,
            sorting: true,
            paging: true,

            data: dirs,

            fields: [
                { name: "name", type: "text", width: 50, validate: "required" },
                { name: "designation", type: "text", width: 50 },
                { type: "control" }
            ]
        });

        $("#sender-ids").jsGrid({
            width: "100%",
            height: "250px",

            inserting: true,
            editing: true,
            sorting: true,
            paging: true,

            data: sends,

            fields: [
                { name: "name", type: "text", width: 50, validate: "required", valueField: "id" },
                { type: "control" }
            ]
        });


        $('.registration').on('submit', function() {
            grid = $("#directors").jsGrid("option", "data");
            grid2 = $("#sender-ids").jsGrid("option", "data");
            $('#items').val(JSON.stringify(grid));
            $('#sender_ids').val(JSON.stringify(grid2));
        });
    </script>
@endpush
