<?php
/**
 * app/plugins/contact/controllers/admin/contact.php
 *
 * This is the contact admin controller.
 *
 * @package TP Contact
 * @version 3.0
 * @author  Joey Kimsey <Joey@thetempusproject.com>
 * @link    https://TheTempusProject.com
 * @license https://opensource.org/licenses/MIT [MIT LICENSE]
 */
namespace TheTempusProject\Controllers\Admin;

use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Navigation;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Classes\AdminController;
use TheTempusProject\Models\Contact as ContactModel;

class Contact extends AdminController {
    protected static $contact;

    public function __construct() {
        parent::__construct();
        self::$title = 'Admin - Contact';
        self::$contact = new ContactModel;
    }

    public function view( $id = null ) {
        Views::view( 'contact.admin.view', self::$contact->findById( $id ) );
    }

    public function delete( $data = null ) {
        if ( Input::exists( 'submit' ) ) {
            $data = Input::post( 'F_' );
        }
        if ( self::$contact->delete( (array) $data ) ) {
            Issues::add( 'success', 'contact deleted' );
        } else {
            Issues::add( 'error', 'There was an error with your request.' );
        }
        $this->index();
    }

    public function clear( $data = null ) {
        self::$contact->clear();
        $this->index();
    }

    public function index( $data = null ) {
        Views::view( 'contact.admin.list', self::$contact->listPaginated() );
    }
}
