<?php
/**
 * Magento Actions Section - Magento Module
 * This demonstrates Magento-specific actions in sidebar
 * Location: Sidebar - After Standard anchor point
 */

use yii\helpers\Html;

// Check if we're being included from within a tab (to avoid duplicate cards)
$isInTab = isset($inTab) && $inTab === true;
?>

<?php if (!$isInTab): ?>
<div class="card border-primary mb-3">
    <div class="card-header bg-primary text-white">
        <h6 class="mb-0">
            <i class="fab fa-magento mr-2"></i>
            Magento Actions
        </h6>
    </div>
    <div class="card-body">
<?php endif; ?>

        <div class="btn-group-vertical w-100">
            <?= Html::button('Sync to Magento', [
                'class' => 'btn btn-sm btn-primary w-100 mb-2',
                'onclick' => 'syncToMagento(' . $model->id . ')',
                'title' => 'Synchronize order data with Magento'
            ]) ?>
            
            <?= Html::button('Update Inventory', [
                'class' => 'btn btn-sm btn-outline-primary w-100 mb-2',
                'onclick' => 'updateMagentoInventory(' . $model->id . ')',
                'title' => 'Update inventory levels in Magento'
            ]) ?>
            
            <?= Html::button('Create Shipment', [
                'class' => 'btn btn-sm btn-success w-100 mb-2',
                'onclick' => 'createMagentoShipment(' . $model->id . ')',
                'title' => 'Create shipment in Magento',
                'style' => $model->billingstatus !== 'paid' ? 'display:none;' : ''
            ]) ?>
            
            <?= Html::button('Generate Invoice', [
                'class' => 'btn btn-sm btn-warning w-100 mb-2',
                'onclick' => 'generateMagentoInvoice(' . $model->id . ')',
                'title' => 'Generate invoice in Magento'
            ]) ?>
            
            <?= Html::button('View in Magento', [
                'class' => 'btn btn-sm btn-outline-info w-100',
                'onclick' => 'viewInMagento(' . $model->id . ')',
                'title' => 'Open order in Magento admin',
                'target' => '_blank'
            ]) ?>
        </div>

<?php if (!$isInTab): ?>
    </div>
</div>
<?php endif; ?>