{% extends "layout_default.html.twig" %}

{% import "macro_functions.html.twig" as mf %}

{% set active_menu = 'extensions' %}

{% block meta_title %} {{ 'Edit Custom Page'|trans }} {% endblock %}

{% set page = admin.custompages_get_page({ page_id }|merge(request)) %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li class="breadcrumb-item">
        <svg class="icon">
            <use xlink:href="#home" />
        </svg>
    </li>
    <li class="breadcrumb-item">
        <a href="{{ 'custompages'|alink }}">{{ 'Custom Pages'|trans }}</a>
    </li>
    <li class="breadcrumb-item active" aria-current="page">{{ page.title }}</li>
</ul>
{% endblock %}

{% block content %}
    {% if page.id > 0 %}

<div class="card">
    <form method="post" action="{{ 'api/admin/custompages/update'|link }}" class="save api-form" data-api-msg="{{ 'Custom page updated'|trans }}">
        <div class="card-body mt-2">
            <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}">
            <input type="hidden" name="id" value="{{ page.id }}">
            <div class="mb-3 row">
                <label class="col-md-3 col-form-label">{{ 'Title'|trans }}</label>
                <div class="col">
                    <input class="form-control" type="text" name="title" value="{{ page.title }}" required="required" placeholder="{{ 'Enter page title here.'|trans }}">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-md-3 col-form-label">{{ 'Meta Description'|trans }}</label>
                <div class="col">
                    <input class="form-control" type="text" name="description" value="{{ page.description }}" required="required" placeholder="{{ 'Enter page meta description here.'|trans }}">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-md-3 col-form-label">{{ 'Meta Keywords'|trans }}</label>
                <div class="col">
                    <input class="form-control" type="text" name="keywords" value="{{ page.keywords }}" required="required" placeholder="{{ 'Enter page meta keywords here.'|trans }}">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-md-3 col-form-label">{{ 'Slug'|trans }}</label>
                <div class="col">
                    <input class="form-control" type="text" name="slug" value="{{ page.slug }}" required="required" placeholder="{{ 'Enter page slug here.'|trans }}">
                </div>
            </div>
            <div class="mb-3 row">
                <label class="col-md-3 col-form-label">{{ 'Content'|trans }}</label>
                <div class="col">
                    <textarea class="bb-textarea" name="content" cols="5" rows="5" required="required" placeholder="{{ 'Enter page content here.'|trans }}">{{ page.content }}</textarea>
                </div>
            </div>
        </div>
        <div class="card-footer text-end">
            <input type="submit" value="{{ 'Update'|trans }}" class="btn btn-primary"/>
        </div>
    </form>
</div>
{% else %}
<script>location.href = "{{ 'custompages'|alink }}"</script>
{% endif %}
{% endblock %}

{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %}
