<?php
/**
 * Minimalist Quote Template - Clean & Simple Design
 * Minimalist, clean, and simple quote template
 */

$text_settings = \EasyInvoice\Helpers\TemplateTextHelper::getQuoteTextSettings();
$company_info = \EasyInvoice\Helpers\TemplateTextHelper::getCompanyInfo();
// Ensure a formatter is available
if (!isset($formatter) || !$formatter) {
    $formatter = new \EasyInvoice\Helpers\QuoteFormatter($quote ?? null);
}
?>
<style>
/* Minimalist Quote Template - Clean & Simple Design */
:root {
    --primary-color: #374151;
    --primary-light: #6b7280;
    --primary-dark: #1f2937;
    --secondary-color: #9ca3af;
    --accent-color: #3b82f6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border-color: #d1d5db;
    --border-light: #e5e7eb;
    --background-primary: #ffffff;
    --background-secondary: #f9fafb;
    --background-accent: #f3f4f6;
    
    --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);
}

.template-minimalist {
    font-family: var(--font-family);
    background: var(--background-primary);
    color: var(--text-primary);
    max-width: 800px;
    margin: 0 auto;
    padding: var(--spacing-8);
    line-height: 1.6;
}

/* Header Section */
.template-minimalist .quote-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-12);
    padding-bottom: var(--spacing-8);
    border-bottom: 1px solid var(--border-light);
}

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

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

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

.template-minimalist .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-minimalist .company-details {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.5;
}

.template-minimalist .quote-meta {
    text-align: right;
    min-width: 200px;
}

.template-minimalist .quote-title {
    font-family: var(--font-family-heading);
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-4);
}

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

.template-minimalist .meta-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

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

.template-minimalist .meta-value {
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    font-weight: 500;
}

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

.template-minimalist .address-block h2 {
    font-family: var(--font-family-heading);
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-3);
}

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

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

/* Quote Items Table */
.template-minimalist .quote-items {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--spacing-12);
    background: var(--background-primary);
    border: 1px solid var(--border-color);
}

.template-minimalist .quote-items th {
    background: var(--background-secondary);
    color: var(--text-primary);
    font-weight: 600;
    text-align: left;
    padding: var(--spacing-3) var(--spacing-4);
    font-size: var(--font-size-sm);
    border-bottom: 1px solid var(--border-color);
}

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

.template-minimalist .quote-items tr:last-child td {
    border-bottom: none;
}

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

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

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

/* Quote Totals */
.template-minimalist .quote-totals {
    margin-left: auto;
    width: 300px;
    background: var(--background-secondary);
    padding: var(--spacing-6);
    border: 1px solid var(--border-color);
}

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

.template-minimalist .quote-total-row:last-child {
    border-bottom: none;
}

.template-minimalist .quote-total-label {
    font-weight: 400;
    color: var(--text-secondary);
}

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

.template-minimalist .quote-grand-total {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--text-primary);
    border-top: 2px solid var(--border-color);
    padding-top: var(--spacing-3);
    margin-top: var(--spacing-3);
}

/* Notes Section */
.template-minimalist .quote-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-minimalist .quote-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-minimalist .notes-content {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.6;
}

.template-minimalist .quote-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-minimalist .quote-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-minimalist .terms-content {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.6;
}

.template-minimalist .quote-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);
}

/* Footer */
.template-minimalist .quote-footer p {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

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

<div class="template template-minimalist">
    <!-- Header -->
    <div class="quote-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="quote-meta">
            <div class="quote-title"><?php echo esc_html($quote->getTitle() ?: __('Quote', 'easy-invoice')); ?></div>
            <div class="meta-item">
                <span class="meta-label"><?php echo esc_html($text_settings['quote_number']); ?></span>
                <span class="meta-value"><?php echo esc_html($quote->getNumber()); ?></span>
            </div>
            <div class="meta-item">
                <span class="meta-label"><?php echo esc_html($text_settings['quote_date']); ?></span>
                <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($quote->getIssueDate())); ?></span>
            </div>
            <div class="meta-item">
                <span class="meta-label"><?php echo esc_html($text_settings['valid_until']); ?></span>
                <span class="meta-value"><?php echo esc_html(\EasyInvoice\Controllers\SettingsController::formatDate($quote->getExpiryDate())); ?></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($quote->getCustomerName()); ?></div>
                <?php if ($quote->getCustomerAddress()): ?>
                    <?php echo nl2br(esc_html($quote->getCustomerAddress())); ?><br>
                <?php endif; ?>
                <?php if ($quote->getCustomerEmail()): ?>
                    <?php echo esc_html($quote->getCustomerEmail()); ?><br>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <!-- Quote Description -->
    <?php if ($quote->getDescription()): ?>
    <div class="quote-description" style="margin-bottom: 1.5rem;">
        <div class="description-content" style="color:#6b7280; line-height:1.6; font-size:0.875rem; white-space:pre-wrap;">
            <?php echo wp_kses_post($quote->getDescription()); ?>
        </div>
    </div>
    <?php endif; ?>

    <!-- Quote Items -->
    <table class="quote-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::shouldShowQuoteAdjustField()): ?>
                <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 ($quote->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::shouldShowQuoteAdjustField()): ?>
                <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>

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

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

    <!-- Terms and Conditions -->
    <?php 
    $terms_conditions = $quote->getTerms() ?: \EasyInvoice\Controllers\SettingsController::getQuoteTermsConditions();
    if ($terms_conditions): 
    ?>
    <div class="quote-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="quote-footer">
        <?php 
        $footer_text = $quote->getFooterText();
        if (!$footer_text) {
            $footer_text = \EasyInvoice\Controllers\SettingsController::getQuoteFooterText();
        }
        ?>
        <p><?php echo wp_kses_post($footer_text); ?></p>
    </div>
</div> 