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

{% block content %}
    <section class="clearfix home-default">
        {% include 'visiosoft.module.advs::new-ad/partials/steps' with {'step': 'new-create'} %}

        <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': {
                            'text': trans('visiosoft.module.advs::button.publish')
                        }}).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 bg-light p-4">
                                <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>

                                {% if setting_value('visiosoft.module.advs::market_place') %}
                                    {{ addBlock('new-ad/fields', {'adv': adv})|raw }}
                                {% endif %}
                                <div class="row form-group select-price
                                            {{ setting_value('visiosoft.module.advs::hide_standard_price_field') ? ' d-none' }}
                                            {{ setting_value('visiosoft.module.advs::market_place') != true ? '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
                                            {{ setting_value('visiosoft.module.advs::price_area_hidden') ? 'hidden' }}">

                                    <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-6 col-sm-7 pr-0 col-md-3">
                                        <input class="form-control priceField whole-price" value="{{ PriceValue|first }}">
                                    </div>
                                    {% if setting_value('visiosoft.field_type.decimal::showDecimal') %}
                                        <div class="col-4 col-md-1">
                                            <input class="form-control priceDecimalField decimal-price" placeholder="00" maxlength="2"
                                                   value="{{ PriceValue[1] }}">
                                        </div>
                                    {% endif %}
                                    <div class="col-sm-3 col-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>

                                {% if not setting_value('visiosoft.module.advs::hide_options_field') %}
                                    <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 product-options">
                                        <label for="productOptions" class="col-sm-2">
                                            {{ trans('visiosoft.module.advs::field.product_option.name') }}
                                        </label>
                                        <div class="col-sm-10">
                                            {{ form.fields.product_options_value.configSet('cat1',adv.cat1).input|raw }}
                                        </div>
                                    </div>
                                {% endif %}
                            </div>

                            <h5 class="mt-5 pb-1 border-bottom">{{ trans('visiosoft.module.advs::field.ad_desc') }}</h5>
                            <div class="bg-light p-4">
                                <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>

                            <h5 class="mt-5 pb-1 border-bottom">
                                {{ trans('visiosoft.module.advs::field.upload_photos') }}
                            </h5>
                            <div class="bg-light p-4">
                                <div class="row form-group images">
                                    <div class="col-md-12">
                                        {{ form.fields.files.input |raw }}
                                    </div>
                                </div>
                            </div>

                            {% if count(custom_fields) %}
                                <h5 class="mt-5 pb-1 border-bottom">
                                    {{ trans('visiosoft.module.advs::field.additional_fields') }}
                                </h5>
                                <div class="bg-light p-4">
                                    {{ addBlock('new-ad/other-fields',{'custom_fields':custom_fields})|raw }}
                                </div>
                            {% endif %}

                            <h5 class="mt-5 pb-1 border-bottom">
                                {{ trans('visiosoft.module.advs::field.ad_location') }}
                            </h5>
                            <div class="bg-light p-4 mb-4">
                                {% 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">
                                {% if setting_value('visiosoft.module.advs::show_post_ad_agreement') %}
                                    <label for="send">
                                        <input type="checkbox" name="send" id="send" required>

                                        {{ trans('visiosoft.module.advs::message.agreement') }}
                                    </label><br>
                                {% endif %}

                                {{ 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 }}";
        var pick_option = "{{ trans('visiosoft.module.location::field.pick_option.name') }}"
    </script>

    {% if setting_value('visiosoft.module.advs::make_map_required') %}
        <script>
            let selectLocationAlert = "{{ trans('visiosoft.module.advs::message.select_location_error') }}"
        </script>
        {{ asset_add("scripts.js", "visiosoft.module.advs::js/required-map.js") }}
    {% endif %}

    {{ 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 %}