
<?php $__env->startSection('title',__('messages.cattle')); ?>
<?php $__env->startSection('content'); ?>
    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('cattle.create')): ?>
        <div class="add-new-button-hidden">
            <button class="btn add_new_btn" data-bs-toggle="modal" data-bs-target="#cattleReg"
            ><i class="plus-ico"></i> <?php echo e(__('messages.add_cattle')); ?>

            </button>
        </div>
    <?php endif; ?>
    <h2 class="ms-2 card-title"><?php echo e(__('messages.cattle_list')); ?></h2>
    <div class="card mt-3 m-lg-2">
        <div class="card-body mt-2 table_card">
            <table id="datatable-buttons" class="table table-bordered dt-responsive nowrap w-100"
                   data-table="dataTables">
                <thead>
                <tr>
                    <th><?php echo e(__('messages.sl')); ?></th>
                    <th><?php echo e(__('messages.lot_name')); ?></th>
                    <th><?php echo e(__('messages.tag_id')); ?></th>
                    <th><?php echo e(__('messages.age')); ?></th>
                    <th><?php echo e(__('messages.sex')); ?></th>
                    <th><?php echo e(__('messages.status')); ?></th>
                    <th><?php echo e(__('messages.action')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $cattles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e(++$key); ?></td>
                        <td><?php echo e($item->lot_id ? $item->lot->name : 'N/A'); ?></td>
                        <td><?php echo e($item->tag_id ? $item->tag->uid : 'N/A'); ?></td>
                        <td>
                            <?php echo e($item->birth_date
                            ? \Carbon\Carbon::parse($item->birth_date)->diff(\Carbon\Carbon::now())->format('%y Y, %m M, %d D')
                            : 'N/A'); ?>

                        </td>
                        <td>
                            <span
                                class="badge badge-pill badge-soft-<?php echo e($item->sex === 'male' ? 'success' : 'info'); ?> font-size-11"><?php echo e($item->sex === 'male' ? 'Male' : 'Female'); ?></span>
                        </td>
                        <td style="text-transform: capitalize">
                            <span
                                class="badge badge-pill badge-soft-<?php echo e($item->status ? 'success' : 'danger'); ?> font-size-11"><?php echo e($item->status ?? 'None'); ?></span>
                        </td>
                        <td class="center">
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('cattle.show')): ?>
                                <a role="button" data-id="<?php echo e($item->id); ?>" class="btn btn-sm cattle-info-show"
                                   data-bs-toggle="offcanvas"
                                   data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">
                                    <i class="eye-ico"></i>
                                </a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('cattle.edit')): ?>
                                <a role="button" data-id="<?php echo e($item->id); ?>" class="btn btn-sm cattle-info-edit"
                                   data-bs-toggle="modal" data-bs-target="#cattleEditModal">
                                    <i class="edit-ico"></i>
                                </a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('cattle.delete')): ?>
                                <a href="#" onclick="deletePost(<?php echo e($item->id); ?>)" class="btn btn-sm">
                                    <i class="delete-ico"></i>
                                    <form id="delete-form-<?php echo e($item->id); ?>"
                                          action="<?php echo e(route('cattles.destroy', $item->id)); ?>" method="POST"
                                          style="display: none;">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                    </form>
                                </a>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>

                <?php endif; ?>

                </tbody>
            </table>
        </div>
    </div>
    <div class="modal fade" id="cattleReg">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content p-5">
                <h1 class="modal-title fs-5" id="exampleModalLabel"><?php echo e(__('messages.cattle_info')); ?></h1>
                <p style="font-size: 16px;color: #6E7796;"><?php echo e(__('messages.fill_all_information_below')); ?></p>
                <div class="modal-body p-0 mt-3 createModal"></div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="cattleEditModal">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content p-5">
                <h1 class="modal-title fs-5" id="exampleModalLabel"><?php echo e(__('messages.cattle_info')); ?> </h1>
                <p style="font-size: 16px;color: #6E7796;"><?php echo e(__('messages.fill_all_information_below')); ?></p>
                <div class="modal-body p-0 mt-3 modalEdit"></div>
            </div>
        </div>
    </div>
    <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight"
         aria-labelledby="offcanvasRightLabel">
        <div class="offcanvas-header d-flex justify-content-around">
            <div class="d-flex justify-content-start w-50 align-items-center">
                <button type="button" class="me-4" data-bs-dismiss="offcanvas" aria-label="Close"
                        style=" border: none;">
                    <i class="arrow-back-ico"></i>
                </button>
                <h5 class="offcanvas-title" id="offcanvasRightLabel"><?php echo e(__('messages.cattle_details')); ?></h5>
            </div>
            <div class="d-flex justify-content-end w-50 align-items-center">
                <div class="button-group">
                    <a href="javascript:void(0)" id="btn-Convert-Html2Image" onclick="downloadDiv()"
                       class="button group-button"><i class="download-ico"></i>
                        <?php echo e(__('messages.download')); ?></a>
                    <a href="javascript:void(0)" onclick="printData('data-list-table')"
                       class="button group-button"><i class="print-ico"></i> <?php echo e(__('messages.print')); ?></a>
                </div>

            </div>
        </div>
        <div class="offcanvas-body offcanva_data_view " style="width: 70vw;"></div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script src="<?php echo e(asset('assets/js/cattle.js')); ?>"></script>
    <script type="text/javascript" src="<?php echo e(asset('backend/assets/js/html2canvas.js')); ?>"></script>
    <script>

        let calf_age_limit = "<?php echo e(config('perameters.calf_age_limit')); ?>",
            heifer_age_limit = "<?php echo e(config('perameters.heifer_age_limit')); ?>",
            adult_age_start = "<?php echo e(config('perameters.adult_age_start')); ?>";

        $('.add_new_btn').click(function () {
            axios.get('<?php echo e(route('cattles.create')); ?>').then(function (response) {
                $('.createModal').html(response.data);
                $(".modal").on("hidden.bs.modal", function () {
                    $(".createModal").html("");
                });
            }).catch(function (error) {
                console.log(error)
            })
        })

        $(document).on('click', '.cattle-info-edit', function () {
            let id = $(this).data('id');
            axios.get("<?php echo e(url('system/cattles/edit')); ?>/" + id).then(function (response) {
                $('#cattleReg').hide();
                $('.modalEdit').html(response.data);
                $(".modal").on("hidden.bs.modal", function () {
                    $(".modalEdit").html("");
                });
            }).catch(function (error) {
                console.log(error)
            })
        })
        $(document).on('click', '.cattle-info-show', function () {
            let id = $(this).data('id');
            axios.get("<?php echo e(url('system/cattles/show')); ?>/" + id).then(function (response) {
                $('.offcanva_data_view').html(response.data);
            }).catch(function (error) {
                console.log(error)
            })
        })

        function downloadDiv() {
            html2canvas($('.data-list-table'), {
                onrendered: function (canvas) {
                    saveAs(canvas.toDataURL("image/png"), '' + tag + '.png');
                }
            });
        }

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

<?php echo $__env->make('backend.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\laragon\www\ml_firm\resources\views/backend/cattle/index.blade.php ENDPATH**/ ?>