{{-- Basic table view --}}

@extends('layouts.app')

@php
  /** @var \App\Models\Table $table */
@endphp

@section('content')
  <div class="row justify-content-start px-3">
    <div class="d-flex w-100 align-items-center">
      <small class="flex-grow-1" style="font-size: 120%;">
        <a href="{{route('profile.view', $table->owner->name)}}" class="link-no-color">{{ $table->owner->handle }}</a>{{--
      --}}<span class="px-1">/</span>{{--
      --}}<b>{{ $table->name }}</b>
      </small>

      <h1 class="mx-3">{{ $table->title }}</h1>

      <a href="{{ $table->viewRoute }}" class="btn btn-outline-primary py-1 btn-sm" @tooltip(Back to Table)>
        @icon(fa-reply, sr:Back to Table)
      </a>
    </div>
  </div>

  <form method="POST" action="{{$table->settingsRoute}}" class="row justify-content-center"
        aria-label="Change Table Metadata">

    @csrf
    <div class="col-md-10">
      @php(Widget::setLayout(3, 7))

      {!! Widget::header(2, 'Table Metadata') !!}

      {!! Widget::text('title', 'Title')->value($table->title)
            ->help('Unique among your tables') !!}

      {!! Widget::par('Changing table name will change its URL, possibly breaking external links or bookmarks!') !!}

      {!! Widget::text('name', 'Name')->value($table->name)->prepend(user()->handle.' /')
            ->help('Unique among your tables, and part of the URL; only letters, digits and
                    some symbols are allowed.') !!}

      {!! Widget::textarea('description', 'Description')->value($table->description)
            ->height('8em')
            ->help('Description of the table. URLs in a full format will be clickable.') !!}

      {!! Widget::text('license', 'License')->value($table->license)
            ->help('License applicable to the table\'s data, if any. By default, all
              tables are CC0 or Public Domain.') !!}

      {!! Widget::text('origin', 'Adapted from')->value($table->origin)
            ->help('If you took the data from some external site, a book, etc., write it here.
               URLs in a full format will be clickable.') !!}

      <div class="row form-group">
        <div class="col-md-7 offset-md-3">
          <button type="submit" class="btn btn-primary">
            @icon(fa-save fa-pr)Save Changes
          </button>
        </div>
      </div>
    </div>
  </form>


  <form method="POST" action="{{$table->deleteRoute}}" class="row justify-content-center mt-3"
        aria-label="Delete table">

    @csrf
    <div class="col-md-6 offset-md-1 border border-danger rounded py-3 border-2">
      @php(Widget::setLayout(0, 12))

      {!! Widget::header(2, 'Delete Table') !!}

      {!! Widget::par(
        'Table deletion cannot be undone. However, data from the table may
         remain accessible if any users forked it.', 'mb-0') !!}

      <hr>

      {!! Widget::par(
        'Confirm table removal by typing its name:') !!}

      <div class="row form-group">
        <div class="col-md-12">
          <div class="form-inline">
            <input name="table-name"
                   class="form-control {{ $errors->has('table-name') ? ' is-invalid' : '' }}"
                   value="" placeholder="table-name">

            <button type="submit" class="btn btn-danger ml-2">
              @icon(fa-save fa-pr)Delete
            </button>
          </div>
        </div>
      </div>
    </div>
  </form>
@endsection