<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

add_filter(
	'body_class',
	function ( $classes ) {
		if ( is_admin() || wp_doing_ajax() || ! is_singular() ) {
			return $classes;
		}

		$post = get_queried_object();
		if ( ! $post || empty( $post->ID ) ) {
			return $classes;
		}

		$lang = (string) get_post_meta( (int) $post->ID, '_reeid_translation_lang', true );
		if ( '' === $lang ) {
			return $classes;
		}

		$classes[] = 'reeid-blocksy-translated-page';

		return $classes;
	},
	20
);

add_action(
	'wp_enqueue_scripts',
	function () {
		if ( is_admin() || wp_doing_ajax() || ! is_singular() ) {
			return;
		}

		$post = get_queried_object();
		if ( ! $post || empty( $post->ID ) ) {
			return;
		}

		$lang = (string) get_post_meta( (int) $post->ID, '_reeid_translation_lang', true );
		if ( '' === $lang ) {
			return;
		}

		wp_enqueue_style(
			'reeid-theme-blocksy-fixes',
			plugins_url( 'theme.css', __FILE__ ),
			array(),
			filemtime( __DIR__ . '/theme.css' )
		);
	},
	20
);