<?php
/**
 * General Settings Component.
 */

if ( ! function_exists( 'render_general_settings_component' ) ) {
    function render_general_settings_component() {
        $heading_text_option    = get_option( 'postology_heading_text', esc_html__( 'Get an AI-generated summary of this article.', 'postology' ) );
        $button_text_option     = get_option( 'postology_button_text', esc_html__( 'Generate Summary', 'postology' ) );
        
        $summary_heading_option = get_option( 'postology_summary_heading_text', esc_html__( 'AI-generated article summary', 'postology' ) );
        $summary_tone_option    = get_option( 'postology_summary_tone', 'informative' );
        $summary_lang_option    = get_option( 'postology_summary_language', 'default' );
       
        $bp_length_option       = get_option( 'postology_bullet_point_length', 'medium' );
        $powered       = get_option( 'postology_display_powered_by', 'no' );
        
        // styles
        $general_form_section = "display: grid; grid-template-columns: 30% 1fr; font-size: 18px;";
        $general_form_description = "margin: 0; font-size: 15px;";
        $general_form_input = "inline-size: min-content; grid-row-start: 1; grid-column-start: 2;";
        ?>
        <div class="postology-field-wrapper">
            <div class="custom-card" style="display:flex;flex-direction:column;gap:15px;">
                <h3 style="margin:0;margin-block-end: 12px;color:grey;">Heading Settings</h3>
                <section style="<?php echo esc_attr($general_form_section); ?>" class="general-form-section">
                    <strong style="align-self: center;"><?php echo esc_html__( 'Heading Text', 'postology' ); ?></strong>
                    <p style="<?php echo esc_attr($general_form_description); ?>" class="description general-form-description"><?php esc_html_e( 'Enter the main heading displayed on the page.', 'postology' ); ?></p>
                    <input type="text" name="postology_heading_text" style="<?php echo esc_attr($general_form_input); ?>" class="general-form-input" value="<?php echo esc_attr( $heading_text_option ); ?>" size="50" />
                </section>
                <section style="<?php echo esc_attr($general_form_section); ?>" class="general-form-section">
                    <strong style="align-self: center;"><?php echo esc_html__( 'Button Text', 'postology' ); ?></strong>
                    <p style="<?php echo esc_attr($general_form_description); ?>" class="description general-form-description"><?php esc_html_e( 'Enter the text to display on the generate summary button.', 'postology' ); ?></p>
                    <input type="text" name="postology_button_text" value="<?php echo esc_attr( $button_text_option ); ?>" size="50" style="<?php echo esc_attr($general_form_input); ?>" class="general-form-input" />
                </section>
            </div>
            <div class="custom-card" style="display:flex;flex-direction:column;">
                <h3 style="margin:0;margin-block-end: 12px;color:grey;">Summary Settings</h3>
                <section style="<?php echo esc_attr($general_form_section); ?>" class="general-form-section">
                    <strong style="align-self: center;"><?php echo esc_html__( 'Summary Heading Text', 'postology' ); ?></strong>
                    <p style="<?php echo esc_attr($general_form_description); ?>" class="description general-form-description"><?php esc_html_e( 'Enter the heading for the summary section.', 'postology' ); ?></p>
                    <input type="text" name="postology_summary_heading_text" value="<?php echo esc_attr( $summary_heading_option ); ?>" size="50" style="<?php echo esc_attr($general_form_input); ?>" class="general-form-input" />
                </section>
                <section style="<?php echo esc_attr($general_form_section); ?>" class="general-form-section">
                    <strong style="align-self: center;"><?php echo esc_html__( 'Summary Tone', 'postology' ); ?></strong>
                    <p style="<?php echo esc_attr($general_form_description); ?>" class="description general-form-description"><?php esc_html_e( 'Select the tone/style for the generated summary.', 'postology' ); ?></p>
                    <select name="postology_summary_tone" style="<?php echo esc_attr($general_form_input); ?>" class="general-form-input">
                        <option value="default" <?php selected( $summary_tone_option, 'default' ); ?>><?php esc_html_e( 'Default', 'postology' ); ?></option>
                        <option value="informative" <?php selected( $summary_tone_option, 'informative' ); ?>><?php esc_html_e( 'Informative', 'postology' ); ?></option>
                        <option value="formal" <?php selected( $summary_tone_option, 'formal' ); ?>><?php esc_html_e( 'Formal', 'postology' ); ?></option>
                        <option value="casual" <?php selected( $summary_tone_option, 'casual' ); ?>><?php esc_html_e( 'Casual', 'postology' ); ?></option>
                        <option value="humorous" <?php selected( $summary_tone_option, 'humorous' ); ?>><?php esc_html_e( 'Humorous', 'postology' ); ?></option>
                        <option value="conversational" <?php selected( $summary_tone_option, 'conversational' ); ?>><?php esc_html_e( 'Conversational', 'postology' ); ?></option>
                        <option value="persuasive" <?php selected( $summary_tone_option, 'persuasive' ); ?>><?php esc_html_e( 'Persuasive', 'postology' ); ?></option>
                        <option value="optimistic" <?php selected( $summary_tone_option, 'optimistic' ); ?>><?php esc_html_e( 'Optimistic', 'postology' ); ?></option>
                        <option value="engaging" <?php selected( $summary_tone_option, 'engaging' ); ?>><?php esc_html_e( 'Engaging', 'postology' ); ?></option>
                        <option value="inspirational" <?php selected( $summary_tone_option, 'inspirational' ); ?>><?php esc_html_e( 'Inspirational', 'postology' ); ?></option>
                        <option value="analytical" <?php selected( $summary_tone_option, 'analytical' ); ?>><?php esc_html_e( 'Analytical', 'postology' ); ?></option>
                    </select>
                </section>
                <section style="<?php echo esc_attr($general_form_section); ?>" class="general-form-section">
                    <strong style="align-self: center;"><?php echo esc_html__( 'Summary Language', 'postology' ); ?></strong>
                    <p style="<?php echo esc_attr($general_form_description); ?>" class="description general-form-description"><?php esc_html_e( 'Select the language for the generated summary.', 'postology' ); ?></p>
                    <select name="postology_summary_language" style="<?php echo esc_attr($general_form_input); ?>" class="general-form-input">
                        <option value="default" <?php selected( $summary_lang_option, 'default' ); ?>><?php esc_html_e( 'Default (Post Language)', 'postology' ); ?></option>
                        <option value="english" <?php selected( $summary_lang_option, 'english' ); ?>><?php esc_html_e( 'English', 'postology' ); ?></option>
                        <option value="spanish" <?php selected( $summary_lang_option, 'spanish' ); ?>><?php esc_html_e( 'Spanish', 'postology' ); ?></option>
                        <option value="french" <?php selected( $summary_lang_option, 'french' ); ?>><?php esc_html_e( 'French', 'postology' ); ?></option>
                        <option value="german" <?php selected( $summary_lang_option, 'german' ); ?>><?php esc_html_e( 'German', 'postology' ); ?></option>
                        <option value="italian" <?php selected( $summary_lang_option, 'italian' ); ?>><?php esc_html_e( 'Italian', 'postology' ); ?></option>
                        <option value="portuguese" <?php selected( $summary_lang_option, 'portuguese' ); ?>><?php esc_html_e( 'Portuguese', 'postology' ); ?></option>
                        <option value="chinese" <?php selected( $summary_lang_option, 'chinese' ); ?>><?php esc_html_e( 'Chinese', 'postology' ); ?></option>
                    </select>
                </section>
            </div>
            <div class="custom-card" style="display:flex;flex-direction:column;">
                <h3 style="margin:0;margin-block-end: 12px;color:grey;">Bullet Points Settings</h3>
                <section style="<?php echo esc_attr($general_form_section); ?>" class="general-form-section">
                    <strong style="align-self:center;display:flex;align-items:center;gap:6px;">
                        <?php
                        echo esc_html__( 'Number of Bullet Points', 'postology' );
                        echo '<svg style="width:21px;" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill-rule="evenodd" clip-rule="evenodd" d="M5.25 10.0546V8C5.25 4.27208 8.27208 1.25 12 1.25C15.7279 1.25 18.75 4.27208 18.75 8V10.0546C19.8648 10.1379 20.5907 10.348 21.1213 10.8787C22 11.7574 22 13.1716 22 16C22 18.8284 22 20.2426 21.1213 21.1213C20.2426 22 18.8284 22 16 22H8C5.17157 22 3.75736 22 2.87868 21.1213C2 20.2426 2 18.8284 2 16C2 13.1716 2 11.7574 2.87868 10.8787C3.40931 10.348 4.13525 10.1379 5.25 10.0546ZM6.75 8C6.75 5.10051 9.10051 2.75 12 2.75C14.8995 2.75 17.25 5.10051 17.25 8V10.0036C16.867 10 16.4515 10 16 10H8C7.54849 10 7.13301 10 6.75 10.0036V8ZM14 16C14 17.1046 13.1046 18 12 18C10.8954 18 10 17.1046 10 16C10 14.8954 10.8954 14 12 14C13.1046 14 14 14.8954 14 16Z" fill="#1C274C"></path></g></svg>';
                        ?>
                    </strong>
                    <p style="<?php echo esc_attr($general_form_description); ?>" class="description general-form-description">
                        <?php esc_html_e( 'Specify how many bullet points to display.', 'postology' ); ?>
                    </p>
                    <input type="number" name="postology_number_of_bullets" disabled value="2" min="1" style="<?php echo esc_attr($general_form_input); ?>" class="general-form-input" />
                </section>
                <section style="<?php echo esc_attr($general_form_section); ?>" class="general-form-section">
                    <strong style="align-self: center;"><?php echo esc_html__( 'Length of Bullet Points', 'postology' ); ?></strong>
                    <p style="<?php echo esc_attr($general_form_description); ?>" class="description general-form-description"><?php esc_html_e( 'Select the desired length for each bullet point in the summary.', 'postology' ); ?></p>
                    <select name="postology_bullet_point_length" style="<?php echo esc_attr($general_form_input); ?>" class="general-form-input">
                        <option value="short" <?php selected( $bp_length_option, 'short' ); ?>><?php esc_html_e( 'Short', 'postology' ); ?></option>
                        <option value="medium" <?php selected( $bp_length_option, 'medium' ); ?>><?php esc_html_e( 'Medium', 'postology' ); ?></option>
                        <option value="long" <?php selected( $bp_length_option, 'long' ); ?>><?php esc_html_e( 'Long', 'postology' ); ?></option>
                    </select>
                </section>
            </div>
            <div class="custom-card" style="display:flex;flex-direction:column;">
                <h3 style="margin:0;margin-block-end: 12px;color:grey;">Powered By Settings</h3>
                <section style="<?php echo esc_attr($general_form_section); ?>" class="general-form-section">
                    <strong style="align-self: center;"><?php echo esc_html__( 'Display Powered By Text', 'postology' ); ?></strong>
                    <p style="<?php echo esc_attr($general_form_description); ?>" class="description general-form-description"><?php esc_html_e( 'Toggle to show or hide the powered by text.', 'postology' ); ?></p>
                    <input type="checkbox" name="postology_display_powered_by" <?php if ($powered == "on") {echo "checked";} ?>
                     style="<?php echo esc_attr($general_form_input); ?>" class="general-form-input" />
                </section>
            </div>
        </div>
        <?php
    }
    
}
