// withHooks
// noPage
import { LibIcon } from 'esoftplay/cache/lib/icon/import';
import { LibNavigation } from 'esoftplay/cache/lib/navigation/import';
import { LibStyle } from 'esoftplay/cache/lib/style/import';
import { LibTextstyle } from 'esoftplay/cache/lib/textstyle/import';
import { LibToastProperty } from 'esoftplay/cache/lib/toast/import';
import { LibUtils } from 'esoftplay/cache/lib/utils/import';
import { MarketSection_menu } from 'esoftplay/cache/market/section_menu/import';
import { MarketStyle } from 'esoftplay/cache/market/style/import';
import esp from 'esoftplay/esp';

import React from 'react';
import { Text, TouchableOpacity, View } from 'react-native';


export interface MarketAddress_itemProps {
  // from ini antara dari mart/account atau market/account
  from?: string
  withKey: number,
  address: string,
  address_merchant?: string,
  address_mitra?: string,
  address_dc?: string,
  address_primary: string,
  address_return: string,
  id: string,
  location_id: string,
  location_latlong: string,
  location_name: string,
  name: string,
  phone: string,
  zipcode: string,
  recipient: string,
}


export default function m(props: MarketAddress_itemProps): any {
  const primaryText = [esp.lang("market/address_item", "address_main"), esp.lang("market/address_item", "address_merchant"), esp.lang("market/address_item", "address_return"), esp.lang("market/address_item", "address_mitra"), esp.lang("market/address_item", "address_dc")]
  const primaryValue = [props.address_primary, props.address_merchant, props.address_return, props.address_mitra, props.address_dc]

  const styleId_wAAsj: any = { backgroundColor: '#fff' }
  const styleId_Z1Uph5z: any = { color: props.from == 'mart' ? MarketStyle.colorPrimaryMart : MarketStyle.colorPrimaryMarket, marginBottom: 5, marginRight: 10 }
  const styleId_h5FC4: any = { marginTop: 5, padding: 5, borderRadius: 5, paddingHorizontal: 10, backgroundColor: LibUtils.hexToRgba(props.from == 'mart' ? MarketStyle.colorPrimaryMart : MarketStyle.colorPrimaryMarket, 0.1) }
  // esp.log(props.location_id == location.location_id);

  return (
    <>
      <TouchableOpacity onPress={() => {
        if (props.withKey > 0) {
          if (props.recipient != '') {
            LibNavigation.sendBackResult(props, props.withKey)
          } else {
            LibToastProperty.show(esp.lang("market/address_item", "empty_recipient"))
          }
        } else {
          LibNavigation.navigate("market/address_edit", { defaultAddress: props, from: props?.from })
        }
      }} style={styleId_wAAsj} >
        <View style={styleId_Z2urvSI} >
          {
            <View style={styleId_17srzJ} >
              {
                primaryValue.map((x, i) => {
                  if (x == '1')
                    return (<LibTextstyle key={i} textStyle="caption2" text={primaryText[i]} style={styleId_Z1Uph5z} />)
                  return null
                })
              }
            </View>
          }
          {
            props?.address == "" &&
            <View style={styleId_Z1IS0fI}>
              <View style={styleId_Z2cTOVS}>
                <Text allowFontScaling={false} style={styleId_Z1kXFXX}>{esp.lang("market/address_item", "address_empty")}</Text>
              </View>
            </View>
          }
          <LibTextstyle textStyle="footnote" text={props.name} style={styleId_aDTfH} />
          {
            props.recipient != '' &&
            <LibTextstyle textStyle="footnote" text={props.recipient} style={styleId_Zp7Rhg} />
          }
          <LibTextstyle
            style={styleId_Zp7Rhg}
            textStyle="footnote" text={props.address + ', ' + props.location_name + '\n' + props.zipcode} />
          <LibTextstyle
            style={styleId_Zp7Rhg}
            textStyle="footnote" text={props.phone} />
          {
            props.recipient == '' &&
            <View style={styleId_h5FC4} >
              <LibTextstyle textStyle="footnote" text={esp.lang("market/address_item", "alert_empty_recipient")} style={styleId_25Xa4I} />
            </View>
          }
        </View>
        <LibIcon.SimpleLineIcons name="location-pin" style={styleId_ZdKeVU} />
        <TouchableOpacity onPress={() => LibNavigation.navigate('market/address_edit', { defaultAddress: props, from: props?.from })} style={{ position: "absolute", top: 0, right: 5, padding: 10 }} >
          <LibIcon.SimpleLineIcons name="pencil" size={16} style={styleId_jBq3B} />
        </TouchableOpacity>
      </TouchableOpacity>
      <MarketSection_menu size="small" />
    </>
  )
}
const styleId_Z2urvSI: any = { paddingHorizontal: 17, paddingVertical: 10, marginLeft: 40 }
const styleId_Z1IS0fI: any = { flexDirection: 'row' }
const styleId_Z2cTOVS: any = { marginVertical: 7, padding: 5, borderRadius: 3, borderWidth: 1, borderColor: LibStyle.colorRed }
const styleId_Z1kXFXX: any = { textAlign: 'center', fontFamily: "Arial", fontSize: 10, fontWeight: "bold", fontStyle: "normal", letterSpacing: 0, color: LibStyle.colorRed }
const styleId_17srzJ: any = { flexDirection: 'row', flexWrap: 'wrap' }
const styleId_aDTfH: any = { fontWeight: 'bold' }
const styleId_Zp7Rhg: any = { marginTop: 5 }
const styleId_25Xa4I: any = { fontSize: 12, color: LibStyle.colorRed }
const styleId_ZdKeVU: any = { color: "#888", position: "absolute", top: 35, left: 17 }
const styleId_jBq3B: any = { color: "#888" }