import * as React from "react";
import { svgToUrl } from "../../open_farm/icons";
import {
CropInfoProps, CropLiveSearchResult, OpenfarmSearch
} from "../interfaces";
import { history, getPathArray } from "../../history";
import { connect } from "react-redux";
import { findBySlug } from "../search_selectors";
import { Everything } from "../../interfaces";
import { OpenFarm } from "../openfarm";
import { OFSearch } from "../util";
import { unselectPlant, setDragIcon } from "../actions";
import { validBotLocationData } from "../../util";
import { createPlant } from "../map/layers/plants/plant_actions";
import { round } from "../map/util";
import { BotPosition } from "../../devices/interfaces";
import {
DesignerPanel, DesignerPanelHeader, DesignerPanelContent
} from "./designer_panel";
import { Actions } from "../../constants";
import {
EmptyStateWrapper, EmptyStateGraphic
} from "../../ui/empty_state_wrapper";
import { startCase, isArray, chain, isNumber } from "lodash";
import { t } from "../../i18next_wrapper";
interface InfoFieldProps {
title: string;
children?: React.ReactNode;
}
interface SummaryItemProps {
key: string;
i: number;
field: string;
value: string;
}
/** Basic field: value display for OpenFarm crop properties. */
const InfoField = (props: InfoFieldProps) =>
{t(startCase(props.title))}
{props.children}
;
const OMITTED_PROPERTIES = [
"slug",
"processing_pictures",
"description",
"main_image_path",
"tags_array",
"guides_count"
];
const NO_VALUE = t("Not Set");
/**
* If there's a value, give it an img element to render the
* actual graphic. If no value, return NO_VALUE.
*/
const SvgIcon = ({ i, field, value }: SummaryItemProps) =>
{value
?
: {NO_VALUE}}
;
/**
* Need to convert the `cm` provided by OpenFarm to `mm`
* to match the Farm Designer units.
*/
const CmProperty = ({ i, field, value }: SummaryItemProps) =>
{!isNaN(parseInt(value))
? (parseInt(value) * 10) + t("mm")
: NO_VALUE}
;
/** Comma-separated list of crop common names. */
const CommonNames = ({ i, field, value }: SummaryItemProps) =>
{(isArray(value)
? value.join(", ")
: value) || NO_VALUE}
;
/** Default behavior for all other properties. */
const DefaultPropertyDisplay = ({ i, field, value }: SummaryItemProps) =>
{value || NO_VALUE}
;
/** Choose the appropriate display function for the crop property. */
const handleDisplay = ([field, value]: string[], i: number) => {
const commonProps: SummaryItemProps = { key: field, i, field, value };
switch (field) {
case "svg_icon":
return ;
case "spread":
case "row_spacing":
case "height":
return ;
case "common_names":
return ;
default:
return ;
}
};
/** Display crop properties from OpenFarm. */
const CropInfoList = (crop: OpenFarm.OFCrop) => {
return