<?php
    include('config.php');
    $user = $_GET['user'] ?? 'Guest';
?>
<script>
    
</script>
<!DOCTYPE html>
<html lang="en" class="light-style customizer-hide">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>
        <title>NPS Dashboard</title>
        <meta name="description" content="" />
        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.googleapis.com" />
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
        <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
        <!-- <link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet"> -->
        <link href="assets/css/main.d810cf0ae7f39f28f336.css" rel="stylesheet">
        <link href="assets/css/animate.css" rel="stylesheet">
        <link href="assets/css/animate.min.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/css/bootstrap-multiselect.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/fontawesome.min.css" integrity="sha512-d0olNN35C6VLiulAobxYHZiXJmq+vl+BGIgAxQtD5+kqudro/xNMvv2yIHAciGHpExsIbKX3iLg+0B6d0k4+ZA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> -->
        <link rel="stylesheet" href="assets/select2/select2.min.css">
        <link rel="stylesheet" href="https://cdn.datatables.net/2.0.3/css/dataTables.dataTables.css" />
        <script type="text/javascript" src="assets/scripts/jquery.min.js"></script>
        <link rel="stylesheet" href="assets/css/styleX.css">

        <style>
            .top_col
            {
                max-width:100px !important;
            }
            .offscreen {
            position: absolute;
            top: -10000px;
            left: -10000px;
            visibility: hidden;
        }
        #ppt_frame
        {
            position: absolute;
            top: 0px;
            /* z-index: 999999; */
            width: 100%;
            height: 100%;
            display:none;
        }
        iframe
        {
            width: 100%;
            height: 100%;
        }
        /* .left-section, .right-section {
            max-height: 430px; 
            overflow-y: auto;
            overflow-x: hidden;
        } */
        .scroll-section
        {
            max-height: 430px;
            max-width: 1360px; 
            overflow-y: auto;
            overflow-x: auto;
        }
        .scroll-section2
        {
            max-height: 430px;
            max-width: 1360px; 
            overflow-y: auto;
            overflow-x: auto;
        }
        /* .pr2, .pr4 {
            padding-right: 15px;
        } */

        .cardBg {
            background-color: #FFFFFF; /* Adjust to match your theme */
            border: 1px solid #ddd;
            border-radius: 5px;
            padding: 5px;
        }
        .card-header>.nav {
            margin-left: 0rem !important;
            height: 100%;
            width: 100%;
        }
        .card-header {
            height: 2.5rem;
        }
        .nav-link {
            display: block;
            padding: .2rem 1rem;
        }
        .female_selected_shadow
        {
            filter: drop-shadow(0px 3px 7px #FF94D4);
        }
        .male_selected_shadow
        {
            filter: drop-shadow(0px 3px 7px #8BCAFF);
        }
        .selected_shadow
        {
            filter: drop-shadow(0px 0px 7px #000000);
        }
        .switchG {
            position: relative;
            height: 32px;
            width: auto;
            margin: 0px;
            background: #FFFFFF;
            border-radius: 32px;
            left: 4%;
            float:right;

        }

        .switch-labelG {
            font-weight: bold;
            position: relative;
            z-index: 2;
            float: left;
            width: 70px;
            line-height: 32px;
            font-size: 12px;
            color: #676a6c;
            text-align: center;
            cursor: pointer;
            margin-bottom:0px;
        }

        .switch-inputG {
            display: none;
        }

        .switch-inputG:checked + .switch-labelG {
            color: #FFF;
            transition: 0.15s ease-out;
            transition-property: color, text-shadow;
        }

        .switch-inputG:checked + .switch-labelG-y ~ .switch-selectorG {
            transform: translateX(0%);
            background-color: #1AB394;
        }

        .switch-inputG:checked + .switch-labelG-i ~ .switch-selectorG {
            transform: translateX(200%);
            background-color: #f8ac59;
        }

        .switch-inputG:checked + .switch-labelG-n ~ .switch-selectorG {
            transform: translateX(100%);
            background-color: #ed5565;
        }

        .switch-selectorG {
            position: absolute;
            z-index: 1;
            top: 0px;
            left: 0px;
            display: block;
            width: 70px;
            height: 32px;
            border-radius: 32px;
            background-color: #1ab394;
            transition: all 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
        }

        .tbodyCat{
            background-color:#F9D00D !important;
            width: 10%;
            font-size:0.7rem;
            color: #000000 !important;
            font-weight: 500;
        }
        .main_td
        {
            background-color:#1F74BA !important;
            color:white !important;
        }

        .promoterTd
        {
            background-color: #C1F0C8 !important;
            font-size:0.6rem !important;
        }
        .passiveTd
        {
            background-color: #FFFFCC !important;
            font-size:0.6rem !important;
        }
        .detractorTd
        {
            background-color: #FBE2D5 !important;
            font-size:0.6rem !important;
        }

        .tbodyCat {
                min-width: 150px; /* Example width */
            }
            .tdContent {
                display: flex;
                justify-content: space-around; /* Space between values */
                width: 100%; /* Match parent width */
            }
            .tdContent span {
                flex: 1; /* Ensure equal spacing for values */
                text-align: center; /* Center each value */
            }

            table {
        width: 100%;
        border-collapse: collapse;
    }

    th, td {
        border: 1px solid #ddd;
        text-align: center;
        vertical-align: top;
    }

    .tbodyCat {
        width: 150px; /* Example width for the first column */
    }

    .tdContent {
        display: flex;
        justify-content: space-around; /* Space values evenly */
        width: 100%;
    }

    .tdContent span {
        flex: 1; /* Equal space for each value */
        text-align: center;
        font-size: 0.7rem;
    }

    .brand_img {
        width: 35px; /* Adjust image size as needed */
        height: 35px;
    }
    .brand_img2 {
        width: 20px; /* Adjust image size as needed */
        height: 20px;
    }
    .waveX
    {
        font-weight: normal;
        font-size: 0.8rem;
    }
    .nps_count
    {
        font-size: 0.8rem;
    }
    .nav-item .nav-link {
        font-weight: normal;
    }
    .dashed_border
    {
        border:2px dashed #e9ecef !important;
    }
    .dashed_border1
    {
        border-right:2px dashed #e9ecef !important;
    }
    .dashed_border2
    {
        border-right:2px dashed #e9ecef !important;
    }
    .solid_border
    {
        border: 1px solid black !important;
        font-size:0.7rem !important;
    }
    .solid_border2 
    {
        border-top: 1px solid black;
        border-bottom: 1px solid black;
        font-size:0.7rem !important;
    }
    .table thead th {
        border-bottom: 2px dashed #e9ecef;
    }
    .table th, .table td 
    {
        padding: .20rem;
    }
    .boldC
    {
        font-weight:500;
    }
    .nps_count2 {
    font-weight: 700;
}
.word_cloud_comment td {
    font-size: 0.7rem;
    text-align: start;
    padding-left: 10px;
}

.WCX
{
    height: 300px;
    border-radius: 70%;
    border: 1px solid black;
}

.waveX
{
    font-weight: bold
}

#overall_tbl_trends {
  border-collapse: collapse;
  width: 100%;
}

#overall_tbl_trends thead th {
  position: sticky;
  top: 0; /* Keeps the header row fixed */
  z-index: 2; /* Ensures it stays above other content */
}

#overall_tbl_trends tbody th {
  position: sticky;
  left: 0; /* Keeps the first column fixed */
  /* z-index: 1;  */
}

#domain_tbl_trends {
  border-collapse: collapse;
  width: 100%;
}

#domain_tbl_trends thead th {
  position: sticky;
  top: 0; /* Keeps the header row fixed */
  z-index: 2; /* Ensures it stays above other content */
}

#domain_tbl_trends tbody th {
  position: sticky;
  left: 0; /* Keeps the first column fixed */
  /* z-index: 1;  */
}

.select2-selection__rendered {
    font-weight: 600 !important;
}

.redcolor
{
    color : red;
}

/* .negativeX
{
    color : #b30000;
}

.positiveX
{
    color : #33cc33;
}

.neutralX
{
    color: #cc7a00;
} */

#flipkart_word_cloud_all_container{
text-align:center;
}
#flipkart_word_cloud_promoter_container{
text-align:center;
}
#flipkart_word_cloud_passive_container{
text-align:center;
}
#flipkart_word_cloud_detractor_container{
text-align:center;
}

#amazon_word_cloud_all_container{
text-align:center;
}
#amazon_word_cloud_promoter_container{
text-align:center;
}
#amazon_word_cloud_passive_container{
text-align:center;
}
#amazon_word_cloud_detractor_container{
text-align:center;
}

#meesho_word_cloud_all_container{
text-align:center;
}
#meesho_word_cloud_promoter_container{
text-align:center;
}
#meesho_word_cloud_passive_container{
text-align:center;
}
#meesho_word_cloud_detractor_container{
text-align:center;
}

#flipkart_voc_chart1{
    text-align:center;
}
#flipkart_voc_chart2{
    text-align:center;
}
#flipkart_voc_chart3{
    text-align:center;
}
#flipkart_voc_chart4{
    text-align:center;
}

#amazon_voc_chart1{
    text-align:center;
}
#amazon_voc_chart2{
    text-align:center;
}
#amazon_voc_chart3{
    text-align:center;
}
#amazon_voc_chart4{
    text-align:center;
}

