<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="web.SwitchCompanyMenu">
    <Dropdown class="'o_switch_company_menu d-none d-md-block'" position="'bottom-end'">
        <t t-set-slot="toggler">
            <i class="fa fa-building d-lg-none"/>
            <span class="oe_topbar_name d-none d-lg-block" t-esc="companyService.currentCompany.name"/>
        </t>
        <t t-foreach="Object.values(companyService.allowedCompaniesWithAncestors)
                      .filter((c) => !c.parent_id)
                      .sort((c1, c2) => c1.sequence - c2.sequence)
                     " t-as="company" t-key="company.id">
            <SwitchCompanyItem company="company" level="0"/>
        </t>
    </Dropdown>
</t>


<t t-name="web.SwitchCompanyItem">
    <DropdownItem class="'p-0'" parentClosingMode="!isCompanyAllowed ? 'none' : 'all'">
        <div
            class="d-flex"
            t-att-class="{ 'disabled': !isCompanyAllowed }"
            data-menu="company"
            t-att-data-company-id="props.company.id">
            <div
                role="menuitemcheckbox"
                t-att-aria-checked="isCompanySelected ? 'true' : 'false'"
                t-att-aria-label="props.company.name"
                t-att-title="(isCompanySelected ? 'Hide ' : 'Show ') + props.company.name + ' content.'"
                tabindex="0"
                class="border-end toggle_company"
                t-att-class="{ 'border-primary': isCurrent, 'disabled': !isCompanyAllowed }"
                t-on-click.stop="() => this.toggleCompany()">

                <span class="btn border-0 p-2" t-att-class="isCompanyAllowed ? 'btn-link text-primary' : 'disabled'">
                    <i class="fa fa-fw py-2" t-att-class="isCompanySelected ? 'fa-check-square text-primary' : 'fa-square-o'"/>
                </span>
            </div>

            <div
                role="button"
                t-att-aria-pressed="isCurrent ? 'true' : 'false'"
                t-att-aria-label="'Switch to ' + props.company.name "
                t-att-title="'Switch to ' + props.company.name "
                tabindex="0"
                class="d-flex flex-grow-1 align-items-center py-0 log_into ps-2"
                t-att-class="isCurrent ? 'alert-primary' : 'btn fw-normal border-0 ' + (isCompanyAllowed ? 'btn-link text-primary' : 'disabled')"
                t-on-click="() => this.logIntoCompany()">

                <span
                    class='company_label pe-3'
                    t-att-class="isCurrent ? 'text-900 fw-bold' : ''"
                    t-attf-style="padding-left:{{props.level * 20}}px;">
                    <t t-out="props.company.name"/>
                </span>
            </div>
        </div>
    </DropdownItem>
    <t t-foreach="props.company.child_ids" t-as="child" t-key="child">
        <SwitchCompanyItem company="companyService.getCompany(child)" level="props.level + 1"/>
    </t>
</t>

</templates>
