<?php

namespace App\Filament\Resources\AlbumResource\Pages;

use App\Filament\Resources\AlbumResource;
use App\Models\Album;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Database\Eloquent\Model;

class EditAlbum extends EditRecord
{
    protected static string $resource = AlbumResource::class;

    protected function getRedirectUrl(): string
    {
        return $this->getResource()::getUrl('index');
    }
    protected function getHeaderActions(): array
    {
        return [
            // Actions\DeleteAction::make(),
        ];
    }
    protected function mutateFormDataBeforeFill(array $data): array
    {
        if($data["upload_type"] == 1){
            $data['link_video'] = $data["link"];
        }elseif($data["upload_type"] == 2){
            $data['link_upload'] = $data["link"];
        }
        return $data;
    }
    protected function handleRecordUpdate(Model $record, array $data): Model
    {
        if($data["upload_type"] == 1){
            $data['link'] = $data["link_video"];
        }elseif($data["upload_type"] == 2){
            $data['link'] = $data["link_upload"];
        }
        $record->update($data);
        return $record;
    }
}
