@extends('layouts.master')
@section('page-title') 
    {{ $page_title }}
@endsection
@section('page-css')
    <!-- <link href="https://unpkg.com/tabulator-tables@6.4.0/dist/css/tabulator.min.css" rel="stylesheet"> -->
    <link href="{{ url('public/libs/tabulator-master/dist/css/tabulator_bootstrap5.css') }}" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/css/datepicker.min.css">

@endsection
@section('content')
<div id="loadingOverlay" 
     style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; 
            background:rgba(255,255,255,0.8); z-index:9999; 
            align-items:center; justify-content:center;">
  <div class="spinner-border text-primary" role="status">
    <span class="visually-hidden">Loading...</span>
  </div>
</div>
        <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">SMS Traffic Monitoring</div>
                    <!-- <h1 class="display-6 fw-semibold mb-3">Track every message your team sends.</h1>
                    <p class="fs-5 opacity-75 mb-0">
                        Search sent SMS, review delivery outcomes, inspect failed attempts, and give clients a fast audit trail for every campaign.
                    </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">Campaigns</div>
                                <div class="h3 mb-0">18</div>
                            </div>
                        </div> -->
                        <div class="col-12">
                            @if(in_array(session('current_user.role'), ['administrator', 'finance']))
                            <div class="rounded-4 p-3 bg-white bg-opacity-10">
                                <div class="small opacity-75">SMS Account Balance</div>
                                <div class="h3 mb-0" id="mainSmsBalance">{{ number_format($balance_arr['balance']) }}</div>
                            </div>
                            @endif
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <section class="row g-4 mb-4">
            <div class="col-md-6 col-xl-6">
                <article class="traffic-card">
                    <div class="d-flex align-items-start justify-content-between mb-3">
                        <!-- <div class="icon-wrap"><i class="bi bi-send-check"></i></div> -->
                        <!-- <span class="small text-success fw-semibold">+12.6%</span> -->
                    </div>
                    <div class="muted-label mb-2">
                        <!-- Messages sent from  -->
                        <span id="reportRange">{{ $split_sms_units_arr['reportDate'] }}</span> </div>

                    <div class="row">
                        <div class="col-md-6">
                            <input id="startDate" name="start_date" type="text" class="form-control" placeholder="Select Start Date">
                        </div>
                        <div class="col-md-6">
                            <input id="endDate" name="end_date" type="text" class="form-control" placeholder="Select End Date">
                        </div>
                        <!-- <div id="loadingSpinner" class="spinner-border text-primary" role="status" style="display:none;">
                          <span class="visually-hidden">Loading...</span>
                        </div> -->
                    </div>
                    
                    <!-- <div class="h3 mb-2 pt-1" id="smsUnitsValue">SMS Units : {{ $sms_units_arr['smsUnits'] }}</div> -->
                    <!-- <div class="mini-chart"><span style="width: 52%;"></span></div> -->
                </article>
            </div>
            <div class="col-md-6 col-xl-6">
                <article class="traffic-card">
                    <div class="d-flex align-items-start justify-content-between mb-3">
                        <div class="icon-wrap"><i class="bi bi-check2-circle"></i></div>
                        <!-- <span class="small text-success fw-semibold">98.4%</span> -->
                    </div>
                    <div class="muted-label mb-2">Sent Messages (last 10 days)</div>
                    <!-- <div class="h3 mb-2">183,372</div> -->
                    <div class="h5 mb-2 pt-1" id="smsUnitsCharge">SMS Charge(<?php echo (session('current_user.ucm_org_id') == 629)? "MWK" : "MZM"; ?>) : <b>{{ $split_sms_units_arr['charge_computation'] }}</b></div>
                    @if(session('current_user.ucm_org_id') == 629)
                    <div class="h5 mb-2 pt-1" id="smsUnitsValue">SMS Units : Airtel : <b>{{ number_format($split_sms_units_arr['Airtel SMSUnits']) }}</b> | TNM : <b>{{ number_format($split_sms_units_arr['TNM SMSUnits']) }}</b></div>
                    @else
                    <div class="h5 mb-2 pt-1" id="smsUnitsValue">SMS Units : <b>{{ number_format($split_sms_units_arr['units_computation']) }}</div>
                    @endif
                    <div class="mini-chart"><span style="width: 57%;"></span></div>
                </article>
            </div>
            
        </section>
        <section class="row g-4">
            <div class="col-xl-12">
                <div class="filter-card mb-4">
                    <div class="d-flex flex-column flex-lg-row align-items-lg-center justify-content-between gap-3 mb-3">
                        <div>
                            <h2 class="h4 mb-1">Sent SMS list</h2>
                            <!-- <p class="text-secondary mb-0">Filter messages by date, sender, recipient, or delivery state.</p> -->
                        </div>
                        <!-- <div class="d-flex flex-wrap gap-2">
                            <button class="btn btn-ghost px-4"><i class="bi bi-download me-2"></i>Export CSV</button>
                            <button class="btn btn-click px-4"><i class="bi bi-funnel me-2"></i>Apply filters</button>
                        </div> -->
                    </div>

                    <div class="row g-3">
                        <div class="col-md-12">
                            <div class="float-end">                              
                            
                                <!-- <label for="search" class="form-label fw-semibold">Search</label> -->
                                <!-- <input id="search" type="text" class="form-control" placeholder="Phone, sender ID, text"> -->
                            </div>
                        </div>
                    </div>
                </div>

                <div class="traffic-table-card">
                    <h2 class="h4 mb-1">Sent SMS list</h2>
                    <div class="p-1">
                        <button id="download-pdf" class="btn btn-danger"><i class="bi bi-file-pdf-fill me-2"></i> Export PDF</button>
                        <button id="download-xlsx" class="btn btn-success"><i class="bi bi-file-excel-fill me-2"></i> Export Excel</button>
                    </div>
                    <div id="message-table"></div>
                </div>
            </div>

            <!-- <div class="col-xl-2"> -->
                

                <!-- <aside class="detail-card"> -->
                    <!-- <h2 class="h5 mb-3">Recent activity</h2> -->

                    <!-- <div class="timeline-item pt-0 mt-0 border-0">
                        <div class="fw-semibold">Sender ID approved</div>
                        <div class="muted-label">CLICKINFO added </div>
                        <div class="small text-secondary mt-1">09:04</div>
                    </div> -->
                    <!-- <div class="timeline-item">
                        <div class="fw-semibold">Campaign completed</div>
                        <div class="muted-label">[campaign name] batch finished</div>
                        <div class="small text-secondary mt-1">08:41</div>
                    </div> -->
                <!-- </aside> -->
            <!-- </div> -->
        </section>        
@endsection
@section('page-js')
    <!-- <script src="https://unpkg.com/tabulator-tables@6.4.0/dist/js/tabulator.min.js"></script> -->
    <script src="https://cdn.jsdelivr.net/npm/vanillajs-datepicker@1.1.4/dist/js/datepicker.min.js"></script>

    <script src="{{ url('public/libs/tabulator-master/dist/js/tabulator.min.js') }}"></script>

    <script src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"></script>
    <script type="text/javascript" src="https://cdn.sheetjs.com/xlsx-0.20.3/package/dist/xlsx.full.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/luxon@2.3.1/build/global/luxon.min.js"></script>
    <script src="{{ url('public/libs/tabulator-master/dist/js/autotable.min.js') }}"></script>
    <script src="{{ url('public/assets/js/traffic-mgt.js') }}"></script>

@endsection