<?php
/** @var yii\web\View $this */
/** @var app\models\Course $course */
/** @var app\models\CourseActivity $model */

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use app\models\CourseActivity;

$this->title = 'Add Activity';
?>

<div class="page-title">
    <i class="fas fa-plus-circle"></i> Add Activity
    <a href="<?= Url::to(['courses/view', 'id' => $course->id]) ?>"
       class="lms-btn lms-btn-primary lms-btn-sm" style="margin-left:auto;">
        <i class="fas fa-arrow-left"></i> Back to <?= Html::encode($course->course_code) ?>
    </a>
</div>

<div class="lms-card" style="max-width:620px;">
    <div class="lms-card-header">
        <i class="fas fa-clipboard-list"></i> New Activity for
        <code style="background:#f0f4ff; padding:2px 8px; border-radius:4px; font-size:13px; margin-left:4px;">
            <?= Html::encode($course->course_code) ?>
        </code>
        — <?= Html::encode($course->course_name) ?>
    </div>
    <div class="lms-card-body">

    <?php $form = ActiveForm::begin([
        'options'     => ['autocomplete' => 'off'],
        'fieldConfig' => ['errorOptions' => ['class' => 'field-error']],
    ]); ?>

        <?= Html::hiddenInput('CourseActivity[course_id]', $course->id) ?>

        <div class="lms-form-row">
            <?= $form->field($model, 'activity_name', ['options' => ['class' => 'lms-form-group']])
                ->textInput([
                    'class'       => 'form-control',
                    'placeholder' => 'e.g. Introduction to Variables',
                    'style'       => 'padding-left:14px;',
                ]) ?>
        </div>

        <div style="display:grid; grid-template-columns:1fr 1fr; gap:16px;">
            <div class="lms-form-row">
                <?= $form->field($model, 'activity_type', ['options' => ['class' => 'lms-form-group']])
                    ->dropDownList(
                        CourseActivity::TYPES,
                        ['class' => 'form-control', 'style' => 'padding-left:14px;']
                    ) ?>
            </div>
            <div class="lms-form-row">
                <?= $form->field($model, 'activity_code', ['options' => ['class' => 'lms-form-group']])
                    ->textInput([
                        'class'       => 'form-control',
                        'placeholder' => 'e.g. CRS001-A01',
                        'style'       => 'padding-left:14px; font-family:monospace;',
                    ])
                    ->hint('Optional unique code.') ?>
            </div>
        </div>

        <div style="display:grid; grid-template-columns:1fr 1fr; gap:16px;">
            <div class="lms-form-row">
                <?= $form->field($model, 'duration_minutes', ['options' => ['class' => 'lms-form-group']])
                    ->textInput([
                        'class'       => 'form-control',
                        'style'       => 'padding-left:14px;',
                        'type'        => 'number',
                        'min'         => '0',
                        'placeholder' => '30',
                    ])
                    ->hint('Duration in minutes.') ?>
            </div>
            <div class="lms-form-row">
                <?= $form->field($model, 'sort_order', ['options' => ['class' => 'lms-form-group']])
                    ->textInput([
                        'class' => 'form-control',
                        'style' => 'padding-left:14px;',
                        'type'  => 'number',
                        'min'   => '0',
                    ])
                    ->hint('Order within the course.') ?>
            </div>
        </div>

        <div class="lms-form-row">
            <?= $form->field($model, 'description', ['options' => ['class' => 'lms-form-group']])
                ->textarea([
                    'class'       => 'form-control',
                    'rows'        => 2,
                    'style'       => 'padding:10px 14px;',
                    'placeholder' => 'Optional description...',
                ]) ?>
        </div>

        <div class="lms-form-row">
            <?= $form->field($model, 'is_active', ['options' => ['class' => 'lms-form-group']])
                ->dropDownList(
                    ['Y' => 'Active', 'N' => 'Inactive'],
                    ['class' => 'form-control', 'style' => 'padding-left:14px;']
                ) ?>
        </div>

        <div style="margin-top:14px;">
            <?= Html::submitButton('<i class="fas fa-save"></i> Save Activity', ['class' => 'lms-btn lms-btn-success']) ?>
        </div>

    <?php ActiveForm::end(); ?>
    </div>
</div>
