<?php
/**
 * @deprecated
 */
class ProfileWidget_CustomHtml extends Extension_ProfileWidget {
	const ID = 'cerb.profile.tab.widget.html';

	function __construct($manifest=null) {
		parent::__construct($manifest);
	}
	
	function invoke(string $action, Model_ProfileWidget $model) {
		$active_worker = CerberusApplication::getActiveWorker();
		
		if(!Context_ProfileWidget::isReadableByActor($model, $active_worker))
			DevblocksPlatform::dieWithHttpError(null, 403);
		
		return false;
	}
	
	function render(Model_ProfileWidget $model, $context, $context_id) {
		$template = $model->extension_params['template'] ?? null;
		
		$tpl_builder = DevblocksPlatform::services()->templateBuilder()->newInstance('html');
		$active_worker = CerberusApplication::getActiveWorker();
		
		if(empty($template))
			return;
		
		$dict = DevblocksDictionaryDelegate::instance([
			'current_worker__context' => CerberusContexts::CONTEXT_WORKER,
			'current_worker_id' => $active_worker->id,
			'current_worker_nonce' => DevblocksPlatform::getRequestNonce(),
			'record__context' => $context,
			'record_id' => $context_id,
			'widget__context' => CerberusContexts::CONTEXT_PROFILE_WIDGET,
			'widget_id' => $model->id,
		]);
		
		$html = $tpl_builder->build($template, $dict);
		
		echo $html;
	}
	
	function renderConfig(Model_ProfileWidget $model) {
		$tpl = DevblocksPlatform::services()->template();
		$tpl->assign('widget', $model);
		$tpl->display('devblocks:cerberusweb.core::internal/profiles/widgets/html/config.tpl');
	}
	
	function invokeConfig($action, Model_ProfileWidget $model) {
		return false;
	}
}