<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;

class CrmFileManagerController extends Controller
{
    public $roots = [
        [
            'baseUrl' => '@web',
            'basePath' => '@webroot',
            'path' => 'uploads',
            'name' => 'Uploads',
			/*
			'onlyoffice' => [
				'enabled' => true,
				'docServer' => 'https://documentserver.onlyoffice.com/',
				'jqueryUrl' => 'https://code.jquery.com/jquery-3.6.0.min.js',
			],
			*/
        ],
    ];
    
    public function actionIndex()
    {
        return $this->render('index');
    }
	
	public function getOptions()
	{
		$options = parent::getOptions();
		$options['theme'] = "dark";
		
		// Aggiungi questa configurazione
		$options['commandsOptions'] = [
			'edit' => [
				'exts' => ['txt', 'html', 'htm', 'css', 'js', 'php', 'md', 'json', 'xml', 'yml', 'yaml'],
				'mimes' => ['text/plain', 'text/html', 'text/css', 'text/javascript', 'application/json'],
				// Sovrascrivi il comportamento default
				'handler' => new \yii\web\JsExpression("
					function() {
						var file = this.file('hash');
						var url = '" . \yii\helpers\Url::to(['onlyoffice/index']) . "?file=' + encodeURIComponent(file);
						window.open(url, '_blank');
					}
				")
			]
		];
		
		return $options;
	}

}