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

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

<section class="content">
    <div class="box box-default">
        <form data-ajax data-upload class="form-action" action="<?= admin_url_to('/slides/edit/' . $slide['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><?= __('Slide') ?></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="slides-title"><?= __('Title') ?></label>
                                        <input class="form-control" value="<?= $slide['title'] ?>" type="text" name="title" id="slides-title" />
                                    </div>
                                </div>

                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label class="control-label" for="slides-type"><?= __('Type') ?> <span class="required">*</span></label>
                                        <select class="form-control" name="type" id="slides-type">
                                            <option value=""></option>
                                            <?php foreach ($types as $key => $value): ?>
                                                <option<?= $slide['type'] == $key ? ' selected' : '' ?> value="<?= $key ?>"><?= $value ?></option>
                                            <?php endforeach ?>
                                        </select>
                                    </div>
                                </div>

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

                            <div class="form-group">
                                <label class="control-label" for="slides-url"><?= __('URL') ?></label>
                                <input class="form-control"  value="<?= $slide['url'] ?>" type="text" name="url" id="slides-url" />
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="slides-image"><?= __('Image') ?> <span class="required">*</span></label>
                                <input data-upload-field class="form-control" type="file" name="image" />
                            </div>

                            <div class="form-group">
                                <label class="control-label" for="links"><?= __('Links') ?></label>

                                <div class="container-add-link">
                                    <?php $i = 0; foreach (json_decode($slide['links'], true) ?? [] as $link): ?>
                                        <div style="display:flex;margin-bottom:10px;">
                                            <input class="form-control" value="<?= $link['name'] ?>" style="width:40%;margin-right:2%" type="text" placeholder="<?= __('Name') ?>" name="links[<?= $i ?>][name]" />
                                            <input class="form-control" value="<?= $link['link'] ?>" style="width:58%" type="text" placeholder="<?= __('Link') ?>" name="links[<?= $i ?>][link]" />
                                        </div>
                                        <?php $i++; endforeach ?>
                                    <div style="display:flex;margin-bottom:10px;">
                                        <input class="form-control" style="width:40%;margin-right:2%" type="text" placeholder="<?= __('Name') ?>" name="links[<?= $i ?>][name]" />
                                        <input class="form-control" style="width:58%" type="text" placeholder="<?= __('Link') ?>" name="links[<?= $i ?>][link]" />
                                    </div>
                                </div>
                            </div>

                            <div style="text-align:right;margin-top:-10px">
                                <a class="btn btn-xs btn-success add-link" href="javascript:void(0)"><?= __('Add') ?></a>
                            </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>