<section class="content-header">
    <h1><?= __('Auction items') ?></h1>

    <div class="actions">
        <a data-ajax class="btn btn-default btn-sm" href="<?= admin_url_to('/auctions/items?auction_id=' . $auction['id']) ?>"><?= __('List') ?></a>
    </div>
</section>

<section class="content">
    <div class="nav-tabs-custom">
        <ul class="nav nav-tabs">
            <li><a data-ajax href="<?= admin_url_to('/auctions/edit/' . $auction['id']) ?>"><?= __('Auction') ?></a></li>
            <li class="active"><a href="#"><?= __('Items') ?></a></li>
        </ul>

        <div class="tab-content">
            <form data-ajax data-upload class="form-focus" action="<?= admin_url_to('/auctions/items/edit/' . $item['id']) ?>" 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><?= __('Basic options') ?></h5>
                            </div>

                            <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                <div class="row">
                                    <div class="col-md-10">
                                        <div class="form-group">
                                            <label class="control-label" for="item-id"><?= __('Item') ?> <span class="required">*</span></label>
                                            <select disabled class="form-control select2" name="item_id" id="item-id">
                                                <option value=""><?= __('Search for a item') ?></option>
                                                <?php foreach ($items as $category => $its): ?>
                                                    <optgroup label="<?= $category ?>">
                                                        <?php foreach ($its as $it): ?>
                                                            <option<?= $it['id'] === $item['item_id'] ? ' selected' : '' ?> value="<?= $it['id'] ?>"><?= $it['name'] ?></option>
                                                        <?php endforeach ?>
                                                    </optgroup>
                                                <?php endforeach ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label class="control-label" for="active"><?= __('Active') ?></label>
                                            <div>
                                                <input class="form-control toggle" type="checkbox"<?= $item['active'] ? ' checked' : '' ?> id="active" value="1" name="active" />
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label class="control-label" for="level"><?= __('Level') ?></label>
                                            <select class="form-control" id="level" name="level">
                                                <?php for ($i = 0; $i <= 15; $i++): ?>
                                                    <option value="<?= $i ?>"<?= $item['item']->getLevel() === $i ? ' selected' : '' ?>><?= $i ?></option>
                                                <?php endfor ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-4">
                                        <div class="form-group">
                                            <label class="control-label" for="options"><?= __('Option') ?></label>
                                            <select class="form-control" id="option" name="option">
                                                <?php for ($i = 0; $i <= 28; $i+=4): ?>
                                                    <option value="<?= $i ?>"<?= $item['item']->getOption() === $i ? ' selected' : '' ?>>+<?= $i ?></option>
                                                <?php endfor ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label class="control-label" for="luck"><?= __('Luck') ?></label>
                                            <div>
                                                <input class="form-control toggle"<?= $item['item']->hasLuck() ? ' checked' : '' ?> type="checkbox" id="luck" value="1" name="luck" />
                                            </div>
                                        </div>
                                    </div>

                                    <?php if ($item['item']->getDefinitions()->hasSkill()): ?>
                                        <div class="col-md-2">
                                            <div class="form-group" id="item-skill">
                                                <label class="control-label" for="skill"><?= __('Skill') ?></label>
                                                <div>
                                                    <input class="form-control toggle" type="checkbox"<?= $item['item']->hasSkill() ? ' checked' : '' ?> id="skill" value="1" name="skill" />
                                                </div>
                                            </div>
                                        </div>
                                    <?php endif ?>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php if ($item['item']->getDefinitions()->hasAncient()): ?>
                        <div class="section" id="item-ancient">
                            <div class="row">
                                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                                    <h5><?= __('Ancient option') ?></h5>
                                </div>

                                <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                    <select class="form-control" name="ancient" id="ancient">
                                        <option value="0"></option>
                                        <?php foreach ((new Morpheus\Item\Ancient())->available($item['item']->getSection(), $item['item']->getIndex()) as $cod => $name): ?>
                                            <option value="<?= $cod ?>"<?= $cod === $item['item']->getAncient()->get() ? ' selected' : '' ?>><?= $name ?></option>
                                        <?php endforeach ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                    <?php endif ?>

                    <?php if ($item['item']->getDefinitions()->hasExcellentOptions()): ?>
                        <div class="section" id="item-excellent">
                            <div class="row">
                                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                                    <h5><?= __('Excellent options') ?></h5>
                                </div>

                                <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                    <?php foreach ($item['item']->getDefinitions()->getExcellentOptions() as $i => $exc): ?>
                                        <div class="exc" style="margin-bottom:3px;">
                                            <input<?= $item['item']->getExcellent($i) ? ' checked' : '' ?> type="checkbox" id="exc-<?= $i ?>" value="1" name="excellent[<?= $i ?>]" />
                                            <label for="exc-<?= $i ?>"><?= $exc ?></label>
                                        </div>
                                    <?php endforeach ?>
                                </div>
                            </div>
                        </div>
                    <?php endif ?>

                    <?php if ($item['item']->getDefinitions()->hasRefine()): ?>
                        <div class="section" id="item-refine">
                            <div class="row">
                                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                                    <h5><?= __('Refine option') ?></h5>
                                </div>

                                <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                    <div class="form-group">
                                        <input class="form-control toggle" type="checkbox"<?= $item['item']->isRefine() ? ' checked' : '' ?> id="refine" value="1" name="refine" />
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif ?>

                    <?php if ($item['item']->getDefinitions()->hasHarmony()): ?>
                        <div class="section" id="item-harmony">
                            <div class="row">
                                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                                    <h5><?= __('Harmony option') ?></h5>
                                </div>

                                <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                    <div class="form-group">
                                        <select class="form-control" name="harmony" id="harmony">
                                            <option value=""></option>
                                            <?php foreach ($item['item']->getHarmony()->available() as $harmony):  ?>
                                                <optgroup label="<?= $harmony['name'] ?>">
                                                    <?php foreach ($harmony['levels'] as $level): ?>
                                                        <option value="<?= $harmony['index'] ?>,<?= $level['level'] ?>"<?= $item['item']->getHarmony()->getType() === $harmony['index'] && $item['item']->getHarmony()->getLevel() == $level['level'] ? ' selected' : '' ?>>
                                                            +<?= $level['name'] ?>
                                                        </option>
                                                    <?php endforeach ?>
                                                </optgroup>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif ?>

                    <?php if ($item['item']->getDefinitions()->hasSockets()): ?>
                        <div class="section" id="item-socket">
                            <div class="row">
                                <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                                    <h5><?= __('Socket options') ?></h5>
                                </div>

                                <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                    <div class="socket-options">
                                        <?php for ($i = 0; $i < $item['item']->getDefinitions()->getMaxSockets(); $i++) : ?>
                                            <?php $socket = $item['item']->getSocket($i) ?>
                                            <div class="socket" style="margin-bottom:3px;">
                                                <select class="form-control" name="sockets[<?= $i ?>]">
                                                    <option value="-2"<?= $socket->isNull() ? ' selected' : '' ?>>No socket</option>
                                                    <option value="-1"<?= $socket->isEmpty() ? ' selected' : '' ?>>Empty</option>
                                                    <?php foreach ($item['item']->getDefinitions()->getSockets() as $type => $socks):  ?>
                                                        <optgroup label="<?= __($type) ?>">
                                                            <?php foreach ($socks as $sock): ?>
                                                                <option<?= $socket->get() === $sock['value'] ? ' selected' : '' ?> value="<?= $sock['value'] ?>"><?= $sock['name'] ?></option>
                                                            <?php endforeach ?>
                                                        </optgroup>
                                                    <?php endforeach ?>
                                                </select>
                                            </div>
                                        <?php endfor ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif ?>

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

                            <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label" for="coin"><?= __('Coin') ?> <span class="required">*</span></label>
                                            <select class="form-control" name="coin" id="coin">
                                                <option value=""></option>
                                                <?php foreach (config('coins', []) as $coin): ?>
                                                    <option value="<?= $coin['id'] ?>"<?= $coin['id'] === $item['coin'] ? ' selected' : '' ?>><?= $coin['name'] ?></option>
                                                <?php endforeach ?>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="control-label" for="initial-bid"><?= __('Initial bid') ?></label>
                                            <input class="form-control" value="<?= $item['initial_bid'] ?>" type="text" name="initial_bid" id="initial-bid" />
                                        </div>
                                    </div>
                                </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>
    </div>
</section>
