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

    <!-- SEO Content Idea List View -->
    <record id="otk_seo_content_idea_view_tree" model="ir.ui.view">
        <field name="name">otk.seo.content.idea.list</field>
        <field name="model">otk.seo.content.idea</field>
        <field name="arch" type="xml">
            <list string="Content Ideas"
                decoration-info="state == 'idea'"
                decoration-warning="state == 'scheduled'"
                decoration-success="state == 'done'"
                decoration-danger="state == 'failed'"
                decoration-muted="state == 'cancelled'">
                <field name="priority" widget="priority"/>
                <field name="name"/>
                <field name="content_type"/>
                <field name="keywords" optional="show"/>
                <field name="is_recurring" string="Rec." widget="boolean" optional="show"/>
                <field name="scheduled_date"/>
                <field name="state" widget="badge"
                    decoration-info="state == 'idea'"
                    decoration-warning="state in ('scheduled', 'generating')"
                    decoration-success="state == 'done'"
                    decoration-danger="state == 'failed'"
                    decoration-muted="state == 'cancelled'"/>
                <field name="content_id" optional="show"/>
                <button name="action_generate_now" type="object"
                    string="Generate Now" icon="fa-bolt"
                    invisible="state not in ('idea', 'scheduled')"/>
            </list>
        </field>
    </record>

    <!-- SEO Content Idea Form View -->
    <record id="otk_seo_content_idea_view_form" model="ir.ui.view">
        <field name="name">otk.seo.content.idea.form</field>
        <field name="model">otk.seo.content.idea</field>
        <field name="arch" type="xml">
            <form string="Content Idea">
                <header>
                    <button name="action_schedule_now" type="object"
                        string="Schedule Now" class="oe_highlight"
                        invisible="state != 'idea'"/>
                    <button name="action_generate_now" type="object"
                        string="Generate Now" class="oe_highlight"
                        invisible="state not in ('idea', 'scheduled')"/>
                    <button name="action_cancel" type="object"
                        string="Cancel"
                        invisible="state not in ('idea', 'scheduled')"/>
                    <button name="action_reset_to_idea" type="object"
                        string="Reset to Idea"
                        invisible="state not in ('failed', 'cancelled')"/>
                    <field name="state" widget="statusbar"
                        statusbar_visible="idea,scheduled,generating,done"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="action_view_content" type="object"
                            class="oe_stat_button" icon="fa-file-text-o"
                            invisible="not content_id">
                            <span class="o_stat_text">View Content</span>
                        </button>
                    </div>

                    <widget name="web_ribbon" title="Failed"
                        bg_color="text-bg-danger" invisible="state != 'failed'"/>
                    <widget name="web_ribbon" title="Cancelled"
                        bg_color="text-bg-secondary" invisible="state != 'cancelled'"/>

                    <div class="oe_title">
                        <h1>
                            <field name="name" placeholder="Content idea title or topic..."
                                readonly="state not in ('idea', 'scheduled')"/>
                        </h1>
                    </div>

                    <group>
                        <group string="Idea Details">
                            <field name="priority" widget="priority"/>
                            <field name="keywords" placeholder="target, keywords, here"
                                readonly="state not in ('idea', 'scheduled')"/>
                            <field name="topic_brief" placeholder="Describe what the content should cover..."
                                readonly="state not in ('idea', 'scheduled')"/>
                            <field name="product_id"
                                readonly="state not in ('idea', 'scheduled')"/>
                            <field name="reference_ids" widget="many2many_tags"
                                readonly="state not in ('idea', 'scheduled')"/>
                        </group>
                        <group string="Schedule">
                            <field name="scheduled_date"
                                readonly="state not in ('idea', 'scheduled')"/>
                            <field name="generated_at" readonly="1"
                                invisible="state != 'done'"/>
                        </group>
                    </group>

                    <notebook>
                        <page string="Generation Settings" name="settings">
                            <group>
                                <group>
                                    <field name="content_type"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="template_id"
                                        domain="[('content_type', '=', content_type)]"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="brand_voice_id"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                </group>
                                <group>
                                    <field name="tone"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="target_word_count"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="language_id"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                </group>
                            </group>
                        </page>

                        <page string="Images" name="images">
                            <group>
                                <group>
                                    <field name="include_images"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="image_count"
                                        invisible="not include_images"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="image_style"
                                        invisible="not include_images"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                </group>
                            </group>
                        </page>

                        <page string="Recurring" name="recurring">
                            <group>
                                <group>
                                    <field name="is_recurring"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="recurrence_type"
                                        invisible="not is_recurring"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="recurrence_end_date"
                                        invisible="not is_recurring"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                </group>
                                <group>
                                    <field name="parent_idea_id" readonly="1"
                                        invisible="not parent_idea_id"/>
                                </group>
                            </group>
                            <div class="alert alert-info" role="alert"
                                invisible="not is_recurring">
                                <i class="fa fa-repeat" title="Recurring"/>
                                <strong> Recurring Idea:</strong>
                                A new idea will automatically be created and scheduled
                                after this one is processed.
                            </div>
                        </page>

                        <page string="Auto-Publish" name="publish">
                            <group>
                                <group>
                                    <field name="auto_create_blog_post"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="blog_id"
                                        invisible="not auto_create_blog_post"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                    <field name="auto_publish"
                                        invisible="not auto_create_blog_post"
                                        readonly="state not in ('idea', 'scheduled')"/>
                                </group>
                            </group>
                            <div class="alert alert-warning" role="alert"
                                invisible="not auto_publish">
                                <i class="fa fa-exclamation-triangle" title="Auto-Publish"/>
                                <strong>Auto-Publish Enabled:</strong>
                                Content will be automatically published to your website when generated.
                                Make sure you review scheduled ideas before their scheduled time.
                            </div>
                        </page>

                        <page string="Result" name="result" invisible="state not in ('done', 'failed')">
                            <group>
                                <group>
                                    <field name="content_id" readonly="1"/>
                                    <field name="blog_post_id" readonly="1"/>
                                </group>
                                <group>
                                    <field name="generated_at" readonly="1"/>
                                </group>
                            </group>
                            <group string="Error Details" invisible="state != 'failed'">
                                <field name="error_message" readonly="1" nolabel="1"/>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <!-- SEO Content Idea Search View -->
    <record id="otk_seo_content_idea_view_search" model="ir.ui.view">
        <field name="name">otk.seo.content.idea.search</field>
        <field name="model">otk.seo.content.idea</field>
        <field name="arch" type="xml">
            <search string="Search Ideas">
                <field name="name"/>
                <field name="keywords"/>
                <separator/>
                <filter name="filter_ideas" string="Ideas"
                    domain="[('state', '=', 'idea')]"/>
                <filter name="filter_scheduled" string="Scheduled"
                    domain="[('state', '=', 'scheduled')]"/>
                <filter name="filter_done" string="Completed"
                    domain="[('state', '=', 'done')]"/>
                <filter name="filter_failed" string="Failed"
                    domain="[('state', '=', 'failed')]"/>
                <separator/>
                <filter name="filter_high_priority" string="High Priority"
                    domain="[('priority', 'in', ('2', '3'))]"/>
                <filter name="filter_auto_publish" string="Auto-Publish"
                    domain="[('auto_publish', '=', True)]"/>
                <separator/>
                <filter name="filter_my_ideas" string="My Ideas"
                    domain="[('create_uid', '=', uid)]"/>
                <group>
                    <filter name="group_state" string="Status"
                        context="{'group_by': 'state'}"/>
                    <filter name="group_type" string="Content Type"
                        context="{'group_by': 'content_type'}"/>
                    <filter name="group_priority" string="Priority"
                        context="{'group_by': 'priority'}"/>
                    <filter name="group_scheduled" string="Scheduled Date"
                        context="{'group_by': 'scheduled_date:day'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- SEO Content Idea Kanban View -->
    <record id="otk_seo_content_idea_view_kanban" model="ir.ui.view">
        <field name="name">otk.seo.content.idea.kanban</field>
        <field name="model">otk.seo.content.idea</field>
        <field name="arch" type="xml">
            <kanban default_group_by="state" class="o_kanban_small_column">
                <field name="name"/>
                <field name="state"/>
                <field name="priority"/>
                <field name="scheduled_date"/>
                <field name="content_type"/>
                <field name="auto_publish"/>
                <progressbar field="state"
                    colors='{"idea": "info", "scheduled": "warning", "generating": "warning", "done": "success", "failed": "danger", "cancelled": "muted"}'/>
                <templates>
                    <t t-name="card">
                        <div class="oe_kanban_card oe_kanban_global_click">
                            <div class="oe_kanban_content">
                                <div class="o_kanban_record_title d-flex align-items-center">
                                    <field name="priority" widget="priority" class="me-2"/>
                                    <strong class="text-truncate"><field name="name"/></strong>
                                </div>
                                <div class="o_kanban_record_body">
                                    <field name="content_type"/>
                                    <t t-if="record.scheduled_date.raw_value">
                                        <br/>
                                        <span class="text-muted">
                                            <i class="fa fa-clock-o" title="Scheduled Date"/> <field name="scheduled_date"/>
                                        </span>
                                    </t>
                                </div>
                                <div class="o_kanban_record_bottom mt-2">
                                    <div class="oe_kanban_bottom_left">
                                        <t t-if="record.auto_publish.raw_value">
                                            <span class="badge text-bg-warning" title="Auto-Publish">
                                                <i class="fa fa-globe"/>
                                            </span>
                                        </t>
                                    </div>
                                    <div class="oe_kanban_bottom_right">
                                        <field name="state" widget="label_selection"
                                            options="{'classes': {'idea': 'info', 'scheduled': 'warning', 'generating': 'warning', 'done': 'success', 'failed': 'danger', 'cancelled': 'secondary'}}"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <!-- SEO Content Idea Calendar View -->
    <record id="otk_seo_content_idea_view_calendar" model="ir.ui.view">
        <field name="name">otk.seo.content.idea.calendar</field>
        <field name="model">otk.seo.content.idea</field>
        <field name="arch" type="xml">
            <calendar string="Scheduled Ideas" date_start="scheduled_date"
                color="priority" mode="month" quick_create="0"
                event_open_popup="true">
                <field name="name"/>
                <field name="content_type"/>
                <field name="keywords"/>
                <field name="state"/>
                <field name="auto_publish"/>
                <field name="is_recurring"/>
            </calendar>
        </field>
    </record>

    <!-- Action -->
    <record id="action_otk_seo_content_idea" model="ir.actions.act_window">
        <field name="name">Ideas Queue</field>
        <field name="res_model">otk.seo.content.idea</field>
        <field name="view_mode">kanban,list,form,calendar</field>
        <field name="search_view_id" ref="otk_seo_content_idea_view_search"/>
        <field name="context">{'search_default_filter_ideas': 1, 'search_default_filter_scheduled': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Add your first content idea!
            </p>
            <p>
                Create content ideas and schedule them for automatic generation.
                Ideas can include keywords, topic briefs, and publishing settings.
            </p>
        </field>
    </record>

</odoo>
