<section class="content-header">
    <h1><?= __('Market plugin settings') ?></h1>
</section>

<section class="content">

    <div class="box box-default">
        <form data-ajax class="form-focus" action="<?= admin_url_to('/market/config') ?>" method="post">
            <?= csrf_field() ?>

            <div class="box-body">
                <div class="section">
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                            <h5><?= __('Payments') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="form-group" style="margin-top:10px">
                                <?php foreach (config('coins', []) as $coin): ?>
                                    <div style="width:33%;margin-bottom:5px;float:left">
                                        <input<?= in_array($coin['id'], $coinsAllowed) ? ' checked="checked"' : '' ?> type="checkbox" name="allowed_coins[]" id="coin-<?= $coin['id'] ?>" value="<?= $coin['id'] ?>" /> <label for="coin-<?= $coin['id'] ?>"><?= util('Coin')->name($coin['id']) ?></label>
                                    </div>
                                <?php endforeach ?>

                                <div style="width:33%;margin-bottom:5px;float:left">
                                    <input<?= config('market.allow_credits', false) ? ' checked' : '' ?> type="checkbox" name="allow_credits" id="allow_credits" value="1" />
                                    <label for="allow_credits"><?= __('Credits') ?></label>
                                </div>

                                <div style="width:33%;margin-bottom:5px;float:left">
                                    <input<?= config('market.allow_zen', false) ? ' checked' : '' ?> type="checkbox" name="allow_zen" id="allow_zen" value="1" />
                                    <label for="allow_zen"><?= __('Zen') ?></label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="section">
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                            <h5><?= __('Items for Payments') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="grouped-items">
                                <?php $index = 0; foreach ($items as $category => $its): ?>
                                    <p class="title">
                                        <a class="grouped-item-category collapsed" data-toggle="collapse" data-target="#category-payment-<?= $index ?>" href="javascript:void(0)">
                                            <?= $category ?>

                                            <span class="label label-default">
                                                <?= count($its) ?> <?= __('items') ?>
                                            </span>

                                            <span class="label label-success">
                                                <?php $total = array_reduce($paymentItems, function ($carry, $item) use ($index) {
                                                    $carry += strpos($item, $index . '-') !== false ? 1 : 0;

                                                    return $carry;
                                                }) ?>
                                                <?= $total ?? 0 ?> <?= __('allowed') ?>
                                            </span>
                                        </a>

                                        <a class="grouped-item-toggle" href="#" data-select-all="<?= $index ?>"><?= __('Toggle all') ?></a>
                                    </p>

                                    <div class="collapse" id="category-payment-<?= $index ?>">
                                        <?php foreach ($its as $item): ?>
                                            <?php $id = $item['section'] . '-' . $item['index'] ?>
                                            <div class="grouped-item">
                                                <input<?= in_array($id, $paymentItems) ? ' checked="checked"' : '' ?> type="checkbox" data-category="<?= $index ?>" name="items[]" id="item-payment-<?= $id ?>" value="<?= $id ?>" />
                                                <label for="item-payment-<?= $id ?>"><?= $item['name'] ?></label>
                                            </div>
                                        <?php endforeach ?>

                                        <div class="clearfix"></div>
                                    </div>
                                    <?php $index++; endforeach ?>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="section">
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                            <h5><?= __('Allowed options') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="form-group" style="margin-top:10px">
                                <div style="width:33%;margin-bottom:5px;float:left">
                                    <input<?= config('market.allow_excellent', true) ? ' checked="checked"' : '' ?> type="checkbox" name="allow_excellent" id="allow-excellent" value="1" /> <label for="allow-excellent"><?= __('Allow excellent') ?></label>
                                </div>

                                <div style="width:33%;margin-bottom:5px;float:left">
                                    <input<?= config('market.allow_options', true) ? ' checked="checked"' : '' ?> type="checkbox" name="allow_options" id="allow-options" value="1" /> <label for="allow-options"><?= __('Allow options') ?></label>
                                </div>

                                <div style="width:33%;margin-bottom:5px;float:left">
                                    <input<?= config('market.allow_ancient', true) ? ' checked="checked"' : '' ?> type="checkbox" name="allow_ancient" id="allow-ancient" value="1" /> <label for="allow-ancient"><?= __('Allow ancient') ?></label>
                                </div>

                                <div style="width:33%;margin-bottom:5px;float:left">
                                    <input<?= config('market.allow_luck', true) ? ' checked="checked"' : '' ?> type="checkbox" name="allow_luck" id="allow-luck" value="1" /> <label for="allow-luck"><?= __('Allow luck') ?></label>
                                </div>

                                <div style="width:33%;margin-bottom:5px;float:left">
                                    <input<?= config('market.allow_harmony', true) ? ' checked="checked"' : '' ?> type="checkbox" name="allow_harmony" id="allow-harmony" value="1" /> <label for="allow-harmony"><?= __('Allow harmony') ?></label>
                                </div>

                                <div style="width:33%;margin-bottom:5px;float:left">
                                    <input<?= config('market.allow_refine', true) ? ' checked="checked"' : '' ?> type="checkbox" name="allow_refine" id="allow-refine" value="1" /> <label for="allow-refine"><?= __('Allow refine') ?></label>
                                </div>

                                <div style="width:33%;margin-bottom:5px;float:left">
                                    <input<?= config('market.allow_socket', true) ? ' checked="checked"' : '' ?> type="checkbox" name="allow_socket" id="allow-socket" value="1" /> <label for="allow-socket"><?= __('Allow socket') ?></label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="section">
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                            <h5><?= __('Blocked items') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="grouped-items">
                                <?php $index = 0; foreach ($items as $category => $its): ?>
                                    <p class="title">
                                        <a class="grouped-item-category collapsed" data-toggle="collapse" data-target="#category-<?= $index ?>" href="javascript:void(0)">
                                            <?= $category ?>

                                            <span class="label label-default">
                                                <?= count($its) ?> <?= __('items') ?>
                                            </span>

                                            <span class="label label-danger">
                                                <?php $total = array_reduce($itemsBlocked, function ($carry, $item) use ($index) {
                                                    $carry += strpos($item, $index . '-') !== false ? 1 : 0;

                                                    return $carry;
                                                }) ?>
                                                <?= $total ?? 0 ?> <?= __('blocked') ?>
                                            </span>
                                        </a>

                                        <a class="grouped-item-toggle" href="#" data-select-all="<?= $index ?>"><?= __('Toggle all') ?></a>
                                    </p>

                                    <div class="collapse" id="category-<?= $index ?>">
                                        <?php foreach ($its as $item): ?>
                                            <?php $id = $item['section'] . '-' . $item['index'] ?>
                                            <div class="grouped-item">
                                                <input<?= in_array($id, $itemsBlocked) ? ' checked="checked"' : '' ?> type="checkbox" data-category="<?= $index ?>" name="blocked[]" id="item-<?= $id ?>" value="<?= $id ?>" />
                                                <label for="item-<?= $id ?>"><?= $item['name'] ?></label>
                                            </div>
                                        <?php endforeach ?>

                                        <div class="clearfix"></div>
                                    </div>
                                <?php $index++; endforeach ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="box-footer">
                <div class="row">
                    <div class="col-sm-offset-3" style="padding-left:15px">
                        <input type="submit" class="btn btn-primary" value="<?= __('Save') ?>" />
                    </div>
                </div>
            </div>
        </form>
    </div>
</section>