<?php

namespace Database\Seeders;

use App\Models\ProductShowcase;
use App\Models\ProductShowcaseItem;
use App\Models\Product;
use Illuminate\Database\Seeder;

class ProductShowcaseSeeder extends Seeder
{
    public function run(): void
    {
        // Get some products
        $products = Product::take(20)->get();
        
        if ($products->isEmpty()) {
            return; // No products to showcase
        }

        // Showcase 1: پرفروش‌ترین‌ها
        $showcase1 = ProductShowcase::create([
            'title' => 'پرفروش‌ترین محصولات',
            'subtitle' => 'محبوب‌ترین محصولات ماه',
            'display_type' => 'grid',
            'products_limit' => 8,
            'bg_color' => '#f9fafb',
            'title_color' => '#1f2937',
            'sort_order' => 1,
            'is_active' => true,
        ]);

        foreach ($products->take(8) as $index => $product) {
            ProductShowcaseItem::create([
                'showcase_id' => $showcase1->id,
                'product_id' => $product->id,
                'sort_order' => $index,
            ]);
        }

        // Showcase 2: پیشنهاد ویژه
        $showcase2 = ProductShowcase::create([
            'title' => 'پیشنهاد ویژه',
            'subtitle' => 'فرصت استثنایی برای خرید',
            'display_type' => 'carousel',
            'products_limit' => 6,
            'bg_color' => '#fef2f2',
            'title_color' => '#991b1b',
            'sort_order' => 2,
            'is_active' => true,
        ]);

        foreach ($products->skip(8)->take(6) as $index => $product) {
            ProductShowcaseItem::create([
                'showcase_id' => $showcase2->id,
                'product_id' => $product->id,
                'sort_order' => $index,
            ]);
        }

        // Showcase 3: محصولات جدید
        $showcase3 = ProductShowcase::create([
            'title' => 'تازه‌ها',
            'subtitle' => 'جدیدترین محصولات اضافه شده',
            'display_type' => 'grid',
            'products_limit' => 4,
            'bg_color' => '#f0fdf4',
            'title_color' => '#14532d',
            'sort_order' => 3,
            'is_active' => true,
        ]);

        foreach ($products->skip(14)->take(4) as $index => $product) {
            ProductShowcaseItem::create([
                'showcase_id' => $showcase3->id,
                'product_id' => $product->id,
                'sort_order' => $index,
            ]);
        }
    }
}
