<?php
/**
 * Corporate Template - Business-Focused Design
 * Professional, corporate, and business-oriented invoice template
 */

$text_settings = \EasyInvoice\Helpers\TemplateTextHelper::getInvoiceTextSettings();
$company_info = \EasyInvoice\Helpers\TemplateTextHelper::getCompanyInfo();
?>
<style>
/* Corporate Template - Business-Focused Design */
:root {
    --primary-color: #1e3a8a;
    --primary-light: #3b82f6;
    --primary-dark: #1e40af;
    --secondary-color: #64748b;
    --accent-color: #f59e0b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: #cbd5e1;
    --border-light: #e2e8f0;
    --background-primary: #ffffff;
    --background-secondary: #f8fafc;
    --background-accent: #f1f5f9;
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-family-heading: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
    --font-size-4xl: 2.25rem;
    
    --spacing-1: 0.25rem;
    --spacing-2: 0.5rem;
    --spacing-3: 0.75rem;
    --spacing-4: 1rem;
    --spacing-5: 1.25rem;
    --spacing-6: 1.5rem;
    --spacing-8: 2rem;
    --spacing-10: 2.5rem;
    --spacing-12: 3rem;
    --spacing-16: 4rem;
    --spacing-20: 5rem;
    
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
    --radius-2xl: 1rem;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
}

.template-corporate {
    font-family: var(--font-family);
    background: var(--background-primary);
    color: var(--text-primary);
    max-width: 1000px;
    margin: 0 auto;
    padding: var(--spacing-8);
    box-shadow: var(--shadow-2xl);
    border-radius: var(--radius-2xl);
    line-height: 1.6;
    position: relative;
    overflow: hidden;
}

.template-corporate::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    background: var(--primary-color);
}

/* Header Section */
.template-corporate .invoice-header {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--spacing-8);
    margin-bottom: var(--spacing-12);
    padding-bottom: var(--spacing-8);
    border-bottom: 3px solid var(--border-light);
    position: relative;
}

.template-corporate .invoice-header::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 120px;
    height: 3px;
    background: var(--primary-color);
    border-radius: var(--radius-sm);
}

.template-corporate .company-info {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
}

.template-corporate .company-logo {
    margin-bottom: 0;
}

.template-corporate .logo-image {
    max-height: 60px;
    max-width: 200px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.template-corporate .company-name {
    font-family: var(--font-family-heading);
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--spacing-3);
    line-height: 1.2;
}

.template-corporate .company-details {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.5;
}

.template-corporate .invoice-meta {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-4);
    background: var(--background-secondary);
    padding: var(--spacing-6);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    min-width: 300px;
    box-shadow: var(--shadow-md);
}

.template-corporate .invoice-title {
    font-family: var(--font-family-heading);
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: var(--spacing-4);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: -0.025em;
}

.template-corporate .meta-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-3) 0;
    border-bottom: 1px solid var(--border-light);
}

.template-corporate .meta-item:last-child {
    border-bottom: none;
}

.template-corporate .meta-label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: 500;
}

.template-corporate .meta-value {
    font-size: var(--font-size-base);
    color: var(--text-primary);
    font-weight: 600;
}

/* Address Section */
.template-corporate .address-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-8);
    margin-bottom: var(--spacing-12);
}

.template-corporate .address-block {
    background: var(--background-secondary);
    padding: var(--spacing-6);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.template-corporate .address-block::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-color);
}

.template-corporate .address-block h2 {
    font-family: var(--font-family-heading);
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-4);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.template-corporate .client-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: var(--font-size-base);
    margin-bottom: var(--spacing-2);
}

.template-corporate .address-content {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.5;
}

/* Invoice Items Table */
.template-corporate .invoice-items {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--spacing-12);
    background: var(--background-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.template-corporate .invoice-items th {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
    text-align: left;
    padding: var(--spacing-4) var(--spacing-6);
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.template-corporate .invoice-items td {
    padding: var(--spacing-4) var(--spacing-6);
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
}

.template-corporate .invoice-items tr:last-child td {
    border-bottom: none;
}

.template-corporate .invoice-items tr:hover {
    background: var(--background-accent);
}

.template-corporate .item-name .item-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-1);
}

.template-corporate .item-description {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    line-height: 1.4;
    font-weight: normal;
}

.template-corporate .item-quantity,
.template-corporate .item-price,
.template-corporate .item-total {
    text-align: right;
    font-weight: 500;
    color: var(--text-primary);
}

/* Invoice Totals */
.template-corporate .invoice-totals {
    margin-left: auto;
    width: 400px;
    background: var(--background-secondary);
    padding: var(--spacing-8);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}

.template-corporate .invoice-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-3) 0;
    border-bottom: 1px solid var(--border-light);
}

.template-corporate .invoice-total-row:last-child {
    border-bottom: none;
}

.template-corporate .invoice-total-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.template-corporate .invoice-total-value {
    font-weight: 600;
    color: var(--text-primary);
}

.template-corporate .invoice-grand-total {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--primary-color);
    border-top: 2px solid var(--primary-color);
    padding-top: var(--spacing-4);
    margin-top: var(--spacing-4);
}

/* Notes Section */
.template-corporate .invoice-notes {
    margin-top: var(--spacing-8);
    padding: var(--spacing-6);
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.template-corporate .invoice-notes h3 {
    font-family: var(--font-family-heading);
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-3);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: var(--spacing-2);
}

.template-corporate .notes-content {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.6;
}

.template-corporate .invoice-terms {
    margin-top: var(--spacing-8);
    padding: var(--spacing-6);
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.template-corporate .invoice-terms h3 {
    font-family: var(--font-family-heading);
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-3);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: var(--spacing-2);
}

.template-corporate .terms-content {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.6;
}

/* Footer */
.template-corporate .invoice-footer {
    margin-top: var(--spacing-8);
    padding-top: var(--spacing-6);
    border-top: 2px solid var(--border-light);
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.template-corporate .invoice-footer p {
    margin: 0;
    font-size: var(--font-size-sm);
    opacity: 0.9;
}

/* Responsive Design */
@media (max-width: 768px) {
    .template-corporate {
        padding: var(--spacing-4);
    }
    
    .template-corporate .invoice-header {
        grid-template-columns: 1fr;
        gap: var(--spacing-6);
    }
    
    .template-corporate .invoice-meta {
        min-width: auto;
    }
    
    .template-corporate .address-section {
        grid-template-columns: 1fr;
        gap: var(--spacing-6);
    }
    
    .template-corporate .invoice-totals {
        width: 100%;
    }
}
</style>

<div class="template template-corporate">
    <!-- 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> 