package com.kickstarter.ui.adapters;

import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.view.View;

import com.kickstarter.R;
import com.kickstarter.models.Empty;
import com.kickstarter.models.Project;
import com.kickstarter.ui.viewholders.EmptyProfileViewHolder;
import com.kickstarter.ui.viewholders.EmptyViewHolder;
import com.kickstarter.ui.viewholders.KSViewHolder;
import com.kickstarter.ui.viewholders.ProfileCardViewHolder;

import java.util.Collections;
import java.util.List;

public final class ProfileAdapter extends KSAdapter {
  private final Delegate delegate;

  public interface Delegate extends ProfileCardViewHolder.Delegate, EmptyProfileViewHolder.Delegate {}

  public ProfileAdapter(final @NonNull Delegate delegate) {
    this.delegate = delegate;
  }

  public void takeProjects(final @NonNull List<Project> projects) {
    data().clear();
    if (projects.size() == 0) {
      data().add(Collections.singletonList(Empty.get()));
    } else {
      data().add(projects);
    }
    notifyDataSetChanged();
  }

  protected @LayoutRes int layout(final @NonNull SectionRow sectionRow) {
    if (objectFromSectionRow(sectionRow) instanceof Project) {
      return R.layout.profile_card_view;
    } else {
      return R.layout.profile_empty_state_view;
    }
  }

  protected @NonNull KSViewHolder viewHolder(final @LayoutRes int layout, final @NonNull View view) {
    switch(layout) {
      case R.layout.profile_empty_state_view:
        return new EmptyProfileViewHolder(view, delegate);
      case R.layout.profile_card_view:
        return new ProfileCardViewHolder(view, delegate);
      default:
        return new EmptyViewHolder(view);
    }
  }
}

@@ -587,16 +587,122 @@
 apter %7B%0A
+  private static final int SECTION_EMPTY_VIEW = 0;%0A  private static final int SECTION_PROJECTS_VIEW = 1;%0A%0A
   privat
@@ -922,16 +922,152 @@
 elegate;
+%0A%0A    this.data().add(SECTION_EMPTY_VIEW, Collections.emptyList());%0A    this.data().add(SECTION_PROJECTS_VIEW, Collections.emptyList());
 %0A  %7D%0A%0A  
@@ -1136,28 +1136,8 @@
 ) %7B%0A
-    data().clear();%0A
     
@@ -1177,20 +1177,40 @@
  data().
-add(
+set(SECTION_EMPTY_VIEW, 
 Collecti
@@ -1268,20 +1268,43 @@
  data().
-add(
+set(SECTION_PROJECTS_VIEW, 
 projects
@@ -1431,19 +1431,9 @@
 if (
-objectFromS
+s
 ecti
@@ -1441,39 +1441,40 @@
 nRow
-(
+.
 section
-Row) instanceof Project
+() == SECTION_EMPTY_VIEW
 ) %7B%0A
@@ -1499,28 +1499,35 @@
 out.profile_
-card
+empty_state
 _view;%0A    %7D
@@ -1560,35 +1560,28 @@
 out.profile_
-empty_state
+card
 _view;%0A    %7D

make sections to distinguish between profile empty and full