<?php

namespace GriffinForms\Admin\App;

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

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

    protected function setEnqueueFiles()
    {
        wp_enqueue_style(
            'griffinforms-app-inter-font',
            $this->config->getRootUrl() . 'external/fonts/inter/inter.css',
            [],
            '18.0',
            false
        );

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

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