"use client";
import { useState } from 'react';
import { jsxs, jsx } from 'react/jsx-runtime';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
function OrderEntry({
  symbol,
  accountBalance,
  onPlaceOrder,
  disabled = false
}) {
  const [orderType, setOrderType] = useState("market");
  const [orderSide, setOrderSide] = useState("buy");
  const [shares, setShares] = useState("");
  const [limitPrice, setLimitPrice] = useState("");
  const getTickerFromSymbol = /* @__PURE__ */ __name((symbol2) => {
    return symbol2.split(":")[1] || symbol2;
  }, "getTickerFromSymbol");
  const handlePlaceOrder = /* @__PURE__ */ __name(() => {
    if (!shares || orderType === "limit" && !limitPrice) return;
    onPlaceOrder({
      symbol,
      side: orderSide,
      orderType,
      shares: parseInt(shares),
      limitPrice: orderType === "limit" ? parseFloat(limitPrice) : void 0
    });
    setShares("");
    setLimitPrice("");
  }, "handlePlaceOrder");
  return /* @__PURE__ */ jsxs("div", { className: "p-4 space-y-4", children: [
    /* @__PURE__ */ jsxs("div", { className: "bg-white/5 rounded-lg p-3", children: [
      /* @__PURE__ */ jsx("div", { className: "text-xs text-white/60 mb-1", children: "Buying Power" }),
      /* @__PURE__ */ jsxs("div", { className: "text-lg font-semibold text-white", children: [
        "$",
        accountBalance.toLocaleString()
      ] })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-2", children: [
      /* @__PURE__ */ jsx(
        "button",
        {
          onClick: () => setOrderSide("buy"),
          disabled,
          className: `py-2.5 rounded-lg font-semibold transition-all ${orderSide === "buy" ? "bg-success text-white" : "bg-white/5 text-white/60 hover:bg-white/10"} disabled:opacity-50 disabled:cursor-not-allowed`,
          children: "Buy"
        }
      ),
      /* @__PURE__ */ jsx(
        "button",
        {
          onClick: () => setOrderSide("sell"),
          disabled,
          className: `py-2.5 rounded-lg font-semibold transition-all ${orderSide === "sell" ? "bg-danger text-white" : "bg-white/5 text-white/60 hover:bg-white/10"} disabled:opacity-50 disabled:cursor-not-allowed`,
          children: "Sell"
        }
      )
    ] }),
    /* @__PURE__ */ jsxs("div", { children: [
      /* @__PURE__ */ jsx("label", { className: "text-xs text-white/60 mb-2 block", children: "Order Type" }),
      /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-2", children: [
        /* @__PURE__ */ jsx(
          "button",
          {
            onClick: () => setOrderType("market"),
            disabled,
            className: `py-2 rounded-lg text-sm font-medium transition-all ${orderType === "market" ? "bg-white/10 text-white" : "bg-white/5 text-white/60 hover:bg-white/10"} disabled:opacity-50 disabled:cursor-not-allowed`,
            children: "Market"
          }
        ),
        /* @__PURE__ */ jsx(
          "button",
          {
            onClick: () => setOrderType("limit"),
            disabled,
            className: `py-2 rounded-lg text-sm font-medium transition-all ${orderType === "limit" ? "bg-white/10 text-white" : "bg-white/5 text-white/60 hover:bg-white/10"} disabled:opacity-50 disabled:cursor-not-allowed`,
            children: "Limit"
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ jsxs("div", { children: [
      /* @__PURE__ */ jsx("label", { className: "text-xs text-white/60 mb-2 block", children: "Shares" }),
      /* @__PURE__ */ jsx(
        "input",
        {
          type: "number",
          value: shares,
          onChange: (e) => setShares(e.target.value),
          disabled,
          className: "w-full bg-white/5 border border-white/10 rounded-lg px-4 py-2.5 text-white focus:outline-none focus:border-success disabled:opacity-50 disabled:cursor-not-allowed",
          placeholder: "0"
        }
      )
    ] }),
    orderType === "limit" && /* @__PURE__ */ jsxs("div", { children: [
      /* @__PURE__ */ jsx("label", { className: "text-xs text-white/60 mb-2 block", children: "Limit Price" }),
      /* @__PURE__ */ jsx(
        "input",
        {
          type: "number",
          value: limitPrice,
          onChange: (e) => setLimitPrice(e.target.value),
          disabled,
          className: "w-full bg-white/5 border border-white/10 rounded-lg px-4 py-2.5 text-white focus:outline-none focus:border-success disabled:opacity-50 disabled:cursor-not-allowed",
          placeholder: "0.00",
          step: "0.01"
        }
      )
    ] }),
    /* @__PURE__ */ jsxs(
      "button",
      {
        onClick: handlePlaceOrder,
        disabled: disabled || !shares || orderType === "limit" && !limitPrice,
        className: `w-full py-3 rounded-lg font-semibold transition-all ${orderSide === "buy" ? "bg-success hover:bg-success/90 text-white" : "bg-danger hover:bg-danger/90 text-white"} disabled:opacity-50 disabled:cursor-not-allowed`,
        children: [
          orderSide === "buy" ? "Buy" : "Sell",
          " ",
          getTickerFromSymbol(symbol)
        ]
      }
    )
  ] });
}
__name(OrderEntry, "OrderEntry");

export { OrderEntry };
