@extends('layout.app')
@section('content')
    <style>
        .step {
            background: antiquewhite;
            padding: 2%;
            margin: 2% 0;
            border-radius: 2%;
        }
    </style>
    <div class="jumbotron col-8 offset-2 my-4">
        <div class="row">
            <div class="col-lg-12 margin-tb">
                <div class="float-left">
                    <h2>Edit Mapping</h2>
                </div>
                <div class="float-right">
                    <a class="btn btn-primary" href="{{ route('mappings.index') }}" enctype="multipart/form-data">
                        Back</a>
                </div>
            </div>
        </div>

        @if (session('status'))
            <div class="alert alert-success mb-1 mt-1">
                {{ session('status') }}
            </div>
        @endif
        <form action="{{ route('mappings.update', request()->mapping) }}" method="POST">
            @csrf
            @method('PUT')

            <input hidden name="id" value={{ request()->mapping }}>
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12">
                    <div class="form-group">
                        <strong>Type:</strong>
                        <input type="text" name="type" value="{{ $mappings[0]->type }}" class="form-control"
                            placeholder="Type">
                        @error('type')
                            <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
                        @enderror
                    </div>
                </div>
                @foreach ($availablePlatforms as $platform)
                    <div class="col-xs-12 col-sm-12 col-md-12">
                        <h3>{{ ucfirst($platform) }}</h3>
                        @foreach ($mappings as $mapping_platform)
                            <div class="{{ $platform }}">
                                @if ($mapping_platform->platform == $platform)
                                    @foreach ($mapping_platform->steps as $step)
                                        <div class="step">
                                            {{-- <h4><u>{{ 'Step # ' . $step->step }}</u></h4> --}}
                                            <div class="form-group">
                                                <strong>Step #:</strong>
                                                <input type="number" name="{{ $step->platform }}|{{ $step->step }}|step"
                                                    class="form-control" placeholder="Step" value="{{ $step->step }}">
                                                @error('{{ $step->platform }}|{{ $step->step }}|step')
                                                    <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <strong>URL:</strong>
                                                <input type="text" name="{{ $step->platform }}|{{ $step->step }}|url"
                                                    class="form-control" placeholder="URL" value="{{ $step->url }}">
                                                @error('{{ $step->platform }}|{{ $step->step }}|url')
                                                    <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <strong>Method:</strong>
                                                <input type="text"
                                                    name="{{ $step->platform }}|{{ $step->step }}|method"
                                                    value="{{ $step->method }}" class="form-control" placeholder="Method">
                                                @error('{{ $step->platform }}|{{ $step->step }}|method')
                                                    <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <div class="form-check">
                                                    <input class="form-check-input" type="checkbox" value="1"
                                                        id="dependent_check"
                                                        name="{{ $step->platform }}|{{ $step->step }}|dependent" @if($step->dependent==1)checked @endif>
                                                    <label class="form-check-label" for="dependent_check">
                                                        Has dependent parameters
                                                    </label>
                                                </div>
                                            </div>
                                            <div class="form-group dependent_div">
                                                <strong>Dependent Params:</strong>
                                                <input type="text"
                                                    name="{{ $step->platform }}|{{ $step->step }}|dependent_params"
                                                    value="{{ $step->dependent_params }}" class="form-control"
                                                    placeholder="Enter params(comma seperated)">
                                                @error('{{ $step->platform }}|{{ $step->step }}|dependent_params')
                                                    <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <div class="form-check">
                                                    <input class="form-check-input" type="checkbox" value="1"
                                                        id="repetitive_check"
                                                        name="{{ $step->platform }}|{{ $step->step }}|repetitive" @if($step->repetitive==1)checked @endif>
                                                    <label class="form-check-label" for="repetitive_check">
                                                        Has repetitive parameter
                                                    </label>
                                                </div>
                                            </div>
                                            <div class="form-group repetitive_div">
                                                <strong>Repetitive Param:</strong>
                                                <input type="text"
                                                    name="{{ $step->platform }}|{{ $step->step }}|repetitive_params"
                                                    value="{{ $step->repetitive_params }}" class="form-control"
                                                    placeholder="Enter repetitive param">
                                                @error('{{ $step->platform }}|{{ $step->step }}|repetitive_params')
                                                    <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
                                                @enderror
                                            </div>
                                            <div class="form-group">
                                                <strong>Payload (JSON):</strong>
                                                <textarea name="{{ $step->platform }}|{{ $step->step }}|json_payload" class="form-control" placeholder="Payload">{{ $step->json_payload }}</textarea>
                                                @error('json_payload')
                                                    <div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
                                                @enderror
                                            </div>
                                        </div>
                                    @endforeach
                                @endif
                            </div>
                        @endforeach
                @endforeach

                <button type="submit" class="btn btn-primary ml-3">Submit</button>

            </div>

        </form>
    </div>
@endsection
@section('script')
    <script>
        $(document).ready(function() {
            // console.log('ll');
        })
    </script>
@endsection
