<?php $__env->startSection('title', \App\CentralLogics\translate('Add new sub category')); ?>

<?php $__env->startPush('css_or_js'); ?>
    <meta name="csrf-token" content="<?php echo e(csrf_token()); ?>">
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <div class="content container-fluid">
        <!-- Page Header -->
        <div class="page-header">
            <div class="row align-items-center">
                <div class="col-sm mb-2 mb-sm-0">
                    <h1 class="page-header-title"><i
                            class="tio-add-circle-outlined"></i> <?php echo e(\App\CentralLogics\translate('add New Sub-category')); ?>

                    </h1>
                </div>
            </div>
        </div>
        <!-- End Page Header -->
        <div class="row gx-2 gx-lg-3">
            <div class="col-sm-12 col-lg-12 mb-3 mb-lg-2">
                <form action="<?php echo e(route('admin.category.store')); ?>" method="post">
                    <?php echo csrf_field(); ?>
                    <?php ($language=\App\Model\BusinessSetting::where('key','language')->first()); ?>
                    <?php ($language = $language->value ?? null); ?>
                    <?php ($default_lang = 'en'); ?>
                    <?php if($language): ?>
                        <?php ($default_lang = json_decode($language)[0]); ?>
                        <ul class="nav nav-tabs mb-4">
                            <?php $__currentLoopData = json_decode($language); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lang): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <li class="nav-item">
                                    <a class="nav-link lang_link <?php echo e($lang == $default_lang? 'active':''); ?>" href="#" id="<?php echo e($lang); ?>-link"><?php echo e(\App\CentralLogics\Helpers::get_language_name($lang).'('.strtoupper($lang).')'); ?></a>
                                </li>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </ul>
                        <div class="row">
                            <div class="col-6">
                                <?php $__currentLoopData = json_decode($language); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lang): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <div class="form-group <?php echo e($lang != $default_lang ? 'd-none':''); ?> lang_form" id="<?php echo e($lang); ?>-form">
                                        <label class="input-label" for="exampleFormControlInput1"><?php echo e(\App\CentralLogics\translate('sub_category')); ?> <?php echo e(\App\CentralLogics\translate('name')); ?> (<?php echo e(strtoupper($lang)); ?>)</label>
                                        <input type="text" name="name[]" class="form-control" maxlength="255" placeholder="<?php echo e(\App\CentralLogics\translate('New Sub Category')); ?>" <?php echo e($lang == $default_lang? 'required':''); ?> oninvalid="document.getElementById('en-link').click()">
                                    </div>
                                    <input type="hidden" name="lang[]" value="<?php echo e($lang); ?>">
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <?php else: ?>
                                    <div class="row">
                                        <div class="col-6">
                                            <div class="form-group lang_form" id="<?php echo e($default_lang); ?>-form">
                                                <label class="input-label" for="exampleFormControlInput1"><?php echo e(\App\CentralLogics\translate('sub_category')); ?> <?php echo e(\App\CentralLogics\translate('name')); ?>(<?php echo e(strtoupper($lang)); ?>)</label>
                                                <input type="text" name="name[]" class="form-control" placeholder="<?php echo e(\App\CentralLogics\translate('New Sub Category')); ?>" required>
                                            </div>
                                            <input type="hidden" name="lang[]" value="<?php echo e($default_lang); ?>">
                                            <?php endif; ?>
                                            <input name="position" value="1" style="display: none">
                                        </div>
                                        <div class="col-6">
                                            <div class="form-group">
                                                <label class="input-label"
                                                       for="exampleFormControlSelect1"><?php echo e(\App\CentralLogics\translate('main')); ?> <?php echo e(\App\CentralLogics\translate('category')); ?>

                                                    <span class="input-label-secondary">*</span></label>
                                                <select id="exampleFormControlSelect1" name="parent_id" class="form-control" required>
                                                    <?php $__currentLoopData = \App\Model\Category::where(['position'=>0])->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($category['id']); ?>"><?php echo e($category['name']); ?></option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-primary"><?php echo e(\App\CentralLogics\translate('submit')); ?></button>
                </form>
            </div>

            <div class="col-sm-12 col-lg-12 mb-3 mb-lg-2">
                <div class="card">
                    <div class="card-header flex-between">
                        <div class="flex-start">
                            <h5 class="card-header-title"><?php echo e(\App\CentralLogics\translate('Sub Category Table')); ?></h5>
                            <h5 class="card-header-title text-primary mx-1">(<?php echo e($categories->total()); ?>)</h5>
                        </div>
                        <div>
                            <form action="<?php echo e(url()->current()); ?>" method="GET">
                                <div class="input-group">
                                    <input id="datatableSearch_" type="search" name="search"
                                           class="form-control"
                                           placeholder="<?php echo e(\App\CentralLogics\translate('Search')); ?>" aria-label="Search"
                                           value="<?php echo e($search); ?>" required autocomplete="off">
                                    <div class="input-group-append">
                                        <button type="submit" class="input-group-text"><i class="tio-search"></i>
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!-- Table -->
                    <div class="table-responsive datatable-custom">
                        <table class="table table-borderless table-thead-bordered table-nowrap table-align-middle card-table">
                            <thead class="thead-light">
                            <tr>
                                <th><?php echo e(\App\CentralLogics\translate('#')); ?></th>
                                <th style="width: 50%"><?php echo e(\App\CentralLogics\translate('main')); ?> <?php echo e(\App\CentralLogics\translate('category')); ?></th>
                                <th style="width: 50%"><?php echo e(\App\CentralLogics\translate('sub_category')); ?></th>
                                <th style="width: 20%"><?php echo e(\App\CentralLogics\translate('status')); ?></th>
                                <th style="width: 10%"><?php echo e(\App\CentralLogics\translate('action')); ?></th>
                            </tr>

                            </thead>

                            <tbody id="set-rows">
                            <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($categories->firstItem()+$key); ?></td>
                                    <td>
                                        <span class="d-block font-size-sm text-body">
                                            <?php echo e($category->parent['name']); ?>

                                        </span>
                                    </td>

                                    <td>
                                        <span class="d-block font-size-sm text-body">
                                            <?php echo e($category['name']); ?>

                                        </span>
                                    </td>

                                    <td>
                                        <?php if($category['status']==1): ?>
                                            <div style="padding: 10px;border: 1px solid;cursor: pointer"
                                                 onclick="location.href='<?php echo e(route('admin.category.status',[$category['id'],0])); ?>'">
                                                <span
                                                    class="legend-indicator bg-success"></span><?php echo e(\App\CentralLogics\translate('active')); ?>

                                            </div>
                                        <?php else: ?>
                                            <div style="padding: 10px;border: 1px solid;cursor: pointer"
                                                 onclick="location.href='<?php echo e(route('admin.category.status',[$category['id'],1])); ?>'">
                                                <span
                                                    class="legend-indicator bg-danger"></span><?php echo e(\App\CentralLogics\translate('disabled')); ?>

                                            </div>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <!-- Dropdown -->
                                        <div class="dropdown">
                                            <button class="btn btn-secondary dropdown-toggle" type="button"
                                                    id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true"
                                                    aria-expanded="false">
                                                <i class="tio-settings"></i>
                                            </button>
                                            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                                <a class="dropdown-item"
                                                   href="<?php echo e(route('admin.category.edit',[$category['id']])); ?>"><?php echo e(\App\CentralLogics\translate('edit')); ?></a>
                                                <a class="dropdown-item" href="javascript:"
                                                   onclick="form_alert('category-<?php echo e($category['id']); ?>','<?php echo e(\App\CentralLogics\translate('Want to delete this ?')); ?>')"><?php echo e(\App\CentralLogics\translate('delete')); ?></a>
                                                <form action="<?php echo e(route('admin.category.delete',[$category['id']])); ?>"
                                                      method="post" id="category-<?php echo e($category['id']); ?>">
                                                    <?php echo csrf_field(); ?> <?php echo method_field('delete'); ?>
                                                </form>
                                            </div>
                                        </div>
                                        <!-- End Dropdown -->
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                        <hr>
                        <div class="page-area">
                            <table>
                                <tfoot>
                                <?php echo $categories->links(); ?>

                                </tfoot>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <!-- End Table -->
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('script_2'); ?>
    <script>
        $(".lang_link").click(function(e){
            e.preventDefault();
            $(".lang_link").removeClass('active');
            $(".lang_form").addClass('d-none');
            $(this).addClass('active');

            let form_id = this.id;
            let lang = form_id.split("-")[0];
            console.log(lang);
            $("#"+lang+"-form").removeClass('d-none');
            if(lang == '<?php echo e($default_lang); ?>')
            {
                $(".from_part_2").removeClass('d-none');
            }
            else
            {
                $(".from_part_2").addClass('d-none');
            }
        });
    </script>

    <script>
        $('#search-form').on('submit', function () {
            var formData = new FormData(this);
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $.post({
                url: '<?php echo e(route('admin.category.search')); ?>',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                beforeSend: function () {
                    $('#loading').show();
                },
                success: function (data) {
                    $('#set-rows').html(data.view);
                    $('.page-area').hide();
                },
                complete: function () {
                    $('#loading').hide();
                },
            });
        });
    </script>
<?php $__env->stopPush(); ?>

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