protected function buildTabsArray($availableGroups, $attachedGroups)
    {
        $addGroupItems = [];
        $tabs = [];
        foreach ($availableGroups as $id => $name) {
            if (!in_array($id, $attachedGroups)) {
                $addGroupItems[$id] = $name;
            }
            $isAttached = in_array($id, $attachedGroups);
            if ($isAttached) {
                $content = '';
                /** @var Property[] $properties */
                $properties = Property::find()
                    ->from(Property::tableName() . ' p')
                    ->innerJoin(
                        PropertyPropertyGroup::tableName() . ' ppg',
                        'p.id = ppg.property_id'
                    )
                    ->where(['ppg.property_group_id' => $id])
                    ->all();
                foreach ($properties as $property) {
                    $content .= $property
                        ->handler()
                        ->renderProperty(
                            $this->model,
                            $property,
                            AbstractPropertyHandler::BACKEND_EDIT,
                            $this->form
                        );
                }
                $tabs[] = [
                    'label' => Html::encode($name)
                        . '&nbsp;'
                        . Html::button(
                            new Icon('close'),
                            [
                                'class' => 'btn btn-danger btn-xs',
                                'data-group-id' => $id,
                                'data-action' => 'delete-property-group',
                            ]
                        ),
                    'content' => $content . Html::hiddenInput(
                        'propertyGroupIds[]',
                        $id,
                        [
                                'class' => 'property-group-ids',
                            ]
                    ),
                ];
            }
        }

        $tabs[] = [
            'label' => Select2::widget([
                'data' => $addGroupItems,
                'name' => 'plus-group',
                'options' => [
                    'placeholder' => Module::t('widget', '(+) Add group'),
                    'style' => [
                        'min-width' => '100px'
                    ]
                ],
                'pluginOptions' => [
                    'allowClear' => true
                ],
            ]),
            'url' => '#',

        ];

        return $tabs;
    }