<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <!-- Generate Content Wizard Form View (Multi-Step) -->
    <record id="otk_seo_content_generate_wizard_view_form" model="ir.ui.view">
        <field name="name">otk.seo.content.generate.wizard.form</field>
        <field name="model">otk.seo.content.generate.wizard</field>
        <field name="arch" type="xml">
            <form string="Generate SEO Content">
                <!-- Step Indicator -->
                <div class="otk_wizard_steps d-flex justify-content-center align-items-center gap-2 mb-4 px-3 py-3 bg-light rounded">
                    <!-- Step 1: Source — Active -->
                    <div class="d-flex align-items-center gap-2" invisible="state != 'step_source'">
                        <span class="otk_step_circle otk_step_active">1</span>
                        <span class="fw-bold text-primary">Source</span>
                    </div>
                    <!-- Step 1: Source — Completed -->
                    <div class="d-flex align-items-center gap-2" invisible="state == 'step_source'">
                        <span class="otk_step_circle otk_step_done">
                            <i class="fa fa-check" title="Completed"/>
                        </span>
                        <span class="text-success">Source</span>
                    </div>
                    <i class="fa fa-chevron-right text-muted small" title="next step"/>

                    <!-- Step 2: Settings — Active -->
                    <div class="d-flex align-items-center gap-2" invisible="state != 'step_settings'">
                        <span class="otk_step_circle otk_step_active">2</span>
                        <span class="fw-bold text-primary">Settings</span>
                    </div>
                    <!-- Step 2: Settings — Completed -->
                    <div class="d-flex align-items-center gap-2" invisible="state not in ('step_images', 'step_review')">
                        <span class="otk_step_circle otk_step_done">
                            <i class="fa fa-check" title="Completed"/>
                        </span>
                        <span class="text-success">Settings</span>
                    </div>
                    <!-- Step 2: Settings — Upcoming -->
                    <div class="d-flex align-items-center gap-2" invisible="state != 'step_source'">
                        <span class="otk_step_circle otk_step_upcoming">2</span>
                        <span class="text-muted">Settings</span>
                    </div>
                    <i class="fa fa-chevron-right text-muted small" title="next step"/>

                    <!-- Step 3: Images — Active -->
                    <div class="d-flex align-items-center gap-2" invisible="state != 'step_images'">
                        <span class="otk_step_circle otk_step_active">3</span>
                        <span class="fw-bold text-primary">Images</span>
                    </div>
                    <!-- Step 3: Images — Completed -->
                    <div class="d-flex align-items-center gap-2" invisible="state != 'step_review'">
                        <span class="otk_step_circle otk_step_done">
                            <i class="fa fa-check" title="Completed"/>
                        </span>
                        <span class="text-success">Images</span>
                    </div>
                    <!-- Step 3: Images — Upcoming -->
                    <div class="d-flex align-items-center gap-2" invisible="state not in ('step_source', 'step_settings')">
                        <span class="otk_step_circle otk_step_upcoming">3</span>
                        <span class="text-muted">Images</span>
                    </div>
                    <i class="fa fa-chevron-right text-muted small" title="next step"/>

                    <!-- Step 4: Review — Active -->
                    <div class="d-flex align-items-center gap-2" invisible="state != 'step_review'">
                        <span class="otk_step_circle otk_step_active">4</span>
                        <span class="fw-bold text-primary">Review</span>
                    </div>
                    <!-- Step 4: Review — Upcoming -->
                    <div class="d-flex align-items-center gap-2" invisible="state == 'step_review'">
                        <span class="otk_step_circle otk_step_upcoming">4</span>
                        <span class="text-muted">Review</span>
                    </div>
                </div>

                <field name="state" invisible="1"/>

                <!-- ==================== STEP 1: Source ==================== -->
                <group invisible="state != 'step_source'">
                    <group string="Content Type">
                        <field name="content_type" widget="radio"/>
                        <field name="source_type" widget="radio"/>
                    </group>
                </group>

                <group string="Source" invisible="state != 'step_source' or source_type == 'product'">
                    <field name="source_keywords"
                        placeholder="keyword1, keyword2, keyword3..."
                        invisible="source_type == 'existing'"/>
                    <field name="source_topic"
                        placeholder="Describe what the content should be about..."
                        invisible="source_type == 'existing'"/>
                    <field name="source_text"
                        placeholder="Paste existing content to optimize..."
                        invisible="source_type != 'existing'"/>
                </group>

                <group string="Product" invisible="state != 'step_source' or source_type != 'product'">
                    <field name="source_product_id"/>
                    <field name="source_keywords"
                        placeholder="Additional keywords (optional)"/>
                </group>

                <!-- ==================== STEP 2: Settings ==================== -->
                <group invisible="state != 'step_settings'">
                    <group string="Template &amp; Voice">
                        <field name="template_id"
                            domain="[('content_type', '=', content_type)]"
                            placeholder="Optional - select a template"/>
                        <field name="brand_voice_id"
                            placeholder="Select brand voice"/>
                    </group>
                    <group string="Content Settings">
                        <field name="tone"/>
                        <field name="target_word_count"/>
                        <field name="language_id"/>
                    </group>
                </group>

                <group string="References" invisible="state != 'step_settings'">
                    <field name="reference_ids" widget="many2many_tags"
                        domain="['|', ('content_type', '=', content_type), ('content_type', '=', 'all')]"
                        placeholder="Select references to inspire the AI (max 5)..."
                        options="{'no_create': True}"/>
                </group>

                <!-- ==================== STEP 3: Images ==================== -->
                <group invisible="state != 'step_images'">
                    <group string="Image Settings">
                        <field name="include_images" widget="boolean_toggle"/>
                        <field name="image_count"
                            invisible="not include_images"/>
                        <field name="image_style"
                            invisible="not include_images"/>
                    </group>
                    <group string="Advanced Options">
                        <field name="include_toc" widget="boolean_toggle"/>
                        <field name="include_faq" widget="boolean_toggle"/>
                        <field name="custom_instructions"
                            placeholder="Additional instructions for the AI..."/>
                    </group>
                </group>

                <!-- ==================== STEP 4: Review ==================== -->
                <div invisible="state != 'step_review'" class="px-3">
                    <group string="Review Your Settings">
                        <group>
                            <field name="content_type" readonly="1"/>
                            <field name="source_type" readonly="1"/>
                            <field name="source_keywords" readonly="1"
                                invisible="not source_keywords"/>
                            <field name="template_id" readonly="1"/>
                            <field name="brand_voice_id" readonly="1"/>
                        </group>
                        <group>
                            <field name="tone" readonly="1"/>
                            <field name="target_word_count" readonly="1"/>
                            <field name="language_id" readonly="1"/>
                            <field name="include_images" readonly="1"/>
                            <field name="image_count" readonly="1"
                                invisible="not include_images"/>
                        </group>
                    </group>

                    <group string="Publishing">
                        <field name="blog_id" placeholder="Select target blog (optional)"/>
                    </group>

                    <!-- Cost Estimation Panel -->
                    <div class="otk_cost_panel alert alert-info mt-3" role="alert" title="Estimated Token Cost">
                        <h5><i class="fa fa-calculator me-1"/> Estimated Token Cost</h5>
                        <field name="cost_breakdown" readonly="1"
                            style="white-space: pre-line; font-family: monospace;"/>
                        <field name="estimated_cost" invisible="1"/>
                    </div>
                </div>

                <footer>
                    <!-- Steps 1-3: Next button -->
                    <button name="action_prev_step" type="object"
                        string="Back" class="btn-secondary"
                        invisible="state == 'step_source'"/>
                    <button name="action_next_step" type="object"
                        string="Next" class="btn-primary"
                        invisible="state == 'step_review'"/>
                    <!-- Step 4: Generate button -->
                    <button name="action_generate" type="object"
                        string="Generate Content" class="btn-primary"
                        invisible="state != 'step_review'"/>
                    <!-- Steps 2-4: Back button -->
                    <button string="Cancel" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <!-- Action to open wizard -->
    <record id="action_generate_content_wizard" model="ir.actions.act_window">
        <field name="name">Generate Content</field>
        <field name="res_model">otk.seo.content.generate.wizard</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>

</odoo>
