<?php

namespace GriffinForms\Admin\Js\Local;

final class AntiSpam extends \GriffinForms\Admin\Js\Local\Settings
{
    protected function getOptionsDataJs()
    {
        $js = '
        function getOptionsData() {
            getHoneypotOption();
            getActiveCaptchaProviderOption();
            getRateLimitStorageOption();
        }
        ';

        $js .= $this->getHoneypotOptionJs();
        $js .= $this->getRecaptchaOptionJs();
        $js .= $this->getActiveCaptchaProviderOptionJs();
        $js .= $this->getRateLimitStorageOptionJs();

        return $js;
    }

    protected function getHoneypotOptionJs()
    {
        return '
        function getHoneypotOption() {
            optionsData["enable_honeypot"] = $("#griffinforms-settings-antispam-enablehoneypot").prop("checked");
        }
        ';
    }

    protected function getRecaptchaOptionJs()
    {
        return '
        function getRecaptchaOption() {}
        ';
    }

    protected function getRateLimitStorageOptionJs()
    {
        return '
        function getRateLimitStorageOption() {
            optionsData["rate_limit_storage"] = $.trim($("#griffinforms-settings-antispam-ratelimitstorage").val());
        }
        ';
    }

    protected function getActiveCaptchaProviderOptionJs()
    {
        return '
        function getActiveCaptchaProviderOption() {
            optionsData["active_captcha_provider"] = $.trim($("#griffinforms-settings-antispam-activecaptchaprovider").val());
        }
        ';
    }
}
