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

    <record id="action_product_label_section_list" model="ir.actions.act_window">
        <field name="type">ir.actions.act_window</field>
        <field name="name">Sections</field>
        <field name="res_model">print.product.label.section</field>
        <field name="view_mode">list,form</field>
        <field name="context">{'default_template_id': active_id, 'active_test': False}</field>
        <field name="domain">[('template_id', '=', active_id)]</field>
    </record>

    <record id="print_product_label_template_view_form" model="ir.ui.view">
        <field name="name">print.product.label.template.view.form</field>
        <field name="model">print.product.label.template</field>
        <field name="arch" type="xml">
            <form create="false" duplicate="false">
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="%(action_product_label_section_list)d"
                                type="action"
                                class="oe_stat_button"
                                icon="fa-bars"
                                title="Sections"
                        >
                            <field name="section_count" string="Sections" widget="statinfo"/>
                        </button>
                    </div>
                    <field name="active" invisible="1"/>  <!-- Technical field for the web ribbon -->
                    <field name="format" invisible="1"/>  <!-- Technical field for domain -->
                    <field name="is_oversized" invisible="1"/>  <!-- Technical field for domain -->
                    <widget name="web_ribbon" text="Archived" bg_color="bg-danger" invisible="active"/>
                    <field name="preview_html" class="oe_avatar" invisible="not preview"/>
                    <div class="oe_title">
                        <h1>
                            <div class="d-flex">
                                <field class="text-break" name="name"/>
                            </div>
                        </h1>
                        <div>
                            <label for="type_id" class="mr16"/>
                            <field name="type_id" widget="selection"/>
                        </div>
                    </div>
                    <div name="options">
                        <h2 class="d-flex gap-3 g-0 align-items-end">
                            <div>
                                <label for="width" string="Width" class="mr16"/>
                                <field name="width"/>
                            </div>
                            <div>
                                <label for="height" string="Height" class="mr16"/>
                                <field name="height"/>
                            </div>
                        </h2>
                        <div class="d-inline-block">
                            <label for="preview" class="mr8"/>
                            <field name="preview" widget="boolean_toggle"/>
                            <button name="action_pdf_preview" type="object" string="PDF Preview" icon="fa-file-pdf-o" class="border btn btn-sm btn-light rounded ms-2"/>
                        </div>
                    </div>
                    <notebook>
                        <page string="Sections" name="sections">
                            <field name="section_ids" mode="list">
                                <list create="false"
                                      decoration-info="type=='text' and not widget"
                                      decoration-danger="widget=='price' or type=='promo_price'"
                                      decoration-success="widget in ['barcode', 'qr_code']"
                                      decoration-warning="type=='image' or widget=='image'">
                                    <field name="sequence" widget="handle"/>
                                    <field name="display_name" string="Name"/>
                                    <field name="font_name" string="Font" optional="hide"/>
                                    <field name="widget" optional="hide"/>
                                    <field name="position" optional="show"/>
                                    <field name="type" optional="show"/>
                                    <field name="field_name" invisible="type != 'field'" optional="hide"/>
                                    <field name="value" invisible="type != 'text'" optional="hide"/>
                                    <field name="with_background" optional="hide" width="0.5"/>
                                    <field name="height" sum="Total Label Height" width="0.5" optional="show"/>
                                </list>
                            </field>
                        </page>
                        <page string="Page" name="page_settings">
                            <group col="4" colspan="2">
                                <group string="General" name="general" col="2" colspan="2">
                                    <field name="paperformat_id" options="{'no_create': True}"/>
                                    <field name="orientation" groups="base.group_system"/>
                                </group>
                                <group string="Margins, mm" name="page_margin_settings" col="2" colspan="2" groups="base.group_system">
                                    <group>
                                        <field name="margin_top" string="Top"/>
                                        <field name="margin_bottom" string="Bottom"/>
                                    </group>
                                    <group>
                                        <field name="margin_left" string="Left"/>
                                        <field name="margin_right" string="Right"/>
                                    </group>
                                </group>
                                <group string="Layout" col="2" colspan="2">
                                    <field name="cols"/>
                                    <field name="rows"/>
                                </group>
                                <group string="Gap between labels, mm" col="2" colspan="2">
                                    <field name="col_gap" invisible="cols &lt;= 1"/>
                                    <field name="row_gap" invisible="rows &lt;= 1"/>
                                </group>
                            </group>
                        </page>
                        <page string="Paddings" name="padding">
                            <group col="4" colspan="2">
                                <group col="2" colspan="2">
                                    <label for="padding_top" string="Top"/>
                                    <div><field name="padding_top" class="oe_inline"/> mm</div>
                                    <label for="padding_bottom" string="Bottom"/>
                                    <div><field name="padding_bottom" class="oe_inline"/> mm</div>
                                </group>
                                <group col="2" colspan="2">
                                    <label for="padding_left" string="Left"/>
                                    <div><field name="padding_left" class="oe_inline"/> mm</div>
                                    <label for="padding_right" string="Right"/>
                                    <div><field name="padding_right" class="oe_inline"/> mm</div>
                                </group>
                            </group>
                        </page>
                        <page string="Technical" name="technical" groups="base.group_no_one">
                            <group class="o_label_nowrap">
                                <div class="oe_row text-warning" colspan="2">Be aware specifying custom HTML styles, it can break the label generation!</div>
                                <field name="label_style" placeholder="For example, background-color: #FFFF00; border: 2px solid #000;"/>
                            </group>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="print_product_label_template_view_tree" model="ir.ui.view">
        <field name="name">print.product.label.template.view.list</field>
        <field name="model">print.product.label.template</field>
        <field name="arch" type="xml">
            <list create="false" decoration-muted="not active">
                <field name="sequence" widget="handle"/>
                <field name="type_id" optional="show"/>
                <field name="name"/>
                <field name="preview_html" string="Preview" optional="hide"/>
                <field name="orientation" optional="hide"/>
                <field name="width" optional="show"/>
                <field name="height" optional="show"/>
                <field name="paperformat_id" optional="show"/>
                <field name="cols" optional="show"/>
                <field name="rows" optional="show"/>
                <field name="section_count" sum="Total" optional="show"/>
                <field name="active" widget="boolean_toggle" optional="show"/>
            </list>
        </field>
    </record>

</odoo>
