<div class="row">
    
    <div class="col-md-6">
        <div class="card">
            <div class="card-header"><strong>Basic Settings</strong></div>
            <div class="card-body">
                <div class="mb-3">
                    <label class="form-label">Settings Name <span class="text-danger">*</span></label>
                    <input type="text" name="name" class="form-control"
                           value="<?php echo e($setting->name ?? ''); ?>" required>
                </div>

                <div class="mb-3">
                    <label class="form-label">Branch</label>
                    <select name="branch_id" class="form-control">
                        <option value="">All Branches</option>
                        <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($branch->id); ?>"
                                <?php echo e((isset($setting) && $setting->branch_id == $branch->id) ? 'selected' : ''); ?>>
                                <?php echo e($branch->name); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="mb-3">
                    <label class="form-label">Description</label>
                    <textarea name="description" class="form-control" rows="2"><?php echo e($setting->description ?? ''); ?></textarea>
                </div>

                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label class="form-label">Source Type <span class="text-danger">*</span></label>
                            <select name="source_type" id="source_type" class="form-control" required>
                                <option value="CSV" <?php echo e((isset($setting) && $setting->source_type == 'CSV') ? 'selected' : ''); ?>>CSV Only</option>
                                <option value="API" <?php echo e((isset($setting) && $setting->source_type == 'API') ? 'selected' : ''); ?>>API Only</option>
                                <option value="BOTH" <?php echo e((isset($setting) && $setting->source_type == 'BOTH') ? 'selected' : ''); ?>>Both CSV & API</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label class="form-label">Punch Mode <span class="text-danger">*</span></label>
                            <select name="punch_mode" id="punch_mode" class="form-control" required>
                                <option value="IN_OUT" <?php echo e((isset($setting) && $setting->punch_mode == 'IN_OUT') ? 'selected' : ''); ?>>IN/OUT (Separate punch types)</option>
                                <option value="SINGLE" <?php echo e((isset($setting) && $setting->punch_mode == 'SINGLE') ? 'selected' : ''); ?>>SINGLE (Auto-detect by sequence)</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-6">
                        <div class="form-check">
                            <input type="checkbox" name="is_default" value="1" class="form-check-input"
                                   <?php echo e((isset($setting) && $setting->is_default) ? 'checked' : ''); ?>>
                            <label class="form-check-label">Set as Default Profile</label>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-check">
                            <input type="checkbox" name="status" value="1" class="form-check-input"
                                   <?php echo e((!isset($setting) || $setting->status) ? 'checked' : ''); ?>>
                            <label class="form-check-label">Active</label>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    
    <div class="col-md-6">
        <div class="card">
            <div class="card-header"><strong>Format Settings</strong></div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label class="form-label">Date Format <span class="text-danger">*</span></label>
                            <select name="date_format" class="form-control" required>
                                <?php $__currentLoopData = $dateFormats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $format => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($format); ?>"
                                        <?php echo e((isset($setting) && $setting->date_format == $format) ? 'selected' : ''); ?>>
                                        <?php echo e($label); ?>

                                    </option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-3">
                            <label class="form-label">Time Format <span class="text-danger">*</span></label>
                            <select name="time_format" class="form-control" required>
                                <?php $__currentLoopData = $timeFormats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $format => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($format); ?>"
                                        <?php echo e((isset($setting) && $setting->time_format == $format) ? 'selected' : ''); ?>>
                                        <?php echo e($label); ?>

                                    </option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="mb-3">
                    <label class="form-label">DateTime Format (Combined)</label>
                    <input type="text" name="datetime_format" class="form-control"
                           value="<?php echo e($setting->datetime_format ?? ''); ?>"
                           placeholder="Leave empty to use Date + Time formats">
                    <small class="text-muted">Use this if your device outputs a single combined datetime field (e.g., Y-m-d H:i:s)</small>
                </div>

                <div class="mb-3">
                    <label class="form-label">Timezone <span class="text-danger">*</span></label>
                    <select name="timezone" class="form-control" required>
                        <?php $__currentLoopData = $timezones; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tz): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($tz); ?>"
                                <?php echo e((isset($setting) && $setting->timezone == $tz) ? 'selected' : ($tz == 'Asia/Colombo' ? 'selected' : '')); ?>>
                                <?php echo e($tz); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                
                <div id="csv-settings">
                    <hr>
                    <h6>CSV Settings</h6>
                    <div class="row">
                        <div class="col-md-4">
                            <div class="mb-3">
                                <label class="form-label">Delimiter</label>
                                <select name="csv_delimiter" class="form-control">
                                    <?php $__currentLoopData = $delimiters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $delimiter => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($delimiter); ?>"
                                            <?php echo e((isset($setting) && $setting->csv_delimiter == $delimiter) ? 'selected' : ''); ?>>
                                            <?php echo e($label); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="mb-3">
                                <label class="form-label">Encoding</label>
                                <select name="csv_encoding" class="form-control">
                                    <?php $__currentLoopData = $encodings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $encoding => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($encoding); ?>"
                                            <?php echo e((isset($setting) && $setting->csv_encoding == $encoding) ? 'selected' : ''); ?>>
                                            <?php echo e($label); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="mb-3 pt-4">
                                <div class="form-check">
                                    <input type="checkbox" name="csv_has_header" value="1"
                                           class="form-check-input"
                                           <?php echo e((!isset($setting) || $setting->csv_has_header) ? 'checked' : ''); ?>>
                                    <label class="form-check-label">Has Header Row</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="card mt-3">
    <div class="card-header">
        <strong>Field Mapping Configuration</strong>
        <small class="text-muted d-block">Map source data fields to target attendance database fields</small>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered" id="mappingTable">
                <thead class="table-light">
                    <tr>
                        <th width="200">Target Field</th>
                        <th width="100">Required</th>
                        <th class="csv-col">CSV Column Index (0-based)</th>
                        <th class="api-col">API JSON Path</th>
                        <th>Description</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><strong>Employee ID/Code</strong></td>
                        <td><span class="badge bg-danger">Required</span></td>
                        <td class="csv-col">
                            <input type="number" name="field_mapping[emp_id][csv_column]"
                                   class="form-control form-control-sm" min="0" placeholder="0">
                        </td>
                        <td class="api-col">
                            <input type="text" name="field_mapping[emp_id][api_path]"
                                   class="form-control form-control-sm" placeholder="employee.code">
                        </td>
                        <td><small class="text-muted">Employee code that matches employee_code in employees table</small></td>
                    </tr>
                    <tr>
                        <td><strong>Date</strong></td>
                        <td><span class="badge bg-warning text-dark">Conditional</span></td>
                        <td class="csv-col">
                            <input type="number" name="field_mapping[date][csv_column]"
                                   class="form-control form-control-sm" min="0" placeholder="1">
                        </td>
                        <td class="api-col">
                            <input type="text" name="field_mapping[date][api_path]"
                                   class="form-control form-control-sm" placeholder="punch_date">
                        </td>
                        <td><small class="text-muted">Required if DateTime is not provided</small></td>
                    </tr>
                    <tr>
                        <td><strong>Time</strong></td>
                        <td><span class="badge bg-warning text-dark">Conditional</span></td>
                        <td class="csv-col">
                            <input type="number" name="field_mapping[time][csv_column]"
                                   class="form-control form-control-sm" min="0" placeholder="2">
                        </td>
                        <td class="api-col">
                            <input type="text" name="field_mapping[time][api_path]"
                                   class="form-control form-control-sm" placeholder="punch_time">
                        </td>
                        <td><small class="text-muted">Required if DateTime is not provided</small></td>
                    </tr>
                    <tr>
                        <td><strong>DateTime (Combined)</strong></td>
                        <td><span class="badge bg-secondary">Optional</span></td>
                        <td class="csv-col">
                            <input type="number" name="field_mapping[datetime][csv_column]"
                                   class="form-control form-control-sm" min="0" placeholder="">
                        </td>
                        <td class="api-col">
                            <input type="text" name="field_mapping[datetime][api_path]"
                                   class="form-control form-control-sm" placeholder="timestamp">
                        </td>
                        <td><small class="text-muted">Use if date & time are in a single field</small></td>
                    </tr>
                    <tr>
                        <td><strong>Punch Type</strong></td>
                        <td><span class="badge bg-warning text-dark">Conditional</span></td>
                        <td class="csv-col">
                            <input type="number" name="field_mapping[punch_type][csv_column]"
                                   class="form-control form-control-sm" min="0" placeholder="3">
                        </td>
                        <td class="api-col">
                            <input type="text" name="field_mapping[punch_type][api_path]"
                                   class="form-control form-control-sm" placeholder="type">
                        </td>
                        <td><small class="text-muted">IN/OUT indicator. Required for IN_OUT mode, optional for SINGLE mode</small></td>
                    </tr>
                    <tr>
                        <td><strong>In Time (Direct)</strong></td>
                        <td><span class="badge bg-secondary">Optional</span></td>
                        <td class="csv-col">
                            <input type="number" name="field_mapping[in_time][csv_column]"
                                   class="form-control form-control-sm" min="0" placeholder="">
                        </td>
                        <td class="api-col">
                            <input type="text" name="field_mapping[in_time][api_path]"
                                   class="form-control form-control-sm" placeholder="check_in">
                        </td>
                        <td><small class="text-muted">Use if IN time is in a separate column</small></td>
                    </tr>
                    <tr>
                        <td><strong>Out Time (Direct)</strong></td>
                        <td><span class="badge bg-secondary">Optional</span></td>
                        <td class="csv-col">
                            <input type="number" name="field_mapping[out_time][csv_column]"
                                   class="form-control form-control-sm" min="0" placeholder="">
                        </td>
                        <td class="api-col">
                            <input type="text" name="field_mapping[out_time][api_path]"
                                   class="form-control form-control-sm" placeholder="check_out">
                        </td>
                        <td><small class="text-muted">Use if OUT time is in a separate column</small></td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="alert alert-info mt-2 mb-0">
            <strong>Note:</strong>
            <ul class="mb-0">
                <li>CSV Column Index is 0-based (first column = 0, second = 1, etc.)</li>
                <li>API JSON Path uses dot notation (e.g., "data.employee.code" for nested objects)</li>
                <li>Leave fields empty if not applicable to your data source</li>
            </ul>
        </div>
    </div>
