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

    <div class="actions">
        <a data-ajax class="btn btn-default btn-sm" href="<?= admin_url_to('/trackers') ?>"><?= __('List') ?></a>
    </div>
</section>

<section class="content">
    <div class="box box-default">
        <form data-ajax class="form-focus" action="<?= admin_url_to('/trackers/edit/' . $tracker['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><?= __('Tracker') ?></h5>
                        </div>

                        <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                            <div class="form-group">
                                <label class="control-label"><?= __('Title') ?></label>
                                <p class="form-control-static"><?= $tracker['title'] ?></p>
                            </div>

                            <div class="form-group">
                                <label class="control-label"><?= __('Description') ?></label>
                                <p class="form-control-static"><?= $tracker['description'] ?></p>
                            </div>

                            <div class="form-group">
                                <label class="control-label"><?= __('How to reproduce') ?></label>
                                <p class="form-control-static"><?= $tracker['reproduce'] ?></p>
                            </div>

                            <div class="form-group">
                                <label class="control-label"><?= __('Images') ?></label>
                                <?php if (!empty($tracker['images'])): ?>
                                    <div class="row">
                                        <?php foreach (explode(',', $tracker['images']) as $image): ?>
                                            <a class="col-md-2" href="<?= upload_to('/trackers/' . $image) ?>" target="_blank">
                                                <div class="thumbnail">
                                                    <img src="<?= upload_to('/trackers/' . $image) ?>" />
                                                </div>
                                            </a>
                                        <?php endforeach ?>
                                    </div>
                                <?php else: ?>
                                    <p class="form-control-static">-</p>
                                <?php endif ?>
                            </div>

                            <div class="row">
                                <div class="col-md-5">
                                    <div class="form-group">
                                        <label class="control-label" for="status"><?= __('Status') ?> <span class="required">*</span></label>
                                        <select class="form-control" name="status" id="status">
                                            <?php foreach ($statuses as $id => $status): ?>
                                                <option<?= $id == $tracker['status'] ? ' selected' : '' ?> value="<?= $id ?>"><?= $status['name'] ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-5">
                                    <div class="form-group">
                                        <label class="control-label" for="fixed-version-id"><?= __('Fixed in') ?></label>
                                        <select class="form-control" name="fixed_version_id" id="fixed-version-id">
                                            <option value=""></option>
                                            <?php foreach ($versions as $version): ?>
                                                <option<?= $version['id'] === $tracker['fixed_version_id'] ? ' selected' : '' ?> value="<?= $version['id'] ?>"><?= $version['version'] ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>

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

                            <div class="form-group">
                                <label class="control-label" for="comment"><?= __('Comment') ?></label>
                                <textarea class="form-control editor" name="comment" id="comment"></textarea>
                            </div>
                        </div>
                    </div>
                </div>

                <?php if (!empty($comments)): ?>
                    <div class="section">
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-12">
                                <h5><?= __('Messages') ?></h5>
                            </div>

                            <div class="col-lg-9 col-md-9 col-sm-8 col-xs-12">
                                <ul class="list">
                                    <?php foreach ($comments as $comment): ?>
                                        <li>
                                            <div class="desc">
                                                <span class="name"><?= $comment['author'] ?></span>
                                                <span class="created"><?= util('Date')->dateTime($comment['create_date']) ?></span>
                                                <p><?= nl2br($comment['comment']) ?></p>
                                            </div>
                                        </li>
                                    <?php endforeach ?>
                                </ul>
                            </div>
                        </div>
                    </div>
                <?php endif ?>
            </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>