@extends('layouts.main-layout')

@section('title', 'Edit Forecast')
    
@section('content')
<style>
    #submit_btn{
        width: 100%;
        background-color: #008080;
        color: #fff;
    }
</style>
    {{-- <div class="container"> --}}
        {{-- <!--ERROR DISPLAY-->
        <div class="row d-flex justify-content-center mb-5">
            <div class="col-md-8">
                @if ($errors->any())
                <div class="alert alert-danger">
                    @foreach ($errors->all() as $error)
                        <li style="color: #fff">{{$error}}</li>
                    @endforeach
                </div>
            @endif
                @if (Session::has('error'))
                <div class="alert alert-danger">
                    <li style="color: #fff;">{{ Session::get('error') }}</li>
                </div>
            @endif
            @if (Session::has('success'))
                <div class="alert alert-success">
                    <li style="color: #fff;">{{ Session::get('success') }}</li>
                </div>
            @endif
            </div>
        </div>
        <!--END OF ERROR DISPLAY--> --}}
        <div class="row p-2 d-flex justify-content-center align-items-center">
            <div class="col-md-8">
                <div class="card mb-5">
                    <div class="card-body" style="display: flex; flex-direction: column; align-items: center;">
                        <div class="row mb-4">
                            <h3 class="text-muted">Edit Closure Message</h3>
                        </div>
                        <div class="row">
                            <form action="{{ route('closure.message.edit', $closure_message->id) }}"  method="POST">
                             @csrf    
                             <div class="mb-3" style="width: 250px;">
                                     <label class="form-label" for="">Title</label>
                                     <input class="form-control" 
                                     value="{{ $closure_message->title }}" 
                                     type="text" name="title" id="title">
                                 </div>
                                 <div class="mb-3" style="width: 250px;">
                                     <label class="form-label" for="">Message</label>
                                     <textarea class="text-muted" type="text" name="message" id="message" style="width: 250px; resize:none;" rows="8">{{ $closure_message->message }}</textarea>
                                 </div>
                                 <div class="mb-3">
                                    @php
                                        $dateString = $closure_message->schedule; // Replace this with your actual date string
                                        $date = \Carbon\Carbon::parse($dateString)->format('Y-m-d');
                                    @endphp
                                    <label class="form-label" for="">Schedule</label>
                                    <input class="form-control" min="{{ $date }}" value="{{ $date }}" type="date" 
                                    name="schedule" id="schedule" style="width: 250px;">
                                </div>
                                 <div class="mb-3" style="margin-top: 20px;">
                                     <button class="btn" id="submit_btn">Submit</button>
                                 </div>
                             </form> 
                         </div>
                        {{-- <form action="{{ route('forecast.store.edit', $forecast->id) }}" method="POST">
                            @csrf
                            <div class="row mb-3">
                                <div class="col-md-6 col-sm-11 col-xs-12 mb-3">
                                    <label class="form-label" for="">Title</label>
                                    <input class="form-control" type="text" 
                                    value="{{ $forecast->title }}" name="title" id="my_title">
                                </div>
                                <div class="col-md-6 col-sm-11 col-xs-12 mb-3">
                                    <label class="form-label" for="">Banker</label>
                                    <input class="form-control" value="{{ $forecast->banker }}" onkeyup="appendHyphen(event, 'my_banker')" type="text" name="banker" id="my_banker">
                                </div>
                            </div>
                            <div class="row mb-3">
                                <div class="col-md-6 col-sm-11 col-xs-12 mb-3">
                                    <label class="form-label" for="">Two Sure</label>
                                    <input class="form-control" value="{{ $forecast->two_sure }}" onkeyup="appendHyphen(event, 'my_two_sure')" type="text" name="two_sure" id="my_two_sure">
                                </div>
                                <div class="col-md-6 col-sm-11 col-xs-12 mb-3">
                                    <label class="form-label" for="">Three Direct</label>
                                    <input class="form-control" value="{{ $forecast->three_direct }}" onkeyup="appendHyphen(event, 'my_three_direct')" type="text" name="three_direct" id="my_three_direct">
                                </div>
                            </div>
                            <div class="row mb-3">
                                <div class="col-md-6 col-sm-11 col-xs-12 mb-3">
                                    <label class="form-label" for="">Permutations</label>
                                    <input class="form-control" value="{{ $forecast->permutations }}" onkeyup="appendHyphen(event, 'my_permutations')" type="text" name="permutations" id="my_permutations">
                                </div>
                                <div class="col-md-6 col-sm-11 col-xs-12 mb-3">
                                    @php
                                        $dateString = $forecast->schedule; // Replace this with your actual date string
                                        $date = \Carbon\Carbon::parse($dateString)->format('Y-m-d');
                                    @endphp
                                    <label class="form-label" for="">Schedule</label>
                                    <input class="form-control" min="{{ $date }}" value="{{ $date }}" type="date" name="schedule" id="schedule">
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6 col-sm-11 col-xs-12 mb-3" style="margin-top: 30px;">
                                </div>
                                <div class="col-md-6 col-sm-11 col-xs-12 mb-3" style="margin-top: 20px;">
                                    <button class="btn" id="submit_btn">Submit</button>
                                </div>
                            </div>
                        </form> --}}
                    </div>
                </div>
            </div>
        </div>
    {{-- </div> --}}
  
  <script>
    function appendHyphen(event, my_element) {
      if (event.key === " ") {
        const inputElement = document.getElementById(my_element);
        // inputElement.value += "-";
        inputElement.value = inputElement.value.replace(/\s+/g, '-');
      }
    }

    $(document).ready(function() {
    // Iterate through each input field
    $('input').each(function() {
        // Trim and update the value
        var trimmedValue = $(this).val().trim();
        $(this).val(trimmedValue);
    });
});

  </script>

@endsection