@extends('layouts.app')

@section('title', '')

@section('content')
<div class="container-fluid">
    <h3 class="mb-4 text-dark">Tambah Detail Penjualan Baru</h3>

    {{-- Pesan error --}}
    @if ($errors->any())
        <div class="alert alert-danger">
            <ul class="mb-0">
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <form action="{{ route('detailpenjualan.store') }}" method="POST" 
          class="card p-4 shadow-sm" style="border-color: #f8bbd0;"> {{-- border card pink --}}
        @csrf

        {{-- Penjualan --}}
        <div class="mb-3">
            <label for="penjualan_id" class="form-label">Penjualan</label>
            <select name="penjualan_id" id="penjualan_id" class="form-select" style="border-color: #f8bbd0;" required>
                <option value="">-- Pilih Penjualan --</option>
                @foreach($penjualans as $penjualan)
                    <option value="{{ $penjualan->penjualan_id }}" 
                        {{ old('penjualan_id') == $penjualan->penjualan_id ? 'selected' : '' }}>
                        {{ $penjualan->penjualan_id }} - {{ $penjualan->tanggal_penjualan }}
                    </option>
                @endforeach
            </select>
        </div>

        {{-- Produk --}}
        <div class="mb-3">
            <label for="produk_id" class="form-label">Produk</label>
            <select name="produk_id" id="produk_id" class="form-select" style="border-color: #f8bbd0;" required>
                <option value="">-- Pilih Produk --</option>
                @foreach($products as $product)
                    <option value="{{ $product->produk_id }}" 
                        {{ old('produk_id') == $product->produk_id ? 'selected' : '' }}>
                        {{ $product->nama_produk }}
                    </option>
                @endforeach
            </select>
        </div>

        {{-- Jumlah Produk --}}
        <div class="mb-3">
            <label for="jumlah_produk" class="form-label">Jumlah Produk</label>
            <input type="number" name="jumlah_produk" id="jumlah_produk" 
                   class="form-control" style="border-color: #f8bbd0;"
                   min="1" value="{{ old('jumlah_produk') }}" required>
        </div>

        {{-- Subtotal --}}
        <div class="mb-3">
            <label for="sub_total" class="form-label">Subtotal</label>
            <input type="number" step="0.01" name="sub_total" id="sub_total" 
                   class="form-control" style="border-color: #f8bbd0;"
                   min="0" value="{{ old('sub_total') }}" required>
        </div>

        <div class="d-flex gap-2">
            <button type="submit" class="btn" style="background-color: #ff69b4; color: white;">Simpan</button>
            <a href="{{ route('detailpenjualan.index') }}" class="btn btn-secondary">Kembali</a>
        </div>
    </form>
</div>
@endsection
