<?php

use Illuminate\Database\Seeder;
use App\Media;
use App\MediaLocale;

use Faker\Factory;

class MediaTableSeeder extends Seeder
{
    protected $helper;

    public function __construct()
    {
        $this->helper = new App\Database\Seeds\FactoryHelper;
    }
    /**
     * Generate translations
     * 
     * @param App\Media $media
     */
    public function generateTranslations($media, $data = [])
    {
         foreach (config('translatable.locales') as $key => $value) {
             $faker = Factory::create($key);

             $media->locales()->create([
                'locale' => $key,
                'media_title' => (isset($data['title']) ? $data['title'] : ucfirst($faker->words(rand(1, 3), true))),
                'media_content' => (isset($data['content']) ? $data['content'] : '<p>'.$faker->paragraphs(rand(1, 2), true.'</p>')),
                'media_url' => '',
                'media_desc' => ''
             ]);
         }
    }

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        # Seeding media #1
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'Judul Paragraf',
            'media_content' => '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>',
            'media_url' => $this->helper->generateRandomImage('banner', 'img/home/'),
            'media_page' => 'home',
            'media_target' => 'about',
            'media_section' => 'banner-content1',
            'media_desc' => 'Banner1',
            'temp_id' => null,
        ]);
        $this->generateTranslations($media);


        # Seeding media #2
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'Judul Paragraf',
            'media_content' => '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>',
            'media_url' => $this->helper->generateRandomImage('banner', 'img/home/'),
            'media_page' => 'home',
            'media_target' => 'contact',
            'media_section' => 'banner-content2',
            'media_desc' => 'Banner2',
            'temp_id' => null,
        ]);
        $this->generateTranslations($media);

        # Seeding media #3
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'Halaman 1',
            'media_content' => '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>',
            'media_url' => 'banner_section1_20170929085609.jpg',
            'media_page' => 'section1',
            'media_section' => 'banner-header',
            'media_desc' => 'Banner Header Section1',
            'temp_id' => null,
        ]);
        $this->generateTranslations($media, ['content' => '']);

        # Seeding media #4
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'Halaman 2',
            'media_content' => '<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</p>',
            'media_url' => 'banner_section2_20170929085658.jpg',
            'media_page' => 'section2',
            'media_section' => 'banner-header',
            'media_desc' => 'Banner Header Section2',
            'temp_id' => null,
        ]);
        $this->generateTranslations($media, ['content' => '']);

        # Seeding media #5
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => '',
            'media_content' => '',
            'media_url' => 'banner_20171002084023.jpg',
            'media_page' => 'about',
            'media_section' => 'banner-header',
            'media_desc' => 'Banner Header About',
            'temp_id' => null,
        ]);

        # Seeding media #6
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => '',
            'media_content' => '',
            'media_url' => 'banner_20171002085957.jpg',
            'media_page' => 'contact',
            'media_section' => 'banner-header',
            'media_desc' => 'Banner Header Contact',
            'temp_id' => null,
        ]);

        # Seeding media #10
        $media = Media::create([
            'media_type' => 'video',
            'media_title' => 'Judul 1',
            'media_content' => '<p style="text-align: justify;">[ID] 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.</p>',
            'media_url' => 'https://www.youtube.com/embed/ojQbArbuN4E',
            'media_page' => 'about',
            'media_section' => 'content',
            'media_desc' => 'About Content',
            'temp_id' => 1,
        ]);
        $this->generateTranslations($media);

        # Seeding media #12
        $media = Media::create([
            'media_type' => 'video',
            'media_title' => 'Judul 1',
            'media_content' => '<p>[ID] 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.</p>',
            'media_url' => 'https://www.youtube.com/embed/irOrWnomL1k',
            'media_page' => 'section1',
            'media_section' => 'content',
            'media_desc' => 'Section1 Content',
            'temp_id' => 1,
        ]);
        $this->generateTranslations($media);

        # Seeding media #14
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'Judul 1',
            'media_content' => '<p>[ID] 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.</p>',
            'media_url' => 'content_section2_20170929085739.jpg',
            'media_page' => 'section2',
            'media_section' => 'content',
            'media_desc' => 'Section2 Content',
            'temp_id' => null,
        ]);
        $this->generateTranslations($media);

        # Seeding media #15
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'Judul 2',
            'media_content' => '<p>[ID] 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.</p>',
            'media_url' => 'content_section2_20170929085813.jpg',
            'media_page' => 'section2',
            'media_section' => 'content',
            'media_desc' => 'Section2 Content',
            'temp_id' => null,
        ]);
        $this->generateTranslations($media);

        # Seeding media #21
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'Judul Konten',
            'media_content' => '<p>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.</p>',
            'media_url' => 'card_20170927084442.jpg',
            'media_page' => 'home',
            'media_section' => 'card',
            'media_desc' => 'Kartu 1',
            'temp_id' => 1,
        ]);
        $this->generateTranslations($media);

        # Seeding media #22
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'Judul Konten',
            'media_content' => '<p>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.</p>',
            'media_url' => 'card_20170927084502.jpg',
            'media_page' => 'home',
            'media_section' => 'card',
            'media_desc' => 'Kartu 2',
            'temp_id' => 2,
        ]);
        $this->generateTranslations($media);

        # Seeding media #24
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'Judul Konten',
            'media_content' => 'Thank you for ordering, your order will be processed soon, please contact us anytime.',
            'media_url' => null,
            'media_page' => 'order',
            'media_section' => 'email-text',
            'media_desc' => 'custom text for email to customer',
            'temp_id' => null,
        ]);
        $this->generateTranslations($media, ['title' => '']);

        # Seeding media #27
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => '',
            'media_content' => '',
            'media_url' => 'carousel_20170927072453.jpg',
            'media_page' => 'home',
            'media_section' => 'carousel',
            'media_desc' => '',
            'temp_id' => 2,
        ]);
        $this->generateTranslations($media, ['content' => '']);

        # Seeding media #28
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => '',
            'media_content' => '',
            'media_url' => 'card_20170927084422.jpg',
            'media_page' => 'home',
            'media_section' => 'card',
            'media_desc' => '',
            'temp_id' => 3,
        ]);
        $this->generateTranslations($media);

        # Seeding media #29
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => '',
            'media_content' => '',
            'media_url' => 'carousel_5a17cd7508a49.jpg',
            'media_page' => 'home',
            'media_section' => 'carousel',
            'media_desc' => '',
            'temp_id' => 1,
        ]);
        $this->generateTranslations($media, ['content' => '']);

        # Seeding media #30
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => '',
            'media_content' => '',
            'media_url' => 'carousel_20170927101209.jpg',
            'media_page' => 'home',
            'media_section' => 'carousel',
            'media_desc' => '',
            'temp_id' => 3,
        ]);
        $this->generateTranslations($media, ['content' => '']);

        # Seeding media #36
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'The Title 2',
            'media_content' => '<p style="text-align: justify;">[EN] 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.</p>',
            'media_url' => 'content_section1_20171002041250.jpg',
            'media_page' => 'section1',
            'media_section' => 'content',
            'media_desc' => 'Section1 Content',
            'temp_id' => 2,
        ]);
        $this->generateTranslations($media);
        
        # Seeding media #37
        $media = Media::create([
            'media_type' => 'image',
            'media_title' => 'The Title 2',
            'media_content' => '<p style="text-align: justify;">[EN] 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.</p>',
            'media_url' => 'content_20171002041341.jpg',
            'media_page' => 'about',
            'media_section' => 'content',
            'media_desc' => 'About Content',
            'temp_id' => 2,
        ]);
        $this->generateTranslations($media);

        # Seeding media #39
        $media = Media::create([
            'media_type' => 'gallery',
            'media_title' => 'Judul 3',
            'media_content' => '<p style="text-align: justify;">[EN] 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.</p>',
            'media_url' => '1',
            'media_page' => 'section1',
            'media_section' => 'content',
            'media_desc' => 'Section1 Content',
            'temp_id' => 3,
        ]);
        $this->generateTranslations($media);
        
    }
}
