{% set onlineMode = 0 %}
{% set href = path('specialist_show', {'alias': specialist.alias}) %}

{% if app.request.attributes.get('_route') in ['specialist_online_index'] %}
    {% set onlineMode = 1 %}
    {% set href = path('specialist_show', {'alias': specialist.alias, 'specialist_search' : { 'onlineMode': onlineMode }}) %}
{% endif %}

{% if app.request.get('specialist_search')['onlineMode'] is defined and app.request.get('specialist_search')['onlineMode'] == 1 %}
    {% set onlineMode = 1 %}
    {% set href = path('specialist_show', {'alias': specialist.alias, 'specialist_search' : { 'onlineMode': onlineMode }}) %}
{% endif %}
{% set specialistMore = specialist.specialistMore %}

<div class="block-item staff-block block-content">
    <div class="staff-block__main">
        {% if link %}
            <a href="{{ href }}" class="staff-block__img" style="
                background: url(https://api.sovamed.ru/specialist/picture/{{ specialist.img }}) no-repeat; 
                background-size: cover; 
                background-position: center 0px;
            "></a>
        {% else %}
            <span class="staff-block__img" style="
                background: url(https://api.sovamed.ru/specialist/picture/{{ specialist.img }}) no-repeat; 
                background-size: cover; 
                background-position: center 0px;
            "></span>
        {% endif %}
        
        <div class="staff-block__info staff-info">
            {% if link %}
                <a class="staff-info__name" href="{{ href }}">
                    {{ specialist.fio[0] }} <br>
                    {{ specialist.fio[1] }}&nbsp;

                    {% if specialist.fio[2] is defined %}
                        {{ specialist.fio[2] }}
                    {% endif %}
                </a>
            {% else %}
                <p class="staff-info__name">
                    {{ specialist.fio[0] }} <br>
                    {{ specialist.fio[1] }}&nbsp;

                    {% if specialist.fio[2] is defined %}
                        {{ specialist.fio[2] }}
                    {% endif %}
                </p>
            {% endif %}

            {% autoescape %}
                <div class="staff-info__position">{{ specialist.speciality }}</div>
                
                {% if specialist.degree is defined and specialist.degree is not null %}
                    <div class="staff-info__param">
                        {{ specialist.degree }}
                    </div>
                {% endif %}

                {% if specialist.kinder is defined and specialist.kinder is not null %}
                    <div class="staff-info__param">
                        Приём детей с {{ specialist.kinder }} {{ textYear(specialist.kinder, false) }}
                    </div>
                {% endif %}

                {% if specialist.experience is defined and specialist.experience is not null %}
                    <div class="staff-info__param">
                        Опыт работы: {{ specialist.experience }} {{ textYear(specialist.experience, true) }}
                    </div>
                {% endif %}

                {% if specialist.category is defined and specialist.category is not null %}
                    <div class="staff-info__param">
                        Категория: {{ specialist.category }}
                    </div>
                {% endif %}

                {% if specialist.acceptsDms is defined and specialist.acceptsDms is not null %}
                    <div class="staff-info__param{% if not specialist.acceptsDms %} staff-info__param--dms-no{% endif %}">
                        {{ specialist.acceptsDms ? 'Принимает по ДМС' : 'Не принимает по ДМС' }}
                    </div>
                {% endif %}

            {% endautoescape %}

            {% if specialistMore.hasReviews %}
                <a href="{{ path('specialist_show', {'alias': specialist.alias, '_fragment': 'reviews'}) }}" class="staff-info__review">
                    Отзывы
                </a>
            {% endif %}
        </div>
    </div>
    <div class="staff-info__time-list time-list" id="pcode" data-pcode="{{ csrf_token('send-veretify-sms') }}">
        <div {% if specialist.isInfoclinica %}
                data-controller='checkSchedule' data-id="{{ specialistMore.defaultLocation.dcode|default(0) }}:{{ onlineMode }}:{{ specialist.infoclinica }}"
        {% endif %}>

            {% set render = true %}

            {% if specialistMore.locationsCount > 1 %}
                <div class="filter__input-wrap">
                    {% if onlineMode and render %}
                        {% for location in specialistMore.locations %}
                            {% if location.onlineMode == 1 and render %}
                                {% set render = false %}
                                <div class="filter__select bg-address onlineMode">
                                    <span value="{{ location.dcode }}:{{ location.filial }}:{{ location.department }}:1:{{ specialist.infoclinica }}">
                                        Онлайн консультация
                                    </span>
                                </div>
                            {% endif %}
                        
                        {% endfor %}
                    {% else %}
                        <select data-controller='selectpicker' data-width="100%" class="filter__select select-schedule" style="padding-left: 10px;padding-right: 10px;">
                            {% for location in specialistMore.locations %}
                                <option value="{{ location.dcode }}:{{ location.filial }}:{{ location.department }}:0:{{ specialist.infoclinica }}">
                                    {{ location.addressName }}: {{ location.name }}
                                </option>
                            {% endfor %}
                        </select>
                    {% endif %}
                </div>
            {% else %}
                <div class="filter__input-wrap">
                    {% if specialistMore.defaultLocation.onlineMode|default(false) == true and onlineMode and render %}
                        {% set render = false %}
                        <div class="filter__select bg-address onlineMode">
                            <span value="{{ specialistMore.defaultLocation.dcode }}:{{ specialistMore.defaultLocation.filial }}:{{ specialistMore.defaultLocation.department }}:1:{{ specialist.infoclinica }}">
                                Онлайн консультация
                            </span>
                        </div>
                    {% else %}
                        <div class="filter__select bg-address">
                            <span value="{{ specialist.defaultLocation.dcode|default(0) }}:{{ specialist.defaultLocation.filial|default(0) }}:{{ specialist.defaultLocation.department|default(0) }}:0:{{ specialist.infoclinica }}">
                                {{ specialistMore.defaultLocation.addressName|default('null') }}
                            </span>
                        </div>
                    {% endif %}
                </div>
            {% endif %}
        </div>
        {% if specialist.infoclinica %}
            <p class="time-list__title">Удобное время для записи: <span class="cdate">загружается</span></p>
        {% else %}
            <p class="time-list__title">Вы можете записаться, оставив заявку</p>
        {% endif %}

        <div class="time-intervals mt-3 mb-1">
            {% if specialist.infoclinica %}
                <div class="intervals time-list__intervals" id="{{ specialistMore.defaultLocation.dcode|default(0) }}:{{ onlineMode }}:{{ specialist.infoclinica }}">
                    <div class="intervals-wrap"></div>
                    <span
                        class="btn-show-specialist-detail show-specialist-detail"
                        data-address="{{ specialistMore.defaultLocation.address|default('') }}"
                        data-company="{{ specialistMore.defaultLocation.company|default('') }}"
                        data-onlineMode="{{ onlineMode }}"
                        data-departmentId="{{ specialistMore.defaultLocation.department|default(0) }}"
                        data-filialId="{{ specialistMore.defaultLocation.filial|default(0) }}"
                        data-specialistId="{{ specialistMore.defaultLocation.dcode|default(0) }}"
                        data-docName="{{ specialist.name|default('') }}"
                        data-controller="calendar"
                        data-comment="{{ specialist.name|default('') }}, {{ specialist.speciality|default('') }}"
                    >Все даты</span>
                </div>
            {% else %}
                <div class="intervals time-list__intervals space-between">
                    <button
                        data-docName="{{ specialist.name|default('') }}"
                        data-address="{{ specialistMore.defaultLocation.address|default('') }}"
                        data-company="{{ specialistMore.defaultLocation.company|default('') }}"
                        data-comment="{{ specialist.name|default('') }}, {{ specialist.speciality|default('') }}"
                        class="btn-show-specialist-detail"
                        type="button"
                        data-controller="uslugi"
                    >Записаться</button>
                </div>
            {% endif %}
        </div>
        <div class="time-list__bottom">
            {% set route = app.request.get('_route') %}
            {% if isShowInRegion([91,92,93]) %}
                {% if specialistMore.minPrice is not null  and route != 'specialist_online_index' and onlineMode != 1 %}
                    <span class="time-list__price">Прием от {{ specialistMore.minPrice.priceInfo.price }} ₽</span>
                {% else %}
                    <span class="time-list__price">&nbsp;</span>
                {% endif %}
            {% endif %}
            <div data-controller='favorites' data-sid="{{ specialistMore.defaultLocation.dcode|default(0) }}" class="d-block text-right mr-3">
                <i class="fa fa-bookmark d-none dislike" aria-hidden="true">
                    <span class="dislike" aria-hidden="true">
                        <span style="font-family: Circe;">
                            В моих врачах
                        </span>
                    </span>
                </i>
                <i class="fa fa-bookmark-o like like-btn" aria-hidden="true">
                    <span class="like" aria-hidden="true">
                        <span style="font-family: Circe;">
                            В избранное
                        </span>
                    </span>
                </i>
            </div>
        </div>    
    </div>
</div>