{% extends "layout.html" %}

{% import "form_macros.html" as macros %}
{% import "macros/common.html" as common %}

{% set title = "Update field" if item else "Create field" %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
{{ common.render_head(title) }}

<form method="POST" class="space-y-4">
    {{ macros.render_text_input('name', 'Name', item.name if item else '' ) }}
    {{ macros.render_text_input( 'alias', 'Alias', item.alias if item else '') }}
    {{ macros.render_select(
        'field_type',
        'Field type',
        FieldType,
        'name',
        'value',
        item.field_type.name if item else None,
        'name',
        True,
    ) }}
    {{ macros.render_select(
        'collection_id',
        'Collection',
        collections,
        'id',
        'name',
        item.collection_id if item else None,
        'id',
        True
    ) }}
    {{
        macros.render_checkbox("is_list", "Is list?", item.is_list if item else None)
    }}
    {{
        macros.render_checkbox("is_required", "Is required?", item.is_required if item else None)
    }}
    {{
        macros.render_checkbox("display_field", "Display field for content", item.display_field if item else None)
    }}

    <button
        type="submit"
        class="btn"
    >
        {{ "Update" if item else "Create" }}
    </button>
</form>
{% endblock %}
