protected function getHeaderActions(): array
{
$formFilled=false;
if($this->data['difficulty_level'] && $this->data['type']){$formFilled= true;
}
return [
Actions\CreateAction::make()
->label('Generate')
->action(fn() => $this->fillFormFields())
->hidden(!$formFilled)
->color($formFilled ? 'success':'danger'),
];
}
protected function fillFormFields()
{
//dd("hii");
$lesson = \App\Models\Lesson::findOrFail($this->data['lesson_id']);
$topic = \App\Models\Topic::find($lesson->topic_id);
$difficulty_level = $this->data['difficulty_level'];
$type = $this->data['type'];
$material = new \App\Models\Material;
$content = json_decode($material->generateContent($topic->title, $lesson->title, $difficulty_level, $type));
if ($this->data['type'] == 'video') {if ($content->view_link) {
$videoId = explode('?v=', $content->view_link)[1];
}}
$data['type'] = $this->data['type'];
$data['difficulty_level'] = $difficulty_level;
$data['lesson_id'] = $this->data['lesson_id'];
$data['embeded_link'] = $content->link;
$data['title'] = $content->title;
$data['duration'] = $content->duration;
if ($this->data['type'] == 'video') {
$data['captions'] = $material->generateCaption($videoId);
}
if ($this->data['type'] == 'text') {
$data['Text'] = $content->Text;
$data['Description'] = $content->Description;
}
if ($this->data['type'] == 'html') {
$data['Html'] = $content->Html;
}
$this->form->fill($data);
}