<script type="text/javascript">
    function type () {
        var $this = $("#type");
        var $fix = $(".type-fix");
        var $sql = $(".type-sql");
        var $code = $(".type-code");
        if ($this.val() === "fix") {
            $fix.show();
            $sql.hide();
            $code.hide();
        } else if ($this.val() === "code") {
            $fix.hide();
            $sql.hide();
            $code.show();
        } else {
            $fix.hide();
            $sql.show();
            $code.hide();
        }
    }

    $(function () {
        type();
        $("#type").change(function () {
            type();
        });
    })
</script>

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3><?= __('Add patent') ?></h3>
</div>

<form data-ajax data-upload action="<?= admin_url_to('/patents/add') ?>" method="post">
    <?= csrf_field() ?>

    <div class="modal-body">
        <div class="form-group">
            <label class="control-label" for="title"><?= __('Title') ?> <span class="required">*</span></label>
            <input type="text" name="title" class="form-control" id="title" />
        </div>

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

        <div class="form-group">
            <label class="control-label" for="type"><?= __('Type') ?> <span class="required">*</span></label>
            <select name="type" class="form-control" id="type">
                <?php if (!config('patent.table')): ?>
                    <option value="fix"><?= __('Fix') ?></option>
                    <option value="sql"><?= __('SQL') ?></option>
                <?php else: ?>
                    <option value="code"><?= __('Code') ?></option>
                <?php endif ?>
            </select>
        </div>

        <div class="form-group type-sql">
            <label class="control-label" for="command"><?= __('SQL') ?></label>
            <textarea class="form-control" type="text" id="command" name="command"></textarea>
        </div>

        <div class="form-group type-code">
            <label class="control-label" for="code"><?= __('Code') ?></label>
            <input type="text" name="code" class="form-control" id="code" />
        </div>

        <div class="form-group type-fix">
            <label class="control-label" for="levels"><?= __('Level') ?></label>
            <input type="text" name="levels" class="form-control" id="levels" />
        </div>

        <div class="form-group type-fix">
            <label class="control-label" for="resets"><?= __('Resets') ?></label>
            <input type="text" name="resets" class="form-control" id="resets" />
        </div>

        <div class="form-group type-fix">
            <label class="control-label" for="master-level"><?= __('Master Level') ?></label>
            <input type="text" name="master_levels" class="form-control" id="master-level" />
        </div>

        <div class="form-group type-fix">
            <label class="control-label" for="master-resets"><?= __('Master Resets') ?></label>
            <input type="text" name="master_resets" class="form-control" id="master-resets" />
        </div>
    </div>

    <div class="modal-footer" style="margin-top:0">
        <input type="submit" class="btn btn-primary" value="<?= __('Add') ?>" />
    </div>
</form>