<?php

declare(strict_types=1);

/**
 * 本文件属于 DBErp 进销存系统。
 *
 * 版权所有 © 2026 北京珑大钜商科技有限公司。保留所有权利。
 *
 * 未经官方授权，不得删除、篡改或隐藏本文件中的版权声明、产品标识与来源信息。
 * 商业授权、官方更新与技术支持服务，请以珑大官方支持中心记录为准。
 *
 * @link https://support.loongdom.cn
 * @see  https://www.dberp.com.cn
 */

namespace App\Filament\Resources\DberpInventoryBatches\RelationManagers;

use App\Filament\Resources\DberpInventorySerialNumbers\DberpInventorySerialNumberResource;
use App\Models\DberpInventorySerialNumber;
use Filament\Actions\ViewAction;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\ToggleColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class InventoryBatchSerialNumbersRelationManager extends RelationManager
{
    protected static string $relationship = 'serialNumbers';

    public static function getTitle(Model $ownerRecord, string $pageClass): string
    {
        return __('dberp.relations.inventory_batch_serial_numbers');
    }

    protected static function getModelLabel(): ?string
    {
        return __('dberp.resources.inventory_serial_number.label');
    }

    protected static function getPluralModelLabel(): ?string
    {
        return __('dberp.resources.inventory_serial_number.plural');
    }

    public function form(Schema $schema): Schema
    {
        return $schema;
    }

    public function table(Table $table): Table
    {
        return $table
            ->defaultSort('serial_no')
            ->columns([
                TextColumn::make('serial_no')->label(__('dberp.fields.serial_no'))->searchable(),
                TextColumn::make('status')->label(__('dberp.fields.serial_number_status'))->badge(),
                TextColumn::make('warehouse.name')->label(__('dberp.fields.warehouse')),
                ToggleColumn::make('is_enabled')
                    ->label(__('dberp.fields.is_enabled')),
            ])
            ->recordActions([
                ViewAction::make()
                    ->visible(fn (DberpInventorySerialNumber $record): bool => DberpInventorySerialNumberResource::canView($record))
                    ->url(fn (DberpInventorySerialNumber $record): string => DberpInventorySerialNumberResource::getUrl('view', ['record' => $record])),
            ])
            ->paginated([10, 25, 50]);
    }
}
