{% extends "utilities/_base.html" %} {% from "components/chat_dialog.html" import chat_dialog %} {% from "components/distance_input.html" import distance_input %} {% from "components/page_header.html" import page_header %} {% from "components/modal.html" import render_modal %} {% macro render_edit_automation_form() %}
{% endmacro %} {% macro render_configure_form() %} {% for field in config_fields %}
{% if field.type in ('float', 'int') %} {% endif %} {% if field.type == 'string' %} {% endif %} {% if field.type == 'distance' %} {{ distance_input( 'config-' ~ field.key, field.key, field.value, field.unit_key, field.unit, field.units, min=field.min, max=field.max, step=field.step, required=field.required ) }} {% endif %} {% if field.type == 'bool' %} {% endif %} {% if field.help %}

{{ field.help }}

{% endif %}
{% endfor %} {% endmacro %} {% block title %}{{ _("Automations - Yaffo") }}{% endblock %} {% block utility_styles %} {% endblock %} {% block utility_content %} {% if not selected %}

{{ _("No automation selected") }}

{{ _("Pick one from the sidebar, or create one with “New automation”.") }}

{% else %} {% set header_actions %}
{% if scoped_run %} {% else %} {% endif %} {{ _("Edit triggers") }} {% if config_fields %} {% endif %} {% if not selected.is_system %} {% endif %}
{% endset %} {% call page_header(selected.display_name, actions=header_actions) %} {% if selected.is_system %} {{ selected.display_description or _("A built-in automation that ships with Yaffo. System automations cannot be edited or deleted.") }} {% else %} {{ selected.display_description or _("No description yet — use “Edit details” to add one.") }} {% endif %} {% endcall %}
{# System automations are code-backed (no AI builder, no editable code), so the conversation panel and code section are hidden — only the header actions, config, and run history apply to them. #} {% if not selected.is_system %}
{{ chat_dialog( 'automation-chat', _('Conversation'), _('Describe what this automation should do and the assistant will write it.'), _('Describe what this automation should do…'), messages=selected.messages, empty_text=(_('System automations are built-in and have no conversation.') if selected.is_system else _('No conversation yet — describe what you want and the assistant will build it.')), disabled=selected.is_system ) }}

{{ _("Code") }}

{% if selected_has_draft %} {# Unpublished draft: one panel toggles between the working draft and the live (active) code. The visible view is the version tested. #}
{% endif %}
{% if selected_has_draft %}
{{ selected.working_code }}
{% if selected.published_code %} {% else %} {% endif %} {% elif selected.published_code %}
{{ selected.published_code }}
{% else %}

{{ _("No published code yet.") }}

{% endif %} {% if selected.published_code or selected.working_code %}
{% if selected_has_draft %} {% endif %}
{% endif %}
{% endif %} {% include "utilities/automations_runs.html" %}
{% if not selected.is_system %} {{ render_modal('editAutomationModal', _('Edit automation'), url_for('automations_update_details', slug=selected.slug), render_edit_automation_form, _('Save')) }} {% endif %} {% if config_fields %} {{ render_modal('configureAutomationModal', _('Configure automation'), url_for('automations_update_config', slug=selected.slug), render_configure_form, _('Save')) }} {% endif %} {% endif %} {% endblock %} {% block scripts %} {% if selected %} {% endif %} {% endblock %}