@extends('layouts/default')

{{-- Page title --}}
@section('title')
    {{ $company->name }}
    @parent
@stop

@section('header_right')
    <x-button.info-panel-toggle/>
@endsection

{{-- Page content --}}
@section('content')
    <x-container columns="2">
        <x-page-column class="col-md-9 main-panel">
            <x-tabs>
                <x-slot:tabnav>
                    <x-tabs.user-tab count="{{ $tabCounts['users'] }}"/>
                    <x-tabs.asset-tab count="{{ $tabCounts['assets'] }}"/>
                    <x-tabs.license-tab count="{{ $tabCounts['licenses'] }}"/>
                    <x-tabs.accessory-tab count="{{ $tabCounts['accessories'] }}"/>
                    <x-tabs.consumable-tab count="{{ $tabCounts['consumables'] }}"/>
                    <x-tabs.component-tab count="{{ $tabCounts['components'] }}"/>
                    @if ($company->children->isNotEmpty())
                        <x-tabs.company-tab count="{{ $company->children->count() }}"/>
                    @endif
                    <x-tabs.files-tab :item="$company" count="{{ $company->uploads()->count() }}"/>
                    <x-tabs.upload-tab :item="$company"/>
                </x-slot:tabnav>

                <x-slot:tabpanes>
                    <!-- start users tab pane -->
                    <x-tabs.pane name="users">
                        <x-table.users name="users" :route="route('api.users.index', ['company_id' => $company->id, 'expand_company_hierarchy' => 1])"/>
                    </x-tabs.pane>
                    <!-- end users tab pane -->

                    <!-- start assets tab pane -->
                    <x-tabs.pane name="assets">
                        <x-table.assets name="assets" :route="route('api.assets.index', ['company_id' => $company->id, 'expand_company_hierarchy' => 1])"/>
                    </x-tabs.pane>
                    <!-- end assets tab pane -->

                    <!-- start licenses tab pane -->
                    <x-tabs.pane name="licenses">
                        <x-slot:bulkactions>
                            <x-table.bulk-licenses />
                        </x-slot:bulkactions>
                        <x-table.licenses name="licenses" :export_name="$company->name" :route="route('api.licenses.index', ['company_id' => $company->id, 'expand_company_hierarchy' => 1])"/>
                    </x-tabs.pane>
                    <!-- end licenses tab pane -->

                    <!-- start accessory tab pane -->
                    <x-tabs.pane name="accessories">
                        <x-table.accessories name="accessories" :route="route('api.accessories.index', ['company_id' => $company->id, 'expand_company_hierarchy' => 1])"/>
                    </x-tabs.pane>
                    <!-- end accessory tab pane -->

                    <!-- start consumables tab pane -->
                    <x-tabs.pane name="consumables">
                        <x-table.consumables name="consumables" :route="route('api.consumables.index', ['company_id' => $company->id, 'expand_company_hierarchy' => 1])"/>
                    </x-tabs.pane>
                    <!-- end components tab pane -->

                    <!-- start components tab pane -->
                    <x-tabs.pane name="components">
                        <x-table.components name="components" :route="route('api.components.index', ['company_id' => $company->id, 'expand_company_hierarchy' => 1])"/>
                    </x-tabs.pane>

                    @if ($company->children->isNotEmpty())
                        <!-- start child companies tab pane -->
                        <x-tabs.pane name="companies">
                            <x-table.companies name="companies" :route="route('api.companies.index', ['parent_id' => $company->id])"/>
                        </x-tabs.pane>
                        <!-- end child companies tab pane -->
                    @endif

                    <!-- start files tab pane -->
                    <x-tabs.pane name="files">
                        <x-table.files object_type="companies" :object="$company"/>
                    </x-tabs.pane>
                    <!-- end files tab pane -->

                </x-slot:tabpanes>

            </x-tabs>

        </x-page-column>
        <x-page-column class="col-md-3">
            <x-box class="side-box expanded">
                <x-info-panel :infoPanelObj="$company" img_path="{{ app('companies_upload_url') }}" :qr_code_url="route('qr_code/common', ['object_type' => 'companies', 'id' => $company->id])">

                    <x-slot:buttons>
                        <x-button.edit :item="$company" :route="route('companies.edit', $company->id)" />
                        <x-button.delete :item="$company" />
                    </x-slot:buttons>

                    @if ($company->parent)
                        <x-info-element icon_type="company" :icon_color="$company->parent->tag_color" title="{{ trans('admin/companies/table.parent') }}">
                            <x-copy-to-clipboard class="pull-right" copy_what="parent_company">
                                {!! $company->parent->present()->nameUrl !!}
                            </x-copy-to-clipboard>
                        </x-info-element>
                    @endif

                    @if ($company->children->isNotEmpty())
                        <x-info-element icon_type="company" title="{{ trans('admin/companies/table.children') }}">
                            {{ trans('admin/companies/table.children') }}
                            <x-info-element class="subitem">
                                <x-copy-to-clipboard class="pull-right" copy_what="child_companies">
                                    @foreach ($company->children->sortBy('name') as $child)
                                        {!! $child->present()->formattedNameLink !!}<br>
                                    @endforeach
                                </x-copy-to-clipboard>
                            </x-info-element>
                        </x-info-element>
                    @endif

                </x-info-panel>
            </x-box>
        </x-page-column>
    </x-container>

@endsection

@section('moar_scripts')
    @can('files', $company)
        @include ('modals.upload-file', ['item_type' => 'companies', 'item_id' => $company->id])
    @endcan
    <script>
        // Bootstrap-table formatters read these to decorate company tags on
        // rows that are present because of FMCS hierarchy expansion. The set
        // is just [self, parent, ...direct children]; companies outside it
        // (e.g. a user's other memberships) should render unmarked even if
        // they appear in the same row. See companiesLinkObjFormatter and
        // companiesArrayLinkFormatter in partials/bootstrap-table.
        window.viewingCompanyId = {{ (int) $company->id }};
        window.viewingCompanyHierarchyIds = {!! json_encode(\App\Models\Company::reachableCompanyIds($company->id)) !!};
    </script>
    @include ('partials.bootstrap-table')
@endsection

