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

    <record id="print_product_label_section_view_form" model="ir.ui.view">
        <field name="name">print.product.label.section.view.form</field>
        <field name="model">print.product.label.section</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <widget name="web_ribbon" text="Archived" bg_color="bg-danger" invisible="active"/>
                    <field name="template_preview_html" class="oe_avatar" invisible="not preview"/>
                    <div class="oe_title">
                        <h1><div class="d-flex">
                                <field name="display_name" class="text-break"/>
                        </div></h1>
                    </div>
                    <div name="options">
                        <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 ms-2"/>
                        </div>
                    </div>
                    <field name="active" invisible="1"/>  <!-- Technical field for the web ribbon -->
                    <field name="field_ttype" invisible="1"/>  <!-- Technical field for domain -->
                    <field name="field_ids" invisible="1"/>  <!-- Technical field for domain " TODO: remove ? -->
                    <field name="relation_model_id" invisible="1"/>  <!-- Technical field for domain -->
                    <field name="relation_field_ttype" invisible="1"/>  <!-- Technical field for domain -->
                    <field name="nested_relation_model_id" invisible="1"/>  <!-- Technical field for domain -->
                    <group>
                        <group string="Data">
                            <field name="type" />
                            <field name="value" invisible="type != 'text'"/>
                            <field name="image" invisible="type != 'image'" required="type == 'image'"/>
                            <field name="field_id"
                                   invisible="type != 'field'"
                                   options="{'no_open': True, 'no_create': True}"/>

                            <label for="relation_field_id" invisible="type != 'field' or type == 'field' and field_ttype not in ['many2one', 'many2many', 'one2many']" required="type == 'field' and field_ttype in ['many2one', 'many2many', 'one2many']"/>
                            <div class="o_row" invisible="type != 'field' or type == 'field' and field_ttype not in ['many2one', 'many2many', 'one2many']" required="type == 'field' and field_ttype in ['many2one', 'many2many', 'one2many']">
                                <field name="relation_field_id"
                                       domain="[('model_id', '=', relation_model_id), ('ttype', 'in', ['binary', 'char', 'text', 'html', 'selection', 'float', 'monetary', 'integer', 'date', 'datetime', 'many2one'])]"
                                       options="{'no_open': True, 'no_create': True}"/>
                                <field name="nested_relation_field_id"
                                       invisible="type != 'field' or type == 'field' and relation_field_ttype not in ['many2one']"
                                       required="type == 'field' and relation_field_ttype in ['many2one']"
                                       domain="[('model_id', '=', nested_relation_model_id), ('ttype', 'in', ['binary', 'char', 'text', 'html', 'selection', 'float', 'monetary', 'integer', 'date', 'datetime'])]"
                                       options="{'no_open': True, 'no_create': True}"/>
                            </div>
                            <!-- Options for section types -->
                            <field name="currency_position" invisible="type not in ['price', 'promo_price', 'multi_price']"/>
                            <field name="multi_price_order" string="Order" invisible="type != 'multi_price'"/>
                            <field name="multi_price_limit" string="Limit" invisible="type != 'multi_price'"/>
                            <field name="with_product_attribute_name" widget="boolean_toggle" invisible="type != 'product_attributes'"/>
                            <field name="attribute_ids" widget="many2many_tags" invisible="type != 'product_attributes'" options="{'no_open': True, 'no_create': True}"/>
                        </group>
                        <group string="Design">
                            <field name="height"/>
                            <field name="position"/>
                            <label for="width" invisible="position == 'none'"/>
                            <div class="o_row" invisible="position == 'none'">
                                <field name="width" required="position != 'none'"/>
                                <field name="width_measure" />
                            </div>
                            <label for="widget" invisible="type not in ['text', 'field', 'product_attributes']"/>
                            <div class="o_row" invisible="type not in ['text', 'field', 'product_attributes']">
                                <field name="widget"/>
                                <label for="barcode_is_humanreadable" string="human-readable" invisible="widget != 'barcode'" class="ms-2"/>
                                <field name="barcode_is_humanreadable" widget="boolean_toggle" invisible="widget != 'barcode'"/>
                                <label for="barcode_symbology" string="type" invisible="widget != 'barcode'" class="ms-1"/>
                                <field name="barcode_symbology" widget="selection" invisible="widget != 'barcode'"/>
                            </div>
                        </group>
                    </group>
                    <notebook>
                        <page string="Text" name="text_setting">
                            <group>
                                <group>
                                    <field name="align" widget="radio" options="{'horizontal': true}"/>
                                    <field name="font_weight" widget="radio" options="{'horizontal': true}"/>
                                    <field name="font_name" string="Font"/>
                                    <small class="o_row alert alert-info" colspan="2" role="alert" invisible="not font_name">Note: Fonts are not applied on the sample label. Use the PDF Preview to see the actual generated labels.</small>
                                    <label for="font_size"/>
                                    <div class="o_row">
                                        <field name="font_size" />
                                        <field name="font_size_measure" />
                                    </div>
                                    <field name="line_height"/>
                                    <field name="letter_spacing"/>
                                    <field name="text_color" string="Color" widget="color"/>
                                </group>
                                <group>
                                    <field name="value_format" invisible="type not in ['field', 'price', 'promo_price', 'multi_price'] or widget != False"/>
                                    <field name="text_decoration"/>
                                    <separator string="URL values" colspan="2"/>
                                    <field name="make_url_absolute" widget="boolean_toggle" invisible="type not in ['text', 'field']"/>
                                    <field name="shorten_url" widget="boolean_toggle" invisible="type not in ['text', 'field']"/>
                                </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="Margins" name="margin">
                            <group col="4" colspan="2">
                                <group col="2" colspan="2">
                                    <label for="margin_top" string="Top"/>
                                    <div>
                                        <field name="margin_top" class="oe_inline"/> mm
                                    </div>
                                    <label for="margin_bottom" string="Bottom"/>
                                    <div>
                                        <field name="margin_bottom" class="oe_inline"/> mm
                                    </div>
                                </group>
                                <group col="2" colspan="2">
                                    <label for="margin_left" string="Left"/>
                                    <div>
                                        <field name="margin_left" class="oe_inline"/> mm
                                    </div>
                                    <label for="margin_right" string="Right"/>
                                    <div>
                                        <field name="margin_right" class="oe_inline"/> mm
                                    </div>
                                </group>
                            </group>
                        </page>
                        <page string="Borders" name="border">
                            <group col="4" colspan="2">
                                <group col="2" colspan="2">
                                    <field name="with_border_top" string="Top" widget="boolean_toggle"/>
                                    <field name="with_border_bottom" string="Bottom" widget="boolean_toggle"/>
                                </group>
                                <group col="2" colspan="2">
                                    <field name="with_border_left" string="Left" widget="boolean_toggle"/>
                                    <field name="with_border_right" string="Right" widget="boolean_toggle"/>
                                </group>
                                <group col="2" colspan="2" invisible="not with_border_top and not with_border_left and not with_border_right and not with_border_bottom">
                                    <field name="border_width" string="Width, px"/>
                                </group>
                            </group>
                        </page>
                        <page string="Background" name="background">
                            <group>
                                <group>
                                    <field name="with_background" widget="boolean_toggle"/>
                                    <field name="background_color" widget="color" invisible="not with_background"/>
                                </group>
                            </group>
                        </page>
                        <page string="Value Processing" name="post_processing">
                            <group>
                                <group>
                                    <field name="value_prefix"/>
                                    <field name="value_suffix"/>
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="print_product_label_section_view_tree" model="ir.ui.view">
        <field name="name">print.product.label.section.view.list</field>
        <field name="model">print.product.label.section</field>
        <field name="arch" type="xml">
            <list 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'"
                  decoration-muted="not active">
                <field name="sequence" widget="handle"/>
                <field name="display_name"/>
                <field name="font_name" string="Font" optional="hide"/>
                <field name="position" optional="show"/>
                <field name="type" optional="hide"/>
                <field name="field_id" optional="hide"/>
                <field name="relation_field_id" optional="hide"/>
                <field name="widget" optional="hide"/>
                <field name="value_format" optional="hide"/>
                <field name="align" optional="show"/>
                <field name="font_size" optional="show"/>
                <field name="font_size_measure" optional="hide"/>
                <field name="line_height" optional="show"/>
                <field name="font_weight" optional="show"/>
                <field name="height" sum="Total Label Height" optional="show"/>
                <field name="active" widget="boolean_toggle" optional="show"/>
            </list>
        </field>
    </record>

</odoo>
