@extends('layouts.master')
@section('page-title') 
    {{ $page_title }}
@endsection
@section('page-css')
@section('content')
        <section class="traffic-hero mb-4">
            <div class="row g-4 align-items-end">
                <div class="col-lg-8">
                    <div class="text-uppercase small fw-semibold opacity-75 mb-2">Campaign Composer</div>
                    <h1 class="display-6 fw-semibold mb-3">Create and send an SMS campaign in one flow.</h1>
                    <p class="fs-5 opacity-75 mb-0">
                        Draft the message, choose sender and recipients, then send.
                    </p>
                </div>
                <div class="col-lg-4">
                    <!-- <div class="row g-3">
                        <div class="col-6">
                            <div class="rounded-4 p-3 bg-white bg-opacity-10">
                                <div class="small opacity-75">Available credit</div>
                                <div class="h3 mb-0">48.2k</div>
                            </div>
                        </div>
                        <div class="col-6">
                            <div class="rounded-4 p-3 bg-white bg-opacity-10">
                                <div class="small opacity-75">Sender IDs</div>
                                <div class="h3 mb-0">3</div>
                            </div>
                        </div>
                    </div> -->
                </div>
            </div>
        </section>

        <section class="row g-4">
            <div class="col-md-12">
                <div class="compose-card mb-4">
                    <div class="section-kicker mb-2">Message setup</div>
                    <div class="d-flex flex-column flex-lg-row align-items-lg-center justify-content-between gap-3 mb-4">
                        <div>
                            <h2 class="h3 mb-1">Compose message</h2>
                            <p class="text-secondary mb-0">Set campaign details, recipients, and delivery rules before sending.</p>
                        </div>
                        @include('commons.notifications')
                        <!-- <div class="d-flex flex-wrap gap-2">
                            <span class="option-chip active"><i class="bi bi-lightning-charge"></i>Send now</span>
                            <span class="option-chip"><i class="bi bi-calendar-event"></i>Schedule</span>
                        </div> -->
                    </div>

                    <form action="send-sms" method="POST" enctype="multipart/form-data">
                        @csrf
                        <!-- <div class="row g-3 mb-4">
                            <div class="col-md-6">
                                <label for="campaignName" class="form-label fw-semibold">Campaign name</label>
                                <input id="campaignName" type="text" class="form-control" value="March savings reminder">
                            </div>
                            <div class="col-md-3">
                                <label for="senderSelect" class="form-label fw-semibold">Sender ID</label>
                                <select id="senderSelect" class="form-select">
                                    <option>CLICKINFO</option>
                                    <option>CLICKOTP</option>
                                    <option>ACMEBANK</option>
                                </select>
                            </div>
                            <div class="col-md-3">
                                <label for="country" class="form-label fw-semibold">Primary market</label>
                                <select id="country" class="form-select">
                                    <option>Ghana</option>
                                    <option>Malawi</option>
                                    <option>Zambia</option>
                                </select>
                            </div>
                        </div> -->
                        <div class="mb-4">
                            <div class="d-flex flex-column flex-lg-row align-items-lg-center justify-content-between gap-2 mb-2">
                                <label class="form-label fw-semibold mb-0">Sender ID</label>
                                <span class="muted-label">Not more than 11 characters</span>
                            </div>
                            <input type="text" name="sender_id" class="form-control">
                        </div> 
                        <div class="mb-4">
                            <div class="d-flex align-items-center justify-content-between mb-2">
                                <label for="messageText" class="form-label fw-semibold mb-0">Message content</label>
                                <span class="muted-label" id="messageCounter">54 / 160 characters</span>
                            </div>
                            <textarea id="messageText" name="message" class="form-control py-3" rows="5" placeholder="message body goes here"></textarea>
                            <!-- <div class="char-progress mt-3"><span></span></div> -->
                        </div>

                        <div class="mb-4">
                            <div class="d-flex flex-column flex-lg-row align-items-lg-center justify-content-between gap-2 mb-2">
                                <label class="form-label fw-semibold mb-0">Recipients</label>
                                <span class="muted-label">Paste numbers(comma separated) or upload CSV</span>
                            </div>
                            <div class="recipient-box">
                                <!-- <input type="textarea" rows="8"  name="pasted"> -->
                                <textarea name="pasted" class="form-control" rows="6"></textarea>
                                <!-- <span class="recipient-tag"><i class="bi bi-telephone"></i>+233245559001</span>
                                <span class="recipient-tag"><i class="bi bi-telephone"></i>+233502287744</span>
                                <span class="recipient-tag"><i class="bi bi-telephone"></i>+265884412280</span>
                                <span class="recipient-tag"><i class="bi bi-people"></i>Retail Savers Segment</span> -->
                            </div>
                            <div class="mb-3 recipient-box mt-2">
                              <label for="formFile" class="form-label">Upload your file</label>
                              <input type="file" id="formFile" name="recipients_file" class="d-none">
                              <div id="dropZone" class="rounded border border-primary p-4 text-center">
                                Click to select a file or drag and drop here
                              </div>
                            </div>
                        </div>

                        <!-- <div class="row g-3 mb-4">
                            <div class="col-md-12">
                                <label for="deliveryWindow" class="form-label fw-semibold">Delivery window</label>
                                <select id="deliveryWindow" class="form-select">
                                    <option>Immediately</option>
                                    <option>09:00 - 12:00</option>
                                    <option>12:00 - 15:00</option>
                                    <option>15:00 - 18:00</option>
                                </select>
                            </div>
                            
                        </div> -->

                        <div class="d-flex flex-column flex-lg-row gap-3">
                            <button type="submit" class="btn btn-click flex-grow-1"><i class="bi bi-send me-2"></i>Send SMS campaign</button>
                            <!-- <button type="button" class="btn btn-ghost flex-grow-1"><i class="bi bi-floppy me-2"></i>Save draft</button> -->
                        </div>
                    </form>
                </div>
            </div>

            
        </section>
    </div>

@endsection
@section('page-js')
    <script>
        const dropZone = document.getElementById('dropZone');
        const formFile = document.getElementById('formFile');

        dropZone.addEventListener('click', () => {
          formFile.click(); // Trigger the hidden input click
        });

        formFile.addEventListener('change', () => {
          if (formFile.files.length > 0) {
            dropZone.textContent = formFile.files[0].name; // Update the drop zone text
          } else {
            dropZone.textContent = 'Click to select a file or drag and drop here';
          }
        });
        $(document).ready(function(){
            $('#messageText').keyup(function(){
                characterCount = $(this).val().length;
                messagePages = Math.ceil(characterCount/160);
                $('#messageCounter').html(characterCount + " character " + messagePages + " messages");
            });
        });
        
    </script>

@endsection
