<?php

namespace App\Orchid\Screens\Color;

use App\Models\Color;
use Orchid\Screen\Screen;
use Orchid\Screen\Actions\Link;
use Orchid\Support\Facades\Alert;
use App\Orchid\Layouts\Color\ColorListLayout;

class ColorListScreen extends Screen {

  public function query(): iterable {
    return [
      'colors' => Color::filters()->defaultSort('updated_at', 'desc')->paginate(10),
    ];
  }

  public function name(): ?string {
    return 'Colors';
  }

  public function commandBar(): iterable {
    return [
      Link::make('Create new')
        ->icon('bs.plus-circle')
        ->route('platform.color.create'),
    ];
  }

  public function layout(): iterable {
    return [
      ColorListLayout::class,
    ];
  }

  public function remove(Color $color) {
    $color->delete();
    Alert::info('You have successfully deleted the color.');
    return redirect()->route('platform.color.list');
  }
}
