<div role="tabpanel" class="tab-pane{{ $active_tab == 'redirects' ? ' active' : '' }}" id="redirects-tab">
    <h4>@lang('admin.redirects_heading')</h4>
    <p>@lang('admin.redirects_text')</p>
    @if ($album->redirects()->count() > 0)
        <p>@lang('admin.existing_album_redirects')</p>

        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>@lang('admin.redirects_source_url_heading')</th>
                        <th style="width: 100px;">@lang('admin.redirects_actions_heading')</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($album->redirects as $redirect)
                        <tr>
                            <td><a href="{{ route('home') }}/a{{ $redirect->source_url }}">{{ route('home') }}/a{{ $redirect->source_url }}</a></td>
                            <td>
                                <form method="post" action="{{ route('albums.delete_redirect', [$album->id, $redirect->id]) }}">
                                    {{ csrf_field() }}
                                    {{ method_field('DELETE') }}
                                    <input type="hidden" name="redirect_id" value="{{ $redirect->id }}" />
                                    <button type="submit" class="btn btn-sm btn-danger delete-redirect">@lang('forms.delete_action')</button>
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <br/>

    @endif

    <hr/>
    <h5>@lang('admin.create_redirect_heading')</h5>
    <p>@lang('admin.create_redirect_text')</p>

    <form method="post" action="{{ route('albums.store_redirect', [$album->id]) }}">
        {{ csrf_field() }}
        <div class="form-group">
            <label for="redirect-source">@lang('forms.album_redirect_source')</label>
            <input type="text" class="form-control{{ $errors->has('source_url') ? ' is-invalid' : '' }}" id="redirect-source" name="source_url" placeholder="@lang('forms.album_redirect_source_placeholder')" value="{{ old('source_url') }}" aria-describedby="redirect-source-help">
            <small id="redirect-source-help" class="form-text text-muted">@lang('forms.album_redirect_source_help')</small>

            @if ($errors->has('source_url'))
                <div class="invalid-feedback">
                    <strong>{{ $errors->first('source_url') }}</strong>
                </div>
            @endif
        </div>

        <div class="text-right">
            <button type="submit" class="btn btn-success"><i class="fa fa-check"></i> @lang('forms.create_action')</button>
        </div>
    </form>

    <!-- Delete redirect modal -->
    <div class="modal" id="confirm-redirect-delete-modal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">@lang('admin.delete_redirect_confirm_title')</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <p>@lang('admin.delete_redirect_confirm_message')</p>
                    <p><strong class="redirect-url"></strong></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">@lang('forms.cancel_action')</button>
                    <button type="button" class="btn btn-danger">@lang('forms.delete_action')</button>
                </div>
            </div>
        </div>
    </div>
</div>

@push('scripts')
    <script type="text/javascript">
        var source_form = null;

        $(document).ready(function() {
            $('.btn-danger', '#confirm-redirect-delete-modal').click(function(e)
            {
                $(source_form).submit();

                e.preventDefault();
                return false;
            });

            $('.delete-redirect').click(function(e) {
                source_form = $(this).closest('form');
                $('#confirm-redirect-delete-modal').modal();
                $('.redirect-url', '#confirm-redirect-delete-modal').html($(this).closest('a').html());

                e.preventDefault();
                return false;
            });
        });
    </script>
@endpush