

<?php

        if (! isset($selected)) {
            $sortName = str_replace("[]", "", $name);
            $selected = request()->get($sortName);
            if (is_array($selected)) {
                $selected = array_first($selected);
            }
        }
        if (isset($i)) {
            $val = isset(request()->get($sortName)[$i]) ? request()->get($sortName)[$i] : "";
        }
?>
<select class="c-selectbox <?php if(isset($class)): ?> <?php echo e($class); ?><?php endif; ?>" <?php if(isset($required)): ?> required <?php endif; ?> id="<?php if(isset($id)): ?><?php echo e($id); ?><?php endif; ?>" name="<?php echo e($name); ?>">
    <?php if(!empty($title)): ?>
        <option value="" <?php echo e(isSelected('', $selected?? null)); ?>>未選択</option>
    <?php endif; ?>
    <?php if(is_array($options)): ?>
        <?php if(!isset($val)): ?>
            <?php if(isset($max)): ?>
                <?php $__currentLoopData = $options; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                   <?php if($key <= $max): ?>
                        <option value="<?php echo e($item['code']); ?>" <?php if(isset($selected) && $selected==$item['code']): ?> selected
                                <?php elseif(old($name) != null && old($name)==$item['code']): ?> selected <?php endif; ?>><?php echo e($item['name']); ?></option>
                    <?php endif; ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php else: ?>
                <?php $__currentLoopData = $options; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($item['code']); ?>" <?php if(isset($selected) && $selected==$item['code']): ?> selected
                            <?php elseif(old($name) != null && old($name)==$item['code']): ?> selected <?php endif; ?>><?php echo e($item['name']); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php endif; ?>
        <?php else: ?>
            <?php if(isset($max)): ?>
                <?php $__currentLoopData = $options; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php if($key <= $max): ?>
                        <option value="<?php echo e($item['code']); ?>"
                                <?php if($val==$item['code']): ?> selected
                                <?php elseif(old($name) != null && old($name)==$item['code']): ?> selected
                                <?php endif; ?>><?php echo e($item['name']); ?></option>
                    <?php endif; ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php else: ?>
                <?php $__currentLoopData = $options; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($item['code']); ?>"
                        <?php if($val==$item['code']): ?> selected
                        <?php elseif(old($name) != null && old($name)==$item['code']): ?> selected
                        <?php endif; ?>><?php echo e($item['name']); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
</select>
