@extends('tablar::page')

@section('content')
<div class="page-header d-print-none">
    <div class="container-xl">
        <div class="row g-2 align-items-center">
            <div class="col">
                <h2 class="page-title">Edit Winner</h2>
            </div>
        </div>
    </div>
</div>
<div class="page-body">
    <div class="container-xl">
        <div class="card">
            <div class="card-body">
                @if($winner)
                <form method="POST" action="/editwinners" class="row g-3">
                    {{ csrf_field() }}
                    <input type="hidden" name="winid" value="{{ $winner->idwinning_bids }}">
                    
                    <div class="col-md-6">
                        <label for="winnerbiddernum" class="form-label">Bidder</label>
                        <select name="winnerbiddernum" id="winnerbiddernum" class="form-select" required>
                            @foreach($bidders as $bidder)
                                <option value="{{ $bidder->idbidders }}" {{ $winner->winning_bidder_num == $bidder->idbidders ? 'selected' : '' }}>
                                    {{ $bidder->bidder_assigned_number }} - {{ $bidder->bidder_fname }} {{ $bidder->bidder_lname }}
                                </option>
                            @endforeach
                        </select>
                    </div>

                    <div class="col-md-6">
                        <label for="winneritemnum" class="form-label">Item</label>
                        <select name="winneritemnum" id="winneritemnum" class="form-select" required>
                            @foreach($items as $item)
                                <option value="{{ $item->iditems }}" {{ $winner->winning_item_num == $item->iditems ? 'selected' : '' }}>
                                    {{ $item->item_assigned_num }} - {{ $item->item_desc }}
                                </option>
                            @endforeach
                        </select>
                    </div>

                    <div class="col-md-4">
                        <label for="winnerbid" class="form-label">Winning Amount</label>
                        <input type="text" name="winnerbid" id="winnerbid" class="form-control" value="{{ $winner->winning_cost }}" required>
                    </div>

                    <div class="col-12">
                        <button type="submit" class="btn btn-primary">Update Winner</button>
                        <a href="/winnersbyitem" class="btn btn-link">Cancel</a>
                    </div>
                </form>
                @else
                    <div class="alert alert-danger">
                        Winner not found. <a href="/winnersbyitem">Back to list</a>
                    </div>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection
@include('components.tomselect')
@push('js')
@endpush
