<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <template id="tier_validation_buttons">
        <div>
            <field name="validation_status" invisible="1" />
            <button
                name="request_validation"
                string="Request Validation"
                t-attf-attrs="{'invisible': ['|', '|', '|',
                ('need_validation', '!=', True),
                ('validation_status', '=', 'pending'),
                ('validation_status','=','rejected'),('#{state_field}', '#{state_operator}', #{state_value})]}"
                type="object"
            />
            <button
                name="restart_validation"
                string="Restart Validation"
                t-attf-attrs="{'invisible': ['|',
                ('review_ids', '=', []),
                ('#{state_field}', '#{state_operator}', #{state_value})]}"
                type="object"
            />
            <button
                name="reevaluate_reviews"
                string="Reevaluate Reviews"
                t-attf-attrs="{'invisible': ['|',('is_reevaluation_required', '!=', True),('#{state_field}', '#{state_operator}', #{state_value})]}"
                type="object"
            />
        </div>
    </template>
    <template id="tier_validation_label">
        <div>
            <field name="need_validation" invisible="1" />
            <field name="is_reevaluation_required" invisible="1" />
            <field name="validation_status" invisible="1" />
            <div
                class="alert alert-warning mb-0 pb-1 px-4"
                role="alert"
                t-attf-attrs="{'invisible': ['|', '|', '|',
                ('validation_status', '=', 'validated'),
                ('#{state_field}', '#{state_operator}', #{state_value}),
                ('validation_status', '=', 'rejected'),
                ('review_ids', '=', [])]}"
            >
                <p>
                    <i class="fa fa-info-circle" /> This Record needs to be validated.
                    <field name="can_review" invisible="1" />
                    <button
                        name="validate_tier"
                        string="Validate"
                        attrs="{'invisible': [('can_review', '=', False)]}"
                        type="object"
                        class="btn-sm btn-success mx-1"
                        icon="fa-thumbs-up"
                    />
                    <button
                        name="reject_tier"
                        string="Reject"
                        attrs="{'invisible': [('can_review', '=', False)]}"
                        type="object"
                        class="btn-sm btn-danger mx-1"
                        icon="fa-thumbs-down"
                    />
                    <field name="next_review" readonly="1" class="float-end pt-1" />
                </p>
            </div>
            <div
                class="alert alert-success mb-0 pb-1 px-4"
                role="alert"
                t-attf-attrs="{'invisible': ['|', '|',
                ('validation_status', '!=', 'validated'),
                ('#{state_field}', '#{state_operator}', #{state_value}),
                ('review_ids', '=', [])]}"
            >
                <p>
                    <i class="fa fa-thumbs-up" /> Operation has been <b>validated</b>!
                </p>
            </div>
            <div
                class="alert alert-danger mb-0 pb-1 px-4"
                role="alert"
                t-attf-attrs="{'invisible': ['|', '|',
                ('validation_status', '!=', 'rejected'),
                ('#{state_field}', '#{state_operator}', #{state_value}),
                ('review_ids', '=', [])]}"
            >
                <p>
                    <i class="fa fa-thumbs-down" /> Operation has been <b>rejected</b>.
                </p>
            </div>
        </div>
    </template>
    <template id="tier_validation_reviews">
        <field
            name="review_ids"
            widget="tier_validation"
            attrs="{'invisible':[('review_ids', '=', [])]}"
            style="width:100%%; margin-top: 10px;"
        >
            <tree>
                <field name="id" />
                <field name="name" />
                <field name="sequence" />
                <field name="requested_by" />
                <field name="status" />
                <field name="display_status" />
                <field name="todo_by" />
                <field name="done_by" />
                <field name="reviewed_date" />
                <field name="reviewed_formated_date" />
                <field name="comment" />
            </tree>
        </field>
    </template>
</odoo>
