<?php $__env->startSection('title', 'Member'); ?>
<?php $__env->startPush('css'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('/assets/css/datepicker.css')); ?>"/>
    <style>
        .is-invalid {
            border-color: var(--color-primary) !important;
        }
    </style>
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>
    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="">
                    <h4 class="mb-1">Create User</h4>
                    <nav style="--bs-breadcrumb-divider: '|';"  aria-label="breadcrumb" >
                        <ol class="breadcrumb m-0">
                            <li class="breadcrumb-item"><a href="<?php echo e(route('user.index')); ?>" class="text-primary">User</a></li>
                            <li class="breadcrumb-item active" aria-current="page">Create</li>
                        </ol>
                    </nav>
                </div>
            </div>

            <div class="row">
                <div class="mt-4">
                    <div class="col-8">
                        <div class="card myCard form-main-div">
                            <form id="userForm">
                                <div class="row g-3">
                                    <div class="col-lg-12">
                                        <?php echo csrf_field(); ?>
                                        <input type="hidden" name="id" value="<?php echo e($user->id ?? ''); ?>">
                                        <label for="name">Name<span class="required-sign ">*</span></label>
                                        <input type="text" class="form-control" id="name" name="name" value="<?php echo e($user->name ?? ''); ?>" placeholder="Name" >
                                    </div>
                                    <div class="col-lg-12">
                                        <label for="phone">Phone</label>
                                        <input type="text" class="form-control" id="phone" name="phone" value="<?php echo e($user->phone ?? ''); ?>" placeholder="Phone" >
                                    </div>
                                    <div class="col-lg-12">
                                        <label for="name">Email<span class="required-sign ">*</span></label>
                                        <input type="text" class="form-control" id="email" name="email" value="<?php echo e($user->email ?? ''); ?>" placeholder="Email" >
                                    </div>
                                    <div class="col-lg-12">
                                        <label for="password">Password<span class="required-sign ">*</span></label>
                                        <input type="password" class="form-control" id="password" name="password" value="<?php echo e($user->password ?? ''); ?>" placeholder="Password" >
                                    </div>
                                    <div class="col-lg-12">
                                        <label for="user-type">User Type<span class="required-sign ">*</span></label>
                                        <select name="user_type" class="form-select" id="user-type">
                                            <option value="cm" <?php echo e(isset($user) && $user->user_type == "cm" ? 'selected' :''); ?>>CM</option>
                                            <option value="cc" <?php echo e(isset($user) && $user->user_type == "cc" ? 'selected' :''); ?>>CC</option>
                                        </select>
                                    </div>
                                    <div class="col-lg-12">
                                        <label for="menu-grp">Menu Grp<span class="required-sign ">*</span></label>
                                        <select name="menu_grp" class="form-select" id="menu-grp">
                                            <?php $__currentLoopData = getMenuGrp(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($val->id); ?>" <?php echo e(isset($user) && $user->menu_grp == $key ? 'selected' :''); ?>><?php echo e($val->menu_grp_name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                    <div class="col-lg-12">
                                        <label for="status">Status<span class="required-sign ">*</span></label>
                                        <select name="status" class="form-select" id="status">
                                            <?php $__currentLoopData = config('constant.NON_STATUS'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($key); ?>" <?php echo e(isset($user) && $user->status == $key ? 'selected' :''); ?>><?php echo e($val); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                    <div class="mt-4">
                                        <div>
                                            <button class="btn btn-secondary px-4">Save</button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <?php $__env->startPush('scripts'); ?>
        <script>
            $(document).ready(function() {

                $('#userForm').on('submit', function(e) {
                    e.preventDefault();

                    let formData = new FormData(this);
                    let id = $('input[name="id"]').val();
                    let url = id ? "<?php echo e(route('user.update', ':id')); ?>".replace(':id', id) : "<?php echo e(route('user.store')); ?>";

                    $.ajax({
                        url: url,
                        method: 'POST',
                        data: formData,
                        processData: false,
                        contentType: false,
                        success: function(response) {
                            notification('success',response.message,'success',2000)
                            if (!id) $('#userForm')[0].reset(); // clear form on create
                        },
                        error: function(xhr) {
                            let msg = 'Something went wrong.';
                            if (xhr.responseJSON && xhr.responseJSON.message) {
                                msg = xhr.responseJSON.message;
                            }
                            notification('error',msg,'danger',2000)
                        }
                    });
                });
            });
        </script>
    <?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/nari/resources/views/admin/user.blade.php ENDPATH**/ ?>