

<?php $__env->startSection('content'); ?>

<?php
    $route = Route::currentRouteName() == 'sellers.index' ? 'all_seller_route' : 'seller_rating_followers';
?>

<div class="card">
    <!--Nav Tab -->
    <div
        class="d-flex align-items-center justify-content-between flex-wrap border-bottom  border-light px-25px table-nav-tabs pb-3 pb-xl-0">
        <div class="table-tabs-container flex-grow-1">
            <ul class="nav nav-tabs border-0 " id="myTab" role="tablist">
                <?php $__currentLoopData = $seller_types; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $seller_type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li class="nav-item" role="presentation">
                        <button class="nav-link px-0 pb-15px fs-14 fw-500 <?php echo e($loop->first ? 'active' : ''); ?>"
                            data-toggle="tab" role="tab" aria-selected="<?php echo e($loop->first ? 'true' : 'false'); ?>"
                            id="<?php echo e(Str::slug($seller_type)); ?>-tab"
                            onclick="changeTab(this, '<?php echo e(Str::slug($seller_type)); ?>')" role="tab"
                            aria-controls="<?php echo e(Str::slug($seller_type)); ?>">
                            <?php echo e(translate($seller_type)); ?>

                        </button>
                    </li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
        </div>
        <!--Right Side- Add New Button -->
        <div class="">
            <?php if(auth()->user()->can('add_seller') && ($route == 'all_seller_route')): ?>
                <a href="<?php echo e(route('sellers.create')); ?>" class="position-relative overflow-hidden add-new-btn">
                    <span class="position-relative z-2 pr-15px fs-14 fw-500 text-blue label-text"><?php echo e(translate('Add New Seller')); ?></span>
                    <span class="position-absolute top-0 right-0 h-100 w-40px bg-blue d-flex align-items-center justify-content-end z-1 plus-icon-container m-0 p-0 rounded-pill">
                        <svg id="plus-icon" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12">
                            <path id="Path_45216" data-name="Path 45216"
                                d="M141.874-812.13a.706.706,0,0,1-.515-.21.7.7,0,0,1-.212-.514V-817.4h-4.553a.7.7,0,0,1-.514-.209.694.694,0,0,1-.21-.511.706.706,0,0,1,.21-.515.7.7,0,0,1,.514-.212h4.549v-4.557a.7.7,0,0,1,.209-.514.694.694,0,0,1,.511-.21.706.706,0,0,1,.515.21.7.7,0,0,1,.212.514v4.553h4.557a.7.7,0,0,1,.514.208.694.694,0,0,1,.21.511.706.706,0,0,1-.21.515.7.7,0,0,1-.514.212h-4.553v4.553a.7.7,0,0,1-.209.514A.694.694,0,0,1,141.874-812.13Z"
                                transform="translate(-135.87 824.13)" fill="#fff" />
                        </svg>
                    </span>
                </a>
            <?php endif; ?>
        </div>
    </div>
    <div class="tab-filter-bar">
        <form class="" id="sort_sellers" action="" method="GET">
            <div class="card-header row border-0 pb-0 mt-2">
                <div class="col pl-0 pl-md-3">
                    <div class="input-group mb-0 border border-light px-3 bg-light rounded-1">
                        <div class="input-group-prepend">
                            <span class="input-group-text border-0 bg-transparent px-0" id="search">
                                <svg id="Group_38844" data-name="Group 38844" xmlns="http://www.w3.org/2000/svg"
                                    width="16.001" height="16" viewBox="0 0 16.001 16">
                                    <path id="Path_3090" data-name="Path 3090"
                                        d="M8.248,14.642a6.394,6.394,0,1,1,6.394-6.394A6.4,6.4,0,0,1,8.248,14.642Zm0-11.509a5.115,5.115,0,1,0,5.115,5.115A5.121,5.121,0,0,0,8.248,3.133Z"
                                        transform="translate(-1.854 -1.854)" fill="#a5a5b8" />
                                    <path id="Path_3091" data-name="Path 3091"
                                        d="M23.011,23.651a.637.637,0,0,1-.452-.187l-4.92-4.92a.639.639,0,0,1,.9-.9l4.92,4.92a.639.639,0,0,1-.452,1.091Z"
                                        transform="translate(-7.651 -7.651)" fill="#a5a5b8" />
                                </svg>
                            </span>
                        </div>
                        <input type="text" class="form-control form-control-sm border-0 px-2 bg-transparent"
                            id="search_input" name="search" <?php if(isset($sort_search)): ?> value="<?php echo e($sort_search); ?>" <?php endif; ?> 
                            placeholder="<?php echo e(translate('Type name or email or mobile number & Enter')); ?>">
                    </div>
                </div>

                <?php if($route == 'all_seller_route'): ?>
                    <div class="dropdown mb-2 mb-md-0 bg-light mt-2 mt-md-0 px-md-1 rounded-1">
                        <button class="btn border dropdown-toggle border-light text-secondary fs-14 fw-400" type="button"
                            data-toggle="dropdown">
                            <?php echo e(translate('Bulk Action')); ?>

                        </button>
                        <div class="dropdown-menu dropdown-menu-right">
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('delete_seller')): ?>
                                <a class="dropdown-item confirm-alert text-danger fs-14 fw-500 hov-bg-light hov-text-blue"
                                    href="javascript:void(0)" data-target="#bulk-delete-modal">
                                    <?php echo e(translate('Delete selection')); ?>

                                </a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('seller_commission_configuration')): ?>
                                <a class="dropdown-item text-secondary fs-14 fw-500 hov-bg-light hov-text-blue" 
                                    onclick="set_bulk_commission()" href="javascript:void(0)">
                                    <?php echo e(translate('Set Bulk Commission')); ?>

                                </a>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="col-md-2 mr-0 px-0 inner-select ml-1">
                        <select class="form-control aiz-selectpicker mb-2 mb-md-0 bg-light" 
                            name="verification_status" onchange="sort_sellers()" data-selected="<?php echo e($verification_status); ?>">
                            <option value="" class="hov-bg-light text-secondary fs-14 fw-40"><?php echo e(translate('Email Verification Status')); ?></option>
                            <option value="verified" class="hov-bg-light text-secondary fs-14 fw-40"><?php echo e(translate('Verified')); ?></option>
                            <option value="un_verified" class="hov-bg-light text-secondary fs-14 fw-40"><?php echo e(translate('Unverified')); ?></option>
                        </select>
                    </div>

                    <div class="col-md-2 mr-0 px-0 inner-select ml-1">
                        <select class="form-control aiz-selectpicker mb-2 mb-md-0 bg-light" 
                            name="approved_status" id="approved_status" onchange="sort_sellers()">
                            <option value="" class="hov-bg-light text-secondary fs-14 fw-40"><?php echo e(translate('Seller Verification Status')); ?></option>
                            <option value="1" <?php if(isset($approved)): ?> <?php if($approved == '1'): ?> selected <?php endif; ?> <?php endif; ?> 
                                class="hov-bg-light text-secondary fs-14 fw-40"><?php echo e(translate('Approved')); ?></option>
                            <option value="0" <?php if(isset($approved)): ?> <?php if($approved == '0'): ?> selected <?php endif; ?> <?php endif; ?> 
                                class="hov-bg-light text-secondary fs-14 fw-40"><?php echo e(translate('Non-Approved')); ?></option>
                        </select>
                    </div>
                <?php endif; ?>

                <!-- Filter Dropdown -->
                
            </div>

            <!-- Dynamic Tab Content -->
            <div class="tab-content filter-tab-content" id="myTabContent">
                <div class="tab-pane fade show active" id="tab-content">
                    <!-- AJAX content will load here -->
                </div>
            </div>
        </form>
    </div>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('modal'); ?>
	<!-- Delete Modal -->
	<?php echo $__env->make('modals.delete_modal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <!-- Bulk Delete modal -->
    <?php echo $__env->make('modals.bulk_delete_modal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

	<!-- Seller verification info Modal -->
	<div class="modal fade" id="verification_info_modal">
		<div class="modal-dialog modal-dialog-centered">
			<div class="modal-content" id="verification-info-modal-content">

			</div>
		</div>
	</div>

	<!-- Seller Payment Modal -->
	<div class="modal fade" id="payment_modal">
	    <div class="modal-dialog modal-dialog-centered">
	        <div class="modal-content" id="payment-modal-content">

	        </div>
	    </div>
	</div>

	
<!-- Reusable Confirmation Modal -->
<div class="modal fade" id="universal-confirm-modal">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title h6" id="universal-modal-title"><?php echo e(translate('Confirmation')); ?></h5>
                <button type="button" class="close" data-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <p id="universal-modal-message"></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-light" data-dismiss="modal"><?php echo e(translate('Cancel')); ?></button>
                <a class="btn btn-primary" id="universal-confirm-button"><?php echo e(translate('Proceed!')); ?></a>
            </div>
        </div>
    </div>
</div>
   

    
    <div class="modal fade" id="edit_seller_custom_followers">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title h6"><?php echo e(translate('Edit Seller Custom Followers')); ?></h5>
                    <button type="button" class="close" data-dismiss="modal">
                    </button>
                </div>
                <form class="form-horizontal" action="<?php echo e(route('edit_Seller_custom_followers')); ?>" method="POST" enctype="multipart/form-data">
                    <?php echo csrf_field(); ?>
                    <div class="modal-body">
                        <input type="hidden" name="shop_id" value="" id="shop_id">
                        <div class="form-group row">
                            <label class="col-md-3 col-from-label"><?php echo e(translate('Custom Followers')); ?></label>
                            <div class="col-md-9">
                                <input type="number" lang="en" min="0" step="1" placeholder="<?php echo e(translate('Custom Followers')); ?>" value="" name="custom_followers" id="custom_followers" class="form-control" required>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary btn-sm text-white"><?php echo e(translate('save!')); ?></button>
                        <button type="button" class="btn btn-sm btn-light" data-dismiss="modal"><?php echo e(translate('Cancel')); ?></button>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <div class="modal fade" id="set_seller_commission">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title h6"><?php echo e(translate('Set Seller Commission')); ?></h5>
                    <button type="button" class="close" data-dismiss="modal">
                    </button>
                </div>
                <div class="modal-body">
                    <input type="hidden" name="shop_id" value="" id="shop_id">
                    <div class="form-group row">
                        <label class="col-md-3 col-from-label"><?php echo e(translate('Commission Percentage')); ?></label>
                        <div class="col-md-9">
                            <input type="number" lang="en" min="0" step="1" placeholder="<?php echo e(translate('Commission Percentage')); ?>" value="" name="commission_percentage" id="commission_percentage" class="form-control" required>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary btn-sm text-white" onclick="setSellerBasedCommission()"><?php echo e(translate('save!')); ?></button>
                    <button type="button" class="btn btn-sm btn-light" data-dismiss="modal"><?php echo e(translate('Cancel')); ?></button>
                </div>
            </div>
        </div>
    </div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
    <script type="text/javascript">
        let searchTimer;
        let currentTab = '<?php echo e(Str::slug($seller_types[0] ?? '')); ?>';
        $(document).on("change", ".check-all", function() {
            if(this.checked) {
                // Iterate each checkbox
                $('.check-one:checkbox').each(function() {
                    this.checked = true;
                });
            } else {
                $('.check-one:checkbox').each(function() {
                    this.checked = false;
                });
            }

        });

        function show_seller_payment_modal(id){
            $.post('<?php echo e(route('sellers.payment_modal')); ?>',{_token:'<?php echo e(@csrf_token()); ?>', id:id}, function(data){
                $('#payment_modal #payment-modal-content').html(data);
                $('#payment_modal').modal('show', {backdrop: 'static'});
                $('.demo-select2-placeholder').select2();
            });
        }

        function show_seller_verification_info(id){
            $.post('<?php echo e(route('sellers.verification_info_modal')); ?>',{_token:'<?php echo e(@csrf_token()); ?>', id:id}, function(data){
                $('#verification_info_modal #verification-info-modal-content').html(data);
                $('#verification_info_modal').modal('show', {backdrop: 'static'});
            });
        }

        function update_approved(el){
            if('<?php echo e(env('DEMO_MODE')); ?>' == 'On'){
                AIZ.plugins.notify('info', '<?php echo e(translate('Data can not change in demo mode.')); ?>');
                return;
            }

            if(el.checked){
                var status = 1;
            }
            else{
                var status = 0;
            }
            $.post('<?php echo e(route('sellers.approved')); ?>', {_token:'<?php echo e(csrf_token()); ?>', id:el.value, status:status}, function(data){
                if(data == 1){
                    AIZ.plugins.notify('success', '<?php echo e(translate('Approved sellers updated successfully')); ?>');
                }
                else{
                    AIZ.plugins.notify('danger', '<?php echo e(translate('Something went wrong')); ?>');
                }
            });
        }

        // Ban
        function confirm_ban(url) {
            showConfirmationModal({
                url: url,
                message: '<?php echo e(translate("Do you really want to ban this seller?")); ?>'
            });
        }

        // Unban
        function confirm_unban(url) {
            showConfirmationModal({
                url: url,
                message: '<?php echo e(translate("Do you really want to unban this seller?")); ?>'
            });
        }

        function showConfirmationModal({ url, message }) {
            if ('<?php echo e(env('DEMO_MODE')); ?>' === 'On') {
                AIZ.plugins.notify('info', '<?php echo e(translate('Data can not change in demo mode.')); ?>');
                return;
            }

            // Set dynamic content
            document.getElementById('universal-modal-message').innerText = message;
            document.getElementById('universal-confirm-button').setAttribute('href', url);

            // Show the modal
            $('#universal-confirm-modal').modal('show', { backdrop: 'static' });
        }


        function bulk_delete() {
            var data = new FormData($('#sort_sellers')[0]);
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: "<?php echo e(route('bulk-seller-delete')); ?>",
                type: 'POST',
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                success: function (response) {
                    if(response == 1) {
                        AIZ.plugins.notify('success', '<?php echo e(translate('Selected Sellers Deleted Successfully')); ?>');
                        $('#bulk-delete-modal').modal('hide');
                        getSellers(currentTab);
                    }
                }
            });
        }
        // Set seller bulk commission
        function set_bulk_commission(){
            var sellerIds = [];
            $(".check-one[name='id[]']:checked").each(function() {
                sellerIds.push($(this).val());
            });
            if(sellerIds.length > 0){
                $('#seller_ids').val(sellerIds);
                $('#set_seller_commission').modal('show', {backdrop: 'static'});
            }
            else{
                AIZ.plugins.notify('danger', '<?php echo e(translate('Please Select Seller first.')); ?>');
            }
        }

        
        // Edit seller custom followers
        function editCustomFollowers(shop_id, custom_followers){
            $('#shop_id').val(shop_id);
            $('#custom_followers').val(custom_followers);
            $('#edit_seller_custom_followers').modal('show', {backdrop: 'static'});
        }

        // Suspicious / Unsuspicious
        function confirm_suspicious(url, isSuspicious) {
            const action = isSuspicious ? 'unsuspect' : 'suspect';
            showConfirmationModal({
                url: url,
                message: '<?php echo e(translate("Do you really want to")); ?> ' + action + ' <?php echo e(translate("this seller?")); ?>'
            });
        }

        function getSellers(slug, page = 1) {
            currentTab = slug;
            let keyword = $('#search_input').val();
            let status = '<?php echo e($status ?? ''); ?>';
            let verification_status = $('#sort_sellers select[name="verification_status"]').val();
            let approved_status = $('#sort_sellers select[name="approved_status"]').val();
            let route = '<?php echo e($route); ?>';
            let url = '';

            // Build URL based on route type
            if (route === 'all_seller_route') {
                url = '<?php echo e(route("sellers.index")); ?>';
            } else if (route === 'seller_rating_followers') {
                url = '<?php echo e(route("sellers.rating_followers")); ?>';
            } else {
                url = '<?php echo e(route("sellers.index")); ?>'; // default fallback
            }

            $('#tab-content').html('<div class="footable-loader mt-5"><span class="fooicon fooicon-loader"></span></div>');
            $.ajax({
                url: `${url}?page=${page}`,
                method: 'GET',
                data: { search: keyword, status: status, verification_status: verification_status, approved_status: approved_status, seller_type: slug, },
                success: function(response) {
                    $('#tab-content').html(response.html);
                    initFooTable();

                },
                error: function() {
                    $('#tab-content').html(`
                        <div class="text-center py-2 w-100">
                            <h5 class="fs-16 fw-bold text-gray"><?php echo e(translate('Something Went Wrong')); ?></h5>
                            <i class="las la-frown fs-48 text-soft-white"></i>
                        </div>
                    `);
                }
            });
        }

        document.addEventListener('DOMContentLoaded', function() {
            getSellers(currentTab);
        });

        $('#search_input').on('keyup', function () {
            clearTimeout(searchTimer);
            searchTimer = setTimeout(function () {
                getSellers(currentTab);
            }, 500);
        });

        $(document).on('click', '.pagination a', function(e) {
            e.preventDefault();
            const page = $(this).attr('href').split('page=')[1];
            getSellers(currentTab, page);
        });

         function sort_sellers(el){
            getSellers(currentTab);
        }

        function singleDelete(productId) {
            showBulkActionModal();
            $('#confirmation-title').text('<?php echo e(translate('Delete Confirmation')); ?>');
            $('#confirmation-question').text('<?php echo e(translate('Are you sure you want to delete the selected seller?')); ?>');
            $('#impact-message').text('<?php echo e(translate('This action cannot be undone. Once deleted, the seller will be permanently removed.')); ?>');
            $('#conform-yes-btn').attr("onclick", "single_delete(" + productId + ")");
            $('.confirmation-icon').addClass('d-none');
            $('#delete-confirm-icon').removeClass('d-none');
           
        }

        function single_delete(sellerId) {
             $.ajax({
                url: '<?php echo e(route("sellers.ajax.destroy", "")); ?>/' + sellerId,
                type: 'DELETE',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(response) {
                    if (response.success) {
                        AIZ.plugins.notify('success', '<?php echo e(translate('Selected item deleted successfully')); ?>');
                        hideBulkActionModal();
                        getSellers(currentTab);
                    }
                },
                error: function(xhr) {
                    console.log('Error:', xhr);
                    AIZ.plugins.notify('danger', '<?php echo e(translate('Error deleting seller')); ?>');
                }
            });
        }


        function setSellerBasedCommission() {
            var sellerIds = [];
            $(".check-one[name='id[]']:checked").each(function() {
                sellerIds.push($(this).val());
            });
            
            var commission_percentage = $("#commission_percentage").val();
            if(!commission_percentage) {
                AIZ.plugins.notify('warning', 'Please enter commission percentage');
                return false;
            }
            
            var data = new FormData();
            data.append('seller_ids', sellerIds.join(','));
            data.append('commission_percentage', commission_percentage);
            
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: "<?php echo e(route('set_seller_based_commission')); ?>",
                type: 'POST',
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                success: function (response) {
                    if(response == 1) {
                        AIZ.plugins.notify('success', '<?php echo e(translate('Selected sellers Commission Updated successfully')); ?>');
                        $('#set_seller_commission').modal('hide');
                        getSellers(currentTab);
                    } else {
                        AIZ.plugins.notify('danger', 'Something went wrong');
                    }
                },
                error: function () {
                    AIZ.plugins.notify('danger', 'Something went wrong');
                }
            });
        }
        function changeTab(button, statusSlug) {
            document.querySelectorAll('#myTab .nav-link').forEach(el => el.classList.remove('active'));
            button.classList.add('active');
            getSellers(statusSlug);
        }

    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('backend.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/akhanei2/public_html/resources/views/backend/sellers/index.blade.php ENDPATH**/ ?>