<?php

namespace App\Orchid\Screens\Brand;

use App\Models\Brand;
use Orchid\Screen\Screen;
use Orchid\Screen\Actions\Link;
use Orchid\Support\Facades\Alert;
use App\Orchid\Layouts\Brand\BrandListLayout;

class BrandListScreen extends Screen {

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

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

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

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

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