<?php

namespace Storeplugin\PDFInvoice\App\Editors;

defined('ABSPATH') || exit;

use Storeplugin\PDFInvoice\Framework\Contracts\ServiceInterface;
use Storeplugin\PDFInvoice\App\Forms\PDFPanel;

class PackingSlipPanel implements ServiceInterface {
    public function register(): void
    {
        PDFPanel::create(
            'Packing Slip Editor',
            'Packing Slip Editor',
            'nxtpdf-packing-slip-editor-panel',
            'nxtpdf_packing_slip_editor',
            'manage_options',
            'dashicons-media-document',
        )
        ->withAdminSubmenu('nxtpdf-invoice-editor-panel')
        ->addGroup(function($panel) {
            $panel->addPanel([
                'title' => 'Header',
                'icon' => 'dashicons-heading',
                'fields' => [
                    [
                        'id' => 'packing_title',
                        'label' => 'Packing Slip Title',
                        'type' => 'text',
                        'default' => 'Packing Slip',
                        'placeholder' => 'PACKING SLIP',
                        'description' => 'Main title displayed on the packing slip.',
                    ],
                    [
                        'id' => 'header_text',
                        'label' => 'Header Content',
                        'type' => 'text',
                        'description' => 'Enter header text.',
                    ],
                    [
                        'id' => 'header_align',
                        'label' => 'Header Alignment',
                        'default' => 'left',
                        'type' => 'radio',
                        'options' => [
                            'left' => 'Left',
                            'center' => 'Center',
                            'right' => 'Right',
                        ],
                        'description' => 'Text alignment for header.',
                    ],
                    [
                        'id' => 'header_font_size',
                        'label' => 'Header Font Size',
                        'type' => 'number',
                        'placeholder' => '10',
                        'description' => 'Font size for header text (in pt).',
                    ],
                    [
                        'id' => 'header_color',
                        'label' => 'Header Color',
                        'default' => '#284567',
                        'type' => 'color',
                        'description' => 'Text color for header.',
                    ],
                ]
            ]);

            $panel->addPanel([
                'title' => 'Company Information',
                'icon' => 'list-view',
                'fields' => [
                    [
                        'id' => 'show_logo',
                        'label' => 'Show logo',
                        'type' => 'switch',
                        'description' => 'Enable or disable this option.',
                    ],
                    [
                        'id' => 'logo_height',
                        'label' => 'Logo Height (px)',
                        'type' => 'number',
                        'placeholder' => '150',
                        'default' => 150,
                        'min' => 10,
                        'max' => 300,
                        'step' => 1,
                        'description' => 'Maximum logo height in pixels (default: 150).',
                    ],
                    [
                        'id' => 'show_company_name',
                        'label' => 'Show company name',
                        'type' => 'switch',
                        'default' => true,
                        'description' => 'Display company name on packing slip.',
                    ],
                    [
                        'id' => 'show_company_address',
                        'label' => 'Show company address',
                        'type' => 'switch',
                        'default' => true,
                        'description' => 'Display company address (address lines, city, state, postcode, country).',
                    ],
                    [
                        'id' => 'show_company_phone',
                        'label' => 'Show company phone',
                        'type' => 'switch',
                        'description' => 'Display company phone number.',
                    ],
                    [
                        'id' => 'show_company_email',
                        'label' => 'Show company email',
                        'type' => 'switch',
                        'description' => 'Display company email address.',
                    ],
                    [
                        'id' => 'show_company_vat',
                        'label' => 'Show VAT/Tax ID',
                        'type' => 'switch',
                        'description' => 'Display VAT or Tax ID number.',
                    ],
                    [
                        'id' => 'show_company_coc',
                        'label' => 'Show CoC number',
                        'disabled' => true,
                        'type' => 'switch',
                        'description' => 'Display Chamber of Commerce number.',
                        'tip' => 'This field is currently disabled in the free version.',
                    ],
                    [
                        'id' => 'show_company_registration',
                        'label' => 'Show company registration',
                        'disabled' => true,
                        'type' => 'switch',
                        'description' => 'Display company registration number.',
                        'tip' => 'This field is currently disabled in the free version.',
                    ],
                    [
                        'id' => 'show_company_gstin',
                        'label' => 'Show GSTIN',
                        'disabled' => true,
                        'type' => 'switch',
                        'description' => 'Display GST Identification Number.',
                        'tip' => 'This field is currently disabled in the free version.',
                    ],
                    [
                        'id' => 'show_company_abn',
                        'label' => 'Show ABN',
                        'disabled' => true,
                        'type' => 'switch',
                        'description' => 'Display Australian Business Number.',
                        'tip' => 'This field is currently disabled in the free version.',
                    ],
                ]
            ]);

            $panel->addPanel([
                'title' => 'Appearance',
                'icon' => 'dashicons-art',
                'fields' => [
                    [
                        'id' => 'template_selector',
                        'label' => 'Template',
                        'type' => 'select2',
                        'placeholder' => 'Select a template',
                        'options' => [
                            'default' => 'Default',
                            'x_modern' => [
                                'label' => 'Modern',
                                'disabled' => true,
                                'title' => 'Upgrade to Pro',
                            ],
                            'elegant' => [
                                'label' => 'Elegant',
                                'disabled' => true,
                                'title' => 'Upgrade to Pro',
                            ],
                            'minimal' => [
                                'label' => 'Minimal',
                                'disabled' => true,
                                'title' => 'Upgrade to Pro',
                            ],
                            'corporate' => [
                                'label' => 'Corporate',
                                'disabled' => true,
                                'title' => 'Upgrade to Pro',
                            ],
                        ],
                        'support' => ['single', 'search'],
                        'description' => 'The free version currently includes only the Default template.',
                    ],
                ]
            ]);

            $panel->addPanel([
                'title' => 'Packing Slip Numbering',
                'icon' => 'dashicons-editor-ol',
                'fields' => [
                    [
                        'id' => 'invoice_number_mode',
                        'label' => 'Number Mode',
                        'type' => 'select2',
                        'placeholder' => 'Select mode',
                        'options' => [
                            'order_number' => 'Use Order Number',
                            'sequential' => 'Sequential Number',
                        ],
                        'support' => ['single'],
                        'description' => 'How packing slip numbers are generated.',
                    ],
                    [
                        'id' => 'invoice_number_padding',
                        'label' => 'Number Padding',
                        'disabled' => true,
                        'type' => 'number',
                        'placeholder' => '4',
                        'description' => 'Minimum digits (e.g., 4 = 0001, 0002).',
                        'tip' => 'This option is only applicable if "Sequential Number" mode is selected.',
                    ],
                    [
                        'id' => 'invoice_number_next',
                        'label' => 'Next Number',
                        'disabled' => true,
                        'type' => 'number',
                        'placeholder' => '1',
                        'description' => 'Next sequential packing slip number to use.',
                        'tip' => 'This option is only applicable if "Sequential Number" mode is selected.',
                    ],
                    [
                        'id' => 'invoice_number_reset',
                        'label' => 'Reset Counter',
                        'type' => 'radio',
                        'options' => [
                            'never' => 'Never',
                            'yearly' => 'Yearly',
                            'monthly' => 'Monthly',
                        ],
                        'description' => 'When to reset the sequential counter.',
                    ],
                ]
            ]);

            $panel->addPanel([
                'title' => 'Billing Address',
                'icon' => 'dashicons-location',
                'fields' => [
                    [
                        'id' => 'bill_to_label',
                        'label' => 'Bill To Label',
                        'type' => 'text',
                        'placeholder' => 'Bill To',
                    ],
                    [
                        'id' => 'payment_method_label',
                        'label' => 'Payment Method Label',
                        'type' => 'text',
                        'placeholder' => 'Payment Method',
                    ],
                    [
                        'id' => 'show_billing_address',
                        'label' => 'Show billing address',
                        'type' => 'switch',
                        'description' => 'Display billing address on packing slip.',
                    ],
                    [
                        'id' => 'show_billing_email',
                        'label' => 'Show billing email',
                        'type' => 'switch',
                        'description' => 'Display customer email in billing address.',
                    ],
                    [
                        'id' => 'show_billing_phone',
                        'label' => 'Show billing phone',
                        'type' => 'switch',
                        'description' => 'Display customer phone in billing address.',
                    ],
                ]
            ]);

            $panel->addPanel([
                'title' => 'Shipping Address',
                'icon' => 'dashicons-location',
                'fields' => [
                    [
                        'id' => 'ship_to_label',
                        'label' => 'Ship To Label',
                        'type' => 'text',
                        'placeholder' => 'Ship To',
                    ],
                    [
                        'id' => 'shipping_label',
                        'label' => 'Shipping Label',
                        'type' => 'text',
                        'placeholder' => 'Shipping',
                    ],
                    [
                        'id' => 'show_shipping_address',
                        'label' => 'Show shipping address',
                        'type' => 'switch',
                        'description' => 'Display shipping address on packing slip.',
                    ],
                ]
            ]);

            $panel->addPanel([
                'title' => 'Product Data',
                'icon' => 'dashicons-grid-view',
                'fields' => [
                    [
                        'id' => 'item_label',
                        'label' => 'Item Column Label',
                        'type' => 'text',
                        'placeholder' => 'Item',
                    ],
                    [
                        'id' => 'qty_label',
                        'label' => 'Quantity Column Label',
                        'type' => 'text',
                        'placeholder' => 'Qty',
                    ],
                    [
                        'id' => 'price_label',
                        'label' => 'Price Column Label',
                        'type' => 'text',
                        'placeholder' => 'Price',
                    ],
                    [
                        'id' => 'total_label',
                        'label' => 'Total Label',
                        'type' => 'text',
                        'placeholder' => 'Total',
                    ],
                    [
                        'id' => 'subtotal_label',
                        'label' => 'Subtotal Label',
                        'type' => 'text',
                        'placeholder' => 'Subtotal',
                    ],
                    [
                        'id' => 'show_sku',
                        'label' => 'Show SKU',
                        'type' => 'switch',
                        'description' => 'Display product SKU in items table.',
                    ],
                    [
                        'id' => 'show_variations',
                        'label' => 'Show variations',
                        'type' => 'switch',
                        'description' => 'Display product variation details.',
                    ],
                    [
                        'id' => 'show_item_meta',
                        'label' => 'Show item meta',
                        'type' => 'switch',
                        'description' => 'Display additional item metadata.',
                    ],
                    [
                        'id' => 'show_product_image',
                        'label' => 'Show product image',
                        'type' => 'switch',
                        'description' => 'Display product thumbnail in items table.',
                    ],
                    [
                        'id' => 'show_tax_column',
                        'label' => 'Show tax column',
                        'type' => 'switch',
                        'description' => 'Display tax amount per item.',
                    ],
                    [
                        'id' => 'show_discount_column',
                        'label' => 'Show discount column',
                        'type' => 'switch',
                        'description' => 'Display discount amount per item.',
                    ],
                    [
                        'id' => 'unit_price_source',
                        'label' => 'Unit price source',
                        'type' => 'radio',
                        'options' => [
                            'subtotal' => 'Before discount (subtotal)',
                            'total' => 'After discount (total)',
                        ],
                        'description' => 'How to calculate unit price.',
                    ],
                ]
            ]);

            $panel->addPanel([
                'title' => 'Currency Format',
                'icon' => 'dashicons-money-alt',
                'fields' => [
                    [
                        'id' => 'currency_format',
                        'label' => 'Currency display',
                        'default' => 'symbol',
                        'type' => 'radio',
                        'options' => [
                            'symbol' => 'Symbol ($, €, £)',
                            'code' => [
                                'label' => 'Code (USD, EUR, GBP)',
                                'disabled' => true,
                                'title' => 'Upgrade to Pro',
                            ],
                        ],
                        'description' => 'How to display the currency.',
                    ],
                    [
                        'id' => 'currency_position',
                        'label' => 'Currency position',
                        'default' => 'left',
                        'type' => 'select2',
                        'placeholder' => 'Select position',
                        'options' => [
                            'left' => 'Left ($99.99)',
                            'right' => [
                                'label' => 'Right (99.99$)',
                                'disabled' => true,
                                'title' => 'Upgrade to Pro',
                            ],
                            'left_space' => [
                                'label' => 'Left with space ($ 99.99)',
                                'disabled' => true,
                                'title' => 'Upgrade to Pro',
                            ],
                            'right_space' => [
                                'label' => 'Right with space (99.99 $)',
                                'disabled' => true,
                                'title' => 'Upgrade to Pro',
                            ],
                        ],
                        'support' => ['single'],
                        'description' => 'Position of currency symbol/code.',
                    ],
                    [
                        'id' => 'decimal_places',
                        'label' => 'Decimal places',
                        'default' => 2,
                        'disabled' => true,
                        'type' => 'number',
                        'placeholder' => '2',
                        'description' => 'Number of decimal places (0-4).',
                        'tip' => 'This option is currently disabled in the free version.',
                    ],
                    [
                        'id' => 'decimal_separator',
                        'label' => 'Decimal separator',
                        'type' => 'text',
                        'placeholder' => '.',
                        'description' => 'Character for decimal point.',
                    ],
                    [
                        'id' => 'thousand_separator',
                        'label' => 'Thousand separator',
                        'type' => 'text',
                        'placeholder' => ',',
                        'description' => 'Character for thousands (leave empty for none).',
                    ],
                ]
            ]);

            $panel->addPanel([
                'title' => 'Footer',
                'icon' => 'dashicons-editor-textcolor',
                'fields' => [
                    [
                        'id' => 'footer_text',
                        'label' => 'Footer Content',
                        'type' => 'textarea',
                        'description' => 'Enter footer text.',
                    ],
                    [
                        'id' => 'footer_align',
                        'label' => 'Footer Alignment',
                        'type' => 'radio',
                        'options' => [
                            'left' => 'Left',
                            'center' => 'Center',
                            'right' => 'Right',
                        ],
                        'description' => 'Text alignment for footer.',
                    ],
                    [
                        'id' => 'footer_font_size',
                        'label' => 'Footer Font Size',
                        'type' => 'number',
                        'placeholder' => '10',
                        'description' => 'Font size for footer text (in pt).',
                    ],
                    [
                        'id' => 'footer_color',
                        'label' => 'Footer Color',
                        'default' => '#284567',
                        'type' => 'color',
                        'description' => 'Text color for footer.',
                    ],
                    [
                        'id' => 'show_page_numbers',
                        'label' => 'Show Page Numbers',
                        'type' => 'switch',
                        'description' => 'Display page numbers in footer.',
                    ],
                    [
                        'id' => 'terms_title',
                        'label' => 'Terms Title',
                        'type' => 'text',
                        'placeholder' => 'Terms & Conditions',
                        'description' => 'Title for the terms section.',
                    ],
                    [
                        'id' => 'terms_text',
                        'label' => 'Terms Content',
                        'type' => 'textarea',
                        'placeholder' => 'Enter your terms and conditions...',
                        'description' => 'Terms and conditions text.',
                    ],
                    [
                        'id' => 'return_policy_title',
                        'label' => 'Return Policy Title',
                        'type' => 'text',
                        'placeholder' => 'Return Policy',
                        'description' => 'Title for the return policy section.',
                    ],
                    [
                        'id' => 'return_policy_text',
                        'label' => 'Return Policy',
                        'type' => 'textarea',
                        'placeholder' => 'Enter your return policy...',
                        'description' => 'Return policy text.',
                    ],
                    [
                        'id' => 'show_order_notes',
                        'label' => 'Show order notes',
                        'type' => 'switch',
                        'description' => 'Enable or disable this option.',
                    ],
                ]
            ]);

            $panel->addPanel([
                'title' => 'General Settings',
                'icon' => 'dashicons-editor-expand',
                'fields' => [
                    [
                        'id' => 'paper_size',
                        'label' => 'Paper size',
                        'disabled' => true,
                        'default' => 'A4',
                        'type' => 'radio',
                        'options' => ['A4' => 'A4', 'Letter' => 'Letter', 'Legal' => 'Legal'],
                        'description' => 'Select a paper size.',
                    ],
                    [
                        'id' => 'paper_orientation',
                        'label' => 'Paper orientation',
                        'disabled' => true,
                        'type' => 'radio',
                        'default' => 'P',
                        'options' => ['P' => 'Portrait', 'L' => 'Landscape'],
                        'description' => 'Select a single option.',
                    ],
                    [
                        'id' => 'page_margin_top',
                        'label' => 'Margin Top (mm)',
                        'type' => 'number',
                        'placeholder' => '15',
                        'description' => 'Top margin in millimeters.',
                    ],
                    [
                        'id' => 'page_margin_right',
                        'label' => 'Margin Right (mm)',
                        'type' => 'number',
                        'placeholder' => '15',
                        'description' => 'Right margin in millimeters.',
                    ],
                    [
                        'id' => 'page_margin_bottom',
                        'label' => 'Margin Bottom (mm)',
                        'type' => 'number',
                        'placeholder' => '15',
                        'description' => 'Bottom margin in millimeters.',
                    ],
                    [
                        'id' => 'page_margin_left',
                        'label' => 'Margin Left (mm)',
                        'type' => 'number',
                        'placeholder' => '15',
                        'description' => 'Left margin in millimeters.',
                    ],
                ]
            ]);
        })
        ->render();
    }
}
