<?php
/* @var $this yii\web\View */
/* @var $model common\models\Cart */

use yii\helpers\Html;
?>

<div class="magento-comprehensive-tab">
    <div class="row">
        <div class="col-md-12">
            <h4>Magento Integration</h4>
        </div>
    </div>
    
    <!-- Magento Status Bar Section -->
    <div class="row mb-3">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h5>Magento Status</h5>
                </div>
                <div class="card-body">
                    <?php 
                    // Include the existing magento status bar content
                    if (file_exists(Yii::getAlias('@PortalPeople/magento/views/cart/sections/magento_status_bar.php'))) {
                        echo $this->render('@PortalPeople/magento/views/cart/sections/magento_status_bar', ['model' => $model]);
                    } else {
                        echo '<p>Magento status information will appear here.</p>';
                    }
                    ?>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Magento Order Info Section -->
    <div class="row mb-3">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h5>Magento Order Information</h5>
                </div>
                <div class="card-body">
                    <?php 
                    // Include the existing magento order info content
                    if (file_exists(Yii::getAlias('@PortalPeople/magento/views/cart/sections/magento_order_info.php'))) {
                        echo $this->render('@PortalPeople/magento/views/cart/sections/magento_order_info', ['model' => $model]);
                    } else {
                        echo '<p>Magento order information will appear here.</p>';
                    }
                    ?>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Magento Actions Section -->
    <div class="row mb-3">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h5>Magento Actions</h5>
                </div>
                <div class="card-body">
                    <?php 
                    // Include the existing magento actions content without card wrapper
                    if (file_exists(Yii::getAlias('@PortalPeople/magento/views/cart/sections/magento_actions.php'))) {
                        echo $this->render('@PortalPeople/magento/views/cart/sections/magento_actions', [
                            'model' => $model, 
                            'inTab' => true
                        ]);
                    } else {
                        echo '<div class="btn-group-vertical w-100">';
                        echo Html::button('Sync to Magento', [
                            'class' => 'btn btn-primary w-100 mb-2',
                            'onclick' => 'syncToMagento(' . $model->id . ')',
                            'data-cart-id' => $model->id
                        ]);
                        echo Html::button('Update Magento Order', [
                            'class' => 'btn btn-info w-100 mb-2',
                            'onclick' => 'updateMagentoOrder(' . $model->id . ')',
                            'data-cart-id' => $model->id
                        ]);
                        echo Html::button('View in Magento', [
                            'class' => 'btn btn-outline-info w-100',
                            'onclick' => 'viewInMagento(' . $model->id . ')',
                            'title' => 'Open order in Magento admin',
                            'target' => '_blank'
                        ]);
                        echo '</div>';
                    }
                    ?>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Legacy Magento Sync Content (if any) -->
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <h5>Magento Sync Details</h5>
                </div>
                <div class="card-body">
                    <?php 
                    // Include the existing magento sync tab content if it exists
                    if (file_exists(Yii::getAlias('@PortalPeople/magento/views/cart/viewtabs/_magento_sync_tab.php'))) {
                        echo $this->render('@PortalPeople/magento/views/cart/viewtabs/_magento_sync_tab', ['model' => $model]);
                    } else {
                        echo '<p>Magento sync details and history will appear here.</p>';
                    }
                    ?>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
.magento-comprehensive-tab .card {
    border-left: 4px solid #007bff;
}

.magento-comprehensive-tab .card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.magento-comprehensive-tab .btn-group {
    width: 100%;
}

.magento-comprehensive-tab .btn-group .btn {
    flex: 1;
}
</style>