<?php

if (!class_exists('STylemixAnnouncements')) {
	class STylemixAnnouncements
	{
		public $apiurl = 'https://stylemixthemes.com/api/announcement.json';
		public $announcement = array();

		function __construct()
		{
			add_action('wp_dashboard_setup', array($this, 'dashboard_changelog'));
			add_action('wp_dashboard_setup', array($this, 'dashboard_news'));
			add_action('admin_enqueue_scripts', array($this, 'scripts'));
		}

		function dashboard_changelog()
		{
			add_meta_box('pearl_dashboard_announcement', 'Announcement by StylemixThemes', array($this, 'announcement_screen'), 'dashboard', 'side', 'high');
		}

		function dashboard_news()
		{
			add_meta_box('pearl_dashboard_news', 'News by StylemixThemes', array($this, 'news_screen'), 'dashboard', 'side', 'high');
		}

		function announcement_screen()
		{ ?>
            <div id="pearl-announcement">
                <div v-for="announcement in announcements">
                    <div v-html="announcement.content"></div>
                </div>
            </div>
		<?php }

		function news_screen()
		{ ?>
            <div id="pearl-changelog">
                <ul>
                    <li v-for="item in news">
                        <a v-bind:href="item.link" v-html="item.title.rendered" target="_blank"></a>
                    </li>
                </ul>
                <p class="community-events-footer">
                    <a href="https://themeforest.net/user/stylemixthemes/portfolio?ref=stylemixthemes" target="_blank">Themes
                        <span aria-hidden="true" class="dashicons dashicons-external"></span>
                    </a>
                    <a href="https://stylemixthemes.com/wp?utm_source=dashnotice" target="_blank">Blog
                        <span aria-hidden="true" class="dashicons dashicons-external"></span>
                    </a>
                </p>
            </div>
		<?php }

		function scripts($hook)
		{
			if ($hook == 'index.php') {
				$theme_info = time();
				$assets = STM_LMS_URL . 'announcement/assets/';
				wp_enqueue_style('milligram', $assets . 'custom.css', null, $theme_info, 'all');

				wp_enqueue_script('vue.js', $assets . 'vue.min.js', null, $theme_info, true);
				wp_enqueue_script('vue-resource.js', $assets . 'vue-resource.js', array('vue.js'), $theme_info, true);
				wp_enqueue_script('pearl-vue.js', $assets . 'vue.js', array('vue.js'), $theme_info, true);
			}
		}
	}

	new STylemixAnnouncements();
}