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

    <record id="woo_setup_wizard_form_view" model="ir.ui.view">
        <field name="name">woo.setup.wizard.form</field>
        <field name="model">woo.setup.wizard</field>
        <field name="arch" type="xml">
            <form string="WooCommerce Setup Wizard">
                <sheet>
                    <!-- Step indicator -->
                    <div class="o_statusbar_status mb-3">
                        <button type="object" name="action_back"
                            class="btn btn-secondary me-1"
                            invisible="step == 'connection'">
                            &#8592; Back
                        </button>
                        <span class="badge bg-primary me-1"
                            invisible="step != 'connection'">
                            Step 1: Connection
                        </span>
                        <span class="badge bg-secondary me-1"
                            invisible="step == 'connection'">
                            Step 1: Connection &#10003;
                        </span>
                        <span class="badge bg-primary me-1"
                            invisible="step != 'config'">
                            Step 2: Configuration
                        </span>
                        <span class="badge bg-secondary me-1"
                            invisible="step in ('connection', 'config')">
                            Step 2: Configuration &#10003;
                        </span>
                        <span class="badge bg-muted me-1"
                            invisible="step in ('config', 'done')">
                            Step 2: Configuration
                        </span>
                        <span class="badge bg-primary me-1"
                            invisible="step != 'done'">
                            Step 3: Done
                        </span>
                        <span class="badge bg-muted me-1"
                            invisible="step == 'done'">
                            Step 3: Done
                        </span>
                    </div>

                    <!-- Step 1: Connection -->
                    <group invisible="step != 'connection'">
                        <group string="WooCommerce Connection">
                            <field name="name" placeholder="e.g. My WooCommerce Store"/>
                            <field name="url" placeholder="https://mystore.com"/>
                            <field name="consumer_key" password="True"/>
                            <field name="consumer_secret" password="True"/>
                        </group>
                        <group>
                            <div class="alert alert-info" role="alert"
                                invisible="connection_tested == True">
                                Enter your WooCommerce store URL and REST API credentials, then test the connection.
                            </div>
                            <div class="alert alert-success" role="alert"
                                invisible="connection_tested == False">
                                Connection successful! Click Next to continue.
                            </div>
                            <field name="connection_tested" invisible="1"/>
                            <field name="step" invisible="1"/>
                        </group>
                    </group>

                    <!-- Step 2: Configuration -->
                    <group invisible="step != 'config'">
                        <group string="Sync Configuration">
                            <field name="default_warehouse_id"/>
                            <field name="sync_interval"/>
                        </group>
                    </group>

                    <!-- Step 3: Done -->
                    <group invisible="step != 'done'">
                        <group string="Setup Complete">
                            <div class="alert alert-success" role="alert">
                                <strong>Your WooCommerce instance has been created successfully!</strong>
                                <br/>Save the API key below — it is used to authenticate incoming webhooks from WooCommerce.
                            </div>
                            <field name="api_key" readonly="1"/>
                            <field name="instance_id" readonly="1"/>
                        </group>
                    </group>
                </sheet>

                <footer>
                    <!-- Connection step buttons -->
                    <button type="object" name="action_test_connection"
                        string="Test Connection"
                        class="btn-primary"
                        invisible="step != 'connection'"/>
                    <button type="object" name="action_next_step"
                        string="Next"
                        class="btn-primary"
                        invisible="step != 'connection'"/>

                    <!-- Config step buttons -->
                    <button type="object" name="action_complete"
                        string="Complete Setup"
                        class="btn-primary"
                        invisible="step != 'config'"/>

                    <!-- Done step buttons -->
                    <button type="object" name="action_fetch_products"
                        string="Fetch Products"
                        class="btn-primary"
                        invisible="step != 'done'"/>
                    <button type="object" name="action_open_instance"
                        string="Open Instance"
                        class="btn-secondary"
                        invisible="step != 'done'"/>

                    <button string="Close" class="btn-secondary" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <record id="action_woo_setup_wizard" model="ir.actions.act_window">
        <field name="name">WooCommerce Setup Wizard</field>
        <field name="res_model">woo.setup.wizard</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>

</odoo>
