<?php

namespace App\Admin\Controllers;

use App\Models\Student;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use App\Admin\Controllers\AdminController;

use Dcat\Admin\Layout\Content;
use App\Models\ToothLog;

class ToothLogController extends AdminController
{
    public function index($parent, Content $content)
    {
        $title = '长牙记录';
        return $content
            ->title($title)
            ->description('列表')
            // 添加面包屑导航
            ->breadcrumb([
                    'text' => '返回列表',
                    'url' => admin_url('/student'),
                    'icon' => 'fa fa-step-backward'
                ],['text' => $title]
            )
            ->body($this->grid($parent));
    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid($id)
    {
        return Grid::make(new ToothLog(), function (Grid $grid) use($id) {
            //$grid->column('student_id');
            $grid->column('student_id','学生信息')->display(function () {
                  $str  = "";
                  $str .= "<div style='margin-right:10px;display: flex;align-items: center;padding-right:10px;'>";
                  $str .= '<img data-action="preview-img" src="' . $this->student_id . '" style="height:56px;width:56px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
                  $str .= '<div>';
                  $str .= '<p style="margin:0px">姓名：小朋友</p>';
                  $str .= '<p style="margin:0px">出生年月：2023-01-01</p>';
                  $str .= '<p style="margin:0px">家庭住址：四川省成都市金牛区三泰魔方</p>';
                  $str .= '<p style="margin:0px">所属班级：黄桃班</p>';
                  $str .= '<p style="margin:0px">入园日期：2022-03-10</p>';
                  $str .= "</div>";
                  $str .= "</div>";
                  return $str;
            });
            $grid->column('log_time');
            $grid->column('desc')->limit(50);
            $grid->column('photos')->display(function ($photo_urls){
                return json_decode($photo_urls, true);
            })->image('', '60', '60');;
            $grid->disableActions();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->like('student_id')->width(4);
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ToothLog(), function (Show $show) {
            $show->field('id');
           
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form($id)
    {
        return Form::make(new ToothLog(), function (Form $form) use($id) {
          $form->width(6)->datetime('time')->required()->placeholder('时间');
          $form->width(6)->textarea('desc')->placeholder('长牙描述');
          $form->width(6)->multipleImage('photos')->placeholder('上传照片')->saveAsJson();
        });
    }
}
