chats_list.blade.php 5.58 KB
@if ($chats->count() || $admin_chat)
    @csrf

    @if($admin_chat)
        <div class="messages__item hover-shadow admin-chat-wrap">
            <a class="messages__item-info" href="{{ route($user_type . '.dialog', ['chat' => $admin_chat->id]) }}">
                @include('svg.logo_icon')
                <div class="messages__item-text">
                    <div>
                        <b>Администратор сайта</b>
                    </div>
                    <div>
                        {{ $admin_chat->last_message?->text }}
                    </div>
                </div>
            </a>

            <div class="messages__item-actions" data-chat-id="{{ $admin_chat->id }}">
                <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($admin_chat->created_at)) }}</div>
                <div class="messages__item-buttons">
                    @if($admin_chat->unread_messages_count > 0)
                        <div class="unread-messages-count mr-15">{{ $admin_chat->unread_messages_count }}</div>
                    @endif
                </div>
            </div>
        </div>
    @endif

    @if ($chats->count())
    @include('modals.flash-message', [
        'title' => 'Успешно!',
        'message' => session('success')
    ])
    @foreach($chats as $chat)
        @if(!$chat->is_admin_chat)
        <div class="messages__item hover-shadow {{ intval($chat->is_fixed) == 1 ? 'chat-fixed' : '' }}">
            <a class="messages__item-info" href="{{ route($user_type . '.dialog', ['chat' => $chat->id]) }}">
                <div class="messages__item-photo">
                    @if (isset($chat->employer->logo))
                        <img src="{{ asset(Storage::url($chat->employer->logo)) }}" alt="">
                    @elseif(isset($chat->worker->photo))
                        <img src="{{ asset(Storage::url($chat->worker->photo)) }}" alt="">
                    @else
                        <img src="{{ asset('images/default_man.jpg') }}" alt="">
                    @endif
                </div>
                <div class="messages__item-text">
                    <div>
                        <b id="chat_name">
                            @if ($chat->employer && $chat->employer->name_company)
                                {{ $chat->employer->name_company }}
                            @elseif($chat->user)
                                {{ $chat->user->surname . ' ' . $chat->user->name_man . ' ' . $chat->user->surname2  }}
                            @endif
                        </b>
                    </div>
                    <div>
                        {{ $chat->last_message?->text }}
                    </div>
                </div>
            </a>

            <div class="messages__item-actions" data-chat-id="{{ $chat->id }}">
                <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($chat->created_at)) }}</div>
                <div class="messages__item-buttons">
                    @if($chat->unread_messages_count > 0)
                        <div class="unread-messages-count mr-15">{{ $chat->unread_messages_count }}</div>
                    @endif
                    <button
                        class="pin-chat {{ intval($chat->is_fixed) == 1 ? 'pin-on' : 'pin-off' }} mr-15"
                        data-form-id="pin-chat-form-{{ $chat->id }}">
                        @if (intval($chat->is_fixed) == 1)
                            @include('svg.pin_on')
                        @else
                            @include('svg.pin_off')
                        @endif
                    </button>
                    <form id="pin-chat-form-{{ $chat->id }}" action="{{ route('employer.pin_chat') }}" method="POST" style="display: none;">
                        @csrf
                        <input type="hidden" name="id" value="{{ $chat->id }}">
                        <input type="hidden" name="is_fixed" value="{{ intval($chat->is_fixed) == 1 ? 0 : 1 }}">
                    </form>
                    <button class="remove-chat" data-user="{{ $chat->user_id }}" data-fancybox data-src="#remove_chat">
                        <svg>
                            <use xlink:href="{{ asset('images/sprite.svg#del') }}"></use>
                        </svg>
                    </button>
                </div>
                <div class="clear"></div>
            </div>
        </div>
        @endif
    @endforeach
    <div style="margin-top: 20px">
        {{ $chats->onEachSide(0)->appends($_GET)->links('paginate') }}
    </div><!-- конец -->
     @endif
@else
    <div class="notify">
        <svg>
            <use xlink:href="{{ asset('images/sprite.svg#i') }}"></use>
        </svg>
        <span>Сообщений не найдено</span>
    </div>
@endif

<script>
    $(function (){
        $('.pin-chat').on('click', function (event) {
            event.preventDefault();
            const formId = $(this).data('form-id');
            const $form = $('#' + formId);

            if ($form.length) {
                $form.submit();
            } else {
                console.error('Form not found:', formId);
            }
        });

        $('.remove-chat').click(function(){
            var this_btn = $(this);
            var chat_id = this_btn.closest('.messages__item-actions').data('chat-id');
            var wrap = this_btn.closest('.messages__item');
            var target = wrap.find('.messages__item-text').find('#chat_name').text();

            $('#remove_chat').data('chat-id', chat_id);
            $('#remove_chat').find('.target-chat').text(target.trim());
        });
    });
</script>