<?php
if (!defined('ABSPATH')) exit;
$openai_api_key = base64_decode(get_option('rgfb_openai_api_key'));
$stability_key = base64_decode(get_option('rgfb_stability_key'));
$fal_key = base64_decode(get_option('rgfb_fal_key'));
$leonardo_key = base64_decode(get_option('rgfb_leonardo_key'));
$claude_key = base64_decode(get_option('rgfb_claude_key'));
$openai_model = get_option('rgfb_openai_model');
$rgfb_claude_model = get_option('rgfb_claude_model');
$image_generation_model = get_option('rgfb_image_generation_model');
$limit_image_requests_by_ip = get_option('rgfb_limit_image_requests_by_ip');
$image_generation_strength = get_option('rgfb_image_generation_strength');
$rgfb_video_resolution = get_option('rgfb_video_resolution');
?>
<div class="wrap" id="rgfb_from_builder_wrap">
    <form id="rgfb_settings">
        <?php esc_html(wp_nonce_field('save-settings-nonce', 'save_settings_nonce')); ?>
        <div class="row">
            <div class="col-md-12">
                <h2>Settings</h2>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="alert alert-secondary">
                    <p>Welcome to the API settings section of AIenabler! To activate the full functionality of the plugin, please enter the appropriate API keys from the various AI platforms listed below. You can easily find each platform's API key by following the links provided.</p>
                    <ul class="list-group">
                        <li class="list-group-item">OpenAI API Key: Enter your OpenAI API key <a href="https://platform.openai.com/api-keys" target="_blank">here</a>. Get your API key</li>
                        <li class="list-group-item">Stability Key: Enter your Stability AI key <a href="https://beta.dreamstudio.ai/account" target="_blank">here</a>. Get your API key</li>
                        <li class="list-group-item">FAL Key: Enter your FAL AI key <a href="https://fal.ai/dashboard/keys" target="_blank">here</a>. Get your API key</li>
                        <li class="list-group-item">Leonardo KEY: Enter your Leonardo AI key <a href="https://docs.leonardo.ai/docs/create-your-api-key" target="_blank">here</a>. Get your API key</li>
                    </ul>
                    
                    <p>You can also select your preferred Text Generation Model for the plugin, such as GPT-3.5-turbo, to tailor the responses generated by AI to your needs.</p>

                    <p>For image generation, adjust the Image Generation Strength. This controls how much freedom the generator has in creating the image. The higher the number, the more creative freedom it has in interpreting the base image.</p>

                    <p>Make sure to set the correct model and any additional parameters as per your needs. Once you've filled in the fields, AIenabler will be able to utilize the connected AI models for enhanced creative features across your WordPress site.</p>
                </div>
            </div>
        </div>
        <!-- <div class="row mb-3">
            <div class="col-md-12">
                <label for="rgfb_model">Text Generation Model: </label>
                <select name="rgfb_model" id="rgfb_model" class="form-control form-select">
                    <option value="openai">OpenAI</option>
                    <option value="claude">Claude</option>
                </select>
            </div>
        </div> -->

        <div class="row mb-3">
            <div class="col-md-6 col-sm-12">
                <label for="rgfb_openai_model">Text Generation Model: </label>
                <div class="text-generation-model">
                    <select name="rgfb_openai_model" id="rgfb_openai_model" class="form-control form-select">
                        <option value="" selected>Select Text Generation Model</option>
                        <option value="gpt-4o" <?php echo $openai_model == 'gpt-4o' ? 'selected' : '' ?>>gpt-4o</option>
                        <option value="gpt-4o-mini" <?php echo $openai_model == 'gpt-4o-mini' ? 'selected' : '' ?>>gpt-4o-mini</option>
                        <option value="gpt-4-1106-preview" <?php echo $openai_model == 'gpt-4-1106-preview' ? 'selected' : '' ?>>gpt-4-1106-preview</option>
                        <option value="gpt-4" <?php echo $openai_model == 'gpt-4' ? 'selected' : '' ?>>gpt-4</option>
                        <option value="gpt-4.1-mini" <?php echo $openai_model == 'gpt-4.1-mini' ? 'selected' : '' ?>>gpt-4.1-mini</option> 
                        <option value="gpt-4-32k" <?php echo $openai_model == 'gpt-4-32k' ? 'selected' : '' ?>>gpt-4-32k</option>
                        <option value="gpt-3.5-turbo-1106" <?php echo $openai_model == 'gpt-3.5-turbo-1106' ? 'selected' : '' ?>>gpt-3.5-turbo-1106</option>
                        <option value="gpt-3.5-turbo" <?php echo $openai_model == 'gpt-3.5-turbo' ? 'selected' : '' ?>>gpt-3.5-turbo</option>
                        <option value="gpt-3.5-turbo-16k" <?php echo $openai_model == 'gpt-3.5-turbo-16k' ? 'selected' : '' ?>>gpt-3.5-turbo-16k</option>
                        <option value="text-davinci-003" <?php echo $openai_model == 'text-davinci-003' ? 'selected' : '' ?>>text-davinci-003</option>
                        <option value="text-davinci-002" <?php echo $openai_model == 'text-davinci-002' ? 'selected' : '' ?>>text-davinci-002</option>
                        <option value="text-curie-001" <?php echo $openai_model == 'text-curie-001' ? 'selected' : '' ?>>text-curie-001</option>
                        <option value="text-babbage-001" <?php echo $openai_model == 'text-babbage-001' ? 'selected' : '' ?>>text-babbage-001</option>
                        <option value="text-ada-001" <?php echo $openai_model == 'text-ada-001' ? 'selected' : '' ?>>text-ada-001</option>
                        <option value="davinci" <?php echo $openai_model == 'davinci' ? 'selected' : '' ?>>davinci</option>
                        <option value="curie" <?php echo $openai_model == 'curie' ? 'selected' : '' ?>>curie</option>
                        <option value="babbage" <?php echo $openai_model == 'babbage' ? 'selected' : '' ?>>babbage</option>
                        <option value="ada" <?php echo $openai_model == 'ada' ? 'selected' : '' ?>>ada</option>
                        <optgroup label="Claude">
                            <option value="claude-3-opus-20240229" <?php echo $openai_model == 'claude-3-opus-20240229' ? 'selected' : '' ?>>claude-3-opus</option>
                            <!--<option value="sonnet-3.5" <?php echo $openai_model == 'sonnet-3.5' ? 'selected' : '' ?>>sonnet-3.5</option>
                            <option value="haiku-3.5" <?php echo $openai_model == 'haiku-3.5' ? 'selected' : '' ?>>haiku-3.5</option>-->
                            <option value="claude-3-5-haiku-20241022" <?php echo $openai_model == 'claude-3-5-haiku-20241022' ? 'selected' : '' ?>>claude-3-5-haiku</option>
                            <option value="claude-3-5-sonnet-20241022" <?php echo $openai_model == 'claude-3-5-sonnet-20241022' ? 'selected' : '' ?>>claude-3-5-sonnet</option>
                            <option value="claude-3-7-sonnet-20250219" <?php echo $openai_model == 'claude-3-7-sonnet-20250219' ? 'selected' : '' ?>>claude-3-7-sonnet</option>
                            <option value="claude-sonnet-4-20250514" <?php echo $openai_model == 'claude-sonnet-4-20250514' ? 'selected' : '' ?>>claude-sonnet-4</option>
                            <option value="claude-opus-4-20250514" <?php echo $openai_model == 'claude-opus-4-20250514' ? 'selected' : '' ?>>claude-opus-4</option>
                        </optgroup>
                    </select>
                </div>
            </div>
            <div class="col-md-6 col-sm-12">
                <label for="rgfb_openai_model">Image Generation Model: </label>
                <select name="rgfb_image_generation_model" id="rgfb_image_generation_model" class="form-control form-select">
                    <option value="" selected>Select Image Generation Model</option>
                    <option value="dalle3" <?php echo $image_generation_model == 'dalle3' ? 'selected' : '' ?>>Dall-E 3</option>
                    <option value="stabilityai" <?php echo $image_generation_model == 'stabilityai' ? 'selected' : '' ?>>Stability AI</option>
                    <option value="fal" <?php echo $image_generation_model == 'fal' ? 'selected' : '' ?>>FAL</option>
                    <option value="leonardo" <?php echo $image_generation_model == 'leonardo' ? 'selected' : '' ?>>Leonardo</option>
                </select>
            </div>
        <div><br>

        <div class="row mb-3">
            <div class="col-md-6 col-sm-12">
                <label for="rgfb_video_resolution">Video Resolution: </label>
                <select name="rgfb_video_resolution" id="rgfb_video_resolution" class="form-control form-select">
                    <option value="" selected>Select Video Resolution</option>
                    <option value="RESOLUTION_480" <?php echo $rgfb_video_resolution == 'RESOLUTION_480' ? 'selected' : '' ?>>480p</option>
                    <option value="RESOLUTION_720" <?php echo $rgfb_video_resolution == 'RESOLUTION_720' ? 'selected' : '' ?>>720p</option>
                </select>
            </div>
        <div><br>
        
        <div class="api-key-section mb-3">
            <div class="row mb-3">
                <div class="col-md-6 col-sm-12">
                    <label for="rgfb_openai_api_key">OpenAI API KEY: </label>
                    <div class="input-group input-group-sm" id="show_hide_open_api_key" class="show_hide_password">
                        <input type="password" name="rgfb_openai_api_key" id="rgfb_openai_api_key" placeholder="Enter OpenAI API Key" class="form-control" value="<?php echo esc_attr(!empty($openai_api_key) ? $openai_api_key : '') ?>">
                        <!-- <div class="input-group-text">
                        <a href="javascript:void(0)" class="text-visibility"><i class="fa fa-eye-slash" aria-hidden="true"></i></a>
                        </div> -->
                    </div>
                    <small>API Key location: <a target="__blank" href="https://platform.openai.com/api-keys">Click here</a></small>
                </div>
                <div class="col-md-6 col-sm-12">
                    <label for="rgfb_openai_api_key">Stability KEY: </label>
                    <div class="input-group input-group-sm" id="show_hide_stability_key" class="show_hide_password">
                        <input type="password" name="rgfb_stability_key" id="rgfb_stability_key" placeholder="Enter Stability Key" class="form-control" value="<?php echo esc_attr(!empty($stability_key) ? $stability_key : '') ?>">
                        <!-- <div class="input-group-text">
                        <a href="javascript:void(0)" class="text-visibility"><i class="fa fa-eye-slash" aria-hidden="true"></i></a>
                        </div> -->
                    </div>
                    <small>API Key location: <a target="__blank" href="https://beta.dreamstudio.ai/account">Click here</a></small>
                </div>
                
            </div>
            <div class="row mb-3">
                <div class="col-md-6 col-sm-12">
                    <label for="rgfb_openai_api_key">FAL KEY: </label>
                    <div class="input-group input-group-sm" id="show_hide_fal_key" class="show_hide_password">
                        <input type="password" name="rgfb_fal_key" id="rgfb_fal_key" placeholder="Enter FAL Key" class="form-control" value="<?php echo esc_attr(!empty($fal_key) ? $fal_key : '') ?>">
                        <!-- <div class="input-group-text">
                        <a href="javascript:void(0)" class="text-visibility"><i class="fa fa-eye-slash" aria-hidden="true"></i></a>
                        </div> -->
                    </div>
                    <small>API Key location: <a target="__blank" href="https://fal.ai/dashboard/keys">Click here</a></small>
                </div>
                <div class="col-md-6 col-sm-12">
                    <label for="rgfb_openai_api_key">Leonardo KEY: </label>
                    <div class="input-group input-group-sm" id="show_hide_leonardo_key" class="show_hide_password">
                        <input type="password" name="rgfb_leonardo_key" id="rgfb_leonardo_key" placeholder="Enter Leonardo Key" class="form-control" value="<?php echo esc_attr(!empty($leonardo_key) ? $leonardo_key : '') ?>">
                        <!-- <div class="input-group-text">
                        <a href="javascript:void(0)" class="text-visibility"><i class="fa fa-eye-slash" aria-hidden="true"></i></a>
                        </div> -->
                    </div>
                    <small>API Key location: <a target="__blank" href="https://docs.leonardo.ai/docs/create-your-api-key">Click Here</a></small>
                </div>

            </div>
            <div class="row mb-3">
                <div class="col-md-12 col-sm-12">
                    <label for="rgfb_openai_api_key">Claude KEY: </label>
                    <div class="input-group input-group-sm" id="show_hide_claude_key" class="show_hide_password">
                        <input type="password" name="rgfb_claude_key" id="rgfb_claude_key" placeholder="Enter Claude Key" class="form-control" value="<?php echo esc_attr(!empty($claude_key) ? $claude_key : '') ?>">
                        <!-- <div class="input-group-text">
                        <a href="javascript:void(0)" class="text-visibility"><i class="fa fa-eye-slash" aria-hidden="true"></i></a>
                        </div> -->
                    </div>
                    <small>API Key location: <a target="__blank" href="https://www.anthropic.com/api">Click here</a></small>
                </div>
            </div>
        </div>
        
        

        <div class="row mb-3 mt-3">
            <div class="col-md-12"><label for="rgfb_openai_model">Image Generation Strength: </label></div>
            <div class="col-md-6 col-sm-12">
                <label for="rgfb_openai_model"><small>Set the Image Strength from 0 to 1. Default 0.35</small></label>
                <input type="number" class="form-control" id="rgfb_image_generation_strength" name="rgfb_image_generation_strength" min="0" max="1" value="<?php echo esc_attr(!empty($image_generation_strength) ? $image_generation_strength : 0.35); ?>">
            </div>
            <div class="col-md-6 col-sm-12">
                <label for="rgfb_limit_image_requests_by_ip"><small>Limit Image Requests by IP:</small> </label>
                <input type="text" name="rgfb_limit_image_requests_by_ip" id="rgfb_limit_image_requests_by_ip" placeholder="How many image requests for free users" class="form-control" value="<?php echo esc_attr(!empty($limit_image_requests_by_ip) ? $limit_image_requests_by_ip : '') ?>">
            </div>
            <input type="hidden" class="form-control" id="rgfb_image_generation_strength" name="rgfb_image_generation_strength" min="0" max="1" value="0.7">
            <input type="hidden" name="rgfb_limit_image_requests_by_ip" id="rgfb_limit_image_requests_by_ip" placeholder="How many image requests for free users" class="form-control" value="10">
            <div class="col-md-12">
                <div class="select_form_style_section">
                    <div class="new-action-buttons mt-4">
                        <button id="save-settings" class="save_btn">Save</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>