@php($title = 'Битрикс24: агенты')
@extends('layouts.admin')
@section('content')
    <table class="table">
        <thead>
            <tr>
                <th scope="col">Имя</th>
                <th scope="col">Агентство</th>
                <th scope="col">Телефон</th>
                <th scope="col">Эл. почта</th>
                <th scope="col">ID</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach ($agents as $agent)
                @if($agent->user)
                <tr>
                    <td>{{ $agent->user->name }}
                    <td>{{ $agent->company?->name }}
                    <td>{{ $agent->user?->phone }}
                    <td>{{ $agent->user?->email }}
                    <td>
                        <form method="post" action="{{ route('admin.bitrix.agent.set', ['agent' => $agent->id]) }}"
                            class="input-group mb-3">
                            @csrf
                            <input type="text" name="id" class="form-control" placeholder="ID из Битрикс24"
                                aria-label="" aria-describedby="button-addon2" value="{{ $agent->bitrixId() }}">
                            <button class="btn btn-outline-secondary" type="submit" id="button-addon2">Сохранить</button>
                        </form>
                    </td>
                    <td>
                        <a href="{{ route('admin.bitrix.agent.deals.sync', ['agent' => $agent->id]) }}">Sync</a>
                    </td>
                </tr>
                @endif   
            @endforeach
        </tbody>
    </table>
@endsection
