{% extends layout('new-create') %}

{% block content %}
    <section class="clearfix home-default">
        <div>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    {% for cat in cats_d %}
                        <li class="breadcrumb-item text-primary">{{ cat }}</li>
                    {% endfor %}
                    <li class="breadcrumb-item">
                        <a href="{{ url_route('adv::edit_category',[id]) }}">
                            <i class="fas fa-pencil-alt"></i> {{ trans('visiosoft.module.advs::field.edit_category') }}
                        </a>
                    </li>
                </ol>
            </nav>
            <div class="adpost-details">
                <div class="row">
                    <div class="col-md-12">
                        {% set form = form('advs', 'advs').entry(id).actions(['update']).get() %}
                        {{ form_open({
                            'id': 'createEditAdvForm',
                            'class': 'form ' ~ form.options.class ,
                            'enctype': 'multipart/form-data',
                            'url': 'advs/save_adv',
                        })|raw }}
                        <input type="hidden" value="pending_user" name="status">
                        <input type="hidden" name="cat1" value="{{ cats.cat1 }}">
                        <input type="hidden" name="cat2" value="{{ cats.cat2 }}">
                        <input type="hidden" name="cat3" value="{{ cats.cat3 }}">
                        <input type="hidden" name="cat4" value="{{ cats.cat4 }}">
                        <input type="hidden" name="cat5" value="{{ cats.cat5 }}">
                        <input type="hidden" name="cat6" value="{{ cats.cat6 }}">
                        <input type="hidden" name="cat7" value="{{ cats.cat7 }}">
                        <input type="hidden" name="cat8" value="{{ cats.cat8 }}">
                        <input type="hidden" name="cat9" value="{{ cats.cat9 }}">
                        <input type="hidden" name="cat10" value="{{ cats.cat10 }}">
                        <input type="hidden" id="currencies" name="currencies" value="">
                        <input type="hidden" name="update_id" value="{{ id }}">
                        <fieldset>

                            {% include 'visiosoft.module.advs::new-ad/partials/contact-info' %}

                            <h5 class="mt-5 pb-1 border-bottom">{{ trans('visiosoft.module.advs::field.ad_info') }}</h5>
                            <div class="section postdetails">
                                <div class="row form-group add-title">
                                    {% set fields = form.fields.base().pluck('field_name').all() %}
                                    <div class="col-md-12">
                                        <div class="field-group name">
                                            {% for field in form.fields.translations('name') %}
                                                {{ field.render({'form': form})|raw }}
                                            {% endfor %}
                                        </div>
                                    </div>

                                    <div style="display: none">
                                        {{ form.fields.slug|raw }}
                                    </div>
                                </div>

                                {{ addBlock('new-ad/fields', {'adv': adv})|raw }}

                                <div class="row form-group select-price{{ setting_value('visiosoft.module.advs::hide_standard_price_field') ? ' d-none' }}">
                                    <label class="col-sm-2 col-xs-12">
                                        {{ form.fields.standard_price.label|raw }}
                                        <span class="required">*</span>
                                    </label>
                                    <div class="col-12 standard-price-hidden d-none">
                                        {{ form.fields.standard_price.setAttributes({
                                            'required' :true
                                        }).input|raw }}
                                    </div>
                                    {% set standardPriceValue = form.fields.standard_price.value|split('.') %}
                                    <div class="col-8 pr-0 col-md-3">
                                        <input class="form-control standard-price-field whole-price" value="{{ standardPriceValue|first }}">
                                    </div>
                                    <div class="col-4 col-md-1">
                                        <input class="form-control standard-price-decimal-field decimal-price" placeholder="00" maxlength="2"
                                               value="{{ standardPriceValue[1] }}">
                                    </div>
                                </div>

                                <div class="row form-group select-price">
                                    <label class="col-sm-2 col-xs-12">
                                        {{ form.fields.price.label|raw }}
                                        <span class="required">*</span>
                                    </label>
                                    <div class="col-12 priceHidden d-none">
                                        {{ form.fields.price.setAttributes({
                                            'required' :true
                                        }).input|raw }}
                                    </div>
                                    {% set PriceValue = form.fields.price.value|split('.') %}
                                    <div class="col-8 pr-0 col-md-3">
                                        <input class="form-control priceField whole-price" value="{{ PriceValue|first }}">
                                    </div>
                                    <div class="col-4 col-md-1">
                                        <input class="form-control priceDecimalField decimal-price" placeholder="00" maxlength="2"
                                               value="{{ PriceValue[1] }}">
                                    </div>
                                    <div class="col-sm-3 col-xs-6">
                                        <select name="currency" class="custom-select form-control" data-field="currency"
                                                data-field_name="currency" data-provides="anomaly.field_type.select"
                                                id="currency" required="">
                                            {% for currency in config_get('streams::currencies.enabled') %}
                                                <option value="{{ currency }}">
                                                    {% if currency == "TRY" %}
                                                        {{ currency_symbol(currency) }}
                                                    {% else %}
                                                        {{ currency }}
                                                    {% endif %}
                                                </option>
                                            {% endfor %}

                                        </select>
                                    </div>
                                </div>

                                <div class="row form-group select-options">
                                    <label for="selectOptions" class="col-sm-2">
                                        {{ trans('visiosoft.module.advs::field.options') }}
                                    </label>
                                    <div class="col-sm-10">
                                        <select id="selectOptions" class="form-control options-tags" multiple="multiple"
                                                name="options[]">
                                            {% if count(options) %}
                                                {% for option in options %}
                                                    <option id="advOption{{ option.id }}" selected="selected">{{ option.name }}</option>
                                                {% endfor %}
                                            {% endif %}
                                        </select>
                                    </div>
                                </div>

                                <div class="row form-group brand-name">
                                    <div class="col-md-12">
                                        <div class="field-group advs_desc">
                                            {% for field in form.fields.translations('advs_desc') %}
                                                {{ field.render({'form': form})|raw }}
                                            {% endfor %}
                                        </div>
                                    </div>
                                </div>
                                <div class="row form-group images">
                                    <div class="col-md-12">
                                        {{ form.fields.files.input |raw }}
                                    </div>
                                </div>
                                {{ addBlock('new-ad/other-fields',{'custom_fields':custom_fields})|raw }}

                                {% include "visiosoft.module.location::new-ad/map" %}

                                <input value="{{ adv.map_Val }}" name="map_Val" data-max="255" data-mask=""
                                       data-alias="" data-regex=""
                                       type="text" placeholder="" class="hidden d-none mapVal" data-field="map_Val"
                                       data-field_name="map_Val" data-provides="anomaly.field_type.text">
                            </div><!-- section -->

                            <div class="checkbox section agreement">

                                <label for="send">
                                    <input type="checkbox" name="send" id="send" required>

                                    {{ trans('visiosoft.module.advs::message.agreement') }}
                                </label><br>
                                {{ form.actions|raw }}
                            </div><!-- section -->

                        </fieldset>
                    </div>
                </div><!-- photos-ad -->

            </div>
            {{ form.close|raw }}
        </div>
    </section>
    {% include "visiosoft.module.advs::new-ad/partials/modals" %}
    {{ addBlock('new-ad/modals')|raw }}
    <script>
        var default_country = "{{ setting_value('visiosoft.module.location::default_country') }}";
        var default_city = "{{ setting_value('visiosoft.module.location::default_city') }}";
        var default_district = "{{ setting_value('visiosoft.module.location::default_district') }}";
        var default_neighborhood = "{{ setting_value('visiosoft.module.location::default_neighborhood') }}";
        var default_currency = "{{ setting_value('streams::currency') }}";
        var default_GET = "{{ setting_value('visiosoft.module.advs::default_GET') }}";
        var adv_id = "{{ id }}";
    </script>

    {{ asset_add("scripts.js", "visiosoft.module.advs::js/new-create.js") }}
    {{ asset_add("scripts.js", "streams::js/form/form.js") }}
    {{ asset_add("scripts.js", "streams::js/form/translations.js") }}
    {{ asset_add("styles.css", "visiosoft.module.advs::css/new-create.js") }}

{% endblock %}