@extends('admin.template')

@section('title', 'Tambah Data TPS')

@section('content')
<div class="content-wrapper">
    <div class="row">
        <div class="col-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">

                    <h4 class="card-title">Tambah Data TPS</h4>
                    <p class="card-description">Form tambah data TPS</p>

                    <form action="{{ route('admin.tps.store') }}" method="POST" enctype="multipart/form-data">
                        @csrf

                        {{-- NAMA TPS --}}
                        <div class="form-group">
                            <label>Nama TPS</label>
                            <input type="text"
                                   name="nama_tps"
                                   class="form-control @error('nama_tps') is-invalid @enderror"
                                   value="{{ old('nama_tps') }}"
                                   placeholder="Nama TPS">

                            @error('nama_tps')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>

                        {{-- ALAMAT --}}
                        <div class="form-group">
                            <label>Alamat</label>
                            <input type="text"
                                   name="alamat_tps"
                                   class="form-control @error('alamat_tps') is-invalid @enderror"
                                   value="{{ old('alamat_tps') }}"
                                   placeholder="Alamat TPS">

                            @error('alamat_tps')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>

                        {{-- KATEGORI --}}
                        <div class="form-group">
                            <label>Kategori TPS</label>
                            <select name="kategori_tps_id"
                                    class="form-control @error('kategori_tps_id') is-invalid @enderror">
                                <option value="">Pilih Kategori</option>
                                @foreach ($kategori as $item)
                                    <option value="{{ $item->id_kategori_tps }}"
                                        {{ old('kategori_tps_id') == $item->id_kategori_tps ? 'selected' : '' }}>
                                        {{ $item->nama_kategori }}
                                    </option>
                                @endforeach
                            </select>

                            @error('kategori_tps_id')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>

                        {{-- TAHUN --}}
                        <div class="form-group">
                            <label>Tahun Pembuatan</label>
                            <input type="number"
                                   name="tahun_pembuatan"
                                   class="form-control @error('tahun_pembuatan') is-invalid @enderror"
                                   value="{{ old('tahun_pembuatan') }}"
                                   placeholder="Contoh: 2022">

                            @error('tahun_pembuatan')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>

                        {{-- KAPASITAS --}}
                        <div class="form-group">
                            <label>Kapasitas</label>
                            <input type="text"
                                   name="kapasitas_tps"
                                   class="form-control @error('kapasitas_tps') is-invalid @enderror"
                                   value="{{ old('kapasitas_tps') }}"
                                   placeholder="Kapasitas TPS">

                            @error('kapasitas_tps')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>

                        {{-- STATUS --}}
                        <div class="form-group">
                            <label>Status</label>
                            <select name="status_tps"
                                    class="form-control @error('status_tps') is-invalid @enderror">
                                <option value="">Pilih Status</option>
                                <option value="Aktif" {{ old('status_tps') == 'Aktif' ? 'selected' : '' }}>Aktif</option>
                                <option value="Tidak Aktif" {{ old('status_tps') == 'Tidak Aktif' ? 'selected' : '' }}>Tidak Aktif</option>
                                <option value="Pembangunan" {{ old('status_tps') == 'Pembangunan' ? 'selected' : '' }}>Pembangunan</option>
                            </select>

                            @error('status_tps')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>

                        {{-- LATITUDE --}}
                        <div class="form-group">
                            <label>Latitude</label>
                            <input type="text"
                                   name="latitude"
                                   class="form-control @error('latitude') is-invalid @enderror"
                                   value="{{ old('latitude') }}"
                                   placeholder="Contoh: -7.623 atau 7°35'17.25&quot;S">

                            @error('latitude')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>

                        {{-- LONGITUDE --}}
                        <div class="form-group">
                            <label>Longitude</label>
                            <input type="text"
                                   name="longitude"
                                   class="form-control @error('longitude') is-invalid @enderror"
                                   value="{{ old('longitude') }}"
                                   placeholder="Contoh: 111.980 atau 111°55'0.97&quot;E">

                            @error('longitude')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>

                        {{-- FOTO --}}
                        <div class="form-group">
                            <label>Foto TPS</label>

                            <input type="file"
                                   name="foto_tps"
                                   id="foto_tps"
                                   class="file-upload-default @error('foto_tps') is-invalid @enderror">

                            <div class="input-group col-xs-12">
                                <input type="text"
                                       class="form-control file-upload-info"
                                       disabled
                                       placeholder="Upload Foto">
                                <span class="input-group-append">
                                    <button class="file-upload-browse btn btn-primary" type="button">
                                        Upload
                                    </button>
                                </span>
                            </div>

                            @error('foto_tps')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>

                        <button type="submit" class="btn btn-primary">Simpan</button>
                        <a href="{{ route('admin.tps.index') }}" class="btn btn-light">Batal</a>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
@endsection
