<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var $block \Magento\Catalog\Block\Adminhtml\Product\Edit\Tabs */
?>
<?php if (!empty($tabs)) :?>
    <?php $tabGroups = [
        \Magento\Catalog\Block\Adminhtml\Product\Edit\Tabs::BASIC_TAB_GROUP_CODE,
        \Magento\Catalog\Block\Adminhtml\Product\Edit\Tabs::ADVANCED_TAB_GROUP_CODE,
    ];?>

    <div id="<?= $block->escapeHtmlAttr($block->getId()) ?>"
         data-mage-init='{"tabs":{
        "active": "<?= $block->escapeHtmlAttr($block->getActiveTabId()) ?>",
        "destination": "#<?= $block->escapeHtmlAttr($block->getDestElementId()) ?>",
        "shadowTabs": "<?= /* @noEscape */ $block->getAllShadowTabs() ?>",
        "tabsBlockPrefix": "<?= $block->escapeHtmlAttr($block->getId()) ?>_",
        "tabIdArgument": "active_tab",
        "tabPanelClass": "<?= $block->escapeHtmlAttr($block->getPanelsClass()) ?>",
        "excludedPanel": "<?= $block->escapeHtmlAttr($block->getExcludedPanel()) ?>",
        "groups": "ul.tabs"
    }}'>
        <?php foreach ($tabGroups as $tabGroupCode) :?>
            <?php
                $tabGroupId = $block->getId() . '-' . $tabGroupCode;
                $isBasic = $tabGroupCode == \Magento\Catalog\Block\Adminhtml\Product\Edit\Tabs::BASIC_TAB_GROUP_CODE;
                $activeCollapsible = $block->isAdvancedTabGroupActive() ? true : false;
            ?>

            <div class="admin__page-nav <?php if (!$isBasic) :?> <?= '_collapsed' ?> <?php endif;?>"
                data-role="container"
                id="<?= $block->escapeHtmlAttr($tabGroupId) ?>"
                <?php if (!$isBasic) :?>
                    data-mage-init='{"collapsible":{
                    "active": "<?= /* @noEscape */ $activeCollapsible ?>",
                    "openedState": "_show",
                    "closedState": "_hide",
                    "animate": 200,
                    "collapsible": true
                    }}'
                <?php endif;?>>

                <div class="admin__page-nav-title-wrap" <?= /* @noEscape */ $block->getUiId('title') ?> data-role="title">
                    <div class="admin__page-nav-title <?php if (!$isBasic) :?> <?= '_collapsible' ?><?php endif;?>"
                        data-role="trigger">
                        <strong>
                            <?= $block->escapeHtml($isBasic ? __('Basic Settings') : __('Advanced Settings')) ?>
                        </strong>
                        <span data-role="title-messages" class="admin__page-nav-title-messages"></span>
                    </div>
                </div>

                <ul <?= /* @noEscape */ $block->getUiId('tab', $tabGroupId) ?> class="tabs admin__page-nav-items" data-role="content">
                    <?php foreach ($tabs as $_tab) :?>
                        <?php /** @var $_tab \Magento\Backend\Block\Widget\Tab\TabInterface */ ?>
                        <?php if (!$block->canShowTab($_tab) || $_tab->getParentTab()
                            || ($_tab->getGroupCode() && $_tab->getGroupCode() != $tabGroupCode)
                            || (!$_tab->getGroupCode() && $isBasic)) : continue;
                        endif;?>
                        <?php $_tabClass = 'tab-item-link ' . $block->getTabClass($_tab) . ' ' . (preg_match('/\s?ajax\s?/', $_tab->getClass()) ? 'notloaded' : '') ?>
                        <?php $_tabType = (!preg_match('/\s?ajax\s?/', $_tabClass) && $block->getTabUrl($_tab) != '#') ? 'link' : '' ?>
                        <?php $_tabHref = $block->getTabUrl($_tab) == '#' ? '#' . $block->getTabId($_tab) . '_content' : $block->getTabUrl($_tab) ?>
                        <li class="admin__page-nav-item <?php if ($block->getTabIsHidden($_tab)) :?> <?= "no-display" ?> <?php endif; ?> " <?= /* @noEscape */ $block->getUiId('tab', 'item', $_tab->getId()) ?>>
                            <a href="<?= $block->escapeUrl($_tabHref) ?>" id="<?= $block->escapeHtmlAttr($block->getTabId($_tab)) ?>"
                               name="<?= $block->escapeHtmlAttr($block->getTabId($_tab, false)) ?>"
                               title="<?= $block->escapeHtmlAttr($block->getTabTitle($_tab)) ?>"
                               class="admin__page-nav-link <?= $block->escapeHtmlAttr($_tabClass) ?>"
                               data-tab-type="<?= /* @noEscape */ $_tabType ?>" <?= /* @noEscape */ $block->getUiId('tab', 'link', $_tab->getId()) ?>
                            >
                                <span><?= $block->escapeHtml($block->getTabLabel($_tab)) ?></span>
                                <span class="admin__page-nav-item-messages" data-role="item-messages">
                                   <span class="admin__page-nav-item-message _changed">
                                       <span class="admin__page-nav-item-message-icon"></span>
                                       <span class="admin__page-nav-item-message-tooltip">
                                           <?= $block->escapeHtml(__('Changes have been made to this section that have not been saved.')) ?>
                                       </span>
                                   </span>
                                   <span class="admin__page-nav-item-message _error">
                                       <span class="admin__page-nav-item-message-icon"></span>
                                       <span class="admin__page-nav-item-message-tooltip">
                                           <?= $block->escapeHtml(__('This tab contains invalid data. Please resolve this before saving.')) ?>
                                       </span>
                                   </span>
                                    <span class="admin__page-nav-item-message-loader">
                                       <span class="spinner">
                                           <span></span><span></span><span></span><span></span>
                                           <span></span><span></span><span></span><span></span>
                                       </span>
                                   </span>
                                </span>
                            </a>
                            <div id="<?= $block->escapeHtmlAttr($block->getTabId($_tab)) ?>_content" class="no-display"
                                 data-tab-panel="<?= $block->escapeHtmlAttr($_tab->getTabId()) ?>"
                                <?= /* @noEscape */ $block->getUiId('tab', 'content', $_tab->getId()) ?>
                            >
                                <?= /* @noEscape */ $block->getTabContent($_tab) ?>
                                <?= /* @noEscape */ $block->getAccordion($_tab) ?>
                            </div>
                        </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
