<?php

use Illuminate\Database\Seeder;
use App\General;
use App\GeneralLocale;
use Faker\Factory;

class GeneralTableSeeder extends Seeder
{

    /**
     * Generate translations
     * 
     * @param App\General $general
     */
    public function generateTranslations($general, $data = [])
    {
         foreach (config('translatable.locales') as $key => $value) {
             $faker = Factory::create($key);

             $general->locales()->create([
                'locale' => $key,
                'general_title' => (isset($data['title']) ? $data['title'] : $faker->sentence),
                'general_content' => (isset($data['content']) ? $data['content'] : '<p>'.$faker->paragraphs(rand(2, 3), true.'</p>')),
                'general_url' => '',
                'general_desc' => ''
             ]);
         }
    }

    /**
     * Run the database seeder
     */

    public function run()
    {
        $general = General::create([
            'general_title' => '',
            'general_content' => 'my best slogan',
            'general_url' => 'section1',
            'general_page' => 'home',
            'general_section' => 'divider1',
            'general_desc' => 'Divider Home #1',
            'temp_id' => null
        ]);

        $this->generateTranslations($general, ['content' => 'Divider 1', 'title' => '']);

        $general = General::create([
            'general_title' => '',
            'general_content' => 'my best slogan',
            'general_url' => '',
            'general_page' => 'home',
            'general_section' => 'featured-product',
            'general_desc' => 'Featured Products',
            'temp_id' => null
        ]);

        $this->generateTranslations($general, ['title' => 'Top Collection', 'content' => '']);

        $general = General::create([
            'general_title' => '',
            'general_content' => 'Moto atau slogan perusahaan',
            'general_url' => 'section2',
            'general_page' => 'home',
            'general_section' => 'divider2',
            'general_desc' => 'Divider Home #2',
            'temp_id' => null
        ]);

        $this->generateTranslations($general, ['title' => '', 'content' => 'Divider 2']);

        $general = General::create([
            'general_title' => 'Judul Pembuka / Selamat datang',
            'general_content' => '<p style="text-align: center;">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>',
            'general_url' => 'about',
            'general_page' => 'home',
            'general_section' => 'content',
            'general_desc' => 'Divider Home #2',
            'temp_id' => null
        ]);

        $this->generateTranslations($general, ['title' => 'Welcome']);

    }
}
