@extends('layouts.app')
@section('title','Registrasi')
@section('content')
    <section class="section">
        <div class="section-header">
        <h1>Registrasi</h1>
        <div class="section-header-breadcrumb">
        </div>
        </div>

        <form class="needs-validation" novalidate="" method="POST" action="{{ route('user.preview')}}" enctype="multipart/form-data">
        <div class="section-body">
            @csrf
            <div class="row">
                <div class="col-12 col-md-8 col-lg-8">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12 form-group" @if ($errors->has('nama')) has-error @endif>
                                    <label>Nama</label>
                                    <input type="text" id="nama" name="nama" class="form-control" required="" placeholder="" value="{{ old('nama')}}">
                                    @if ($errors->has('nama'))
                                        <label id="login-error" class="error" for="nama" style="color: red">{{$errors->first('nama')}}</label>
                                    @endif
                                </div>
                            </div>
                                <div class="row">
                                    <div class="col-6 form-group" @if ($errors->has('email')) has-error @endif>
                                        <label>E-mail</label>
                                        <div class="input-group">
                                            <div class="input-group-prepend">
                                                <div class="input-group-text">
                                                    <i class="fas fa-envelope"></i>
                                                </div>
                                            </div>
                                            <input type="email" id="email" name="email" class="form-control email" required="" placeholder="" value="{{ old('email')}}">
                                        </div>
                                        @if ($errors->has('email'))
                                            <label id="login-error" class="error" for="nama_depan" style="color: red">{{$errors->first('email')}}</label>
                                        @endif
                                    </div>
                                    <div class="col-6 form-group" @if ($errors->has('telepon')) has-error @endif>
                                        <label>Telepon</label>
                                        <div class="input-group">
                                            <div class="input-group-prepend">
                                                <div class="input-group-text">
                                                    <i class="fas fa-phone"></i>
                                                </div>
                                            </div>
                                            <input type="number" id="telepon" name="telepon" class="form-control number" required="true" placeholder="" value="{{ old('telepon')}}">
                                        </div>
                                        @if ($errors->has('telepon'))
                                            <label id="login-error" class="error" for="telepon" style="color: red">{{$errors->first('telepon')}}</label>
                                        @endif
                                    </div>
                            </div>
                            <div class="form-group" @if ($errors->has('instansi')) has-error @endif>
                                <label>Instansi</label>
                                    <div class="input-group">
                                        <input type="text" id="instansi" name="instansi" class="form-control number" required="true" placeholder="" value="{{ old('instansi')}}">
                                    </div>
                                    @if ($errors->has('instansi'))
                                        <label id="login-error" class="error" for="instansi" style="color: red">{{$errors->first('instansi')}}</label>
                                    @endif
                            </div>
                            <div class="form-group" @if ($errors->has('jabatan')) has-error @endif>
                                <label>Jabatan</label>
                                    <div class="input-group">
                                        <input type="text" id="jabatan" name="jabatan" class="form-control email" required="true" placeholder="" value="{{ old('jabatan')}}">
                                    </div>
                                    @if ($errors->has('jabatan'))
                                        <label id="login-error" class="error" for="jabatan" style="color: red">{{$errors->first('jabatan')}}</label>
                                    @endif
                            </div>
                            <div class="row">
                                <div class="col-8 form-group" @if ($errors->has('alamat')) has-error @endif>
                                    <label>Alamat</label>
                                    <div class="input-group">
                                        <input type="text" id="alamat" name="alamat" class="form-control" required="true" placeholder="" value="{{ old('alamat')}}">
                                        {{-- <div class="invalid-feedback">Mohon isikan alamat lengkap Anda</div> --}}
                                    </div>
                                    @if ($errors->has('alamat'))
                                        <label id="login-error" class="error" for="alamat" style="color: red">{{$errors->first('alamat')}}</label>
                                    @endif
                                </div>
                                <div class="form-group" @if ($errors->has('kodepos')) has-error @endif>
                                    <label>Kode Pos</label>
                                    <input type="number" id="kodepos" name="kodepos" class="form-control number" required="true" placeholder="" value="{{ old('kodepos')}}">
                                    @if ($errors->has('kodepos'))
                                        <label id="login-error" class="error" for="kodepos" style="color: red">{{$errors->first('kodepos')}}</label>
                                    @endif
                                    {{-- <div class="invalid-feedback">Isikan Kode Pos yg sesuai</div> --}}
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-12">
                                    <div class="form-group" @if ($errors->has('kota')) has-error @endif>
                                        <label>Kota</label>
                                        <input type="text" id="kota" name="kota" class="form-control" required="" placeholder="" value="{{ old('kota')}}">
                                        @if ($errors->has('kota'))
                                            <label id="login-error" class="error" for="kota" style="color: red">{{$errors->first('kota')}}</label>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="col-12 col-md-4 col-lg-4">
                    <div class="row" id="parent-kegiatan">
                        {{ view('form_kegiatan', [
                            'kegiatan' => $kegiatan,
                            'konferensi' => $konferensi,
                            'i' => 0
                        ]) }}
                    </div>
                    <div>
                        <button type="button" class="btn btn-primary" onclick="tambahKegiatan()" name="tambah-kegiatan" id="tambah-kegiatan">Tambah kegiatan</button>
                    </div>
                    <hr>
                    <div class="card">
                        {{-- <div class="card-body">
                            <div class="form-group" @if ($errors->has('kode_registrasi')) has-error @endif>
                                <label>Kode Registrasi</label>
                                <input type="text" id="kode_registrasi" name="kode_registrasi" class="form-control number" required="true" placeholder="" value="{{ $kode_registrasi }}">
                                @if ($errors->has('kode_registrasi'))
                                    <label id="login-error" class="error" for="kode_registrasi" style="color: red">{{$errors->first('kode_registrasi')}}</label>
                                @endif
                            </div>
                            <div class="form-group" @if ($errors->has('biaya')) has-error @endif>
                                <label>Biaya Pendaftaran</label>
                                <input type="text" id="biaya" name="biaya" class="form-control number" required="true" placeholder="" value="{{ old('biaya')}}" disabled>
                                @if ($errors->has('biaya'))
                                    <label id="login-error" class="error" for="biaya" style="color: red">{{$errors->first('biaya')}}</label>
                                @endif
                            </div>
                        </div> --}}
                    </div>
                </div>
            </div>
            <div class="card-footer text-right">
                <button class="btn btn-primary mr-1" type="submit">Daftar</button>
                <button class="btn btn-secondary" type="reset">Reset</button>
            </div>
        </div>
        </form>
    </section>
@endsection

@push('js')
    <script>
        function cekKegiatan(id){
            var value = document.getElementById(id).value;
            if(value == '498633a9-082c-4a4a-9dbd-e20b678ec15e'){
                $('#grup-konferensi').hide();
                $('#tambah-kegiatan').hide();
                var konferensi = document.getElementById("konferensi");
                konferensi.required = false;
            } else {
                $('#grup-konferensi').show();
                $('#tambah-kegiatan').show();
                var konferensi = document.getElementById("konferensi");
                konferensi.required = true;
            }
        }

    </script>

    <script>
        var i = 1;
        function tambahKegiatan(){
            let token = '{{ csrf_token() }}';

            if (i === undefined) {
                i = 1;
            }

            var request = $.ajax({
                url: '{{ route('registrasi.form-kegiatan.add') }}',
                type:'POST',
                dataType: 'html',
                data: {_token:token, i:i},
                success: function (result) {
                    $('#parent-kegiatan').append(result);
                },

                error: function(error) {
                    alert('periksa koneksi anda');
                }
            });

            i++;
        }

        function hapusKegiatan(id){
            $('#'+id).remove();
        }

        }
    </script>
@endpush
