@extends(Theme::viewName('layout'))
@section('title', trans('admin.about.title'))

@section('breadcrumb')
    <li class="breadcrumb-item"><a href="{{ route('home') }}"><i class="fa fa-fw fa-home"></i></a></li>
    <li class="breadcrumb-item"><a href="{{ route('admin') }}">@lang('navigation.breadcrumb.admin')</a></li>
    <li class="breadcrumb-item active">@lang('navigation.breadcrumb.about')</li>
@endsection

@section('content')
    <div class="container">
        <div class="row">
            <div class="col">
                <h1>@lang('admin.about.title')</h1>
                <p>
                    @lang('admin.about.intro')<br/>
                    @lang('admin.about.intro_2')
                </p>

                <ul class="nav nav-tabs mt-5">
                    <li class="nav-item">
                        <a class="nav-link active" data-toggle="tab" href="#versions-tabpanel" role="tab">@lang('admin.about.versions_header')</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" data-toggle="tab" href="#licence-tabpanel" role="tab">@lang('admin.about.licence_header')</a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">@lang('admin.about.links_header')</a>
                        <div class="dropdown-menu">
                            <a class="dropdown-item" href="https://andysh.uk/software/blue-twilight-php-photo-gallery/" target="_blank">@lang('admin.about.website_link')</a>
                            <a class="dropdown-item" href="https://andysh.uk/software/blue-twilight-php-photo-gallery/manual/" target="_blank">@lang('admin.about.user_guide_link')</a>
                            <a class="dropdown-item" href="https://apps.andysh.uk/aheathershaw/blue-twilight" target="_blank">@lang('admin.about.project_website_link')</a>
                        </div>
                    </li>
                </ul>

                <div class="tab-content">
                    <div class="tab-pane active" id="versions-tabpanel" role="tabpanel">
                        <div class="row" id="about-app">
                            <div class="col-md-6 text-center">
                                <p>@lang('admin.about.current_version')</p>
                                <p class="m-0" style="font-size: 2.5rem;">{{ $current_version }}</p>
                            </div>

                            <div class="col-md-6 text-center pt-2">
                                <div v-if="is_loading">
                                    <p><img src="{{ asset('ripple.svg') }}"></p>
                                    <p class="m-0">@lang('admin.about.latest_version_loading')</p>
                                </div>

                                <p v-cloak v-if="!is_loading && !can_upgrade" class="text-success">
                                    <i class="fa fa-check fa-fw"></i> @lang('admin.about.up_to_date')
                                </p>

                                <div v-cloak v-if="!is_loading && can_upgrade" class="text-danger">
                                    <p><i class="fa fa-warning fa-fw"></i> @lang('admin.about.update_available')</p>
                                    <p class="mt-0" style="font-size: 2.5rem;" v-text="version_name"></p>
                                    <p><a class="btn btn-secondary text-white" href="#version-update-modal" data-toggle="modal">View details</a></p>
                                </div>
                            </div>

                            <div class="modal" id="version-update-modal">
                                <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title">@lang('admin.about.version_label') <span v-text="version_name"></span></h5>
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                        </div>
                                        <div class="modal-body">
                                            <div class="alert alert-info">
                                                <p class="m-0"><b>@lang('admin.about.update_available')</b></p>
                                                <p class="m-0">@lang('admin.about.date_published_label') <span v-text="version_date"></span></p>
                                            </div>

                                            <p v-html="version_body"></p>
                                        </div>
                                        <div class="modal-footer">
                                            <a class="btn btn-primary" v-bind:href="version_url">@lang('forms.download_action')</a>
                                            <a class="btn btn-secondary" href="#" data-dismiss="modal">@lang('forms.cancel_action')</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="licence-tabpanel" role="tabpanel">
                        <textarea class="form-control" rows="20" style="border: 0;">
                        {!! $licence_text !!}
                        </textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@push('scripts')
    <script type="text/javascript">
        $(document).ready(function()
        {
            var viewModel = new AboutViewModel({
                latest_release_url: '{{ route('admin.aboutLatestRelease') }}'
            });

            var app = new Vue(viewModel);
            app.$watch('can_upgrade', function(value)
            {
                $('#version-update-modal').modal();
            });
            app.init();
        });
    </script>
@endpush