package kz.cafe.admin;

import java.util.*;
import kz.cafe.admin.constants.AccessConstants.EditMode;
import kz.cafe.admin.panel_extensions.*;
import kz.cafe.admin.panels.*;
import kz.cafe.admin.panels.model.*;
import kz.cafe.db.*;
import kz.cafe.db.model.*;




public class TabUserClients extends AbstractTab{
   private static final long serialVersionUID = 6486710312950457250L;


   public TabUserClients(AdminMain application, Set<EditMode> setMode){
      super(application, setMode);
   }







   public static CustomDescriptor descriptorClient(AdminMain application){     
      CustomDescriptor dscr = new CustomDescriptor();
      
      CustomField field = new CustomField();
      field.visible = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER;
      field.name = "ID";
      field.db = "ID";
      field.isEditable = false;
      field.style.width = 30;
      field.isSortable = true;
      field.search.row = 0;
      dscr.addField(field);
      
      

      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Логин";
      field.db = "login";
      field.isEditable = true;
      field.style.width = 100;
      field.isMust = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      dscr.addField(field);
      
      
      
      CustomPassword fieldPassword = new CustomPassword();
      fieldPassword.visible = true;
      fieldPassword.name = "Пароль";
      fieldPassword.db = "password";
      fieldPassword.isEditable = true;
      fieldPassword.style.width = 100;
      fieldPassword.isMust = true;
      fieldPassword.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      dscr.addField(fieldPassword);
      

      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Активен";
      field.db = "active";
      field.isEditable = true;
      field.style.width = 20;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE; 
      field.search.row = 2;
      dscr.addField(field);
      

      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Email подтвержден";
      field.db = MUser.F_EMAIL_CONFIRMED;
      field.isEditable = true;
      field.style.width = 30;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE; 
      field.search.row = 2;
      dscr.addField(field);
      
      
      
      
      
      CustomImageField fieldImage = new CustomImageField();
      fieldImage.visible = true;
      fieldImage.name = "Аватар";
      fieldImage.db = "image";
      fieldImage.isEditable = true;
      fieldImage.style.width = 35;
      fieldImage.style.height = 35;
      fieldImage.isImageInTable = true;
      dscr.addField(fieldImage);
      
      

      
      
      
      field = new CustomField();
      field.visible = true;
      field.name = "Язык";
      field.db = "lang";
      field.isEditable = false;
      field.style.width = 30;
      field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      field.search.row = 1;
      dscr.addField(field);
      
      
      
      
      

      
      field = new CustomField();
      field.visible = true;
      field.name = "Имя";
      field.db = "name";
      field.isEditable = true;
      //field.style.width = 100;
      field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      field.search.row = 1;
      dscr.addField(field);
      
      
      
      
      field = new CustomField();
      field.visible = true;
      //field.searchable = CustomField.SEARCH_MODES.INTEGER;
      field.name = "Телефон";
      field.db = "phone";
      field.isEditable = true;
      //field.style.width = 100;
      field.search.mode = CustomField.Search.SEARCH_MODES.STRING;
      field.search.row = 1;
      dscr.addField(field);
      
      
      
      
      
      
      CustomFixedComboField ccf = new CustomFixedComboField();
      ccf.visible = true;
      ccf.name = "Город";
      ccf.db = "city";
      ccf.isEditable = true;
      ccf.style.width = 100;
      ccf.isMust = true;
      ccf.search.row = 1;
      dscr.addField(ccf);      
      
      
      
      
      
      field = new CustomField();
      field.visible = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER;
      field.name = "Заказов сделано";
      field.db = "cntrOrdersTotal";
      field.isEditable = false;
      field.style.width = 110;
      field.isSortable = true;
      field.search.row = 0;
      dscr.addField(field);
      
      
      
      
      
      field = new CustomField();
      field.visible = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.INTEGER;
      field.name = "Оплачено";
      field.db = "cntrOrdersPaid";
      field.isEditable = false;
      field.style.width = 60;
      field.isSortable = true;
      field.search.row = 0;
      dscr.addField(field);
      
      

      field = new CustomField();
      field.visible = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.NONE;
      field.name = "Устройство";
      field.db = "device";
      field.isEditable = false;
      field.style.width = 300;
      field.isSortable = true;
      field.search.row = 0;
      dscr.addField(field);
      
      
      
      
      
      CustomDateField dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Создан";
      dateField.db = "created";
      dateField.isEditable = false;
      dateField.style.width = 120;
      dateField.isSortable = true;
      dateField.search.mode = CustomField.Search.SEARCH_MODES.DATE_RANGE; 
      dateField.search.row = 2;
      dscr.addField(dateField);
      
      
      
      
      
      dateField = new CustomDateField();
      dateField.visible = true;
      dateField.name = "Последний вход";
      dateField.db = "updated";
      dateField.isEditable = false;
      dateField.style.width = 120;
      dateField.isSortable = true;
      dateField.search.mode = CustomField.Search.SEARCH_MODES.DATE_RANGE;
      dateField.search.row = 2;
      dscr.addField(dateField);

      
      
      
      field = new CustomField();
      field.visible = true;
      field.name = "GUI";
      field.db = "canUseGUI";
      field.isEditable = true;
      field.style.width = 20;
      field.isSortable = true;
      field.search.mode = CustomField.Search.SEARCH_MODES.BOOLEAN_ONLY_TRUE; 
      field.search.row = 2;
      dscr.addField(field);
      
      
      return dscr;
   }
   
   
   
   
   
   

   @Override
   public DBListPanel<MUser> build(){
      CustomDescriptor dscr = descriptorClient(application);

      Constraint constraint = new Constraint();
      constraint.criteria.add(new Constraint.Criterion(MUser.F_CAN_USE_GUI, false));
      
      Set<Integer> setBlockedRecords = Collections.singleton(0);
      
      
      DBListPanel<MUser> panel = new DBListPanel<MUser>(application,
                                                        MUser.class,
                                                        dscr,
                                                        Dimension.getFull(application),
                                                        setMode,
                                                        constraint,
                                                        setBlockedRecords);
      panel.addPanel(new ExtraPanelImageUploader(panel, (CustomImageField) dscr.mapDBFields.get(MAbstractDescriptor.F_IMAGE)), false);
      //panelCourse.addPanel(new ExtraPanelImageViewer(panelCourse, fieldImage, 50), true);
      
      return panel;
   }










   @Override
   public DBSingle<MUser> build(int ID){
      CustomDescriptor dscr = descriptorClient(application);
      
      
      DBSingle<MUser> panel = new DBSingle<MUser>(application,
               MUser.class,
               ID,
               dscr,
               Dimension.getFull(application),
               setMode
               );
      
      return panel;
   }
}




