import { TypographyValues } from '@/types/typography';
import { Portfolio, PortfolioContributorStatus } from '@prisma/client';
import { z } from 'zod';
import { ComponentType } from '../components/builder/config/componentRegistry';
import { PortfolioProject, Project } from './project';

export const portfolioFormSchema = z.object({
  title: z.string({ required_error: 'Portfolio name is required' }),
});

export type PortfolioFormValues = z.infer<typeof portfolioFormSchema>;

export type PortfolioContributor = {
  id: string;
  email: string;
  status: PortfolioContributorStatus;
};

export interface PortfolioActionButtonsProps {
  portfolio: PortfolioTable;
  isDeleting: boolean;
  onDelete: (id: string) => void;
}

export interface PortfolioFormProps {
  onSubmit: (values: PortfolioFormValues, shouldNavigateToEditor: boolean) => Promise<Portfolio | undefined>;
  isLoading?: boolean;
  defaultValues?: { title?: string, contributors?: PortfolioContributor[] };
  isEdit?: boolean;
}
export interface PortfolioCardProps {
  portfolio: PortfolioTable;
  onDelete: (id: string) => void;
  onInvitation: (portfolioId: string, accept: boolean) => Promise<void>;
  isDeleting: boolean;
}

export type PortfolioTable = Portfolio & {
  role: string;
  status: string;
  owner: string;
  pendingProjects: number;
};

export type PortfolioEdit = Portfolio & {
  contributors: PortfolioContributor[];
  portfolioProjects: PortfolioProject[];
  invitations: {
    email: string;
  }[];
};

export interface PortfolioConfig {
  elements: PortfolioElement[];
  colors?: Record<string, string>;
  typography?: TypographyValues;
}

export type PortfolioRevision = {
  id: string;
  portfolioId: string;
  createdAt: string;
  updatedAt: string;
  config: PortfolioConfig;
};

export interface PortfolioElement {
  id: string;
  layout: ComponentType;
  styling?: {
    align?: 'start' | 'center' | 'end';
    padding?: {
      top?: number;
      bottom?: number;
      left?: number;
      right?: number;
    };
    height?: number;
    width?: number;
    textColor?: string;
    backgroundColor?: string;
    fontSize?: number;
    fontFamily?: string;
    fontWeight?: string;
    textDecoration?: string;
    fontStyle?: string;
    color?: string;
  };
  props: Record<string, unknown>;
}

export interface EditFormProps {
  props: PortfolioElement['props'];
  onPropChange: (key: string, value: PortfolioElement['props']) => void;
}

export interface PortfolioCanvasProps {
  elements: PortfolioElement[];
  selectedElementId?: string;
  onElementSelect: (element: PortfolioElement) => void;
  onElementRemove: (id: string) => void;
  onElementMove: (id: string, direction: 'up' | 'down') => void;
  onAddComponent: (index: number, componentType: ComponentType) => void;
  onAddToSection: (parentId: string, position: string, componentType: ComponentType) => void;
  portfolioProjects: Project[];
}

export interface TopPanelProps {
  name: string;
  className?: string;
  portfolioId: string;
}
