*/ public static function make(): ColumnSet { return ColumnSet::for(Product::class) ->add('id', 'ID', static fn (Product $product): int => $product->id) ->notImportable() ->add('category', 'Category', static fn (Product $product): mixed => TreeOptions::label(['table' => 'categories', 'display' => 'name', 'tree' => ['parent' => 'parent_id', 'level' => 'level', 'leaf' => 'category', 'name' => 'name']], $product->category_id)) ->importTo( 'category_id', static fn (string $name): mixed => TreeOptions::idFor(['table' => 'categories', 'display' => 'name', 'tree' => ['parent' => 'parent_id', 'level' => 'level', 'leaf' => 'category', 'name' => 'name']], $name), ) ->add('name', 'Name', static fn (Product $product): mixed => $product->name) ->add('slug', 'Slug', static fn (Product $product): mixed => $product->slug) ->add('sku', 'SKU', static fn (Product $product): mixed => $product->sku) ->add('status', 'Status', static fn (Product $product): string => $product->status->value) ->add('price', 'Price', static fn (Product $product): mixed => $product->price) ->add('compare_at_price', 'Compare-at price', static fn (Product $product): mixed => $product->compare_at_price) ->add('cost_price', 'Cost Price', static fn (Product $product): mixed => $product->cost_price) ->add('photos', 'Photos', static fn (Product $product): mixed => $product->photos) ->hiddenFromTable() ->hiddenFromExport() ->notImportable() ->add('video_url', 'Video', static fn (Product $product): mixed => $product->video_url) ->add('description', 'Description', static fn (Product $product): mixed => trim(strip_tags((string) ($product->description ?? '')))) ->hiddenFromTable() ->add('size_chart', 'Size chart', static fn (Product $product): mixed => $product->size_chart) ->hiddenFromTable() ->notImportable() ->add('is_featured', 'Is Featured', static fn (Product $product): bool => $product->is_featured) ->exportAs(static fn (Product $product): string => $product->is_featured ? 'Yes' : 'No') ->importTo( 'is_featured', static fn (string $cell): bool => in_array(mb_strtolower($cell), ['yes', 'y', 'ya', 'true', '1'], true), ) ->add('published_at', 'Published', static fn (Product $product): mixed => $product->published_at) ->exportAs(static fn (Product $product): ?string => $product->published_at?->toDateTimeString()) ->add('publishedByRef', 'Published by', static fn (Product $product): mixed => $product->publishedByRef?->name) ->importTo( 'published_by', static fn (string $name): mixed => ImportLookup::key(User::class, 'name', $name), ) ->add('specs', 'Specifications', static fn (Product $product): mixed => JsonDocument::text($product->specs)) ->hiddenFromTable() ->importTo( 'specs', static fn (string $cell): mixed => json_decode($cell, true) ?? $cell, ) ->add('created_at', 'Created At', static fn (Product $product): mixed => $product->created_at) ->notImportable() ->exportAs(static fn (Product $product): ?string => $product->created_at?->toDateTimeString()); } }