<?php /*

 Composr
 Copyright (c) Christopher Graham, 2004-2024

 See docs/LICENSE.md for full licensing information.


 NOTE TO PROGRAMMERS:
   Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
   **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****

*/

/**
 * @license    http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright  Christopher Graham
 * @package    core_configuration
 */

/**
 * Hook class.
 */
class Hook_config_site_closed
{
    /**
     * Gets the details relating to the config option.
     *
     * @return ?array The details (null: disabled)
     */
    public function get_details() : ?array
    {
        return [
            'human_name' => 'CLOSED_SITE_OPTION',
            'type' => 'special',
            'category' => 'SITE',
            'group' => 'CLOSED_SITE',
            'explanation' => 'CONFIG_OPTION_site_closed',
            'shared_hosting_restricted' => '0',
            'list_options' => '',
            'order_in_category_group' => 1,
            'required' => true,
            'public' => false,
            'addon' => 'core_configuration',
        ];
    }

    /**
     * Gets the default value for the config option.
     *
     * @return ?string The default value (null: option is disabled)
     */
    public function get_default() : ?string
    {
        return $GLOBALS['DEV_MODE'] ? '0' : '1';
    }

    /**
     * Field inputter (because the_type=special).
     *
     * @param  ID_TEXT $name The config option name
     * @param  array $myrow The config row
     * @param  ID_TEXT $config_field_name The form field name to use for this config
     * @param  Tempcode $human_name The field title
     * @param  Tempcode $explanation The field description
     * @return Tempcode The inputter
     */
    public function field_inputter(string $name, array $myrow, string $config_field_name, object $human_name, object $explanation) : object
    {
        $list = '';
        $list .= static_evaluate_tempcode(form_input_radio_entry($config_field_name, '0', '0' == get_option($name), do_lang('OPEN')));
        $list .= static_evaluate_tempcode(form_input_radio_entry($config_field_name, '1', '1' == get_option($name), do_lang('CLOSED')));
        $list .= static_evaluate_tempcode(form_input_radio_entry($config_field_name, '2', '2' == get_option($name), do_lang('CLOSED_HIDE_HERO')));
        return form_input_radio($human_name, $explanation, $config_field_name, make_string_tempcode($list), true);
    }
}
