<?php

namespace RtmMail\AjaxAction;

use RtmMail\Actions\Handlers\EditLogAction;

class EditLogAjaxAction
{
    public function handleAction(): void
    {
        $logId = isset($_POST['log_id']) ? intval($_POST['log_id']) : null;
        $subject = $_POST['subject'] ?? '';
        $senderOptions = [
            'title' => $_POST['sender_options']['title'] ?? '',
            'address' => $_POST['sender_options']['address'] ?? ''
        ];
        $receiver = $_POST['receiver'] ?? '';
        $cc = $_POST['cc'] ?? '';
        $bcc = $_POST['bcc'] ?? '';
        $body = $_POST['body'] ?? '';

        // Initialize and call the EditLogAction
        $editAction = new EditLogAction();
        $result = $editAction->handleAction($logId, $subject, $senderOptions, $receiver, $cc, $bcc, $body);

        wp_send_json($result);
    }
}
