@view('header', [ 'title' => $account->name . ' - Accounts' ])

<div class="breadcrumb">
    <ul>
        <li><a href="/">Banq</a></li>
        <li><a href="/accounts">Accounts</a></li>
        <li class="is-active"><a href="/accounts/{{ $account->id }}">{{ $account->name }}</a></li>
    </ul>
</div>

<h1 class="title">{{ $account->name }}</h1>

@if ($account->user_id == Auth::id()):
    <p style="margin-bottom: 16px;">
        @if ($account->type == Accounts::TYPE_SAVE):
            <span class="tag is-success">SAVE ACCOUNT</span>
        @endif
        @if ($account->type == Accounts::TYPE_PAYMENT):
            <span class="tag is-info">PAYMENT ACCOUNT</span>
        @endif
    </p>

    <p style="margin-bottom: 16px;">Amount: {!! format_money($account->amount) !!}</p>

    <div class="buttons">
        <a class="button" href="/transactions/create/?from_account_id={{ $account->id }}">Create transaction</a>
        <a class="button" href="/payment-links/create/?account_id={{ $account->id }}">Create payment link</a>
        <a class="button is-link" href="/accounts/{{ $account->id }}/edit">Edit</a>
        <a class="button is-danger" href="/accounts/{{ $account->id }}/delete">Delete</a>
    </div>

    <h2 class="title">Transactions</h2>

    @if (count($transactions) > 0):
        @view('pagination', [ 'page' => $page, 'last_page' => $last_page ])

        @foreach ($transactions as $transaction):
            @if ($transaction->to_account_id == $account->id):
                <div class="box has-text-white has-background-success">
                    <h2 class="title is-4">
                        <a class="has-text-white" href="/transactions/{{ $transaction->id }}">{{ $transaction->name }}</a>
                    </h2>

                    @if (is_numeric($transaction->from_account_id)):
                        <p>From: <a class="has-text-white" href="/accounts/{{ $transaction->from_account_id }}">{{ $transaction->from_account->name }}</a></p>
                    @else:
                        <p>From: {{ $transaction->from_account_id }}</p>
                    @endif

                    <p>Amount: {!! format_money($transaction->amount) !!}</p>
                    <p>Send at: <i>{{ $transaction->created_at }}</i></p>
                </div>
            @endif

            @if ($transaction->from_account_id == $account->id):
                <div class="box has-text-white has-background-danger">
                    <h2 class="title is-4">
                        <a class="has-text-white" href="/transactions/{{ $transaction->id }}">{{ $transaction->name }}</a>
                    </h2>

                    @if (is_numeric($transaction->to_account_id)):
                        <p>To: <a class="has-text-white" href="/accounts/{{ $transaction->to_account_id }}">{{ $transaction->to_account->name }}</a></p>
                    @else:
                        <p>To: {{ $transaction->to_account_id }}</p>
                    @endif

                    <p>Amount: {!! format_money($transaction->amount) !!}</p>
                    <p>Send at: <i>{{ $transaction->created_at }}</i></p>
                </div>
            @endif
        @endforeach

        @view('pagination', [ 'page' => $page, 'last_page' => $last_page ])
    @else:
        <p><i>There are no transactions found</i></p>
    @endif
@else:
    <p>From {{ $account->user->firstname }} {{ $account->user->lastname }}</p>
@endif

@view('footer')
