<?php

namespace App\Filament\Exports;

use App\Models\StickerDetail;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;

class StickerDetailExporter extends Exporter
{
    protected static ?string $model = StickerDetail::class;

    public static function getColumns(): array
    {
        static $rowNumber = 0;
        return [
            ExportColumn::make('no')
                ->label('NO')
                ->state(function ($record) use (&$rowNumber) {
                    // Increment and return the row number
                    return ++$rowNumber;
                }),
            ExportColumn::make('stickerStructureDetail.sticker_id')
            ->label('STICKER ID'),
            ExportColumn::make('design_element_type')
            ->label('DESIGN ELEMENT TYPE'),
            ExportColumn::make('element_id')
            ->label('ELEMENT ID'),
            ExportColumn::make('element_type')
            ->label('ELEMENT TYPE'),
            ExportColumn::make('characteristics_type')
            ->label('CHARACTERISTICS TYPE'),
            ExportColumn::make('string_value')
            ->label('STRING VALUE'),
            ExportColumn::make('string_font')
            ->label('STRING FONT'),
            ExportColumn::make('string_size')
            ->label('STRING SIZE'),
            ExportColumn::make('element_colour')
            ->label('ELEMENT COLOUR'),
            ExportColumn::make('string_align')
            ->label('STRING ALIGN'),
            ExportColumn::make('string_x_value')
            ->label('STRING X VALUE'),
            ExportColumn::make('string_y_value')
            ->label('STRING Y VALUE'),
            ExportColumn::make('shape_name')
            ->label('SHAPE NAME'),
            ExportColumn::make('shape_pen_size')
            ->label('SHAPE PEN SIZE'),
            ExportColumn::make('curve_radius')
            ->label('CURVE RADIUS'),
            ExportColumn::make('shape_x1_value')
            ->label('SHAPE X1 VALUE'),
            ExportColumn::make('shape_y1_value')
            ->label('SHAPE Y1 VALUE'),
            ExportColumn::make('shape_x2_value')
            ->label('SHAPE X2 VALUE'),
            ExportColumn::make('shape_y2_value')
            ->label('SHAPE Y2 VALUE'),
            ExportColumn::make('image_x')
            ->label('IMAGE X'),
            ExportColumn::make('image_y')
            ->label('IMAGE Y'),
            ExportColumn::make('image_width')
            ->label('IMAGE WIDTH'),
            ExportColumn::make('image_height')
            ->label('IMAGE HEIGHT'),
            ExportColumn::make('qr_value')
            ->label('QR VALUE'),
            ExportColumn::make('qr_align')
            ->label('QR ALIGN'),
            ExportColumn::make('qr_size')
            ->label('QR SIZE'),
            ExportColumn::make('qr_x_value')
            ->label('QR X VALUE'),
            ExportColumn::make('qr_y_value')
            ->label('QR Y VALUE'),
            ExportColumn::make('created_at')
            ->label('CREATED AT'),
            ExportColumn::make('updated_at')
            ->label('UPDATED AT'),
            ExportColumn::make('created_by')
            ->label('CREATED BY'),
            ExportColumn::make('deleted_at')
            ->label('DELETED AT')
            ->enabledByDefault(false),
        ];
    }

    public static function getCompletedNotificationBody(Export $export): string
    {
        $body = 'Your sticker detail export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';

        if ($failedRowsCount = $export->getFailedRowsCount()) {
            $body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
        }

        return $body;
    }
}
