import { CSSProperties, MouseEventHandler } from "react";

export type Style = {
  styles?: CSSProperties;
};

export type TitleProps = {
  title?: string;
  must?: boolean;
};

/**
 * 输入组件参数
 */
export type InputProps = {
  inputHint?: string; // 输入提示
  maxLength?: number; // 最大输入字数限制
  tip?: string; // 功能提示
  onTextChanged?: (text: string) => void; // 输入改变监听
} & TitleProps &
  Style;

/**
 * 状态组件参数
 */
export enum Status {
  LOADING,
  FAILED
}

export type StatusProps = {
  status?: Status
  width?: string | number
  height?: string | number
  iconSize?: string | number
  iconColor?: string
  text?: string
  textMargin?: string | number
  fontSize?: string | number
  fontColor?: string
  fontWeight?: number | string
  backgroundColor?: string
  backgroundOpacity?: number
  borderRadius?: string | number
}

/**
 * 弹层组件按钮
 */
export type ModalBtn = {
  btnText: string;
  onClick?: () => void;
};

/**
 * 弹层组件参数
 */
export type ModalProps = {
  title?: string
  content?: string
  leftBtn?: ModalBtn
  rightBtn?: ModalBtn
  dimBackground?: boolean // 背景是否变暗
  dismissOnOutsideClick?: boolean // 背景点击是否隐藏弹层
  show: boolean
};

/* 分组单选模块 */
export type RadioProps = {
  label: string;
  value: number;
  selectedValue: number;
  onClick: MouseEventHandler<HTMLDivElement>;
  style?: CSSProperties;
};
export type RadioOption = Omit<RadioProps, "selectedValue" | "onClick">;
export type RadioGroupProps = TitleProps &
  Style & { options: RadioOption[]; defaultValue: number; valueChanged: (selected: RadioOption) => void };

/* 订单模块 */
export type OrderProps = {
  orderId: string;
  changeOrder: boolean;
  imgUrl: string;
  name: string;
  price: string;
  num: number;
  status: string;
} & Style;

/* 数量选择模块 */
export type NumberSelectorProps = {
  defaultValue: number;
  max?: number;
  valueChanged: (value: number) => void;
} & TitleProps &
  Style;

export type UploadData = {
  aid: string
  appId: string
  clientType: 'm'
  pin: string
}

/**
 * 图片上传组件参数
 */
export type ImgUploaderProps = {
  onUploadStatusChange?: (status: string) => void // 上传状态改变回调(status: uploading/finish)
  onResult?: (urls: string[]) => void // 结果回调（上传成功、图片删除都会走）
  enableCompress?: boolean // 是否开启图片压缩（超过20M）
  limit?: number // 最大图片上传数
  uploadData?: UploadData // 上传接口所需参数
} & TitleProps & Style
