{% extends "layouts/app.twig" %}

{% block title %}{{ lang.EMAIL_AUTO_RESP }}{% endblock %}

{% block content %}
    <div class="page-wrapper">
        <div class="page-content">

            <!--breadcrumb-->
            <div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
                <div class="breadcrumb-title pe-3"><a href="{{route('email.index')}}" class="text-dark">{{ lang.EMAIL_AUTO_RESP }}</a></div>
                <div class="ps-3">
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb mb-0 p-0">
                            <li class="breadcrumb-item active" aria-current="page">{{ lang.EMAIL_AUTO_RESP_CREATE }}</li>
                        </ol>
                    </nav>
                </div>
                <div class="ms-auto">
                    <div class="btn-group btn-group-sm">
                        <a class="btn btn-primary btn-sm" href="{{route('email.index')}}"><i class="bi bi-reply font16"></i> {{ lang.go_back }}</a>
                    </div>
                </div>
            </div>
            <!--end breadcrumb-->

            <div class="row">
                <div class="col-xl-7 mx-auto">
                    <div class="card border shadow-none">
                        <div class="card-body p-5">
                            {% include 'partials/flash.twig' %}
                            <form method="post" action="{{ route('email.autoresponder.manage') }}">
                                <div class="modal-body row g-3 p-3">
                                    {{ csrf.field | raw }}
                                    <div class="col-md-12">
                                        <label for="email" class="form-label">{{ lang.email }}</label>
                                        <input type="email" value="{{ email }}" placeholder="{{ lang.email }}" class="form-control {{ errors.email ? ' is-invalid' : '' }}" id="cemail" name="email" readonly>
                                    </div>

                                    <div class="col-md-12">
                                        <label for="from" class="form-label">{{ lang.EMAIL_AUTO_RESP_FROM }}</label>
                                        <input type="text" placeholder="{{ lang.EMAIL_AUTO_RESP_FROM }}" value="{{list.from}}" class="form-control {{ errors.from ? ' is-invalid' : '' }}" id="from" name="from" required>
                                        {% if errors.from %}
                                            <div class="invalid-feedback">{{ errors.from | first }}</div>
                                        {% endif %}
                                    </div>

                                    <div class="col-md-12">
                                        <label for="is_html" class="form-label">{{ lang.EMAIL_AUTO_RESP_ISHTML }}</label>
                                        <select name="is_html" id="is_html" class="form-control">
                                            {% if (list.is_html==1)%}
                                                <option value="1">1</option>
                                                <option value="0">0</option>
                                            {% else %}
                                                <option value="0">0</option>
                                                <option value="1">1</option>
                                            {% endif %}
                                        </select>
                                        <p style="font-size:12px; font-style: italic;">{{lang.EMAIL_AUTO_RESP_ISHTML_NOTE | raw}}</p>
                                    </div>

                                    <div class="col-md-12">
                                        <label for="interval" class="form-label">{{ lang.EMAIL_AUTO_RESP_INTERVAL }}</label>
                                        {% if (list.interval) %}
                                            <input id="interval" name="interval" type="number"  value="{{list.interval}}" class="form-control {{ errors.from ? ' is-invalid' : '' }}"/>
                                        {% else %}
                                            <input id="interval" name="interval" type="number"  value="0" class="form-control {{ errors.from ? ' is-invalid' : '' }}"/>
                                        {% endif %}
                                        <p style="font-size:12px; font-style: italic;">{{lang.EMAIL_AUTO_RESP_INTERVAL_NOTE}}</p>
                                    </div>

                                    <div class="row">
                                        <div class="col-md-6">
                                            <label for="start">{{lang.EMAIL_AUTO_RESP_START}}</label>
                                            <input id="start" name="start" type="text" maxlength="50"  value="{{list.start|date('Y-m-d')}}" class="date form-control {{ errors.start ? ' is-invalid' : '' }}" />
                                            {% if errors.start %}
                                                <div class="invalid-feedback">{{ errors.start | first }}</div>
                                            {% endif %}
                                        </div>
                                        <div class="col-md-6">
                                            <label for="stop">{{lang.EMAIL_AUTO_RESP_STOP}}</label>
                                            <input id="stop" name="stop" type="text" maxlength="100"  value="{{list.stop|date('Y-m-d')}}" class="date form-control {{ errors.stop ? ' is-invalid' : '' }}" />
                                            {% if errors.stop %}
                                                <div class="invalid-feedback">{{ errors.stop | first }}</div>
                                            {% endif %}
                                        </div>
                                    </div>

                                    <div class="col-md-12">
                                        <label for="subject">{{lang.EMAIL_AUTO_RESP_SUBJECT}}</label>
                                        <input id="subject" name="subject" type="text" maxlength="200" value="{{list.subject}}" placeholder="{{lang.EMAIL_AUTO_SUBJECT}}" class="form-control {{ errors.from ? ' is-invalid' : '' }}" required />
                                        {% if errors.subject %}
                                            <div class="invalid-feedback">{{ errors.subject | first }}</div>
                                        {% endif %}
                                    </div>

                                    <div class="col-md-12">
                                        <p>{{lang.EMAIL_AUTO_RESP_BODY}}</p>
                                        <textarea id="body" name="body" class="editor" placeholder="{{lang.EMAIL_AUTO_BODY}}" required>{{list.body}}</textarea>
                                        {% if errors.body %}
                                            <div class="invalid-feedback">{{ errors.body | first }}</div>
                                        {% endif %}
                                    </div>

                                    <div class="row mt-3">
                                        <div class="col-md-6">
                                            <button type="submit" class="btn btn-primary px-5">{{ lang.update }}</button>
                                        </div>
                                        {% if (list.from) %}
                                        <div class="col-md-6" style="text-align: right">
                                            <a href="{{route('email.autoresponder.create',{'email':baseEncode(email)},{'delete':1})}}" onclick="return confirm('Are you sure you want to delete auto responder')" class="btn btn-danger px-5">{{ lang.delete }}</a>
                                        </div>
                                        {% endif %}
                                    </div>

                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
