<?php
/**
 * Human-readable labels for activity log contexts and messages.
 *
 * @package SuiteMkt3k
 */

namespace SuiteMkt3k\Utils;

defined( 'ABSPATH' ) || exit;

final class Activity_Labels {

	public static function context( string $context ): string {
		$map = array(
			'coupon'        => __( 'Coupons', 'suitemkt3k' ),
			'coupons'       => __( 'Coupons', 'suitemkt3k' ),
			'newsletter'    => __( 'Newsletter', 'suitemkt3k' ),
			'cart_recovery' => __( 'Cart recovery', 'suitemkt3k' ),
			'cart'          => __( 'Cart recovery', 'suitemkt3k' ),
			'subscriber'    => __( 'Subscribers', 'suitemkt3k' ),
			'subscribers'   => __( 'Subscribers', 'suitemkt3k' ),
			'settings'      => __( 'Settings', 'suitemkt3k' ),
			'security'      => __( 'Security', 'suitemkt3k' ),
			'smtp'          => __( 'SMTP', 'suitemkt3k' ),
			'form'          => __( 'Form', 'suitemkt3k' ),
			'backup'        => __( 'Backup', 'suitemkt3k' ),
			'unsubscribe'   => __( 'Unsubscribe', 'suitemkt3k' ),
			'mailer'        => __( 'Email', 'suitemkt3k' ),
			'mail'          => __( 'Email', 'suitemkt3k' ),
		);

		return $map[ $context ] ?? ucfirst( str_replace( '_', ' ', $context ) );
	}

	public static function message( string $message ): string {
		$map = array(
			'Subscriber unsubscribed via email link'   => __( 'Subscriber unsubscribed via email link', 'suitemkt3k' ),
			'Test email sent'                          => __( 'Test email sent', 'suitemkt3k' ),
			'Recovery email sent'                      => __( 'Recovery email sent', 'suitemkt3k' ),
			'New subscriber via form'                  => __( 'New subscriber via form', 'suitemkt3k' ),
			'New subscriber via coupon opt-in'         => __( 'New subscriber via coupon opt-in', 'suitemkt3k' ),
			'Coupon campaign created'                  => __( 'Coupon campaign created', 'suitemkt3k' ),
			'Coupon campaign updated'                  => __( 'Coupon campaign updated', 'suitemkt3k' ),
			'Coupon impression'                        => __( 'Coupon impression', 'suitemkt3k' ),
			'Coupon click'                             => __( 'Coupon click', 'suitemkt3k' ),
			'Newsletter sent'                          => __( 'Newsletter sent', 'suitemkt3k' ),
			'Newsletter queued'                        => __( 'Newsletter queued', 'suitemkt3k' ),
			'Newsletter saved'                         => __( 'Newsletter saved', 'suitemkt3k' ),
			'Abandoned carts table truncated by admin' => __( 'Abandoned carts cleared by admin', 'suitemkt3k' ),
			'Settings updated'                         => __( 'Settings updated', 'suitemkt3k' ),
			'SMTP test email sent'                     => __( 'SMTP test email sent', 'suitemkt3k' ),
			'SMTP test email failed'                   => __( 'SMTP test email failed', 'suitemkt3k' ),
			'Backup stored'                            => __( 'Backup stored', 'suitemkt3k' ),
			'Backup restored'                          => __( 'Backup restored', 'suitemkt3k' ),
			'ok'                                       => __( 'Unsubscribe completed', 'suitemkt3k' ),
			'invalid_or_already'                       => __( 'Unsubscribe request processed', 'suitemkt3k' ),
			'Unsubscribed via token'                   => __( 'Subscriber unsubscribed via email link', 'suitemkt3k' ),
		);

		if ( isset( $map[ $message ] ) ) {
			return $map[ $message ];
		}

		if ( str_starts_with( $message, 'Tab saved: ' ) ) {
			$tab  = substr( $message, 11 );
			$tabs = array(
				'company'    => __( 'My company', 'suitemkt3k' ),
				'coupons'    => __( 'Coupons', 'suitemkt3k' ),
				'newsletter' => __( 'Newsletter', 'suitemkt3k' ),
				'cart'       => __( 'Cart recovery', 'suitemkt3k' ),
				'smtp'       => __( 'Email SMTP', 'suitemkt3k' ),
				'backup'     => __( 'Backup', 'suitemkt3k' ),
				'advanced'   => __( 'Advanced', 'suitemkt3k' ),
			);
			$label = $tabs[ $tab ] ?? $tab;
			return sprintf(
				/* translators: %s settings tab name */
				__( 'Settings tab saved: %s', 'suitemkt3k' ),
				$label
			);
		}

		return $message;
	}
}
