<?php
namespace ZenCommunity\Addons\LifterLms\Feeds;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class CourseCompletedFeed extends Abstracts\EventFeed {
	public function init(): void {
		add_action(
			'lifterlms_course_completed',
			[ $this, 'notify' ],
			10, 2
		);

	}
	public function notify( int $user_id, int $course_id ) : void {
		if ( empty( $user_id ) ) {
			return;
		}
		$course_permalink = get_permalink( $course_id );
		$course_title = get_the_title( $course_id );
		$user = get_userdata( $user_id );
		$this->course_id = $course_id;
		$this->title     = sprintf(
			/* translators:  %s is the username, %s is the course name */
			__( '%1$s has just completed @ %2$s!', 'zencommunity' ),
			esc_html( $user ? $user->display_name : '' ),
			esc_html( $course_title )
		);
		$this->message   = sprintf(
			/* translators:  %s is the username, %s is the course name */
			__( '🎉 Congratulations on completing %1$s, %2$s! Your dedication and hard work truly paid off. We’re proud of your achievement—well done! 🚀', 'zencommunity' ),
			esc_html( $course_title ),
			esc_html( $user ? $user->display_name : '' )
		);
		$this->event     = 'course_complete';
		$this->push();
	}
}
