<?php

namespace App\PageBuilder\Components\Content;

use App\PageBuilder\PageComponent;

class ImageComponent extends PageComponent
{
    public function key(): string { return 'image'; }
    public function category(): string { return 'content'; }
    public function label(): string { return 'Image'; }
    public function icon(): string { return 'fas fa-camera'; }

    public function schema(): array
    {
        return [
            'src'     => ['type' => 'image', 'label' => 'Görsel', 'required' => true],
            'alt'     => ['type' => 'text', 'label' => 'Alt metni'],
            'caption' => ['type' => 'text', 'label' => 'Açıklama'],
            'link'    => ['type' => 'link', 'label' => 'Tıklanınca git'],
            'options' => [
                'padding'      => ['type' => 'padding_token', 'default' => 'md'],
                'alignment'    => ['type' => 'alignment_token', 'default' => 'center'],
                'max_width'    => ['type' => 'select', 'label' => 'Maks genişlik', 'options' => ['25%','50%','75%','100%'], 'default' => '100%'],
                'rounded'      => ['type' => 'select', 'label' => 'Köşe yuvarlama', 'options' => ['none', 'sm', 'md', 'lg', 'circle'], 'default' => 'md'],
                'shadow'       => ['type' => 'select', 'label' => 'Gölge', 'options' => ['none', 'sm', 'md', 'lg'], 'default' => 'none'],
                'aspect_ratio' => ['type' => 'select', 'label' => 'En-boy oranı', 'options' => ['auto', '16:9', '4:3', '1:1', '3:4'], 'default' => 'auto'],
                'lazy'         => ['type' => 'boolean', 'label' => 'Lazy load', 'default' => true],
            ],
        ];
    }

    public function defaults(): array
    {
        return [
            'src' => null, 'alt' => '', 'caption' => null, 'link' => null,
            'options' => [
                'padding' => 'md', 'alignment' => 'center', 'max_width' => '100%',
                'rounded' => 'md', 'shadow' => 'none', 'aspect_ratio' => 'auto', 'lazy' => true,
            ],
        ];
    }

    public function render(array $data, array $options): string
    {
        return view('page-builder.components.image', compact('data', 'options'))->render();
    }
}
