<?php
namespace App\Distributor\Actions\Extensions;


use Dcat\Admin\Widgets\Modal;
use App\Distributor\Forms\ImportProduct;
use Dcat\Admin\Grid\BatchAction;

class DistProductImportForm extends BatchAction
{
    protected $title = 'import';


    public function render()
    {
        // 实例化表单类
        $form = ImportProduct::make();

        return Modal::make()
            ->lg()
            ->title($this->title)
            ->body($form)
            // 因为此处使用了表单异步加载功能，所以一定要用 onLoad 方法
            // 如果是非异步方式加载表单，则需要改成 onShow 方法
            ->onShow($this->getModalScript())
            ->button($this->getButtonHTML());

    }

    protected function getModalScript()
    {
        // 弹窗显示后往隐藏的id表单中写入批量选中的行ID
        return <<<JS
        // 获取选中的ID数组
        var key = {$this->getSelectedKeysScript()}

        $('#product_ids').val(key);
        JS;
    }


    /**
     * 获取按钮的 HTML
     * @return string
     */

    public function title()
    {
        return '<i class="feather icon-shopping-cart"></i> &nbsp;'.admin_trans('admin.dist_product_import');
    }

    protected function getButtonHTML()
    {
        $title='<i class="feather icon-shopping-cart"></i> &nbsp;'.admin_trans('admin.import');


        return <<<HTML
        <button class="btn btn-success">
            <i class="feather"></i> {$title}
        </button>
        HTML;
    }

}
