<?php
    $fieldOptions = $field->options();
    $checkedValues = (array) $field->value;
?>
<!-- Checkbox List -->
<?php if ($this->previewMode && $field->value): ?>

    <div class="field-checkboxlist">
        <?php $index = 0; foreach ($fieldOptions as $value => $option): ?>
            <?php
                $index++;
                $checkboxId = 'checkbox_'.$field->getId().'_'.$index;
                if (!in_array($value, $checkedValues)) continue;
                if (is_string($option)) $option = [$option];
            ?>
            <div class="checkbox custom-checkbox">
                <input
                    type="checkbox"
                    id="<?= $checkboxId ?>"
                    name="<?= $field->getName() ?>[]"
                    value="<?= $value ?>"
                    disabled="disabled"
                    checked="checked">

                <label for="<?= $checkboxId ?>">
                    <?= e(trans($option[0])) ?>
                </label>
                <?php if (isset($option[1])): ?>
                    <p class="help-block"><?= e(trans($option[1])) ?></p>
                <?php endif ?>
            </div>
        <?php endforeach ?>
    </div>

<?php elseif (!$this->previewMode && count($fieldOptions)): ?>

    <div class="field-checkboxlist">
        <?php if (count($fieldOptions) > 10): ?>
            <!-- Quick selection -->
            <small>
                <?= e(trans('backend::lang.form.select')) ?>:
                <a href="javascript:;" data-field-checkboxlist-all><?= e(trans('backend::lang.form.select_all')) ?></a>,
                <a href="javascript:;" data-field-checkboxlist-none><?= e(trans('backend::lang.form.select_none')) ?></a>
            </small>

            <!-- Scrollable Checkbox list -->
            <div class="field-checkboxlist-scrollable">
                <div class="control-scrollbar" data-control="scrollbar">
        <?php endif ?>

        <input
            type="hidden"
            name="<?= $field->getName() ?>"
            value="0" />

        <?php $index = 0; foreach ($fieldOptions as $value => $option): ?>
            <?php
                $index++;
                $checkboxId = 'checkbox_'.$field->getId().'_'.$index;
                if (is_string($option)) $option = [$option];
            ?>
            <div class="checkbox custom-checkbox">
                <input
                    type="checkbox"
                    id="<?= $checkboxId ?>"
                    name="<?= $field->getName() ?>[]"
                    value="<?= $value ?>"
                    <?= in_array($value, $checkedValues) ? 'checked="checked"' : '' ?>>

                <label for="<?= $checkboxId ?>">
                    <?= e(trans($option[0])) ?>
                </label>
                <?php if (isset($option[1])): ?>
                    <p class="help-block"><?= e(trans($option[1])) ?></p>
                <?php endif ?>
            </div>
        <?php endforeach ?>

        <?php if (count($fieldOptions) > 10): ?>
                </div>
            </div>
        <?php endif ?>

    </div>

<?php else: ?>

    <!-- No options specified -->
    <?php if ($field->placeholder): ?>
        <p><?= e(trans($field->placeholder)) ?></p>
    <?php endif ?>

<?php endif ?>