#meesho_voc_chart1{
    text-align:center;
}
#meesho_voc_chart2{
    text-align:center;
}
#meesho_voc_chart3{
    text-align:center;
}
#meesho_voc_chart4{
    text-align:center;
}
.occur {
    padding-left: 20px;
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 16px;
    background-color: aquamarine;
    display:none;
}
img.data_icon {
    height: 30px;
}
.ss{
    height: 50%;
    font-size: 13px;
}
.btnSection
{
    display:flex;
    gap: 15px;
    margin-left:10px;
}
        </style>
    </head>

    <body>
        <div class="app-container app-theme-white body-tN-shadow fixed-sidebar fixed-header" id="app-containerX">
            <div class="app-header header-shadow" style="height:30px;display:none">
                <div class="app-header__logo" style="background-color:white">
                    <button class="openbtn" id="openbtn" data-status="1" onclick="tabSidebar()" style="display:none"><i class="fa fa-bars" aria-hidden="true"></i></button>
                    <!-- <button class="openbtn" id="filterbtn" onclick="filterS(this)" data-value="1"><i class="fa fa-filter" aria-hidden="true"></i></button> -->
                    
                </div>
                <div class="app-header__mobile-menu">
                    <div>
                        <button type="button" class="hamburger hamburger--elastic mobile-toggle-nav">
                        <span class="hamburger-box">
                        <span class="hamburger-inner"></span>
                        </span>
                        </button>
                    </div>
                </div><!-- app-header mobile menu div-->
                <div class="app-header__menu">
                    <span>
                        <button type="button" class="btn-icon btn-icon-only btn btn-primary btn-sm mobile-toggle-header-nav">
                        <span class="btn-icon-wrapper">
                        <i class="fa fa-ellipsis-v fa-w-6"></i>
                        </span>
                        </button>
                    </span>
                </div><!-- app-header menu div-->
                <div class="app-header__content" style="background-color:white;display:block">
                    <div class="row">
                        <div class="col-lg-11">
                            
                        </div>
                        <div class="col-lg-1 text-center">
                            
                        </div>
                    </div>
                    <!-- <div class="app-header-left" style="margin:0px auto;margin-top:15px">
                        
                    </div>
                    <div class="app-header-right">
                        
                    </div> -->
                </div><!-- app-header content-->
            </div><!-- app-header div-->
            <div id="mySidebar" class="sidebar">
                <?php include("tabs.php"); ?>
            </div>
            <div class="app-main" id="main">
                <div class="splash">
                    <div class="splash-title">
                        <div class="spinner">

                        </div>
                    </div>
                </div>
                <div class="app-main__outer" style="background-color: #E4ECF3;">
                    <div class="app-main__inner" style="padding: 0px;padding-right:15px">
                        <div class="card cardXX mt-2 pr3" style="background-color:#FFFFFF;margin-left:0px;margin-right:0px;margin-bottom:5px;" id="filterdefination_div">
                            <div class="row" id="filterdefination_overall_div">
                                <div class="col-md-10">
                                    <textarea class="paraX" style="height:auto;max-width:200px;word-wrap:break-word;display:none">Filters:All Selected</textarea>
                                    <h6 class="ml-2 mt-2 paraY" style="height:auto;color:#000000;font-size:0.9rem">Filters:All Selected</h6>
                                </div>
                                <div class="col-lg-2" style="text-align:end;margin-left:-10px">
                                    <h6 class="ml-2 mt-2" style="height:auto;color:#003e80 !important;font-size:0.8rem;display:none" id="overallBase"><span class="boldC">Sample Size:</span> 1200</h6>
                                </div>
                            </div>
                            <div class="row" id="filterdefination_trend_div" style="display:none">
                                <div class="col-md-12">
                                    <p class="ml-2 mt-3 paraYT" style="height:auto;color:#000000">Filters:All Selected</p>
                                </div>
                            </div>
                        </div>
                        <div class="card">
                            <div class="card-header" style="position: sticky; top: 0; z-index: 1000; background-color: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.1);">
                                <div class="header__pane bars" style="margin-left:-15px">
                                    <div class="logo-src">
                                        <img src="assets/images/filpkart.png" style="width:30px;height:30px;">
                                    </div>
                                </div>
                                <button class="openbtn btn" onclick="openF();" style="background-color:transparent"><i class="fa fa-filter"></i></button>
                                <ul class="nav nav-justified ml-2">
                                    <li class="nav-item"><a data-toggle="tab" href="#tab-eg9-1" class="nav-link active">NPS</a></li>
                                    <li class="nav-item"><a data-toggle="tab" href="#tab-eg9-2" class="nav-link">Trends</a></li>
                                    <li class="nav-item"><a data-toggle="tab" href="#tab-eg9-3" class="nav-link">VOC</a></li>
                                </ul>
                                <!-- <div class="header__pane bars ccxs" style="">
                                    <div>
                                        <button type="button" data-toggle="modal" data-target="#exampleModal" class="mb-0 mr-0 border-0 btn-transition btn btn-outline-primary">Import</button>
                                    </div>
                                </div> -->
                                <!-- <div class="header__pane bars ccxs" style="">
                                    <div>
                                        <button type="button" data-toggle="modal" data-target="#exampleModal2" class="mb-0 mr-0 border-0 btn-transition btn btn-outline-primary">VOC</button>
                                    </div>
                                </div> -->
                                <div class="header__pane bars" style="margin-left:5px" id="ashimport">
                                    <div>
                                        <button type="button" data-toggle="modal" data-target="#exampleModal" class="mb-0 mr-0 border-0 btn-transition btn btn-outline-primary">Import</button>
                                    </div>
                                </div>
                                <!-- <div class="header__pane bars" style="margin-left:5px;width:130px">
                                    <div>
                                        <button type="button" data-toggle="modal" data-target="#exampleModal7" class="mb-0 mr-0 border-0 btn-transition btn btn-outline-primary">VOC Import</button>
                                    </div>
                                </div> -->
                                <div class="header__pane bars" style="margin-left:5px">
                                    <div>
                                        <button class="mb-0 mr-0 border-0 btn-transition btn btn-outline-primary" onclick="resetFilters();">Reset</button>
                                    </div>
                                </div>
                                <div class="header__pane bars" style="margin-left:5px">
                                    <div>
                                        <button class="mb-0 mr-0 border-0 btn-transition btn btn-outline-primary" onclick="exportExcel();">Export</button>
                                    </div>
                                </div>
                                <div class="header__pane bars" style="margin-left:5px">
                                    <button type="button" class="mb-0 mr-0 border-0 btn-transition btn btn-outline-danger" onclick="logout();"> <i class="fa fa-power-off" style="font-size:0.9rem"></i></button>
                                </div>
                            </div>
                            <div class="card-body" style="padding-top:5px;padding-bottom:5px">
                                <div class="tab-content">
                                    <div class="tab-pane active" id="tab-eg9-1" role="tabpanel">
                                        <?php include "tab1.php"; ?>
                                    </div>
                                    <div class="mt-2"></div>
                                    <div class="tab-pane" id="tab-eg9-2" role="tabpanel">
                                        <?php include "tab2.php"; ?>
                                    </div>
                                    <div class="tab-pane" id="tab-eg9-3" role="tabpanel">
                                        <?php include "tab3.php"; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div><!-- app-main inner-->
                </div><!-- app-main outer-->
            </div><!-- app-main div-->
        </div><!-- app-container div-->
        

        <div class="card animate__animated animate__fadeInDown" id="alert_div" style="display:none">
            
        </div>
        <div class="card animate__animated animate__fadeInDown" id="alert_div2" style="display:none">
            
        </div>
        <div class="card animate__animated animate__fadeInDown" id="alert_div3" style="display:none">
            <h6>Please select month</h6>
        </div>

        <!-- <div class="popup-btn trends" onclick="trends(1)" id="trends_open_div">
            <a href="javascript:void(0)">
                TRENDS
            </a>
        </div>
        <div class="popup-btn trends" onclick="trends(2)" id="trends_close_div" style="display:none">
            <a href="javascript:void(0)">
                GO BACK
            </a>
        </div> -->
        <div id="mySidebar2" class="sidebar2">
            <a href="javascript:void(0)" class="closebtn" onclick="closeF()"><i class="fa fa-times"></i></a>
            <ul class="vertical-nav-menu" style="padding:0px 0px 0px 10px !important;font-family: 'Roboto', sans-serif" id="filterX">
                <?php include('filter.php');?>
            </ul>
        </div>

        <div id="frame" style="display:none">
            
        </div>

        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" style="display: none;" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-body">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        <div style="text-align:center;display:flex;gap:10px">
                            <button type="button" data-toggle="modal" data-target="#importModal" class="btn btn-outline-primary" ><img class="data_icon" src="assets/images/import.png" alt="" srcset=""></img></br></br><h6 style="font-size:0.7rem">Import Data</h6></button>
                            <button type="button" data-toggle="modal" data-target="#deleteModal" class="btn btn-outline-danger"><img class="data_icon" src="assets/images/delete.png" alt="" srcset=""></img></br></br><h6 style="font-size:0.7rem">Delete Data</h6></button>
                            <button type="button" data-toggle="modal" data-target="#importModal7" class="btn btn-outline-primary" ><img class="data_icon" src="assets/images/import.png" alt="" srcset=""></img></br></br><h6 style="font-size:0.7rem">Import VOC Data</h6></button>
                            <button type="button" data-toggle="modal" data-target="#deleteModal7" class="btn btn-outline-danger"><img class="data_icon" src="assets/images/delete.png" alt="" srcset=""></img></br></br><h6 style="font-size:0.7rem">Delete VOC Data</h6></button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Import Data Modal -->
        <div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="importModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="importModalLabel">Import Data</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <input type="file" class="form-control-file" id="excelFile" accept=".xlsx, .xls">
                            <small class="form-text text-success">Please upload a file in Excel format (.xlsx or .xls).</small>
                        </div>
                        <button type="button" class="btn btn-primary" onclick="importData();">Upload</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Delete Data Modal -->
        <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="deleteModalLabel">Delete Data</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="monthSelect">Select Month</label>
                                <select class="form-control" id="monthSelect">
                                </select>
                            </div>
                            <button type="button" class="btn btn-danger" onclick="deleteData();">Delete Data</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!--  -->

        <!-- Import Data Modal -->
        <div class="modal fade" id="importModal7" tabindex="-1" role="dialog" aria-labelledby="importModalLabel7" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="importModalLabel7">Import Data</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <input type="file" class="form-control-file" id="excelFile7" accept=".xlsx, .xls">
                            <small class="form-text text-success">Please upload a file in Excel format (.xlsx or .xls).</small>
                        </div>
                        <button type="button" class="btn btn-primary" onclick="importDataVOC();">Upload</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Delete Data Modal -->
        <div class="modal fade" id="deleteModal7" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel7" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="deleteModalLabel7">Delete Data</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="vocmonth">Select Month</label>
                                <select class="form-control" id="vocmonthdelete">
                                </select>
                            </div>
                            <button type="button" class="btn btn-danger" onclick="deleteDataVOC();">Delete Data</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript" src="assets/scripts/main.d810cf0ae7f39f28f336.js"></script>
        <script type="text/javascript" src="assets/select2/select2.min.js"></script>
        <script async defer src="https://buttons.github.io/buttons.js"></script>
        <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
	    <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>
        <script src="https://cdn.datatables.net/2.0.3/js/dataTables.js"></script>
        <script src="assets/wizard/js/jquery.steps.js"></script>
	    <script src="assets/wizard/js/main.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.js"></script>
        <!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.min.js.map"></script> -->
        <script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script>
        <script type="text/javascript" src="https://code.highcharts.com/modules/variable-pie.js"></script>
        <script type="text/javascript" src="https://code.highcharts.com/highcharts-more.js"></script>
        <script type="text/javascript" src="https://code.highcharts.com/modules/exporting.js"></script>
        <script type="text/javascript" src="https://code.highcharts.com/modules/offline-exporting.js"></script>
        <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/linways/table-to-excel@v1.0.4/dist/tableToExcel.js"></script>
        <!-- <script lang="javascript" src="https://cdn.sheetjs.com/xlsx-0.20.1/package/dist/xlsx.full.min.js"></script> -->
        <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script> -->

        <script type="text/javascript" src="https://keresearch.in/demoDash/assets/code/modules/heatmap.js"></script>
        <script src="https://code.highcharts.com/highcharts-more.js"></script>
        <script src="https://code.highcharts.com/maps/modules/map.js"></script>
        <script src="https://code.highcharts.com/maps/modules/exporting.js"></script>
        <script src="https://code.highcharts.com/modules/wordcloud.js"></script>

        <script>
            var filtercondX = ``;
            var zoneTxt = [];
            var tierTxt = [];
            var architectTxt = [];
            var accountTxt = [];
            var normalmonthX = [];
            var normalmonthLabelX = [];
            var trendsmonthX = [];
            var trendsmonthLabelX = [];
            var conX = ``;
            var condX = ``;
            var domainDropCvalX = '0';
            var domainDropC2valX = '0';
            var domainDropC3valX = '0';
            var vocMonth = '0';
            var domainLabel = <?php echo json_encode($domain); ?>;
            var subdomainLabel = <?php echo json_encode($subdomain); ?>;
            var brandLabel = <?php echo json_encode($brand); ?>;
            // var monthLabel = ['Jan\'25', 'Mar\'25', 'Apr\'25', 'May\'25', 'Jun\'25', 'Jul\'25', 'Aug\'25', 'Sep\'25', 'Oct\'25', 'Nov\'25', 'Dec\'25', 'Jan\'26'];
            var monthLabel = ['Jan\'25', 'Mar\'25', 'Apr\'25', 'May\'25', 'Jun\'25', 'Jul\'25', 'Aug\'25', 'Sep\'25', 'Oct\'25', 'Nov\'25', 'Dec\'25', 'Jan\'26', 'Feb\'26', 'Mar\'26', 'Apr\'26'];
            var npsLabel = ["Promoter","Passive","Detractor"];
            var colorPalletNPS = ["#006620","#A58E1A","#C00000"];
            var domainflipkartCurrentBASE = [];
            var domainamazonCurrentBASE = [];
            var domainmeeshoCurrentBASE = [];
            var domainflipkartPreviousBASE = [];
            var domainamazonPreviousBASE = [];
            var domainmeeshoPreviousBASE = [];
            var CurrentbaseValues = [];

            $(document).ready(function() {
                const userNameX = <?php echo json_encode($user); ?>;
                console.log("Logged in as:", userNameX);
                if(userNameX=="admin")
                {
                    $("#ashimport").hide();
                }else{
                    $("#ashimport").show();
                }
                $('#exampleModal').on('hidden.bs.modal', function () {
                    $('.modal-backdrop').remove(); // Remove leftover backdrops
                    $('body').removeClass('modal-open'); // Fix scrolling issues
                });
                $('#importModal').on('hidden.bs.modal', function () {
                    $('.modal-backdrop').remove(); // Remove leftover backdrops
                    $('body').removeClass('modal-open'); // Fix scrolling issues
                });
                $('#deleteModal').on('hidden.bs.modal', function () {
                    $('.modal-backdrop').remove(); // Remove leftover backdrops
                    $('body').removeClass('modal-open'); // Fix scrolling issues
                });

                $(".splash").show();
                $(".splash").hide();
                $('#zone').multiselect({
                    includeSelectAllOption: true,
                    enableFiltering: false,
                    enableFullValueFiltering: false
                });
                $("#zone").multiselect('selectAll', false);
                $("#zone").multiselect("deselectAll", false);
                $("#zone").multiselect('updateButtonText');

                $('#tier').multiselect({
                    includeSelectAllOption: true,
                    enableFiltering: false,
                    enableFullValueFiltering: false
                });
                $("#tier").multiselect('selectAll', false);
                $("#tier").multiselect("deselectAll", false);
                $("#tier").multiselect('updateButtonText');

                $('#architect').multiselect({
                    includeSelectAllOption: true,
                    enableFiltering: false,
                    enableFullValueFiltering: false
                });
                $("#architect").multiselect('selectAll', false);
                $("#architect").multiselect("deselectAll", false);
                $("#architect").multiselect('updateButtonText');

                $('#account').multiselect({
                    includeSelectAllOption: true,
                    enableFiltering: false,
                    enableFullValueFiltering: false
                });
                $("#account").multiselect('selectAll', false);
                $("#account").multiselect("deselectAll", false);
                $("#account").multiselect('updateButtonText');
                select2Initialize();
            });

            $(window).on("load", function() {
                fetchMonth();
                applyF();
                var heightX = $(window).height();
                heightX = (90/100)*heightX;
                // $(".ov-card").css("max-height",heightX);
                var widthX = $(window).width();
                widthX = (93/100)*widthX;
                $(".scroll-section").each(function(){
                    $(this).css("max-width",widthX);
                })
                $(".scroll-section2").each(function(){
                    $(this).css("max-width",widthX);
                })
            });

            $(window).on("resize", function() {
                var heightX = $(window).height();
                heightX = (90/100)*heightX;
                // $(".ov-card").css("max-height",heightX);
                var widthX = $(window).width();
                widthX = (93/100)*widthX;
                $(".scroll-section").each(function(){
                    $(this).css("max-width",widthX);
                })
                $(".scroll-section2").each(function(){
                    $(this).css("max-width",widthX);
                })
            });

            //=================================Drodpown============================================
            function select2Initialize()
            {
                $(".js-select2").each(function(){
                    $(this).select2({
                        minimumResultsForSearch: 20,
                        dropdownParent: $(this).next('.dropDownSelect2')
                    });
                    $(".js-select2").each(function(){
                        $(this).on('select2:close', function (e){
                            if($(this).val() == "Please chooses") {
                                $('.js-show-service').slideUp();
                            }
                            else {
                                $('.js-show-service').slideUp();
                                $('.js-show-service').slideDown();
                            }
                        });
                    });
                });

                $("#domainDrop").next().addClass("ml-2");
            }
            //=================================Filter Sidebar START============================================

            function openF() 
            {
                document.getElementById("mySidebar2").style.width = "220px";
                document.getElementById("app-containerX").style.opacity = "0.5";
            }

            function closeF() 
            {
                document.getElementById("mySidebar2").style.width = "0px";
                document.getElementById("app-containerX").style.opacity = "1";
            }

            //=================================Filter Sidebar END============================================

            //=================================Logout============================================
            function logout() {
                window.stop();
                $.ajax({
                    url: "api/logout.php",
                    type: "POST",
                    data: {
                        'action': 'logout'
                    },
                    success: function(response) {
                        if (response == "success") {
                            window.location.href = "index.php";
                        }
                    }
                })
            }
            //=================================Logout============================================

            function resetFilters()
            {
                $('#zone').multiselect({
                    includeSelectAllOption: true,
                    enableFiltering: false,
                    enableFullValueFiltering: false
                });
                $("#zone").multiselect('selectAll', false);
                $("#zone").multiselect("deselectAll", false);
                $("#zone").multiselect('updateButtonText');

                $('#tier').multiselect({
                    includeSelectAllOption: true,
                    enableFiltering: false,
                    enableFullValueFiltering: false
                });
                $("#tier").multiselect('selectAll', false);
                $("#tier").multiselect("deselectAll", false);
                $("#tier").multiselect('updateButtonText');

                $('#architect').multiselect({
                    includeSelectAllOption: true,
                    enableFiltering: false,
                    enableFullValueFiltering: false
                });
                $("#architect").multiselect('selectAll', false);
                $("#architect").multiselect("deselectAll", false);
                $("#architect").multiselect('updateButtonText');

                $('#account').multiselect({
                    includeSelectAllOption: true,
                    enableFiltering: false,
                    enableFullValueFiltering: false
                });
                $("#account").multiselect('selectAll', false);
                $("#account").multiselect("deselectAll", false);
                $("#account").multiselect('updateButtonText');
                flagConstruct();
            }

            function flagConstruct()
            {
                applyF();
            }

            function extractValues(array,npsArray,valueType)
            {
                debugger;
                if(valueType=="Simple")
                {
                    array.forEach(function(e,i,a){
                        npsArray.push(e.npsPercentage);
                    });
                }
                else
                {
                    array.forEach(function(e,i,a){
                        var arrayV2 = [];
                        e.forEach(function(e2,i2,a2){
                            arrayV2.push(e2.npsPercentage);
                        });
                        npsArray.push(arrayV2);
                    });
                }
            }  

            function customizedArray(array,valueArray,labelArray,colorLabel,chartType,nameXX)
            {
                if(chartType=="Doughnut")
                {
                    array.forEach(function(e,i,a){
                        var valueE = {
                            name: labelArray[i],
                            y: e,
                            color: colorLabel[i]
                        };
                        valueArray.push(valueE);
                    });
                }
                else if(chartType=="StackBar")
                {
                    array.forEach(function(e,i,a){
                        var valueE = {
                            name: labelArray[i],
                            data: e,
                            color: colorLabel[i]
                        };
                        valueArray.push(valueE);
                    });
                }
                else if(chartType=="Line")
                {
                    debugger;
                    array.forEach(function(e,i,a){
                        var valueE = {
                            name: labelArray[i],
                            data: e,
                        };
                        valueArray.push(valueE);
                    });
                }
                else if(chartType=="Bar")
                {
                    var valueE = {
                        name: nameXX,
                        data: array,
                    };
                    valueArray.push(valueE);
                }
                else if(chartType=="Heat")
                {
                    const result = array.flatMap((row, rowIndex) => 
                        row.map((value, colIndex) => [rowIndex, colIndex, value])
                    );
                    valueArray.push(result);
                }
                else if(chartType=="Bubble")
                {
                    array.forEach(function(e, i) {
                        var arrX = {
                            name: labelArray[i],
                            data: [],
                            marker: {
                                fillColor: radialColors[i]
                            }
                        };
                        e.forEach(function(e2, i2) {
                            var dataPoint = {
                                x: i2,
                                y: i,
                                z: e2
                            };
                            arrX.data.push(dataPoint);
                        });
                        valueArray.push(arrX);
                    });
                }
                else
                {
                    const dataX = airportName.map((airport, index) => ({
                        'hc-key': airportDataMap[airport],
                        value: array[index],
                        name: airport
                    }));

                    valueArray.push(dataX);
                }
                
            }

            function transposeData(data) 
            {
                return data[0].map((col, i) => data.map(row => row[i]));
            }

            function calculateDifference(array1, array2) 
            {
                if (array1.length !== array2.length || array1.some((row, index) => row.length !== array2[index].length)) {
                    throw new Error("Arrays must have the same dimensions.");
                }
                const result = array1.map((row, rowIndex) => {
                    return row.map((value, colIndex) => {
                        return value - array2[rowIndex][colIndex];
                    });
                });
                return result;
            }

            function domainDropC(id)
            {
                $(".splash").show();
                debugger;
                domainDropCvalX = parseInt($(`#${id}`).val());
                var domainLabelX = domainLabel[domainDropCvalX-1];
                var subdomainLabelX = subdomainLabel[domainDropCvalX-2];

                var html = ``;
                var html2 = ``;
                html += `
                    <tr>
                        <th class="tbodyCat ${domainLabelX}_td main_td">${domainLabelX}</th>
                    `;

                $('#current_tbl tbody tr').eq(domainDropCvalX+1).find(".nps_count").each(function(i,e){
                    var X = $(e).html();
                    html += `
                        <td class="dashed_border">
                            <div class="tdContent">
                                <span class="nps_count nps_count2" id="nps_count_SDC_${brandLabel[i]}">${X}</span>
                            </div>
                        </td>
                    `;
                });
                html += `</tr>`;

                subdomainLabelX.forEach(function(e,i,a){
                    html += `<tr>`;
                    html += `<th class="tbodyCat ${e}_td">${e}</th>`;
                    brandLabel.forEach(function(e2,i2,a2){
                        html += `<td class="dashed_border">
                            <div class="tdContent">
                                <span class="nps_count" id="nps_count_SDC_${e2}_${i+1}">-</span>
                            </div>
                        </td>`;
                    });
                    html += `</tr>`;
                });

                $("#sd_current_tbl > tbody").empty().append(html);

                html2 += `
                    <tr>
                        <th class="tbodyCat ${domainLabelX}_td main_td">${domainLabelX}</th>
                    `;

                $('#previous_tbl tbody tr').eq(domainDropCvalX+1).find(".nps_count").each(function(i,e){
                    var X = $(e).html();
                    html2 += `
                        <td class="dashed_border">
                            <div class="tdContent">
                                <span class="nps_count nps_count2" id="nps_count_SDC_${brandLabel[i]}">${X}</span>
                            </div>
                        </td>
                    `;
                });
                html2 += `</tr>`;

                subdomainLabelX.forEach(function(e,i,a){
                    html2 += `<tr>`;
                    html2 += `<th class="tbodyCat ${e}_td">${e}</th>`;
                    brandLabel.forEach(function(e2,i2,a2){
                        html2 += `<td class="dashed_border">
                            <div class="tdContent">
                                <span class="nps_count" id="nps_count_SDP_${e2}_${i+1}">-</span>
                            </div>
                        </td>`;
                    });
                    html2 += `</tr>`;
                });
                $("#sd_previous_tbl > tbody").empty().append(html2);

                if(domainDropCvalX != 0)
                {
                    applyF();
                }
                else
                {
                    $(".splash").hide();
                }
            }

            function domainDropC2(id)
            {
                $(".splash").show();
                debugger;
                domainDropC2valX = parseInt($(`#${id}`).val());
                var domainLabelX = domainLabel[domainDropCvalX-1];
                var subdomainLabelX = subdomainLabel[domainDropCvalX-2];
                if(domainDropC2valX!=0)
                {
                    applyF();
                }
                else
                {
                    $(".splash").hide();
                }
            }

            function domainDropC3()
            {
                domainDropC3valX = parseInt($(`#domainDrop3`).val());
                vocMonth = parseInt($(`#vocmonth`).val());
                var domainLabelX = domainLabel[domainDropC3valX-1];
                if(domainDropC3valX!=0)
                {
                    if(vocMonth!=0)
                    {
                        applyF();
                    }
                    else
                    {
                        $("#alert_div3").show();
                        setTimeout(() => {
                            $("#alert_div3").hide();
                        }, 1500);
                    }
                }
                else
                {
                    $(".splash").hide();
                }
            }

            function applyF()
            {
                normalmonthX = [
                    $("#pmd").val(),
                    $("#cmd").val() 
                ];

                normalmonthLabelX = [];
                normalmonthX.forEach(function(e,i,a){
                    if(e==1)
                    {
                        normalmonthLabelX.push(monthLabel[0]);
                    }
                    else{
                        normalmonthLabelX.push(monthLabel[e-2]);
                    }
                });


                $(".splash").show();
                $(".splash").hide();
                debugger;
                closeF();
                filtercondX = ``;
                zoneTxt = [];
                tierTxt = [];
                architectTxt = [];
                accountTxt = [];

                conX = ``;
                condX = ``;

                var htmlX = `Please select phrase from left for comments`;
                $("#flipkart_word_cloud_all_comment > tbody").empty().append(htmlX);
                $("#flipkart_word_cloud_promoter_comment > tbody").empty().append(htmlX);
                $("#flipkart_word_cloud_passive_comment > tbody").empty().append(htmlX);
                $("#flipkart_word_cloud_detractor_comment > tbody").empty().append(htmlX);

                $("#amazon_word_cloud_all_comment > tbody").empty().append(htmlX);
                $("#amazon_word_cloud_promoter_comment > tbody").empty().append(htmlX);
                $("#amazon_word_cloud_passive_comment > tbody").empty().append(htmlX);
                $("#amazon_word_cloud_detractor_comment > tbody").empty().append(htmlX);

                $("#meesho_word_cloud_all_comment > tbody").empty().append(htmlX);
                $("#meesho_word_cloud_promoter_comment > tbody").empty().append(htmlX);
                $("#meesho_word_cloud_passive_comment > tbody").empty().append(htmlX);
                $("#meesho_word_cloud_detractor_comment > tbody").empty().append(htmlX);
                
                var zoneLengthY = $("#zone option:selected").length;
                var tierLengthY = $("#tier option:selected").length;
                var architectLengthY = $("#architect option:selected").length;
                var accountLengthY = $("#account option:selected").length;

                var zoneVal = $("#zone").val();
                var tierVal = $("#tier").val();
                var architectVal = $("#architect").val();
                var accountVal = $("#account").val();

                var selectedOptionsZone = $("#zone").find("option:selected");
                selectedOptionsZone.each(function () {
                    var dataNameValue = $(this).data("name");
                    zoneTxt.push(dataNameValue);
                });

                var selectedOptionsTier = $("#tier").find("option:selected");
                selectedOptionsTier.each(function () {
                    var dataNameValue = $(this).data("name");
                    tierTxt.push(dataNameValue);
                });

                var selectedOptionsarchitect = $("#architect").find("option:selected");
                selectedOptionsarchitect.each(function () {
                    var dataNameValue = $(this).data("name");
                    architectTxt.push(dataNameValue);
                });

                var selectedOptionsaccount = $("#account").find("option:selected");
                selectedOptionsaccount.each(function () {
                    var dataNameValue = $(this).data("name");
                    accountTxt.push(dataNameValue);
                });

                if((zoneLengthY == 0) && (tierLengthY == 0) && (architectLengthY == 0) && (accountLengthY == 0))
                {
                    conX = 1;
                }
                else
                {
                    conX = 2;
                }
                if(conX==2)
                {
                    filtercondX += `<b>Filters</b>: `;
                    if(zoneLengthY != 0)
                    {
                        condX += `Q2A IN (${zoneVal}) AND `
                        filtercondX += `<b>Zone</b> - (${zoneTxt.join(", ")}) || `;
                    }
                    if(tierLengthY != 0)
                    {
                        condX += `Q2D IN (${tierVal}) AND `
                        filtercondX += `<b>Tier</b> - (${tierTxt.join(", ")}) || `;
                    }
                    if(architectLengthY != 0)
                    {
                        condX += `Good_Architect IN (${architectVal}) AND `
                        filtercondX += `<b>Good Architect</b> - (${architectTxt.join(", ")}) || `;
                    }
                    if(accountLengthY != 0)
                    {
                        condX += `Account_Type IN (${accountVal}) AND `
                        filtercondX += `<b>Account Type</b> - (${accountTxt.join(", ")}) || `;
                    }
                    condX += ` 1=1`;
                }
                else
                {
                    filtercondX += `<span class="boldC">Filters</span>: Overall`;
                    condX += ` 1=1`;
                }
                ////console.log(condX);
                filtercondX = filtercondX.replace(/\|\| $/, '');
                $(".paraY").empty().append(filtercondX);
                fetchBase();
                firstAjax();
                thirdAjax();
                if(domainDropCvalX != '0')
                {
                    secondAjax();
                }
                if(domainDropC2valX != '0')
                {
                    forthAjax();
                }
                if(domainDropC3valX!=0)
                {
                    fifthAjax();
                }
            }

            function fetchMonth()
            {
                $.ajax({
                    url: "api/month.php",
                    type: "POST",
                    async: false,
                    success: function(response) {
                        debugger;
                        var data = JSON.parse(response);
                        console.log(data);
                        //normalmonthX = data['Month_1'].reverse();
                        trendsmonthX = data['Month_2'];

                        trendsmonthLabelX = [];
                        //normalmonthLabelX = [];
                        //normalmonthX.forEach(function(e,i,a){
                        //    normalmonthLabelX.push(monthLabel[e-2]);
                        //});

                        var html = ``;
                        html += `<option value="0">-SELECT MONTH-</option>`
                        trendsmonthX.forEach(function(e,i,a){
                            trendsmonthLabelX.push(monthLabel[i]);
                            html += `<option value="${e}">${monthLabel[i]}</option>`
                        });
                        debugger;
                        $("#vocmonthdelete").empty().append(html);
                        $("#vocmonth").empty().append(html);
                        $("#monthSelect").empty().append(html);
                        $("#cmd").empty().append(html);
                        $("#cmd option:last").prop("selected", true);

                        $("#pmd").empty().append(html);
                        $("#pmd option").eq(-2).prop("selected", true);

                        normalmonthX = [
                            $("#pmd").val(),
                            $("#cmd").val() 
                        ];

                        normalmonthLabelX = [];
                        normalmonthX.forEach(function(e,i,a){
                           normalmonthLabelX.push(monthLabel[e-1]);
                        });

                        console.log(normalmonthX);
                        console.log(normalmonthLabelX);

                        // normalmonthX = [1,1];
                        // trendsmonthX = [1,1];

                        // normalmonthLabelX = ["M1","M1"];
                        // trendsmonthLabelX = ["M1","M1"];

                        
                    }
                });
            }

            function fetchBase()
            {
                $.ajax({
                    url: "api/base.php",
                    type: "POST",
                    data: {
                        'condX' : condX,
                        'conX' : conX,
                        'normalmonthX' : normalmonthX
                    },
                    success: function(response) {
                        debugger;
                        var data = JSON.parse(response);
                        //console.log("base");
                        //console.log(data);
                        $("#overallBase").empty().append(`<span class="boldC">Sample Size:</span> ${data[0]}`);
                        
                        $("#currentmonthname").empty().append(`${normalmonthLabelX[1]}`);
                        $("#currentmonthbase").empty().append(`${data[2]}`);

                        $("#currentmonthname2").empty().append(`${normalmonthLabelX[1]}`);
                        $("#currentmonthbase2").empty().append(`${data[2]}`);
                        
                        $("#previousmonthbase").empty().append(`${data[1]}`);
                        $("#previousmonthname").empty().append(`${normalmonthLabelX[0]}`);

                        $("#previousmonthbase2").empty().append(`${data[1]}`);
                        $("#previousmonthname2").empty().append(`${normalmonthLabelX[0]}`);
                        
                        
                    }
                });
            }

            function firstAjax()
            {
                //console.log(normalmonthX);
                $.ajax({
                    url: "api/ajax1.php",
                    type: "POST",
                    data: {
                        'condX' : condX,
                        'conX' : conX,
                        'normalmonthX' : normalmonthX
                    },
                    success: function(response) {
                        var data = JSON.parse(response);

                        //console.log("ajax1data");
                        //console.log(data);

                        var dataOverall = [data[0]];
                        var dataDomain = [data[1]];

                        //console.log("ajax1");
                        //console.log(dataDomain);

                        var overallflipkartCurrentNPS = [];
                        var overallamazonCurrentNPS = [];
                        var overallmeeshoCurrentNPS = [];
                        var overallflipkartPreviousNPS = [];
                        var overallamazonPreviousNPS = [];
                        var overallmeeshoPreviousNPS = [];

                        var domainflipkartCurrentNPS = [];
                        var domainamazonCurrentNPS = [];
                        var domainmeeshoCurrentNPS = [];
                        var domainflipkartPreviousNPS = [];
                        var domainamazonPreviousNPS = [];
                        var domainmeeshoPreviousNPS = [];

                        domainflipkartCurrentBASE = [];
                        domainamazonCurrentBASE = [];
                        domainmeeshoCurrentBASE = [];

                        var overallcurrentWave = [];
                        var overallpreviousWave = [];

                        var domaincurrentWave = [];
                        var domainpreviousWave = [];

                        dataOverall.forEach(function(e,i,a){
                            overallflipkartCurrentNPS.push(e['overallflipkartCurrentNPS']);
                            overallamazonCurrentNPS.push(e['overallamazonCurrentNPS']);
                            overallmeeshoCurrentNPS.push(e['overallmeeshoCurrentNPS']);
                            overallflipkartPreviousNPS.push(e['overallflipkartPreviousNPS']);
                            overallamazonPreviousNPS.push(e['overallamazonPreviousNPS']);
                            overallmeeshoPreviousNPS.push(e['overallmeeshoPreviousNPS']);
                        });

                        dataDomain.forEach(function(e,i,a){
                            e.CurrentNPS.forEach(function(e2,i2,a2){
                                domainflipkartCurrentNPS.push(e2[0].nps);
                                domainamazonCurrentNPS.push(e2[1].nps);
                                domainmeeshoCurrentNPS.push(e2[2].nps);

                                domainflipkartCurrentBASE.push(e2[0].base);
                                domainamazonCurrentBASE.push(e2[1].base);
                                domainmeeshoCurrentBASE.push(e2[2].base);
                            });

                            e.PreviousNPS.forEach(function(e2,i2,a2){
                                domainflipkartPreviousNPS.push(e2[0].nps);
                                domainamazonPreviousNPS.push(e2[1].nps);
                                domainmeeshoPreviousNPS.push(e2[2].nps);
                            });
                        });

                        overallcurrentWave.push(overallflipkartCurrentNPS);
                        overallcurrentWave.push(overallamazonCurrentNPS);
                        overallcurrentWave.push(overallmeeshoCurrentNPS);

                        overallpreviousWave.push(overallflipkartPreviousNPS);
                        overallpreviousWave.push(overallamazonPreviousNPS);
                        overallpreviousWave.push(overallmeeshoPreviousNPS);

                        domaincurrentWave.push(domainflipkartCurrentNPS);
                        domaincurrentWave.push(domainamazonCurrentNPS);
                        domaincurrentWave.push(domainmeeshoCurrentNPS);

                        domainpreviousWave.push(domainflipkartPreviousNPS);
                        domainpreviousWave.push(domainamazonPreviousNPS);
                        domainpreviousWave.push(domainmeeshoPreviousNPS);

                        var transposeoverallcurrentWave = transposeData(overallcurrentWave);
                        var transposeoverallpreviousWave = transposeData(overallpreviousWave);

                        var transposedomaincurrentWave = transposeData(domaincurrentWave);
                        var transposedomainpreviousWave = transposeData(domainpreviousWave);

                        var difference2 = calculateDifference(transposeoverallcurrentWave[0], transposeoverallpreviousWave[0]);
                        var difference = calculateDifference(transposedomaincurrentWave, transposedomainpreviousWave);

                        overallcurrentWave.forEach(function(e,i,a){
                            e.forEach(function(e2,i2,a2){
                                $(`#nps_count_C_${i2+1}_${i+1}`).empty().append(e2[4]);
                                $(`#promoterTd_C_${i2+1}_${i+1}`).empty().append(`${e2[1]}%`);
                                $(`#passiveTd_C_${i2+1}_${i+1}`).empty().append(`${e2[2]}%`);
                                $(`#detractorTd_C_${i2+1}_${i+1}`).empty().append(`${e2[3]}%`);
                            });
                        });

                        transposedomaincurrentWave.forEach(function(e,i,a){
                            e.forEach(function(e2,i2,a2){
                                $(`#nps_count_C_${i+2}_${i2+1}`).empty().append(e2);
                            });
                        });

                        difference.forEach(function(e,i,a){
                            e.forEach(function(e2,i2,a2){
                                ////////////console.log(`#nps_count_P_${i + 2}_${i2 + 1}`);
                                const $element = $(`#nps_count_P_${i + 2}_${i2 + 1}`);
                                $element.empty().append(e2);

                                $element.removeClass('negativeX positiveX neutralX');

                                if (e2 < 0) {
                                    $element.addClass('negativeX');
                                } else if (e2 > 0) {
                                    $element.addClass('positiveX');
                                } else if (e2 == 0) {
                                    $element.addClass('blankX');
                                }
                                else {
                                    $element.addClass('blankX');
                                }

                            });
                        });

                        difference2.forEach(function(e,i,a){
                            $(`#nps_count_P_1_${i+1}`).empty().append(`${e[4]}`);
                            $(`#promoterTd_P_1_${i+1}`).empty().append(`${e[1]}%`);
                            $(`#passiveTd_P_1_${i+1}`).empty().append(`${e[2]}%`);
                            $(`#detractorTd_P_1_${i+1}`).empty().append(`${e[3]}%`);
                        });

                        // difference2.forEach(function(e,i,a){
                        //     $(`#nps_count_P_1_${i+1}`).empty().append(`-`);
                        //     $(`#promoterTd_P_1_${i+1}`).empty().append(`-`);
                        //     $(`#passiveTd_P_1_${i+1}`).empty().append(`-`);
                        //     $(`#detractorTd_P_1_${i+1}`).empty().append(`-`);
                        // });

                        $("#nps_count_C_11_3").empty().append(`-`);
                        $("#nps_count_P_11_3").empty().append(`-`);

                    },complete: function (data) 
                    {
                        $(".splash").hide();
                    }
                });
            }

            function secondAjax()
            {
                $.ajax({
                    url: "api/ajax2.php",
                    type: "POST",
                    data: {
                        'condX' : condX,
                        'conX' : conX,
                        'normalmonthX' : normalmonthX,
                        'domainDropCvalX' : domainDropCvalX
                    },
                    success: function(response) {
                        var data = JSON.parse(response);
                        //console.log("ajax2");
                        //console.log(data);
                        var PreviousNPS = [];
                        var CurrentNPS = [];
                        var PreviousNPSX = [];
                        var CurrentNPSX = [];

                        $("#domainbasedivF").empty().append(`<b>FK Overall</b> (Base: ${domainflipkartCurrentBASE[parseInt(domainDropCvalX)-2]})`);
                        $("#domainbasedivA").empty().append(`<b>AZ Overall</b> (Base: ${domainamazonCurrentBASE[parseInt(domainDropCvalX)-2]})`);
                        $("#domainbasedivM").empty().append(`<b>MS Overall</b> (Base: ${domainmeeshoCurrentBASE[parseInt(domainDropCvalX)-2]})`);

                        data.forEach(function(e,i,a){
                            PreviousNPS.push(data[i]['PreviousNPS']);
                            CurrentNPS.push(data[i]['CurrentNPS']);
                        });

                        var PreviousNPSX = PreviousNPS[0];
                        var CurrentNPSX = CurrentNPS[0];

                        var PreviousnpsValues = PreviousNPSX.map(subArray => 
                            subArray.map(item => item.nps)
                        );

                        var CurrentnpsValues = CurrentNPSX.map(subArray => 
                            subArray.map(item => item.nps)
                        );

                        CurrentbaseValues = CurrentNPSX.map(subArray => 
                            subArray.map(item => item.base)
                        );

                        $("#domainbasedivF2").empty().append(`<b>FK</b> (Base: ${CurrentbaseValues[0][0]})`);
                        $("#domainbasedivA2").empty().append(`<b>AZ</b> (Base: ${CurrentbaseValues[0][1]})`);
                        $("#domainbasedivM2").empty().append(`<b>MS</b> (Base: ${CurrentbaseValues[0][2]})`);

                        var difference = calculateDifference(CurrentnpsValues, PreviousnpsValues);

                        CurrentNPSX.forEach(function(e,i,a){
                            e.forEach(function(e2,i2,a2){
                                $(`#nps_count_SDC_${brandLabel[i2]}_${i+1}`).empty().append(e2.nps);
                            });
                        });

                        PreviousNPSX.forEach(function(e,i,a){
                            e.forEach(function(e2,i2,a2){
                                $(`#nps_count_SDP_${brandLabel[i2]}_${i+1}`).empty().append(e2.nps);
                            });
                        });

                        difference.forEach(function(e,i,a){
                            e.forEach(function(e2,i2,a2){
                                const $element = $(`#nps_count_SDP_${brandLabel[i2]}_${i+1}`);
                                $element.empty().append(e2);
                                //$element.empty().append(`-`);

                                $element.removeClass('negativeX positiveX neutralX');

                                // Add class based on value
                                if (e2 < 0) {
                                    $element.addClass('negativeX');
                                } else if (e2 > 0) {
                                    $element.addClass('positiveX');
                                } else if (e2 == 0) {
                                    $element.addClass('blankX');
                                }
                                else {
                                    $element.addClass('blankX');
                                }
                            });
                        });

                        if(domainDropCvalX=="2")
                        {
                            $("#nps_count_SDC_Filpkart_3").empty().append(`-`);
                            $("#nps_count_SDC_Amazon_3").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_3").empty().append(`-`);

                            $("#nps_count_SDC_Filpkart_4").empty().append(`-`);
                            $("#nps_count_SDC_Amazon_4").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_4").empty().append(`-`);

                            $("#nps_count_SDC_Filpkart_8").empty().append(`-`);
                            $("#nps_count_SDC_Amazon_8").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_8").empty().append(`-`);

                            $("#nps_count_SDP_Filpkart_3").empty().append(`-`);
                            $("#nps_count_SDP_Amazon_3").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_3").empty().append(`-`);

                            $("#nps_count_SDP_Filpkart_4").empty().append(`-`);
                            $("#nps_count_SDP_Amazon_4").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_4").empty().append(`-`);

                            $("#nps_count_SDP_Filpkart_8").empty().append(`-`);
                            $("#nps_count_SDP_Amazon_8").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_8").empty().append(`-`);
                        }
                        if(domainDropCvalX=="4")
                        {
                            $("#nps_count_SDC_Filpkart_2").empty().append(`-`);
                            $("#nps_count_SDC_Amazon_2").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_2").empty().append(`-`);

                            $("#nps_count_SDC_Filpkart_4").empty().append(`-`);
                            $("#nps_count_SDC_Amazon_4").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_4").empty().append(`-`);

                            $("#nps_count_SDP_Filpkart_2").empty().append(`-`);
                            $("#nps_count_SDP_Amazon_2").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_2").empty().append(`-`);

                            $("#nps_count_SDP_Filpkart_4").empty().append(`-`);
                            $("#nps_count_SDP_Amazon_4").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_4").empty().append(`-`);
                        }
                        if(domainDropCvalX=="9")
                        {
                            $("#nps_count_SDC_Filpkart_4").empty().append(`-`);
                            $("#nps_count_SDC_Amazon_4").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_4").empty().append(`-`);

                            $("#nps_count_SDC_Filpkart_6").empty().append(`-`);
                            $("#nps_count_SDC_Amazon_6").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_6").empty().append(`-`);

                            $("#nps_count_SDP_Filpkart_4").empty().append(`-`);
                            $("#nps_count_SDP_Amazon_4").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_4").empty().append(`-`);

                            $("#nps_count_SDP_Filpkart_6").empty().append(`-`);
                            $("#nps_count_SDP_Amazon_6").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_6").empty().append(`-`);

                            $("#nps_count_SDC_Filpkart_10").empty().append(`LB`);
                            $("#nps_count_SDC_Amazon_10").empty().append(`LB`);
                            $("#nps_count_SDC_Meesho_10").empty().append(`-`);
                            $("#nps_count_SDC_Filpkart_11").empty().append(`LB`);
                            $("#nps_count_SDC_Amazon_11").empty().append(`LB`);
                            $("#nps_count_SDC_Meesho_11").empty().append(`-`);
                            
                            $("#nps_count_SDP_Filpkart_10").empty().append(`LB`);
                            $("#nps_count_SDP_Amazon_10").empty().append(`LB`);
                            $("#nps_count_SDP_Meesho_10").empty().append(`-`);
                            $("#nps_count_SDP_Filpkart_11").empty().append(`LB`);
                            $("#nps_count_SDP_Amazon_11").empty().append(`LB`);
                            $("#nps_count_SDP_Meesho_11").empty().append(`-`);

                            $("#nps_count_SDC_Filpkart_10").addClass("redcolor");
                            $("#nps_count_SDC_Amazon_10").addClass("redcolor");
                            $("#nps_count_SDC_Meesho_10").addClass("redcolor");
                            $("#nps_count_SDC_Filpkart_11").addClass("redcolor");
                            $("#nps_count_SDC_Amazon_11").addClass("redcolor");
                            $("#nps_count_SDC_Meesho_11").addClass("redcolor");
                            
                            $("#nps_count_SDP_Filpkart_10").addClass("redcolor");
                            $("#nps_count_SDP_Amazon_10").addClass("redcolor");
                            $("#nps_count_SDP_Meesho_10").addClass("redcolor");
                            $("#nps_count_SDP_Filpkart_11").addClass("redcolor");
                            $("#nps_count_SDP_Amazon_11").addClass("redcolor");
                            $("#nps_count_SDP_Meesho_11").addClass("redcolor");

                            // $("#LBTEXT").show();
                            $("#LBTEXT2").show();
                        }
                        else
                        {
                            // $("#LBTEXT").hide();
                            $("#LBTEXT2").hide();
                        }

                        if(domainDropCvalX=="11")
                        {
                            $("#nps_count_SDC_Meesho_1").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_2").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_3").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_4").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_5").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_6").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_7").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_8").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_9").empty().append(`-`);
                            $("#nps_count_SDC_Filpkart_9").empty().append(`-`);
                            $("#nps_count_SDC_Amazon_9").empty().append(`-`);
                            $("#nps_count_SDC_Meesho_9").empty().append(`-`);

                            $("#nps_count_SDP_Meesho_1").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_2").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_3").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_4").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_5").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_6").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_7").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_8").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_9").empty().append(`-`);
                            $("#nps_count_SDP_Filpkart_9").empty().append(`-`);
                            $("#nps_count_SDP_Amazon_9").empty().append(`-`);
                            $("#nps_count_SDP_Meesho_9").empty().append(`-`);
                        }
                    },
                    complete: function (data) 
                    {
                        setTimeout(() => {
                            $(".splash").hide();
                        }, 200);
                        
                    }
                });
            }

            function thirdAjax()
            {
                $.ajax({
                    url: "api/ajax3.php",
                    type: "POST",
                    data: {
                        'condX' : condX,
                        'conX' : conX,
                        'trendsmonthX' : trendsmonthX
                    },
                    success: function(response) {
                        var data = JSON.parse(response);
                        //console.log(data);
                        var flipkartData = data[0]['overallflipkartNPS'];
                        var amazonData = data[0]['overallamazonNPS'];
                        var meeshoData = data[0]['overallmeeshoNPS'];

                        var flipkartV = [];
                        var amazonV = [];
                        var meeshoV = [];
                        var overallTrendData = [];
                        var overallTrendDataX = [];

                        extractValues(flipkartData,flipkartV,"Simple");
                        extractValues(amazonData,amazonV,"Simple");
                        extractValues(meeshoData,meeshoV,"Simple");
                        
                        overallTrendData.push(flipkartV);
                        overallTrendData.push(amazonV);
                        overallTrendData.push(meeshoV);

                        var cl = ['#C07B60','#FFAD33','#FF33BB','#B1DCD3','#74A9CE','#A6BCDB','#D0D0E7'];

                        customizedArray(overallTrendData,overallTrendDataX,brandLabel,cl,"Line");
                        lineChart(overallTrendDataX,"overall_charts_trends",trendsmonthLabelX);

                        var tbltbody1 = ``;
                        ////////console.log("overallTrendData");
                        ////////console.log(overallTrendData);

                        debugger;
                        tbltbody1 += `<tr><th></th>`;
                            brandLabel.forEach(function(e2,i2,a2){
                                trendsmonthLabelX.forEach(function(e,i,a){
                                    tbltbody1 += `<td class="waveX" style="font-size:0.7rem">${e}</td>`;
                                });
                            })
                        tbltbody1 += `</tr>`;

                        tbltbody1 += `<tr><th class="tbodyCat main_td">Overall</th>`;
                        overallTrendData.forEach(function(e2,i2,a2){
                            e2.forEach(function(e3,i3,a3){
                                tbltbody1 += `<td class="dashed_border" style="font-size:0.7rem">${e3}</td>`;
                            })
                        });
                        tbltbody1 += `</tr>`;

                        $("#overall_tbl_trends > tbody").empty().append(tbltbody1);


                    },complete: function (data) 
                    {
                        $(".splash").hide();
                    }
                });
            }

            function forthAjax()
            {
                $.ajax({
                    url: "api/ajax4.php",
                    type: "POST",
                    data: {
                        'condX' : condX,
                        'conX' : conX,
                        'trendsmonthX' : trendsmonthX,
                        'domainDropC2valX' : domainDropC2valX
                    },
                    success: function(response) {
                        var data = JSON.parse(response);
                        //console.log("dataT");
                        //console.log(data);
                        var currentData = data[0]['CurrentNPS'];
                        var previousData = data[0]['PreviousNPS'];

                        var currentData2 = data[1]['CurrentNPS2'];
                        var previousData2 = data[1]['PreviousNPS2'];

                        var currentBaseArr = [];
                        debugger;
                        currentData2[0].forEach(function(e,i,a){
                            var arrayV2 = [];
                            e.forEach(function(e2,i2,a2){
                                arrayV2.push(e2.baseCount);
                            });
                            currentBaseArr.push(arrayV2);
                        });

                        //console.log("currentBaseArr");
                        //console.log(currentBaseArr);

                        $("#domainbasedivF3").empty().append(`<b>FK Overall</b> (Base: ${domainflipkartCurrentBASE[parseInt(domainDropC2valX)-2]})`);
                        $("#domainbasedivA3").empty().append(`<b>AZ Overall</b> (Base: ${domainamazonCurrentBASE[parseInt(domainDropC2valX)-2]})`);
                        $("#domainbasedivM3").empty().append(`<b>MS Overall</b> (Base: ${domainmeeshoCurrentBASE[parseInt(domainDropC2valX)-2]})`);

                        $("#domainbasedivF4").empty().append(`<b>FK</b> (Base: ${currentBaseArr[0][0]})`);
                        $("#domainbasedivA4").empty().append(`<b>AZ</b> (Base: ${currentBaseArr[1][0]})`);
                        $("#domainbasedivM4").empty().append(`<b>MS</b> (Base: ${currentBaseArr[2][0]})`);

                        previousData.push(...currentData);
                        previousData2.push(...currentData2);

                        var domainTrendData = [];
                        var domainTrendDataX = [];

                        var subdomainTrendData = [];

                        var cl = ['#C07B60','#FFAD33','#FF33BB','#B1DCD3','#74A9CE','#A6BCDB','#D0D0E7'];

                        extractValues(previousData,domainTrendData,"Trends");

                        ////console.log(previousData2);
                        
                        previousData2.forEach(function(e,i,a){
                            var subdomainTrendDataX2 = [];
                            extractValues(e,subdomainTrendDataX2,"Trends");
                            subdomainTrendData.push(subdomainTrendDataX2);
                        })

                        console.log("subdomainTrendData");
                        console.log(subdomainTrendData);

                        var subdomainTrendDataresult = [];
                        
                        for(var i=0; i<3;i++)
                        {
                            debugger;
                            for(var j=0; j<subdomainTrendData.length;j++) // change here only
                            {
                                subdomainTrendDataresult.push(subdomainTrendData[j][i])
                            }
                        }

                        var transposeddomainTrendData = transposeData(domainTrendData);
                        var transposedsubdomainTrendData = transposeData(subdomainTrendDataresult);
                        
                        customizedArray(transposeddomainTrendData,domainTrendDataX,brandLabel,cl,"Line");

                        lineChart(domainTrendDataX,"domain_charts_trends",trendsmonthLabelX);

                        var tbltbody1 = ``;
                        var tbltbody2 = ``;
                        var domainLabelX = domainLabel[domainDropC2valX-1];
                        var subdomainLabelX = subdomainLabel[domainDropC2valX-2];

                        // // colspan dekho

                            tbltbody1 += `<tr><th></th>`;
                                brandLabel.forEach(function(e2,i2,a2){
                                    trendsmonthLabelX.forEach(function(e,i,a){
                                        tbltbody1 += `<td class="waveX" style="font-size:0.7rem">${e}</td>`;
                                    });
                                })
                            tbltbody1 += `</tr>`;

                            tbltbody1 += `<tr><th class="tbodyCat main_td">${domainLabelX}</th>`;
                            transposeddomainTrendData.forEach(function(e2,i2,a2){
                                e2.forEach(function(e3,i3,a3){
                                    tbltbody1 += `<td class="dashed_border" style="font-size:0.7rem">${e3}</td>`;
                                })
                            });
                            tbltbody1 += `</tr>`;

                            tbltbody2 += `<tr><th></th>`;
                                brandLabel.forEach(function(e2,i2,a2){
                                    trendsmonthLabelX.forEach(function(e,i,a){
                                        tbltbody2 += `<td class="waveX" style="font-size:0.7rem">${e}</td>`;
                                    });
                                })
                            tbltbody2 += `</tr>`;

                            tbltbody2 += `<tr><th class="tbodyCat main_td">${domainLabelX}</th>`;
                            transposeddomainTrendData.forEach(function(e2,i2,a2){
                                e2.forEach(function(e3,i3,a3){
                                    tbltbody2 += `<td class="dashed_border" style="font-size:0.7rem">${e3}</td>`;
                                })
                            });
                            tbltbody2 += `</tr>`;
                        
                            subdomainLabelX.forEach(function(e,i,a){
                                tbltbody2 += `<tr><th class="tbodyCat">${e}</th>`;
                                transposedsubdomainTrendData[i].forEach(function(e2,i2,a2){
                                    tbltbody2 += `<td class="dashed_border" style="font-size:0.7rem">${e2}</td>`;
                                });
                                tbltbody2 += `</tr>`;
                            }); 
                            
                        $("#domain_tbl_trends > tbody").empty().append(tbltbody1);
                        $("#subdomain_tbl_trends > tbody").empty().append(tbltbody2);

                        if(domainDropC2valX=="11")
                        {
                            $('#domain_tbl_trends > tbody').find("tr").each(function(i,e,a){
                                if(i != 0)
                                {
                                    $(e).find("td").eq(4).empty().append('-');
                                    $(e).find("td").eq(5).empty().append('-')
                                }
                            })

                            $('#subdomain_tbl_trends > tbody').find("tr").each(function(i,e,a){
                                if(i != 0)
                                {
                                    $(e).find("td").eq(4).empty().append('-');
                                    $(e).find("td").eq(5).empty().append('-')
                                }
                            })
                        }

                        // if(domainDropC2valX=="9")
                        // {
                        //     $('#subdomain_tbl_trends > tbody').find("tr").each(function(i,e,a){
                        //         if(i == 7)
                        //         {
                        //             $(e).find("td").each(function(){
                        //                 $(this).empty().append('LB');
                        //             })
                        //         }
                        //     })
                        // }

                    },complete: function (data) 
                    {
                        $(".splash").hide();
                    }
                });
            }

            function fifthAjax()
            {
                var domainLabelX = domainLabel[domainDropC3valX-1];
                $.ajax({
                    url: "api/ajax5.php",
                    type: "POST",
                    data: {
                        'condX' : condX,
                        'conX' : conX,
                        'normalmonthX' : normalmonthX,
                        'vocMonth' : vocMonth,
                        'domainDropC3valX' : domainDropC3valX,
                        'domainLabelX' : domainLabelX
                    },
                    success: function(response) {
                        var data = JSON.parse(response);
                        var CurrentNPSX = data['CurrentNPS'][0];
                        var wordCloudArr = data['wordcloud'];
                        console.log(wordCloudArr);
                        var lucifer = [
                            {
                                "name": "Promoter",
                                "y": CurrentNPSX[0].promoter,
                                "color":"#006620"
                            },
                            {
                                "name": "Passive",
                                "y": CurrentNPSX[0].passive,
                                "color":"#A58E1A"
                            },
                            {
                                "name": "Detractor",
                                "y": CurrentNPSX[0].detractor,
                                "color":"#C00000"
                            }
                        ];

                        var lucifer2 = [
                            {
                                "name": "Promoter",
                                "y": CurrentNPSX[1].promoter,
                                "color":"#006620"
                            },
                            {
                                "name": "Passive",
                                "y": CurrentNPSX[1].passive,
                                "color":"#A58E1A"
                            },
                            {
                                "name": "Detractor",
                                "y": CurrentNPSX[1].detractor,
                                "color":"#C00000"
                            }
                        ];

                        var lucifer3 = [
                            {
                                "name": "Promoter",
                                "y": CurrentNPSX[2].promoter,
                                "color":"#006620"
                            },
                            {
                                "name": "Passive",
                                "y": CurrentNPSX[2].passive,
                                "color":"#A58E1A"
                            },
                            {
                                "name": "Detractor",
                                "y": CurrentNPSX[2].detractor,
                                "color":"#C00000"
                            }
                        ];

                        doughnutChart(lucifer,"flipkart_voc_chart1","Percentage",CurrentNPSX[0].nps);
                        doughnutChart(lucifer,"flipkart_voc_chart2","Percentage",CurrentNPSX[0].nps);
                        doughnutChart(lucifer,"flipkart_voc_chart3","Percentage",CurrentNPSX[0].nps);
                        doughnutChart(lucifer,"flipkart_voc_chart4","Percentage",CurrentNPSX[0].nps);

                        doughnutChart(lucifer2,"amazon_voc_chart1","Percentage",CurrentNPSX[1].nps);
                        doughnutChart(lucifer2,"amazon_voc_chart2","Percentage",CurrentNPSX[1].nps);
                        doughnutChart(lucifer2,"amazon_voc_chart3","Percentage",CurrentNPSX[1].nps);
                        doughnutChart(lucifer2,"amazon_voc_chart4","Percentage",CurrentNPSX[1].nps);

                        doughnutChart(lucifer3,"meesho_voc_chart1","Percentage",CurrentNPSX[2].nps);
                        doughnutChart(lucifer3,"meesho_voc_chart2","Percentage",CurrentNPSX[2].nps);
                        doughnutChart(lucifer3,"meesho_voc_chart3","Percentage",CurrentNPSX[2].nps);
                        doughnutChart(lucifer3,"meesho_voc_chart4","Percentage",CurrentNPSX[2].nps);

                        function getTopAndBottomWords(wordsArray) {
                            const frequencyMap = {};

                            for (const item of wordsArray) {
                                frequencyMap[item] = (frequencyMap[item] || 0) + 1;
                            }

                            const sortedByFrequency = Object.entries(frequencyMap).sort((a, b) => b[1] - a[1]);
                            const top3 = sortedByFrequency.slice(0, 3);
                            const bottom3 = sortedByFrequency.slice(-3);

                            return { top3, bottom3 };
                        }


                        function renderTopBottomWords(top3, bottom3, divId) {
                            let html = ``;
                            html += `<strong>Top 3 Phrases:</strong> `;
                            top3.forEach(([word, count]) => {
                                html += `${word}: ${count},&nbsp;&nbsp;`;
                            });

                            // html += `<br><strong>Bottom 3:</strong> `;
                            // bottom3.forEach(([word, count]) => {
                            //     html += `${word}: ${count},&nbsp;&nbsp;`;
                            // });

                            $(`#${divId}`).empty().append(html);
                        }

                        const { top3: flipkart1top3, bottom3: flipkart1bottom3 } = getTopAndBottomWords(wordCloudArr[0][0]);
                        const { top3: flipkart2top3, bottom3: flipkart2bottom3 } = getTopAndBottomWords(wordCloudArr[0][1]);
                        const { top3: flipkart3top3, bottom3: flipkart3bottom3 } = getTopAndBottomWords(wordCloudArr[0][2]);
                        const { top3: flipkart4top3, bottom3: flipkart4bottom3 } = getTopAndBottomWords(wordCloudArr[0][3]);

                        $(".occur").each(function(){
                            $(this).show();
                        })
                        renderTopBottomWords(flipkart1top3, flipkart1bottom3, "flipkart_occur_1");
                        renderTopBottomWords(flipkart2top3, flipkart2bottom3, "flipkart_occur_2");
                        renderTopBottomWords(flipkart3top3, flipkart3bottom3, "flipkart_occur_3");
                        renderTopBottomWords(flipkart4top3, flipkart4bottom3, "flipkart_occur_4");

                        const { top3: amazon1top3, bottom3: amazon1bottom3 } = getTopAndBottomWords(wordCloudArr[1][0]);
                        const { top3: amazon2top3, bottom3: amazon2bottom3 } = getTopAndBottomWords(wordCloudArr[1][1]);
                        const { top3: amazon3top3, bottom3: amazon3bottom3 } = getTopAndBottomWords(wordCloudArr[1][2]);
                        const { top3: amazon4top3, bottom3: amazon4bottom3 } = getTopAndBottomWords(wordCloudArr[1][3]);

                        renderTopBottomWords(amazon1top3, amazon1bottom3, "amazon_occur_1");
                        renderTopBottomWords(amazon2top3, amazon2bottom3, "amazon_occur_2");
                        renderTopBottomWords(amazon3top3, amazon3bottom3, "amazon_occur_3");
                        renderTopBottomWords(amazon4top3, amazon4bottom3, "amazon_occur_4");

                        const { top3: meesho1top3, bottom3: meesho1bottom3 } = getTopAndBottomWords(wordCloudArr[2][0]);
                        const { top3: meesho2top3, bottom3: meesho2bottom3 } = getTopAndBottomWords(wordCloudArr[2][1]);
                        const { top3: meesho3top3, bottom3: meesho3bottom3 } = getTopAndBottomWords(wordCloudArr[2][2]);
                        const { top3: meesho4top3, bottom3: meesho4bottom3 } = getTopAndBottomWords(wordCloudArr[2][3]);

                        renderTopBottomWords(meesho1top3, meesho1bottom3, "meesho_occur_1");
                        renderTopBottomWords(meesho2top3, meesho2bottom3, "meesho_occur_2");
                        renderTopBottomWords(meesho3top3, meesho3bottom3, "meesho_occur_3");
                        renderTopBottomWords(meesho4top3, meesho4bottom3, "meesho_occur_4");

                        wordChart(wordCloudArr[0][0],"flipkart_word_cloud_all_container","rgba(60,170,200,");
                        wordChart(wordCloudArr[0][1],"flipkart_word_cloud_promoter_container","rgba(51, 153, 51,");
                        wordChart(wordCloudArr[0][2],"flipkart_word_cloud_passive_container","rgba(255, 153, 0,");
                        wordChart(wordCloudArr[0][3],"flipkart_word_cloud_detractor_container","rgba(204, 0, 0,");
                        wordChart(wordCloudArr[1][0],"amazon_word_cloud_all_container","rgba(60,170,200,");
                        wordChart(wordCloudArr[1][1],"amazon_word_cloud_promoter_container","rgba(51, 153, 51,");
                        wordChart(wordCloudArr[1][2],"amazon_word_cloud_passive_container","rgba(255, 153, 0,");
                        wordChart(wordCloudArr[1][3],"amazon_word_cloud_detractor_container","rgba(204, 0, 0,");
                        wordChart(wordCloudArr[2][0],"meesho_word_cloud_all_container","rgba(60,170,200,");
                        wordChart(wordCloudArr[2][1],"meesho_word_cloud_promoter_container","rgba(51, 153, 51,");
                        wordChart(wordCloudArr[2][2],"meesho_word_cloud_passive_container","rgba(255, 153, 0,");
                        wordChart(wordCloudArr[2][3],"meesho_word_cloud_detractor_container","rgba(204, 0, 0,");
                    },complete: function (data) 
                    {
                        $(".splash").hide();
                    }

                });
            }

            function fetchComment(wordX)
            {
                var domainLabelX = domainLabel[domainDropC3valX-1];
                var commentTbl = "voc";
                $.ajax({
                    url: "api/comment.php",
                    type: "POST",
                    data: {
                        'condX' : condX,
                        'conX' : conX,
                        'tblX' : commentTbl,
                        'wordX' : wordX,
                        'vocMonth' : vocMonth,
                        'domainLabelX' : domainLabelX
                    },
                    success: function(response) {
                        var data = JSON.parse(response);
                        console.log("verbatim");
                        console.log(data);

                        var flipkartVerbatim = data['verbatim'][0];
                        var amazonVerbatim = data['verbatim'][1];
                        var meeshoVerbatim = data['verbatim'][2];
                        console.log(flipkartVerbatim)

                        var html = ``;
                        var html2 = ``;
                        var html3 = ``;
                        var html4 = ``;
                        var html5 = ``;
                        var html6 = ``;
                        var html7 = ``;
                        var html8 = ``;
                        var html9 = ``;
                        var html10 = ``;
                        var html11 = ``;
                        var html12 = ``;

                        html  += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${flipkartVerbatim[0].length}</th></tr>`;
                        // html  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Neutral</th></tr>`;
                        html2 += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${flipkartVerbatim[1].length}</th></tr>`;
                        // html2  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Positive</th></tr>`;
                        html3 += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${flipkartVerbatim[2].length}</th></tr>`;
                        // html3  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Neutral</th></tr>`;
                        html4 += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${flipkartVerbatim[3].length}</th></tr>`;
                        // html4  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Negative</th></tr>`;

                        html5  += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${amazonVerbatim[0].length}</th></tr>`;
                        // html5  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Neutral</th></tr>`;
                        html6 += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${amazonVerbatim[1].length}</th></tr>`;
                        // html6  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Positive</th></tr>`;
                        html7 += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${amazonVerbatim[2].length}</th></tr>`;
                        // html7  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Neutral</th></tr>`;
                        html8 += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${amazonVerbatim[3].length}</th></tr>`;
                        // html8  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Negative</th></tr>`;

                        html9  += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${meeshoVerbatim[0].length}</th></tr>`;
                        // html9  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Neutral</th></tr>`;
                        html10 += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${meeshoVerbatim[1].length}</th></tr>`;
                        // html10  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Positive</th></tr>`;
                        html11 += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${meeshoVerbatim[2].length}</th></tr>`;
                        // html11  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Neutral</th></tr>`;
                        html12 += `<tr><th style="width:50%;font-size:0.8rem;">Word: ${wordX}</th><th style="width:50%;font-size:0.8rem;">Count: ${meeshoVerbatim[3].length}</th></tr>`;
                        // html12  += `<tr><th style="width:100%;font-size:0.8rem" colspan="2">Sentiment: Negative</th></tr>`;
                        
                        flipkartVerbatim[0].forEach(function(e,i,a){
                            html += `<tr><td colspan="2">${e}</td></tr>`;
                        });

                        flipkartVerbatim[1].forEach(function(e,i,a){
                            html2 += `<tr><td colspan="2">${e}</td></tr>`;
                        });

                        flipkartVerbatim[2].forEach(function(e,i,a){
                            html3 += `<tr><td colspan="2">${e}</td></tr>`;
                        });

                        flipkartVerbatim[3].forEach(function(e,i,a){
                            html4 += `<tr><td colspan="2">${e}</td></tr>`;
                        });

                        // 

                        if(amazonVerbatim[0].length != 0)
                        {
                            amazonVerbatim[0].forEach(function(e,i,a){
                                html5 += `<tr><td colspan="2">${e}</td></tr>`;
                            });
                        }
                        else
                        {
                            html5 = ``;
                            html5 += `Please select phrase from left for comments`;
                        }

                        if(amazonVerbatim[1].length != 0)
                        {
                            amazonVerbatim[1].forEach(function(e,i,a){
                                html6 += `<tr><td colspan="2">${e}</td></tr>`;
                            });
                        }
                        else
                        {
                            html6 = ``;
                            html6 += `Please select phrase from left for comments`;
                        }

                        if(amazonVerbatim[2].length != 0)
                        {
                            amazonVerbatim[2].forEach(function(e,i,a){
                                html7 += `<tr><td colspan="2">${e}</td></tr>`;
                            });
                        }
                        else
                        {
                            html7 = ``;
                            html7 += `Please select phrase from left for comments`;
                        }

                        if(amazonVerbatim[3].length != 0)
                        {
                            amazonVerbatim[3].forEach(function(e,i,a){
                                html8 += `<tr><td colspan="2">${e}</td></tr>`;
                            });
                        }
                        else
                        {
                            html8 = ``;
                            html8 += `Please select phrase from left for comments`;
                        }
                        

                        // 

                        if(meeshoVerbatim[0].length != 0)
                        {
                            meeshoVerbatim[0].forEach(function(e,i,a){
                                html9 += `<tr><td colspan="2">${e}</td></tr>`;
                            });
                        }
                        else
                        {
                            html9 = ``;
                            html9 += `Please select phrase from left for comments`;
                        }
                        
                        if(meeshoVerbatim[1].length != 0)
                        {
                            meeshoVerbatim[1].forEach(function(e,i,a){
                                html10 += `<tr><td colspan="2">${e}</td></tr>`;
                            });
                        }
                        else
                        {
                            html10 = ``;
                            html10 += `Please select phrase from left for comments`;
                        }
                        
                        if(meeshoVerbatim[2].length != 0)
                        {
                            meeshoVerbatim[2].forEach(function(e,i,a){
                                html11 += `<tr><td colspan="2">${e}</td></tr>`;
                            });
                        }
                        else
                        {
                            html11 = ``;
                            html11 += `Please select phrase from left for comments`;
                        }

                        if(meeshoVerbatim[3].length != 0)
                        {
                            meeshoVerbatim[3].forEach(function(e,i,a){
                                html12 += `<tr><td colspan="2">${e}</td></tr>`;
                            });
                        }
                        else
                        {
                            html12 = ``;
                            html12 += `Please select phrase from left for comments`;
                        }

                        $("#flipkart_word_cloud_all_comment > tbody").empty().append(html);
                        $("#flipkart_word_cloud_promoter_comment > tbody").empty().append(html2);
                        $("#flipkart_word_cloud_passive_comment > tbody").empty().append(html3);
                        $("#flipkart_word_cloud_detractor_comment > tbody").empty().append(html4);

                        $("#amazon_word_cloud_all_comment > tbody").empty().append(html5);
                        $("#amazon_word_cloud_promoter_comment > tbody").empty().append(html6);
                        $("#amazon_word_cloud_passive_comment > tbody").empty().append(html7);
                        $("#amazon_word_cloud_detractor_comment > tbody").empty().append(html8);

                        $("#meesho_word_cloud_all_comment > tbody").empty().append(html9);
                        $("#meesho_word_cloud_promoter_comment > tbody").empty().append(html10);
                        $("#meesho_word_cloud_passive_comment > tbody").empty().append(html11);
                        $("#meesho_word_cloud_detractor_comment > tbody").empty().append(html12);

                    }
                });
            }

            function importData() {
                debugger;
                var fileInput = document.getElementById('excelFile');
                var file = fileInput.files[0];
                var formData = new FormData();
                formData.append('excelFile', file);
                $('#exampleModal').modal('hide');
                $('#importModal').modal('hide');
                $(".splash").show();
                $.ajax({
                    url: 'api/import.php',
                    type: 'POST',
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function(response) {
                        debugger;
                        console.log(response);
                        $(".splash").hide();
                        if(response=='Success'){
                            $("#alert_div").empty().append(`<h6>Database updated successfully</h6>`);
                            $("#alert_div").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800); 
                        }else if(response=='Data is already present for this month'){
                            $("#alert_div2").empty().append(`<h6>Data is already present for this month</h6>`);
                            $("#alert_div2").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800);
                        }
                        else{
                            $("#alert_div2").empty().append(`<h6>Operation Failed !! Try Again !!</h6>`);
                            $("#alert_div2").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800);
                        }
                    },
                    error: function(xhr, status, error) {
                        alert("Error: " + error);
                    }
                });
            }

            function deleteData() {
                var monthSelect = $("#monthSelect").val();
                $('#exampleModal').modal('hide');
                $('#deleteModal').modal('hide');
                $(".splash").show();
                $.ajax({
                    url: 'api/delete.php',
                    type: 'POST',
                    data:{
                        'monthSelect': monthSelect
                    },
                    success: function(response) {
                        debugger;
                        $(".splash").hide();
                        debugger;
                        if(response=='success'){
                            $("#alert_div").empty().append(`<h6>Data deleted successfully</h6>`);
                            $("#alert_div").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800); 
                        }else{
                            $("#alert_div2").empty().append(`<h6>Operation Failed !! Try Again !!</h6>`);
                            $("#alert_div2").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800);
                        }
                    },
                    error: function(xhr, status, error) {
                        alert("Error: " + error);
                    }
                });
            }

            // VOC

            function importDataVOC() {
                debugger;
                var fileInput = document.getElementById('excelFile7');
                var file = fileInput.files[0];
                var formData = new FormData();
                formData.append('excelFile7', file);
                $('#exampleModal').modal('hide');
                $('#importModal7').modal('hide');
                $(".splash").show();
                $.ajax({
                    url: 'api/import2.php',
                    type: 'POST',
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function(response) {
                        debugger;
                        console.log(response);
                        $(".splash").hide();
                        if(response=='Success'){
                            $("#alert_div").empty().append(`<h6>Database updated successfully</h6>`);
                            $("#alert_div").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800); 
                        }else if(response=='Data is already present for this month'){
                            $("#alert_div2").empty().append(`<h6>Data is already present for this month</h6>`);
                            $("#alert_div2").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800);
                        }
                        else{
                            $("#alert_div2").empty().append(`<h6>Operation Failed !! Try Again !!</h6>`);
                            $("#alert_div2").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800);
                        }
                    },
                    error: function(xhr, status, error) {
                        alert("Error: " + error);
                    }
                });
            }

            function deleteDataVOC() {
                var monthSelect = $("#vocmonthdelete").val();
                $('#exampleModal').modal('hide');
                $('#deleteModal7').modal('hide');
                $(".splash").show();
                $.ajax({
                    url: 'api/delete2.php',
                    type: 'POST',
                    data:{
                        'monthSelect': monthSelect
                    },
                    success: function(response) {
                        debugger;
                        $(".splash").hide();
                        debugger;
                        if(response=='success'){
                            $("#alert_div").empty().append(`<h6>Data deleted successfully</h6>`);
                            $("#alert_div").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800); 
                        }else{
                            $("#alert_div2").empty().append(`<h6>Operation Failed !! Try Again !!</h6>`);
                            $("#alert_div2").show();
                            setTimeout(() => {
                                window.location.reload();
                            }, 1800);
                        }
                    },
                    error: function(xhr, status, error) {
                        alert("Error: " + error);
                    }
                });
            }


            // VOC

            function swapTable(thisX,type)
            {
                //debugger;
                var getTxt = $(thisX).attr('data-value');
                if(getTxt=="Tbl")
                {
                    $(".chart_div").hide();
                    $(".tbl_div").show();
                    $(thisX).attr('data-value','Chart');
                    $(thisX).html('Show Chart');
                    tableStatus = true;
                }
                else
                {
                    $(".chart_div").show();
                    $(".tbl_div").hide();
                    $(thisX).attr('data-value','Tbl');
                    $(thisX).html('Show Table');
                    tableStatus = false;
                }
            }

            function lineChart(data,id,cat)
            {
                Highcharts.chart(id, {
                    chart: {
                        style: {
                            fontFamily: 'Roboto'
                        },
                        "backgroundColor": "transparent",
                    },
                    title: {
                        text: '',
                    },
                    navigation: {
                        buttonOptions: {
                            enabled: false
                        }
                    },
                    yAxis: {
                        title: {
                            text: ''
                        },
                        gridLineWidth: 0,
                        minorGridLineWidth: 0,
                        alignTicks: false,
                        labels: {
                            enabled: false
                        }
                    },
                    credits: {
                        enabled: false
                    },
                    legend: {
                        layout: 'horizontal',
                        align: 'center',
                        verticalAlign: 'bottom',
                        backgroundColor: Highcharts.defaultOptions.legend.backgroundColor || // theme
                            '#fff'
                    },
                    xAxis: {
                        labels: {
                            style: {
                                fontWeight: 'bold'
                            },
                            rotation:0,
                            useHTML: true,
                            padding:15,
                            height:10,
                            width:10,
                        },
                        categories: cat
                    },
                    tooltip: {
                        shared: true,
                        split: false,
                        enabled: true,
                        headerFormat: '',
                        pointFormat: '<span style="color:{point.color}">\u25CF</span> NPS for {series.name}: <b>{point.y}</b> <br/>',
                    },
                    plotOptions: {
                        series: {
                            cursor: 'pointer',
                            dataLabels: {
                                enabled: true,
                                color: '#000000',
                                formatter: function() {
                                    return (this.y);
                                },
                            },
                            label: {
                                connectorAllowed: false
                            },
                        }
                    },
                    colors: ['#33A0FF','#FFAD33','#FF33BB','#B1DCD3','#74A9CE','#A6BCDB','#D0D0E7'],
                    series: data,
                });
            }

            function wordChart(lucifer, id, color) {
                var colorPalette2 = [
                    '#E6F0FA', '#CFE1F4', '#B8D3EE', '#A1C5E8', '#8AB7E2', '#73A8DC',
                    '#5C9AD6', '#468CD0', '#317EC9', '#1F74BA', '#1A66A3'
                ];

                var scaledData = lucifer.reduce((arr, word) => {
                    let obj = Highcharts.find(arr, obj => obj.name === word);
                    if (obj) {
                        obj.weight += 1;
                    } else {
                        obj = {
                            name: word,
                            weight: 1
                        };
                        arr.push(obj);
                    }
                    return arr;
                }, []);

                Highcharts.chart(id, {
                    chart: {
                        type: 'wordcloud',
                        // backgroundColor: '#f8f9fa', // Light background
                    },
                    navigation: {
                        buttonOptions: {
                            enabled: false
                        }
                    },
                    credits: {
                        enabled: false
                    },
                    series: [{
                        type: 'wordcloud',
                        data: scaledData,
                        rotation: {
                            from: 0,
                            to: 0
                        },
                        minFontSize: 20,
                        maxFontSize: 50,
                        style: {
                            fontFamily: 'Arial',
                        },
                        name: 'Verbatims Count',
                        point: {
                            events: {
                                click: function () {
                                    var X = this.name;
                                    fetchComment(X);
                                }
                            }
                        },
                        dataLabels: {
                            enabled: true,
                            useHTML: true,
                            formatter: function () {
                                return `<span style="
                                    display: inline-block;
                                    padding: 5px 10px;
                                    border: 1px solid #317EC9;
                                    border-radius: 5px;
                                    background-color: #E6F0FA;
                                    font-weight: bold;
                                ">${this.point.name}</span>`;
                            }
                        }
                    }],
                    title: {
                        text: '',
                        align: 'left'
                    },
                    tooltip: {
                        headerFormat: '<span style="font-size: 12px"><b>{point.name}</b>' +
                            '</span><br>'
                    }
                });
            }


            function doughnutChart(lucifer,divId,seriesName,npsX)
            {
                Highcharts.chart(divId, {
                    chart: {
                        type: 'pie',
                        custom: {},
                        style: {
                            fontFamily: 'Roboto'
                        },
                        events: {
                            render() {
                                const chart = this,
                                    series = chart.series[0];
                                let customLabel = chart.options.chart.custom.label;

                                if (!customLabel) {
                                    customLabel = chart.options.chart.custom.label =
                                    chart.renderer.label(
                                        '<strong>' + npsX + '</strong>' + 
                                        '<br/><br/><br/><span style="font-size: 0.6em; color: black;"></span>' // Add Base: 1116 with smaller font-size
                                    )
                                            .css({
                                                color: '#0070C0',
                                                textAnchor: 'middle',
                                            })
                                            .add();
                                }

                                const x = series.center[0] + chart.plotLeft,
                                    y = series.center[1] + chart.plotTop - 
                                    (customLabel.attr('height') / 4);

                                customLabel.attr({
                                    x,
                                    y
                                });
                                
                                // Set font size based on chart diameter
                                customLabel.css({
                                    fontSize: `${series.center[2] / 12}px`
                                });
                            }
                        },
                        "backgroundColor": "transparent",
                    },
                    accessibility: {
                        point: {
                            valueSuffix: '%'
                        }
                    },
                    navigation: {
                        buttonOptions: {
                            enabled: false
                        }
                    },
                    title: {
                        text: ''
                    },
                    subtitle: {
                        text: ''
                    },
                    tooltip: {
                        pointFormat: '{series.name}: <b>{point.y:.0f}%</b>'
                    },
                    legend: {
                        layout: 'horizontal',
                        align: 'center',
                        verticalAlign: 'bottom',
                    },
                    credits: {
                        enabled: false
                    },
                    plotOptions: {
                        series: {
                            allowPointSelect: true,
                            cursor: 'pointer',
                            borderRadius: 8,
                            dataLabels: [{
                                enabled: true,
                                color: '#FFFFFF',
                                formatter: function() {
                                    return this.y > 0 ? this.y.toFixed(0) + '%' : null;
                                },
                                distance: -20,
                                // format: '{point.percentage:.1f}%',
                                style: {
                                    fontSize: '0.7em',
                                    
                                },
                                shadow: false
                            }],
                            showInLegend: true,
                        }
                    },
                    // colors: ['#C07B60','#FA8D62','#2C626E','#B1DCD3','#74A9CE','#A6BCDB','#D0D0E7'],
                    series: [{
                        name: seriesName,
                        colorByPoint: true,
                        innerSize: '75%',
                        data: lucifer
                    }],
                });
            }

            function exportExcel()
            {
                var txtArr = [];
                $(".tbl_filter_show").each(function(){
                    $(this).empty().append(filtercondX);
                })
                
                $(".div-head").each(function(){
                    var txt = $(this).text();
                    txtArr.push(txt.trim());
                });
                txtArr.splice(-3);

                $(".tbl_base_show").each(function(i,e){
                    $(e).empty().append(txtArr[i]);
                })
                
                let table1 = document.getElementById("current_tbl");
                let table2 = document.getElementById("previous_tbl");
                let table3 = document.getElementById("sd_current_tbl");
                let table4 = document.getElementById("sd_previous_tbl");
                let table5 = document.getElementById("overall_tbl_trends");
                let table6 = document.getElementById("domain_tbl_trends");
                let table7 = document.getElementById("subdomain_tbl_trends");

                let book = TableToExcel.tableToBook(table1, {sheet:{name:"Domain Current Month"}});
                let book2 = TableToExcel.tableToSheet(book,table2, {sheet:{name:"Domain Delta"}});
                let book3 = TableToExcel.tableToSheet(book2,table3, {sheet:{name:"Sub Domain Current Month"}});
                let book4 = TableToExcel.tableToSheet(book3, table4, {sheet:{name:"Sub Domain Delta"}});
                let book5 = TableToExcel.tableToSheet(book4, table5, {sheet:{name:"Overall Trends"}});
                let book6 = TableToExcel.tableToSheet(book5, table6, {sheet:{name:"Domain Trends"}});
                let book7 = TableToExcel.tableToSheet(book6, table7, {sheet:{name:"Sub Domain Trends"}});

                TableToExcel.save(book, "DasboardData.xlsx");
            }


        </script>
    </body>
</html>