<?php
/**
 * Standard Template - Clean SaaS Design
 * Clean, modern, and professional invoice template
 */

$text_settings = \EasyInvoice\Helpers\TemplateTextHelper::getInvoiceTextSettings();
$company_info = \EasyInvoice\Helpers\TemplateTextHelper::getCompanyInfo();
?>
<style>
/* Standard Template - Clean and Simple Design */
.template-standard {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #ffffff;
    color: #333333;
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
    line-height: 1.5;
}

/* Header Section */
.template-standard .invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e0e0e0;
}

.template-standard .company-info {
    flex: 1;
}

.template-standard .company-logo {
    margin-bottom: 1rem;
}

.template-standard .logo-image {
    max-height: 50px;
    max-width: 180px;
    object-fit: contain;
}

.template-standard .company-name {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.template-standard .company-details {
    color: #666666;
    font-size: 0.9rem;
    line-height: 1.4;
}

.template-standard .invoice-meta {
    text-align: right;
    min-width: 200px;
}

.template-standard .invoice-title {
    font-size: 1.75rem;
    font-weight: 600;
    color: #333333;
    margin-bottom: 1rem;
}

.template-standard .meta-item {
    margin-bottom: 0.5rem;
}

.template-standard .meta-label {
    color: #666666;
    font-size: 0.9rem;
}

.template-standard .meta-value {
    font-weight: 500;
}

/* Address Section */
.template-standard .address-section {
    margin-bottom: 2rem;
}

.template-standard .address-block h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.template-standard .client-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.template-standard .address-content {
    color: #666666;
    font-size: 0.9rem;
}

/* Invoice Items Table */
.template-standard .invoice-items {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
    border: 1px solid #e0e0e0;
}

.template-standard .invoice-items th {
    background: #f5f5f5;
    color: #333333;
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
    font-size: 0.9rem;
}

.template-standard .invoice-items td {
    padding: 0.75rem;
    border-bottom: 1px solid #e0e0e0;
    vertical-align: top;
}

.template-standard .item-name .item-title {
    font-weight: 500;
}

.template-standard .item-description {
    color: #666666;
    font-size: 0.9rem;
    margin-top: 0.25rem;
    font-weight: 300;
}

.template-standard .item-quantity,
.template-standard .item-price,
.template-standard .item-total {
    text-align: right;
}

/* Invoice Totals */
.template-standard .invoice-totals {
    margin-left: auto;
    width: 300px;
    margin-bottom: 2rem;
}

.template-standard .invoice-total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
}

.template-standard .invoice-total-label {
    color: #666666;
}

.template-standard .invoice-grand-total {
    font-weight: 600;
    border-top: 2px solid #333333;
    padding-top: 0.5rem;
    margin-top: 0.5rem;
}

/* Notes and Terms */
.template-standard .invoice-notes,
.template-standard .invoice-terms {
    margin-top: 2rem;
    font-size: 0.9rem;
    color: #666666;
}

.template-standard .invoice-notes h3,
.template-standard .invoice-terms h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #333333;
    margin-bottom: 0.5rem;
}

/* Footer */
.template-standard .invoice-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    color: #666666;
    font-size: 0.9rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .template-standard {
        padding: 1rem;
    }
    
    .template-standard .invoice-header {
        flex-direction: column;
    }
    
    .template-standard .invoice-meta {
        text-align: left;
        margin-top: 1rem;
    }
    
    .template-standard .invoice-totals {
        width: 100%;
    }
}
</style>

