@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">Judging Entry</h2>
            </div>
        </div>
    </div>
</div>
<div class="page-body">
    <div class="container-xl">
        <div class="row row-cards">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <form method="POST" action="/judgingentry" class="row g-3">
                            {{ csrf_field() }}
                            <div class="col-md-4">
                                <label for="judge_id" class="form-label">Judge</label>
                                <!-- Temporarily disabling TomSelect with data-no-tomselect -->
                                <select name="judge_id" id="judge_id" class="form-select" data-no-tomselect="true" required>
                                    @foreach($judges as $judge)
                                        <option value="{{ $judge->idjudges }}">{{ $judge->judge_number }}</option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-md-4">
                                <label for="vehicle_id" class="form-label">Vehicle</label>
                                <select name="vehicle_id" id="vehicle_id" class="form-select" data-no-tomselect="true" required>
                                    @foreach($vehicles as $vehicle)
                                        <option value="{{ $vehicle->idvehicles }}">
                                            {{ $vehicle->vehicleOwner->bidder_assigned_number ?? '?' }} - {{ $vehicle->make }} {{ $vehicle->model }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-md-4">
                                <label for="score" class="form-label">Score</label>
                                <input type="number" name="score" id="score" class="form-control" required>
                            </div>
                            <div class="col-12">
                                <button type="submit" class="btn btn-primary">Submit Score</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
@push('js')
<script>
    // Update the tomselect component to ignore elements with data-no-tomselect
    document.addEventListener("DOMContentLoaded", function () {
        document.querySelectorAll('select:not([data-no-tomselect])').forEach((el) => {
            if (el.tomselect) return;
            new TomSelect(el, {
                copyClassesToDropdown: false,
                dropdownParent: 'body',
                controlInput: '<input>',
                sortField: { field: 'text', direction: 'asc' }
            });
        });
    });
</script>
@endpush
