@extends('layouts.master')
  @section('page_title')
      @if(isset($page_title))
          {{ $page_title }}
      @endif
  @endsection

@section('content')

<div class="row">
              <div class="col-md-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Client Meeting Reports</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" title="Select Account Manager" data-toggle="dropdown" role="button" aria-expanded="false" style="font-size: 30px;"><i class="fa fa-list-alt" style="color: green;"></i></a>
                        <ul class="dropdown-menu" role="menu" style="height: 150px; overflow: scroll; ">
                          @for($i=0; $i < 10; $i++)
                          <li style="font-size: 20px;"><a href="#">Settings {{ $i }}</a>
                          </li>
                          @endfor
                          <!-- <li style="font-size: 20px;"><a href="#">Settings 2</a>
                          </li> -->
                        </ul>
                      </li>
                      <li><a class="close-linkbbb"  title="Clear filter" style="font-size: 30px;"><i class="fa fa-close" style="color: red;"></i></a>
                    </ul>
                    <div class="clearfix"></div>
                  </div>

                  <div class="x_content">

                    <div class="col-md-9 col-sm-9 col-xs-12">

                      <ul class="stats-overview">
                        <li>
                          <span class="name"> Current Balance </span>
                          <span class="value text-success"> {{ $main_discussion->current_balance or 'N/A' }} </span>
                        </li>
                        <li>
                          <span class="name"> Payment Status </span>
                          <span class="value text-success"> {{ $main_discussion->payment_status }} </span>
                        </li>
                        <li class="hidden-phone">
                          <span class="name"> Service Type </span>
                          <span class="value text-success"> {{ $main_discussion->service }} </span>
                        </li>
                      </ul>
                      <br />

                      <div class="x_content">

                  <div class="bs-example" data-example-id="simple-jumbotron">
                    <div class="jumbotron">
                      <h3>{{ $main_discussion->client_info->name }} | {{ $main_discussion->contact_person }} | {{ $main_discussion->email }}</h3>
                
                      <p>Main Discussion : {{ $main_discussion->discussion }}</p>
                      <small class="text-success">Account Manager: {{ $main_discussion->auth_user_info->name }}</small>
                      <div class="clearfix"></div>
                      <p class="pull-left"><i class="fa fa-arrow-circle-left"></i> Last Follow Up : @if($main_discussion->last_follow_up_date) {{ date('d-m-Y', strtotime($main_discussion->last_follow_up_date)) }}  @endif </p>
                      <p class="pull-right">@if($main_discussion->next_follow_up_date) Next Follow Up : {{ date('d-m-Y', strtotime($main_discussion->next_follow_up_date)) }} @endif <i class="fa fa-arrow-right"></i> </p>
                    </div>
                  </div>

                </div>

                      <div style="">

                        <h4>Recent Activity</h4>
                        <div style="border-radius: 8px; background-color: #dce2e4; height: 350px; overflow: scroll; padding-right: 10px;">
                        <ul class="messages">
                          <?php for ($i = 0; $i < $meeting_report_arr->count(); $i++) {  ?>
                          <li>
                            <div class="message_date">
                              <h3 class="date text-info"><?php echo date('d', strtotime($meeting_report_arr[$i]->created_at)); ?></h3>
                              <p class="month"><?php echo date('M', strtotime($meeting_report_arr[$i]->created_at)); ?></p>
                              <p class="year"><?php echo date('Y', strtotime($meeting_report_arr[$i]->created_at)); ?></p>
                            </div>
                            <div class="message_wrapper">
                              <h4 class="heading">{{ $meeting_report_arr[$i]->client_info->name }}</h4>
                              <a href="{!! url('reportdetails', $meeting_report_arr[$i]->id) !!} "><blockquote class="message">{{ $meeting_report_arr[$i]->discussion }}</blockquote></a>
                              <br />
                              <p class="url">
                                <span class="fs1 text-info" aria-hidden="true" data-icon=""></span>
                                <a href="#" data-original-title="">{{ $meeting_report_arr[$i]->auth_user_info->name }}</a>
                              </p>
                            </div>
                          </li>
                        <?php } ?>
                        </ul>
                      </div>
                      </div>


                    </div>

                    <!-- start project-detail sidebar -->
                    <div class="col-md-3 col-sm-3 col-xs-12">
                      <section class="panel">
                        <div class="x_title">
                          <h2>{{ date('l jS F Y') }}</h2>
                          <div class="clearfix"></div>
                        </div>
                        <div class="panel-body">
                          <h3 class="green"><i class="fa fa-comments"></i> Sam's Comments</h3>
                          <div style="" class="frame">
                            <?php //dump($main_discussion->sam_comment_info->isEmpty()); ?>
                            @if(!$main_discussion->sam_comment_info->isEmpty())
                              <?php $comments_arr = $main_discussion->sam_comment_info->reverse(); ?>
                              @foreach($comments_arr as $comment)
                              <p>{{ $comment->message }}</p>
                              <!-- <br> -->
                              <small><b>Date: {{ date('d-m-Y', strtotime($comment->created_at)) }}</b></small>
                              <hr>
                              @endforeach
                            @else
                              <p class="bg-danger" style="padding:15px;">No comments yet</p>
                            @endif
                          </div>
                          <br />
                          <div class="project_detail">
                            <?php //dump(session('current_user')); dump(session('current_user.designation') !== 'administrator'); ?>
                            <form action="{!! url('reports') !!}">
                              {{ csrf_field() }}
                              <input type="hidden" id="reportID" name="report_id" value="{{ $main_discussion->id }}">
                              <input type="hidden" id="createdById" name="created_by_id" value="{{ session('current_user.id') }}">
                              <div class="form-group">
                                <textarea class="form-control" id="samComment" rows="10" placeholder="enter comment here" required="" <?php echo (session('current_user.designation') !== 'administrator') ? 'disabled' : '' ; ?>></textarea>
                              </div>
                              <div class="form-group">
                                <button type="button" id="samCommentBtn" class="btn btn-sm btn-success btn-block" <?php echo (session('current_user.designation') !== 'administrator') ? 'disabled' : '' ; ?> ><i class="fa fa-send"></i> Submit Comment</button>
                              </div>
                            </form>
                          </div>

                          <br />
                         <!--  <h5>Project files</h5>
                          <ul class="list-unstyled project_files">
                            <li><a href=""><i class="fa fa-file-word-o"></i> Functional-requirements.docx</a>
                            </li>
                            <li><a href=""><i class="fa fa-file-pdf-o"></i> UAT.pdf</a>
                            </li>
                            <li><a href=""><i class="fa fa-mail-forward"></i> Email-from-flatbal.mln</a>
                            </li>
                            <li><a href=""><i class="fa fa-picture-o"></i> Logo.png</a>
                            </li>
                            <li><a href=""><i class="fa fa-file-word-o"></i> Contract-10_12_2014.docx</a>
                            </li>
                          </ul> -->
                          <br />

                          <div class="text-center mtop20" style="margin-top: 20px;" style="border-radius: 10px;">
                            <!-- <a href="#" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> Add Comment</a> -->
                            <a href="{!! url('reports/create') !!}" class="btn btn-sm btn-warning btn-block"><i class="fa fa-plus-circle"></i> Add New Report</a>
                          </div>
                        </div>

                      </section>

                    </div>
                    <!-- end project-detail sidebar -->

                  </div>
                </div>
              </div>
            </div>
            @endsection

@section('javascript')
<script type="text/javascript">
  $(document).ready(function(){

    $('#samCommentBtn').click(function(evt){
      evt.preventDefault();

      let URL = "{!! url('reports/samcomment') !!}";
      let reportIDD = $('#reportID').val();
      let createdByIDD = $('#createdById').val();
      let mainMessage = $('#samComment').val();

      let myData = {'created_by_id' : createdByIDD, 'report_id' : reportIDD, 'message' : mainMessage };

      $.ajax({
        headers: {
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        url: URL,
        type : 'POST',
        data : myData,
      }).done(function(data) {
        $('#samComment').val('');
        swal('Comments added successfully!');
      }).fail(function(){
        console.log('failed ');
        swal('Comments could not be added at this time. Try again!');
      }).always(function(){
        console.log('always here');
        location.reload();
      });
    });
  });

</script>


@endsection