<div class="template template-standard">
    <!-- Header -->
    <div class="invoice-header">
        <div class="company-info">
            <div class="company-logo">
                <?php if (!empty($company_info['logo'])): ?>
                    <img src="<?php echo esc_url($company_info['logo']); ?>" alt="<?php echo esc_attr($company_info['name']); ?>" class="logo-image">
                <?php endif; ?>
            </div>
            <div class="company-name"><?php echo esc_html($company_info['name']); ?></div>
            <div class="company-details">
                <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateFromSection($company_info, false, 'details-only'); ?>
            </div>
        </div>
        
        <div class="invoice-meta">
            <div class="invoice-title"><?php echo esc_html($invoice->getTitle() ?: __('Invoice', 'easy-invoice')); ?></div>
            <div class="meta-item">
                <span class="meta-label"><?php echo esc_html($text_settings['invoice_number']); ?></span>
                <span class="meta-value"><?php echo esc_html($invoice->getNumber()); ?></span>
            </div>
            <div class="meta-item">
                <span class="meta-label"><?php echo esc_html($text_settings['invoice_date']); ?></span>
                <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getIssueDate())); ?></span>
            </div>
            <div class="meta-item">
                <span class="meta-label"><?php echo esc_html($text_settings['due_date']); ?></span>
                <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($invoice->getDueDate())); ?></span>
            </div>
        </div>
    </div>

    <!-- Address Section -->
    <div class="address-section">
        <div class="address-block">
            <h2><?php echo esc_html($text_settings['to']); ?></h2>
            <div class="address-content">
                <div class="client-name"><?php echo esc_html($invoice->getCustomerName()); ?></div>
                <?php if ($invoice->getCustomerAddress()): ?>
                    <?php echo nl2br(esc_html($invoice->getCustomerAddress())); ?><br>
                <?php endif; ?>
                <?php if ($invoice->getCustomerEmail()): ?>
                    <?php echo esc_html($invoice->getCustomerEmail()); ?><br>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <!-- Invoice Items -->
    <table class="invoice-items">
        <thead>
            <tr>
                <th><?php echo esc_html($text_settings['service']); ?></th>
                <th><?php echo esc_html($text_settings['qty']); ?></th>
                <th><?php echo esc_html($text_settings['rate_price']); ?></th>
                <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField()): ?>
                <th><?php echo esc_html($text_settings['adjust']); ?> (%)</th>
                <?php endif; ?>
                <th><?php echo esc_html($text_settings['total']); ?></th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($invoice->getItems() as $item): ?>
            <tr>
                <td class="item-name">
                    <div class="item-title"><?php echo esc_html($item->getName()); ?></div>
                    <?php if ($item->getDescription()): ?>
                        <div class="item-description"><?php echo esc_html($item->getDescription()); ?></div>
                    <?php endif; ?>
                </td>
                <td class="item-quantity"><?php echo esc_html($item->getQuantity() ?: '0'); ?></td>
                <td class="item-price"><?php echo esc_html($formatter->format($item->getPrice())); ?></td>
                <?php if (\EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField()): ?>
                <td class="item-adjust"><?php 
                    $adjust_percentage = $item->getAdjustPercentage();
                    if ($adjust_percentage != 0) {
                        echo esc_html($adjust_percentage > 0 ? '+' : '') . esc_html($adjust_percentage) . '%';
                    } else {
                        echo esc_html__('—', 'easy-invoice');
                    }
                ?></td>
                <?php endif; ?>
                <td class="item-total"><?php echo esc_html($formatter->format($item->getAmount())); ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>

    <!-- Invoice Totals -->
    <div class="invoice-totals">
        <?php echo \EasyInvoice\Helpers\TemplateTextHelper::generateTotalsSection($invoice, $text_settings, $formatter, 'invoice'); ?>
    </div>

    <!-- Notes -->
    <?php if ($invoice->getNotes()): ?>
    <div class="invoice-notes">
        <h3><?php _e('Notes:', 'easy-invoice'); ?></h3>
        <div class="notes-content">
            <?php echo wp_kses_post($invoice->getNotes() ?: ''); ?>
        </div>
    </div>
    <?php endif; ?>

    <!-- Terms and Conditions -->
    <?php 
    $terms_conditions = $invoice->getTerms() ?: \EasyInvoice\Controllers\SettingsController::getInvoiceTermsConditions();
    if ($terms_conditions): 
    ?>
    <div class="invoice-terms">
        <h3><?php _e('Terms & Conditions:', 'easy-invoice'); ?></h3>
        <div class="terms-content">
            <?php echo wp_kses_post($terms_conditions); ?>
        </div>
    </div>
    <?php endif; ?>

    <!-- Footer -->
    <div class="invoice-footer">
        <?php 
        $invoice_footer_text = $invoice->getFooterText();
        if (!$invoice_footer_text) {
            $invoice_footer_text = \EasyInvoice\Controllers\SettingsController::getInvoiceFooterText();
        }
        ?>
        <p><?php echo wp_kses_post($invoice_footer_text); ?></p>
    </div>
</div> 