package kz.cafe.admin.panel_extensions;

import kz.cafe.admin.*;
import kz.cafe.admin.panels.*;
import kz.cafe.db.*;
import com.vaadin.ui.*;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class ExtraPanelOneToMany extends AbstractExtendedPanel implements java.io.Serializable{
   private static final long serialVersionUID = 711754256190346567L;
   
   private final Table table;
   
   private final Button btMenu = new Button("Отзывы"); 
   
   
   public ExtraPanelOneToMany(final AdminMain application,
                              final DBListPanel<?> pnlParent,
                              final Class<?> classRelatedTo,
                              final Constraint constraint){

      AbstractLayout panelLayout = (AbstractLayout) getContent();
      panelLayout.setMargin(false);      
      
      
      
      this.table = pnlParent.table;

      btMenu.addListener(new ClickListener() {

         private static final long serialVersionUID = 4542127344900596681L;

         @Override
         public void buttonClick(ClickEvent event){
            
            Window window = new Window("Отзывы");
            window.setModal(true);
            window.center();
            
            Dimension dim = Dimension.get80(table.getApplication());
            
            window.setWidth(dim.iWidth + "px");
            window.setHeight(dim.iHeight + "px");
            window.setVisible(true);
            
            
            
            
            

            
            AdminMain app = (AdminMain) pnlParent.getApplication();
            //CustomDescriptor dscr = TabFeedback.buildDescriptor(app);
            
            
            Constraint constraint = new Constraint();
            
            
            int ID = (Integer) table.getValue();
            
//            Constraint.Criterion criterion = new Constraint.Criterion(true, "CID",  ID);
//            constraint.criteria.add(criterion);
//            
//            MCafe mCafe = MongoService.get(MCafe.class, ID);
//
//            criterion = new Constraint.Criterion(false, "cafe_type",  mCafe.type);
//            constraint.criteria.add(criterion);
//            
//            
//            criterion = new Constraint.Criterion(false, "cafe_name",  mCafe.name);
//            constraint.criteria.add(criterion);
//            
//            
//            if(application.isAdmin){
//            }
//            else{
//               constraint.criteria.add(new Constraint.Criterion(true, MUser.F_OWNER_ID, application.UID));
//            }
//            
//            
//            
//            DBListPanel panel =
//                     new DBListPanel(app,
//                                     classRelatedTo,
//                                     dscr,
//                                     Dimension.get80(app),
//                                     ViewConstants.EditMode.FULL,
//                                     constraint);
////            
//            panel.addPanel(new ExtraPanelImageUploader(panel, (CustomImageField) dscr.mapDBFields.get("image")), false);
//            
//            AbstractLayout panelLayout = (AbstractLayout) panel.getContent();
//            panelLayout.setMargin(false);
//            window.setContent(panel);
//            
//            pnlParent.getApplication().getMainWindow().addWindow(window);
         }
      });
      
      btMenu.setEnabled(false);

      this.addComponent(btMenu);
   }
   

   



   @Override
   public void changeFocus(){
      if(table.getValue() == null){
         btMenu.setEnabled(false);
      }
      else{
         btMenu.setEnabled(true);
      }
   }
}
