<style>
    .dark-blue-color {
        color: #1c77d4 !important;
        font-weight: bold !important;
    }
</style>

<script type="text/javascript">
    $(function() {
        list_data_master();
        $(".tabs-master").css("color", "#4E5154 !important");
        $("#modal_form .modal-dialog").removeClass("modal-lg");
    });

    function list_data_master() {
        loading_master();
        var local_storage_master = localStorage.getItem('sales-activity-tab-master');
        if (local_storage_master == null) {
            <?php if ($this->level_user == '1') : ?>
                var local_storage_master = "tahapan";
            <?php else: ?>
                var local_storage_master = "group_product";
            <?php endif; ?>
        }
        
        <?php if ($this->is_sales_admin === true) : ?>
            if (local_storage_master !== "group_product" && local_storage_master !== "product") {
                var local_storage_master = "group_product";
            }
        <?php endif; ?>

        $('#tab_content_master').load("<?= route('sales_activity.master.tabs') . "/" ?>" + local_storage_master);
        $(".tabs-master").removeClass('dark-blue-color active');
        $("#btn_tabs_" + local_storage_master).addClass('dark-blue-color active');
    }

    function select_tab_master(e) {
        loading_master();
        $(".tabs-master").removeClass('dark-blue-color active');

        switch (e.attr("id")) {
            case "btn_tabs_aktivitas":
                $("#tab_content_master").load("<?= route('sales_activity.master.tabs') . "/aktivitas" ?>");
                e.addClass('dark-blue-color active');
                localStorage.setItem('sales-activity-tab-master', 'aktivitas');
                break;

            case "btn_tabs_lead_source":
                $("#tab_content_master").load("<?= route('sales_activity.master.tabs') . "/lead_source" ?>");
                e.addClass('dark-blue-color active');
                localStorage.setItem('sales-activity-tab-master', 'lead_source');
                break;

            case "btn_tabs_group_area":
                $("#tab_content_master").load("<?= route('sales_activity.master.tabs') . "/group_area" ?>");
                e.addClass('dark-blue-color active');
                localStorage.setItem('sales-activity-tab-master', 'group_area');
                break;

            case "btn_tabs_group_product":
                $("#tab_content_master").load("<?= route('sales_activity.master.tabs') . "/group_product" ?>");
                e.addClass('dark-blue-color active');
                localStorage.setItem('sales-activity-tab-master', 'group_product');
                break;

            case "btn_tabs_tahapan":
                $("#tab_content_master").load("<?= route('sales_activity.master.tabs') . "/tahapan" ?>");
                e.addClass('dark-blue-color active');
                localStorage.setItem('sales-activity-tab-master', 'tahapan');
                break;

            case "btn_tabs_product":
                $("#tab_content_master").load("<?= route('sales_activity.master.tabs') . "/product" ?>");
                e.addClass('dark-blue-color active');
                localStorage.setItem('sales-activity-tab-master', 'product');
                break;

            case "btn_tabs_jenis_perusahaan":
                $("#tab_content_master").load("<?= route('sales_activity.master.tabs') . "/jenis_perusahaan" ?>");
                e.addClass('dark-blue-color active');
                localStorage.setItem('sales-activity-tab-master', 'jenis_perusahaan');
                break;

            case "btn_tabs_jenis_perorangan":
                $("#tab_content_master").load("<?= route('sales_activity.master.tabs') . "/jenis_perorangan" ?>");
                e.addClass('dark-blue-color active');
                localStorage.setItem('sales-activity-tab-master', 'jenis_perorangan');
                break;

            default:
                $("#tab_content_master").load("<?= route('sales_activity.master.tabs') . "/admin_sales" ?>>");
                $("#btn_tabs_admin_sales").addClass('dark-blue-color active');
                localStorage.setItem('sales-activity-tab-master', 'admin_sales');
                break;
        }
    }

    function loading_master() {
        $('#tab_content_master').html('<div class="modal-body"><div class="text-center"><div class="custom-lds-ring"><div></div><div></div><div></div></div></div></div>');
    }
</script>

<div class="card card-rounded">
    <div class="card-content">
        <div class="card-body">
            <div class="nav-tabs-boxed">
                <ul class="nav nav-tabs" role="tablist">
                    <?php if ($this->level_user == '1') : ?>
                        <li class="nav-item" onclick="select_tab_master($(this).find('a'))">
                            <a href="#" id="btn_tabs_tahapan" class="nav-link px-2 tabs-master" data-toggle="tab" role="tab">
                                <?= $this->lang->line('tahapan_penjualan') ?>
                            </a>
                        </li>
                        <li class="nav-item" onclick="select_tab_master($(this).find('a'))">
                            <a href="#" id="btn_tabs_aktivitas" class="nav-link px-2 tabs-master" data-toggle="tab" role="tab">
                                <?= $this->lang->line('aktivitas') ?>
                            </a>
                        </li>
                        <li class="nav-item" onclick="select_tab_master($(this).find('a'))">
                            <a href="#" id="btn_tabs_lead_source" class="nav-link px-2 tabs-master" data-toggle="tab" role="tab">
                                <?= $this->lang->line('lead_source') ?>
                            </a>
                        </li>
                        <li class="nav-item" onclick="select_tab_master($(this).find('a'))">
                            <a href="#" id="btn_tabs_group_area" class="nav-link px-2 tabs-master" data-toggle="tab" role="tab">
                                <?= $this->lang->line('group_area') ?>
                            </a>
                        </li>
                    <?php endif; ?>

                    <?php if ($this->is_sales_admin === true || $this->level_user == '1') : ?>
                        <li class="nav-item" onclick="select_tab_master($(this).find('a'))">
                            <a href="#" id="btn_tabs_group_product" class="nav-link px-2 tabs-master" data-toggle="tab" role="tab">
                                <?= $this->lang->line('group_product') ?>
                            </a>
                        </li>
                        <li class="nav-item" onclick="select_tab_master($(this).find('a'))">
                            <a href="#" id="btn_tabs_product" class="nav-link px-2 tabs-master" data-toggle="tab" role="tab">
                                <?= $this->lang->line('product') ?>
                            </a>
                        </li>
                    <?php endif; ?>
                    
                    <?php if ($this->level_user == '1') : ?>
                        <li class="nav-item" onclick="select_tab_master($(this).find('a'))">
                            <a href="#" id="btn_tabs_jenis_perusahaan" class="nav-link px-2 tabs-master" data-toggle="tab" role="tab">
                                <?= $this->lang->line('jenis_perusahaan') ?>
                            </a>
                        </li>
                        <li class="nav-item" onclick="select_tab_master($(this).find('a'))">
                            <a href="#" id="btn_tabs_jenis_perorangan" class="nav-link px-2 tabs-master" data-toggle="tab" role="tab">
                                <?= $this->lang->line('jenis_perorangan') ?>
                            </a>
                        </li>
                    <?php endif; ?>
                </ul>
            </div>
            <div class="row mt-2">
                <div id="tab_content_master" class="col-md-12"></div>
            </div>
        </div>
    </div>
</div>
