
<?php $__env->startSection('title',' Farms'); ?>
<?php $__env->startSection('content'); ?>
    <h2 class="ms-2 mb-3 card-title"><?php echo e(__('messages.farms') ." ". __('messages.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('farm.create')): ?>
                <div class="add-new-button-hidden">
                    <button class="btn add_new_btn" data-bs-toggle="modal" data-bs-target="#farm_add_modal"
                            ><i class="plus-ico"></i> <?php echo e(__('messages.add') ." ". __('messages.farms')); ?>

                    </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.name')); ?></th>
                    <th><?php echo e(__('messages.owner') ." ". __('messages.name')); ?></th>
                    <th><?php echo e(__('messages.address')); ?></th>
                    <th><?php echo e(__('messages.phone')); ?></th>
                    <th><?php echo e(__('messages.action')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php $__currentLoopData = $farms; $__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->name); ?></td>
                        <td><?php echo e(($item->owner_name) ?? 'N/A'); ?></td>
                        <td><?php echo e(($item->address) ?? 'N/A'); ?></td>
                        <td><?php echo e(($item->phone) ?? 'N/A'); ?></td>
                        <td class="center">
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('farm.edit')): ?>
                                <a id="edit_btn" edit-id="<?php echo e($item->id); ?>" class="btn" data-bs-toggle="modal"
                                   data-bs-target="#farm_edit_modal"><i class="edit-ico"></i></a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('farm.delete')): ?>
                                <a href="#" class="btn" onclick="deletePost(<?php echo e($item->id); ?>)">
                                    <img src="<?php echo e(asset('assets/icons/svg/delete.svg')); ?>" alt="" />
                                    <form id="delete-form-<?php echo e($item->id); ?>"
                                          action="<?php echo e(route('farms.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="modal fade" id="farm_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.farms') ." ". __('messages.information')); ?></h4>
                <div class="modal-body p-0 mt-3">
                    <form action="<?php echo e(route('farms.store')); ?>" method="POST" role="form" id="form1"
                          enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="farmname"><?php echo e(__('messages.name')); ?> <span
                                            class="text-danger">*</span></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['name'];
$__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="name" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.farms')." ". __('messages.name')); ?>" id="farmname" required/>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="ownername"><?php echo e(__('messages.owner')." ". __('messages.name')); ?><span
                                            class="text-danger">*</span></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['owner_name'];
$__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="owner_name" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.owner')." ". __('messages.name')); ?>" required id="ownername"/>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="farmaddress"><?php echo e(__('messages.address')); ?></label>
                                    <input type="text" class="form-control" name="address" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.address')); ?>"
                                           id="farmaddress"/>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="farmphone"><?php echo e(__('messages.phone')); ?> <span
                                            class="text-danger">*</span></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['phone'];
$__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="phone" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.phone')); ?>" id="farmphone" required/>
                                </div>
                            </div>
                        </div>
                        <div class="mt-5 d-flex justify-content-end ">
                            <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('farm.create')): ?>
                                <button type="submit" class="btn btn-primary" >
                                    <?php echo e(__('messages.save')); ?>

                                </button>
                            <?php endif; ?>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="farm_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">Farm Information</h4>
                <div class="modal-body p-0 mt-3">
                    <form action="<?php echo e(route('farms.new.update')); ?>" method="POST" role="form" id="form1"
                          enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="name"><?php echo e(__('messages.name')); ?> <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['name'];
$__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="name" id="name" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.farms')." ". __('messages.name')); ?>" required/>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="owner_name"><?php echo e(__('messages.owner')." ". __('messages.name')); ?><span
                                            class="text-danger">*</span></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['owner_name'];
$__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="owner_name" id="owner_name" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.owner')." ". __('messages.name')); ?>" required/>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="address"><?php echo e(__('messages.address')); ?></label>

                                    <input type="text" class="form-control" name="address" id="address"
                                           placeholder="<?php echo e(__('messages.enter') ." ". __('messages.address')); ?>"/>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="phone"><?php echo e(__('messages.phone')); ?> <span
                                            class="text-danger">*</span></label>

                                    <input type="text" class="form-control <?php $__errorArgs = ['phone'];
$__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="phone" id="phone" placeholder="<?php echo e(__('messages.enter') ." ". __('messages.phone')); ?>"/>
                                </div>
                            </div>
                        </div>
                        <input type="hidden" name="item_id" id="item_id">
                        <div class="mt-5 d-flex justify-content-end ">
                            <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('farm.edit')): ?>
                                <button type="submit" class="btn btn-primary" >
                                    <?php echo e(__('messages.update')); ?>

                                </button>
                            <?php endif; ?>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startPush('scripts'); ?>
    <script type="text/javascript">
        $(document).ready(function ($) {
            $(document).on('click', '#edit_btn', function () {
                let id = $(this).attr('edit-id');
                $.ajax({
                    type: "GET",
                    url: "<?php echo e(url('system/farms')); ?>/" + id + "/edit",
                    success: function (res) {
                        $('#name').val(res.name);
                        $('#owner_name').val(res.owner_name);
                        $('#address').val(res.address);
                        $('#phone').val(res.phone);
                        $('#item_id').val(res.id);
                    },
                    error: function (response) {
                        console.log(response);
                    }
                });
            });
        });
    </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/general/farm/index.blade.php ENDPATH**/ ?>