@php
if(Auth::user()->user_type == 'organization')
{
    $layout = 'fcviews.layouts.org';
}
elseif(Auth::user()->user_type == 'organization_user')
{
    $layout = 'fcviews.layouts.user';
}
@endphp
@extends($layout)
@section('content')
<style>
.dropdown-menu a:hover{ background:#f27200;color:#fff;}
</style>
<div class="main-panel">
    <div class="content">
            <div class="panel-header">
                <div class="page-inner py-5 text-white"  style="background:#313232;">
                    <div class="d-flex align-items-left align-items-md-center flex-column flex-md-row">
                        <div><div class="page-header">
                            <h4 class="page-title text-white">Send Message</h4>
                            <ul class="breadcrumbs">
                                    <li class="nav-home">
                                        <a class="text-white" href="">
                                            <i class="flaticon-home"></i>
                                        </a>
                                    </li>
                                    <li class="separator">
                                        <i class="flaticon-right-arrow"></i>
                                    </li>
                                    <li class="nav-item">
                                        <a class="text-white" href="">Upload Numbers|Add Numbers</a>
                                    </li>
                                </ul>
                        </div></div>



                        <div class="ml-md-auto py-2 py-md-0">
                       
                            <div class="btn-group dropdown">
                       
                                
                                <button class="btn btn-white btn-round dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="true">
                                   <i class="fas fa-plus"></i> Send SMS
                                </button>
                                
                 

                           
                                
                                <ul class="dropdown-menu" role="menu" x-placement="top-start" style="position: absolute; transform: translate3d(0px, -117px, 0px); top: 0px; left: 0px; will-change: transform;">
                                <li><a href="#" data-toggle="modal" data-target="#sendsmstoClienttypecontact" id="show-modal" class="dropdown-item"><i class="fas fa-plus"></i> To Individuals</a></li>
                                  <!--<li><a href="#" data-toggle="modal" data-target="#add" id="show-modal" class="dropdown-item"><i class="fas fa-file-import"></i> From Template</a></li>-->
                                <li> <a href="#" data-toggle="modal" data-target="#importClient" id="show-modal" class="dropdown-item"><i class="fas fa-plus"></i> To Uploaded Contacts </a>
                                </li>
                                </ul>
                            </div>
                            <a href="" class="btn btn-white btn-border btn-round mr-2"><i class="fas fa-arrow-circle-left"></i> Back</a>
                     
    
                         
                        </div>
                    </div>
                </div>
                
                <style type="text/css">   
                    a.button {
                    -webkit-appearance: button;
                    -moz-appearance: button;
                    appearance: button;  }
                
                    text-decoration: none;
                    color: initial;
                    }
                </style>      
                            
                
          <div id="app">          
            <div class="page-category">
                <div class="page-inner mt--5">
                    <div class="row mt--2">
                            <div class="col-md-12">
                                <div class="card full-height">
                                    <div class="card-body">
                                    

                                    <div class="text-right mb-3 border-bottom pb-3">
                                    <div class="card-title pull-left">  
                                
                                    
                                    @if($contacts->count())
                                    <a href="#" data-toggle="modal" data-target="#sendsmstoClient" id="show-modal" class="btn btn-success btn-round"><strong></strong>Compose SMS </strong></a>
                                    @endif
                                    
                    
                                 
                                    </div>
                                      
                                 
                                        <!--  <a class="btn btn-primary btn-border btn-round btn-sm" data-toggle="modal" data-target="#confirmsms">-->
            
                                        <!--    <i class="fab fa-telegram-plane"></i>Send-->
                                        <!--</a>-->
                                        
                                        
                                        
                                    </div>
                                    <!----------     ---------------------------------->
                                    
                                      <div class="modal fade" id="confirmsms" tabindex="-1" role="dialog" aria-hidden="true">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                    <h4>Confirm Recipients</h4>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                            <span aria-hidden="true">&times;</span>
                                                        </button>
                                                    </div>
                                                    <form action="{{ route('sendMessageExcel')}}" method="post">
                                                        @csrf
                                                        <div class="modal-body">
                                                             <h4>Send SMS to: {{count($contacts)}} Recipients </h4>
                                                             <input type="hidden" value="{{$contacts}}" name="contactsv"/>
                                                        </div>
                                                        
                                                        <div class="modal-footer">
                                                            <button type="submit" class="btn btn-success btn-round btn-md"><i class="fa fa-check"></i> Confirm</button>
                                                            <button type="button" class="btn btn-danger btn-round btn-md" data-dismiss="modal">Close</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                    
                                    <!------------------------------------------------->

                                    <div id="filter-msg" class="d-none">
                                        <div class="alert alert-info shadow-sm mb-0" role="alert">
                                            <p class="mb-0"><i class="fas fa-info-circle"></i> This is a filtered view. <span id="filters"></span></p>
                                        </div>
                                        <hr>
                                    </div>
                                   <div id="app">
                                        
                                        @if ($errors->any())
                                            <div class="alert alert-danger alert-dismissible" role="alert">
                                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                            <strong>Error! </strong>There were some errors with inputs.
                                            <ul>
                                                @foreach($errors->all() as $error)
                                                <li>{{ $error }}</li>
                                            @endforeach
                                            </ul>
                                            </div>

                                        @endif
                                        @include('layouts.messages')
                                        <!-- tabs -->
                                       
                                        <!--/tabs  -->
                                        <br>
                                    <div class="tab-content" id="pills-tabContent">
                                        <div id="initiated" role="tabpanel" aria-labelledby="initiated-tab" class="tab-pane fade show active">
                                       
                                        <div class="table-responsive">
                                        <table  id="table" class="display table table-striped table-hover">
                                            <thead>
                                            <tr>
                                                <th>ID#</th>
                                                <th>Contact Name</th>
                                                <th>Phone</th>
                                                <th>Message</th>
                                  
                                  <th>Actions</th>
                                                </tr>
                                            </thead>
                                            <tfoot>
                                            <tr>
                                                <th>ID#</th>
                                                <th>Contact Name</th>
                                                <th>Phone</th>
                                                <th>Message</th>
                                       
                                       
                                       <th>Actions</th>
                                                </tr>
                                            </tfoot>
                                            <tbody>
                                            @foreach($contacts as $contact)
                                            <tr>
                                            <td>{{ $contact->import_id }}</td>
                                            <td>{{ ucfirst($contact->import_name) }}</td>   
                                            <td>{{ $contact->phone }}</td>
                                            <td>{{ $contact->message }}</td>
                                      
                                       <td>
                                            <div class="form-button-action" role="group" aria-label="Actions">
                                            <a href="#" data-target="#edit-{{ $contact->import_id }}" data-toggle="modal" id="show-modal"> <button class="btn btn-success btn-sm" data-toggle="tooltip"  data-original-title="View"><i class="far fa-eye"></i> </button>  </a>
                                            <a href="#" data-target="#view-{{ $contact->import_id }}" data-toggle="modal" id="show-modal"> <button class="btn btn-primary btn-sm" data-toggle="tooltip"  data-original-title="Edit"><i class="fa fa-edit"></i> </button></a>
                                            <button  @click.prevent="deleteItem('ExcelUploadDeletepath',{{$contact->import_id}})" data-toggle="tooltip"  data-original-title="Delete" name="delete" class="btn btn-danger btn-sm" title="delete">
                                                        <i class="fa fa-trash-alt"></i> 
                                            </button>
                                            
                                            </form>
                                            </div>
                                            </td>
                                     
                                            </tr>
                                            <!-- edit modal -->
                                            <div class="modal fade" id="edit-{{ $contact->import_id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                                                <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h5 class="modal-title" id="exampleModalLongTitle">View Contact </h5>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                <span aria-hidden="true">&times;</span>
                                                            </button>
                                                        </div>
                                                        <div class="modal-body panel-default bg-light">
                                                        <importsview_component :contactsdata="{{json_encode($contact)}}"/>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            
                                             <div class="modal fade" id="view-{{ $contact->import_id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                                                <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h5 class="modal-title" id="exampleModalLongTitle">Edit Contact </h5>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                <span aria-hidden="true">&times;</span>
                                                            </button>
                                                        </div>
                                                        <div class="modal-body panel-default bg-light">
                                                         
                                                         <importsedit_component :contactsdata="{{json_encode($contact)}}"/>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            
                                            
                                            
                                            
                                            <!-- end edit modal -->
                                            <!-- view modal -->
                                            <div class="modal fade" id="view-{{ $contact->import_id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                                                <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h5 class="modal-title" id="exampleModalLongTitle">Edit Contact </h5>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                <span aria-hidden="true">&times;</span>
                                                            </button>
                                                        </div>
                                                        <div class="modal-body panel-default bg-light">
                                                         
                                                         <importsedit_component :contactsdata="{{json_encode($contact)}}"/>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <!-- end view modal -->
                                            @endforeach
                                            </tbody>
                                        </table>
                                         
                                    
                                    </div>


                                            </div>
                                        </div>
                                        
  
                         
                                        
                                
                                   
                                            <!--  import -->              
                                        <div class="modal fade" id="importClient" tabindex="-1" role="dialog" aria-hidden="true">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                    <h4>Import SMS Contacts</h4>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                            <span aria-hidden="true">&times;</span>
                                                        </button>
                                                    </div>
                                                    <form action="{{ route('uploadsbatchimportsms')}}" method="post" enctype="multipart/form-data">
                                                        @csrf
                                                        <div class="modal-body bg-light">
                                                            <div class="alert alert-info shadow-sm">
                                                                <p class="mb-0">Download <a href="{{ url('sample/TypeMessageImports.xlsx') }}">sample file</a></p>
                                                            </div>
                                                            <div class="col form-group">
                                                                <label for="import-file">Select excel file to import* <div style="color:red;">(Can Only send to ) 
                                                                                                                       </div> @foreach ($mycountries as $object)
                                                              {{ $object->rateCountry->name }}
                                                                @endforeach</label>
                                                                <input name="file" id="import-file" type="file" class="form-control">
                                                            </div>
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="submit" class="btn btn-success btn-round btn-md"><i class="fa fa-check"></i> Save</button>
                                                            <button type="button" class="btn btn-danger btn-round btn-md" data-dismiss="modal">Close</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- / import -->
                                        
                                    
                                    
                                    
                                    
                                         <!--  Type SMS -->              
                                        <div class="modal fade" id="sendsmstoClient" tabindex="-1" role="dialog" aria-hidden="true">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                    <h4>Send SMS To Contacts</h4>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                            <span aria-hidden="true">&times;</span>
                                                        </button>
                                                    </div>
                                                    
                                            
                                                    
                                                    
                                                    
                                                    <form action="{{ route('MessageTypesmsImport')}}" method="post" enctype="multipart/form-data">
                                                        @csrf
                                                        <div class="modal-body bg-light">
                                                         
                                                            <div class="col form-group">
                                                                <label for="import-file"> <div style="color:red;">(Can Only send to ) 
                                                                                                                       </div> @foreach ($mycountries as $object)
                                                              {{ $object->rateCountry->name }}
                                                                @endforeach</label><br><br>
                                                                <lable>Message</lable>
                                                                <textarea name="comment" value="" class="form-control"required="" placeholder="Enter Message..."></textarea>
         
                                                                
                                                                
                                                            </div>
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="submit" class="btn btn-success btn-round btn-md"><i class="fa fa-check"></i> Send SMS</button>
                                                            <button type="button" class="btn btn-danger btn-round btn-md" data-dismiss="modal">Close</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- / import -->    
                                    
                                    
                                    
                                    
                                    
                                               <!-- Send SMS Via Template modal -->
                                    <div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                                        <div class="modal-dialog modal-dialog-centered" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="exampleModalLongTitle">Send SMS Via Template </h5>
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                        <span aria-hidden="true">&times;</span>
                                                    </button>
                                                </div>
                                                <div class="modal-body panel-default bg-light">
                                                  
                                               
                                  @if ($contacts->count())
           @foreach($contacts as $user)
          
            
       <sendsmstemplatecreate_component :templatedata="{{json_encode($contact)}}"/>

            
            
        @endforeach
          @else

            There is no records. Upload Contacts First

            @endif              
                                               
                                               
                                               
                                               
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                <!-- end Create modal -->
                                    
                                    
                                    
                                    
                                                   <!--  Type Contact SMS -->              
                                        <div class="modal fade" id="sendsmstoClienttypecontact" tabindex="-1" role="dialog" aria-hidden="true">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                    <h4>Send SMS To Contacts</h4>
                                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                            <span aria-hidden="true">&times;</span>
                                                        </button>
                                                    </div>
                                                    
                                            
                                                    
                                                    
                                                    
                                                    <form action="{{ route('ContactMessageTypesms')}}" method="post" enctype="multipart/form-data">
                                                        @csrf
                                                        <div class="modal-body bg-light">
                                                         
                                                            <div class="col form-group">
                                                                <label for="import-file"> <div style="color:red;">(Can Only send to ) 
                                                                                                                       </div> @foreach ($mycountries as $object)
                                                              {{ $object->rateCountry->name }}
                                                                @endforeach</label><br><br>
                                                               
                                                          <lable>Contact</lable>

                                    <input type="text" name="contact" value="" class="form-control"required="" placeholder="Enter contact...">                                    
                                                               
                                                               
                                                               
                                                                <lable>Message</lable>
                                      <textarea name="comment" value="" class="form-control"required="" placeholder="Enter Message..."></textarea>
         
                                                                
                                                                
                                                            </div>
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="submit" class="btn btn-success btn-round btn-md"><i class="fa fa-check"></i> Send SMS</button>
                                                            <button type="button" class="btn btn-danger btn-round btn-md" data-dismiss="modal">Close</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- / import --> 
                                    
                                    
                                    
                                    
                                        </div>  </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>   </div>
            </div>
    </div
@endsection
      <script src='https://code.jquery.com/jquery-3.2.0.min.js'></script>
    <script src='https://unpkg.com/popper.js@1.11.1'></script>
    <script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js'></script>

@section('scripts')

<script>

        $(document).ready(() => {
            let url = location.href.replace(/\/$/, "");

            if (location.hash) {
                const hash = url.split("#");
                console.log(hash);
                $('#pills-tab a[href="#'+hash[1]+'"]').tab("show");
                url = location.href.replace(/\/#/, "#");
                console.log(url);
                history.replaceState(null, null, url);
                setTimeout(() => {
                    $(window).scrollTop(0);
                }, 0);
            }
        });

</script>
@endsection
