<?php $__env->startSection('title'); ?>
    <?php echo e(__('messages.calving')); ?>

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

<?php $__env->startSection('styles'); ?>
    <!-- DataTables -->
    <link href="<?php echo e(asset('backend/assets/libs/datatables/datatables.min.css')); ?>" rel="stylesheet" type="text/css"/>

<?php $__env->stopSection(); ?>
<?php
    $c_id = request()->get('tag');
?>
<?php $__env->startSection('content'); ?>
    <h2 class="ms-2 mb-3 card-title"><?php echo e(__('messages.calving_list')); ?></h2>
    <div class="card mt-3 m-lg-2">
        <div class="card-body table_card mt-2">
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('AI.create')): ?>
                <div class="add-new-button-hidden">
                    <button class="btn add_new_btn" data-bs-toggle="modal" data-bs-target="#dryoff_add_modal"
                    ><i class="plus-ico"></i> <?php echo e(__('messages.add_calving')); ?>

                    </button>
                </div>
            <?php endif; ?>
            <table id="myTable" class="table table-bordered dt-responsive nowrap w-100">
                <thead>
                <tr>
                    <th><?php echo e(__('messages.sl')); ?></th>
                    <th><?php echo e(__('messages.tag_id')); ?></th>
                    <th><?php echo e(__('messages.calving_date')); ?></th>
                    <th><?php echo e(__('messages.calving_type')); ?></th>
                    <th><?php echo e(__('messages.calf_sex')); ?></th>
                    <th><?php echo e(__('messages.action')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php $__currentLoopData = $calvings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e(++$key); ?></td>
                        <td><?php echo e(($item->cattle_id) ? $item->cattle->tag->uid : 'N/A'); ?></td>
                        <td><?php echo e(($item->calving_date) ? \Carbon\Carbon::createFromFormat('Y-m-d', $item->calving_date)->format('d-m-Y') : 'N/A'); ?></td>
                        <td>
                            <span
                                class="badge badge-pill badge-soft-<?php echo e(($item->calving_type === 'normal') ? 'success' : 'danger'); ?> font-size-11"><?php echo e(($item->calving_type === 'normal') ? 'Normal' : 'Abnormal'); ?></span>
                        </td>
                        <td>
                            <span
                                class="badge badge-pill badge-soft-<?php echo e(($item->calf_sex === 'male') ? 'success' : 'info'); ?> font-size-11"><?php echo e(($item->calf_sex === 'male') ? 'Male' : 'Female'); ?></span>
                        </td>
                        <td class="center">
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Calving.list')): ?>
                                <a data-url="<?php echo e(route('calving.show',$item->id)); ?>" class="btn view_details"
                                   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('Calving.edit')): ?>
                                <a data-url="<?php echo e(route('calving.edit',$item->id)); ?>" class="btn edit-btn"
                                   data-bs-toggle="modal"
                                   data-bs-target="#dryoff_edit_modal">
                                    <i class="edit-ico"></i>
                                </a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Calving.delete')): ?>
                                <a href="#" class="btn " onclick="deletePost(<?php echo e($item->id); ?>)">
                                    <i class="delete-ico"></i>

                                    <form id="delete-form-<?php echo e($item->id); ?>"
                                          action="<?php echo e(route('calving.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(); ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight"
         aria-labelledby="offcanvasRightLabel">
        <div class="offcanvas-header">
            <button type="button" class="me-4" data-bs-dismiss="offcanvas" aria-label="Close"
                    style=" border: none;">
                <svg xmlns="http://www.w3.org/2000/svg" width="24"
                     height="24" viewBox="0 0 24 24" fill="none">
                    <path d="M20 11H7.83L13.42 5.41L12 4L4 12L12 20L13.41 18.59L7.83 13H20V11Z" fill="black"/>
                </svg>
            </button>
            <h5 class="offcanvas-title" id="offcanvasRightLabel"><?php echo e(__('messages.calving_details')); ?> </h5>
        </div>
        <div class="offcanvas-body me-2 offcanva_data_view" style="width: 24rem;"></div>
    </div>

    <!-- Add New -->
    <div class="modal fade" id="dryoff_add_modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content p-5">
                <h4 class="card-title"><?php echo e(__('messages.add_calving')); ?></h4>
                <div class="modal-body p-0 mt-3">
                    <form action="<?php echo e(route('calving.store')); ?>" method="POST" role="form" id="form1"
                          enctype="multipart/form-data" autocomplete="off">
                        <?php echo csrf_field(); ?>
                        <div class="row">
                            <div class="col-md-6">
                                <label class="form-label" for="cattle_id"><?php echo e(__('messages.tag_id')); ?><span
                                        class="text-danger">*</span></label>
                                <select class="form-control select2-multiple <?php $__errorArgs = ['cattle_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                        name="cattle_id" id="cattle_id" required>
                                    <option value="" disabled>Select Tag Id</option>
                                    <?php $__currentLoopData = $cattles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php
                                            $today = Carbon\Carbon::now()->addDays(1)->format('Y-m-d');
                                            $adult_age_start_day = config('perameters.adult_age_start');
                                            $adult_date = Carbon\Carbon::createFromFormat('Y-m-d', $item->birth_date)->addDays($adult_age_start_day)->format('Y-m-d');
                                        ?>
                                        <?php if($today >=  $adult_date): ?>
                                            <option
                                                value="<?php echo e($item->id); ?>" <?php echo e((($c_id) && ($c_id===$item->id)) ? 'selected' : ''); ?>><?php echo e($item->tag->uid); ?></option>
                                        <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="calving_date"><?php echo e(__('messages.calving_date')); ?> <span
                                        class="text-danger">*</span></label>
                                <input type="text"
                                       class="form-control custom-date-format <?php $__errorArgs = ['calving_date'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                       name="calving_date" id="calving_date" value="<?php echo e(old('calving_date')); ?>"
                                       placeholder="Pick calving date" required/>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <label class="form-label" for="calving_type"><?php echo e(__('messages.calving_type')); ?> <span
                                        class="text-danger">*</span></label>
                                <select class="form-control  <?php $__errorArgs = ['calving_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                        name="calving_type" id="calving_type" required>
                                    <option value="">Select Calving Type</option>
                                    <option value="normal">Normal</option>
                                    <option value="abnormal">Abnormal</option>
                                    <option value="dead">Dead</option>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="calf_sex"><?php echo e(__('messages.calf_sex')); ?> <span
                                        class="text-danger">*</span></label>
                                <select class="form-control  <?php $__errorArgs = ['calf_sex'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" name="calf_sex"
                                        id="calf_sex" required>
                                    <option value="">Select Calf Sex</option>
                                    <option value="male">Male</option>
                                    <option value="female">Female</option>
                                </select>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <label class="form-label" for="birth_weight"><?php echo e(__('messages.birth_weight')); ?></label>
                                <input type="text" class="form-control" name="birth_weight" id="birth_weight"
                                       value="<?php echo e(old('birth_weight')); ?>" placeholder="Enter calf birth weight"/>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label" for="calf_id"><?php echo e(__('messages.calf_code')); ?></label>
                                <input type="text" class="form-control" name="calf_id" id="calf_id"
                                       value="<?php echo e(old('calf_id')); ?>" placeholder="Enter calf code or id"/>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <label class="form-label"
                                       for="reproductive_problems"> <?php echo e(__('messages.reproductive_problem')); ?></label>
                                <select class="form-control " name="reproductive_problems" id="reproductive_problems">
                                    <option value="">Select Reproductive Problems</option>
                                    <option value="rop">ROP</option>
                                    <option value="dystocia">Dystocia</option>
                                    <option value="post_prolapse">Post Prolapse</option>
                                    <option value="pre_prolapse">Pre Prolapse</option>
                                    <option value="rfm_instead_of_rop">RFM instead of ROP</option>
                                    <option value="follicular_cyst">Follicular cyst</option>
                                    <option value="luteal_cyst">Luteal cys</option>
                                    <option value="sub_clinical_endometritis">Sub-clinical Endometritis</option>
                                    <option value="pyomtera">Pyomtera</option>
                                    <option value="metritis">Metritis</option>
                                    <option value="vaginitis">Vaginitis</option>
                                    <option value="cervicitis">Cervicitis</option>
                                    <option value="uterine_prolapse">Uterine Prolapse</option>
                                    <option value="vaginal_prolapse">Vaginal Prolapse</option>
                                    <option value="uterovaginal_prolapse">Uterovaginal Prolapse</option>
                                    <option value="irregular_ovary">Irregular Ovary</option>
                                    <option value="small_ovary">Small Ovary</option>
                                </select>
                                <div class="row mt-3">
                                    <div class="form-group mt-2">
                                        <label class="form-label"
                                               for="calving_by"><?php echo e(__('messages.calving_by')); ?></label>
                                        <select class="form-control" name="calving_by" id="calving_by">
                                            <option value="">Select Calving By</option>
                                            <?php $__currentLoopData = $inseminators; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($item->id); ?>"><?php echo e($item->name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="comments"><?php echo e(__('messages.comments')); ?></label>
                                    <textarea type="text" class="form-control" name="comments" id="comments" rows="5"
                                              cols="50"
                                              placeholder="Enter comments"><?php echo e(old('comments')); ?></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="mt-5 d-flex justify-content-end mt-5">
                            <button type="button" class="btn  me-2" data-bs-dismiss="modal"
                                    style="background: #EAECF0;">
                                <?php echo e(__('messages.close')); ?>

                            </button>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Calving.create')): ?>
                                <div class="d-flex flex-flex-row-reverse gap-2">
                                    <button type="submit" class="btn btn-primary waves-effect waves-light">
                                        <?php echo e(__('messages.save')); ?>

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

                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- Add New End -->
    <div class="modal fade" id="dryoff_edit_modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content p-5">
                <h4 class="card-title"><?php echo e(__('messages.update_calving')); ?></h4>
                <div class="modal-body p-0 mt-3 editModal">

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

<?php $__env->startPush('scripts'); ?>
    <script type="text/javascript">
        $(document).ready(function ($) {
            $('.select2-multiple').select2({
                dropdownParent: $('#dryoff_add_modal'),
                width: 'resolve',
            });
        });
        $(".custom-date-format").datepicker({
            autoHide: true,
            endDate: "today",
            format: 'dd-mm-yyyy',
        });
        $('.view_details').click(function () {
            let id = $(this).attr('data-url');
            $('.offcanva_data_view').empty();
            axios.get(id, {}).then(function (response) {
                $('.offcanva_data_view').html(response.data);

            }).catch(function (error) {
                console.log(error);
            });
        });

        $(document).on('click', '.edit-btn', function () {
            let url = $(this).data('url');
            axios.get(url).then(function (response) {
                $('.editModal').html(response.data);
                $('#disposalEditModal').modal('show');
            }).catch(function (error) {
                console.log(error)
            })
        });


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

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