import dayjs from 'dayjs';
/**
 * 资源 / Holder 流程的客户 id：以 tempOrder 为订单真源。
 *
 * 优先级：tempOrder.customer_id → orderCustomerSnapshot → payload（如 OS CustomerModule 选中，可能为 walk-in）。
 * 避免 payload 为 walk-in(1) 时盖住订单已绑定的真实客户，导致抽屉内不展示 minor/Holder。
 */
export function resolveBookingEditCustomerId(tempOrder, payloadCustomerId, orderCustomerSnapshotId) {
  var orderCustomerId = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.customer_id;
  if (orderCustomerId != null && orderCustomerId !== '') {
    return orderCustomerId;
  }
  if (orderCustomerSnapshotId != null && orderCustomerSnapshotId !== '') {
    return orderCustomerSnapshotId;
  }
  if (payloadCustomerId != null && payloadCustomerId !== '') {
    return payloadCustomerId;
  }
  return undefined;
}

/** 加车流程与 {@link resolveBookingEditCustomerId} 同一套优先级。 */
export function resolveAddFlowCustomerId(tempOrder, payloadCustomerId, orderCustomerSnapshotId) {
  return resolveBookingEditCustomerId(tempOrder, payloadCustomerId, orderCustomerSnapshotId);
}

/**
 * 构造 Resources / Holder / Capacity 子组件所需的 state 快照（不依赖 miniRedux）。
 */
export function buildBookingEditDrawerState(input) {
  var _input$bookingConfig, _input$renderType, _input$amountSymbol, _input$channelDisable, _input$isFranchisee;
  var dateStr = input.date || dayjs().format('YYYY-MM-DD');
  return {
    bookingConfig: (_input$bookingConfig = input.bookingConfig) !== null && _input$bookingConfig !== void 0 ? _input$bookingConfig : null,
    renderType: (_input$renderType = input.renderType) !== null && _input$renderType !== void 0 ? _input$renderType : 'booking',
    date: {
      value: dayjs(dateStr)
    },
    client: input.customerId != null ? {
      value: {
        id: input.customerId
      }
    } : {
      value: null
    },
    pet: {},
    locale: input.locale,
    amountSymbol: (_input$amountSymbol = input.amountSymbol) !== null && _input$amountSymbol !== void 0 ? _input$amountSymbol : '$',
    channelDisabledEdit: (_input$channelDisable = input.channelDisabledEdit) !== null && _input$channelDisable !== void 0 ? _input$channelDisable : false,
    isFranchisee: (_input$isFranchisee = input.isFranchisee) !== null && _input$isFranchisee !== void 0 ? _input$isFranchisee : false,
    isBookingCreatePage: false,
    isBookingTicket2: true,
    isTerminalDayBookingPage: false,
    isTerminal: false,
    drawerMask: true,
    service: {
      cacheItem: input.cacheItem,
      resourcesOrigin: input.resourcesOrigin,
      changeService: false
    }
  };
}