<form action="{{ request()->category ? url('member/store-new')  : route('member.store') }}" method="POST">
    @csrf
    <div class="form-group row">
        <div class="col-md-6">
            <label>Nama Member</label>
            <input type="text" name="nama" class="form-control @error('nama') is-invalid @enderror"
                placeholder="Nama Member" value="{{ old('nama') }}">
            @error('nama')
                <div class="invalid-feedback">
                    {{ $message }}
                </div>
            @enderror
        </div>
        <div class="col-md-6">
            <label>Email Member</label>
            <input type="email" name="email" class="form-control @error('email') is-invalid @enderror"
                placeholder="Email Member" value="{{ old('email') }}">
            @error('email')
                <div class="invalid-feedback">
                    {{ $message }}
                </div>
            @enderror
        </div>
    </div>
    <div class="form-group row">
        <div class="col-md-6">
            
        <label>No Telepon Member</label>
        <input type="number" name="phone" class="form-control @error('phone') is-invalid @enderror"
            placeholder="No Telepon Member" value="{{ old('phone') }}">
        @error('phone')
            <div class="invalid-feedback">
                {{ $message }}
            </div>
        @enderror
        </div>
        <div class="col-md-6">
            <label for="">Tanggal Lahir</label>
            <div class="input">
                <!--<span class="fa fa-calendar mr-2"></span>-->
                <input type="date" class="form-control @error('tgl_lahir') is-invalid @enderror"
                    id="tgl_lahir" name="tgl_lahir" value="{{ old('tgl_lahir') }}"
                    placeholder="No Telepon">
            </div>
            @error('tgl_lahir')
                <div class="invalid-feedback">
                    {{ $message }}
                </div>
            @enderror
            <br>
        </div>
        <div class="col-md-6">
            <label>Gerai</label>
            <select class="form-control @error('id_branch') is-invalid @enderror" name="id_branch">
                <option value=''>---Pilih Gerai---</option>
                @foreach($branch as $item)
                    <option value='{{$item->id}}' {{old('id_branch') == $item->id ? 'selected' : ''}}>{{$item->cabang}}</option>
                @endforeach
            </select>
            @error('id_branch')
                <div class="invalid-feedback">
                    {{ $message }}
                </div>
            @enderror
        </div>
        <div class="col-md-6">
            <label>Kategori Member</label>
            <select class="select2 form-control @error('category_id') is-invalid @enderror" name="category_id">
                @if(empty($_GET['category']))
                    <option value=''>---Pilih Kategori---</option>
                    @foreach($categories as $item)
                        <option value='{{$item->id}}' {{old('category_id') == $item->id ? 'selected' : ''}}>{{$item->category}} ({{$item->percent}}%)</option>
                    @endforeach
                @else
                    <option value='{{$selectedCategory->id}}'>{{$selectedCategory->category}}</option>
                @endif
            </select>
            @error('category_id')
                <div class="invalid-feedback">
                    {{ $message }}
                </div>
            @enderror
            @if(isset($_GET['category']))
                <input type='hidden' name='is_category' value='{{$_GET['category']}}'>
            @endif
        </div>
    </div>


    <button type="submit" class="btn btn-primary mr-2"><i class="fa fa-save"></i> Simpan</button>
    <button type="reset" class="btn btn-default"><i class="fa fa-times"></i> Reset</button>
</form>