</div>


<div class="card mt-3" id="in-out-mapping-card">
    <div class="card-header">
        <strong>IN/OUT Data Structure</strong>
        <small class="text-muted d-block">Define how IN and OUT times are structured in your data</small>
    </div>
    <div class="card-body">
        
        <div class="mb-3">
            <label class="form-label"><strong>How does your data provide IN/OUT times?</strong></label>
            <div class="row g-3">
                <?php
                    $currentStructure = isset($setting) && isset($setting->in_out_mapping['structure'])
                        ? $setting->in_out_mapping['structure']
                        : 'SAME_COLUMN';
                ?>
                <div class="col-md-4">
                    <div class="card h-100 border-primary structure-option" data-structure="SEPARATE_COLUMNS">
                        <div class="card-body">
                            <div class="form-check">
                                <input type="radio" name="in_out_structure" id="structure_separate_columns"
                                       value="SEPARATE_COLUMNS" class="form-check-input"
                                       <?php echo e($currentStructure == 'SEPARATE_COLUMNS' ? 'checked' : ''); ?>>
                                <label class="form-check-label" for="structure_separate_columns">
                                    <strong>Separate Columns</strong>
                                </label>
                            </div>
                            <p class="text-muted small mt-2 mb-0">IN time and OUT time are in <strong>different columns</strong> of the same row.</p>
                            <div class="mt-2 small">
                                <code>EMP001, 2024-01-15, 08:30, 17:30</code>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card h-100 border-success structure-option" data-structure="SAME_COLUMN">
                        <div class="card-body">
                            <div class="form-check">
                                <input type="radio" name="in_out_structure" id="structure_same_column"
                                       value="SAME_COLUMN" class="form-check-input"
                                       <?php echo e($currentStructure == 'SAME_COLUMN' ? 'checked' : ''); ?>>
                                <label class="form-check-label" for="structure_same_column">
                                    <strong>Same Column (Multiple Rows)</strong>
                                </label>
                            </div>
                            <p class="text-muted small mt-2 mb-0">Multiple rows per employee with <strong>punch type indicator</strong>.</p>
                            <div class="mt-2 small">
                                <code>EMP001, 2024-01-15, 08:30, IN</code><br>
                                <code>EMP001, 2024-01-15, 17:30, OUT</code>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card h-100 border-warning structure-option" data-structure="TIME_BASED">
                        <div class="card-body">
                            <div class="form-check">
                                <input type="radio" name="in_out_structure" id="structure_time_based"
                                       value="TIME_BASED" class="form-check-input"
                                       <?php echo e($currentStructure == 'TIME_BASED' ? 'checked' : ''); ?>>
                                <label class="form-check-label" for="structure_time_based">
                                    <strong>Time-Based Auto</strong>
                                </label>
                            </div>
                            <p class="text-muted small mt-2 mb-0">Multiple rows, <strong>no punch type</strong>. MIN time = IN, MAX time = OUT.</p>
                            <div class="mt-2 small">
                                <code>EMP001, 2024-01-15, 08:30</code><br>
                                <code>EMP001, 2024-01-15, 17:30</code>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <hr>

        
        <div id="separate-columns-info" style="display: none;">
            <div class="alert alert-info mb-0">
                <i class="bi bi-info-circle"></i>
                <strong>Separate Columns Mode:</strong>
                <p class="mb-2">Use the <strong>"In Time (Direct)"</strong> and <strong>"Out Time (Direct)"</strong> fields in the Field Mapping section above to specify which columns contain the IN and OUT times.</p>
                <small>Example CSV: <code>EMP001, 2024-01-15, 08:30:00, 17:30:00</code> where column 2 = IN time, column 3 = OUT time</small>
            </div>
        </div>

        
        <div id="same-column-values">
            <h6 class="mb-3"><i class="bi bi-tag"></i> Punch Type Value Mapping</h6>
            <?php
                $inValues = isset($setting) && isset($setting->in_out_mapping['in_values'])
                    ? implode(',', $setting->in_out_mapping['in_values'])
                    : 'IN,I,1,CHECKIN,CHECK-IN';
                $outValues = isset($setting) && isset($setting->in_out_mapping['out_values'])
                    ? implode(',', $setting->in_out_mapping['out_values'])
                    : 'OUT,O,0,CHECKOUT,CHECK-OUT';
                $caseSensitive = isset($setting) && isset($setting->in_out_mapping['case_sensitive'])
                    ? $setting->in_out_mapping['case_sensitive']
                    : false;
            ?>
            <div class="row">
                <div class="col-md-5">
                    <label class="form-label">IN Values <span class="text-muted">(comma-separated)</span></label>
                    <input type="text" id="in_values" class="form-control"
                           value="<?php echo e($inValues); ?>" placeholder="IN,I,1,CHECKIN">
                    <small class="text-muted">Values in the punch_type column that indicate an IN punch</small>
                </div>
                <div class="col-md-5">
                    <label class="form-label">OUT Values <span class="text-muted">(comma-separated)</span></label>
                    <input type="text" id="out_values" class="form-control"
                           value="<?php echo e($outValues); ?>" placeholder="OUT,O,0,CHECKOUT">
                    <small class="text-muted">Values in the punch_type column that indicate an OUT punch</small>
                </div>
                <div class="col-md-2">
                    <label class="form-label">&nbsp;</label>
                    <div class="form-check mt-2">
                        <input type="checkbox" id="case_sensitive" class="form-check-input"
                               <?php echo e($caseSensitive ? 'checked' : ''); ?>>
                        <label class="form-check-label">Case Sensitive</label>
                    </div>
                </div>
            </div>
            <div class="alert alert-secondary mt-3 mb-0">
                <i class="bi bi-lightbulb"></i>
                <strong>Fallback:</strong> If a punch type value doesn't match any IN/OUT values, the system will use sequence-based detection (odd = IN, even = OUT).
            </div>
        </div>

        
        <div id="time-based-info" style="display: none;">
            <div class="alert alert-success mb-0">
                <i class="bi bi-clock"></i>
                <strong>Time-Based Auto Detection:</strong>
                <p class="mb-2">The system will automatically determine IN/OUT based on time for each employee per day:</p>
                <ul class="mb-0">
                    <li><strong>Earliest punch</strong> of the day = <span class="badge bg-success">IN</span></li>
                    <li><strong>Latest punch</strong> of the day = <span class="badge bg-danger">OUT</span></li>
                    <li>All punches in between will be recorded as additional punch records</li>
                </ul>
            </div>
        </div>
    </div>
</div>
<?php /**PATH /home/codeproh/va.laraoffice.com/app/Modules/HR/Attendance/Providers/../Views/settings/partials/form.blade.php ENDPATH**/ ?>