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

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

{% block meta_title %}{{ post.title }}{% endblock %}

{% set active_menu = 'support' %}

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

{% block content %}
<div class="card">
    <form method="post" action="{{ 'api/admin/news/update'|link }}" class="api-form" data-api-msg="{{ 'Post updated'|trans }}">
        <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
        <div class="card-body">
            <h3>{{ 'Edit post'|trans }}</h3>
            <p class="text-muted">{{ post.title }}</p>

            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Title'|trans }}</label>
                <div class="col">
                    <input class="form-control" type="text" name="title" value="{{ post.title }}" required>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Content'|trans }}</label>
                <div class="col">
                    <textarea class="bb-textarea" name="content" rows="10">{{ post.content }}</textarea>
                    <small class="my-2 form-hint">If the text is very long you can use <strong>&lt;!--more--&gt;</strong> tag. Inserting this tag within the post will create and excerpt of text (before the tag) to be displayed in posts list. Users will be able to see whole content when they click on "Read more" button.</small>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Image'|trans }}</label>
                <div class="col">
                    <input class="form-control" type="text" name="image" value="{{ post.image }}" id="post_image" placeholder="{{ 'https://www.yourdomain.com/image.jpg'|trans }}"/>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Meta description'|trans }}</label>
                <div class="col">
                    <textarea class="form-control" name="description" rows="2" placeholder="{{ post.description }}">{{ post.description }}</textarea>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Slug'|trans }}</label>
                <div class="col">
                    <input class="form-control" type="text" name="slug" value="{{ post.slug }}" required>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label">{{ 'Status'|trans }}</label>
                <div class="col">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioStatusDraft" type="radio" name="status" value="draft"{% if post.status == 'draft' %} checked{% endif %}>
                        <label class="form-check-label" for="radioStatusDraft">{{ 'Draft'|trans }}</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" id="radioStatusActive" type="radio" name="status" value="active"{% if post.status == 'active' %} checked{% endif %}>
                        <label class="form-check-label" for="radioStatusActive">{{ 'Active'|trans }}</label>
                    </div>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label" for="post_created">{{ 'Post created'|trans }}</label>
                <div class="col">
                    <div class="input-group">
                        <div class="input-icon w-100">
                            <input class="form-control datepicker"
                                   id="post_created"
                                   value="{{ post.created_at|date('Y-m-d') }}"
                                   name="created_at"
                                   required
                            >
                            <span class="input-icon-addon">
                                <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                    <path d="M4 5m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"></path>
                                    <path d="M16 3l0 4"></path>
                                    <path d="M8 3l0 4"></path>
                                    <path d="M4 11l16 0"></path>
                                    <path d="M11 15l1 0"></path>
                                    <path d="M12 15l0 3"></path>
                                </svg>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="mb-3 row">
                <label class="form-label col-3 col-form-label" for="last_updated">{{ 'Last update'|trans }}</label>
                <div class="col">
                    <div class="input-group">
                        <div class="input-icon w-100">
                            <input class="form-control datepicker"
                                   id="last_updated"
                                   value="{{ post.updated_at|date('Y-m-d') }}"
                                   name="updated_at"
                                   required
                            >
                            <span class="input-icon-addon">
                                <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                    <path d="M4 5m0 2a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2z"></path>
                                    <path d="M16 3l0 4"></path>
                                    <path d="M8 3l0 4"></path>
                                    <path d="M4 11l16 0"></path>
                                    <path d="M11 15l1 0"></path>
                                    <path d="M12 15l0 3"></path>
                                </svg>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <input type="hidden" name="id" value="{{ post.id }}">

        <div class="card-footer d-flex gap-2">
            <a href="{{ 'news'|alink }}" class="btn btn-secondary">
                <svg class="icon">
                    <use xlink:href="#arrow-sm-left" />
                </svg>
                {{ 'Go back'|trans }}
            </a>
            <input type="submit" value="{{ 'Update'|trans }}" class="btn btn-primary w-100">
        </div>
    </form>
</div>
{% endblock %}

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