<?php

namespace GriffinForms\Admin\Js\Local;

final class Ai extends \GriffinForms\Admin\Js\Local\Settings
{
    protected function getOptionsDataJs()
    {
        $js = '
        function getOptionsData() {
            getButlerActiveProviderOption();
            getButlerGenerationTimeoutOption();
            getAiDataSharingAcknowledgedOption();
        }
        ';

        $js .= $this->getButlerActiveProviderOptionJs();
        $js .= $this->getButlerGenerationTimeoutOptionJs();
        $js .= $this->getAiDataSharingAcknowledgedOptionJs();

        return $js;
    }

    protected function getButlerActiveProviderOptionJs()
    {
        return '
        function getButlerActiveProviderOption() {
            optionsData["butler_active_provider"] = $.trim($("#griffinforms-settings-ai-butleractiveprovider").val());
        }
        ';
    }

    protected function getButlerGenerationTimeoutOptionJs()
    {
        return '
        function getButlerGenerationTimeoutOption() {
            var timeout = $.trim($("#griffinforms-settings-ai-butlergenerationtimeout").val());
            optionsData["butler_generation_timeout"] = timeout === "" ? "20" : timeout;
        }
        ';
    }

    protected function getAiDataSharingAcknowledgedOptionJs()
    {
        return '
        function getAiDataSharingAcknowledgedOption() {
            optionsData["ai_data_sharing_acknowledged"] = $("#griffinforms-settings-ai-aidatasharingacknowledged").prop("checked");
        }
        ';
    }
}
