@extends('template.'.config('settings.template').'.content.master')
@section('content')
    @if (\Route::currentRouteName() != 'author.get')
        <div class="row" style="margin-top:50px;">
            <div class="mx-auto" style="overflow: scroll">
                <div class="btn-group btn-group-toggle mx-auto" data-toggle="buttons">
                    <label class="btn btn-lg {{ (!isset($categoryModel) and \Request::route()->getName() != 'nachrichten.get' and \Request::route()->getName() != 'author.get') ? 'active btn-primary' : 'btn-outline-primary' }}" onclick="location.href = '{{ url('/')  }}';">
                        <input type="radio" name="options" id="option1" autocomplete="off" checked=""> <i class="fal fa-bookmark" aria-hidden="true"></i> Home
                    </label>
                    @foreach ($categories as $category)
                        <label class="btn btn-lg {{ (isset($categoryModel) and $category->id == $categoryModel->id) ? 'active btn-primary' : 'btn-outline-primary' }}" onclick="location.href = '{{ url('/' . $category->slug)  }}';">
                            <input type="radio" name="options" id="option3" autocomplete="off">
                            @if($category->icon == 'bitcoin')
                                <i class="fab fa-{{$category->icon}}"></i>
                            @else
                                <i class="fal fa-{{$category->icon}}"></i>
                            @endif
                            {{ $category->name }}
                        </label>
                    @endforeach
                </div>
            </div>
        </div>
        <div class="container">
            <div class="col-12">
                @if (isset($categoryModel))
                    <br><br>
                    <h1>
                        @if($categoryModel->icon == 'bitcoin')
                            <i class="fab fa-{{$categoryModel->icon}}"></i>
                        @else
                            <i class="fal fa-{{$categoryModel->icon}}"></i>
                        @endif
                        {{ $categoryModel->name }}</h1>
                @else
                    <br><br>
                    <h1>{{ config('settings.name')}}</h1>
                @endif
                    <p class="intro">
                        @if (isset($categoryModel))
                            {{ $categoryModel->description }}
                        @else
                            {{ config('settings.description')}}
                        @endif
                        <br>
                    </p>
            </div>
        </div>
    @endif
    <div class="container">
        <div class="row">
            @if (\Route::currentRouteName() == 'author.get')
                <div class="col-sm-12 col-md-2 text-center">
                    <br>
                    <br>
                    <img src="{{ $author->gravatar() }}?s=120&d=identicon&r=PG" width="120" class="rounded-circle img-fluid border" title="{{ $author->name }}">
                </div>
                <div class="col-sm-12 col-md-10">
                    <br><br>
                    <h1>{{ $author->name }}</h1>
                    <p class="intro">
                        {{ $author->description }}
                    </p>
                    <div class="row">
                    <div class="col-md-7 col-sm-12">
                        @if (isset($author->social_networks['email']))
                            <a href="mailto:{{ $author->social_networks['email'] }}"><i class="fal fa-envelope"></i></a>
                            |
                        @endif
                        @if (isset($author->social_networks['site']))
                            <a href="{{ $author->social_networks['site'] }}">{{ $author->social_networks['site'] }}</a>
                        @endif
                        <br>
                        <br>
                    </div>
                    <div class="col-md-5 col-sm-12 text-center">
                        <?php
                            $social = [
                                'telegram',
                                'behance',
                                'snapchat',
                                'stack-overflow',
                                'vimeo',
                                'github',
                                'reddit',
                                'instagram',
                                'linkedin',
                                'pinterest',
                                'twitter',
                                'facebook',
                                'youtube'
                            ];
                        ?>
                        @foreach ($social as $value)
                            @if (isset($author->social_networks[$value]))
                                <a href="{{ $author->social_networks[$value] }}"><i class="fab fa-{{ $value }}"></i></a>
                            @endif
                        @endforeach
                        <br>
                        <br>
                    </div>
                    </div>
                </div>
            @endif
            @if (\Route::currentRouteName() == 'welcome')
                <div class="col-12">
                    <br>
                    <br>
                    <h2 class="h4" class="text-center">{{ __('public.popular-authors') }}</h2>
                </div>
                @foreach ($authors as $author)
                    <div class="col-4 col-md-2 text-center">
                        <br>
                        <a href="{{ route('author.get', [$author->slug]) }}" title="{{ $author->name }}">
                            <img src="{{ $author->gravatar() }}?s=120&d=identicon&r=PG" width="120" class="rounded-circle img-fluid border">
                        </a>
                    </div>
                @endforeach
                <!--<div class="col-lg-12" style="text-align: center">
                    <br>
                    <br>
                    <a href=""> See all authors <i class="fal fa-arrow-right"></i></a>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                    <br>
                </div>-->
                <div class="col-lg-12">
                    <br>
                    <br>
                    <br>
                </div>
            @endif
        </div>
    </div>
    <section id="article-section">
        <div class="container">
            @if (env('APP_WRITE', false))
                    <br>
                    <br>
                    <br>
                    <a href="" class="float-right" data-toggle="modal" data-target="#exampleModal"><i class="fal fa-plus"></i> {{ __('public.propose-content') }} Neuen Inhalt einreichen</a>
                    <br>
                    <br>
                @endif
            @include('template.'.config('settings.template').'.content.includes.create-content')
            <br>
            @if (session()->has('success'))
                <div class="row justify-content-center">
                    <div class="col-lg-8">
                        @if(is_array(session()->get('success')))
                        <div class="alert alert-success alert-dismissible fade show" role="alert">
                            <h4 class="alert-heading">Nachricht wurde erfolgreich eingereicht!</h4>
                            Ihre Nachricht wurde erfolgreich an uns übermittelt und wir nach Prüfung hier veröffentlicht.
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        @else
                            {{ session()->get('success') }}
                        @endif
                    </div>
                </div>
            @endif
            @if (session()->has('error'))
                <div class="row justify-content-center">
                    <div class="col-lg-8">
                        @if(is_array(session()->get('error')))
                        <div class="alert alert-danger alert-dismissible fade show" role="alert">
                            <h4 class="alert-heading">Es ist ein Fehler aufgetreten!</h4>
                            Beim übermitteln Ihrer Nachricht ist ein Fehler aufgetreten. Der Admin wurde informiert.
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        @else
                            {{ session()->get('error') }}
                        @endif
                    </div>
                </div>
            @endif
            <div class="article-feed">
                    @foreach($nachrichten as $nach)
                    <article class="newsentry" style="width: 100%;" data-slug="{{ $nach->category->slug }}/{{ $nach->slug }}">
                    @if ($nach->paid != 0 and (empty($nach->premium_until) or $nach->premium_until > date('Y-m-d')) and !\Session::get('premium_code'))
                            <div class="col-lg-12">
                                <div class="card shadow-lg" id="news-{{$nach->id}}">
                                    <div class="card-body" style="padding-bottom: 0;">
                                        @if($nach->created_at->diffInHours(date('Y-m-d H:i:s')) < 1)
                                            <div class="progress" style="height: 30px;">
                                                <div class="progress-bar progress-bar-striped progress-bar-animated bg-warning" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
                                                    <span style="color: black; font-size: 16px;">{{ $nach->created_at->diffForHumans() }} veröffentlicht</span>
                                                </div>
                                            </div>
                                            <br>
                                        @endif
                                        <a href="{{ route('nachrichten.get', [$nach->category->slug, $nach->slug]) }}">
                                            <h2 class="card-title">{{$nach->title}}</h2>
                                        </a>
                                        <h6 class="card-subtitle mb-2">
                                            @if ($nach->user and $nach->user->public_author == 1)
                                           <a   class="text-dark" href="{{ route('author.get', [$nach->user->slug]) }}"">
                                               <img src="{{ $nach->user->gravatar() }}?s=32&d=identicon&r=PG" width="32" class="rounded-circle">
                                               {{ $nach->user->name }}
                                               </a> - <span style="font-weight: normal " class="text-dark"">{{date('d.m.Y H:i', strtotime($nach->created_at))}}</span>
                                            @else
                                                <span style="font-weight: normal " class="text-dark"">{{date('d.m.Y H:i', strtotime($nach->created_at))}}</span>
                                            @endif
                                        </h6>
                                        @if ($nach->category)
                                            <a href="{{ route('category.get', [$nach->category->slug]) }}">
                                                <div class="badge badge-primary">
                                                    <p style="margin:3px;font-size:15px;">{{ $nach->category->name}}</p>
                                                </div>
                                            </a>
                                        @endif
                                            @if ($nach->image)
                                                <img src="{{ asset('uploads/' . $nach->image) }}" class="img-responsive" style="max-width: 100%;margin-bottom: 20px; margin-top:20px;    display: block;">
                                            @endif
                                    </div>
                                    <div class="card-body card-preview-{{ $nach->id }} pay-preview">
                                        <div>
                                            <div class="card-text" id="text_news_{{$nach->id}}">
                                                <!-- Here comes the payment preview, tha is the first 200 words of the news content  -->
                                                {!! \Str::limit($nach->nachrichten, 285, ' ...') !!}
                                            </div>
                                        </div>
                                            @if ($nach->type_id == 2)
                                                <p class="card-text">
                                                    <p style="font-weight:600;">{{ __('public.work-location') }}</p>
                                                    <div id="text_news_workplace_{{$nach->id}}">{{ isset($nach->additional_fields['workplace']) ? \Str::limit($nach->additional_fields['workplace'], 30, ' ...') : '-'}}
                                                    </div>
                                                        </p>
                                                <p class="card-text">
                                                <p style="font-weight:600;">{{ __('public.contact-data') }}</p>
                                                <div id="text_news_contact_info_{{$nach->id}}">{!! isset($nach->additional_fields['contact_info']) ? \Str::limit($nach->additional_fields['contact_info'], 30, ' ...') : '-' !!}
                                                </div>
                                                </p>
                                            @endif
                                        <div id="box_action_{{ $nach->id }}"></div>
                                    </div>
                                    <div class="card-body payment-request" id="payment-request-{{ $nach->id }}">
                                        <h2 class="text-center"><i class="far fa-gem fa-2x" style="font-size: 20px;"></i> {{ __('public.premium-content') }}</h2>
                                        @if (!empty($nach->premium_until) and $nach->premium_until > date('Y-m-d'))
                                        <small class="text-center d-block">{{ __('public.article-requires-payment') }}mjn  <div id="counter_{{ $nach->id }}" data-id="{{ $nach->id }}" data-date="{{ $nach->premium_until }}" class="counter-class">-</div></small>
                                        @endif
                                        <p class="text-center">To read the article
                                            @if (!empty($nach->premium_until) and $nach->premium_until > date('Y-m-d'))
                                                {{ __('public.now') }}now
                                            @endif
                                            {{ __('public.please-pay') }} {{ $nach->paid }} sats</p>
                                        <br>
                                        <p class="text-center">
                                            <a href="#ln-invoice-{{ $nach->id }}" data-id="{{ $nach->id }}" class="btn btn-warning get-collapse-invoice"><i class="fas fa-bolt"></i> Pay {{ $nach->paid }} sats</a>
                                            <br>
                                            <a href="" class="howtopay" data-toggle="modal" data-target="#exampleModalCode">{{ __('public.use') }} <i class="fal fa-gem"></i> {{ __('public.premium-pass') }}</a>
                                            @include('template.'.config('settings.template').'.content.includes.explain-lightning')
                                            <br>
                                        </p>
                                        <div class="row collapse" id="ln-invoice-{{ $nach->id }}">
                                            <div class="col-sm-6 offset-sm-3">
                                                <a class="pay-news pay-news-{{ $nach->id }}" data-id="{{$nach->id}}" style="cursor:pointer !important;"></a>
                                                <br>
                                                <div id="pay-news-title-{{ $nach->id }}"> </div>
                                            </div>
                                        </div>
                                    </div>
                                    @if (env('APP_COMMENTS', false))
                                        <div class="card-footer" id="comment_button_{{$nach->id}}">
                                            @if(sizeof($nach->comments) > 0)
                                                <a href="#" onclick="showComments(event, {{$nach->id}})"> <span class="badge badge-primary">{{sizeof($nach->comments)}}</span> {{ __('public.display-comments') }}{{ __('public.see-comments') }}</a>
                                            @else
                                                <i>{{ __('public.no-comments-yet') }}</i>
                                            @endif
                                            <button class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#exampleModal2" onclick="setCommentId({{$nach->id}}),ga('send', 'event', 'Read Comments', 'Website', '{{$nach->title}}');">
                                                <i class="fas fa-comment"></i> {{ __('public.comment') }}
                                            </button>
                                        </div>
                                    @endif
                                    <div style="display:none" id="comments_{{$nach->id}}">
                                        <div class="card-footer bg-primary">
                                            <a  class="text-white"> <span class="badge badge-light">{{sizeof($nach->comments)}}</span> {{ __('public.no-comments-yet') }}</a>
                                            <button class="btn btn-dark btn-sm float-right" data-toggle="modal" data-target="#exampleModal2" onclick="setCommentId({{$nach->id}}),ga('send', 'event', 'Create Comment', 'Modal for Comment Creation', '{{$nach->title}}');">
                                                <i class="fas fa-comment"></i> {{ __('public.comment') }}
                                            </button>
                                        </div>
                                        <table>
                                            @foreach($nach->comments as $comment)
                                                <row>
                                                    <div class="card-footer">
                                                        <i class="fas fa-user" style="color: #007BFF"></i> {{$comment->name}}:
                                                        <!-- For now taking that out, time is wrong... -->
                                                        <span class="float-right" title="{{date('d.m.Y | H:i', strtotime($comment->created_at))}} Uhr">{{date('d.m.Y H:i', strtotime($comment->created_at))}} Uhr</span>
                                                    </div>
                                                    <div class="card-body comment-text">
                                                        <p class="card-text">
                                                            {{$comment->comment}}
                                                        </p>
                                                    </div>
                                                </row>
                                            @endforeach
                                        </table>
                                    </div>
                                </div>
                            </div>
                        @else
                            <div class="col-lg-12">
                                <div class="card shadow-lg" id="news-{{$nach->id}}">
                                    @if(\Session::get('premium_code') and $nach->paid != 0 and (empty($nach->premium_until) or $nach->premium_until > date('Y-m-d')))
                                        <div class="bg-ci text-center top-border-radius" style="font-size: 12px;"><i class="fal fa-gem"></i> Premium content</div>
                                    @endif
                                    <div class="card-body">
                                        @if($nach->created_at->diffInHours(date('Y-m-d H:i:s')) < 1)
                                            <div class="progress" style="height: 30px;">
                                                <div class="progress-bar progress-bar-striped progress-bar-animated bg-warning" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
                                                    <span style="color: black; font-size: 16px;">{{ $nach->created_at->diffForHumans() }} veröffentlicht</span>
                                                </div>
                                            </div>
                                            <br>
                                        @endif
                                        <a href="{{ route('nachrichten.get', [$nach->category->slug, $nach->slug]) }}">
                                            <h2 class="card-title">{{$nach->title}}</h2>
                                        </a>
                                        <h6 class="card-subtitle mb-2">
                                            @if ($nach->user and $nach->user->public_author == 1)
                                            <a   class="text-dark" href="{{ route('author.get', [$nach->user->slug]) }}">
                                                <img src="{{ $nach->user->gravatar() }}" width="32" class="rounded-circle">
                                                {{ $nach->user->name }}</a> - <span style="font-weight: normal " class="text-dark"">{{date('d.m.Y H:i', strtotime($nach->created_at))}}</span>
                                            @else
                                                <span style="font-weight: normal " class="text-dark"">{{date('d.m.Y H:i', strtotime($nach->created_at))}}</span>
                                            @endif
                                        </h6>
                                        @if ($nach->category)
                                            <a href="{{ route('category.get', [$nach->category->slug]) }}">
                                                <div class="badge badge-primary">
                                                    <p style="margin:3px;font-size:15px;">{{ $nach->category->name}}</p>
                                                </div>
                                            </a>
                                        @endif
                                        @if ($nach->image)
                                            <img src="{{ asset('uploads/' . $nach->image) }}" class="img-responsive" style="max-width: 100%;margin-bottom: 20px; margin-top:20px;    display: block;">
                                        @endif
                                        <p class="card-text">
                                            {!! $nach->nachrichten !!}
                                        </p>
                                        @if ($nach->type_id == 2)
                                            <p class="card-text">
                                                <p style="font-weight:600;">{{ __('public.work-location') }}</p> {{ isset($nach->additional_fields['workplace']) ? $nach->additional_fields['workplace'] : '-'}}
                                            </p>
                                            <p class="card-text">
                                                <p style="font-weight:600;">{{ __('public.contact-data') }}</p> {!! isset($nach->additional_fields['contact_info']) ? $nach->additional_fields['contact_info'] : '-' !!}
                                            </p>
                                        @endif
                                        @if($nach->type_id == 3)
                                            <hr>
                                            <div class="row">
                                                    @if($nach->show_total_paid_action == 1)
                                                        @if ($nach->actions->count() > 1)
                                                        <div class="col-12">
                                                            <i class="text-center">{{ __('public.vote-distribution') }}</i>
                                                            <div class="progress">
                                                                @foreach ($nach->actions as $action)
                                                                    <div class="progress-bar bg-{{ $action->color }}" role="progressbar" style="width: {{ !empty($nach->total_paid_actions()) ? round(($action->payments()->where('status', 1)->sum('amount') * 100) / $nach->total_paid_actions()) : 0 }}%" aria-valuenow="66" aria-valuemin="0" aria-valuemax="100" title="{{ $action->payments()->where('status', 1)->sum('amount') }} sats">{{ !empty($nach->total_paid_actions()) ? round(($action->payments()->where('status', 1)->sum('amount') * 100) / $nach->total_paid_actions()) : 0 }}% </div>
                                                                @endforeach
                                                            </div>
                                                            <br>
                                                        </div>
                                                        @endif
                                                    @endif
                                                @foreach ($nach->actions as $action)
                                                    <div class="col">
                                                    <small>{{ $action->description }}</small>
                                                        <br>
                                                    @if ($action->type == 2)
                                                            <br>
                                                            <textarea class="form-control" id="message_action_{{ $action->id }}" rows="3" placeholder="Write here your message.."></textarea>
                                                    @endif
                                                   <!-- @if($nach->show_total_paid_action == 1)
                                                        <br>
                                                        @if($action->type == 5)
                                                            <i class="text-center">Donation Goal: 10000 sats.</i>
                                                            <div class="progress">
                                                                <div class="progress-bar bg-{{ $action->color }}" role="progressbar"  aria-valuenow="{{ $action->payments()->where('status', 1)->sum('amount') }}" aria-valuemin="0" aria-valuemax="1000">{{ $action->payments()->where('status', 1)->sum('amount') }} sats</div>
                                                            </div>
                                                        @else
                                                            <i class="text-center">Total paid: {{ $nach->actions->first()->payments()->where('status', 1)->sum('amount') }} sats</i>
                                                        @endif
                                                    @endif-->
                                                    </div>
                                                @endforeach
                                            </div>
                                            <div class="row">
                                                @foreach ($nach->actions as $action)
                                                    <div class="col">
                                                        <a href="" style="margin-top: 20px;" id="action{{ $action->id }}" class="btn btn-{{ $action->color }} mx-0 d-block get-action-invoice" data-id="{{ $action->id }}" data-type="{{ $action->type }}" data-execute="0"><i class="fal fa-{{ $action->icon }}"></i> {{ $action->name }} for {{ $action->amount }} sats.</a>
                                                    </div>
                                                @endforeach
                                            </div>
                                        @endif
                                        @if(sizeof($nach->files) > 0)
                                            <br>
                                            <h5>{{ __('public.files-download') }}</h5>
                                            <div class="row">
                                                @foreach ($nach->files as $file)
                                                    <div class="col-lg-12">
                                                        <a href="{{ asset($file->url)}}" class="btn btn-primary" onclick="ga('send', 'event', 'File Download', 'User', '{{$file->filename}}');" >
                                                            <i class="fas fa-download"></i>
                                                            {{$file->filename}}
                                                        </a>
                                                        <br>
                                                        <br>
                                                    </div>
                                                @endforeach
                                            </div>
                                        @endif
                                    </div>
                                    @if (env('APP_COMMENTS', false))
                                        <div class="card-footer" id="comment_button_{{$nach->id}}">
                                            @if(sizeof($nach->comments) > 0)
                                                <a href="#" onclick="showComments(event, {{$nach->id}})"> <span class="badge badge-primary">{{sizeof($nach->comments)}}</span> {{ __('public.see-comments') }}</a>
                                            @else
                                                <i>{{ __('public.no-comments-yet') }}</i>
                                            @endif
                                            <button class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#exampleModal2" onclick="setCommentId({{$nach->id}}),ga('send', 'event', 'Read Comments', 'Website', '{{$nach->title}}');">
                                                <i class="fas fa-comment"></i> {{ __('public.comment') }}
                                            </button>
                                        </div>
                                    @endif
                                    <div style="display:none" id="comments_{{$nach->id}}">
                                        <div class="card-footer bg-primary">
                                            <a  class="text-white"> <span class="badge badge-light">{{sizeof($nach->comments)}}</span> {{ __('public.comments') }}</a>
                                            <button class="btn btn-dark btn-sm float-right" data-toggle="modal" data-target="#exampleModal2" onclick="setCommentId({{$nach->id}}),ga('send', 'event', 'Create Comment', 'Modal for Comment Creation', '{{$nach->title}}');">
                                                <i class="fas fa-comment"></i> {{ __('public.comment') }}
                                            </button>
                                        </div>
                                        <table>
                                            @foreach($nach->comments as $comment)
                                                <row>
                                                    <div class="card-footer">
                                                        <i class="fas fa-user" style="color: #007BFF"></i> {{$comment->name}}:
                                                        <!-- For now taking that out, time is wrong... -->
                                                        <span class="float-right" title="{{date('d.m.Y | H:i', strtotime($comment->created_at))}} Uhr">{{date('d.m.Y H:i', strtotime($comment->created_at))}} Uhr</span>
                                                    </div>
                                                    <div class="card-body comment-text">
                                                        <p class="card-text">
                                                            {{$comment->comment}}
                                                        </p>
                                                    </div>
                                                </row>
                                            @endforeach
                                        </table>
                                    </div>
                                </div>
                            </div>
                        @endif
                    </article>
                @endforeach
                {{ $nachrichten->links() }}
            </div>
        </div>
    </section>
@stop
