<?php

namespace Workdo\LandingPage\Database\Seeders;

use Illuminate\Database\Seeder;
use Workdo\LandingPage\Models\LandingPageSetting;
use Illuminate\Support\Facades\Log;

class LandingPageSettingSeeder extends Seeder
{
    public function run()
    {
        if (LandingPageSetting::exists()) {
            return;
        }

        try {
            LandingPageSetting::create($this->getDefaultSettings());
        } catch (\Exception $e) {
            Log::error('Failed to seed landing page settings: ' . $e->getMessage());
            throw $e;
        }
    }

    private function getDefaultSettings(): array
    {
        return [
            'company_name' => 'AccountGo',
            'contact_email' => 'support@accountgo.com',
            'contact_phone' => '+1 (555) 123-4567',
            'contact_address' => '123 Business Ave, City, State 12345',
            'config_sections' => $this->getDefaultConfigSections()
        ];
    }

    private function getDefaultConfigSections(): array
    {
        return [
            'sections' => $this->getDefaultSections(),
            'section_visibility' => $this->getDefaultVisibility(),
            'section_order' => $this->getDefaultOrder(),
            'colors' => $this->getDefaultColors()
        ];
    }

    private function getDefaultSections(): array
    {
        return [
            'hero' => [
                'variant' => 'hero1',
                'title' => 'Streamline Your Business Finances',
                'subtitle' => 'A comprehensive accounting solution designed for efficiency and growth. Manage your organization\'s finances with precision.',
                'primary_button_text' => 'Login',
                'primary_button_link' => route('login'),
                'secondary_button_text' => 'Contact Us',
                'secondary_button_link' => '#contact',
                'highlight_text' => 'AccountGo',
                'image' => 'packages/workdo/LandingPage/src/Resources/assets/img/hero.png'
            ],
            'header' => [
                'variant' => 'header1',
                'company_name' => 'AccountGo',
                'cta_text' => 'Get Started',
                'navigation_items' => [
                    ['text' => 'Home', 'href' => route('landing.page')]
                ]
            ],
            'stats' => [
                'variant' => 'stats1',
                'stats' => [
                    ['label' => 'Businesses Trust Us', 'value' => '10,000+'],
                    ['label' => 'Uptime Guarantee', 'value' => '99.9%'],
                    ['label' => 'Customer Support', 'value' => '24/7'],
                    ['label' => 'Countries Worldwide', 'value' => '50+']
                ]
            ],
            'features' => [
                'variant' => 'features1',
                'title' => 'Powerful Financial Features',
                'subtitle' => 'Everything your business needs to manage finances, inventory, and growth in one integrated platform',
                'features' => $this->getDefaultFeatures()
            ],
            'modules' => [
                'variant' => 'modules1',
                'title' => 'Complete Business Modules',
                'subtitle' => 'Discover our comprehensive modules designed to streamline every aspect of your business operations',
                'modules' => [
                    [
                        'key' => 'account',
                        'label' => 'Accounting',
                        'title' => 'Comprehensive Financial Management',
                        'description' => 'Experience the precision of a fully integrated double-entry accounting system deeply integrated into your daily operations. Automate complex bookkeeping tasks, manage comprehensive accounts payable and receivable, and generate detailed financial reports on demand. From real-time balance sheets to granular profit and loss statements, gain a 360-degree view of your organization\'s financial health, ensuring every decision is backed by accurate data.',
                        'image' => 'packages/workdo/LandingPage/src/Resources/assets/img/accounting.png'
                    ],
                    [
                        'key' => 'retainer',
                        'label' => 'Retainer',
                        'title' => 'Advanced Retainer Management',
                        'description' => 'Optimize your recurring revenue streams with our advanced retainer management module. Effortlessly track advance payments, manage billing cycles, and monitor consumption against retainer balances in real-time. Designed for service-based businesses, this tool handles the intricacies of retainer agreements, ensuring transparent billing and fostering stronger, long-term client relationships.',
                        'image' => 'packages/workdo/LandingPage/src/Resources/assets/img/retainer.png'
                    ],
                    [
                        'key' => 'contract',
                        'label' => 'Contract',
                        'title' => 'Digital Contract Lifecycle',
                        'description' => 'Digitize your entire contract lifecycle with our end-to-end management solution. Draft professional agreements using customizable templates, track approval workflows, and securely store signed documents. With automated alerts for key dates and renewals, you can ensure compliance and never miss a critical deadline, keeping your business legally secure and operationally efficient.',
                        'image' => 'packages/workdo/LandingPage/src/Resources/assets/img/contracts.png'
                    ],
                    [
                        'key' => 'asset',
                        'label' => 'Assets',
                        'title' => 'Strategic Asset Tracking',
                        'description' => 'Maximize the return on your capital investments with intelligent asset management specific to your organizational needs. Monitor the complete lifecycle of every asset from acquisition to disposal. Our system automatically handles complex depreciation calculations, schedules preventive maintenance, and tracks asset locations, helping you prevent loss and optimize resource utilization across all departments.',
                        'image' => 'packages/workdo/LandingPage/src/Resources/assets/img/assets.png'
                    ],
                    [
                        'key' => 'budget',
                        'label' => 'Budget',
                        'title' => 'Precision Budget Planning',
                        'description' => 'Drive financial discipline and strategic growth with our dynamic budgeting module. Set precise financial targets for every department and project. Monitor actual spending against budgets in real-time, receiving instant variance alerts that allow you to pivot strategies immediately. Empower your managers to make cost-effective decisions without compromising operational quality.',
                        'image' => 'packages/workdo/LandingPage/src/Resources/assets/img/budget.png'
                    ]
                ]
            ],
            'benefits' => [
                'variant' => 'benefits1',
                'title' => 'Why Use AccountGo?',
                'benefits' => [
                    ['title' => 'Professional Double-Entry Precision', 'description' => 'Ensure absolute accuracy in your financial records with our robust double-entry system. Every transaction is automatically balanced for bulletproof audit trails. Our system validates every entry to prevent errors, giving you peace of mind during tax season and financial audits.'],
                    ['title' => 'Strategic Asset Life-Cycle Management', 'description' => 'Maximize the value of company investments. Track acquisitions, calculate depreciation methods, and schedule proactive maintenance efficiently. By extending the useful life of your equipment and reducing downtime, you significantly lower your long-term capital expenditure.'],
                    ['title' => 'Dynamic Budget Planning & Analysis', 'description' => 'Control your fiscal future. Set granular budgets for departments or projects and monitor spending in real-time with variance alerts. This proactive approach to financial planning ensures that resources are allocated where they are needed most, driving sustainable growth.'],
                    ['title' => 'Unified Business Module Ecosystem', 'description' => 'Breakdown silos between business functions. Integrated modules for Accounting, Retainer billing, and Contracts provide a unified data source. When all your financial and operational data lives in one interconnected platform, you eliminate duplicate entry and ensure everyone works from the same truth.'],
                    ['title' => 'Seamless Payment Integration', 'description' => 'Process payments effortlessly with built-in support for multiple methods. Automate payment collection and reconcile transactions automatically. Drastically reduce administrative overhead by automating the entire accounts receivable process, improving your cash flow and reducing days sales outstanding.'],
                    ['title' => 'Powerful Reporting & Analytics', 'description' => 'Make informed decisions with comprehensive financial reports. Generate Balance Sheets, P&L statements, and custom analytics instantly. Transform raw data into actionable insights with drill-down capabilities that reveal the underlying trends driving your business performance.']
                ]
            ],
            'gallery' => [
                'variant' => 'gallery1',
                'title' => 'Sleek Operational Interface',
                'subtitle' => 'Visualize your financial performance with our intuitive and customizable interface',
                'images' => [
                    'packages/workdo/LandingPage/src/Resources/assets/img/gallery1.jpeg',
                    'packages/workdo/LandingPage/src/Resources/assets/img/gallery2.jpeg',
                    'packages/workdo/LandingPage/src/Resources/assets/img/gallery3.jpeg',
                    'packages/workdo/LandingPage/src/Resources/assets/img/gallery4.jpeg'
                ]
            ],
            'cta' => [
                'variant' => 'cta1',
                'title' => 'Empower Your Financial Team',
                'subtitle' => 'Experience the power of professional accounting tools designed for modern business operations.',
                'primary_button' => 'Login',
                'secondary_button' => 'Contact Support'
            ],
            // 'pricing' => [
            //     'title' => 'Flexible Pricing Plans',
            //     'subtitle' => 'Choose the perfect subscription plan for your business needs',
            //     'default_subscription_type' => 'pre-package',
            //     'default_price_type' => 'monthly',
            //     'show_pre_package' => true,
            //     'show_monthly_yearly_toggle' => true,
            //     'empty_message' => 'No plans available. Check back later for new pricing plans.'
            // ],
            'footer' => [
                'variant' => 'footer1',
                'description' => 'The complete financial management solution for modern enterprises.',
                'email' => 'support@accountgo.com',
                'phone' => '+1 (555) 123-4567',
                'newsletter_title' => 'Stay Updated',
                'newsletter_description' => 'Subscribe to our newsletter for the latest accounting tips and updates.',
                'newsletter_button_text' => 'Subscribe',
                'copyright_text' => '',
                'navigation_sections' => [
                    [
                        'title' => 'Product',
                        'links' => [
                            ['text' => 'Features', 'href' => '#features'],
                            ['text' => 'Demo', 'href' => '#demo']
                        ]
                    ],
                    [
                        'title' => 'Company',
                        'links' => [
                            ['text' => 'About', 'href' => '#about'],
                            ['text' => 'Contact', 'href' => '#contact'],
                            ['text' => 'Support', 'href' => '#support']
                        ]
                    ]
                ]
            ]
        ];
    }

