@extends('layouts.app')

@section('content')
<div class="container app-content pt-3">
    <h1 class="h3 mb-4">Translations</h1>
    <div class="d-flex flex-column flex-md-row">
        <a href="{{ route('admin.translation.create') }}" class="btn btn-sm btn-success mb-3 mb-md-0"><i class="mr-2 fa fa-plus"></i> Add Translations</a>
        <a href="{{ route('admin.translation.create.group') }}" class="btn btn-sm btn-outline-info mb-3 mb-md-0 ml-md-3"><i class="mr-2 fa fa-plus-circle"></i> Add Translation Group</a>
        <a href="{{ route('admin.translation.delete.group') }}" class="btn btn-sm btn-outline-secondary mb-3 mb-md-0 ml-md-3"><i class="mr-2 fa fa-trash"></i> Delete Translation Group</a>
    </div>

    <div class="">
        <form action="{{ route('admin.translation.index') }}" method="get" class="row my-3">
            <div class="col-12 col-md-6 mb-3 mb-md-0">
                <div class="input-group">
                    <select name="show_page" class="custom-select custom-select-sm form-control form-control-sm" style="width: auto; flex: inherit;">
                        <option value="10" {{ $show_page == 10 ? 'selected' : '' }}>10</option>
                        <option value="25" {{ $show_page == 25 ? 'selected' : '' }}>25</option>
                        <option value="50" {{ $show_page == 50 ? 'selected' : '' }}>50</option>
                        <option value="100" {{ $show_page == 100 ? 'selected' : '' }}>100</option>
                    </select>
                    <select name="show_lang" class="custom-select custom-select-sm form-control form-control-sm ml-3" style="width: auto; flex: inherit;">
                        @foreach ($languages as $select_lang)
                            <option value="{{ $select_lang->locale }}" {{ $lang == $select_lang->locale ? 'selected' : '' }}>{{ $select_lang->locale.' - '.$select_lang->name }}</option>
                        @endforeach
                    </select>
                    <button class="btn btn-secondary btn-sm ml-2" type="submit">Filter</button>
                </div>
            </div>
            <div class="col-12 col-md-6">
                <div class="input-group">
                    <input type="text" name="search" class="form-control form-control-sm" placeholder="Search">
                    <div class="input-group-append ">
                        <button type="submit" class="btn btn-secondary btn-sm"> <i class="fa fa-search" aria-hidden="true"></i> </button>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <div class="card mb-3">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th scope="col">Group</th>
                        <th scope="col">Key</th>
                        <th scope="col">Text EN</th>
                        <th scope="col" style="max-width: 100px">Text <span class="text-uppercase">{{ $lang }}</span></th>
                        <th scope="col" style="width: auto; min-width: 150px">Action</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($translations as $trans)
                        <tr>
                            <td scope="row" class="text-muted">{{ $trans->group }}</td>
                            <td scope="row" class="text-muted">{{ $trans->item }}</td>
                            <td class="text-muted">{{ __("{$trans->group}.{$trans->item}") }}</td>
                            <td>{{ $trans->text }}</td>
                            <td>
                                <a href="{{ route('admin.translation.edit', $trans) }}" class="btn btn-warning btn-sm" type="button">Edit</a>
                                <a href="{{ route('admin.translation.destroy', $trans) }}" class="btn btn-danger btn-sm"
                                    onclick="event.preventDefault();document.getElementById('delete-{{ $trans->id }}').submit();">Delete</a>

                                <form id="delete-{{ $trans->id }}" action="{{ route('admin.translation.destroy', $trans) }}" method="POST" style="display: none;">
                                    @csrf
                                    @method('DELETE')
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>

    {{ $translations->withQueryString()->links() }}

</div>
@endsection
