{% extends "_layouts/cp" %}
{% set fullPageForm = true %}

{% import "_includes/forms" as forms %}


{% block content %}
    <input type="hidden" name="action" value="sections/save-entry-type">

    {% if section.type == 'single' %}
        {{ redirectInput('settings/sections') }}
    {% else %}
        {{ redirectInput('settings/sections/'~section.id~'/entrytypes') }}
    {% endif %}
    <input type="hidden" name="sectionId" value="{{ section.id }}">
    {% if entryType.id %}<input type="hidden" name="entryTypeId" value="{{ entryType.id }}">{% endif %}

    {% if section.type != 'single' %}
        {{ forms.textField({
            first: true,
            label: "Name"|t('app'),
            instructions: "What this entry type will be called in the CP."|t('app'),
            id: 'name',
            name: 'name',
            value: entryType.name,
            errors: entryType.getErrors('name'),
            autofocus: true,
            required: true
        }) }}

        {{ forms.textField({
            label: "Handle"|t('app'),
            instructions: "How you’ll refer to this entry type in the templates."|t('app'),
            id: 'handle',
            name: 'handle',
            class: 'code',
            autocorrect: false,
            autocapitalize: false,
            value: entryType.handle,
            errors: entryType.getErrors('handle'),
            required: true
        }) }}

        <hr>

    {% endif %}

    {{ forms.checkboxField({
        first: (section.type == 'single'),
        label: "Show the Title field"|t('app'),
        name: 'hasTitleField',
        toggle: 'titleLabel-container',
        reverseToggle: 'titleFormat-container',
        checked: entryType.hasTitleField
    }) }}

    <div id="titleLabel-container"{% if not entryType.hasTitleField %} class="hidden"{% endif %}>
        {{ forms.textField({
            label: "Title Field Label"|t('app'),
            instructions: "What do you want the Title field to be called?"|t('app'),
            id: 'titleLabel',
            name: 'titleLabel',
            value: entryType.titleLabel,
            errors: entryType.getErrors('titleLabel'),
            required: true
        }) }}
    </div>

    <div id="titleFormat-container"{% if entryType.hasTitleField %} class="hidden"{% endif %}>
        {{ forms.textField({
            label: "Title Format"|t('app'),
            instructions: "What the auto-generated entry titles should look like. You can include tags that output entry properties, such as {ex}."|t('app', { ex: '<code>{myCustomField}</code>' }),
            id: 'titleFormat',
            name: 'titleFormat',
            class: 'code',
            value: entryType.titleFormat,
            errors: entryType.getErrors('titleFormat'),
            required: true
        }) }}
    </div>

    <hr>

    {% include "_includes/fieldlayoutdesigner" with {
        fieldLayout: entryType.getFieldLayout(),
    } only %}
{% endblock %}


{% if not entryType.handle %}
    {% js "new Craft.HandleGenerator('#name', '#handle');" %}
{% endif %}
