@extends('dashboard.admin.layouts.app')
@section('content')
    <div class="page-container">

        <div class="page-title-head d-flex align-items-sm-center flex-sm-row flex-column gap-2">
            <div class="flex-grow-1">
                <h4 class="fs-18 fw-semibold mb-0">{{ $title }}</h4>
            </div>

            <div class="text-end">
                <x-dashboard.breadcrumbs :breadcrumbs="$breadcrumbs" />
            </div>
        </div>

        <div class="row">
            <x-dashboard.card title="{{ $title }}" :button="[
                'route' => route('admin.trader.performance.index', $trader->uuid),
                'text' => 'Back',
                'icon' => 'fa fa-arrow-left me-1',
            ]">

                <form action="{{ route('admin.trader.performance.update', [$trader->uuid, $traderPerformance->uuid]) }}"
                    method="post">
                    @csrf
                    @method('PUT')

                    <div class="row">
                        <!-- Trader -->
                        <div class="col-md-12 mb-3">
                            <label for="trader_id" class="form-label fw-semibold">Select Trader</label>
                            <select name="trader_id" id="trader_id" required
                                class="form-select @error('trader_id') is-invalid @enderror">
                                <option value="">Select</option>
                                @foreach ($traders as $trader)
                                    <option value="{{ $trader->id }}"
                                        {{ old('trader_id', $traderPerformance->trader_id) == $trader->id ? 'selected' : '' }}>
                                        {{ $trader->user->name }}</option>
                                @endforeach
                            </select>
                            @error('trader_id')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <!-- Direction -->
                        <div class="col-md-12 mb-3">
                            <label for="direction" class="form-label fw-semibold">Select Direction</label>
                            <select name="direction" id="direction" required
                                class="form-select @error('direction') is-invalid @enderror">
                                <option value="">Select</option>
                                @foreach ($traderPerformanceDirections as $direction)
                                    <option value="{{ $direction->value }}"
                                        {{ old('direction', $traderPerformance->direction->value) == $direction->value ? 'selected' : '' }}>
                                        {{ $direction->label() }}</option>
                                @endforeach
                            </select>
                            @error('direction')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <!-- ROI Percentage -->
                        <x-dashboard.form-input name="roi_percentage" label="ROI Percentage" class="col-md-12 mb-3"
                            value="{{ old('roi_percentage', $traderPerformance->roi_percentage) }}" required />

                        <!-- Recorded At -->
                        <x-dashboard.form-input name="recorded_at" label="Recorded At" class="col-md-12 mb-3" type="date"
                            value="{{ old('recorded_at', date('Y-m-d', strtotime($traderPerformance->recorded_at))) }}"
                            required />
                    </div>

                    <x-dashboard.form-button />

                </form>

            </x-dashboard.card>
        </div>

    </div>
@endsection
