<?php namespace TPS\Birzha\Components;

use Cms\Classes\ComponentBase;
use TPS\Birzha\Models\Product;
use Input;
use Flash;

class MyComments extends ComponentBase
{
    /**
     * @var Collection A collection of user's posts
     */
    public $comments;
    
    
    public function componentDetails()
    {
        return [
            'name'        => 'MyComments List',
            'description' => 'List of my comments'
        ];
    }

    public function defineProperties()
    {
        return [
            'perPage' => [
                'title' => 'Number of offers',
                'description' => 'How many offers do you want to display',
                'default' => 12,
                'validationPattern' => '^[0-9]+$',
                'validationMessage' => 'Only numbers allowed'
            ],
        ];
    }


    public function onRun() {
        $this->comments = $this->loadComments();
    }

    protected function loadComments() {
        $perPage = $this->property('perPage');
        return \Auth::user()->comments()
            ->orderBy('updated_at', 'desc')
            ->paginate($perPage);
    }

    
}