    private function getDefaultFeatures(): array
    {
        return [
            ['title' => 'Double Entry Accounting', 'description' => 'Maintain impeccable financial records with our industry-standard double-entry ledger system, designed to ensure every transaction is perfectly balanced and audit-ready for total compliance.', 'icon' => 'BookOpen'],
            ['title' => 'Contract Management', 'description' => 'Streamline your legal workflows by creating, tracking, and managing all business contracts digitally. Set automated reminders for renewals and keep all documents secure.', 'icon' => 'FileText'],
            ['title' => 'Budget Planning', 'description' => 'Take command of your company\'s financial future with robust budgeting tools. Analyze variance in real-time and adjust departmental allocations to maximize efficiency.', 'icon' => 'PieChart'],
            ['title' => 'Asset Tracking', 'description' => 'Gain complete visibility over your physical and functional assets. Automatically calculate depreciation, track location history, and schedule maintenance to prolong asset lifecycles.', 'icon' => 'Monitor'],
            ['title' => 'Goal Tracking', 'description' => 'Define clear financial targets and monitor progress with dynamic, real-time dashboards. Empower your teams to stay aligned with organizational objectives through visual performance indicators.', 'icon' => 'Target'],
            ['title' => 'Retainer Invoicing', 'description' => 'Simplify long-term client engagements with automated retainer invoicing. Track usage against pre-paid amounts and generate transparent reports to build trust with your clients.', 'icon' => 'Repeat']
        ];
    }

    private function getDefaultVisibility(): array
    {
        return [
            'header' => true,
            'hero' => true,
            'stats' => true,
            'features' => true,
            'modules' => true,
            'benefits' => true,
            'gallery' => true,
            'cta' => true,
            'footer' => true,
        ];
    }

    private function getDefaultOrder(): array
    {
        return ['header', 'hero', 'stats', 'features', 'modules', 'benefits', 'gallery', 'cta', 'footer'];
    }

    private function getDefaultColors(): array
    {
        return [
            'primary' => '#10b77f',
            'secondary' => '#059669',
            'accent' => '#065f46'
        ];
    }
}