<?php $__env->startSection('page-title', isset($outlet) ? __('Update') . ' ' . __('Outlet') : __('Add') . ' ' . __('Outlet')); ?>
<?php $__env->startPush('page-css'); ?>
<?php $__env->stopPush(); ?>
<?php $__env->startSection('page-content'); ?>
<div class="container-xxl flex-grow-1 container-p-y">
    <div class="d-flex flex-column flex-md-row justify-content-between align-items-start align-items-md-center mb-6 row-gap-4">
        <div class="d-flex flex-column justify-content-center">
            <h4 class="mb-0"><?php echo e(isset($outlet) ? __('Update Outlet') : __('Add Outlet')); ?></h4>
        </div>
        <?php echo $__env->make('backend.components.breadcrumb', [
            'breadcrumbs' => [
                [
                    'label' => '<i class="ti tabler-home"></i>',
                    'link' => '#'
                ],
                [
                    'label' => __('Outlet'), 
                    'link' => '#'
                ],
                [
                    'label' => isset($outlet) ? __('Update Outlet') : __('Add Outlet'),
                    'active' => true
                ]
            ]
        ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
    </div>

    <?php if(session('success')): ?>
        <?php echo insertSuccess(session('success')); ?>

    <?php endif; ?>
    <?php if(session('error')): ?>
        <?php echo insertFailed(session('error')); ?>

    <?php endif; ?>


    <div class="row">
        <div class="col-12">
            <form action="<?php echo e(isset($outlet) ? route('outlet.update', encrypt($outlet->id)) : route('outlet.store')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <?php if(isset($outlet)): ?>
                    <?php echo method_field('PUT'); ?>
                <?php endif; ?>
                <div class="card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-12 col-md-6 col-lg-4">
                                <div class="mb-5">
                                    <label class="form-label" for="outlet_code"><?php echo e(__('Outlet')); ?> <?php echo e(__('Code')); ?> <?php echo requiredField(); ?></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['outlet_code'];
$__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); ?>" 
                                        placeholder="<?php echo e(__('Outlet')); ?> <?php echo e(__('Code')); ?>" name="outlet_code" id="outlet_code" 
                                        value="<?php echo e(old('outlet_code', isset($outlet) ? $outlet->outlet_code : $outlet_code)); ?>" readonly />
                                    <?php $__errorArgs = ['outlet_code'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>
                            <div class="col-12 col-md-6 col-lg-4">
                                <div class="mb-5">
                                    <label class="form-label" for="outlet_name"><?php echo e(__('Outlet')); ?> <?php echo e(__('Name')); ?> <?php echo requiredField(); ?></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['outlet_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); ?>" 
                                        placeholder="<?php echo e(__('Outlet')); ?> <?php echo e(__('Name')); ?>" name="outlet_name" id="outlet_name" 
                                        value="<?php echo e(old('outlet_name', isset($outlet) ? $outlet->outlet_name : '')); ?>" />
                                    <?php $__errorArgs = ['outlet_name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>
                            <div class="col-12 col-md-6 col-lg-4">
                                <div class="mb-5">
                                    <label class="form-label" for="phone"><?php echo e(__('Phone')); ?> <?php echo requiredField(); ?></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); ?>" 
                                        placeholder="<?php echo e(__('Phone')); ?>" name="phone" id="phone" 
                                        value="<?php echo e(old('phone', isset($outlet) ? $outlet->phone : '')); ?>" />
                                    <?php $__errorArgs = ['phone'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>
                            <div class="col-12 col-md-6 col-lg-4">
                                <div class="mb-5">
                                    <label class="form-label" for="email"><?php echo e(__('Email')); ?></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['email'];
$__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); ?>" 
                                        placeholder="<?php echo e(__('Email')); ?>" name="email" id="email" 
                                        value="<?php echo e(old('email', isset($outlet) ? $outlet->email : '')); ?>" />
                                    <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>
                            <?php if(isEnableGST()): ?>
                            <div class="col-12 col-md-6 col-lg-4">
                                <div class="mb-5">
                                    <label class="form-label" for="state_id"><?php echo e(__('State')); ?> <?php echo requiredField(); ?></label>
                                    <select id="state_id" class="select2 form-select <?php $__errorArgs = ['state_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="state_id" data-placeholder="<?php echo e(__('Select State')); ?>">
                                        <option value=""><?php echo e(__('Select State')); ?></option>
                                        <?php $__currentLoopData = $states ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $state): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($state->id); ?>" data-state-code="<?php echo e($state->state_code); ?>"
                                                <?php echo e(old('state_id', isset($outlet) ? $outlet->state_id : '') == $state->id ? 'selected' : ''); ?>>
                                                <?php echo e($state->state_name); ?> (<?php echo e($state->state_code); ?>)
                                            </option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                    <?php $__errorArgs = ['state_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>
                            <div class="col-12 col-md-6 col-lg-4">
                                <div class="mb-5">
                                    <label class="form-label" for="gstin"><?php echo e(__('GSTIN')); ?> <?php echo requiredField(); ?></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['gstin'];
$__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); ?>"
                                        placeholder="27AABCU9603R1ZM" name="gstin" id="gstin" maxlength="15"
                                        value="<?php echo e(old('gstin', isset($outlet) ? $outlet->gstin : '')); ?>" />
                                    <div class="form-text" id="gstin-hint"><?php echo e(__('15 character Indian GSTIN')); ?></div>
                                    <div class="invalid-feedback" id="gstin-state-error"><?php $__errorArgs = ['gstin'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><?php echo e($message); ?><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?></div>
                                </div>
                            </div>
                            <?php endif; ?>
                            <div class="col-12 col-md-6 col-lg-4">
                                <div class="mb-5">
                                    <label class="form-label" for="status"><?php echo e(__('Status')); ?> <?php echo requiredField(); ?></label>
                                    <select id="status" class="select2 form-select <?php $__errorArgs = ['active_status'];
$__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="active_status" data-placeholder="<?php echo e(__('Status')); ?>">
                                        <option value="Active" <?php echo e(old('active_status', isset($outlet) && $outlet->active_status == 'Active' ? 'selected' : '')); ?>><?php echo e(__('Active')); ?></option>
                                        <option value="Inactive" <?php echo e(old('active_status', isset($outlet) && $outlet->active_status == 'Inactive' ? 'selected' : '')); ?>><?php echo e(__('Inactive')); ?></option>
                                    </select>
                                    <?php $__errorArgs = ['active_status'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>
                            <div class="col-12 col-md-6 col-lg-4">
                                <div class="mb-5">
                                    <label class="form-label" for="address"><?php echo e(__('Address')); ?> <?php echo requiredField(); ?></label>
                                    <textarea class="form-control <?php $__errorArgs = ['address'];
$__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); ?>" 
                                        placeholder="<?php echo e(__('Address')); ?>" name="address" id="address"><?php echo e(old('address', isset($outlet) ? $outlet->address : '')); ?></textarea>
                                    <?php $__errorArgs = ['address'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="card-footer">
                        <div class="d-flex">
                            <button type="submit" class="btn btn-primary waves-effect waves-light me-4">
                                <?php echo submitIconWithText(isset($outlet) ? $outlet : ''); ?>

                            </button>
                            <a href="<?php echo e(route('outlet.index')); ?>" class="btn btn-primary waves-effect waves-light">
                                <?php echo backIconWithText(); ?>

                            </a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

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

<?php $__env->startPush('page-js'); ?>
<?php if(isEnableGST()): ?>
<script>
(function() {
    const GSTIN_REGEX = /^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[A-Z0-9]{1}Z[A-Z0-9]{1}$/;

    function validateGstinForState() {
        const gstinEl = document.getElementById('gstin');
        const stateEl = document.getElementById('state_id');
        const hintEl = document.getElementById('gstin-hint');
        const errorEl = document.getElementById('gstin-state-error');

        if (!gstinEl || !stateEl) return;

        const gstin = gstinEl.value.trim().toUpperCase().replace(/[\s-]/g, '');
        const selectedOption = stateEl.options[stateEl.selectedIndex];
        const stateCode = selectedOption?.dataset?.stateCode || '';

        gstinEl.classList.remove('is-invalid');
        if (errorEl) errorEl.textContent = '';

        if (!gstin) return;

        if (gstin.length !== 15) {
            gstinEl.classList.add('is-invalid');
            if (errorEl) errorEl.textContent = '<?php echo e(__("GSTIN must be exactly 15 characters.")); ?>';
            return;
        }

        if (!GSTIN_REGEX.test(gstin)) {
            gstinEl.classList.add('is-invalid');
            if (errorEl) errorEl.textContent = '<?php echo e(__("Invalid GSTIN format.")); ?>';
            return;
        }

        if (stateCode && gstin.substring(0, 2) !== stateCode) {
            gstinEl.classList.add('is-invalid');
            if (errorEl) errorEl.textContent = '<?php echo e(__("GSTIN state code must match the selected state.")); ?>';
        }
    }

    document.addEventListener('DOMContentLoaded', function() {
        const gstinEl = document.getElementById('gstin');
        const stateEl = document.getElementById('state_id');

        if (gstinEl) {
            gstinEl.addEventListener('input', function() {
                this.value = this.value.toUpperCase().replace(/[^A-Z0-9]/g, '');
                validateGstinForState();
            });
            gstinEl.addEventListener('blur', validateGstinForState);
        }

        if (stateEl) {
            stateEl.addEventListener('change', validateGstinForState);
        }
    });
})();
</script>
<?php endif; ?>
<?php $__env->stopPush(); ?>


<?php echo $__env->make('backend.backend_layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/uzbeacom/pos.uzbea.com/off_pos/Modules/Configuration/resources/views/outlet/create.blade.php ENDPATH**/ ?>