<?php

/** @var \App\Assets $assets */
$this->layout(
    'main',
    [
        'title' => __('Music Files'),
        'manual' => true,
        'page_class' => 'page-file-manager',
    ]
);

/** @var App\Http\RouterInterface $router */
$props = [
    'listUrl' => (string)$router->fromHere('api:stations:files:list'),
    'batchUrl' => (string)$router->fromHere('api:stations:files:batch'),
    'uploadUrl' => (string)$router->fromHere('api:stations:files:upload'),
    'listDirectoriesUrl' => (string)$router->fromHere('api:stations:files:directories'),
    'mkdirUrl' => (string)$router->fromHere('api:stations:files:mkdir'),
    'renameUrl' => (string)$router->fromHere('api:stations:files:rename'),
    'initialPlaylists' => $playlists,
    'customFields' => $custom_fields,
    'validMimeTypes' => $mime_types,
];

$assets
    ->addInlineJs($this->fetch('partials/radio_controls.js'), 95)
    ->addVueRender('Vue_StationsMedia', '#media-manager', $props);
?>

<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header bg-primary-dark">
                <div class="row align-items-center">
                    <div class="col-md-7">
                        <h2 class="card-title"><?=__('Music Files')?></h2>
                    </div>
                    <div class="col-md-5 text-right text-white-50">
                        <?php
                        if ($space_total): ?>
                            <div class="progress">
                                <div class="progress-bar" role="progressbar" aria-valuenow="<?=$space_percent?>"
                                     aria-valuemin="0" aria-valuemax="100" style="width: <?=$space_percent?>%;">
                                    <span class="sr-only"><?=$space_percent?>%</span>
                                </div>
                            </div>
                            <?=__('%s of %s Used (%d Files)', $space_used, $space_total, $files_count)?>
                        <?php
                        else: ?>
                            <?=__('%s Used (%d Files)', $space_used, $files_count)?>
                        <?php
                        endif; ?>
                    </div>
                </div>
            </div>
            <?php
            if ($show_sftp): ?>
                <div class="card-body alert-info d-flex align-items-center" role="alert">
                    <div class="flex-shrink-0 mr-2">
                        <i class="material-icons" aria-hidden="true">info</i>
                    </div>
                    <div class="flex-fill">
                        <p class="mb-0">
                            <?=__('You can also upload files in bulk via SFTP.')?>
                        </p>
                    </div>
                    <div class="flex-shrink-0 ml-2">
                        <a class="btn btn-sm btn-light" target="_blank"
                           href="<?=$router->fromHere('stations:sftp_users:index')?>">
                            <?=__('Manage SFTP Accounts')?>
                        </a>
                    </div>
                </div>
            <?php
            endif; ?>

            <div id="media-manager"></div>
        </div>
    </div>
</div>
