@extends('layouts.app')
@section('title', __('lang_v1.supplier_notifications'))

@section('content')

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>{{ __('lang_v1.supplier_notifications')}}</h1>
</section>

<!-- Main content -->
<section class="content">

    	<div class="row">
		<div class="col-sm-12">
			<div class="box">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">@lang('superadmin::lang.compose_message')</h3>
				</div>
		        <div class="box-body">
		        	{!! Form::open(['url' => action('NotificationTemplateController@sendSupplierSms'), 'method' => 'post', 'id'=>'communication_form']) !!}
		        		<div class="col-md-12 form-group">
		        			{!! Form::label('recipients', __('superadmin::lang.recipients').':*') !!} <button type="button" class="btn btn-primary btn-xs select-all">@lang('lang_v1.select_all')</button> <button type="button" class="btn btn-primary btn-xs deselect-all">@lang('lang_v1.deselect_all')</button>
							{!! Form::select('recipients[]', $customers, null, ['class' => 'form-control select2', 'required', 'multiple', 'id' => 'recipients']); !!}
		        		</div>
						<div class="col-md-12">
								<strong>@lang('lang_v1.available_tags'):</strong>
							<p class="text-primary">{contact_name},{outstanding_balance}</p>
						</div>
		        		<div class="col-md-12 form-group">
		        			{!! Form::label('message', __('superadmin::lang.message').':*') !!}
		        			{!! Form::textarea('message', null, ['class' => 'form-control', 'required', 'rows' => 6]); !!}
		        		</div>
		        		<div class="col-md-12 form-group">
		        			<button type="submit" class="btn btn-danger pull-right" id="send_message">@lang('superadmin::lang.send')</button>
		        		</div>
		        	{!! Form::close() !!}
		        </div>
		    </div>
		</div>
		<div class="col-sm-12">
			<div class="box">
				<div class="box-header">
					<i class="fa fa-history"></i>
					<h3 class="box-title">@lang('superadmin::lang.message_history')</h3> <h6>Last 50 Messages</h6>
				</div>
		        <div class="box-body">
		        	<table class="table" id="customer-message-history">
		        		<thead>
		        			<tr>
		        				<th>Phone Number</th>
		        				<th>@lang('superadmin::lang.message')</th>
		        				<th>Message Length</th>
		        				<th>Status</th>
		        				<th>Response</th>
		        				<th>Sent On</th>
		        			</tr>
		        		</thead>
						<?php if (!empty($sentMessages)){
							?>
						<tbody>
						<?php 
						foreach($sentMessages as $sentmessage){
							?>
							<tr>
								<td><?php echo $sentmessage->phoneno;?> </td>
								<td><?php echo $sentmessage->message;?> </td>
								<td><?php echo strlen($sentmessage->message);?> </td>
								<td><?php echo $sentmessage->stats==0 ? "Pending" : ($sentmessage->stats==1 ? "Sent" : "Unknown");?> </td>
								<td><?php echo $sentmessage->response;?> </td>
								<td><?php  echo date('Y-m-d H:i:s',strtotime($sentmessage->createdtime));?> </td>
							</tr>
						<?php 
						}
						?>
						</tbody>
							<?php 
						}?>
		        	</table>
		        </div>
		     </div>
		</div>

	</div>

</section>
<!-- /.content -->
@stop
@section('javascript')
<script type="text/javascript">
    $('textarea.ckeditor').each( function(){
        var editor_id = $(this).attr('id');
        tinymce.init({
            selector: 'textarea#'+editor_id,
        });
    });
</script>
@endsection