<?php

/**
 * @package         Tassos Code Snippets
 * @version         1.0.1-RC2 Free
 *
 * @author          Tassos Marinos <info@tassos.gr>
 * @link            https://www.tassos.gr
 * @copyright       Copyright © 2026 Tassos Marinos All Rights Reserved
 * @license         GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
 */

namespace Tassos\CodeSnippets\Administrator\Extension;

defined('_JEXEC') or die;

use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Categories\CategoryServiceInterface;
use Joomla\CMS\Categories\CategoryServiceTrait;
use Joomla\CMS\Extension\BootableExtensionInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
use Joomla\CMS\Tag\TagServiceInterface;
use Joomla\CMS\Tag\TagServiceTrait;
use Psr\Container\ContainerInterface;

/**
 * Component class for Tassos Code Snippets
 */
class TassosCodeSnippetsComponent extends MVCComponent implements
    BootableExtensionInterface,
    CategoryServiceInterface,
    TagServiceInterface
{
    use CategoryServiceTrait {
        CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait;
        CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait;
    }
    use HTMLRegistryAwareTrait;
    use TagServiceTrait;

    /**
     * Booting the extension. This is the function to set up the environment of the extension like
     * registering new class loaders, etc.
     *
     * @param   ContainerInterface  $container  The container
     *
     * @return  void
     */
    public function boot(ContainerInterface $container): void
    {
        // Load the Tassos Framework
        if (!@include_once(JPATH_PLUGINS . '/system/nrframework/autoload.php'))
        {
            return;
        }

        // Load component language
        \Tassos\Framework\Functions::loadLanguage('com_tassoscodesnippets');
    }

    /**
     * Returns the table name for the category
     *
     * @param   string|null  $section  The section
     *
     * @return  string
     */
    protected function getTableNameForSection(?string $section = null): string
    {
        return 'tassos_codesnippets';
    }

    /**
     * Returns the state column for the category
     *
     * @param   string|null  $section  The section
     *
     * @return  string
     */
    protected function getStateColumnForSection(?string $section = null): string
    {
        return 'state';
    }

    /**
     * Returns the context for the content
     *
     * @param   string|null  $context  The optional context
     *
     * @return  array
     */
    public function getContexts(): array
    {
        return [
            'com_tassoscodesnippets.snippet' => 'COM_TASSOSCODESNIPPETS_SNIPPET'
        ];
    }
}
