<?php

use Botble\Gallery\Models\Gallery;
use Botble\Widget\AbstractWidget;
use Illuminate\Support\Collection;

class GalleriesWidget extends AbstractWidget
{
    public function __construct()
    {
        parent::__construct([
            'name' => __('Galleries'),
            'description' => __('Widget description'),
            'gallery_id' => null,
        ]);
    }

    protected function adminConfig(): array
    {
        if (! is_plugin_active('gallery')) {
            return ['galleries' => []];
        }

        return [
            'galleries' => Gallery::query()
                ->wherePublished()
                ->pluck('name', 'id'),
        ];
    }

    protected function data(): array|Collection
    {
        if (! is_plugin_active('gallery')) {
            return ['galleries' => []];
        }

        return [
            'gallery' => Gallery::query()
                ->wherePublished()
                ->where('id', $this->getConfig('gallery_id'))
                ->first(),
        ];
    }
}
