middleware('auth'); $this->_service = 'contact'; $this->_module = 'contact_list'; $this->_viewname = 'contactlist'; $this->_title = 'Contact List'; $this->_base_url = '/contactlist'; } protected function get_list_fields() { return [ 'actions' => ['title' => 'Actions', 'buttons' => ['edit', 'delete']], 'name' => ['title' => 'Name', 'type' => 'text'], 'status' => ['title' => 'Status', 'type' => 'select'] ]; } protected function get_form_fields($type, $values) { // $teams = $this->getlambda('get', 'communication', 'template', 'dropdown'); // // echo '
'; print_r($teams); exit;
        // $templates = [];
        // foreach ($teams->data->items as $team) {
        //     $templates[$team->template_code] = $team->name;
        // }

        // $chans = $this->getlambda('get', 'communication', 'channel', 'dropdown');
        // // echo '
'; print_r($teams); exit;
        // $channels = [];
        // foreach ($chans->data->items as $chan) {
        //     $channels[$chan->id] = $chan->name;
        // }

        return [
            'name' => ['title' => 'Name', 'type' => 'text', 'required' => true],
            'type' => ['title' => 'Type', 'type' => 'select', 'values' => ["normal" => "Normal","dynamic" => "Dynamic"], 'required' => true],
            'conditions' => ['title' => 'Conditions', 'type' => 'textarea', 'fullwidth' => true],
            
            'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled']],
        ];
    }

    public function form($type, $id = null)
    {
        $values = [];
        if ($type == 'edit') {
            $response = LambdaRequest::signedrequest('get', $this->_service, $this->_module . '/get_one', ['id' => $id]);
            $values = $response->data->item;
            // echo '
'; print_r($values); exit;
        }
        //echo '
'; print_r($values); exit;
        $data = $this->_beforeform($type, $values);
        $fields = $this->get_form_fields($type, $values);
        //echo '
'; print_r($fields); exit;
        return $this->view('form')->with([
            'title' => $this->_title,
            'mode' => $type,
            'fields' => $fields,
            'base_url' => $this->_base_url,
            'item' => $values,
        ]);
    }

    protected function _beforesave($type, $request)
    {
        $data = $request->except('_token');
        if ($request->file('image')) {
            $data['image'] = $this->_uploadMedia($request, 'image', 'template');
        }
        return $data;
    }
}