import type { ReactNode } from "react";

type Props = {
  requestNumber: string;
  requestedBy: string;
  department: string;
  budgetCode: string;
  requestedDate: string;
  deliveryExpected: string;
  deliveryLocation: string;
  costCenter: string;
  glAccount: string;
  companyCode: string;
  onRequestedByChange: (v: string) => void;
  onDepartmentChange: (v: string) => void;
  onBudgetCodeChange: (v: string) => void;
  onRequestedDateChange: (v: string) => void;
  onDeliveryExpectedChange: (v: string) => void;
  onDeliveryLocationChange: (v: string) => void;
  onCostCenterChange: (v: string) => void;
  onGlAccountChange: (v: string) => void;
  onCompanyCodeChange: (v: string) => void;
};

const INPUT =
  "mt-0.5 w-full rounded-md border border-outline-variant bg-surface-container-lowest px-2 py-1 text-[11px] leading-tight text-primary shadow-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary";

function MiniField({
  label,
  children,
}: {
  label: string;
  children: ReactNode;
}) {
  return (
    <div>
      <label className="font-label-caps text-[8px] font-bold uppercase leading-none tracking-wide text-secondary">
        {label}
      </label>
      {children}
    </div>
  );
}

export function RequestSummaryPanel({
  requestNumber,
  requestedBy,
  department,
  budgetCode,
  requestedDate,
  deliveryExpected,
  deliveryLocation,
  costCenter,
  glAccount,
  companyCode,
  onRequestedByChange,
  onDepartmentChange,
  onBudgetCodeChange,
  onRequestedDateChange,
  onDeliveryExpectedChange,
  onDeliveryLocationChange,
  onCostCenterChange,
  onGlAccountChange,
  onCompanyCodeChange,
}: Props) {
  return (
    <div className="shrink-0 rounded-lg border border-outline-variant bg-surface-container-low px-2.5 py-2 shadow-sm">
      <h2 className="mb-1.5 font-label-caps text-[8px] font-bold uppercase leading-none tracking-wide text-secondary">
        Request details
      </h2>
      <div className="grid grid-cols-2 gap-x-2 gap-y-1.5">
        <MiniField label="Request Number">
          <input
            type="text"
            readOnly
            value={requestNumber}
            className={`${INPUT} bg-surface-container-high font-data-mono text-[10px]`}
            aria-readonly
          />
        </MiniField>
        <MiniField label="Requested Date">
          <input
            type="date"
            value={requestedDate}
            onChange={(e) => onRequestedDateChange(e.target.value)}
            className={INPUT}
          />
        </MiniField>
        <MiniField label="Requested By">
          <input
            type="text"
            value={requestedBy}
            onChange={(e) => onRequestedByChange(e.target.value)}
            placeholder="Name or ID"
            className={INPUT}
          />
        </MiniField>
        <MiniField label="Department">
          <input
            type="text"
            value={department}
            onChange={(e) => onDepartmentChange(e.target.value)}
            placeholder="Cost center / org unit"
            className={INPUT}
          />
        </MiniField>
        <div className="col-span-2">
          <MiniField label="Budget Code">
            <input
              type="text"
              value={budgetCode}
              onChange={(e) => onBudgetCodeChange(e.target.value)}
              placeholder="GL / WBS / budget reference"
              className={INPUT}
            />
          </MiniField>
        </div>
        <MiniField label="Delivery Expected">
          <input
            type="date"
            value={deliveryExpected}
            onChange={(e) => onDeliveryExpectedChange(e.target.value)}
            className={INPUT}
          />
        </MiniField>
        <MiniField label="Delivery Location">
          <input
            type="text"
            value={deliveryLocation}
            onChange={(e) => onDeliveryLocationChange(e.target.value)}
            placeholder="Location / area"
            className={INPUT}
          />
        </MiniField>
        <MiniField label="Please Enter the Cost Center">
          <input
            type="text"
            value={costCenter}
            onChange={(e) => onCostCenterChange(e.target.value)}
            placeholder="Cost center"
            className={INPUT}
          />
        </MiniField>
        <MiniField label="GL Account">
          <input
            type="text"
            value={glAccount}
            onChange={(e) => onGlAccountChange(e.target.value)}
            placeholder="GL account"
            className={INPUT}
          />
        </MiniField>
        <MiniField label="Company Code">
          <input
            type="text"
            value={companyCode}
            onChange={(e) => onCompanyCodeChange(e.target.value)}
            placeholder="Company code"
            className={INPUT}
          />
        </MiniField>
      </div>
    </div>
  );
}
