<?php

namespace GriffinForms\Admin\App;

final class JavaScripts extends \GriffinForms\Admin\App\Format
{
    protected $file_names;
    protected $enqueue_files;
    protected $enqueue_cdn_files;

    protected function setFileNames()
    {
        $dir =  $this->config->getRootPath() . 'admin/js/app/';
        $this->file_names = array_diff(scandir($dir), array('..', '.'));
    }

    protected function setEnqueueFiles()
    {
        if (empty($this->file_names)) {
            return;
        }

        foreach ($this->file_names as $file_name) {
            if (pathinfo($file_name, PATHINFO_EXTENSION) !== 'js') {
                continue;
            }
            $src = $this->config->getRootUrl() . 'admin/js/app/' . $file_name;
            $handle = str_replace('.js', '', $file_name);
            $file = $this->config->getRootPath() . 'admin/js/app/' . $file_name;
            $version = file_exists($file) ? (string) filemtime($file) : '1.0';
            wp_enqueue_script($handle, $src, [], $version, false);
        }
    }

    protected function setEnqueueCdnFiles()
    {

    }
}
